clipoox-render 0.4.6 → 0.4.8

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.
Files changed (142) hide show
  1. package/package.json +2 -2
  2. package/scripts/render-local.mjs +2656 -1672
  3. package/shared/photocraft/LICENSE.txt +206 -0
  4. package/shared/photocraft/clipoox_photo.js +396 -0
  5. package/shared/photocraft/clipoox_photo_bg.wasm +0 -0
  6. package/web/assets/{FxEmbed-ROS6C_HI.js → FxEmbed-adbxHEBi.js} +1 -1
  7. package/web/assets/ImageStudio-CMxiT1jp.js +3 -0
  8. package/web/assets/ImageStudio-De_DCTrz.css +1 -0
  9. package/web/assets/{MotionEmbed-E2hCysi-.js → MotionEmbed-CDUIyjk0.js} +1 -1
  10. package/web/assets/{PluginStore-CwUSpwPp.js → PluginStore-By_pdOOg.js} +2 -2
  11. package/web/assets/ShotComposer-DcwWZ-eP.css +1 -0
  12. package/web/assets/ShotComposer-XIbJ4nNm.js +287 -0
  13. package/web/assets/{TemplateEmbed-qG1AXdtf.js → TemplateEmbed-a01nKECT.js} +1 -1
  14. package/web/assets/{TimelinePlugins-CB1b6-Cb.js → TimelinePlugins-CqLMVjuh.js} +4 -4
  15. package/web/assets/TimelineShotFx-QmkyCg31.js +2 -0
  16. package/web/assets/{TransitionEmbed-Dym9P7--.js → TransitionEmbed-Cbwlxfl2.js} +1 -1
  17. package/web/assets/{Whiteboard-BdGjJZXW.js → Whiteboard-ChYqIr3v.js} +1 -1
  18. package/web/assets/{aerial-yLD_gDzw.js → aerial-CZeCeacv.js} +2 -2
  19. package/web/assets/{agentTools-B7g6tXTR.js → agentTools-DW2ETnxE.js} +2 -2
  20. package/web/assets/{aiInbetween-6eKDYbYS.js → aiInbetween-De98iM4m.js} +2 -2
  21. package/web/assets/analyzerRun-D5-g-Vxe.js +1 -0
  22. package/web/assets/{analyzerSandbox-N92T6amg.js → analyzerSandbox-E3CdovIk.js} +1 -1
  23. package/web/assets/{api-Dnl2uaKO.js → api-CZoVJ9Fy.js} +87 -87
  24. package/web/assets/auraTrack-ClhHuqlf.js +1 -0
  25. package/web/assets/{breakthrough-DSiuVwEX.js → breakthrough-DTpiUIZd.js} +2 -2
  26. package/web/assets/{cameraPresets-Cfn7qhXK.js → cameraPresets-DD0WmxiI.js} +1 -1
  27. package/web/assets/{cameraTracker-DHdF8Zqx.js → cameraTracker-Df9jWmz6.js} +2 -2
  28. package/web/assets/{captionLayout-cckQ7p-t.js → captionLayout-eiu9QPJu.js} +1 -1
  29. package/web/assets/{clientExport-pkLbOmEF.js → clientExport-BXegTdNc.js} +1 -1
  30. package/web/assets/{clientJobs-CcsLDqFM.js → clientJobs-eB-lNyin.js} +2 -2
  31. package/web/assets/clipoox_photo_bg-BQ0aVNY0.wasm +0 -0
  32. package/web/assets/depthEstimate-CfwX-tXP.js +1 -0
  33. package/web/assets/{directorTools-DMsatulF.js → directorTools-ABbI8m0e.js} +1 -1
  34. package/web/assets/distortFrames-DMnZ8OYh.js +2 -0
  35. package/web/assets/distortGL-DQu0Df2c.js +18 -0
  36. package/web/assets/{domino-DBrinEUu.js → domino-trmDBvfH.js} +1 -1
  37. package/web/assets/{editTools-BNnAvCw-.js → editTools-DEFo9Ahv.js} +1 -1
  38. package/web/assets/{engine-Co-ivzlQ.js → engine-Y-GotDIy.js} +1 -1
  39. package/web/assets/exportGlb-BeLpJKJT.js +2 -0
  40. package/web/assets/{faceTracker-ClR-lS6Y.js → faceTracker-BeSFnLM8.js} +1 -1
  41. package/web/assets/{fightDirector-BlpVAURl.js → fightDirector-Dfz3vu5-.js} +1 -1
  42. package/web/assets/{fightDrama-BK0QidpM.js → fightDrama-CNVn69s0.js} +2 -2
  43. package/web/assets/{focusTool-sVOb2GGS.js → focusTool-Dd2UDkiO.js} +1 -1
  44. package/web/assets/{frameSink-CSRqCnwI.js → frameSink-Rj02YES5.js} +3 -3
  45. package/web/assets/{glTransitionSources.generated-q0H-ZbnZ.js → glTransitionSources.generated-Cs8lVRqs.js} +438 -2
  46. package/web/assets/{gpuCompose-B5bgbHdQ.js → gpuCompose-DkkKH1Ab.js} +1 -1
  47. package/web/assets/gpuExport-DwrXpVGF.js +199 -0
  48. package/web/assets/{handMatte-Dj2taFoC.js → handMatte-B5sUeqKi.js} +1 -1
  49. package/web/assets/{handTracker-c6_rvuwA.js → handTracker-CQV-D7va.js} +2 -2
  50. package/web/assets/i18n-ClNt3LKg.js +3 -0
  51. package/web/assets/{index-Ds_8isyf.js → index-D2u6mD-8.js} +1 -1
  52. package/web/assets/layer-worker-DP0N05Ua.js +5 -0
  53. package/web/assets/library-cb43ZEmy.js +1 -0
  54. package/web/assets/{lottieLayer-Cv8ub9f6.js → lottieLayer-DEw0c3to.js} +4 -4
  55. package/web/assets/main-C_XcvNyC.js +311 -0
  56. package/web/assets/{main-B_MAOvi6.css → main-DlzdW5C4.css} +1 -1
  57. package/web/assets/{mapBake-DtQboFIX.js → mapBake-BUWz0cSx.js} +1 -1
  58. package/web/assets/maskTrack-GYpJyKFw.js +1 -0
  59. package/web/assets/matteFixRun-BCVsuSxf.js +1 -0
  60. package/web/assets/{objectLocate-XuAcemlO.js → objectLocate-CjIlo_u0.js} +1 -1
  61. package/web/assets/{objectSegmenter-D66spD7o.js → objectSegmenter-C4T9qgUL.js} +1 -1
  62. package/web/assets/{objectTrack.worker-BZS6WZ6l.js → objectTrack.worker-BVvsDmR0.js} +1450 -908
  63. package/web/assets/{pathTracer-DykgPkkh.js → pathTracer-DgL1_83l.js} +2 -2
  64. package/web/assets/{pendingMatte-BWBIWajI.js → pendingMatte-DPTe6xoZ.js} +2 -2
  65. package/web/assets/peopleMatte-C1hruEM6.js +1 -0
  66. package/web/assets/{personAi-EhBknW6X.js → personAi-Cjg9KKeH.js} +2 -2
  67. package/web/assets/{personHq-Ca351o06.js → personHq-CBP8v_cw.js} +2 -2
  68. package/web/assets/photo.worker-DK_ulTzR.js +1 -0
  69. package/web/assets/photoRun-lZ2BdSEk.js +2 -0
  70. package/web/assets/photoTools-DmUh69Qk.js +1 -0
  71. package/web/assets/plateCamera-DLqlXhMp.js +1 -0
  72. package/web/assets/{plateCameraMatch-GPZl1fQQ.js → plateCameraMatch-4VUlUMi-.js} +2 -2
  73. package/web/assets/{plateFollow-CJUilsNV.js → plateFollow-D2rjnmZA.js} +2 -2
  74. package/web/assets/plateMatte-0tTG7oeO.js +2 -0
  75. package/web/assets/{pluginAutomation-DAPHWZPN.js → pluginAutomation-ClFdpcCR.js} +1 -1
  76. package/web/assets/popTools-B38V4wub.js +1 -0
  77. package/web/assets/{poseTracker-CzEKvJph.js → poseTracker-qtuytI-L.js} +1 -1
  78. package/web/assets/{productTools-ce-zyZO0.js → productTools-DlC5vWjx.js} +2 -2
  79. package/web/assets/remote-CpkPQOQH.js +989 -0
  80. package/web/assets/{rigTrack-DMyqb0pb.js → rigTrack-BbKqZGs7.js} +1 -1
  81. package/web/assets/{rotoMaskStore-pE1AIt3I.js → rotoMaskStore-BZBJLcCp.js} +1 -1
  82. package/web/assets/{rotoMatte-7b7Ow64f.js → rotoMatte-BI-vjjrv.js} +1 -1
  83. package/web/assets/rotoscope-DuNcCxQy.js +1 -0
  84. package/web/assets/{sceneTrack-DlAH5s74.js → sceneTrack-CO4fTjft.js} +1 -1
  85. package/web/assets/{sceneTrack-CA21MCOP.js → sceneTrack-_n6WKKQv.js} +1 -1
  86. package/web/assets/{sceneTrack.worker-COlhlHRe.js → sceneTrack.worker-f2d-WOzw.js} +1496 -954
  87. package/web/assets/{shot-worker-DL1ZoIym.js → shot-worker-BSmfIXHO.js} +1 -1
  88. package/web/assets/{shotFxAgent-DqngnGFb.js → shotFxAgent-L2GG88W3.js} +1 -1
  89. package/web/assets/{skin-xFScwS3T.js → skin-CirUiqcr.js} +1 -1
  90. package/web/assets/{spark.module-DjaIF6J1.js → spark.module-3Q8DniuL.js} +1 -1
  91. package/web/assets/{spellDuel-BYNtnE8f.js → spellDuel-2CDLbiLQ.js} +2 -2
  92. package/web/assets/{store-CpqHUcA2.js → store-D3Y663py.js} +1 -1
  93. package/web/assets/{surfaceLight-C7YI9SV8.js → surfaceLight--HQj7xhO.js} +1 -1
  94. package/web/assets/{surfacePin-CzpUj1Cw.js → surfacePin-BCmgw-40.js} +2 -2
  95. package/web/assets/{textAnimators-B9vO_hbP.js → textAnimators-C4eMnVRD.js} +1 -1
  96. package/web/assets/{thumb-BTFsBS1u.js → thumb-M9B_goj-.js} +1 -1
  97. package/web/assets/{timeline3d-DrFaMPPB.js → timeline3d-BcW68fQr.js} +2 -2
  98. package/web/assets/{timeline3dExport-Uo0S0CR0.js → timeline3dExport-DgnorHLm.js} +1 -1
  99. package/web/assets/timelineComp-Ciu9JCWJ.js +1 -0
  100. package/web/assets/timelineOps-f1WsVbgS.js +526 -0
  101. package/web/assets/{timelineProps-0v-s69pw.js → timelineProps-CE1R11Hx.js} +1 -1
  102. package/web/assets/{timelineText-DurRhyuh.js → timelineText-Cppd4KB7.js} +1 -1
  103. package/web/assets/{titleArt-CnC0A7x7.js → titleArt-D0YI5xT2.js} +3 -3
  104. package/web/assets/{titleFrameBudget-DsM0V482.js → titleFrameBudget-h4nOQ5u9.js} +1717 -1175
  105. package/web/assets/titleFrames-DnCzi_AI.js +1 -0
  106. package/web/assets/{tool-D1FpErrX.js → tool-tp6gat1J.js} +1 -1
  107. package/web/assets/{tools-DIvrRu-5.js → tools-C07G9KUM.js} +1 -1
  108. package/web/assets/{toonTools-D9MNdRty.js → toonTools-Cazx2CL7.js} +2 -2
  109. package/web/assets/{trackAnchor-XvUuvkWP.js → trackAnchor-DoqFDcJB.js} +1 -1
  110. package/web/assets/{userFonts-Djka6RJX.js → userFonts-BlVEJfDk.js} +1 -1
  111. package/web/assets/{vfxAlpha-B-JzzRI1.js → vfxAlpha-Bp6VgIGN.js} +1 -1
  112. package/web/assets/vfxBackground-BFq44Srn.js +2 -0
  113. package/web/assets/{videoExport-NN-QijHd.js → videoExport-Cz02XKtX.js} +1 -1
  114. package/web/assets/{views-RQBs4zva.js → views-CNF3Afse.js} +1 -1
  115. package/web/assets/{weaponDuel-DKAEYJjO.js → weaponDuel-ChqBQo_b.js} +1 -1
  116. package/web/assets/{windowFrames-DhhJLIs-.js → windowFrames-dBMXwGek.js} +1 -1
  117. package/web/layer-worker.html +3 -3
  118. package/web/shot-worker.html +24 -24
  119. package/web/assets/ShotComposer-DLxWpdYH.js +0 -287
  120. package/web/assets/ShotComposer-deLi4grZ.css +0 -1
  121. package/web/assets/TimelineShotFx-CyHTgJHj.js +0 -2
  122. package/web/assets/analyzerRun-Cr-_79RH.js +0 -1
  123. package/web/assets/auraTrack-C8eAEIWQ.js +0 -1
  124. package/web/assets/depthEstimate-Cav4MmQ1.js +0 -1
  125. package/web/assets/distortFrames-D_v-aSVO.js +0 -2
  126. package/web/assets/distortGL-vhnBRB59.js +0 -12
  127. package/web/assets/exportGlb-D3PrWUvi.js +0 -2
  128. package/web/assets/gpuExport-oA2mUsdm.js +0 -198
  129. package/web/assets/i18n-C9zFX25m.js +0 -3
  130. package/web/assets/layer-worker-ClVZG6ZW.js +0 -5
  131. package/web/assets/library-BK0QVG4O.js +0 -1
  132. package/web/assets/main-CwrkBJ63.js +0 -309
  133. package/web/assets/maskTrack-D4QZfMWc.js +0 -1
  134. package/web/assets/matteFixRun-CytaeRzS.js +0 -1
  135. package/web/assets/plateCamera-BcdXD1uI.js +0 -1
  136. package/web/assets/plateMatte-CoEoVjxZ.js +0 -2
  137. package/web/assets/remote-8XzEAnAJ.js +0 -974
  138. package/web/assets/rotoscope-BUqNTKLd.js +0 -1
  139. package/web/assets/timelineComp-i-zdaoB2.js +0 -1
  140. package/web/assets/timelineOps-DSSaDsU2.js +0 -525
  141. package/web/assets/titleFrames-C8kvflgT.js +0 -1
  142. package/web/assets/vfxBackground-b053ziDK.js +0 -2
@@ -0,0 +1,526 @@
1
+ import{G as Cn,I as uw,t as dw,hm as to,l as en,hl as Qe,hM as Zi,au as ut,kP as Za,cp as hw,F as ve,gH as Ji,dK as fw,dJ as Rp,d1 as ge,kQ as mw,kR as Nh,dZ as Ee,dH as Qg,d$ as Qt,aG as qn,kS as $c,kT as gw,iA as vp,kU as yw,s as ls,kV as bw,kW as t1,kX as ww,ax as Rh,aw as Dh,h as an,f as Xn,kY as kw,ay as Bh,kZ as Ja,k_ as xw,U as ph,ao as uh,v as Oi,bm as e1,k$ as Mw,l0 as o1,l1 as r1,l2 as n1,aB as Yt,l3 as jn,e0 as bs,d7 as Kt,l4 as a1,aX as dh,b5 as $p,dN as Yu,l5 as vw,l6 as br,l7 as hh,l8 as $w,ig as _e,b4 as Ec,l9 as Ew,M as tl,gT as Sc,at as _h,la as Hs,dX as Vh,lb as qu,lc as Sw,ld as Iw,le as i1,lf as Aw,fd as Br,eX as el,fg as dl,eZ as Cw,ib as fh,ia as jw,lg as yl,kw as Tw,lh as s1,kx as Ow,li as zw,dn as l1,ha as Pw,dr as Lw,dq as Fw,dQ as Nw,lj as pn,cz as Ic,B as Ac,z as yn,lk as Rw,aN as Dw,bh as c1,fS as ca,d_ as Ep,ll as p1,fZ as Bs,ir as Ze,fB as li,lm as Zu,ln as u1,lo as ac,jx as d1,lp as Gh,hk as Cc,lq as Bw,lr as _w,ls as Vw,lt as Gw,lu as Kw,i3 as Ww,iC as mh,gQ as Cr,lv as Hw,lw as Xw,lx as Uw,ly as Yw,lz as qw,lA as Zw,fe as jr,gL as In,gK as Zn,lB as _r,lC as Ju,g5 as kn,cT as Dn,cC as fr,lD as h1,lE as Jw,hL as Dp,lF as Qw,lG as t2,lH as e2,lI as o2,m as xn,ip as ic,im as Sp,cs as ui,cW as Qu,b$ as f1,eY as r2,fk as n2,lJ as a2,fi as Vr,gJ as cs,lK as m1,e_ as sc,gS as g1,aE as Kh,lL as Ip,hi as y1,bg as Bp,lM as b1,al as bn,h4 as _s,he as lc,aj as jc,ac as i2,hg as Wh,lN as s2,h6 as l2,lO as c2,hb as p2,am as td,ak as u2,aV as w1,eE as dr,ik as d2,il as h2,iF as f2,iS as m2,ce as ed,cf as g2,cd as k1,lP as on,lQ as ps,lR as mr,fR as tr,gc as ga,gf as Tc,ge as Xs,lS as gh,lT as us,fz as x1,lU as yh,fx as _p,lV as Hh,fW as Xh,lW as y2,lX as b2,lY as M1,lZ as Uh,l_ as w2,fG as Yh,fO as bh,fy as qh,l$ as k2,m0 as ol,m1 as x2,m2 as v1,m3 as M2,gd as v2,m4 as Zh,m5 as $2,m6 as E2,m7 as od,aI as S2,av as I2,cE as pa,cv as A2,cA as bl,m8 as Jh,cJ as rd,cB as C2,du as Qh,kh as j2,dp as tf,m9 as T2,dw as O2,aJ as z2,ma as ef,c0 as Vp,c2 as of,cg as P2,c8 as Gp,mb as rf,mc as wl,bA as $1,md as nf,me as L2,mf as F2,mg as N2,gR as R2,i as kl,aW as af,mh as D2,cm as fi,iB as sf,iq as B2,io as _2,bo as V2,bp as G2,E as lf,mi as K2,mj as W2,mk as H2,ml as X2,mm as Oc,q as cf,mn as U2,D as Y2,e as pf,c as q2,R as uf,n as Z2,a as J2,d as Q2,fH as dn,mo as df,mp as tk,mq as ek,fI as ok,mr as rk,fL as nk,C as ak,aO as Ms,aM as hf,ms as cc,mt as ff,mu as mf,mv as gf,mw as ik,mx as sk,my as lk,iz as ra,c$ as xl,is as yf,mz as Ml,dv as ck,g7 as bf,da as wf,df as Kp,dk as Wp,mA as pk,mB as kf,it as uk,di as dk,dj as hk,iv as fk,mC as mk,mD as gk,mE as yk,mF as bk,fn as wk,hn as kk,mG as xk,mH as Mk,mI as vk,mJ as $k,hJ as Ek,iD as Sk,mK as Ik,mL as xf,mM as Ak,mN as Ck,mO as jk,mP as Tk,ke as Ok,h0 as zk,A as Pk,gI as Mf,mQ as Lk,mR as Fk,mS as Nk,mT as Rk,id as vf,i7 as $f,mU as Dk,mV as Bk,mW as _k,gr as Vk,j as Ef,mX as Sf,b6 as Gk,g as Kk,mY as Wk,dU as Hk,jj as ja,c5 as If,c4 as Xk,c3 as Uk,dt as Yk,cr as qk,mZ as Af,m_ as Zk,m$ as Jk,gU as Cf,g3 as Qk,n0 as tx,fs as ex,n1 as ox,n2 as rx,hX as nx,bz as E1,n3 as ax,n4 as jf,n5 as Tf,iw as ix,ix as sx,iy as lx,n6 as Of,n7 as cx,kF as px}from"./titleFrameBudget-h4nOQ5u9.js";import{C as ux,N as dx,b as zf,O as hx,E as fx,F as mx,s as gx,Q as yx,R as bx,G as wx,o as kx,T as xx,h as Mx,U as vx,q as $x,l as Ex,j as Sx}from"./sceneTrack-CO4fTjft.js";import{h as Ix,i as Ax,B as S1,m as pc,s as Cx,t as ri,r as Pf,j as jx,k as Tx,n as Ox,D as zx,E as Px,o as vl,q as Lx,u as Fx,f as Nx,v as Rx,w as Dx}from"./cameraTracker-Df9jWmz6.js";import{A as Bx,H as _x,h as Vx,j as Gx,p as Kx,C as Wx,M as Lf}from"./textAnimators-C4eMnVRD.js";import{i as Ff,u as Hx,p as Xx,f as Ux,m as Yx}from"./timelineComp-Ciu9JCWJ.js";import{bT as Nf,aM as qx,aK as Zx}from"./api-CZoVJ9Fy.js";import{L as $l,f as Jx,s as Qx,r as t3}from"./store-D3Y663py.js";import{n as e3,P as ya,o as Nr,q as Rf,A as nd,t as I1,u as Df,v as Qi,x as o3,y as r3,B as Hp,z as n3,C as a3,D as i3,E as s3,F as l3,G as c3,H as p3,I as Xp,J as u3,K as Bf,L as d3,N as _f,O as h3,Q as A1,R as Vf,T as f3,U as zc,V as Pc,W as ad,X as Gf}from"./rigTrack-BbKqZGs7.js";import{addClientJob as Fe}from"./clientJobs-CuuUyhEy.js";const m3={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",inkline:"scene"},Kf={"inkline-lower":"overlay","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 g3(t,e){const o=typeof t=="string"?t:t?.id,r=typeof t=="string"?e:t?.pack;return/^fxo-/.test(o||"")?Kf[o]||"look":Kf[o]||m3[r]||"overlay"}const y3=Object.freeze(["general","creator","education","commerce","corporate","finance","tech","ai","saas","gaming","data","product","luxury","beauty","food","event","realestate","health","fitness","travel","auto"]),Wf=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},inkline:{industries:["general","creator","food","travel","education","event"],tone:"light",energy:1},basic:{industries:["general"],tone:"any",energy:2}}),b3=[[/\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"]],w3=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}]]))}),k3=t=>{const e=String(t||"").match(/\/\/ ([^\n]+)/);return e?e[1].trim():""},x3={text:"text",sub:"subText",items:"items",number:"numberValue",icon:"icon",glyph:"icon",posX:"posX"};function M3(t){const e=t.pack||"basic",o=Wf[e]||Wf.basic,r=g3(t),a=k3(t.code).slice(0,140),n=`${t.id} ${t.name} ${a}`;let i=r==="transition"?["transition"]:r==="background"?["background"]:r==="look"?["decor"]:[];if(!i.length)for(const[f,m]of b3)f.test(n)&&!i.includes(m)&&i.push(m);i.length||(i=[r==="scene"?"explain":"decor"]);const c=w3[t.id];c?.beats&&(i=[...c.beats]);const u=t.params?.position,p=["scene","background","look","transition"].includes(r)?"full":["top","center","lower"].includes(u)?u:"center",s=[...new Set(Object.keys(t.params||{}).map(f=>x3[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:p,fields:s,energy:o.energy,tone:o.tone,industries:o.industries,dur:t.duration,about:a,fmt:h})}let Up=null;function uc(){return Up||(Up=Object.freeze(Cn.filter(t=>uw.includes(t.id)).map(M3))),Up}const v3={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ễ"]},$3={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"]},Hf=(t,e)=>t.includes(e);function C1(t){const e=` ${String(t||"").toLowerCase()} `,o=Object.entries(v3).filter(([,a])=>a.some(n=>Hf(e,n))).map(([a])=>a),r=Object.entries($3).filter(([,a])=>a.some(n=>Hf(e,n))).map(([a])=>a);return{industries:o,beats:r}}const E3=Object.freeze(["minimal","luxury","friendly","bold","tech"]),S3=Object.freeze({minimal:["iris","slab"],luxury:["iris","ink"],friendly:["shapes","stripes"],bold:["slab","flash","whip"],tech:["glitch","tunnel","whip"]}),I3=/^#[0-9a-f]{6}$/i,mi=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function j1(t){if(!t||typeof t!="object")return null;const e=new Set(dw.map(a=>a.id)),o={name:mi(t.name,60),tagline:mi(t.tagline,80),website:mi(t.website,80),phone:mi(t.phone,40),address:mi(t.address,100),industry:y3.includes(t.industry)?t.industry:"general",tone:E3.includes(t.tone)?t.tone:"minimal",colors:(Array.isArray(t.colors)?t.colors:[]).filter(a=>I3.test(a)).map(a=>a.toLowerCase()).slice(0,3),pack:e.has(t.pack)?t.pack:null,banned:(Array.isArray(t.banned)?t.banned:[]).filter(a=>e.has(a)).slice(0,20),logoMaterialId:mi(t.logoMaterialId,200)||null},r=Object.fromEntries(["heading","body"].filter(a=>Bx(t.fonts?.[a])).map(a=>[a,t.fonts[a]]));return Object.keys(r).length&&(o.fonts=r),o.name||o.colors.length||o.logoMaterialId?o:null}const A3=t=>[t?.website,t?.phone,t?.address].filter(Boolean);function Aj(t){const e=j1(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 fe=(t,e,...o)=>({name:t,dur:e,presets:o}),T1=Object.freeze({"tvc-15":{name:"TVC 15 giây",beats:[fe("open",2.5,"tvc-brand-open"),fe("problem",3,"tvc-problem"),fe("solution",3.5,"tvc-solution"),fe("offer",3,"tvc-offer","tvc-big-stat"),fe("cta",3,"tvc-cta-contact")]},"tvc-30":{name:"TVC 30 giây",beats:[fe("open",3,"tvc-brand-open"),fe("problem",4,"tvc-problem"),fe("solution",4,"tvc-solution"),fe("features",5,"tvc-feature-trio"),fe("proof",4,"tvc-testimonial","tvc-big-stat","tvc-trust-badges"),fe("offer",4,"tvc-offer","tvc-countdown-offer"),fe("cta",3,"tvc-cta-contact"),fe("logo",3,"tvc-logo-sting")]},"product-launch":{name:"Ra mắt sản phẩm",beats:[fe("open",3,"tvc-brand-open"),fe("solution",4,"tvc-solution"),fe("features",5,"tvc-feature-trio"),fe("compare",4,"tvc-before-after"),fe("cta",3,"tvc-cta-contact"),fe("logo",3,"tvc-logo-sting")]},"promo-sale":{name:"Khuyến mãi",beats:[fe("slogan",3,"tvc-slogan"),fe("offer",4,"tvc-offer"),fe("countdown",3,"tvc-countdown-offer"),fe("proof",2.5,"tvc-trust-badges"),fe("cta",3,"tvc-cta-contact")]},"brand-story":{name:"Câu chuyện thương hiệu",beats:[fe("logo",3,"tvc-logo-sting"),fe("slogan",4,"tvc-slogan"),fe("number",4,"tvc-big-stat"),fe("proof",5,"tvc-testimonial"),fe("partners",4,"tvc-partners"),fe("cta",3,"tvc-cta-contact")]},"store-visit":{name:"Mời ghé cửa hàng",beats:[fe("open",3,"tvc-brand-open"),fe("features",4,"tvc-feature-trio"),fe("offer",3.5,"tvc-offer"),fe("location",4,"tvc-location"),fe("logo",3,"tvc-logo-sting")]}}),C3=Object.freeze(Object.keys(T1)),j3={flash:.8,whip:.8,glitch:.8,slab:1,iris:1,stripes:1,ink:1.2,shapes:1.2,tunnel:1.2},Ta=t=>+(+t).toFixed(3),Yp=t=>String(t??"").slice(0,60);function T3(t,e,o){const r=e?.[t.name]||{},a={},n=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),c=Array.isArray(r.items)?r.items:t.name==="cta"?A3(o):void 0;return n&&(a.text=Yp(n)),i&&(a.subText=Yp(i)),c?.length&&(a.items=c.map(Yp).slice(0,5)),Number.isFinite(+r.number)&&r.number!==null&&r.number!==""&&(a.numberValue=+r.number),a}function O3({recipe:t="tvc-15",copy:e={},brand:o=null,start:r=0,portrait:a=!1,dark:n=!1,base:i=0}={}){const c=T1[t];if(!c)throw Error(`TVC recipe must be ${C3.join("/")}`);const u=o?.colors?.[0],p=[],s=c.beats.reduce((g,v)=>g+v.dur,0),h=S3[o?.tone||"minimal"];for(let g=0;g<s-.001;g+=to.maxDuration)p.push({op:"addMotion",motionPreset:"tvc-backdrop",start:Ta(r+g),duration:Ta(Math.min(to.maxDuration,s-g)),numberValue:n?1:0,...u?{color:u}:{}});let f=r,m=null;if(c.beats.forEach((g,v)=>{const x=e?.[g.name]?.preset,E=g.presets.includes(x)?x:g.presets[0];if(p.push({op:"addMotion",motionPreset:E,start:Ta(f),duration:Ta(g.dur),placement:"center",...T3(g,e,o),...u?{color:u}:{}}),E==="tvc-logo-sting"&&(m={start:f,dur:g.dur}),v>0){const $=h[(v-1)%h.length],S=j3[$];p.push({op:"addMotion",motionPreset:`bridge-${$}`,start:Ta(Math.max(r,f-S/2)),duration:S,...u?{color:u}:{}})}f+=g.dur}),o?.logoMaterialId&&m){const g=i+p.filter(v=>/^add/.test(v.op)).length+1;p.push({op:"addClip",materialId:o.logoMaterialId,start:Ta(m.start+.25),duration:Ta(m.dur-.25),track:en(6)},{op:"setPropertyKeys",clipId:`new:${g}`,property:"zoom",propertyKeys:[{time:0,value:a?.2:.16}]},{op:"setPropertyKeys",clipId:`new:${g}`,property:a?"y":"x",propertyKeys:[{time:0,value:a?-.045:-.12}]})}return p}const z3=t=>{try{const e=JSON.parse(String(t||"{}"));return e&&typeof e=="object"?e:{}}catch{return{}}};function P3(t,{brand:e=null,portrait:o=!1}={}){if(!t.some(u=>u?.op==="tvc"))return t;const r=[],a=[];let n=0,i=0;const c=u=>{const p=typeof u=="string"&&/^new:(\d+)$/.exec(u);if(!p)return u;const s=+p[1];let h=0;for(const f of a)s>f.after&&(h+=f.by);return`new:${s+h}`};for(const u of t){const p=u?.clipId||u?.fromClipId||u?.sourceClipId?{...u,...u.clipId?{clipId:c(u.clipId)}:{},...u.fromClipId?{fromClipId:c(u.fromClipId)}:{},...u.sourceClipId?{sourceClipId:c(u.sourceClipId)}:{}}:u;if(p?.op!=="tvc"){r.push(p),/^(add|lockup$)/.test(p?.op??"")&&(n++,i++);continue}const s=O3({recipe:p.preset,copy:z3(p.prompt),brand:e,start:+p.start||0,portrait:o,dark:p.booleanValue===!0,base:n}),h=s.filter(f=>/^add/.test(f.op)).length;r.push(...s),h&&a.push({after:i,by:h}),n+=h}return r}const O1="vfx-qi-core",z1="vfx-qi-aura",P1="vfx-yinyang-vortex",Cj=Object.freeze([O1,z1,P1]),Lc=Object.freeze({core:Object.freeze({preset:O1,label:"Tụ khí kết ấn",duration:3,sfx:"sp-whoosh-transition-1"}),aura:Object.freeze({preset:z1,label:"Hào quang nội lực mịn",duration:3.5,sfx:"sp-whoosh-transition-1"}),vortex:Object.freeze({preset:P1,label:"Xoáy nội lực Âm Dương",duration:3.5,sfx:"sp-sub-hit-1"})}),L1=Object.freeze(Object.keys(Lc)),L3=Object.freeze({color:Object.freeze({kind:"color",vi:"Màu khí chính",en:"Primary qi colour"}),color2:Object.freeze({kind:"color",vi:"Màu khí phụ",en:"Secondary qi colour"}),core:Object.freeze({kind:"color",vi:"Màu lõi sáng",en:"Core colour"}),colorA:Object.freeze({kind:"color",vi:"Màu dòng Dương",en:"Yang flow colour"}),colorB:Object.freeze({kind:"color",vi:"Màu dòng Âm",en:"Yin flow colour"}),mistColor:Object.freeze({kind:"color",vi:"Màu sương khí",en:"Mist colour"}),swirl:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Độ xoáy",en:"Swirl"}),silk:Object.freeze({kind:"range",min:.3,max:2,step:.05,vi:"Độ mịn lụa khí",en:"Silk thickness"}),intensity:Object.freeze({kind:"range",min:.2,max:2.2,step:.05,vi:"Nội lực",en:"Intensity"}),flow:Object.freeze({kind:"range",min:.2,max:3,step:.05,vi:"Tốc độ bốc khí",en:"Flow speed"}),turbulence:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Độ cuộn sóng",en:"Turbulence"}),ripple:Object.freeze({kind:"range",min:0,max:2,step:.05,vi:"Độ gợn sóng mịn",en:"Ripple smoothness"}),width:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Độ rộng",en:"Width"}),height:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Chiều cao",en:"Height"}),size:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Độ lớn",en:"Size"}),glow:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Phát sáng (Glow)",en:"Glow"}),speed:Object.freeze({kind:"range",min:.2,max:3,step:.05,vi:"Tốc độ",en:"Speed"}),motes:Object.freeze({kind:"range",min:0,max:100,step:2,vi:"Bụi linh khí",en:"Qi motes"}),embers:Object.freeze({kind:"range",min:0,max:100,step:2,vi:"Tàn lửa khí",en:"Qi embers"}),x:Object.freeze({kind:"range",min:0,max:1,step:.01,vi:"Vị trí X",en:"Position X"}),y:Object.freeze({kind:"range",min:0,max:1,step:.01,vi:"Vị trí Y",en:"Position Y"}),seed:Object.freeze({kind:"range",min:1,max:99,step:1,vi:"Biến thể (Seed)",en:"Variation seed"})}),F3=/^#[0-9a-fA-F]{6}$/,vs=t=>Math.round(t*1e4)/1e4,El=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r;function N3({id:t,style:e="core",at:o=0,duration:r,u:a,v:n,params:i={}}){const c=Lc[e];if(!c)throw Error(`addQiVfx style: ${L1.join("|")}`);const u=Cn.find(h=>h.id===c.preset);if(!u)throw Error(`Unknown Qi preset ${c.preset}`);const p=vs(El(r,[.4,20],c.duration)),s={...u.params};Number.isFinite(a)&&(s.x=vs(El(a,[0,1],s.x))),Number.isFinite(n)&&(s.y=vs(El(n,[0,1],s.y)));for(const[h,f]of Object.entries(i||{})){if(!(h in s)||f===void 0||f===null)continue;const m=L3[h];if(m){if(m.kind==="color")F3.test(String(f))&&(s[h]=String(f));else if(m.kind==="range"){const g=Number(f);Number.isFinite(g)&&(s[h]=vs(El(g,[m.min,m.max],s[h])))}}}return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:vs(Math.max(0,o)),duration:p,label:c.label,motionV:2,posX:0,posY:0,scale:1,opacity:1,motion:Qe({code:`@preset:${c.preset}`,params:s,preset:c.preset,kind:"three"})}}const F1="vfx-tvc-speedflow-tunnel",N1="vfx-tvc-synapse-ring",R1="vfx-tvc-starburst-flare",D1="vfx-tvc-prism-caustic",jj=Object.freeze([F1,N1,R1,D1]),Fc=Object.freeze({speedflow:Object.freeze({preset:F1,label:"Luồng tốc độ Speedflow TVC",duration:2.5,sfx:"sp-whoosh-transition-1"}),synapse:Object.freeze({preset:N1,label:"Vòng xung điện phản xạ TVC",duration:2.2,sfx:"sp-sub-hit-1"}),starburst:Object.freeze({preset:R1,label:"Vụ nổ ánh sao & Bokeh TVC",duration:1.8,sfx:"sp-sub-hit-1"}),prism:Object.freeze({preset:D1,label:"Hào quang lăng kính Logo TVC",duration:3,sfx:"sp-whoosh-transition-1"})}),B1=Object.freeze(Object.keys(Fc)),R3=Object.freeze({color:Object.freeze({kind:"color",vi:"Màu chính",en:"Primary colour"}),color2:Object.freeze({kind:"color",vi:"Màu phụ",en:"Secondary colour"}),core:Object.freeze({kind:"color",vi:"Màu lõi sáng",en:"Core highlight"}),density:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Mật độ tia",en:"Streak density"}),clearCore:Object.freeze({kind:"range",min:.05,max:.65,step:.01,vi:"Vùng trống tâm",en:"Clear center radius"}),chroma:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Tán sắc RGB",en:"Chromatic dispersion"}),intensity:Object.freeze({kind:"range",min:.2,max:2.2,step:.05,vi:"Cường độ",en:"Intensity"}),size:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Độ lớn",en:"Size"}),glow:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Phát sáng (Glow)",en:"Glow"}),speed:Object.freeze({kind:"range",min:.2,max:3,step:.05,vi:"Tốc độ",en:"Speed"}),bokeh:Object.freeze({kind:"range",min:0,max:2,step:.05,vi:"Hạt bokeh cầu vồng",en:"Chromatic bokeh"}),x:Object.freeze({kind:"range",min:0,max:1,step:.01,vi:"Vị trí X",en:"Position X"}),y:Object.freeze({kind:"range",min:0,max:1,step:.01,vi:"Vị trí Y",en:"Position Y"}),seed:Object.freeze({kind:"range",min:1,max:99,step:1,vi:"Biến thể (Seed)",en:"Variation seed"})}),D3=/^#[0-9a-fA-F]{6}$/,$s=t=>Math.round(t*1e4)/1e4,Sl=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r;function B3({id:t,style:e="speedflow",at:o=0,duration:r,u:a,v:n,params:i={}}){const c=Fc[e];if(!c)throw Error(`addTvcVfx style: ${B1.join("|")}`);const u=Cn.find(h=>h.id===c.preset);if(!u)throw Error(`Unknown TVC preset ${c.preset}`);const p=$s(Sl(r,[.4,20],c.duration)),s={...u.params};Number.isFinite(a)&&(s.x=$s(Sl(a,[0,1],s.x))),Number.isFinite(n)&&(s.y=$s(Sl(n,[0,1],s.y)));for(const[h,f]of Object.entries(i||{})){if(!(h in s)||f===void 0||f===null)continue;const m=R3[h];m&&(m.kind==="color"?D3.test(String(f))&&(s[h]=String(f)):m.kind==="range"&&(s[h]=$s(Sl(Number(f),[m.min,m.max],s[h]))))}return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:$s(Math.max(0,o)),duration:p,label:c.label,motionV:2,posX:0,posY:0,scale:1,opacity:1,motion:Qe({code:`@preset:${c.preset}`,params:s,preset:c.preset,kind:"three"})}}const id="vfx-weapon-slash",_1="vfx-cross-slash",sd="vfx-clash-sparks",zi="vfx-energy-ribbon",Tj=Object.freeze({color:Object.freeze({kind:"color",vi:"Màu năng lượng",en:"Energy colour"}),core:Object.freeze({kind:"color",vi:"Màu lõi sáng",en:"Core colour"}),angle:Object.freeze({kind:"range",min:-180,max:180,step:1,unit:"°",vi:"Góc chém",en:"Slash angle"}),arc:Object.freeze({kind:"range",min:40,max:280,step:5,unit:"°",vi:"Độ rộng cung",en:"Arc sweep"}),spread:Object.freeze({kind:"range",min:25,max:140,step:1,unit:"°",vi:"Góc chéo X",en:"Cross angle"}),delay:Object.freeze({kind:"range",min:0,max:.25,step:.01,unit:"s",vi:"Độ trễ nhát 2",en:"2nd slash delay"}),width:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Độ dày",en:"Thickness"}),size:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Độ lớn",en:"Size"}),glow:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Phát sáng (Glow)",en:"Glow"}),speed:Object.freeze({kind:"range",min:.3,max:2.5,step:.05,vi:"Tốc độ",en:"Speed"}),length:Object.freeze({kind:"range",min:.08,max:1.5,step:.02,unit:"s",vi:"Độ dài vệt",en:"Trail length"}),flare:Object.freeze({kind:"range",min:0,max:2.5,step:.05,vi:"Độ loé sao",en:"Star flare"}),sparks:Object.freeze({kind:"sparks",min:0,max:80,step:2,vi:"Tia lửa",en:"Sparks"}),flip:Object.freeze({kind:"bool",vi:"Đảo chiều chém",en:"Flip direction"}),ring:Object.freeze({kind:"bool",vi:"Vòng xung kích",en:"Shockwave ring"}),x:Object.freeze({kind:"range",min:0,max:1,step:.01,vi:"Vị trí X",en:"Position X"}),y:Object.freeze({kind:"range",min:0,max:1,step:.01,vi:"Vị trí Y",en:"Position Y"}),seed:Object.freeze({kind:"range",min:1,max:99,step:1,vi:"Biến thể (Seed)",en:"Variation seed"})}),Oj=Object.freeze([id,_1,sd,zi]),zj=t=>t==="n"||t==="fps"||t==="t0"||/^p\d+$/.test(t),Nc=/^#[0-9a-fA-F]{6}$/,To=t=>Math.round(t*1e4)/1e4,Zr=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,ld=Object.freeze({slash:Object.freeze({preset:id,label:"Vệt chém kiếm khí",color:"#38bdf8",core:"#ffffff",duration:.55,hitstop:.1,impactFrame:"impact-bw",sfx:Object.freeze([{id:"sp-slice-1",offset:-.04},{id:"sp-impact-2",offset:0}])}),cross:Object.freeze({preset:_1,label:"Song trảm chữ thập",color:"#f43f5e",core:"#fff5f7",duration:.65,hitstop:.14,impactFrame:"impact-crimson",sfx:Object.freeze([{id:"sp-slice-1",offset:-.04},{id:"sp-slice-1",offset:.05},{id:"sp-sub-hit-1",offset:.08}])}),clash:Object.freeze({preset:sd,label:"Tia lửa giao kiếm",color:"#ffb02e",core:"#ffffff",duration:.75,hitstop:.12,impactFrame:"impact-bw",sfx:Object.freeze([{id:"sp-impact-1",offset:0},{id:"sp-sub-hit-1",offset:.02}])}),heavy:Object.freeze({preset:id,extraPreset:sd,label:"Trọng kích kiếm khí",color:"#ff6b1a",core:"#fff7d6",duration:.75,hitstop:.18,impactFrame:"impact-crimson",sfx:Object.freeze([{id:"sp-slice-1",offset:-.04},{id:"sp-impact-1",offset:0},{id:"sp-sub-hit-1",offset:.02}])})}),_3=Object.freeze(Object.keys(ld));function Xf({id:t,presetId:e,label:o,at:r,u:a=.5,v:n=.5,color:i,core:c,angle:u,arc:p,flip:s,spread:h,width:f,size:m=1,sparks:g,seed:v,duration:x}){const E=Cn.find(k=>k.id===e);if(!E)throw Error(`Unknown combat preset ${e}`);const $=To(Zr(x,[.2,2.5],E.duration)),S={...E.params,x:To(Zr(a,[-.2,1.2],.5)),y:To(Zr(n,[-.2,1.2],.5)),color:Nc.test(i??"")?i:E.params.color,core:Nc.test(c??"")?c:E.params.core,size:To(Zr(m,[.3,3],1)),...Number.isFinite(f)&&"width"in E.params?{width:To(Zr(f,[.3,3],1))}:{},...Number.isFinite(u)&&"angle"in E.params?{angle:Math.round(u)}:{},...Number.isFinite(p)&&"arc"in E.params?{arc:Math.round(Zr(p,[40,280],155))}:{},...s!==void 0&&"flip"in E.params?{flip:!!s}:{},...Number.isFinite(h)&&"spread"in E.params?{spread:Math.round(Zr(h,[25,140],78))}:{},...g!==void 0&&"sparks"in E.params?{sparks:typeof E.params.sparks=="boolean"?!!g:Math.round(Zr(Number(g),[0,80],E.params.sparks))}:{},...Number.isFinite(v)&&"seed"in E.params?{seed:Math.max(1,Math.round(v))}:{}};return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:To(Math.max(0,r)),duration:$,label:o||E.name,motionV:2,posX:0,posY:0,scale:1,opacity:1,motion:Qe({code:`@preset:${e}`,params:S,preset:e,kind:"three"})}}function V3(t,e,o=Ax.fps){if(!Array.isArray(t)||t.length<2)throw Error("weaponTrail path needs at least 2 [u, v] points");const r=t.map(c=>{if(!Array.isArray(c)||c.length<2||!Number.isFinite(Number(c[0]))||!Number.isFinite(Number(c[1])))throw Error("weaponTrail path points must be [u, v] in 0..1");return[Math.max(0,Math.min(1,Number(c[0]))),Math.max(0,Math.min(1,Number(c[1])))]}),a=Math.max(6,Math.min(240,Math.round(e*o))),n=r.length-1,i=[];for(let c=0;c<=a;c++){const u=c/a,p=u*n,s=Math.min(n-1,Math.floor(p)),h=p-s,f=r[Math.max(0,s-1)],m=r[s],g=r[Math.min(n,s+1)],v=r[Math.min(n,s+2)],x=h*h,E=x*h,$=(y,C,A,z)=>.5*(2*C+(-y+A)*h+(2*y-5*C+4*A-z)*x+(-y+3*C-3*A+z)*E),S=Math.max(0,Math.min(1,$(f[0],m[0],g[0],v[0]))),k=Math.max(0,Math.min(1,$(f[1],m[1],g[1],v[1])));i.push([To(u*e),To(S),To(k)])}return i}function G3({id:t,at:e,duration:o,color:r,core:a,width:n,length:i,sparks:c,source:u,point:p,path:s}){const h=Cn.find(E=>E.id===zi),f=To(Zr(o,[.15,20],1.5)),m={...h.params,color:Nc.test(r??"")?r:h.params.color,core:Nc.test(a??"")?a:h.params.core,width:To(Zr(n,[.3,3],1)),length:To(Zr(i,[.08,1.5],.35)),sparks:c!==!1};if(Array.isArray(s)&&s.length>=2){const E=Ix(V3(s,f));return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:To(Math.max(0,e)),duration:f,label:h.name,motionV:2,posX:0,posY:0,scale:1,opacity:1,motion:Qe({code:`@preset:${zi}`,params:{...m,...E},preset:zi,kind:"three"})}}const g=.03,v=p??[.5,.5],x={x:To(Math.max(0,Math.min(1-2*g,v[0]-g))),y:To(Math.max(0,Math.min(1-2*g,v[1]-g))),w:2*g,h:2*g};return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:To(Math.max(0,e)),duration:f,label:h.name,motionV:2,posX:0,posY:0,scale:1,opacity:0,motion:Qe({code:`@preset:${zi}`,params:m,preset:zi,kind:"three"}),pendingPin:{source:u,at:To(e),region:x,mode:"bolt",...p?{}:{person:!0}}}}const V1=15,K3=7.5,qp=1e-6,Es=t=>Math.round(t*30)/30;function Pj(t){const e=Number(t);if(!Number.isFinite(e)||e<1-qp||e>V1+qp)return null;const o=Math.max(1,Math.ceil(e/K3-qp)),r=e/o;return Array.from({length:o},(a,n)=>({k:n+1,n:o,from:Es(n*r),to:Es((n+1)*r),duration:Es(Es((n+1)*r)-Es(n*r))}))}const Zp=t=>String(+t.toFixed(2));function Lj(t,e,o,r=6e3){if(!e||e.n<=1)return String(t).slice(0,r);const a=`(Phần ${e.k}/${e.n}: chỉ dựng đoạn ${Zp(e.from)}–${Zp(e.to)} giây của cảnh ${Zp(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-a.length-1)}
2
+ ${a}`}const rl="(\\d+(?:[.,]\\d+)?)",G1="(s|secs?|seconds?|giây|giay|phút|phut|min|mins|minutes?)(?![\\p{L}\\p{N}])",W3=new RegExp(`${rl}\\s*(?:–|—|-|đến|tới|to)\\s*${rl}\\s*${G1}`,"giu"),H3=new RegExp(`(?:từ\\s+)?(?:giây|giay|second)\\s*${rl}\\s*(?:–|—|-|đến|tới|to)\\s*(?:giây|giay|second)?\\s*${rl}(?![\\p{L}\\p{N}])`,"giu"),X3=new RegExp(`${rl}\\s*${G1}`,"giu"),Ss=t=>Number(t.replace(",",".")),Jp=t=>/^(phút|phut|min)/i.test(t)?60:1;function Fj(t){let e=String(t||"").toLowerCase();const o=[];e=e.replace(W3,(c,u,p,s)=>(o.push([Ss(u)*Jp(s),Ss(p)*Jp(s)])," ")),e=e.replace(H3,(c,u,p)=>(o.push([Ss(u),Ss(p)])," "));const r=[...e.matchAll(X3)].map(c=>Ss(c[1])*Jp(c[2])).filter(c=>c>0),a=o.filter(([c,u])=>u>c),n=a.length?Math.max(...a.map(c=>c[1]))-Math.min(...a.map(c=>c[0])):0,i=Math.max(0,n,...r);return i>0?Math.round(i*100)/100:null}const U3=Object.freeze(["left","zoom","strips","up","glitch","right","zoom","down","strips","left","glitch","up"]),Y3={left:"whoosh-fast-swish",right:"whoosh-fast-swish",up:"whoosh-short-up",down:"whoosh-short-down",zoom:"zoom-whoosh",strips:"whoosh-double",glitch:"glitch"},q3=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"]),Z3=["cyber-slab-wipe","cyber-pixel-dissolve"],K1={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"]},Uf=["rect","circle","diamond","bars"],J3=Object.freeze(["letters","solid","outline","streak","echo","solid","reflect","chrome","glitch","outline"]),Q3=["chrome","echo","glitch"],t5=["reflect","streak"],Rc=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],e5=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=>Rc(t)||"",when:t=>(Rc(t)||"").length>=5}]);function o5(t,e=!0){const o=e?9:16,r=e?16:9,a=Math.min(o,r),n=o-2*o*(e?.075:.07),i=Math.min(n,a*(e?.86:.62)),c=i*.56,u=o/2-i/2,p=r*(e?.6:.56),s={icon:[o/2,p+c*.45],photo:[o/2,p+c*.42],player:[o/2,p+c*.45],chat:[u+i*.92,p+c*.48],cube:[o/2,p+c*.5],nodes:[u+i*.18,p+c*.35],timeline:[u+i*.6,p+c*.55],chart:[u+i*.82,p+c*.3],render:[u+i*.9,p+c*.6],logo:[o/2,p+c*.35]}[t]||[o/2,r/2];return[+(s[0]/o).toFixed(3),+(s[1]/r).toFixed(3)]}const r5=[["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/]],n5=[[/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"]]],W1=t=>[...new Set(n5.filter(([e])=>e.test(t)).flatMap(([,e])=>e))],a5=[[/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/]],H1=t=>r5.find(([,e])=>e.test(t))?.[0]??null,Yf=t=>String(t).toLowerCase().normalize("NFC").split(/[^\p{L}\p{N}]+/u).filter(e=>e.length>=3),X1=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 i5(t,{industries:e=[],dark:o=!0,used:r=new Set,pack:a=null,accent:n="#e8141c"}={}){const i=H1(t);if(!i)return null;const c=Yf(t),u=i==="number"?"numberValue":i==="list"?"items":null,p=uc().filter(S=>S.role==="overlay"&&!S.pack.startsWith("kinetic")&&!S.id.startsWith("kin-")&&S.beats.includes(i)&&S.zone!=="top"&&S.fields.includes("text")&&(!u||S.fields.includes(u))&&(S.tone==="any"||S.tone==="dark"===o)&&!r.has(S.id));if(!p.length)return null;const s=a5.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===a?2:0)+Yf(h(S)).filter(k=>c.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),g=p.map(S=>({t:S,s:m(S)})).sort((S,k)=>k.s-S.s||S.t.id.localeCompare(k.t.id))[0].t,v=String(t).replace(/[.!?…]+$/,"").trim(),x=X1(v),E={color:n,placement:"lower",text:(i==="number"&&x!=null?v.replace(/\d[\d.,]*\s*%?/,"").replace(/\s+/g," ").trim():v).slice(0,28)||v.slice(0,28)};if(x!=null&&g.fields.includes("numberValue")&&(E.numberValue=x),g.fields.includes("items")){const S=v.split(/,| và | and /).map(k=>k.trim()).filter(Boolean);E.items=(S.length>=2?S:v.split(" ").reduce((k,y,C)=>{const A=Math.floor(C/2);return k[A]=k[A]?k[A]+" "+y:y,k},[])).slice(0,4)}const $=Zi(v);$&&g.fields.includes("icon")&&(E.icon=$);try{const S=Za(g.id,E);return{preset:g.id,pack:g.pack,params:S.params,library:!0}}catch{return null}}function s5(t,e=!0){const o=Zi(t);if(!o)return null;const r=hw[o];return{el:"icon",preset:"kin-el2",label:(e?r.name:r.en||r.name)||"",glyph:o}}function l5(t,{vi:e=!0,prev:o=null,last:r=!1}={}){if(r&&Rc(t)&&o!=="logo")return{el:"logo",preset:"kin-el2",label:Rc(t)};for(const a of e5)if(a.re.test(t)&&(!a.when||a.when(t))&&a.el!==o){const n=a.label(t,e);if(n)return{el:a.el,preset:a.preset,label:n}}return null}const Dc=/[.!?…:;,]$/,U1=/[.!?…]$/,c5=[[.91,.1],[.09,.9],[.91,.9],[.09,.1]],Qa=Object.freeze({words:300,beatMin:.28,lineChars:{portrait:14,landscape:22},maxBeatWords:3}),p5=t=>String(t||"").split(/\s+/).filter(Boolean).length,Y1=t=>`Vượt giới hạn ${Qa.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 u5(t,e=0,{rate:o=2.6}={}){const r=[];let a=e;const n=p5(t);if(n>Qa.words)throw Error(Y1(n));for(const i of String(t||"").split(/\s+/).filter(Boolean)){const c=Math.max(.24,Math.min(.7,(.18+i.length*.035)*2.6/o));r.push({word:i,start:+a.toFixed(3),end:+(a+c).toFixed(3)}),a+=c+(U1.test(i)?.35:Dc.test(i)?.15:0)}return r}const qf=t=>/[!?]$/.test(t)||/\d/.test(t)||t.length>2&&t===t.toUpperCase()&&/[A-ZÀ-Ỹ]/.test(t);function d5(t,{portrait:e=!0,dense:o=!1,wide:r=!1}={}){const a=(t||[]).filter(u=>u&&typeof u.word=="string"&&u.word.trim()&&Number.isFinite(u.start)).slice(0,Qa.words).map(u=>({word:u.word.trim(),start:u.start,end:Number.isFinite(u.end)?u.end:u.start+.3})),n=Qa.lineChars[e?"portrait":"landscape"]+(r?22:o?8:0),i=[];let c=null;return a.forEach((u,p)=>{const s=a[p-1],h=s?u.start-s.end:0,f=c?c.words.join(" ").length+1+u.word.length:0;(!c||Dc.test(s?.word??"")||h>=.45||f>n+(Dc.test(u.word)?10:0))&&(c={words:[],beats:[]},i.push(c));const m=c.beats.at(-1),g=c.words.length;c.words.push(u.word);const v=qf(u.word)||m&&qf(c.words[g-1]);m&&(u.start-m.start<Qa.beatMin||!v&&u.word.length<=3&&m.k<Qa.maxBeatWords)?(m.k++,m.n++,m.end=u.end):c.beats.push({n:g+1,k:1,start:u.start,end:u.end})}),i.map(u=>({text:u.words.join(" "),beats:u.beats}))}const ni=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"]}}),Nj=Object.keys(ni),h5=/ướ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,f5={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]},m5={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 g5(t,{industries:e=[],tone:o=null}={}){const r={};for(const a of Object.keys(ni))r[a]=0;for(const[a,[n,i]]of Object.entries(f5))r[a]+=Math.min(3,(String(t).match(n)||[]).length)*i;for(const[a,n]of Object.entries(m5))n.some(i=>e.includes(i))&&(r[a]+=n[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 y5(t,e={}){const o=g5(t,e),r=Math.max(...Object.values(o)),a=Object.keys(o).filter(n=>o[n]>=r-.5&&o[n]>0);return a[(e.seed??1)%a.length]||"motion"}const Bc=[[/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"]],Zf=[[/đ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"]],b5=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",w5={l:"r",r:"l",t:"b",b:"t",c:"c"},Jf=["r","t","l","b","r"],cd=["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"],q1=["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"],Qf="lumen-white-flash",k5=["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"],x5=[[/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"]],M5=["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"],v5=["dot","ring","line","star","pill","diamond","square","bar","cross","heart"],$5=["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"],E5=[[/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"]],S5=new Set(["promo-prompt-bar","promo-icon-cloud","promo-dome-horizon","promo-cta-button","promo-aurora-card","promo-flare-card"]),I5=["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"],A5=[[/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"]],C5=[[/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 j5(t,e,{accent:o,seed:r,tail:a,known:n}){const i=[];let c=null;for(const C of t)(!c||c.end-c.start>=e.min)&&(c={lines:[],start:C.beats[0].start,end:0},i.push(c)),c.lines.push(C),c.end=C.beats.at(-1).end;if(i.length>1&&i.at(-1).end-i.at(-1).start<e.min*.6){const C=i.pop();i.at(-1).lines.push(...C.lines),i.at(-1).end=C.end}if(["lumen","rebound","fluid"].includes(e.pack)&&i.length>1&&i.at(-1).lines.length>1){const C=i.at(-1),A=C.lines.pop();C.end=C.lines.at(-1).beats.at(-1).end,i.push({lines:[A],start:A.beats[0].start,end:A.beats.at(-1).end})}const u=[],p=[],s=[],h=C=>!n||n(C),f=new Set,m=t.map(C=>C.text).join(" "),g=b5(m),v=t.find(C=>/\?$/.test(C.text)&&C.text.length<=40)?.text??"...";let x=null,E=r,$="l";const S=["dot"],k=(e.pack==="cine"?Bc.map(C=>C[1]):e.pack==="story"?Zf.map(C=>C[1]):e.pack==="lumen"?q1:e.pack==="rebound"?k5:e.pack==="fluid"?I5:e.pack==="promo"?$5:e.pack==="morph"?M5:cd).filter(h);if(!k.length)throw Error(`Poox 1.1: the ${e.pack} scenes are not installed`);i.forEach((C,A)=>{const z=C.lines.map(pt=>pt.text).join(" "),j=e.pack==="cine"?Bc:e.pack==="story"?Zf:e.pack==="lumen"?C5:e.pack==="rebound"?x5:e.pack==="fluid"?A5:e.pack==="promo"?E5:null;let P=j?j.find(([pt,yt])=>pt.test(z)&&yt!==x&&!f.has(yt)&&h(yt))?.[1]:null;!P&&["story","lumen","rebound","fluid","promo","morph"].includes(e.pack)&&(P=k.find(pt=>!f.has(pt)&&pt!==x));const F=e.pack==="fluid"?"fluid-melt-word":e.pack+"-neon-word",N=["lumen","rebound","fluid"].includes(e.pack)&&A===i.length-1&&A>0&&h(F);N&&(P=F),e.pack==="promo"&&A===0&&h("promo-flare-card")&&(P="promo-flare-card"),e.pack==="morph"&&A===i.length-1&&A>0&&h("morph-logo-wings")&&(P="morph-logo-wings");for(let pt=0;!P&&pt<k.length*2;pt++){const yt=k[E++%k.length];yt!==x&&(P=yt)}P=P??k[0],x=P,N||f.add(P),f.size>=k.length&&f.clear();const G=e.pack==="promo"&&S5.has(P)&&(P==="promo-cta-button"?C.lines.at(-1).text.length<=24:C.lines.every(pt=>pt.text.length<=40)),V=e.pack==="story"||e.pack==="rebound",et=V?.7:0,U=A?C.start-et:Math.max(0,C.start-.15),at=A<i.length-1?i[A+1].start:C.end+a,W=e.colors[A%e.colors.length],_=A<i.length-1?e.colors[(A+1)%e.colors.length]:e.colors[0],J=Jf[A%Jf.length],tt=(A?"i":"")+(A<i.length-1?"o":""),rt=e.pack==="morph"?(()=>{const pt=S.at(-1),yt=v5.filter(l=>!S.slice(-2).includes(l)),Mt=yt[(A*3+r)%yt.length];return S.push(Mt),{formIn:pt,formOut:Mt}})():{},D=e.pack==="story"?{hero:g,heroIn:$,heroOut:J,pan:tt}:e.pack==="rebound"?{ballIn:A?$:"c",ballOut:J,pan:tt}:e.pack==="pulse"?{ballIn:$}:{};$=w5[J],u.push({start:ut(U),duration:ut(Math.max(.6,at-U)),line:A,preset:P,params:{bg:W,next:_,fg:o,text:N?C.lines.at(-1).text.slice(0,60):G?P==="promo-cta-button"?C.lines.at(-1).text.slice(0,24):C.lines.map(pt=>pt.text).join(P==="promo-prompt-bar"?"|":" ").slice(0,80):"",...D,...rt,...P==="story-phone-message"?{msg:v}:{}}});const q=V?[]:(K1[e.pack==="cine"?"cinematic":e.pack]||[]).filter(h);A&&A%2===1&&q.length&&!(e.pack==="lumen"&&A%3===2)&&p.push({start:ut(Math.max(0,U-.45)),duration:ut(.9),preset:q[(A>>1)%q.length],params:{fg2:e.colors[A%e.colors.length]}}),e.pack==="rebound"&&A%4===3&&h("rebound-gradient-flash")&&p.push({start:ut(Math.max(0,U+et-.35)),duration:ut(.7),preset:"rebound-gradient-flash",params:{bg:W,next:W,fg:o}}),e.pack==="lumen"&&A%3===2&&h(Qf)&&p.push({start:ut(Math.max(0,U-.3)),duration:ut(.6),preset:Qf,params:{bg:W,next:W,fg:o}}),(!N&&!G?C.lines:G&&P==="promo-cta-button"?C.lines.slice(0,-1):[]).forEach((pt,yt)=>{const Mt=Math.max(U+et+.25,pt.beats[0].start-.05),l=yt<C.lines.length-1?C.lines[yt+1].beats[0].start:at-.35;l-Mt>.3&&p.push({start:ut(Mt),duration:ut(l-Mt),preset:e.caption,params:{text:pt.text.slice(0,120),position:"lower"}})}),A&&s.push({at:ut(Math.max(0,U+et-.3)),id:e.pack==="pulse"||e.pack==="rebound"?"whoosh-short-up":"whoosh-airy"})});const y={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 y&&i.length>2&&y.forEach(([C,A,z])=>{const j=i[A];if(j&&h(C)&&A<i.length-1){const P=j.start+.4,F=i[A+1].start-.4;F-P>.8&&p.push({start:ut(P),duration:ut(F-P),preset:C,params:{position:z,fg:o}})}}),{beats:u,els:p,sfx:s}}const Z1=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))),J1=(t,e)=>t.map(o=>Math.max(0,o-e).toFixed(2)).join(",").slice(0,300),T5=/[ăâđêôơưàáạảãằắặẳẵầấậẩẫèéẹẻẽềếệểễìíịỉĩòóọỏõồốộổỗờớợởỡùúụủũừứựửữỳýỵỷỹ]/i,dc=t=>t.replace(/[.,;:…]+$/,""),O5=["glass-orb-rise","glass-balance","glass-coin-bars","glass-step-chart","glass-line-target","glass-candles","glass-progress","glass-emblem"],z5=[[/%|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"]],tm=new Set(["glass-balance","glass-progress","glass-emblem"]);function P5(t,e,{accent:o,tail:r,known:a}){const n=E=>!a||a(E),i=[];let c=null;for(const E of t){const $=c?c.end-c.start:0;(!c||$>=e.min&&Dc.test(c.lines.at(-1).text)||$>=e.min*2.5)&&(c={lines:[],start:E.beats[0].start,end:0},i.push(c)),c.lines.push(E),c.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 u=O5.filter(n);if(!u.length)throw Error("Poox 1.1: the glass scenes are not installed");const p=[],s=[],h=[],f=new Set,m=e.colors[0],g=T5.test(t.map(E=>E.text).join(" "));let v=null,x=0;return i.forEach((E,$)=>{const S=E.lines.map(j=>j.text).join(" "),k=X1(S);let y=z5.find(([j,P])=>j.test(S)&&P!==v&&!f.has(P)&&n(P)&&(!tm.has(P)||k!=null||P==="glass-balance"))?.[1];for(let j=0;!y&&j<u.length*2;j++){const P=u[x++%u.length];P!==v&&!f.has(P)&&(y=P)}y=y??u.find(j=>j!==v)??u[0],v=y,f.add(y),f.size>=u.length&&f.clear();const C=$?E.start-.1:Math.max(0,E.start-.15),A=$<i.length-1?i[$+1].start-.1:E.end+r,z=k!=null&&tm.has(y)?{number:y==="glass-progress"?Math.min(100,k):k,...y==="glass-balance"?{from:Math.round(k*.86)}:{}}:{};p.push({start:ut(C),duration:ut(Math.max(.3,ut(A)-ut(C))),line:$,preset:y,params:{bg:m,next:m,accent:o,text:"",sub:"",...z}}),E.lines.forEach((j,P)=>{const F=Math.max(C+.05,j.beats[0].start-.08),N=P<E.lines.length-1?E.lines[P+1].beats[0].start-.04:A-.02;if(N-F<=.3)return;const G=j.text.split(" ").filter(Boolean),V=G.length<2?G.length:G.length>=4&&(g||G.at(-1).length<=3)?2:1,et=Z1(j);s.push({start:ut(F),duration:ut(N-F),preset:e.caption,params:{text:G.slice(0,G.length-V).join(" ").slice(0,80),sub:dc(G.slice(G.length-V).join(" ")).slice(0,40),marks:J1(et,F),panel:($+P)%3===2,position:"top",accent:o}})}),$&&h.push({at:ut(Math.max(0,C-.15)),id:"whoosh-airy"})}),{beats:p,els:s,sfx:h}}function L5(t,e,{accent:o,tail:r}){const a=[];let n=null;for(const p of t)(!n||n.lines.length>=3||U1.test(n.lines.at(-1).text))&&(n={lines:[]},a.push(n)),n.lines.push(p);const i=[],c=[],u=e.palette.dark;return a.forEach((p,s)=>{const h=p.lines[0].beats[0].start,f=s?h-.08:Math.max(0,h-.12),m=a[s+1],g=m?m.lines[0].beats[0].start-.08:p.lines.at(-1).beats.at(-1).end+r,v=p.lines.map((E,$)=>{const S=E.text.split(" ").filter(Boolean),k=p.lines.length===1;let y=new Set(S.map((C,A)=>/\d/.test(C)?A:-1).filter(C=>C>=0));if(!y.size&&($%2===1||k)){const C=k?S.length-1:S.reduce((A,z,j)=>dc(z).length>dc(S[A]).length?j:A,0);y.add(C),!k&&S.length>=3&&C+1<S.length&&dc(S[C+1]).length>=4&&y.add(C+1)}return S.map((C,A)=>y.has(A)?`*${C}*`:C).join(" ").replace(/\* \*/g," ")}),x=p.lines.flatMap(Z1);i.push({start:ut(f),duration:ut(Math.max(.3,ut(g)-ut(f))),line:s,preset:e.caption,params:{text:v.join("|").slice(0,240),marks:J1(x,f),bg:u,accent:o,position:"center"}}),s&&c.push({at:ut(Math.max(0,f-.1)),id:"whoosh-short-up"})}),{beats:i,els:[],sfx:c}}function F5(t,{palette:e={},io:o=.16,portrait:r=!0,seed:a=1,tail:n=.7,orb:i=!0,industry:c=null,genre:u="punch",known:p=null}={}){const s=ni[u]||ni.punch;if(s.palette&&(e={...s.palette,...e.accent&&!["luxury","neon","glass"].includes(u)?{accent:e.accent}:{}}),s.orb===!1&&(i=!1),(t||[]).length>Qa.words)throw Error(Y1(t.length));const h=(t||[]).length>120,f=d5(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"?P5:L5)(f,s,{accent:e.accent,tail:n,known:p}),orbs:[],texture:[],carriers:[],lines:f.length,genre:u};if(s.kind==="scenes")return{...j5(f,s,{accent:e.accent||s.colors[1],seed:a,tail:n,known:p}),orbs:[],texture:[],carriers:[],lines:f.length,genre:u};const m=e.dark||"#0b0b0d",g=e.light||"#f4f4f1",v=e.accent||"#e8141c",x=I=>{const O=parseInt(I.slice(1),16),L=O>>16&255,B=O>>8&255,H=O&255;return L*.299+B*.587+H*.114>150?"#111111":"#ffffff"};let E=null;const $=f.map((I,O)=>{let B=(/[!?]$/.test(I.text)||/\d/.test(I.text))&&E!==v?v:(O+a)%2?g:m;return B===E&&(B=B===m?g:m),E=B,B}),S=[],k=[],y=f.flatMap((I,O)=>I.beats.map((L,B)=>({...L,li:O,bi:B,line:I}))),C=/[ăâđêôơưàáạảãằắặẳẵầấậẩẫèéẹẻẽềếệểễìíịỉĩòóọỏõồốộổỗờớợởỡùúụủũừứựửữỳýỵỷỹ]/i.test(f.map(I=>I.text).join(" "));let A=null;const z=f.map(I=>I.text).join(" "),j=C1(z),P=[...new Set([...j.industries,...W1(z),...c&&c!=="general"?[c]:[]])],F=new Set;let N=null;const G=[],V=f.map((I,O)=>{const L=(I.beats.at(-1).end??I.beats.at(-1).start)-I.beats[0].start;if(L<.8)return A=null,null;let B=l5(I.text,{vi:C,prev:A,last:I===f.at(-1)});if(B?.el==="chart"&&(B=null),!B&&A!=="photo"){const H=e3(I.text,{exclude:G});H&&(G.push(H.id),B={el:"photo",preset:"kin-el2",label:C?H.vi:H.en,photo:H.id,glyph:Zi(I.text)||"sparkle"})}if(!B&&L>=.8&&A!=="library"){const H=ot=>i5(I.text,{industries:P,dark:ot,used:F,pack:N,accent:$[O]===v?"#ffffff":v});let Z=H($[O]!==g);if($[O]===g){const ot=H(!0);ot&&(!Z||P.some(st=>uc().find(Y=>Y.id===ot.preset)?.industries.includes(st))&&!P.some(st=>uc().find(Y=>Y.id===Z.preset)?.industries.includes(st)))&&(Z=ot,$[O]=m)}Z&&(F.add(Z.preset),N=N??Z.pack,B={el:"library",...Z})}if(!B&&H1(I.text)==="number"&&A!=="chart"&&(B={el:"chart",preset:"kin-el2",label:C?"Kết quả":"Results"}),!B){const H=s5(I.text,C);H&&H.glyph!==A&&(B=H)}return A=B?.el==="icon"?B.glyph:B?.el??null,B}),et=f.map(()=>null);if(s.interlude&&p){const I=h5.test(z),O=P.some(B=>["ai","tech","gaming","saas","data"].includes(B));let L=0;f.forEach((B,H)=>{const Z=(B.beats.at(-1).end??B.beats.at(-1).start)-B.beats[0].start;if(!(H>0&&H<f.length-1&&H%3===2&&Z>=1&&!et[H-1]))return;const ot=I?"cine":O?L%2?"lumen":"pulse":["pulse","cine","lumen"][L%3];let st=(ot==="pulse"?cd:ot==="lumen"?q1:Bc.map(mt=>mt[1])).filter(mt=>p(mt));if(st.length||(st=cd.filter(mt=>p(mt))),!st.length)return;const Y=ot==="cine"?Bc.find(([mt,Q])=>mt.test(B.text)&&p(Q))?.[1]:null,ct=Y??st[(L*5+a)%st.length];et[H]={preset:ct,caption:ct.startsWith("cine-")?"cine-caption":ct.startsWith("lumen-")&&p("lumen-caption")?"lumen-caption":"pulse-word"},V[H]=null,L++})}let U=null;const at=f.map((I,O)=>{const L=/[!?]$/.test(I.text)||/\d/.test(I.text);let B=(s.looks||J3).filter(Z=>Z!==U&&($[O]!==g||!t5.includes(Z)));L&&(B=B.filter(Z=>Q3.includes(Z)));const H=B[(O+a)%B.length];return U=H,H}),W=s.joins||U3,_=I=>W[(I-1+a)%W.length],J=(I,O)=>`${O.n}|${O.k}|${V[I]?1:0}|${f[I].text}`;let tt=!1,rt=0,D=0,q=0;const pt=P.some(I=>["ai","tech","gaming","saas","data"].includes(I)),yt=f.map((I,O)=>{if(!O)return null;if(et[O]||et[O-1])return tt=!0,{mode:"scene"};const L=f[O-1],B=J(O-1,L.beats.at(-1)),H=J(O,I.beats[0]),Z=/[!?]$/.test(L.text),ot=(K1[u]||[]).filter(Q=>!p||p(Q)),st=[...q3,...pt?Z3:[],...ot,...ot],Y=()=>({mode:"lib",preset:st[(rt+++a)%st.length]}),ct=V[O]&&!V[O].library?{mode:"cover",a:`word:${B}`,b:"panel"}:V[O-1]&&!V[O-1].library?{mode:"cover",a:`dot:${V[O-1].el}`,b:`word:${H}`}:Z?{mode:"cover",a:`letter:${B}`,b:`word:${H}`}:null;let mt=null;if(V[O]?.library||V[O-1]?.library)mt=q++%2?Y():{mode:"cover",a:`word:${B}`,b:V[O]?.library?"none":`word:${H}`};else{const Q=["carrier","push","lib","line"][D++%4];tt?mt=!h&&(Q==="line"||Q==="carrier")?{mode:"line",a:`word:${B}`,b:`word:${H}`}:null:Q==="carrier"?mt=ct??Y():Q==="lib"?mt=Y():Q==="line"&&!h&&(mt={mode:"line",a:`word:${B}`,b:`word:${H}`})}return tt=mt?.mode==="cover"||mt?.mode==="lib",mt}),Mt=I=>["cover","lib","scene"].includes(yt[I]?.mode);y.forEach((I,O)=>{if(et[I.li])return;const L=y[O+1],B=I.bi===0,H=O===0?"zoom":B?Mt(I.li)?"cut":_(I.li):"build",Z=L?L.bi===0?Mt(L.li)?"cut":_(L.li):"cut":"zoom",ot=O===0?Math.max(0,I.start-.12):B&&!Mt(I.li)?I.start-o/2:I.start,st=L?L.bi===0&&!Mt(L.li)?L.start+o/2:L.start:I.end+n,Y=$[I.li],ct=at[I.li];S.push({start:ut(ot),duration:ut(Math.max(.1,st-ot)),line:I.li,params:{...s.style?{style:s.style}:{},text:I.line.text,n:I.n,k:I.k,bg:Y+":"+(Y===g?"dust":Y===v?"glow":I.li%2?"dots":"glow")+(V[I.li]?":top":""),look:ct,color:x(Y),accent:Y===v?x(Y)==="#ffffff"?"#111111":"#ffffff":v,in:H,out:Z,io:o,hit:B}}),B&&O>0&&(Mt(I.li)||!h&&I.li%2===0)?k.push({at:ut(Math.max(0,I.start-(Mt(I.li)?.3:o/2+.04))),id:Mt(I.li)?"whoosh-cinematic":Y3[H]||"swoosh"}):B&&O===0&&k.push({at:ut(Math.max(0,ot)),id:"impact"})});{const I=[];for(const O of S){const L=I.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=ut(O.start+O.duration-L.start),L.params.out=O.params.out):I.push({...O,params:{...O.params},marks:[[0,O.params.n,O.params.k]]})}S.length=0;for(const O of I){const{marks:L,...B}=O;S.push({...B,params:{...B.params,n:L.length>1?L.map(H=>H.join(":")).join("|").slice(0,300):L[0][1],k:L[0][2]}})}}const l=[];f.forEach((I,O)=>{const L=et[O];if(!L)return;const B=I.beats[0].start,H=f[O+1]?.beats[0].start??I.beats.at(-1).end+n;S.push({start:ut(B),duration:ut(H-B),line:O,preset:L.preset,params:{bg:$[O-1]??m,next:$[O+1]??m,fg:v,text:""}}),H-B>.8&&l.push({start:ut(B+.25),duration:ut(H-B-.55),preset:L.caption,params:{text:I.text.slice(0,120),position:"lower"}}),k.push({at:ut(Math.max(0,B-.05)),id:"whoosh-cinematic"})});const lt=[];if(i&&S.length){const I=S[0].start,O=S.at(-1).start+S.at(-1).duration,L=(H,Z)=>V[H]&&!V[H].library?[...o5(V[H].el,r),0]:[...c5[Z%4],-1],B=f.map((H,Z)=>({li:Z,at:H.beats[0].start+(Z?.3:0)})).filter(H=>H.li);for(let H=I;H<O-.05;H+=19){const Z=Math.min(O,H+19),ot=[...f.keys()].filter(Y=>f[Y].beats[0].start<=H+.2).at(-1)??0,st=[[0,...L(ot,lt.length*3)]];B.filter(Y=>Y.at>H+.2&&Y.at<Z-.05).forEach((Y,ct)=>st.push([+(Y.at-H).toFixed(2),...L(Y.li,lt.length*3+ct+1)])),lt.push({start:ut(H),duration:ut(Z-H),params:{pts:st.slice(0,20).map(Y=>Y.map(ct=>+(+ct).toFixed(2)).join(",")).join("|"),accent:v}})}}const K=[...l];f.forEach((I,O)=>{const L=V[O];if(!L)return;const B=S.filter(ot=>ot.line===O),H=B[0],Z=B.at(-1);if(H){if(L.library){K.push({start:H.start,duration:ut(Z.start+Z.duration-H.start),preset:L.preset,params:L.params,library:!0});return}K.push({start:H.start,duration:ut(Z.start+Z.duration-H.start),preset:L.preset,params:{el:L.el,label:L.label,...L.glyph?{glyph:L.glyph}:{},...L.photo?{photo:L.photo}:{},in:H.params.in,out:Z.params.out,io:o,dark:H.params.color==="#ffffff",accent:H.params.accent}})}});const d=[];let w=0;yt.forEach((I,O)=>{if(!I||I.mode==="scene")return;const L=f[O].beats[0].start,B=S.filter(ot=>ot.line===O-1).at(-1)?.params.accent??v;if(I.mode==="lib"){const ot=Math.min(.9,(uc().find(Y=>Y.id===I.preset)?.dur??1)*.8);let st={};try{st=Za(I.preset,{color:v}).params}catch{}d.push({start:ut(Math.max(0,L-ot/2)),duration:ut(ot),preset:I.preset,params:st});return}const H=I.mode==="cover"?L-.24:L-o/2-.1,Z=I.mode==="cover"?.46:o+.45;d.push({start:ut(Math.max(0,H)),duration:ut(Z),preset:"kin-carry",params:{mode:I.mode,a:I.a.slice(0,290),b:I.b.slice(0,290),fill:B,...I.mode==="cover"?{shape:Uf[w++%Uf.length]}:{}}})});const T=[];if(S.length){const I=S[0].start,O=S.at(-1).start+S.at(-1).duration;for(let L=I;L<O-.05;L+=19)T.push({start:ut(L),duration:ut(Math.min(O,L+19)-L),params:{amount:.5}})}return{beats:S,orbs:lt,sfx:k,texture:T,els:K,carriers:d,lines:f.length,genre:u}}const N5={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"},R5=[{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"]}],D5={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"},B5=[{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}],_5={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"},V5=[{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}],em={"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},nl={"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"},om={"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},G5=[{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}],Rj={..._5,...N5,...D5},K5=t=>t.id in em?{...t,duration:em[t.id],stereo:!0}:t,W5=t=>t.id in om?{...t,duration:om[t.id],stereo:!0,suno:!0}:t,pd=[...R5,...B5].map(K5).concat(V5.map(t=>({...t,stereo:!0}))).map(W5).concat(G5.map(t=>({...t,stereo:!0}))).filter(t=>!(t.id in nl)),Q1=.35,H5=.6,X5=1.5;pd.map(t=>t.id);const vn=t=>pd.find(e=>e.id===t)??(typeof t=="string"&&Object.hasOwn(nl,t)?pd.find(e=>e.id===nl[t]):void 0),U5=[7,6,2],Y5=t=>typeof t=="string"&&Object.hasOwn(nl,t)?nl[t]:null,q5=t=>{const e=typeof t=="string"&&/^\/sfx\/([a-z0-9-]+)\.mp3$/.exec(t);if(!e)return null;const o=Y5(e[1])||e[1];return vn(o)?o:null};function Z5(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 J5(t,e,o,r,a=null){const n=c=>!e[c]?.locked&&!t.some(u=>u.track===c&&u.start<o+r-1e-6&&u.start+u.duration>o+1e-6);if(a!=null){if(!Ji.includes(a))throw Error("Sound effects go on an audio track");if(!n(a))throw Error("That audio track is locked or already has a clip there");return a}const i=U5.find(n);if(i===void 0)throw Error("No free audio track at that time — move or delete an overlapping clip");return i}function Q5(t,e,o,r,a={}){const{sfx:n,...i}=ha(t,e,o,r,a);return{...i,nodeId:`music:${o.id}`,label:`Nhạc · ${o.name}`,volume:Number.isFinite(a.volume)?i.volume:H5}}function ha(t,e,o,r,{volume:a,track:n,id:i}={}){const c=ut(r),u=ut(Math.max(1/ve,o.duration)),p=Number.isFinite(a)?Math.max(0,Math.min(1,a)):Q1;return{id:i,nodeId:`sfx:${o.id}`,track:J5(t,e,c,u,n),start:c,duration:u,inPoint:0,sourceDuration:o.duration,volume:p,url:o.url,kind:"audio",label:`SFX · ${o.name}`,sfx:o.id}}const t4={"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","inkline-title":"paper-slide","inkline-walker":"whoosh-airy","inkline-street":"swell-pad","inkline-cyclist":"whoosh-windy","inkline-boat":"whoosh-airy","inkline-birds":"whoosh-windy","inkline-lanterns":"sparkle","inkline-rain":"whoosh-airy","inkline-lower":"paper-slide","inkline-moon-cta":"sting-reveal","inkline-office":"swell-pad","inkline-cafe":"whoosh-airy","inkline-park":"whoosh-windy"},e4=t=>t4[t]??"pop";function Dj({clips:t=[],punches:e=[],existing:o=[]}={},{gap:r=X5,volume:a=Q1}={}){const n=[...t.filter(u=>u&&(u.motion||u.title)&&Number.isFinite(u.start)).map(u=>({at:u.start,sfxId:u.motion?.preset?e4(u.motion.preset):"pop"})),...e.filter(u=>Number.isFinite(u?.at)).map(u=>({at:u.at,sfxId:u.sfxId??"punch"}))].sort((u,p)=>u.at-p.at),i=o.filter(u=>u.sfx||q5(u.url)).map(u=>u.start),c=[];for(const u of n)!vn(u.sfxId)||i.some(p=>Math.abs(p-u.at)<r)||(i.push(u.at),c.push({op:"addSfx",sfxId:u.sfxId,at:+u.at.toFixed(3),volume:a}));return c}const ty=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},chest:{s:1.6,x:0,y:2.4,z:0,ry:0,rx:0,f:.35}}),o4=2.6,ud=Object.freeze(Object.keys(ty)),ey=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"}]},eyes:{name:"Mắt phát sáng",en:"Glowing eyes",layers:[{preset:"fh-eyes-glow",place:"scan"}]},rune:{name:"Phù văn trán",en:"Forehead rune",layers:[{preset:"fh-forehead-rune",place:"scan"}]},veins:{name:"Gân năng lượng mặt",en:"Face energy veins",layers:[{preset:"fh-energy-veins",place:"scan"}]},awakening:{name:"Thức tỉnh nội lực",en:"Power awakening",layers:[{preset:"fh-eyes-glow",place:"scan"},{preset:"fh-forehead-rune",place:"scan"},{preset:"fh-energy-veins",place:"scan"}]},gag_eyeballs:{name:"Mắt lồi trên cuống",en:"Eyes on stalks",layers:[{preset:"fh-gag-eyeballs",place:"scan"}]},gag_heart:{name:"Tim đập ra khỏi ngực",en:"Heart pumping out",layers:[{preset:"fh-gag-heart",place:"chest"}]},gag_love:{name:"Mắt hình tim",en:"Heart eyes",layers:[{preset:"fh-gag-heart-eyes",place:"scan"},{preset:"fh-gag-heart",place:"chest"}]},gag_dizzy:{name:"Choáng, sao quay",en:"Dizzy stars",layers:[{preset:"fh-gag-stars",place:"ring"}]},gag_sweat:{name:"Toát mồ hôi",en:"Shock sweat",layers:[{preset:"fh-gag-sweat",place:"scan"}]},gag_fuming:{name:"Tức xì khói",en:"Fuming",layers:[{preset:"fh-gag-steam",place:"scan"},{preset:"fh-gag-anger",place:"scan"}]}}),r4=Object.freeze(Object.keys(ey)),rm=t=>+t.toFixed(3),nm=(t,[e,o])=>Math.max(e,Math.min(o,t));function Qp(t="front",e=16/9,o={}){const r=ty[t];if(!r)throw Error(`Face place must be one of ${ud.join(", ")}`);const a=nm(e,Rp.a),{short:n,...i}=r,c={...fw,...i,s:n?n*Math.max(1,a):Math.min(r.s,o4*a),a:rm(a)},u=p=>typeof p=="number"&&Number.isFinite(p);for(const[p,s]of[["s","s"],["x","x"],["y","y"],["z","z"],["ry","ry"],["rx","rx"],["r","r"],["follow","f"]])u(o[p])&&(c[s]=o[p]);o.mirror!==void 0&&o.mirror!==null&&(c.m=o.mirror===!0||o.mirror===1?1:0);for(const p of Object.keys(c))p in Rp&&p!=="m"&&(c[p]=rm(nm(c[p],Rp[p])));return c.m||delete c.m,c}const gi=t=>t?.face?.v===2&&!!t.face.mesh,am=.7,n4=1/30,a4=t=>t<.5?4*t*t*t:1-(-2*t+2)**3/2;function i4({at:t,dur:e}){const o=Math.max(Nh.dur[0]/(1-am),Number(e)||1.2),r=+(o*am).toFixed(3);return mw({at:+(Number(t)+r).toFixed(3),dur:+Math.max(Nh.dur[0],o-r).toFixed(3),lead:r})}function dd(t,e,o,r){return Ee(t,e).filter(a=>a.time+t.start<o-1e-6||a.time+t.start>r+1e-6)}function oy(t,e,o,r){const a=t.find(F=>F.id===e),n=a?.pin?.dive;if(!n?.lead||a.pin.scene)return t;const i=t.find(F=>F.id===a.pin.clip);if(!i)return t;const c=n.at-n.lead,u=n.at,p=n.at+n.dur;let s=i;for(const F of["x","y","zoom"])s={...s,...ge(s,F,dd(s,F,c,p))};const h={...a,pin:{...a.pin,dive:void 0}},f=F=>Qg(h,t.map(N=>N.id===i.id?s:N),F,o,r),m=f(u);if(!m||!m.every(F=>F.every(Number.isFinite)))return t;const g=F=>[(F[0][0]+F[1][0]+F[2][0]+F[3][0])/4,(F[0][1]+F[1][1]+F[2][1]+F[3][1])/4],[v,x]=g(m),E=Math.max(m[0][0],m[2][0]),$=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&&v-E>1&&k-x>1&&x-S>1))return t;const y=1.04*Math.max(o/2/(v-E),o/2/($-v),r/2/(x-S),r/2/(k-x)),C={x:[],y:[],zoom:[]},A=(F,N,G)=>{const V=F-i.start,[et,U]=g(G),at=1+(y-1)*N,W=Qt(s,"x",V),_=Qt(s,"y",V),J=Qt(s,"zoom",V),tt=[o/2+W*o,r/2+_*r],rt=[et+(o/2-et)*N,U+(r/2-U)*N],D=[rt[0]-(et-tt[0])*at,rt[1]-(U-tt[1])*at];C.x.push({time:+V.toFixed(4),value:+((D[0]-o/2)/o).toFixed(5)}),C.y.push({time:+V.toFixed(4),value:+((D[1]-r/2)/r).toFixed(5)}),C.zoom.push({time:+V.toFixed(4),value:+(J*at).toFixed(5)})},z=Math.max(2,Math.round(n.lead/n4));for(let F=0;F<=z;F++){const N=c+n.lead*F/z,G=f(N);G&&A(N,a4(F/z),G)}const j=f(p);j&&A(Math.min(p,i.start+i.duration),1,j);let P=s;for(const F of["x","y","zoom"])P={...P,...ge(P,F,[...dd(s,F,c,p),...C[F]].sort((N,G)=>N.time-G.time))};return t.map(F=>F.id===i.id?{...F,motionKeys:P.motionKeys,motionV:2,...P.posX!==void 0?{posX:P.posX}:{},...P.posY!==void 0?{posY:P.posY}:{},...P.scale!==void 0?{scale:P.scale}:{}}:F.id===a.id?{...F,pin:{...F.pin,dive:{...n,keys:!0}}}:F)}function s4(t,e){const o=t.find(c=>c.id===e),r=o?.pin?.dive??o?.pendingPin?.dive;if(!r)return t;const a=o.pin?.clip??o.pendingPin?.source,n=r.lead?t.find(c=>c.id===a):null;let i=n;if(n)for(const c of["x","y","zoom"])i={...i,...ge(i,c,dd(i,c,r.at-r.lead,r.at+r.dur))};return t.map(c=>{if(n&&c.id===n.id)return{...c,motionKeys:i.motionKeys,motionV:2};if(c.id!==o.id)return c;if(c.pin?.dive){const{dive:s,...h}=c.pin;return{...c,pin:h}}const{dive:u,...p}=c.pendingPin;return{...c,pendingPin:p}})}function Bj(t,e,o){let r=t;for(const a of t)a.pin?.dive?.lead&&!a.pin.dive.keys&&!a.pin.scene&&(r=oy(r,a.id,e,o));return r}const wh=t=>Math.max(1/30,Math.floor(t*30+1e-6)/30),im=t=>Math.round(t*1e3)/1e3;function Us(t,e){if(t.start+e.duration>Xn+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,t1(o),!an(t)&&!an(o))Object.assign(o,kw(t,o.duration));else{const r=a=>Math.max(0,Math.min(o.duration,Ja(o,ls(t,a))));t.captions&&(o.captions=t.captions.map(a=>({...a,start:r(a.start),end:r(a.end)})).filter(a=>a.end>a.start)),t.captionWords&&(o.captionWords=t.captionWords.map(a=>({...a,start:im(r(a.start)),end:im(r(a.end))})).filter(a=>a.end-a.start>=.005))}return t.motionKeys?.length&&(o.motionKeys=t.motionKeys.map(r=>({...r,time:r.time*o.duration/t.duration}))),o}const l4=t=>{if(["image","model"].includes(t.kind)&&!t.comp)throw Error("Invalid playback speed");if(qn(t))throw Error("Time remap replaces speed, speed ramp, reverse and freeze frame")};function hd(t,e){if(l4(t),!Number.isFinite(e)||e<Rh||e>Dh)throw Error(`Invalid playback speed (${Rh}–${Dh}×)`);const o=vp(t);return Us(t,{playbackRate:e,duration:an(t)?wh(o/e):ut(t.duration*(t.playbackRate||1)/e)})}function c4(t){if(!Array.isArray(t)||t.length<2||t.length>Bh)throw Error(`Speed ramp needs 2–${Bh} 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 p4(t,{preset:e,keys:o,hitAt:r,peak:a}={}){if(t.kind!=="video")throw Error("Speed ramp requires a video clip");if(qn(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 n=vp(t);if(e==="normal")return hd(t,1);if(e!=null&&!o?.length){if(!$c.includes(e))throw Error(`Unknown speed ramp preset (${$c.join(", ")})`);if(Number.isFinite(r)){const{duration:c,speedRamp:u}=yw(e,n,ls(t,r),a);return Us(t,{duration:c,speedRamp:u})}return Us(t,bw(e,n,a))}const i=c4(o);return i.every(c=>c.speed===i[0].speed)?hd(t,i[0].speed):(t1({kind:"video",speedRamp:i}),Us(t,{speedRamp:i,duration:wh(ww(n,i))}))}function sm(t,e,o,{peak:r}={}){if(t.kind!=="video")throw Error("Speed ramp requires a video clip");if(qn(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(!$c.includes(e))throw Error(`Unknown speed ramp preset (${$c.join(", ")})`);const a=wh(o),n=Number.isFinite(t.sourceDuration)?Math.max(.05,t.sourceDuration-(t.inPoint||0)):1/0,i=gw(e,a,n,r);return Us(t,{duration:a,speedRamp:i.speedRamp})}const u4=t=>+(+t).toFixed(4),Oa=(t,e)=>u4(Math.max(0,Math.min(t,t-e)));function d4(t){const e=t.duration,o={...xw(t)},r=n=>({...n,keys:n.keys.map(i=>({...i,t:Oa(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(n=>{const i=r(n);return delete i.in,delete i.out,n.out!==void 0&&(i.in=Oa(e,n.out)),n.in!==void 0&&(i.out=Oa(e,n.in)),i})}),Array.isArray(t.planar?.frames)&&(o.planar={...t.planar,frames:t.planar.frames.map(n=>[Oa(e,n[0]),...n.slice(1)]).reverse(),...t.planar.surface?{surface:{...t.planar.surface,t:Oa(e,t.planar.surface.t)}}:{}}),t.roto?.points&&(o.roto={...t.roto,points:t.roto.points.map(n=>[Oa(e,n[0]),n[1],n[2],n[3]]).reverse()});const a=ph(t.grade);return a.some(n=>n?.motion?.mode==="keys")&&(o.grade=uh(t.grade,a.map(n=>n?.motion?.mode==="keys"?{...n,motion:{...n.motion,keys:n.motion.keys.map(i=>[Oa(e,i[0]),...i.slice(1)]).reverse()}}:n))),o}const hc=t=>Math.round(t*30)/30;function lm(t,e,o,r={}){const a=t.find(u=>u.id===e);if(!a)throw Error("Clip not found");if(r[a.track]?.locked)throw Error("Track is locked");const n=hc(a.start+a.duration);if(t.some(u=>u.id!==e&&u.track===a.track&&u.start<n-1/60&&u.start+u.duration>a.start+1/60))throw Error("Resolve overlapping clips before ripple editing");const i=hc((o?.duration||0)-a.duration),c=t.flatMap(u=>u.id===e?o?[{...o,start:a.start}]:[]:[{...u,...u.track===a.track&&u.start>=n-1/60?{start:hc(u.start+i)}:{}}]);if(c.some(u=>u.start<0||u.start+u.duration>600))throw Error("Ripple exceeds timeline bounds");return c}function h4(t,e,o,r,a={}){const n=t.find(p=>p.id===e),i=n&&t.find(p=>p.id!==e&&p.track===n.track&&Math.abs(p.start-n.start-n.duration)<1/60);if(!n||n.kind==="audio"||!i||i.kind==="audio")throw Error("Select a visual clip with an adjacent next clip on the same track");if(a[n.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(n.duration,i.duration)))throw Error("Transition is longer than adjacent clips");const c=o==="none"?0:hc(r/2),u=o==="fade-white"?"white":"black";return t.map(p=>p.id===e?{...p,visualFadeOut:c,fadeOutColor:u}:p.id===i.id?{...p,visualFadeIn:c,fadeInColor:u}:p)}function _j(t,e){const o=Math.min(t.visualFadeIn||0,t.duration),r=Math.min(t.visualFadeOut||0,t.duration),a=o?Math.max(0,Math.min(1,e/o)):1,n=r?Math.max(0,Math.min(1,(t.duration-e)/r)):1;return a<n?{amount:1-a,color:t.fadeInColor||"black"}:{amount:1-n,color:t.fadeOutColor||"black"}}const f4=["font","color","emphasisColor","emphasisColor2","strokeColor","strokeWidth","shadow","glow","box","boxOpacity","boxShape","emphasisText","upper","trColor","hl"],xe=t=>({emphasisColor:t,emphasisColor2:t}),ry=[{id:"classic",label:"Cổ điển",font:"Noto Sans",color:"#ffffff",...xe("#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",...xe("#ffffff"),strokeWidth:1.6,upper:!0},{id:"green-hi",label:"Xanh nổi",font:"Montserrat ExtraBold",color:"#ffffff",...xe("#3dff4f"),upper:!0,strokeWidth:1.3},{id:"red-hi",label:"Đỏ nổi",font:"Montserrat ExtraBold",color:"#ffffff",...xe("#ff3b30"),upper:!0,strokeWidth:1.3},{id:"challenge",label:"Thử thách",font:"Paytone One",color:"#ffffff",...xe("#ffe600"),strokeWidth:2.2,shadow:"#000000"},{id:"comic",label:"Truyện tranh",font:"Bangers",color:"#ffffff",...xe("#ff3b30"),strokeWidth:1.8,shadow:"#000000"},{id:"black-box",label:"Hộp đen",font:"Be Vietnam Pro ExtraBold",color:"#ffffff",...xe("#ffe14a"),strokeWidth:0,box:"#000000",boxOpacity:.72,boxShape:"line"},{id:"white-box",label:"Hộp trắng",font:"Be Vietnam Pro ExtraBold",color:"#111111",...xe("#e5232b"),strokeWidth:0,box:"#ffffff",boxOpacity:1,boxShape:"line"},{id:"news-red",label:"Tin nóng",font:"Oswald Bold",color:"#ffffff",...xe("#ffe14a"),strokeWidth:0,box:"#d7141a",boxOpacity:.95,boxShape:"block",upper:!0},{id:"yellow-word",label:"Ô vàng",font:"Paytone One",color:"#ffffff",...xe("#ffd60a"),strokeWidth:1.2,box:"#ffd60a",boxShape:"word",emphasisText:"#111111"},{id:"blue-word",label:"Ô xanh dương",font:"Lexend Bold",color:"#ffffff",...xe("#2f6bff"),strokeWidth:1,box:"#2f6bff",boxShape:"word",emphasisText:"#ffffff"},{id:"pink-word",label:"Ô hồng",font:"Baloo 2",color:"#ffffff",...xe("#ff3ea5"),strokeWidth:1,box:"#ff3ea5",boxShape:"word",emphasisText:"#ffffff"},{id:"neon-yellow",label:"Neon vàng",font:"Lexend Bold",color:"#f6ff8a",...xe("#ffffff"),strokeWidth:0,glow:"#d4ff00"},{id:"neon-cyan",label:"Neon xanh",font:"Chakra Petch",color:"#e9feff",...xe("#00e5ff"),strokeWidth:0,glow:"#00c8ff"},{id:"neon-pink",label:"Neon hồng",font:"Lobster",color:"#fff0fb",...xe("#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",...xe("#c6f432"),strokeWidth:1.2,shadow:"#000000"},{id:"soft-shadow",label:"Bóng mềm",font:"Be Vietnam Pro ExtraBold",color:"#ffffff",...xe("#ffe14a"),strokeWidth:0,shadow:"#000000"},{id:"minimal",label:"Tối giản",font:"Be Vietnam Pro",color:"#ffffff",...xe("#ffffff"),strokeWidth:0,shadow:"#000000"},{id:"cinema",label:"Điện ảnh",font:"Playfair Display",color:"#f5f0e6",...xe("#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",...xe("#ffd1e8"),strokeColor:"#1a1a1a",strokeWidth:.6,shadow:"#000000"},{id:"hand",label:"Viết tay",font:"Patrick Hand",color:"#fff8e7",...xe("#ffd23f"),strokeColor:"#3a2a1a",strokeWidth:1},{id:"retro",label:"Retro",font:"Lobster",color:"#ffe9a8",...xe("#ff9b54"),strokeColor:"#7a2e00",strokeWidth:1.2},{id:"candy",label:"Kẹo ngọt",font:"Baloo 2",color:"#ffffff",...xe("#ffe14a"),strokeColor:"#ff4fa3",strokeWidth:1.6},{id:"orange-pop",label:"Cam rực",font:"Paytone One",color:"#ff8a1f",...xe("#ffe14a"),strokeColor:"#ffffff",strokeWidth:1.4,shadow:"#5a1a00"},{id:"aqua",label:"Xanh ngọc",font:"Lexend Bold",color:"#5ef3ff",...xe("#ffffff"),strokeColor:"#062a33",strokeWidth:1.2},{id:"gaming",label:"Game",font:"Chakra Petch",color:"#ffffff",...xe("#a6ff00"),strokeWidth:1.3,upper:!0},{id:"pastel",label:"Pastel",font:"Baloo 2",color:"#4a1d3a",...xe("#c2185b"),strokeWidth:0,box:"#ffc4dc",boxOpacity:.92,boxShape:"line"},{id:"karaoke-green",label:"Karaoke xanh",font:"Bungee",color:"#ffffff",...xe("#39ff14"),strokeWidth:1.2},{id:"kinetic-red",label:"Chữ nhấn đỏ khổng lồ",font:"Montserrat ExtraBold",color:"#ffffff",...xe("#e8251a"),strokeWidth:0,shadow:"#000000",emphasisScale:1.9},{id:"surf",label:"Biển xanh",font:"Pacifico",color:"#ffffff",...xe("#7ee8fa"),strokeColor:"#0b4f6c",strokeWidth:1}],m4=new Map(ry.map(t=>[t.id,t])),ny=t=>m4.get(t)||null;function g4(t){const e=ny(t);if(!e)throw Error(`Unknown caption look "${t}"`);const o={look:t};for(const r of f4)o[r]=e[r];return e.emphasisScale&&(o.emphasisScale=e.emphasisScale),o}function cm(t,e){const o={...t||{style:"classic"},...g4(e)};for(const r of Object.keys(o))o[r]===void 0&&delete o[r];return Oi(o)}const ay=[{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"}],y4=new Map(ay.map(t=>[t.id,t])),iy=t=>y4.get(t)||null;function b4(t,e){const o=iy(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 w4=[.3,1.9,.5,1],tu={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:w4}},eu={fade:{type:"fade",duration:.3},pop:{type:"pop",duration:.3,amount:.5},slide:{type:"slide-down",duration:.4,amount:.25}},pm=.5,k4=.8,x4=.6,M4=28,Il=(t,e,o)=>Math.max(e,Math.min(o,t));function v4(t){const e=t?.element?.anim??{};return{in:o1.includes(e.in)?e.in:"none",out:r1.includes(e.out)?e.out:"none",loop:n1.includes(e.loop)?e.loop:"none"}}const $4=(t,e)=>[...e.in==="spin"||e.loop==="wiggle"?["rot"]:[],...e.loop==="pulse"?["zoom"]:[],...e.loop==="float"?["y"]:[]].includes(t);function ou(t,e,o,r,a,n){const i=[];for(let c=0,u=t;u<=e+1e-6&&i.length<M4;c++,u=t+c*a)i.push({time:ut(Math.min(u,e)),value:c%2?r:o,...c%2===0?{ease:n}:{}});return i.filter((c,u)=>!u||c.time>i[u-1].time+1/60)}function E4(t,e={}){const o=v4(t),r=!!t.element?.anim,a=e1(t.element?.id)?.anim??Mw,n={in:e.in??(r?o.in:a.in),out:e.out??(r?o.out:a.out),loop:e.loop??(r?o.loop:a.loop)};if(!o1.includes(n.in)||!r1.includes(n.out)||!n1.includes(n.loop))throw Error("Unknown element animation preset");let i={...t};for(const f of["rot","zoom","y"])$4(f,o)&&(i={...i,...ge(i,f,[])});if(o.in==="wipe"||o.out==="wipe"){const{revealType:f,reveal:m,...g}=i;i={...g,...ge(g,"reveal",[])}}o.in==="draw"&&(i={...i,...ge(i,"trimEnd",[])}),delete i.enter,delete i.exit;const c=i.duration;tu[n.in]&&(i.enter={...tu[n.in],duration:Math.min(tu[n.in].duration,c/2)}),eu[n.out]&&(i.exit={...eu[n.out],duration:Math.min(eu[n.out].duration,c/2)});const u=Il(Qt(i,"rot",0),-180,180),p=ut(Math.min(x4,c)),s=n.in==="spin"?[{time:0,value:-180,ease:Yt["ease-out"]}]:[];let h=s;if(n.loop==="wiggle"?h=[...s,...ou(s.length?p:0,c,u,Il(u+5,-180,180),.2,Yt["ease-in-out"])]:s.length&&(h=[...s,{time:p,value:u}]),h.length>1&&(i={...i,...ge(i,"rot",h)}),n.loop==="pulse"){const f=Qt(i,"zoom",0);i={...i,...ge(i,"zoom",ou(0,c,f,Il(f*1.08,0,bs),.4,Yt["ease-in-out"]))}}if(n.loop==="float"){const f=Qt(i,"y",0);i={...i,...ge(i,"y",ou(0,c,f,Il(f-.03,-1,1),.8,Yt["ease-in-out"]))}}if(n.in==="wipe"||n.out==="wipe"){const f=[];n.in==="wipe"&&f.push({time:0,value:0,ease:Yt["ease-out"]},{time:ut(Math.min(pm,c/2)),value:1}),n.out==="wipe"&&f.push({time:ut(c-Math.min(pm,c/2)),value:1,ease:Yt["ease-in"]},{time:ut(c),value:0}),i={...i,revealType:"wipe-left",...ge(i,"reveal",f.filter((m,g)=>!g||m.time>f[g-1].time+1/60))}}return n.in==="draw"&&i.shape&&(i={...i,...ge(i,"trimEnd",[{time:0,value:0,ease:Yt["ease-out"]},{time:ut(Math.min(k4,c/2)),value:1}])}),i.element={...i.element??{},anim:n},jn(i),i}[...Object.keys(S1)];const S4=4,I4=/^gs:\/\/[\w.-]+\/(uploads|assets|outputs)\/[^\s?#\\]+$/,Pi=t=>typeof t=="string"&&t.length<=400&&!t.includes("..")&&I4.test(t),Vj=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 A4(t,e,o){let r=null,a=0;for(const n of t||[]){if(!n?.refs?.length)continue;const i=Math.min(n.end,e+o)-Math.max(n.start,e);i>a+1e-9&&(a=i,r=n)}return r}const Gj=(t,e)=>t.map(o=>{if(o?.op!=="generateBroll"||o.refs?.length||!Number.isFinite(o.start)||!Number.isFinite(o.duration))return o;const r=A4(e,o.start,o.duration);return r?{...o,refs:r.refs.map(a=>a.gcsUri)}:o}),C4=["dissolve","cut","whip"],j4=.12,T4=.08,O4=1.06,z4=.2,P4=.12,sy=.35,L4=.7,ly=/[.!?…。]["')\]]*$/,F4=/[,;:,]["')\]]*$/,ru=t=>Math.floor(t*ve+1e-6)/ve,Is=t=>Math.ceil(t*ve-1e-6)/ve,um=t=>Math.round(t*1e3)/1e3;function N4(t,e=[]){const o=[];for(const a of t){if(a.kind!=="video"&&a.kind!=="audio"||a.gen)continue;let n=a.captionWords;if(!n?.length){const i=e.find(c=>c.id===a.nodeId);Array.isArray(i?.words)&&i.words.length?n=dh(a,i.words):a.captions?.length&&(n=$p(a.captions))}for(const i of n??[])o.push({start:um(a.start+i.start),end:um(a.start+i.end),word:i.word})}o.sort((a,n)=>a.start-n.start||a.end-n.end);const r=[];for(const a of o)(!r.length||a.start>=r.at(-1).end-.02)&&r.push(a);return r}function dm(t,{gap:e=sy,maxWords:o=14,soft:r=!0}={}){const a=[];let n=[];return t.forEach((i,c)=>{n.push(i);const u=t[c+1];(!u||u.start-i.end>=e||ly.test(i.word)||r&&F4.test(i.word)&&n.length>=4||n.length>=o)&&(a.push(n),n=[])}),a.map(i=>({start:i[0].start,end:i.at(-1).end,text:i.map(c=>c.word).join(" "),words:i}))}function Kj(t,e){const o=dm(t);if(!o.length)return null;let r=o.findIndex(c=>e>=c.start-.05&&e<=c.end+.05);r<0&&(r=o.findIndex(c=>c.start>e)),r<0&&(r=o.length-1);const a=dm(t,{gap:L4,maxWords:60,soft:!1}),n=Math.max(0,a.findIndex(c=>o[r].start>=c.start-.001&&o[r].start<=c.end+.001)),i=a.slice(Math.max(0,n-1),n+2).map(c=>c.text).join(" ").slice(0,600);return{start:o[r].start,end:o[r].end,text:o[r].text,context:i}}function R4(t,e,o,{min:r=2,max:a=8,lead:n=j4,tail:i=T4}={}){const c=Math.min(e,o),u=Math.max(e,o),p=a-1/ve,s=()=>{const z=ru(Math.max(0,c)),j=ut(Math.min(a,Math.max(r,u-c)));return{start:z,end:ut(z+j),duration:j,snapped:!1,words:[]}},h=t.filter(z=>z.end>z.start),f=h.findIndex(z=>z.end>c+.02);if(f<0||h[f].start>=u-.02)return s();let m=f;for(;m+1<h.length&&h[m+1].start<u-.02;)m++;const g=h[f-1],v=h[f];let x=g?Math.max(v.start-n,Math.min(v.start,(g.end+v.start)/2)):v.start-n;x=Math.max(0,x);let E=ru(x);g&&E<g.end-1e-6&&(E=Math.min(v.start,Is(g.end)));const $=z=>z===h.length-1||h[z+1].start-h[z].end>=sy||ly.test(h[z].word),S=z=>h[z].end+i-E;let k=m;if(!$(m)){let z=m+1;for(;z<h.length&&S(z)<=p&&h[z].end-u<=1.5&&!$(z);)z++;if(z<h.length&&S(z)<=p&&h[z].end-u<=1.5&&$(z))k=z;else{let j=m-1;for(;j>f&&!$(j);)j--;j>=f&&$(j)&&h[j].end-E>=r*.6&&(k=j)}}const y=z=>{const j=h[z+1];let P=h[z].end+i;j&&j.start>=h[z].end&&(P=Math.min(P,(h[z].end+j.start)/2));let F=Is(P);return j&&F>j.start+1e-6&&j.start>=h[z].end&&Is(h[z].end)<=j.start&&(F=Is(h[z].end)),F};for(;k>f&&y(k)-E>p;)k--;let C=y(k);if(C-E<r-1e-6){const z=Is(E+r);for(;k+1<h.length&&h[k+1].start<z-1e-6&&y(k+1)-E<=p;)k++;C=Math.max(z,y(k))}let A=!1;return C-E>a+1e-6&&(C=ru(E+a),A=!0),h.some(z=>z.start<C-1e-6&&z.end>C+1e-6)&&(A=!0),{start:ut(E),end:ut(C),duration:ut(C-E),snapped:!0,clipped:A,words:h.slice(f,k+1)}}function fd(t,e,o,r,a=null,{fallback:n=!1}={}){const{track:i,moved:c}=Kt(t,e,o,r,a,{fallback:n}),u=t.filter(s=>s.kind!=="audio"&&s.start<r-1e-9&&s.start+s.duration>o+1e-9),p=Math.max(0,...u.map(s=>s.zIndex??0));return{track:i,...p>0?{zIndex:Math.min(100,p)}:{},...c?{moved:c}:{}}}function Wj(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,a)=>(r.kind===a.kind?0:r.kind==="video"?-1:1)||r.track-a.track)[0]??null}function D4(t,{transition:e="dissolve",pushIn:o=!0,layout:r="cutaway"}={}){const a={};if(o&&r==="cutaway"&&t>=1&&(a.motionKeys=[{time:0,zoom:1},{time:ut(t),zoom:O4}],a.motionV=2),e==="dissolve"){const n=Math.max(.05,Math.min(z4,t/4));a.enter={type:"fade",duration:n},a.exit={type:"fade",duration:n}}else if(e==="whip"){const n=Math.max(.05,Math.min(P4,t/4));a.enter={type:"slide-left",amount:1,duration:n},a.exit={type:"slide-left",amount:1,duration:n}}return a}function B4({clips:t,tracks:e={},materials:o=[],generator:r,prompt:a,start:n,duration:i,layout:c="cutaway",transition:u="dissolve",pushIn:p,colorMatch:s=!0,preset:h,track:f=null,trackFallback:m=!1,newId:g,refs:v}){const x=S1[r];if(!x)throw Error("Unsupported B-roll generator");const E=typeof a=="string"?a.trim():"";if(E.length<12||E.length>1200)throw Error("B-roll prompt must be 12–1200 characters");if(!a1.includes(c))throw Error("Unsupported B-roll layout");if(v!==void 0&&(!Array.isArray(v)||v.length>S4||!v.every(Pi)))throw Error("Invalid B-roll reference images");if(!C4.includes(u))throw Error("Unsupported B-roll transition");if(!Number.isFinite(n)||!Number.isFinite(i)||n<0||i<1/ve||n+i>Xn)throw Error("Invalid creative clip timing");const $=N4(t,o),S=$.length?R4($,n,n+i,{min:x.min,max:x.max}):null,k=S?.snapped?S.start:ut(n),y=S?.snapped?S.duration:ut(i);if(y<x.min-1e-6||y>x.max+1e-6)throw Error(`${x.label}: ${x.min}–${x.max}s`);if(k+y>Xn)throw Error("Invalid creative clip timing");const{moved:C,...A}=fd(t,e,k,k+y,f,{fallback:m}),z=p??!0,j=D4(y,{transition:u,pushIn:z,layout:c});h&&h!=="none"?j.motionKeys=pc(h,y):h==="none"&&(delete j.motionKeys,delete j.motionV);const P={nodeId:"",kind:"video",url:"",label:`AI B-roll · ${E.slice(0,40)}`,inPoint:0,sourceDuration:y,volume:0,fit:"cover",layout:c,...A,...j,id:g(),start:k,duration:y,gen:{status:"pending",generator:r,prompt:E,duration:y,finish:{transition:u,pushIn:z&&c==="cutaway",colorMatch:s},...v?.length?{refs:[...v]}:{}}};return{clip:P,snap:S,...C?{trackNote:`track ${f} → ${P.track} (${C})`}:{}}}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 md=[.5,.85],hm=[.1,4],G4=/^#[0-9a-f]{6}$/i,K4=(t,e,o)=>Math.min(o,Math.max(e,t)),ti=t=>Math.round(t*1e4)/1e4;function W4(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 a=t.keyColor??Yu.color;if(typeof a!="string"||!G4.test(a))throw Error("Footage VFX: màu key không hợp lệ");e.keyColor=a.toLowerCase()}const o=Number(t.anchorU??md[0]),r=Number(t.anchorV??md[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=ti(o),e.anchorV=ti(r),e}const H4=t=>({...Yu,color:(t||Yu.color).toLowerCase(),similarity:.14,blend:.1,spill:.7});function X4(t,e,o,r=1){const a=t.W/t.H,n=e.width&&e.height?e.width/e.height:a,i=n>=a?1:n/a,c=n>=a?a/n:1,u=K4(Number(r)||1,hm[0],hm[1]);if(!o)return{posX:0,posY:0,scale:ti(u)};const[p,s]=o;return{posX:ti(p-.5-(e.anchorU-.5)*i*u),posY:ti(s-.5-(e.anchorV-.5)*c*u),scale:ti(u)}}const U4=(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 fm({id:t,track:e,start:o,duration:r,footage:a,frame:n,at:i,scale:c,sound:u=!1}){const p=W4(a),s=X4(n,{...a,...p},i,c);return{id:t,nodeId:a.id?`vfx:${a.id}`:t,track:e,start:o,duration:r,inPoint:0,sourceDuration:a.duration,kind:"video",url:a.url,...a.gcsUri?{gcsUri:a.gcsUri}:{},...U4(a.proxy,p.bg)??{},label:String(a.name||"VFX").slice(0,80),volume:u?1:0,motionV:2,...s,...p.bg==="green"?{key:H4(p.keyColor)}:p.bg==="black"?{blend:"screen"}:{},vfxFootage:{...a.id?{id:a.id}:{},bg:p.bg,anchor:[p.anchorU,p.anchorV],...a.width>0&&a.height>0?{aspect:ti(a.width/a.height)}:{}}}}const Y4="clipoox-canvas-assets",q4=t=>`gs://${Y4}/library/models/${t}/model.glb`,Z4=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:q4(t.sha)})));function J4(t){return Z4.find(e=>e.id===t)??null}function Q4(t,{show:e=0,rise:o=!0,at:r,height:a,rotation:n}={}){return{gcsUri:t.model,label:t.name.slice(0,60),at:r??[...t.at],height:a??t.height,rotation:n??t.rotation,show:e,rise:o}}function Hj(t){return{label:t.name.slice(0,60),center:[...t.at],zoom:t.zoom??16.4,pitch:55,bearing:t.bearing??0}}const gd=1e3,Ap=["ờ","ơ","ừm","ưm","ừ","ờm","hừm","hmm","hm","ừa","um","umm","uh","uhm","erm","er","ah","eh","mm"],cy=t=>String(t||"").normalize("NFC").toLowerCase().replace(/[^\p{L}]/gu,""),hl=t=>{const e=cy(t);return!!e&&Ap.includes(e)};function tM(t=[]){return t.flatMap(e=>Ap.includes(cy(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 eM(t,e){const o=[...t.map(n=>({start:+n.start.toFixed(3),end:+n.end.toFixed(3),kind:"silence"})),...e.map(n=>({start:+n.start.toFixed(3),end:+n.end.toFixed(3),kind:"filler",text:n.text.slice(0,20)}))],r=n=>n.kind==="filler"?1:n.end-n.start>=.6?0:2;return(o.length<=gd?o:[...o].sort((n,i)=>r(n)-r(i)||i.end-i.start-(n.end-n.start)||n.start-i.start).slice(0,gd)).sort((n,i)=>n.start-i.start)}function oM(t){if(!Array.isArray(t)||t.length>gd||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 fc=Object.freeze({min:.3,lead:.05,tail:.08,long:.6,minShare:.25,minWords:10}),py=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 rM(t,e,{min:o,lead:r,tail:a}=fc){const n=py(t).filter(u=>!hl(u.word)),i=[],c=(u,p)=>{p-u>=o-r-a&&p-u>.05&&i.push({start:Math.max(0,u),end:p})};if(!n.length)return i;n[0].start>=o&&c(0,n[0].start-a);for(let u=1;u<n.length;u++)n[u].start-n[u-1].end>=o&&c(n[u-1].end+r,n[u].start-a);return Number.isFinite(e)&&e-n.at(-1).end>=o&&c(n.at(-1).end+r,e),i}function uy(t){const e=Array.isArray(t?.pauses)?t.pauses:null,o=py(t?.words).filter(c=>!hl(c.word));if(o.length<fc.minWords)return e;const r=[];for(let c=1;c<o.length;c++)o[c].start-o[c-1].end>=fc.long&&r.push({start:o[c-1].end,end:o[c].start});if(!r.length)return e;const a=(e||[]).filter(c=>c?.kind==="silence"),n=r.filter(c=>a.some(u=>Math.min(u.end,c.end)-Math.max(u.start,c.start)>=.5*(c.end-c.start))).length;if(e&&n>=fc.minShare*r.length)return e;const i=[...(e||[]).filter(c=>c?.kind==="filler").map(c=>({start:c.start,end:c.end,text:String(c.text||"")})),...tM(t.words)].filter((c,u,p)=>p.findIndex(s=>Math.abs(s.start-c.start)<.05)===u);return eM(rM(t.words,Number(t.duration)),i)}function nM(t,e,o,{minGap:r=.6,padding:a=.12,fillers:n=!1,maxClips:i=100,isBed:c=s=>s.kind==="audio"&&s.nodeId!==o?.id}={},u={},p=()=>Math.random().toString(36).slice(2,10)){const s=t.find(A=>A.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(u[s.track]?.locked)throw Error("Track is locked");const h=uy(o);if(!h)throw Error("Analyze speech first (pauses unknown)");if(!(r>=.2&&r<=5)||!(a>=0&&a<=.5))throw Error("Invalid pause settings");const f=s.playbackRate||1,m=s.inPoint||0,g=m+s.duration*f;let x=hh(oM(h).flatMap(A=>A.kind==="filler"?n?[{start:A.start-.02,end:A.end+.02}]:[]:A.end-A.start>=r?[{start:A.start+a,end:A.end-a}]:[]).map(A=>({start:Math.max(A.start,m),end:Math.min(A.end,g)})).filter(A=>A.end-A.start>=2/30)).map(A=>({start:ut(s.start+(A.start-m)/f),end:ut(s.start+(A.end-m)/f)})).filter(A=>A.end-A.start>=2/30);const E=Math.max(0,i-t.length),$=Math.max(0,x.length-E);$&&(x=[...x].sort((A,z)=>z.end-z.start-(A.end-A.start)).slice(0,E)),x.sort((A,z)=>z.start-A.start);let S=t.map(A=>({...A})),k=0,y=$,C=0;for(const A of x){const z=S.find(U=>U.track===s.track&&U.nodeId===s.nodeId&&U.start<=A.start+1e-6&&U.start+U.duration>=A.end-1e-6),j=!z||S.some(U=>U.track!==s.track&&!c(U)&&U.start<A.end-1/60&&U.start+U.duration>A.start+1/60)||S.some(U=>u[U.track]?.locked&&U.start>=A.end-1/60),P=z&&A.start<=z.start+1/30,F=z&&A.end>=z.start+z.duration-1/30;if(j||P&&F){y++;continue}let N=null,G=null;if(P)G=_e(z,A.end,p())[1];else if(F)N=_e(z,A.start,p())[0];else{const[U,at]=_e(z,A.start,p());N=U,G=at&&_e(at,A.end,p())[1]}if(!N&&!G){y++;continue}const V=ut(A.end-A.start),et=[...N?[N]:[],...G?[{...G,id:N?G.id:z.id,start:A.start}]:[]];S=S.flatMap(U=>U.id===z.id?et:[U.start>=A.end-1/60&&!(c(U)&&U.start<A.end+1/60&&U.start>A.start)?{...U,start:ut(U.start-V)}:U]),k++,C+=V}return{clips:S,removed:k,skipped:y,saved:ut(C)}}function aM(t,e,o={},r=new Set){const a=[];for(const n of t){if(r.has(n.id)||n.kind==="image"||n.kind==="model"||(n.volume??1)<=0||o[n.track]?.muted)continue;const i=e.find(c=>c.id===n.nodeId);for(const c of Ec(n,Array.isArray(i?.transcript)?i.transcript:[]))a.push({start:n.start+c.start,end:n.start+c.end})}return hh(a,.4)}function iM(t,e,o,r,a={}){if(!(r>=.05&&r<=.8))throw Error("Duck level must be 0.05–0.8");const n=new Set(e);if(!n.size)throw Error("No music/audio clip to duck");const i=aM(t,o,a,n);if(!i.length)throw Error("No analysed speech to duck under — analyze the talking-head clip first");let c=0;return{clips:t.map(p=>{if(!n.has(p.id))return p;if(a[p.track]?.locked)throw Error("Track is locked");if(!["audio","video"].includes(p.kind))throw Error("Only audio/video clips can be ducked");const s=hh(i.flatMap(h=>{const f=Math.max(0,h.start-p.start),m=Math.min(p.duration,h.end-p.start);return m>f?[{start:+f.toFixed(3),end:+m.toFixed(3)}]:[]}),2*Ew).slice(0,$w);if(!s.length){const{duck:h,...f}=p;return f}return c++,{...p,duck:{level:+r.toFixed(3),ranges:s}}}),ducked:c}}function dy(t,e,o=.5,r=.5){const a=t,n=e;if(!(a>0)||!(n>0))throw Error("Unknown source dimensions");const i=Math.min(4,Math.max(a/n,n/a)),c=Number.isFinite(o)?Math.max(0,Math.min(1,o)):.5,u=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,p=(i-1)/2,s=a>n?Math.max(-p,Math.min(p,i*(.5-c))):0,h=a<n?Math.max(-p,Math.min(p,i*(.5-u))):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)}}const mm=Object.freeze({minMove:.02});function sM(t,e,o){if(t.speedRamp||t.timeRemap||t.reverse)return null;const r=t.playbackRate||1,a=t.inPoint||0,n=a+t.duration*r,i=(e.scenes||[]).filter(s=>Number.isFinite(s.start)&&Number.isFinite(s.end)&&s.end>a&&s.start<n).sort((s,h)=>s.start-h.start);if(!i.some(s=>Number.isFinite(s.subjectX)||Number.isFinite(s.subjectY)))return null;const c=[],u=[];let p=null;for(const s of i){if(!Number.isFinite(s.subjectX)&&!Number.isFinite(s.subjectY)&&p)continue;const h=dy(e.width/e.height,o,s.subjectX,s.subjectY),f=+Math.max(0,(s.start-a)/r).toFixed(3);if(!(p&&Math.abs(h.posX-p.posX)<mm.minMove&&Math.abs(h.posY-p.posY)<mm.minMove)){if(f>=t.duration)break;!c.length&&f>0?(c.push({time:0,value:h.posX,ease:"hold"}),u.push({time:0,value:h.posY,ease:"hold"})):(c.push({time:f,value:h.posX,ease:"hold"}),u.push({time:f,value:h.posY,ease:"hold"})),p=h}}return c.length>=2?{x:c,y:u}:null}function lM(t,e,o,{clipId:r}={},a={}){const n=vw(o);let i=0;const c=[];return{clips:t.map(p=>{if(r?p.id!==r:p.kind!=="video"&&p.kind!=="image"||p.title)return p;const s=e.find(x=>x.id===p.nodeId),h=p.label||p.id;if(a[p.track]?.locked)return c.push(`${h}: locked`),p;if(!(s?.width>0&&s?.height>0))return c.push(`${h}: size unknown (analyze first)`),p;if(Ee(p,"x").length||Ee(p,"zoom").length||Ee(p,"y").length)return c.push(`${h}: has position keyframes`),p;const f=(p.inPoint||0)+p.duration*(p.playbackRate||1)/2,m=(s.scenes||[]).find(x=>x.start<=f&&x.end>f)||(s.scenes||[]).find(x=>Number.isFinite(x.subjectX));i++;const g=dy(s.width/s.height,n,m?.subjectX,m?.subjectY),v=sM(p,s,n);return v?{...p,...g,posX:v.x[0].value,posY:v.y[0].value,motionV:2,motionKeys:br({...p,motionKeys:br(p,"x",v.x)},"y",v.y)}:{...p,...g,motionV:2}}),reframed:i,skipped:c}}const ts=Object.freeze({reach:.6,breath:.08,near:.04});function nu(t,e){if(!Array.isArray(t)||!t.length||!Number.isFinite(e))return e;const o=t.findIndex(p=>p.start<e&&e<p.end),r=p=>{const s=t[p-1],h=t[p];return s?[s.end,h.start]:[Math.max(0,h.start-.3),h.start]},a=p=>{const s=t[p],h=t[p+1];return h?[s.end,h.start]:[s.end,s.end+.3]},n=([p,s],h)=>{const f=Math.max(0,s-p),m=Math.min(ts.breath,f/2);return h==="before"?s-m:p+m};if(o>=0){const p=t[o];return(p.start+p.end)/2>e?n(r(o),"before"):n(a(o),"after")}const i=t.findIndex(p=>p.start>=e),c=i>0?t[i-1]:i<0?t[t.length-1]:null,u=i>=0?t[i]:null;return u&&u.start-e<ts.near?n([c?c.end:u.start-.3,u.start],"before"):c&&e-c.end<ts.near?n([c.end,u?u.start:c.end+.3],"after"):e}const Oo=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}),hy=Object.freeze(["best","last","first"]),cM=/[.?!…。]["'”’)\]]*$/u,fy=t=>String(t||"").normalize("NFC").toLowerCase().replace(/[^\p{L}\p{N}]/gu,""),ws=t=>fy(t).normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d"),pM=new Set(Ap),uM=new Set([...Ap,"à","like","kiểu"]),dM=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(" ")),gm=t=>(t.kind==="video"||t.kind==="audio")&&!t.reverse&&!t.title&&!t.motion&&!t.shape,ym=t=>!!(t&&(Array.isArray(t.words)&&t.words.length||Array.isArray(t.transcript)&&t.transcript.length));function hM(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((a,n)=>({start:e.start+n*r,end:e.start+(n+1)*r,word:a,...n===o.length-1?{cueEnd:!0}:{}}))})}const my=t=>(Array.isArray(t?.pauses)?t.pauses:[]).filter(e=>e?.kind==="filler"&&Number.isFinite(e.start)&&e.end>e.start),gy=(t,e,o,r)=>Math.max(0,Math.min(e,r)-Math.max(t,o));function yd(t,e,o){const r=t.length,a=e.length,n=a+1,i=new Uint16Array((r+1)*n);for(let s=1;s<=r;s++)for(let h=1;h<=a;h++)i[s*n+h]=t[s-1]===e[h-1]?i[(s-1)*n+h-1]+1:Math.max(i[(s-1)*n+h],i[s*n+h-1]);let c=r,u=a,p=0;for(;c>0&&u>0;)t[c-1]===e[u-1]?(o[c-1]&&p++,c--,u--):i[(c-1)*n+u]>=i[c*n+u-1]?c--:u--;return{len:i[r*n+a],mc:p}}const au=t=>t.reduce((e,o)=>e+(o?1:0),0);function bm(t,e,o=Oo.minSimilarity){const r=t.keys,a=e.keys;if(r.length<2||a.length<2)return null;let n=null;const[i,c]=r.length<=a.length?[t,e]:[e,t];if(i.keys.length<c.keys.length&&i.keys[0]===c.keys[0]){const u=yd(i.keys,c.keys.slice(0,i.keys.length+1),i.content),p=i.keys.length-(i.keys.length>=4?1:0);u.len>=p&&u.mc>=1&&u.mc===au(i.content)&&(i.keys.length>=3||u.mc>=2)&&(n={kind:"prefix",sim:+(u.len/i.keys.length).toFixed(4),short:i===t?0:1})}if(r.length>=3&&a.length>=3){const u=au(t.content),p=au(e.content);if(u>=2&&p>=2){const s=yd(r,a,t.content),h=+(2*s.len/(r.length+a.length)).toFixed(4);h>=o&&s.mc>=.8*Math.min(u,p)-1e-9&&s.mc>=.5*Math.max(u,p)-1e-9&&(!n||h>n.sim)&&(n={kind:"full",sim:h})}}return n}function yy(t,e){const o=[],r=t.length;for(let a=0;a<r-3;a++){let n=null;for(let i=Math.floor((r-a)/2);i>=(a>0?3:2)&&!n;i--)for(const c of[0,1]){const u=a+i+c;if(u+i>r)continue;let p=!0;for(let s=0;s<i&&p;s++)p=t[a+s]===t[u+s];if(p&&(i>=3||e.slice(a,a+i).some(Boolean))){n={i:a,j:u};break}}n&&(o.push(n),a=n.j-1)}return o}function fM(t,e,o,r){const a=s=>e.find(h=>h.id===s);let n;if(Array.isArray(o)&&o.length){n=o.map(h=>{const f=t.find(m=>m.id===h);if(!f)throw Error(`Clip not found: ${h}`);return f});const s=n.find(h=>!gm(h)||!ym(a(h.nodeId)));if(s)throw Error(`"${s.label||s.id}" has no analysed speech (video / audio with a transcript)`)}else n=t.filter(s=>gm(s)&&ym(a(s.nodeId)));if(!n.length)throw Error("Analyze speech first (no clip with transcript words)");const i=s=>(s.volume??1)>0&&!r[s.track]?.muted,c=[...n].sort((s,h)=>Number(i(h))-Number(i(s))||(s.kind==="audio")-(h.kind==="audio")||s.track-h.track||s.start-h.start),u=[],p=[];for(const s of c)(u.filter(f=>f.track!==s.track).reduce((f,m)=>f+gy(s.start,s.start+s.duration,m.start,m.start+m.duration),0)>=s.duration*.5?p:u).push(s);return{primary:u,companions:p}}function mM(t,e){const o=new Map;for(const r of t){const a=e.find(s=>s.id===r.nodeId),n=r.playbackRate||1,i=r.inPoint||0,c=i+r.duration*n,u=r.start+r.duration,p=o.get(r.track)??[];o.set(r.track,p);for(const s of hM(a)){const h=(s.start+s.end)/2;if(h<i-1e-6||h>=c-1e-6)continue;const f=fy(s.word),m=ws(s.word),g=!m||uM.has(f);p.push({t:r.start+(Math.max(s.start,i)-i)/n,te:r.start+(Math.min(s.end,c)-i)/n,s:s.start,e:s.end,clipId:r.id,node:r.nodeId,track:r.track,cs:r.start,ce:u,rate:n,text:String(s.word).trim(),key:g?"":m,content:!g&&!dM.has(f),filler:pM.has(f),stop:cM.test(String(s.word).trim())||!!s.cueEnd})}}for(const r of o.values())r.sort((a,n)=>a.t-n.t||a.s-n.s);return o}function gM(t,e){const o=new Map,r=[];let a=null;const n=(i,c)=>{if(i.node!==c.node)return 0;let u=o.get(i.node);return u||(u=my(e.find(p=>p.id===i.node)),o.set(i.node,u)),u.reduce((p,s)=>p+gy(i.e,c.s,s.start,s.end),0)/(i.rate||1)};t.forEach((i,c)=>{const u=t[c-1];(!a||u.stop||u.node!==i.node||i.s<u.s-.05||i.s-u.e>3||i.t-u.te-n(u,i)>=Oo.pause||a.keys.length>=Oo.maxWords)&&(a?.keys.length&&r.push(a),a={w0:c,w1:c,keys:[],content:[],keyWord:[]}),a.w1=c,i.key&&(a.keys.push(i.key),a.content.push(i.content),a.keyWord.push(c))}),a?.keys.length&&r.push(a);for(const i of r)i.t=t[i.w0].t,i.te=t[i.w1].te;return r}function yM(t,{window:e,minSimilarity:o}){const r=new Array(t.length).fill(-1),a=[];for(let i=0;i<t.length;i++){let c=null;for(let p=i-1;p>=0&&i-p<=Oo.lookBack&&!(t[i].t-t[p].te>e);p--){const s=bm(t[p],t[i],o);if(!s)continue;let h=0;for(let f=p+1;f<i;f++)t[f].keys.length>=4&&(r[p]<0||r[f]!==r[p])&&h++;(s.kind==="prefix"?h>0||t[i].t-t[p].te>Oo.restartGap:h>Oo.maxBetween)||(!c||s.sim>c.rel.sim+1e-9)&&(c={i:p,rel:s})}if(!c)continue;let u=r[c.i];u<0&&(u=a.length,a.push([c.i]),r[c.i]=u),a[u].push(i),r[i]=u}const n=[];for(let i=1;i<t.length;i++){const c=t[i-1],u=t[i];if(r[i-1]>=0||u.t-c.te>Oo.restartGap)continue;const p=c.keys.lastIndexOf(u.keys[0]);p<2||c.keys.length-p<3||bm({keys:c.keys.slice(p),content:c.content.slice(p)},u,o)&&n.push({i:i-1,j:i,p})}return{groups:a,gid:r,tails:n}}function bM(t,e,o){const r=t.slice(e.w0,e.w1+1);let a=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 g=m[0].s,v=m.at(-1).e;a+=my(o.find(x=>x.id===f)).filter(x=>x.start>=g-1e-6&&x.end<=v+1e-6).length}const n=e.keys;let i=yy(n,e.content).length;for(let f=1;f<n.length;f++)n[f]===n[f-1]&&i++;const c=r.filter(f=>f.key);let u=0;for(let f=1;f<c.length;f++)u+=Math.max(0,c[f].t-c[f-1].te-.3);const p=c.slice(1).map((f,m)=>f.t-c[m].t),s=p.reduce((f,m)=>f+m,0)/(p.length||1),h=p.length>=2&&s>0?Math.sqrt(p.reduce((f,m)=>f+(m-s)**2,0)/p.length)/s:0;return{fillers:a,restarts:i,longPause:+u.toFixed(3),steady:+Math.max(0,1-Math.min(1,h)).toFixed(3)}}const by=(t,e=5)=>{const o=t.split(/\s+/).filter(Boolean);return o.length>e?`${o.slice(0,e).join(" ")}…`:o.join(" ")};function wM(t,e){const o=t.map((a,n)=>({t:a,i:n})).filter(a=>a.t.full);if(e==="first")return o[0].i;if(e==="last")return o.at(-1).i;const r=Math.max(...o.map(a=>a.t.score));return o.filter(a=>a.t.score>=r-.03).at(-1).i}function kM(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 xM(t,e=[],o={}){const r=o.keep??"best";if(!hy.includes(r))throw Error("keep must be best, last or first");const a=o.window??Oo.window,n=o.minSimilarity??Oo.minSimilarity;if(!(a>=5&&a<=600))throw Error("window must be 5–600 s");if(!(n>=0&&n<=1))throw Error("minSimilarity must be 0..1");const i=o.tracks??{},{primary:c,companions:u}=fM(t,e,o.clipIds,i),p=mM(c,e),s=[];for(const[m,g]of[...p].sort((v,x)=>v[0]-x[0])){const v=gM(g,e),{groups:x,gid:E,tails:$}=yM(v,{window:a,minSimilarity:Math.max(.4,n)}),S=[];for(const k of x){const y=k.map(C=>({w0:v[C].w0,w1:v[C].w1,keys:v[C].keys,content:v[C].content}));S.push({kind:"repeat",track:m,takes:y,between:[],utt:k})}for(const{i:k,j:y,p:C}of $){const A=v[k],z={w0:A.keyWord[C],w1:A.w1,keys:A.keys.slice(C),content:A.content.slice(C)};E[y]>=0&&S[E[y]].utt[0]===y?(S[E[y]].takes.unshift(z),S[E[y]].utt.unshift(-1)):E[y]<0&&(E[y]=S.length,x.push([y]),S.push({kind:"repeat",track:m,takes:[z,{w0:v[y].w0,w1:v[y].w1,keys:v[y].keys,content:v[y].content}],between:[],utt:[-1,y]}))}v.forEach((k,y)=>{for(const C of yy(k.keys,k.content)){const A=E[y]>=0?S[E[y]]:null,z={w0:k.keyWord[C.i]===k.keyWord[0]?k.w0:k.keyWord[C.i],w1:k.keyWord[C.j]-1,keys:k.keys.slice(C.i,C.j),content:k.content.slice(C.i,C.j)},j={w0:k.keyWord[C.j],w1:k.w1,keys:k.keys.slice(C.j),content:k.content.slice(C.j)};S.push({kind:"restart",track:m,takes:[z,j],between:[],parentRef:A?{g:A,take:A.utt.indexOf(y)}:null})}});for(const k of S){const y=new Set(k.takes.flatMap(A=>A.keys));for(const A of k.takes)Object.assign(A,bM(g,A,e)),A.completeness=+(new Set(A.keys.filter(z=>y.has(z))).size/y.size).toFixed(3);const C=Math.max(...k.takes.map(A=>A.completeness));for(const A of k.takes)A.full=A.completeness>=Math.max(.6,C-.3)-1e-9,A.score=+(.6*A.completeness+.1*A.steady-.06*A.fillers-.08*A.restarts-.15*Math.min(1,A.longPause)).toFixed(4);if(k.kind==="repeat"){const A=k.takes.map((z,j)=>j<k.takes.length-1&&z.full&&!g[z.w1].stop&&g[k.takes[j+1].w0].t-g[z.w1].te<=Oo.abandonGap);k.takes.some((z,j)=>z.full&&!A[j])&&k.takes.forEach((z,j)=>{A[j]&&(z.full=!1)})}if(k.kind==="repeat")for(let A=1;A<k.takes.length;A++){const z=k.takes[A-1].w1+1,j=k.takes[A].w0-1;if(j<z)continue;const P=v.filter(N=>N.w0>=z&&N.w1<=j),F=N=>!g[N.w1].stop&&N.keys.length>=2&&yd(N.keys,k.takes[A].keys,N.content).len>=.7*N.keys.length;P.every(N=>N.keys.length<=Oo.junkWords||F(N))&&g[j].te-g[z].t<=Oo.junkSeconds&&k.between.push({w0:z,w1:j})}}for(const k of S)s.push(k)}const h=s.map(m=>{const g=p.get(m.track),v=g[m.takes[0].w0];return{...m,id:`${m.kind==="restart"?"r":"g"}:${v.node}@${v.s.toFixed(2)}`}}).sort((m,g)=>p.get(m.track)[m.takes[0].w0].t-p.get(g.track)[g.takes[0].w0].t||m.track-g.track),f={groups:[],streams:Object.fromEntries(p),primary:c.map(wm),companions:u.map(wm),speechNodes:[...new Set([...c,...u].map(m=>m.nodeId))]};for(const m of h){const g=p.get(m.track),v=wM(m.takes,r),x=m.takes.map($=>({w0:$.w0,w1:$.w1,text:g.slice($.w0,$.w1+1).map(S=>S.text).join(" "),start:+g[$.w0].t.toFixed(3),end:+g[$.w1].te.toFixed(3),clipId:g[$.w0].clipId,score:$.score,completeness:$.completeness,fillers:$.fillers,restarts:$.restarts,longPause:$.longPause,steady:$.steady,full:$.full})),E=m.parentRef?{id:h.find($=>$.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:by(x[v].text),takes:x,kept:v,reasons:x.map(($,S)=>kM(m,S,v,r)),between:m.between,parent:E?.id?E:null,cuts:[]})}for(const m of f.groups)m.cuts=m.takes.flatMap((g,v)=>v===m.kept?[]:[{take:v,reason:m.reasons[v],ranges:MM(f,bd(f.streams[m.track],m.takes[v].w0,m.takes[v].w1),m.track)}]);return f}const wm=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 bd(t,e,o){const r=t[e],a=t[o],n=t[e-1],i=t[o+1],u=n&&n.te<=r.t+1e-6&&n.te>=r.cs-1e-6?r.t-Math.min(Oo.breath,Math.max(0,r.t-n.te)/2):r.t-r.cs<=Oo.closeGap?r.cs:r.t-Oo.breath,p=i?i.t:a.ce,s=Math.max(0,p-a.te),h=s<=Oo.closeGap?i?i.t-Math.min(Oo.breath,s/2):p:a.te+.12;return{start:Math.max(0,u),end:Math.max(u,h)}}function wd(t,e,o){return t.primary.filter(r=>r.track===o).flatMap(r=>{const a=ut(r.start+r.duration);let n=ut(Math.max(e.start,r.start)),i=ut(Math.min(e.end,a));return n-r.start<=1/30+1e-9&&(n=r.start),a-i<=1/30+1e-9&&(i=a),i-n>=2/30?[{clipId:r.id,track:o,nodeId:r.nodeId,start:n,end:i,srcStart:+(r.inPoint+(n-r.start)*r.rate).toFixed(3),srcEnd:+(r.inPoint+(i-r.start)*r.rate).toFixed(3)}]:[]})}const MM=(t,e,o)=>wd(t,e,o).map(r=>({clipId:r.clipId,start:r.srcStart,end:r.srcEnd}));function vM(t,e,o,r){const a=t.start+t.duration,n=e<=t.start+1/30,i=o>=a-1/30;if(n&&i)return[];if(n){const s=_e(t,o,r())[1];return s?[{...s,id:t.id,start:t.start}]:[t]}if(i)return[_e(t,e,r())[0]];const[c,u]=_e(t,e,r()),p=u&&_e(u,o,r())[1];return p?[c,{...p,start:ut(e)}]:[c]}const $M=t=>t.label||t.id;function EM(t,e,o={}){const r=o.tracks??{},a=o.makeId??(()=>Math.random().toString(36).slice(2,10)),n=o.maxClips??tl,i=o.isBed??(j=>j.kind==="audio"&&!e.speechNodes.includes(j.nodeId)),c=o.choose??{},u=new Set(o.skip??[]),p=new Map(e.groups.map(j=>[j.id,j])),s=j=>{const P=c[j.id];return Number.isInteger(P)&&P>=0&&P<j.takes.length?P:j.kept},h=(j,P)=>{const F=p.get(j);return!!F&&!u.has(j)&&s(F)!==P},f=[],m=[];for(const j of e.groups){if(u.has(j.id)||j.parent&&h(j.parent.id,j.parent.take))continue;const P=s(j),F=j.takes.map((V,et)=>et).filter(V=>V!==P),N=e.streams[j.track],G={id:j.id,label:j.kind==="restart"?j.label:SM(j,P),kind:j.kind,takes:j.takes.length,kept:P,cut:F,blocked:[]};f.push(G);for(const V of F)m.push({...bd(N,j.takes[V].w0,j.takes[V].w1),track:j.track,who:[[G,V]]});if(F.length)for(const V of j.between)m.push({...bd(N,V.w0,V.w1),track:j.track,who:[]})}const g=new Set(e.primary.map(j=>j.id)),v=new Set(e.companions.map(j=>`${j.track}|${j.nodeId}`)),x=(j,P,F)=>j.start<=P+1e-6&&j.start+j.duration>=F-1e-6,E=j=>{if(r[j.track]?.locked)return"locked";for(const P of wd(e,j,j.track)){const F=G=>G.start<P.end-.016666666666666666&&G.start+G.duration>P.start+.016666666666666666,N=t.find(G=>G.id!==P.clipId&&F(G)&&(G.track===j.track?!g.has(G.id):!i(G)&&!(v.has(`${G.track}|${G.nodeId}`)&&x(G,P.start,P.end))));if(N)return`"${$M(N)}"`;if(t.some(G=>r[G.track]?.locked&&(G.start>=P.end-1/60||F(G)&&v.has(`${G.track}|${G.nodeId}`))))return"locked"}return null},$=[];for(const j of m.sort((P,F)=>P.track-F.track||P.start-F.start)){const P=E(j);if(P){for(const[N,G]of j.who)N.blocked.push({take:G,reason:P});continue}const F=$.at(-1);F&&F.track===j.track&&j.start<=F.end+1/60?(F.end=Math.max(F.end,j.end),F.who.push(...j.who)):$.push({...j,who:[...j.who]})}const S=[];let k=0;for(const j of $){const P=wd(e,j,j.track);let F=null;if(!P.length)continue;const N=P.reduce((G,V)=>{const et=t.find(at=>at.id===V.clipId),U=et&&V.start>et.start+1/30&&V.end<et.start+et.duration-1/30;return G+(U?1+t.filter(at=>at.track!==j.track&&v.has(`${at.track}|${at.nodeId}`)&&x(at,V.start,V.end)).length:0)},0);if(!F&&t.length+k+N>n&&(F="limit"),F){for(const[G,V]of j.who)G.blocked.push({take:V,reason:F});continue}k+=N,S.push(...P)}let y=t.map(j=>({...j})),C=0,A=0;for(const j of S.sort((P,F)=>F.start-P.start)){const P=y.filter(G=>(G.track===j.track&&G.nodeId===j.nodeId||G.track!==j.track&&v.has(`${G.track}|${G.nodeId}`))&&x(G,j.start,j.end));if(!P.some(G=>G.track===j.track))continue;const F=ut(j.end-j.start),N=new Set(P.map(G=>G.id));y=y.flatMap(G=>N.has(G.id)?vM(G,j.start,j.end,a):[G.start>=j.end-1/60&&!(i(G)&&G.start<j.end+1/60&&G.start>j.start)?{...G,start:ut(G.start-F)}:G]),C++,A+=F}const z=f.filter(j=>j.cut.length).map(j=>IM(j,o.en));return{clips:y,groups:f,removed:C,saved:ut(A),lines:z}}const SM=(t,e)=>by(t.takes[e].text);function IM(t,e){const o=t.cut.filter(n=>!t.blocked.some(i=>i.take===n)),r=[...new Set(t.blocked.map(n=>n.reason==="locked"?e?"a locked track":"track đã khoá":n.reason==="limit"?e?"the clip limit":"giới hạn clip":n.reason))].join(", "),a=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"}${a}`:`retakes: nói vấp "${t.label}" → ${o.length?"bỏ đoạn vấp":"giữ nguyên"}${a}`:e?`retakes: ${t.takes} takes of "${t.label}" → kept take ${t.kept+1}${a}`:`retakes: ${t.takes} lần nói "${t.label}" → giữ lần ${t.kept+1}${a}`}function AM(t,e,o={}){const r=xM(t,e,o);return{...EM(t,r,o),found:r}}const za=Object.freeze({lead:.3,iconLead:.2,minGap:.8,maxLead:2}),km=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(" ")),kd=t=>String(t??"").split(",")[0].split(/[\s\-–—/.]+/).map(ws).filter(Boolean);function wy(t,e,o,r,a=null){const n=[];for(const i of Array.isArray(t)?t:[]){if((a?i.id!==a:!["audio","video"].includes(i.kind)||i.muted||i.volume===0)||!(i.start<r&&i.start+i.duration>o))continue;const c=(e??[]).find(u=>u.id===i.nodeId);for(const u of Sc(i,Array.isArray(c?.words)?c.words:null)){const p=i.start+u.start;p>=o-1e-6&&p<r&&n.push({start:p,end:i.start+u.end,word:u.word,key:ws(u.word)})}}return n.sort((i,c)=>i.start-c.start)}function xd(t,e,o=-1/0){const r=kd(t);if(!r.length)return null;let a=null;for(let n=0;n<e.length;n++)if(!(e[n].start<o)){for(let i=0;i<r.length;i++){let c=0;for(;n+c<e.length&&i+c<r.length&&e[n+c].key===r[i+c];)c++;if(!c)continue;const u=r.filter(s=>!km.has(s)),p=r.slice(i,i+c).filter(s=>!km.has(s)).length;c<r.length&&!(p&&(p===u.length||p>=2))||(!a||c>a.n)&&(a={n:c,at:e[n].start,said:e.slice(n,n+c).map(s=>s.word).join(" ")})}if(a?.n===r.length)break}return a&&{at:a.at,said:a.said}}const Al=t=>Math.round(t*100)/100,iu=(t,e,o)=>Math.min(o,Math.max(e,t));function CM(t,e,{words:o=[],times:r=null,start:a=0,duration:n,lead:i=za.lead}){const c=n,u=iu(Number.isFinite(i)?i:za.lead,0,za.maxLead),p=[],s=Array.isArray(r)?r.filter(y=>y&&Number.isFinite(Number(y.at))):null,h=(y,C,A)=>{const z=A[C];if(Number.isInteger(z))return z>=1&&z<=y.length?z-1:-1;const j=kd(z).join(" ");return j?y.findIndex(P=>kd(P.label).join(" ")===j):-1},f=t.map(()=>null);let m=a-1e-6;t.forEach((y,C)=>{const A=s?.find(j=>j.place!=null&&h(t,"place",j)===C),z=A?{at:Number(A.at),said:null}:s?null:xd(y.label,o,m);z&&(f[C]=z,m=z.at+.001),p.push({kind:"place",name:y.label||`#${C+1}`,at:z?Al(z.at):null,...z?.said?{said:z.said}:{}})});const g=(e??[]).map((y,C)=>{const A=s?.find(j=>j.icon!=null&&h(e,"icon",j)===C),z=A?{at:Number(A.at),said:null}:s||!y.label?null:xd(y.label,o,a-1e-6);return p.push({kind:"icon",name:y.label||y.icon,at:z?Al(z.at):null,...z?.said?{said:z.said}:{}}),z});if(!f.some(Boolean)&&!g.some(Boolean))throw Error("None of the map's places or icons is said in the voice (check the Transcript, or give times)");const v=t.length,x=v>1?c*.85:0,E=f.map(y=>y?iu(y.at-a-u,0,c-.3):null);for(let y=1;y<v;y++)if(E[y]!=null){const C=E.slice(0,y).reverse().find(A=>A!=null);C!=null&&E[y]<C+za.minGap&&(E[y]=Math.min(c-.3,C+za.minGap))}const $=E.map((y,C)=>y==null?null:C).filter(y=>y!=null);for(let y=0;y<v;y++){if(E[y]!=null)continue;const C=[...$].reverse().find(z=>z<y),A=$.find(z=>z>y);C!=null&&A!=null?E[y]=E[C]+(E[A]-E[C])*(y-C)/(A-C):A!=null?E[y]=E[A]*y/A:C!=null?E[y]=Math.min(c-.3,E[C]+Math.max(za.minGap,(x-E[C])/(v-1-C))*(y-C)):E[y]=v>1?x*y/(v-1):0}const S=t.map((y,C)=>({...y,at:Al(E[C])})),k=(e??[]).map((y,C)=>{const A=g[C],{show:z,...j}=y;return A?{...j,show:Al(iu(A.at-a-za.iconLead,0,c-.5))}:j});return{places:S,icons:k,report:p}}function jM(t){return t.map(e=>e.at==null?`${e.name} not said`:`${e.name} ${e.at} s${e.said?` («${e.said}»)`:""}`).join("; ")}const hn=Object.freeze({maxReplace:60,maxCues:300,maxText:300,near:.35}),TM=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),OM=(t,e)=>new RegExp(`(?<![\\p{L}\\p{N}])${TM(t.normalize("NFC"))}(?![\\p{L}\\p{N}])`,e?"gu":"giu");function zM(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(a=>a.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 PM(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>hn.maxReplace)throw Error(`at most ${hn.maxReplace} replacements`);if(r.length>hn.maxCues)throw Error(`at most ${hn.maxCues} cues per edit`);const a=zM(t,e.clipIds);if(!a.length)throw Error("No subtitles on the timeline yet (addSocialCaptions first)");const n=[],i=o.map((p,s)=>{if(!p||typeof p.from!="string"||!p.from.trim()||typeof p.to!="string")throw Error(`replace[${s}] needs from and to (text)`);if(p.from.length>120||p.to.length>120)throw Error(`replace[${s}]: from / to ≤ 120 characters`);return{re:OM(p.from.trim(),p.matchCase===!0),to:p.to.normalize("NFC"),from:p.from.trim(),n:0}});if(i.length){for(const p of a)p.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(p,_h(p,h,{text:f.slice(0,hn.maxText)}))}});n.push(...i.map(p=>`replace "${p.from.slice(0,40)}" → "${p.to.slice(0,40)}": ${p.n} time${p.n===1?"":"s"}`))}const c=r.map((p,s)=>{if(!p||!Number.isFinite(p.at))throw Error(`cues[${s}].at must be timeline seconds`);if(p.text!=null&&typeof p.text!="string")throw Error(`cues[${s}].text must be text (null = delete the cue)`);if(typeof p.text=="string"&&p.text.length>hn.maxText)throw Error(`cues[${s}].text ≤ ${hn.maxText} characters`);let h=null;for(const f of a){const m=p.at-f.start;m<-hn.near||m>f.duration+hn.near||f.captions.forEach((g,v)=>{const x=m<g.start?g.start-m:m>=g.end?m-g.end:0;x<=hn.near&&(!h||x<h.d||x===h.d&&(f.track??0)>(h.c.track??0))&&(h={c:f,k:v,d:x})})}if(!h)throw Error(`cues[${s}]: no subtitle shows at ${p.at} s`);return{...h,i:s,text:typeof p.text=="string"?p.text.normalize("NFC").trim():""}}),u=new Set;for(const p of c){const s=`${p.c.id}#${p.k}`;if(u.has(s))throw Error(`cues[${p.i}]: the same subtitle is edited twice`);u.add(s)}for(const p of[...c].sort((s,h)=>s.c.id<h.c.id?-1:s.c.id>h.c.id?1:h.k-s.k)){const s=p.c.captions[p.k].text,h=+(p.c.start+p.c.captions[p.k].start).toFixed(2);Object.assign(p.c,_h(p.c,p.k,p.text?{text:p.text}:null)),n.push(p.text?`subtitle @${h}s: "${s.slice(0,40)}" → "${p.text.slice(0,40)}"`:`subtitle @${h}s deleted: "${s.slice(0,40)}"`)}return n}const Md={rotation:[-Hs,Hs],brightness:[0,2],contrast:[0,2],exposure:[-3,3],saturation:[0,2],hue:[-180,180],audioFadeIn:[0,600],audioFadeOut:[0,600],volume:[0,1]},LM=["flipX","flipY","reverse","colorBypass","motionBlur","disabled"],Ys=["analyzeFootage","exportVideo","setExportFormat","play","pause","seek","undo","redo"];function FM(t,e){const o=structuredClone(t),r=e.property;if(e.op==="setClipProperty"){if(r in Md){const[a,n]=Md[r],i=e.numberValue;if(!Number.isFinite(i)||i<a||i>n)throw Error("Invalid clip value");o[r]=i}else if(LM.includes(r)){if(typeof e.booleanValue!="boolean")throw Error("Invalid clip flag");o[r]=e.booleanValue}else if(r==="blend"){const a=e.blend??e.preset;if(!Vh.includes(a))throw Error(`blend must be ${Vh.join(" | ")}`);a==="normal"?delete o.blend:o.blend=a}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 a=hd(o,e.numberValue);for(const n of Object.keys(o))n in a||delete o[n];Object.assign(o,a)}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=qu(o,e.motionKeys),delete o.posX,delete o.posY,delete o.scale,o.motionV=2,o.motionKeys.some(a=>a.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,d4(o)),jn(o),o}const Cp=.35,NM=2e3,RM=1200;function DM(t,e,o=.25){const r=t?.beats;if(!Array.isArray(r)||!r.length||!((t.confidence??0)>=Cp))return e;let a=0,n=r.length-1;for(;a<n;){const c=a+n>>1;r[c]<e?a=c+1:n=c}const i=[r[a],r[a-1]].filter(c=>c!==void 0).sort((c,u)=>Math.abs(c-e)-Math.abs(u-e))[0];return Math.abs(i-e)<=o?i:e}function BM(t){if(t==null)return null;const e=i=>Array.isArray(i)&&i.length<=NM&&i.every((c,u)=>Number.isFinite(c)&&c>=0&&c<=3600&&(u===0||c>i[u-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");const r=Array.isArray(t.hits)&&t.hits.length<=RM&&t.hits.every((i,c)=>Number.isFinite(i)&&i>=0&&i<=3600&&(c===0||i>t.hits[c-1])),a=r?t.hits:[],n=r&&Array.isArray(t.hitStrength)&&t.hitStrength.length===a.length&&t.hitStrength.every(i=>Number.isFinite(i)&&i>=0&&i<=1);return{bpm:o,confidence:Math.max(0,Math.min(1,Number(t.confidence)||0)),beats:t.beats,downbeats:t.downbeats??[],drops:t.drops??[],...a.length?{hits:a,hitStrength:n?t.hitStrength:a.map(()=>1)}:{},duration:Number(t.duration)||0}}const _M=t=>Math.round(t*1e3)/1e3;function VM(t,e){const o=[];for(const r of t){const a=e.find(c=>c.id===r.nodeId)?.beats;if(!Array.isArray(a?.beats)||!((a.confidence??0)>=Cp)||r.reverse)continue;const n=Number(r.playbackRate)||1,i=Number(r.inPoint)||0;for(const c of a.beats)c>=i-1e-6&&c<i+r.duration*n-1e-6&&o.push(_M(r.start+(c-i)/n))}return[...new Set(o)].sort((r,a)=>r-a)}const GM=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"}))]);GM.map(t=>t.id);function Xj(t,e="speed",o=30,r=20,a=24){const n=t==="montage"?[{u:0,speed:3},{u:1,speed:3}]:Sw[t];if(!n)throw Error(`Unknown curve ${t}`);const i=n.map(s=>({t:s.u,speed:s.speed,...s.ease?{ease:s.ease}:{}})),c=Array.from({length:a+1},(s,h)=>Iw(i,h/a));let u;if(e==="value"){let s=0;u=c.map((f,m)=>m?s+=(f+c[m-1])/2/a:0).map(f=>f/(s||1))}else{const s=Math.max(...c),h=Math.min(...c);u=c.map(f=>s-h<1e-6?.5:(f-h)/(s-h))}const p=2;return u.map((s,h)=>[+(p+(o-2*p)*h/a).toFixed(2),+(r-p-(r-2*p)*s).toFixed(2)])}const xm=Object.freeze([.5,1,2,4]);function KM(t,e,o,r=1){const a=(t||[]).filter(Number.isFinite);if(a.length<2||!(e>0))return[];const n=r===.5?a.flatMap((p,s)=>s<a.length-1?[p,(p+a[s+1])/2]:[p]):a,i=r===.5?1:r;let c=0;for(let p=1;p<n.length;p++)Math.abs(n[p]-o)<Math.abs(n[c]-o)&&(c=p);const u=[];for(let p=0;p<e;p++){const s=c+p*i,h=s+i;if(h>=n.length)break;u.push({start:+n[s].toFixed(3),duration:+(n[h]-n[s]).toFixed(3)})}return u}const ky=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}}),vd=Object.keys(ky);function WM(t="all",e=.5,o={}){const r=ky[t];if(!r)throw Error(`Shake axis must be one of ${vd.join(", ")}`);const a=Math.max(.1,Math.min(1,Number.isFinite(e)?e:.5)),n=(i,c)=>Math.max(0,Math.min(1,Number.isFinite(i)?i:c));if(t==="custom"){const i={x:.03*n(o.amountX,.5),y:.03*n(o.amountY,.5),rot:3.2*n(o.amountRot,.3)},c=["x","y","rot"].filter(u=>i[u]>1e-6);if(!c.length)throw Error("Custom shake needs some amountX, amountY or amountRot");return{props:c,amp:Object.fromEntries(c.map(u=>[u,+(i[u]*a*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]*a*2).toFixed(4)])),freq:r.freq}}const xy=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]}),Mm=Object.keys(xy),Uj=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"}]),_c=Object.freeze(["zoom-in-start","zoom-in-end","zoom-out-start","zoom-out-end"]);function HM(t,e,o=1,r=.25,a){if(!_c.includes(t))throw Error(`zoomMove preset must be one of ${_c.join(", ")}`);const n=Math.max(.05,Math.min(1,Number.isFinite(r)?r:.25)),i=Math.max(.2,Math.min(e,Number.isFinite(a)?a:Math.min(1.2,e/3))),c=t.startsWith("zoom-in"),u=t.endsWith("start"),p=+(o*(1+n)).toFixed(4),s=+o.toFixed(4),h=c?u?+(o/(1+n)).toFixed(4):p:u?p:+(o/(1+n)).toFixed(4);return u?[{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 Yj=Object.freeze({min:.1,max:1}),su=1,vm=Object.freeze(["color","number","bool","choice"]),$m=Object.freeze(["chieu.blend","generator.py"]),sr=Object.freeze({params:16,seconds:10,fps:[24,25,30,60],width:3840,height:3840,tags:24,sfx:4}),qj=Object.freeze(["draft","standard","film"]),$d=Object.freeze([Object.freeze({key:"sceneLight",type:"number",min:0,max:2,step:.05,default:1,label:"Ánh sáng hắt",labelEn:"Light on the scene"}),Object.freeze({key:"debris",type:"number",min:0,max:2,step:.05,default:1,label:"Đá văng",labelEn:"Flying rocks"}),Object.freeze({key:"dust",type:"number",min:0,max:2,step:.05,default:1,label:"Bụi cuộn",labelEn:"Dust wave"}),Object.freeze({key:"cracks",type:"bool",default:!0,label:"Nứt đất",labelEn:"Ground cracks"}),Object.freeze({key:"airShock",type:"number",min:0,max:2,step:.05,default:1,label:"Sóng khí (méo hình)",labelEn:"Air shock (distortion)"})]),Em=["ground","radius","tail","debris","dust","shock","cracks","seed","at","wall"],XM=t=>Math.round((t.duration+(t.scene?.tail??0))*1e3)/1e3,UM=t=>t.scene?[...t.params,...$d]:t.params;function YM(t){if(t==null)return null;(typeof t!="object"||Array.isArray(t)||Object.keys(t).some(r=>!Em.includes(r)))&&me("scene",`{${Em.join(", ")}}`);const e=(r,a,n,i)=>{const c=t[r]??i;return(!Sr(c)||c<a||c>n)&&me(`scene.${r}`,`${a}..${n}`),c},o={ground:e("ground",-10,0,-1.2),radius:e("radius",.2,12,2.2),tail:e("tail",0,4,1.5),debris:e("debris",0,2,1),dust:e("dust",0,2,1),shock:e("shock",0,2,1),cracks:t.cracks??!0,seed:e("seed",0,99999,11),wall:e("wall",0,6,.9)};return typeof o.cracks!="boolean"&&me("scene.cracks","true | false"),Number.isInteger(o.seed)||me("scene.seed","integer"),t.at!==void 0&&((!Array.isArray(t.at)||t.at.length!==3||!t.at.every(r=>Sr(r)&&Math.abs(r)<=20))&&me("scene.at","[x, y, z] metres"),o.at=[...t.at]),o}const qM=t=>`/vfx-presets/${t}/preview.webm`,Zj=t=>`/vfx-presets/${t}/poster.jpg`,ZM=(t,e)=>`/vfx-presets/${t}/preview-${e}.webm`,JM=Object.freeze(["light","distort"]),QM=/^[a-z0-9][a-z0-9-]{1,63}$/,Sm=/^[a-z][a-zA-Z0-9_]{0,31}$/,My=/^#[0-9a-fA-F]{6}$/,me=(t,e)=>{throw Error(`${t}: ${e}`)},Sr=t=>typeof t=="number"&&Number.isFinite(t),$n=(t,e)=>typeof t=="string"&&t.trim()&&t.length<=e;function tv(t,e){const o=`params[${e}]`;(!t||typeof t!="object")&&me(o,"object"),Sm.test(t.key??"")||me(`${o}.key`,"a-z start, letters / digits / _ (≤ 32)"),vm.includes(t.type)||me(`${o}.type`,vm.join(" | ")),(!$n(t.label,40)||!$n(t.labelEn,40))&&me(`${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"&&(My.test(t.default??"")||me(`${o}.default`,"#RRGGBB"),r.default=t.default.toLowerCase()),t.type==="bool"&&(typeof t.default!="boolean"&&me(`${o}.default`,"true | false"),r.default=t.default),t.type==="number"&&((!Sr(t.min)||!Sr(t.max)||!(t.min<t.max))&&me(`${o}.min`,"min < max"),(!Sr(t.default)||t.default<t.min||t.default>t.max)&&me(`${o}.default`,`${t.min}..${t.max}`),Object.assign(r,{min:t.min,max:t.max,default:t.default,step:Sr(t.step)&&t.step>0?t.step:(t.max-t.min)/100}),t.unit!==void 0&&($n(t.unit,8)||me(`${o}.unit`,"≤ 8 chars"),r.unit=t.unit)),t.type==="choice"){const a=Array.isArray(t.options)?t.options:[];(a.length<2||a.length>12||a.some(n=>!n||!Sm.test(n.value??"")||!$n(n.label,40)||!$n(n.labelEn,40)))&&me(`${o}.options`,"2–12 {value, label, labelEn}"),a.some(n=>n.value===t.default)||me(`${o}.default`,"one of the options"),Object.assign(r,{options:a.map(n=>({value:n.value,label:n.label.trim(),labelEn:n.labelEn.trim()})),default:t.default})}return r}function ev(t,{allowScript:e=!1}={}){(!t||typeof t!="object"||Array.isArray(t))&&me("chieu.json","object"),QM.test(t.id??"")||me("id","lowercase a-z0-9-, 2–64 chars"),(t.version??1)!==su&&me("version",`must be ${su}`),(!$n(t.name,60)||!$n(t.nameEn,60))&&me("name","name + nameEn (1–60 chars)"),$m.includes(t.entry)||me("entry",$m.join(" | ")),t.entry==="generator.py"&&!e&&me("entry","a Plug-in Store move is a .blend (no Python runs from a partner's file)"),(!Sr(t.duration)||t.duration<.2||t.duration>sr.seconds)&&me("duration",`0.2..${sr.seconds} s`);const o=t.fps??30;sr.fps.includes(o)||me("fps",sr.fps.join(" | "));const r=t.width??1920,a=t.height??1080;(!Number.isInteger(r)||!Number.isInteger(a)||r<64||a<64||r>sr.width||a>sr.height||r%2||a%2)&&me("width","even 64..3840");const n=t.impact??0;(!Sr(n)||n<0||n>t.duration)&&me("impact","0..duration");const i=t.emit??[.5,.5];(!Array.isArray(i)||i.length!==2||!i.every(m=>Sr(m)&&m>=0&&m<=1))&&me("emit","[u, v] 0..1");const c=t.tags??[];(!Array.isArray(c)||c.length>sr.tags||c.some(m=>!$n(m,30)))&&me("tags",`≤ ${sr.tags} short strings`);const u=t.sfx??[];(!Array.isArray(u)||u.length>sr.sfx||u.some(m=>!m||!/^[a-z0-9-]{2,64}$/.test(m.id??"")||!Sr(m.at)||m.at<0||m.at>t.duration))&&me("sfx",`≤ ${sr.sfx} {id, at}`);let p=null;if(t.shake!=null){const m=t.shake;(!Sr(m.at)||!Sr(m.duration)||!Sr(m.intensity)||m.at<0||m.duration<=0||m.duration>2||m.intensity<=0||m.intensity>1)&&me("shake","{at, duration ≤ 2, intensity 0..1}"),p={at:m.at,duration:m.duration,intensity:m.intensity}}const s=Array.isArray(t.params)?t.params:me("params","array");s.length>sr.params&&me("params",`≤ ${sr.params}`);const h=s.map(tv);new Set(h.map(m=>m.key)).size!==h.length&&me("params","keys must be unique");const f=YM(t.scene);return f&&h.some(m=>$d.some(g=>g.key===m.key))&&me("params",`${$d.map(m=>m.key).join(", ")} belong to the scene`),f&&t.duration+f.tail>sr.seconds&&me("scene.tail",`duration + tail ≤ ${sr.seconds} s`),{id:t.id,version:su,name:t.name.trim(),nameEn:t.nameEn.trim(),...$n(t.desc,200)?{desc:t.desc.trim()}:{},...$n(t.descEn,200)?{descEn:t.descEn.trim()}:{},entry:t.entry,duration:t.duration,fps:o,width:r,height:a,impact:n,emit:[i[0],i[1]],tags:c.map(m=>m.trim().toLowerCase()),sfx:u.map(m=>({id:m.id,at:m.at})),...p?{shake:p}:{},params:h,...f?{scene:f}:{}}}function ov(t,e={}){if(e&&typeof e!="object")throw Error("params: object");const o=UM(t),r=new Set(o.map(n=>n.key));for(const n of Object.keys(e||{}))if(!r.has(n))throw Error(`params.${n}: unknown — ${[...r].join(", ")}`);const a={};for(const n of o){const i=e?.[n.key];if(i==null){a[n.key]=n.default;continue}if(n.type==="color"){if(!My.test(String(i)))throw Error(`params.${n.key}: #RRGGBB`);a[n.key]=String(i).toLowerCase()}else if(n.type==="bool"){if(typeof i!="boolean")throw Error(`params.${n.key}: true | false`);a[n.key]=i}else if(n.type==="choice"){if(!n.options.some(c=>c.value===i))throw Error(`params.${n.key}: ${n.options.map(c=>c.value).join(" | ")}`);a[n.key]=i}else{const c=Number(i);if(!Number.isFinite(c))throw Error(`params.${n.key}: number ${n.min}..${n.max}`);a[n.key]=Math.round(Math.min(n.max,Math.max(n.min,c))*1e4)/1e4}}return a}const rv=[{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"}],scene:{ground:-1.2,radius:1.8,tail:1.2,debris:.6}},{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"}],scene:{ground:-1.2,radius:1.6,tail:1.2,debris:.5,dust:.7,shock:1.2}},{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"}],scene:{ground:-2.45,radius:2.6,tail:1.6,at:[0,0,-2.3],wall:0,debris:1.3,dust:1.2}},{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"}],scene:{ground:-1.2,radius:2.2,tail:1.6}},{id:"cong-khong-gian",version:1,name:"Cổng Không Gian Plexus",nameEn:"Spatial Rift Portal",desc:"Vòng xoáy không gian phát sáng xanh băng kèm mạng lưới tinh tú hình học và hạt năng lượng quay quanh",descEn:"Luminous swirling cyan spatial rift ring with geometric constellation plexus splines and orbiting star motes",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.35,emit:[.5,.5],tags:["cong khong gian","cổng không gian","portal","rift","plexus","dich chuyen","dịch chuyển","xanh bang","donghua","scifi","vo hiep"],sfx:[{id:"sp-whoosh-transition-1",at:.1},{id:"sp-sub-hit-1",at:.35}],shake:{at:.35,duration:.4,intensity:.45},params:[{key:"color",type:"color",default:"#14e8ff",label:"Màu cổng",labelEn:"Portal colour"},{key:"color2",type:"color",default:"#9d4edd",label:"Màu tinh tú",labelEn:"Plexus colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{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:.85,label:"Phát sáng",labelEn:"Glow"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}],scene:{ground:-1.6,radius:2.4,tail:.8,debris:.3,dust:.6,shock:1,cracks:!1}},{id:"bien-lua-cuon",version:1,name:"Biển Lửa Cuộn Hỏa Liên",nameEn:"Swirling Flame Tsunami",desc:"Sóng lửa 3D cuộn xoáy đỏ cam lõi vàng trắng kèm sương lửa thể tích và hàng trăm tàn lửa bốc lên",descEn:"Monumental curling 3D incandescent flame wave ribbons with volumetric fire mist and rising molten embers",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.3,emit:[.5,.6],tags:["bien lua","biển lửa","hoa lien","hỏa liên","lua","fire","flame","tsunami","donghua","vo hiep","combat"],sfx:[{id:"sp-whoosh-transition-1",at:.1},{id:"sp-sub-hit-1",at:.3}],shake:{at:.3,duration:.55,intensity:.65},params:[{key:"color",type:"color",default:"#ff4d0a",label:"Màu lửa chính",labelEn:"Flame colour"},{key:"color2",type:"color",default:"#ffcf24",label:"Màu lõi lửa",labelEn:"Core colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{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:.85,label:"Phát sáng",labelEn:"Glow"},{key:"mist",type:"bool",default:!0,label:"Khói lửa thể tích",labelEn:"Volumetric fire mist"}],scene:{ground:-1.2,radius:2.4,tail:1,debris:.4,dust:.9,shock:1}},{id:"van-kiem-linh-hon",version:1,name:"Vạn Kiếm Quy Tông",nameEn:"Astral Spirit Sword Swarm",desc:"Hàng chục linh kiếm phát sáng xanh băng bạc xoay quỹ đạo 3D hội tụ và lao vút kèm dải kiếm khí thể tích",descEn:"Swarm of luminous astral spirit blades orbiting in 3D helical streams with trailing sword-qi ribbons and volumetric aura",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.45,emit:[.5,.5],tags:["van kiem","vạn kiếm","kiem tran","kiếm trận","linh kiem","sword swarm","blades","kiem khi","donghua","vo hiep","tien hiep"],sfx:[{id:"sp-whoosh-transition-1",at:.1},{id:"sp-sub-hit-1",at:.45}],shake:{at:.45,duration:.45,intensity:.5},params:[{key:"color",type:"color",default:"#22d3ee",label:"Màu kiếm khí",labelEn:"Blade colour"},{key:"color2",type:"color",default:"#e0f2fe",label:"Màu lõi kiếm",labelEn:"Core colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{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:.85,label:"Phát sáng",labelEn:"Glow"},{key:"mist",type:"bool",default:!0,label:"Sương kiếm khí",labelEn:"Volumetric mist"}],scene:{ground:-1.4,radius:2,tail:1,debris:.8,dust:.6,shock:1.2}},{id:"cot-anh-sang-trieu-hoi",version:1,name:"Cột Năng Lượng Triệu Hồi",nameEn:"Celestial Summoning Pillar",desc:"Cột ánh sáng năng lượng thẳng đứng từ trời xuống kèm các vòng pháp trận xoay ngược chiều, dải khí xoắn và bụi sáng bay lên",descEn:"Towering vertical celestial energy beam with counter-rotating arcane rings, ascending plasma ribbons, and rising light motes",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.25,emit:[.5,.85],tags:["cot anh sang","cột ánh sáng","trieu hoi","triệu hồi","phap tran","pháp trận","pillar","beam","summon","celestial","donghua","tien hiep"],sfx:[{id:"sp-sub-hit-1",at:.25},{id:"sp-whoosh-transition-1",at:.05}],shake:{at:.25,duration:.5,intensity:.6},params:[{key:"color",type:"color",default:"#38bdf8",label:"Màu cột sáng",labelEn:"Beam colour"},{key:"color2",type:"color",default:"#fbbf24",label:"Màu vòng pháp trận",labelEn:"Rune ring colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{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:.85,label:"Phát sáng",labelEn:"Glow"},{key:"mist",type:"bool",default:!0,label:"Sương năng lượng",labelEn:"Volumetric mist"}],scene:{ground:-2.25,radius:2.8,tail:1,at:[0,0,-2.15],wall:0,debris:.8,dust:1}},{id:"tieu-canh-kiem-tran",version:1,name:"Tiểu Canh Kiếm Trận",nameEn:"Lesser Geng Sword Array",desc:"Kiếm trận 3 tầng chuẩn Tiên Hiệp 3D: vầng hào quang 72 phi kiếm vàng kim, trận pháp Bát Quái cổ văn, 32 cự kiếm ngọc bích tỏa 360°, mạng lôi điện Canh Kim và đá vỡ lơ lửng",descEn:"Three-tier Xianxia 3D sword array: 72-blade golden sun-wheel halo, rotating Daoist Bagua rune rings, 32 radial emerald-silver giant spirit swords, crackling golden lightning web, and suspended debris",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.42,emit:[.5,.5],tags:["tieu canh kiem tran","tiểu canh kiếm trận","pham nhan tu tien","phàm nhân tu tiên","han lap","hàn lập","kiem tran","kiếm trận","van kiem","vạn kiếm","bat quai","bát quái","sword array","sword formation","xianxia","donghua","tien hiep"],sfx:[{id:"sp-whoosh-transition-1",at:.08},{id:"sp-sub-hit-1",at:.42}],shake:{at:.42,duration:.48,intensity:.58},params:[{key:"color",type:"color",default:"#34f5b5",label:"Màu cự kiếm ngọc",labelEn:"Jade blade colour"},{key:"color2",type:"color",default:"#ffd466",label:"Màu hào quang vàng",labelEn:"Gold halo colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ xoay",labelEn:"Rotation speed"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Quy mô trận",labelEn:"Array scale"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.9,label:"Phát sáng HDR",labelEn:"HDR Glow"},{key:"mist",type:"bool",default:!0,label:"Khói khí & đá vỡ",labelEn:"Mist & debris"}],scene:{ground:-1.4,radius:2.2,tail:1,debris:.8,dust:.6,shock:1.2}},{id:"kiem-luan-thai-duong",version:1,name:"Hào Quang Kiếm Luân Thái Dương",nameEn:"Imperial Golden Sword Sun-Wheel Halo",desc:"Vầng hào quang 96 phi kiếm vàng kim xếp 2 tầng dày đặc tỏa sau lưng nhân vật, vòng tâm ngọc bích phát sáng, lôi điện Canh Kim và khí quang vàng bốc lên từ dưới chân",descEn:"Radiant 96-blade imperial gold sun-wheel sword halo framing a hero silhouette, inner emerald-jade sacred seal, golden lightning arcs, and rising warm ground aura",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.36,emit:[.5,.5],tags:["kiem luan","kiếm luân","thai duong","thái dương","hao quang","hào quang","phi kiem","phi kiếm","vang kim","vàng kim","han lap","hàn lập","pham nhan tu tien","sword halo","golden halo","xianxia","donghua"],sfx:[{id:"sp-whoosh-transition-1",at:.08},{id:"sp-sub-hit-1",at:.36}],shake:{at:.36,duration:.42,intensity:.5},params:[{key:"color",type:"color",default:"#ffbe3b",label:"Màu hào quang vàng",labelEn:"Imperial gold colour"},{key:"color2",type:"color",default:"#34f5b5",label:"Màu vòng tâm ngọc",labelEn:"Inner jade seal"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ xoay",labelEn:"Spin speed"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Halo scale"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.9,label:"Phát sáng HDR",labelEn:"HDR Glow"},{key:"mist",type:"bool",default:!0,label:"Khí quang vàng chân",labelEn:"Rising golden mist"}],scene:{ground:-1.4,radius:2.2,tail:1,debris:.8,dust:.6,shock:1.2}},{id:"bat-quai-cuu-thien",version:1,name:"Trận Pháp Bát Quái Cửu Thiên",nameEn:"Nine-Heavens Bagua Lightning Formation",desc:"Đại trận Bát Quái cổ văn 6 tầng xoay ngược chiều chuẩn Tiên Hiệp 3D, ngôi sao 12 cánh, 3 đợt sóng xung kích khí áp trong suốt, mạng lôi điện và đá vỡ lơ lửng",descEn:"Six-layer counter-rotating 3D Daoist Bagua & dodecagram magic array with three expanding optical air-pressure shockwave ripples, high-voltage lightning web, and suspended debris",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.4,emit:[.5,.5],tags:["bat quai","bát quái","tran phap","trận pháp","cuu thien","cửu thiên","co van","cổ văn","loi dien","lôi điện","pham nhan tu tien","magic circle","bagua","rune array","xianxia","donghua"],sfx:[{id:"sp-whoosh-transition-1",at:.08},{id:"sp-sub-hit-1",at:.4}],shake:{at:.4,duration:.45,intensity:.55},params:[{key:"color",type:"color",default:"#38f5d2",label:"Màu trận pháp chính",labelEn:"Primary array colour"},{key:"color2",type:"color",default:"#ffd466",label:"Màu cổ văn & sét vàng",labelEn:"Gold rune & lightning"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ xoay",labelEn:"Rotation speed"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Quy mô trận",labelEn:"Array scale"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.9,label:"Phát sáng HDR",labelEn:"HDR Glow"},{key:"mist",type:"bool",default:!0,label:"Sóng khí áp & đá vỡ",labelEn:"Shockwaves & debris"}],scene:{ground:-1.6,radius:2.6,tail:1,debris:1,dust:.8,shock:1.4}}],nv=Object.freeze(rv.map(t=>Object.freeze(ev(t,{allowScript:!0})))),av=t=>nv.find(e=>e.id===t)??null,De=Object.freeze({points:21,slots:2,maxSeconds:20,maxFrames:600,fps:[15,30]}),Cl=Object.freeze({wrist:0,thumb:4,index:8,middle:12,ring:16,pinky:20,indexBase:5,middleBase:9}),Vc=Object.freeze(["pinch","index","thumb","middle","ring","pinky","wrist","palm"]),Ed=Object.freeze(["any","right","left"]),Gc=1+De.points*4,Sd=-.5,Id=2,yo=t=>Math.round(t*1e4)/1e4,Vs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",jl=Object.fromEntries([...Vs].map((t,e)=>[t,e]));function Im(t){let e="";for(let o=0;o<t.length;o+=3){const r=t[o],a=t[o+1]??0,n=t[o+2]??0,i=r<<16|a<<8|n;e+=Vs[i>>18&63]+Vs[i>>12&63]+(o+1<t.length?Vs[i>>6&63]:"=")+(o+2<t.length?Vs[i&63]:"=")}return e}function Am(t){const e=t.replace(/=+$/,""),o=new Uint8Array(Math.floor(e.length*3/4));let r=0;for(let a=0;a<e.length;a+=4){const n=jl[e[a]]<<18|jl[e[a+1]]<<12|(jl[e[a+2]]??0)<<6|(jl[e[a+3]]??0);r<o.length&&(o[r++]=n>>16&255),r<o.length&&(o[r++]=n>>8&255),r<o.length&&(o[r++]=n&255)}return o}function Jj({mw:t,mh:e,fps:o,s0:r,frames:a}){const n=Math.min(De.maxFrames,a.length),i=new Uint8Array(n*De.slots*Gc),c=new DataView(i.buffer);for(let p=0;p<n;p++)for(let s=0;s<De.slots;s++){const h=a[p]?.[s],f=(p*De.slots+s)*Gc;if(!(!h?.lm||h.lm.length<De.points)){i[f]=Math.max(1,Math.min(255,Math.round((Number.isFinite(h.score)?h.score:1)*255)));for(let m=0;m<De.points;m++)for(let g=0;g<2;g++){const v=Math.max(0,Math.min(65535,Math.round((h.lm[m][g]-Sd)/Id*65535)));c.setUint16(f+1+(m*2+g)*2,v,!0)}}}let u=null;if(a.slice(0,n).some(p=>p?.some(s=>Array.isArray(s?.edge)))){const p=new Int8Array(n*De.slots*nn);for(let s=0;s<n;s++)for(let h=0;h<De.slots;h++){const f=a[s]?.[h]?.edge;if(Array.isArray(f))for(let m=0;m<nn;m++)p[(s*De.slots+h)*nn+m]=Math.max(-127,Math.min(127,Math.round((f[m]||0)*Gi.unit)))}u=Im(new Uint8Array(p.buffer))}return iv({v:1,mw:Math.round(t),mh:Math.round(e),fps:o,s0:yo(r),n,data:Im(i),...u?{edge:u}:{}})}function iv(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||!De.fps.includes(t.fps)||!Number.isFinite(t.s0)||t.s0<0||t.s0>36e3||!Number.isInteger(t.n)||t.n<1||t.n>De.maxFrames||typeof t.data!="string"||!/^[A-Za-z0-9+/]*={0,2}$/.test(t.data)||Math.floor(t.data.replace(/=+$/,"").length*3/4)!==t.n*De.slots*Gc||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*De.slots*nn))throw Error("Invalid hand track");return t}const As=new Map;function fl(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=Am(t.data),a=new DataView(r.buffer),n=[],i=t.edge?new Int8Array(Am(t.edge).buffer):null;for(let u=0;u<t.n;u++){const p=[];for(let s=0;s<De.slots;s++){const h=(u*De.slots+s)*Gc;if(!r[h]){p.push(null);continue}const f=[];for(let g=0;g<De.points;g++)f.push([Sd+a.getUint16(h+1+g*4,!0)/65535*Id,Sd+a.getUint16(h+3+g*4,!0)/65535*Id]);const m=i?Array.from(i.subarray((u*De.slots+s)*nn,(u*De.slots+s+1)*nn),g=>g/Gi.unit):null;p.push({lm:f,score:r[h]/255,...m?{edge:m}:{}})}n.push(p)}const c={fps:t.fps,s0:t.s0,n:t.n,mw:t.mw,mh:t.mh,frames:n};return As.size>16&&As.delete(As.keys().next().value),As.set(e,c),c}const Kc=(t,e)=>(t.inPoint||0)+e*(t.playbackRate||1),vy=(t,e)=>(e-(t.inPoint||0))/(t.playbackRate||1);function lu(t,e,o){const r=t?.hands;if(!r)return!1;const a=Kc(t,e),n=Kc(t,e+o),i=r.s0+(r.n-1)/r.fps;return a>=r.s0-1.5/r.fps&&n<=i+1.5/r.fps}const $y=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o];function Wc(t,e,o){const r=(e-t.s0)*t.fps;if(r<-.5||r>t.n-.5)return null;const a=Math.max(0,Math.min(t.n-1,Math.floor(r))),n=Math.min(t.n-1,a+1),i=Math.max(0,Math.min(1,r-a)),c=t.frames[a][o],u=t.frames[n][o];if(c&&u)return c.lm.map((s,h)=>$y(s,u.lm[h],i));const p=i<.5?c:u;return p?p.lm:null}function sv(t,e,o="any"){return o==="right"?0:o==="left"?1:Wc(t,e,0)?0:Wc(t,e,1)?1:0}const Ey=(t,e,o)=>Math.hypot((t[0][0]-t[9][0])*e,(t[0][1]-t[9][1])*o);function Vi(t,e="index"){if(e==="pinch")return $y(t[Cl.thumb],t[Cl.index],.5);if(e==="palm"){const o=[0,5,9,13,17];return[o.reduce((r,a)=>r+t[a][0],0)/5,o.reduce((r,a)=>r+t[a][1],0)/5]}return t[Cl[e]??Cl.index]}const na=Object.freeze({on:.3,off:.46,hold:2,minHold:.2}),yi=Object.freeze({fast:2.2,back:1,cos:-.25,gap:.35,window:3});function lv(t){const e=[];for(let o=0;o<De.slots;o++){let r=!1,a=!1,n=0,i=0,c=-1/0;const u=[],p=[],s=[];for(let f=0;f<t.n;f++){const m=t.frames[f][o];if(!m){u.push(null),p.push(null),s.push(!1);continue}const g=Ey(m.lm,t.mw,t.mh)||1;u.push(Math.hypot((m.lm[4][0]-m.lm[8][0])*t.mw,(m.lm[4][1]-m.lm[8][1])*t.mh)/g),p.push([m.lm[8][0]*t.mw/g,m.lm[8][1]*t.mh/g,Math.hypot((m.lm[8][0]-m.lm[5][0])*t.mw,(m.lm[8][1]-m.lm[5][1])*t.mh)/g]),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],g=u[f];if(!m){if(i++,r&&i>=3){const F=t.frames[f-i]?.[o],N=F?Vi(F.lm,"pinch"):[.5,.5];e.push({type:"release",s:yo(h(f-i)),slot:o,u:yo(N[0]),v:yo(N[1])}),r=!1}n=0;continue}if(i=0,r){if(n=g>na.off?n+1:0,n>=na.hold){const F=f-na.hold+1,N=Vi(t.frames[F][o].lm,"pinch");e.push({type:"release",s:yo(h(F)),slot:o,u:yo(N[0]),v:yo(N[1])}),r=!1,n=0}}else if(g>na.off&&(a=!0),n=a&&g<na.on?n+1:0,n>=na.hold){const F=f-na.hold+1,N=Vi(t.frames[F][o].lm,"pinch");e.push({type:"pinch",s:yo(h(F)),slot:o,u:yo(N[0]),v:yo(N[1])}),r=!0,a=!1,n=0}const v=Math.max(1,Math.round(yi.window*t.fps/30)),x=f-v,E=f+v;if(r||x<0||E>=t.n||!s[x]||!s[E]||!p[f]||u[f]<na.off||p[f][2]<.55||h(f)-c<yi.gap)continue;const $=v/t.fps,S=[(p[f][0]-p[x][0])/$,(p[f][1]-p[x][1])/$],k=[(p[E][0]-p[f][0])/$,(p[E][1]-p[f][1])/$],y=Math.hypot(...S),C=Math.hypot(...k);if(y<yi.fast||C<yi.back||(S[0]*k[0]+S[1]*k[1])/(y*C)>yi.cos)continue;let z=f,j=-1/0;for(let F=x;F<=E;F++)if(p[F]){const N=p[F][0]*S[0]+p[F][1]*S[1];N>j&&(j=N,z=F)}if(h(z)-c<yi.gap)continue;const P=t.frames[z][o].lm[8];e.push({type:"tap",s:yo(h(z)),slot:o,u:yo(P[0]),v:yo(P[1])}),c=h(z)}if(r){const f=[...t.frames].reverse().find(g=>g[o])?.[o],m=f?Vi(f.lm,"pinch"):[.5,.5];e.push({type:"release",s:yo(t.s0+(t.n-1)/t.fps),slot:o,u:yo(m[0]),v:yo(m[1])})}}return e.sort((o,r)=>o.s-r.s||(o.type==="release"?-1:1))}const Li=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]],Ad=[2.4,1.6,.8],nn=Li.length*9+4+2*Ad.length,Qj=Object.freeze([0,1,2,3,4,5,nn-4,nn-3,nn-2,nn-1]);function Sy(t,e,o,{width:r=.17,arm:a=3.2}={}){const n=t.map(([P,F])=>[P*e,F*o]),i=Math.hypot(n[0][0]-n[9][0],n[0][1]-n[9][1])||1,c=(P,F)=>[P[0]-F[0],P[1]-F[1]],u=(P,F)=>[P[0]+F[0],P[1]+F[1]],p=(P,F)=>[P[0]*F,P[1]*F],s=P=>{const F=Math.hypot(P[0],P[1])||1;return[P[0]/F,P[1]/F]},h=P=>[-P[1],P[0]],f=(P,F)=>P[0]*F[0]+P[1]*F[1],m=[],g=(P,F,N,G=!0)=>m.push({anchor:P,dir:F,dist:N,snap:G}),v=s(c(n[0],n[9])),x=h(v),E=.36*i,$=f(x,c(n[1],n[0]))>0?1:-1,S=p(x,$),k=p(x,-$),y=u(n[0],p(v,a*i)),C=P=>u(n[0],p(v,P*i)),A=P=>E*(1+.1*P);g(y,k,A(a),!1),g(y,S,A(a),!1);for(const P of Ad)g(C(P),S,A(P));g(n[0],S,E);const z=u(n[0],p(S,E)),j=u(n[0],p(k,E));for(let P=0;P<Li.length;P++){const F=Li[P],N=F.map(tt=>n[tt]),G=P?n[Li[P-1][0]]:z,V=P<Li.length-1?n[Li[P+1][0]]:j,et=s(c(N[3],N[0])),U=h(et),at=f(U,c(G,N[0]))-f(U,c(V,N[0]))>=0?1:-1,W=p(U,at),_=p(W,-1),J=tt=>r*(P===0?1.15:1)*(1-.18*tt/3)*i/2;for(let tt=0;tt<3;tt++)g(N[tt],W,J(tt));g(N[3],W,J(3)),g(N[3],s(c(N[3],N[2])),J(3)*1.2),g(N[3],_,J(3));for(let tt=2;tt>=0;tt--)g(N[tt],_,J(tt))}g(n[0],k,E);for(const P of[...Ad].reverse())g(C(P),k,A(P));return{pts:m,S:i}}function cv(t,e,o,{width:r=.17,arm:a=3.2,edge:n=null,scale:i=1,grow:c=0}={}){const{pts:u,S:p}=Sy(t,e,o,{width:r,arm:a});return u.map((s,h)=>{const f=Math.max(0,s.dist*i+(n?.[h]??0)*p+c*p);return[yo((s.anchor[0]+s.dir[0]*f)/e),yo((s.anchor[1]+s.dir[1]*f)/o)]})}const Gi=Object.freeze({in:.6,out:.1,unit:200});function tT(t,e,o,r,a={}){const{pts:n,S:i}=Sy(t,e,o,a),c=t.map(([S,k])=>[S*e,k*o]),u=(S,k)=>{let y=0,C=0,A=0;for(let z=-1;z<=1;z++)for(let j=-1;j<=1;j++){const P=r(Math.round(S+j),Math.round(k+z));y+=P[0],C+=P[1],A+=P[2]}return[y/9,C/9,A/9]},p=(S,k)=>(S[0]-k[0])**2+(S[1]-k[1])**2+(S[2]-k[2])**2,s=(S,k)=>Math.min(...k.map(y=>p(S,y))),h=S=>[0,1,2].map(k=>S.map(y=>y[k]).sort((y,C)=>y-C)[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])=>u((c[S][0]+c[k][0])/2,(c[S][1]+c[k][1])/2));const m=[0,5,9,13,17].reduce((S,k)=>[S[0]+c[k][0]/5,S[1]+c[k][1]/5],[0,0]);f.push(u(m[0],m[1]));const g=h(f);if(f=f.filter(S=>p(S,g)<55**2),f.length<4)return null;let v=n.filter(S=>S.snap).map(S=>u(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=>p(S,g))))+12;if(v=v.filter(S=>Math.sqrt(s(S,f))>x),v.length<4)return null;const E=S=>s(S,f)<s(S,v),$=Math.max(.5,i/60);return n.map(S=>{if(!S.snap)return 0;const k=z=>u(S.anchor[0]+S.dir[0]*z,S.anchor[1]+S.dir[1]*z);if(!E(k(S.dist*.3)))return 0;const y=S.dist*(1-Gi.in),C=S.dist+Gi.out*i;let A=Math.max(S.dist*.3,y);for(;A<C&&E(k(A+$));)A+=$;return Math.round((Math.max(y,A+$/2)-S.dist)/i*Gi.unit)/Gi.unit})}const Go=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}}),Cd=Object.freeze(["x","y","z","rx","ry","rz","s"]),Iy={x:0,y:0,z:0,rx:0,ry:0,rz:0,s:1},Vo=t=>Math.round(t*1e6)/1e6,_o=t=>Math.round(t*1e3)/1e3,Ko=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],Or=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Be=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],Ar=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],kh=(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]],ci=t=>{const e=Math.hypot(...t)||1;return Be(t,1/e)},yr=(t,e)=>[Ar(t[0],e),Ar(t[1],e),Ar(t[2],e)],Kn=t=>[0,1,2].map(e=>[t[0][e],t[1][e],t[2][e]]),er=(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])),Ay=()=>[[1,0,0],[0,1,0],[0,0,1]],Tl=[[1,0,0],[0,-1,0],[0,0,-1]],jd=t=>[t[0],-t[1],-t[2]],Ol=t=>{if(!t.length)return 0;const e=[...t].sort((o,r)=>o-r);return e[e.length>>1]},Sn=Math.PI/180,pv=t=>[[1,0,0],[0,Math.cos(t),-Math.sin(t)],[0,Math.sin(t),Math.cos(t)]],uv=t=>[[Math.cos(t),0,Math.sin(t)],[0,1,0],[-Math.sin(t),0,Math.cos(t)]],dv=t=>[[Math.cos(t),-Math.sin(t),0],[Math.sin(t),Math.cos(t),0],[0,0,1]],Cy=(t,e,o)=>er(er(pv(t*Sn),uv(e*Sn)),dv(o*Sn));function jy(t,e,o){let r=!1;for(let a=0,n=t.length-1;a<t.length;n=a++){const[i,c]=t[a],[u,p]=t[n];c>o!=p>o&&e<(u-i)*(o-c)/(p-c)+i&&(r=!r)}return r}function hv(t){const e=[...t].sort((n,i)=>n[0]-i[0]||n[1]-i[1]);if(e.length<3)return e;const o=(n,i,c)=>(i[0]-n[0])*(c[1]-n[1])-(i[1]-n[1])*(c[0]-n[0]),r=[],a=[];for(const n of e){for(;r.length>=2&&o(r.at(-2),r.at(-1),n)<=0;)r.pop();r.push(n)}for(const n of[...e].reverse()){for(;a.length>=2&&o(a.at(-2),a.at(-1),n)<=0;)a.pop();a.push(n)}return[...r.slice(0,-1),...a.slice(0,-1)]}function fv(t,e,o,r){if(jy(t,e,o))return!0;for(let a=0,n=t.length-1;a<t.length;n=a++){const[i,c]=t[n],[u,p]=t[a],s=u-i,h=p-c,f=s*s+h*h,m=f?Math.max(0,Math.min(1,((e-i)*s+(o-c)*h)/f)):0;if(Math.hypot(i+m*s-e,c+m*h-o)<=r)return!0}return!1}function mv(t,e,o,{n:r=Go.seeds,minScore:a=1e-4,taken:n=[]}={}){const{w:i,h:c,data:u}=t,p=4,s=Math.max(p,Math.floor(o[0])),h=Math.max(p,Math.floor(o[1])),f=Math.min(i-p-1,Math.ceil(o[2])),m=Math.min(c-p-1,Math.ceil(o[3]));if(!(f>s&&m>h))return[];let g=0;for(let $=h;$<=m;$+=2)for(let S=s;S<=f;S+=2)e(S,$)&&(g+=4);const v=Math.max(5,Math.sqrt(g/Math.max(1,r))),x=[],E=($,S)=>n.some(k=>Math.abs(k[0]-$)<v*.7&&Math.abs(k[1]-S)<v*.7);for(let $=h;$<=m;$+=v)for(let S=s;S<=f;S+=v){let k=null;for(let y=Math.round($);y<Math.min(m+1,$+v);y++)for(let C=Math.round(S);C<Math.min(f+1,S+v);C++){if(!e(C,y))continue;let A=0,z=0,j=0;for(let F=-2;F<=2;F++)for(let N=-2;N<=2;N++){const G=(y+F)*i+C+N,V=(u[G+1]-u[G-1])/2,et=(u[G+i]-u[G-i])/2;A+=V*V,z+=V*et,j+=et*et}const P=(A+j)/2-Math.sqrt(((A-j)/2)**2+z*z);P>a&&(!k||P>k[2])&&(k=[C,y,P])}k&&!E(k[0],k[1])&&x.push([k[0],k[1]])}return x}const gv=(t,e,o,r,a)=>{const n=yr(t.R,Ko(e,t.C));return n[2]>-1e-6?null:[r+o*n[0]/-n[2],a-o*n[1]/-n[2]]},Ga=(t,e,o,r,a,n)=>{const i=gv(t,e,r,a,n);return i?Math.hypot(i[0]-o[0],i[1]-o[1]):1e3},Cm=(t,e,o,r,a,n)=>Or(t.C,yr(Kn(t.R),[(e[0]-a)/r*o,-(e[1]-n)/r*o,-o]));function yv(t,e){const o=Math.cos(e),r=Math.sin(e),a=1-o;return[[o+t[0]*t[0]*a,t[0]*t[1]*a-t[2]*r,t[0]*t[2]*a+t[1]*r],[t[1]*t[0]*a+t[2]*r,o+t[1]*t[1]*a,t[1]*t[2]*a-t[0]*r],[t[2]*t[0]*a-t[1]*r,t[2]*t[1]*a+t[0]*r,o+t[2]*t[2]*a]]}function bv(t,e){if(e.length<4)return null;const o=Be(e.reduce((g,v)=>Or(g,v),[0,0,0]),1/e.length),r=[[0,0,0],[0,0,0],[0,0,0]];for(const g of e){const v=Ko(g,o);for(let x=0;x<3;x++)for(let E=0;E<3;E++)r[x][E]+=v[x]*v[E]}const{values:a,vectors:n}=al(r),i=[0,1,2].reduce((g,v)=>a[v]<a[g]?v:g,0),c=yr(t.R,Ko(o,t.C)),u=ci(c),p=yr(t.R,n.map(g=>g[i])),s=Ko(Be(u,2*Ar(p,u)),p),h=kh(p,s),f=Math.hypot(...h);if(f<Math.sin(.5*Sn))return null;const m=er(yv(Be(h,1/f),Math.atan2(f,Ar(p,s))),t.R);return{R:m,C:Ko(o,yr(Kn(m),c))}}function wv(t){const e=t.length,o=t.map(n=>[...n]),r=Array.from({length:e},(n,i)=>Array.from({length:e},(c,u)=>i===u?1:0));for(let n=0;n<60;n++){let i=0;for(let c=0;c<e;c++)for(let u=c+1;u<e;u++)i+=o[c][u]**2;if(i<1e-24)break;for(let c=0;c<e;c++)for(let u=c+1;u<e;u++){if(Math.abs(o[c][u])<1e-300)continue;const p=(o[u][u]-o[c][c])/(2*o[c][u]),s=Math.sign(p||1)/(Math.abs(p)+Math.sqrt(p*p+1)),h=1/Math.sqrt(s*s+1),f=s*h;for(let m=0;m<e;m++){const g=o[m][c],v=o[m][u];o[m][c]=h*g-f*v,o[m][u]=f*g+h*v}for(let m=0;m<e;m++){const g=o[c][m],v=o[u][m];o[c][m]=h*g-f*v,o[u][m]=f*g+h*v}for(let m=0;m<e;m++){const g=r[m][c],v=r[m][u];r[m][c]=h*g-f*v,r[m][u]=f*g+h*v}}}let a=0;for(let n=1;n<e;n++)o[n][n]<o[a][a]&&(a=n);return r.map(n=>n[a])}function kv(t,e){if(t.length<8)return[];const o=Array.from({length:9},()=>new Array(9).fill(0));for(let y=0;y<t.length;y++){const[C,A]=t[y],[z,j]=e[y];for(const P of[[C,A,1,0,0,0,-z*C,-z*A,-z],[0,0,0,C,A,1,-j*C,-j*A,-j]])for(let F=0;F<9;F++)for(let N=0;N<9;N++)o[F][N]+=P[F]*P[N]}const r=wv(o),a=[[r[0],r[1],r[2]],[r[3],r[4],r[5]],[r[6],r[7],r[8]]],{values:n}=al(er(Kn(a),a)),i=Math.sqrt([...n].sort((y,C)=>y-C)[1]);let c=a.map(y=>y.map(C=>C/i)),u=0;for(let y=0;y<t.length;y++)u+=Ar([e[y][0],e[y][1],1],yr(c,[t[y][0],t[y][1],1]))>0?1:-1;u<0&&(c=c.map(y=>y.map(C=>-C)));const{values:p,vectors:s}=al(er(Kn(c),c)),h=[0,1,2].sort((y,C)=>p[C]-p[y]),f=p[h[0]],m=p[h[2]],g=s.map(y=>y[h[0]]),v=s.map(y=>y[h[1]]),x=s.map(y=>y[h[2]]);if(!(f-m>1e-9))return[];const E=Math.sqrt(f-m),$=Math.sqrt(Math.max(0,1-m))/E,S=Math.sqrt(Math.max(0,f-1))/E,k=[];for(const y of[Or(Be(g,$),Be(x,S)),Ko(Be(g,$),Be(x,S))]){let C=ci(kh(v,y));C[2]>0&&(C=Be(C,-1)),k.push(C)}return k}function xv(t,e,{iters:o=80,thr:r=1}={}){const a=t.length;if(a<8)return null;let n=5;const i=()=>(n=n*1664525+1013904223>>>0)/2**32,c=m=>{const g=[[0,0,0],[0,0,0],[0,0,0]],v=[0,0,0],x=[0,0,0];for(const S of m){const k=[t[S][0],t[S][1],1];for(let y=0;y<3;y++){v[y]+=k[y]*e[S][0],x[y]+=k[y]*e[S][1];for(let C=0;C<3;C++)g[y][C]+=k[y]*k[C]}}const E=jm(g,v),$=jm(g,x);return E&&$?[E,$]:null},u=m=>t.map((g,v)=>Math.hypot(m[0][0]*g[0]+m[0][1]*g[1]+m[0][2]-e[v][0],m[1][0]*g[0]+m[1][1]*g[1]+m[1][2]-e[v][1]));let p=null,s=-1;for(let m=0;m<o;m++){const g=[Math.floor(i()*a),Math.floor(i()*a),Math.floor(i()*a)];if(g[0]===g[1]||g[1]===g[2]||g[0]===g[2])continue;const v=c(g);if(!v)continue;const x=u(v).filter(E=>E<r).length;x>s&&(s=x,p=v)}if(!p)return null;const h=u(p),f=c(h.map((m,g)=>m<r*1.5?g:-1).filter(m=>m>=0))??p;return u(f)}function Mv(t){if(t.length<8)return null;const e=Be(t.reduce((i,c)=>Or(i,c),[0,0,0]),1/t.length),o=[[0,0,0],[0,0,0],[0,0,0]];for(const i of t){const c=Ko(i,e);for(let u=0;u<3;u++)for(let p=0;p<3;p++)o[u][p]+=c[u]*c[p]}const{values:r,vectors:a}=al(o),n=[0,1,2].sort((i,c)=>r[i]-r[c]);return r[n[0]]<.15**2*r[n[1]]?{O:e,n:ci(a.map(i=>i[n[0]]))}:null}function vv(t,e,{w:o,h:r,f:a,region:n,follow:i,seed:c,onProgress:u=null,seeds:p=Go.seeds}){const s=o/2,h=r/2,f=Go.minPoints,m=Array.from({length:t},()=>new Map),g=new Map,v=new Map,x=new Map,E=new Map,$=new Array(t).fill(null);let S=0,k=0;const y=W=>[Math.min(...W.map(_=>_[0])),Math.min(...W.map(_=>_[1])),Math.max(...W.map(_=>_[0])),Math.max(...W.map(_=>_[1]))];$[e]={R:Ay(),C:[0,0,0]};for(const W of c(e,(_,J)=>jy(n,_,J),[],y(n))){const _=S++;m[e].set(_,W),g.set(_,Cm($[e],W,1,a,s,h)),v.set(_,e)}if(g.size<10)throw Error("FLAT");const C=(W,_)=>g.has(W)&&(v.get(W)===e||Math.abs(_-v.get(W))>=3),A=W=>{g.delete(W);for(const _ of m)_.delete(W)},z=(W,_)=>{const J=[...m[W]].filter(([tt])=>C(tt,W)).map(([tt,rt])=>[Math.hypot(rt[0]-_[0],rt[1]-_[1]),-yr($[W].R,Ko(g.get(tt),$[W].C))[2]]).sort((tt,rt)=>tt[0]-rt[0]).slice(0,6);return J.length?Ol(J.map(tt=>tt[1])):1},j=()=>{const W=$.map((J,tt)=>J&&tt!==e?tt:-1).filter(J=>J>=0),_=Math.max(1,Math.ceil(W.length/20));yl($,g,m,[e,...W.filter((J,tt)=>tt%_===0||tt===W.length-1)],a,s,h,4)},P=(W,_,J=!0)=>{const tt=pt=>pt&&pt.R.flat().every(Number.isFinite)&&pt.C.every(Number.isFinite),rt=pt=>{let yt;try{yt=zw(W,pt,a,s,h,1).pose}catch{return null}if(!tt(yt))return null;const Mt=W.map(l=>Ga(yt,l.X,l.px,a,s,h));return{pose:yt,res:Mt,e:Mt.reduce((l,lt)=>l+Math.min(lt,3),0)/Mt.length}};let D=rt(_);const q=J&&bv(_,W.map(pt=>pt.X));if(tt(q)){const pt=rt(q);pt&&(!D||pt.e<D.e*.98)&&(D=pt)}return D??{pose:_,res:W.map(pt=>Ga(_,pt.X,pt.px,a,s,h)),e:1/0}},F=W=>{let _=new Map([...m[e]].filter(([tt])=>g.has(tt))),J=0;for(let tt=e+W;tt>=0&&tt<t;tt+=W){const rt=[..._.keys()],D=i(tt-W,tt,rt.map(lt=>_.get(lt))),q=new Map;rt.forEach((lt,K)=>{D[K]&&q.set(lt,D[K])});{const lt=[...q.keys()],K=lt.map(T=>_.get(T)),d=lt.map(T=>q.get(T)),w=xv(K,d);if(w){const T=Math.max(1,3*Ol(w));lt.forEach((I,O)=>{const L=w[O]>T?(E.get(I)??0)+1:0;E.set(I,L),L>=2&&(A(I),q.delete(I))})}}const pt=()=>{const lt=[...q].filter(([d])=>C(d,tt));if(lt.length<f)return null;const K=lt.map(([d,w])=>({X:g.get(d),px:w}));return{...P(K,$[tt-W],tt%3===0),use:lt}};let yt=pt();if(!yt)break;const Mt=Math.max(1.5,3*Ol(yt.res));let l=0;for(const[lt,K]of q){const T=Ga(yt.pose,g.get(lt),K,a,s,h)>(C(lt,tt)?Mt:3*Mt+4)?(x.get(lt)??0)+1:0;x.set(lt,T),T>=2&&(A(lt),q.delete(lt),l++)}if(l&&(yt=pt(),!yt))break;$[tt]=yt.pose;for(const[lt,K]of q)m[tt].set(lt,K);if(_=q,_.size<p*.7){const lt=hv([..._].filter(([K])=>C(K,tt)).map(([,K])=>K));if(lt.length>=3){const K=Math.max(3,o*.012);for(const d of c(tt,(w,T)=>fv(lt,w,T,K),[..._.values()],y(lt).map((w,T)=>w+(T<2?-K:K)))){const w=S++;g.set(w,Cm($[tt],d,z(tt,d),a,s,h)),v.set(w,tt),_.set(w,d),m[tt].set(w,d)}}}++J>=15&&(J=0,j()),u?.(++k/t)}};F(1),F(-1);const N=$.map((W,_)=>W?_:-1).filter(W=>W>=0),G=Math.max(1,Math.ceil(N.length/36)),V=[e,...N.filter((W,_)=>W!==e&&(_%G===0||_===N.length-1))],et=(W=!1,_=!1)=>{for(const J of N){if(!W&&V.includes(J))continue;const tt=[];for(const[rt,D]of m[J])g.has(rt)&&tt.push({X:g.get(rt),px:D});tt.length>=f&&J!==e&&($[J]=P(tt,$[J],_).pose)}},U=()=>{let W=0;for(const _ of V)for(const[J,tt]of m[_])if(g.has(J)){const rt=Ga($[_],g.get(J),tt,a,s,h);W+=rt<=2?rt*rt:4*rt-4}return W},at=Mv([...m[e].keys()].filter(W=>g.has(W)).map(W=>g.get(W)));if(at){const W=()=>({P:$.map(l=>l&&{R:l.R.map(lt=>[...lt]),C:[...l.C]}),X:new Map([...g].map(([l,lt])=>[l,[...lt]]))}),_=l=>{l.P.forEach((lt,K)=>{$[K]=lt&&{R:lt.R.map(d=>[...d]),C:[...lt.C]}}),g.clear();for(const[lt,K]of l.X)g.set(lt,[...K])},J=l=>{let lt=0;for(const K of l)for(const[d,w]of m[K])if(g.has(d)){const T=Ga($[K],g.get(d),w,a,s,h);lt+=T<=2?T*T:4*T-4}return lt},tt=()=>{for(const l of[1,-1])for(let lt=e+l;$[lt];lt+=l){const K=[];for(const[d,w]of m[lt])g.has(d)&&K.push({X:g.get(d),px:w});$[lt]=K.length>=f?P(K,$[lt-l],!0).pose:{...$[lt-l]}}},rt=l=>[...m[e].keys()].filter(lt=>m[l].has(lt)&&g.has(lt)),q=[N.find(l=>rt(l).length>=12),[...N].reverse().find(l=>rt(l).length>=12)].filter(l=>l!==void 0&&l!==e).map(l=>{const lt=rt(l),K=d=>[(d[0]-s)/a,(d[1]-h)/a];return kv(lt.map(d=>K(m[e].get(d))),lt.map(d=>K(m[l].get(d))))}).filter(l=>l.length),pt=[];if(q.length===2)for(const l of q[0]){const lt=q[1].reduce((K,d)=>Ar(d,l)>Ar(K,l)?d:K);Ar(l,lt)>Math.cos(15*Sn)&&pt.push(ci(Or(l,lt)))}else q.length===1&&pt.push(...q[0]);const yt=W();let Mt={cost:J(N),st:yt};for(const l of pt){const lt=[l[0],-l[1],-l[2]];_(yt);for(const d of m[e].keys()){const w=g.get(d);if(!w)continue;const T=ci(w),I=Ar(lt,T);if(Math.abs(I)>.05){const O=Ar(lt,at.O)/I;O>0&&g.set(d,Be(T,O))}}tt(),yl($,g,m,V,a,s,h,8),et(!0,!0);const K=J(N);K<Mt.cost&&(Mt={cost:K,st:W()})}_(Mt.st)}for(let W=0;W<4;W++){et(!0,W===0);const _=new Map;for(const rt of N)for(const[D,q]of m[rt])g.has(D)&&_.set(D,Math.max(_.get(D)??0,Ga($[rt],g.get(D),q,a,s,h)));const J=Math.max(1.5,2.5*Ol([..._.values()]));let tt=0;for(const[rt,D]of _)D>J&&(A(rt),tt++);if(yl($,g,m,V,a,s,h,8),et(),!tt&&W)break}for(let W=0,_=U();W<8;W++){yl($,g,m,V,a,s,h,5);const J=U();if(J>_*.998)break;_=J}return et(!0),u?.(1),{poses:$,points:g,obs:m,ref:e}}function $v(t,e,{w:o,h:r,mw:a,mh:n,f:i,region:c,smooth:u=Go.smooth,id:p="o1",name:s=""}){const{poses:h,points:f,obs:m,ref:g}=t,v=o/2,x=r/2,E=[...f.values()];if(E.length<Go.minPoints)throw Error("FLAT");const $=Be(E.reduce((q,pt)=>Or(q,pt),[0,0,0]),1/E.length),S=h[g].C,k=h[g].R,y=Math.hypot(...Ko($,S))||1,C=[[0,0,0],[0,0,0],[0,0,0]];for(const q of E){const pt=Ko(q,$);for(let yt=0;yt<3;yt++)for(let Mt=0;Mt<3;Mt++)C[yt][Mt]+=pt[yt]*pt[Mt]}const{values:A,vectors:z}=al(C),j=[0,1,2].sort((q,pt)=>A[q]-A[pt]),P=A[j[0]]<.08**2*A[j[1]];let F=Kn(k);if(P){let q=ci(z.map(l=>l[j[0]]));Ar(q,Ko(S,$))<0&&(q=Be(q,-1));const pt=yr(Kn(k),[1,0,0]),yt=ci(Ko(pt,Be(q,Ar(q,pt)))),Mt=kh(q,yt);F=Kn([yt,Mt,q])}const N=q=>Be(yr(Kn(F),Ko(q,$)),1/y),G=h.map((q,pt)=>q?pt:-1).filter(q=>q>=0),V=Math.min(...G),et=Math.max(...G),U=[];for(let q=V;q<=et;q++){const pt=h[q]??h[U.length?q-1:g];h[q]=pt;const yt=er(pt.R,F),Mt=Be(yr(pt.R,Ko($,pt.C)),1/y);let l=0,lt=0;for(const[K,d]of m[q]){const w=f.get(K);w&&(l+=Ga(pt,w,d,i,v,x),lt++)}U.push({t:e[q],R:yt,T:Mt,err:lt?l/lt:0,n:lt})}const at=new Map;for(const q of m)for(const pt of q.keys())f.has(pt)&&at.set(pt,(at.get(pt)??0)+1);const W=[...at].sort((q,pt)=>pt[1]-q[1]).slice(0,Go.points).map(([q])=>N(f.get(q))),_=W.map(q=>q[0]).sort((q,pt)=>q-pt),J=Math.max(1e-4,_[Math.floor(_.length*.98)]-_[Math.floor(_.length*.02)]),tt=Ev(U,W,i,u);let rt=0,D=0;for(const q of U)rt+=q.err*q.n,D+=q.n;return{v:1,id:p,...s?{name:String(s).slice(0,40)}:{},w:o,h:r,mw:a||o,mh:n||r,f:Vo(i),ref:Vo(e[g]),region:c.map(q=>[_o(q[0]),_o(q[1])]),plane:P,width:Vo(J),err:Vo(D?rt/D:0),smooth:u,frames:tt.map((q,pt)=>[Vo(q.t),...s1(q.R).map(Vo),...q.T.map(Vo),_o(U[pt].err),U[pt].n]),points:W.map(q=>q.map(Vo))}}function Ev(t,e,o,r){if(!(r>0)||t.length<3)return t;const a=r*Go.smoothFrames,n=Math.ceil(a*2.5),i=Go.smoothTolPx,c=e.filter((h,f)=>f%Math.max(1,Math.floor(e.length/40))===0),u=(h,f)=>{const m=Or(yr(h.R,f),h.T);return m[2]>-1e-6?null:[o*m[0]/-m[2],o*m[1]/-m[2]]},p=(h,f)=>{let m=0;for(const g of c){const v=u(h,g),x=u(f,g);v&&x&&(m=Math.max(m,Math.hypot(v[0]-x[0],v[1]-x[1])))}return m},s=t.map(h=>s1(h.R));return t.map((h,f)=>{let m=0,g=[0,0,0],v=[0,0,0,0];for(let k=Math.max(0,f-n);k<=Math.min(t.length-1,f+n);k++){const y=Math.exp(-((k-f)**2)/(2*a*a)),C=Td(s[k],s[f])<0?s[k].map(A=>-A):s[k];m+=y,g=Or(g,Be(t[k].T,y)),v=v.map((A,z)=>A+C[z]*y)}const x=k=>{const y=s[f].map((A,z)=>A+(v[z]/m-A)*k),C=Math.hypot(...y);return{...h,R:i1(y.map(A=>A/C)),T:Or(h.T,Be(Ko(Be(g,1/m),h.T),k))}};let E=1,$=x(1),S=p(h,$);for(let k=0;k<6&&S>i;k++)E*=Math.max(.3,i/S*.95),$=x(E),S=p(h,$);return S>i?h:$})}const Td=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3];function jm(t,e){const o=a=>a[0][0]*(a[1][1]*a[2][2]-a[1][2]*a[2][1])-a[0][1]*(a[1][0]*a[2][2]-a[1][2]*a[2][0])+a[0][2]*(a[1][0]*a[2][1]-a[1][1]*a[2][0]),r=o(t);return Math.abs(r)>1e-30?[0,1,2].map(a=>o(t.map((n,i)=>n.map((c,u)=>u===a?e[i]:c)))/r):null}function al(t){const e=t.map(r=>[...r]),o=Ay();for(let r=0;r<40;r++){let a=0;for(let n=0;n<3;n++)for(let i=n+1;i<3;i++)a+=e[n][i]**2;if(a<1e-26)break;for(let n=0;n<3;n++)for(let i=n+1;i<3;i++){if(Math.abs(e[n][i])<1e-300)continue;const c=(e[i][i]-e[n][n])/(2*e[n][i]),u=Math.sign(c||1)/(Math.abs(c)+Math.sqrt(c*c+1)),p=1/Math.sqrt(u*u+1),s=u*p;for(let h=0;h<3;h++){const f=e[h][n],m=e[h][i];e[h][n]=p*f-s*m,e[h][i]=s*f+p*m}for(let h=0;h<3;h++){const f=e[n][h],m=e[i][h];e[n][h]=p*f-s*m,e[i][h]=s*f+p*m}for(let h=0;h<3;h++){const f=o[h][n],m=o[h][i];o[h][n]=p*f-s*m,o[h][i]=s*f+p*m}}}return{values:[e[0][0],e[1][1],e[2][2]],vectors:o}}const Sv=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 eT(t,e,{ref:o,region:r,f:a,mw:n,mh:i,smooth:c,onProgress:u=null,id:p,name:s}={}){if(t.length<3)throw Error("FLAT");const h=t[0].w,f=t[0].h,m=new Map,g=x=>{let E=m.get(x);return E||(m.size>3&&m.delete(m.keys().next().value),E=Ow(Sv(t[x])),m.set(x,E)),E},v=vv(t.length,o,{w:h,h:f,f:a,region:r,onProgress:u,follow:(x,E,$)=>Tw(g(x),g(E),$),seed:(x,E,$,S)=>mv(g(x)[0],E,S,{taken:$})});if(v.poses.filter(Boolean).length<Math.min(t.length,3))throw Error("LOST");return $v(v,e,{w:h,h:f,mw:n,mh:i,f:a,region:r,smooth:c,id:p,name:s})}function Iv(t,e){const o=t.frames,r=o.length;let a=0;for(;a<r-2&&o[a+1][0]<=e;)a++;const n=o[a],i=o[Math.min(r-1,a+1)],c=i[0]>n[0]?Math.max(0,Math.min(1,(e-n[0])/(i[0]-n[0]))):0;let u=n.slice(1,5),p=i.slice(1,5);Td(u,p)<0&&(p=p.map(f=>-f));const s=Math.min(1,Math.max(-1,Td(u,p)));let h;if(s>.9995){h=u.map((m,g)=>m+(p[g]-m)*c);const f=Math.hypot(...h);h=h.map(m=>m/f)}else{const f=Math.acos(s),m=Math.sin(f);h=u.map((g,v)=>g*Math.sin((1-c)*f)/m+p[v]*Math.sin(c*f)/m)}return{R:i1(h),T:[0,1,2].map(f=>n[5+f]+(i[5+f]-n[5+f])*c),err:n[8]+(i[8]-n[8])*c,n:Math.round(n[9]+(i[9]-n[9])*c)}}function Av(t,e,o){const r=(t.keys??[]).filter(c=>Number.isFinite(c[e])).sort((c,u)=>c.t-u.t);if(!r.length)return t.fix?.[e]??Iy[e];if(o<=r[0].t)return r[0][e];if(o>=r.at(-1).t)return r.at(-1)[e];let a=0;for(;r[a+1].t<o;)a++;const n=r[a],i=r[a+1];return n[e]+(i[e]-n[e])*(o-n.t)/(i.t-n.t)}const Cv=(t,e)=>Object.fromEntries(Cd.map(o=>[o,Av(t,o,e)]));function xh(t,e,{raw:o=!1}={}){const r=Iv(t,e);if(o)return{...r,s:1};const a=Cv(t,e);return{...r,R:er(r.R,Cy(a.rx,a.ry,a.rz)),T:Or(r.T,Be(jd([a.x,a.y,a.z]),t.width)),s:a.s}}function Ty(t,e,o,r=xh(t,o)){const a=Or(yr(r.R,Be(e,r.s)),r.T);return a[2]>-1e-6?null:[t.w/2+t.f*a[0]/-a[2],t.h/2-t.f*a[1]/-a[2]]}function oT(t,e,o=.5){const r=xh(t,e),a=t.width*o,n=i=>Ty(t,i,e,r);return{o:n([0,0,0]),x:n([a,0,0]),y:n([0,a,0]),z:n([0,0,a])}}function rT(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 nT(t,e,o,r=!1){let a=(t.keys??[]).map(i=>({...i})),n={...t.fix};o=_o(o);for(const i of Cd){const c=e[i];if(typeof c!="number"||!Number.isFinite(c))continue;if(a.some(p=>Number.isFinite(p[i]))||r){let p=a.find(s=>Math.abs(s.t-o)<.016666666666666666);p||(p={t:o},a.push(p)),p[i]=_o(c)}else n[i]=_o(c)}for(const i of Cd)n[i]===Iy[i]&&delete n[i];return a=a.sort((i,c)=>i.t-c.t),{...t,keys:a.length?a:void 0,fix:Object.keys(n).length?n:void 0}}function aT(t,e){const o=(t.keys??[]).filter(r=>Math.abs(r.t-e)>=.016666666666666666);return{...t,keys:o.length?o:void 0}}function iT(t){const e=new Set((t?.objectTracks??[]).map(r=>r.id));let o=1;for(;e.has(`o${o}`);)o++;return`o${o}`}function Oy(t,e,o,r,a){const n=zf(t,e,t.w/2,t.h/2,o,r,a),i=zf(t,e,t.w/2+10,t.h/2,o,r,a);return Math.hypot(i[0]-n[0],i[1]-n[1])/10}function jv(t,e,o,r,a,n,i=null){return i?Aw(i,e.w,e.w/e.h):5*Br(r,a)*(el(n)?dl(n,"zoom",t.start+o):1)/Oy(e,t,o,r,a)}function sT(t,e,o,r,a=t.f){return a*Oy(t,e,t.ref,o,r)/(5*Br(o,r))}function Tv(t,e,o,r,a,n=null){if(t.size)return t.size*o/t.width;if(n?.mode==="free"&&Array.isArray(n.frames)){const i=n.w/t.w,c=t.region.map(g=>g[0]),u=t.region.map(g=>g[1]),p=[(Math.min(...c)+Math.max(...c))/2*i,Math.max(...u)*i],s=[c.reduce((g,v)=>g+v,0)/c.length*i,u.reduce((g,v)=>g+v,0)/u.length*i],h=hx(n,t.ref).C,f=fx(n,p[0],p[1],t.ref)??mx(n,s[0],s[1],t.ref),m=Math.hypot(...Ko(f,h));if(m>0)return m*gx(n,e,o,r).k}return 5*Br(o,r)*(el(a)?dl(a,"zoom",e.start+t.ref):1)}function Ov(t,e){const o=Math.asin(Math.max(-1,Math.min(1,t[1][2]))),r=Math.atan2(-t[0][2],t[2][2]),a=[[o,r],[Math.PI-o,r+Math.PI]].map(([n,i])=>{const c=[[1,0,0],[0,Math.cos(n),Math.sin(n)],[0,-Math.sin(n),Math.cos(n)]],u=[[Math.cos(i),0,-Math.sin(i)],[0,1,0],[Math.sin(i),0,Math.cos(i)]],p=er(Kn(er(u,c)),t);return[n/Sn,i/Sn,Math.atan2(p[1][0],p[0][0])/Sn]});return zy(a,e)}function zv(t,e){const o=Math.asin(Math.max(-1,Math.min(1,t[0][2]))),r=Math.atan2(-t[1][2],t[2][2]),a=Math.atan2(-t[0][1],t[0][0]);return zy([[r,o,a],[r+Math.PI,Math.PI-o,a+Math.PI]].map(n=>n.map(i=>i/Sn)),e)}function zy(t,e){const o=(a,n)=>{if(n===void 0)return a;for(;a-n>180;)a-=360;for(;a-n<-180;)a+=360;return a},r=t.map(a=>a.map((n,i)=>o(n,e?.[i])));return e?r.reduce((a,n)=>n.reduce((i,c,u)=>i+Math.abs(c-e[u]),0)<a.reduce((i,c,u)=>i+Math.abs(c-e[u]),0)?n:a):r[0]}const Pv=["x","y","depth","zoom","rot","tiltX","tiltY","rx","ry","rz"],Lv=t=>t.kind==="model"?"model":t.nullLayer?"null":t.title?"text":"plane";function Fv(t,e,o,r,a,n,i={},{scene:c=null}={}){const u=Math.max(t.start,e.start+o.frames[0][0]),p=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=el(n)?n:{enabled:!0,motionV:2,motionKeys:[]},m=jv(e,o,o.ref,r,a,f);if(Math.abs(m/o.f-1)>.03)throw Error("LENS");const g=Br(r,a),v=Tv(o,e,r,a,f,c),x=Lv(t),E=Number.isFinite(i.size)&&i.size>0?i.size:Go.glue[x],$=(i.offset??[0,0,0]).map(tt=>tt*o.width),S=i.turn??[0,0,0],k=Cy(S[0],S[1],S[2]),y=[Math.max(s,Math.min(h,u)),...o.frames.map(tt=>e.start+tt[0]).filter(tt=>tt>u+1e-4&&tt<p-1e-4),Math.min(h,Math.max(s,p))],C=y.filter((tt,rt)=>rt===0||tt>y[rt-1]+1e-4),A=[];let z,j;for(const tt of C){const rt=tt-e.start,D=xh(o,rt),q=Cw(f,tt,r,a),pt=er(er(D.R,k),Tl),yt=Or(yr(D.R,Be(jd($),D.s)),D.T),Mt=Be(jd(yt),v),l=Or(yr(q.R,Mt),q.pos),lt=er(q.R,er(Tl,pt)),K=-l[2]/g;if(!(K>=fh&&K<=jw)||!(Mt[2]>1))throw Error("FAR");const d={time:+(tt-t.start).toFixed(4),x:l[0]/r,y:l[1]/a,depth:K,zoom:E*o.width*D.s*v/(x==="model"?1.8*g:r),d:Mt[2],f:q.f};if(x==="model"){const w=zv(er(er(Tl,lt),Tl),j);j=w,Object.assign(d,{rx:w[0],ry:w[1],rz:w[2]})}else{const w=Ov(lt,z);z=w,Object.assign(d,{tiltX:w[0],tiltY:w[1],rot:w[2]})}A.push(d)}const P=Go.keyTolPx,F=Math.max(1,...A.map(tt=>tt.zoom*(x==="model"?1.8*g:r)*tt.f/tt.d)),N=Math.min(...A.map(tt=>tt.d)),G=2*P/F/Sn,V={x:P/r,y:P/a,depth:P*N/F/g,zoom:P/F*A[0].zoom,rot:G,tiltX:G,tiltY:G,rx:G,ry:G,rz:G};let et={...t,motionV:2};for(const tt of Pv)(et.motionKeys??[]).some(rt=>rt[tt]!==void 0)&&(et={...et,motionKeys:br(et,tt,[])});const U=x==="model"?["x","y","depth","zoom","rx","ry","rz"]:["x","y","depth","zoom","rot","tiltX","tiltY"],at={},W=A.map(tt=>tt.time);for(const tt of U){const rt=A.map(D=>D[tt]);if(Math.max(...rt)-Math.min(...rt)<=V[tt]){at[tt]=Vo(rt[0]);continue}et={...et,motionKeys:br(et,tt,dx(W,rt,V[tt],1/0).sort((D,q)=>D-q).map(D=>({time:W[D],value:Vo(rt[D])})))}}const _=A[0],J={is3D:!0,motionV:2,motionKeys:et.motionKeys??[],posX:Vo(_.x),posY:Vo(_.y),spatialDepth:Vo(_.depth),scale:Vo(at.zoom??_.zoom),objectGlue:{source:e.id,object:o.id,...Number.isFinite(i.size)?{size:_o(i.size)}:{},...i.offset?{offset:i.offset.map(_o)}:{},...i.turn?{turn:i.turn.map(_o)}:{}}};return x==="model"?Object.assign(J,{modelDepth:J.spatialDepth,modelGround:void 0,modelRotation:{x:_o(at.rx??_.rx),y:_o(at.ry??_.ry),z:_o(at.rz??_.rz)}}):Object.assign(J,{rotation:_o(at.rot??_.rot),tiltX:_o(at.tiltX??_.tiltX),tiltY:_o(at.tiltY??_.tiltY)}),{camera:el(n)?null:f,patch:J}}function lT(t,e,o,r,a,n,{scene:i=null}={}){const c=t.find(m=>m.id===e),u=c?.objectTracks?.find(m=>m.id===o);let p=n,s=null;const h=[];return u?{clips:t.map(m=>{if(m.objectGlue?.source!==e||m.objectGlue.object!==o)return m;try{const g=Fv(m,c,u,r,a,p,m.objectGlue,{scene:i});return g.camera&&(p=s=g.camera),{...m,...g.patch}}catch{return h.push(m.id),m}}),camera:s,failed:h}:{clips:t,camera:null,failed:h}}const qr=t=>typeof t=="number"&&Number.isFinite(t)?t:null,Tm=(t,e,o)=>{if(t!=null){if(!(Array.isArray(t)&&t.length===3&&t.every(r=>qr(r)!==null&&Math.abs(r)<=o)))throw Error(`placeOnObject ${e}: [x, y, z] (each within ±${o})`);return t.map(_o)}};function Nv(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(g=>qr(g)!==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,[a,n]=Go.regionPoints;if(!(Array.isArray(r)&&r.length>=a&&r.length<=n&&r.every(g=>Array.isArray(g)&&g.length===2&&g.every(v=>qr(v)!==null&&v>=0&&v<=1))))throw Error(`trackObject3D region: ${a}–${n} points [u, v] (0..1 of the footage picture) round the object`);let i=0;for(let g=0,v=r.length-1;g<r.length;v=g++)i+=(r[v][0]+r[g][0])*(r[v][1]-r[g][1]);if(!(Math.abs(i)/2>=4e-4))throw Error("trackObject3D region: draw round the object (the region is too small)");const c=Math.max(0,Math.min(e.duration,(qr(t.at)??e.start)-e.start)),u=Math.max(0,Math.min(e.duration,(qr(t.from)??qr(t.start)??e.start)-e.start)),p=Math.min(e.duration-u,qr(t.duration)??e.duration-u);if(!(p>=.3))throw Error("trackObject3D: at least 0.3 s of the footage");if(c<u-.001||c>u+p+.001)throw Error("trackObject3D: `at` (the frame the region is drawn on) must be inside from … from + duration");const s=qr(t.size),h=qr(t.lens),f=qr(t.smooth);if(s!==null&&!(s>=Go.size[0]&&s<=Go.size[1]))throw Error(`trackObject3D size: ${Go.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)>=Go.max)throw Error(`trackObject3D: at most ${Go.max} objects per clip (remove one first)`);const m=u<.001&&p>e.duration-.001;return{region:r.map(g=>[Vo(g[0]),Vo(g[1])]),at:+c.toFixed(4),...m?{}:{from:+u.toFixed(4),duration:+p.toFixed(4)},...s!==null?{size:s}:{},...h?{lens:h}:{},...f!==null?{smooth:f}:{},...t.name?{name:String(t.name).slice(0,40)}:{}}}function Rv(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 n=t.objectId??t.object;if(n!=null&&!(typeof n=="string"&&/^[\w-]{1,24}$/.test(n)))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(n&&!i&&!o.objectTracks?.some(s=>s.id===n))throw Error(`placeOnObject: ${o.label||o.id} has no object ${n} (trackObject3D first)`);if(!n&&!i&&!o.objectTracks?.length)throw Error(`placeOnObject: ${o.label||o.id} has no tracked object (trackObject3D first)`);const c=qr(t.size);if(c!==null&&!(c>.01&&c<=100))throw Error("placeOnObject size: 0.01–100 (× the object's width)");const u=Tm(t.offset,"offset",50),p=Tm(t.turn,"turn",3600);return{source:o.id,...n?{object:n}:{},...c!==null?{size:c}:{},...u?{offset:u}:{},...p?{turn:p}:{}}}const cT=(t,e,o)=>o.map(([r,a])=>ux(t,e,r,a)),Hc=Object.freeze(["hand","roto","planar","face","object"]),Py=15,Od=900,Dv=t=>t?.crop??{left:0,right:0,top:0,bottom:0},Bv=(t,e,o)=>{const r=Dv(t);return[r.left+e*(1-r.left-r.right),r.top+o*(1-r.top-r.bottom)]},zl=t=>Math.round(t*1e4)/1e4;function pT(t){if(!t||t.kind!=="video")return[];const e=[];t.hands?.data&&e.push({source:"hand",label:"Tay (tracking tay)",points:Vc,sides:["right","left"]}),t.roto?.points?.length&&e.push({source:"roto",label:"Điểm Roto"}),t.planar?.frames?.length&&!l1(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 _v(t,e,{side:o="right",point:r="palm",object:a,from:n=0,to:i,fps:c=Py}={}){if(!t||t.kind!=="video")throw Error("VFX tracks come from a filmed video clip");if(!Hc.includes(e))throw Error(`source must be ${Hc.join(" / ")}`);const u=Math.min(t.duration,i??t.duration),p=1/Math.max(1,Math.min(30,c)),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 g=fl(t.hands),v=o==="left"?1:0,x=Vc.includes(r)?r:"palm";f=g.mw,m=g.mh,h=E=>{const $=Wc(g,Kc(t,E),v);return $?[...Vi($,x),Ey($,g.mw,g.mh)/(g.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=g=>Pw(t,g)}else if(e==="planar"){if(!t.planar?.frames?.length)throw Error(l1(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 g=f&&m?f/m:16/9;h=v=>{if(!Lw(t.planar,v))return null;const x=Fw(t.planar,v).map(([E,$])=>Bv(t,E,$));return[x.reduce((E,$)=>E+$[0],0)/x.length,x.reduce((E,$)=>E+$[1],0)/x.length,Math.hypot((x[0][0]-x[3][0])*g,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=g=>{const v=Nw(t,g);return v&&v.score>0?[v.cx,v.cy,v.h]:null}}else{const g=(t.objectTracks??[]).find(v=>v?.id===a)??(a==null?t.objectTracks?.[0]:null);if(!g?.frames?.length)throw Error(a==null?"this clip has no 3D-tracked object (edit_timeline trackObject3D)":`no 3D-tracked object ${a} on this clip`);f=g.mw,m=g.mh,h=v=>{if(v<g.frames[0][0]-1e-6||v>g.frames.at(-1)[0]+1e-6)return null;const x=Ty(g,[0,0,0],v);return x?[x[0]/g.w,x[1]/g.h]:null}}for(let g=0;s.length<Od;g++){const v=Math.max(0,n)+g*p;if(v>u+1e-6)break;const x=h(Math.min(v,u));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([zl(Math.min(v,u)),zl(x[0]),zl(x[1]),...Number.isFinite(x[2])&&x[2]>0?[zl(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/p),points:s,...f>0&&m>0?{mw:f,mh:m}:{}}}function uT(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>Od)throw Error(`track: 2 to ${Od} points`);let o=-1/0;const r=t.points.map(a=>{if(!Array.isArray(a)||a.length<3||!a.slice(0,3).every(u=>Number.isFinite(Number(u))))throw Error("each track point is [t, u, v]");const[n,i,c]=a.map(Number);if(n<0||n>e+.001||n<=o)throw Error(`track times must rise within the shot (0–${e} s)`);if(i<-.5||i>1.5||c<-.5||c>1.5)throw Error("track u / v are fractions of the picture (−0.5..1.5)");return o=n,[n,i,c]});return{fps:Number.isFinite(Number(t.fps))?Number(t.fps):Py,points:r}}const Vv=15,Bn=t=>Math.round(t*1e4)/1e4,Gv=new Set(["hand","face","planar"]);function Kv(t,e,o){const r=t.vfxFootage||{},a=Array.isArray(r.anchor)&&r.anchor.length===2&&r.anchor.every(Number.isFinite)?r.anchor:md,n=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:a,aspect:n}}function Wv(t,e,{source:o,hand:r="right",point:a="palm",object:n,scale:i=!1,offset:c=null,W:u=1280,H:p=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(!Hc.includes(o))throw Error(`vfxFootageFollow: source must be ${Hc.join(" / ")}`);if(i&&!Gv.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=_v(e,o,{side:r==="left"?"left":"right",point:a,...n!=null?{object:String(n)}:{},from:s-e.start,to:h-e.start,fps:Vv}),m=f.mw||Number(e.proxy?.width)||u,g=f.mh||Number(e.proxy?.height)||p,v=e.crop??{left:0,right:0,top:0,bottom:0},x=1-v.left-v.right||1,E=1-v.top-v.bottom||1,$=f.points.map(([at,W,_,J])=>{const tt=Ic(e,(W-v.left)/x,(_-v.top)/E,at,u,p,m,g);return{T:e.start+at,fx:tt.px/u,fy:tt.py/p,size:J}});if(i&&$.some(at=>!(at.size>0)))throw Error(`vfxFootageFollow: the ${o} track has no size to scale with`);const S={...t,...pn(t)},k=$[0],y=at=>Bn(at-t.start),{anchor:C,aspect:A}=Kv(t,u,p),z=u/p,j=A>=z?1:A/z,P=A>=z?z/A:1,F=Array.isArray(c)&&Number.isFinite(Number(c[0]))?Number(c[0]):0,N=Array.isArray(c)&&Number.isFinite(Number(c[1]))?Number(c[1]):0,G=Qt(S,"zoom",k.T-t.start)||1,V=$.map(at=>i?Math.max(.05,G*at.size/k.size):Qt(S,"zoom",at.T-t.start)||1);let et={...S,motionV:2};delete et.posX,delete et.posY,et={...et,...ge(et,"x",$.map((at,W)=>({time:y(at.T),value:Bn(at.fx+F-.5-(C[0]-.5)*j*V[W])})))},et={...et,...ge(et,"y",$.map((at,W)=>({time:y(at.T),value:Bn(at.fy+N-.5-(C[1]-.5)*P*V[W])})))},i&&(et={...et,...ge(et,"zoom",$.map((at,W)=>({time:y(at.T),value:Bn(V[W])})))});const U={clip:e.id,source:o,...o==="hand"?{hand:r==="left"?"left":"right",point:a}:{},...o==="object"&&n!=null?{object:String(n)}:{},...i?{scale:!0}:{}};return{patch:{motionV:2,motionKeys:et.motionKeys,posX:void 0,posY:void 0,vfxFootage:{...t.vfxFootage,follow:U}},keys:$.length,from:Bn($[0].T),to:Bn($.at(-1).T)}}function Hv(t,e=0){const o=t?.vfxFootage?.follow;if(!o)throw Error("vfxFootageFollow: this effect follows nothing");const r={...t,...pn(t)},a=Qt(r,"x",e),n=Qt(r,"y",e),i=Qt(r,"zoom",e),c=(r.motionKeys||[]).map(s=>{const{x:h,y:f,...m}=s;if(o.scale&&delete m.zoom,m.ease){const{x:g,y:v,...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:u,...p}=t.vfxFootage;return{motionV:2,motionKeys:c,posX:Bn(a),posY:Bn(n),...o.scale?{scale:Bn(i)}:{},vfxFootage:p}}const ba=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"]}),Jr=(t,[e,o],r)=>{const a=Number(t);return Number.isFinite(a)?Math.min(o,Math.max(e,a)):r},ze=t=>Math.round(t*1e4)/1e4,Om=Object.freeze({grow:-.35,feather:.004});function Jn(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,Om.grow),feather:Math.max(r.person.feather??0,Om.feather)}),delete r.roto,delete r.planar,delete r.personPending,delete r.sceneTrack,delete r.shocks,delete r.impacts,r}function Xv(t,{copies:e=5,gap:o=.07,fade:r=.35,opacity:a=.85,spread:n=0,look:i=null,start:c=null,duration:u=null}={},p){const s=Math.round(Jr(e,ba.echo.copies,5)),h=Jr(o,ba.echo.gap,.07),f=Jr(r,ba.echo.fade,.35),m=Jr(n,ba.echo.spread,0);if(i!=null&&!Object.hasOwn(Ac,i))throw Error(`personEcho: look must be a clip effect (${Object.keys(Ac).join(", ")})`);const g=i?[...(t.effects??[]).slice(0,yn-1),{type:i,amount:.85}]:null,v=Math.max(t.start,Number.isFinite(c)?c:t.start),x=Math.min(t.start+t.duration,Number.isFinite(u)?v+u:t.start+t.duration);if(!(x-v>.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,y=v+k;if(y>=x-.05)continue;const C=(t.inPoint||0)+(v-t.start)*(t.playbackRate||1);E.push(Jn(t,p(),{start:ze(y),duration:ze(x-y),inPoint:ze(C),opacity:ze(a*(1-f)**(S-1)*(1-.5*S/(s+1))),label:`${t.label||"Video"} · vệt ${S}`,...m?{motionV:2,posX:ze((t.posX??0)+S*m)}:{},...g?{effects:g}:{}}))}const $=(t.inPoint||0)+(v-t.start)*(t.playbackRate||1);return E.push(Jn(t,p(),{start:ze(v),duration:ze(x-v),inPoint:ze($),label:`${t.label||"Video"} · người`})),E}function Uv(t,e="wedge",o=.22,r=.25,a=7){const n=[];let i=a;const c=()=>(i=i*1664525+1013904223>>>0)/2**32;for(let u=1;u<=t;u++){const p=u%2?1:-1,s=Math.ceil(u/2);e==="row"?n.push([p*o*s,0]):e==="wedge"?n.push([p*o*s*.8,-r*s*.35]):n.push([(c()*2-1)*o*3,-r*(.15+c()*.85)])}return n}function Yv(t,{count:e=6,layout:o="wedge",spread:r=.2,depth:a=.25,delay:n=.12,mirror:i=!0,feet:c=[.5,.9],horizon:u=.4,start:p=null,duration:s=null,smoke:h=!0,appear:f=.12}={},m){const g=Math.round(Jr(e,ba.clone.count,6)),v=ba.layouts.includes(o)?o:"wedge",x=Jr(r,ba.clone.spread,.2),E=Jr(a,ba.clone.depth,.25),$=Jr(n,[-2,2],.12),S=[Jr(c?.[0],[0,1],.5),Jr(c?.[1],[.05,1],.9)],k=Jr(u,[-1,S[1]-.05],Math.min(.4,S[1]-.1)),y=Math.max(t.start,Number.isFinite(p)?p:t.start),C=Math.min(t.start+t.duration,Number.isFinite(s)?y+s:t.start+t.duration);if(!(C-y>.2))throw Error("clonePerson: the clones must lie inside the person clip");const A=Uv(g,v,x,E).map(([F,N],G)=>({i:G,T:[S[0]+F,S[1]+N]})).filter(F=>F.T[1]>k+.02);A.sort((F,N)=>F.T[1]-N.T[1]);const z=[],j=[],P=(t.inPoint||0)+(y-t.start)*(t.playbackRate||1);for(const{i:F,T:N}of A){const G=F+1,V=(N[1]-k)/(S[1]-k),et=ze(N[0]-.5-V*(S[0]-.5)),U=ze(N[1]-.5-V*(S[1]-.5)),at=Math.abs($)*G,W=$>=0?y+Math.min(at,(C-y)*.6):y,_=$>=0?P:P+Math.min(at,(C-y)*.6)*(t.playbackRate||1),J=ze(W+(f>0?f*(G-1)*.5:0));J>=C-.1||(z.push(Jn(t,m(),{start:J,duration:ze(C-J),inPoint:ze(_+(J-W)*(t.playbackRate||1)),motionV:2,posX:et,posY:U,scale:ze((t.scale??1)*V),...i&&G%2===0?{flipX:!t.flipX}:{},enter:{type:"fade",duration:.18},label:`${t.label||"Video"} · bản sao ${G}`})),h&&j.push({at:J,u:N[0],v:N[1]-.18*V,size:V}))}return z.push(Jn(t,m(),{start:ze(y),duration:ze(C-y),inPoint:ze(P),label:`${t.label||"Video"} · người`})),{layers:z,poofs:j.map(F=>qv(F,m))}}const cu="vfx-smoke-poof";function qv({at:t,u:e,v:o,size:r=1,duration:a=1.1},n){const i=Cn.find(c=>c.id===cu);return{id:n(),nodeId:"",kind:"image",url:"",volume:0,start:ze(Math.max(0,t-.12)),duration:a,label:"Khói bụp",motionV:2,posX:ze(e-.5),posY:ze(o-.5),scale:ze(Math.max(.2,Math.min(3,r))),motion:Qe({code:`@preset:${cu}`,params:{...i.params},preset:cu})}}const pu="vfx-debris-burst";function Zv({id:t,at:e,u:o,v:r,size:a=1,seed:n=7,duration:i=1.2}){const c=Cn.find(u=>u.id===pu);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:ze(Math.max(0,e)),duration:i,label:"Mảnh vụn",motionV:2,posX:ze(o-.5),posY:ze(r-.5),scale:ze(Math.max(.2,Math.min(3,a))),motion:Qe({code:`@preset:${pu}`,params:{...c.params,seed:n},preset:pu})}}function Ly(t){if(t?.kind!=="video")return!1;const e=Rw(t);return e?e.some(o=>o.speed<.999):(t.playbackRate||1)<.999}function dT(t,e,o=30){if(Dw(t)==="none"&&(!t?.smoothSlow||!Ly(t)))return null;const r=c1(t,e)*o,a=Math.floor(r+1e-6);return{frame:a,phase:Math.min(1,Math.max(0,r-a))}}const Jv=Object.freeze(["flame","spirit","electric","smoke","burst"]),Ka=Object.freeze({fps:15,maxFrames:900,color:"#b44dff",hot:"#fff1ff",size:[.3,3],intensity:[.2,2.5],stretch:[.2,4],taper:.75}),Qv=Object.freeze([0,11,12,13,14,15,16,23,24,25,26,27,28]),da=t=>Math.round(t*1e3)/1e3,zd=t=>Math.round(t*1e4)/1e4,bi=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,zm=/^#[0-9a-fA-F]{6}$/;function Mh(t={}){const e=Jv.includes(t.look)?t.look:"flame",o=Array.isArray(t.wind)&&t.wind.length===2&&t.wind.every(Number.isFinite)?t.wind.map(r=>da(bi(r,-1,1,0))):[0,0];return{look:e,color:zm.test(t.color??"")?t.color.toLowerCase():Ka.color,hot:zm.test(t.hot??"")?t.hot.toLowerCase():Ka.hot,size:da(bi(t.size,...Ka.size,1)),intensity:da(bi(t.intensity,...Ka.intensity,1)),wind:o,speed:da(bi(t.speed,0,2,1)),stretch:da(bi(t.stretch,...Ka.stretch,1)),taper:da(bi(t.taper,0,1,Ka.taper))}}function hT(t,e=o=>o){const o=[];for(const r of t){if(!r?.lm)continue;const a=[zd(r.t)];for(const n of Qv){const i=r.lm[n];if(!i||(i[3]??1)<.35){a.push(-1,-1);continue}const[c,u]=e([i[0],i[1]]);a.push(da(c),da(u))}if(o.push(a),o.length>=Ka.maxFrames)break}return o}function t$(t,e,o="person"){const r=Mh(e),a="const SK="+JSON.stringify(t??[])+";const KIND="+JSON.stringify(o==="thing"?"thing":"person")+";"+e$;return Qe({code:a,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 e$=`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 o$({id:t,at:e,duration:o,settings:r,body:a=[],kind:n="person",label:i}){const c=Mh(r);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:zd(e),duration:zd(o),label:i||`Aura · ${c.look}`,motionV:2,posX:0,posY:0,scale:1,motion:t$(a,c,n)}}const Cs=Object.freeze({count:[3,8],size:[.05,.8],open:[.03,.6],items:24,head:.4}),Pl=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,Pa=t=>Math.round(t*1e4)/1e4;function r$({x:t,y:e,radius:o,squash:r=.38,count:a=8,seed:n=3}){let i=n>>>0||1;const c=()=>(i=i*1664525+1013904223>>>0)/2**32,u=[],p=(s,h,f,m,g,v)=>{const x=[[s,h]];let E=s,$=h,S=f;for(let k=1;k<=g;k++){S+=(c()-.5)*.9;const y=m/g*(.7+.6*c());E+=Math.cos(S)*y,$+=Math.sin(S)*y*r,x.push([E,$]),v<1&&k>1&&k<g&&c()<.28&&p(E,$,S+(c()<.5?-1:1)*(.5+.5*c()),m*(.35+.25*c()),Math.max(2,g-k),v+1)}u.push({pts:x,depth:v})};for(let s=0;s<a;s++)p(t,e,(s+c()*.7)/a*Math.PI*2,o*(.55+.45*c()),7,0);return u}function Pm(t,e){const o=t.slice(1).reduce((i,c,u)=>i+Math.hypot(c[0]-t[u][0],c[1]-t[u][1]),0),r=o*e,a=[t[0]];let n=0;for(let i=1;i<t.length;i++){const c=Math.hypot(t[i][0]-t[i-1][0],t[i][1]-t[i-1][1]);if(n+c>=r){const u=(r-n)/(c||1);return a.push([t[i-1][0]+(t[i][0]-t[i-1][0])*u,t[i-1][1]+(t[i][1]-t[i-1][1])*u]),a}n+=c,a.push(t[i])}return a}function n$({id:t,at:e,duration:o=1.6,u:r,v:a,size:n=.3,squash:i=.38,count:c=6,open:u=.12,color:p="#1a120c",seed:s=3,W:h=1280,H:f=720}){const m=Cx(h,f),g=Math.round(Pl(c,Cs.count,6)),v=Pl(n,Cs.size,.3)*h,x=Pl(u,Cs.open,.12),E=Math.max(x+.3,o),$=r$({x:r*h,y:a*f,radius:v,squash:Pl(i,[.15,1],.38),count:g,seed:s}),S=Math.max(1.2,h/900),k=[],y=$.filter(j=>j.depth===0),C=$.filter(j=>j.depth>0).slice(0,Math.max(0,Cs.items-3*y.length)),A=(j,P,F,N,G,V,et=[0,0])=>k.push({id:j,name:P,type:"path",params:{pts:F.map(U=>m.pt(U)),closed:!1},pos:et,rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:G,width:Pa(m.len(N)),cap:"round",join:"round",opacity:V}});y.forEach(({pts:j},P)=>{A(`c${P}l`,`crack ${P+1} lip`,Pm(j,.7),S*1.6,"#ffffff",.18,[0,Pa(m.len(S*1.4))]),A(`c${P}`,`crack ${P+1}`,j,S,p,.85),A(`c${P}w`,`crack ${P+1} wide`,Pm(j,Cs.head),S*3.2,p,.9)}),C.forEach(({pts:j},P)=>A(`f${P}`,`crack fork ${P+1}`,j,S*.8,p,.75));let z={id:t,nodeId:"",kind:"image",url:"",volume:0,start:Pa(e),duration:Pa(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 z={...z,...ge(z,"trimEnd",[{time:0,value:0},{time:Pa(x),value:1}])},z={...z,...ge(z,"opacity",[{time:0,value:1},{time:Pa(E*.55),value:.85},{time:Pa(E),value:0}])},z}const Lm=Object.freeze(["float","turntable","drop-bounce","flip","fly-in","hero-spin","tilt-to-camera","exit-spin"]),a$=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}),Fm=t=>+t.toFixed(3);function i$(t,e){switch(t){case"float":{const r={y:[],ry:[]};for(let a=0;a<=4;a++){const n=a/4;r.y.push({t:n,v:(a%2?-1:1)*.025*e*(a&&a<4?1:0),ease:"ease-in-out"}),r.ry.push({t:n,v:(a%2?1:-1)*8*e*(a&&a<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 s$={rx:"tiltX",ry:"tiltY",rz:"rot"},Nm=t=>t==null?void 0:typeof t=="string"?t:Object.entries(Yt).find(([,e])=>JSON.stringify(e)===JSON.stringify(t))?.[0];function l$(t,e,{at:o=0,duration:r,amount:a=1}={}){const n=i$(e,Math.max(.25,Math.min(3,Number.isFinite(+a)?+a:1)));if(!n)throw Error(`Unknown 3D move: ${e}`);const i=Math.max(.2,Number.isFinite(+r)&&+r>0?+r:a$[e]),c=Math.max(0,+o||0),u=Math.min(t.duration,c+i);if(!(u-c>=.2))throw Error("3D move outside the clip");let p=t;for(const[s,h]of Object.entries(n)){const f=t.kind==="model"?s:s$[s]||s,m=["rx","ry","rz","tiltX","tiltY","rot"].includes(f);let g=Qt(p,f,c);m&&(g=(g%360+540)%360-180);const v=Ee(p,f).filter(E=>E.time<c-1/60||E.time>u+1/60).map(E=>({time:E.time,value:E.value,...Nm(E.ease)?{ease:Nm(E.ease)}:{}})),x=h.map(E=>({time:Fm(c+(u-c)*E.t),value:Fm(E.abs?E.v:g+E.v),...E.ease?{ease:E.ease}:{}}));p=ca(p,f,[...v,...x].sort((E,$)=>E.time-$.time))}return p}const jp=Object.freeze({x:"x",y:"y",lift:"depth",scale:"zoom",yaw:"ry",tilt:"rx",roll:"rz"}),c$=(t,e)=>t==="tilt"?90+e:e,p$=(t,e)=>t==="tilt"?e-90:e,mc=t=>Math.round(t*1e3)/1e3;function fT(t,e){const o={};for(const[r,a]of Object.entries(jp))o[r]=mc(p$(r,Qt(t,a,e)));return o}function mT(t){const e=[];for(const o of Object.values(jp))for(const r of Ee(t,o))e.some(a=>Math.abs(a-r.time)<1/60)||e.push(r.time);return e.sort((o,r)=>o-r)}function u$(t,e,o,r=!1){let a={...t,...pn(t)};for(const[i,c]of Object.entries(jp)){const u=e[i];if(typeof u!="number"||!Number.isFinite(u))continue;const p=mc(c$(i,u)),s=r&&!Ee(a,c).length?{motionKeys:br(a,c,[{time:mc(o),value:p}])}:Ep(a,c,p,mc(o));a={...a,...s},c==="depth"&&!Ee(a,c).length&&(a.modelDepth=p)}const n={};for(const i of["motionKeys","posX","posY","scale","spatialDepth","modelDepth","modelRotation"])a[i]!==t[i]&&(n[i]=a[i]);return n}function gT(t,e){let o={...t};for(const r of Object.values(jp)){const a=Ee(o,r);a.some(n=>Math.abs(n.time-e)<1/60)&&(o={...o,motionKeys:br(o,r,a.filter(n=>Math.abs(n.time-e)>=1/60))})}return{motionKeys:o.motionKeys??[]}}const yT=["easy-ease","ease-out","ease-in-out","expo-out","back-out","linear"],bT=["none","elastic","bounce"],d$=Object.freeze({ease:"easy-ease",in:.5,out:.4,settle:"none"}),vh=t=>({...d$,...t||{}}),wT=t=>{const e=Yt[vh(t).ease];return Array.isArray(e)&&!(e[0]===0&&e[1]===0&&e[2]===1&&e[3]===1)?[...e]:void 0};function h$(t){const e=Yt[vh(t).ease];return Array.isArray(e)?{in:+(1-e[2]).toFixed(2),out:+e[0].toFixed(2)}:{in:0,out:0}}const f$=Object.freeze(["hero","icon","broll","motion","text"]),kT=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"}}),Rm=300,m$=300,g$=/^[A-Za-z0-9_-]{1,40}$/;function y$(t){if(!Array.isArray(t)||t.length>Rm)throw Error(`At most ${Rm} 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(!g$.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(!f$.includes(o.kind))throw Error("Invalid pin kind");if(o.note!==void 0&&(typeof o.note!="string"||o.note.length>m$))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 b$(t,e){const o=e?.[t.from],r=e?.[t.to];return o&&r?{start:o.start,end:r.end}:null}const Fy=(t,e)=>!t.some(o=>o.nodeId===e&&o.kind!=="audio"&&!o.reverse),Ny=(t,e,o)=>t.nodeId!==e||t.kind==="audio"!==o||t.reverse;function Dm(t,e,o){const r=Fy(t,e);for(const a of t){if(Ny(a,e,r))continue;const n=a.inPoint||0,i=n+vp(a);if(o>=n-1e-6&&o<i-1e-6)return+(a.start+Ja(a,o-n)).toFixed(3)}return null}function xT(t,e,o){const r=(o.start+o.end)/2,a=Fy(t,e);for(const n of t){if(Ny(n,e,a))continue;const i=n.inPoint||0,c=i+vp(n);if(r>=i-1e-6&&r<c-1e-6)return+(n.start+Ja(n,Math.max(o.start,i)-i)).toFixed(3)}return null}function MT(t,e,o){const r=b$(t,o);if(!r)return null;const a=Dm(e,t.mediaId,r.start),n=Dm(e,t.mediaId,Math.max(r.start,r.end-.02));return a===null&&n===null?null:{start:a??n,end:n!==null?+(n+.02).toFixed(3):a,cut:a===null||n===null}}function w$(t,e=.6){const o=[];let r=0;return(t||[]).forEach((a,n)=>{const i=t[n+1],c=/[.?!…]["'”)]?$/.test(String(a.word).trim()),u=i&&i.start-a.end>=e;(!i||c||u)&&(o.push({from:r,to:n}),r=n+1)}),o}const k$=/\d/,Bm=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(" ")),x$=new Set("xin chào cảm ơn hello hi".split(" "));function vT(t,e,{existing:o=[],newId:r}={}){const a=new Set(o.flatMap(c=>Array.from({length:c.to-c.from+1},(u,p)=>c.from+p))),n=r||(()=>{let c=0;return()=>`p${Date.now().toString(36)}${(c++).toString(36)}`})(),i=[];for(const c of w$(t)){const u=Array.from({length:c.to-c.from+1},(g,v)=>c.from+v).filter(g=>!a.has(g)),p=u.find(g=>k$.test(t[g].word));if(p!==void 0){const g=Math.min(c.to,p+(t[p+1]&&/^(%|triệu|tỷ|nghìn|k|đ|đồng|usd|\$)/i.test(t[p+1].word)?1:0));i.push({id:n(),mediaId:e,from:p,to:g,kind:"text",status:"idea"});continue}const s=g=>{const v=String(t[g].word).replace(/[^\p{L}\p{N}]/gu,""),x=v.toLowerCase();return!v||Bm.has(x)||x$.has(x)?0:p1(v)+(g>c.from&&/^\p{Lu}/u.test(v)?3:0)+(g-c.from)/(c.to-c.from+1)},h=u.filter(g=>s(g)>=1.5).sort((g,v)=>s(v)-s(g))[0],f=g=>String(t[g]?.word??"").replace(/[^\p{L}\p{N}]/gu,""),m=h!==void 0&&h>c.from&&u.includes(h-1)&&/^\p{Ll}/u.test(f(h))&&/^\p{Ll}/u.test(f(h-1))&&!Bm.has(f(h-1).toLowerCase())?h-1:h;h!==void 0&&c.to-c.from>=3&&i.push({id:n(),mediaId:e,from:m,to:h,kind:"hero",status:"idea"})}return i}const _m=500,M$=60,Xc=Object.freeze(["#ffd23f","#ff5d73","#4fb3ff","#3ddc84","#b18cff","#ff9f43"]),Vm=Object.freeze(["beats","bars","drops","hits"]),Ry=(t,e)=>t.t-e.t||t.id.localeCompare(e.id),Dy=t=>typeof t=="string"?t.trim().slice(0,M$):void 0,By=t=>{if(typeof t!="number"||!Number.isFinite(t)||t<0||t>Xn)throw Error(`Marker time must be 0–${Xn} s`);return ut(t)};let v$=0;const $$=()=>`m${Date.now().toString(36)}${(v$++).toString(36)}`;function E$(t,{t:e,label:o,color:r,id:a=$$()}={}){const n=By(e),i=t.find(p=>Math.abs(p.t-n)<1e-6);if(i)return{markers:t,id:i.id,added:!1};if(t.length>=_m)throw Error(`Tối đa ${_m} marker`);if(r!==void 0&&!Xc.includes(r))throw Error("Màu marker không hợp lệ");const c=Dy(o),u={id:a,t:n,...c?{label:c}:{},...r?{color:r}:{}};return{markers:[...t,u].sort(Ry),id:a,added:!0}}function S$(t,e,{t:o,label:r,color:a}={}){const n=t.find(c=>c.id===e);if(!n)throw Error(`Không thấy marker ${e}`);if(a!=null&&!Xc.includes(a))throw Error("Màu marker không hợp lệ");const i={...n};if(o!==void 0&&(i.t=By(o)),r!==void 0){const c=Dy(r);c?i.label=c:delete i.label}return a!==void 0&&(a?i.color=a:delete i.color),t.map(c=>c.id===e?i:c).sort(Ry)}function I$(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 Gm(t,e,{density:o="beats"}={}){const r={hit:0,beat:1,bar:2,drop:3},a=new Map;for(const n of t??[]){if(n.disabled||n.reverse)continue;const i=e?.find(h=>h.id===n.nodeId)?.beats;if(!Array.isArray(i?.beats)||!((i.confidence??0)>=Cp))continue;const c=Number(n.playbackRate)||1,u=Number(n.inPoint)||0,p=u+n.duration*c,s=[["drop",i.drops],...o==="drops"?[]:[["bar",i.downbeats]],...o==="beats"?[["beat",i.beats]]:[],...o==="hits"?[["hit",i.hits]]:[]];for(const[h,f]of s)for(const m of Array.isArray(f)?f:[]){if(m<u-1e-6||m>=p-1e-6)continue;const g=ut(n.start+(m-u)/c),v=g.toFixed(3),x=a.get(v);(!x||r[h]>r[x.kind])&&a.set(v,{t:g,kind:h})}}return[...a.values()].sort((n,i)=>n.t-i.t)}function $T(t,e=[]){return[...new Set([...(t??[]).map(o=>o.t),...e.map(o=>o.t)])].sort((o,r)=>o-r)}function ET(t,e,{pps:o,px:r=8}){let a=null;for(const n of t)(a===null||Math.abs(n-e)<Math.abs(a-e))&&(a=n);return a!==null&&Math.abs(a-e)*o<r?a:null}function A$(t,e){const o=t.start+.03333333333333333-1e-6,r=t.start+t.duration-1/30+1e-6;return e.filter(a=>a>o&&a<r).sort((a,n)=>a-n)}const Io=t=>Object.freeze(t),_n=Object.freeze({white:Io({vi:"Chớp trắng",en:"White flash",fx:[["exposure",[[0,1,"hold"],[1,.75,"ease-out"],[5,0]]]]}),"white-double":Io({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:Io({vi:"Bật sáng",en:"Exposure pop",fx:[["exposure",[[0,.55,"ease-out"],[6,0]]]]}),negative:Io({vi:"Âm bản 2 khung",en:"Negative (2 frames)",fx:[["invert",[[0,1,"hold"],[2,0]]]]}),"negative-double":Io({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":Io({vi:"Âm bản 1 khung",en:"Negative blink (1 frame)",fx:[["invert",[[0,1,"hold"],[1,0]]]]}),"luma-negative":Io({vi:"Âm bản giữ màu",en:"Hue-keeping negative",fx:[["luma-invert",[[0,1,"hold"],[3,0]]]]}),"flash-negative":Io({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:Io({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:Io({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:Io({vi:"Giật tách màu",en:"RGB hit",fx:[["rgb-split",[[0,1,"ease-out"],[6,0]]]]}),blur:Io({vi:"Nhoè giật",en:"Blur hit",fx:[["blur",[[0,.8,"ease-out"],[6,0]]]]}),threshold:Io({vi:"Đen trắng gắt 2 khung",en:"Hard black & white (2 frames)",fx:[["threshold",[[0,.5,"hold"],[2,0]]]]}),"threshold-blink":Io({vi:"Đen trắng gắt 1 khung",en:"Hard black & white blink (1 frame)",fx:[["threshold",[[0,.5,"hold"],[1,0]]]]}),"poster-bw":Io({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]]]]}),"impact-bw":Io({vi:"Khung va chạm Đen-Trắng",en:"Anime B&W impact frame",fx:[["exposure",[[0,.9,"hold"],[1,0]]],["threshold",[[1,.52,"hold"],[3,0]]],["invert",[[2,1,"hold"],[3,0]]]]}),"impact-crimson":Io({vi:"Khung va chạm Huyết Chiến",en:"Combat impact flash",fx:[["exposure",[[0,.85,"hold"],[2,.35,"ease-out"],[5,0]]],["luma-invert",[[0,1,"hold"],[2,0]]],["rgb-split",[[0,1,"ease-out"],[6,0]]],["glow",[[0,.9,"ease-out"],[7,0]]]]})}),C$=Object.freeze(Object.keys(_n)),_y=30,Km=32,Pd=t=>(Math.max(..._n[t].fx.map(([,e])=>e.at(-1)[0]))+1)/_y;function Ld(t,e=1){const o=_n[t];if(!o)throw Error(`addFlash style: ${C$.join("|")}`);if(!Number.isFinite(e)||e<.1||e>1)throw Error("addFlash strength: 0.1..1");return o.fx.map(([r,a])=>{if(!Object.hasOwn(Ac,r))throw Error(`Unknown effect ${r}`);return{type:r,amount:1,keys:a.map(([n,i,c])=>({time:+(n/_y).toFixed(4),value:+Math.min(1,i*e).toFixed(3),...c?{ease:Yt[c]}:{}}))}})}const Ge=(t,e)=>({id:li(t),rot:0,scale:[1,1],opacity:1,...e}),Mr=t=>({type:"color",color:t}),aa={type:"none"},ia=(t,e,o={})=>({color:t,width:e,cap:"round",join:"round",...o});function Lr(t){const e=[];for(const o of t)e.push({...o,id:li(e)});return{v:2,items:e}}const $h={callout:{vi:"Callout",en:"Callout",build:({color:t})=>Lr([Ge([],{name:"Khung",type:"rect",params:{w:520,h:240,round:36},pos:[500,440],fill:Mr(t),stroke:null}),Ge([],{name:"Đuôi",type:"path",params:{pts:[[-40,-30],[40,-30],[-30,60]],closed:!0},pos:[420,590],fill:Mr(t),stroke:null})])},"chat-bubble":{vi:"Bong bóng chat",en:"Chat bubble",build:({color:t})=>Lr([Ge([],{name:"Bóng",type:"rect",params:{w:560,h:260,round:130},pos:[500,450],fill:Mr(t),stroke:null}),Ge([],{name:"Đuôi",type:"path",params:{pts:[[-20,-60],[60,-40,0,0,-20,40],[-70,60]],closed:!0},pos:[330,600],fill:Mr(t),stroke:null})])},badge:{vi:"Huy hiệu",en:"Badge",build:({color:t,accent:e})=>Lr([Ge([],{name:"Răng cưa",type:"star",params:{points:16,outer:260,inner:225,round:6},pos:[500,500],fill:Mr(t),stroke:null}),Ge([],{name:"Lõi",type:"ellipse",params:{w:380,h:380},pos:[500,500],fill:aa,stroke:ia(e,10)})])},"lower-third":{vi:"Lower third",en:"Lower third",build:({color:t,accent:e})=>Lr([Ge([],{name:"Vạch nhấn",type:"rect",params:{w:22,h:150,round:4},pos:[-60,790],fill:Mr(e),stroke:null}),Ge([],{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}),Ge([],{name:"Dòng phụ",type:"rect",params:{w:420,h:56,round:6},pos:[170,895],fill:Mr("#0d0f12"),stroke:null})])},"progress-bar":{vi:"Thanh tiến trình",en:"Progress bar",build:({color:t,duration:e})=>{const o=Lr([Ge([],{name:"Rãnh",type:"rect",params:{w:800,h:44,round:22},pos:[500,500],fill:Mr("#1f2622"),stroke:null}),Ge([],{name:"Tiến trình",type:"rect",params:{w:800,h:44,round:22},pos:[500,500],fill:Mr(t),stroke:null})]),r=+Math.max(.2,e).toFixed(3),a=o.items[1];return a.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})=>Lr([Ge([],{name:"Tia",type:"star",params:{points:18,outer:300,inner:170,round:0},pos:[500,500],fill:Mr(t),stroke:null})])},"loading-ring":{vi:"Vòng loading",en:"Loading ring",build:({color:t,duration:e})=>{const o=Lr([Ge([],{name:"Rãnh",type:"ellipse",params:{w:300,h:300},pos:[500,500],fill:aa,stroke:ia("#1f2622",26)}),Ge([],{name:"Vòng chạy",type:"ellipse",params:{w:300,h:300},pos:[500,500],fill:aa,stroke:ia(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})=>Lr([Ge([],{name:"Viền ngoài",type:"rect",params:{w:760,h:520,round:12},pos:[500,500],fill:aa,stroke:ia(t,28,{join:"miter",cap:"butt"})}),Ge([],{name:"Viền trong",type:"rect",params:{w:690,h:450,round:6},pos:[500,500],fill:aa,stroke:ia(e,4,{join:"miter",cap:"butt"})})])},"arrow-curved":{vi:"Mũi tên cong",en:"Curved arrow",build:({color:t})=>Lr([Ge([],{name:"Thân",type:"path",params:{pts:[[-280,160],[0,-120,-200,40,200,-40],[260,-40]],closed:!1},pos:[500,520],fill:aa,stroke:ia(t,22)}),Ge([],{name:"Đầu",type:"path",params:{pts:[[-60,-70],[0,0],[-80,40]],closed:!1},pos:[760,480],fill:aa,stroke:ia(t,22)})])},"arrow-bold":{vi:"Mũi tên đậm",en:"Bold arrow",build:({color:t})=>Lr([Ge([],{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:Mr(t),stroke:null})])},"hand-underline":{vi:"Gạch chân vẽ tay",en:"Hand-drawn underline",build:({color:t,duration:e})=>{const o=Lr([Ge([],{name:"Nét",type:"path",params:{pts:[[-380,10],[0,-6,-150,10,150,-14],[380,4]],closed:!1},pos:[500,620],fill:aa,stroke:ia(t,18),ops:[{...Bs("wiggle"),size:8,detail:24,speed:0,seed:3},{...Bs("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})=>Lr([Ge([],{name:"Nhãn",type:"path",params:{pts:[[-300,-120],[180,-120],[300,0],[180,120],[-300,120]],closed:!0},pos:[500,500],fill:Mr(t),stroke:null,ops:[{...Bs("round"),radius:24}]}),Ge([],{name:"Lỗ",type:"ellipse",params:{w:48,h:48},pos:[740,500],fill:Mr("#000000"),stroke:null,ops:[{...Bs("merge"),mode:"subtract"}]})])}},ST=Object.keys($h),j$={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 T$(t,{color:e="#c6f432",accent:o="#2bd4c9",duration:r=5,en:a=!1}={}){const n=$h[t];if(!n)throw Error(`Unknown library shape "${t}"`);const i=n.build({color:e,accent:o,duration:r});if(a)for(const c of i.items)c.name=j$[c.name]??c.name;return Ze(i)}const Vy={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}),O$=new Set(Object.values(Vy).flat().map(t=>`✨ ${t}`)),z$=t=>O$.has(t?.name),La=t=>+t.toFixed(3),uu=(t,e)=>{const o=Number(t);return Number.isFinite(o)?Math.max(0,Math.min(1,o)):e};function P$(t={}){return{smooth:uu(t.smooth,Ll.smooth),brighten:uu(t.brighten,Ll.brighten),even:uu(t.even,Ll.even),eyes:t.eyes==null?Ll.eyes:t.eyes===!0||t.eyes==="true"||Number(t.eyes)>0}}function L$(t,e="vi"){const o=u=>`✨ ${Vy[u][e==="en"?1:0]}`,{smooth:r,brighten:a,even:n,eyes:i}=t,c=[];return r>0&&c.push({name:o("smooth"),shape:"skin",fx:{type:"denoise",amount:La(Math.min(1,.45+.6*r)),size:La(Math.min(1,.45+.6*r))},blur:La(.1*r),contrast:La(1-.06*r)}),n>0&&c.push({name:o("even"),shape:"skin",saturation:La(1-.2*n)}),a>0&&c.push({name:o("brighten"),shape:"face",exposure:La(.05+.3*a),contrast:La(1-.06*a)}),i&&(r>0||a>0)&&c.push({name:o("eyes"),shape:"eyes",exposure:.08,contrast:1.1,sharpen:30}),c}const ao=t=>Math.round(t*1e4)/1e4,ai=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,F$=t=>t*t*(3-2*t),ml=Object.freeze({flipKeys:16,auraColors:["#ffd23f","#7dff6a","#3ff2ff","#e85dff"],maxHits:8}),N$=(t,e=16,o=9)=>{const r=Math.abs(t%180)*Math.PI/180,a=Math.min(r,Math.PI-r);return Math.cos(a)+Math.max(e/o,o/e)*Math.sin(a)};function R$(t,{from:e=0,to:o=.6,turn:r=180,back:a=!1,W:n=1280,H:i=720}={}){const c=pn(t),u={...t,...c};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=ai(r,-720,720,180);const p=ml.flipKeys,s=Array.from({length:p+1},($,S)=>ao(e+(o-e)*S/p)),h=$=>a?r*Math.sin(Math.PI*$):r*F$($),f=$=>Qt(u,"rot",$),m=$=>Qt(u,"zoom",$),g=$=>Ee(u,$).filter(S=>S.time<e-1e-6||S.time>o+1e-6),v=s.map(($,S)=>({time:$,value:ao(f($)+h(S/p))})),x=s.map(($,S)=>{const k=N$(h(S/p),n,i);return{time:$,value:ao(m($)*(k>1+1e-6?k*1.01:1))}});let E=br(u,"rot",[...g("rot"),...v].sort(($,S)=>$.time-S.time));return E=br({...u,motionKeys:E},"zoom",[...g("zoom"),...x].sort(($,S)=>$.time-S.time)),{...c,motionKeys:E,rotFit:"frame"}}function Wm(t,e,o="rainbow",r=ml.auraColors[0]){if(o==="fresnel")return[{type:"glow-pro",amount:.9,params:{color:r,tint:.95,radius:.45,threshold:.25,soft:.5,spread:.55,core:.7}},{type:"glow",amount:.85},...e?[{type:"invert",amount:1}]:[]].slice(0,yn);const a=Math.min(u1,Math.max(2,Math.round(t*3)+1)),n=Array.from({length:a},(c,u)=>({time:ao(t*u/(a-1)),value:ao(.5-.5*Math.cos(2*Math.PI*u/(a-1)))}));return[{type:"glow",amount:1},...e?[{type:"invert",amount:1}]:[{type:"blur",amount:.25}],{type:"hue",amount:0,keys:n},{type:"light-burst",amount:.7}].slice(0,yn)}function D$(t,e,{start:o,duration:r,color:a=ml.auraColors[0],silhouette:n=!1,style:i="rainbow"}={}){const c=Math.max(t.start,o??t.start),u=Math.min(t.start+t.duration,c+(r??t.start+t.duration-c));if(!(u-c>.2))throw Error("personAura must lie inside the person clip");const p=i==="fresnel",s=ao(u-c),h=ao((t.inPoint||0)+(c-t.start)*(t.playbackRate||1)),f=t.scale??1,m=Gy(t,c,s),g=Math.min(30,Math.max(3,Math.round(s*4)+1)),v={...t,...m,motionKeys:m.motionKeys??[],scale:m.scale??f},x=Array.from({length:g},(C,A)=>ao(s*A/(g-1))),E=p?1.012:1.035,$=p?.008:.025;let S=br(v,"zoom",x.map((C,A)=>({time:C,value:ao(Qt(v,"zoom",C)*(E+$*Math.sin(A*1.7)))})));S=br({...v,motionKeys:S},"opacity",x.map((C,A)=>({time:C,value:A===0||A===g-1?0:p?.96:.92})));const k=Jn(t,e(),{start:ao(c),duration:s,inPoint:h,label:`${t.label||"Video"} · ${p?"viền nội lực":"hào quang"}`,...m,motionV:2,motionKeys:S,edge:Zu({color:a,width:p?.018:.03,glow:2,amount:1}),effects:Wm(s,!1,i,a)});delete k.impacts;const y=Jn(t,e(),{start:ao(c),duration:s,inPoint:h,label:`${t.label||"Video"} · ${n?"bóng màu":"người nét"}`,...m,...n?{effects:Wm(s,!0,i,a).filter(C=>C.type!=="light-burst")}:{}});return n||delete y.effects,m.motionKeys||delete y.motionKeys,delete y.impacts,delete y.edge,[k,y]}function Gy(t,e,o){if(!t.motionKeys?.length)return{motionKeys:void 0};const r=ac(t,e-t.start,o),a={motionV:2,motionKeys:r.motionKeys};for(const n of["posX","posY","scale"])r[n]!==void 0&&(a[n]=r[n]);return a}const Ky=(t,e,{at:o,u:r,v:a,size:n=1,duration:i,label:c,params:u={}})=>{const p=Cn.find(s=>s.id===e);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:ao(Math.max(0,o)),duration:ao(i??p.duration),label:c,motionV:2,posX:ao(r-.5),posY:ao(a-.5),scale:ao(ai(n,.2,3,1)),motion:Qe({code:`@preset:${e}`,params:{...p.params,...u},preset:e})}},B$=({id:t,at:e,u:o,v:r,angle:a=200,length:n=1,size:i=1,duration:c=1.6,color:u})=>Ky(t,"vfx-breath-mist",{at:e,u:o,v:r,size:i,duration:c,label:"Hơi thở",params:{angle:ai(a,-360,360,200),length:ai(n,.2,3,1),seed:Math.round(e*1e3)%997+1,...u?{color:u}:{}}}),_$=({id:t,at:e,u:o,v:r,size:a=1,color:n})=>({...Ky(t,"vfx-light-pillar",{at:e,u:.5,v:.5,size:1,label:"Cột sáng",params:{x:ao(ai(o,0,1,.5)),y:ao(ai(r,0,1,.5)),size:ao(ai(a,.2,3,1)),seed:Math.round(e*1e3)%997+1,...n?{color:n}:{}}})});function V$(t){const e=(Array.isArray(t.hits)?t.hits:Number.isFinite(t.at)?[t.at]:[]).filter(Number.isFinite).slice(0,ml.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 a of e)r.push({op:"addImpact",clipId:t.clipId,at:a,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 G$(t,e){const o=[];for(const r of[...e].sort((a,n)=>a-n)){const a=r-t.start;for(const[n,i]of[[-.06,0],[0,1],[.18,.55],[.5,0]]){const c=ao(a+n);c>=0&&c<=t.duration&&(!o.length||c-o.at(-1).time>=1/60)&&o.push({time:c,value:i})}}return o.slice(0,u1)}const $a=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}),Fd="\\d+(?:[.,]\\d+)?",K$="(?:\\d{1,2}:)?\\d{1,2}:\\d{2}(?:[.,]\\d+)?",Hm=`(?:${K$}|${Fd})`,Uc="\\s*(?:s|sec|secs|giây|seconds?)\\b",W$=new RegExp(`(${Hm})(?:${Uc})?\\s*(?:-|–|—|→|->|~|đến|to)\\s*(${Hm})(?:${Uc})?`,"iu"),H$=new RegExp(`[([]\\s*(${Fd})${Uc}\\s*[)\\]]|^\\s*(${Fd})${Uc}\\s*[:\\-–—]`,"iu"),du=/^\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,Fl=/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,hu=/giây|giay|thời gian|thoi gian|time|tc\b|timecode|\bs\b|duration|độ dài|do dai/iu;function Xm(t){const e=String(t).trim().replace(",",".");return e.includes(":")?e.split(":").reduce((o,r)=>o*60+Number(r),0):Number(e)}const Nl=t=>String(t).replace(/\*\*|__|`/g,"").replace(/^[\s|"“”'‘’«»>*•\-–—]+|[\s"“”'‘’«»]+$/g,"").replace(/\s{2,}/g," ").trim();function fu(t){const e=W$.exec(t);if(e){const r=Xm(e[1]),a=Xm(e[2]);if(Number.isFinite(r)&&a>r)return{time:{start:r,end:a},rest:t.replace(e[0]," ")}}const o=H$.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 X$=t=>t.includes(" ")?t.split(" "):t.trim().startsWith("|")?t.trim().replace(/^\||\|$/g,"").split("|"):null,Rl=t=>/\p{L}{2}/u.test(t);function Um(t){const o=String(t??"").slice(0,$a.maxChars).replace(/\r\n?/g,`
98
+ `).split(`
99
+ `),r=o.map(X$);let a=-1,n=-1;const i=r.filter(p=>p&&p.length>1&&!p.every(s=>/^\s*:?-{2,}:?\s*$/.test(s)));if(i.length){const p=i[0],s=i.length>=2&&p.every(f=>!/\d/.test(f)||hu.test(f))&&p.some(f=>Fl.test(f)||hu.test(f));s&&(a=p.findIndex(f=>Fl.test(f)),n=p.findIndex(f=>hu.test(f)&&!Fl.test(f)));const h=s?i.slice(1):i;if(a<0){const f=Math.max(...h.map(g=>g.length)),m=g=>h.reduce((v,x)=>v+(Rl(x[g]??"")?x[g].length:0),0);a=[...Array(f).keys()].filter(g=>g!==n).sort((g,v)=>m(v)-m(g))[0]??0}}const c=[];let u=null;for(const[p,s]of o.entries()){const h=r[p];if(h&&h.length>1){if(h.every(y=>/^\s*:?-{2,}:?\s*$/.test(y)))continue;const x=Nl(h[a]??"");if(!x||Fl.test(x)&&x.split(/\s+/).length<=3&&i[0]===h)continue;let E=null;for(const[y,C]of h.entries()){if(y===a)continue;const A=fu(C).time;if(A){E=A;break}}!E&&n>=0&&/^\s*\d+(?:[.,]\d+)?\s*$/.test(h[n]??"")&&(E={duration:Number(h[n].replace(",","."))});const{time:$,rest:S}=fu(x),k=Nl(S.replace(du,""));Rl(k)&&c.push({text:k,...$??E??{}});continue}if(!s.trim()||/^\s*(#{1,6}\s|={3,}|-{3,}\s*$)/.test(s)&&!Rl(s.replace(/^#+/,"").trim())||/^\s*#{1,6}\s/.test(s))continue;const{time:f,rest:m}=fu(s);if(!f&&/\p{Lu}/u.test(s)&&s===s.toUpperCase()&&s.trim().split(/\s+/).length<=4)continue;let g=Nl(m.replace(du,"").replace(du,""));const v=/(?:lời|loi|thoại|thoai|vo|voice ?over)\s*[::]\s*(.+)$/iu.exec(m);if(v&&(g=Nl(v[1])),!Rl(g)){f&&(u=f);continue}if(c.push({text:g,...f??u??{}}),u=null,c.length>=$a.maxLines)break}return c.slice(0,$a.maxLines).map(p=>{const s={text:p.text.slice(0,600)};return Number.isFinite(p.start)&&Number.isFinite(p.end)&&p.end>p.start?(s.start=+p.start.toFixed(3),s.end=+p.end.toFixed(3),s.duration=+(p.end-p.start).toFixed(3)):p.duration>0&&(s.duration=+p.duration.toFixed(3)),s})}const U$=t=>String(t).split(/\s+/).filter(e=>!hl(e)).map(ws).filter(Boolean);function Y$(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,a=0;for(;o<t.length&&r<e.length;){if(t[o]===e[r]){o++,r++;continue}if(++a>1)return 0;t.length>e.length?o++:(e.length>t.length||o++,r++)}return a+(t.length-o)+(e.length-r)<=1?1:0}const q$=2,Z$=1,J$=-1,Q$=-1,t6=-.5;function Ym(t,e,o,r){const a=t.length,n=r-o;if(!a||n<=0)return null;let i=new Float64Array(n+1),c=new Float64Array(n+1);const u=new Uint8Array((a+1)*(n+1)),p=new Uint8Array((a+1)*(n+1));let s=0,h=0,f=0;for(let E=1;E<=a;E++){c[0]=0;for(let $=1;$<=n;$++){const S=Y$(t[E-1],e[o+$-1]),k=i[$-1]+(S===2?q$:S===1?Z$:J$),y=i[$]+Q$,C=c[$-1]+t6;let A=0,z=0;k>A&&(A=k,z=1),y>A&&(A=y,z=2),C>A&&(A=C,z=3),c[$]=A,u[E*(n+1)+$]=z,p[E*(n+1)+$]=z===1?S:0,A>s&&(s=A,h=E,f=$)}[i,c]=[c,i]}if(s<=0)return null;let m=h,g=f,v=0,x=f;for(;m>0&&g>0;){const E=u[m*(n+1)+g];if(E===0)break;E===1?(v+=p[m*(n+1)+g]/2,x=g,m--,g--):E===2?m--:g--}return{score:s,a:o+x-1,b:o+f-1,matched:v,coverage:v/a}}function e6(t,e,o=e.map(r=>ws(r.word))){const r=U$(t.text??t);if(!r.length)return[];const a=r.length+Math.ceil(r.length*.3)+2,n=new Set(r.slice(0,3)),i=new Set(r.slice(-3)),c=[],u=s=>{if(!s||s.coverage<$a.minCoverage)return;const h=c.find(f=>s.a<=f.b&&s.b>=f.a);h?s.score>h.score&&Object.assign(h,s):c.push(s)},p=s=>c.some(h=>s>h.a&&s<=h.b);for(let s=0;s<o.length;s++)n.has(o[s])&&!p(s)&&u(Ym(r,o,s,Math.min(o.length,s+a))),i.has(o[s])&&!p(s)&&u(Ym(r,o,Math.max(0,s-a+1),s+1));return c.sort((s,h)=>s.a-h.a)}function o6(t,{maxPause:e=$a.maxPause}={}){const o=(Array.isArray(t)?t:[]).filter(c=>Number.isFinite(c?.start)&&Number.isFinite(c?.end)&&!hl(c.word)).sort((c,u)=>c.start-u.start);if(o.length<12)return null;let r=0,a=o[0].start;const n=[];for(let c=1;c<=o.length;c++){const u=c<o.length?o[c].start-o[c-1].end:1/0;u>e&&(r+=o[c-1].end-a,c<o.length&&(u<3&&n.push(u),a=o[c].start))}if(!(r>0))return null;n.sort((c,u)=>c-u);const i=n.length?n[n.length>>1]:$a.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)),cr=t=>+t.toFixed(3);function r6(t,e,o={}){const r={...$a,...o.maxPause?{maxPause:Dl(o.maxPause,.2,3)}:{}},a=o.pace??null;a?.pause&&(r.pause=Dl(a.pause,.12,.6),r.maxPause=o.maxPause?r.maxPause:Math.max(.3,r.pause*1.6));const n=o.cutPauses!==!1,i=o.speed!==!1,c=new Set(o.skip??[]),u=(Array.isArray(e)?e:[]).filter(E=>Number.isFinite(E?.start)&&Number.isFinite(E?.end)&&E.end>=E.start&&!hl(E.word)).sort((E,$)=>E.start-$.start),p=u.map(E=>ws(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,$)=>E.start-$.start),h=E=>s.find($=>$.start>=E-.05&&$.start<=E+r.snap),f=E=>[...s].reverse().find($=>$.end<=E+.05&&$.end>=E-r.snap),m=(E,$)=>s.find(S=>S.start<$&&S.end>E),g=[],v=[];for(const[E,$]of t.entries()){const S={index:E,text:$.text,...$.duration?{target:$.duration}:{}};if(c.has(E)){v.push({...S,status:"skipped"});continue}const k=e6($,u,p);if(!k.length){v.push({...S,status:"missing",takes:0});continue}const y=k.filter(D=>!g.some(q=>D.a<=q.b&&D.b>=q.a)),C=y.length?y:k,A=Math.max(...C.map(D=>D.coverage)),z=C.filter(D=>D.coverage>=A-r.tieCoverage).at(-1);g.push(z);const j=u.slice(z.a,z.b+1),P=u[z.a-1],F=u[z.b+1],N=(D,q)=>u.filter((pt,yt)=>(yt<z.a||yt>z.b)&&pt.end>D+.02&&pt.start<q-.02).length;let G=f(j[0].start),V=h(j.at(-1).end);G&&N(G.end,j[0].start)>0&&(G=null),V&&N(j.at(-1).end,V.start)>2&&(V=null);const et=G?Math.max(G.start,G.end-Math.min(r.lead,(G.end-G.start)/2)):Math.max(j[0].start-r.lead,P?P.end+.02:0,0),U=V?Math.min(V.end,V.start+Math.min(r.tail,(V.end-V.start)/2)):Math.min(j.at(-1).end+r.tail,F?F.start-.02:1/0),at=[];let W=et,_=0,J=0;for(let D=1;D<j.length;D++){const q=j[D].start-j[D-1].end;if(n&&q>r.maxPause){const pt=m(j[D-1].end,j[D].start),yt=pt?Math.max(pt.start,j[D-1].end):j[D-1].end,Mt=pt?Math.min(pt.end,j[D].start):j[D].start;if(Mt-yt<=r.pause)continue;const l=r.pause/2;at.push({start:cr(W),end:cr(yt+l)}),W=Mt-l,_++,J+=Mt-yt-r.pause}}at.push({start:cr(W),end:cr(U)});const tt=at.reduce((D,q)=>D+q.end-q.start,0);let rt=1;if(i&&$.duration>0)rt=Dl(tt/$.duration,r.minRate,r.maxRate);else if(i&&a?.wordsPerSecond){const D=at.reduce((q,pt)=>q+pt.end-pt.start,0)-(r.lead+r.tail);D>.5&&(rt=Dl(a.wordsPerSecond/(j.length/D),r.minRate,r.maxRate))}Math.abs(rt-1)<r.rateStep&&(rt=1),rt=+rt.toFixed(2),v.push({...S,status:"ok",takes:k.length,take:k.indexOf(z),coverage:+z.coverage.toFixed(2),source:{start:cr(et),end:cr(U)},heard:j.map(D=>D.word).join(" "),pieces:at,pausesCut:_,pauseSaved:cr(J),rate:rt,natural:cr(tt),final:cr(tt/rt)})}const x=v.filter(E=>E.status==="ok");for(const E of x)for(const $ of x){if(E===$||!($.source.start<E.source.end&&$.source.start>=E.source.start))continue;const S=$.pieces[0];E.source.end>=S.end-.05||(S.start=$.source.start=cr(E.source.end),$.natural=cr($.pieces.reduce((k,y)=>k+y.end-y.start,0)),$.final=cr($.natural/$.rate))}return{lines:v,found:x.length,missing:v.filter(E=>E.status==="missing").length,length:cr(x.reduce((E,$)=>E+$.final,0)),pause:r.pause,maxPause:r.maxPause,...a?{pace:a}:{}}}const n6=t=>t.label||t.id;function a6(t,e,o,r={}){const a=r.tracks??{},n=r.makeId??(()=>Math.random().toString(36).slice(2,10)),i=r.maxClips??tl,c=r.isBed??(y=>y.kind==="audio"),u=t.find(y=>y.id===e);if(!u||!["video","audio"].includes(u.kind))throw Error("Script edit needs the talking video or audio clip");if(u.reverse)throw Error("Script edit does not support reversed clips");if(an(u)||u?.timeRemap)throw Error("Script edit does not support speed-ramped or time-remapped clips");if(Array.isArray(u.motionKeys)&&u.motionKeys.length)throw Error("The clip has keyframes — run the script edit on the raw clip, before animating it");if(a[u.track]?.locked)throw Error("Track is locked");const p=o.lines.filter(y=>y.status==="ok");if(!p.length)throw Error("No script line was found in the clip");const s=u.start+u.duration,h=t.filter(y=>y.id!==u.id&&y.nodeId===u.nodeId&&y.track!==u.track&&Math.abs(y.start-u.start)<1/30&&Math.abs(y.duration-u.duration)<1/30&&!y.reverse),f=new Set(h.map(y=>y.id)),m=t.filter(y=>y.id!==u.id&&!f.has(y.id)&&y.track!==u.track&&!c(y)&&y.start<s-1/60&&y.start+y.duration>u.start+1/60);if(m.length)throw Error(`Layers over the clip would lose their place: ${m.slice(0,3).map(n6).join(", ")} — run the script edit before adding titles / B-roll`);if(t.some(y=>a[y.track]?.locked&&y.start>=s-1/60))throw Error("A locked track has clips after the clip");const g=p.flatMap(y=>y.pieces.map(C=>({...C,rate:y.rate,line:y.index}))),v=(g.length-1)*(1+h.length);if(t.length+v>i)throw Error(`Too many clips: the script edit needs ${g.length} pieces (limit ${i})`);const x=(y,C)=>{let A=u.start;return g.map((z,j)=>{const P=ut((z.end-z.start)/z.rate),F={...y,id:j===0?C:n(),start:ut(A),inPoint:cr(z.start),duration:P,playbackRate:z.rate};return F.playbackRate===1&&delete F.playbackRate,A+=P,F})},E=x(u,u.id),$=E.reduce((y,C)=>y+C.duration,0),S=ut($-u.duration);return{clips:t.flatMap(y=>y.id===u.id?E:f.has(y.id)?x(y,y.id).map((C,A)=>({...C,track:y.track,start:E[A].start,duration:E[A].duration})):y.start>=s-1/60&&!(c(y)&&y.track!==u.track)?[{...y,start:ut(Math.max(0,y.start+S))}]:[y]),pieces:g.length,length:ut($),delta:S}}function i6(t,e=!1){return t.lines.map(o=>{const r=`#${o.index+1}`,a=o.text.length>48?o.text.slice(0,47)+"…":o.text;if(o.status==="skipped")return e?`${r} "${a}": left out`:`${r} "${a}": bỏ qua`;if(o.status==="missing")return e?`${r} "${a}": not found in the clip`:`${r} "${a}": không thấy trong clip`;const n=[];return o.takes>1&&n.push(e?`take ${o.take+1} of ${o.takes}`:`lần ${o.take+1}/${o.takes}`),o.pausesCut&&n.push(e?`${o.pausesCut} pause${o.pausesCut>1?"s":""} −${o.pauseSaved}s`:`${o.pausesCut} chỗ ngừng −${o.pauseSaved}s`),o.rate!==1&&n.push(`${o.rate}×`),n.push(`${o.final.toFixed(1)}s${o.target?` / ${o.target}s`:""}`),`${r} "${a}": ${n.join(", ")}`})}const Nd=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})}),s6=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","inkline-birds","inkline-boat","inkline-cafe","inkline-cyclist","inkline-lanterns","inkline-moon-cta","inkline-office","inkline-park","inkline-rain","inkline-street","inkline-title","inkline-walker","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 l6=null;const c6=()=>l6??=new Function("return "+d1)(),mu=new Map;function p6(t){if(mu.has(t))return mu.get(t);const e=Cn.find(r=>r.id===t&&!r.kind);let o=null;if(e)try{o=new Function("M",'"use strict";'+e.code+`
100
+ ;return render`)(c6())}catch{o=null}return mu.set(t,o),o}const Rd=t=>Cn.find(e=>e.id===t&&!e.kind)??null,Bl=(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]],Yr=(t,e,o)=>[t[0]*e+t[2]*o+t[4],t[1]*e+t[3]*o+t[5]],qm=t=>{const e=/(\d+(?:\.\d+)?)px/.exec(String(t||""));return e?+e[1]:10},u6=t=>typeof t=="string"?t:t&&t.stops?.length?t.stops[Math.floor(t.stops.length/2)]:null;function d6(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 a=[];let n=[];const i=()=>Math.sqrt(Math.abs(r.m[0]*r.m[3]-r.m[1]*r.m[2])),c=(x,E)=>{const[$,S]=Yr(r.m,x,E);n.push({t:"pt",x:$,y:S})},u=()=>{const x={stops:[],addColorStop(E,$){x.stops.push($)}};return x},p=x=>{let E=1/0,$=1/0,S=-1/0,k=-1/0;for(const[y,C]of x)E=Math.min(E,y),$=Math.min($,C),S=Math.max(S,y),k=Math.max(k,C);return{x:E,y:$,w:S-E,h:k-$}},s=x=>{const E=$=>x.reduce((S,k)=>$(k)>$(S)?k:S);return[E($=>-($[0]+$[1])),E($=>$[0]-$[1]),E($=>$[0]+$[1]),E($=>$[1]-$[0])]},h=()=>{const x=[],E=[],$=[];let S=0,k=[],y=0,C=!1,A=0,z=!1,j=null;for(const V of n)V.t==="pt"?(x.push([V.x,V.y]),E.push([V.x,V.y])):V.t==="move"?(A++,x.push([V.x,V.y]),E.push([V.x,V.y])):V.t==="rect"?(y++,j=V.pts,x.push(...V.pts)):V.t==="arc"?(S++,C||=V.full,x.push([V.cx-V.r,V.cy-V.r],[V.cx+V.r,V.cy+V.r])):V.t==="arcTo"?(k.push(V.r),$.push([V.x,V.y]),x.push([V.x,V.y])):V.t==="close"&&(z=!0);if(!x.length)return null;const P=p(x);let F="path",N=0,G=null;if(y===1&&!S&&!k.length&&A<=1)F="rect",G=s(j);else if(k.length>=4&&A<=1&&!S)F="rrect",N=Math.min(...k),G=s($.slice(0,4));else if(S===1&&C&&!k.length&&!y&&x.length<=4)F="circle",N=P.w/2;else if(!S&&!k.length&&!y&&A===1&&(z||E.length>=4)){const V=E.length;if(V===4)F="quad",G=s(E);else if(V>=8&&V%4===0){const et=V/4,U=[];let at=0;for(let W=0;W<4;W++){const _=E.slice(W*et,W*et+et),J=_[0],tt=_[et-1],rt=[(J[0]+tt[0])/2,(J[1]+tt[1])/2];if(et>=4){const D=[_[1][0]+_[et-2][0],_[1][1]+_[et-2][1]],q=[(D[0]-J[0]-tt[0])/.366,(D[1]-J[1]-tt[1])/.366];U.push([rt[0]+q[0]/2,rt[1]+q[1]/2])}else U.push(rt);at+=Math.hypot(J[0]-tt[0],J[1]-tt[1])/Math.SQRT2}F="rrect",N=at/4,G=s(U)}}return{...P,kind:F,r:N,...G?{quad:G}:{}}},f=(x,E,$={})=>{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:u6(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,...$})},m=(x,E,$,S)=>{if(E=String(E??""),!E.trim())return;const k=qm(r.font),y=E.length*k*.56,C=r.textAlign,A=r.textBaseline,z=C==="center"?$-y/2:C==="right"||C==="end"?$-y:$,j=A==="top"||A==="hanging"?S:A==="middle"?S-k/2:A==="bottom"||A==="ideographic"?S-k:S-k*.8,P=[[z,j],[z+y,j],[z,j+k],[z+y,j+k]].map(([F,N])=>Yr(r.m,F,N));f(x,{...p(P),kind:"text",r:0},{text:E,size:k*i()})},g={save(){a.push({...r,m:[...r.m]})},restore(){a.length&&(r=a.pop())},translate(x,E){r.m=Bl(r.m,[1,0,0,1,x,E])},scale(x,E){r.m=Bl(r.m,[x,0,0,E,0,0])},rotate(x){const E=Math.cos(x),$=Math.sin(x);r.m=Bl(r.m,[E,$,-$,E,0,0])},transform(x,E,$,S,k,y){r.m=Bl(r.m,[x,E,$,S,k,y])},setTransform(x,E,$,S,k,y){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,$,S,k,y]},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(){n=[]},closePath(){n.push({t:"close"})},moveTo(x,E){const[$,S]=Yr(r.m,x,E);n.push({t:"move",x:$,y:S})},lineTo(x,E){c(x,E)},quadraticCurveTo(x,E,$,S){c(x,E),c($,S)},bezierCurveTo(x,E,$,S,k,y){c(x,E),c($,S),c(k,y)},arcTo(x,E,$,S,k){const[y,C]=Yr(r.m,x,E);n.push({t:"arcTo",x:y,y:C,r:k*i()}),c($,S)},arc(x,E,$,S,k,y){const[C,A]=Yr(r.m,x,E);n.push({t:"arc",cx:C,cy:A,r:Math.abs($)*i(),full:Math.abs((k??0)-(S??0))>=Math.PI*2-.001||!!y&&!1})},ellipse(x,E,$,S){const[k,y]=Yr(r.m,x,E);n.push({t:"arc",cx:k,cy:y,r:Math.max($,S)*i(),full:!1})},rect(x,E,$,S){n.push({t:"rect",pts:[[x,E],[x+$,E],[x,E+S],[x+$,E+S]].map(([k,y])=>Yr(r.m,k,y))})},roundRect(x,E,$,S,k){const y=Array.isArray(k)?k[0]:k,C=typeof y=="object"?y.x:y||0,A=[[x,E],[x+$,E],[x,E+S],[x+$,E+S]].map(([z,j])=>Yr(r.m,z,j));if(n.push({t:"rect",pts:A}),C>0){n.pop(),n.push({t:"move",x:A[0][0],y:A[0][1]});for(const z of A)n.push({t:"arcTo",x:z[0],y:z[1],r:C*i()})}},fill(){f("fill",h())},stroke(){f("stroke",h())},clip(){},fillRect(x,E,$,S){const k=[[x,E],[x+$,E],[x,E+S],[x+$,E+S]].map(([y,C])=>Yr(r.m,y,C));f("fill",{...p(k),kind:"rect",r:0})},strokeRect(x,E,$,S){const k=[[x,E],[x+$,E],[x,E+S],[x+$,E+S]].map(([y,C])=>Yr(r.m,y,C));f("stroke",{...p(k),kind:"rect",r:0})},clearRect(){},fillText(x,E,$){m("fill",x,E,$)},strokeText(x,E,$){m("stroke",x,E,$)},measureText(x){const E=qm(r.font);return{width:String(x).length*E*.56,actualBoundingBoxAscent:E*.8,actualBoundingBoxDescent:E*.2}},drawImage(x,...E){const[$,S,k,y]=E.length>=8?E.slice(4):E.length>=4?E:[E[0],E[1],x?.width||0,x?.height||0],C=[[$,S],[$+k,S],[$,S+y],[$+k,S+y]].map(([A,z])=>Yr(r.m,A,z));f("fill",{...p(C),kind:"image",r:0})},createLinearGradient:u,createRadialGradient:u,createConicGradient:u,createPattern:()=>({stops:[]}),getImageData:(x,E,$,S)=>({data:new Uint8ClampedArray(Math.max(4,($|0)*(S|0)*4)),width:$,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 g?g[E]:E in r?r[E]:void 0,set:(x,E,$)=>(E!=="m"&&(r[E]=$),!0)})}function h6(t,e,{W:o=1280,H:r=720,params:a={},duration:n}={}){const i=p6(t),c=Rd(t);if(!i||!c)return[];const u=d6(o,r),p=n??c.duration;try{i(u,e,Object.freeze({width:o,height:r,duration:p,fps:30,progress:p?e/p:0,params:Object.freeze({...c.params,...a}),fonts:{}}))}catch{return u.draws.slice()}return u.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(a=>a+a).join(""):e[1];return[0,2,4].map(a=>parseInt(r.slice(a,a+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},f6=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 a=o[1].split(",").map(Number);return a[3]>=.05?[a.slice(0,3),a[3]]:null}const r=Ki(t);return r?[r,1]:null},Zm=[14,16,19],Jm=(t,e,o)=>t.map((r,a)=>r+(e[a]-r)*o),js=t=>{if(!t)return 0;const e=Math.max(...t),o=Math.min(...t);return e?(e-o)/e:0},_l=t=>t?(.2126*t[0]+.7152*t[1]+.0722*t[2])/255:0,m6=(t,e)=>{const o=Math.max(t.x,e.x),r=Math.max(t.y,e.y),a=Math.min(t.x+t.w,e.x+e.w),n=Math.min(t.y+t.h,e.y+e.h),i=Math.max(0,a-o)*Math.max(0,n-r);return i/(t.w*t.h+e.w*e.h-i||1)},Ts=t=>t?"#"+t.map(e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")).join(""):null;function g6(t,{W:e=1280,H:o=720,accent:r}={}){const a=e*o,n=Ki(r),i=[];for(const p of t){if(p.kind==="text"||p.kind==="image"||p.kind==="path")continue;const s=p.w*p.h;if(s>a*.85||p.w<6||p.h<6||s<a*8e-4||Math.max(0,Math.min(e,p.x+p.w)-Math.max(0,p.x))*Math.max(0,Math.min(o,p.y+p.h)-Math.max(0,p.y))/s<.7||p.w>e*.92&&p.op==="fill"&&!p.glow||p.alpha<.3||p.gradient&&p.kind==="circle"&&p.op==="fill"&&p.alpha<.8)continue;const f=i.find(x=>m6(x,p)>.88),m=f6(p.color),g=m?m[0]:null,v=m?m[1]*p.alpha:0;if(f){p.op==="fill"&&g&&(f.fillRgb=Jm(f.fillRgb??Zm,g,v)),p.op==="stroke"&&g&&(f.borderRgb=g),p.glow&&(f.glow=p.glow),f.z=Math.max(f.z,p.z);continue}i.push({x:p.x,y:p.y,w:p.w,h:p.h,kind:p.kind,r:p.r,quad:p.quad,fillRgb:p.op==="fill"&&g?Jm(Zm,g,v):null,borderRgb:p.op==="stroke"?g:null,glow:p.glow,z:p.z,alpha:p.alpha})}const c=[];for(const p of i){const s=p.w*p.h/a,h=Math.min(p.w,p.h),f=p.w/p.h;let m;if(p.kind==="circle"||p.kind==="rrect"&&p.r>=h*.45&&f>.8&&f<1.25?m="circle":p.kind==="rrect"&&p.r>=h*.38&&f>=1.6?m="pill":s<=.03&&f>=1.4&&f<=5&&(js(p.fillRgb)>.3||_l(p.fillRgb)>.55)?m="button":s<.008?m="chip":s<.42?m="card":m="panel",m==="chip"&&!p.borderRgb&&!p.glow&&js(p.fillRgb)<.25)continue;const g=p.borderRgb??p.fillRgb,v=n&&g?1-Math.min(1,Math.hypot(g[0]-n[0],g[1]-n[1],g[2]-n[2])/120):0,x=m==="panel"?.45:Math.min(1,Math.sqrt(s/.03));if(Math.max(_l(p.fillRgb)>.55?.7:js(p.fillRgb)*_l(p.fillRgb)*1.6,p.borderRgb?.8:0,p.glow?1:0)<.12)continue;const $=x+.7*Math.max(v,js(g)*_l(g))+(p.glow?.45:0)+(p.borderRgb?.25:0)+(m==="pill"||m==="button"?.35:m==="card"?.2:m==="circle"?.15:0)+.15*(p.z/Math.max(1,t.length));c.push({role:m,x:p.x,y:p.y,w:p.w,h:p.h,r:Math.min(p.r||0,h/2),...p.quad?{quad:p.quad.map(S=>S.map(k=>+k.toFixed(1)))}:{},fill:Ts(p.fillRgb),border:Ts(p.borderRgb),glow:p.glow?Ts(Ki(p.glow))??null:null,score:+$.toFixed(3)})}const u=t.filter(p=>p.kind==="text"&&p.alpha>.5&&p.size>=o*.035);for(const p of u){const s=Ki(p.color),h=c.find(f=>f.role==="headline"&&Math.abs(f.y-p.y)<p.size*.6&&Math.abs(f.size-p.size)<2);if(h){const f=Math.min(h.x,p.x),m=Math.max(h.x+h.w,p.x+p.w);h.x=f,h.w=m-f,h.text+=" "+p.text;continue}c.push({role:"headline",x:p.x,y:p.y,w:p.w,h:p.h,r:0,fill:Ts(s),border:null,glow:p.glow?Ts(Ki(p.glow)):null,text:p.text,size:p.size,score:+(.5+p.size/o*4+(js(s)>.4?.3:0)).toFixed(3)})}return c.sort((p,s)=>s.score-p.score).slice(0,8)}function y6(t,e,{W:o=1280,H:r=720,accent:a}={}){const n=t?.motion?.preset;if(!n||!Rd(n))return[];const i=t.motion.duration??Rd(n).duration,c=Math.max(0,Math.min(i-1/30,e+(t.inPoint||0)));return g6(h6(n,c,{W:o,H:r,params:t.motion.params||{},duration:i}),{W:o,H:r,accent:a??t.motion.params?.accent})}const b6={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}},Vn={minScore:.32,ease:"easy-ease",maxZoom:4},w6=t=>t.w*t.h,Qm=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],Wy=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]],Wi=t=>Math.sqrt(w6(t)),k6=t=>t.filter(e=>e.kind!=="audio"&&e.motion?.preset&&!e.seam?.hero),Dd=(t,e)=>({x:Qt(t,"x",e),y:Qt(t,"y",e),zoom:Qt(t,"zoom",e)});function x6(t,e,o,r){const a=([u,p])=>[o/2+e.x*o+(u-o/2)*e.zoom,r/2+e.y*r+(p-r/2)*e.zoom],n=Wy(t).map(a),i=n.map(u=>u[0]),c=n.map(u=>u[1]);return{...t,quad:n,x:Math.min(...i),y:Math.min(...c),w:Math.max(...i)-Math.min(...i),h:Math.max(...c)-Math.min(...c),r:t.r*e.zoom}}function t0(t,e,{W:o=1280,H:r=720,accent:a}={}){const n=[];for(const i of k6(t)){const c=e-i.start;if(c<-1e-6||c>i.duration+1e-6)continue;const u=Dd(i,c);for(const p of y6(i,c,{W:o,H:r,accent:a}))n.push({...x6(p,u,o,r),layer:i.id})}return n.sort((i,c)=>c.score-i.score)}function e0(t,e,o,r,{W:a=1280,H:n=720,accent:i}={}){const c=t0(t,o,{W:a,H:n,accent:i}).slice(0,5),u=t0(e,r,{W:a,H:n,accent:i}).slice(0,5);if(!c.length||!u.length)return null;const p=m=>Math.max(...m.map(g=>g.score)),s=p(c),h=p(u);let f=null;for(const m of c)for(const g of u){const v=b6[m.role]?.[g.role]??0;if(!v)continue;const x=y=>y.w/y.h,E=Math.min(x(m),x(g))/Math.max(x(m),x(g)),$=Math.min(Wi(m),Wi(g))/Math.max(Wi(m),Wi(g)),S=m.score/s*(g.score/h),k=v*(.7+.3*E)*(.65+.35*Math.sqrt($))*S*($<1/Vn.maxZoom?.6:1);(!f||k>f.score)&&(f={a:m,b:g,score:+k.toFixed(3)})}return f&&f.score>=Vn.minScore?f:null}const wa=t=>Math.round(t*1e4)/1e4;function M6(t,e,o,r,a,{W:n=1280,H:i=720,ease:c=Vn.ease}={}){const u=new Map,p=a-r,s=Object.hasOwn(Yt,c)?c:Vn.ease,[h,f]=Qm(t.a),[m,g]=Qm(t.b),v=Math.max(1/Vn.maxZoom,Math.min(Vn.maxZoom,Wi(t.b)/Wi(t.a))),x=($,S,k,y)=>{y=Math.min(y,Vn.maxZoom/Math.max(.01,$.zoom));const C=$.zoom*y,A=n/2+$.x*n,z=i/2+$.y*i;return{x:wa((k[0]-n/2-(S[0]-A)*y)/n),y:wa((k[1]-i/2-(S[1]-z)*y)/i),zoom:wa(C)}},E=($,S,k,y,C)=>{const A=$.duration,z=j=>Math.min(A,Math.max(0,wa(j-$.start)));for(const j of["x","y","zoom"])$=Gh($,j,[{time:z(S),value:k[j],ease:s},{time:z(S+p),value:y[j]}]);return Gh($,"opacity",C.map(([j,P])=>({time:z(S+j*p),value:P})))};for(const $ of e){if($.kind==="audio")continue;const S=ut(a-$.start);if(S<p+1/30)continue;let k={...$,duration:S};delete k.exit;const y=Dd($,r-$.start);k=E(k,r,{...y},x(y,[h,f],[m,g],v),[[.22,1],[.5,0]]),u.set(k.id,{...k,seam:{...k.seam,out:!0,excl:!0}})}for(const $ of o){if($.kind==="audio")continue;const S=ut($.start+$.duration-r);if(S<p+1/30)continue;let k={...$,start:ut(r),duration:S};delete k.enter;const y=Dd($,a-$.start);k=E(k,r,x(y,[m,g],[h,f],1/v),{...y},[[.5,0],[.78,1]]),u.set(k.id,{...k,seam:{...k.seam,in:!0,excl:!0}})}return u}const v6=`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 $6(t,e,o,r,{W:a=1280,H:n=720,accent:i="#c6f432",ease:c=Vn.ease,id:u}={}){const p=E=>Wy(E).map(([$,S])=>`${wa($/a)},${wa(S/n)}`).join(","),s=Yt[c]??Yt[Vn.ease],h=ut(r-o),f=E=>({fill:E.fill??E.border??i,line:E.border??E.fill??i}),m=f(t.a),g=f(t.b),v={qa:p(t.a),qb:p(t.b),ra:wa(t.a.r/Math.min(a,n)),rb:wa(t.b.r/Math.min(a,n)),fa:m.fill,fb:g.fill,ba:m.line,bb:g.line,glow:i,e0:s[0],e1:s[1],e2:s[2],e3:s[3],peak:1,veil:.5},x=Qe({code:v6,params:v,preset:"match-morph"});return{id:u??`seam-match-${e}`,nodeId:"",kind:"image",url:"",label:`Nối ${e} · ${t.a.role} → ${t.b.role}`,volume:0,start:ut(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 Yc={overlap:Nd.overlap[1],collide:1/30,world:.75,worldMin:6},o0="#c6f432",r0=["whoosh-short-up","swoosh"],n0=["top","center","lower"],il=t=>Math.round(t*1e3)/1e3,Je=t=>t.start+t.duration,E6=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 Fi(t){if(t?.kind==="audio")return null;if(t?.title)return{band:n0.includes(t.title.placement)?t.title.placement:"lower",set:a=>({...t,title:{...t.title,placement:a},url:"",gcsUri:void 0})};const e=t?.motion?.preset;if(e==="kin-beat"||e==="kin-orb"||!e||!Ju(e,"text")||s6.has(e))return null;const o=Ju(e,"placement"),r=o?t.motion.params?.[o]:null;return!o||!n0.includes(r)?null:{band:r,set:a=>({...t,motion:{...t.motion,params:{...t.motion.params,[o]:a}}})}}const S6=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 gu(t){if(S6.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=Fi(t);return e?e.band:t?.kind!=="audio"&&(t?.title||t?.motion?.preset&&Ju(t.motion.preset,"text"))?"full":null}const Tp=(t,e)=>Math.min(Je(t),Je(e))-Math.max(t.start,e.start);function a0(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 a=Math.min(o.duration,t.duration/(t.enter?2:1)),n=Math.min(r.duration,e.duration/(e.exit?2:1));return Math.abs(Je(t)-a-e.start)<1/60&&Math.abs(a-n)<1/60&&Math.abs(Tp(t,e)-a)<1/60}const i0=t=>t&&t.fade!==!1&&t.duration||0,I6=.15,s0=(t,e)=>{const o=Math.max(e.start>=t.start-1e-6?i0(e.enter):0,Je(t)<=Je(e)+1e-6?i0(t.exit):0);return o>0&&Tp(t,e)<=o+I6},l0=(t,e)=>!!(t.seam?.out&&e.seam?.in&&t.seam.excl&&e.seam.excl&&e.seam.scene===t.seam.scene+1),c0=t=>Math.max(...String(t.title.text).split(`
117
+ `).map(e=>e.length))*t.title.fontSize*.62+t.title.fontSize,A6=(t,e)=>!!(t.title&&e.title)&&[t.title.align,e.title.align].sort().join()==="left,right"&&c0(t)+c0(e)<=1040;function C6(t,e={}){const o=t.filter(a=>!e[a.track]?.hidden&&gu(a)).sort((a,n)=>a.start-n.start||a.track-n.track),r=[];return o.forEach((a,n)=>{for(const i of o.slice(0,n)){const c=gu(i),u=gu(a),p=i.seam?.scene!==void 0&&a.seam?.scene!==void 0&&i.seam.scene!==a.seam.scene;(c===u||(c==="full"||u==="full")&&p)&&(Tp(i,a)<=Yc.collide||a0(i,a)||a0(a,i)||l0(i,a)||l0(a,i)||c===u&&A6(i,a)||(c==="full"||u==="full")&&(s0(i,a)||s0(a,i))||r.push({a:i,b:a,at:il(Math.max(i.start,a.start))}))}}),r}const j6={center:["lower","top"],lower:["top","center"],top:["lower","center"]},T6=.8;function Bd(t,{tracks:e={},movable:o=null}={}){let r=t.slice();const a=[],n=new Set,i=new Set,c=u=>!o||o.has(u.id);for(let u=0;u<80;u++){const p=C6(r,e),s=p.find(v=>Fi(v.b)&&!n.has(v.b.id)&&c(v.b));if(s){const v=r.filter(E=>E.id!==s.b.id&&Fi(E)&&Tp(E,s.b)>Yc.collide).map(E=>Fi(E).band),x=j6[Fi(s.b).band].find(E=>!v.includes(E));if(!x){n.add(s.b.id);continue}r=r.map(E=>E.id===s.b.id?Fi(E).set(x):E),a.push(`"${s.b.label}" moved to ${x} (was over "${s.a.label}")`);continue}const h=p.find(v=>!i.has(v.a.id+"|"+v.b.id)&&(c(v.a)||c(v.b)));if(!h)break;const{a:f,b:m}=h,g=il(m.start-f.start);c(f)&&g>=T6?(r=r.map(v=>v.id===f.id?{...v,duration:g}:v),a.push(`"${f.label}" now ends when "${m.label}" starts (their text cannot share the frame)`)):c(m)?(r=r.map(v=>v.id===m.id?{...v,start:il(Je(f))}:v),a.push(`"${m.label}" now starts after "${f.label}" (their text cannot share the frame)`)):(i.add(f.id+"|"+m.id),a.push(`"${m.label}" still overlaps "${f.label}"`))}return{clips:r,notes:a}}function O6(t){const e=Math.min(...t.map(s=>s.start)),o=Math.max(...t.map(Je)),r=o-e,a=t.filter(s=>r>=Yc.worldMin&&s.duration>=Yc.world*r),n=t.filter(s=>!a.includes(s)),i=new Map;for(const s of n)Number.isInteger(s.seam?.scene)&&(i.has(s.seam.scene)||i.set(s.seam.scene,[]),i.get(s.seam.scene).push(s));const c=[...i.values()].map(s=>({s:Math.min(...s.map(h=>h.start)),e:Math.max(...s.map(Je)),list:s})),u=[];for(const s of n.filter(h=>!Number.isInteger(h.seam?.scene)).sort((h,f)=>h.start-f.start)){const h=c.map(m=>({k:m,o:Math.min(Je(s),m.e)-Math.max(s.start,m.s)})).filter(m=>m.o>.5*s.duration).sort((m,g)=>g.o-m.o)[0];if(h){h.k.list.push(s);continue}const f=u.at(-1);f&&s.start<f.e-1e-6?(f.list.push(s),f.e=Math.max(f.e,Je(s))):u.push({s:s.start,e:Je(s),list:[s]})}const p=[...c,...u].map(s=>s.list).sort((s,h)=>Math.min(...s.map(f=>f.start))-Math.min(...h.map(f=>f.start)));return{world:a,scenes:p}}function Eh(t,e={},o=null,{overlap:r,accent:a,newId:n,seed:i="clipoox",W:c=1280,H:u=720}={}){if(t.some(_=>E6(_)))throw Error("makeSeamless is for motion / text timelines (no footage or 3D models)");a=a??t.find(_=>_.seam?.hero&&_.shape)?.shape?.paths?.[0]?.stroke??t.find(_=>_.seam?.match)?.motion?.params?.glow??t.find(_=>Number.isInteger(_.seam?.deco))?.motion?.params?.accent??o0;const p=t.filter(_=>Number.isInteger(_.seam?.joinFx)),s=t.filter(_=>!_.seam?.hero&&!_.seam?.join&&!Number.isInteger(_.seam?.joinFx)).map(_=>_.seam?.raw?Bw(_):_),h=s.filter(_=>_.kind!=="audio");if(!h.length)throw Error("Nothing to link: add motion / text layers first");if(h.some(_=>e[_.track]?.locked))throw Error("Track đã khóa");const{world:f,scenes:m}=O6(h),g=new Set(f.map(_=>_.id)),v=[],x={};m.forEach((_,J)=>{const tt=_.find(rt=>rt.seam&&(rt.seam.style||rt.seam.dur||rt.seam.ease||rt.seam.shuffle||rt.seam.not))?.seam;tt&&(x[J]={style:tt.style,dur:tt.dur,ease:tt.ease,shuffle:tt.shuffle,not:tt.not})});const E={};for(let _=1;_<m.length;_++){const J=x[_]??{};if(J.style&&J.style!=="match-morph")continue;const tt=m[_-1].filter(pt=>!g.has(pt.id)),rt=m[_].filter(pt=>!g.has(pt.id)),D=Number.isFinite(J.dur)?J.dur:Cc("match-morph").dur,q=tt.length&&rt.length?e0(tt,rt,Math.max(...tt.map(Je))-D,Math.min(...rt.map(pt=>pt.start))+D,{accent:a,W:c,H:u}):null;q?E[_]=q:J.style==="match-morph"&&(v.push(`join ${_}: no element pair to morph — kept a plain style`),x[_]={...J,style:void 0})}const $=_w(m.map(Vw),{seed:i,overrides:x}).map((_,J)=>Cc(E[J+1]?"match-morph":_)),S=_=>{const J=$[_-1],tt=x[_]??{},rt=Number.isFinite(tt.dur)?tt.dur:Number.isFinite(r)?r:J.dur;return Math.max(.2,Math.min(1.2,rt))},k=s.filter(_=>_.kind==="audio"&&_.sfx),y=new Map(k.map(_=>[_.id,m.findIndex(J=>J.some(tt=>_.start>=tt.start-1e-6&&_.start<Je(tt)))])),C=new Map;let A=null;m.forEach((_,J)=>{const tt=Math.min(..._.map(q=>q.start)),rt=Math.max(..._.map(Je)),D=J===0?0:Math.max(-tt,ut(A-S(J)-tt));C.set(J,D),A=rt+D});const z=new Map(m.flatMap((_,J)=>_.map(tt=>[tt.id,J])));let j=s.map(_=>{if(_.kind==="audio"){const D=y.get(_.id);return D>=0&&C.get(D)?{..._,start:ut(Math.max(0,_.start+C.get(D)))}:_}const J=z.get(_.id);if(J===void 0)return _;const tt=x[J]??{},rt={..._,start:ut(_.start+C.get(J))};return{...rt,seam:{scene:J,...Object.fromEntries(Object.entries(tt).filter(([,D])=>D!==void 0)),raw:Gw(rt)}}});const P=_=>j.filter(J=>J.seam?.scene===_&&J.kind!=="audio"&&!g.has(J.id)),F=_=>{const J=P(_);return[Math.min(...J.map(tt=>tt.start)),Math.max(...J.map(Je))]},N=[];for(let _=1;_<m.length;_++){const J=$[_-1],tt=F(_-1)[1],rt=ut(tt-S(_)),D=J.kind==="match"?e0(P(_-1),P(_),rt,tt,{accent:a,W:c,H:u})??E[_]:null;N.push({k:_,b0:rt,b1:tt,style:J,pair:D});const q=D?M6(D,P(_-1),P(_),rt,tt,{W:c,H:u,ease:x[_]?.ease??J.ease}):Kw(J,{out:P(_-1),inn:P(_),b0:rt,b1:tt,ease:x[_]?.ease});if(j=j.map(pt=>q.get(pt.id)??pt),J.kind==="sequence"){const pt=ut(rt+(tt-rt)/2);j=j.map(yt=>yt.kind==="audio"&&yt.sfx&&y.get(yt.id)===_&&yt.start<pt-1e-6?{...yt,start:ut(pt+(yt.start-rt))}:yt)}}const G=Math.min(...j.filter(_=>_.kind!=="audio").map(_=>_.start)),V=Math.max(...j.filter(_=>_.kind!=="audio"&&!g.has(_.id)).map(Je),G+.5);j=j.map(_=>g.has(_.id)&&Je(_)>V+1e-6?{..._,duration:ut(Math.max(1/30,V-_.start))}:_);const et=[...j.filter(_=>g.has(_.id)).sort((_,J)=>_.track-J.track),...m.flatMap((_,J)=>P(J).sort((tt,rt)=>tt.track-rt.track||tt.start-rt.start))],U=j.filter(_=>_.kind==="audio");for(const _ of et){const{track:J}=Kt(U,e,_.start,Je(_),_.track);U.push({..._,track:J})}j=U,j=j.map(_=>{if(!_.transition)return _;const J=Ww(j,_);if(J&&mh(J))return _;const{transition:tt,...rt}=_;return v.push(`transition on "${_.label}" removed (layers re-timed)`),rt});let at=o;if(m.length>=2){j=j.map(D=>D.seam?.scene!==void 0&&D.kind!=="audio"&&D.zIndex===void 0?{...D,zIndex:Math.min(99,D.seam.scene)}:D);const _=[];for(const D of N){const q=D.pair?$6(D.pair,D.k,D.b0,D.b1,{W:c,H:u,accent:a,ease:x[D.k]?.ease??D.style.ease,...n?{id:n()}:{}}):{...Cr({id:n?n():`seam-flight-${D.k}`,track:0,start:ut(D.b0),duration:ut(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)};q.track=Kt([...j,..._],e,q.start,Je(q)).track,_.push(q)}j.push(..._);for(const D of p){const q=N.find(Mt=>Mt.k===D.seam.joinFx);if(!q){v.push(`Claude Motion layer of join ${D.seam.joinFx} removed (that join is gone)`);continue}const pt=ut(Math.max(0,(q.b0+q.b1)/2-D.duration/2)),yt={...D,start:pt,zIndex:Math.min(99,q.k),is3D:!0};yt.track=Kt(j,e,yt.start,Je(yt)).track,j.push(yt)}for(const D of N){const q=D.style.pack==="urban",pt=D.style.pack==="techlaunch",yt=pt?Hw(D.style.deco):q?Xw(D.style.deco):Uw(D.style.deco);if(!yt)continue;const Mt=(D.b0+D.b1)/2,l=ut(Math.min(2*Mt,to.maxDuration,Math.max(yt.min,(D.b1-D.b0)*yt.k+yt.add))),lt=Yt[x[D.k]?.ease??D.style.ease],K=lt==="hold"?[-1,0,0,0]:Array.isArray(lt)?lt:[0,0,1,1],d=Qe({code:yt.code,params:pt?{...Yw,...a&&a!==o0?{accent:a}:{},e0:K[0],e1:K[1],e2:K[2],e3:K[3]}:q?{accent:a,...qw,e0:K[0],e1:K[1],e2:K[2],e3:K[3]}:{accent:a,...Zw,e0:K[0],e1:K[1],e2:K[2],e3:K[3],w:D.b1-D.b0,flash:"#ffffff"},preset:D.style.id}),w={id:n?n():`seam-deco-${D.k}`,nodeId:"",kind:"image",url:"",label:`${pt?"Tech Launch":q?"Urban":"Editorial"} · nối ${D.k}`,volume:0,start:ut(Mt-l/2),duration:l,track:0,motion:{...d,duration:l},motionKeys:[],seam:{join:!0,deco:D.k},zIndex:Math.min(99,D.k),is3D:!!yt.cam};w.track=Kt(j,e,w.start,Je(w)).track,j.push(w)}j=j.map(D=>D.kind!=="audio"&&!D.nullLayer&&!g.has(D.id)&&D.is3D===void 0?{...D,is3D:!0}:D);const J={...o??{...jr,motionKeys:[]},enabled:!0},tt=Zn.cz.base(J),rt=Yt["sine-in-out"];at=In(J,"cz",[{time:ut(G),value:tt,ease:rt},{time:ut(V),value:il(Math.min(Zn.cz.max,tt+Nd.camera.push))}]),at=In(at,"roll",[{time:ut(G),value:0,ease:rt},{time:ut(V),value:Nd.camera.roll}]),_r(at),N.forEach((D,q)=>{const pt=Math.max(0,D.b0-.05);if(j.some(Mt=>Mt.kind==="audio"&&/whoosh|swoosh|glitch/.test(Mt.sfx||"")&&Math.abs(Mt.start-pt)<.35))return;const yt=vn(D.style.sfx)??vn(r0[q%r0.length]);yt&&j.push({...ha(j,e,yt,pt,{id:n?n():`seam-join-${q}`}),seam:{join:!0}})})}const W=Bd(j,{tracks:e});return j=W.clips,v.push(...W.notes),v.unshift(m.length>=2?`${m.length} scenes linked: ${N.map(_=>`${_.k}: ${_.style.id}${_.pair?` (${_.pair.a.role} → ${_.pair.b.role})`:""} ${il(_.b1-_.b0)}s`).join(", ")} — camera + whoosh`:"one scene so far — it will link to the next one"),{clips:j,camera:at,notes:v,scenes:m.length,joins:N.map(_=>({k:_.k,start:_.b0,end:_.b1,style:_.style.id,..._.pair?{match:{a:_.pair.a.role,b:_.pair.b.role,score:_.pair.score}}:{}}))}}function z6(t,e={},o=null,{join:r,style:a,duration:n=null,ease:i=null,newId:c,seed:u,W:p,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 g={style:m.style,dur:m.dur,ease:m.ease,shuffle:m.shuffle,not:m.not};if(a==="auto")g={},t=t.filter(S=>S.seam?.joinFx!==r);else if(a==="shuffle")g={...g,style:void 0,shuffle:(g.shuffle??0)+1,not:f??void 0};else if(a!=null){if(!Cc(a))throw Error(`Unknown join style "${a}"`);if(Cc(a).only==="footage")throw Error(`"${a}" is for cuts between filmed clips (joinCut), not a motion piece`);g={...g,style:a,not:void 0}}if(n!=null){if(!(n>=.2&&n<=1.2))throw Error("Join duration must be 0.2–1.2 s");g.dur=n}if(i!=null){if(!Object.hasOwn(Yt,i))throw Error(`Unknown easing "${i}"`);g.ease=i}const v=Object.fromEntries(Object.entries(g).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:y,ease:C,shuffle:A,not:z,...j}=S.seam;return{...S,seam:{...j,...v}}}),E=Eh(x,e,o,{newId:c,seed:u,W:p,H:s}),$=E.joins.find(S=>S.k===r)?.style;return v.style&&$!==v.style&&E.notes.push(`"${v.style}" does not fit these scenes — kept ${$}`),{...E,style:$}}const P6=t=>/\b(fillText|strokeText)\b/.test(String(t));function L6(t,e={},o=null,{join:r,code:a,params:n={},prompt:i="",duration:c,newId:u,seed:p,W:s,H:h}={}){if(!t.some(x=>x.seam?.flight===r))throw Error("No such join — link the scenes first (makeSeamless)");if(P6(a))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(to.maxDuration,Number(c)||1.2)),m=Qe({code:a,params:n,preset:"claude",prompt:String(i).slice(0,2e3)}),g={id:u?u():`seam-fx-${r}`,nodeId:"",kind:"image",url:"",label:`Claude Motion · nối ${r}`,volume:0,start:0,duration:ut(f),track:0,motion:{...m,duration:ut(f)},motionKeys:[],seam:{joinFx:r}},v=Eh([...t.filter(x=>x.seam?.joinFx!==r),g],e,o,{newId:u,seed:p,W:s,H:h});return{...v,layer:v.clips.find(x=>x.seam?.joinFx===r)?.id}}const Qo={minDuration:.4,maxDuration:3,defaultDuration:1.2,minAmount:1.05,maxAmount:1.3,defaultAmount:1.12,ramp:.35,defaultStyle:"smooth",styles:["cut","smooth","push"]},Qr=1/30,wi=.4,F6=.7,Hi=(t,e,o)=>Math.max(e,Math.min(o,t)),p0=t=>+t.toFixed(4);function qc(t,e){const o=Array.isArray(e?.scenes)?e.scenes:[],r=(t.inPoint||0)+t.duration*(t.playbackRate||1)/2,a=o.find(n=>n.start<=r&&n.end>r&&Number.isFinite(n.subjectX))||o.find(n=>Number.isFinite(n.subjectX));return a?{x:Hi(a.subjectX,0,1),y:Number.isFinite(a.subjectY)?Hi(a.subjectY,0,1):.5}:null}function N6(t,e,o,r,a){const n=[];if(r==="cut"){if(t>=Qr&&n.push({time:ut(t-Qr),f:0,ease:"hold"}),n.push({time:t,f:1}),a)for(let c=t+wi;c<e-Qr-.05;c+=wi)n.push({time:ut(c),f:1});e>=o-1e-6?n.push({time:o,f:1}):n.push({time:ut(e-Qr),f:1,ease:"hold"},{time:e,f:0})}else if(r==="push"){if(n.push({time:t,f:0,ease:"ease-in-out"}),a)for(let c=t+wi;c<e-Qr-.05;c+=wi)n.push({time:ut(c),f:(c-t)/(e-Qr-t)});e>=o-1e-6?n.push({time:o,f:1}):n.push({time:ut(e-Qr),f:1,ease:"hold"},{time:e,f:0})}else{const c=Math.min(Qo.ramp,(e-t)/3);if(n.push({time:t,f:0,ease:"easy-ease"},{time:ut(t+c),f:1}),a)for(let u=t+c+wi;u<e-c-.05;u+=wi)n.push({time:ut(u),f:1});e>=o-1e-6?n.push({time:o,f:1}):n.push({time:ut(e-c),f:1,ease:"easy-ease"},{time:e,f:0})}const i=[];for(const c of n)(!i.length||c.time>i.at(-1).time+1e-6)&&i.push(c);return i}function u0(t,{at:e,duration:o=Qo.defaultDuration,amount:r=Qo.defaultAmount,style:a=Qo.defaultStyle,anchor:n=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(!Qo.styles.includes(a))throw Error(`Punch-in style must be ${Qo.styles.join("/")}`);if(!Number.isFinite(e)||e<0||e>=t.duration-Qr)throw Error("Punch-in must start inside the clip");const i=Hi(Number.isFinite(o)?o:Qo.defaultDuration,Qo.minDuration,Qo.maxDuration),c=Hi(Number.isFinite(r)?r:Qo.defaultAmount,Qo.minAmount,Qo.maxAmount),u=ut(e);let p=ut(Math.min(t.duration,u+i));if(t.duration-p<Qr&&(p=t.duration),p-u<Qr*3)throw Error("Punch-in is too short for the clip");const s=Ee(t,"zoom").length>=2||!!n&&(Ee(t,"x").length>=2||Ee(t,"y").length>=2),h=N6(u,p,t.duration,a,s),f=h[0].time,m=h.at(-1).time,g=n?n.x-.5:0,v=n?n.y-.5:0,x=($,S)=>{const k=Qt(t,$,S.time),y=Qt(t,"zoom",S.time),C=Math.min(bs,y*(1+(c-1)*S.f));if($==="zoom")return p0(C);const A=Math.max(0,(C-1)/2),z=-(C-y)*($==="x"?g:v)*F6;return p0(Hi(k+Hi(z,-A,A),-1,1))};let E={...t};for(const $ of n?["zoom","x","y"]:["zoom"]){const S=Ee(t,$).filter(A=>A.time<f-.001||A.time>m+.001),k=h.map(A=>({time:A.time,value:x($,A),...A.ease?{ease:Yt[A.ease]}:{}})),y=[...S,...k].sort((A,z)=>A.time-z.time),C=ge(E,$,y);E={...E,...C}}return jn(E),{motionV:E.motionV,motionKeys:E.motionKeys,...E.posX!==void 0?{posX:E.posX,posY:E.posY,scale:E.scale}:{}}}const R6=/[!?]$/;function Hy(t,{every:e=[2.5,5],max:o=12,lead:r=.08,from:a=0}={}){const[n,i]=e;if(!Array.isArray(t)||!t.length||!(n>0)||!(i>=n))return[];const c=t.map((p,s)=>{const h=String(p.word??""),f=t[s-1];let m=0;return p.kw===!0?m+=6:p.kw!==!1&&(m+=Math.max(0,p1(h)-1)),(!f||/[.!?…]$/.test(f.word)||p.start-f.end>.6)&&(m+=2),p.end-p.start>=.45&&(m+=1),R6.test(h)&&(m+=1),{at:Math.max(a,+(p.start-r).toFixed(3)),word:h,score:m,start:p.start}}).filter(p=>p.at>=a),u=[];for(;!(u.length>=o);){const p=u.length?u.at(-1).at+n:a,s=u.length?u.at(-1).at+i:a+i,h=c.filter(m=>m.at>=p-1e-9&&m.at<=s+1e-9);if(!h.length){const m=c.find(g=>g.at>s);if(!m)break;u.push({at:m.at,word:m.word,score:m.score});continue}const f=h.reduce((m,g)=>g.score>m.score?g:m);u.push({at:f.at,word:f.word,score:f.score})}return u}function Xy(t,e){try{if(Array.isArray(t.captionWords)&&t.captionWords.length)return t.captionWords;if(Array.isArray(e?.words)&&e.words.length)return dh(t,e.words);const o=t.captions?.length?t.captions:Array.isArray(e?.transcript)?Ec(t,e.transcript):[];return o.length?$p(o):[]}catch{return[]}}function IT(t,e,o={}){const r=Ee(t,"zoom");return Hy(Xy(t,e),{from:.5,...o}).filter(a=>!r.some(n=>Math.abs(n.time-a.at)<=2.5*Qr)).map(a=>({...a,at:+(t.start+a.at).toFixed(3)}))}const de=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}),we=t=>+(+t).toFixed(3),Xo=t=>String(t??"").trim().slice(0,40),rr=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}]+/gu,"").trim(),Zc=t=>/[.!?…:;]$/u.test(String(t??"").trim()),D6={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},yu={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6,đầu:1},bu=new Set(["cuối","cuối cùng","final","last"]),_d=t=>{const e=rr(t);return/^\d{1,2}$/.test(e)?+e:D6[e]??null},B6=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"]),_6=new Set(["rồi","và","sau","then","and","xong","nhé","nha"]),d0=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 Sh(t,e,o){const r=t.find(i=>i.id===e);if(!r)return[];const a=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),n=o.find(i=>i.id===r.nodeId);return a.flatMap(i=>Xy(i,n).map(c=>({start:we(i.start+c.start),end:we(i.start+c.end),word:String(c.word)}))).sort((i,c)=>i.start-c.start)}function Uy(t){const e=[];return t.forEach((o,r)=>{const a=rr(o.word),n=t[r+1],i=t[r-1];let c=null,u=r+2,p=o.start,s=a==="step"?"Step":"Bước";if((a==="bước"||a==="step")&&n&&(c=_d(n.word),c===null)){const f=rr(n.word),m=f+" "+rr(t[r+2]?.word);yu[f]===1&&a==="bước"?c=1:bu.has(m)?(c=-1,u=r+3):bu.has(f)&&(c=-1)}if(c===null&&a==="step"&&i){const f=rr(i.word);yu[f]?(c=yu[f],p=i.start,u=r+1):bu.has(f)&&(c=-1,p=i.start,u=r+1)}if(c===null||(c===-1&&(c=(e.at(-1)?.number??0)+1),e.some(f=>f.number===c)))return;const h=[];for(let f=u;f<t.length&&h.length<3;f++){const m=rr(t[f].word);if(!h.length&&B6.has(m)){if(Zc(t[f].word))break;continue}if(!(_d(t[f].word)!==null&&!h.length)&&(["bước","step"].includes(m)||(h.push(String(t[f].word).replace(/[.,!?…:;"“”]+$/u,"")),Zc(t[f].word)||t[f+1]&&t[f+1].start-t[f].end>.5)))break}e.push({i:r,at:p,number:c,label:s,auto:h.join(" ")})}),e}function V6(t,e=new Set){const o=[];for(let r=0;r<t.length;r++){if(e.has(r)||!d0.has(rr(t[r].word)))continue;const a=[];let n=r;for(;n<t.length&&a.length<6;n++){a.push(String(t[n].word).replace(/[,!?…:;"“”]+$/u,"").replace(/\.$/u,""));const i=rr(t[n+1]?.word);if(Zc(t[n].word)||/,$/u.test(t[n].word)||t[n+1]&&t[n+1].start-t[n].end>.45||d0.has(i)||_6.has(i))break}["đợi","chờ","wait"].includes(rr(t[r].word))&&!a.slice(1).some(i=>_d(i)!==null||/phút|giây|minute|second|chút|lát/u.test(rr(i)))||a.length<2||(o.push({i:r,at:t[r].start,text:a.join(" ")}),r=n)}return o}function G6(t,e,o=0){const r=String(e||"").split(/\s+/u).map(rr).filter(n=>n.length>1);if(!r.length)return null;const a=Math.min(2,r.length);for(let n=0;n<t.length;n++){if(t[n].start<o)continue;let i=0;for(;i<r.length&&n+i<t.length&&rr(t[n+i].word)===r[i];)i++;if(i>=a)return t[n].start}return null}function h0(t,e,o,r){const a=[...t].sort((i,c)=>i[0]-c[0]);let n=e;for(const[i,c]of a){if(n+o<=i+1e-6)break;c>n&&(n=c+.05)}return n+o<=r+1e-6?we(n):null}const Os=(t,e,o,r)=>{let a=null;for(const n of t){if(n.start<o||n.start>r)continue;const i=t[t.indexOf(n)-1],c=Math.abs(n.start-e)-(i&&(Zc(i.word)||n.start-i.end>.25)?.6:0);(!a||c<a.score)&&(a={at:n.start,score:c})}return a?a.at:e},K6=t=>{try{const e=typeof t=="string"?JSON.parse(t||"{}"):t;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}},W6=/sản phẩm|san pham|product|packshot|chai|lọ|tuýp|hộp|bottle|serum|kem|dầu|son/iu;function H6({clips:t=[],materials:e=[],clipId:o,copy:r={},brand:a=null,en:n=!1,portrait:i=!0}={}){const c=(()=>{const K=t.find(d=>d.id===o);return K?t.filter(d=>d.id===o||K.nodeId&&d.nodeId===K.nodeId&&d.track===K.track&&d.kind===K.kind&&!d.mask).sort((d,w)=>d.start-w.start):[]})();if(!c.length)throw Error("productReview: the speaker clip was not found");const u=Sh(t,o,e),p=c[0].start,s=c.at(-1).start+c.at(-1).duration,h=s-p;if(h<6)throw Error("productReview: the clip is too short for a review (≥ 6 s)");const f=K=>{const d=e.find(w=>w.id===K);return d&&d.kind==="image"&&d.url?d.id:null},m=Xo(r.brand??a?.name??""),g=Xo(r.tagline??a?.tagline??""),v=f(r.logoImage)||f(a?.logoMaterialId),x=Xo(r.product??""),E=Xo(r.stepLabel??""),$=e.filter(K=>K.kind==="image"&&K.url&&K.id!==v&&K.role!=="reference"&&W6.test(`${K.label||""} ${(K.labels||[]).join(" ")} ${K.description||""}`)).map(K=>K.id),S=f(r.productImage)||$[0]||null,k=[],y=[],C=[],A=K=>(k.push(K),K),z=Uy(u),j=new Set(z.flatMap(K=>[K.i,K.i+1,K.i+2,K.i+3,K.i+4])),P=Array.isArray(r.steps)?r.steps:[];for(const K of z){const d=P[K.number-1],w=Xo(typeof d=="string"?d:d?.name??K.auto);C.push({kind:"step",at:we(Math.max(p,K.at-de.caption.lead)),number:K.number,label:E||(K.label==="Step"||n?"Step":"Bước"),text:w,image:f(typeof d=="object"?d?.image:null)||($.length>=Math.max(2,z.length)?$[K.number-1]??null:null)})}const F=Array.isArray(r.instructions)?r.instructions.map(Xo).filter(Boolean):null;if(F){let K=0;for(const d of F){const w=d.split(/\s+/u).slice(0,2).map(rr),T=u.findIndex((I,O)=>I.start>=K&&rr(I.word)===w[0]&&(!w[1]||rr(u[O+1]?.word)===w[1]));T<0||(K=u[T].end,C.push({kind:"do",at:we(Math.max(p,u[T].start-de.caption.lead)),text:d}))}}else for(const K of V6(u,j))C.push({kind:"do",at:we(Math.max(p,K.at-de.caption.lead)),text:Xo(K.text)});C.sort((K,d)=>K.at-d.at||(K.kind==="step"?-1:1));const N=we(Math.max(p+de.logo+2,s-de.cta)),G=we(p+de.logo),V=[];for(const K of C){if(K.at<G-.3||K.at>N-de.caption.min)continue;const d=V.at(-1);if(d&&K.at-d.at<de.caption.min)if(K.kind==="step"&&d.kind!=="step")V.pop();else continue;V.push(K)}V.forEach((K,d)=>{const w=V[d+1]?.at??N;K.dur=we(Math.max(de.caption.min,Math.min(de.caption.max,w-de.caption.gap-K.at)))});const et=Number.isFinite(+r.rating)&&r.rating!==null&&r.rating!==""?Math.max(0,Math.min(5,+r.rating)):null;let U=null;if(et!==null||r.verdict){const K=[...V].reverse().find(T=>T.at+T.dur>N-de.rating),d=we(Math.max(N-de.rating-.05,K?K.at+de.caption.min+de.caption.gap:0,G)),w=we(N-.05-d);if(w>=2.4){U={at:d,dur:w};for(const T of V)T.at+T.dur>d-de.caption.gap&&(T.dur=we(d-de.caption.gap-T.at))}}for(const K of V)y.push([K.at,K.at+K.dur]);U&&y.push([U.at,U.at+U.dur]);const at=G6(u,x,p),W=at!==null&&at>=G?at:Os(u,p+h*.28,G,p+h*.5);let _=x||m?h0(y,Math.max(G+.2,W-.1),de.packshot,N-.5):null,J=de.logo,tt=de.packshot;if(_===null&&(x||m)){const K=V[0]?.at??N,d=we(Math.max(p+1.4,Math.min(at??p+1.4,G)-.1)),w=K-d-.05>=2?d:we(p+1.4),T=we(Math.min(de.packshot,K-w-.05));T>=2&&(_=w,tt=T,J=we(w-p))}_!==null&&y.push([_,_+tt]);{const K=_!==null?[[_,_+tt]]:[];for(const d of V)if(d.image){if(K.some(([w,T])=>d.at<T+2&&d.at+d.dur>w-2)){d.image=null;continue}K.push([d.at,d.at+d.dur])}}const rt=[..._!==null?[[_,_+tt]]:[],...V.filter(K=>K.image).map(K=>[K.at,K.at+K.dur])],D=(K,d)=>rt.some(([w,T])=>K<T-.05&&d>w+.05),q=K=>c.find(d=>K>=d.start-1e-6&&K<d.start+d.duration-1e-6);let pt=Os(u,p+2.4,p+de.wide[0],p+de.wide[1]),yt=0,Mt=p;for(;pt<N-de.close[0];){const K=Math.min(N-.1,Os(u,pt+2.5,pt+de.close[0],pt+de.close[1])),d=q(pt);let w=d?Math.min(K,d.start+d.duration):K;const T=rt.find(([I,O])=>pt<O-.05&&w>I+.05);if(T&&T[0]-pt>=1.2)w=T[0];else if(T){pt=Os(u,T[1]+.15,T[1]+.05,T[1]+.6),Mt=T[1];continue}if(d&&w-pt>=de.pieceMin&&!D(pt,w)&&A({op:"punchIn",clipId:o,at:we(pt),duration:we(Math.min(3,w-pt)),numberValue:de.closeAmount,punchStyle:"cut",accent:!1}),yt++,yt%de.pushEvery===0){const I=q(Mt+.05),O=we(Mt+.05),L=Math.min(pt-.05,I?I.start+I.duration:pt,O+3);I&&L-O>=1&&!D(O,L)&&A({op:"punchIn",clipId:o,at:O,duration:we(L-O),numberValue:de.pushAmount,punchStyle:"push",accent:!1})}Mt=K,pt=Os(u,K+2.4,K+de.wide[0],K+de.wide[1])}if(v)A({op:"addElement",materialId:v,start:G,duration:we(s-G),posX:0,posY:i?.3:.385,scale:i?.16:.1,anim:{in:"fade",out:"fade"}});else if(m){const K=s-G,d=Math.ceil(K/to.maxDuration-1e-9);for(let w=0;w<d;w++){const T=G+K*w/d,I=G+K*(w+1)/d;A({op:"addMotion",motionPreset:"rv-brand-watermark",start:we(T),duration:we(I-T),placement:"lower",text:m,...w>0?{numberValue:w<d-1?3:1}:d>1?{numberValue:2}:{}})}}(m||v)&&(A({op:"addMotion",motionPreset:"rv-logo-open",start:we(p),duration:J,placement:"center",text:m||x||" ",...g?{subText:g}:{},...v?{numberValue:1}:{}}),v&&A({op:"addElement",materialId:v,start:we(p+.15),duration:we(J-.3),posX:0,posY:i?-.02:-.06,scale:i?.3:.2,anim:{in:"pop",out:"fade"}})),_!==null&&(A({op:"addMotion",motionPreset:"rv-packshot-title",start:_,duration:tt,placement:"center",text:x||m,subText:r.tag===""?" ":Xo(r.tag??(n?"New":"Mới")),items:[m||" ",...g?[g]:[]]}),S&&A({op:"addElement",materialId:S,start:we(_+.2),duration:we(tt-.2),posX:i?0:.2,posY:i?.1:.08,scale:i?.62:.5,anim:{in:"pop",out:"none"}}));for(const K of V){if(K.image){const w=K.dur;A({op:"addMotion",motionPreset:"rv-packshot-title",start:K.at,duration:w,placement:"center",text:x||" ",numberValue:1}),A({op:"addElement",materialId:K.image,start:we(K.at+.05),duration:we(w-.05),posX:i?0:.2,posY:i?.1:.08,scale:i?.62:.5,anim:{in:"fade",out:"none"}})}const d=K.image?{params:{color:"#2b2230"}}:{};K.kind==="step"?A({op:"addMotion",motionPreset:"rv-step-caption",start:K.at,duration:K.dur,placement:K.image?"top":"center",text:K.text||" ",subText:K.label,numberValue:K.number,...d}):A({op:"addMotion",motionPreset:"rv-instruction",start:K.at,duration:K.dur,placement:"center",text:K.text,...d})}const l=(K,d)=>{const w=h0(y,Number.isFinite(+d)?Math.max(G,+d):G+.5,K,N-.2);return w!==null&&y.push([w,w+K]),w},lt=(Array.isArray(r.benefits)?r.benefits:[]).map(Xo).filter(Boolean).slice(0,4);if(lt.length){const K=l(de.benefits,r.benefitsAt);K!==null&&A({op:"addMotion",motionPreset:"rv-benefit-list",start:K,duration:de.benefits,placement:"center",text:Xo(r.benefitsTitle??(n?"Why it works":"Vì sao nên dùng")),items:lt})}if(r.callout&&typeof r.callout=="object"&&r.callout.text){const K=l(de.callout,r.callout.at);K!==null&&A({op:"addMotion",motionPreset:"rv-product-callout",start:K,duration:de.callout,placement:"center",text:Xo(r.callout.text),...r.callout.sub?{subText:Xo(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&&A({op:"addMotion",motionPreset:"rv-rating",start:U.at,duration:U.dur,placement:"center",text:Xo(r.verdict??(n?"Worth it":"Đáng mua")),numberValue:et??0,...r.ratingNote?{subText:Xo(r.ratingNote)}:{}}),A({op:"addMotion",motionPreset:"rv-cta-end",start:N,duration:we(s-N),placement:"lower",text:x||m||(n?"Shop now":"Mua ngay"),subText:Xo(r.cta??(n?"Shop now · Link in bio":"Mua ngay · Link ở bio"))}),k}function X6(t,{clips:e=[],materials:o=[],brand:r=null,portrait:a=!0,en:n=!1,simulate:i=null}={}){if(!Array.isArray(t)||!t.some(h=>h?.op==="productReview"))return t;const c=[],u=[];let p=0;const s=h=>{const f=typeof h=="string"&&/^new:(\d+)$/.exec(h);if(!f)return h;const m=+f[1];let g=0;for(const v of u)m>v.after&&(g+=v.by);return`new:${m+g}`};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"){c.push(f),/^(add|lockup$)/.test(f?.op??"")&&p++;continue}const m=f.fromClipId??f.clipId,g=e.find(k=>k.id===m),v=g&&o.find(k=>k.id===g.nodeId),x=[];g&&f.booleanValue!==!0&&Array.isArray(v?.pauses)&&v.pauses.length&&!c.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||c.some(k=>["cutPauses","removeRetakes","split","trim","delete","move","compact","ripple"].includes(k?.op))))try{E=i([...c,...x])??e}catch{E=e}const $=[...x,...H6({clips:E,materials:o,clipId:m,copy:K6(f.prompt),brand:r,en:n,portrait:a})],S=$.filter(k=>/^add/.test(k.op)).length;c.push(...$),S&&u.push({after:p,by:S})}return c}const ka=Object.freeze({beat:{min:2.5,max:6,base:2.8,perWord:.2},maxBeats:8,gap:0,photoScale:.5,photoScaleTall:.62}),U6=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}}),wu="#2a241c",ku="#d62b25",f0="#f6efdd",Ue=t=>+(+t).toFixed(3),zs=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function Y6(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(n=>n.kind==="image"&&n.url).map(n=>[n.id,n])),a=(Array.isArray(o?.scenes)?o.scenes:[]).filter(n=>r.has(n?.materialId)).slice(0,ka.maxBeats).map(n=>({materialId:n.materialId,label:zs(n.label,40),year:zs(n.year,12),caption:zs(n.caption,140),keys:(Array.isArray(n.keys)?n.keys:[]).map(i=>zs(i,24)).filter(Boolean).slice(0,3),cutout:["person","object"].includes(n.cutout)?n.cutout:"none",old:n.old===!0}));if(!a.length)throw Error("voxCollage: no scene uses an image from Media");return{title:zs(o?.title,60),beats:a}}function m0(t){const e=`${t.caption} ${t.keys.join(" ")}`.split(/\s+/).filter(Boolean).length;return Ue(Math.max(ka.beat.min,Math.min(ka.beat.max,ka.beat.base+e*ka.beat.perWord)))}function q6({prompt:t,materials:e,start:o=0,portrait:r=!1}){const{beats:a}=Y6(t,e),n=[],i={n:0},c=h=>(n.push(h),["addElement","addText","addMotion"].includes(h.op)&&i.n++,`new:${i.n}`),u=a.reduce((h,f)=>h+m0(f),0),p=Ue(Math.max(0,o));for(let h=0;h<u-.001;h+=to.maxDuration){const f=c({op:"addMotion",motionPreset:"fxo-paper-bg",start:Ue(p+h),duration:Ue(Math.min(to.maxDuration,u-h)),label:"Motion · Nền giấy"});n.push({op:"collageStyle",clipId:f,back:!0})}let s=p;a.forEach((h,f)=>{const m=m0(h),g=f%2===0,v=g?-1:1,x=h.cutout!=="none",E=r?0:v*.24,$=r?-.14:.04,S=r?ka.photoScaleTall:ka.photoScale,k=c({op:"addElement",materialId:h.materialId,start:Ue(s),duration:m,posX:E,posY:$,scale:S,anim:x?{in:"pop",out:"fade",loop:"none"}:{in:"none",out:"fade",loop:"none"}});n.push({op:"collageStyle",clipId:k,sticker:x?"white-red":"paper",...x?{cutout:h.cutout}:{torn:"all",watercolor:!0,seed:f+1}}),h.old&&n.push({op:"setEffect",clipId:k,property:"mono",numberValue:.95}),x&&c({op:"addElement",elementId:"doodle-circle",start:Ue(s+.6),duration:Ue(m-.6),posX:E,posY:$,scale:Ue(S*.95),primary:"#e2382f"}),h.label&&c({op:"addText",text:h.label,styleId:"tape-label",accentColor:"#e6d9b8",color:wu,fontFamily:"Oswald",fontSize:40,placement:"top",align:g?"left":"right",start:Ue(s+.15),duration:Ue(m-.15),preset:"slide-left"}),h.year&&(c({op:"addText",text:h.year,styleId:"serif-year",accentColor:ku,color:ku,fontFamily:"Playfair Display",fontSize:96,placement:"top",align:g?"right":"left",start:Ue(s+.35),duration:Ue(m-.35),preset:"pop-in"}),c({op:"addElement",elementId:"doodle-underline",start:Ue(s+.7),duration:Ue(m-.7),posX:r?0:-v*.62,posY:-.46,scale:.22,primary:ku})),h.keys.length&&c({op:"addText",text:h.keys.join(`
118
+ `),styleId:"accent-bar",accentColor:f0,color:wu,fontFamily:"Oswald",fontSize:44,placement:"center",align:r?"center":g?"right":"left",start:Ue(s+.9),duration:Ue(m-.9),preset:"slide-left"}),h.caption&&c({op:"addText",text:h.caption,styleId:"accent-bar",accentColor:f0,color:wu,fontFamily:"Noto Serif",fontSize:30,placement:"lower",align:"center",start:Ue(s+.5),duration:Ue(m-.5),preset:"slide-up"}),s=Ue(s+m+ka.gap)});for(let h=0;h<u-.001;h+=to.maxDuration)c({op:"addMotion",motionPreset:"fxo-paper-grain",start:Ue(p+h),duration:Ue(Math.min(to.maxDuration,u-h)),label:"Motion · Vân giấy"});return n}const g0=["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement"];function Z6(t,{materials:e=[],portrait:o=!1}={}){if(!Array.isArray(t)||!t.some(c=>c?.op==="voxCollage"))return t;const r=[],a=[];let n=0;const i=c=>{const u=typeof c=="string"&&/^new:(\d+)$/.exec(c);if(!u)return c;const p=Number(u[1]);return`new:${p+a.filter(([s])=>s<p).reduce((s,[,h])=>s+h,0)}`};for(const c of t){if(c?.op!=="voxCollage"){r.push(c&&(c.clipId||Array.isArray(c.clipIds))?{...c,...c.clipId?{clipId:i(c.clipId)}:{},...Array.isArray(c.clipIds)?{clipIds:c.clipIds.map(i)}:{}}:c),g0.includes(c?.op)&&n++;continue}const u=q6({prompt:c.prompt,materials:e,start:Number.isFinite(c.start)?c.start:0,portrait:o}),p=n+a.reduce((h,[,f])=>h+f,0),s=h=>{const f=typeof h=="string"&&/^new:(\d+)$/.exec(h);return f?`new:${Number(f[1])+p}`:h};for(const h of u)r.push(h.clipId?{...h,clipId:s(h.clipId)}:h);a.push([n,u.filter(h=>g0.includes(h.op)).length])}return r}const Ie=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 Jc(t,e,o,{W:r,H:a}){if(!t||t.kind!=="video"||t.motion||t.title||t.shape)return null;const n=Array.isArray(e?.scenes)?e.scenes:[],i=(t.inPoint||0)+(o-t.start)*(t.playbackRate||1),c=n.find(E=>E.start<=i&&E.end>i&&Number.isFinite(E.subjectX))||n.find(E=>Number.isFinite(E.subjectX)),u=!!(t.captions?.length||t.captionWords?.length||e?.transcript?.length||e?.words?.length);if(!c&&!u)return null;const p=a>r*1.1,s=p?Ie.face.portrait:Ie.face.landscape;if(!c)return{...s,assumed:!0};const h=e?.width&&e?.height?e.width/e.height:r/a,f=r/a,m=t.scale??1,g=h>f?h/f:1,v=h<f?f/h:1,x=Number.isFinite(c.subjectY)?c.subjectY:.4;return{x:.5+(c.subjectX-.5)*g*m+(t.posX??0),y:.5+(x-.5)*v*m+(t.posY??0)}}function y0(t,e,o,r=!1){const a=e.y-Ie.head,n=o?Ie.halfWidth.portrait:Ie.halfWidth.landscape;return e.x+n<.08||e.x-n>.92?!1:t[1]>a&&(!r||t[0]<e.y+Ie.chin)}const fo=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})}),nr=(t,e,o)=>Math.max(e,Math.min(o,t)),Ae=t=>+t.toFixed(4);function Yy(t,e,o,r,a,n=fo.points){const i=o*r/a;return Array.from({length:n},(c,u)=>{const p=u/n*2*Math.PI;return[Ae(t+Math.cos(p)*o),Ae(e+Math.sin(p)*i)]})}function Vd(t,{W:e,H:o,mw:r,mh:a,corner:n="bottom-left",size:i=fo.size,anchor:c=null,cx:u,cy:p,ru:s,posX:h=null,posY:f=null}){const m=r<=a,g=Math.min(.5,.5*a/r),v=nr(Number.isFinite(s)?s:Math.min(m?.34:.34*a/r,g),fo.minFace*Math.min(1,a/r),g),x=v*r/a,E=nr(Number.isFinite(u)?u:c?.x??.5,v,1-v),$=nr(Number.isFinite(p)?p:c?.y??(m?.36:.45),x,1-x),S=t.fit==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a),k=r*S,y=a*S,C=nr(i,fo.minSize,fo.maxSize),A=C/2*Math.min(e,o),z=A/(v*k),j=n.endsWith("left"),P=n.startsWith("bottom"),F=fo.margin*Math.min(e,o),N=(et,U)=>nr(et*U,A,U-A)-U/2,G=Number.isFinite(h)?N(h,e):(j?-1:1)*(e/2-F-A),V=Number.isFinite(f)?N(f,o):(P?1:-1)*(o/2-F-A);return{mask:{v:1,mw:r,mh:a,keys:[{t:0,pts:Yy(E,$,v,r,a)}],smooth:!0,feather:.004},posX:Ae((G-z*(E-.5)*k)/e),posY:Ae((V-z*($-.5)*y)/o),scale:Ae(z),bubble:{cx:Ae(E),cy:Ae($),ru:Ae(v),size:Ae(C),corner:n}}}function J6(t,e,{at:o,duration:r,corner:a="bottom-left",size:n,W:i=1080,H:c=1920,material:u=null,newId:p,posX:s=null,posY:h=null,color:f=null}){const m=t.find(A=>A.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(!fo.corners.includes(a))throw Error(`Bubble corner must be ${fo.corners.join("/")}`);const g=ut(Math.max(m.start,o)),v=ut(Math.min(m.start+m.duration,g+nr(Number.isFinite(r)?r:5,fo.minDuration,fo.maxDuration)));if(v-g<fo.minDuration-1e-6)throw Error("Speaker bubble must start at least 1 s before the clip ends");const x=Math.round(u?.width)||(i<=c?1080:1920),E=Math.round(u?.height)||(i<=c?1920:1080);let $=t,S=m;const k=[p?.()??`${m.id}-b`,p?.()??`${m.id}-a`];if(g>m.start+1e-6){const[A,z]=_e(S,g,k[0]);z&&($=$.flatMap(j=>j.id===S.id?[A,z]:[j]),S=z)}if(v<S.start+S.duration-1e-6){const[A,z]=_e(S,v,k[1]);z&&($=$.flatMap(j=>j.id===S.id?[A,z]:[j]),S=A)}const y=Vd(S,{W:i,H:c,mw:x,mh:E,corner:a,size:n,anchor:qc(S,u),posX:s,posY:h}),C={...S,motionV:2,motionKeys:[],posX:y.posX,posY:y.posY,scale:y.scale,mask:y.mask,bubble:y.bubble,zIndex:fo.zIndex,edge:{...fo.rim,...f?{color:f}:{}},shadow:{...kn,opacity:.55,blur:18,distance:8},enter:{type:"pop",duration:.3},exit:{type:"zoom-out",duration:.2}};for(const A of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout"])delete C[A];return{clips:$.map(A=>A.id===S.id?C:A),bubbleId:S.id}}const Ir=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 Gd({W:t,H:e,width:o,cx:r,cy:a,aspect:n=Ir.aspect}={}){const i=e>t*1.1,c=i?Ir.portrait:Ir,u=Ir.margin*Math.min(t,e),p=t*nr(Number.isFinite(o)?o:c.width,Ir.minWidth,Ir.maxWidth),s=Math.min(e*.86,p/nr(n,.4,2)),h=nr(t*(Number.isFinite(r)?r:c.x)-p/2,u,t-u-p),f=nr(e*(Number.isFinite(a)?a:c.y)-s/2,u,e-u-s);return{x:h,y:f,w:p,h:s,params:{posX:Ae((h+p/2)/t),posY:Ae((f+s/2)/e),pw:Ae(p/t),ph:Ae(s/e),radius:Ir.radius}}}function Q6(t,{W:e,H:o,mw:r,mh:a,rect:n,anchor:i=null}){const c=n.w/n.h,u=r<=a;let p=a*(u?.42:.74),s=p*c;s>r&&(s=r,p=s/c),p>a&&(p=a,s=p*c);const h=i?.x??.5,f=i?.y??(u?.36:.4),m=nr(h,s/r/2,1-s/r/2),g=nr(f+p/a*.24,p/a/2,1-p/a/2),v=t.fit==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a),x=r*v,E=a*v,$=n.w/(s*v),S=nr(2*Ir.radius*n.w/Math.min(n.w,n.h),0,1),k=Dn({kind:"rect",cx:Ae(m),cy:Ae(g),w:Ae(s/r),h:Ae(p/a),rot:0,round:Ae(S)},r,a);return{mask:fr({mw:r,mh:a},[k]),posX:Ae((n.x+n.w/2-e/2-$*(m-.5)*x)/e),posY:Ae((n.y+n.h/2-o/2-$*(g-.5)*E)/o),scale:Ae($)}}function tE(t,e,{at:o,duration:r,width:a,cx:n,cy:i,aspect:c,color:u="#ff2d3f",W:p=1280,H:s=720,material:h=null,newId:f}){const m=t.find(z=>z.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(u)))throw Error("Speaker window color must be #RRGGBB");const g=ut(Math.max(m.start,o)),v=ut(Math.min(m.start+m.duration,g+nr(Number.isFinite(r)?r:5,Ir.minDuration,Ir.maxDuration)));if(v-g<Ir.minDuration-1e-6)throw Error("Speaker window must start at least 1 s before the clip ends");const x=Math.round(h?.width)||(p<=s?1080:1920),E=Math.round(h?.height)||(p<=s?1920:1080);let $=t,S=m;const k=[f?.()??`${m.id}-wb`,f?.()??`${m.id}-wa`];if(g>m.start+1e-6){const[z,j]=_e(S,g,k[0]);j&&($=$.flatMap(P=>P.id===S.id?[z,j]:[P]),S=j)}if(v<S.start+S.duration-1e-6){const[z,j]=_e(S,v,k[1]);j&&($=$.flatMap(P=>P.id===S.id?[z,j]:[P]),S=z)}const y=Gd({W:p,H:s,width:a,cx:n,cy:i,...Number.isFinite(c)?{aspect:c}:{}}),C=Q6(S,{W:p,H:s,mw:x,mh:E,rect:y,anchor:qc(S,h)}),A={...S,motionV:2,motionKeys:[],posX:C.posX,posY:C.posY,scale:C.scale,mask:C.mask,zIndex:Ir.zIndex,edge:{color:u.toLowerCase(),...Ir.rim},shadow:{...kn,opacity:.5,blur:22,distance:6},enter:{type:"fade",duration:.3},exit:{type:"fade",duration:.25}};for(const z of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])delete A[z];return{clips:$.map(z=>z.id===S.id?A:z),windowId:S.id}}function eE(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!==fo.points||t.zIndex!==fo.zIndex)return null;const a=r.map(m=>m[0]),n=r.map(m=>m[1]),i=(Math.min(...a)+Math.max(...a))/2,c=(Math.min(...n)+Math.max(...n))/2,u=(Math.max(...a)-Math.min(...a))/2,{mw:p,mh:s}=t.mask,h=t.fit==="cover"?Math.max(e/p,o/s):Math.min(e/p,o/s),f=2*(t.scale??1)*u*p*h/Math.min(e,o);return{cx:Ae(i),cy:Ae(c),ru:Ae(u),size:Ae(nr(f,fo.minSize,fo.maxSize)),corner:`${(t.posY??0)<0?"top":"bottom"}-${(t.posX??0)>0?"right":"left"}`}}function AT(t,e,{W:o,H:r}){const a=eE(t,{W:o,H:r});if(!a)throw Error("Not a speaker bubble");const{mw:n,mh:i}=t.mask,c={...a,...e},u=Vd(t,{W:o,H:r,mw:n,mh:i,...a}),p=Vd(t,{W:o,H:r,mw:n,mh:i,...c}),s=e.corner===void 0||e.corner===a.corner,h=s?(t.posX??0)-u.posX:0,f=s?(t.posY??0)-u.posY:0;return{mask:p.mask,posX:Ae(p.posX+h),posY:Ae(p.posY+f),scale:p.scale,bubble:p.bubble}}const jt=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]}}),b0=Object.freeze(Object.keys(h1)),w0=Object.freeze(["questions","chapters","steps","none"]),oE=Object.freeze({style:"karaoke",position:"bottom",font:"Be Vietnam Pro",perGroup:3,emphasis:!0,emphasisColor:"#8fc4ff",emphasisColor2:"#3d7bff",size:.8}),Lt=t=>+(+t).toFixed(3),Zo=(t,e,o)=>Math.max(e,Math.min(o,t)),sn=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}]+/gu,"").trim(),rE=t=>/[.!?…]$/u.test(String(t??"").trim()),ds=t=>String(t??"").replace(/[.,!?…:;"“”]+$/u,""),pi=t=>{const e=String(t??"").trim().replace(/[.,:;…"“”]+$/u,"");return e.charAt(0).toUpperCase()+e.slice(1)},ke=(t,e)=>String(t??"").replace(/\s+/gu," ").trim().slice(0,e),Wn=(t,e=24)=>{let o="";for(const r of ds(String(t??"")).split(/[\s,;:]+/u).filter(Boolean)){const a=o?o+" "+r:r;if(a.length>e)break;o=a}return ds(o)},nE=/[ăâđêôơưạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ]/iu,aE={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},sl=t=>{const e=sn(t);return/^\d{1,2}$/u.test(e)?+e:aE[e]??null},Op=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"]),Qc={nhất:1,hai:2,ba:3,tư:4,năm:5,sáu:6},tp={first:1,firstly:1,second:2,secondly:2,third:3,thirdly:3,fourth:4,fourthly:4,fifth:5,finally:-1,lastly:-1},iE=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"}]),sE=/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 lE(t){const e=[];let o=null;return t.forEach((r,a)=>{const n=t[a-1],i=n?r.start-n.end:1/0;(!o||i>.8||rE(n.word))&&(o={start:r.start,end:r.end,words:[],gap:i,i0:a},e.push(o)),o.words.push(r),o.end=r.end}),e.map(r=>({...r,text:r.words.map(a=>String(a.word)).join(" ")}))}const hs=(t,e,o=12)=>{const r=t.words.slice(e).map(a=>String(a.word));for(;r.length&&Op.has(sn(r[0]));)r.shift();return r.slice(0,o).join(" ").replace(/^[,:–-]+\s*/u,"")},k0={tiếp:null,đầu:1,cuối:null};function cE(t){const e=t.words.map(o=>sn(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 a=sl(t.words[r]?.word);if(a!==null)return{j:r+1,number:a};if(e[r]in k0&&["theo","tiên","cùng"].includes(e[r+1]))return{j:r+2,number:k0[e[r]]};continue}if(e[o]==="question"){let r=o+1;["number","no"].includes(e[r])&&r++;const a=sl(t.words[r]?.word);if(a!==null)return{j:r+1,number:a};if(["next","first","last","final"].includes(e[o-1]))return{j:r,number:e[o-1]==="first"?1:null}}}return null}function pE(t){const e=[];if(t.forEach((r,a)=>{const n=cE(r);if(!n)return;let i=hs(r,n.j,14);i.split(" ").filter(Boolean).length<3&&t[a+1]&&(i=t[a+1].text),e.push({at:r.start,number:n.number,text:ke(pi(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>=jt.questionPause)&&r!==t[0]||o.length&&r.start-o.at(-1).at<jt.questionGap||o.push({at:r.start,text:ke(pi(r.text),90)});return o}function uE(t){const e=[];for(const o of t){const r=o.words.map(a=>sn(a.word));for(let a=0;a<Math.min(4,r.length-1);a++){if(!["chương","phần","chapter","part","module","bài"].includes(r[a]))continue;const n=sl(o.words[a+1].word);if(n!==null){e.some(i=>i.number===n)||e.push({at:o.start,number:n,title:ke(ds(hs(o,a+2,8)),60)});break}}}return e}function dE(t,e){const o=(i,c)=>{const u=e.find(p=>i>=p.i0&&i<p.i0+p.words.length);return u?Wn(hs(u,c-u.i0,6)):""},r=Uy(t).map(i=>({at:i.at,number:i.number,label:o(i.i,i.i+(sl(t[i.i+1]?.word)!==null||sn(t[i.i]?.word)==="bước"?2:1))||ke(i.auto,24)}));for(const i of e){const c=sn(i.words[0]?.word),u=sn(i.words[1]?.word);let p=null,s=1;c==="thứ"&&Qc[u]?(p=Qc[u],s=2):tp[c]&&(p=tp[c]),p!==null&&(p===-1&&(p=(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:p,label:Wn(hs(i,s,6))}))}r.sort((i,c)=>i.at-c.at);const a=[];for(const i of r){const c=a.at(-1),u=c?.at(-1);!c||i.number===1&&u.number!==1||i.number<=u.number||i.at-u.at>jt.stepGap?a.push([i]):c.push(i)}const n=[];for(const i of a){if(i.length<2)continue;const c=Math.min(jt.maxItems,Math.max(...i.map(p=>p.number))),u=Array.from({length:c},(p,s)=>i.find(h=>h.number===s+1)?.label||String(s+1));i.forEach((p,s)=>{if(p.number>c)return;const h=i[s+1]?.at;n.push({at:Lt(p.at),duration:Lt(Zo((h??p.at+jt.steps.dur)-p.at-.1,jt.steps.min,jt.steps.dur)),labels:u,current:p.number})})}return n}const hE=/(?<![\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,fE=/(?<![\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,mE=/(?<![\p{L}\p{N}])(mô hình|khung|framework|model|the)?\s*([3-6])\s?([APCSM])(?:'?s)?(?![\p{L}\p{N}])/u,x0=/(?:^|\s)(mô hình|khung|framework|model)\s*$/iu;function ep(t){const e=t.words.map(o=>sn(o.word));for(let o=0;o<Math.min(6,e.length);o++){if(e[o]==="thứ"&&Qc[e[o+1]])return{num:Qc[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&&tp[e[o]])return{num:tp[e[o]],j:o+1}}return null}const gE=/^(tức là|nghĩa là|có nghĩa là|là|which means|that is|meaning|means|is)\s+/iu,yE=new Set([...Op,"one","chữ","cái","yếu","tố","điều","step","bước","nguyên","tắc","letter","then"]);function bE(t){const e=String(t??"").split(/\s+/u).filter(Boolean);for(;e.length&&yE.has(sn(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),a=r?r[1]:o,n=r?r[2].replace(gE,""):"",i=a.split(/\s+/u).filter(Boolean),c=i.length<=3?ds(a):ds(i.slice(0,3).join(" ")),u=i.length<=3?Wn(n,30):Wn(i.slice(3).join(" ")+" "+n,30);return{title:pi(Wn(c,20)),sub:Wn(u,30),short:!!r&&i.length<=3}}function wE(t){const e=[],o=new Set,r=(a,n)=>{const i=[];for(let c=a;c<t.length;c++){const u=t[c];if(u.start>n)break;if(o.has(c))continue;const p=ep(u);if(!p)continue;const s=p.num===-1?i.length+1:p.num;if(s!==i.length+1){if(i.length>=2)break;if(s===1)i.length=0;else continue}if(i.push({k:c,at:Lt(u.start),...bE(hs(u,p.j,16))}),i.length>=jt.framework.max)break}return i.filter(c=>c.title)};t.forEach((a,n)=>{if(e.length>=jt.framework.maxCount||o.has(n))return;const i=a.text,c=hE.exec(i),u=fE.exec(i),p=mE.exec(i),s=c||u||p;if(!s)return;const h=p&&!c&&!u?+p[2]:sl(s[1]);if(!(h>=3&&h<=jt.framework.max))return;const f=r(n,a.start+jt.framework.within).slice(0,h);if(f.length<Math.min(3,h))return;const m=i.slice(0,s.index),g=p&&!c&&!u?`${p[1]&&p[1]!=="the"?p[1]+" ":""}${p[2]}${p[3]}`:(x0.exec(m)?.[1]?x0.exec(m)[1]+" ":"")+s[0].trim();f.forEach(v=>o.add(v.k)),o.add(n),e.push({at:Lt(a.start),title:ke(pi(g),32),items:f.map(({k:v,short:x,...E})=>E)})});for(let a=0;a<t.length&&e.length<jt.framework.maxCount;a++){if(o.has(a)||!ep(t[a]))continue;const n=r(a,t[a].start+jt.framework.within);n.length<3||!n.every(i=>i.short)||(n.forEach(i=>o.add(i.k)),e.push({at:n[0].at,title:"",items:n.map(({k:i,short:c,...u})=>u)}))}return e.sort((a,n)=>a.at-n.at)}const kE=/(?<![\p{L}])(video|tập|bài|số|clip)\s+(trước|lần trước|vừa rồi)(?![\p{L}])/iu,xE=/(?<![\p{L}])(previous|last|earlier)\s+(video|episode|lesson|part)(?![\p{L}])/iu,ME=new Set([...Op,"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 vE(t){const e=[];for(const o of t){if(e.length>=jt.label.maxAuto)break;const r=kE.exec(o.text)||xE.exec(o.text);if(!r||e.length&&o.start-e.at(-1).at<jt.label.gap)continue;const a=o.text.slice(r.index+r[0].length).split(/\s+/u).filter(Boolean);for(;a.length&&ME.has(sn(a[0]));)a.shift();e.push({at:Lt(o.start),sub:Wn(a.join(" "),30)})}return e}const $E=/(?<![\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,EE=/(?<![\p{L}\p{N}])(two|2)\s+(ways|paths|options|routes|kinds|types|models|approaches)(?![\p{L}\p{N}])/iu,SE=new Set([...Op,"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"]),IE=/(?: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,AE=/\$\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,M0=t=>t?/^(k|thousand)$/i.test(t)?"K":"M":"";function xu(t){const e=String(t??""),o=IE.exec(e);if(o)return`${o[1]}${o[2]?"–"+o[2]:""} ${o[3].toLowerCase()}`;const r=AE.exec(e);if(!r)return"";const a=r[1]??r[5],n=r[3]??r[7],i=r[4]??r[8]??r[2]??r[6],c=r[2]??r[6]??(r[5]?i:void 0);return`$${a}${M0(c)}${n?` – $${n}${M0(i)}`:""}`}function CE(t){const e=String(t??"").split(/\s+/u).filter(Boolean);for(;e.length&&SE.has(sn(e[0]));)e.shift();const o=e.join(" "),r=/^([^,:;–—]+?)\s*[,:;–—]\s*(.*)$/u.exec(o),a=r?r[1]:o,n=a.split(/\s+/u);return{head:pi(ds(n.slice(0,5).join(" "))),rest:r?r[2]:n.slice(5).join(" ")}}function jE(t){const e=[];return t.forEach((o,r)=>{if(e.length>=jt.compare.maxAuto||e.length&&o.start<e.at(-1).end)return;const a=$E.exec(o.text)||EE.exec(o.text);if(!a)return;const n=[];let i=r;for(;i<t.length&&t[i].start<=o.start+jt.compare.within&&n.length<3;i++){const f=t[i],m=i===r?null:ep(f);if(!m)continue;if((m.num===-1?n.length+1:m.num)!==n.length+1)break;n.push({k:i,m})}if(n.length!==2)return;let c=1;const u=(f,m)=>{const g=t[f.k],{head:v,rest:x}=CE(hs(g,f.m.j,24)),E=m===0?t[n[1].k].start:g.start+jt.compare.side,$=t.slice(f.k+1).filter(A=>A.start<E&&!ep(A)).slice(0,m===0?jt.compare.lines:Math.max(1,c)).map(A=>A.text),S=[x,...$].filter(Boolean);m===0&&(c=$.length);const k=S.map(xu).find(Boolean)||xu(g.text),y=[...new Set(S.filter(A=>!xu(A)).map(A=>pi(Wn(A,40))).filter(A=>A.split(" ").length>=2))].slice(0,jt.compare.lines),C=t[f.k+$.length];return{head:ke(v,28),amount:k,lines:y,end:C?.end??g.end}},p=u(n[0],0),s=u(n[1],1);if(!p.head||!s.head)return;const h=ke(pi(Wn(o.text.slice(a.index),48)).toUpperCase(),48);e.push({at:Lt(o.start),end:Lt(s.end),title:h,left:{head:p.head,amount:p.amount,lines:p.lines},right:{head:s.head,amount:s.amount,lines:s.lines}})}),e}function TE(t,e=!1){const o=[];for(const r of t)for(const a of iE)o.some(n=>n.kind===a)||a.re.test(r.text)&&o.push({kind:a,at:Lt(r.start+.2),label:e?a.en:a.vi,icon:a.icon});return o.sort((r,a)=>r.at-a.at).map(({kind:r,...a})=>a).slice(0,jt.tool.maxCount)}const OE=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")}},Uo=(t,e,o)=>t.some(([r,a])=>e<a-.05&&o>r+.05),Vl=(t,e)=>{const o=Math.max(1,Math.ceil((e-t)/to.maxDuration-1e-9)),r=[];for(let a=0;a<o;a++){const n=t+(e-t)*a/o,i=t+(e-t)*(a+1)/o;r.push({start:Lt(n),duration:Lt(i-n),fade:o===1?"both":a===0?"in":a===o-1?"out":"none"})}return r},gc=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),v0=/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 $0(t,e){const o=Math.min(t,e)/Math.max(t,e),r=1-o;return t>=e?{left:Lt(r/2),right:Lt(r/2),top:0,bottom:0}:{left:0,right:0,top:Lt(r*.3),bottom:Lt(r*.7)}}function zE(t,e,o){const r=t/e;if(r>o){const n=Lt((1-o/r)/2);return{left:n,right:n,top:0,bottom:0}}const a=1-r/o;return{left:0,right:0,top:Lt(a*.4),bottom:Lt(a*.6)}}function ki(t,e,o,r,a,n){const i=g=>Math.max(2,Math.floor(g/2)*2),c=i(t),u=i(e),p=Math.abs(r*Math.PI/180),s=Math.abs(Math.cos(p)),h=Math.abs(Math.sin(p)),f=p?Math.ceil((c*s+u*h)/2)*2:c,m=p?Math.ceil((c*h+u*s)/2)*2:u;return Lt(Zo(o/Math.min(a/f,n/m),.02,4))}function PE({clips:t=[],materials:e=[],op:o={},W:r=1280,H:a=720,en:n=null,maxOps:i=1/0,brand:c=null}={}){const u={...OE(o.prompt),...Object.fromEntries(Object.entries(o).filter(([X,gt])=>!["op","prompt"].includes(X)&&gt!==null&&gt!==void 0))},p=t.find(X=>X.id===u.clipId);if(!p||p.kind!=="video"||p.motion||p.title||p.shape)throw Error("clipId must be the main lesson video on the timeline");if(u.navigator!=null&&!w0.includes(u.navigator))throw Error(`navigator must be ${w0.join(" / ")}`);if(u.theme!=null&&!b0.includes(u.theme))throw Error(`theme must be ${b0.join(" / ")}`);for(const X of["chapters","steps","tools","screenClips","overhead","photos","labels","split","docs"])if(u[X]!=null&&!Array.isArray(u[X]))throw Error(`${X} must be a list`);for(const X of["framework","journey","cover","map"])if(u[X]!=null&&(typeof u[X]!="object"||Array.isArray(u[X])))throw Error(`${X} must be an object`);if(u.compare!=null&&u.compare!==!1&&(typeof u.compare!="object"||Array.isArray(u.compare)))throw Error("compare must be an object (or false)");const s=h1[u.theme??Jw],h=t.filter(X=>X.id===p.id||p.nodeId&&X.nodeId===p.nodeId&&X.track===p.track&&X.kind===p.kind&&!X.mask).sort((X,gt)=>X.start-gt.start),f=h[0].start,m=h.at(-1).start+h.at(-1).duration,g=Math.max(.001,m-f),v=X=>X>=f-1e-6&&X<m-.5,x=Sh(t,p.id,e),E=lE(x),$=x.map(X=>X.word).join(" "),S=$?!nE.test($)&&n!==!1:!!n,k=a>r*1.1,y=X=>e.find(gt=>gt.id===X),C=Math.min(r,a),A=(X,gt)=>{if(!Number.isFinite(+X))throw Error(`${gt} needs at (timeline seconds)`);return Lt(Zo(+X,f,m-.5))},z=X=>`${y(X.nodeId)?.label||X.label||""} ${(y(X.nodeId)?.labels||[]).join(" ")}`,j=(X,gt)=>{const bt=y(X);if(!bt||bt.kind!=="image"||!bt.url)throw Error(`${gt} must be an image from Media`);return bt},P=(u.chapters??[]).slice(0,30).map((X,gt)=>({at:A(X?.at,`chapters[${gt}]`),title:ke(X?.title,80),sub:ke(X?.sub,80),takeaways:(Array.isArray(X?.takeaways)?X.takeaways:[]).map(bt=>ke(bt,48)).filter(Boolean).slice(0,3),number:gt+1})).sort((X,gt)=>X.at-gt.at),F=P.length?[]:uE(E).filter(X=>v(X.at)),N=P.length?P:F.map((X,gt)=>({...X,number:X.number??gt+1,sub:"",takeaways:[]})),G=(X,gt,bt)=>{const St=X&&typeof X=="object",Rt=St?`${X.title??""}${X.sub?" — "+X.sub:""}`:String(X??""),Dt=Rt.split(/\s+[—–-]\s+|\s*:\s+/u),Ft=ke(St?X.title:Dt[0],20),Xt=ke(St?X.sub:Dt.slice(1).join(" "),30);if(!Ft)throw Error(`framework.items[${gt}] needs a title`);return{at:St&&Number.isFinite(+X.at)?A(X.at,`framework.items[${gt}]`):Lt(bt+jt.framework.lead*2+gt*jt.framework.step),title:Ft,sub:Xt,icon:St&&Dp(X.icon)?X.icon:null}},V=u.framework?(()=>{const X=u.framework,gt=A(X.at,"framework"),bt=Array.isArray(X.items)?X.items.slice(0,jt.framework.max):[];if(bt.length<jt.framework.min)throw Error(`framework needs ${jt.framework.min}–${jt.framework.max} items`);return[{at:gt,title:ke(X.title,32),items:bt.map((St,Rt)=>G(St,Rt,gt)).sort((St,Rt)=>St.at-Rt.at)}]})():wE(E).filter(X=>v(X.at)).map(X=>({...X,items:X.items.map(gt=>({...gt,icon:null}))})),et=X=>[X.at-1,X.items.at(-1).at+jt.framework.hold],U=(X,gt)=>{if(!X||typeof X!="object"||!ke(X.head,28))throw Error(`compare.${gt} needs head`);return{head:ke(X.head,28),amount:ke(X.amount,24),lines:(Array.isArray(X.lines)?X.lines:[]).map(bt=>ke(bt,40).replace(/[|]+/gu," ")).filter(Boolean).slice(0,4)}},at=u.compare===!1?[]:u.compare?[(()=>{const X=u.compare,gt=A(X.at,"compare");return{at:gt,end:gt+(Number.isFinite(+X.duration)?+X.duration:jt.compare.dur),title:ke(X.title,48),left:U(X.left,"left"),right:U(X.right,"right"),given:!0}})()]:jE(E).filter(X=>v(X.at)),W=X=>[X.at-.5,X.end+.5],_=(u.steps?u.steps.slice(0,40).map((X,gt)=>{const bt=(Array.isArray(X?.labels)?X.labels:[]).map(St=>ke(St,24)).filter(Boolean).slice(0,jt.maxItems);if(!bt.length)throw Error(`steps[${gt}] needs labels`);return{at:A(X?.at,`steps[${gt}]`),duration:Lt(Zo(Number.isFinite(+X?.duration)?+X.duration:jt.steps.dur,jt.steps.min,8)),labels:bt,current:Zo(Math.round(+X?.current||1),1,bt.length)}}):dE(x,E).filter(X=>v(X.at))).filter(X=>u.steps||!V.some(gt=>{const[bt,St]=et(gt);return X.at>=bt&&X.at<=St})&&!at.some(gt=>{const[bt,St]=W(gt);return X.at>=bt&&X.at<=St})),J=u.tools?u.tools.slice(0,jt.tool.maxCount).map((X,gt)=>{const bt=ke(X?.label,32);if(!bt)throw Error(`tools[${gt}] needs label`);return{at:A(X?.at,`tools[${gt}]`),duration:Number.isFinite(+X?.duration)?Zo(+X.duration,jt.tool.min,jt.tool.max):jt.tool.dur,label:bt,url:ke(X?.url,40),icon:Dp(X?.icon)?X.icon:Zi(`${X?.label??""} ${X?.url??""}`)||"sparkle"}}):TE(E,S).filter(X=>v(X.at)).map(X=>({...X,duration:jt.tool.dur,url:""})),tt=pE(E).filter(X=>v(X.at)),rt=u.navigator??(N.length?"chapters":tt.length>=2?"questions":_.length?"steps":"none");if(!x.length&&!N.length&&!_.length&&!J.length&&!(u.screenClips??[]).length&&!(u.overhead??[]).length&&!u.framework&&!(u.photos??[]).length&&!u.cover&&!u.journey&&!(u.labels??[]).length&&!(u.split??[]).length&&!(u.docs??[]).length&&!u.map&&!u.compare&&u.brand!==!0)throw Error("analyse the speech first (transcript) or give chapters / steps / tools");const D=u.overhead??t.filter(X=>["video","image"].includes(X.kind)&&!h.includes(X)&&!X.motion&&!X.title&&!X.shape&&v0.test(z(X))&&X.start<m-1&&X.start+X.duration>f+1).map(X=>({clipId:X.id})),q=[],pt=new Map;D.slice(0,jt.overhead.maxCount).forEach((X,gt)=>{const bt=t.find(se=>se.id===X?.clipId),St=bt&&y(bt.nodeId);if(!bt||!["video","image"].includes(bt.kind)||bt.motion||bt.title||bt.shape||!St?.url)throw Error(`overhead[${gt}] clipId must be a whiteboard / B-roll video or image clip from Media`);if(h.includes(bt))throw Error("the lesson video cannot be its own overhead shot");const Rt=A(X.at??bt.start,`overhead[${gt}]`),Dt=(bt.inPoint||0)+(pt.get(bt.id)||0),Ft=bt.kind==="video"&&Number.isFinite(St.duration)?St.duration-Dt:1/0;let Xt=Math.min(Number.isFinite(+X.duration)?+X.duration:bt.duration,m-Rt,jt.overhead.max);const Zt=Ft>=Math.min(Xt,jt.overhead.min)?Dt:bt.inPoint||0;bt.kind==="video"&&Number.isFinite(St.duration)&&(Xt=Math.min(Xt,St.duration-Zt));const te=q.at(-1);te&&Rt<te.a+te.d&&(Xt=0),!(Xt<jt.overhead.min)&&(pt.set(bt.id,(pt.get(bt.id)||0)+Xt),q.push({c:bt,m:St,a:Rt,d:Lt(Xt),inPoint:Lt(bt.kind==="video"?Zt:0)}))});const yt=q.map(X=>[X.a,X.a+X.d]),Mt=Gd({W:r,H:a}),l=new Set(q.map(X=>X.c.id)),K=(u.screenClips??t.filter(X=>X.kind==="video"&&!h.includes(X)&&!X.motion&&!l.has(X.id)&&!v0.test(z(X))&&sE.test(z(X))).map(X=>X.id)).map(X=>{const gt=t.find(bt=>bt.id===X);if(!gt||!["video","image"].includes(gt.kind)||gt.motion||gt.title)throw Error(`screen clip ${String(X).slice(0,40)} not found`);if(h.includes(gt))throw Error("the lesson video cannot be its own screen recording");return gt}),d=K.map(X=>[X.start,X.start+X.duration]),w=X=>{if(Uo(yt,X,X+.01))return{x:Mt.params.posX,y:Mt.params.posY-Mt.params.ph*.2,window:!0};const gt=h.find(bt=>X>=bt.start&&X<bt.start+bt.duration)??h[0];return Jc(gt,y(gt.nodeId),X,{W:r,H:a})??(k?Ie.face.portrait:Ie.face.landscape)},T=(X,gt,bt)=>{const St=w(X);return gt<St.y+Ie.chin&&bt>St.y-Ie.head},I=u.captions===!0?jt.lift:0,O=(X,gt,bt)=>T(X,gt-I,bt-I)&&!T(X,k?.08:.06,k?.3:.24)?"top":"lower",L=[],B=[],H=[],Z=[],ot=[...yt],st=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 ct=X=>(L.push(X),gc.has(X.op)&&Y++,X),mt=()=>`new:${Y}`,Q=X=>{const gt=w(X),bt=gt.window?Mt.params.pw/2:Ie.halfWidth.landscape,St=gt.x-bt-.07-.03,Rt=.93-(gt.x+bt)-.03;return Rt>=St?{side:"right",x0:gt.x+bt+.03,w:Rt,f:gt}:{side:"left",x0:.07,w:St,f:gt}},nt=(X,gt)=>{H.push([X,X+gt]),ct({op:"addMotion",motionPreset:"course-chapter-card",start:X,duration:gt,placement:"center",params:{text:"",sub:"",number:0,label:"",...u.theme?{bg:s.bg}:{}}})};for(const X of l)ct({op:"delete",clipId:X});for(const X of q){ct({op:"addBroll",materialId:X.m.id,start:Lt(X.a),duration:X.d,inPoint:X.inPoint});const gt=mt();ct({op:"setAnimation",clipId:gt,property:"enter",preset:"fade",duration:jt.overhead.fade}),ct({op:"setAnimation",clipId:gt,property:"exit",preset:"fade",duration:jt.overhead.fade}),ct({op:"speakerWindow",clipId:p.id,at:Lt(X.a),duration:X.d,numberValue:Mt.params.pw,posX:Mt.params.posX,posY:Mt.params.posY,color:s.accent});for(const bt of Vl(X.a,X.a+X.d))ct({op:"addMotion",motionPreset:"course-pip-frame",start:bt.start,duration:bt.duration,placement:"center",params:{...Mt.params,fade:bt.fade,text:""}})}(u.chapterCards===!0?N.map(X=>({at:X.at,end:Lt(Math.min(m,X.at+jt.card))})):[]).forEach((X,gt)=>{const bt=N[gt];H.push([X.at,X.end]),ct({op:"addMotion",motionPreset:"course-chapter-card",start:X.at,duration:Lt(X.end-X.at),placement:"center",text:bt.title||`${st.ch} ${bt.number}`,...bt.sub?{subText:bt.sub}:{},numberValue:bt.number,params:{label:st.ch,...u.theme?{bg:s.bg}:{}}})});const vt=[],It=X=>Math.floor(X*30+1e-6)/30,xt=X=>Math.floor(X*1e3)/1e3,Et=X=>+(+X).toFixed(4),Ct=(X,gt)=>!Uo([...H,...yt,...d,...vt],X,gt),Gt=(X,gt,bt)=>It(Math.min(m-bt,Zo(Number.isFinite(+X)?+X:gt.dur,gt.min,gt.max))),ee=(X,gt)=>{H.push([X,X+gt]),ot.push([X,X+gt]),vt.push([X,X+gt])},re=(X,gt)=>{ct({op:"setAnimation",clipId:X,property:"enter",preset:"fade",duration:gt}),ct({op:"setAnimation",clipId:X,property:"exit",preset:"fade",duration:gt})},Me=k?jt.split.portrait:jt.split.landscape,qt=new Set;(u.split??[]).slice(0,jt.split.maxCount).forEach((X,gt)=>{const bt=X?.clipId!=null?t.find(pw=>pw.id===X.clipId):null;if(X?.clipId!=null&&(!bt||!["video","image"].includes(bt.kind)||bt.motion||bt.title||bt.shape))throw Error(`split[${gt}] clipId must be a B-roll video or image clip`);if(bt&&h.includes(bt))throw Error("the lesson video cannot be its own split card");const St=y(bt?bt.nodeId:X?.materialId);if(!St||!["video","image"].includes(St.kind)||!St.url)throw Error(`split[${gt}] needs clipId or materialId (a video / image from Media)`);const Rt=A(X.at??bt?.start,`split[${gt}]`),Dt=St.kind==="video"?Lt(bt?bt.inPoint||0:Zo(+X.inPoint||0,0,Math.max(0,(St.duration||0)-1))):0;let Ft=Gt(X.duration??bt?.duration,jt.split,Rt);if(St.kind==="video"&&Number.isFinite(St.duration)&&(Ft=It(Math.min(Ft,St.duration-Dt))),Ft<jt.split.min||!Ct(Rt,Rt+Ft))return;bt&&!qt.has(bt.id)&&(qt.add(bt.id),ct({op:"delete",clipId:bt.id}));const[Xt,Zt,te,se]=Me.m,ce=St.width||1920,Ut=St.height||1080,oe=zE(ce,Ut,te*r/(se*a)),ae=ce*(1-oe.left-oe.right),kr=ki(ae,Ut*(1-oe.top-oe.bottom),te*r/ae,0,r,a);ct({op:"addBroll",materialId:St.id,start:Rt,duration:Ft,inPoint:Dt});const go=mt();ct({op:"courseStyle",clipId:go,crop:oe,fit:"contain",mask:"rounded"}),ct({op:"setKeyframes",clipId:go,motionKeys:[{time:0,x:Lt(Xt-.5),y:Lt(Zt-.5),zoom:kr},{time:xt(Ft),x:Lt(Xt-.5),y:Lt(Zt-.5),zoom:kr}]}),re(go,jt.split.fade);const[un,Pr,xr,Aa]=Me.p,Ca=Et(xr*r/(Aa*a)),oa=Gd({W:r,H:a,width:xr,cx:un,cy:Pr,aspect:Ca});ct({op:"speakerWindow",clipId:p.id,at:Rt,duration:Ft,numberValue:xr,posX:un,posY:Pr,aspect:Ca,color:s.accent}),ct({op:"addMotion",motionPreset:"course-split-cards",start:Rt,duration:Ft,placement:"center",params:{mx:Xt,my:Zt,mw:te,mh:se,px:oa.params.posX,py:oa.params.posY,pw:oa.params.pw,ph:oa.params.ph,bg:s.bg}}),ee(Rt,Ft)});for(const X of at){const gt=X.at,bt=Gt(X.given?X.end-X.at:Math.max(jt.compare.min,X.end-X.at+1.2),jt.compare,gt);bt<jt.compare.min||!Ct(gt,gt+bt)||(ct({op:"addMotion",motionPreset:"course-compare-board",start:gt,duration:bt,placement:"center",params:{title:X.title,leftHead:X.left.head,leftAmount:X.left.amount,leftLines:X.left.lines.join("|"),rightHead:X.right.head,rightAmount:X.right.amount,rightLines:X.right.lines.join("|"),vs:"VS",bg:s.bg}}),ee(gt,bt))}if((u.docs??[]).slice(0,jt.doc.maxCount).forEach((X,gt)=>{const bt=j(X?.materialId,`docs[${gt}].materialId`),St=A(X.at,`docs[${gt}]`),Rt=Gt(X.duration,jt.doc,St),Dt=X.highlight;if(Dt!=null&&!(["x","y","w","h"].every(ae=>Number.isFinite(+Dt[ae]))&&Dt.x>=0&&Dt.y>=0&&Dt.w>0&&Dt.h>0&&Dt.x+Dt.w<=1.001&&Dt.y+Dt.h<=1.001))throw Error(`docs[${gt}].highlight must be {x, y, w, h} (0..1 of the document)`);if(Rt<jt.doc.min||!Ct(St,St+Rt))return;const Ft=bt.width||1200,Xt=bt.height||1600,Zt=Math.min(jt.doc.w*r/Ft,jt.doc.h*a/Xt),te=Et(Ft*Zt/r),se=Et(Xt*Zt/a),ce=jt.doc.cy,Ut=ki(Ft,Xt,Zt,0,r,a);ct({op:"addBroll",materialId:bt.id,start:St,duration:Rt});const oe=mt();ct({op:"courseStyle",clipId:oe,fit:"contain"}),ct({op:"setKeyframes",clipId:oe,motionKeys:[{time:0,x:0,y:Lt(ce-.5),zoom:Ut},{time:xt(Rt),x:0,y:Lt(ce-.5),zoom:Et(Ut*(1+jt.doc.zoom*xt(Rt)/Rt))}]}),re(oe,jt.doc.fade),ct({op:"addMotion",motionPreset:"course-doc-highlight",start:St,duration:Rt,placement:"center",params:{cx:.5,cy:ce,cw:te,ch:se,...Dt?{posX:Et(.5+(+Dt.x+Dt.w/2-.5)*te),posY:Et(ce+(+Dt.y+Dt.h/2-.5)*se),bw:Et(Dt.w*te),bh:Et(Dt.h*se)}:{bw:0,bh:0},text:ke(X.note,30)}}),ee(St,Rt)}),u.map){const X=u.map,gt=A(X.at,"map"),bt=X.materialId!=null?j(X.materialId,"map.materialId"):null,St=Array.isArray(X.pins)?X.pins.slice(0,jt.map.pins):[];if(!St.length)throw Error(`map needs 1–${jt.map.pins} pins [{x, y, label}]`);const Rt=St.map((Ft,Xt)=>{let Zt=+Ft?.x,te=+Ft?.y;if(!(Ft?.x!=null&&Ft?.y!=null)&&!bt&&Number.isFinite(+Ft?.lat)&&Number.isFinite(+Ft?.lon)&&(Zt=(+Ft.lon+180)/360,te=(85-Ft.lat)/145),!(Zt>=0&&Zt<=1&&te>=0&&te<=1))throw Error(`map.pins[${Xt}] needs x, y (0..1 of the map)${bt?"":" or lat / lon"}`);if(bt){const se=bt.width||1920,ce=bt.height||1080,Ut=Math.max(r/se,a/ce);Zt=.5+(Zt-.5)*se*Ut/r,te=.5+(te-.5)*ce*Ut/a}return{x:Lt(Zt),y:Lt(te),label:ke(Ft.label,24).replace(/[|@]+/gu," ")}}).filter(Ft=>Ft.x>=0&&Ft.x<=1&&Ft.y>=0&&Ft.y<=1),Dt=Gt(X.duration,jt.map,gt);Rt.length&&Dt>=jt.map.min&&Ct(gt,gt+Dt)&&(bt&&(ct({op:"addBroll",materialId:bt.id,start:gt,duration:Dt}),re(mt(),jt.map.fade)),ct({op:"addMotion",motionPreset:"course-map-pins",start:gt,duration:Dt,placement:"center",params:{items:Rt.map(Ft=>`${Ft.label}@${Ft.x},${Ft.y}`).join("|"),map:bt?0:1,text:ke(X.title,30),route:Rt.length>1?1:0,bg:s.bg}}),ee(gt,Dt))}const Nt=u.journey,_t=Nt?(()=>{const X=A(Nt.at,"journey"),gt=Lt(Math.min(to.maxDuration,m-X,Number.isFinite(+Nt.duration)?Zo(+Nt.duration,jt.journey.min,to.maxDuration):jt.journey.dur));return gt>=jt.journey.min?{a:X,d:gt,avatar:Nt.avatarMaterialId!=null?j(Nt.avatarMaterialId,"journey.avatarMaterialId"):null,from:Zo(Number.isFinite(+Nt.from)?+Nt.from:0,0,1),to:Zo(Number.isFinite(+Nt.to)?+Nt.to:1,0,1),labels:(Array.isArray(Nt.labels)?Nt.labels:[]).map(bt=>ke(bt,22)).filter(Boolean).slice(0,6),text:ke(Nt.text,32)}:null})():null,Vt=_t?[_t.a,_t.a+_t.d]:null,he=rt==="chapters"?N.map(X=>({at:X.at,text:X.title,badge:st.ch,n:X.number})):rt==="questions"?tt.map((X,gt)=>({at:X.at,text:X.text,badge:st.q,n:X.number??gt+1})):rt==="steps"?_.map(X=>({at:X.at,text:X.labels[X.current-1],badge:st.step,n:X.current,total:X.labels.length})):[],ne=Math.max(1,...he.map(X=>X.n)),be=he.slice(1).map(X=>Lt((X.at-f)/g)).filter(X=>X>0&&X<1).slice(0,40).join("|");if(he.forEach((X,gt)=>{const bt=H.find(([Xt,Zt])=>X.at>=Xt-.05&&X.at<Zt),St=Lt(bt?bt[1]+.1:X.at),Rt=he[gt+1]?.at??m,Dt=Lt(Math.min(jt.nav.dur,Rt-.15-St,m-St));if(Dt<jt.nav.min)return;B.push([St,St+Dt]);const Ft=Vt&&Uo([Vt],St,St+Dt)?"top":O(St+Dt/2,k?.62:.68,k?.8:.9);ct({op:"addMotion",motionPreset:"course-question-nav",start:St,duration:Dt,text:ke(X.text,90),numberValue:X.n,placement:Ft,params:{sub:X.badge,total:X.total??ne,lift:I}}),u.progress!==!1&&rt!=="steps"&&ct({op:"addMotion",motionPreset:"course-progress-bar",start:St,duration:Dt,params:{from:Lt(Zo((St-f)/g,0,1)),to:Lt(Zo((St+Dt-f)/g,0,1)),ticks:be,text:"",position:Ft==="top"||w(St+Dt/2).y-Ie.head<.16?"lower":"top"}})}),rt!=="steps")for(const X of _)Uo(B,X.at,X.at+X.duration)||Uo(H,X.at,X.at+X.duration)||Vt&&Uo([Vt],X.at,X.at+X.duration)||(B.push([X.at,X.at+X.duration]),ct({op:"addMotion",motionPreset:"course-step-tiles",start:X.at,duration:X.duration,items:X.labels,numberValue:X.current,placement:O(X.at+X.duration/2,k?.7:.78,k?.8:.92),params:{lift:I}}));if(_t){const{a:X,d:gt}=_t,bt=T(X+gt/2,.74,.86),St=Lt(bt?.2:.8-I*.6),Rt=C*(k?jt.journey.r.portrait:jt.journey.r.landscape),Dt=k?.075:.07,Ft=1-Dt,Xt=Zt=>Lt(Dt+(Ft-Dt)*Zt-.5);if(_t.avatar){const Zt=_t.avatar,te=Zt.width||1e3,se=Zt.height||1e3,ce=jt.journey.delay,Ut=Lt(2*Rt/C),oe=Lt(gt-ce),ae=Lt(jt.journey.a-ce),kr=Lt(Math.max(ae+.1,gt-jt.journey.b-ce));ct({op:"addElement",materialId:Zt.id,start:Lt(X+ce),duration:oe,posX:Xt(_t.from),posY:Lt(St-.5),scale:.25,anim:{in:"pop",out:"fade",loop:"none"}});const go=mt();ct({op:"courseStyle",clipId:go,crop:$0(te,se),mask:"circle"}),ct({op:"setKeyframes",clipId:go,motionKeys:[{time:0,x:Xt(_t.from),y:Lt(St-.5),zoom:Ut},{time:ae,x:Xt(_t.from),y:Lt(St-.5),zoom:Ut},{time:kr,x:Xt(_t.to),y:Lt(St-.5),zoom:Ut},{time:oe,x:Xt(_t.to),y:Lt(St-.5),zoom:Ut}]})}ct({op:"addMotion",motionPreset:"course-journey-line",start:X,duration:gt,placement:"lower",..._t.text?{text:_t.text}:{},..._t.labels.length?{items:_t.labels}:{},params:{from:_t.from,to:_t.to,posY:St,ring:_t.avatar?1:0,glyph:"user",..._t.labels.length?{}:{items:""}}}),B.push([X,X+gt]),ot.push([X,X+gt])}for(const X of V){const gt=X.items.filter(Ut=>Ut.at<m-.5),bt=gt.length;if(bt<jt.framework.min)continue;const St=gt.map(Ut=>Ut.icon||Zi(`${Ut.title} ${Ut.sub}`)),Rt=St.every(Boolean)?St:gt.map(Ut=>Ut.icon),Dt=Ut=>gt.map((oe,ae)=>`${Rt[ae]?Rt[ae]+":":""}${oe.title}${oe.sub?" — "+oe.sub.slice(0,Ut):""}`.replace(/[|]+/gu," ")).join("|");let Ft=30;for(;Dt(Ft).length>290&&Ft>0;)Ft-=4;const Xt=[];gt.forEach((Ut,oe)=>{const ae=Xt.at(-1);ae&&Ut.at-gt[oe-1].at<=jt.framework.gap?ae.last=oe:Xt.push({first:oe,last:oe})});const Zt=[...H,...Z],te=Q((X.at+gt.at(-1).at)/2),se=Math.min(jt.framework.w,te.w/(1+.08*(bt-1))),ce=!k&&se<jt.framework.minW;for(const Ut of Xt){const oe=Lt(Ut.first===0?X.at:gt[Ut.first].at-jt.framework.lead),ae=Lt(Math.min(m,gt[Ut.last].at+jt.framework.hold,(gt[Ut.last+1]?.at??1/0)-jt.framework.lead-.1));if(ae-oe<jt.framework.min||Uo(Zt,oe,ae))continue;ce&&nt(oe,Lt(ae-oe));const kr=Uo(B,oe,ae)?.44:.5;for(const go of Vl(oe,ae)){const un=gt.map((Pr,xr)=>xr<Ut.first?-1:xr>Ut.last?999:Lt(Pr.at-go.start)).join("|");ct({op:"addMotion",motionPreset:"course-framework-stack",start:go.start,duration:go.duration,placement:"center",...X.title?{text:X.title}:{},params:{items:Dt(Ft),at:un,fade:go.fade,...X.title?{}:{text:""},...ce?{position:"left",posX:.5,posY:.5,width:.3}:{position:k?"left":te.side,...k?{}:{width:Lt(se),posY:kr}}}})}Z.push([oe,ae]),ot.push([oe,ae])}}const ir=(u.photos??[]).slice(0,jt.photo.maxCount).map((X,gt)=>({at:A(X?.at,`photos[${gt}]`),m:j(X?.materialId,`photos[${gt}].materialId`),scribble:X?.scribble===!0})).sort((X,gt)=>X.at-gt.at),zr=[];for(const X of ir){const gt=zr.at(-1);gt&&!X.scribble&&!gt[0].scribble&&gt.length<3&&X.at-gt[0].at<jt.photo.group?gt.push(X):zr.push([X])}if(zr.forEach((X,gt)=>{const bt=X[0].at,St=Lt(Math.min(m,X.at(-1).at+jt.photo.dur,(zr[gt+1]?.[0].at??1/0)-.15));if(St-bt<jt.photo.min||Uo([...H,...Z],bt,St))return;let Rt=Q((bt+St)/2),Dt=!1;const Ft=X.length,Xt=jt.photo.size[Ft-1]*a,Zt=Math.min(Xt,Rt.w*r/Ft*.86);(Zt<jt.photo.minSize*a||X[0].scribble&&Rt.w<.22)&&(Dt=!0,Rt={side:"right",x0:.15,w:.7}),Dt&&nt(bt,Lt(St-bt)),X.forEach((te,se)=>{const ce=te.m,Ut=ce.width||1e3,oe=ce.height||1e3,ae=Rt.x0+Rt.w*(se+.5)/Ft,kr=(k?.36:.42)+(Ft>1?se%2?.05:-.03:0),go=jt.photo.rot[se%3]*(Rt.side==="left"?-1:1),un=Lt(St-te.at);if(!(un<1))if(te.scribble){const Pr=Math.min(a*(k?.36:.5),Rt.w*r*.9*oe/Ut),xr=ki(Ut,oe,Pr/oe,go,r,a),Aa=Pr*Ut/oe,Ca=Lt(Math.max(Aa/2/.74,Pr/2/.68)*1.06/C);ct({op:"addElement",materialId:ce.id,start:te.at,duration:un,posX:Lt(ae-.5),posY:Lt(kr-.5),scale:Math.max(.25,xr),anim:{in:"pop",out:"fade",loop:"none"}});const oa=mt();xr<.25&&ct({op:"setKeyframes",clipId:oa,motionKeys:[{time:0,x:Lt(ae-.5),y:Lt(kr-.5),zoom:xr}]}),ct({op:"collageStyle",clipId:oa,sticker:"white",cutout:"person"}),ct({op:"courseStyle",clipId:oa,rotation:go}),ct({op:"addMotion",motionPreset:"course-photo-pop",start:te.at,duration:un,placement:"center",params:{tile:0,scribble:1,posX:Lt(ae),posY:Lt(kr),size:Ca,rot:go,text:""}})}else{const Pr=Math.min(Ut,oe),xr=Dt?Xt:Zt,Aa=ki(Pr,Pr,xr/Pr,go,r,a);ct({op:"addElement",materialId:ce.id,start:te.at,duration:un,posX:Lt(ae-.5),posY:Lt(kr-.5),scale:Math.max(.25,Aa),anim:{in:"pop",out:"fade",loop:"none"}});const Ca=mt();Aa<.25&&ct({op:"setKeyframes",clipId:Ca,motionKeys:[{time:0,x:Lt(ae-.5),y:Lt(kr-.5),zoom:Aa}]}),ct({op:"courseStyle",clipId:Ca,crop:$0(Ut,oe),rotation:go,shadow:!0}),ct({op:"addMotion",motionPreset:"course-photo-pop",start:te.at,duration:un,placement:"center",params:{tile:1,scribble:0,posX:Lt(ae),posY:Lt(kr),size:Lt(xr/C),rot:go,text:""}})}}),Z.push([bt,St]),ot.push([bt,St])}),u.cover){const X=u.cover,gt=j(X.materialId,"cover.materialId"),bt=A(X.at,"cover"),St=Lt(Math.min(m-bt,Number.isFinite(+X.duration)?Zo(+X.duration,jt.cover.min,to.maxDuration):jt.cover.dur));if(St>=jt.cover.min&&!Uo([...H,...Z],bt,bt+St)){let Rt=Q(bt+St/2);const Dt=gt.width||800,Ft=gt.height||1200;let Xt=Math.min(a*(k?.4:jt.cover.size),Rt.w*r*.85*Ft/Dt);Xt<a*.28&&(Rt={side:"right",x0:.2,w:.6},nt(bt,St),Xt=a*jt.cover.size);const Zt=Rt.x0+Rt.w/2,te=k?.36:.46,se=Rt.side==="right"?-jt.cover.rot:jt.cover.rot,ce=ki(Dt,Ft,Xt/Ft,se,r,a);ct({op:"addElement",materialId:gt.id,start:bt,duration:St,posX:Lt(Zt-.5),posY:Lt(te-.5),scale:Math.max(.25,ce),anim:{in:"pop",out:"fade",loop:"none"}});const Ut=mt();ce<.25&&ct({op:"setKeyframes",clipId:Ut,motionKeys:[{time:0,x:Lt(Zt-.5),y:Lt(te-.5),zoom:ce}]}),ct({op:"courseStyle",clipId:Ut,rotation:se,shadow:!0}),ct({op:"addMotion",motionPreset:"course-cover-insert",start:bt,duration:St,placement:"center",params:{cover:1,text:"",sub:ke(X.title,28),posX:Lt(Zt),posY:te,size:Lt(Xt/a),aspect:Lt(Dt/Ft),rot:se}}),Z.push([bt,bt+St]),ot.push([bt,bt+St])}}const Ur=X=>w(X).x>=.5?"left":"right";for(const X of J){const gt=Lt(Math.min(X.duration,m-X.at));if(gt<jt.tool.min||Uo([...H,...Z],X.at,X.at+gt))continue;const bt=w(X.at+gt/2),St=Ur(X.at+gt/2),Rt=k?bt.y-Ie.head>.19?`top-${St}`:`bottom-${St}`:St;ct({op:"addMotion",motionPreset:"course-tool-badge",start:X.at,duration:gt,text:X.label,...X.url?{subText:X.url}:{},icon:X.icon,params:{position:Rt,...k?{}:{posY:Lt(Zo(bt.y-.02,.2,.6))}}})}N.forEach((X,gt)=>{if(!X.takeaways.length)return;const bt=N[gt+1]?.at??m,St=Lt(Math.max(X.at+1,bt-jt.takeaway-.2)),Rt=Lt(Math.min(jt.takeaway,bt-.1-St));if(Rt<2||Uo([...H,...Z],St,St+Rt))return;const Dt=w(St+Rt/2),Ft=Ie.halfWidth.landscape,Xt=.93-(Dt.x+Ft)-.02,Zt=Dt.x-Ft-.07-.02,te=Math.min(.34,Math.max(Xt,Zt)),se={op:"addMotion",motionPreset:"course-key-takeaway",start:St,duration:Rt,text:st.take,items:X.takeaways};if(k){ct({...se,params:{position:"lower"}});return}if(te>=.26){ct({...se,params:{position:Xt>=Zt?"right":"left",width:Lt(te)}});return}nt(St,Rt),ct({...se,params:{position:"center",width:.5}})});const No=u.labels?u.labels.slice(0,20).map((X,gt)=>{const bt=ke(X?.title,28);if(!bt)throw Error(`labels[${gt}] needs title`);return{at:A(X?.at,`labels[${gt}]`),title:bt,sub:ke(X?.sub,40),icon:Dp(X?.icon)?X.icon:Zi(`${bt} ${X?.sub??""}`)||"flag"}}):vE(E).filter(X=>v(X.at)).map(X=>({at:X.at,title:st.prev,sub:X.sub,icon:"play"}));for(const X of No){const gt=Lt(Math.min(jt.label.dur,m-X.at));if(gt<2||Uo(H,X.at,X.at+gt))continue;const bt=w(X.at+gt/2),St=bt.window||bt.x>=.5?"left":"right",Rt=!Uo([...B,...Z],X.at,X.at+gt)&&!T(X.at+gt/2,.76,.88),Dt=Math.max(C*.085,Math.min(C*.13,r*jt.label.w*.27))/a;ct({op:"addMotion",motionPreset:"course-label-tag",start:X.at,duration:gt,text:X.title,...X.sub?{subText:X.sub}:{},icon:X.icon,params:{position:`${Rt?"lower":"top"}-${St}`,...Rt&&I?{posY:Lt((k?.8:.86)-I-Dt/2)}:{}}})}const ro=k?jt.screen.portrait:jt.screen.landscape;for(const X of K){const gt=y(X.nodeId),bt=gt?.width&&gt?.height?gt.width/gt.height:16/9,St=r/a,Rt=X.fit==="cover",Dt=bt>St!==Rt?r:a*bt,Ft=bt>St!==Rt?r/bt:a,Xt=Lt(Math.min(ro.w*r/Dt,ro.h*a/Ft)),Zt=Lt(Xt*Dt/r),te=Lt(Xt*Ft/a),se=Lt(ro.cy-.5),ce=J.find(Ut=>Ut.url&&Ut.at>=X.start-3&&Ut.at<X.start+X.duration)?.url??"";ct({op:"setKeyframes",clipId:X.id,motionKeys:[{time:0,x:0,y:se,zoom:Xt},{time:Lt(X.duration),x:0,y:se,zoom:Xt}]}),ct({op:"setAnimation",clipId:X.id,property:"enter",preset:"fade",duration:jt.fade}),ct({op:"setAnimation",clipId:X.id,property:"exit",preset:"fade",duration:jt.fade});for(const Ut of Vl(X.start,X.start+X.duration))ct({op:"addMotion",motionPreset:"course-screen-frame",start:Ut.start,duration:Ut.duration,placement:"center",params:{cw:Zt,ch:te,cy:ro.cy,text:ce,fade:Ut.fade,...u.theme?{bg:s.screenBg}:{}}})}if(u.captions===!0&&(y(p.nodeId)?.transcript?.length||p.captions?.length)&&ct({op:"addSocialCaptions",clipId:p.id,captionStyle:"lesson",...u.theme&&u.theme!=="blue"?{color:s.accent}:{}}),u.punchIns!==!1&&E.length){const X=E.map(St=>({start:St.start,end:St.start+.3,word:String(St.words[0].word),kw:St.gap>=.4})),gt=Math.max(0,i-L.length),bt=Hy(X,{every:jt.punch.every,max:Math.min(jt.punch.maxCount,gt),lead:.04,from:f+1});for(const St of bt){const Rt=E.find(Ft=>Math.abs(Ft.start-St.at)<.1)??E.find(Ft=>Ft.start>=St.at),Dt=Lt(Math.min(jt.punch.max,Math.max(.8,(Rt?Rt.end:St.at+2)-St.at)));St.at+Dt>m-.1||Uo([...H,...d,...ot],St.at,St.at+Dt)||!h.some(Ft=>St.at>=Ft.start&&St.at+Dt<=Ft.start+Ft.duration)||ct({op:"punchIn",clipId:p.id,at:Lt(St.at),duration:Dt,numberValue:jt.punch.amount,punchStyle:"cut",accent:!1})}}const So=u.brand===!0?j1(c):null;if(So){const X=w(f+g/2),gt=Ie.halfWidth[k?"portrait":"landscape"]??Ie.halfWidth.landscape,[bt,St]=jt.brand.margin,Rt=X.x+gt>1-bt-jt.brand.maxW&&X.y-Ie.head<St+jt.brand.h+.02,Dt=So.logoMaterialId?y(So.logoMaterialId):null;if(Dt?.kind==="image"&&Dt.url){const Ft=Dt.width||600,Xt=Dt.height||600,Zt=Math.min(jt.brand.h*a/Xt,jt.brand.maxW*r/Ft),te=ki(Ft,Xt,Zt,0,r,a),se=Rt?bt+Ft*Zt/r/2:1-bt-Ft*Zt/r/2,ce=St+Xt*Zt/a/2;ct({op:"addElement",materialId:Dt.id,start:f,duration:It(m-f),posX:Lt(se-.5),posY:Lt(ce-.5),scale:Math.max(.25,te),anim:{in:"fade",out:"fade",loop:"none"}});const Ut=mt();te<.25&&ct({op:"setKeyframes",clipId:Ut,motionKeys:[{time:0,x:Lt(se-.5),y:Lt(ce-.5),zoom:te}]})}else if(So.name)for(const Ft of Vl(f,m))ct({op:"addMotion",motionPreset:"course-brand-bug",start:Ft.start,duration:Ft.duration,placement:"top",text:ke(So.name,40),params:{fade:Ft.fade,position:Rt?"top-left":"top-right"}})}for(const X of L)X.op==="addMotion"&&(X.color||(X.color=s.accent),s.look&&(X.params={...X.params,look:s.look}));return L.length>i?L.filter(X=>X.op!=="punchIn").slice(0,i):L}function LE(t,{clips:e=[],materials:o=[],W:r=1280,H:a=720,en:n=null,maxOps:i=1/0,simulate:c=null,brand:u=null}={}){if(!Array.isArray(t)||!t.some(m=>m?.op==="courseEdit"&&!m.error))return t;const p=[],s=[];let h=0;const f=m=>{const g=typeof m=="string"&&/^new:(\d+)$/.exec(m);if(!g)return m;const v=+g[1];let x=0;for(const E of s)v>E.after&&(x+=E.by);return`new:${v+x}`};for(const m of t){const g=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(g?.op!=="courseEdit"||g.error){p.push(g),gc.has(g?.op)&&h++;continue}let v=e;if(c&&p.some(x=>["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"].includes(x?.op)))try{v=c([...p])??e}catch{v=e}try{const x=PE({clips:v,materials:o,op:g,W:r,H:a,en:n,maxOps:Math.max(1,i-t.length),brand:u}),E=x.filter(k=>gc.has(k.op)).length,$=p.filter(k=>gc.has(k?.op)).length,S=k=>{const y=typeof k=="string"&&/^new:(\d+)$/.exec(k);return y?`new:${+y[1]+$}`:k};p.push(...x.map(k=>typeof k.clipId=="string"?{...k,clipId:S(k.clipId)}:k)),E&&s.push({after:h,by:E})}catch(x){p.push({op:"courseEdit",error:String(x?.message||x).slice(0,300)})}}return p}const Hn=(t,e,o)=>Math.max(e,Math.min(o,t)),gr=t=>+(+t).toFixed(4),Wa=t=>+(+t).toFixed(3),FE=new Function("return "+d1)(),Ih=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]}),NE=Object.fromEntries(Object.entries(Ih).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;"+Qw(o)+"const "+t2[e]+",r="+e2+";return {x:wx,y:wy,w:ww,h:wh,r:Math.min(r,ww/2,wh/2)}")]));function op(t,e,o){const r=NE[t];return r?r(FE,{width:e,height:o}):null}const E0=(t,e,o)=>({x:gr(t.x/e),y:gr(t.y/o),w:gr(t.w/e),h:gr(t.h/o),r:gr(t.r/Math.min(e,o))});Object.freeze(Object.fromEntries(Object.keys(Ih).map(t=>[t,Object.freeze({landscape:E0(op(t,1920,1080),1920,1080),portrait:E0(op(t,1080,1920),1080,1920)})])));const S0=Object.freeze(["full","center","left","right","small","corner"]),ho=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}})}),qy=(t,e)=>e>t*1.1;function Zy(t,e,o){const r=qy(e,o),a=Math.min(e,o);if(t==="full")return{x:0,y:0,w:e,h:o,r:0};if(ho.scenes[t])return op(ho.scenes[t][r?1:0],e,o);if(t==="corner"){const n=a*.028;if(r){const s=ho.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:n}}const i=ho.corner.landscape,c=e*i.w,u=c*o/e,p=i.margin*a;return{x:e-p-c,y:o-p-u,w:c,h:u,r:n}}if(typeof t=="string"&&/^fr-/.test(t)){const n=op(t,e,o);if(n)return n;throw Error(`${t.slice(0,40)} has no speaker window — use ${S0.join(" / ")} or a window scene (${Object.keys(Ih).filter(i=>!i.startsWith("fr-v-")).join(", ")})`)}throw Error(`layout must be ${S0.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 RE=t=>t!=="full",DE=t=>1-Math.pow(1-t,3),xi=(t,e,o)=>t+(e-t)*o;function BE(t,e){const o=Array.isArray(t?.scenes)?t.scenes:[],r=o.find(a=>a.start<=e&&a.end>e&&Number.isFinite(a.subjectX))||o.find(a=>Number.isFinite(a.subjectX));return r?{x:Hn(r.subjectX,0,1),y:Number.isFinite(r.subjectY)?Hn(r.subjectY,0,1):.42}:null}function Jy(t,{W:e,H:o,morph:r=ho.morph}={}){if(!Array.isArray(t)||!t.length)throw Error("needs beats [{start, end, layout}]");if(t.length>ho.maxBeats)throw Error(`at most ${ho.maxBeats} beats`);const a=Number.isFinite(+r)?Hn(+r,0,ho.maxMorph):ho.morph,n=t.map((i,c)=>{if(!i||typeof i!="object")throw Error(`beats[${c}] must be an object`);const u=+i.start,p=+i.end;if(!Number.isFinite(u)||!Number.isFinite(p)||u<0)throw Error(`beats[${c}] needs start and end (timeline s)`);if(p-u<ho.minBeat)throw Error(`beats[${c}]: end must be at least ${ho.minBeat} s after start`);if(i.zoom!=null&&!(Number.isFinite(+i.zoom)&&+i.zoom>=1&&+i.zoom<=ho.zoomMax))throw Error(`beats[${c}].zoom must be 1–${ho.zoomMax}`);if(i.morph!=null&&!(Number.isFinite(+i.morph)&&+i.morph>=0&&+i.morph<=ho.maxMorph))throw Error(`beats[${c}].morph must be 0–${ho.maxMorph} s`);let s;try{s=Zy(i.layout??"full",e,o)}catch(h){throw Error(`beats[${c}]: ${h.message}`)}return{i:c,start:ut(u),end:ut(p),layout:i.layout??"full",rect:s,zoom:i.zoom!=null?+i.zoom:1,morph:i.morph!=null?+i.morph:a}}).sort((i,c)=>i.start-c.start);for(let i=1;i<n.length;i++)if(n[i].start<n[i-1].end-1e-6)throw Error(`beats[${n[i].i}] overlaps beats[${n[i-1].i}] — one layout at a time`);return n}function _E(t,e,o,r){const a={rect:{x:0,y:0,w:o,h:r,r:0},zoom:1};let n=-1;for(let f=0;f<t.length;f++)t[f].start<=e+1e-9&&(n=f);if(n<0)return a;const i=t[n],c=n>0?t[n-1]:a,u=Math.min(i.morph,(i.end-i.start)*.6);if(u<=1e-6||e>=i.start+u)return i;const p=DE(Hn((e-i.start)/u,0,1)),s=c.rect,h=i.rect;return{rect:{x:xi(s.x,h.x,p),y:xi(s.y,h.y,p),w:xi(s.w,h.w,p),h:xi(s.h,h.h,p),r:xi(s.r,h.r,p)},zoom:xi(c.zoom,i.zoom,p)}}function VE(t,e,o){const r=[];let a={rect:{x:0,y:0,w:e,h:o},zoom:1};for(const n of t){const i=Math.min(n.morph,(n.end-n.start)*.6),c=a.rect,u=n.rect;(Math.abs(c.x-u.x)+Math.abs(c.y-u.y)+Math.abs(c.w-u.w)+Math.abs(c.h-u.h)>.5||Math.abs(a.zoom-n.zoom)>.001)&&r.push(i>1e-6?[n.start,n.start+i]:[n.start,n.start]),a=n}return r}function GE(t,{rect:e,zoom:o},{W:r,H:a,mw:n,mh:i,face:c}){const u=t.fit==="cover"?Math.max(r/n,a/i):Math.min(r/n,a/i),p=n*u,s=i*u,h=e.w/e.h;let f=h<=n/i?i:n/h,m=f*h;f/=o,m/=o;const g=c?.x??.5,v=c?.y??(n<=i?.36:.42),x=Hn(g*n,m/2,n-m/2),E=Hn(v*i+f*.08,f/2,i-f/2),$=e.w/(m*u),S=t.flipX?-1:1,k=t.flipY?-1:1,y=(e.x+e.w/2-r/2-S*$*(x/n-.5)*p)/r,C=(e.y+e.h/2-a/2-k*$*(E/i-.5)*s)/a,A=1/($*u),z=.02*Math.min(r,a)*A,j=e.x<=.5?z:0,P=e.y<=.5?z:0,F=e.x+e.w>=r-.5?z:0,N=e.y+e.h>=a-.5?z:0,G=(x-m/2-j)/n,V=(x+m/2+F)/n,et=(E-f/2-P)/i,U=(E+f/2+N)/i,at=Math.min(e.r*A,m/2,f/2),W=at/n,_=at/i,J=.5523*W,tt=.5523*_,rt=pt=>gr(Hn(pt,-1,2)),D=pt=>gr(Hn(pt,-1,1)),q=[[G+W,et,-J,0,0,0],[V-W,et,0,0,J,0],[V,et+_,0,-tt,0,0],[V,U-_,0,0,0,tt],[V-W,U,J,0,0,0],[G+W,U,0,0,-J,0],[G,U-_,0,tt,0,0],[G,et+_,0,0,0,-tt]].map(pt=>[rt(pt[0]),rt(pt[1]),D(pt[2]),D(pt[3]),D(pt[4]),D(pt[5])]);return{x:gr(y),y:gr(C),zoom:gr($),pts:q}}function KE(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,a)=>r.start-a.start)}function WE(t,e,{beats:o,morph:r,W:a=1280,H:n=720,material:i=null}={}){const c=KE(t,e),u=Jy(o,{W:a,H:n,morph:r}),p=c[0].start,s=c.at(-1).start+c.at(-1).duration;if(u[0].start>=s-1e-6||u.at(-1).end<=p+1e-6)throw Error("beats must fall inside the speaker clip");const h=Math.round(i?.width)||(a<=n?1080:1920),f=Math.round(i?.height)||(a<=n?1920:1080),m=VE(u,a,n),g=new Map;for(const v of c){const x=v.start,E=v.start+v.duration,$=m.filter(([P,F])=>F>x-1e-6&&P<E+1e-6);if(!(u.some(P=>P.start<E&&P.end>x)||$.length||u[0].start<E))continue;const S=Hn(Math.floor((ho.keysMax-2)/Math.max(1,$.length*2))-1,2,8),k=new Set([0,Wa(v.duration)]);for(const[P,F]of $){if(P-x>1/30&&k.add(Wa(P-x)),F>P)for(let N=0;N<=S;N++){const G=P+(F-P)*N/S;G>x&&G<E&&k.add(Wa(G-x))}F-x<v.duration&&k.add(Wa(Math.max(0,F-x))),F<=P&&P-x>1/30&&k.add(Wa(Math.max(0,P-x-1/30)))}const y=v.playbackRate||1,C=P=>(v.inPoint||0)+P*y,z=[...k].filter(P=>P>=0&&P<=v.duration+1e-6).sort((P,F)=>P-F).map(P=>{const F=_E(u,v.start+P,a,n);return{t:P,...GE(v,F,{W:a,H:n,mw:h,mh:f,face:BE(i,C(P))})}});let j={...v,...pn(v)};for(const P of["sx","sy","ax","ay","rot"])Ee(j,P).length&&(j={...j,motionKeys:br(j,P,[])});for(const P of["x","y","zoom"])j={...j,motionKeys:br(j,P,z.map(F=>({time:F.t,value:F[P]})))};if(j.motionKeys.length>o2)throw Error("too many layout changes on one clip — fewer beats or a shorter morph");j.posX=z[0].x,j.posY=z[0].y,j.scale=z[0].zoom,j.mask={v:2,mw:h,mh:f,masks:[{id:"m1",name:"Khung người nói",mode:"add",feather:ho.maskFeather,smooth:!1,keys:HE(z.map(P=>({t:Wa(Math.min(P.t,v.duration)),pts:P.pts})))}]},j.speakerLayout={beats:u.filter(P=>P.start<E&&P.end>x).length,v:1};for(const P of["crop","rotation","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","pin","layout","person","roto","planar","bubble"])delete j[P];g.set(v.id,j)}if(!g.size)throw Error("beats must fall inside the speaker clip");return{clips:t.map(v=>g.get(v.id)??v),pieces:g.size}}function HE(t){const e=(o,r)=>o.pts.every((a,n)=>a.every((i,c)=>i===r.pts[n][c]));return t.filter((o,r)=>!(r>0&&r<t.length-1&&e(o,t[r-1])&&e(o,t[r+1])))}const XE=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),Ah=(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,a])=>!["op","prompt"].includes(r)&&a!==null&&a!==void 0))}},UE=/^#[0-9a-f]{6}$/i;function YE(t,e,{W:o,H:r}){const a=qy(o,r),n=[],i=UE.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 c of e){const u=t.beats[c.i],p=u.motion,s=Wa(Math.min(c.end-c.start,to.maxDuration));if(p!=null){if(typeof p!="object"||Array.isArray(p))throw Error(`beats[${c.i}].motion must be an object`);const h=p.preset??p.motionPreset??(typeof c.layout=="string"&&c.layout.startsWith("fr-")?c.layout:null);if(!h)throw Error(`beats[${c.i}].motion needs preset (a layout like "${c.layout}" names no scene)`);const{preset:f,motionPreset:m,...g}=p;n.push({op:"addMotion",motionPreset:h,start:c.start,duration:s,...g,...i&&!g.color?{color:i}:{}})}else if(t.frame==="brackets"&&RE(c.layout)){const h=c.rect;n.push({op:"addMotion",motionPreset:a?"fr-v-window":"fr-window",start:c.start,duration:s,...i?{color:i}:{},params:{bg:!1,text:typeof u.label=="string"?u.label.slice(0,40):"",sub:"",wx:gr(h.x/o),wy:gr(h.y/r),ww:gr(h.w/o),wh:gr(h.h/r)}})}}return n}function qE(t,{W:e=1280,H:o=720}={}){if(!Array.isArray(t)||!t.some(c=>c?.op==="speakerLayout"&&!c.error))return t;const r=[],a=[];let n=0;const i=c=>{const u=typeof c=="string"&&/^new:(\d+)$/.exec(c);if(!u)return c;const p=+u[1];let s=0;for(const h of a)p>h.after&&(s+=h.by);return`new:${p+s}`};for(const c of t){const u=c&&typeof c=="object"?{...c,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(p=>typeof c[p]=="string").map(p=>[p,i(c[p])])),...Array.isArray(c.clipIds)?{clipIds:c.clipIds.map(i)}:{}}:c;if(u?.op!=="speakerLayout"||u.error){r.push(u),XE.has(u?.op)&&n++;continue}try{const p=Ah(u,"speakerLayout");if(p.frame!=null&&p.frame!=="brackets"&&p.frame!=="none")throw Error("frame must be brackets or none");if(!(p.frame==="brackets"||Array.isArray(p.beats)&&p.beats.some(E=>E&&E.motion!=null))){r.push(u);continue}const h=Jy(p.beats,{W:e,H:o,morph:p.morph}),f=YE(p,h,{W:e,H:o}),{frame:m,accent:g,prompt:v,...x}=p;r.push({...x,op:"speakerLayout",beats:p.beats.map(E=>{const{motion:$,label:S,...k}=E;return k})},...f),f.length&&a.push({after:n,by:f.length})}catch(p){r.push({op:"speakerLayout",error:String(p?.message||p).slice(0,300)})}}return r}const bo=t=>+(+t).toFixed(3),I0=(t,e,o)=>Math.max(e,Math.min(o,t)),rp=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}*/]+/gu,"").trim(),wn=(t,e)=>typeof t=="string"?t.replace(/\s+/gu," ").trim().slice(0,e):"",ZE=/^#[0-9a-f]{6}$/i,yc=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"}}),JE=Object.freeze(Object.keys(yc)),co=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 QE(t,e,o=0){const r=String(e??"").split(/\s+/u).map(rp).filter(Boolean);if(!r.length)return null;const a=t.map(u=>rp(u.word)),n=(u,p)=>u===p||p.length>2&&u.startsWith(p)||u.length>2&&p.startsWith(u),i=u=>{for(let p=u;p<=a.length-r.length;p++)if(r.every((s,h)=>n(a[p+h],s)))return[p,p+r.length-1];return null},c=i(o)??i(0);if(c)return c;for(const u of[o,0])for(let p=u;p<a.length;p++)if(n(a[p],r[0])){for(let s=p+1;s<Math.min(a.length,p+r.length+3);s++)if(n(a[s],r.at(-1)))return[p,s]}return null}function Qy(t,e,o,r){const a=e.filter(p=>p.start>=o-.1&&p.start<r),n=t.map(p=>{const s=String(p),h=s.indexOf(":");return rp((h>0&&!/\s/.test(s.slice(0,h))?s.slice(h+1):s).split(/\s+/u)[0])});let i=0;const c=n.map(p=>{for(let s=i;s<a.length;s++){const h=rp(a[s].word);if(p&&(h===p||p.length>2&&h.startsWith(p)||h.length>2&&p.startsWith(h)))return i=s+1,bo(Math.max(0,a[s].start-o))}return null});if(c.every(p=>p===null))return null;for(let p=0;p<c.length;p++)if(c[p]===null){let s=p-1;for(;s>=0&&c[s]===null;)s--;let h=p+1;for(;h<c.length&&c[h]===null;)h++;const f=s>=0?c[s]:null,m=h<c.length?c[h]:null;c[p]=bo(f!==null&&m!==null?f+(m-f)*(p-s)/(h-s):f!==null?f+.4*(p-s):Math.max(0,m-.4*(h-p)))}let u=0;return c.map(p=>{const s=bo(Math.max(u,p));return u=s+.05,s})}const tS=t=>String(t??"").split("/").flatMap(e=>e.split(" ").filter(Boolean)).map(e=>e.replace(/[*]/g,"")).filter(Boolean);function A0(t,e,o,r,a=0){const n=Qy(tS(t),e,o,r);if(!n)return null;let i=0;return n.map(c=>{const u=bo(Math.max(a,i,c));return i=u+.05,u})}const eS=["label","caret","total","position","times"];function oS(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=wn(String(t.text),120));const o=t.sub??t.subText;o!=null&&(e.subText=wn(String(o),160)),Array.isArray(t.items)&&(e.items=t.items.filter(n=>typeof n=="string").map(n=>wn(n,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 a=Object.fromEntries(eS.filter(n=>t[n]!=null&&["string","number","boolean"].includes(typeof t[n])).map(n=>[n,typeof t[n]=="string"?t[n].slice(0,120):t[n]]));return Object.keys(a).length&&(e.params=a),e}function rS({clips:t=[],materials:e=[],op:o={},W:r=1280,H:a=720}={}){const n=Ah(o),i=t.find(j=>j.id===n.clipId);if(!i||i.kind!=="video"||i.motion||i.title||i.shape)throw Error("clipId must be the speaker video on the timeline");if(n.aspect!=null&&!["16:9","9:16"].includes(n.aspect))throw Error("aspect must be 16:9 or 9:16");if(n.accent!=null&&!ZE.test(String(n.accent)))throw Error("accent must be #RRGGBB");if(n.flavor!=null&&!["creator","course"].includes(n.flavor))throw Error("flavor must be creator or course");if(!Array.isArray(n.beats)||!n.beats.length)throw Error("needs beats [{kind, say | start, end?, fields?}]");if(n.beats.length>co.maxBeats)throw Error(`at most ${co.maxBeats} beats`);const c=n.aspect?n.aspect==="9:16":a>r*1.1,u=j=>j&&c?j.replace(/^fr-/,"fr-v-"):j,p=n.accent?String(n.accent).toLowerCase():co.accent,s=t.filter(j=>j.id===i.id||i.nodeId&&j.nodeId===i.nodeId&&j.track===i.track&&j.kind===i.kind&&!j.bubble).sort((j,P)=>j.start-P.start),h=s[0].start,f=s.at(-1).start+s.at(-1).duration,m=Sh(t,i.id,e);let g=0;const v=n.beats.map((j,P)=>{if(!j||typeof j!="object")throw Error(`beats[${P}] must be an object`);if(!yc[j.kind])throw Error(`beats[${P}].kind must be ${JE.join(" / ")}`);let F=j.start!=null?+j.start:null,N=null;if(j.start!=null&&!Number.isFinite(F))throw Error(`beats[${P}].start must be timeline seconds`);if(j.say!=null){if(!m.length)throw Error(`beats[${P}].say needs the speaker's transcript (transcribe the clip first) — or give start / end`);const V=QE(m,j.say,g);if(!V)throw Error(`beats[${P}].say "${wn(String(j.say),60)}" is not in the transcript`);N={start:m[V[0]].start,end:m[V[1]].end,first:V[0]},g=V[1]+1,F===null&&(F=Math.max(h,N.start-co.lead))}if(F===null)throw Error(`beats[${P}] needs say (a phrase of the transcript) or start`);if(j.end!=null&&!Number.isFinite(+j.end))throw Error(`beats[${P}].end must be timeline seconds`);let G;try{G=oS(j.fields)}catch(V){throw Error(`beats[${P}].${V.message}`)}return{i:P,kind:j.kind,start:bo(I0(F,h,f)),end:j.end!=null?+j.end:null,said:N,fields:G}}).sort((j,P)=>j.start-P.start);if(v[0].start-h<co.snap&&(v[0].start=bo(h)),n.flavor==="course"&&n.instructor&&typeof n.instructor=="object"&&wn(n.instructor.name,60)&&!v.some(j=>j.kind==="lowerThird")){const j=h+.3,P=Math.min(h+.3+co.lower.dur,v[0].start);P-j>=co.lower.min&&v.unshift({i:-1,kind:"lowerThird",start:bo(j),end:bo(P),said:null,fields:{text:wn(n.instructor.name,60),...wn(n.instructor.role,80)?{subText:wn(n.instructor.role,80)}:{},...wn(n.instructor.label,24)?{params:{label:wn(n.instructor.label,24)}}:{}}})}const x=v.map((j,P)=>{const F=v[P+1],N=F?F.start:f;let G=j.end!==null?Math.min(j.end,N):F?F.start:Math.min(f,(j.said?.end??j.start+3)+co.tail);if(G=bo(Math.min(G,f)),G-j.start<co.minBeat-1e-6)throw Error(`beats[${j.i}] (${j.kind}) is too short (${bo(G-j.start)} s) — the next beat starts right after it`);return{...j,end:G}});v.at(-1).end===null&&f-x.at(-1).end<co.closeGap&&(x.at(-1).end=bo(f));let E=null;const $=x.map(j=>{const P=yc[j.kind],F=P.sit==="window"?u(P.scene):P.sit==="cover"?E??u("fr-window"):"full";return E=F,F}),S=$.map(j=>Zy(j,r,a)),k=(j,P)=>{if(!j||!P)return!1;const F=N=>N.w>=r-1&&N.h>=a-1;return F(j)!==F(P)?!0:Math.hypot((j.x+j.w/2-P.x-P.w/2)/r,(j.y+j.h/2-P.y-P.h/2)/a)>co.jump},y=n.whip!==!1,C=[],A=[],z=x.map((j,P)=>{const F=P>0&&k(S[P-1],S[P])&&$[P]!==$[P-1];return F&&y&&A.push(bo(Math.max(0,j.start-.05))),{start:j.start,end:j.end,layout:$[P],...F&&y?{morph:co.whipMorph}:{}}});if(C.push({op:"speakerLayout",clipId:i.id,beats:z,morph:Number.isFinite(+n.morph)?I0(+n.morph,0,ho.maxMorph):ho.morph}),n.backdrop!==!1){const j=x[0].start,P=x.at(-1).end;let F=0;for(let N=j;N<P-.001;N+=to.maxDuration){const G=bo(Math.min(to.maxDuration,P-N));C.push({op:"addMotion",motionPreset:co.backdrop[c?1:0],start:bo(N),duration:G,params:{offset:bo(N-j)}}),F++}for(let N=1;N<=F;N++)C.push({op:"setLayerOrder",clipId:`new:${N}`,numberValue:-1})}for(const j of x){const P=yc[j.kind];if(!P.scene)continue;const F={...j.fields,params:{...j.fields.params??{}}};if(j.kind==="chips"&&F.items?.length&&F.params.times==null){const N=Qy(F.items,m,j.start,j.end);N&&(F.params.times=N.join(","))}if(j.kind==="headline"&&F.text&&F.params.times==null){const N=A0(F.text,m,j.start,j.end);N&&(F.params.times=N.join(","))}if(j.kind==="question"&&F.subText&&F.params.times==null){const N=A0(F.subText,m,j.start,j.end,co.replyFrom);N&&(F.params.times=N.join(","))}Object.keys(F.params).length||delete F.params,C.push({op:"addMotion",motionPreset:u(P.scene),start:j.start,duration:bo(Math.min(j.end-j.start,to.maxDuration)),color:p,...F})}if(n.punch!==!1){for(const j of x)if(j.kind==="full"&&j.end-j.start>=co.punch.min){const P=bo(Math.max(j.start,j.said?j.said.start:j.start+.1)),F=bo(Math.min(co.punch.max,j.end-P-.25));F>=.4&&C.push({op:"punchIn",clipId:i.id,at:P,duration:F,numberValue:co.punch.amount,punchStyle:"smooth"})}}for(const j of A)C.push({op:"addSfx",sfxId:co.whipSfx,at:j,volume:co.whipVolume});return C}const Mu=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),nS=["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"];function aS(t,{clips:e=[],materials:o=[],W:r=1280,H:a=720,maxOps:n=1/0,simulate:i=null}={}){if(!Array.isArray(t)||!t.some(h=>h?.op==="framedEdit"&&!h.error))return t;const c=[],u=[];let p=0;const s=h=>{const f=typeof h=="string"&&/^new:(\d+)$/.exec(h);if(!f)return h;const m=+f[1];let g=0;for(const v of u)m>v.after&&(g+=v.by);return`new:${m+g}`};for(const h of t){const f=h&&typeof h=="object"?{...h,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(g=>typeof h[g]=="string").map(g=>[g,s(h[g])])),...Array.isArray(h.clipIds)?{clipIds:h.clipIds.map(s)}:{}}:h;if(f?.op!=="framedEdit"||f.error){c.push(f),Mu.has(f?.op)&&p++;continue}let m=e;if(i&&c.some(g=>nS.includes(g?.op)))try{m=i([...c])??e}catch{m=e}try{const g=rS({clips:m,materials:o,op:f,W:r,H:a}),v=g.filter($=>Mu.has($.op)).length;if(c.length+g.length>n)throw Error(`makes ${g.length} ops — over the plan's ${n}; fewer beats`);const x=c.filter($=>Mu.has($?.op)).length,E=$=>{const S=typeof $=="string"&&/^new:(\d+)$/.exec($);return S?`new:${+S[1]+x}`:$};c.push(...g.map($=>typeof $.clipId=="string"?{...$,clipId:E($.clipId)}:$)),v&&u.push({after:p,by:v})}catch(g){c.push({op:"framedEdit",error:String(g?.message||g).slice(0,300)})}}return c}const Oe=Object.freeze({shot:1.8,minShot:1.5,maxShot:2,hook:2.6,phone:2.4,minPiece:.8,maxShots:15,endcard:{def:5,min:4,max:6},phones:2,cards:2,mascots:[3,4],words:2,grade:{warm:.25,fade:.12},ui:{scale:.22},card:{w:380,h:128},round:.1,wordAside:.27,portraitBands:{lower:[.58,.86],top:[.06,.4]}}),je=t=>+(+t).toFixed(3),Ni=(t,e,o)=>Math.max(e,Math.min(o,t)),Fa=(t,e)=>typeof t=="string"?t.replace(/\s+/gu," ").trim().slice(0,e):"",C0=/^#[0-9a-f]{6}$/i,vu=t=>String(t).replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]),iS=/(điện thoại|smartphone|(?<![\p{L}])phone|iphone|cầm máy|màn hình (điện thoại|app|ứng dụng)|ứng dụng|(?<![\p{L}])app(?![\p{L}])|nhắn tin|texting|scroll|lướt|bấm|chạm)/iu,sS=/(bàn|desk|table|ghế|sofa|seat|xe|(?<![\p{L}])car(?![\p{L}])|vai|shoulder|sàn|floor|quầy|counter|kệ|shelf|giường|bed)/iu,lS=/(người|anh|chị|cô|chú|bạn|nhân viên|khách|man|woman|person|girl|boy|people|guy|lady)/iu,cS=/(ui|app|ứng dụng|màn hình|screen|screenshot|giao diện|mockup)/iu,pS=/(logo|brand|thương hiệu)/iu,bc=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","addDevice","addMap"]),uS=["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"],dS=t=>{try{const e=typeof t=="string"?JSON.parse(t||"{}"):t;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{throw Error("appAdEdit prompt must be the options as JSON")}},j0=t=>t&&typeof t=="object"&&[t.x,t.y,t.w,t.h].every(Number.isFinite)&&t.x>=0&&t.y>=0&&t.w>=.02&&t.h>=.02&&t.x+t.w<=1+1e-6&&t.y+t.h<=1+1e-6?{x:je(t.x),y:je(t.y),w:je(t.w),h:je(t.h)}:null;function T0(t,e){const o=+t.inPoint||0,r=o+t.duration,a=(Array.isArray(e?.scenes)?e.scenes:[]).map(n=>({a:Math.max(o,+n.start),b:Math.min(r,+n.end),desc:String(n.description||""),subjectX:n.subjectX,subjectY:n.subjectY,subjectH:n.subjectH,people:n.people})).filter(n=>Number.isFinite(n.a)&&Number.isFinite(n.b)&&n.b-n.a>=Oe.minPiece);return a.length?a:[{a:o,b:r,desc:"",analysed:!1}]}const $u=t=>({phone:iS.test(t.desc),surface:sS.test(t.desc),person:Number.isFinite(t.people)&&t.people>0||lS.test(t.desc)});function hS({clips:t=[],materials:e=[],pacing:o=!0,shot:r=Oe.shot,maxShots:a=Oe.maxShots}={}){const n=t.filter(g=>g.kind==="video"&&!g.motion&&!g.vfx&&!g.vfxFootage&&!g.vfxPreset&&!g.mask&&!g.bubble);if(!n.length)throw Error("appAdEdit needs the raw footage on the timeline (video clips)");const i=n.map(g=>g.track).sort((g,v)=>xn(g)-xn(v))[0],c=n.filter(g=>g.track===i).sort((g,v)=>g.start-v.start),u=c[0].start;if(!o)return{track:i,T0:u,shots:c.map(g=>{const v=e.find($=>$.id===g.nodeId),x=T0(g,v),E=x.find($=>$u($).phone)??x[0];return{clipId:g.id,orig:!0,materialId:g.nodeId,inPoint:+g.inPoint||0,L:g.duration,t:g.start,scene:E,tags:$u(E),keep:!0}}),end:c.at(-1).start+c.at(-1).duration};const p=Ni(+r||Oe.shot,Oe.minShot,Oe.maxShot);let s=[];const h=g=>(g.phone?4:0)+(g.surface?2:0)+(g.person?1:0);for(const g of c){const v=e.find($=>$.id===g.nodeId),x=T0(g,v).map($=>({s:$,tags:$u($)})),E=x.reduce(($,S,k)=>h(S.tags)>h(x[$].tags)?k:$,0);x.forEach(($,S)=>s.push({c:g,m:v,s:$.s,k:S===E?0:1+S,tags:$.tags}))}if(s.length>a){const g=new Set(s.filter($=>$.k===0)),v=s.filter($=>$.k>0&&$.tags.phone),x=s.filter($=>$.k>0&&!$.tags.phone);for(const $ of v)g.size<a&&g.add($);const E=Math.max(0,a-g.size);for(let $=0;$<E&&x.length;$++)g.add(x[Math.floor($*x.length/E)]);s=s.filter($=>g.has($))}let f=u;const m=s.map((g,v)=>{const x=g.s.b-g.s.a,E=v===0?Oe.hook:g.tags.phone?Oe.phone:p,$=je(Math.min(x,E)),S=je(g.s.a+(x-$)/2),k={clipId:g.k===0?g.c.id:null,orig:g.k===0,materialId:g.c.nodeId,inPoint:S,L:$,t:je(f),scene:g.s,tags:g.tags,sourceDuration:g.m?.duration};return f+=$,k});return{track:i,T0:u,shots:m,end:je(f)}}function fS(t,e){const o=Number.isFinite(t?.subjectX)?t.subjectX:.5,r=Number.isFinite(t?.subjectY)?t.subjectY:null;if(!e)return{placement:"center",x:o>.5?-Oe.wordAside:Oe.wordAside};if(r===null)return{placement:"top",x:0};const a=[r-.14,r+.1],n=c=>c[0]<a[1]&&c[1]>a[0],i=Object.entries(Oe.portraitBands).find(([,c])=>!n(c));return i?{placement:i[0],x:0}:null}function mS({title:t="",sub:e="",amount:o="",color:r="#1fb36b"}={}){const a=[`<div style="display:flex;width:56px;height:56px;border-radius:16px;background:${r};margin-right:18px"></div>`],n=[`<div style="display:flex;font-size:26px;font-weight:800;color:#14171c">${vu(t)}</div>`];return o&&n.push(`<div style="display:flex;font-size:30px;font-weight:800;color:${r}">${vu(o)}</div>`),e&&n.push(`<div style="display:flex;font-size:20px;color:#5b6472">${vu(e)}</div>`),`<div style="display:flex;flex-direction:row;align-items:center;width:100%;height:100%;padding:18px 24px;background:#ffffff;border-radius:28px;box-shadow:0 12px 32px rgba(0,0,0,0.25)">${a.join("")}<div style="display:flex;flex-direction:column">${n.join("")}</div></div>`}function gS({clips:t=[],materials:e=[],copy:o={},brand:r=null,portrait:a=!1,en:n=!1}={}){const i=[],c=[];let u=0;const p=W=>(c.push(W),bc.has(W.op)&&u++,`new:${u}`),s=W=>e.find(_=>_.id===W&&_.url),h=new Set(t.filter(W=>W.kind==="video").map(W=>W.nodeId)),f=(W,_,J)=>{const tt=s(W);return tt&&_.includes(tt.kind)?tt:J?e.find(rt=>rt.url&&_.includes(rt.kind)&&rt.role!=="reference"&&!h.has(rt.id)&&J.test(`${rt.label||""} ${(rt.labels||[]).join(" ")} ${rt.description||""}`)):null},m=C0.test(o.color)?o.color:C0.test(r?.colors?.[0])?r.colors[0]:"#1fb36b",g=Fa(o.app??r?.name??"",40),v=Fa(o.tagline??r?.tagline??"",60),x=f(o.ui,["image","video"],cS),E=f(o.logo,["image"],null)??(r?.logoMaterialId?f(r.logoMaterialId,["image"],null):null)??f(null,["image"],pS),$=f(o.mascot,["model"],null)??e.find(W=>W.url&&W.kind==="model"&&W.role!=="reference")??null,S=hS({clips:t,materials:e,pacing:o.pacing!==!1,shot:o.shot}),{shots:k}=S,y=Math.max(0,...t.filter(W=>W.kind!=="audio").map(W=>xn(W.track))),C=W=>en(y+1+W);if(o.pacing!==!1){for(const W of k)W.orig?(p({op:"trim",clipId:W.clipId,inPoint:W.inPoint,duration:W.L}),p({op:"move",clipId:W.clipId,start:W.t})):(W.ref=p({op:"addClip",materialId:W.materialId,track:S.track,start:W.t,duration:W.L}),p({op:"trim",clipId:W.ref,inPoint:W.inPoint,duration:W.L}));k.some(W=>W.scene.analysed!==!1)||i.push(n?"footage not analysed: one shot per clip, no phone / surface detection (run analyzeFootage first)":"footage chưa phân tích: mỗi clip một shot, không nhận diện được điện thoại / mặt bàn (chạy analyzeFootage trước)")}for(const W of k)W.ref??=W.clipId;if(o.grade!==!1)for(const W of k)p({op:"setEffect",clipId:W.ref,property:"warm",numberValue:Oe.grade.warm}),p({op:"setEffect",clipId:W.ref,property:"fade",numberValue:Oe.grade.fade});const A=new Set,z=W=>k.find(_=>_.orig&&_.clipId===W),j=Array.isArray(o.phones)?o.phones.map(W=>({s:z(W?.clipId),region:j0(W?.region)})).filter(W=>W.s):[],P=(j.length?j:k.filter(W=>W.orig&&W.tags.phone).map(W=>({s:W,region:null}))).slice(0,Oe.phones);P.length?x||i.push(n?'no app UI picture / video in Media: screen replacement skipped (add one named "UI app")':'Media chưa có ảnh / video UI app: bỏ bước thay màn hình (thêm một file tên "UI app")'):i.push(n?"no shot with a phone in hand (from the scene descriptions): screen replacement and fly-out cards skipped":"không có shot cầm điện thoại (theo mô tả cảnh): bỏ bước thay màn hình và thẻ bay ra");const F=(Array.isArray(o.cards)?o.cards:[]).filter(W=>W&&typeof W=="object"&&Fa(W.title,40)).slice(0,Oe.cards);P.length&&!F.length&&i.push(n?"no card copy (cards: [{title, sub?, amount?}]): fly-out cards skipped":"chưa có chữ cho thẻ UI (cards): bỏ thẻ bay ra"),P.forEach(({s:W,region:_},J)=>{A.add(W);const tt=Number.isFinite(W.scene.subjectX)&&W.scene.subjectX>.5?-1:1;if(x)if(_){const D=p({op:"addClip",materialId:x.id,track:C(0),start:W.t,duration:W.L});p({op:"pinToSurface",clipId:D,sourceClipId:W.clipId,at:je(W.t+Math.min(.1,W.L/4)),region:_,mode:"plane",round:Oe.round,booleanValue:!1})}else{const D=x.kind==="image"?p({op:"addElement",materialId:x.id,start:W.t,duration:W.L,posX:0,posY:0,scale:Oe.ui.scale,anim:{in:"fade",out:"none"}}):p({op:"addClip",materialId:x.id,track:C(0),start:W.t,duration:W.L});x.kind!=="image"&&p({op:"setPropertyKeys",clipId:D,property:"zoom",propertyKeys:[{time:0,value:Oe.ui.scale}]}),p({op:"handAttach",clipId:D,sourceClipId:W.clipId,point:"palm",scale:!0}),J===0&&i.push(n?"screen box not given: the app UI follows the hand holding the phone (handAttach); give phones[].region for a corner-pinned screen":"chưa có khung màn hình: UI app bám theo bàn tay cầm máy (handAttach); gửi phones[].region để corner-pin đúng màn hình")}(P.length===1?F:F[J]?[F[J]]:[]).forEach((D,q)=>{const pt=je(W.t+.3+q*.35),yt=je(W.t+W.L-.05-pt);if(yt<.6)return;const Mt=_?(_.x+_.w/2-.5)*2:tt*.05,l=_?(_.y+_.h/2-.5)*2:.25,lt=p({op:"addCard",html:mS({title:Fa(D.title,40),sub:Fa(D.sub,48),amount:Fa(D.amount,24),color:m}),width:Oe.card.w,height:Oe.card.h,start:pt,duration:yt,posX:je(Ni(Mt,-.8,.8)),posY:je(Ni(l,-.8,.8)),scale:.35}),K=Ni(Mt+tt*(a?.1:.22),-.3,.3),d=Ni(l-(a?.3:.4)-q*(a?.12:.2),-.38,.38);p({op:"setPropertyKeys",clipId:lt,property:"x",propertyKeys:[{time:0,value:je(Mt)},{time:.6,value:je(K),ease:"back-out"}]}),p({op:"setPropertyKeys",clipId:lt,property:"y",propertyKeys:[{time:0,value:je(l)},{time:.6,value:je(d),ease:"back-out"}]}),p({op:"setPropertyKeys",clipId:lt,property:"zoom",propertyKeys:[{time:0,value:.15},{time:.6,value:a?.55:.5,ease:"back-out"}]})})});const[N,G]=Oe.mascots;if(!$)i.push(n?"no mascot GLB in Media: mascot shots skipped (add a .glb, or one from the 3D model library)":"Media chưa có linh vật GLB: bỏ các shot linh vật (thêm file .glb hoặc lấy từ kho model 3D)");else{const W=Array.isArray(o.mascotShots)?o.mascotShots.map(rt=>({s:z(rt?.clipId),region:j0(rt?.region)})).filter(rt=>rt.s):[],_=k.filter(rt=>rt.orig&&!A.has(rt)&&rt!==k[0]),J=rt=>(rt.tags.surface?2:0)+(rt.tags.person?1:0),tt=(W.length?W:[..._].sort((rt,D)=>J(D)-J(rt)||rt.t-D.t).slice(0,G).sort((rt,D)=>rt.t-D.t).map(rt=>({s:rt,region:null}))).slice(0,G);tt.length<N&&i.push(n?`only ${tt.length} shot(s) for the mascot (3–4 wanted): the other shots are phone / hook shots or added copies`:`chỉ có ${tt.length} shot cho linh vật (cần 3–4): các shot còn lại là shot điện thoại / mở đầu hoặc bản sao thêm`);for(const{s:rt,region:D}of tt){A.add(rt);const q=Number.isFinite(rt.scene.subjectX)?rt.scene.subjectX:.5,pt=q>.5?.27:.73,yt=D??{x:je(pt-.18),y:.62,w:.36,h:.3},Mt=p({op:"addClip",materialId:$.id,track:C(1),start:rt.t,duration:rt.L});p({op:"pinToSurface",clipId:Mt,sourceClipId:rt.clipId,at:je(rt.t+Math.min(.1,rt.L/4)),region:yt,mode:"camera3d",booleanValue:!1}),p({op:"modelLook",clipId:Mt,prompt:JSON.stringify({preset:"overcast",shadow:.5,blur:.5})})}}const V=(Array.isArray(o.words)?o.words:[]).map(W=>Fa(String(W??""),14).split(" ")[0]).filter(Boolean).slice(0,Oe.words);if(!V.length)i.push(n?'no words given (words: ["SMART","SIMPLE"]): animated words skipped':'chưa có chữ (words: ["SMART","SIMPLE"]): bỏ chữ động');else{const W=k.filter(rt=>rt!==k[0]&&!A.has(rt)&&rt.tags.person),_=k.filter(rt=>rt!==k[0]&&!P.some(D=>D.s===rt)),J=W.length>=V.length?W:[...W,..._.filter(rt=>!W.includes(rt))],tt=V.map((rt,D)=>J[Math.min(J.length-1,Math.floor((D+.5)*J.length/V.length))]).filter(Boolean);V.forEach((rt,D)=>{const q=tt[D];if(!q)return;const pt=fS(q.scene,a);if(!pt){i.push(n?`"${rt}" skipped: the face fills every title-safe band of its shot`:`bỏ chữ "${rt}": mặt người chiếm mọi vùng an toàn của shot`);return}const yt=p({op:"addMotion",motionPreset:"creator-neon-script",text:rt,start:je(q.t+.1),duration:je(q.L-.15),placement:pt.placement,color:m,params:{accent:m},aside:!0});pt.x&&p({op:"setPropertyKeys",clipId:yt,property:"x",propertyKeys:[{time:0,value:pt.x}]})})}const et=Ni(Number.isFinite(+o.endcard)&&o.endcard!==null?+o.endcard:Oe.endcard.def,Oe.endcard.min,Oe.endcard.max),U=S.end;if(p({op:"addMotion",motionPreset:"tvc-backdrop",start:U,duration:et,numberValue:0,color:m,track:C(5)}),x){const W=p({op:"addClip",materialId:x.id,track:C(6),start:U,duration:et}),_=p({op:"addDevice",clipId:W,preset:"phone"});p({op:"setPropertyKeys",clipId:_,property:a?"y":"x",propertyKeys:[{time:0,value:a?-.02:-.2}]})}if($){const W=p({op:"addClip",materialId:$.id,track:C(7),start:U,duration:et});p({op:"setPropertyKeys",clipId:W,property:"x",propertyKeys:[{time:0,value:a?.2:-.02}]}),p({op:"setPropertyKeys",clipId:W,property:"y",propertyKeys:[{time:0,value:a?.22:.2}]}),p({op:"setPropertyKeys",clipId:W,property:"zoom",propertyKeys:[{time:0,value:a?.45:.55}]})}E&&p({op:"addElement",materialId:E.id,start:je(U+.2),duration:je(et-.2),posX:a?0:.28,posY:a?-.38:-.18,scale:a?.3:.18,anim:{in:"pop",out:"fade"}});const at=v||g;return at&&p({op:"addText",text:at,start:je(U+.5),duration:je(et-.5),placement:a?"lower":"center",...a?{}:{posX:.28,posY:.12},fontSize:a?44:40,color:"#14171c",preset:"slide-up"}),!x&&!$&&!E&&!at&&i.push(n?"end card has no app UI, mascot, logo or tagline: only its backdrop":"end card chưa có UI app, linh vật, logo hay tagline: chỉ có nền"),{ops:c,notes:i,end:je(U+et),shots:k.length}}function yS(t,{clips:e=[],materials:o=[],brand:r=null,portrait:a=!1,en:n=!1,maxOps:i=1/0,simulate:c=null}={}){if(!Array.isArray(t)||!t.some(f=>f?.op==="appAdEdit"&&!f.error&&!f.note))return t;const u=[],p=[];let s=0;const h=f=>{const m=typeof f=="string"&&/^new:(\d+)$/.exec(f);if(!m)return f;const g=+m[1];let v=0;for(const x of p)g>x.after&&(v+=x.by);return`new:${g+v}`};for(const f of t){const m=f&&typeof f=="object"?{...f,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(v=>typeof f[v]=="string").map(v=>[v,h(f[v])])),...Array.isArray(f.clipIds)?{clipIds:f.clipIds.map(h)}:{}}:f;if(m?.op!=="appAdEdit"||m.error||m.note){u.push(m),bc.has(m?.op)&&s++;continue}let g=e;if(c&&u.some(v=>uS.includes(v?.op)))try{g=c([...u])??e}catch{g=e}try{const{ops:v,notes:x}=gS({clips:g,materials:o,copy:{...dS(m.prompt),...Object.fromEntries(Object.entries(m).filter(([k])=>!["op","prompt"].includes(k)))},brand:r,portrait:a,en:n});if(u.length+v.length>i)throw Error(`makes ${v.length} ops — over the plan's ${i}`);const E=v.filter(k=>bc.has(k.op)).length,$=u.filter(k=>bc.has(k?.op)).length,S=k=>{const y=typeof k=="string"&&/^new:(\d+)$/.exec(k);return y?`new:${+y[1]+$}`:k};u.push(...v.map(k=>typeof k.clipId=="string"?{...k,clipId:S(k.clipId)}:k)),x.length&&u.push({op:"appAdEdit",note:x.join("; ").slice(0,600)}),E&&p.push({after:s,by:E})}catch(v){u.push({op:"appAdEdit",error:String(v?.message||v).slice(0,300)})}}return u}const np=Object.freeze(["tilt-reveal","float-hero","zoom-detail","paparazzi","deck-deal","flip-swap","exploded"]),O0=Object.freeze({"tilt-reveal":{name:"Trang nghiêng dựng lên",clips:[1,1],camera:!0,about:"the page lies tilted back far away and rises to face the camera, then a slow push"},"float-hero":{name:"Thẻ lơ lửng",clips:[1,1],camera:!0,about:"the picture floats as a hero card: a gentle 3D sway, a bob and a slow push (a hold shot)"},"zoom-detail":{name:"Phóng vào chi tiết",clips:[1,1],camera:!1,about:"a smooth push into one detail of the picture (focus x / y / size)"},paparazzi:{name:"Ba lần chớp",clips:[1,1],camera:!1,about:"three warm flashes, three tight crops of the picture (points / times, e.g. on drum hits), then the whole card"},"deck-deal":{name:"Chia bài",clips:[2,6],camera:!1,about:"the pictures are dealt in one after another into a fanned stack, then the top card rises to the front"},"flip-swap":{name:"Lật thẻ",clips:[2,2],camera:!0,about:"the first card flips over in 3D and the second one is on its back (at = the timeline second of the flip)"},exploded:{name:"Tách lớp",clips:[1,1],camera:!0,about:"the page tilts to an isometric view and its bands (header / body / footer) lift apart in depth, then close again"}}),z0=t=>Math.round(t*1e4)/1e4,Yo=(t,e,o)=>Math.min(o,Math.max(e,t)),Na=t=>typeof t=="number"&&Number.isFinite(t),ie=(...t)=>t.filter(Boolean).map(([e,o,r])=>({time:z0(e),value:z0(o),...r?{ease:r}:{}})).filter((e,o,r)=>!o||e.time-r[o-1].time>=1/30);function bS(t,e,o={}){if(!np.includes(t))throw Error(`promoShot shot must be ${np.join(" | ")}`);const[r,a]=O0[t].clips;if(e.length<r||e.length>a)throw Error(`promoShot ${t} needs ${r===a?r:`${r}–${a}`} picture clip${a>1?"s":""}`);const n={cards:[],camera:O0[t].camera},i=e[0],c=i.duration,u=p=>Yo(p,0,c);if(c<.8)throw Error("promoShot needs a clip of at least 0.8 s");if(t==="tilt-reveal"){const p=u(Math.min(1.1,c*.45)),s=i.zoom;n.cards.push({id:i.id,is3D:!0,keys:{tiltX:ie([0,58,"expo-out"],[p,0]),depth:ie([0,-7,"expo-out"],[p,0]),y:ie([0,.3,"expo-out"],[p,0]),zoom:ie([0,s],[p,s,"ease-in-out"],[c,s*1.05]),opacity:ie([0,0],[u(.25),1]),x:ie([0,0]),rot:ie([0,0])}})}else if(t==="float-hero"){const p=i.zoom,s=c/4;n.cards.push({id:i.id,is3D:!0,keys:{tiltY:ie([0,-16,"sine-in-out"],[s*2,-7,"sine-in-out"],[c,-13]),tiltX:ie([0,9,"sine-in-out"],[c,4]),y:ie([0,.012,"sine-in-out"],[s,-.012,"sine-in-out"],[s*2,.012,"sine-in-out"],[s*3,-.012,"sine-in-out"],[c,.006]),zoom:ie([0,p*.96,"ease-out"],[c,p*1.04]),opacity:ie([0,0],[u(.2),1]),x:ie([0,0]),rot:ie([0,0])}})}else if(t==="zoom-detail"){const p=o.focus??{},s=Yo(Na(p.x)?p.x:.5,0,1),h=Yo(Na(p.y)?p.y:.35,0,1),f=Yo(Na(p.size)?p.size:.4,.15,1),m=i.zoom,g=Yo(1/f,1,3.5),v=m*g,x=u(.25),E=u(Math.max(x+.4,c*.65)),$=-(s-.5)*i.dispW*v,S=-(h-.5)*i.dispH*v;n.cards.push({id:i.id,is3D:!1,keys:{zoom:ie([0,m],[x,m,"expo-in-out"],[E,v],[c,v*1.03]),x:ie([0,0],[x,0,"expo-in-out"],[E,$],[c,$*1.03]),y:ie([0,0],[x,0,"expo-in-out"],[E,S],[c,S*1.03]),rot:ie([0,0])}})}else if(t==="paparazzi"){const p=(Array.isArray(o.points)&&o.points.length?o.points:[{x:.25,y:.3},{x:.72,y:.45},{x:.45,y:.75}]).slice(0,3),s=(Array.isArray(o.times)&&o.times.length>=p.length?o.times.slice(0,p.length):p.map((S,k)=>c*(.12+.24*k))).map(S=>u(S)).sort((S,k)=>S-k),h=u(Math.max(s[s.length-1]+.5,c*.82)),f=i.zoom,m=f*2.3,g=[[0,f,"hold"]],v=[[0,0,"hold"]],x=[[0,0,"hold"]],E=[[0,0]],$=[[0,0]];p.forEach((S,k)=>{const y=s[k],C=Yo(Na(S?.x)?S.x:.5,0,1),A=Yo(Na(S?.y)?S.y:.5,0,1);g.push([y,m,"hold"]),v.push([y,-(C-.5)*i.dispW*m,"hold"]),x.push([y,-(A-.5)*i.dispH*m,"hold"]),E.push([Math.max(0,y-.04),0],[y,1],[u(y+.14),0]),$.push([Math.max(0,y-.04),0],[y,.8],[u(y+.2),0])}),g.push([h,f]),v.push([h,0]),x.push([h,0]),E.push([Math.max(0,h-.04),0],[h,.8],[u(h+.14),0]),$.push([Math.max(0,h-.04),0],[h,.6],[u(h+.2),0]),n.cards.push({id:i.id,is3D:!1,keys:{zoom:ie(...g),x:ie(...v),y:ie(...x),rot:ie([0,0])},effects:{exposure:ie(...E),warm:ie(...$)}})}else if(t==="deck-deal"){const p=e.length;e.forEach((s,h)=>{const f=s.duration,m=Yo(h*.16,0,f),g=Yo(m+.5,0,f),v=h-(p-1)/2,x={x:v*.07,y:Math.abs(v)*.012,rot:v*5},E=h===p-1,$=Yo(Math.max(g+.4,f*.6),0,f),S=Yo($+.5,0,f);n.cards.push({id:s.id,is3D:!1,keys:{x:ie([0,.75],[m,.75,"expo-out"],[g,x.x],...E?[[$,x.x,"ease-in-out"],[S,0]]:[[f,x.x*1.2]]),y:ie([0,.7],[m,.7,"expo-out"],[g,x.y],...E?[[$,x.y,"ease-in-out"],[S,0]]:[[f,x.y]]),rot:ie([0,24],[m,24,"expo-out"],[g,x.rot],...E?[[$,x.rot,"ease-in-out"],[S,0]]:[[f,x.rot*1.15]]),zoom:ie([0,s.zoom*.9],[m,s.zoom*.9,"expo-out"],[g,s.zoom],...E?[[$,s.zoom,"back-out"],[S,s.zoom*1.28]]:[[f,s.zoom*.97]]),opacity:ie([0,0],[m,0],[Yo(m+.12,0,f),1])}})})}else if(t==="flip-swap"){const[p,s]=e,h=Yo(Na(o.at)?o.at:p.duration/2,.3,p.duration-.05),f=.22,m=Yo(h-(o.bStart??0),.05,s.duration-.05);n.cards.push({id:p.id,is3D:!0,keys:{tiltY:ie([0,0],[Math.max(0,h-f),0,"ease-in"],[h,90]),opacity:ie([0,1],[h,1,"hold"],[Math.min(p.duration,h+.05),0]),zoom:ie([0,p.zoom],[h,p.zoom*.94])}}),n.cards.push({id:s.id,is3D:!0,keys:{tiltY:ie([0,-90],[m,-90,"ease-out"],[Math.min(s.duration,m+f),0]),opacity:ie([0,0],[Math.max(0,m-.05),0,"hold"],[m,1]),zoom:ie([0,s.zoom*.94],[m,s.zoom*.94,"ease-out"],[Math.min(s.duration,m+f+.3),s.zoom])}})}else if(t==="exploded"){const p=Yo(Math.round(Na(o.slices)?o.slices:3),2,4),s=i.zoom,h=s*.8,f=u(.15),m=u(Math.min(1.1,c*.35)),g=u(Math.max(m+.3,c-.9)),v=u(c-.3);n.slices=p;for(let x=0;x<p;x++){const E=((x+.5)/p-.5)*i.dispH,$=-(p-1-x)*2.2,S=(p-1-x)*.035,k=u(m+.6+x*.08);n.cards.push({id:`${i.id}#${x}`,slice:x,is3D:!0,keys:{tiltY:ie([0,0],[f,0,"expo-in-out"],[m,-34],[g,-34,"expo-in-out"],[v,0]),depth:ie([0,0],[m,0,"back-out"],[k,$],[g,$,"expo-in-out"],[v,0]),x:ie([0,0],[m,0,"back-out"],[k,S],[g,S,"expo-in-out"],[v,0]),y:ie([0,E*s],[f,E*s,"expo-in-out"],[m,E*h],[g,E*h,"expo-in-out"],[v,E*s]),zoom:ie([0,s],[f,s,"expo-in-out"],[m,h],[g,h,"expo-in-out"],[v,s]),rot:ie([0,0])}})}}return n}const ln=1/30,Er=t=>Math.round(t*1e3)/1e3,eo=t=>Math.round(t*1e4)/1e4,Tr=(t,e,o)=>Math.max(e,Math.min(o,t)),zo=(t,e)=>Number.isFinite(t)?t:e,Ch=/^#[0-9a-f]{6}$/i,di=Object.freeze({strobe:Object.freeze({clips:[2,40],duration:[.5,15],default:4,maxShot:[.15,2],defaultMaxShot:.45,flashEvery:[0,16],defaultFlashEvery:4,bwEvery:[0,16],defaultBwEvery:3,on:["hits","beats","bars"]}),dip:Object.freeze({hold:[0,2],defaultHold:.4,fade:[.1,1.5],defaultFade:.4}),logo:Object.freeze({styles:["metal-sweep","glitch-in"],duration:[1,8],default:3}),lyric:Object.freeze({lines:[1,8],size:[28,96],defaultSize:58,sides:["left","center","right"]}),credits:Object.freeze({items:[1,40],every:[.8,6],defaultEvery:2.2}),bug:Object.freeze({corners:["top-right","top-left","bottom-right","bottom-left"],size:[.04,.3],defaultSize:.09})}),es=t=>!!t&&mh(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 wS({at:t,duration:e,times:o=[],maxShot:r=di.strobe.defaultMaxShot}){const a=ut(t),n=ut(t+e);let i=[a,...o.map(ut).filter(p=>p>a+1e-6&&p<n-1e-6),n].sort((p,s)=>p-s);const c=[];for(const p of i)!c.length||p-c.at(-1)>=2*ln-1e-6?c.push(p):p===n&&(c[c.length-1]=n);if(c.length<2)return[{start:a,duration:eo(n-a)}];const u=[];for(let p=0;p+1<c.length;p++){const s=c[p],h=c[p+1]-s,f=Math.max(1,Math.ceil(h/r-1e-6));for(let m=0;m<f;m++){const g=ut(s+h*m/f),v=m===f-1?c[p+1]:ut(s+h*(m+1)/f);v-g>=ln-1e-6&&u.push({start:g,duration:eo(v-g)})}}return u}const kS="#fff4e6";function xS(t,e={},{clipIds:o,at:r,duration:a,times:n=[],maxShot:i,flashEvery:c,bwEvery:u,newId:p,overlayTrack:s,locale:h="vi",aspect:f=16/9}={}){const m=di.strobe,g=[...new Set(Array.isArray(o)?o:[])];if(g.length<m.clips[0]||g.length>m.clips[1])throw Error(`beatStrobe needs ${m.clips[0]}–${m.clips[1]} clips`);const v=g.map(W=>t.find(_=>_.id===W));if(v.some(W=>!W))throw Error("Clip not found");if(v.some(W=>!es(W)))throw Error("beatStrobe takes filmed clips or photos only (no motion, text, shape or generator layers)");if(v.some(W=>e[W.track]?.locked))throw Error("Track đã khóa");const x=v[0].track,E=ut(Math.max(0,zo(r,Math.min(...v.map(W=>W.start))))),$=ut(Tr(zo(a,m.default),...m.duration)),S=E+$,k=t.find(W=>!g.includes(W.id)&&W.track===x&&W.kind!=="audio"&&W.start<S-1e-6&&W.start+W.duration>E+1e-6);if(k)throw Error(`No room for the cold open on that track (${k.label??k.id} is in the way from ${E.toFixed(2)} to ${S.toFixed(2)} s)`);const y=wS({at:E,duration:$,times:n,maxShot:Tr(zo(i,m.defaultMaxShot),...m.maxShot)}),C=new Map,A=new Set,z=y.map((W,_)=>{const J=v[_%v.length],{transition:tt,join:rt,visualFadeIn:D,visualFadeOut:q,fadeInColor:pt,fadeOutColor:yt,enter:Mt,exit:l,audioFadeIn:lt,audioFadeOut:K,...d}=J,w=A.has(J.id)?p():J.id;A.add(J.id);const T={...d,id:w,track:x,start:W.start,duration:W.duration,volume:0};if(J.kind==="video"){const I=J.playbackRate||1,O=Number.isFinite(J.sourceDuration)?J.sourceDuration:1/0,L=C.get(J.id)??0;let B=(J.inPoint||0)+L*I;B+W.duration*I>O&&(B=Math.max(0,J.inPoint||0)),B+W.duration*I>O&&(B=Math.max(0,O-W.duration*I)),T.inPoint=eo(B),C.set(J.id,eo(B-(J.inPoint||0))/I+W.duration)}return T}),j=new Map(z.filter(W=>g.includes(W.id)).map(W=>[W.id,W]));let P=[...t.filter(W=>!g.includes(W.id)||j.has(W.id)).map(W=>j.get(W.id)??W),...z.filter(W=>!g.includes(W.id))];const F=z.filter(W=>!g.includes(W.id)).map(W=>W.id),N=Math.round(Tr(zo(c,m.defaultFlashEvery),...m.flashEvery)),G=Math.round(Tr(zo(u,m.defaultBwEvery),...m.bwEvery)),V=[],et=(W,_,J)=>{const tt=ut(Pd(W)),{track:rt}=s(P,e,_,_+tt),D=p();F.push(D),V.push({style:W,t:_}),P.push({...ic({id:D,track:rt,start:_,duration:tt,label:J}),motionKeys:[],effects:Ld(W,1)})},U=h==="en",at=W=>{const{track:_}=s(P,e,W,W+ln),J=p();F.push(J),P.push(Sp({id:J,track:_,start:W,duration:ut(ln),label:U?"Flash · White frame":"Chớp · Khung trắng",fill:{type:"color",color:kS},aspect:f}))};return z.forEach((W,_)=>{_>0&&N&&_%N===0?(et("white",W.start,U?"Flash · White flash":"Chớp · Chớp trắng"),at(W.start)):G&&_%G===G-1&&W.duration>=3*ln-1e-6&&et("threshold",W.start,U?"Flash · Hard black & white":"Chớp · Đen trắng gắt")}),{clips:P,created:F,shots:z.length,flashes:V}}function MS(t,e,{hold:o,fade:r}={}){const a=di.dip;if(!t||!e||!es(t)||!es(e))throw Error("dipHold needs two filmed clips or photos either side of a cut");if(t.track!==e.track||Math.abs(t.start+t.duration-e.start)>ln/2)throw Error("dipHold: the two clips must touch on the same track");const n=ut(Tr(zo(o,a.defaultHold),...a.hold)/2),i=Er(Tr(zo(r,a.defaultFade),...a.fade));if(t.duration-n<i+ln||e.duration-n<i+ln)throw Error("dipHold: the clips are too short for that fade and hold");const c={duration:eo(t.duration-n),visualFadeOut:i,fadeOutColor:"black",transition:void 0},u={start:eo(e.start+n),duration:eo(e.duration-n),visualFadeIn:i,fadeInColor:"black"};return e.kind==="video"&&(u.inPoint=eo((e.inPoint||0)+n*(e.playbackRate||1))),{a:c,b:u}}const tb=(t,e)=>({motionV:2,motionKeys:br(t,"opacity",e.map(([o,r,a])=>({time:Er(o),value:r,...a?{ease:Yt[a]}:{}})))});function vS(t,{style:e="metal-sweep",at:o=0,duration:r,tagline:a,color:n="#ffffff",font:i="Be Vietnam Pro",mw:c=1e3,mh:u=1e3,newId:p,W:s=1280,H:h=720}={}){const f=di.logo;if(!t||!["image","video"].includes(t.kind)||t.motion||t.title||t.shape||t.card||t.geo)throw Error("logoSting needs the logo picture clip");if(!f.styles.includes(e))throw Error(`logoSting style: ${f.styles.join(" | ")}`);if(!Ch.test(n))throw Error("logoSting color must be #RRGGBB");const m=Er(Tr(zo(o,0),0,Math.max(0,t.duration-1))),g=Er(Tr(zo(r,Math.min(f.default,t.duration-m)),f.duration[0],Math.max(f.duration[0],t.duration-m)));if(t.duration-m<f.duration[0]-1e-6)throw Error("logoSting: the logo clip is shorter than 1 s after `at`");const v=(t.effects??[]).filter($=>!["glow","exposure","rgb-split"].includes($.type)),x=[];let E;if(e==="metal-sweep"){if(E={effects:[...v,{type:"glow",amount:.3,keys:[{time:m,value:0,ease:Yt["ease-out"]},{time:Er(m+.5),value:.55,ease:Yt["ease-in-out"]},{time:Er(m+1.1),value:.3}]}],enter:{type:"zoom-out",duration:Er(Math.min(.8,g*.4)),amount:.1,fade:!0}},E.effects.length>6)throw Error("At most 6 effects per clip");const $=Er(m+.45),S=Er(Math.min(t.duration,$+Math.max(.6,g*.35))),k=P=>[[P-.18,-.2],[P+.02,-.2],[P+.32,1.2],[P+.12,1.2]].map(([F,N])=>[eo(F),eo(N)]),{transition:y,join:C,enter:A,exit:z,...j}=t;x.push({...j,...E,id:p(),label:`${t.label||"Logo"} · quét sáng`,volume:0,blend:"add",effects:[{type:"exposure",amount:.65}],mask:{v:1,mw:Math.round(c),mh:Math.round(u),keys:[{t:0,pts:k(-.6)},{t:$,pts:k(-.6)},{t:S,pts:k(1.3)}],smooth:!1,feather:.04}})}else{const $=k=>Er(m+k*ln),S=t.duration;if(E={effects:[...v,{type:"rgb-split",amount:1,keys:[{time:m,value:1,ease:Yt.hold},{time:$(3),value:.7,ease:Yt["ease-out"]},{time:$(10),value:0}]},{type:"exposure",amount:0,keys:[{time:m,value:.6,ease:Yt["ease-out"]},{time:$(6),value:0}]}],...tb(t,[[m,0,"hold"],[$(1),1,"hold"],[$(2),.2,"hold"],[$(3),1,"hold"],[$(5),.35,"hold"],[$(6),1],...S-(m+g)>.4?[[m+g,1,"ease-in"],[Math.min(S,m+g+.8),0]]:[[Math.max($(7),S-.6),1,"ease-in"],[S,0]]])},E.effects.length>6)throw Error("At most 6 effects per clip")}if(typeof a=="string"&&a.trim()){const $=Er(t.start+m+.6),S=Er(t.start+t.duration-$);if(S>=.5){const k=ri({text:a.trim().slice(0,120),fontSize:30,color:n,placement:"center",fontFamily:i,align:"center",animation:e==="glitch-in"?"glitch-in":"mask-rise",design:{lines:[{scale:1,fill:n,font:i,weight:700,tracking:.18}],layers:[{type:"text",fill:"{color}",shadow:{color:"#000000",blur:.25,x:0,y:.03}}]}});x.push({id:p(),nodeId:"",kind:"image",url:"",label:a.trim().slice(0,40),title:k,decor:!0,volume:0,start:$,duration:S,motionV:2,posX:eo(t.posX??0),posY:eo(Tr((t.posY??0)+.5*(t.scale??1)*Math.min(1,s/h/(c/u))+.06,-.45,.45)),scale:1,motionKeys:[]})}}return{patch:E,layers:x}}function $S(t,{end:e,side:o="left",size:r,color:a="#ffffff",font:n="Oswald",newId:i,H:c=720}={}){const u=di.lyric;if(!Array.isArray(t)||t.length<u.lines[0]||t.length>u.lines[1])throw Error(`lyricStack needs ${u.lines[0]}–${u.lines[1]} lines`);if(!u.sides.includes(o))throw Error(`lyricStack side: ${u.sides.join(" | ")}`);if(!Ch.test(a))throw Error("lyricStack color must be #RRGGBB");const p=t.map((x,E)=>{const $=typeof x?.text=="string"?x.text.trim():"",S=Number(x?.at);if(!$||$.length>60)throw Error(`lyricStack line ${E+1}: text of 1–60 characters`);if(!Number.isFinite(S)||S<0)throw Error(`lyricStack line ${E+1}: at (timeline s)`);return{text:$,at:ut(S)}}).sort((x,E)=>x.at-E.at),s=ut(zo(Number(e),p.at(-1).at+2.5));if(s<=p.at(-1).at+.3)throw Error("lyricStack end must come after the last line");const h=Math.round(Tr(zo(r,u.defaultSize),...u.size)),f=eo(h*1.25/c*(c/720)),m=p.length,g=0,v=o==="left"?"left":o==="right"?"right":"center";return p.map((x,E)=>{const $=ri({text:x.text.toUpperCase(),fontSize:h,color:a,placement:"center",fontFamily:n,align:v,animation:"slide-in",design:{uppercase:!0,lineHeight:1.25,lines:[{scale:1,fill:a,font:n,weight:700,tracking:.02}],layers:[{type:"text",fill:"{color}",shadow:{color:"#000000",blur:.3,x:0,y:.03}}]}}),S={id:i(),nodeId:"",kind:"image",url:"",label:x.text.slice(0,40),title:$,decor:!0,volume:0,start:x.at,duration:eo(s-x.at),motionV:2,posX:g,posY:eo((E-(m-1)/2)*f),scale:1,motionKeys:[]},k=p[E+1]?.at;return k!=null&&k-x.at>=.1?{...S,...tb(S,[[k-x.at,1,"ease-out"],[Math.min(k-x.at+.25,s-x.at),.45]])}:S})}function ES(t,{at:e=0,every:o,color:r="#ffffff",font:a="Be Vietnam Pro",newId:n}={}){const i=di.credits;if(!Array.isArray(t)||t.length<i.items[0]||t.length>i.items[1])throw Error(`addCredits needs ${i.items[0]}–${i.items[1]} items`);if(!Ch.test(r))throw Error("addCredits color must be #RRGGBB");const c=ut(Tr(zo(o,i.defaultEvery),...i.every)),u=ut(Math.max(0,zo(e,0)));return t.map((p,s)=>{const h=typeof p?.role=="string"?p.role.trim():"",f=typeof p?.name=="string"?p.name.trim():"";if(!f||f.length>90||h.length>60)throw Error(`addCredits item ${s+1}: name (1–90 characters) and role (≤ 60)`);const m=h?`${h}
119
+ ${f}`:f,g=ri({text:m,fontSize:26,color:r,placement:"lower",fontFamily:a,align:"center",animation:"mask-rise",design:{lineHeight:1.3,...h?{lines:[{scale:.62,fill:r,font:a,weight:400,tracking:.16},{scale:1,fill:r,font:a,weight:700,tracking:.04}]}:{},layers:[{type:"text",fill:"{color}",shadow:{color:"#000000",blur:.35,x:0,y:.03}}]}});return{id:n(),nodeId:"",kind:"image",url:"",label:`Credit · ${f.slice(0,30)}`,title:g,volume:0,start:eo(u+s*c),duration:eo(c-ln),motionV:2,posX:0,posY:0,scale:1,motionKeys:[]}})}function SS(t,{corner:e="top-right",size:o,opacity:r=.9,from:a=0,to:n,W:i=1280,H:c=720,mw:u=1e3,mh:p=1e3}={}){const s=di.bug;if(!t||!["image","video"].includes(t.kind)||t.motion||t.title||t.shape)throw Error("logoBug needs the logo picture clip");if(!s.corners.includes(e))throw Error(`logoBug corner: ${s.corners.join(" | ")}`);const h=Tr(zo(o,s.defaultSize),...s.size),f=Tr(zo(r,.9),.2,1),m=Math.min(1,i/c/(u/p)),g=eo(h/m),v=h*(u/p)*(c/i),x=.035,E=.05,$=eo((e.endsWith("right")?1:-1)*(.5-x-v/2)),S=eo((e.startsWith("top")?-1:1)*(.5-E-h/2)),k=ut(Math.max(0,zo(a,0))),y=ut(zo(n,k+t.duration));if(y-k<ln)throw Error("logoBug: to must come after from");return{start:k,duration:eo(y-k),posX:$,posY:S,scale:g,opacity:Er(f),motionV:2,motionKeys:[],...t.kind==="video"?{volume:0}:{},enter:void 0,exit:void 0}}const fs="torn",ap=["top","right","bottom","left"],P0=Object.freeze({depth:.03,seed:1}),IS=30;function AS(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 Mi=t=>Math.round(t*1e4)/1e4;function CS({sides:t=ap,depth:e=P0.depth,seed:o=P0.seed,aspect:r=16/9}={}){const a=new Set(t.filter(v=>ap.includes(v)));if(!a.size)throw Error("Pick at least one side to tear");if(!Number.isFinite(e)||e<.005||e>.1)throw Error("Invalid tear depth");const n=AS(o),i=e/Math.max(1,r),c=e*Math.min(1,r),u=(v,x,E,$)=>[Mi(a.has(E)?v?1-i*(.4+n()*.6):i*(.4+n()*.6):v),Mi(a.has($)?x?1-c*(.4+n()*.6):c*(.4+n()*.6):x)],p=u(0,0,"left","top"),s=u(1,0,"right","top"),h=u(1,1,"right","bottom"),f=u(0,1,"left","bottom"),m=(v,x,E)=>{if(!a.has(E))return[];const $=[],S=IS,k=E==="top"||E==="bottom";for(let y=1;y<S;y++){const C=y/S+(n()-.5)*.6/S,A=n()**1.6,z=v[0]+(x[0]-v[0])*C,j=v[1]+(x[1]-v[1])*C;k?$.push([Mi(z),Mi(E==="top"?A*c:1-A*c)]):$.push([Mi(E==="left"?A*i:1-A*i),Mi(j)])}return $},g=[p,...m(p,s,"top"),s,...m(s,h,"right"),h,...m(h,f,"bottom"),f,...m(f,p,"left")];if(g.length>Qu)throw Error("Torn outline too long");return g}function jS(t,{mw:e,mh:o,crop:r,sides:a,depth:n,seed:i}){const c=ui(t).filter(h=>h.id!==fs),u=r||{left:0,right:0,top:0,bottom:0},p=e*(1-u.left-u.right)/Math.max(1,o*(1-u.top-u.bottom)),s={id:fs,name:"Mép xé",mode:c.length?"intersect":"add",keys:[{t:0,pts:CS({sides:a,depth:n,seed:i,aspect:p})}],feather:.0015};return fr(t?{mw:t.mw,mh:t.mh}:{mw:e,mh:o},[...c,s])}function CT(t){const e=ui(t).filter(o=>o.id!==fs);return t&&e.length?fr(t,e.map((o,r)=>r===0&&o.mode==="intersect"?{...o,mode:"add"}:o)):void 0}const jT=t=>ui(t).some(e=>e.id===fs),eb="cut",jh=t=>new RegExp(`^${eb}\\d+$`).test(t.id);function TT(t,{mw:e,mh:o},r){if(!r.length)throw Error("Nothing to cut out");const a=ui(t).filter(p=>!jh(p)),n=a.filter(p=>p.id===fs),i=a.filter(p=>p.id!==fs),c=r.slice(0,Math.max(1,8-a.length)).map((p,s)=>({id:`${eb}${s+1}`,name:"Tách nền",mode:"add",keys:[{t:0,pts:p}],smooth:!0,feather:.0012})),u=[...i,...c,...n.map(p=>({...p,mode:"intersect"}))].map((p,s)=>s===0&&p.mode!=="add"?{...p,mode:"add"}:p);return fr(t?{mw:t.mw,mh:t.mh}:{mw:e,mh:o},u)}const OT=t=>ui(t).some(jh);function zT(t){const e=ui(t).filter(o=>!jh(o));return t&&e.length?fr(t,e.map((o,r)=>r===0&&o.mode!=="add"?{...o,mode:"add"}:o)):void 0}const En=Object.freeze({maxCards:24,cols:[1,8],rows:[1,6],curve:[0,1],maxSeconds:20,fly:[.25,2],color:"#5ee7ff"}),TS=Object.freeze(["glass","neon","mono"]),Eu=Object.freeze(["chart","play","photo","music","chat","map","cart","stats","calendar","mail","code","camera"]),ob=/^#[0-9a-fA-F]{6}$/,le=t=>Math.round(t*1e4)/1e4,wc=t=>Math.round(t*1e3)/1e3,qs=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,OS={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"]]},L0=["#5ee7ff","#7c8cff","#ff6bd6","#ffd166","#6dffb3","#ff8f5e"];function os(t,e,o,r){var a=Math.max(1e-4,(t.curve||0)*1.75),n=1.55,i=(e-.5)*a,c=t.w/a,u=c*Math.sin(i),p=c*(1-Math.cos(i)),s=(o-.5)*t.h,h=n/(n-p);return[t.cx+u*h,t.cy+s*h*r,h]}function zS(t,e,o,r){let a=.5+(e-t.cx)/t.w,n=.5+(o-t.cy)/(t.h*r);for(let i=0;i<12;i++){const c=os(t,a,n,r),u=1e-4,p=os(t,a+u,n,r),s=os(t,a,n+u,r),h=(p[0]-c[0])/u,f=(s[0]-c[0])/u,m=(p[1]-c[1])/u,g=(s[1]-c[1])/u,v=h*g-f*m||1e-9,x=e-c[0],E=o-c[1];a+=(g*x-f*E)/v,n+=(-m*x+h*E)/v}return[a,n]}function rb(t,e){var o=Math.floor(e/t.cols),r=e%t.cols,a=.07,n=a*(t.w/t.cols)/(t.h/t.rows);return[(r+a)/t.cols,(o+n)/t.rows,(r+1-a)/t.cols,(o+1-n)/t.rows]}function F0(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 a=Math.max(0,Math.min(t.cols-1,Math.floor(e*t.cols))),n=Math.max(0,Math.min(t.rows-1,Math.floor(o*t.rows))),i=n*t.cols+a;return i<t.cards.length?i:-1}function PS(t,e=[],o="vi"){const r=Array.isArray(t?.cards)?t.cards.slice(0,En.maxCards):null,a=r?r.length:Math.round(qs(Number(t?.count),1,En.maxCards,12));if(!a)throw Error("hudWall needs at least one card");const n=OS[o==="en"?"en":"vi"],i={},c=[];for(let u=0;u<a;u++){const p=r?.[u]??{},s=n[u%n.length],h={title:String(p.title??s[0]).slice(0,40),sub:String(p.sub??(r?"":s[1])).slice(0,60),color:ob.test(p.color??"")?p.color.toLowerCase():L0[u%L0.length],icon:Eu.includes(p.icon)?p.icon:Eu[u%Eu.length]};if(p.materialId!=null){const f=e.find(g=>g.id===p.materialId);if(!f||f.kind!=="image"||typeof f.gcsUri!="string")throw Error(`hudWall card ${u+1}: "${String(p.materialId).slice(0,40)}" is not a picture in the Media bin`);const m=`card${u}.img`;i[m]=f.gcsUri,h.img=m}c.push(h)}return{cards:c,assets:i}}function LS({cards:t,cols:e,rows:o,curve:r,color:a,look:n,toolbar:i=!0,W:c=1280,H:u=720,fill:p=!1}){const s=t.length,h=c/u,f=i!==!1,m=Math.round(qs(e,...En.cols,Math.min(s,h>=1?4:2))),g=Math.round(qs(o,...En.rows,Math.ceil(s/m)));if(m*g<s)throw Error(`hudWall: ${s} cards do not fit ${m} × ${g}`);const v=1.45,x=p?f?.84:.92:h>=1?.64:.82,E=(p?.84:.58)/h*m/g*v,$=Math.min(x,E),S=$/m*g/v;return{cols:m,rows:g,curve:wc(qs(r,...En.curve,.45)),color:ob.test(a??"")?a.toLowerCase():En.color,look:TS.includes(n)?n:"glass",toolbar:f,cx:.5+(f?p?.045:.02:0),cy:p?.5:.4,w:le($),h:le(S),cards:t,...p?{asp:le(h)}:{}}}function nb(t,e,o,r,a,n,i){var c=Math.min(o,r)*(i?.02:.09),u=Math.min(o,r*1.45),p=function(yt,Mt,l,lt,K){t.beginPath(),t.moveTo(yt+K,Mt),t.arcTo(yt+l,Mt,yt+l,Mt+lt,K),t.arcTo(yt+l,Mt+lt,yt,Mt+lt,K),t.arcTo(yt,Mt+lt,yt,Mt,K),t.arcTo(yt,Mt,yt+l,Mt,K),t.closePath()},s=e.color||a,h=e.img&&typeof M<"u"&&M.asset?M.asset(e.img):null;t.save(),p(0,0,o,r,c),t.clip();var f=t.createLinearGradient(0,0,o,r),m=i?1:0;if(n==="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 g=t.createRadialGradient(o*.75,r*.2,0,o*.75,r*.2,o*.7);g.addColorStop(0,(e.color||a)+"33"),g.addColorStop(1,(e.color||a)+"00"),t.fillStyle=g,t.fillRect(0,0,o,r)}var v=n==="mono"?"#0d1424":"#eaf6ff",x=n==="mono"?"rgba(13,20,36,0.55)":"rgba(234,246,255,0.55)",E=o*.07,$=r*.36,S=o*.86,k=r*.56;if(h){var y=Math.max(o/h.width,r/h.height),C=h.width*y,A=h.height*y;t.drawImage(h,(o-C)/2,(r-A)/2,C,A);var z=t.createLinearGradient(0,r*.45,0,r);z.addColorStop(0,"rgba(0,0,0,0)"),z.addColorStop(1,"rgba(0,0,0,0.62)"),t.fillStyle=z,t.fillRect(0,0,o,r),v="#ffffff",x="rgba(255,255,255,0.75)"}else{t.strokeStyle=s,t.fillStyle=s,t.lineWidth=Math.max(1,u*.012),t.lineCap="round",t.lineJoin="round";var j=(e.title||"").length*7+(e.icon||"").length,P=function(yt){var Mt=Math.sin(j*12.9898+yt*78.233)*43758.5453;return Mt-Math.floor(Mt)},F=e.icon;if(F==="chart"||F==="stats"){t.globalAlpha=.9,t.beginPath();for(var N=0;N<=8;N++){var G=E+S*N/8,V=$+k*(.85-.6*(.3+.7*P(N))*(.4+N/12));N?t.lineTo(G,V):t.moveTo(G,V)}t.stroke(),t.globalAlpha=.18,t.lineTo(E+S,$+k),t.lineTo(E,$+k),t.closePath(),t.fill(),t.globalAlpha=1}else if(F==="play"||F==="camera"){var et=t.createLinearGradient(E,$,E+S,$+k);et.addColorStop(0,s),et.addColorStop(1,"#101a30"),t.globalAlpha=.55,t.fillStyle=et,p(E,$,S,k,c*.5),t.fill(),t.globalAlpha=1,t.fillStyle=v,t.beginPath();var U=E+S/2,at=$+k/2,W=k*.22;F==="play"?(t.moveTo(U-W*.6,at-W),t.lineTo(U+W,at),t.lineTo(U-W*.6,at+W)):t.arc(U,at,W,0,Math.PI*2),t.closePath(),t.fill()}else if(F==="photo")t.globalAlpha=.5,t.fillStyle=s,p(E,$,S,k,c*.5),t.fill(),t.globalAlpha=1,t.fillStyle="rgba(255,255,255,0.85)",t.beginPath(),t.moveTo(E,$+k),t.lineTo(E+S*.35,$+k*.35),t.lineTo(E+S*.6,$+k*.7),t.lineTo(E+S*.75,$+k*.5),t.lineTo(E+S,$+k),t.closePath(),t.fill(),t.beginPath(),t.arc(E+S*.78,$+k*.25,k*.1,0,Math.PI*2),t.fill();else if(F==="music"){for(var N=0;N<18;N++){var _=k*(.15+.75*P(N));t.globalAlpha=.35+.65*P(N+30),t.fillRect(E+S*N/18,$+k/2-_/2,S/18*.55,_)}t.globalAlpha=1}else if(F==="chat"||F==="mail"){for(var N=0;N<3;N++){var J=$+k*(.05+N*.33),tt=S*(.45+.4*P(N));t.globalAlpha=N%2?.85:.35,p(N%2&&F==="chat"?E+S-tt:E,J,tt,k*.24,k*.1),t.fill()}t.globalAlpha=1}else if(F==="map"){t.globalAlpha=.25;for(var N=1;N<5;N++)t.beginPath(),t.moveTo(E,$+k*N/5),t.lineTo(E+S,$+k*(N/5+.08)),t.stroke();t.globalAlpha=1,t.beginPath(),t.moveTo(E+S*.1,$+k*.85),t.bezierCurveTo(E+S*.4,$+k*.2,E+S*.6,$+k*.9,E+S*.88,$+k*.2),t.stroke(),t.beginPath(),t.arc(E+S*.88,$+k*.2,k*.09,0,Math.PI*2),t.fill()}else if(F==="calendar"){for(var N=0;N<14;N++)t.globalAlpha=N===9?1:.28,p(E+S*(N%7)/7,$+k*Math.floor(N/7)*.5,S/7*.82,k*.4,k*.06),t.fill();t.globalAlpha=1}else if(F==="cart"){for(var N=0;N<7;N++){var _=k*.45*(.3+.7*(N+1)/7*(.7+.3*P(N)));t.globalAlpha=.35+.08*N,t.fillRect(E+S*(.55+N*.064),$+k*.5-_,S*.04,_)}t.globalAlpha=1}else{for(var N=0;N<4;N++)t.globalAlpha=.3+.5*P(N),t.fillRect(E+S*.06*(N%2),$+k*N/4,S*(.4+.5*P(N+9)),k*.12);t.globalAlpha=1}(F==="stats"||F==="cart")&&(t.fillStyle=v,t.font="700 "+Math.round(Math.min(u*.15,k*.42))+"px "+(typeof FONTS<"u"&&FONTS.mont?FONTS.mont:"sans-serif"),t.textBaseline="alphabetic",t.fillText(e.sub||"",E,$+k*.95,S))}t.fillStyle=s,t.beginPath(),t.arc(o*.1,r*.16,u*.042,0,Math.PI*2),t.fill();var rt=typeof FONTS<"u"&&FONTS.mont?FONTS.mont:"sans-serif";t.fillStyle=v,t.textBaseline="middle",t.font="700 "+Math.round(u*(i?.05:.082))+"px "+rt;var D=o*.17,q=o*.78;t.fillText(e.title||"",D,r*.16,q),(e.sub&&e.icon!=="stats"&&e.icon!=="cart"||h)&&(t.fillStyle=x,t.font="500 "+Math.round(u*(i?.032:.056))+"px "+rt,t.fillText(e.sub||"",D,r*.26,q)),t.restore(),p(.5,.5,o-1,r-1,c),t.lineWidth=Math.max(1,u*.008),t.strokeStyle=n==="neon"?s:"rgba(255,255,255,0.28)",t.stroke();var pt=t.createLinearGradient(0,0,0,r*.2);pt.addColorStop(0,"rgba(255,255,255,0.16)"),pt.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=pt,p(1,1,o-2,r*.2,c),t.fill()}function FS(t,e,o,r,a){for(var n=function(g,v,x,E,$,S){t.save(),t.beginPath();var k=(E[0]+$[0]+S[0])/3,y=(E[1]+$[1]+S[1])/3,C=function(at){var W=at[0]-k,_=at[1]-y,J=Math.hypot(W,_)||1;return[at[0]+W/J*.7,at[1]+_/J*.7]},A=C(E),z=C($),j=C(S);t.moveTo(A[0],A[1]),t.lineTo(z[0],z[1]),t.lineTo(j[0],j[1]),t.closePath(),t.clip();var P=g[0]*(v[1]-x[1])+v[0]*(x[1]-g[1])+x[0]*(g[1]-v[1]);if(Math.abs(P)<1e-9){t.restore();return}var F=(E[0]*(v[1]-x[1])+$[0]*(x[1]-g[1])+S[0]*(g[1]-v[1]))/P,N=(E[1]*(v[1]-x[1])+$[1]*(x[1]-g[1])+S[1]*(g[1]-v[1]))/P,G=(E[0]*(x[0]-v[0])+$[0]*(g[0]-x[0])+S[0]*(v[0]-g[0]))/P,V=(E[1]*(x[0]-v[0])+$[1]*(g[0]-x[0])+S[1]*(v[0]-g[0]))/P,et=(E[0]*(v[0]*x[1]-x[0]*v[1])+$[0]*(x[0]*g[1]-g[0]*x[1])+S[0]*(g[0]*v[1]-v[0]*g[1]))/P,U=(E[1]*(v[0]*x[1]-x[0]*v[1])+$[1]*(x[0]*g[1]-g[0]*x[1])+S[1]*(g[0]*v[1]-v[0]*g[1]))/P;t.transform(F,N,G,V,et,U),t.drawImage(e,0,0),t.restore()},i=2,c=function(g,v){return[a[0][0]*(1-g)*(1-v)+a[1][0]*g*(1-v)+a[2][0]*(1-g)*v+a[3][0]*g*v,a[0][1]*(1-g)*(1-v)+a[1][1]*g*(1-v)+a[2][1]*(1-g)*v+a[3][1]*g*v]},u=0;u<i;u++)for(var p=0;p<i;p++){var s=p/i,h=(p+1)/i,f=u/i,m=(u+1)/i;n([s*o,f*r],[h*o,f*r],[s*o,m*r],c(s,f),c(h,f),c(s,m)),n([h*o,f*r],[h*o,m*r],[s*o,m*r],c(h,f),c(h,m),c(s,m))}}const NS=`const GEO=${os.toString()};const CARD=${nb.toString()};
120
+ const CW=360,CH=248,cache=globalThis.__hudCards||(globalThis.__hudCards=new Map())
121
+ 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}
122
+ const CELL=${rb.toString()},cell=k=>CELL(HUD,k)
123
+ function render(ctx,t,env){
124
+ 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]]}
125
+ 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)
126
+ if(grow<=0||fade<=0)return
127
+ ctx.globalAlpha=fade
128
+ // the wall's glass back plate + grid lines
129
+ 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}
130
+ const plate=ring(-.025,-.05,1.025,1.05,24),mid=.5
131
+ ctx.save();ctx.beginPath();plate.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath()
132
+ 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()
133
+ ctx.save();ctx.globalAlpha=fade*grow*.12;ctx.strokeStyle=col;ctx.lineWidth=1
134
+ 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()}
135
+ ctx.restore()
136
+ // the side toolbar
137
+ 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()
138
+ 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()}
139
+ ctx.restore()}
140
+ // the finger's hover point on the wall
141
+ 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]}}
142
+ for(let k=0;k<HUD.cards.length;k++){
143
+ let [a0,b0,a1,b1]=cell(k)
144
+ const cv=cardCanvas(k,col,look);if(!cv)continue
145
+ const enter=ease((t-.12-.035*k)/.45);if(enter<=0)continue
146
+ const held=G&&G.k===k&&t>=G.t0
147
+ // press: the card dips in for 0.3 s at each tap / pinch on it; glow after
148
+ let press=0,glow=0
149
+ 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)}
150
+ if(hov&&hov[1]>=a0&&hov[1]<=a1&&hov[2]>=b0&&hov[2]<=b1)glow=Math.max(glow,.6)
151
+ const sc=(.82+.18*enter)*(1-.07*press),ca=(a0+a1)/2,cb=(b0+b1)/2
152
+ a0=ca+(a0-ca)*sc;a1=ca+(a1-ca)*sc;b0=cb+(b0-cb)*sc;b1=cb+(b1-cb)*sc
153
+ if(held){ // the empty slot the card was pulled out of
154
+ 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
155
+ }
156
+ ctx.save();ctx.globalAlpha=fade*enter*(.92+.08*glow)
157
+ const N=5;for(let s=0;s<N;s++){
158
+ 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
159
+ 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()
160
+ }
161
+ 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()}
162
+ ctx.restore()
163
+ }
164
+ // ripples where the finger touched
165
+ 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
166
+ ctx.save();ctx.globalCompositeOperation='lighter';ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=16
167
+ 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()}
168
+ 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()}
169
+ }`,RS=`const CARD=${nb.toString()};const QUAD=${FS.toString()};
170
+ const CW=720,CH=496,cache=globalThis.__hudGrab||(globalThis.__hudGrab=new Map())
171
+ 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}
172
+ 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)}
173
+ // the card's corners while it is held: the slot's quad carried with the pinch, standing up and coming closer as it lifts
174
+ function held(T,W,H){
175
+ 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)
176
+ 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
177
+ 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
178
+ // swing: the card leans with the hand's sideways speed (3D feel)
179
+ 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]]
180
+ 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])
181
+ }
182
+ function render(ctx,t,env){
183
+ if(!G||t<G.t0)return
184
+ const W=env.width,H=env.height,p=env.params||{},col=p.color||COL,look=p.look||LOOK
185
+ let q,fly=0
186
+ if(t<G.t1)q=held(t,W,H)
187
+ 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
188
+ 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])
189
+ q=r.map((p,i)=>[p[0]+(full[i][0]-p[0])*fly,p[1]+(full[i][1]-p[1])*fly])}
190
+ const card=canvasOf(CW,CH,false,col,look);if(!card)return
191
+ // shadow under the held card
192
+ 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()}
193
+ if(fly<1)QUAD(ctx,card,CW,CH,q)
194
+ 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()}}
195
+ // light: the card's edge glows while held, streaks while it flies
196
+ ctx.save();ctx.globalCompositeOperation='lighter';ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=24;ctx.lineWidth=2.4;ctx.globalAlpha=(1-fly)*.95
197
+ 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()
198
+ 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()}}
199
+ ctx.restore()
200
+ }`,xa=(t,e)=>`const ${t}=${JSON.stringify(e)};`;function ab({cfg:t,events:e=[],grab:o=null,hover:r=[],assets:a}){const n=[xa("HUD",t),xa("EV",e),xa("G",o),xa("FP",r),NS].join(`
201
+ `);return Qe({code:n,params:{color:t.color,look:t.look},preset:"hud-wall",...a&&Object.keys(a).length?{assets:a}:{}})}function Kd({card:t=null,grab:e=null,color:o=En.color,look:r="glass",assets:a}){const n=[xa("C",t),xa("G",e),xa("COL",o),xa("LOOK",r),RS].join(`
202
+ `);return Qe({code:n,params:{color:o,look:r},preset:"hud-grab",...a&&Object.keys(a).length?{assets:a}:{}})}function Th(t){const e={};for(const o of String(t?.code??"").split(`
203
+ `,4)){const r=/^const ([A-Z]+)=(.*);$/.exec(o);if(r)try{e[r[1]]=JSON.parse(r[2])}catch{}}return e}const ib=t=>t?.motion?.preset==="hud-wall";function DS({id:t,at:e,duration:o,cfg:r,assets:a,label:n}){if(!(o>=.2))throw Error("hudWall needs at least 0.2 s");return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:le(e),duration:le(Math.min(En.maxSeconds,o)),label:n||"Tường HUD",motionV:2,posX:0,posY:0,scale:1,motion:ab({cfg:r,assets:a})}}function Wd(t,e,o,r,a,n=null){if(t.pin&&!t.pin.scene){const c=Qg(t,e,o,r,a,n);if(c)return c}const i=Math.max(0,Math.min(t.duration,o-t.start));if(el(n)&&r2(t)){const c=n2(t,i,n,o,r,a);if(c)return c.quad}return a2(t,i,r,a)}function Hd(t){const[e,o,r,a]=t,n=o[0]-a[0],i=r[0]-a[0],c=o[1]-a[1],u=r[1]-a[1],p=e[0]-o[0]+a[0]-r[0],s=e[1]-o[1]+a[1]-r[1];let h=0,f=0;const m=n*u-i*c||1e-12;(Math.abs(p)>1e-9||Math.abs(s)>1e-9)&&(h=(p*u-i*s)/m,f=(n*s-p*c)/m);const g=o[0]-e[0]+h*o[0],v=r[0]-e[0]+f*r[0],x=e[0],E=o[1]-e[1]+h*o[1],$=r[1]-e[1]+f*r[1],S=e[1],k=(et,U)=>{const at=h*et+f*U+1;return[(g*et+v*U+x)/at,(E*et+$*U+S)/at]},y=$-S*f,C=x*f-v,A=v*S-x*$,z=S*h-E,j=g-x*h,P=x*E-g*S,F=E*f-$*h,N=v*h-g*f,G=g*$-v*E;return{apply:k,inverse:(et,U)=>{const at=F*et+N*U+G;return[(y*et+C*U+A)/at,(z*et+j*U+P)/at]}}}const kc=(t,e,o,r,a,n)=>{const i=t.crop||{left:0,right:0,top:0,bottom:0},c=1-i.left-i.right||1,u=1-i.top-i.bottom||1,p=Ic(t,(o[0]-i.left)/c,(o[1]-i.top)/u,r,a,n,e.mw,e.mh);return[p.px,p.py]};function Xi(t,e,o,{point:r="index",side:a="any",W:n=1280,H:i=720}={}){const c=o-t.start,u=Kc(t,c),p=sv(e,u,a),s=Wc(e,u,p);if(!s)return null;const h=kc(t,e,Vi(s,r),c,n,i),f=kc(t,e,s[9],c,n,i),m=kc(t,e,s[0],c,n,i);return{x:h[0],y:h[1],size:Math.hypot(f[0]-m[0],f[1]-m[1]),slot:p}}const sb=1/15;function BS(t,e,{point:o="index",side:r="any",scale:a=!1,offset:n=null,W:i=1280,H:c=720}={}){if(!e?.hands)throw Error("The footage has no hand track yet");const u=fl(e.hands),p=Math.max(t.start,e.start),s=Math.min(t.start+t.duration,e.start+e.duration);if(!(s-p>=1/30))throw Error("The layer and the footage do not play at the same time");const h=Math.max(1,Math.min(De.maxFrames,Math.ceil((s-p)/sb))),f=[];for(let k=0;k<=h;k++){const y=p+(s-p)*k/h,C=Xi(e,u,y,{point:o,side:r,W:i,H:c});C&&f.push({T:y,...C})}if(!f.length)throw Error("No hand is seen while the layer plays");const m={...t,...pn(t)},g=f[0],v=k=>le(k-t.start),x=Array.isArray(n)?Number(n[0])||0:Qt(m,"x",g.T-t.start)-(g.x-i/2)/i,E=Array.isArray(n)?Number(n[1])||0:Qt(m,"y",g.T-t.start)-(g.y-c/2)/c,$=Qt(m,"zoom",g.T-t.start)||1;let S={...m,motionV:2};return delete S.posX,delete S.posY,S={...S,...ge(S,"x",f.map(k=>({time:v(k.T),value:le((k.x-i/2)/i+x)})))},S={...S,...ge(S,"y",f.map(k=>({time:v(k.T),value:le((k.y-c/2)/c+E)})))},a&&(S={...S,...ge(S,"zoom",f.map(k=>({time:v(k.T),value:le(Math.max(.05,$*k.size/(g.size||1)))})))}),{motionV:2,motionKeys:S.motionKeys,posX:void 0,posY:void 0}}function N0(t,{until:e=1/0}={}){const o=fl(t.hands),r=t.crop||{left:0,right:0,top:0,bottom:0},a=1-r.left-r.right||1,n=1-r.top-r.bottom||1,i=Math.max(1,Math.ceil(o.n/600)),c=[];for(let u=0;u<De.slots;u++){const p=[];let s=null,h=null,f=null;for(let g=0;g<o.n;g+=i){const v=le(vy(t,o.s0+g/o.fps));if(v<0||v>t.duration+.001)continue;const x=o.frames[g][u];let E;if(x)E=cv(x.lm,o.mw,o.mh,{edge:x.edge}).map(([$,S])=>[le(Math.max(-.95,Math.min(1.95,($-r.left)/a))),le(Math.max(-.95,Math.min(1.95,(S-r.top)/n)))]),s===null&&(s=v),h=v,f=E;else{const $=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:nn},()=>[le($[0]),le($[1])])}p.length&&p.at(-1).t>=v||p.push({t:v,pts:E})}if(s===null)continue;const m=Math.min(h+1/o.fps,e);m<=s||c.push({id:`h${u+1}`,name:u?"Tay trái":"Tay phải",mode:"add",keys:p,feather:.0035,in:le(s),out:le(Math.min(t.duration,m))})}return c.length?{v:2,mw:o.mw,mh:o.mh,masks:c}:null}const Xd=(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 _S({wall:t,layer:e,src:o,clips:r,cam:a=null,W:n=1280,H:i=720,events:c=null,grab:u="auto",side:p="any",fly:s=.7}){if(!ib(t))throw Error("hudInteract needs a HUD wall layer (hudWall)");const h=Th(t.motion),f=h.HUD;if(!f)throw Error("The HUD wall has no settings");const m=o.hands?fl(o.hands):null,g=f.asp||n/i,v=qs(s,...En.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),$=(U,at,W)=>{const _=Hd(Wd(t,r,W,n,i,a)),[J,tt]=_.inverse(U,at);return zS(f,J,tt,g)},S=(U,at,W)=>{const _=Hd(Wd(t,r,W,n,i,a)),J=os(f,U,at,g),[tt,rt]=_.apply(J[0],J[1]);return[tt/n,rt/i]};let k;if(Array.isArray(c)&&c.length)k=c.map(U=>{const at=Number(U.t);if(!Number.isFinite(at)||!["tap","pinch","release"].includes(U.type))throw Error("hudInteract events: [{t (timeline s), type tap | pinch | release, point? [x, y]}]");let W,_;if(Array.isArray(U.point)&&U.point.length===2&&U.point.every(Number.isFinite))W=U.point[0]*n,_=U.point[1]*i;else{const J=m&&Xi(o,m,at,{point:U.type==="tap"?"index":"pinch",side:p,W:n,H:i});if(!J)throw Error(`hudInteract event at ${at}s: give point [x, y] (no hand seen there)`);W=J.x,_=J.y}return{type:U.type,T:at,x:W,y:_}}).sort((U,at)=>U.T-at.T);else{if(!m)throw Error("The footage has no hand track yet");const U=at=>p==="any"||(p==="right"?at===0:at===1);k=lv(m).filter(at=>U(at.slot)).map(at=>{const W=vy(o,at.s),_=o.start+W,[J,tt]=kc(o,m,[at.u,at.v],W,n,i);return{type:at.type,T:_,x:J,y:tt,slot:at.slot}})}k=k.filter(U=>U.T>=x-1e-6&&U.T<=E+1e-6);const y=[],C={taps:0,pinches:0,grabbed:null};let A=null,z=null;const j=U=>U.slot===1?"left":U.slot===0?"right":p,P=U=>{const at=k[U],W=k.slice(U+1).find(_=>_.type==="release"&&(_.slot===void 0||_.slot===at.slot));return Math.min(E-.05,W?W.T:E-v)};let F=-1,N=-1/0;u!==!1&&k.forEach((U,at)=>{if(U.type!=="pinch"||U.T<t.start+.6)return;const[W,_]=$(U.x,U.y,U.T),J=F0(f,W,_,.25),tt=P(at);if(J<0&&!Number.isInteger(u)||tt-U.T<.3||E-tt<Math.min(.5,v))return;const rt=m&&Xi(o,m,tt,{point:"pinch",side:j(U),W:n,H:i}),D=rt?Math.hypot(rt.x-U.x,rt.y-U.y)/n:0,q=Math.min(1.5,tt-U.T)+3*D;q>N&&(N=q,F=at)});for(let U=0;U<k.length;U++){const at=k[U];if(at.type==="release")continue;const[W,_]=$(at.x,at.y,at.T);let J=F0(f,W,_,at.type==="pinch"?.25:0);const tt=le(at.T-t.start);if(U===F){Number.isInteger(u)&&(J=Math.max(0,Math.min(f.cards.length-1,u)));const rt=P(U),[D,q,pt,yt]=rb(f,J),Mt=[[D,q],[pt,q],[D,yt],[pt,yt]].map(([K,d])=>S(K,d,at.T).map(le)),l=[],lt=Math.max(2,Math.ceil((rt+.15-at.T)*30));for(let K=0;K<=lt;K++){const d=at.T+(rt+.15-at.T)*K/lt,w=m&&Xi(o,m,d,{point:"pinch",side:j(at),W:n,H:i});w&&l.push([le(d-e.start),le(w.x/n),le(w.y/i),le(w.size/n)])}l.length||l.push([le(at.T-e.start),le(at.x/n),le(at.y/i),1]),A={k:J,t0:le(at.T-e.start),t1:le(rt-e.start),fly:wc(v),q:Mt,path:l},z=Kd({card:f.cards[J],grab:A,color:t.motion.params?.color??f.color,look:t.motion.params?.look??f.look,assets:t.motion.assets}),y.push({k:J,t:tt,a:le(W),b:le(_)}),C.pinches++,C.grabbed=J;continue}at.T<t.start+.35||W<-.05||W>1.05||_<-.05||_>1.05||(y.push({k:J,t:tt,a:le(W),b:le(_)}),at.type==="tap"?C.taps++:C.pinches++)}if(A)for(let U=y.length-1;U>=0;U--)y[U].k===A.k&&y[U].t>A.t0+e.start-t.start+1e-6&&y.splice(U,1);const G=[];if(m)for(let U=x;U<=E;U+=1/15){const at=Xi(o,m,U,{point:"index",side:p,W:n,H:i});if(!at)continue;const[W,_]=$(at.x,at.y,U);if(!(W<0||W>1||_<0||_>1)&&(G.push([le(U-t.start),wc(W),wc(_)]),G.length>=300))break}const V=ab({cfg:f,events:y,grab:A?{k:A.k,t0:le(A.t0+e.start-t.start)}:null,hover:G,assets:t.motion.assets});V.params={...V.params,...t.motion.params??{}},z||(z=Kd({card:null,grab:null,color:t.motion.params?.color??f.color,look:t.motion.params?.look??f.look}));const et=A?le(A.t1+e.start+v*.55-o.start):1/0;return{wall:V,grab:z,cutoutUntil:et,report:C}}function R0(t){const e=t.point??"index",o=t.hand??"any";if(!Vc.includes(e))throw Error(`handAttach point: ${Vc.join(" | ")}`);if(!Ed.includes(o))throw Error(`hand: ${Ed.join(" | ")}`);return{point:e,side:o}}const Ha=Object.freeze({dx:.01,dy:.035,opacity:.3,blur:.65,feather:.025});function VS(t,e,o,{cam:r=null,W:a=1280,H:n=720}={}){const i=Th(t.motion).HUD,c=i.asp||a/n,u=e.hands?.mw??a,p=e.hands?.mh??n,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,g=-1/0,v=-1/0;for(const E of[s,(s+h)/2,h-.001]){const $=Hd(Wd(t,o,E,a,n,r));for(const[S,k]of[[-.02,-.04],[1.02,-.04],[-.02,1.04],[1.02,1.04],[.5,-.04],[.5,1.04]]){const y=os(i,S,k,c),[C,A]=$.apply(y[0],y[1]),z=f1(e,C,A,E-e.start,a,n,u,p);f=Math.min(f,z.u),g=Math.max(g,z.u),m=Math.min(m,z.v),v=Math.max(v,z.v)}}const x=E=>le(Math.max(-.95,Math.min(1.95,E)));return{id:"wall",name:"Màn hình HUD",mode:"add",feather:Ha.feather,keys:[{t:0,pts:[[x(f),x(m)],[x(g),x(m)],[x(g),x(v)],[x(f),x(v)]]}]}}function GS(t,{id:e,wallMask:o,mw:r=1280,mh:a=720}){const{mask:n,person:i,...c}=t,u={...c,id:e,label:`${t.label?.replace(/ · tay$/,"")||"Video"} · bóng tay`,volume:0,hud:{...t.hud,role:"shadow"},brightness:0,opacity:Ha.opacity,effects:[{type:"blur",amount:Ha.blur}]};return Array.isArray(c.motionKeys)&&c.motionKeys.some(s=>Number.isFinite(s.x)||Number.isFinite(s.y))?u.motionKeys=c.motionKeys.map(s=>({...s,...Number.isFinite(s.x)?{x:le(s.x+Ha.dx)}:{},...Number.isFinite(s.y)?{y:le(s.y+Ha.dy)}:{}})):(u.posX=le((c.posX||0)+Ha.dx),u.posY=le((c.posY||0)+Ha.dy)),u.mask=i?{v:2,mw:r,mh:a,masks:[o]}:{v:2,mw:r,mh:a,masks:[{...Xd(r,a).masks[0]},{...o,mode:"intersect"}]},i&&(u.person=i),u}const ko=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}),D0=ko.presets,ip=1/30,Su=.4,Gl=(t,e,o)=>Math.max(e,Math.min(o,t)),KS=t=>+t.toFixed(4);function WS(t,e,o,r,a){const n=[];if(r==="rush")n.push({time:t,d:0,ease:"expo-in"},{time:e,d:a,ease:"hold"}),e+ip*2<o&&n.push({time:ut(e+ip*2),d:0});else if(r.startsWith("push")){const c=r==="push-left"?-1:1,u=Math.min(ko.push,(e-t)/3);n.push({time:t,d:0,ease:"expo-in"},{time:ut(t+u),d:c,ease:"hold"}),e>=o-1e-6?n.push({time:o,d:c}):n.push({time:ut(e-u),d:-c,ease:"expo-out"},{time:e,d:0})}else{const c=r==="down"||r==="right"?1:-1,u=Math.min(ko.ramp,(e-t)/3);n.push({time:t,d:0,ease:"expo-out"},{time:ut(t+u),d:c*a}),e>=o-1e-6?n.push({time:o,d:c*a}):n.push({time:ut(e-u),d:c*a,ease:"ease-in-out"},{time:e,d:0})}const i=[];for(const c of n)(!i.length||c.time>i.at(-1).time+1e-6)&&i.push(c);return i}function HS(t,{at:e,duration:o,preset:r="down",amount:a}={}){if(t.kind==="audio"||t.kind==="model"||t.title||t.shape||t.motion)throw Error("Make room needs a video or image clip");if(!ko.presets.includes(r))throw Error(`Make room preset must be ${ko.presets.join("/")}`);if(!Number.isFinite(e)||e<0||e>=t.duration-ip)throw Error("Make room must start inside the clip");const n=r==="rush",i=Gl(Number.isFinite(o)?o:3,n?.3:ko.minDuration,ko.maxDuration),c=n?Gl(Number.isFinite(a)?a:ko.defaults.rush,ko.rush.min,ko.rush.max):Gl(Number.isFinite(a)?a:ko.defaults[r],ko.minAmount,ko.maxAmount),u=ut(e);let p=ut(Math.min(t.duration,u+i));if(t.duration-p<ip&&(p=t.duration),p-u<(n?.3:ko.minDuration)-1e-6&&p<t.duration)throw Error("Make room is too short for the clip");const s=n?"zoom":r==="down"?"y":"x",h=WS(u,p,t.duration,r,c),f=h[0].time,m=h.at(-1).time,g=Ee(t,s).some(z=>z.time>f+.001&&z.time<m-.001),v=[...h];if(g)for(let z=f+Su;z<m-Su/2;z+=Su){const j=ut(z);if(!v.some(P=>Math.abs(P.time-j)<.001)){const P=v.findIndex(G=>G.time>j),F=v[P-1],N=v[P];v.splice(P,0,{time:j,d:F.ease==="hold"?F.d:F.d+(N.d-F.d)*(j-F.time)/(N.time-F.time)})}}const x=Ee(t,s).filter(z=>z.time<f-.001||z.time>m+.001),E=v.map(z=>({time:z.time,value:KS(n?Math.min(bs,Qt(t,s,z.time)*(1+z.d)):Gl(Qt(t,s,z.time)+z.d,-1,1)),...z.ease?{ease:Yt[z.ease]}:{}})),$={...t,...ge(t,s,[...x,...E].sort((z,j)=>z.time-j.time))};jn($);const{motionV:S,motionKeys:k,posX:y,posY:C,scale:A}=$;return{motionV:S,motionKeys:k,...y!==void 0?{posX:y,posY:C,scale:A}:{}}}const ur=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}}}),lr=t=>+t.toFixed(3),XS=t=>Math.max(-1,Math.min(1,t)),B0=(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 US({speakerClipId:t,portrait:e=!0,at:o,handoff:r,end:a,card:n,scene:i,rows:c=0,base:u=0}={}){if(!t||!n?.preset||!i?.preset)throw Error("A bridge needs the speaker clip, a card and a scene");if(o=+o,r=Math.max(+r,o+ur.minCard),a=Math.max(+a,r+ur.grow+ur.minScene),!Number.isFinite(o)||o<0||!Number.isFinite(a))throw Error("Bridge times must be timeline seconds");const p=$=>en(c+$),s=e?ur.centre.portrait:ur.centre.landscape,h=ur.zoom,f=lr(Math.max(0,o-ur.lead)),m=lr(r+ur.grow),g=lr(r+ur.grow*.6),v=lr(g+ur.sceneIn+.05),x=Math.min(ko.maxDuration,lr(v+ko.ramp+.2-f)),E=$=>`new:${u+$}`;return[{op:"makeRoom",clipId:t,at:f,duration:x,preset:e?"down":"left"},{op:"addMotion",motionPreset:"exp-room-panel",start:f,duration:lr(v-f),track:p(0),placement:"top"},{op:"addMotion",motionPreset:n.preset,start:lr(o),duration:lr(v-o),track:p(1),placement:"top",...B0(n)},{op:"setPropertyKeys",clipId:E(2),property:"zoom",propertyKeys:[{time:lr(r-o),value:1,ease:"ease-in"},{time:lr(m-o),value:h}]},{op:"setPropertyKeys",clipId:E(2),property:s.prop,propertyKeys:[{time:lr(r-o),value:0,ease:"ease-in"},{time:lr(m-o),value:lr(XS(s.off*h))}]},{op:"addMotion",motionPreset:i.preset,start:g,duration:lr(a-g),track:p(2),placement:"center",...B0(i)},{op:"setAnimation",clipId:E(3),property:"enter",preset:"zoom-in",duration:ur.sceneIn,numberValue:.35}]}const lb={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"},_0=Object.freeze(["zoom-through","push","match-zoom",...Object.keys(lb)]),YS={flash:.8,whip:.8,glitch:.8,slab:1,iris:1,stripes:1,ink:1.2,shapes:1.2,tunnel:1.2},Ra=t=>+(+t).toFixed(3),V0=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},sp=t=>/^(add|lockup$)/.test(t?.op??"");function qS(t,{portrait:e=!1,rows:o=1,base:r=0}={}){const a=t.preset,n=+t.at,i=Math.max(1,+t.duration||4),c=t.booleanValue!==!1,u=t.fromClipId;if(!_0.includes(a))throw Error(`Bridge kind must be ${_0.join("/")}`);if(!Number.isFinite(n)||n<0)throw Error("Bridge needs at (timeline seconds of the cut)");if(!u)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 p=x=>en(o+x),s=x=>`new:${r+x}`,h=Ra(n+i),f=[],m=(x,E,$)=>t.clipId?t.clipId:(f.push({op:"addMotion",motionPreset:t.motionPreset,start:Ra(x),duration:Ra(E),track:$,placement:"center",...V0(t)}),s(f.filter(sp).length));if(a==="zoom-through"){if(t.clipId)throw Error("zoom-through grows into a new scene: give motionPreset, not clipId");const x=Math.max(ur.minCard,n-ur.grow*.6),E=US({speakerClipId:u,portrait:e,at:Math.max(0,x-ur.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($=>$.op==="addMotion"&&$.motionPreset===t.motionPreset?{...$,...V0(t)}:$)),c){const $=f.filter(sp).length;f.push({op:"setAnimation",clipId:s($),property:"exit",preset:"zoom-out",duration:.4,numberValue:.3})}return f}if(a==="push"){const x=ko.push;f.push({op:"makeRoom",clipId:u,at:Ra(Math.max(0,n-x*.5)),duration:Ra(Math.min(ko.maxDuration,i+x)),preset:"push-left"});const E=m(n-x*.5,i+x*.5,p(0));return f.push({op:"setAnimation",clipId:E,property:"enter",preset:"slide-left",duration:x,numberValue:1,booleanValue:!1}),c&&f.push({op:"setAnimation",clipId:E,property:"exit",preset:"slide-left",duration:x,numberValue:1,booleanValue:!1}),f}if(a==="match-zoom"){const x=.4666666666666667;f.push({op:"makeRoom",clipId:u,at:Math.max(0,Math.round((n-x)*30)/30),duration:x,preset:"rush"});const E=m(n,i,p(0));return f.push({op:"setAnimation",clipId:E,property:"enter",preset:"zoom-out",duration:.45,numberValue:.45,booleanValue:!1}),c&&f.push({op:"setAnimation",clipId:E,property:"exit",preset:"zoom-in",duration:.35,numberValue:.4,booleanValue:!1}),f}const g=YS[a],v=lb[a];return m(n,i,p(0)),f.push({op:"addMotion",motionPreset:v,start:Ra(Math.max(0,n-g/2)),duration:g,track:p(1),...t.color?{color:t.color}:{}}),c&&f.push({op:"addMotion",motionPreset:v,start:Ra(Math.max(0,h-g/2)),duration:g,track:p(1),...t.color?{color:t.color}:{}}),f}function ZS(t,{portrait:e=!1}={}){if(!t.some(c=>c?.op==="bridge"))return t;const o=[],r=[];let a=0,n=0;const i=c=>{const u=s=>{const h=typeof s=="string"&&/^new:(\d+)$/.exec(s);if(!h)return s;const f=+h[1];let m=0;for(const g of r)f>g.after&&(m+=g.by);return`new:${f+m}`},p={...c};return p.clipId&&(p.clipId=u(p.clipId)),p.fromClipId&&(p.fromClipId=u(p.fromClipId)),p.sourceClipId&&(p.sourceClipId=u(p.sourceClipId)),Array.isArray(p.clipIds)&&(p.clipIds=p.clipIds.map(u)),p};for(const c of t){const u=i(c);if(u?.op!=="bridge"){o.push(u),sp(u)&&(a++,n++);continue}const p=qS(u,{portrait:e,base:a}),s=p.filter(sp).length;o.push(...p),s&&r.push({after:n,by:s}),a+=s}return o}const cb=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]}}),PT=Object.keys(cb),G0=8,JS=.25,Ma=t=>Math.round(t*1e3)/1e3,Ud=(t,e)=>Math.max(Vr[t].min,Math.min(Vr[t].max,e));function QS(t,e,o){const r=n=>n.map(i=>t.find(c=>c.id===i)).filter(i=>i&&i.kind!=="audio");return(o?.length?o.map(r).filter(n=>n.length):r(e).sort((n,i)=>n.start-i.start).reduce((n,i)=>{const c=n.at(-1);return c&&i.start-c[0].start<JS?c.push(i):n.push([i]),n},[])).map(n=>({clips:n,time:Math.min(...n.map(i=>i.start))})).sort((n,i)=>n.time-i.time)}function t8(t,e,o){if(!o)return{};const r=Ee(t,e);return r.length?ge(t,e,r.map(a=>({...a,value:Ma(Ud(e,a.value+o))}))):Ep(t,e,Ma(Ud(e,Qt(t,e,0)+o)),0)}function e8(t,e,o,{style:r="fly-truck",travel:a=1,spacing:n=1.2,swing:i=!0,push:c=!0,groups:u}={}){const p=cb[r];if(!p)throw Error(`Unknown stations style "${r}"`);if(!(a>=.2&&a<=5))throw Error("Flight time must be 0.2–5 s");if(!(n>=.5&&n<=3))throw Error("Station spacing must be 0.5–3");const s=QS(t,e,u);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>G0)throw Error(`At most ${G0} stations`);const h=s.length,f=s.map((j,P)=>p.at(P,n));if(f.some(j=>Math.abs(j[0])>Vr.x.max||Math.abs(j[1])>Vr.y.max||j[2]<fh+5))throw Error("Too many stations for this spacing — lower the spacing");const m={},g=[],v=new Set(s.flatMap(j=>j.clips.map(P=>P.id)));s.forEach((j,P)=>{const F=(tt,rt)=>rt?Math.round(tt.reduce((D,q)=>D+q,0)/tt.length/rt)*rt:0,N=j.clips.filter(tt=>!tt.parentId||!v.has(tt.parentId));if(!N.length)return;const[G,V,et]=f[P],U=p.at(1,n)[0]||0,at=p.at(1,n)[1]||p.at(2,n)[1]||0,W=p.at(1,n)[2]||0,_=[F(N.map(tt=>Qt(tt,"x",0)),U),F(N.map(tt=>Qt(tt,"y",0)),Math.abs(at)),F(N.map(tt=>Qt(tt,"depth",0)),Math.abs(W))];for(const tt of N){let rt={...tt,is3D:!0},D={is3D:!0};for(const[q,pt]of[[0,"x"],[1,"y"],[2,"depth"]]){const yt=Ma([G,V,et][q]-_[q]),Mt=t8(rt,pt,yt);rt={...rt,...Mt},D={...D,...Mt}}m[tt.id]=D}const J=P<h-1?s[P+1].time+a:null;if(J!=null)for(const tt of j.clips)tt.kind!=="video"&&tt.start+tt.duration<J&&(m[tt.id]={...m[tt.id],duration:Ma(J-tt.start)},g.push(tt.id))});const x=Yt["expo-in-out"],E=Yt.linear,$=s[0].time,S=s.at(-1).time+a;let k={...o??{...jr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]};const y=dl(k,"roll",$),C=j=>({cx:f[j][0],cy:f[j][1],cz:-5-f[j][2]}),A={cx:[],cy:[],cz:[],roll:[]},z=(j,P,F,N)=>A[j].push({time:Ma(P),value:Ma(Math.max(Zn[j].min,Math.min(Zn[j].max,F))),...N?{ease:N}:{}});if(s.forEach((j,P)=>{const F=C(P),N=P?j.time+a:$,G=P<h-1?s[P+1].time:null;for(const V of["cx","cy","cz"])z(V,N,F[V],c&&V==="cz"?E:x);if(G!=null&&G-N>.3){const V=c?Math.min(.35,(G-N)*.12):0;for(const et of["cx","cy"])z(et,G,F[et],x);z("cz",G,F.cz+V,x)}}),i){const j=(F,N)=>Math.sign(N[0]-F[0]||N[1]-F[1]||1),P=Yt["sine-in-out"];z("roll",$,y),s.forEach((F,N)=>{if(!N)return;const G=j(f[N-1],f[N]);z("roll",F.time,y,P),z("roll",F.time+a/2,y-6*G,P),z("roll",F.time+a,y)})}for(const[j,P]of Object.entries(A)){if(!P.length)continue;const N=[...cs(k,j).filter(G=>G.time<$-1e-6||G.time>S+1e-6),...P].sort((G,V)=>G.time-V.time).filter((G,V,et)=>!V||Math.abs(G.time-et[V-1].time)>1/120);k=In(k,j,N)}return{patches:m,camera:_r(k),stations:h,extended:g}}function o8(t,e,{strength:o=1}={}){if(!(o>=.25&&o<=3))throw Error("Parallax strength must be 0.25–3");const r=t.filter(p=>e.includes(p.id)&&p.kind!=="audio");if(r.length<2)throw Error("Chọn ít nhất 2 layer để tách lớp parallax");const a=m1(r,()=>0),n=a.length,i=Math.min(3,1.2*o),c=Math.max(fh+1,-6*o),u={};return a.forEach((p,s)=>{const h=Ma(c+(i-c)*s/(n-1)),f=Qt(p,"depth",0),m=(5-h)/(5-Math.min(4.5,f));let g={...p,is3D:!0},v={is3D:!0};for(const x of["depth","zoom","x","y"]){const E=k=>Ma(Ud(x,x==="depth"?k+h-f:k*m)),$=Ee(g,x),S=$.length?ge(g,x,$.map(k=>({...k,value:E(k.value)}))):Ep(g,x,E(Qt(g,x,0)),0);g={...g,...S},v={...v,...S}}u[p.id]=v}),u}const pb=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"}}),LT=Object.keys(pb),K0=48,r8=["x","y","depth","zoom","rot","tiltX","tiltY"],Bo=t=>Math.round(t*1e3)/1e3,ii=t=>t*Math.PI/180,rs=t=>t*180/Math.PI,W0=(t,e)=>Math.max(Vr[t].min,Math.min(Vr[t].max,e));function n8(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 a8(t,e,{rot:o=0,tiltX:r=0,tiltY:a=0}){const n=ii(o),i=ii(r),c=ii(a),u=t*Math.cos(n)-e*Math.sin(n),p=t*Math.sin(n)+e*Math.cos(n),s=p*Math.cos(i),h=-p*Math.sin(i);return[u*Math.cos(c)-h*Math.sin(c),s,u*Math.sin(c)+h*Math.cos(c)]}function i8(t,e,{W:o=1280,H:r=720,spread:a=1,ids:n=[]}={}){const i=Br(o,r),c=[],u=([p,s,h],f)=>({x:p/o,y:s/r,depth:-h/i,...f});if(e==="wall"){const p=Math.max(1,Math.min(t,Math.ceil(Math.sqrt(t*1.4)))),s=Math.ceil(t/p),h=.1*a,f=Math.min(.6,1.6/(p*(1+h))),m={rot:-8,tiltX:26,tiltY:-20};for(let g=0;g<t;g++){const v=g%p,x=Math.floor(g/p);c.push(u(a8((v-(p-1)/2)*o*f*(1+h),(x-(s-1)/2)*r*f*(1+h),m),{zoom:f,...m}))}}else if(e==="arc"){const p=Math.min(.75,2.4/t),s=o*p*(1+.012*a),h=4.2*i/Math.max(.5,a),f=s/h;for(let m=0;m<t;m++){const g=(m-(t-1)/2)*f;c.push(u([h*Math.sin(g),0,h*(Math.cos(g)-1)],{zoom:p,rot:0,tiltX:0,tiltY:-rs(g)}))}}else if(e==="fan"){const s=Math.min(14,70/Math.max(1,t-1))*a,h=r*.42*1.15;for(let f=0;f<t;f++){const m=(f-(t-1)/2)*s,g=ii(m);c.push(u([h*Math.sin(g),r*.12+h*(1-Math.cos(g)),-f*.04*i],{zoom:.42,rot:m,tiltX:0,tiltY:0}))}}else if(e==="scatter")for(let s=0;s<t;s++){const h=n8(n[s]??s),f=Math.min(2,a);c.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 p=0;p<t;p++)c.push({x:.05*p*a,y:-.035*p*a,depth:-1.4*p*a,zoom:1,rot:p%2?-2:2,tiltX:0,tiltY:-10});else if(e==="boards")for(let p=0;p<t;p++){const s=p%2?1:-1;c.push({x:1.25*p*a,y:s*.12*a,depth:-2.2*p*a,zoom:1,rot:s*-3,tiltX:s*-6,tiltY:s*28})}else throw Error(`Unknown 3D layout "${e}"`);return c}function ub(t,e,o,{W:r=1280,H:a=720,spread:n=1}={}){if(!pb[o])throw Error(`Unknown 3D layout "${o}"`);if(!(n>=.5&&n<=2))throw Error("Layout spread must be 0.5–2");const i=new Map(t.map(s=>[s.id,s]));let c=e.map(s=>i.get(s)).filter(s=>s&&s.kind!=="audio");if(c.length<2)throw Error("Chọn ít nhất 2 layer để sắp xếp 3D");if(c.length>K0)throw Error(`At most ${K0} layers`);o==="stack"&&(c=m1(c,()=>0).reverse());const u=i8(c.length,o,{W:r,H:a,spread:n,ids:c.map(s=>s.id)}),p={};return c.forEach((s,h)=>{let f={...s,is3D:!0},m={is3D:!0};for(const g of r8){const v=Bo(W0(g,u[h][g])),x=Ee(f,g),E=x.length?ge(f,g,x.map($=>({...$,value:Bo(W0(g,$.value+v-x[0].value))}))):Ep(f,g,v,0);f={...f,...E},m={...m,...E}}p[s.id]=m}),p}function H0(t,e,o,r,{margin:a=1}={}){const n=Br(o,r),{center:i,corners:[c,u,p]}=sc(t,e,o,r),s=(F,N)=>F.map((G,V)=>G-N[V]),h=F=>Math.hypot(...F),f=F=>{const N=h(F)||1;return F.map(G=>G/N)},m=s(u,c),g=s(p,c),v=h(m);if(!(v>1))throw Error("Layer này quá nhỏ để camera nhìn vào");const x=f([m[1]*g[2]-m[2]*g[1],m[2]*g[0]-m[0]*g[2],m[0]*g[1]-m[1]*g[0]]),E=5*n*v/o*a,$=i.map((F,N)=>F-x[N]*E),S=rs(Math.asin(Math.max(-1,Math.min(1,-x[1])))),k=rs(Math.atan2(x[0],x[2])),y=ii(k),C=ii(S),A=[Math.cos(y),0,-Math.sin(y)],z=[Math.sin(y)*Math.sin(C),Math.cos(C),Math.cos(y)*Math.sin(C)],j=f(m),P=rs(Math.atan2(j[0]*z[0]+j[1]*z[1]+j[2]*z[2],j[0]*A[0]+j[1]*A[1]+j[2]*A[2]));return{cx:$[0]/o,cy:$[1]/r,cz:$[2]/n,pan:k,tilt:S,roll:P}}const s8=(t,e)=>e==null?t:t+360*Math.round((e-t)/360);function Yd(t,e,o,{at:r=0,flight:a=1,hold:n=1.5,margin:i=1,push:c=!0,W:u=1280,H:p=720}={}){if(!(a>=.2&&a<=12))throw Error("Flight time must be 0.2–12 s");if(!(n>=0&&n<=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(y=>[y.id,y])),h=e.map(y=>s.get(y)).filter(y=>y&&y.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??{...jr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},m=["cx","cy","cz","pan","tilt","roll"],g=Object.fromEntries(m.map(y=>[y,[]])),v=(y,C,A,z)=>g[y].push({time:Bo(C),value:Bo(Math.max(Zn[y].min,Math.min(Zn[y].max,A))),...z?{ease:z}:{}}),x=Yt["expo-in-out"],E=Yt.linear,$=Object.fromEntries(m.map(y=>[y,dl(f,y,r)]));for(const y of m)v(y,r,$[y],x);let S=r;h.forEach((y,C)=>{const A=S+a,z=Math.max(0,Math.min(y.duration,A-y.start)),j=H0({...y,is3D:!0},z,u,p,{margin:i});for(const F of["pan","roll"])j[F]=s8(j[F],$[F]);const P=C===h.length-1;for(const F of m)v(F,A,j[F],F==="cz"&&c&&n>0?E:x);if(n>0){const F=A+n,N=c?Math.min(.04,n*.015):0,G=H0({...y,is3D:!0},z,u,p,{margin:i*(1-N)});for(const V of m)v(V,F,V==="pan"||V==="roll"?j[V]:G[V],P?void 0:x);S=F}else S=A;Object.assign($,j)});let k=f;for(const y of m){const C=cs(k,y).filter(A=>A.time<r-1e-6||A.time>S+1e-6);k=In(k,y,[...C,...g[y]].sort((A,z)=>A.time-z.time).filter((A,z,j)=>!z||Math.abs(A.time-j[z-1].time)>1/120))}return{camera:_r(k),end:Bo(S)}}const db=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}]);db.map(t=>t.id);function l8(t,e,o,r,{at:a,W:n=1280,H:i=720}={}){const c=db.find(g=>g.id===r);if(!c)throw Error(`Unknown 3D scene "${r}"`);const u=ub(t,e,c.layout,{W:n,H:i}),p=new Map(t.map(g=>[g.id,g])),s=e.filter(g=>u[g]),h=t.map(g=>u[g.id]?{...g,...u[g.id]}:g),f=Number.isFinite(a)?a:Math.min(...s.map(g=>p.get(g).start));let m;if(c.camera==="tour")m=Yd(h,c.layout==="stack"?[...s].sort((g,v)=>Qt({...p.get(v),...u[v]},"depth",0)-Qt({...p.get(g),...u[g]},"depth",0)):s,o,{at:f,flight:c.flight,hold:c.hold,margin:c.margin,W:n,H:i});else if(c.camera==="glide"||c.camera==="sweep"){const g=Br(n,i),v=s.map(A=>{const z=h.find(j=>j.id===A);return sc(z,0,n,i).center}),x=Math.min(12,Math.max(4,s.length*.8)),E=f+x,$={...o??{...jr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},S=Yt["sine-in-out"],k={cx:[],cy:[],cz:[],pan:[],tilt:[],roll:[]},y=(A,z,j,P)=>k[A].push({time:Bo(z),value:Bo(Math.max(Zn[A].min,Math.min(Zn[A].max,j))),...P?{ease:P}:{}});if(c.camera==="glide"){const A=h.find(N=>N.id===s[0]),z=Math.hypot(...sc(A,0,n,i).corners[1].map((N,G)=>N-sc(A,0,n,i).corners[0][G])),j=5*g*z/n*c.margin,P=v[0],F=v.at(-1);y("cx",f,P[0]/n,S),y("cx",E,F[0]/n),y("cy",f,P[1]/i,S),y("cy",E,F[1]/i),y("cz",f,(P[2]-j)/g,S),y("cz",E,(F[2]-j)/g);for(const N of["pan","tilt"])y(N,f,0);y("roll",f,-3,S),y("roll",E,2)}else{const z=j=>rs(Math.atan2(j[0],j[2]+7.5*g))*.8;y("cx",f,0),y("cy",f,0),y("cz",f,-7.5),y("tilt",f,0),y("roll",f,0),y("pan",f,z(v[0]),S),y("pan",E,z(v.at(-1)))}let C=$;for(const[A,z]of Object.entries(k))z.length&&(C=In(C,A,[...cs(C,A).filter(j=>j.time<f-1e-6||j.time>E+1e-6),...z].sort((j,P)=>j.time-P.time)));m={camera:_r(C),end:Bo(E)}}else if(c.camera==="push")m=Yd(h,[s[Math.floor(s.length/2)]],o,{at:f,flight:c.flight,hold:c.hold,margin:c.margin,W:n,H:i});else{const g={...o??{...jr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},v=Math.max(4,s.length*1.2),x=5,E=f+v,$=Yt["sine-in-out"],S={cx:[],cz:[],pan:[]};for(let y=0;y<=4;y++){const C=ii(-40+y*20),A=f+v*y/4,z=x-1.2*y/4;S.cx.push({time:Bo(A),value:Bo(Math.sin(C)*z*Br(n,i)/n),ease:$}),S.cz.push({time:Bo(A),value:Bo(-Math.cos(C)*z),ease:$}),S.pan.push({time:Bo(A),value:Bo(-rs(C)),ease:$})}let k=g;for(const[y,C]of Object.entries(S))k=In(k,y,[...cs(k,y).filter(A=>A.time<f-1e-6||A.time>E+1e-6),...C].sort((A,z)=>A.time-z.time));m={camera:_r(k),end:Bo(E)}}for(const g of s){const v=p.get(g);v.kind!=="video"&&v.start+v.duration<m.end&&(u[g]={...u[g],duration:Bo(m.end-v.start)})}return{patches:u,camera:m.camera,end:m.end}}const Da=Object.freeze({angle:300,strips:[3,10],samples:16}),c8=Object.freeze(["center","start","end"]),Iu=["posX","posY","scale","scaleX","scaleY","rotation","tiltX","tiltY","spatialDepth","anchorX","anchorY","motionKeys","motionV","parentId","zIndex"],Do=t=>Math.round(t*1e4)/1e4;function p8(t,e){const o=t.find(a=>a.id===e);if(!o)return null;if(o.bend)return o;const r=o.parentId?t.find(a=>a.id===o.parentId):null;return r?.bend&&o.bendStrip?r:t.find(a=>a.bend?.source===e)??null}function hb(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 a=(r??[]).find(n=>n&&(n.url===t.url||t.nodeId&&n.id===t.nodeId));return a?.width&&a?.height?a.width/a.height:e/o}function u8(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 a=(r??[]).find(n=>n&&(n.url===t.url||t.nodeId&&n.id===t.nodeId));return a?.width&&a?.height?[a.width,a.height]:null}function d8(t,e,o,r,a=0){const n=o*Math.PI/180,i=(t+.5)/e-.5;if(Math.abs(n)<1e-6)return{along:i*r,depth:0,turn:0,chord:1};const c=r/n,u=n/e,p=(i-a)*n,s=c*Math.cos(u/2);return{along:a*r+s*Math.sin(p),depth:c-s*Math.cos(p),turn:p*180/Math.PI,chord:Math.abs(2*c*Math.sin(u/2))/(r/e)}}function h8(t,e,o,r,{angle:a=60,angleTo:n,angleKeys:i,axis:c,anchor:u,strips:p,aspect:s,media:h,newId:f,W:m=1280,H:g=720}={}){if(typeof f!="function")throw Error("bendPlan needs newId");const v=Y=>Y!=null&&Number.isFinite(+Y);if(!v(a)||Math.abs(a)>Da.angle||n!=null&&(!v(n)||Math.abs(n)>Da.angle))throw Error("Góc uốn từ −300° đến 300°");const x=p8(t,o),E=new Map(t.map(Y=>[Y.id,Y])),$=x?E.get(x.bend.source):E.get(o);if(!$)throw Error("Không thấy layer để uốn");if($.kind!=="image"||$.nullLayer||$.solid||$.fit==="cover"||$.geo||$.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),y={},C=[],A=f8(x?S[0]?.motionKeys:$.motionKeys),z=x?E.get(x.bend.source):E.get(o),j=Array.isArray(i)&&i.length?i.map(Y=>({time:+Y?.time,angle:+Y?.angle})):null;if(j&&(j.length<2||j.length>24||j.some((Y,ct)=>!Number.isFinite(Y.time)||!Number.isFinite(Y.angle)||Math.abs(Y.angle)>Da.angle||Y.time<0||Y.time>(z?.duration??1/0)+1e-6||ct&&Y.time<=j[ct-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(!+a&&!(v(n)&&+n)&&!j?.some(Y=>Y.angle)){if(x){k.push(x.id);const Y=X0(x.motionKeys,A);y[$.id]={disabled:void 0,...Object.fromEntries(Iu.map(ct=>[ct,x[ct]])),motionKeys:Y.length?Y:void 0}}return{add:C,patches:y,remove:k,camera:r??null,end:$.start+$.duration}}const F=c==="y"||!c&&x?.bend.axis==="y"?"y":"x";if(u!=null&&!c8.includes(u))throw Error("Điểm giữ: center, start hoặc end");const N=u??x?.bend.anchor??"center",G=N==="start"?-.5:N==="end"?.5:0,V=Math.max(Da.strips[0],Math.min(Da.strips[1],Math.round(p??x?.bend.strips??8))),et=$.crop??{left:0,right:0,top:0,bottom:0},U=1-et.left-et.right,at=1-et.top-et.bottom,W=(v(s)&&s>0?+s:hb($,m,g,h))*U/at,_=Y=>Y<=m/g?[g*Y,g]:[m,m/Y],[J,tt]=_(W),rt=F==="x"?J:tt,D=Math.min(V,Math.floor((F==="x"?U:at)/.1+1e-9));if(D<Da.strips[0])throw Error("Layer đã cắt quá hẹp để uốn");const q=Br(m,g),pt=Math.min($.motionBlur?.05:.012,.3/D),yt=t.filter(Y=>!k.includes(Y.id)),Mt=Y=>{const{track:ct}=Kt(yt,e,Y.start,Y.start+Y.duration),mt={...Y,track:ct};return yt.push(mt),mt},l=x?{...x}:Mt({...Cr({id:f(),track:0,start:$.start,duration:$.duration,label:`Uốn cong · ${String($.label||"").slice(0,40)}`,is3D:!0}),...Object.fromEntries(Iu.filter(Y=>$[Y]!==void 0).map(Y=>[Y,$[Y]])),...$.motionKeys?{motionKeys:m8($.motionKeys)}:{},is3D:!0}),lt={source:$.id,angle:Do(j?j[0].angle:+a),axis:F,strips:D,...G?{anchor:N}:{},...j?{angleKeys:j.map(Y=>({time:Do(Y.time),angle:Do(Y.angle)}))}:v(n)?{angleTo:Do(+n)}:{}};x?y[x.id]={bend:lt}:(l.bend=lt,C.push(l));const K=u8($,m,g,h)?.[F==="x"?0:1],d=F==="x"?et.left:et.top,w=F==="x"?U:at,T=Y=>{if(!K)return Y;const ct=Math.round((d+Y*w)*K/2)*2/K;return Math.max(0,Math.min(1,(ct-d)/w))},I=Y=>Math.round(Y*1e6)/1e6,O=(Y,ct)=>{const mt=I(d+Y*w),Q=I(1-(d+ct*w));if(!K)return{lo:Y,hi:ct,a0:mt,b0:Q};const nt=Math.trunc(K*mt/2)*2,dt=Math.max(2,Math.trunc(K*(1-mt-Q)/2)*2);return{lo:(nt/K-d)/w,hi:((nt+dt)/K-d)/w,a0:mt,b0:Q}},L=Y=>{const{lo:ct,hi:mt,a0:Q,b0:nt}=O(T(Math.max(0,Y/D-(Y?pt:0))),T(Math.min(1,(Y+1)/D+(Y<D-1?pt:0)))),[dt,vt]=_(F==="x"?W*(mt-ct):W/(mt-ct));return{lo:ct,hi:mt,a0:Q,b0:nt,zoom:F==="x"?tt/vt:J/dt}},B=(Y,ct)=>{const mt=d8(Y,D,ct,rt,G),{lo:Q,hi:nt,zoom:dt}=L(Y),vt=((Q+nt)/2-(Y+.5)/D)*rt,It=mt.turn*Math.PI/180,xt=mt.along+vt*mt.chord*Math.cos(It),Et=mt.depth+vt*mt.chord*Math.sin(It);return F==="x"?{x:Do(xt/m),depth:Do(Et/q),tiltY:Do(-mt.turn),zoom:Do(dt),sx:Do(mt.chord)}:{y:Do(xt/g),depth:Do(Et/q),tiltX:Do(mt.turn),zoom:Do(dt),sy:Do(mt.chord)}},H=Yt["sine-in-out"],Z=j?j.map(Y=>[Y.time,Y.angle]):v(n)&&+n!=+a?[[0,+a],[$.duration,+n]]:null,ot=Z?Z.slice(1).flatMap(([Y,ct],mt)=>{const[Q,nt]=Z[mt],dt=Math.max(2,Math.floor(Da.samples*2/Z.length));return Array.from({length:dt+(mt?0:1)},(vt,It)=>{const xt=(It+(mt?1:0))/dt;return[Q+(Y-Q)*xt,nt+(ct-nt)*g8(H,xt)]})}):null,st=Object.fromEntries(Object.entries($).filter(([Y])=>!Iu.includes(Y)&&!["id","track","disabled","bendStrip"].includes(Y)));for(let Y=0;Y<D;Y++){const{a0:ct,b0:mt}=L(Y),Q=F==="x"?{left:ct,right:mt,top:et.top,bottom:et.bottom}:{left:et.left,right:et.right,top:ct,bottom:mt},nt=B(Y,j?j[0].angle:+a),dt={posX:nt.x,posY:nt.y,spatialDepth:nt.depth,tiltX:nt.tiltX,tiltY:nt.tiltY,scale:nt.zoom,scaleX:nt.sx,scaleY:nt.sy},vt=ot?ot.map(([Et,Ct])=>{const{zoom:Gt,...ee}=B(Y,Ct);return{time:Do(Et),...Object.fromEntries(Object.entries(ee).filter(([,re])=>re!==void 0))}}):[],It=X0(vt,A),xt=Mt({...st,id:f(),label:`${String($.label||"Layer").slice(0,40)} · ${Y+1}/${D}`,start:$.start,duration:$.duration,parentId:l.id,is3D:!0,bendStrip:!0,crop:Q,...Object.fromEntries(Object.entries(dt).filter(([,Et])=>Et!==void 0)),...It.length?{motionV:2,motionKeys:It}:{}});C.push(xt)}return x||(y[$.id]={disabled:!0}),{add:C,patches:y,remove:k,camera:_r({...r??{...jr,motionKeys:[]},enabled:!0}),end:$.start+$.duration}}const f8=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 m8(t){return t.map(e=>{const{opacity:o,ease:r,...a}=e,n=r?Object.fromEntries(Object.entries(r).filter(([i])=>i!=="opacity")):null;return{...a,...n&&Object.keys(n).length?{ease:n}:{}}}).filter(e=>Object.keys(e).some(o=>o!=="time"&&o!=="ease"))}function X0(t,e){const o=new Map;for(const r of[...t??[],...e??[]]){const a=Do(r.time),n=o.get(a);o.set(a,n?{...n,...r,time:a,...n.ease||r.ease?{ease:{...n.ease,...r.ease}}:{}}:{...r,time:a})}return[...o.values()].sort((r,a)=>r.time-a.time)}function g8(t,e){const[o,r,a,n]=t,i=(p,s,h)=>3*p*h*(1-h)**2+3*s*h*h*(1-h)+h**3;let c=0,u=1;for(let p=0;p<30;p++){const s=(c+u)/2;i(o,a,s)<e?c=s:u=s}return i(r,n,(c+u)/2)}const fb=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"}]),y8=fb.map(t=>t.id),We=t=>Math.round(t*1e3)/1e3,b8=Yt.linear,Au=Yt["sine-in-out"];function vi(t,e,o){const{track:r}=Kt(t,e,o.start,o.start+o.duration),a={...o,track:r};return t.push(a),a}const Cu=t=>({motionV:2,motionKeys:t.map(([e,o,r])=>({time:We(e),...o,...r?{ease:Object.fromEntries(Object.keys(o).map(a=>[a,r]))}:{}}))});function w8(t,e,o,r,a,{at:n,newId:i,W:c=1280,H:u=720,duration:p,angle:s,angleTo:h,angleKeys:f,axis:m,anchor:g,media:v}={}){if(!fb.some(F=>F.id===a))throw Error(`Unknown 3D null rig "${a}"`);if(typeof i!="function")throw Error("nullRigPlan needs newId");if(a==="bend"){if(o.length!==1)throw Error("Chọn 1 layer để uốn cong");return h8(t,e,o[0],r,{angle:s??60,angleTo:h,angleKeys:f,axis:m,anchor:g,newId:i,W:c,H:u,media:v})}const x=new Map(t.map(F=>[F.id,F])),E=o.map(F=>x.get(F)).filter(F=>F&&F.kind!=="audio"&&!F.nullLayer);if(a!=="cube-spin"&&!E.length)throw Error("Chọn layer để dựng rig null 3D");const $=Number.isFinite(n)?n:E.length?Math.min(...E.map(F=>F.start)):0,S=We(Math.max(2,Math.min(30,p??6))),k=We($+S),y=Br(c,u),C=[...t],A=[],z={},j=F=>{z[F.id]={...z[F.id]??{},is3D:!0,...F.kind!=="video"&&F.start+F.duration<k?{duration:We(k-F.start)}:{}}};let P=r;if(a==="orbit-system"){const F=vi(C,e,{...Cr({id:i(),track:0,start:$,duration:S,label:"Quỹ đạo",is3D:!0}),posY:.06,tiltX:-70});A.push(F);const N=vi(C,e,{...Cr({id:i(),track:0,start:$,duration:S,label:"Vòng quay",is3D:!0}),parentId:F.id,...Cu([[0,{tiltY:0},b8],[S,{tiltY:360}]])});A.push(N);const G=.3,V=E.length;E.forEach((et,U)=>{const at=2*Math.PI*U/V;z[et.id]={parentId:N.id,is3D:!0,posX:We(G*Math.cos(at)),posY:0,spatialDepth:We(G*Math.sin(at)*c/y),scale:We(Math.min(.24,.9/Math.max(3,V))),tiltX:70,rotation:0,tiltY:0},j(et)})}else if(a==="cube-spin"){const F=vi(C,e,{...Cr({id:i(),track:0,start:$,duration:S,label:"Khối",is3D:!0}),...Cu([[0,{tiltY:-25,tiltX:18},Au],[S,{tiltY:335,tiltX:-22}]])});A.push(F);const N=.56*u,G=N/2,V=We(N/(u*.96)),et=Ze({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:We(G/y)}],["Mặt sau",{spatialDepth:We(-G/y),tiltY:180}],["Mặt phải",{posX:We(G/c),tiltY:90}],["Mặt trái",{posX:We(-G/c),tiltY:-90}],["Mặt trên",{posY:We(-G/u),tiltX:90}],["Mặt dưới",{posY:We(G/u),tiltX:-90}]];for(const[W,_]of U){const J=vi(C,e,{id:i(),nodeId:"",kind:"image",url:"",label:W,track:0,start:$,duration:S,volume:0,motionV:2,fit:"contain",shape:structuredClone(et),is3D:!0,parentId:F.id,scale:V,..._});A.push(J)}const at=Ze({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[W,_,J]of[["Tia cạnh phải",U[2][1],2],["Tia cạnh trái",U[3][1],3]]){const rt=[];for(let D=0;D<J;D++)rt.push({time:We(S*D/J),trimStart:0,trimEnd:.14},{time:We(S*(D+1)/J-(D<J-1?.001:0)),trimStart:1-.14,trimEnd:1});A.push(vi(C,e,{id:i(),nodeId:"",kind:"image",url:"",label:W,track:0,start:$,duration:S,volume:0,motionV:2,motionKeys:rt,fit:"contain",shape:structuredClone(at),is3D:!0,parentId:F.id,scale:V,..._}))}E.forEach((W,_)=>{z[W.id]={parentId:F.id,is3D:!0,posX:0,posY:0,spatialDepth:We((_-(E.length-1)/2)*.4),scale:We(Math.min(.26,.6/Math.max(1,E.length))),tiltX:0,tiltY:0},j(W)})}else{const F=E[0],N=Math.max(0,Math.min(F.duration,$-F.start)),G=vi(C,e,{...Cr({id:i(),track:0,start:$,duration:S,label:"Tâm camera",is3D:!0}),posX:We(Qt(F,"x",N)),posY:We(Qt(F,"y",N)),spatialDepth:We(Qt(F,"depth",N)),tiltX:-10,...Cu([[0,{tiltY:-40},Au],[S,{tiltY:40}]])});A.push(G);for(const et of E)j(et);P={...r??{...jr},enabled:!0,motionV:2,motionKeys:r?.motionKeys??[],parentId:G.id};for(const[et,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]]}))P=In(P,et,[...cs(P,et).filter(at=>at.time<$-1e-6||at.time>k+1e-6),...U.map(([at,W],_)=>({time:We($+at),value:W,..._===0&&U.length>1?{ease:Au}:{}}))].sort((at,W)=>at.time-W.time));P=_r(P)}return a!=="camera-orbit"&&(P=_r({...r??{...jr,motionKeys:[]},enabled:!0})),{add:A,patches:z,camera:P,end:k}}const k8=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"}]),mb=k8.map(t=>t.id),qe=t=>Math.round(t*1e3)/1e3,Zs=t=>Yt[t];function sa(t,e,o){const{track:r}=Kt(t,e,o.start,o.start+o.duration),a={...o,track:r};return t.push(a),a}const Ps=t=>({motionV:2,motionKeys:t.map(([e,o,r])=>({time:qe(e),...o,...r?{ease:Object.fromEntries(Object.keys(o).map(a=>[a,Zs(r)]))}:{}}))}),Kl=(t,e,o,r,a,n={})=>({id:t,nodeId:"",kind:"image",url:"",label:r,track:0,start:e,duration:o,volume:0,motionV:2,fit:"contain",shape:Ze({v:2,square:!0,items:a}),...n});function Wl(t,e,o){const r=(t.motionKeys??[]).map(a=>{const{[e]:n,ease:i,...c}=a;if(i){const{[e]:u,...p}=i;Object.keys(p).length&&(c.ease=p)}return c}).filter(a=>Object.keys(a).some(n=>n!=="time"&&n!=="ease"));for(const[a,n,i]of o){let c=r.find(u=>Math.abs(u.time-a)<.008333333333333333);c||r.push(c={time:qe(a)}),c[e]=qe(n),i&&(c.ease={...c.ease,[e]:Zs(i)})}return r.sort((a,n)=>a.time-n.time)}function x8(t,e,o,r,a,{at:n,newId:i,W:c=1280,H:u=720,duration:p,color:s,media:h}={}){if(!mb.includes(a))throw Error(`Unknown 3D null rig "${a}"`);const f=new Map(t.map(A=>[A.id,A])),m=o.map(A=>f.get(A)).filter(A=>A&&A.kind!=="audio"&&!A.nullLayer),g=Number.isFinite(n)?n:m.length?Math.min(...m.map(A=>A.start)):0,v=qe(Math.max(2,Math.min(30,p??6))),x=qe(g+v),E=[...t],$=[],S={},k=A=>({is3D:!0,...A.kind!=="video"&&A.start+A.duration<x?{duration:qe(x-A.start)}:{}});let y=_r({...r??{...jr,motionKeys:[]},enabled:!0});const C=typeof s=="string"&&/^#[0-9a-fA-F]{6}$/.test(s)?s:"#39e6e0";if(a==="fan-cards"){if(!m.length)throw Error("Chọn 1–6 thẻ để xoè");const A=m.slice(0,6),z=A.length,j=(z-1)/2,P=sa(E,e,{...Cr({id:i(),track:0,start:g,duration:v,label:"Quạt thẻ",is3D:!0}),tiltX:-8,...Ps([[0,{tiltY:-10},"sine-in-out"],[v,{tiltY:10}]])});$.push(P);const F=qe(Math.min(.42,1.1/Math.max(2.4,z)));A.forEach((N,G)=>{const V=G-j,et=qe(V*Math.min(.17,.8/Math.max(1,z))),U=qe(V*9),at=qe(Math.abs(V)*.025),W=g-N.start,_=Math.max(0,W)+G*.09,J=_+.7;let tt={parentId:P.id,...k(N),posX:et,posY:at,scale:F,rotation:U,tiltX:0,tiltY:qe(-V*8),spatialDepth:qe(G*.12),opacity:1,motionV:2},rt=Wl(N,"x",[[_,0,"back-out"],[J,et]]);rt=Wl({motionKeys:rt},"y",[[_,.45,"expo-out"],[J,at]]),rt=Wl({motionKeys:rt},"rot",[[_,0,"back-out"],[J,U]]),rt=Wl({motionKeys:rt},"opacity",[[_,0,"ease-out"],[_+.25,1]]),S[N.id]={...tt,motionKeys:rt}})}else if(a==="coin-beam"){const A=sa(E,e,Kl(i(),g,v,"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:[[`${C}00`,0],[`${C}66`,.5],[`${C}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:[[`${C}10`,0],[`${C}cc`,.35],["#e8ffffee",.5],[`${C}cc`,.65],[`${C}10`,1]]},stroke:null}],{...Ps([[0,{opacity:0},"ease-out"],[.5,{opacity:1}]])}));$.push(A);const z=sa(E,e,Kl(i(),g,v,"Á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:[[`${C}aa`,0],[`${C}00`,1]]},stroke:null}],{posY:.3,scale:.8}));$.push(z);const j=sa(E,e,{...Cr({id:i(),track:0,start:g,duration:v,label:"Đồng xu",is3D:!0}),...Ps([[0,{tiltY:-720,y:-.05,zoom:.6},"expo-out"],[Math.min(1.6,v*.4),{tiltY:0,y:0,zoom:1},"sine-in-out"],[Math.min(1.6,v*.4)+(v-Math.min(1.6,v*.4))/2,{tiltY:16,y:-.015},"sine-in-out"],[v,{tiltY:-8,y:0}]])});$.push(j);const P=.46;if($.push(sa(E,e,Kl(i(),g,v,"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],[C,.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:j.id,scale:P,spatialDepth:0}))),m[0]){const F=m[0],{track:N}=Kt(E.filter(U=>U.id!==F.id),e,Math.min(F.start,g),Math.max(F.start+F.duration,x)),G=hb(F,c,u,h),V=.6*P*.94*u,et=G>=c/u?V/c:V/(u*Math.max(1,G));S[F.id]={parentId:j.id,...k(F),track:N,posX:0,posY:0,scale:qe(et),rotation:0,tiltX:0,tiltY:0,spatialDepth:.02}}}else if(a==="grid-floor"){const j=[],P=[];for(let V=0;V<=10;V++){const et=qe(V*100),U=V%2?[et,1e3]:[et,0],at=V%2?[et,0]:[et,1e3];j.push(U,at)}for(let V=0;V<=10;V++){const et=qe(V*100),U=V%2?[1e3,et]:[0,et],at=V%2?[0,et]:[1e3,et];P.push(U,at)}const F=(V,et,U,at)=>({id:V,name:et,type:"path",params:{pts:U,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:at?.35:.9,fill:{type:"none"},stroke:{color:at?C:"#cfe9ff",width:at?10:2.5,...at?{blur:10}:{},join:"miter"}}),N=sa(E,e,{...Cr({id:i(),track:0,start:g,duration:v,label:"Sàn lưới",is3D:!0}),posY:.28,tiltX:-78,...Ps([[0,{y:.1},"linear"],[v,{y:0}]])});$.push(N),$.push(sa(E,e,Kl(i(),g,v,"Lưới",[F("gv","Glow V",j,!0),F("gh","Glow H",P,!0),F("v","Lines V",j),F("h","Lines H",P)],{is3D:!0,parentId:N.id,scale:2.6,opacity:.8})));const G=m.length;m.forEach((V,et)=>{S[V.id]={...k(V),posX:qe((et-(G-1)/2)*.28),posY:-.04,spatialDepth:qe(-.3*(et%2)),scale:qe(Math.min(.3,.9/Math.max(3,G))),tiltX:0,tiltY:0}})}else{const A=m.find(N=>["image","video"].includes(N.kind)&&N.url);if(!A)throw Error("Chọn một clip ảnh hoặc video để đưa lên màn hình điện thoại");const z=sa(E,e,{...Cr({id:i(),track:0,start:g,duration:v,label:"Điện thoại",is3D:!0}),...Ps([[0,{y:.04,zoom:.85},"expo-out"],[1.4,{y:0,zoom:1},"sine-in-out"],[v/2+.7,{y:-.02},"sine-in-out"],[v,{y:0}]])});$.push(z);const{clip:j,sourcePatch:P}=g1(E,e,A,"phone",{id:i(),color:s,start:g,duration:v,pose:{scale:.62,parentId:z.id,modelRotation:{x:-6,y:180,z:0},motionV:2,motionKeys:[{time:0,ry:180,ease:{ry:Zs("expo-out")}},{time:1.6,ry:-14,ease:{ry:Zs("sine-in-out")}},{time:qe(v),ry:12}]}});j.duration=v,E.push(j),$.push(j),S[A.id]={...P,...A.kind==="image"&&A.start+A.duration<x?{duration:qe(x-A.start)}:{}};let F={...y,motionV:2,motionKeys:y.motionKeys??[]};F=In(F,"cz",[...cs(F,"cz").filter(N=>N.time<g-1e-6||N.time>x+1e-6),{time:qe(g),value:-6,ease:Zs("sine-in-out")},{time:x,value:-4.8}].sort((N,G)=>N.time-G.time)),y=_r(F)}return{add:$,patches:S,camera:y,end:x}}const Ui=Object.freeze({points:[2,24],samples:[8,48]}),M8=Object.freeze(["x","y","depth","rot","tiltY"]),ua=t=>Math.round(t*1e4)/1e4,ei=(t,e)=>Math.max(Vr[t].min,Math.min(Vr[t].max,e));function gb(t){if(!t||typeof t!="object")throw Error("Invalid motion path");const e=t.points;if(!Array.isArray(e)||e.length<Ui.points[0]||e.length>Ui.points[1])throw Error(`Motion path needs ${Ui.points[0]}–${Ui.points[1]} points`);const r={points:e.map(a=>{if(!Array.isArray(a)||a.length<2||a.length>3||!a.every(Number.isFinite))throw Error("A path point is [x, y] or [x, y, depth]");return[ei("x",a[0]),ei("y",a[1]),...a.length===3?[ei("depth",a[2])]:[]]})};for(const a of["start","end"])if(t[a]!==void 0){if(!Number.isFinite(t[a])||t[a]<0)throw Error(`Invalid path ${a}`);r[a]=ua(t[a])}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"||!Yt[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 v8(t,e){const o=t.length,r=u=>e?t[(u+o)%o]:t[Math.max(0,Math.min(o-1,u))],a=e?o:o-1,n=(u,p)=>{const s=r(u-1),h=r(u),f=r(u+1),m=r(u+2),g=(A,z)=>Math.max(1e-6,Math.sqrt(Math.hypot(...A.map((j,P)=>j-z[P])))),v=g(s,h),x=v+g(h,f),E=x+g(f,m),$=v+(x-v)*p,S=(A,z,j,P)=>A.map((F,N)=>(P-$)/(P-j)*F+($-j)/(P-j)*z[N]),k=S(s,h,0,v),y=S(h,f,v,x),C=S(f,m,x,E);return S(S(k,y,0,x),S(y,C,v,E),v,x)},i=[{s:0,p:t[0].slice()}];for(let u=0;u<a;u++)for(let p=1;p<=24;p++){const s=n(u,p/24),h=i.at(-1);i.push({s:h.s+Math.hypot(...s.map((f,m)=>f-h.p[m])),p:s})}const c=i.at(-1).s||1;return u=>{const p=Math.max(0,Math.min(1,u))*c;let s=1;for(;s<i.length-1&&i[s].s<p;)s++;const h=i[s-1],f=i[s],m=f.s>h.s?(p-h.s)/(f.s-h.s):0;return h.p.map((g,v)=>g+(f.p[v]-g)*m)}}function yb(t,e,{W:o=1280,H:r=720}={}){const a=gb(e),n=Br(o,r),i=a.points.some(E=>E.length===3),c=a.points.map(E=>[E[0]*o,E[1]*r,(E[2]??0)*n]),u=v8(c,!!a.closed),p=Math.min(a.start??0,Math.max(0,t.duration-.1)),s=Math.min(t.duration,a.end??t.duration),h=Math.max(.1,s-p),f=Math.max(Ui.samples[0],Math.min(Ui.samples[1],Math.max(Math.round(h*6),a.points.length*4))),m=Yt[a.ease??"linear"],g=[];for(let E=0;E<=f;E++)g.push(u(Kh(m,E/f)));const v=E=>ua(p+h*E/f),x={x:[],y:[],...i?{depth:[]}:{}};if(g.forEach((E,$)=>{const S=$<f?{ease:"auto"}:{};x.x.push({time:v($),value:ua(ei("x",E[0]/o)),...S}),x.y.push({time:v($),value:ua(ei("y",E[1]/r)),...S}),i&&x.depth.push({time:v($),value:ua(ei("depth",E[2]/n)),...S})}),a.orient){const E=y=>{const C=u(Math.max(0,y-.004)),A=u(Math.min(1,y+.004));return[A[0]-C[0],A[1]-C[1],A[2]-C[2]]},$=y=>{for(let C=1;C<y.length;C++){let A=y[C].value-y[C-1].value;for(;A>180;)y[C].value-=360,A-=360;for(;A<-180;)y[C].value+=360,A+=360}return y},S=[],k=[];for(let y=0;y<=f;y++){const[C,A,z]=E(Kh(m,y/f)),j=y<f?{ease:"auto"}:{};if(i){const P=Math.hypot(C,z);k.push({time:v(y),value:ua(Math.atan2(-z,C||1e-9)*180/Math.PI),...j}),S.push({time:v(y),value:ua(Math.atan2(A,P||1e-9)*180/Math.PI),...j})}else S.push({time:v(y),value:ua(Math.atan2(A,C||1e-9)*180/Math.PI),...j})}x.rot=$(S),i&&(x.tiltY=$(k));for(const y of M8)x[y]&&(x[y]=x[y].map(C=>({...C,value:ei(y,C.value)})))}return x}function $8(t,e,{W:o=1280,H:r=720}={}){let a={...t},n={};const i=t.path?E8(t.path):[];for(const p of i){const s=ge(a,p,[]);a={...a,...s},n={...n,...s}}if(!e)return{...n,path:void 0};const c=gb(e),u=yb(a,c,{W:o,H:r});for(const[p,s]of Object.entries(u)){const h=ge(a,p,s);a={...a,...h},n={...n,...h}}return{...n,path:c}}function E8(t){const e=t.points?.some(o=>o.length===3);return["x","y",...e?["depth"]:[],...t.orient?e?["rot","tiltY"]:["rot"]:[]]}function FT(t,{W:e=1280,H:o=720}={}){if(!t.path)return!1;try{const r=yb(t,t.path,{W:e,H:o});return Object.entries(r).every(([a,n])=>{const i=Ee(t,a);return i.length===n.length&&i.every((c,u)=>Math.abs(c.time-n[u].time)<.001&&Math.abs(c.value-n[u].value)<.001)})}catch{return!1}}const S8=1,bb=100,I8=40,A8=60,Oh=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"}),wb=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"]}),C8=(t,e=3)=>wb[t]?.[e<=2?0:e>=4?2:1]??Oh[t]??null;Object.freeze([...new Set([...Object.values(Oh),...Object.values(wb).flat()].filter(Boolean))]);const j8=Object.freeze(["hook","build","payoff","reaction","outro"]),T8=Object.freeze(["text","framing","motion","color"]),O8=Object.freeze({"extreme-close":1.3,close:1.15,insert:1.2}),U0=["luma","sat","warmth","contrast","shadowTint","highlightTint"],Gn=t=>Math.round(t*1e3)/1e3,lp=(t,e,o)=>Math.max(e,Math.min(o,t)),kb=t=>t&&typeof t=="object"&&U0.every(e=>Number.isFinite(t[e])&&Math.abs(t[e])<=1)?Object.fromEntries(U0.map(e=>[e,Gn(t[e])])):null;function z8(t){const e=kb(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:Gn(lp((e.warmth-.04)*6,.3,.8))}:e.warmth<-.04?{effect:"cool",amount:Gn(lp(-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 P8(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 a=/\d/.test(t)?o.findIndex(c=>/\d/.test(c)):-1,n=lp(t.split(/\s+/).filter(Boolean).length+1,2,6),i=o.slice(Math.max(0,a),Math.max(0,a)+n).join(" ").replace(/[,.;:!?…]+$/u,"").slice(0,60);return{text:r?i.toLocaleUpperCase():i,source:"speech"}}function L8(t,e,o,r){const a=(i,c)=>(Array.isArray(i?.scenes)?i.scenes:[]).find(u=>u.start<=c&&u.end>c&&Number.isFinite(u.flowX))?.flowX??0;return a(t,Math.max(0,e-.05))+a(o,r+.05)>.02?1:-1}function F8(t){if(!t||typeof t!="object"||t.v!==S8||!(t.duration>0&&t.duration<=3600)||!Array.isArray(t.shots)||!t.shots.length||t.shots.length>bb)throw Error("Invalid reference recipe");for(const e of t.shots)if(!(e?.len>0&&e.len<=3600)||!Object.hasOwn(Oh,e.transition)||!j8.includes(e.role))throw Error("Invalid reference shot");if(t.color!==void 0&&!kb(t.color))throw Error("Invalid reference colour");return t}function N8(t){return Object.fromEntries(T8.map(e=>[e,!(t&&typeof t=="object"&&t[e]===!1)]))}function R8(t,e,o,r,a){const n={punch:null,move:null,shake:null,text:null},i=O8[t.framing];return r.framing&&i&&o>=.4&&(n.punch={amount:i,style:r.motion&&t.motion==="slow"?"push":"cut"}),r.motion&&o>=.3&&(t.motion==="shake"?n.shake=Gn(lp(.25+.08*t.energy,.3,.65)):t.motion==="fast"?n.move=e%2?"pan-right":"pan-left":t.motion==="slow"&&n.punch?.style!=="push"&&(n.move=t.framing==="wide"?e%2?"pan-left":"pan-right":"push-in")),r.text&&t.text&&(n.text={...P8(t.text,a),placement:t.textPlacement==="bottom"?"lower":t.textPlacement==="top"?"top":"center"}),n}function D8(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 B8({recipe:t,picks:e,beats:o=null,duration:r=null,start:a=0,sourceDuration:n=()=>1/0,copy:i=null,spoken:c=()=>""}){const u=N8(i);if(F8(t),!Array.isArray(e)||!e.length)throw Error("Choose at least one moment of your footage");const p=Math.max(3,Math.min(A8,Number(r)>0?Number(r):t.duration)),s=t.shots.map(k=>({...k}));for(let k=0,y=t.duration;y<p-1e-6&&s.length<bb;k++){const C=t.shots[k%t.shots.length];s.push({...C}),y+=C.len}const h=o?.beats?.length&&(o.confidence??0)>=Cp?o:null,f=h?(h.drops||[]).find(k=>k>p*.25&&k<p*.9)??null:null;let m=-1;if(f!=null&&s.length>1){const k=s.findIndex((y,C)=>C>0&&y.role==="payoff");m=k>0?k:s.reduce((y,C,A)=>A>0&&C.energy>s[y].energy?A:y,1)}const g=(k,y,C)=>{const A=k.reduce((P,F)=>P+F.len,0),z=[];let j=y;for(const P of k)j+=P.len*(C-y)/A,z.push(j);return z};let v=m>0?[...g(s.slice(0,m),0,f),...g(s.slice(m),f,p)].slice(0,-1):g(s,0,p).slice(0,-1);if(h){const k=60/(h.bpm||120),y=Math.max(.25,Math.min(k,.6));v=v.map(A=>A===f?A:DM(h,A,k/2));const C=[];for(const A of v)if((A-(C.at(-1)??0)>=y||A===f)&&p-A>=y){if(A===f)for(;C.length&&f-C.at(-1)<y;)C.pop();C.push(A)}v=C}const x=[0,...v,p],E=e.map(k=>({...k,cursor:k.start})),$=[];let S=0;for(let k=0;k<x.length-1;k++){const y=Gn(x[k+1]-x[k]),C=s[Math.min(k,s.length-1)];let A=null;for(let j=0;j<E.length*2&&!A;j++){const P=E[S%E.length];(P.cursor>=P.end-.05||n(P.materialId)-P.cursor<y-.001)&&(P.cursor=P.start),n(P.materialId)-P.cursor>=y-.001?A=P:S++}if(!A)throw Error("The chosen moments are too short for this edit");const z=Gn(A.cursor);$.push({materialId:A.materialId,inPoint:z,duration:y,start:Gn(a+x[k]),transition:k===0?null:C8(C.transition,C.energy),role:C.role,energy:C.energy,...R8(C,k,y,u,C.text&&u.text?c(A.materialId,z,z+y):"")}),A.cursor+=y,S++}return{segments:$,look:u.color?z8(t.color):null,snapped:!!h,drop:f!=null?Gn(f):null,duration:Gn(p)}}const xb=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]]}}]),Mb=new Map(xb.map(t=>[t.id,t])),vb=(t,[e,o])=>Math.max(e,Math.min(o,t)),qd=t=>+t.toFixed(3);function _8(t,e){const o=typeof e=="string"?Mb.get(e):e;if(!o)throw Error("Unknown colour recipe");const r={...t||{}};if(o.mixer){const a={...r.mixer||{}};for(const[n,i]of Object.entries(o.mixer)){const c={...a[n]||{}};for(const[u,p]of Object.entries(i)){const s=qd(vb((c[u]??0)+p,Ip[u]));s?c[u]=s:delete c[u]}Object.keys(c).length?a[n]=c:delete a[n]}Object.keys(a).length?r.mixer=a:delete r.mixer}return o.curves&&(r.curves={...r.curves||{},...Object.fromEntries(Object.entries(o.curves).map(([a,n])=>[a,n.map(i=>i.slice())]))}),r}function NT(t,e,o,r){const a=typeof t=="string"?Mb.get(t):t;if(!a)return[e,o,r];const n={curves:a.curves};return a.curves&&(e=Bp(n,"r",e),o=Bp(n,"g",o),r=Bp(n,"b",r)),a.mixer?b1(a.mixer,e,o,r):[e,o,r]}const $b=20,V8=4;function G8(t,e,o){const{h:r,c:a,l:n}=y1(t,e,o);if(a<.03||n<.05)return null;const i=(r-$b+540)%360-180;return{hue:+r.toFixed(1),delta:+i.toFixed(1),ok:Math.abs(i)<=V8,chroma:+a.toFixed(3),luma:+n.toFixed(3)}}function RT(t,e){const o=G8(...e);if(!o||o.ok)return null;const r=t?.mixer||{},a={red:r.red?.shift??0,yellow:r.yellow?.shift??0},n=h=>{const[f,m,g]=b1({red:{shift:h},yellow:{shift:h}},...e);return(y1(f,m,g).h-$b+540)%360-180};let i=-1,c=1;n(i)>0||n(c)<0;for(let h=0;h<30;h++){const f=(i+c)/2;n(f)>0?c=f:i=f}const u=(i+c)/2,p={...r};for(const h of["red","yellow"]){const f=qd(vb(a[h]+u,Ip.shift)),m={...p[h]||{}};f?m.shift=f:delete m.shift,Object.keys(m).length?p[h]=m:delete p[h]}const s={...t||{}};return Object.keys(p).length?s.mixer=p:delete s.mixer,{grade:s,shift:qd(u),before:o}}const la=t=>({...bn,type:"ellipse",...t}),Ke=(t,e,o)=>o==="en"?e:t,Eb=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:Ke("Sáng mặt","Face",e),window:_s("face"),adjust:{exposure:.3}}:{name:Ke("Sáng giữa","Centre",e),window:la({cx:.5,cy:.42,w:.34,h:.5,feather:.5}),adjust:{exposure:.3}},{name:Ke("Tối quanh","Surround",e),window:la({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:Ke("Vignette","Vignette",t),window:la({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:Ke("Tối trời","Sky",t),window:{...bn,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:Ke("Đè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:Ke("Nền","Background",e),window:lc(),invert:!0,adjust:{saturation:.7,exposure:-.3}}:{name:Ke("Nền","Background",e),window:la({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:Ke("Sáng mặt","Brighter face",t),window:_s("face"),adjust:{exposure:.2}},{name:Ke("Mịn da","Smooth skin",t),window:_s("skin"),blur:.1,adjust:{contrast:.97}},{name:Ke("Mắt sáng","Bright eyes",t),window:_s("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:Ke("Xa (trên)","Far (top)",t),window:{...bn,type:"gradient",cx:.5,cy:.45,w:1,h:1,rot:0,feather:.5},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.08}},{name:Ke("Gần (dưới)","Near (bottom)",t),window:{...bn,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:Ke("Xa (giữa)","Far (centre)",t),window:la({cx:.5,cy:.45,w:.32,h:.45,feather:.6}),adjust:{contrast:.84,saturation:.85,temperature:-12,exposure:.05}},{name:Ke("Gần (viền)","Near (edges)",t),window:la({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:Ke("Nền (xa)","Background (far)",e),window:t?lc():la({cx:.5,cy:.5,w:.5,h:.8,feather:.5}),invert:!0,adjust:{contrast:.85,saturation:.85,temperature:-12,exposure:-.1}},{name:Ke("Người (gần)","Subject (near)",e),window:t?lc():la({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:Ke("Xa (AI)","Far (AI)",e),window:{...bn,type:"depth",range:[0,.42],feather:.35},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.06}},{name:Ke("Gần (AI)","Near (AI)",e),window:{...bn,type:"depth",range:[.58,1],feather:.35},adjust:{contrast:1.08,saturation:1.05,temperature:8}}]:[{name:Ke("Xa (trên)","Far (top)",e),window:{...bn,type:"gradient",cx:.5,cy:.45,w:1,h:1,rot:0,feather:.5},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.07}},{name:Ke("Gần (dưới)","Near (bottom)",e),window:{...bn,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:Ke("Đè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}}]}]),Sb=new Map(Eb.map(t=>[t.id,t])),Ib=t=>Sb.get(t);function ll(t,{face:e=!1,person:o=!1,depth:r=!1,locale:a="vi"}={}){const n=Sb.get(t);if(!n)throw Error("Unknown window preset");return n.faceOnly&&!e?null:n.build({face:e,person:o,depth:r,locale:a})}function K8(t){const e=n=>JSON.stringify([n.window,n.adjust??null,!!n.invert]);let o=0;const r=["vi","en"].map(n=>[ll("depth-ai",{depth:!1,locale:n}),ll("depth-ai",{depth:!0,locale:n})]),a=t.map(n=>{for(const[i,c]of r)for(let u=0;u<i.length;u++)if(e(n)===e(i[u]))return o++,{...c[u],...n.on===!1?{on:!1}:{},name:n.name===i[u].name?c[u].name:n.name};return n});return{list:o?a:t,upgraded:o}}function W8(t,e,o){const r=ll(e,o);if(!r)throw Error("This preset needs a face track — detect faces first");if(t.length+r.length>jc)throw Error(`Up to ${jc} power windows per clip`);return[...t,...r]}const DT=Object.freeze(Object.defineProperty({__proto__:null,WINDOW_PRESETS:Eb,presetWindows:ll,upgradeDepthWindows:K8,windowPreset:Ib,withPreset:W8},Symbol.toStringTag,{value:"Module"})),xc=["exposure","contrast","saturation","brightness","hue"],H8=i2.map(t=>t[0]),X8=Object.keys(Ip),U8=Object.keys(td),Y8=["exposure","contrast","saturation","hue","temperature","tint"],Mo=t=>Math.round(t*1e4)/1e4,hr=(t,e,o)=>Math.max(e,Math.min(o,t)),q8={cx:[-.5,1.5],cy:[-.5,1.5],w:[.02,3],h:[.02,3],rot:[-180,180],feather:[0,1]};function Ab(t,e={}){const o={...e};if(!t||typeof t!="object")return o;for(const r of H8){const a=t[r];if(!a||typeof a!="object")continue;const n={};for(const i of X8)if(a[i]!=null){const[c,u]=Ip[i],p=Math.round(hr(Number(a[i])||0,c,u)*1e3)/1e3;p&&(n[i]=p)}Object.keys(n).length?o[r]=n:delete o[r]}return o}function Z8(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(td,e.preset))throw Error(`qualifier: ${U8.join(" | ")} or {hue, hueWidth, satMin, satMax, lumMin, lumMax, soft}`);const o=e.preset!=null?td[e.preset]:u2,r=(n,i,c,u)=>{const p=e[n]??(u?e[u]:void 0);return p==null||!Number.isFinite(+p)?o[n]:Mo(hr(+p,i,c))},a={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 a.satMin>a.satMax&&([a.satMin,a.satMax]=[a.satMax,a.satMin]),a.lumMin>a.lumMax&&([a.lumMin,a.lumMax]=[a.lumMax,a.lumMin]),a}function J8(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 a=hr(Number(r.x)||0,-1,1),n=hr(Number(r.y)||0,-1,1);const i=Math.hypot(a,n);i>1&&(a/=i,n/=i);const c={x:Mo(a),y:Mo(n),l:Mo(hr(Number(r.l)||0,-1,1))};(c.x||c.y||c.l)&&(e[o]=c)}return Object.keys(e).length?e:void 0}function Q8(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 a=[];for(const n 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,c)=>i.x-c.x)){const i=Mo(hr(+n.x,0,1)),c=Mo(hr(+n.y,0,1));(!a.length||i>a.at(-1)[0]+.001)&&a.push([i,c])}a.length>=2&&a.length<=16&&(e[o]=a)}return Object.keys(e).length?e:void 0}function tI(t,{hasFace:e=!1,hasPerson:o=!1,pending:r=null}={}){const a=(f,m,g,v)=>t[f]==null?v:Mo(hr(t[f],m,g));let n;if(t.shape==="whole"||t.shape==="qualifier")n=null;else if(["face","skin","eyes","lips"].includes(t.shape)){if(!e){if(!r)return null;r.add("face")}const f=_s(t.shape==="face"?"face":t.shape);n={...f,cx:a("cx",-.5,.5,0),cy:a("cy",-.5,.5,0),w:a("w",.5,2,1),h:a("h",.5,2,a("w",.5,2,1)),feather:a("feather",0,1,f.feather)}}else if(t.shape==="person"){if(!o){if(!r)return null;r.add("person")}n=lc()}else if(t.shape==="depth"){const f=a("from",0,.99,0),m=a("to",.01,1,.42);n={...bn,type:"depth",range:[Math.min(f,m-.01),Math.max(m,f+.01)],feather:a("feather",0,1,.35)}}else{const f=t.shape==="gradient"?{cx:.5,cy:.4,w:1,h:1,rot:0,feather:.3}:{...bn};n={type:t.shape==="rect"?"rect":t.shape==="gradient"?"gradient":"ellipse",...Object.fromEntries(Object.entries(q8).map(([m,[g,v]])=>[m,a(m,g,v,f[m])]))}}const i={};for(const f of Y8)if(t[f]!=null){const{min:m,max:g,base:v}=p2[f],x=Mo(hr(t[f],m,g));x!==v&&(i[f]=f==="hue"||f==="temperature"||f==="tint"?Math.round(x):x)}const c=J8(t.wheels??{lift:t.lift,gamma:t.gamma,gain:t.gain}),u=Q8(t.curves),s=t.shape==="qualifier"||t.qualifier!=null&&n&&["ellipse","rect","gradient"].includes(n.type)?Z8(t.qualifier??"skin"):null,h={name:String(t.name||"").slice(0,40)||void 0,...s?{qualifier:s}:{},...n?{window:n}:s?{}:{whole:!0},...t.invert&&(n||s)?{invert:!0}:{},...Object.keys(i).length?{adjust:i}:{},...c?{wheels:c}:{},...u?{curves:u}:{},...t.on===!1?{on:!1}:{}};if(t.blur!=null&&t.blur>0&&(h.blur=Mo(hr(t.blur,0,1))),t.sharpen!=null&&t.sharpen>0&&(h.sharpen=Math.round(hr(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:Mo(hr(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:Mo(hr(f.amount,0,1))}:{},...f.size!=null?{size:Mo(hr(f.size,0,1))}:{}}}if((t.branch==="parallel"||t.branch==="layer")&&(h.branch=t.branch),t.mixer){const f=Ab(t.mixer);Object.keys(f).length&&(h.mixer=f)}return h.name||delete h.name,h}function eI(t,e,{locale:o="vi",notes:r=[],queue:a=!1}={}){const n={};for(const c of xc)if(e[c]!=null){const[u,p]=Md[c];n[c]=Mo(Math.max(u,Math.min(p,e[c])))}let i={...t.grade||{}};if(e.recipe&&(i=_8(i,e.recipe),r.push(`recipe:${e.recipe}`)),e.mixer){const c=Ab(e.mixer,i.mixer||{});Object.keys(c).length?i.mixer=c:delete i.mixer,r.push("mixer")}for(const[c,{min:u,max:p}]of Object.entries(Wh))e[c]!=null&&(i[c]=Math.round(Math.max(u,Math.min(p,e[c]))));if(e.lut&&(i.lut=s2({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 c={...i.wheels||{}};for(const u of l2){const p=e.wheels[u];if(!p)continue;let s=Math.max(-1,Math.min(1,p.x)),h=Math.max(-1,Math.min(1,p.y));const f=Math.hypot(s,h);f>1&&(s/=f,h/=f),c[u]={x:Mo(s),y:Mo(h),l:Mo(Math.max(-1,Math.min(1,p.l)))}}i.wheels=c}if(e.curves){const c={...i.curves||{}};for(const u of["master","r","g","b"]){const p=e.curves[u];if(!p)continue;const s=[];for(const h of[...p].sort((f,m)=>f.x-m.x)){const f=Mo(Math.max(0,Math.min(1,h.x))),m=Mo(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&&(c[u]=s)}i.curves=c}if(e.windows){const c=a?new Set:null,u={face:!!t.hasFace,person:!!t.hasPerson,depth:!!t.hasDepth,locale:o},p=[];for(const h of e.windows.presets||[]){const f=c?Ib(h)?.needs:null,m=f==="face"?!u.face:f==="person"?!u.person:!1,g=ll(h,m?{...u,[f]:!0}:u);g?(p.push(...g),r.push(`preset:${h}`),m&&c.add(f)):r.push(`skipped:${h}`)}for(const h of e.windows.custom||[]){const f=tI(h,{hasFace:u.face,hasPerson:u.person,pending:c});f?p.push(f):r.push(`skipped:${h.shape}`)}if(c)for(const h of c)r.push(`pending:${h}`);const s=[...e.windows.mode==="replace"?[]:ph(i),...p];if(s.length>jc)throw Error(`Up to ${jc} nodes (power windows) per clip`);i=uh(i,s),p.length&&r.push(`windows:${p.length}`)}for(const c of Object.keys(Wh))i[c]||delete i[c];return c2(i),n.grade=Object.keys(i).length?i:void 0,n}const Ao=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}),oI={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}}},rI={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}}},tn=t=>Math.round(t*1e3)/1e3,cp=(t,e,o)=>Math.max(e,Math.min(o,t)),rn=t=>{throw Error(`lockup: ${t}`)};function Cb(t,e){if(t==null||t==="")return null;if(t==="accent")return e;if(Object.hasOwn(Ao.accents,t))return Ao.accents[t];if(typeof t=="string"&&_x.test(t))return t.toLowerCase();rn(`colour "${String(t).slice(0,20)}" must be #rrggbb, red, green or accent`)}function nI(t,e){(!Array.isArray(t)||!t.length||t.length>Ao.maxLines)&&rn(`lines needs 1–${Ao.maxLines} entries`);const o=t.map((r,a)=>{const n=typeof r=="string"?{text:r}:r;(!n||typeof n!="object")&&rn(`lines[${a}] must be {text, role}`);const i=typeof n.text=="string"?n.text.replace(/\s+/g," ").trim():"";return(!i||i.length>Ao.maxChars)&&rn(`lines[${a}].text needs 1–${Ao.maxChars} characters`),n.role!=null&&!Ao.roles.includes(n.role)&&rn(`lines[${a}].role must be lead, hero or tail`),{text:i,role:n.role??(t.length===1||a>0?"hero":"lead"),color:Cb(n.color,e)}});if(o.some(r=>r.role==="hero")||rn("needs at least one hero line (the big word)"),!o.some(r=>r.color)&&o.length>1){const r=o.map(a=>a.role).lastIndexOf("hero");o[r]={...o[r],color:e}}return o}function aI(t,e,o,r,{W:a,H:n}){const i=n>a*1.1,c=i?Ie.halfWidth.portrait:Ie.halfWidth.landscape,u=[o,(o+r)/2,Math.max(o,r-.05)].map(p=>Jc(t,e,cp(p,t.start,t.start+t.duration-.001),{W:a,H:n})).filter(Boolean);return u.length?{x0:Math.min(...u.map(p=>p.x))-c,x1:Math.max(...u.map(p=>p.x))+c,top:Math.min(...u.map(p=>p.y))-Ie.head,faceY:Math.max(...u.map(p=>p.y)),assumed:u.every(p=>p.assumed),port:i}:null}function iI(t,e="auto",{W:o=1280,H:r=720}={}){const{margin:a,gap:n,minColumn:i,maxColumn:c}=Ao,u=r>o*1.1,p=t??{x0:.5-Ie.halfWidth.landscape,x1:.5+Ie.halfWidth.landscape,top:.24,faceY:.38},s={left:Math.max(0,p.x0-n-a),right:Math.max(0,1-a-(p.x1+n))},h=x=>!u&&s[x]>=i,f=e==="left"||e==="right"?e:s.left>=s.right?"left":"right",m=f==="left"?"right":"left",g=h(f)?f:h(m)?m:null;if(g){const x=Math.min(c,s[g]),E=g==="left"?a:p.x1+n,$=g==="left"?p.x0-n:1-a,S=g==="left"?Math.min((E+$)/2,$-x/2):Math.max((E+$)/2,E+x/2);return{mode:"side",side:g,cx:tn(S),width:tn(x),moved:g!==f&&e!=="auto"}}const v=p.top>(u?.3:.36);return{mode:"band",band:v?"top":"lower",cy:tn(v?Math.max(.12,p.top/2):Math.min(.86,(p.faceY+Ie.chin+1)/2)),width:.86,moved:e!=="auto"}}function sI(t,e){let o=Sc(t,Array.isArray(e?.words)&&e.words.length?e.words:null);return!o.length&&Array.isArray(e?.transcript)&&e.transcript.length&&(o=Sc(t,$p(e.transcript))),o.map(r=>({start:t.start+r.start,end:t.start+r.end,key:w1(r.word)}))}function lI(t,e,o,r){const a=Math.min(10,r-.35),n=(e||[]).filter(s=>s.start>=o-.25&&s.start<o+r),i=t.map(()=>null);let c=0,u=0;if(t.forEach((s,h)=>{const f=w1(s);for(let m=c;m<Math.min(n.length,c+8);m++)if(f&&(n[m].key===f||f.length>2&&n[m].key.startsWith(f))){i[h]=n[m].start-o,c=m+1,u++;break}}),!u)return{times:t.map((s,h)=>tn(cp(.15+h*.28,0,a))),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,g=f<i.length?i[f]:null;i[s]=m!==null&&g!==null?m+(g-m)*(s-h)/(f-h):m!==null?m+.25*(s-h):g-.25*(f-s)}let p=0;return{times:i.map(s=>{const h=tn(cp(Math.max(p,s),0,a));return p=h,h}),matched:u}}function cI(t,{clips:e=[],materials:o=[],W:r=1280,H:a=720}={}){const n=e.find(P=>P.id===t.clipId);(!n||n.kind!=="video"||n.title||n.motion||n.shape)&&rn("clipId must be the speaker's video clip");const i=Number.isFinite(t.at)?t.at:Number.isFinite(t.start)?t.start:n.start,c=Number.isFinite(t.duration)?t.duration:3;(c<Ao.minDuration||c>Ao.maxDuration)&&rn(`duration ${Ao.minDuration}–${Ao.maxDuration} s`),(i<n.start-.05||i>=n.start+n.duration)&&rn("at must fall inside the speaker clip");const u=t.style==null?"condensed":t.style;Ao.styles.includes(u)||rn("style must be condensed, serif or script");const p=t.side==null?"auto":t.side;Ao.sides.includes(p)||rn("side must be auto, left or right");const s=Cb(t.color,Ao.accents.red)??Ao.accents.red,h=nI(t.lines,s),f=oI[u],m=o.find(P=>P.id===n.nodeId),g=iI(aI(n,m,i,i+c,{W:r,H:a}),p,{W:r,H:a}),v=h.map(P=>f[P.role].caps?P.text.toLocaleUpperCase("vi"):P.text),x=v.flatMap(P=>P.split(" ").filter(Boolean)),{times:E}=lI(x,sI(n,m),i,c);let $=0;const S=v.map((P,F)=>{const N=P.split(" ").filter(Boolean).length,G=h[F].role,V=rI[G],et=E.slice($,$+N).map(U=>tn(Math.max(0,G==="hero"?U-.06:U)));return $+=N,G==="tail"?{lines:[F],unit:"line",at:[et[0]],duration:V.duration,easing:V.easing,from:{...V.from,x:g.mode==="side"&&g.side==="right"?V.from.x:-V.from.x}}:{lines:[F],unit:"word",at:et,duration:V.duration,easing:V.easing,from:V.from}}),k=g.mode==="band"?.55:1,y={weight:700,lineHeight:1.25,uppercase:!1,stack:"ink",gap:.12,maxWidth:g.width,lines:h.map(P=>{const F=f[P.role];return{scale:tn(F.scale*k),font:F.font,weight:F.weight,...F.italic?{italic:!0}:{},...F.tracking!==void 0?{tracking:F.tracking}:{},...P.color?{fill:P.color}:{}}}),layers:[{type:"text",fill:"{color}",shadow:{color:"#000000",blur:.22,x:0,y:.03},opacity:1}]},C=Math.min(1,r*720/1280/a),A=C>.99,z=g.mode==="side"?{posX:tn(g.cx-.5),posY:0}:A?{posX:0,posY:0}:{posX:0,posY:tn(cp(g.cy-.5,-.5+C/2,.5-C/2))},j=g.mode==="band"&&A?g.band:"center";return{addText:{op:"addText",text:v.join(`
204
+ `),start:tn(i),duration:tn(c),fontSize:Ao.fontSize,color:"#ffffff",accentColor:s,placement:j,align:"center",fontFamily:f.hero.font,design:y,animation:{version:1,in:S,out:"none"},...z,...t.track!=null?{track:t.track}:{}},placement:g}}const pI=Object.freeze(["wide","medium","close","side","phone"]),Y0=Object.freeze(["speaker","sentence","beat","mixed"]),Dr=Object.freeze({minShot:2.5,maxShot:8,minAngles:2,maxAngles:8,lead:.12,turnGap:.6}),pp=t=>String(t??"").normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d").replace(/Đ/g,"D").toLowerCase(),uI=(t,e)=>t.test(e),dI=[["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])/]],hI=[["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)/]],fI=t=>{const e=t.filter(Number.isFinite).sort((o,r)=>o-r);return e.length?e[Math.floor(e.length/2)]:null};function mI(t,e=[]){if(pI.includes(t?.angle))return{role:t.angle,from:"user"};const o=pp(t?.label).replace(/\.[a-z0-9]{2,4}$/,"").replace(/[_.]+/g," ");for(const[c,u]of dI)if(uI(u,o))return{role:c,from:"name"};const r=pp([t?.description,...Array.isArray(t?.scenes)?t.scenes.slice(0,20).map(c=>c?.description):[]].filter(Boolean).join(" ")),a=hI.map(([c,u])=>[c,(r.match(new RegExp(u.source,"g"))||[]).length]).filter(([,c])=>c>0).sort((c,u)=>u[1]-c[1]);if(a.length)return{role:a[0][0],from:"analysis"};const n=fI((Array.isArray(t?.scenes)?t.scenes:[]).map(c=>Number(c?.subjectH)));return n!=null?{role:n>=.3?"close":n>=.16?"medium":"wide",from:"size"}:(c=>Number(c?.height)>Number(c?.width)*1.1)(t)&&e.some(c=>c!==t&&Number(c?.width)>Number(c?.height))?{role:"phone",from:"shape"}:{role:null,from:null}}const jb=/\?|(?<![\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,Tb=/!|(?<![\p{L}])(quan trong|nhat dinh|tuyet doi|chac chan|never|always|must|important|really|absolutely)(?![\p{L}])/u;function gI(t){const e=(Array.isArray(t)?t:[]).filter(a=>Number.isFinite(a?.start)&&Number.isFinite(a?.end)&&typeof a.word=="string").sort((a,n)=>a.start-n.start),o=[];let r=null;for(let a=0;a<e.length;a++){const n=e[a],i=e[a-1],c=i?n.start-i.end:1/0;(!r||c>=Dr.turnGap||/[.?!…]["”')\]]*$/.test(i?.word??""))&&(r&&o.push(r),r={start:n.start,end:n.end,words:[],gapBefore:c}),r.words.push(n.word.trim()),r.end=Math.max(r.end,n.end)}return r&&o.push(r),o.map(a=>{const n=a.words.join(" "),i=pp(n);return{start:a.start,end:a.end,text:n,words:a.words.length,gapBefore:a.gapBefore,question:jb.test(i),emphasis:Tb.test(i)||a.words.length<=5}})}function yI(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 a=pp(o.text),n=o.text.trim().split(/\s+/).filter(Boolean).length;return{start:o.start,end:o.end,text:o.text,words:n,gapBefore:r?o.start-e[r-1].end:1/0,question:jb.test(a),emphasis:Tb.test(a)||n<=5}})}const bI={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 wI({angles:t,span:e,sentences:o=[],beats:r=[],gaps:a=[],mode:n="sentence",minShot:i=Dr.minShot,maxShot:c=Dr.maxShot,wideEvery:u=null,crowd:p=()=>!1}){const[s,h]=e,f=1e-6,m=[],g=C=>C.start-Math.min(Dr.lead,Number.isFinite(C.gapBefore)?C.gapBefore/2:Dr.lead);if(n==="sentence"||n==="mixed")for(const C of o)m.push({t:g(C),strength:Math.min(1,Number.isFinite(C.gapBefore)?C.gapBefore:1)+.5});if(n==="speaker"){const C=o.filter(A=>!(A.gapBefore<Dr.turnGap));for(const A of C.length>=2?C:o)m.push({t:g(A),strength:1.5})}if(n==="beat"||n==="mixed")for(const C of r)m.push({t:C,strength:n==="beat"?1.2:.4});for(const C of t)for(const A of[C.from,C.to])m.push({t:A,strength:.3});const v=m.filter(C=>C.t>s+f&&C.t<h-f).sort((C,A)=>C.t-A.t||A.strength-C.strength),x=Math.min(c,Math.max(i,(i+c)/2-.5)),E=(C,A,z)=>{let j=null;for(const P of a){const F=(P.start+P.end)/2;if(!(F>C&&F<A))continue;const N=Math.min(1,P.end-P.start)-Math.abs(F-z)*.02;(!j||N>j.s+1e-9)&&(j={t:F,s:N})}return j?j.t:null},$=[s];for(let C=s;C<h-f;){const A=h-C;let z;if(A<=c+f)z=h;else if(A<2*i)z=C+A/2;else{const j=C+i,P=Math.min(C+c,h-i),F=v.filter(N=>N.t>=j-f&&N.t<=P+f);F.length?z=F.reduce((N,G)=>{const V=G.strength*1.5-Math.abs(G.t-C-x)/2;return!N||V>N.s+1e-9?{t:G.t,s:V}:N},null).t:z=E(j,P,C+x)??Math.min(C+x,P),z>C+f||(z=Math.min(h,C+c))}$.push(z),C=z}const S=(C,A)=>{const z=o.filter(j=>j.end>C+.05&&j.start<A-.05);return{question:z.some(j=>j.question),emphasis:z.some(j=>j.emphasis)&&z.every(j=>j.words<=12),long:z.some(j=>j.end-j.start>6||j.words>18)||A-C>6&&z.length<=1&&z.some(j=>j.words>10),crowd:!!p((C+A)/2)}},k=[];let y=-1/0;for(let C=0;C+1<$.length;C++){const A=$[C],z=$[C+1],j=S(A,z),P=t.filter(W=>W.from<=A+.02&&W.to>=z-.02),F=P.length?P:t.filter(W=>W.to>A&&W.from<z).sort((W,_)=>Math.min(_.to,z)-Math.max(_.from,A)-(Math.min(W.to,z)-Math.max(W.from,A))).slice(0,1);if(!F.length)continue;const N=k.at(-1),G=k.at(-2);let V=null;F.forEach(W=>{const _=W.role??"medium";let J=bI[_](j);_==="wide"&&(C===0||u&&A-y>=u)&&(J+=C===0?2.5:6),N&&N.id===W.id&&N.end>=A-.02&&(J-=100),G&&G.id===W.id&&(J-=.8),(!V||J>V.s+1e-9)&&(V={x:W,s:J,role:_})});const et=j.question?"question":j.emphasis?"emphasis":j.long?"explanation":j.crowd?"group":V.role==="wide"&&C===0?"opening":"rhythm",U=Math.max(A,V.x.from),at=Math.min(z,V.x.to);if(N&&N.id===V.x.id&&Math.abs(N.end-U)<.02&&at-N.start<=c+f){N.end=at;continue}k.push({id:V.x.id,start:U,end:at,role:V.role,why:et}),V.role==="wide"&&(y=z)}return k}const po=t=>Number.isFinite(t)?Number(t):null,kI={wide:"toàn",medium:"trung",close:"cận",side:"bên",phone:"điện thoại"};function $i(t){if(!t||typeof t.syncGroup!="string"||!t.syncGroup)return null;const e=t.syncMain?0:po(t.syncOffset);return e===null?null:{o:e,d:(po(t.syncDrift)??0)*1e-6,group:t.syncGroup}}const fn=(t,e)=>e*(1+t.d)+t.o,q0=(t,e)=>(e-t.o)/(1+t.d);function xI(t,e,o=[],r={},{newId:a}={}){const n=[...new Set((Array.isArray(e?.materials)?e.materials:Array.isArray(e?.materialIds)?e.materialIds:[]).filter(I=>typeof I=="string"))];if(n.length<Dr.minAngles||n.length>Dr.maxAngles)throw Error(`multicam needs ${Dr.minAngles}–${Dr.maxAngles} video materials (the synced camera angles)`);const i=n.map(I=>{const O=o.find(B=>B.id===I);if(!O)throw Error(`Không thấy material ${I}`);if(O.kind!=="video"||!O.url)throw Error(`${O.label||I}: multicam angles must be videos`);if(!(po(O.duration)>0))throw Error(`${O.label||I}: unknown duration — open it in Media first`);const L=$i(O);if(!L)throw Error(`${O.label||I} 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}}),c=i[0].s.group;if(i.some(I=>I.s.group!==c))throw Error("These videos were synced in different groups — sync them together first");const u=e.mode??null;if(u!==null&&!Y0.includes(u))throw Error(`multicam mode must be ${Y0.join(" / ")}`);const p=po(e.minShot)??Dr.minShot,s=po(e.maxShot)??Dr.maxShot,h=po(e.wideEvery);if(p<1||p>20)throw Error("minShot must be 1–20 s");if(s<p+.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(I=>$i(I)?.group===c&&(I.kind==="video"||I.kind==="audio")&&po(I.duration)>0&&I.url),m=typeof e.main=="string"?e.main:null;if(m&&!n.includes(m))throw Error("main must be one of the multicam materials");const g=i.find(I=>I.m.id===m)??i.find(I=>I.m.syncMain)??i[0];let v=null;if(typeof e.audioFrom=="string"){const I=f.find(O=>O.id===e.audioFrom);if(!I)throw Error("audioFrom must be a synced video / audio of the same group");v={m:I,s:$i(I)}}else{const I=L=>po(L.syncAudio)??-1/0,O=[...f].sort((L,B)=>I(B)-I(L)||(B.id===g.m.id)-(L.id===g.m.id)||(L.id<B.id?-1:1))[0];v=O&&I(O)>I(g.m)?{m:O,s:$i(O)}:{m:g.m,s:g.s}}const x=I=>({from:I.s.o,to:fn(I.s,po(I.m.duration))}),E=i.map(I=>({...I,role:mI(I.m,i.map(O=>O.m)).role,...x(I)})),$=x(v);let S=null,k=Math.max($.from,Math.min(...E.map(I=>I.from))),y=Math.min($.to,Math.max(...E.map(I=>I.to)));if(e.clipId){if(S=t.find(L=>L.id===e.clipId),!S)throw Error("Clip not found");const I=o.find(L=>L.id===S.nodeId),O=$i(I);if(!O||O.group!==c||!["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,fn(O,S.inPoint||0)),y=Math.min(y,fn(O,(S.inPoint||0)+S.duration))}po(e.inPoint)!==null&&(k=Math.max(k,po(e.inPoint))),po(e.duration)!==null&&(y=Math.min(y,k+Math.max(0,po(e.duration))));let C=t.filter(I=>I!==S);const A=ut(Math.max(0,po(e.start)??(S?S.start:C.filter(I=>I.track===0).reduce((I,O)=>Math.max(I,O.start+O.duration),0))));let z="";if(A+(y-k)>Xn&&(y=k+Xn-A,z=` (cut at the ${Xn/60}-minute timeline limit)`),!(y-k>=p))throw Error("The synced videos do not overlap the sound long enough for a multicam edit");const j=[g,v,...i].find(I=>I.m.words?.length)??[g,v,...i].find(I=>I.m.transcript?.length)??null,P=I=>(Array.isArray(I)?I:[]).filter(O=>Number.isFinite(O?.start)&&Number.isFinite(O?.end)).map(O=>({...O,start:fn(j.s,O.start),end:fn(j.s,O.end)})),F=j?.m.words?.length?P(j.m.words):[],N=F.length?gI(F):j?yI(P(j.m.transcript)):[],G=[];for(let I=1;I<F.length;I++)F[I].start-F[I-1].end>=.12&&G.push({start:F[I-1].end,end:F[I].start});if(!F.length)for(const I of[g,v])for(const O of Array.isArray(I.m.pauses)?I.m.pauses:[])Number.isFinite(O?.start)&&Number.isFinite(O?.end)&&G.push({start:fn(I.s,O.start),end:fn(I.s,O.end)});const V=[v,...f.map(I=>({m:I,s:$i(I)}))].find(I=>Array.isArray(I.m.beats?.beats)&&I.m.beats.beats.length&&(I.m.beats.confidence??0)>=.35),et=V?V.m.beats.beats.map(I=>fn(V.s,I)):[],U=u??(N.length?"sentence":et.length?"beat":"sentence");if(U==="beat"&&!et.length)throw Error("mode beat needs a song with a beat grid in the group (Media → Nhạc, analysed)");const at=E.filter(I=>I.role==="wide"||I.m.id===g.m.id),W=I=>at.some(O=>(O.m.scenes||[]).some(L=>Number(L?.people)>=2&&fn(O.s,L.start)<=I&&fn(O.s,L.end)>I)),_=wI({angles:E.map(I=>({id:I.m.id,role:I.role,from:I.from,to:I.to})),span:[k,y],sentences:N,beats:et,gaps:G,mode:U,minShot:p,maxShot:s,wideEvery:h,crowd:W});if(!_.length)throw Error("No camera angle covers the synced sound");const J=A+(y-k),tt=I=>C.some(O=>O.track===I&&O.start<J-1e-6&&O.start+O.duration>A+1e-6),rt=po(e.track),D=rt!==null&&!tt(rt)&&!r[rt]?.locked?rt:!tt(0)&&!r[0]?.locked&&!r[0]?.hidden?0:Kt(C,r,A,J,null).track,q=Ji.find(I=>!r[I]?.locked&&!tt(I));if(q===void 0)throw Error("Không còn hàng audio trống cho âm thanh multicam");if(C.length+_.length+1>tl)throw Error(`Tối đa ${tl} clip — chọn đoạn ngắn hơn (inPoint / duration) hoặc maxShot dài hơn`);const pt=[],yt=[],Mt=(I,O)=>I<=O+.001?ut(I):Math.floor(O*ve+1e-6)/ve,l=+Math.max(0,q0(v.s,k)).toFixed(4),lt=Mt(y-k,po(v.m.duration)-l),K={id:a(),nodeId:v.m.id,track:q,start:A,duration:lt,inPoint:l,volume:1,url:v.m.url,...v.m.gcsUri?{gcsUri:v.m.gcsUri}:{},kind:"audio",label:`${v.m.label||"Audio"} · multicam audio`,sourceDuration:po(v.m.duration)};pt.push(K.id),yt.push(K);const d={};for(const I of _){const O=E.find(st=>st.m.id===I.id),L=ut(A+I.start-k),B=ut(A+I.end-k),H=+Math.max(0,q0(O.s,k+(L-A))).toFixed(4),Z=Mt(B-L,po(O.m.duration)-H);if(Z<1/ve)continue;const ot={id:a(),nodeId:O.m.id,track:D,start:L,duration:Z,inPoint:H,volume:0,url:O.m.url,...O.m.gcsUri?{gcsUri:O.m.gcsUri}:{},kind:"video",label:`${O.m.label||"Video"} · ${kI[I.role]??I.role}`,sourceDuration:po(O.m.duration)};pt.push(ot.id),yt.push(ot),d[I.role]=(d[I.role]||0)+1}const T=`multicam: ${yt.length-1} shots from ${new Set(_.map(I=>I.id)).size} angles (${Object.entries(d).map(([I,O])=>`${I} ${O}`).join(", ")}), cut on ${U}${N.length?"":" (no transcript: pauses / rhythm)"}, audio from ${v.m.label||v.m.id}, ${ut(y-k)}s${z}`;return{clips:[...C,...yt],created:pt,note:T,plan:_}}const Z0=3,J0=40,Hl=[1,6],Ls={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},MI={rgb:"invert",luma:"luma-invert"},vI=30,$I=t=>!!t&&mh(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 EI(t,e={},{clipIds:o,at:r,frames:a,polarity:n=!1,style:i="anchor",newId:c=()=>`mt-${Math.random().toString(36).slice(2,9)}`}={}){const u=i==="strobe",p=[...new Set(Array.isArray(o)?o:[])];if(p.length<Z0||p.length>J0)throw Error(`A montage needs ${Z0}–${J0} clips`);const s=p.map(C=>t.find(A=>A.id===C));if(s.some(C=>!C))throw Error("Clip not found");if(s.some(C=>!$I(C)))throw Error("A montage takes filmed clips or photos only (no motion, text, shape or generator layers)");if(s.some(C=>e[C.track]?.locked))throw Error("Track đã khóa");const h=Math.round(Number.isFinite(a)?a:u?Ls.frames:2);if(h<Hl[0]||h>Hl[1])throw Error(`Frames per shot must be ${Hl[0]}–${Hl[1]}`);const f=u?s.flatMap((C,A)=>Ls.invert(A)?[{c:C,copy:!0,inv:"luma"},{c:C,inv:null}]:[{c:C,inv:null}]):s.map((C,A)=>({c:C,inv:n&&A%2?"rgb":null})),m=ut(h/vI),g=s[0].track,v=ut(Number.isFinite(r)?Math.max(0,r):Math.min(...s.map(C=>C.start))),x=v+m*f.length,E=t.find(C=>!p.includes(C.id)&&C.track===g&&C.kind!=="audio"&&C.start<x-1e-6&&C.start+C.duration>v+1e-6);if(E)throw Error(`No room for the montage on that track (${E.label??E.id} is in the way from ${v.toFixed(2)} to ${x.toFixed(2)} s)`);const $=(C,A,z,j)=>{const{transition:P,join:F,visualFadeIn:N,visualFadeOut:G,fadeInColor:V,fadeOutColor:et,enter:U,exit:at,audioFadeIn:W,audioFadeOut:_,...J}=C;let tt={...J,id:j,track:g,start:ut(v+A*m),duration:m,posX:0,posY:0,volume:0};const rt=C.playbackRate||1;C.kind==="video"&&Number.isFinite(C.sourceDuration)&&(C.inPoint||0)+m*rt>C.sourceDuration&&(tt.inPoint=Math.max(0,C.sourceDuration-m*rt));for(const q of["x","y"])Ee(tt,q).length&&(tt={...tt,motionKeys:br(tt,q,[])});const D=(tt.effects??[]).filter(q=>q.type!=="invert"&&q.type!=="luma-invert");return z&&D.push({type:MI[z],amount:1}),D.length?tt.effects=D:delete tt.effects,tt},S=f.map((C,A)=>$(C.c,A,C.inv,C.copy?c():C.c.id)),k=new Map(S.filter(C=>p.includes(C.id)).map(C=>[C.id,C]));let y=[...t.map(C=>k.get(C.id)??C),...S.filter(C=>!p.includes(C.id))];return u&&S.forEach((C,A)=>{const z=vn(Ls.ticks[A%Ls.ticks.length]);if(z)try{y=[...y,ha(y,e,z,C.start,{volume:Ls.volume,id:c()})]}catch{}}),y}const SI=Object.freeze(["map","cork","wall","paper"]),Q0=Object.freeze(["year","place","photo","file","news","type","counter","portrait"]),ar=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}}),tg=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]]}),uo=t=>Math.round(t*100)/100,Zd=t=>Math.round(t*1e3)/1e3,II=/^#[0-9a-fA-F]{6}$/,Ro=(t,e=ar.text)=>typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,e):"",ju=t=>typeof t=="number"&&Number.isFinite(t)?t:typeof t=="string"&&t.trim()&&Number.isFinite(+t)?+t:null;function AI(t={},e=0){const o=Q0.includes(t?.kind)?t.kind:null;if(!o)throw Error(`documentary station ${e+1}: kind must be one of ${Q0.join(" | ")}`);const r={kind:o},a=ju(t.at),n=ju(t.hold),i=Ro(t.say,120);a!==null&&(r.at=uo(Math.max(0,a))),n!==null&&(r.hold=uo(Math.min(12,Math.max(1,n)))),i&&(r.say=i);const c=(u,p)=>{const s=Ro(t[u],p);if(!s)throw Error(`documentary station ${e+1} (${o}) needs ${u}`);return s};if(o==="year"){r.text=c("text",24);const u=Ro(t.sub,60);u&&(r.sub=u)}if(o==="place"){r.label=c("label",48);const u=Ro(t.sub,60);u&&(r.sub=u),Array.isArray(t.lonlat)&&t.lonlat.length===2&&t.lonlat.every(Number.isFinite)&&(r.lonlat=t.lonlat.map(Zd));const p=Ro(t.query,120);p&&(r.query=p)}if(o==="photo"){const u=Ro(t.caption,48);u&&(r.caption=u)}if(o==="file"){r.title=Ro(t.title,40)||"HỒ SƠ",r.text=c("text");const u=Ro(t.sub,60);u&&(r.sub=u)}if(o==="news"){r.headline=c("headline",90),r.paper=Ro(t.paper,40)||"NHẬT BÁO";const u=Ro(t.date,48),p=Ro(t.deck,90),s=Ro(t.stamp,22);u&&(r.date=u),p&&(r.deck=p),s&&(r.stamp=s)}if(o==="type"){r.text=c("text",60);const u=Ro(t.then,40);u&&(r.then=u)}if(o==="counter"){r.label=c("label",48);const u=ju(t.value);if(u===null||u<0)throw Error(`documentary station ${e+1} (counter) needs value ≥ 0`);r.value=Math.min(9e15,Math.round(u));const p=Ro(t.unit,16);p&&(r.unit=p)}if(o==="portrait"){const u=Ro(t.title,40),p=Ro(t.sub,60);u&&(r.title=u),p&&(r.sub=p)}if(o==="photo"||o==="portrait"){const u=typeof t.asset=="string"?t.asset.trim():"";if(u){if(!/^(?:gs:\/\/[a-z0-9._-]{3,63}\/[A-Za-z0-9._\/%-]{1,240}|local:[A-Za-z0-9._-]{1,100})$/.test(u)||u.includes(".."))throw Error(`documentary station ${e+1}: asset must be a picture of the Media bin`);r.asset=u}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 CI(t={}){const e=Array.isArray(t.stations)?t.stations:[];if(!e.length)throw Error("documentary needs stations [{kind, …}]");if(e.length>ar.maxStations)throw Error(`documentary: at most ${ar.maxStations} stations`);return{style:SI.includes(t.style)?t.style:"map",accent:II.test(t.accent??"")?t.accent.toLowerCase():ar.accent,sfx:t.sfx!==!1,stations:e.map(AI)}}function jI(t,e=()=>null){const o=[];let r=.2;for(const[h,f]of t.stations.entries()){const m={...f},g=m.hold??ar.hold[m.kind];let v=m.at??(m.say?e(m.say,r-.5):null);v=v==null?r:Math.max(v-.35,h?o[h-1].t0+1.1:0),m.t0=uo(v),m.t1=uo(v+g),r=m.t1,o.push(m)}for(let h=0;h<o.length-1;h++)o[h].t1=uo(Math.max(o[h].t1,Math.min(o[h].t1,o[h+1].t0)));const a=Math.min(ar.maxSeconds,uo(o.at(-1).t1+.6));let n=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=ar.width[f.kind],g=f.kind==="place"&&t.style==="map";f.x=uo(g?n:n+m/2),f.y=uo(h?(i(h)-.5)*70:0),f.rot=uo((i(h+7)-.5)*(f.kind==="type"||f.kind==="counter"||f.kind==="portrait"||f.kind==="year"?0:5)),n+=g?200:m+170,f.asset&&(f.a=`p${h}`)}const c=[];for(const[h,f]of o.entries()){const m=ar.zoom[f.kind],g=h?Math.min(1.05,Math.max(.5,(f.t0-o[h-1].t0)*.42)):0,v=f.x,x=f.y+(f.kind==="news"?-20:0),E=h&&t.style==="map"&&o[h-1].kind==="place";E&&c.push([uo(f.t0+.9),o[h-1].x,o[h-1].y,ar.zoom.place]);const $=h?E?f.t0+1.7:f.t0+g*.55:0;c.push([uo($),v,x,m]),f.kind==="file"&&c.push([uo(f.t0+1.4),v,x-20,m*1.05],[uo(f.t0+2.1),v-10,x-30,m*1.45]),f.kind==="news"&&c.push([uo(f.t0+1.6),v,x+30,m*1.2]),c.push([uo(Math.max($+.3,f.t1-(h<o.length-1?Math.min(.9,(o[h+1].t0-f.t0)*.3):0))),v+6,x-4,c.at(-1)[3]*1.04])}for(let h=1;h<c.length;h++)c[h][0]<=c[h-1][0]&&(c[h][0]=uo(c[h-1][0]+.05));const u=new Set(["photo","file","news","place"]);for(const[h,f]of o.entries())if(f.kind==="place"&&t.style==="map"){const m=o.findIndex((g,v)=>v>h&&u.has(g.kind)&&g.kind!=="place");m>0&&(f.q=m,f.t2=uo(o[m].t0+1.3))}const p=[];if(t.sfx)for(const h of o){for(const[f,m]of tg[h.kind]??[])p.push([f,uo(h.t0+m)]);h.kind==="news"&&h.stamp&&p.push([tg.stamp[0][0],uo(h.t0+2.05)])}const s=t.style==="map"?o.find(h=>h.kind==="place"):null;return{style:t.style,accent:t.accent,total:a,K:c,S:o,sfx:p,place:s?{lonlat:s.lonlat??null,query:s.query??s.label}:null}}const TI=`
205
+ const ACC=SPEC.accent,INK='#2a2622',PAPER='#e8e2d2',CREAM='#ece6d8',LIGHT=SPEC.style==='paper',WARM=SPEC.style==='wall'||LIGHT,FG=LIGHT?INK:CREAM
206
+ 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)
207
+ 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)}
208
+ const hash=i=>{const s=Math.sin(i*127.1+311.7)*43758.5453;return s-Math.floor(s)}
209
+ const K=SPEC.K
210
+ function cam(t){
211
+ if(t<=K[0][0])return {x:K[0][1],y:K[0][2],z:K[0][3]}
212
+ if(t>=K[K.length-1][0]){const k=K[K.length-1];return {x:k[1],y:k[2],z:k[3]}}
213
+ let i=0;while(i<K.length-2&&t>K[i+1][0])i++
214
+ const a=K[i],b=K[i+1],h=b[0]-a[0],u=cl((t-a[0])/h)
215
+ 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}
216
+ 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
217
+ 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}
218
+ return {x:H(1),y:H(2),z:H(3,true)}
219
+ }
220
+ const typed=(s,p)=>s.slice(0,Math.floor(s.length*cl(p)))
221
+ const plain=s=>s.replace(/\\*/g,'')
222
+ 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()}
223
+ 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()}
224
+ 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)}}
225
+ // wrapped text with *marked* words: draws it, returns the marked words' boxes [[x,y,w,h]] (one per line)
226
+ 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}
227
+ const sp=ctx.measureText(' ').width,boxes=[];let cx=x,cy=y,cur=null
228
+ 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}
229
+ if(draw!==false)ctx.fillText(k.wd,cx,cy)
230
+ 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
231
+ cx+=tw+sp}
232
+ return {boxes,bottom:cy+lh}}
233
+ 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
234
+ 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()}
235
+ 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()}
236
+ const STAMPS=new Map()
237
+ 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)
238
+ 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)
239
+ 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()}
240
+ STAMPS.set(key,c);return c}
241
+ const GREY=new Map()
242
+ 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
243
+ 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}
244
+ function photo(ctx,name,x,y,w,h){let bm=null;try{bm=name?M.asset(name):null}catch(e){bm=null}
245
+ 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}
246
+ 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'
247
+ 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()}
248
+ 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}
249
+ function drawStation(ctx,s,T,F,shake){
250
+ 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
251
+ if(out<=0)return
252
+ ctx.save();ctx.globalAlpha*=out;ctx.translate(s.x,s.y);ctx.rotate(s.rot*Math.PI/180)
253
+ 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
254
+ 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]:' '))
255
+ 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()}
256
+ 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)}
257
+ 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)}}
258
+ 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)}
259
+ 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)
260
+ 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)}
261
+ 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)
262
+ 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)}
263
+ 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)
264
+ 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)}
265
+ 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')
266
+ 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)
267
+ 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)
268
+ 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
269
+ 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}
270
+ 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'
271
+ 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)
272
+ 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)}
273
+ 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
274
+ 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)}
275
+ 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'}}}
276
+ 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)
277
+ 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
278
+ 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()}}
279
+ 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
280
+ 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
281
+ 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
282
+ 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)}}
283
+ 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))
284
+ 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)}}
285
+ 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)}}}
286
+ ctx.restore()
287
+ }
288
+ 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
289
+ 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)}
290
+ 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)}
291
+ // wall: warm plaster (its specks travel with the camera); windowLight: the light of a 2 x 3 pane window falling across the
292
+ // frame (screen space: the light stays while the camera glides), drawn over the stations so it falls across the photos too
293
+ 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)
294
+ 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
295
+ 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)}}
296
+ 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])
297
+ 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)'
298
+ 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')
299
+ 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()}
300
+ // paper: grid paper that travels with the camera, soft crumple light; torn: red and navy torn paper over the corners, slid in
301
+ 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
302
+ 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()
303
+ 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)}}
304
+ function torn(ctx,W,H,T){const u=Math.min(W,H),k=1-eo(seg(T,0,.9))
305
+ 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}
306
+ 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()}
307
+ 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()}
308
+ piece([[0,H*.36],[0,0],[W*.58,0]],[W*.58,0,0,H*.36],'#8b1c22',11,-W*.6,-H*.4)
309
+ piece([[W*.62,H],[0,H],[0,H*.74]],[0,H*.74,W*.62,H],'#1c2a52',37,-W*.6,H*.4)}
310
+ function render(ctx,t,env){
311
+ 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)))
312
+ 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)}
313
+ 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)}
314
+ // the place ping: on the map's centre (style map — the map layer below holds still)
315
+ 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
316
+ ctx.save();ctx.globalAlpha=pA*fin;const px=W/2,py=H/2
317
+ 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()}
318
+ 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()
319
+ 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()}
320
+ 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
321
+ // red string: cork = from each pinned thing to the next; map = from the place ping (the frame centre) to the next pinned thing
322
+ 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()}
323
+ ctx.save();ctx.globalAlpha=fin;ctx.strokeStyle='rgba(190,34,26,.92)';ctx.lineWidth=2.6*S
324
+ 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}}
325
+ 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)))}
326
+ ctx.restore()
327
+ ctx.save();ctx.globalAlpha=fin;ctx.setTransform(z,0,0,z,ox,oy)
328
+ 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)}
329
+ ctx.restore()
330
+ if(SPEC.style==='wall')windowLight(ctx,W,H,T);if(LIGHT)torn(ctx,W,H,T)
331
+ 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)}
332
+ 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()
333
+ }`;function OI(t){const e={style:t.style,accent:t.accent,total:t.total,K:t.K,S:t.S.map(({at:o,say:r,hold:a,asset:n,lonlat:i,query:c,...u})=>u)};return`const SPEC=${JSON.stringify(e)};const DOCW=${JSON.stringify(ar.width)};
334
+ ${TI}`}function zI({ids:t,at:e,plan:o,label:r}){const a=OI(o),n={};for(const u of o.S)u.a&&u.asset&&(n[u.a]=u.asset);const i=Math.ceil(o.total/ar.layerSeconds-1e-6),c=[];for(let u=0;u<i;u++){const p=u*ar.layerSeconds,s=Math.min(ar.layerSeconds,o.total-p);c.push({id:t[u],nodeId:"",kind:"image",url:"",volume:0,start:Zd(e+p),duration:Zd(s),label:`${r||"Phim tư liệu"}${i>1?` · ${u+1}/${i}`:""}`,motionV:2,posX:0,posY:0,scale:1,motion:Qe({code:a,params:{off:p},assets:n})})}return c}const Tu=(t,e=.45)=>({color:t,blur:e,x:0,y:0}),PI={"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:Tu("{accent}",.6),opacity:.85},{type:"text",fill:"{color}",shadow:Tu("{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:Tu("{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}}},Jd=Object.freeze(Object.fromEntries(Object.entries(PI).map(([t,e])=>[t,Object.freeze({...e,design:Gx(e.design,`estateText.${t}`),animation:Vx(e.animation,`estateText.${t}`)})])));Object.freeze(Object.keys(Jd));const LI={top:-.3,center:0,lower:.24},FI=1.7;function NI(t,{portrait:e=!1}={}){const o=Jd[t.preset]??Jd["neon-cyan"],r=t.start??t.at,a=["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:a,align:"center",design:e?{...o.design,maxWidth:.52}:o.design,animation:o.animation,posX:t.posX??0,posY:t.posY??LI[a]*(e?.8:1),scale:t.scale??(e?FI:1),...t.track!=null?{track:t.track}:{}}}const va=t=>Math.round(t*10)/10,b=(t,e)=>`${va(t)} ${va(e)}`,Ln=.5523,Se=(t,e,o,r)=>`M${b(t+o,e)} C${b(t+o,e+r*Ln)} ${b(t+o*Ln,e+r)} ${b(t,e+r)} C${b(t-o*Ln,e+r)} ${b(t-o,e+r*Ln)} ${b(t-o,e)} C${b(t-o,e-r*Ln)} ${b(t-o*Ln,e-r)} ${b(t,e-r)} C${b(t+o*Ln,e-r)} ${b(t+o,e-r*Ln)} ${b(t+o,e)} Z`,$t=(t,e,o)=>Se(t,e,o,o);function RI(t,e,o,r,a=0){if(a=Math.max(0,Math.min(a,o/2,r/2)),!a)return`M${b(t,e)} L${b(t+o,e)} L${b(t+o,e+r)} L${b(t,e+r)} Z`;const n=a*(1-Ln);return`M${b(t+a,e)} L${b(t+o-a,e)} C${b(t+o-n,e)} ${b(t+o,e+n)} ${b(t+o,e+a)} L${b(t+o,e+r-a)} C${b(t+o,e+r-n)} ${b(t+o-n,e+r)} ${b(t+o-a,e+r)} L${b(t+a,e+r)} C${b(t+n,e+r)} ${b(t,e+r-n)} ${b(t,e+r-a)} L${b(t,e+a)} C${b(t,e+n)} ${b(t+n,e)} ${b(t+a,e)} Z`}const ft=(t,e,o,r,a=0)=>RI(t-o/2,e-r/2,o,r,a),Pt=(t,e=!0)=>"M"+t.map(o=>b(o[0],o[1])).join(" L")+(e?" Z":"");function Ea(t,e=!0,o=1){const r=t.length,a=i=>e?t[(i+r)%r]:t[Math.max(0,Math.min(r-1,i))];let n=`M${b(...t[0])}`;for(let i=0;i<(e?r:r-1);i++){const c=a(i-1),u=a(i),p=a(i+1),s=a(i+2),h=o/6;n+=` C${b(u[0]+(p[0]-c[0])*h,u[1]+(p[1]-c[1])*h)} ${b(p[0]-(s[0]-u[0])*h,p[1]-(s[1]-u[1])*h)} ${b(...p)}`}return e?n+" Z":n}const no=t=>t*Math.PI/180,up=(t,e,o,r,a,n,i=10)=>Array.from({length:i+1},(c,u)=>{const p=no(a+(n-a)*u/i);return[t+Math.cos(p)*o,e+Math.sin(p)*r]}),He=(t,e,o,r,a,n=o)=>Ea(up(t,e,o,n,r,a),!1),Ob=(t,e,o,r,a=-90)=>Array.from({length:o},(n,i)=>{const c=no(a+i*360/o);return[t+Math.cos(c)*r,e+Math.sin(c)*r]}),Ve=(t,e,o,r,a,n=-90)=>Pt(Array.from({length:o*2},(i,c)=>{const u=no(n+c*180/o),p=c%2?a:r;return[t+Math.cos(u)*p,e+Math.sin(u)*p]})),At=(t,e,o,r)=>`M${b(t,e)} L${b(o,r)}`,wt=(...t)=>t.join(" ");function or(t,e,o,r,a){const n=Math.atan2(r-e,o-t)*180/Math.PI,i=a/2;return Pt([...up(o,r,i,i,n-90,n+90,6),...up(t,e,i,i,n+90,n+270,6)])}function $o(t,e,o,r,a=6){const n=[],i=a*6;for(let c=0;c<i;c++){const u=c/i,p=Math.PI*2*u,s=Math.max(0,-Math.sin(p)),h=Math.abs(Math.sin(p*a/2)),f=1+(.18*s+.06)*h;n.push([t+Math.cos(p)*o/2*f,e+Math.sin(p)*r/2*(Math.sin(p)>0?.82:f)])}return Ea(n,!0)}function DI(t,e,o,r=1,a=9,n=.18){const i=[];for(let c=0;c<a;c++){const u=Math.PI*2*c/a,p=Math.sin(r*12.9898+c*78.233)*43758.5453,s=(p-Math.floor(p))*2-1;i.push([t+Math.cos(u)*o*(1+n*s),e+Math.sin(u)*o*(1+n*s)])}return Ea(i,!0)}const dp=(t,e,o)=>`M${b(t,e+o*.9)} C${b(t-o*1.3,e+o*.05)} ${b(t-o*1.05,e-o*.95)} ${b(t,e-o*.4)} C${b(t+o*1.05,e-o*.95)} ${b(t+o*1.3,e+o*.05)} ${b(t,e+o*.9)} Z`,Un=(t,e,o)=>`M${b(t,e-o)} C${b(t+o*.25,e-o*.45)} ${b(t+o*.75,e-o*.05)} ${b(t+o*.75,e+o*.35)} C${b(t+o*.75,e+o*.8)} ${b(t+o*.4,e+o*1.05)} ${b(t,e+o*1.05)} C${b(t-o*.4,e+o*1.05)} ${b(t-o*.75,e+o*.8)} ${b(t-o*.75,e+o*.35)} C${b(t-o*.75,e-o*.05)} ${b(t-o*.25,e-o*.45)} ${b(t,e-o)} Z`,R=(t,e=1)=>({d:t,fill:null,role:e,_f:!0}),zp=(t,e=1)=>({d:t,fill:null,role:e,_f:!0,eo:!0}),Ot=(t,e=5)=>({d:t,fill:null,role:e,line:!0}),Xl=(t,e)=>({d:t,fill:e,role:7}),zh=Object.freeze(["#f4efe6","#4a90d9","#f2b33d","#e5534b","#ffffff","#2d3142"]),BI=t=>zh[1+((t-1)%5+5)%5];function _I(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:BI(e.role),role:e.role,...e.eo?{eo:!0}:{},...e.line===!1?{line:!1}:{}})}const zb=[],hp={};function io(t,e,o){hp[t]=[e,o]}function ht(t,e,o,r,a,n,i={}){zb.push({id:t,cat:e,vi:o,en:r,words:a,parts:n,human:!!i.human,outline:i.outline??!0,tags:i.tags})}io("people","Người (biểu tượng)","People (pictograms)");const VI=["#f1c7a5","#c68c62","#8d5524"];function cl({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,a=t==="run"?10:t==="elder"?8:0,n=[0,r(18)],i=[a*.6,r(-48)],c=r(-40),u=30*o.w,p=[i[0]+a*.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,[y,C],A,z,j)=>{const P=no(y),F=no(C),N=[k[0]+Math.sin(P)*A,k[1]+Math.cos(P)*A],G=[N[0]+Math.sin(F)*z,N[1]+Math.cos(F)*z];return{d:wt(or(k[0],k[1],N[0],N[1],j),or(N[0],N[1],G[0],G[1],j*.92)),end:G}},f=r(30),m=r(36),g=u/2-o.limb*.35,v=h([i[0]+g,c],s.la,f,f*.95,o.limb),x=h([i[0]-g,c],s.ra,f,f*.95,o.limb),E=h([n[0]+u*.22,n[1]-2],s.ll,m,m,o.limb*1.12),$=h([n[0]-u*.22,n[1]-2],s.rl,m,m,o.limb*1.12),S=Ea([[i[0]-u/2,c-6],[i[0]+u/2,c-6],[n[0]+u*.44,n[1]+4],[n[0]-u*.44,n[1]+4]],!0,.35);return{head:$t(p[0],p[1],o.head),torso:S,la:v,ra:x,ll:E,rl:$}}const fa=(t,e=1)=>[R(wt(t.ll.d,t.rl.d,t.la.d,t.torso,t.ra.d,t.head),e)],GI=[["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"]],Qn={role:["explain","overlay"],style:["clean","minimal","corporate"]};for(const[t,e,o]of GI){const r=cl({pose:t}),a=(r.la.end[0]+r.ra.end[0])/2,n=(r.la.end[1]+r.ra.end[1])/2,i=t==="carry"?[R(ft(a,n-14,58,40,4),2)]:t==="sit"?[R(wt(ft(-14,30,72,10,3),ft(-44,56,8,44,2),ft(18,22,8,112,2)),5)]:t==="present"?[R(ft(-130,-40,90,64,4),4),Ot(wt(At(-160,-20,-102,-20),At(-160,-4,-110,-4),At(-160,12,-120,12)),5)]:[];ht(`person-${t}`,"people",`Người ${e}`,`Person ${o}`,["người","person","human","pictogram",e,o],t==="present"||t==="sit"?[...i,...fa(r)]:[...fa(r),...i],{human:!0,tags:Qn})}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=cl({pose:t==="elder"?"elder":"stand",body:t}),a=t==="elder"?[R(or(-34,-6,-40,72,5),5)]:[];ht(`person-${t}`,"people",`Người ${e}`,`Person ${o}`,["người","person","human","pictogram","body",e,o],[...fa(r,t==="child"?3:1),...a],{human:!0,tags:Qn})}{const t=cl({pose:"stand"}),e=cl({pose:"stand",body:"child"}),o=(r,a)=>r.replace(/(-?\d*\.?\d+) (-?\d*\.?\d+)/g,(n,i,c)=>`${va(+i+a)} ${c}`);ht("people-family","people","Gia đình","Family",["gia đình","family","parent","child","người","people"],[...fa(t).map(r=>({...r,d:o(r.d,-34)})),...fa(e,3).map(r=>({...r,d:o(r.d.replace(/(-?\d*\.?\d+) (-?\d*\.?\d+)/g,(a,n,i)=>`${n} ${va(+i+16)}`),34)}))],{human:!0,tags:Qn}),ht("people-group","people","Nhóm người","Group of people",["nhóm","group","team","đội","people","người"],[...fa(t,2).map(r=>({...r,d:o(r.d,-52)})),...fa(t,3).map(r=>({...r,d:o(r.d,52)})),...fa(t,1)],{human:!0,tags:Qn})}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=cl({pose:t});ht(`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:Qn})}function Pp({skin:t=0,hair:e="short",top:o=1,bottom:r=5,arm:a="down"}){const n=VI[t],i=[];i.push(R(or(-14,40,-16,96,17),r),R(or(14,40,16,96,17),r)),i.push(R(ft(-17,100,26,10,5),5),R(ft(17,100,26,10,5),5));const c=a==="wave"?wt(or(-30,-14,-44,30,13)):or(-30,-14,-40,34,13),u=a==="wave"?or(30,-14,56,-50,13):or(30,-14,40,34,13);return i.push(R(c,o),R(u,o),Xl($t(-41,38,8),n),Xl($t(a==="wave"?58:41,a==="wave"?-56:38,8),n)),i.push(R(Ea([[-30,-24],[30,-24],[34,46],[-34,46]],!0,.4),o)),i.push(Xl(ft(0,-30,14,12,3),n),Xl($t(0,-58,26),n)),e==="short"?i.push(R(wt(`M${b(-27,-60)} C${b(-28,-92)} ${b(28,-92)} ${b(27,-60)} C${b(18,-74)} ${b(-10,-78)} ${b(-27,-60)} Z`),5)):e==="long"?i.push(R(`M${b(-29,-56)} C${b(-34,-96)} ${b(34,-96)} ${b(29,-56)} L${b(30,-20)} L${b(18,-22)} L${b(20,-56)} C${b(8,-70)} ${b(-14,-72)} ${b(-20,-56)} L${b(-18,-22)} L${b(-30,-20)} Z`,5)):i.push(R(`M${b(-28,-62)} C${b(-28,-92)} ${b(28,-92)} ${b(28,-62)} Z`,3),R(ft(14,-64,34,8,4),3)),i.push({...R(wt($t(-9,-58,2.6),$t(9,-58,2.6)),5),line:!1},Ot(He(0,-50,8,20,160),5)),i}ht("character-a","people","Nhân vật phẳng A","Flat character A",["nhân vật","character","người","person","flat"],Pp({skin:0,hair:"short",top:1}),{human:!0,tags:Qn});ht("character-b","people","Nhân vật phẳng B","Flat character B",["nhân vật","character","người","person","flat"],Pp({skin:1,hair:"long",top:3,bottom:2}),{human:!0,tags:Qn});ht("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"],Pp({skin:2,hair:"cap",top:2,arm:"wave"}),{human:!0,tags:Qn});ht("character-d","people","Nhân vật phẳng D","Flat character D",["nhân vật","character","người","person","flat"],Pp({skin:1,hair:"short",top:4,bottom:1,arm:"wave"}),{human:!0,tags:Qn});io("hands","Bàn tay & cử chỉ","Hands & gestures");const Lp=(t=0,e=10)=>ft(t,e,56,58,18),Wo=(t,e,o,r=0,a=14)=>or(t,e,t+Math.sin(no(r))*o,e-Math.cos(no(r))*o,a),Sa={role:["explain","sticker"],style:["playful","clean"]};ht("hand-thumbs-up","hands","Like (giơ ngón cái)","Thumbs up",["like","thích","ngón cái","thumb"],[R(ft(0,14,52,56,14),4),R(Wo(-18,-6,40,-8,18),4),R(wt(ft(18,0,22,12,6),ft(18,14,22,12,6),ft(18,28,22,12,6)),4),R(ft(0,60,58,22,4),1)],{tags:Sa});ht("hand-point","hands","Tay chỉ","Pointing hand",["chỉ","point","tay","hand"],[R(ft(6,14,50,48,14),4),R(or(-10,0,-70,-4,15),4),R(wt(ft(26,0,18,12,6),ft(26,13,18,12,6),ft(26,26,18,12,6)),4),R(ft(14,52,40,20,4),1)],{tags:Sa});ht("hand-open","hands","Bàn tay mở","Open palm",["bàn tay","palm","stop","dừng","hi"],[R(Lp(),4),R(wt(Wo(-20,-10,40,-6),Wo(-6,-14,46,-2),Wo(8,-14,44,2),Wo(21,-10,36,8),Wo(-30,16,30,-60)),4),R(ft(0,52,52,18,4),1)],{tags:Sa});ht("hand-ok","hands","Tay OK","OK hand",["ok","tốt","được"],[R(Lp(4,14),4),R(wt(Wo(-2,-12,44,2),Wo(12,-10,40,8),Wo(24,-4,32,14)),4),R(wt($t(-22,-10,16)),4),Ot($t(-22,-10,7),5)],{tags:Sa});ht("hand-peace","hands","Tay chữ V","Peace sign",["peace","chiến thắng","victory","v"],[R(Lp(0,16),4),R(wt(Wo(-10,-8,50,-14),Wo(8,-8,50,12)),4),R(ft(0,54,52,18,4),1)],{tags:Sa});ht("hand-fist","hands","Nắm tay","Fist",["nắm tay","fist","power","sức mạnh"],[R(ft(0,4,60,54,16),4),Ot(wt(At(-14,-22,-14,-6),At(2,-22,2,-6),At(18,-22,18,-6)),5),R(ft(0,48,52,22,4),1)],{tags:Sa});ht("hand-wave","hands","Tay vẫy","Waving hand",["vẫy","wave","hello","xin chào"],[R(Lp(),4),R(wt(Wo(-20,-10,40,-16),Wo(-6,-14,46,-8),Wo(8,-14,44,-2),Wo(21,-10,36,4),Wo(-30,16,30,-70)),4),Ot(wt(He(48,-30,16,-60,40),He(48,-30,28,-60,40)),3)],{tags:Sa});ht("hand-clap","hands","Vỗ tay","Clapping hands",["vỗ tay","clap","applause"],[R(ft(-14,4,40,70,16),4),R(ft(14,0,40,70,16),4),Ot(wt(At(-48,-40,-38,-30),At(-30,-56,-26,-42),At(46,-44,36,-32)),3)],{tags:Sa});io("faces","Mặt & biểu cảm","Faces & emoji");const KI={role:["sticker","social"],style:["playful"]},Gr=(t,e,o,r,a)=>ht(`face-${t}`,"faces",e,o,["mặt","face","emoji","biểu cảm",...r],[R($t(0,0,60),2),...a],{tags:KI}),hi=(t=-12,e=7)=>R(wt($t(-20,t,e),$t(20,t,e)),5);Gr("smile","Mặt cười","Smile",["vui","happy","cười"],[hi(),Ot(He(0,4,28,25,155),5)]);Gr("grin","Cười toe","Grin",["toe","grin","haha"],[hi(),R(`M${b(-32,8)} L${b(32,8)} C${b(30,40)} ${b(-30,40)} ${b(-32,8)} Z`,5),R(`M${b(-24,10)} L${b(24,10)} L${b(22,18)} L${b(-22,18)} Z`,4)]);Gr("sad","Buồn","Sad",["buồn","sad"],[hi(-8),Ot(He(0,38,24,205,335),5)]);Gr("wink","Nháy mắt","Wink",["nháy mắt","wink"],[R($t(-20,-12,7),5),Ot(He(20,-10,9,200,340),5),Ot(He(0,4,28,25,155),5)]);Gr("surprised","Ngạc nhiên","Surprised",["ngạc nhiên","wow","surprised","bất ngờ"],[hi(-14,8),R(Se(0,24,12,16),5)]);Gr("love","Mắt tim","Heart eyes",["yêu","love","tim"],[R(wt(dp(-21,-12,13),dp(21,-12,13)),3),Ot(He(0,4,28,25,155),5)]);Gr("cool","Đeo kính","Cool",["ngầu","cool","kính"],[R(wt(ft(-21,-12,34,20,8),ft(21,-12,34,20,8)),5),Ot(At(-4,-14,4,-14),5),Ot(He(0,10,22,30,150),5)]);Gr("angry","Giận","Angry",["giận","angry","tức"],[hi(-6),Ot(wt(At(-34,-30,-10,-20),At(34,-30,10,-20)),5),Ot(He(0,38,20,210,330),5)]);Gr("laugh","Cười lớn","Laugh",["cười lớn","laugh","lol"],[Ot(wt(He(-20,-10,9,200,340),He(20,-10,9,200,340)),5),R(`M${b(-34,4)} L${b(34,4)} C${b(32,46)} ${b(-32,46)} ${b(-34,4)} Z`,5),R(Se(0,32,14,8),3)]);Gr("think","Suy nghĩ","Thinking",["nghĩ","thinking","hmm"],[hi(-12,6),Ot(At(-16,24,18,18),5),Ot(wt(At(-28,-30,-10,-26)),5)]);Gr("sleepy","Buồn ngủ","Sleepy",["ngủ","sleepy","zzz"],[Ot(wt(At(-28,-10,-12,-10),At(12,-10,28,-10)),5),R(Se(0,24,8,10),5),Ot(wt(Pt([[40,-60],[56,-60],[40,-44],[56,-44]],!1)),5)]);Gr("neutral","Bình thường","Neutral",["bình thường","neutral","meh"],[hi(),Ot(At(-20,22,20,22),5)]);io("nature","Thiên nhiên","Nature");const so={role:["overlay","background","explain"],style:["playful","soft","clean"]};ht("tree-round","nature","Cây tán tròn","Round tree",["cây","tree","xanh"],[R(ft(0,50,18,70,4),5),R($o(0,-20,140,120,5),1)],{tags:so});ht("tree-pine","nature","Cây thông","Pine tree",["thông","pine","cây","noel"],[R(ft(0,78,16,34,3),5),R(Pt([[0,-96],[46,-28],[24,-28],[60,30],[30,30],[70,82],[-70,82],[-30,30],[-60,30],[-24,-28],[-46,-28]]),1)],{tags:so});ht("tree-palm","nature","Cây dừa","Palm tree",["dừa","palm","biển","cây"],[R(`M${b(-4,96)} C${b(-8,40)} ${b(4,-10)} ${b(14,-50)} L${b(26,-46)} C${b(16,-6)} ${b(8,44)} ${b(12,96)} Z`,5),R(wt(`M${b(18,-52)} C${b(-20,-90)} ${b(-60,-70)} ${b(-80,-40)} C${b(-40,-60)} ${b(-10,-56)} ${b(18,-52)} Z`,`M${b(18,-52)} C${b(50,-96)} ${b(90,-80)} ${b(100,-46)} C${b(70,-64)} ${b(44,-60)} ${b(18,-52)} Z`,`M${b(18,-52)} C${b(30,-100)} ${b(10,-120)} ${b(-14,-118)} C${b(6,-104)} ${b(14,-80)} ${b(18,-52)} Z`,`M${b(18,-52)} C${b(60,-40)} ${b(70,-6)} ${b(64,20)} C${b(52,-6)} ${b(38,-30)} ${b(18,-52)} Z`),1)],{tags:so});ht("bush","nature","Bụi cây","Bush",["bụi","bush","cỏ"],[R($o(0,10,170,90,6),1)],{tags:so});ht("flower","nature","Bông hoa","Flower",["hoa","flower"],[R(or(0,10,0,96,8),1),R(`M${b(0,60)} C${b(30,40)} ${b(48,52)} ${b(50,64)} C${b(30,70)} ${b(14,68)} ${b(0,60)} Z`,1),R(wt(...Ob(0,-30,6,30).map(([t,e])=>$t(t,e,20))),3),R($t(0,-30,16),2)],{tags:so});ht("tulip","nature","Hoa tulip","Tulip",["tulip","hoa","flower"],[R(or(0,0,0,96,7),1),R(`M${b(0,64)} C${b(-34,44)} ${b(-40,20)} ${b(-34,4)} C${b(-20,26)} ${b(-10,40)} ${b(0,64)} Z`,1),R(`M${b(-34,-70)} L${b(-17,-46)} L${b(0,-74)} L${b(17,-46)} L${b(34,-70)} C${b(40,-20)} ${b(24,4)} ${b(0,4)} C${b(-24,4)} ${b(-40,-20)} ${b(-34,-70)} Z`,3)],{tags:so});ht("leaf","nature","Chiếc lá","Leaf",["lá","leaf"],[R(`M${b(-70,60)} C${b(-70,-20)} ${b(-10,-80)} ${b(70,-70)} C${b(70,10)} ${b(10,70)} ${b(-70,60)} Z`,1),Ot(wt(`M${b(-70,60)} C${b(-20,10)} ${b(20,-30)} ${b(60,-60)}`,At(-24,16,-30,-10),At(4,-12,2,-40),At(-24,16,4,22),At(4,-12,30,-6)),5)],{tags:so});ht("cactus","nature","Xương rồng","Cactus",["xương rồng","cactus","sa mạc"],[R(ft(0,80,70,30,4),3),R(wt(ft(0,0,36,150,18),`M${b(-18,10)} L${b(-40,10)} C${b(-50,10)} ${b(-54,4)} ${b(-54,-6)} L${b(-54,-40)} C${b(-54,-52)} ${b(-38,-52)} ${b(-38,-40)} L${b(-38,-6)} L${b(-18,-6)} Z`,`M${b(18,20)} L${b(42,20)} C${b(52,20)} ${b(56,14)} ${b(56,4)} L${b(56,-24)} C${b(56,-36)} ${b(40,-36)} ${b(40,-24)} L${b(40,4)} L${b(18,4)} Z`),1)],{tags:so});ht("mushroom","nature","Cây nấm","Mushroom",["nấm","mushroom"],[R(`M${b(-20,0)} L${b(20,0)} L${b(24,70)} L${b(-24,70)} Z`,4),R(`M${b(-80,10)} C${b(-80,-70)} ${b(80,-70)} ${b(80,10)} Z`,3),R(wt($t(-36,-20,10),$t(10,-40,12),$t(44,-10,8)),4)],{tags:so});ht("grass","nature","Đám cỏ","Grass tuft",["cỏ","grass"],[R(Pt([[-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:so});ht("mountain","nature","Núi","Mountain",["núi","mountain"],[R(Pt([[-110,70],[-20,-70],[90,70]]),1),R(Pt([[-20,-70],[-44,-32],[-30,-38],[-18,-26],[-4,-40],[8,-30]]),4),R(Pt([[20,70],[70,-10],[120,70]]),2)],{tags:so});ht("hills","nature","Đồi","Hills",["đồi","hills","đồng cỏ"],[R(`M${b(-130,60)} C${b(-90,-30)} ${b(-30,-30)} ${b(10,60)} Z`,1),R(`M${b(-30,60)} C${b(10,-50)} ${b(90,-50)} ${b(130,60)} Z`,2)],{tags:so});ht("rock","nature","Hòn đá","Rock",["đá","rock","stone"],[R(Ea([[-60,40],[-50,-10],[-14,-34],[30,-26],[58,8],[60,40]],!0,.5),5)],{tags:so});ht("sun","nature","Mặt trời","Sun",["mặt trời","sun","nắng"],[R(Ve(0,0,12,96,70,-90),3),R($t(0,0,58),2)],{tags:so});ht("moon","nature","Trăng khuyết","Crescent moon",["trăng","moon","đêm","night"],[R(`M${b(20,-70)} C${b(-40,-70)} ${b(-70,-20)} ${b(-60,20)} C${b(-50,60)} ${b(0,80)} ${b(40,60)} C${b(0,50)} ${b(-24,10)} ${b(-10,-30)} C${b(-2,-52)} ${b(10,-64)} ${b(20,-70)} Z`,2),R(wt(Ve(50,-40,4,10,4,0),Ve(60,20,4,7,3,0)),4)],{tags:so});ht("cloud","nature","Đám mây","Cloud",["mây","cloud"],[R($o(0,0,190,100,6),4)],{tags:so});ht("waves","nature","Sóng biển","Waves",["sóng","biển","sea","waves","nước"],[R(`M${b(-120,0)} C${b(-100,-30)} ${b(-80,-30)} ${b(-60,0)} C${b(-40,-30)} ${b(-20,-30)} ${b(0,0)} C${b(20,-30)} ${b(40,-30)} ${b(60,0)} C${b(80,-30)} ${b(100,-30)} ${b(120,0)} L${b(120,50)} L${b(-120,50)} Z`,1),Ot(wt(`M${b(-110,24)} C${b(-90,10)} ${b(-70,10)} ${b(-50,24)}`,`M${b(10,30)} C${b(30,16)} ${b(50,16)} ${b(70,30)}`),4)],{tags:so});ht("river","nature","Dòng sông","River",["sông","river","suối"],[R(`M${b(-30,-90)} C${b(30,-60)} ${b(-60,-10)} ${b(-10,30)} C${b(30,60)} ${b(-10,80)} ${b(10,100)} L${b(70,100)} C${b(40,80)} ${b(80,50)} ${b(40,20)} C${b(-10,-20)} ${b(70,-60)} ${b(10,-90)} Z`,1)],{tags:so});ht("island","nature","Đảo nhỏ","Island",["đảo","island","biển"],[R(`M${b(-110,50)} C${b(-60,20)} ${b(60,20)} ${b(110,50)} Z`,1),R(`M${b(-70,40)} C${b(-50,0)} ${b(50,0)} ${b(70,40)} Z`,3),R(`M${b(0,30)} C${b(-4,0)} ${b(4,-30)} ${b(12,-54)} L${b(20,-50)} C${b(12,-28)} ${b(8,0)} ${b(10,30)} Z`,5),R(wt(`M${b(14,-56)} C${b(-10,-80)} ${b(-40,-70)} ${b(-50,-50)} C${b(-24,-62)} ${b(-4,-60)} ${b(14,-56)} Z`,`M${b(14,-56)} C${b(36,-84)} ${b(64,-74)} ${b(70,-52)} C${b(50,-64)} ${b(32,-62)} ${b(14,-56)} Z`),1)],{tags:so});ht("rainbow","nature","Cầu vồng","Rainbow",["cầu vồng","rainbow"],[R(`M${b(-100,40)} C${b(-100,-90)} ${b(100,-90)} ${b(100,40)} L${b(80,40)} C${b(80,-66)} ${b(-80,-66)} ${b(-80,40)} Z`,3),R(`M${b(-80,40)} C${b(-80,-66)} ${b(80,-66)} ${b(80,40)} L${b(60,40)} C${b(60,-42)} ${b(-60,-42)} ${b(-60,40)} Z`,2),R(`M${b(-60,40)} C${b(-60,-42)} ${b(60,-42)} ${b(60,40)} L${b(40,40)} C${b(40,-18)} ${b(-40,-18)} ${b(-40,40)} Z`,1),R($o(-80,46,70,36,4),4),R($o(80,46,70,36,4),4)],{tags:so});io("weather","Thời tiết","Weather");const ta={role:["overlay","explain","sticker"],style:["playful","clean"]};ht("weather-sun-cloud","weather","Nắng có mây","Sun and cloud",["nắng","mây","partly cloudy"],[R(Ve(-26,-24,10,62,46,-90),3),R($t(-26,-24,38),2),R($o(20,20,150,80,5),4)],{tags:ta});ht("weather-rain","weather","Mây mưa","Rain cloud",["mưa","rain"],[R($o(0,-20,170,90,6),4),R(wt(Un(-40,58,12),Un(0,72,12),Un(40,58,12)),1)],{tags:ta});ht("weather-storm","weather","Giông bão","Storm",["bão","sấm","storm","thunder"],[R($o(0,-24,170,90,6),5),R(Pt([[6,10],[-20,56],[0,56],[-12,96],[30,40],[10,40],[24,10]]),2)],{tags:ta});ht("weather-snow","weather","Tuyết rơi","Snow",["tuyết","snow","lạnh"],[R($o(0,-24,170,90,6),4),Ot(wt(...[[-40,60],[0,74],[40,60]].flatMap(([t,e])=>[At(t-9,e,t+9,e),At(t-5,e-8,t+5,e+8),At(t-5,e+8,t+5,e-8)])),1)],{tags:ta});ht("snowflake","weather","Bông tuyết","Snowflake",["tuyết","snowflake","noel"],[Ot(wt(...[0,60,120].map(t=>{const e=Math.cos(no(t)),o=Math.sin(no(t));return At(-80*e,-80*o,80*e,80*o)}),...[0,60,120,180,240,300].flatMap(t=>{const e=Math.cos(no(t)),o=Math.sin(no(t)),r=50*e,a=50*o;return[At(r,a,r+Math.cos(no(t+40))*22,a+Math.sin(no(t+40))*22),At(r,a,r+Math.cos(no(t-40))*22,a+Math.sin(no(t-40))*22)]})),1)],{tags:ta});ht("wind","weather","Gió","Wind",["gió","wind"],[Ot(wt(`M${b(-90,-30)} L${b(30,-30)} C${b(60,-30)} ${b(60,-70)} ${b(34,-70)}`,`M${b(-70,0)} L${b(60,0)} C${b(96,0)} ${b(96,48)} ${b(64,48)}`,`M${b(-100,30)} L${b(0,30)}`),1)],{tags:ta});ht("umbrella","weather","Cái ô","Umbrella",["ô","dù","umbrella","mưa"],[R(`M${b(-90,0)} C${b(-90,-80)} ${b(90,-80)} ${b(90,0)} C${b(70,-14)} ${b(50,-14)} ${b(30,0)} C${b(10,-14)} ${b(-10,-14)} ${b(-30,0)} C${b(-50,-14)} ${b(-70,-14)} ${b(-90,0)} Z`,3),Ot(`M${b(0,-4)} L${b(0,70)} C${b(0,90)} ${b(-26,90)} ${b(-26,72)}`,5)],{tags:ta});ht("thermometer","weather","Nhiệt kế","Thermometer",["nhiệt độ","nóng","thermometer","temperature"],[R(wt(ft(0,-20,30,130,15)),4),R($t(0,56,26),3),R(ft(0,10,12,80,6),3),Ot(wt(At(18,-60,28,-60),At(18,-36,28,-36),At(18,-12,28,-12)),5)],{tags:ta});ht("lightning","weather","Tia sét","Lightning bolt",["sét","lightning","điện","energy"],[R(Pt([[14,-96],[-46,10],[-6,10],[-22,96],[48,-20],[6,-20]]),2)],{tags:ta});io("city","Nhà cửa & phố","Buildings & city");const Po={role:["background","explain","overlay"],style:["clean","playful"]},Ho=(t,e,o=18,r=22)=>ft(t,e,o,r,2);ht("house","city","Ngôi nhà","House",["nhà","house","home"],[R(ft(0,30,140,100,2),4),R(Pt([[-86,-16],[0,-90],[86,-16]]),3),R(ft(40,-70,18,36,1),5),R(ft(-30,50,34,60,3),1),R(wt(Ho(28,20,30,28)),2),Ot(wt(At(28,6,28,34),At(13,20,43,20)),5)],{tags:Po});ht("house-two-storey","city","Nhà hai tầng","Two-storey house",["nhà","nhà phố","townhouse","house"],[R(ft(0,10,120,160,2),4),R(Pt([[-72,-70],[0,-118],[72,-70]]),3),R(wt(Ho(-30,-40,26,30),Ho(30,-40,26,30),Ho(30,30,26,30)),2),R(ft(-30,56,30,68,3),1),R(ft(0,-2,130,8,2),5)],{tags:Po});ht("apartment","city","Chung cư","Apartment block",["chung cư","căn hộ","apartment"],[R(ft(0,0,130,200,4),1),R(wt(...[-70,-30,10,50].flatMap(t=>[-38,0,38].map(e=>Ho(e,t,22,24)))),4),R(ft(0,88,34,24,2),5)],{tags:Po});ht("skyscraper","city","Toà nhà cao tầng","Skyscraper",["cao ốc","tòa nhà","office tower","skyscraper"],[R(Pt([[-40,110],[-40,-80],[0,-110],[40,-80],[40,110]]),2),R(wt(...Array.from({length:8},(t,e)=>ft(0,-60+e*20,56,8,1))),4),R(ft(0,-120,4,30,1),5)],{tags:Po});ht("shop","city","Cửa hàng","Shop",["cửa hàng","shop","store","tiệm"],[R(ft(0,26,150,104,2),4),R(wt(...[-60,-20,20,60].map(t=>`M${b(t-20,-26)} L${b(t+20,-26)} L${b(t+20,-6)} C${b(t+20,6)} ${b(t-20,6)} ${b(t-20,-6)} Z`)),3),R(ft(0,-36,160,22,3),1),R(ft(-36,46,40,60,2),2),R(ft(30,36,50,40,2),2)],{tags:Po});ht("factory","city","Nhà máy","Factory",["nhà máy","factory","sản xuất","industry"],[R(Pt([[-100,80],[-100,-10],[-50,-40],[-50,-10],[0,-40],[0,-10],[50,-40],[50,-10],[100,-10],[100,80]]),4),R(ft(70,-60,22,100,2),5),R($o(84,-100,50,30,4),4),R(wt(Ho(-70,30),Ho(-30,30),Ho(10,30)),2)],{tags:Po});ht("school","city","Trường học","School",["trường","school","học","education"],[R(ft(0,30,170,100,2),4),R(Pt([[-50,-20],[0,-70],[50,-20]]),3),R(ft(0,0,100,40,2),4),R($t(0,-30,12),2),R(wt(Ho(-62,30),Ho(-32,30),Ho(32,30),Ho(62,30)),2),R(ft(0,56,24,48,2),1),Ot(At(0,-70,0,-100),5),R(Pt([[0,-100],[24,-92],[0,-84]]),3)],{tags:Po});ht("hospital","city","Bệnh viện","Hospital",["bệnh viện","hospital","y tế","health"],[R(ft(0,20,170,140,4),4),R(wt(ft(0,-20,40,12,2),ft(0,-20,12,40,2)),3),R(wt(Ho(-56,30),Ho(-26,30),Ho(26,30),Ho(56,30)),2),R(ft(0,68,30,44,2),1)],{tags:Po});ht("bank","city","Ngân hàng","Bank",["ngân hàng","bank","tài chính","finance"],[R(Pt([[-90,-40],[0,-90],[90,-40]]),3),R(ft(0,-34,170,14,2),5),R(wt(...[-60,-20,20,60].map(t=>ft(t,20,16,90,2))),4),R(ft(0,72,180,14,2),5)],{tags:Po});ht("pagoda","city","Chùa / tháp","Pagoda",["chùa","tháp","pagoda","temple","đình"],[R(ft(0,70,70,40,2),4),R(`M${b(-70,48)} C${b(-40,40)} ${b(40,40)} ${b(70,48)} L${b(52,30)} L${b(-52,30)} Z`,3),R(ft(0,10,56,40,2),4),R(`M${b(-58,-8)} C${b(-30,-16)} ${b(30,-16)} ${b(58,-8)} L${b(42,-24)} L${b(-42,-24)} Z`,3),R(ft(0,-40,42,32,2),4),R(`M${b(-46,-54)} C${b(-20,-62)} ${b(20,-62)} ${b(46,-54)} L${b(0,-90)} Z`,3)],{tags:Po});ht("bridge","city","Cây cầu","Bridge",["cầu","bridge"],[R(`M${b(-130,10)} L${b(130,10)} L${b(130,26)} L${b(-130,26)} Z`,5),Ot(wt(`M${b(-130,10)} C${b(-60,-70)} ${b(60,-70)} ${b(130,10)}`,...[-90,-60,-30,0,30,60,90].map(t=>At(t,10,t,10-Math.max(0,62-Math.abs(t)*.6)))),1),R(wt(ft(-80,48,20,44,2),ft(80,48,20,44,2)),5)],{tags:Po});ht("streetlamp","city","Đèn đường","Street lamp",["đèn đường","street lamp","đèn"],[R(ft(0,10,10,180,4),5),R(`M${b(-24,-80)} L${b(24,-80)} L${b(16,-64)} L${b(-16,-64)} Z`,5),R(Se(0,-60,14,8),2),R(ft(0,98,30,10,3),5)],{tags:Po});ht("traffic-light","city","Đèn giao thông","Traffic light",["đèn giao thông","traffic light","đèn xanh đỏ"],[R(ft(0,-10,50,130,12),5),R($t(0,-50,15),3),R($t(0,-10,15),2),R($t(0,30,15),1),R(ft(0,90,10,70,3),5)],{tags:Po});ht("skyline","city","Đường chân trời thành phố","City skyline",["thành phố","city","skyline","phố"],[R(Pt([[-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])=>ft(t,e,8,10,1))),2)],{tags:Po});ht("tent","city","Lều trại","Tent",["lều","cắm trại","tent","camping"],[R(Pt([[-90,60],[0,-70],[90,60]]),3),R(Pt([[-26,60],[0,0],[26,60]]),5),Ot(wt(At(0,-70,-10,-90),At(0,-70,10,-90)),5)],{tags:Po});ht("castle","city","Lâu đài","Castle",["lâu đài","castle","cổ tích"],[R(wt(ft(-60,10,40,130,0),ft(60,10,40,130,0),ft(0,30,90,90,0)),4),R(wt(...[-74,-46,46,74].map(t=>ft(t,-62,12,16,0)),...[-30,0,30].map(t=>ft(t,-22,14,14,0))),4),R(wt(Pt([[-84,-70],[-60,-110],[-36,-70]]),Pt([[36,-70],[60,-110],[84,-70]])),3),R(`M${b(-18,76)} L${b(-18,40)} C${b(-18,20)} ${b(18,20)} ${b(18,40)} L${b(18,76)} Z`,5)],{tags:Po});ht("cafe-front","city","Quán cà phê","Café front",["quán","cà phê","cafe","coffee shop"],[R(ft(0,26,160,104,2),4),R(wt(...[-60,-30,0,30,60].map((t,e)=>`M${b(t-15,-34)} L${b(t+15,-34)} L${b(t+15,-14)} L${b(t-15,-14)} Z`)),3),R(ft(0,-40,170,14,2),1),R(ft(-40,40,46,64,2),2),R(ft(34,40,60,44,2),2),R(wt($t(40,-60,4),At(30,-66,50,-66)),5)],{tags:Po});io("transport","Phương tiện","Transport");const Kr={role:["explain","overlay"],style:["playful","clean"]},wr=(t,e,o=16)=>[R($t(t,e,o),5),R($t(t,e,o*.4),4)];ht("car","transport","Ô tô","Car",["ô tô","xe hơi","car"],[R(`M${b(-100,30)} L${b(-100,0)} C${b(-100,-10)} ${b(-90,-14)} ${b(-80,-16)} L${b(-56,-20)} L${b(-30,-50)} C${b(-24,-56)} ${b(-18,-58)} ${b(-10,-58)} L${b(40,-58)} C${b(50,-58)} ${b(56,-54)} ${b(62,-46)} L${b(80,-20)} C${b(94,-18)} ${b(100,-10)} ${b(100,0)} L${b(100,30)} Z`,3),R(wt(`M${b(-44,-22)} L${b(-24,-46)} L${b(4,-46)} L${b(4,-22)} Z`,`M${b(16,-22)} L${b(16,-46)} L${b(44,-46)} L${b(62,-22)} Z`),4),...wr(-54,32,20),...wr(56,32,20)],{tags:Kr});ht("taxi","transport","Taxi","Taxi",["taxi","xe"],[R(`M${b(-100,30)} L${b(-100,-4)} L${b(-60,-20)} L${b(-36,-52)} L${b(40,-52)} L${b(66,-20)} L${b(100,-6)} L${b(100,30)} Z`,2),R(ft(0,-62,40,14,3),5),R(wt(`M${b(-48,-22)} L${b(-30,-44)} L${b(-2,-44)} L${b(-2,-22)} Z`,`M${b(10,-22)} L${b(10,-44)} L${b(36,-44)} L${b(54,-22)} Z`),4),...wr(-54,32,20),...wr(56,32,20)],{tags:Kr});ht("bus","transport","Xe buýt","Bus",["xe buýt","bus"],[R(ft(0,-10,220,100,14),1),R(wt(...[-80,-40,0,40].map(t=>ft(t,-30,30,30,4)),ft(86,-20,26,50,4)),4),R(ft(0,24,220,8,2),4),...wr(-64,46,20),...wr(64,46,20)],{tags:Kr});ht("truck","transport","Xe tải","Truck",["xe tải","truck","giao hàng","delivery"],[R(ft(-30,-14,140,90,6),4),R(`M${b(44,30)} L${b(44,-30)} L${b(84,-30)} L${b(110,4)} L${b(110,30)} Z`,1),R(`M${b(54,-20)} L${b(80,-20)} L${b(98,2)} L${b(54,2)} Z`,4),...wr(-60,38,18),...wr(70,38,18)],{tags:Kr});ht("bicycle","transport","Xe đạp","Bicycle",["xe đạp","bicycle","bike"],[Ot(wt($t(-56,30,34),$t(56,30,34),Pt([[-56,30],[-14,-26],[36,-26],[56,30]],!1),Pt([[-14,-26],[0,30],[36,-26]],!1),At(0,30,-56,30),At(-20,-40,-4,-40),At(36,-26,30,-46),At(22,-48,42,-48)),5)],{tags:Kr});ht("scooter","transport","Xe máy","Motorbike",["xe máy","motorbike","scooter","xe tay ga"],[R(`M${b(-70,20)} C${b(-70,-10)} ${b(-40,-24)} ${b(-10,-20)} L${b(30,-20)} L${b(50,-60)} L${b(64,-60)} L${b(56,20)} Z`,3),R(ft(-30,-30,60,14,6),5),...wr(-56,30,22),...wr(64,30,22),Ot(At(56,-60,76,-70),5),R($t(78,-40,6),2)],{tags:Kr});ht("train","transport","Tàu hoả","Train",["tàu hỏa","tàu","train","metro"],[R(ft(0,-10,200,110,24),1),R(ft(0,-36,160,40,8),4),R(ft(0,40,200,14,4),5),R(wt($t(-60,10,8),$t(60,10,8)),2),...wr(-50,60,14),...wr(50,60,14)],{tags:Kr});ht("airplane","transport","Máy bay","Airplane",["máy bay","plane","du lịch","bay"],[R(`M${b(-110,0)} C${b(-110,-14)} ${b(-96,-16)} ${b(-80,-16)} L${b(90,-16)} C${b(110,-16)} ${b(120,-4)} ${b(120,0)} C${b(120,6)} ${b(110,16)} ${b(90,16)} L${b(-80,16)} C${b(-96,16)} ${b(-110,14)} ${b(-110,0)} Z`,4),R(wt(Pt([[-10,-14],[30,-90],[50,-90],[30,-14]]),Pt([[-10,14],[30,90],[50,90],[30,14]]),Pt([[-100,-12],[-110,-56],[-92,-56],[-70,-14]])),1),R(wt(...[50,70,90].map(t=>$t(t,-2,4))),5)],{tags:Kr});ht("boat","transport","Thuyền buồm","Sailboat",["thuyền","boat","buồm","sail"],[R(`M${b(-90,40)} L${b(90,40)} L${b(66,74)} L${b(-66,74)} Z`,3),R(ft(0,-20,6,124,2),5),R(Pt([[6,-80],[6,30],[76,30]]),4),R(Pt([[-6,-60],[-6,30],[-60,30]]),2)],{tags:Kr});ht("ship","transport","Tàu thuỷ","Ship",["tàu thủy","ship","cargo"],[R(`M${b(-120,20)} L${b(120,20)} L${b(96,66)} L${b(-100,66)} Z`,3),R(ft(10,-4,120,48,4),4),R(ft(40,-48,30,40,3),3),R(wt($t(-20,-4,7),$t(10,-4,7),$t(40,-4,7)),2)],{tags:Kr});ht("rocket","transport","Tên lửa","Rocket",["tên lửa","rocket","khởi nghiệp","launch"],[R(`M${b(0,-110)} C${b(40,-70)} ${b(44,-10)} ${b(36,40)} L${b(-36,40)} C${b(-44,-10)} ${b(-40,-70)} ${b(0,-110)} Z`,4),R(wt(`M${b(-36,0)} L${b(-66,50)} L${b(-36,40)} Z`,`M${b(36,0)} L${b(66,50)} L${b(36,40)} Z`),3),R($t(0,-40,18),1),R(`M${b(-22,44)} L${b(22,44)} C${b(20,70)} ${b(6,96)} ${b(0,110)} C${b(-6,96)} ${b(-20,70)} ${b(-22,44)} Z`,2)],{tags:Kr});ht("delivery-scooter","transport","Xe giao hàng","Delivery scooter",["giao hàng","shipper","delivery","xe máy"],[R(ft(-50,-46,56,50,4),2),R(`M${b(-70,20)} C${b(-70,-6)} ${b(-40,-18)} ${b(-10,-16)} L${b(30,-16)} L${b(50,-56)} L${b(64,-56)} L${b(56,20)} Z`,1),...wr(-56,30,22),...wr(64,30,22),Ot(At(56,-56,76,-66),5)],{tags:Kr});io("food","Đồ ăn & thức uống","Food & drink");const Lo={role:["sticker","explain","overlay"],style:["playful"]};ht("coffee-cup","food","Ly cà phê","Coffee cup",["cà phê","coffee","ly"],[R(`M${b(-50,-30)} L${b(50,-30)} L${b(40,70)} C${b(38,80)} ${b(30,84)} ${b(20,84)} L${b(-20,84)} C${b(-30,84)} ${b(-38,80)} ${b(-40,70)} Z`,4),R(ft(0,-40,112,20,8),3),R(ft(0,20,96,34,0),2),Ot(wt(`M${b(-14,-64)} C${b(-24,-80)} ${b(-4,-90)} ${b(-14,-108)}`,`M${b(14,-64)} C${b(4,-80)} ${b(24,-90)} ${b(14,-108)}`),5)],{tags:Lo});ht("pho-bowl","food","Tô phở","Noodle bowl (phở)",["phở","bún","tô","noodle","bowl"],[R(`M${b(-100,-10)} L${b(100,-10)} C${b(96,50)} ${b(50,80)} ${b(0,80)} C${b(-50,80)} ${b(-96,50)} ${b(-100,-10)} Z`,4),R(ft(0,-14,210,14,7),3),Ot(wt(...[-40,-10,20,50].map(t=>`M${b(t,-14)} C${b(t+10,10)} ${b(t-10,30)} ${b(t,50)}`)),2),R(wt($t(-50,-24,12),$t(40,-26,10)),1),Ot(wt(At(40,-90,100,-40),At(58,-96,110,-50)),5)],{tags:Lo});ht("banh-mi","food","Bánh mì","Bánh mì",["bánh mì","sandwich","banh mi"],[R(`M${b(-110,10)} C${b(-110,-40)} ${b(110,-40)} ${b(110,10)} C${b(110,40)} ${b(-110,40)} ${b(-110,10)} Z`,2),R(`M${b(-96,4)} C${b(-60,-6)} ${b(60,-6)} ${b(96,4)} L${b(90,12)} C${b(60,4)} ${b(-60,4)} ${b(-90,12)} Z`,1),Ot(wt(At(-60,-22,-44,-10),At(-20,-26,-4,-14),At(20,-26,36,-14),At(60,-22,76,-10)),5)],{tags:Lo});ht("pizza","food","Lát pizza","Pizza slice",["pizza"],[R(Pt([[-70,-70],[70,-70],[0,90]]),2),R(ft(0,-74,150,22,10),3),R(wt($t(-24,-36,12),$t(18,-20,10),$t(-4,22,10)),3)],{tags:Lo});ht("burger","food","Bánh burger","Burger",["burger","hamburger","fast food"],[R(`M${b(-90,-10)} C${b(-90,-80)} ${b(90,-80)} ${b(90,-10)} Z`,2),R(`M${b(-96,0)} L${b(96,0)} L${b(80,16)} L${b(60,4)} L${b(40,18)} L${b(20,4)} L${b(0,18)} L${b(-20,4)} L${b(-40,18)} L${b(-60,4)} L${b(-80,16)} Z`,1),R(ft(0,26,190,22,10),5),R(ft(0,54,180,30,14),2)],{tags:Lo});ht("apple","food","Quả táo","Apple",["táo","apple","trái cây","fruit"],[R(`M${b(0,-40)} C${b(30,-70)} ${b(80,-50)} ${b(76,0)} C${b(72,50)} ${b(40,86)} ${b(0,70)} C${b(-40,86)} ${b(-72,50)} ${b(-76,0)} C${b(-80,-50)} ${b(-30,-70)} ${b(0,-40)} Z`,3),R(or(0,-40,8,-76,7),5),R(`M${b(8,-60)} C${b(30,-90)} ${b(60,-80)} ${b(60,-70)} C${b(40,-60)} ${b(20,-58)} ${b(8,-60)} Z`,1)],{tags:Lo});ht("banana","food","Quả chuối","Banana",["chuối","banana","fruit"],[R(`M${b(-90,-50)} C${b(-60,60)} ${b(60,80)} ${b(96,-10)} C${b(60,30)} ${b(-40,20)} ${b(-70,-60)} Z`,2),R(ft(-80,-58,14,20,3),5)],{tags:Lo});ht("watermelon","food","Dưa hấu","Watermelon slice",["dưa hấu","watermelon","fruit"],[R(`M${b(-100,-20)} L${b(100,-20)} C${b(100,60)} ${b(-100,60)} ${b(-100,-20)} Z`,1),R(`M${b(-88,-20)} L${b(88,-20)} C${b(88,46)} ${b(-88,46)} ${b(-88,-20)} Z`,3),R(wt(...[[-40,0],[0,14],[40,0],[-20,24],[20,24]].map(([t,e])=>Se(t,e,4,7))),5)],{tags:Lo});ht("cake","food","Bánh kem","Cake",["bánh kem","sinh nhật","birthday","cake"],[R(ft(0,40,170,70,6),4),R(`M${b(-85,10)} L${b(85,10)} L${b(85,26)} C${b(70,36)} ${b(56,16)} ${b(42,30)} C${b(28,40)} ${b(14,16)} ${b(0,30)} C${b(-14,40)} ${b(-28,16)} ${b(-42,30)} C${b(-56,40)} ${b(-70,16)} ${b(-85,26)} Z`,3),R(wt(ft(-30,-14,10,40,3),ft(0,-14,10,40,3),ft(30,-14,10,40,3)),1),R(wt(Un(-30,-44,9),Un(0,-44,9),Un(30,-44,9)),2)],{tags:Lo});ht("ice-cream","food","Kem ốc quế","Ice cream",["kem","ice cream","mùa hè"],[R(Pt([[-40,-10],[40,-10],[0,100]]),2),Ot(wt(At(-24,10,14,64),At(24,10,-14,64)),5),R($o(0,-40,100,80,5),3),R($t(0,-84,10),3)],{tags:Lo});ht("tea-cup","food","Tách trà","Tea cup",["trà","tea","tách"],[R(`M${b(-70,-20)} L${b(70,-20)} C${b(70,40)} ${b(36,64)} ${b(0,64)} C${b(-36,64)} ${b(-70,40)} ${b(-70,-20)} Z`,4),Ot(`M${b(66,-6)} C${b(100,-6)} ${b(100,30)} ${b(58,30)}`,5),R(Se(0,70,90,10),1),Ot(`M${b(0,-40)} C${b(-14,-60)} ${b(14,-70)} ${b(0,-90)}`,5)],{tags:Lo});ht("rice-bowl","food","Bát cơm","Rice bowl",["cơm","rice","bát"],[R($o(0,-14,170,60,7),4),R(`M${b(-90,0)} L${b(90,0)} C${b(86,54)} ${b(46,76)} ${b(0,76)} C${b(-46,76)} ${b(-86,54)} ${b(-90,0)} Z`,1),Ot(wt(At(30,-90,80,-10),At(46,-96,92,-18)),5)],{tags:Lo});ht("cupcake","food","Bánh cupcake","Cupcake",["cupcake","bánh"],[R(Pt([[-50,0],[50,0],[36,80],[-36,80]]),1),Ot(wt(At(-20,4,-14,76),At(0,4,0,76),At(20,4,14,76)),5),R($o(0,-20,120,70,5),4),R($t(0,-60,12),3)],{tags:Lo});ht("egg","food","Trứng ốp la","Fried egg",["trứng","egg","bữa sáng"],[R(DI(0,0,80,3,10,.16),4),R($t(10,-6,32),2)],{tags:Lo});ht("fish","food","Con cá","Fish",["cá","fish","hải sản","seafood"],[R(`M${b(-80,0)} C${b(-40,-56)} ${b(40,-56)} ${b(70,0)} C${b(40,56)} ${b(-40,56)} ${b(-80,0)} Z`,1),R(Pt([[60,0],[110,-40],[100,0],[110,40]]),1),R($t(-44,-10,7),5),Ot(He(-14,0,20,-60,60),5)],{tags:Lo});ht("carrot","food","Cà rốt","Carrot",["cà rốt","carrot","rau"],[R(`M${b(-24,-50)} C${b(-20,0)} ${b(-10,60)} ${b(0,100)} C${b(10,60)} ${b(20,0)} ${b(24,-50)} Z`,2),R(wt(Pt([[-4,-50],[-30,-100],[0,-60]]),Pt([[0,-52],[0,-110],[10,-56]]),Pt([[4,-50],[34,-96],[10,-56]])),1),Ot(wt(At(-16,-14,0,-12),At(4,20,14,22)),5)],{tags:Lo});ht("bubble-tea","food","Trà sữa","Bubble tea",["trà sữa","bubble tea","boba","milk tea"],[R(Pt([[-40,-40],[40,-40],[30,90],[-30,90]]),4),R(ft(0,-48,96,18,8),1),R(wt(...[[-16,64],[4,72],[18,58],[-2,50],[-20,40]].map(([t,e])=>$t(t,e,7))),5),R(ft(10,-90,10,90,4),3)],{tags:Lo});io("tech","Công nghệ","Tech");const Eo={role:["explain","overlay"],style:["tech","clean"]};ht("laptop","tech","Máy tính xách tay","Laptop",["laptop","máy tính","computer"],[R(ft(0,-20,170,110,8),5),R(ft(0,-20,150,90,4),1),R(`M${b(-110,40)} L${b(110,40)} L${b(120,56)} C${b(120,60)} ${b(116,62)} ${b(112,62)} L${b(-112,62)} C${b(-116,62)} ${b(-120,60)} ${b(-120,56)} Z`,4)],{tags:Eo});ht("phone","tech","Điện thoại","Phone",["điện thoại","phone","smartphone","mobile"],[R(ft(0,0,90,170,16),5),R(ft(0,-4,76,140,6),1),R(ft(0,-78,24,5,2),4),R($t(0,78,5),4)],{tags:Eo});ht("monitor","tech","Màn hình máy tính","Desktop monitor",["màn hình","monitor","pc","desktop"],[R(ft(0,-20,200,124,8),5),R(ft(0,-24,184,104,4),1),R(Pt([[-16,42],[16,42],[26,80],[-26,80]]),5),R(ft(0,82,90,10,4),5)],{tags:Eo});ht("tablet","tech","Máy tính bảng","Tablet",["máy tính bảng","tablet","ipad"],[R(ft(0,0,130,170,14),5),R(ft(0,0,114,146,6),1)],{tags:Eo});ht("camera","tech","Máy ảnh","Camera",["máy ảnh","camera","chụp ảnh","photo"],[R(ft(0,10,180,110,14),5),R(ft(-40,-50,60,22,6),5),R($t(0,14,40),4),R($t(0,14,26),1),R($t(60,-24,7),2)],{tags:Eo});ht("video-camera","tech","Máy quay","Video camera",["máy quay","video","quay phim","camcorder"],[R(ft(-20,0,130,90,12),5),R(Pt([[46,-16],[100,-44],[100,44],[46,16]]),5),R($t(-50,-62,22),4),R($t(10,-62,22),4),R($t(40,-24,6),3)],{tags:Eo});ht("headphones","tech","Tai nghe","Headphones",["tai nghe","headphones","âm nhạc","music"],[Ot(He(0,10,70,180,360),5),R(wt(ft(-70,30,30,64,10),ft(70,30,30,64,10)),1)],{tags:Eo});ht("microphone","tech","Micro","Microphone",["micro","mic","podcast","thu âm"],[R(ft(0,-40,52,90,26),5),Ot(wt(`M${b(-44,-20)} C${b(-44,40)} ${b(44,40)} ${b(44,-20)}`,At(0,30,0,70),At(-30,70,30,70)),5),Ot(wt(At(-14,-60,14,-60),At(-14,-44,14,-44),At(-14,-28,14,-28)),4)],{tags:Eo});ht("gear","tech","Bánh răng","Gear",["bánh răng","gear","cài đặt","settings"],[R(Ve(0,0,10,90,70,0),5),R($t(0,0,30),4)],{tags:Eo});ht("cloud-upload","tech","Đám mây tải lên","Cloud upload",["tải lên","upload","cloud","đám mây"],[R($o(0,0,190,110,6),4),R(Pt([[0,-40],[30,-6],[12,-6],[12,36],[-12,36],[-12,-6],[-30,-6]]),1)],{tags:Eo});ht("wifi","tech","Wi-Fi","Wi-Fi",["wifi","mạng","internet","kết nối"],[Ot(wt(He(0,40,30,225,315),He(0,40,60,225,315),He(0,40,90,225,315)),1),R($t(0,40,10),1)],{tags:Eo});ht("battery","tech","Pin","Battery",["pin","battery","năng lượng"],[R(ft(-6,0,150,70,10),5),R(ft(76,0,12,30,3),5),R(ft(-30,0,90,52,4),1)],{tags:Eo});ht("lightbulb","tech","Bóng đèn ý tưởng","Light bulb",["ý tưởng","idea","bóng đèn","lightbulb"],[R(`M${b(-26,40)} C${b(-26,10)} ${b(-60,-6)} ${b(-60,-40)} C${b(-60,-80)} ${b(-30,-100)} ${b(0,-100)} C${b(30,-100)} ${b(60,-80)} ${b(60,-40)} C${b(60,-6)} ${b(26,10)} ${b(26,40)} Z`,2),R(wt(ft(0,52,52,12,4),ft(0,68,46,12,4)),5),Ot(wt(At(-80,-90,-96,-104),At(80,-90,96,-104),At(0,-118,0,-136),At(-92,-40,-112,-40),At(92,-40,112,-40)),3)],{tags:Eo});ht("robot","tech","Rô-bốt","Robot",["robot","ai","trí tuệ nhân tạo","bot"],[R(ft(0,10,130,100,20),4),R(wt($t(-30,0,14),$t(30,0,14)),1),R(ft(0,38,50,10,4),5),Ot(At(0,-40,0,-62),5),R($t(0,-68,9),3),R(wt(ft(-74,10,14,40,5),ft(74,10,14,40,5)),5)],{tags:Eo});ht("chip","tech","Vi mạch","Chip",["chip","vi mạch","processor","cpu"],[R(ft(0,0,110,110,10),5),R(ft(0,0,60,60,6),1),Ot(wt(...[-30,0,30].flatMap(t=>[At(t,-55,t,-80),At(t,55,t,80),At(-55,t,-80,t),At(55,t,80,t)])),5)],{tags:Eo});ht("play-button","tech","Nút phát","Play button",["play","phát","video","youtube"],[R(ft(0,0,170,120,30),3),R(Pt([[-20,-30],[34,0],[-20,30]]),4)],{tags:Eo});ht("cursor","tech","Con trỏ chuột","Mouse cursor",["con trỏ","cursor","click","chuột"],[R(Pt([[-30,-60],[40,10],[6,14],[26,56],[10,64],[-10,22],[-30,44]]),4)],{tags:Eo});ht("browser","tech","Cửa sổ trình duyệt","Browser window",["trình duyệt","browser","website","web"],[R(ft(0,0,220,150,10),4),R(ft(0,-62,220,26,10),5),R(wt($t(-92,-62,5),$t(-76,-62,5),$t(-60,-62,5)),3),R(ft(-40,0,100,60,4),1),Ot(wt(At(30,-20,90,-20),At(30,0,90,0),At(30,20,70,20)),5)],{tags:Eo});io("office","Văn phòng & kinh doanh","Office & business");const lo={role:["explain","stat","list"],style:["corporate","clean"]};ht("briefcase","office","Cặp tài liệu","Briefcase",["cặp","briefcase","công việc","work"],[R(ft(0,10,180,120,12),2),R(`M${b(-30,-50)} L${b(-30,-66)} C${b(-30,-72)} ${b(-24,-76)} ${b(-18,-76)} L${b(18,-76)} C${b(24,-76)} ${b(30,-72)} ${b(30,-66)} L${b(30,-50)} L${b(18,-50)} L${b(18,-64)} L${b(-18,-64)} L${b(-18,-50)} Z`,5),R(ft(0,4,180,8,2),5),R(ft(0,4,24,22,4),3)],{tags:lo});ht("document","office","Tài liệu","Document",["tài liệu","document","giấy tờ","file"],[R(Pt([[-60,-80],[30,-80],[60,-50],[60,80],[-60,80]]),4),R(Pt([[30,-80],[30,-50],[60,-50]]),1),Ot(wt(At(-38,-30,38,-30),At(-38,-6,38,-6),At(-38,18,38,18),At(-38,42,10,42)),5)],{tags:lo});ht("clipboard","office","Bảng kẹp hồ sơ","Clipboard",["clipboard","checklist","danh sách"],[R(ft(0,10,130,170,10),3),R(ft(0,14,110,140,4),4),R(ft(0,-72,56,24,6),5),Ot(wt(...[-30,0,30].flatMap(t=>[Pt([[-40,t],[-32,t+8],[-18,t-8]],!1),At(-4,t,36,t)])),1)],{tags:lo});ht("calendar","office","Lịch","Calendar",["lịch","calendar","ngày","date","sự kiện"],[R(ft(0,10,170,150,12),4),R(ft(0,-48,170,34,12),3),R(wt(ft(-44,-70,10,26,4),ft(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])=>ft(t,e,22,20,3))),1)],{tags:lo});ht("bar-chart","office","Biểu đồ cột","Bar chart",["biểu đồ","chart","số liệu","growth","tăng trưởng"],[R(ft(-54,40,30,70,3),1),R(ft(-14,20,30,110,3),2),R(ft(26,-10,30,170,3),3),R(ft(66,-34,30,218,3),1),Ot(wt(At(-90,76,100,76),At(-90,76,-90,-110)),5)],{tags:lo});ht("pie-chart","office","Biểu đồ tròn","Pie chart",["biểu đồ tròn","pie chart","tỉ lệ","percent"],[R($t(0,0,80),1),R(`M${b(0,0)} L${b(0,-80)} C${b(44,-80)} ${b(80,-44)} ${b(80,0)} Z`,3),R(`M${b(0,0)} L${b(80,0)} C${b(80,34)} ${b(60,62)} ${b(30,74)} Z`,2)],{tags:lo});ht("line-chart","office","Biểu đồ đường","Line chart",["biểu đồ đường","line chart","xu hướng","trend"],[Ot(wt(At(-100,70,100,70),At(-100,70,-100,-80)),5),Ot(Pt([[-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])=>$t(t,e,8))),1)],{tags:lo});ht("pencil","office","Bút chì","Pencil",["bút chì","pencil","viết","write"],[R(Pt([[-90,30],[60,-36],[80,-6],[-70,60]]),2),R(Pt([[60,-36],[100,-30],[80,-6]]),4),R(Pt([[-90,30],[-104,62],[-70,60]]),5)],{tags:lo});ht("folder","office","Thư mục","Folder",["thư mục","folder","hồ sơ"],[R(`M${b(-90,-60)} L${b(-30,-60)} L${b(-14,-44)} L${b(90,-44)} L${b(90,60)} L${b(-90,60)} Z`,2),R(ft(0,8,180,104,6),2)],{tags:lo});ht("envelope","office","Phong bì / email","Envelope",["thư","email","mail","phong bì"],[R(ft(0,0,180,120,8),4),Ot(Pt([[-90,-60],[0,10],[90,-60]],!1),5)],{tags:lo});ht("clock","office","Đồng hồ","Clock",["đồng hồ","clock","thời gian","time"],[R($t(0,0,86),4),R($t(0,0,74),1),Ot(wt(At(0,0,0,-48),At(0,0,34,18)),5),R($t(0,0,7),5)],{tags:lo});ht("magnifier","office","Kính lúp","Magnifier",["tìm kiếm","search","kính lúp","magnifier"],[R(or(34,34,86,86,22),5),R($t(-14,-14,62),5),R($t(-14,-14,46),4)],{tags:lo});ht("target","office","Mục tiêu","Target",["mục tiêu","target","goal","kpi"],[R($t(0,0,86),3),R($t(0,0,62),4),R($t(0,0,38),3),R($t(0,0,14),4)],{tags:lo});ht("trophy","office","Cúp","Trophy",["cúp","trophy","chiến thắng","winner"],[R(`M${b(-50,-80)} L${b(50,-80)} L${b(46,-20)} C${b(40,10)} ${b(20,24)} ${b(0,24)} C${b(-20,24)} ${b(-40,10)} ${b(-46,-20)} Z`,2),Ot(wt(`M${b(-48,-64)} C${b(-90,-64)} ${b(-90,-14)} ${b(-40,-10)}`,`M${b(48,-64)} C${b(90,-64)} ${b(90,-14)} ${b(40,-10)}`),2),R(ft(0,46,20,44,2),2),R(ft(0,80,90,22,4),5)],{tags:lo});ht("money-bag","office","Túi tiền","Money bag",["tiền","money","doanh thu","revenue"],[R(`M${b(-24,-52)} C${b(-90,-10)} ${b(-90,80)} ${b(0,80)} C${b(90,80)} ${b(90,-10)} ${b(24,-52)} Z`,1),R(Pt([[-30,-60],[-40,-90],[0,-76],[40,-90],[30,-60]]),1),R(ft(0,-54,60,10,4),5),Ot(wt(`M${b(18,0)} C${b(8,-12)} ${b(-24,-10)} ${b(-20,8)} C${b(-16,22)} ${b(20,16)} ${b(20,32)} C${b(20,50)} ${b(-12,50)} ${b(-22,38)}`,At(0,-14,0,56)),4)],{tags:lo});ht("coin","office","Đồng xu","Coin",["xu","coin","tiền"],[R($t(0,0,70),2),R($t(0,0,54),2),Ot(wt(`M${b(16,-20)} C${b(8,-30)} ${b(-20,-28)} ${b(-16,-10)} C${b(-12,4)} ${b(18,0)} ${b(18,16)} C${b(18,32)} ${b(-10,32)} ${b(-20,22)}`,At(0,-36,0,40)),5)],{tags:lo});ht("banknote","office","Tờ tiền","Banknote",["tiền mặt","cash","banknote"],[R(ft(0,0,200,100,8),1),R(ft(0,0,170,74,6),4),R($t(0,0,26),1),R(wt($t(-66,0,8),$t(66,0,8)),1)],{tags:lo});ht("piggy-bank","office","Heo đất","Piggy bank",["heo đất","tiết kiệm","savings","piggy bank"],[R(Se(0,10,90,64),3),R(wt(ft(-50,70,18,26,4),ft(40,70,18,26,4)),3),R(Pt([[-34,-44],[-20,-74],[-6,-50]]),3),R(ft(86,10,22,30,8),3),R($t(-40,-6,6),5),R(ft(10,-48,40,8,4),5)],{tags:lo});ht("handshake","office","Bắt tay hợp tác","Handshake",["hợp tác","handshake","deal","đối tác"],[R(wt(ft(-80,0,40,40,8),ft(80,0,40,40,8)),5),R(`M${b(-60,-10)} L${b(-10,-30)} L${b(40,-2)} L${b(54,16)} C${b(56,28)} ${b(44,34)} ${b(34,26)} L${b(20,40)} C${b(12,48)} ${b(0,44)} ${b(-6,36)} L${b(-60,20)} Z`,4),Ot(wt(At(20,0,30,14),At(6,10,18,26)),5)],{tags:lo});ht("presentation-board","office","Bảng trình chiếu","Presentation board",["thuyết trình","presentation","bảng","slide"],[R(ft(0,-20,200,130,6),4),R(ft(0,-90,210,14,4),5),Ot(wt(At(0,45,0,90),At(0,60,-40,96),At(0,60,40,96)),5),R(wt(ft(-50,-6,26,60,2),ft(-14,-26,26,100,2),ft(22,-16,26,80,2)),1)],{tags:lo});io("home","Nhà & nội thất","Home & interior");const Wr={role:["explain","background"],style:["soft","clean"]};ht("sofa","home","Ghế sofa","Sofa",["sofa","ghế","phòng khách","living room"],[R(ft(0,-20,180,70,16),1),R(wt(ft(-96,10,30,70,12),ft(96,10,30,70,12)),1),R(ft(0,24,170,40,10),2),R(wt(ft(-80,62,10,20,3),ft(80,62,10,20,3)),5)],{tags:Wr});ht("chair","home","Ghế","Chair",["ghế","chair"],[R(ft(-30,-40,14,120,4),2),R(ft(0,20,80,14,4),2),R(wt(ft(-30,60,10,70,3),ft(30,60,10,70,3)),2)],{tags:Wr});ht("table","home","Bàn","Table",["bàn","table"],[R(ft(0,-20,200,18,4),2),R(wt(ft(-80,30,14,90,3),ft(80,30,14,90,3)),2)],{tags:Wr});ht("bed","home","Giường","Bed",["giường","bed","ngủ","phòng ngủ"],[R(ft(-90,-10,20,110,4),2),R(ft(10,20,200,40,6),4),R(ft(-50,0,50,24,10),4),R(ft(30,10,130,30,8),1),R(wt(ft(-86,56,10,22,3),ft(104,56,10,22,3)),2)],{tags:Wr});ht("lamp","home","Đèn bàn","Table lamp",["đèn","lamp"],[R(Pt([[-40,-70],[40,-70],[60,-10],[-60,-10]]),2),R(ft(0,30,10,80,3),5),R(ft(0,72,70,12,5),5)],{tags:Wr});ht("plant-pot","home","Chậu cây","Potted plant",["chậu cây","plant","cây cảnh"],[R(Pt([[-40,20],[40,20],[30,90],[-30,90]]),3),R(ft(0,20,96,16,4),3),R(wt(`M${b(0,10)} C${b(-60,-10)} ${b(-70,-60)} ${b(-40,-80)} C${b(-30,-40)} ${b(-10,-20)} ${b(0,10)} Z`,`M${b(0,10)} C${b(60,-10)} ${b(70,-60)} ${b(40,-80)} C${b(30,-40)} ${b(10,-20)} ${b(0,10)} Z`,`M${b(0,10)} C${b(-14,-40)} ${b(-8,-90)} ${b(0,-104)} C${b(8,-90)} ${b(14,-40)} ${b(0,10)} Z`),1)],{tags:Wr});ht("window","home","Cửa sổ","Window",["cửa sổ","window"],[R(ft(0,0,150,170,4),4),R(wt(ft(-36,-40,62,70,2),ft(36,-40,62,70,2),ft(-36,40,62,70,2),ft(36,40,62,70,2)),1),R(ft(0,92,170,12,3),5)],{tags:Wr});ht("door","home","Cửa ra vào","Door",["cửa","door","lối vào"],[R(ft(0,0,110,200,6),2),R(wt(ft(0,-50,80,70,4),ft(0,40,80,70,4)),2),R($t(38,6,6),3)],{tags:Wr});ht("key","home","Chìa khoá","Key",["chìa khóa","key","bảo mật"],[R($t(-50,0,40),2),R($t(-50,0,16),4),R(wt(ft(30,0,120,18,4),ft(70,20,14,24,2),ft(46,20,14,18,2)),2)],{tags:Wr});ht("lock","home","Ổ khoá","Padlock",["khóa","lock","bảo mật","security"],[Ot(`M${b(-40,-10)} L${b(-40,-40)} C${b(-40,-90)} ${b(40,-90)} ${b(40,-40)} L${b(40,-10)}`,5),R(ft(0,30,120,90,12),2),R(wt($t(0,20,10),ft(0,38,8,24,3)),5)],{tags:Wr});ht("mug","home","Cốc","Mug",["cốc","mug","ly"],[R(ft(0,0,100,120,10),1),Ot(`M${b(50,-30)} C${b(96,-30)} ${b(96,30)} ${b(50,30)}`,1),R(ft(0,-30,70,10,4),4)],{tags:Wr});ht("picture-frame","home","Khung tranh","Picture frame",["tranh","khung","picture","frame"],[R(ft(0,0,170,130,4),2),R(ft(0,0,140,100,2),4),R(Pt([[-60,40],[-20,-10],[10,20],[30,0],[60,40]]),1),R($t(36,-26,12),3)],{tags:Wr});io("icons","Biểu tượng","Icons");const oo={role:["sticker","overlay","social"],style:["clean","playful"]};ht("heart","icons","Trái tim","Heart",["tim","heart","yêu","love","like"],[R(dp(0,0,80),3)],{tags:oo});ht("star","icons","Ngôi sao","Star",["sao","star","đánh giá","rating"],[R(Ve(0,6,5,92,40),2)],{tags:oo});ht("check","icons","Dấu tích","Check mark",["đúng","check","tick","xong","done"],[R($t(0,0,80),1),Ot(Pt([[-36,0],[-10,28],[40,-30]],!1),4)],{tags:oo});ht("cross","icons","Dấu X","Cross mark",["sai","cross","x","không"],[R($t(0,0,80),3),Ot(wt(At(-30,-30,30,30),At(30,-30,-30,30)),4)],{tags:oo});ht("plus","icons","Dấu cộng","Plus",["cộng","plus","thêm","add"],[R(wt(ft(0,0,40,150,10),ft(0,0,150,40,10)),1)],{tags:oo});ht("location-pin","icons","Ghim vị trí","Location pin",["địa điểm","location","pin","bản đồ","map"],[R(`M${b(0,96)} C${b(-20,60)} ${b(-70,10)} ${b(-70,-30)} C${b(-70,-70)} ${b(-36,-100)} ${b(0,-100)} C${b(36,-100)} ${b(70,-70)} ${b(70,-30)} C${b(70,10)} ${b(20,60)} ${b(0,96)} Z`,3),R($t(0,-30,26),4)],{tags:oo});ht("home-icon","icons","Biểu tượng nhà","Home icon",["nhà","home","trang chủ"],[R(wt(Pt([[-80,-4],[0,-80],[80,-4],[60,-4],[60,70],[-60,70],[-60,-4]])),1),R(ft(0,40,30,60,4),4)],{tags:oo});ht("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($t(0,-36,36),1),R(`M${b(-70,80)} C${b(-70,10)} ${b(70,10)} ${b(70,80)} Z`,1)],{tags:oo,human:!1});ht("bell","icons","Chuông thông báo","Bell",["chuông","thông báo","notification","bell"],[R(`M${b(-60,40)} C${b(-50,20)} ${b(-50,0)} ${b(-50,-20)} C${b(-50,-60)} ${b(-26,-80)} ${b(0,-80)} C${b(26,-80)} ${b(50,-60)} ${b(50,-20)} C${b(50,0)} ${b(50,20)} ${b(60,40)} Z`,2),R($t(0,56,14),2),R($t(0,-86,8),2)],{tags:oo});ht("flag","icons","Lá cờ","Flag",["cờ","flag","đích","milestone"],[R(ft(-60,0,10,200,3),5),R(`M${b(-56,-96)} C${b(-20,-110)} ${b(10,-80)} ${b(70,-96)} L${b(70,-24)} C${b(10,-8)} ${b(-20,-38)} ${b(-56,-24)} Z`,3)],{tags:oo});ht("gift","icons","Hộp quà","Gift box",["quà","gift","khuyến mãi","present"],[R(ft(0,30,150,110,6),3),R(ft(0,-34,170,34,6),3),R(wt(ft(0,30,24,110,2),ft(0,-34,24,34,2)),2),Ot(wt(`M${b(0,-52)} C${b(-50,-110)} ${b(-80,-60)} ${b(0,-52)}`,`M${b(0,-52)} C${b(50,-110)} ${b(80,-60)} ${b(0,-52)}`),2)],{tags:oo});ht("cart","icons","Giỏ hàng","Shopping cart",["giỏ hàng","cart","mua sắm","shopping"],[Ot(Pt([[-100,-70],[-70,-70],[-40,40],[70,40]],!1),5),R(Pt([[-62,-46],[96,-46],[78,20],[-46,20]]),2),R(wt($t(-30,66,14),$t(56,66,14)),5)],{tags:oo});ht("price-tag","icons","Nhãn giá","Price tag",["giá","sale","tag","giảm giá"],[R(Pt([[-90,-40],[40,-40],[90,0],[40,40],[-90,40]]),3),R($t(50,0,10),4)],{tags:oo});ht("bookmark","icons","Đánh dấu","Bookmark",["bookmark","lưu","save"],[R(Pt([[-50,-90],[50,-90],[50,90],[0,50],[-50,90]]),1)],{tags:oo});ht("fire","icons","Ngọn lửa","Fire",["lửa","hot","fire","trending"],[R(`M${b(0,96)} C${b(-60,96)} ${b(-80,40)} ${b(-60,0)} C${b(-50,-20)} ${b(-40,-30)} ${b(-30,-50)} C${b(-20,-20)} ${b(0,-10)} ${b(0,-10)} C${b(-10,-50)} ${b(10,-90)} ${b(30,-100)} C${b(30,-60)} ${b(80,-20)} ${b(70,30)} C${b(64,70)} ${b(40,96)} ${b(0,96)} Z`,3),R(`M${b(0,90)} C${b(-30,90)} ${b(-40,60)} ${b(-30,40)} C${b(-20,20)} ${b(-4,10)} ${b(0,-4)} C${b(14,20)} ${b(36,40)} ${b(30,64)} C${b(26,80)} ${b(14,90)} ${b(0,90)} Z`,2)],{tags:oo});ht("water-drop","icons","Giọt nước","Water drop",["giọt nước","water","drop","nước"],[R(Un(0,0,90),1),Ot(He(-20,20,30,110,170),4)],{tags:oo});ht("music-note","icons","Nốt nhạc","Music note",["nhạc","music","nốt nhạc"],[R(wt(Se(-40,60,26,20),Se(50,40,26,20)),5),R(wt(ft(-16,-10,10,140,2),ft(74,-30,10,140,2)),5),R(Pt([[-21,-80],[79,-100],[79,-74],[-21,-54]]),5)],{tags:oo});ht("speaker","icons","Loa","Speaker",["loa","âm thanh","speaker","sound","volume"],[R(Pt([[-70,-30],[-30,-30],[20,-70],[20,70],[-30,30],[-70,30]]),5),Ot(wt(He(30,0,30,-50,50),He(30,0,56,-50,50)),3)],{tags:oo});ht("lightning-icon","icons","Tia chớp","Lightning icon",["nhanh","fast","flash","power"],[R($t(0,0,80),2),R(Pt([[10,-56],[-30,8],[-2,8],[-14,56],[30,-10],[2,-10]]),4)],{tags:oo});ht("shield","icons","Khiên bảo vệ","Shield",["bảo vệ","shield","an toàn","security","bảo hành"],[R(`M${b(0,-90)} C${b(30,-70)} ${b(60,-66)} ${b(80,-66)} C${b(80,10)} ${b(60,70)} ${b(0,96)} C${b(-60,70)} ${b(-80,10)} ${b(-80,-66)} C${b(-60,-66)} ${b(-30,-70)} ${b(0,-90)} Z`,1),Ot(Pt([[-30,0],[-6,26],[36,-26]],!1),4)],{tags:oo});ht("eye","icons","Con mắt","Eye",["mắt","xem","view","eye","lượt xem"],[R(`M${b(-100,0)} C${b(-60,-60)} ${b(60,-60)} ${b(100,0)} C${b(60,60)} ${b(-60,60)} ${b(-100,0)} Z`,4),R($t(0,0,32),1),R($t(0,0,14),5)],{tags:oo});io("arrows","Mũi tên","Arrows");const Hr={role:["explain","overlay"],style:["clean","bold"]};ht("arrow-right","arrows","Mũi tên phải","Arrow right",["mũi tên","arrow","phải"],[R(Pt([[-100,-20],[30,-20],[30,-56],[100,0],[30,56],[30,20],[-100,20]]),3)],{tags:Hr});ht("arrow-up","arrows","Mũi tên lên","Arrow up",["mũi tên","arrow","lên","tăng","up"],[R(Pt([[-20,100],[-20,-30],[-56,-30],[0,-100],[56,-30],[20,-30],[20,100]]),1)],{tags:Hr});ht("arrow-down","arrows","Mũi tên xuống","Arrow down",["mũi tên","arrow","xuống","giảm","down"],[R(Pt([[-20,-100],[-20,30],[-56,30],[0,100],[56,30],[20,30],[20,-100]]),3)],{tags:Hr});ht("arrow-curved","arrows","Mũi tên cong","Curved arrow",["mũi tên cong","curved arrow"],[Ot(`M${b(-90,60)} C${b(-70,-40)} ${b(20,-70)} ${b(80,-30)}`,5),Ot(Pt([[46,-52],[84,-28],[56,6]],!1),5)],{tags:Hr});ht("arrow-double","arrows","Mũi tên hai chiều","Double arrow",["hai chiều","double arrow","trao đổi","exchange"],[R(Pt([[-100,0],[-50,-44],[-50,-16],[50,-16],[50,-44],[100,0],[50,44],[50,16],[-50,16],[-50,44]]),1)],{tags:Hr});ht("arrow-circle","arrows","Mũi tên vòng","Circular arrow",["vòng lặp","refresh","cycle","lặp lại"],[Ot(He(0,0,70,-60,230),5),R(Pt([[34,-74],[50,-40],[14,-38]]),5)],{tags:Hr});ht("arrow-zigzag","arrows","Mũi tên gấp khúc","Zigzag arrow",["zigzag","gấp khúc","tăng trưởng"],[Ot(Pt([[-100,60],[-40,0],[0,30],[80,-50]],!1),3),R(Pt([[50,-60],[96,-66],[90,-20]]),3)],{tags:Hr});ht("arrow-uturn","arrows","Mũi tên quay đầu","U-turn arrow",["quay đầu","u-turn","quay lại","back"],[Ot(`M${b(60,80)} L${b(60,-20)} C${b(60,-80)} ${b(-40,-80)} ${b(-40,-20)} L${b(-40,40)}`,5),R(Pt([[-72,20],[-40,70],[-8,20]]),5)],{tags:Hr});ht("chevrons","arrows","Mũi tên kép","Chevrons",["chevron","tiếp theo","next","fast forward"],[R(wt(Pt([[-90,-60],[-50,-60],[0,0],[-50,60],[-90,60],[-40,0]]),Pt([[0,-60],[40,-60],[90,0],[40,60],[0,60],[50,0]])),3)],{tags:Hr});ht("arrow-swoosh","arrows","Mũi tên vẽ tay","Hand-drawn swoosh arrow",["vẽ tay","swoosh","hand drawn"],[Ot(`M${b(-100,30)} C${b(-60,70)} ${b(-10,60)} ${b(10,20)} C${b(30,-20)} ${b(60,-40)} ${b(96,-40)}`,5),Ot(wt(At(96,-40,70,-60),At(96,-40,74,-14)),5)],{tags:Hr});ht("arrow-block-left","arrows","Mũi tên trái","Arrow left",["mũi tên","arrow","trái","left"],[R(Pt([[100,-20],[-30,-20],[-30,-56],[-100,0],[-30,56],[-30,20],[100,20]]),2)],{tags:Hr});ht("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 $t(-100+o*170,40-Math.sin(o*Math.PI)*70,6)})),5),R(Pt([[70,10],[100,40],[60,52]]),5)],{tags:Hr});io("frames","Khung","Frames");const Xr={role:["overlay","title","background"],style:["clean","editorial"]};ht("frame-rounded","frames","Khung bo góc","Rounded frame",["khung","frame","viền"],[zp(wt(ft(0,0,240,160,24),ft(0,0,212,132,14)),1)],{tags:Xr});ht("frame-circle","frames","Khung tròn","Circle frame",["khung tròn","circle frame","avatar"],[zp(wt($t(0,0,100),$t(0,0,84)),3)],{tags:Xr});ht("banner-ribbon","frames","Băng rôn","Ribbon banner",["băng rôn","ribbon","banner","tiêu đề"],[R(wt(Pt([[-130,-10],[-96,-10],[-96,40],[-130,40],[-112,15]]),Pt([[130,-10],[96,-10],[96,40],[130,40],[112,15]])),5),R(ft(0,0,200,50,2),3)],{tags:Xr});ht("scroll","frames","Cuộn giấy","Scroll",["cuộn giấy","scroll","thông báo"],[R(ft(0,0,180,120,2),4),R(wt(ft(-96,0,22,140,11),ft(96,0,22,140,11)),2)],{tags:Xr});ht("polaroid","frames","Ảnh polaroid","Polaroid frame",["polaroid","ảnh","photo"],[R(ft(0,0,170,200,4),4),R(ft(0,-18,146,140,2),5)],{tags:Xr});ht("ticket","frames","Vé","Ticket",["vé","ticket","sự kiện","coupon"],[R(`M${b(-110,-50)} L${b(110,-50)} L${b(110,-14)} C${b(96,-14)} ${b(96,14)} ${b(110,14)} L${b(110,50)} L${b(-110,50)} L${b(-110,14)} C${b(-96,14)} ${b(-96,-14)} ${b(-110,-14)} Z`,3),Ot(At(50,-40,50,40),4)],{tags:Xr});ht("brackets","frames","Ngoặc vuông","Brackets",["ngoặc","brackets","nhấn mạnh"],[Ot(wt(Pt([[-60,-80],[-100,-80],[-100,80],[-60,80]],!1),Pt([[60,-80],[100,-80],[100,80],[60,80]],!1)),5)],{tags:Xr});ht("filmstrip","frames","Cuộn phim","Film strip",["phim","film","cuộn phim","cinema"],[R(ft(0,0,240,120,4),5),R(wt(...[-80,0,80].map(t=>ft(t,0,64,70,3))),4),R(wt(...Array.from({length:10},(t,e)=>ft(-108+e*24,-50,10,10,2)),...Array.from({length:10},(t,e)=>ft(-108+e*24,50,10,10,2))),4)],{tags:Xr});ht("phone-frame","frames","Khung điện thoại","Phone frame",["khung điện thoại","phone mockup","mockup"],[zp(wt(ft(0,0,120,230,20),ft(0,0,104,200,8)),5),R(ft(0,-104,30,6,3),4)],{tags:Xr});ht("sticky-note","frames","Giấy ghi chú","Sticky note",["ghi chú","note","sticky","post-it"],[R(Pt([[-80,-80],[80,-80],[80,40],[40,80],[-80,80]]),2),R(Pt([[80,40],[40,40],[40,80]]),5),R(ft(0,-80,60,18,2),4)],{tags:Xr});ht("frame-wavy","frames","Khung lượn sóng","Wavy frame",["khung","wavy","dễ thương"],[R(Ve(0,0,24,100,90,0),1),R($t(0,0,80),4)],{tags:Xr});ht("frame-stamp","frames","Khung tem","Stamp frame",["tem","stamp","bưu thiếp"],[zp(wt(ft(0,0,170,210,0),...Array.from({length:7},(t,e)=>$t(-72+e*24,-105,8)),...Array.from({length:7},(t,e)=>$t(-72+e*24,105,8)),...Array.from({length:9},(t,e)=>$t(-85,-96+e*24,8)),...Array.from({length:9},(t,e)=>$t(85,-96+e*24,8))),4),R(ft(0,0,140,180,2),1)],{tags:Xr});io("bubbles","Bong bóng thoại","Speech bubbles");const Tn={role:["caption","quote","overlay"],style:["playful","clean"]};ht("bubble-round","bubbles","Bóng thoại tròn","Round speech bubble",["lời thoại","speech","nói","bubble"],[R(`M${b(-100,0)} C${b(-100,-60)} ${b(-50,-80)} ${b(0,-80)} C${b(50,-80)} ${b(100,-60)} ${b(100,0)} C${b(100,60)} ${b(50,76)} ${b(0,76)} C${b(-14,76)} ${b(-26,74)} ${b(-38,70)} L${b(-80,96)} L${b(-66,58)} C${b(-90,44)} ${b(-100,24)} ${b(-100,0)} Z`,4)],{tags:Tn});ht("bubble-rect","bubbles","Bóng thoại vuông","Box speech bubble",["lời thoại","speech","box","chat"],[R(`M${b(-110,-70)} L${b(110,-70)} L${b(110,50)} L${b(-20,50)} L${b(-60,90)} L${b(-56,50)} L${b(-110,50)} Z`,4)],{tags:Tn});ht("bubble-thought","bubbles","Bóng suy nghĩ","Thought bubble",["suy nghĩ","thought","nghĩ"],[R($o(0,-14,220,140,7),4),R(wt($t(-70,80,14),$t(-96,104,8)),4)],{tags:Tn});ht("bubble-shout","bubbles","Bóng hét","Shout bubble",["hét","shout","wow","bất ngờ","boom"],[R(Ve(0,0,14,110,76,-90),2)],{tags:Tn});ht("bubble-chat","bubbles","Tin nhắn chat","Chat message",["chat","tin nhắn","message","nhắn tin"],[R(`M${b(-100,-50)} C${b(-100,-66)} ${b(-90,-76)} ${b(-74,-76)} L${b(74,-76)} C${b(90,-76)} ${b(100,-66)} ${b(100,-50)} L${b(100,30)} C${b(100,46)} ${b(90,56)} ${b(74,56)} L${b(-50,56)} L${b(-90,86)} L${b(-84,52)} C${b(-94,48)} ${b(-100,40)} ${b(-100,30)} Z`,1),R(wt($t(-40,-10,10),$t(0,-10,10),$t(40,-10,10)),4)],{tags:Tn});ht("bubble-double","bubbles","Hai bóng thoại","Conversation",["hội thoại","conversation","trò chuyện"],[R(`M${b(-120,-40)} C${b(-120,-80)} ${b(-10,-80)} ${b(-10,-40)} C${b(-10,-6)} ${b(-60,0)} ${b(-80,-2)} L${b(-110,20)} L${b(-100,-10)} C${b(-114,-18)} ${b(-120,-28)} ${b(-120,-40)} Z`,1),R(`M${b(10,30)} C${b(10,-10)} ${b(120,-10)} ${b(120,30)} C${b(120,62)} ${b(80,70)} ${b(60,68)} L${b(30,90)} L${b(38,60)} C${b(22,54)} ${b(10,44)} ${b(10,30)} Z`,2)],{tags:Tn});ht("caption-box","bubbles","Hộp chú thích","Caption box",["chú thích","caption","box"],[R(ft(0,0,240,70,6),4),R(ft(-112,0,16,70,3),3)],{tags:Tn});ht("callout-left","bubbles","Chú thích chỉ trái","Callout pointing left",["callout","chú thích","chỉ"],[R(`M${b(-60,-50)} L${b(110,-50)} L${b(110,50)} L${b(-60,50)} L${b(-60,16)} L${b(-110,0)} L${b(-60,-16)} Z`,4)],{tags:Tn});ht("bubble-whisper","bubbles","Bóng thì thầm","Whisper bubble",["thì thầm","whisper","nhỏ"],[Ot(wt(...Array.from({length:16},(t,e)=>{const o=e*22.5,r=o+12;return Ea(up(0,0,100,64,o,r,2),!1)})),5)],{tags:Tn});ht("bubble-heart","bubbles","Bóng thoại trái tim","Heart bubble",["yêu","love","trái tim","tim"],[R(dp(0,-10,74),3),R(Pt([[-10,50],[-40,96],[14,62]]),3)],{tags:Tn});io("badges","Huy hiệu & nhãn","Badges & labels");const On={role:["proof","cta","sticker"],style:["bold","playful"]};ht("badge-seal","badges","Con dấu răng cưa","Seal badge",["huy hiệu","seal","chất lượng","badge"],[R(Ve(0,0,18,100,86,0),3),R($t(0,0,70),4),R($t(0,0,58),3)],{tags:On});ht("badge-ribbon","badges","Huy chương ruy băng","Ribbon badge",["huy chương","ribbon","giải thưởng","award"],[R(wt(Pt([[-40,30],[-70,110],[-36,94],[-20,120],[0,40]]),Pt([[40,30],[70,110],[36,94],[20,120],[0,40]])),3),R($t(0,-10,70),2),R($t(0,-10,52),4),R(Ve(0,-10,5,34,15),2)],{tags:On});ht("badge-shield","badges","Huy hiệu khiên","Shield badge",["khiên","shield","an toàn","badge"],[R(`M${b(0,-96)} L${b(84,-66)} C${b(84,20)} ${b(50,70)} ${b(0,100)} C${b(-50,70)} ${b(-84,20)} ${b(-84,-66)} Z`,1),R(`M${b(0,-76)} L${b(64,-52)} C${b(64,14)} ${b(38,52)} ${b(0,78)} C${b(-38,52)} ${b(-64,14)} ${b(-64,-52)} Z`,4),R(Ve(0,-4,5,40,17),2)],{tags:On});ht("badge-stamp","badges","Tem tròn","Round stamp",["tem","stamp","chứng nhận","approved"],[Ot(wt($t(0,0,96),$t(0,0,80)),3),R(Ve(0,0,5,36,15),3),Ot(wt(At(-60,40,60,40),At(-60,-40,60,-40)),3)],{tags:On});ht("badge-new","badges","Nhãn MỚI (nổ)","NEW burst",["mới","new","sale","nổ"],[R(Ve(0,0,16,100,74,0),3),R(Ve(0,0,16,80,60,11),2)],{tags:On});ht("badge-check","badges","Huy hiệu tích xanh","Verified badge",["xác minh","verified","tích xanh","uy tín"],[R(Ve(0,0,12,90,78,0),1),Ot(Pt([[-30,0],[-8,24],[34,-24]],!1),4)],{tags:On});ht("medal","badges","Huy chương","Medal",["huy chương","medal","vàng","winner"],[R(wt(Pt([[-50,-100],[-20,-100],[10,-30],[-20,-30]]),Pt([[50,-100],[20,-100],[-10,-30],[20,-30]])),1),R($t(0,30,62),2),R($t(0,30,46),2),R(Ve(0,30,5,30,13),4)],{tags:On});ht("label-tag","badges","Nhãn dán","Label",["nhãn","label","tag"],[R(ft(0,0,220,70,35),2),R($t(-84,0,10),4)],{tags:On});ht("badge-percent","badges","Nhãn phần trăm","Percent badge",["giảm giá","percent","%","sale","khuyến mãi"],[R($t(0,0,90),3),Ot(At(-30,40,30,-40),4),R(wt($t(-30,-26,14),$t(30,26,14)),4)],{tags:On});ht("badge-crown","badges","Huy hiệu vương miện","Crown badge",["vương miện","crown","vip","premium"],[R($t(0,0,90),5),R(Pt([[-56,30],[-60,-30],[-30,0],[0,-50],[30,0],[60,-30],[56,30]]),2)],{tags:On});io("doodles","Hoạ tiết vẽ tay","Doodles & decor");const Fo={role:["overlay","sticker"],style:["playful","soft"]};ht("sparkle","doodles","Lấp lánh","Sparkle",["lấp lánh","sparkle","sáng","shine"],[R(`M${b(0,-90)} C${b(8,-20)} ${b(20,-8)} ${b(90,0)} C${b(20,8)} ${b(8,20)} ${b(0,90)} C${b(-8,20)} ${b(-20,8)} ${b(-90,0)} C${b(-20,-8)} ${b(-8,-20)} ${b(0,-90)} Z`,2),R(`M${b(70,-80)} C${b(73,-64)} ${b(76,-61)} ${b(92,-58)} C${b(76,-55)} ${b(73,-52)} ${b(70,-36)} C${b(67,-52)} ${b(64,-55)} ${b(48,-58)} C${b(64,-61)} ${b(67,-64)} ${b(70,-80)} Z`,2)],{tags:Fo});ht("swirl","doodles","Xoáy","Swirl",["xoáy","swirl","spiral"],[Ot(Ea(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:Fo});ht("underline-scribble","doodles","Gạch chân nguệch ngoạc","Scribble underline",["gạch chân","underline","nhấn mạnh"],[Ot(`M${b(-110,0)} C${b(-60,-10)} ${b(20,-12)} ${b(110,-6)} C${b(40,4)} ${b(-40,10)} ${b(-90,18)}`,3)],{tags:Fo});ht("circle-scribble","doodles","Khoanh tròn vẽ tay","Scribble circle",["khoanh tròn","circle","highlight"],[Ot(`M${b(20,-70)} C${b(-60,-74)} ${b(-110,-30)} ${b(-100,10)} C${b(-90,60)} ${b(-20,74)} ${b(40,66)} C${b(100,56)} ${b(110,0)} ${b(90,-36)} C${b(70,-70)} ${b(10,-80)} ${b(-40,-56)}`,3)],{tags:Fo});ht("stars-cluster","doodles","Chùm sao","Star cluster",["sao","stars","lấp lánh"],[R(wt(Ve(-40,-20,5,40,17),Ve(40,30,5,26,11),Ve(50,-50,5,16,7)),2)],{tags:Fo});ht("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 a=Math.cos(no(o)),n=Math.sin(no(o)),i=r%2?6:9,c=r%2?18:9;return Pt([[t-i*a+c*n,e-i*n-c*a],[t+i*a+c*n,e+i*n-c*a],[t+i*a-c*n,e+i*n+c*a],[t-i*a-c*n,e-i*n+c*a]])})),3),R(wt($t(-40,0,6),$t(30,-20,5),$t(-20,40,5)),1)],{tags:Fo});ht("dots-pattern","doodles","Chấm bi","Polka dots",["chấm bi","dots","hoạ tiết"],[R(wt(...Array.from({length:25},(t,e)=>$t(-80+e%5*40+Math.floor(e/5)%2*20,-80+Math.floor(e/5)*40,8))),1)],{tags:Fo});ht("zigzag-line","doodles","Đường răng cưa","Zigzag line",["răng cưa","zigzag"],[Ot(Pt(Array.from({length:11},(t,e)=>[-100+e*20,e%2?-16:16]),!1),3)],{tags:Fo});ht("heart-doodle","doodles","Tim vẽ tay","Doodle heart",["tim","heart","vẽ tay"],[Ot(`M${b(0,70)} C${b(-90,10)} ${b(-80,-70)} ${b(-30,-66)} C${b(-10,-64)} ${b(0,-50)} ${b(0,-36)} C${b(4,-56)} ${b(20,-70)} ${b(40,-66)} C${b(90,-56)} ${b(86,20)} ${b(0,70)}`,3)],{tags:Fo});ht("crown","doodles","Vương miện","Crown",["vương miện","crown","king","queen"],[R(Pt([[-80,50],[-90,-40],[-44,0],[0,-70],[44,0],[90,-40],[80,50]]),2),R(wt($t(-90,-46,10),$t(0,-76,10),$t(90,-46,10)),2)],{tags:Fo});ht("emphasis-lines","doodles","Vạch nhấn","Emphasis lines",["nhấn mạnh","emphasis","pop","chú ý"],[Ot(wt(At(-60,-60,-90,-90),At(0,-70,0,-110),At(60,-60,90,-90)),3)],{tags:Fo});ht("motion-lines","doodles","Vệt chuyển động","Speed lines",["tốc độ","speed lines","motion","nhanh"],[Ot(wt(At(-100,-40,40,-40),At(-70,0,80,0),At(-100,40,40,40)),5)],{tags:Fo});ht("loop-line","doodles","Đường xoắn vòng","Loop line",["vòng","loop","line"],[Ot(`M${b(-110,30)} C${b(-60,30)} ${b(-40,-50)} ${b(-10,-40)} C${b(30,-30)} ${b(-30,40)} ${b(10,40)} C${b(50,40)} ${b(60,-10)} ${b(110,-10)}`,5)],{tags:Fo});ht("flower-doodle","doodles","Hoa vẽ tay","Doodle flower",["hoa","flower","doodle"],[Ot(wt(...Ob(0,0,6,40).map(([t,e])=>$t(t,e,20)),$t(0,0,16)),3)],{tags:Fo});ht("leaf-sprig","doodles","Nhánh lá","Leaf sprig",["nhánh lá","sprig","lá","decor"],[Ot(`M${b(-90,60)} C${b(-30,20)} ${b(30,-20)} ${b(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(no(o)),a=Math.sin(no(o));return`M${b(t,e)} C${b(t+(r*10-a*14),e+(a*10+r*14))} ${b(t+(r*30-a*10),e+(a*30+r*10))} ${b(t+r*36,e+a*36)} C${b(t+(r*30+a*10),e+(a*30-r*10))} ${b(t+(r*10+a*14),e+(a*10-r*14))} ${b(t,e)} Z`})),1)],{tags:Fo});ht("exclamation","doodles","Dấu chấm than","Exclamation",["chú ý","exclamation","!","warning"],[R(wt(`M${b(-16,-90)} L${b(16,-90)} L${b(10,30)} L${b(-10,30)} Z`,$t(0,66,16)),3)],{tags:Fo});ht("question","doodles","Dấu hỏi","Question mark",["câu hỏi","question","?","faq"],[Ot(`M${b(-40,-50)} C${b(-40,-100)} ${b(40,-100)} ${b(40,-50)} C${b(40,-14)} ${b(0,-14)} ${b(0,20)}`,1),R($t(0,62,14),1)],{tags:Fo});io("animals","Con vật","Animals");const Ia={role:["sticker","explain"],style:["playful","soft"]};ht("cat","animals","Con mèo","Cat",["mèo","cat","thú cưng","pet"],[R(Se(0,40,70,56),1),R($t(0,-40,48),1),R(wt(Pt([[-44,-60],[-40,-104],[-12,-82]]),Pt([[44,-60],[40,-104],[12,-82]])),1),R(wt(Se(-18,-44,6,9),Se(18,-44,6,9)),5),R(Pt([[-6,-24],[6,-24],[0,-16]]),3),Ot(`M${b(66,60)} C${b(110,60)} ${b(110,0)} ${b(90,-10)}`,1)],{tags:Ia});ht("dog","animals","Con chó","Dog",["chó","dog","thú cưng","pet","cún"],[R(Se(0,40,74,54),2),R($t(0,-34,50),2),R(wt(Se(-50,-30,16,34),Se(50,-30,16,34)),5),R(wt($t(-18,-42,7),$t(18,-42,7)),5),R(Se(0,-16,14,10),5),Ot(He(0,-8,10,20,160),5)],{tags:Ia});ht("bird","animals","Chim","Bird",["chim","bird"],[R(Se(0,0,70,50),1),R($t(46,-34,30),1),R(Pt([[74,-36],[100,-28],[74,-22]]),2),R($t(52,-40,5),5),R(`M${b(-20,-10)} C${b(-60,-60)} ${b(-90,-30)} ${b(-80,0)} C${b(-60,-10)} ${b(-40,-6)} ${b(-20,-10)} Z`,4)],{tags:Ia});ht("butterfly","animals","Bướm","Butterfly",["bướm","butterfly"],[R(wt(Se(-44,-30,40,48),Se(44,-30,40,48)),3),R(wt(Se(-34,36,28,30),Se(34,36,28,30)),2),R(ft(0,0,14,120,7),5),Ot(wt(`M${b(0,-56)} C${b(-6,-80)} ${b(-20,-90)} ${b(-30,-96)}`,`M${b(0,-56)} C${b(6,-80)} ${b(20,-90)} ${b(30,-96)}`),5)],{tags:Ia});ht("chicken","animals","Con gà","Chicken",["gà","chicken","rooster"],[R(Se(0,20,70,60),4),R($t(40,-40,32),4),R(wt($t(36,-76,10),$t(50,-80,9),$t(24,-74,8)),3),R(Pt([[68,-42],[90,-36],[68,-30]]),2),R($t(46,-46,5),5),R(wt(ft(-16,90,6,30,2),ft(16,90,6,30,2)),2)],{tags:Ia});ht("fish-tropical","animals","Cá nhiệt đới","Tropical fish",["cá","fish","biển","sea"],[R(`M${b(-70,0)} C${b(-30,-70)} ${b(50,-60)} ${b(70,0)} C${b(50,60)} ${b(-30,70)} ${b(-70,0)} Z`,2),R(Pt([[-60,0],[-110,-40],[-100,0],[-110,40]]),3),R(wt(ft(-10,0,14,96,6),ft(24,0,14,80,6)),4),R($t(46,-10,7),5)],{tags:Ia});ht("elephant","animals","Con voi","Elephant",["voi","elephant"],[R(Se(-10,20,80,56),5),R($t(54,-20,40),5),R(`M${b(84,-10)} C${b(110,20)} ${b(100,70)} ${b(80,80)} L${b(70,72)} C${b(84,50)} ${b(84,20)} ${b(64,0)} Z`,5),R(Se(30,-24,26,34),4),R(wt(ft(-60,70,24,40,6),ft(30,70,24,40,6)),5),R($t(62,-28,5),1)],{tags:Ia});ht("turtle","animals","Con rùa","Turtle",["rùa","turtle"],[R(wt(Se(-50,30,18,12),Se(50,30,18,12),Se(86,0,26,20)),1),R(`M${b(-80,20)} C${b(-80,-60)} ${b(70,-60)} ${b(70,20)} Z`,2),Ot(wt(At(-50,-24,-36,16),At(0,-44,0,16),At(40,-24,30,16)),5),R($t(96,-6,4),5)],{tags:Ia});io("scenery","Cảnh nền","Scenery");const ea={role:["background"],style:["soft","playful","clean"]};ht("ground-grass","scenery","Dải cỏ","Grass ground",["mặt đất","cỏ","ground","grass"],[R(`M${b(-300,0)} C${b(-200,-20)} ${b(-100,-20)} ${b(0,-6)} C${b(100,8)} ${b(200,-14)} ${b(300,0)} L${b(300,60)} L${b(-300,60)} Z`,1)],{tags:ea,outline:!1});ht("road","scenery","Con đường","Road",["đường","road","phố","street"],[R(ft(0,0,600,70,0),5),R(wt(...Array.from({length:8},(t,e)=>ft(-262+e*75,0,40,6,2))),4)],{tags:ea,outline:!1});ht("hills-band","scenery","Dải đồi","Rolling hills",["đồi","hills","landscape"],[R(`M${b(-300,40)} C${b(-220,-60)} ${b(-120,-60)} ${b(-40,30)} C${b(40,-50)} ${b(160,-60)} ${b(300,20)} L${b(300,80)} L${b(-300,80)} Z`,1),R(`M${b(-300,60)} C${b(-180,0)} ${b(-60,10)} ${b(40,56)} C${b(140,10)} ${b(220,10)} ${b(300,50)} L${b(300,80)} L${b(-300,80)} Z`,2)],{tags:ea,outline:!1});ht("city-band","scenery","Dải thành phố","City band",["thành phố","city","skyline","background"],[R(Pt([[-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:ea,outline:!1});ht("sea-band","scenery","Dải biển","Sea band",["biển","sea","ocean","nước"],[R(wt(`M${b(-300,0)}`+Array.from({length:12},(t,e)=>` C${b(-300+e*50+15,-14)} ${b(-300+e*50+35,-14)} ${b(-300+e*50+50,0)}`).join("")+` L${b(300,70)} L${b(-300,70)} Z`),1),Ot(wt(...[-200,-60,80,220].map(t=>`M${b(t,30)} C${b(t+15,22)} ${b(t+35,22)} ${b(t+50,30)}`)),4)],{tags:ea,outline:!1});ht("sky-clouds","scenery","Trời nhiều mây","Sky with clouds",["bầu trời","sky","mây","clouds"],[R(wt($o(-180,-10,140,60,5),$o(30,-40,180,70,6),$o(210,10,120,50,4)),4)],{tags:ea,outline:!1});ht("mountain-range","scenery","Dãy núi","Mountain range",["dãy núi","mountains","range"],[R(Pt([[-300,70],[-220,-50],[-150,20],[-60,-90],[30,10],[110,-70],[200,0],[260,-40],[300,0],[300,70]]),2),R(wt(Pt([[-60,-90],[-84,-54],[-70,-58],[-56,-48],[-40,-62]]),Pt([[110,-70],[94,-44],[108,-48],[122,-40],[130,-50]])),4)],{tags:ea,outline:!1});ht("rice-field","scenery","Ruộng lúa bậc thang","Rice terraces",["ruộng","lúa","rice field","terraces","quê"],[R(`M${b(-300,-20)} C${b(-150,-50)} ${b(150,-50)} ${b(300,-20)} L${b(300,0)} C${b(150,-30)} ${b(-150,-30)} ${b(-300,0)} Z`,1),R(`M${b(-300,10)} C${b(-150,-18)} ${b(150,-18)} ${b(300,10)} L${b(300,32)} C${b(150,4)} ${b(-150,4)} ${b(-300,32)} Z`,2),R(`M${b(-300,42)} C${b(-150,18)} ${b(150,18)} ${b(300,42)} L${b(300,70)} L${b(-300,70)} Z`,1)],{tags:ea,outline:!1});ht("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])=>Ve(t,e,4,o*2,o*.6,0))),2),R($t(170,-60,26),4)],{tags:ea,outline:!1});io("emotes","Biểu cảm hoạt hình","Cartoon emotes");const zn={role:["overlay","sticker"],style:["playful","soft"]};ht("sweat-drops","emotes","Giọt mồ hôi","Sweat drops",["mồ hôi","sweat","lo lắng","nervous","ngại"],[R(wt(Un(-20,-30,46),Un(34,10,30)),4)],{tags:zn});ht("anger-mark","emotes","Dấu tức giận","Anger mark",["tức giận","anger","giận","bực","💢"],[Ot(wt(...[[-1,-1],[1,-1],[1,1],[-1,1]].map(([t,e])=>`M${b(t*14,e*70)} C${b(t*14,e*30)} ${b(t*30,e*14)} ${b(t*70,e*14)}`)),3)],{tags:zn});ht("zzz","emotes","Ngủ zzz","Sleeping zzz",["ngủ","sleep","zzz","buồn ngủ","mệt"],[Ot(wt(...[[-50,40,36],[10,-6,28],[54,-46,20]].map(([t,e,o])=>`M${b(t-o,e-o)} L${b(t+o,e-o)} L${b(t-o,e+o)} L${b(t+o,e+o)}`)),5)],{tags:zn});ht("idea-bulb","emotes","Ý tưởng","Idea bulb",["ý tưởng","idea","bóng đèn","nghĩ ra","aha"],[R(wt($t(0,-20,46),`M${b(-22,20)} L${b(22,20)} L${b(18,52)} L${b(-18,52)} Z`),3),R(`M${b(-14,56)} L${b(14,56)} L${b(10,70)} L${b(-10,70)} Z`,2),Ot(wt(At(-80,-20,-60,-20),At(60,-20,80,-20),At(0,-100,0,-80),At(-58,-78,-44,-64),At(58,-78,44,-64)),3)],{tags:zn});ht("dizzy","emotes","Choáng váng","Dizzy",["choáng","dizzy","chóng mặt","hoa mắt","bị đánh"],[Ot(`M${b(-70,0)} C${b(-70,-40)} ${b(70,-40)} ${b(70,0)} C${b(70,30)} ${b(-40,34)} ${b(-40,4)} C${b(-40,-14)} ${b(30,-14)} ${b(30,4)}`,1),R(wt(Ve(-60,-50,5,20,9),Ve(64,-36,5,16,7),Ve(0,46,5,14,6)),3)],{tags:zn});ht("shock-lines","emotes","Giật mình","Shock lines",["giật mình","shock","bất ngờ","surprise","hoảng"],[Ot(wt(...Array.from({length:8},(t,e)=>{const o=no(e*45),r=Math.cos(o),a=Math.sin(o);return At(r*44,a*44,r*(e%2?78:96),a*(e%2?78:96))})),3)],{tags:zn});ht("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${b(t,e+o*.9)} C${b(t-o*1.4,e)} ${b(t-o,e-o*1.1)} ${b(t,e-o*.4)} C${b(t+o,e-o*1.1)} ${b(t+o*1.4,e)} ${b(t,e+o*.9)} Z`)),3)],{tags:zn});ht("blush-lines","emotes","Ngượng đỏ mặt","Blush lines",["ngượng","blush","đỏ mặt","xấu hổ","shy"],[Ot(wt(...[-60,-10,40].map(t=>At(t,50,t+30,-50))),3)],{tags:zn});ht("steam-puff","emotes","Xì khói (bực)","Steam puff",["xì khói","steam","bực","tức","huff"],[R(wt($t(-44,10,26),$t(-14,-6,30),$t(22,4,24),$t(40,-30,18),$t(62,-54,12)),4)],{tags:zn});ht("music-notes-pop","emotes","Nốt nhạc (vui)","Happy notes",["vui","hát","notes","happy","nhạc"],[R(wt($t(-40,40,16),$t(30,20,14)),1),Ot(wt(At(-26,40,-26,-50),At(44,20,44,-60),`M${b(-26,-50)} L${b(44,-60)}`),1)],{tags:zn});const Fp=zb.map(t=>({...t,parts:_I(t.parts)})),WI=new Map(Fp.map(t=>[t.id,t])),HI=Object.freeze(Object.entries(hp).map(([t,[e,o]])=>({id:t,vi:e,en:o,count:Fp.filter(r=>r.cat===t).length}))),Pb=Object.freeze(Fp.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"]}})}))),XI=Object.freeze(Fp.map(t=>t.id)),UI=t=>{let e=1/0,o=1/0,r=-1/0,a=-1/0;for(const n of t){const i=n.d.match(/-?\d*\.?\d+/g).map(Number);for(let c=0;c+1<i.length;c+=2)e=Math.min(e,i[c]),r=Math.max(r,i[c]),o=Math.min(o,i[c+1]),a=Math.max(a,i[c+1])}return[va(e),va(o),va(r),va(a)]},eg=t=>String(t).toLowerCase().normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d");function Lb(t,{id:e="s1",pos:o=[500,500],scale:r=1,rot:a=0,colors:n=null,en:i=!1,stroke:c=null}={}){const u=WI.get(t);if(!u)throw Error(`Unknown 2D library shape "${String(t).slice(0,48)}" — search_shape_library lists the ids`);const p=Array.isArray(n)?Object.fromEntries(n.map((h,f)=>[f+1,h])):n||{};for(const h of Object.values(p))if(!/^#[0-9a-fA-F]{6}$/.test(h))throw Error("Library colours are #RRGGBB");const s=u.parts.map(h=>h.role!==7&&h.fill!==null&&p[h.role]?{...h,fill:p[h.role],role:7}:h);return{id:e,name:(i?u.en:u.vi).slice(0,40),type:"art",params:{parts:s,box:UI(s),...u.outline?{}:{outline:!1},lib:u.id},pos:[...o],rot:a,scale:[r,r],opacity:1,fill:{type:"color",color:s.find(h=>h.fill)?.fill??"#4a90d9"},stroke:c??{color:p[5]??zh[5],width:5,cap:"round",join:"round"}}}function YI({query:t="",cat:e=null,human:o=null,limit:r=24}={}){const a=eg(t).split(/[^a-z0-9]+/).filter(i=>i.length>1);return Pb.filter(i=>(!e||i.cat===e)&&(o==null||i.human===!!o)).map(i=>{const c=eg([i.id.replace(/-/g," "),i.vi,i.en,...i.words,hp[i.cat][0],hp[i.cat][1]].join(" ")),u=a.length?a.reduce((p,s)=>p+(` ${c} `.includes(` ${s} `)?3:c.includes(s)?1:0),0):1;return{e:i,score:u}}).filter(i=>i.score>0).sort((i,c)=>c.score-i.score).slice(0,Math.max(1,Math.min(100,r))).map(i=>i.e)}const BT=Object.freeze(Object.defineProperty({__proto__:null,LIB2D:Pb,LIB2D_CATEGORIES:HI,LIB2D_IDS:XI,LIB_PALETTE:zh,libraryArt:Lb,searchLibrary2d:YI},Symbol.toStringTag,{value:"Module"})),og=(t,e,o,r,a)=>t==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a);function qI(t,e){if(!(t>0)||!(e>0))return 0;const o=t/e;return 1-Math.min(o,1/o)}const rg=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},ZI=.4,_T=(t,e,o=ZI)=>qI(rg(t),rg(e))>o;function JI(t,e,o){const r=-(t.angle||0)*Math.PI/180,a=e-t.cx,n=o-t.cy,i=a*Math.cos(r)-n*Math.sin(r),c=a*Math.sin(r)+n*Math.cos(r);return Math.abs(i)<=t.w/2&&Math.abs(c)<=t.h/2}function VT(t,e,o,{alphaAt:r,threshold:a=8}={}){for(const n of t){const i=r?r(n.id,e,o):null;if(i!=null){if(i>=a)return n.id;continue}if(n.rect&&JI(n.rect,e,o))return n.id}return null}const GT=(t,e=.012)=>Math.abs(t)<e?0:t,KT=(t,e)=>Math.abs(t)>=Math.abs(e)?{dx:t,dy:0}:{dx:0,dy:e},Ei=[.37,0,.63,1],ng=[.33,0,.67,1],Yn=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}}),fp=Object.freeze(Object.keys(Yn).filter(t=>Yn[t].move)),Fb=Object.freeze(Object.keys(Yn)),QI=60,mp=t=>Math.round(t*1e4)/1e4,tA=t=>Math.round(t*30)/30,Nb=(t,e)=>Math.max(Vr[t].min,Math.min(Vr[t].max,e));function eA(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 oA(t,e,{amount:o=1,period:r,a=0,b:n=t.duration,phase:i=0}={}){const c=Yn[e];if(!c)throw Error(`animateLayer preset: ${Fb.join(" | ")}`);const u=c.amount*o,p=Math.max(.1,r??c.period),s={},h=x=>Qt(t,x,a),f=Math.max(a+1/30,n),m=(x,E,$,S)=>{const k=s[x]??=[];if(k.length>=QI||E>f+1e-6)return!1;const y=mp(tA(E));return k.length&&y-k.at(-1).time<1/45||k.push({time:y,value:mp(Nb(x,$)),...S?{ease:S}:{}}),!0},g=a-i*p,v=(x,E,$=!1)=>{const S=h(x),k=y=>$?S*(1+E*y):S+E*y;m(x,a,S,Ei);for(let y=0;;y++){const C=g+p/4+y*p/2;if(!(C<=a+1/30)&&(C>f-p/4||!m(x,C,k(y%2?-1:1),Ei)))break}m(x,f,S)};switch(e){case"sway":case"swing":case"wave":v("rot",u);break;case"nod":v("rot",u);break;case"breathe":{const x=h("sy");m("sy",a,x,Ei);for(let E=0;;E++){const $=g+p/2+E*p/2;if(!($<=a+1/30)&&($>f-p/4||!m("sy",$,x*(1+(E%2?0:u)),Ei)))break}m("sy",f,x);break}case"bob":{const x=h("y");m("y",a,x,Ei);for(let E=0;;E++){const $=g+p/2+E*p/2;if(!($<=a+1/30)&&($>f-p/4||!m("y",$,x-(E%2?0:u),Ei)))break}m("y",f,x);break}case"drift":v("x",u);break;case"blink":{const x=h("sy");m("sy",a,x);for(let E=0;;E++){const $=g+p*(E+.6);if(!($<a+.1)&&($+.16>f||!m("sy",$,x)||!m("sy",$+.07,x*(1-u))||!m("sy",$+.15,x)))break}m("sy",f,x);break}case"rise":{const x=h("y"),E=h("zoom");for(let $=0;;$++){const S=g+$*p;if(S+p<=a)continue;if(S>=f)break;const k=Math.max(a,S+(S>a?1/30:0)),y=(k-S)/p,C=Math.min(f,S+p);if(!m("y",k,x-u*y)||!m("opacity",k,Math.sin(Math.PI*y)**1.2,[.4,0,.6,1])||!m("zoom",k,E*(.7+.5*y)))break;S+p/2>k+1/30&&S+p/2<C&&m("opacity",S+p/2,1,[.4,0,.6,1]),m("y",C,x-u*(C-S)/p,"hold"),m("opacity",C,Math.sin(Math.PI*(C-S)/p)**1.2,"hold"),m("zoom",C,E*(.7+.5*(C-S)/p),"hold")}break}case"wiggle":{for(const[x,E]of[["x",11],["y",23]]){const $=h(x);m(x,a,$,"auto");for(let S=1;;S++){const k=a+S*p/2;if(k>=f-p/4||!m(x,k,$+u*(eA(S,E+(t.id?.length??0))*2-1),"auto"))break}m(x,f,$)}break}case"spin":{const x=h("rot");m("rot",a,x),m("rot",f,x+360*u*(f-a)/p);break}case"push-in":case"pull-out":{const x=h("zoom"),[E,$]=e==="push-in"?[x,x*(1+u)]:[x*(1+u),x];m("zoom",a,E,ng),m("zoom",f,$);break}case"pan-left":case"pan-right":{const x=h("x");m("x",a,x,ng),m("x",f,x+(e==="pan-left"?-u:u));break}}return s}const rA=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 Rb(t,e,o){const r=rA(t);if(!r)return null;const a=m2(t,t.start,t.start+t.duration,e,o),n=!a&&(ed(t,"rot")||!!g2(t))&&t.rotFit!=="frame",[i,c]=r,u=Math.ceil(Math.hypot(i,c)/2)*2;return i*(n?og("contain",e,o,u,u):og("contain",e,o,i,c))*k1(t,0,e,o).zoom}function Ou(t,e){const o=new Set(e);let r=!0;for(;r;){r=!1;for(const a of t)a.parentId&&o.has(a.parentId)&&!o.has(a.id)&&(o.add(a.id),r=!0)}return[...o]}function Ul(t,e,o=1280,r=720){dr(t);const a=new Map;for(const n of e){const i=t.find(u=>u.id===n),c=i&&Rb(i,o,r);c&&a.set(n,c)}return a}const ag=(t,e)=>{let o=t;for(const[r,a]of e){const n=Ee(o,r);n.length&&(o={...o,...ge(o,r,n.map(i=>({...i,value:Math.round(Nb(r,i.value*a)*1e6)/1e6})))})}return o},Si=t=>Math.round(t*1e6)/1e6;function Fs(t,e,o=1280,r=720){let a=t.slice();const n=i=>{let c=0,u=a.find(p=>p.id===i);for(;u?.parentId&&c<9;)u=a.find(p=>p.id===u.parentId),c++;return c};for(const i of[...e.keys()].sort((c,u)=>n(c)-n(u))){dr(a);const c=a.findIndex(h=>h.id===i);if(c<0)continue;const u=Rb(a[c],o,r),p=u?e.get(i)/u:1;if(!(Math.abs(p-1)>1e-6))continue;const s=a[c];a[c]=ag({...s,scale:Si((s.scale??1)*p),...s.anchorX!==void 0?{anchorX:Si(s.anchorX/p)}:{},...s.anchorY!==void 0?{anchorY:Si(s.anchorY/p)}:{}},[["zoom",p],["ax",1/p],["ay",1/p]]),a=a.map(h=>h.parentId!==i?h:ag({...h,posX:Si((h.posX??0)/p),posY:Si((h.posY??0)/p),scale:Si((h.scale??1)/p)},[["x",1/p],["y",1/p],["zoom",1/p]]))}return dr(a),a}function Yl(t,e,o={}){if(t.kind==="audio")throw Error("animateLayer needs a visual layer");const r=oA(t,e,o);let a={...t};for(const[n,i]of Object.entries(r))i.length>=2&&(a={...a,...ge(a,n,i)});return a}function nA(t,e,o,r=1280,a=720,n=null){let i,c;if(Array.isArray(o))[i,c]=o;else{const[x,E,$,S]=n??[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+($-x)*k[0],c=E+(S-E)*k[1]}if(![i,c].every(x=>Number.isFinite(x)&&x>=-1&&x<=2))throw Error("anchor: x, y are 0..1 of the frame");const u=k1(t,e,r,a),p=.5+u.x,s=.5+u.y,h=-u.rot*Math.PI/180,f=(i-p)*r,m=(c-s)*a,g=(f*Math.cos(h)-m*Math.sin(h))/(u.sx||1),v=(f*Math.sin(h)+m*Math.cos(h))/(u.sy||1);return[mp(g/(r*u.zoom)),mp(v/(a*u.zoom))]}function Ba(t,e,{parentClipId:o,anchor:r,at:a=0,W:n=1280,H:i=720,box:c=null}){let u={...e};if(o!==void 0){if(o!==null){const p=t.find(s=>s.id===o);if(!p||p.kind==="audio")throw Error("rigLayer parentClipId: a visual layer of this timeline");if(d2(t,e.id,p.id))throw Error("rigLayer: that parent would make a loop")}u={...u,...h2(t,u,o,a,n,i)},u.parentId||delete u.parentId,dr(t.map(p=>p.id===e.id?u:p))}if(r!=null){const[p,s]=nA(u,a,r,n,i,c);u={...u,...f2(u,a,p,s,n,i)}}return u}const gp=t=>t*Math.PI/180,Tt=(t,e)=>[t[0]+e[0],t[1]+e[1]],pl=(t,e)=>[t[0]-e[0],t[1]-e[1]],Co=(t,e)=>[t[0]*e,t[1]*e],Ph=t=>Math.hypot(t[0],t[1]),Lh=t=>{const e=Ph(t)||1;return[t[0]/e,t[1]/e]},Db=t=>[-t[1],t[0]],ms=(t,e,o)=>t+(e-t)*o,Qd=(t,e,o)=>[ms(t[0],e[0],o),ms(t[1],e[1],o)],Yi=(t,e,o)=>Math.max(e,Math.min(o,t)),Ri=t=>t<.5?2*t*t:1-2*(1-t)**2,Ns=t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,aA=300,ig={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"},Ya=Object.freeze({host:{vi:"MC nữ",en:"Female host",hair:"bob",outfit:"blazer",palette:ig},hostman:{vi:"MC nam",en:"Male host",hair:"short",outfit:"shirt",palette:{...ig,top:"#f6eee8",topS:"#d9cbc2",inner:"#f6eee8",accent:"#c8202f",bottom:"#2a3550",bottomS:"#1e2740",hair:"#1c1412"}}}),iA=Object.freeze(Object.keys(Ya)),sA=Object.freeze(["skin","hair","top","inner","bottom","shoe","accent","lip","prop","propLabel"]),sg=Object.freeze(["neutral","smile","grin","surprised","wink","think","sad"]),lg=Object.freeze(["box","bottle","phone","card"]),lA={sway:0,lean:0,tilt:0,turn:0,bounce:0,hR:[42,-128],hL:[-42,-128],shR:"open",shL:"open"},Pe=t=>({...lA,...t}),Bb=Object.freeze({idle:{vi:"Đứng thở",en:"Idle",dur:2,face:"smile",cyc:t=>Pe({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 Pe({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,Pe({hR:[70,-292],shR:"wave",tilt:-3,lean:-2})],[1,Pe({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,Pe({hR:[128,-232],shR:"point",lean:3,turn:.45,tilt:2})],[1,Pe({hR:[126,-230],shR:"point",lean:3,turn:.45,tilt:2})]],ease:[Ns,Ri]},"point-up":{vi:"Chỉ lên",en:"Point up",dur:1.4,face:"smile",keys:[[0,null],[.3,Pe({hR:[66,-318],shR:"point",turn:.2,tilt:-4})],[1,Pe({hR:[66,-316],shR:"point",turn:.2,tilt:-4})]],ease:[Ns,Ri]},present:{vi:"Mời xem",en:"Present",dur:1.6,face:"grin",keys:[[0,null],[.35,Pe({hR:[124,-178],shR:"open",hL:[-36,-150],lean:2,turn:.4,tilt:3})],[1,Pe({hR:[120,-182],shR:"open",hL:[-36,-150],lean:2,turn:.4,tilt:3})]],ease:[Ns,Ri]},thumbs:{vi:"Giơ ngón cái",en:"Thumbs up",dur:1.3,face:"grin",keys:[[0,null],[.3,Pe({hR:[52,-212],shR:"thumb",tilt:-3,bounce:-3})],[1,Pe({hR:[50,-210],shR:"thumb",tilt:-3})]],ease:[Ns,Ri]},clap:{vi:"Vỗ tay",en:"Clap",dur:1.6,face:"grin",cyc:t=>{const e=Math.abs(Math.sin(t*7));return Pe({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,Pe({hR:[24,-170],hL:[-24,-166],shR:"hold",shL:"hold",lean:-2,tilt:3,elDown:1})],[1,Pe({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,Pe({hR:[70,-276],shR:"hold",hL:[-38,-150],turn:.3,tilt:-2})],[1,Pe({hR:[70,-280],shR:"hold",hL:[-38,-150],turn:.3,tilt:-2})]],ease:[Ns,Ri],prop:!0,one:!0},think:{vi:"Suy nghĩ",en:"Think",dur:1.8,face:"think",keys:[[0,null],[.35,Pe({hR:[14,-240],shR:"fist",hL:[-6,-188],shL:"fist",tilt:7,turn:-.2,elDown:1})],[1,Pe({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,Pe({hR:[78,-170],hL:[-78,-170],shR:"open",shL:"open",bounce:-5,tilt:6})],[.75,Pe({hR:[78,-170],hL:[-78,-170],shR:"open",shL:"open",bounce:-5,tilt:6})],[1,Pe({})]]},nod:{vi:"Gật đầu",en:"Nod",dur:1,face:"smile",cyc:t=>Pe({tilt:0,bounce:Math.max(0,Math.sin(t*9))*-3,nod:Math.max(0,Math.sin(t*9))})}}),cg=Object.freeze(Object.keys(Bb)),cA={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 pA(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(a=>/[a-z ,.!?]/.test(a))}));return r=>{const a=o.find(i=>r>=i.start&&r<i.end);if(!a||!a.chars.length)return null;const n=a.chars[Math.min(a.chars.length-1,Math.floor((r-a.start)/(a.end-a.start)*a.chars.length))];return/[ ,.!?]/.test(n)?"X":cA[n]??"C"}}function vr(t,e,o,r){const a=Lh(pl(e,t)),n=Db(a),i=Ph(pl(e,t)),c=[];for(let u=0;u<=3;u++){const p=u/3*.94;c.push(Tt(Tt(t,Co(a,i*p)),Co(n,ms(o,r,p)/2)))}c.push(Tt(e,Co(a,r/2)));for(let u=3;u>=0;u--){const p=u/3*.94;c.push(Tt(Tt(t,Co(a,i*p)),Co(n,-ms(o,r,p)/2)))}return c.push(Tt(t,Co(a,-o/2))),c}const Ne=(t,e,o,r=0,a=10)=>Array.from({length:a},(n,i)=>{const c=i/a*2*Math.PI,u=Math.cos(c)*e,p=Math.sin(c)*o,s=gp(r);return[t[0]+u*Math.cos(s)-p*Math.sin(s),t[1]+u*Math.sin(s)+p*Math.cos(s)]}),ql=(t,e,o,r,a,n=6)=>Array.from({length:n+1},(i,c)=>{const u=gp(ms(r,a,c/n));return[t[0]+Math.cos(u)*e,t[1]+Math.sin(u)*o]});function pg(t,e,o,r,a){const n=pl(e,t),i=Yi(Ph(n),Math.abs(o-r)+1,o+r-.5),c=Math.atan2(n[1],n[0]),u=Math.acos(Yi((o*o+i*i-r*r)/(2*o*i),-1,1)),p=Tt(t,Co([Math.cos(c+a*u),Math.sin(c+a*u)],o));return{joint:p,end:Tt(p,Co(Lh(pl(e,p)),r))}}function uA(t,e,o,r,a,n,i){const c=[],u=(D,q,pt={})=>c.push({points:D.map(n),fill:q,...pt}),p=(D,q=.6)=>c.push({points:D.map(n),fill:null,closed:!1,lw:q}),s=o.bounce,h=[o.sway,-140+s],f=[Math.sin(gp(o.lean)),-Math.cos(gp(o.lean))],m=[-f[1],f[0]],g=(D,q)=>Tt(Tt(h,Co(f,D)),Co(m,q));g(78,0);const v=g(98,0),x=Tt(g(132,0),[o.turn*3,(o.nod??0)*4]),E=g(90,30),$=g(90,-30);u(Ne([o.sway*.5,2],44,6),e.shadow,{line:!1});const S=g(-2,13),k=g(-2,-13),y=[17,-4],C=[-17,-4];t.outfit==="blazer"?(u(vr(S,y,20,13),e.skin),u(vr(k,C,20,13),e.skinB)):(u(vr(S,y,24,18),e.bottom,{lw:1.1}),u(vr(k,C,24,18),e.bottomS,{lw:1.1})),u(Ne([y[0]+4,-2],13,6),e.shoe),u(Ne([C[0]-4,-2],13,6),e.shoe),t.outfit==="blazer"?u([g(4,-26),g(4,26),g(-56,32),g(-60,0),g(-56,-32)],e.bottom,{lw:1.15}):u([g(6,-25),g(6,25),g(-10,26),g(-10,-26)],e.bottom,{lw:1.1}),u([g(4,-25),g(52,-27),g(88,-34),g(96,-12),g(96,12),g(88,34),g(52,27),g(4,25)],e.top,{lw:1.25}),u([g(52,14),g(88,30),g(88,34),g(52,27),g(4,25),g(4,14)],e.topS,{line:!1}),t.outfit==="blazer"?(u([g(96,-10),g(96,10),g(54,0)],e.inner,{line:!1}),p([g(96,-11),g(54,0),g(10,-2)],.7),p([g(96,11),g(54,0)],.7),u(Ne(g(40,-4),2.2,2.2),e.topS,{line:!1}),u(Ne(g(26,-4),2.2,2.2),e.topS,{line:!1})):(p([g(96,-11),g(84,0),g(96,11)],.7),u([g(86,-4),g(86,4),g(50,5),g(42,0),g(50,-5)],e.accent,{lw:.8})),u(vr(v,Tt(x,[0,18]),15,14),e.skinB,{lw:.9}),t.hair==="bob"&&u([Tt(x,[-33,-8]),Tt(x,[-30,-30]),Tt(x,[0,-40]),Tt(x,[30,-30]),Tt(x,[33,-8]),Tt(x,[34,22]),Tt(x,[22,26]),Tt(x,[-22,26]),Tt(x,[-34,22])],e.hair);const A=o.tilt;u(Ne(Tt(x,[-26,4]),6,8),e.skin,{lw:.8}),u(Ne(Tt(x,[26,4]),6,8),e.skin,{lw:.8}),u(Ne(x,26,30,A,12),e.skin,{lw:1.2});const z=o.turn*7,j=(D,q)=>Tt(x,[D+z,q]),P=r.blink,F=(D,q,pt)=>{if(q||pt==="happy"){p(pt==="happy"?ql(j(D,-1),4.5,3.5,200,340):ql(j(D,-2),4.5,2.5,20,160),.7);return}const yt=pt==="wide",Mt=yt?4:3.4,l=yt?5.6:4.4;u(Ne(j(D,-2),Mt,l),e.eye,{line:!1}),u(Ne(j(D+1.2,-3.6),1.2,1.2,0,6),"#ffffff",{line:!1})},N=r.expr,G=N==="grin"?"happy":N==="surprised"?"wide":null;F(10,P,G),F(-10,P||N==="wink",G);const V=N==="surprised"?-17:N==="sad"?-12:-14;p(N==="think"?[j(5,-15),j(10,-18),j(15,-16)]:[j(5,V+1),j(10,V-(N==="sad"?-1:1)),j(15,V+(N==="sad"?-2:1))],.65),p(N==="think"?[j(-15,-14),j(-10,-14),j(-5,-14)]:[j(-15,V+(N==="sad"?-2:1)),j(-10,V-(N==="sad"?-1:1)),j(-5,V+1)],.65),p([j(1,4),j(2,9),j(-1,10)],.5),u(Ne(j(15,9),4.5,2.6,0,8),e.blush,{line:!1}),u(Ne(j(-15,9),4.5,2.6,0,8),e.blush,{line:!1});const et=j(0,17),U=r.mouth;U==="A"?(u(Ne(et,6,5.5),e.mouth,{lw:.6}),u(Ne(Tt(et,[0,2.6]),3.6,2),e.tongue,{line:!1})):U==="E"?(u(Ne(et,7,2.8),e.mouth,{lw:.6}),u([Tt(et,[-5,-1.6]),Tt(et,[5,-1.6]),Tt(et,[4,-.4]),Tt(et,[-4,-.4])],e.teeth,{line:!1})):U==="O"?u(Ne(et,4,4.8),e.mouth,{lw:.6}):U==="C"?u(Ne(et,5,2.2),e.mouth,{lw:.55}):U==="X"?p([Tt(et,[-5,0]),Tt(et,[0,.8]),Tt(et,[5,0])],.6):N==="grin"||N==="surprised"?N==="surprised"?u(Ne(et,4.2,5),e.mouth,{lw:.6}):(u([Tt(et,[-8,-2]),Tt(et,[8,-2]),Tt(et,[5,4]),Tt(et,[0,6]),Tt(et,[-5,4])],e.mouth,{lw:.6}),u([Tt(et,[-7,-1.6]),Tt(et,[7,-1.6]),Tt(et,[6,.4]),Tt(et,[-6,.4])],e.teeth,{line:!1})):N==="sad"?p(ql(Tt(et,[0,3]),6,3,200,340),.65):N==="think"?p([Tt(et,[-4,0]),Tt(et,[4,-1])],.6):p(ql(Tt(et,[0,-2]),7,4,20,160),.65),t.hair==="bob"?u([Tt(x,[-28,-6]),Tt(x,[-27,-26]),Tt(x,[-4,-36]),Tt(x,[22,-31]),Tt(x,[29,-12]),Tt(x,[16,-20]),Tt(x,[2,-15]),Tt(x,[-12,-20]),Tt(x,[-20,-8])],e.hair):u([Tt(x,[-27,-4]),Tt(x,[-26,-24]),Tt(x,[-6,-36]),Tt(x,[18,-34]),Tt(x,[28,-16]),Tt(x,[27,-4]),Tt(x,[20,-18]),Tt(x,[0,-24]),Tt(x,[-18,-16])],e.hair);const at=(D,q,pt,yt,Mt,l)=>{const lt=pg(D,q,52,48,1),K=pg(D,q,52,48,-1),d=I=>I.joint[0]*pt+I.joint[1]*(o.elDown?4:.9),w=d(lt)>=d(K)?lt:K,T=Mt?e.topS:e.top;u(vr(D,w.joint,19,16),T,{lw:1.15}),u(vr(w.joint,w.end,16,13),T,{lw:1.15}),u(vr(Qd(w.joint,w.end,.82),w.end,13,12),t.outfit==="blazer"?e.inner:e.top,{lw:.8}),W(w.end,Lh(pl(w.end,w.joint)),yt,l)},W=(D,q,pt,yt)=>{const Mt=Db(q),l=e.skin;if(pt==="point"){u(vr(D,Tt(D,Co(q,18)),6,5),l,{lw:.9}),u(Ne(D,8,7),l,{lw:.9});return}if(pt==="thumb"){u(Ne(D,8.5,8),l,{lw:.9}),u(vr(Tt(D,[0,-4]),Tt(D,[0,-19]),6,5),l,{lw:.9});return}if(pt==="fist"){u(Ne(D,8.5,8),l,{lw:.9});return}if(pt==="wave"){const lt=[0,-1];u(Ne(Tt(D,[0,-3]),9,10),l,{lw:.9});for(const K of[-6,-2,2,6])u(vr(Tt(D,[K,-9]),Tt(D,[K*1.3,-21]),4.2,3.6),l,{lw:.8});u(vr(Tt(D,[yt?7:-7,0]),Tt(D,Tt(Co(lt,8),[yt?15:-15,-2])),4.6,4),l,{lw:.8});return}u(Ne(Tt(D,Co(q,3)),9,10,Math.atan2(q[1],q[0])*180/Math.PI),l,{lw:.9});for(const lt of[-5,-1.6,1.8,5.2])u(vr(Tt(Tt(D,Co(q,9)),Co(Mt,lt)),Tt(Tt(D,Co(q,pt==="hold"?13:19)),Co(Mt,lt*1.15)),4,3.4),l,{lw:.8})},_=o.shR==="hold",J=D=>{const q=i.kind;q==="bottle"?(u([[-13,28],[13,28],[14,-14],[7,-27],[6,-40],[-6,-40],[-7,-27],[-14,-14]].map(pt=>Tt(D,pt)),e.prop,{lw:1}),u([[-6,-50],[6,-50],[6,-40],[-6,-40]].map(pt=>Tt(D,pt)),e.propLabel,{lw:.9}),u([[-14,-4],[14,-4],[14,14],[-14,14]].map(pt=>Tt(D,pt)),e.propLabel,{line:!1}),u([[-9,-12],[-6,-12],[-6,22],[-9,22]].map(pt=>Tt(D,pt)),"#ffffff",{line:!1})):q==="phone"?(u([Tt(D,[-14,-26]),Tt(D,[14,-26]),Tt(D,[14,26]),Tt(D,[-14,26])],e.eye,{lw:1}),u([Tt(D,[-11,-21]),Tt(D,[11,-21]),Tt(D,[11,21]),Tt(D,[-11,21])],e.propLabel,{line:!1})):q==="card"?(u([Tt(D,[-26,-15]),Tt(D,[26,-15]),Tt(D,[26,15]),Tt(D,[-26,15])],e.prop,{lw:1}),u([Tt(D,[-20,-6]),Tt(D,[4,-6]),Tt(D,[4,0]),Tt(D,[-20,0])],e.propLabel,{line:!1})):(u([Tt(D,[-24,-22]),Tt(D,[24,-22]),Tt(D,[24,22]),Tt(D,[-24,22])],e.prop,{lw:1}),u([Tt(D,[-24,-22]),Tt(D,[24,-22]),Tt(D,[18,-30]),Tt(D,[-18,-30])],e.propS,{lw:.9}),u([Tt(D,[-24,-2]),Tt(D,[24,-2]),Tt(D,[24,8]),Tt(D,[-24,8])],e.propLabel,{line:!1}))},tt=Tt(o.hR,[o.sway,s]),rt=Tt(o.hL,[o.sway,s]);return _&&i&&o.shL==="hold"&&J(Tt(Qd(tt,rt,.5),[0,-6])),at($,rt,-1,o.shL,!0,!0),at(E,tt,1,o.shR,!1,!1),_&&i&&o.shL!=="hold"&&J(Tt(tt,[0,-30])),c}const ug=(t,e,o)=>{const r={};for(const a of new Set([...Object.keys(t),...Object.keys(e)])){const n=t[a],i=e[a];r[a]=i==null?n:n==null?i:Array.isArray(i)?Qd(n,i,o):typeof i=="number"?ms(n,i,o):o<.5?n:i}return r},dg=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 hg({character:t="host",colors:e=null,x:o=.5,ground:r=.95,size:a=.8,fps:n=24,actions:i=[],speech:c=null,W:u=1280,H:p=720}){const s=Ya[t];if(!s)throw Error(`animatePuppet presenter character: ${iA.join(" | ")}`);const h={...s.palette,...e||{}},f=a*p/aA,m=(Array.isArray(i)?i:[]).slice(0,40);if(!m.length)throw Error(`animatePuppet actions: [{move: ${cg.join(" | ")}, duration?, face?, side?, prop?}]`);let g=0;const v=m.map((k,y)=>{const C=Bb[k?.move];if(!C)throw Error(`animatePuppet actions[${y}].move (presenter): ${cg.join(" | ")}`);if(k.face!=null&&!sg.includes(k.face))throw Error(`animatePuppet actions[${y}].face: ${sg.join(" | ")}`);if(k.side!=null&&!["left","right"].includes(k.side))throw Error(`animatePuppet actions[${y}].side: left | right (which side the gesture goes to)`);if(k.prop!=null&&!lg.includes(k.prop))throw Error(`animatePuppet actions[${y}].prop: ${lg.join(" | ")}`);const A=Number.isFinite(k.duration)?Yi(k.duration,.3,20):C.dur,z={g:C,a:k,t0:g,dur:A,face:k.face??C.face,mirror:k.side==="left",prop:C.prop?{kind:k.prop??"box"}:null};return g+=A,z});v.forEach((k,y)=>{k.from=y?v[y-1].at(1,v[y-1].dur):Pe({}),k.at=(C,A)=>{let z;if(k.g.cyc)z=ug(k.from,k.mirror?dg(k.g.cyc(A)):k.g.cyc(A),Yi(A/.35,0,1));else{const j=k.g.keys.map(([U,at])=>[U,at?k.mirror?dg(at):at:k.from]);let P=0;for(;P<j.length-2&&C>j[P+1][0];)P++;const[F,N]=j[P],[G,V]=j[P+1],et=(k.g.ease?.[P]??Ri)(Yi((C-F)/(G-F),0,1));if(z=ug(N,V,et),k.g.wave&&C>.22){const U=Math.sin(A*13)*14;z=k.mirror?{...z,hL:[z.hL[0]-U,z.hL[1]]}:{...z,hR:[z.hR[0]+U,z.hR[1]]}}}return{...z,bounce:(z.bounce||0)+Math.sin(A*3)*.8}}});const x=pA(c),E=g,$=Math.min(Math.round(E*n),480),S=[];for(let k=0;k<$;k++){const y=k/n,C=v.find(et=>y<et.t0+et.dur-1e-9)??v.at(-1),A=y-C.t0,z=Yi(A/C.dur,0,1),j=C.at(z,A),P=(y+.7)%3.4,F=P<2/n&&C.face!=="wink"&&C.face!=="grin",N={expr:C.face,mouth:x(y),blink:F},G=[o*u,r*p],V=([et,U])=>[Math.round((G[0]+et*f)/u*1e4)/1e4,Math.round((G[1]+U*f)/p*1e4)/1e4];S.push({parts:uA(s,h,j,N,y,V,C.prop)})}return{frames:S,duration:$/n}}const Np=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 dA(t,e,o,r=Np){const a=[...t].filter(p=>p.time>e+1e-6&&p.time<o-1e-6).sort((p,s)=>p.time-s.time),n=[],i=(p,s,h,f)=>{s-p>1e-6&&n.push({from:p,to:s,kind:h,...f?{beat:f}:{}})},c=p=>{n.length&&(n[n.length-1].to=Math.max(n[n.length-1].to,p))};let u=e;for(let p=0;p<a.length;p++){const s=a[p],h=a[p+1],f=Math.max(u,s.time-r.cutBefore),m=h?h.time-r.cutBefore:o,g=s.result==="head"||s.result==="body";if(f-u>=r.minShot||!n.length?i(u,f,"wide"):c(f),u=Math.max(u,f),s.last&&g){const v=Math.min(u+r.insert,Math.max(u+r.minShot,o-r.hold));i(u,v,"insert",s),i(v,o,"finisher",s),u=o;break}if(g){let v=Math.min(u+r.insert,m);m-v<r.minShot&&(v=m),i(u,v,"insert",s);const x=Math.min(v+r.reaction,m);x-v>=r.minShot&&i(v,x,"reaction",s),u=Math.max(v,x)}else{const v=Math.min(u+r.insert+r.reaction,m);i(u,v,"reaction",s),u=v}}o-u>1e-6&&(o-u>=r.minShot||!n.length?i(u,o,"wide"):c(o));for(let p=n.length-1;p>0;p--)n[p].to-n[p].from<r.minShot-1e-6&&(n[p-1].to=n[p].to,n.splice(p,1));return n}function WT(t,e=[]){const o=t.map(i=>i.to-i.from).sort((i,c)=>i-c),r=t.length?t[t.length-1].to-t[0].from:0,a=t.filter(i=>i.kind==="insert"&&i.beat).map(i=>+(i.beat.time-i.from).toFixed(3)),n=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:+n.toFixed(2),longest:+(o[o.length-1]??0).toFixed(2),insertLead:a,beats:e.length}}const Xa=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]},qa=(t,e,o=1)=>[t[0]+e[0]*o,t[1]+e[1]*o,t[2]+e[2]*o],yp=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],fg=t=>Math.min(t.atk?.[1]??0,t.def?.[1]??0),mg=t=>Math.atan(18/t);function HT(t,e,o=Np){const r=Xa([e.side[0],0,e.side[2]]),a=Xa([e.axis[0],0,e.axis[2]]),n=[-a[0],0,-a[2]];if(t==="insert"){const f=o.lens.insert,m=(e.foot?o.insertWidthKick:o.insertWidth)/2/Math.tan(mg(f)),g=Xa(qa(r,a,o.insertAxis??.9)),v=[e.contact[0],e.contact[1],e.contact[2]],x=qa(v,g,m);return x[1]=Math.max(fg(e)+.15,e.contact[1]-.05),{position:x,target:v,lens:f}}if(t==="reaction"){const f=o.lens.reaction,m=[e.defHead[0],e.defHead[1]+.03,e.defHead[2]];let g=n;if(e.defFace){const $=Xa([e.defFace[0],0,e.defFace[2]]),S=$[0]*r[0]+$[2]*r[2],k=[$[0]-r[0]*S,0,$[2]-r[2]*S];Math.hypot(k[0],k[2])>.2&&(g=Xa(k)),g=[g[0]*(1+2.5*Math.max(0,-S)),0,g[2]*(1+2.5*Math.max(0,-S))]}const v=Xa(qa(r.map($=>$*o.reactionSide),g,o.reactionBack)),x=Math.hypot(o.reactionSide,o.reactionBack),E=qa(m,v,x);return E[1]=e.defHead[1]+.15,{position:E,target:m,lens:f}}const i=o.lens.finisher,c=fg(e),u=[(e.atk[0]+e.def[0])/2,c,(e.atk[2]+e.def[2])/2],p=Math.max(2.2,(e.sep+2)/2/Math.tan(mg(i))),s=[u[0],c+.8,u[2]],h=qa(s,r,p);return h[1]=c+.45,{position:h,target:s,lens:i}}function XT(t,e,o=Np.clearance,r=1.5){const a=Xa(yp(t.position,t.target)),n=Math.hypot(...yp(t.position,t.target));let i=0;for(let p=0;p<6;p++){const s=qa(t.target,a,n+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 c=qa(t.target,a,n+i);let u=1/0;for(const p of e)u=Math.min(u,Math.hypot(p[0]-c[0],p[1]-c[1],p[2]-c[2]));return{...t,position:c,backed:+i.toFixed(3),near:+u.toFixed(3)}}const UT=Object.freeze([.4,0,.9,-.4,-.8]);function YT(t,e,o,{radius:r=.13,margin:a=.05,skip:n=.06}={}){const i=yp(e,t),c=Math.hypot(...i),u=[i[0]/c,i[1]/c,i[2]/c];let p=0;for(const s of o){if(Math.hypot(s[0]-e[0],s[1]-e[1],s[2]-e[2])<n)continue;const h=yp(s,t),f=h[0]*u[0]+h[1]*u[1]+h[2]*u[2];if(f<.1||f>c-a)continue;Math.hypot(h[0]-u[0]*f,h[1]-u[1]*f,h[2]-u[2]*f)<r&&p++}return p}const Fn=(t,e,o)=>Math.max(e,Math.min(o,t)),hA=300,zu=Object.freeze(["jab","cross","combo","front-kick","roundhouse","flying-kick","thrust","smash","staff-spin","sweep","spin-kick","uppercut","slash","beam","energy-slash","whip","bolt"]),Pu=Object.freeze(["block","dodge","hit","knockdown","launched","roll","parry","ko","hurt"]),Zl=Object.freeze(["backflip","frontflip","cartwheel","roll","taunt","guard","teleport","approach","dash"]),bp=Object.freeze({fighters:4,beats:24}),Jl={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},fA={hurt:.014,ko:.02,hit:.011,knockdown:.018,launched:.02,block:.005,clash:.008,dodge:0,roll:0},mA={hurt:.08,ko:.12,hit:.07,knockdown:.1,launched:.12,block:.04,clash:.09,dodge:0,roll:0},gA={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]},gg=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"]}),yA=new Set(["slash","smash","thrust","parry"]);function bA(t,e){const o=e.length;if(!Array.isArray(t)||!t.length||t.length>bp.beats)throw Error(`animatePuppet beats: [{by 0–${o-1}, target?, attack ${zu.join("|")} | move ${Zl.join("|")}, react? ${Pu.join("|")}, pause?}] (1–${bp.beats})`);return t.map((r,a)=>{const n=`animatePuppet beats[${a}]`;if(!r||typeof r!="object")throw Error(`${n} must be an object`);const i=r.by??a%2;if(!(Number.isInteger(i)&&i>=0&&i<o))throw Error(`${n}.by: 0–${o-1} (which fighter of cast acts)`);const c=r.target??(i===0?1:0);if(!(Number.isInteger(c)&&c>=0&&c<o&&c!==i))throw Error(`${n}.target: another fighter of cast (0–${o-1})`);const u=r.pause??.15;if(!(Number.isFinite(u)&&u>=0&&u<=4))throw Error(`${n}.pause: s before the next beat, 0–4`);if(r.stop!=null&&!(Number.isFinite(r.stop)&&r.stop>=.03&&r.stop<=.9))throw Error(`${n}.stop: 0.03–0.9 (fraction of the frame width)`);if(r.move!=null&&r.attack==null){if(!Zl.includes(r.move))throw Error(`${n}.move: ${Zl.join(" | ")}`);return{by:i,target:c,move:r.move,pause:u,...r.stop!=null?{stop:r.stop}:{}}}if(!zu.includes(r.attack))throw Error(`${n}.attack: ${zu.join(" | ")} (or move: ${Zl.join(" | ")})`);if(Nr[r.attack]?.prop==="staff"&&!nd(e[i].character??"fighter"))throw Error(`${n}: ${r.attack} needs a fighter with a weapon (${Object.keys(ya).filter(nd).join(", ")})`);const p=r.react??"block";if(!Pu.includes(p))throw Error(`${n}.react: ${Pu.join(" | ")}`);return{by:i,target:c,attack:r.attack,react:p,pause:u}})}function wA({cast:t,beats:e,fps:o=12,fx:r=!0,accent:a="#ffd23f",W:n=1280,H:i=720,stick:c=!1,dust:u="#c9bfb2",tempo:p=null,camera:s=null,mocap:h=null,energyColor:f="#ff4fd8",toon:m=null,law:g=!0,maxFrames:v=480}){if(!Array.isArray(t)||t.length<2||t.length>bp.fighters)throw Error(`animatePuppet cast: 2–${bp.fighters} fighters for beats [{character, x?, facing?, …}, {…}]`);const x=t.length,E=t.map((Q,nt)=>Q.x??(nt?.64+(nt-1)*.12:.36)),$=Q=>E[Q===0?1:0]>=E[Q]?"right":"left",S=t.map((Q,nt)=>({character:Q.character??(nt?"brawler":"fighter"),x:E[nt],ground:Q.ground??.9,size:(Q.size??.5)*(Q.height??1),facing:Q.facing??$(nt),colors:Q.colors??null,grip:Q.grip??"guard",hair:Q.hair??null,eyes:Q.eyes??null,weight:Q.weight??null}));for(const Q of S)if(!ya[Q.character])throw Error(`animatePuppet cast character: ${Object.keys(ya).join(" | ")}`);const k=bA(e,S),y=S.map(Q=>Q.size*i/hA),C=Q=>Q.facing==="left"?-1:1,A=S.map(()=>[]),z=S.map(Q=>Q.x*n),j=S.map(()=>!1),P=S.map(()=>!1),F=[],N=[],G=[],V=Q=>c||ya[S[Q].character].look==="stick",et={},U=(Q,nt)=>{const dt=h?gg[Q]:null;if(dt&&!(yA.has(Q)&&S[nt].character&&ya[S[nt].character].prop!=="sword")){const xt=dt.filter(Et=>h[Et]);if(xt.length){const Et=et[Q]=(et[Q]??-1)+1,Ct=xt[Et%xt.length];return{...Rf(Ct,h),name:Q}}}const vt={ko:"knockdown",hurt:"hit",whip:"energy-slash",bolt:"beam"},It=Nr[Q]??Nr[vt[Q]];return It?{...It,name:Nr[Q]?Q:vt[Q]}:null},at=(Q,nt={})=>Q.mocap?{mocap:Q.mocap,...nt}:{move:Q.name,...nt},W=S.some((Q,nt)=>V(nt)),_=p??(W?1.35:1),J=Q=>Q.dur/_,tt=(Q,nt,dt)=>C(S[Q])*(dt??nt?.dx??0)*y[Q],rt=(Q,nt,dt,vt)=>{A[Q].push({...at(nt,dt),at:Math.round(vt*1e4)/1e4}),z[Q]+=tt(Q,nt,dt.dx)};let D=.3;const q=S.map(()=>.3);for(const Q of k){const nt=Q.by,dt=Q.target;if(P[nt])throw Error(`animatePuppet beats: fighter ${nt} was knocked out (ko) — it cannot act again`);for(const gt of[nt,dt])if(j[gt]&&!P[gt]){const bt=U(V(gt)?"kipup":"getup",gt);rt(gt,bt,{duration:J(bt)},Math.max(q[gt],D)),q[gt]=Math.max(q[gt],D)+J(bt),j[gt]=!1}if(D=Math.max(D,q[nt],q[dt]-.25),Q.move==="dash"){const gt=Q.stop!=null?Q.stop*n/y[nt]:Jl.jab*.85,bt=Math.abs(z[dt]-z[nt])/y[nt],St=Math.sign(z[dt]-z[nt])*C(S[nt])||1,Rt=St*Math.max(0,bt-gt),Dt={...Nr.dash,name:"dash"},Ft=J(Dt);rt(nt,Dt,{dx:Rt,duration:Ft},D),G.push({kind:"dash",t:D,dur:Ft,by:nt}),q[nt]=D+Ft,D=q[nt]+Q.pause;continue}if(Q.move==="approach"||Q.move==="teleport"){const gt=Q.stop!=null?Q.stop*n/y[nt]:Jl.jab*.95,bt=Math.abs(z[dt]-z[nt])/y[nt],St=Math.sign(z[dt]-z[nt])*C(S[nt])||1,Rt=St*Math.max(0,bt-gt);if(Q.move==="approach"){const Dt=Math.abs(Rt)>300,Ft=U(Dt?"run":"walk",nt);if(Ft?.mocap&&St>0){const se=Ft.dx||1,ce=Fn(Math.round(Math.abs(Rt)/se),1,8),Ut=Rf(Ft.mocap,h,0,ce),oe=Ut.dur*(Dt?1:1.05),ae=Math.max(q[nt],D-oe*.8-Q.pause);rt(nt,{...Ut,name:Ft.name},{dx:Rt,duration:oe,repeat:ce},ae),q[nt]=ae+oe,D=Math.max(D,q[nt]+Q.pause);continue}const Xt=Dt?Nr.run:Nr.walk,Zt=Fn(Math.abs(Rt)/(Xt.speed*(Dt?1.3:1.15)),.5,3.5),te=Math.max(q[nt],D-Zt*.8-Q.pause);rt(nt,{...Xt,name:Dt?"run":"walk"},{dx:Rt,distance:Rt*y[nt]/n,duration:Zt},te),q[nt]=te+Zt,D=Math.max(D,q[nt]+Q.pause);continue}else{const Dt={...Nr.teleport,name:"teleport"},Ft=J(Dt);rt(nt,Dt,{dx:Rt,duration:Ft},D),G.push({kind:"teleport",t:D,dur:Ft,by:nt}),q[nt]=D+Ft}D=q[nt]+Q.pause;continue}if(Q.move){const gt=U(Q.move,nt),bt=z[nt]+tt(nt,gt),St=Fn(bt,n*.08,n*.92),Rt=(gt.dx??0)*(bt===z[nt]?1:(St-z[nt])/(bt-z[nt]));rt(nt,gt,{dx:Rt,duration:J(gt)},D),q[nt]=D+J(gt),(gt.air||gt.mocap&&Q.move!=="guard"||Q.move==="roll")&&N.push({t:D+J(gt)*.97,by:nt}),D=q[nt]+Q.pause;continue}const vt=Q.attack==="beam"||Q.attack==="whip"||Q.attack==="bolt",It=["ko","knockdown","launched","hurt"].includes(Q.react)?.85:1,xt=Math.abs(z[dt]-z[nt])/y[nt],Et=vt?Math.min(xt,Jl[Q.attack]):Jl[Q.attack]*(V(nt)?.92:1)*It;if(Math.abs(xt-Et)>18&&Q.attack!=="flying-kick"&&!(vt&&xt>200)){const gt=Fn(xt-Et,-160,220),bt=U(gt>0?"step-in":"step-out",nt)??Nr.step,St=bt.mocap?Fn(bt.dur*.6,.35,.8)/_:Fn(.25+Math.abs(gt)/500,.3,.7)/_;rt(nt,bt.name?bt:{...Nr.step,name:"step"},{dx:gt,duration:St},D),D+=St}const Ct=U(Q.attack,nt),Gt=J(Ct),ee=Q.attack==="flying-kick"?Fn(xt-150,60,260):void 0;rt(nt,Ct,{...ee!=null?{dx:ee}:{},duration:Gt},D);const re=(Ct.hits??[.5]).map(gt=>D+gt*Gt),Me=Ct.limbs??(Ct.hits??[.5]).map(()=>Ct.mlimb??Ct.limb??(Ct.prop==="staff"?"staff":"fist"));["beam","energy-slash","whip","bolt"].includes(Q.attack)&&G.push({kind:Q.attack,t:D,dur:Gt,hit:re[0],by:nt,target:dt,limb:Me[0],react:Q.react});const qt=U(Q.react,dt)??Nr[Q.react],Nt=re[0],_t=re.at(-1),Vt=Math.max(J(qt),_t-Nt+.45/_),he=Math.max(q[dt],Nt-(qt.peak??.3)*Vt),ne=Q.react==="parry"&&!nd(S[dt].character)?"block":Q.react,be=ne===Q.react?qt:U(ne,dt),ir=ne==="knockdown"||ne==="launched"||ne==="ko"||ne==="hurt"?.06:.08,zr=z[dt]+tt(dt,be),Ur=Fn(zr,n*ir,n*(1-ir)),No=(be.dx??0)*(zr===z[dt]?1:(Ur-z[dt])/(zr-z[dt]));rt(dt,be,{duration:ne===Q.react?Vt:Math.max(J(be),Vt),dx:No,...["ko","knockdown","launched"].includes(ne)?{still:!0}:{}},he),(ne==="knockdown"||ne==="launched"||ne==="ko")&&(j[dt]=!0,N.push({t:he+Vt*.97,by:dt})),ne==="ko"&&(P[dt]=!0),ne==="roll"&&N.push({t:he+Vt*.9,by:dt}),Q.attack==="sweep"&&N.push({t:re[0],by:nt,at:"foot"});const ro=gt=>ne==="dodge"||ne==="roll"?"dodge":ne==="block"?"block":ne==="parry"?"clash":gt===re.length-1?ne:"hit";re.forEach((gt,bt)=>F.push({t:gt,by:nt,target:dt,attack:Q.attack,j:bt,limb:Me[bt],kind:ro(bt)})),q[nt]=D+Gt,q[dt]=he+Vt,D=Math.max(q[nt],q[dt])+Q.pause;const So=(z[0]+z[1])/2,X=n/2-So;if(x===2&&Math.abs(X)>n*.1){const gt=.45/_;for(const bt of[0,1])j[bt]||rt(bt,{...Nr.step,name:"step"},{dx:X*C(S[bt])/y[bt],duration:gt},D);q[0]=q[1]=D+gt,D+=gt}}const pt=Math.max(...q)+.6,yt=W&&r?F.map(Q=>({t:Q.t,h:mA[Q.kind]??0})).filter(Q=>Q.h>0).sort((Q,nt)=>Q.t-nt.t):[],Mt=Q=>Q+yt.filter(nt=>nt.t<Q-1e-9).reduce((nt,dt)=>nt+dt.h,0),l=Q=>{const nt=Q/o;let dt=0;for(const vt of yt){const It=vt.t+dt;if(nt<It)return nt-dt;if(nt<It+vt.h)return vt.t;dt+=vt.h}return nt-dt},lt=Math.min(v,Math.round((pt+yt.reduce((Q,nt)=>Q+nt.h,0))*o));for(const Q of F)Q.real=Mt(Q.t);const K=Q=>{const nt=Q/o;let dt=0,vt=0;for(const It of F){const xt=(nt-It.real)/.3,Et=r?fA[It.kind]??0:0;if(xt>=0&&xt<1&&Et){const Ct=(Math.round(xt*o*.3)%2?-1:1)*Et*(1-xt);dt+=Ct,vt+=Ct*.6}}return[dt,vt*n/i]},d=Q=>{if(!h)return null;const nt=t[Q].idle??(S[Q].character==="stick-hero"?"guard":"relaxed");return nt==="none"?null:nt==="relaxed"?"relaxed":gg.guard.find(dt=>h[dt])??null};A.forEach(Q=>{Q.length||Q.push({move:"guard",at:0,duration:.3})});const w=S.map((Q,nt)=>{const dt=d(nt);return I1({...Q,size:Q.size,fps:o,actions:A[nt],W:n,H:i,shake:K,total:pt,stick:V(nt),clock:{n:lt,at:l},mocap:h,toon:m,law:g,maxFrames:v,...dt?{idle:dt}:{}})}),T=MA(w,F,{fps:o}),I=w.map(Q=>({track:Q}));for(const Q of F){const nt=Math.min(w[Q.by].frames.length-1,Math.round(Q.real*o)),dt=w[Q.by].frames[nt],vt=dt?Df(dt.J,Q.limb)??dt.J.haF:null;Q.at=vt?Qi(w[Q.by],nt,vt):null}const O=Q=>Q.frames.map((nt,dt)=>{const vt={};for(const It of["fist","back","foot","staff","head","chest",...Object.keys(nt.J.sides??{})]){const xt=Df(nt.J,It);xt&&(vt[It]=Qi(Q,dt,xt))}return vt});I.forEach((Q,nt)=>{Q.ends=O(w[nt]),Q.frames=w[nt].frames});const L=r?F.filter(Q=>Q.at&&Q.kind!=="dodge").map(Q=>({start:Math.round(Q.real*o)/o,frames:SA(Q,{fps:o,accent:a,W:n,H:i,size:S[Q.by].size})})):[],B=r?N.map(Q=>{const nt=Math.min(I[Q.by].ends.length-1,Math.round(Mt(Q.t)*o)),dt=I[Q.by].ends[nt],vt=S[Q.by].ground,It=w[Q.by].frames[nt],xt=Q.at==="foot"&&dt?.foot?dt.foot[0]:It?Qi(w[Q.by],nt,[(It.J.anF[0]+It.J.anB[0])/2,0])[0]:S[Q.by].x;return{start:Math.round(Mt(Q.t)*o)/o,frames:IA(xt,vt,{fps:o,W:n,H:i,size:S[Q.by].size,color:u})}}):[],Z=[...r?G.map(Q=>EA(Q,{actors:I,fps:o,W:n,H:i,realOf:Mt,color:f,size:S[Q.by].size})).filter(Boolean):[],...L,...B],ot=s??(W?"follow":"fixed"),st=Math.max(...S.map(Q=>Q.ground)),Y=ot==="follow"||ot==="director"?kA(w,F,{fps:o,W:n,H:i,n:lt,fx:r,ground:st}):null,ct=ot==="director"?vA(Y,w,F,{fps:o,n:lt,ground:st}):Y;if(ct){for(const Q of w)Q.cam=ct;for(const Q of Z){const nt=Math.round(Q.start*o);Q.frames=Q.frames.map((dt,vt)=>$A(dt,ct[Math.min(nt+vt,ct.length-1)],n,i))}}I.forEach((Q,nt)=>{Q.frames=o3(w[nt]).frames});const mt=w.map((Q,nt)=>r3(Q,T[nt],`fighter ${nt}: `));return{actors:I,fx:Z,impacts:F.map(({real:Q,kind:nt,at:dt})=>({t:Math.round(Q*100)/100,kind:nt,at:dt})),duration:lt/o,camera:ct,tracks:w,reports:mt}}function kA(t,e,{fps:o,W:r,H:a,n,fx:i,ground:c}){const u=k=>{let y=1/0,C=1/0,A=-1/0,z=-1/0;for(const j of t){const P=Math.min(k,j.frames.length-1),F=j.frames[P];if(!F)continue;const N=F.J,G=26*j.k/j.H,V=[N.head,N.neck,N.pelvis,N.haF,N.haB,N.anF,N.anB,N.knF,N.knB,...N.weapon?[N.weapon.a,N.weapon.b]:[]];for(const et of V){if(!et)continue;const U=Qi(j,P,et);y=Math.min(y,U[0]-G*j.H/j.W),A=Math.max(A,U[0]+G*j.H/j.W),C=Math.min(C,U[1]-G),z=Math.max(z,U[1]+G*.4)}}return Number.isFinite(y)?[y,C,A,z]:[.3,.3,.7,.9]},p=k=>{const[y,C,A,z]=u(k),j=A-y+.08,P=z-C+.08,F=Fn(Math.min(.74/j,.72/P),1,1.8);return[(y+A)/2,Math.min((C+z)/2,c-.32/F),F]};let[s,h,f]=p(0),m=0,g=0,v=0;const x=[],E=1/o,$=6.5,S=3.2;for(let k=0;k<n;k++){const[y,C,A]=p(k);for(let F=0;F<2;F++){const N=E/2;m+=($*$*(y-s)-2*$*m)*N,s+=m*N,g+=($*$*(C-h)-2*$*g)*N,h+=g*N,v+=(S*S*(A-f)-2*S*v)*N,f+=v*N}let z=0,j=0;i&&e.forEach((F,N)=>{const G=(k/o-F.real)/.45;if(G<0||G>=1)return;const[V,et]=gA[F.kind]??[0,0];z+=V*(1-G)**2,j+=(N%2?-1:1)*et*Math.sin(Math.PI*Math.min(1,G*1.6))*(1-G)});const P=Math.min(2,f*(1+z));x.push({cx:Math.round(s*1e4)/1e4,cy:Math.round(h*1e4)/1e4,z:Math.round(P*1e4)/1e4,r:Math.round(j*100)/100})}return x}const xA={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 MA(t,e,{fps:o}){const r=t.map(()=>[]),a=Hp.reach.window;for(const n of e){const i=xA[n.attack];if(!i||n.kind==="dodge")continue;const c=t[n.by],u=t[n.target];if(!c||!u)continue;const p=n.kind==="block"||n.kind==="clash"?"guard":Array.isArray(i)?i[n.j%i.length]:i,s=j=>P=>{const F=u.frames[Math.min(P,u.frames.length-1)].J,N=j==="guard"?F.haF:j==="shin"?Mc(F.knF,F.anF,.6):j==="chest"?Mc(F.neck,F.pelvis,.3):j==="belly"?Mc(F.neck,F.pelvis,.7):F.head;return Qi(u,Math.min(P,u.frames.length-1),N)},h=Math.min(c.frames.length-1,Math.round(n.real*o)),f=c.frames[h].J,m=n3(f,n.limb),g=Object.values(a3).find(j=>j[2]===m),v=g?f[g[0]]:m==="weapon"?f.weapon.grip:f.pelvis,x=i3(f,n.limb)*Hp.reach.stretch*.97,E=j=>{const P=Xp(c,h,j(h)),F=P[0]-v[0],N=P[1]-v[1];if(Math.hypot(F,N)<=x)return{lunge:0,left:0};const G=Math.abs(N)<x?Math.abs(F)-Math.sqrt(x*x-N*N):Math.abs(F),V=Math.min(Hp.reach.glide,Math.max(0,G));return{lunge:Math.sign(F)*V,left:Math.max(0,Math.hypot(Math.abs(F)-V,N)-x)}},$=p==="guard"||p==="shin"?[p]:p==="head"?["head","chest","belly"]:[p,"belly"];let S=$[0],k=1/0;for(const j of $){const P=E(s(j));if(P.left<=1){S=j;break}P.left<k&&(k=P.left,S=j)}const y=s(S),C=E(y).lunge;for(let j=0;j<c.frames.length;j++){const P=c.frames[j],F=P.tt-n.t;if(F<-.3||F>.5)continue;let N=P.J;if(C){const V=F<=0?Bf((F+.25)/.25):1-Bf((F-.1)/.35);if(V>0){const et={};for(const[U,at]of Object.entries(N)){if(U==="sides"){et.sides=at;continue}if(U==="weapon"){et.weapon={...at,a:[at.a[0]+C*V,at.a[1]],b:[at.b[0]+C*V,at.b[1]],grip:[at.grip[0]+C*V,at.grip[1]]};continue}et[U]=[at[0]+C*V,at[1]]}N=s3(et,N,{planted:l3(N)})}}const G=c3(F,a);G>0&&(N=p3(N,n.limb,Xp(c,j,y(j)),G)),P.J=N}const A=u3(c.frames[h].J,n.limb),z=Xp(c,h,y(h));r[n.by].push({t:n.real,limb:n.limb,miss:A?Math.hypot(A[0]-z[0],A[1]-z[1])/300:1})}return r}const Mc=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o];function vA(t,e,o,{fps:r,n:a,ground:n}){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)})),c=dA(i,0,a/r,Np),u=[],p=(s,h,f)=>{const m=e[s],g=Math.min(h,m.frames.length-1),v=m.frames[g].J;return Qi(m,g,Mc(v.neck,v.pelvis,.35))};for(let s=0;s<a;s++){const h=s/r,f=c.find($=>h>=$.from-1e-9&&h<$.to)??c.at(-1),m=t[Math.min(s,t.length-1)];if(!f||f.kind==="wide"||!f.beat){u.push(m);continue}const g=f.beat.im,v=Math.round(f.from*r),x=(s-v)/Math.max(1,Math.round((f.to-f.from)*r));let E;if(f.kind==="insert"){const $=g.at??p(g.target,v);E={cx:$[0],cy:Math.min($[1],n-.2),z:2.3*(1+.04*x),r:m.r}}else if(f.kind==="reaction"){const $=p(g.target,v);E={cx:$[0],cy:Math.min($[1],n-.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,n-.3),r:0};u.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 u}function yg(t,e,o,r){const a=e.r*Math.PI/180,n=Math.cos(a),i=Math.sin(a),c=(t[0]-e.cx)*o,u=(t[1]-e.cy)*r;return[Math.round((.5+(c*n-u*i)*e.z/o)*1e4)/1e4,Math.round((.5+(c*i+u*n)*e.z/r)*1e4)/1e4]}function $A(t,e,o,r){return{...t,parts:t.parts.map(a=>a.loops?{...a,loops:a.loops.map(n=>n.map(i=>yg(i,e,o,r)))}:a.points?{...a,points:a.points.map(n=>yg(n,e,o,r))}:a)}}const ns=(t,e,o,r,a=14)=>Array.from({length:a},(n,i)=>{const c=i/a*2*Math.PI;return[t[0]+Math.cos(c)*e*r/o,t[1]+Math.sin(c)*e]});function mn(t,e,o,r,a,n=1){const i=[],c=u=>Math.max(.02,Math.round(Math.min(1,u)*100)/100);for(const[u,p]of[[3.2,.08],[2.2,.14],[1.5,.24]])i.push({points:ns(t,e*u,r,a),fill:o,line:!1,opacity:c(p*n)});return i.push({points:ns(t,e,r,a),fill:o,line:!1,...n<1?{opacity:c(n)}:{}},{points:ns(t,e*.55,r,a,10),fill:"#ffffff",line:!1,...n<1?{opacity:c(n)}:{}}),i}function bg(t,e,o,r,a,n){const i=e[0]-t[0],c=(e[1]-t[1])*n/a,u=Math.hypot(i,c)||1,p=-c/u,s=i/u,h=(f,m,g)=>{const v=o*f;return{points:[[t[0]+p*v*n/a,t[1]+s*v],[e[0]+p*v*n/a,e[1]+s*v],[e[0]-p*v*n/a,e[1]-s*v],[t[0]-p*v*n/a,t[1]-s*v]],fill:m,line:!1,smooth:!1,...g<1?{opacity:g}:{}}};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 EA(t,{actors:e,fps:o,W:r,H:a,realOf:n,color:i,size:c}){const u=(f,m,g)=>{const v=e[f].ends,x=v[Math.max(0,Math.min(v.length-1,m))];return x?.[g]??x?.fist??null},p=c*.06,s=[],h=(f,m=Math.round(o*.55))=>{const g=[];for(let v=0;v<=m;v++){const x=f+v,E=v/m,$=u(t.target,x,"chest")||u(t.target,x,"head");if(!$){g.push({parts:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]});continue}const S=[];E<.25&&S.push(...mn($,p*(2.6-E*4),"#ffffff",r,a,1-E*3)),S.push(...mn($,p*(1.2+E*1.4),i,r,a,(1-E)*.9));const k=p*(1.2+E*5),y=k-p*.5*(1-E);S.push({points:[...ns($,k,r,a,24),...ns($,y,r,a,24).reverse()],fill:i,line:!1,eo:!0,opacity:Math.max(.02,Math.round((1-E)*.8*100)/100)});for(let C=0;C<7;C++){const A=C*2.4+.6,z=p*(1.5+E*6)*(.7+.3*Math.sin(C*3.7)),j=[$[0]+Math.cos(A)*z*a/r,$[1]+Math.sin(A)*z];S.push({points:ns(j,p*.18*(1-E*.6),r,a,6),fill:"#1a1a1a",line:!1,...E>.6?{opacity:Math.max(.02,Math.round((1-E)*2.5*100)/100)}:{}})}g.push({parts:S})}return g};if(t.kind==="beam"){const f=Math.round(n(t.t+t.dur*.12)*o),m=Math.round(n(t.hit)*o),g=m+Math.round(o*.45);for(let x=f;x<=g;x++){const E=u(t.by,x,t.limb)||u(t.by,x,"back"),$=u(t.target,x,"head")||u(t.target,x,"chest"),S=[];if(E){if(x<m){const k=(x-f)/Math.max(1,m-f);S.push(...mn(E,p*(.4+k*1.1),i,r,a,.6+k))}else{const k=(x-m)/Math.max(1,g-m),y=1-Math.max(0,k-.6)/.4,C=1+.25*Math.sin(x*2.3);$&&S.push(...bg(E,$,p*.55*C*y,i,r,a)),S.push(...mn(E,p*1.2*y,i,r,a,y)),$&&S.push(...mn($,p*(1.4+k*.8)*y,i,r,a,y))}s.push({parts:S})}}const v=h(m);for(let x=0;x<v.length;x++){const E=m-f+x;s[E]?s[E]={parts:[...s[E].parts,...v[x].parts]}:s.push(v[x])}return s.length?{start:Math.round(f)/o,frames:s}:null}if(t.kind==="energy-slash"){const f=Math.round(n(t.hit-.22)*o),m=Math.round(n(t.hit+.06)*o),g=m+Math.round(o*.3),v=[];for(let x=f;x<=m;x++){const E=u(t.by,x,t.limb);E&&v.push(E)}if(v.length<3)return null;for(let x=f;x<=g;x++){const E=Math.min(v.length,x-f+1),$=v.slice(0,E),S=x>m?1-(x-m)/(g-m+1):1,k=[];if($.length>=2)for(const[y,C,A]of[[2.4,.18,i],[1.4,.4,i],[.7,1,i],[.28,1,"#ffffff"]]){const z=[],j=[],P=$.length-1;$.forEach((F,N)=>{const G=$[Math.max(0,N-1)],V=$[Math.min(P,N+1)],et=V[0]-G[0],U=(V[1]-G[1])*a/r,at=Math.hypot(et,U)||1,W=p*y*Math.sin(Math.PI*Math.min(1,(N+.5)/(P+.5)));z.push([F[0]-U/at*W*a/r,F[1]+et/at*W]),j.push([F[0]+U/at*W*a/r,F[1]-et/at*W])}),k.push({points:[...z,...j.reverse()],fill:A,line:!1,opacity:Math.max(.02,Math.round(C*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(n(t.hit-.2)*o),m=Math.round(n(t.hit)*o),g=m+Math.round(o*.3);for(let x=f;x<=g;x++){const E=u(t.by,x,"chest"),$=u(t.target,x,"chest"),S=[];if(E&&$){const k=x<=m?(x-f)/Math.max(1,m-f):1-(x-m)/Math.max(1,g-m);for(let y=0;y<3;y++){const C=[-.9,.5,1.3][y],A=Math.hypot(($[0]-E[0])*r/a,$[1]-E[1]),z=[(E[0]+$[0])/2,(E[1]+$[1])/2-C*A*.22],j=16,P=[];for(let F=0;F<=j*k;F++){const N=F/j,G=1-N;P.push([G*G*E[0]+2*G*N*z[0]+N*N*$[0],G*G*E[1]+2*G*N*z[1]+N*N*$[1]+Math.sin(N*9+x*.7+y)*p*.15])}if(!(P.length<3)){for(const[F,N,G]of[[2,.16,i],[1.1,.45,i],[.5,1,i]]){const V=[],et=[],U=P.length-1;P.forEach((at,W)=>{const _=P[Math.max(0,W-1)],J=P[Math.min(U,W+1)],tt=J[0]-_[0],rt=(J[1]-_[1])*a/r,D=Math.hypot(tt,rt)||1,q=p*F*(.35+.65*W/U);V.push([at[0]-rt/D*q*a/r,at[1]+tt/D*q]),et.push([at[0]+rt/D*q*a/r,at[1]-tt/D*q])}),S.push({points:[...V,...et.reverse()],fill:G,line:!1,...N<1?{opacity:N}:{}})}S.push(...mn(P.at(-1),p*.55,i,r,a,1.2))}}}s.push({parts:S.length?S:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}const v=h(m);for(let x=0;x<v.length;x++){const E=m-f+x;s[E]?s[E]={parts:[...s[E].parts,...v[x].parts]}:s.push(v[x])}return{start:f/o,frames:s}}if(t.kind==="bolt"){const f=Math.round(n(t.hit-.32)*o),m=Math.round(n(t.hit)*o);for(let g=f;g<m;g++){const v=u(t.by,f,t.limb)||u(t.by,f,"chest"),x=u(t.target,m,"chest"),E=[];if(v&&x){const $=(g-f)/Math.max(1,m-f),S=[v[0]+(x[0]-v[0])*$,v[1]+(x[1]-v[1])*$],k=Math.max(0,$-.45);for(const y of[0,Math.PI]){const C=[];for(let z=0;z<=14;z++){const j=k+($-k)*z/14,P=[v[0]+(x[0]-v[0])*j,v[1]+(x[1]-v[1])*j],F=Math.sin(j*22+y+g*.4)*p*.5*(z/14);C.push([P[0],P[1]+F])}for(const[z,j,P]of[[1,.3,i],[.4,1,i],[.15,1,"#ffffff"]]){const F=[],N=[],G=C.length-1;C.forEach((V,et)=>{const U=C[Math.max(0,et-1)],at=C[Math.min(G,et+1)],W=at[0]-U[0],_=(at[1]-U[1])*a/r,J=Math.hypot(W,_)||1,tt=p*z*(.2+.8*et/G);F.push([V[0]-_/J*tt*a/r,V[1]+W/J*tt]),N.push([V[0]+_/J*tt*a/r,V[1]-W/J*tt])}),E.push({points:[...F,...N.reverse()],fill:P,line:!1,...j<1?{opacity:j}:{}})}}E.push(...mn(S,p*.9,i,r,a,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(n(t.t)*o),m=Math.round(n(t.t+t.dur)*o),g=m+Math.round(o*.35),v=u(t.by,f,"chest");for(let x=f;x<=g;x++){const E=u(t.by,Math.min(x,m),"chest"),$=[];if(v&&E){const S=x>m?1-(x-m)/(g-m+1):1,k=[v[0]+(E[0]-v[0])*Math.max(0,(x-m)/(g-m+1)),v[1]];$.push(...bg(k,E,p*1.5*S,i,r,a).map((y,C)=>C===4?{...y,fill:"#f3dcff"}:y)),$.push(...mn(E,p*1.6*S,i,r,a,S))}s.push({parts:$.length?$:[{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(n(t.t)*o),m=Math.round(n(t.t+t.dur*.5)*o),g=m+Math.round(o*.3),v=u(t.by,f,"chest"),x=u(t.by,Math.min(g,m+2),"chest");for(let E=f;E<=g;E++){const $=[],S=(E-f)/Math.max(1,m-f),k=(E-m)/Math.max(1,g-m);v&&E<=m+3&&$.push(...mn(v,p*(1+S*2.2)*(E>m?.5:1),i,r,a,1-Math.max(0,S-.7))),x&&E>=m-1&&$.push(...mn(x,p*(2.6-k*1.8),i,r,a,1-k*.8)),s.push({parts:$.length?$:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:s}}return null}function SA(t,{fps:e,accent:o,W:r,H:a,size:n}){const i=Math.max(3,Math.round(e*.25)),[c,u]=t.at,p=n*.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,g=(x,E)=>[c+Math.cos(E)*x*a/r,u+Math.sin(E)*x],v=[];for(let x=0;x<i;x++){const E=x/(i-1),$=p*(.55+E*.9),S=[],k=s?8:12;if(x<i-1){const y=[];for(let C=0;C<k*2;C++){const A=C/(k*2)*2*Math.PI+(C%4===1?.08:0);y.push(g(C%2?$*.38:$*(C%3===0?1.1:.85),A))}S.push({points:y,fill:m,line:!1}),S.push({points:Array.from({length:10},(C,A)=>g($*.28,A/10*2*Math.PI)),fill:f,line:!1})}for(let y=0;y<8;y++){const C=y/8*2*Math.PI+.2;S.push({points:[g($*(.9+E*.5),C),g($*(1.3+E*.9),C)],fill:null,closed:!1,lw:Math.max(.3,1.4-E)})}v.push({parts:S})}return v}function IA(t,e,{fps:o,W:r,H:a,size:n,color:i}){const c=Math.max(3,Math.round(o*.4)),u=n*.05,p=[];for(let s=0;s<c;s++){const h=s/(c-1),f=[];for(const[m,g]of[[-1,1],[-.45,1.25],[.45,1.25],[1,1]]){const v=u*g*(1-h*.65),x=t+m*u*(1.4+h*2.6)*a/r,E=e-v*.7-h*u*.5;f.push({points:Array.from({length:10},($,S)=>{const k=S/10*2*Math.PI;return[x+Math.cos(k)*v*a/r,E+Math.sin(k)*v*.75]}),fill:i,line:!1})}p.push({parts:f})}return p}const Ql=t=>Math.round(t*10)/10,Lu=(t,e,o,r,a,n,i=0)=>{const c=[];for(let u=0;u<=a*3;u++){const p=u/(a*3),s=t+(e-t)*p,h=o-r*(.55+.45*Math.sin(p*a*2*Math.PI+i)*Math.cos(p*a*.7*Math.PI+i*2));c.push([s,h])}return[...c,[e,n],[t,n]]},Fu=(t,e,o,r=9,a=1)=>Array.from({length:r},(n,i)=>{const c=i/r*2*Math.PI,u=1+.18*Math.sin(i*2.7+a);return[t[0]+Math.cos(c)*e*u,t[1]+Math.sin(c)*o*u*(Math.sin(c)>0?.55:1)]}),$r=(t,e,o,r)=>[[t,e],[o,e],[o,r],[t,r]],_b=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:Fu([e,.36+o%2*.06],.26,.11,10,o),fill:o%2?"#d8b4dc":"#c69fd3"})),{pts:Lu(-1.2,2.2,t-.2,.22,7,t+.1,.4),fill:"#b48ac8"}]},{p:.5,parts:[{pts:Lu(-1.3,2.3,t-.06,.12,5,t+.12,1.3),fill:"#8f2f2c"},{pts:Lu(-1.3,2.3,t-.03,.05,9,t+.12,2.1),fill:"#a8413a"}]},{p:1,parts:[{pts:$r(-1.6,t,2.6,t+.9),fill:"#4e3423",smooth:!1},{pts:$r(-1.6,t-.004,2.6,t+.022),fill:"#d9c6a8",smooth:!1},{pts:Fu([.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:$r(e-.035,-.4,e+.035,t),fill:"#6b4423",smooth:!1})),{pts:$r(-1.5,.08,2.5,.12),fill:"#5a381c",smooth:!1},...[-.85,-.35,.15,.65,1.15,1.65].map(e=>({pts:$r(e-.17,.2,e+.17,t-.08),fill:"#f3ead6",smooth:!1}))]},{p:1,parts:[{pts:$r(-1.6,t,2.6,t+.9),fill:"#a8743f",smooth:!1},...[0,1,2,3].map(e=>({pts:$r(-1.6,t+.03+e*.05,2.6,t+.034+e*.05),fill:"#8c5d30",smooth:!1})),{pts:$r(-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:Fu([.78,.2],.05,.09,14,0),fill:"#f3efd2"}]},{p:.25,parts:[...Array.from({length:14},(e,o)=>{const r=-1.1+o*.24,a=.18+.14*(o*7%5)/4;return{pts:$r(r,t-.08-a,r+.2,t),fill:"#141a36",smooth:!1}})]},{p:.55,parts:[...Array.from({length:9},(e,o)=>{const r=-1.2+o*.42,a=.12+.1*(o*3%4)/3;return{pts:$r(r,t-.02-a,r+.3,t),fill:"#1d2547",smooth:!1}}),...Array.from({length:18},(e,o)=>{const r=-1.12+o*.21,a=t-.1-.05*(o%3);return{pts:$r(r,a,r+.025,a+.03),fill:"#e8c66a",smooth:!1}})]},{p:1,parts:[{pts:$r(-1.6,t,2.6,t+.9),fill:"#10142a",smooth:!1},{pts:$r(-1.6,t-.006,2.6,t+.01),fill:"#3a4470",smooth:!1}]}]}}),th=Object.freeze(Object.keys(_b));function AA(t,{size:e,camera:o,fps:r,duration:a,ground:n=.9,finish:i,en:c=!1}){const u=_b[t];if(!u)throw Error(`animatePuppet scene: ${th.join(" | ")}`);const p=on(e),s=p.pt([.5,.5]),h=p.k,f=u.layers(n).map((y,C)=>{const A=y.parts.map(z=>{const j=z.pts.map(P=>{const F=p.pt(P);return[F[0]-s[0],F[1]-s[1]]});return{d:z.smooth===!1?"M"+j.map(P=>`${Math.round(P[0])} ${Math.round(P[1])}`).join(" L")+" Z":ps(j,!0),fill:z.fill,line:!1,role:7}});return{p:y.p,it:{id:`d${C+1}`,name:`${c?"Depth":"Lớp"} ${C+1}`,type:"art",params:{parts:A,box:mr(A.map(z=>z.d).join(" ")),outline:!1},pos:[s[0],s[1]],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:A[0].fill},stroke:null,role:7}}}),[m,g]=e,v={id:"sky",name:c?"Sky":"Bầu trời",type:"rect",params:{w:Ql(m/h*1.6),h:Ql(g/h*1.6),round:0},pos:[s[0],s[1]],rot:0,scale:[1,1],opacity:1,fill:{type:"linear",stops:[[u.sky[0],0],[u.sky[1],1]],angle:90},stroke:null},x=(y,C)=>{const A=1+(C.z-1)*y,z=C.r*Math.PI/180,j=Math.cos(z),P=Math.sin(z),F=p.pt([.5+(C.cx-.5)*y,.5+(C.cy-.5)*y]),N=s[0]-F[0],G=s[1]-F[1];return{x:Ql(s[0]+(N*j-G*P)*A),y:Ql(s[1]+(N*P+G*j)*A),z:Math.round(A*1e4)/1e4,r:Math.round(C.r*100)/100}},E=`${c?"Scene":"Cảnh nền"} · ${c?u.en:u.vi}`;if(!o?.length){const y=f.map(({p:C,it:A})=>({...A,...(()=>{const z=x(C,{cx:.5,cy:.5,z:1,r:0});return{pos:[z.x,z.y]}})()}));return[{shape:i({v:2,size:e,items:[v,...y]},null,{colors:"keep"}),label:E,start:0,duration:a}]}const $=[],S=o.length,k=Math.max(1,Math.round(6*r));for(let y=0;y<S;y+=k){const C=Math.min(S,y+k),A=y/r,z=(C-y)/r,j=Math.min(60,C-y-1)||1,P=[...new Set(Array.from({length:j+1},(N,G)=>Math.min(C-1,y+Math.round(G*(C-1-y)/j))))],F=f.map(({p:N,it:G})=>{const V=P.map(U=>({t:Math.round((U-y)/r*1e4)/1e4,q:x(N,o[U])})),et=U=>V.map(({t:at,q:W},_)=>({time:at,value:U(W),..._<V.length-1?{ease:"auto"}:{}}));return{...G,pos:[V[0].q.x,V[0].q.y],scale:[V[0].q.z,V[0].q.z],rot:V[0].q.r,keys:{"pos.0":et(U=>U.x),"pos.1":et(U=>U.y),"scale.0":et(U=>U.z),"scale.1":et(U=>U.z),rot:et(U=>U.r)}}});$.push({shape:i({v:2,size:e,items:[v,...F]},null,{colors:"keep"}),label:E,start:A,duration:z})}return $}const tc=/^#[0-9a-fA-F]{6}$/,Rs=Number.isFinite,CA=t=>[1,3,5].map(e=>parseInt(t.slice(e,e+2),16)),jA=t=>"#"+t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join(""),Rr=(t,e)=>jA(CA(t).map(o=>e>=0?o+(255-o)*e:o*(1+e))),wg=Object.freeze(["box","stairs","cylinder","plane","panel"]),wp=Object.freeze({iso:[Math.cos(Math.PI/6),.5],dimetric:[2/Math.sqrt(5),1/Math.sqrt(5)]}),Js=Object.freeze({solids:24,steps:24,size:[.002,2]}),Qs=t=>Math.round(t),TA=(t,e=!0)=>"M"+t.map(o=>`${Qs(o[0])} ${Qs(o[1])}`).join(" L")+(e?" Z":"");function OA(t){const e=[...t].sort((n,i)=>n[0]-i[0]||n[1]-i[1]),o=(n,i,c)=>(i[0]-n[0])*(c[1]-n[1])-(i[1]-n[1])*(c[0]-n[0]),r=[],a=[];for(const n of e){for(;r.length>=2&&o(r.at(-2),r.at(-1),n)<=0;)r.pop();r.push(n)}for(const n of e.reverse()){for(;a.length>=2&&o(a.at(-2),a.at(-1),n)<=0;)a.pop();a.push(n)}return r.slice(0,-1).concat(a.slice(0,-1))}function zA(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(!wg.includes(r))throw Error(`${o}.kind: ${wg.join(" | ")}`);if(!Array.isArray(t.at)||t.at.length!==2||!t.at.every(u=>Rs(u)&&u>=-.5&&u<=1.5))throw Error(`${o}.at: [x, y] of its base centre on the ground, 0..1 of the frame`);const[a,n]=Js.size;if(!Array.isArray(t.size)||t.size.length!==3||!t.size.every((u,p)=>Rs(u)&&u<=n&&(u>=a||p===2&&r==="plane"&&u>=0||p===1&&r==="panel"&&u>=0)))throw Error(`${o}.size: [w, d, h] as fractions of the frame width (${a}–${n}; a plane's h and a panel's d may be 0)`);if(t.z!=null&&!(Rs(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(!tc.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(([u,p])=>!["top","left","right"].includes(u)||!tc.test(p))))throw Error(`${o}.colors: {top?, left?, right?: #RRGGBB}`);if(t.steps!=null&&!(Number.isInteger(t.steps)&&t.steps>=2&&t.steps<=Js.steps))throw Error(`${o}.steps: 2–${Js.steps}`);for(const[u,p]of[["rise",["left","right"]],["face",["left","right"]]])if(t[u]!=null&&!p.includes(t[u]))throw Error(`${o}.${u}: ${p.join(" | ")}`);if(t.inset!=null&&!(Rs(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&&!tc.test(t.inner))throw Error(`${o}.inner: #RRGGBB (the panel's inside: screen, mirror, window)`);const c=t.shadow;if(c!=null&&typeof c!="boolean"&&(typeof c!="object"||Array.isArray(c)||Object.keys(c).some(u=>!["length","side","color"].includes(u))||c.length!=null&&!(Rs(c.length)&&c.length>=0&&c.length<=4)||c.side!=null&&!["left","right"].includes(c.side)||c.color!=null&&!tc.test(c.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:c??!0,name:t.name!=null?String(t.name).slice(0,40):null}}function PA(t,e,{view:o="iso",light:r="left",shadowColor:a="#1e1719"}={}){const[n,i]=wp[o]??wp.iso,c=e.pt(t.at),u=W=>e.len(W),[p,s,h]=t.size.map(u),f=u(t.z||0),m=([W,_,J])=>[c[0]+(W-_)*n,c[1]+(W+_)*i-J-f],g=t.colors?.left??t.color,v={top:t.colors?.top??Rr(t.color,.18),lit:g,dark:t.colors?.right??Rr(t.color,-.28)},x=r==="left"?v.lit:v.dark,E=r==="left"?v.dark:v.lit,$=[],S=(W,_)=>$.push({d:TA(W),fill:_,line:!1,role:7}),k=t.shadow,y=k===!1?0:typeof k=="object"?k.length??1:1,A=(typeof k=="object"&&k.side?k.side:r==="left"?"right":"left")==="right"?[1,-.35]:[-.35,1],z=t.kind==="plane"?0:(t.kind==="panel",h);if(y>0&&z>0){let W;if(t.kind==="cylinder"){W=[];for(let tt=0;tt<16;tt++){const rt=tt/16*2*Math.PI;W.push([Math.cos(rt)*p/2,Math.sin(rt)*p/2])}}else t.kind==="panel"?W=t.face==="left"?[[-p/2,0],[p/2,0]]:[[0,-p/2],[0,p/2]]:W=[[-p/2,-s/2],[p/2,-s/2],[p/2,s/2],[-p/2,s/2]];const _=[A[0]*z*y,A[1]*z*y],J=OA([...W,...W.map(tt=>[tt[0]+_[0],tt[1]+_[1]])]);S(J.map(([tt,rt])=>m([tt,rt,0])),typeof k=="object"&&k.color?k.color:a)}const j=(W,_,J,tt,rt,D,q=v)=>{const pt=[[W,J,D],[_,J,D],[_,tt,D],[W,tt,D]].map(m),yt=[[W,tt,rt],[_,tt,rt],[_,tt,D],[W,tt,D]].map(m),Mt=[[_,J,rt],[_,tt,rt],[_,tt,D],[_,J,D]].map(m);D-rt>0&&(S(yt,q===v?x:q.left),S(Mt,q===v?E:q.right)),S(pt,q.top)};if(t.kind==="box")j(-p/2,p/2,-s/2,s/2,0,h);else if(t.kind==="plane")S([[-p/2,-s/2,h],[p/2,-s/2,h],[p/2,s/2,h],[-p/2,s/2,h]].map(m),v.top);else if(t.kind==="stairs"){const W=t.steps;for(let _=W-1;_>=0;_--){const J=h*(_+1)/W;t.rise==="left"?j(p/2-p*(_+1)/W,p/2-p*_/W,-s/2,s/2,0,J):j(-p/2,p/2,s/2-s*(_+1)/W,s/2-s*_/W,0,J)}}else if(t.kind==="cylinder"){const _=D=>Array.from({length:24},(q,pt)=>{const yt=pt/24*2*Math.PI;return m([Math.cos(yt)*p/2,Math.sin(yt)*p/2,D])}),J=_(0),tt=_(h),rt=(D,q)=>{const pt=[];for(let yt=D;yt<=q;yt++)pt.push(J[yt%24]);for(let yt=q;yt>=D;yt--)pt.push(tt[yt%24]);return pt};h>0&&(S(rt(0,24/4),E),S(rt(24/4,24/2),x)),S(tt,v.top)}else if(t.kind==="panel"){const W=(J,tt)=>t.face==="left"?m([J,s/2,tt]):m([s/2,J,tt]),_=(J,tt,rt,D)=>[W(J,rt),W(tt,rt),W(tt,D),W(J,D)];if(s>0?j(...t.face==="left"?[-p/2,p/2,-s/2,s/2]:[-s/2,s/2,-p/2,p/2],0,h):S(_(-p/2,p/2,0,h),t.face==="left"?x:E),t.inner){const J=Math.min(p,h)*t.inset;S(_(-p/2+J,p/2-J,J,h-J),t.inner)}}const P=$.flatMap(W=>W.d.match(/-?\d+(\.\d+)?/g).map(Number)),F=P.filter((W,_)=>_%2===0),N=P.filter((W,_)=>_%2===1),G=Qs((Math.min(...F)+Math.max(...F))/2),V=Qs((Math.min(...N)+Math.max(...N))/2),et=$.map(W=>{let _=0;return{...W,d:W.d.replace(/-?\d+(\.\d+)?/g,J=>String(Qs(Number(J)-(_++%2?V:G))))}}),U=F.map(W=>W-G),at=N.map(W=>W-V);return{parts:et,pos:[G,V],box:[Math.min(...U),Math.min(...at),Math.max(...U),Math.max(...at)]}}const _a=/^#[0-9a-fA-F]{6}$/,Ii=Number.isFinite,kg=Object.freeze(["corridor","box","panel","wall-panel"]),ma=Object.freeze({solids:24,depth:[0,60],repeat:24,fly:[0,40]}),Ds=-.55;function Vb(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(!kg.includes(r))throw Error(`${o}.kind (perspective): ${kg.join(" | ")}`);const a=t.color??"#efe6df";if(!_a.test(a))throw Error(`${o}.color: #RRGGBB`);const n=(c,u,p)=>{if(c==null)return null;if(typeof c!="object"||Array.isArray(c)||Object.entries(c).some(([s,h])=>!u.includes(s)||!_a.test(h)))throw Error(`${o}.${p}: {${u.join(", ")}: #RRGGBB}`);return c};if(((c,u)=>{if(c!=null&&!(Ii(c)&&c>=ma.depth[0]&&c<=ma.depth[1]))throw Error(`${o}.${u}: 0–${ma.depth[1]} (0 = the picture plane, 1 = twice as far)`)})(t.depth,"depth"),r==="corridor"){const c=(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 g of Object.keys(h))if(!f.includes(g))throw Error(`${o}.${m}: ${f.join(", ")}`);return h},u=c(t.carpet,["color","width"],"carpet"),p=c(t.doors,["count","color","inner","height","width"],"doors"),s=c(t.lines,["count","color"],"lines");if(u&&(!_a.test(u.color??"")||u.width!=null&&!(Ii(u.width)&&u.width>0&&u.width<=1)))throw Error(`${o}.carpet: {color #RRGGBB, width? 0–1 of the floor}`);if(p&&(!(Number.isInteger(p.count)&&p.count>=1&&p.count<=8)||p.color!=null&&!_a.test(p.color)||p.inner!=null&&!_a.test(p.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&&!_a.test(s.color)))throw Error(`${o}.lines: {count 1–16, color?} (floor lines across)`);return{kind:r,color:a,colors:n(t.colors,["floor","ceiling","left","right","back"],"colors"),depth:t.depth??6,carpet:u,doors:p,lines:s}}if(!Array.isArray(t.at)||t.at.length!==2||!t.at.every(c=>Ii(c)&&c>=-1&&c<=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((c,u)=>Ii(c)&&c>=0&&c<=(u===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<=ma.repeat)||!(Ii(t.repeat.step)&&t.repeat.step>0&&t.repeat.step<=20)||t.repeat.dx!=null&&!Ii(t.repeat.dx)))throw Error(`${o}.repeat: {count 2–${ma.repeat}, step (depth units), dx? (frame width per copy)}`);if(t.inner!=null&&!_a.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:a,colors:n(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 LA(t,{vanish:e=[.5,.45],cam:o=0,W:r=1280,H:a=720}={}){const n=[e[0]*r,e[1]*a],i=[],c=(h,f,m)=>{const g=1/(1+Math.max(Ds,m-o));return[(n[0]+(h-n[0])*g)/r,(n[1]+(f-n[1])*g)/a]},u=(h,f)=>i.push({pts:h.map(m=>[Math.round(m[0]*1e4)/1e4,Math.round(m[1]*1e4)/1e4]),fill:f}),p=h=>Math.max(h,o+Ds);if(t.kind==="corridor"){const h=t.colors||{},f=t.depth,m=p(0),g=f,v=h.floor??Rr(t.color,-.12),x=h.ceiling??Rr(t.color,.1),E=h.left??t.color,$=h.right??Rr(t.color,-.06),S=h.back??Rr(t.color,-.2);if(g<=o+Ds)return i;if(u([c(0,0,m),c(r,0,m),c(r,0,g),c(0,0,g)],x),u([c(0,a,m),c(r,a,m),c(r,a,g),c(0,a,g)],v),u([c(0,0,m),c(0,0,g),c(0,a,g),c(0,a,m)],E),u([c(r,0,m),c(r,0,g),c(r,a,g),c(r,a,m)],$),u([c(0,0,g),c(r,0,g),c(r,a,g),c(0,a,g)],S),t.lines){const k=t.lines.count;for(let y=1;y<=k;y++){const C=f*y/(k+1);if(C<=m)continue;const A=.006*r;u([c(0,a,C),c(r,a,C),c(r,a,C+A/r*f*.4),c(0,a,C+A/r*f*.4)],t.lines.color??Rr(v,-.1))}}if(t.carpet){const k=(t.carpet.width??.3)*r/2;u([c(r/2-k,a,m),c(r/2+k,a,m),c(r/2+k,a,g),c(r/2-k,a,g)],t.carpet.color)}if(t.doors){const k=t.doors.count,y=(t.doors.height??.62)*a,C=t.doors.width??Math.min(.55,f/(k*2.2)),A=t.doors.color??Rr(E,-.25),z=t.doors.inner??Rr(E,-.45);for(let j=k-1;j>=0;j--){const P=f*(j+.35)/k,F=P+C;if(F<=o+Ds)continue;const N=p(P);for(const G of[0,r]){u([c(G,a-y,N),c(G,a-y,F),c(G,a,F),c(G,a,N)],A);const V=C*.14;F-V>N+V&&u([c(G,a-y*.9,N+V),c(G,a-y*.9,F-V),c(G,a,F-V),c(G,a,N+V)],z)}}}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,[g,v]=[t.at[0]*r+m,t.at[1]*a],x=t.size[0]*r,E=t.size[1],$=t.size[2]*r,S=g-x/2,k=g+x/2,y=v,C=v-$,A=f+E;if(A<=o+Ds)continue;const z=p(f),j=t.colors||{},P=j.front??t.color,F=j.top??Rr(t.color,.16),N=j.side??Rr(t.color,-.22),G=j.bottom??Rr(t.color,-.35);if(t.kind==="wall-panel"){if(u([c(g,C,z),c(g,C,A),c(g,y,A),c(g,y,z)],P),t.inner){const V=(A-z)*t.inset,et=$*t.inset;u([c(g,C+et,z+V),c(g,C+et,A-V),c(g,y-et,A-V),c(g,y-et,z+V)],t.inner)}continue}if(E>0&&(C>n[1]&&u([c(S,C,z),c(k,C,z),c(k,C,A),c(S,C,A)],F),y<n[1]&&u([c(S,y,z),c(k,y,z),c(k,y,A),c(S,y,A)],G),S>n[0]&&u([c(S,C,z),c(S,C,A),c(S,y,A),c(S,y,z)],N),k<n[0]&&u([c(k,C,z),c(k,C,A),c(k,y,A),c(k,y,z)],N)),u([c(S,C,z),c(k,C,z),c(k,y,z),c(S,y,z)],P),t.kind==="panel"&&t.inner){const V=Math.min(x,$)*t.inset;u([c(S+V,C+V,z),c(k-V,C+V,z),c(k-V,y-V,z),c(S+V,y-V,z)],t.inner)}}return i}function Gb(t,e){return t.map((r,a)=>({s:r,i:a})).sort((r,a)=>(a.s.kind==="corridor")-(r.s.kind==="corridor")||a.s.depth+(a.s.repeat?a.s.repeat.step*(a.s.repeat.count-1):0)-(r.s.depth+(r.s.repeat?r.s.repeat.step*(r.s.repeat.count-1):0))||r.i-a.i).map(({s:r})=>({s:r,parts:LA(r,e)}))}const Nu=Object.freeze({size:[6,16],size0:10,palette:[2,16],sampleFrames:16,parts:64,points:900,partPoints:200,backdropPoints:4e3}),FA=Object.freeze(["plate","none","keep"]),NA=/^#[0-9a-f]{6}$/i;function RA(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=>!NA.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??Nu.size0;if(!(Number.isInteger(o)&&o>=Nu.size[0]&&o<=Nu.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 Ru=Object.freeze({seconds:30,fps:[8,12,24,30],width:640,plateFrames:48,parts:64,points:100}),xg=Object.freeze(["flash","glow","smoke","shadow","blood","cloth","eyes"]),Du=Object.freeze(["dark","mid","cloth","blood"]),eh=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}}),DA=/^#[0-9a-f]{6}$/i;function BA(t={}){const e=eh[t.look??"ninja"];if(!e)throw Error(`rotoscope look: ${Object.keys(eh).join(" | ")}`);if(e.flat)return{flat:RA(t)};for(const a of["palette","paletteSize","boil"])if(t[a]!=null)throw Error(`rotoscope ${a}: 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: {${Du.join(" | ")}: '#RRGGBB'}`);for(const[a,n]of Object.entries(t.colors)){if(!Du.includes(a)||!DA.test(String(n)))throw Error(`rotoscope colors: {${Du.join(" | ")}: '#RRGGBB'}`);o[a]=String(n).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(([a,n])=>!xg.includes(a)||typeof n!="boolean"))throw Error(`rotoscope effects: {${xg.join(" | ")}: true | false}`);Object.assign(r,t.effects)}return{colors:o,effects:r}}function _A(t,e,o=480){const r=Number.isFinite,a=t.fps??24;if(!Ru.fps.includes(a))throw Error(`rotoscope fps: ${Ru.fps.join(" | ")} drawings per second (24 = smooth, 12 = on twos)`);const n=t.from??0,i=Math.min(Ru.seconds,Math.floor(o/a*100)/100);if(!(r(n)&&n>=0&&n<e))throw Error(`rotoscope from: s into the video clip, 0–${Math.round(e*100)/100}`);const c=t.duration??Math.round(Math.min(i,e-n)*1e4)/1e4;if(!(r(c)&&c>=.25&&c<=i+1e-6&&n+c<=e+1e-6))throw Error(`rotoscope duration: 0.25–${i} s at ${a} fps, inside the video clip`);return{fps:a,from:n,duration:c,n:Math.max(1,Math.round(c*a))}}function VA(t={}){const e=!!eh[t.look??"ninja"]?.flat,o=t.background??"plate";if(!(e?FA:["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 Ai=Object.freeze({events:24,size:[.02,.6]}),GA=/^#[0-9a-f]{6}$/i,Ci=Number.isFinite,$e=t=>Math.round(t*1e3)/1e3,as=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"}}),Bu=["shadow","trail",...Object.keys(as)];function Kb(t,e="drawFrames"){if(t==null||t===!1)return null;const o=Object.fromEntries(Object.keys(as).map(a=>[a,[]]));if(t===!0)return{shadow:!0,trail:!0,...o};if(typeof t!="object"||Array.isArray(t))throw Error(`${e} fx: true | {${Bu.join("?, ")}?}`);for(const a of Object.keys(t))if(!Bu.includes(a))throw Error(`${e} fx: ${Bu.join("?, ")}? (unknown "${String(a).slice(0,20)}")`);const r=a=>{const n=as[a],i=t[a];if(i==null)return[];if(!Array.isArray(i)||i.length>Ai.events)throw Error(`${e} fx.${a}: up to ${Ai.events} [{at (s), x, y (0..1 of the frame), size?}]`);return i.map((c,u)=>{const p=c?.at,s=c?.x??.5,h=c?.y??.5,f=c?.size??n.size;if(!(Ci(p)&&p>=0&&Ci(s)&&s>=-.2&&s<=1.2&&Ci(h)&&h>=-.2&&h<=1.2))throw Error(`${e} fx.${a}[${u}]: {at (s from the start), x, y (0..1 of the frame)}`);if(!(Ci(f)&&f>=Ai.size[0]&&f<=(a==="flash"?1:Ai.size[1])))throw Error(`${e} fx.${a}[${u}].size: ${Ai.size[0]}–${a==="flash"?1:Ai.size[1]} of the frame height`);if(n.color&&c.color!=null&&!GA.test(c.color))throw Error(`${e} fx.${a}[${u}].color: #RRGGBB`);if(n.angle&&c.angle!=null&&!Ci(c.angle))throw Error(`${e} fx.${a}[${u}].angle: degrees`);if(n.span&&c.span!=null&&!(Ci(c.span)&&c.span>=.05&&c.span<=10))throw Error(`${e} fx.${a}[${u}].span: 0.05–10 s`);return{at:p,x:s,y:h,size:f,...n.color?{color:c.color??n.color}:{},...n.angle?{angle:c.angle??0}:{},...n.span?{span:c.span??(a==="aura"?1:.4)}:{}}})};return{shadow:t.shadow!==!1,trail:t.trail!==!1,...Object.fromEntries(Object.keys(as).map(a=>[a,r(a)]))}}const KA=t=>t.fill&&(t.opacity??1)>.9&&Array.isArray(t.points);function Mg(t){let e=1e9,o=1e9,r=-1e9,a=-1e9;for(const n of t)for(const[i,c]of n.points)i<e&&(e=i),i>r&&(r=i),c<o&&(o=c),c>a&&(a=c);return r<e?null:{x0:e,y0:o,x1:r,y1:a,cx:(e+r)/2,cy:(o+a)/2,w:r-e,h:a-o}}function WA(t){const e=t.filter(KA).map(r=>({p:r,b:Mg([r])})).filter(r=>r.b),o=[];for(const r of e){const a=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),n={parts:[r.p,...a.flatMap(i=>i.parts)]};n.b=Mg(n.parts);for(const i of a)o.splice(o.indexOf(i),1);o.push(n)}return o.filter(r=>r.b.h>.04)}const ji=(t,e,o,r,a=16)=>Array.from({length:a},(n,i)=>{const c=i/a*Math.PI*2;return[$e(t+Math.cos(c)*o),$e(e+Math.sin(c)*r)]});function vg(t,e,o,r,a){const n=[];for(let i=0;i<r*2;i++){const c=i/(r*2)*Math.PI*2+a,u=i%2?.38:1+(Math.sin(a*7+i*3.1)+1)/2*.35;n.push([$e(t+Math.cos(c)*o*u),$e(e+Math.sin(c)*o*u*1.05)])}return n}function HA(t,e,o,{aspect:r=16/9,maxParts:a=64}={}){if(!o)return t;let n=0;const i=t.map(u=>{const p=n;return n+=(u.hold??1)/e,p}),c=t.map(u=>WA(u.parts));return t.map((u,p)=>{const s=[],h=[],f=i[p];if(o.shadow)for(const S of c[p]){const k=Math.max(.03,S.b.w*.55);s.push({points:ji(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&&p>0)for(const S of c[p]){const k=c[p-1].reduce((y,C)=>{const A=Math.hypot(C.b.cx-S.b.cx,(C.b.cy-S.b.cy)/r);return A<y.d?{d:A,q:C}:y},{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 y of k.q.parts)s.push({points:y.points,fill:y.fill,opacity:.22,line:!1,smooth:y.smooth!==!1})}for(const[S,k]of o.hits.entries()){const y=(f-k.at)/.2;if(y<0||y>=1)continue;const C=k.size*(.6+.6*Math.sin(Math.min(1,y*1.6)*Math.PI/2)),A=C/r;h.push({points:vg(k.x,k.y,1,9,S*1.7).map(([z,j])=>[$e(k.x+(z-k.x)*A*1.25),$e(k.y+(j-k.y)*C*1.25)]),fill:k.color,opacity:Math.max(.02,$e(.45*(1-y))),line:!1,smooth:!1}),h.push({points:vg(k.x,k.y,1,7,S*2.3).map(([z,j])=>[$e(k.x+(z-k.x)*A*.8),$e(k.y+(j-k.y)*C*.8)]),fill:"#ffffff",opacity:$e(Math.max(.05,1-y)),line:!1,smooth:!1})}for(const[S,k]of o.dust.entries()){const y=(f-k.at)/.6;if(!(y<0||y>=1))for(let C=0;C<3;C++){const A=(C-1)*k.size*.9*(.4+y)/r,z=k.size*(.35+y*.6)*(C===1?1.1:.8);h.push({points:ji(k.x+A,k.y-z*.45,z/r,z*.55,14),fill:"#d9d2cc",opacity:Math.max(.02,$e(.55*(1-y))),line:!1,smooth:!0})}}const m=S=>Math.max(.02,$e(S)),g=S=>S*Math.PI/180;for(const S of o.slash){const k=(f-S.at)/.25;if(k<0||k>=1)continue;const y=g(S.angle)-1.3,C=2.6*Math.min(1,k*2.2),A=S.size/2,z=[],j=[];for(let P=0;P<=14;P++){const F=y+C*P/14,N=Math.sin(Math.PI*P/14)*A*.22;z.push([$e(S.x+Math.cos(F)*A/r),$e(S.y+Math.sin(F)*A)]),j.push([$e(S.x+Math.cos(F)*(A-N)/r),$e(S.y+Math.sin(F)*(A-N))])}h.push({points:[...z,...j.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 y=g(k.angle),C=Math.cos(y),A=Math.sin(y),z=-A,j=C;for(let P=0;P<7;P++){const F=Math.sin((S+1)*12.9898+P*78.233+Math.floor(f*24)*3.1)*43758.5453,N=F-Math.floor(F),G=(N-.5)*k.size,V=k.size*(.5+N*.6),et=.0025+N*.003,U=k.x+z*G/r,at=k.y+j*G,W=U-C*V/r,_=at-A*V,J=U+C*V*.2/r,tt=at+A*V*.2;h.push({points:[[$e(W),$e(_)],[$e(J+z*et/r),$e(tt+j*et)],[$e(J-z*et/r),$e(tt-j*et)]],fill:k.color,opacity:m(.55),line:!1,smooth:!1})}}for(const[S,k]of o.sparks.entries()){const y=(f-k.at)/.35;if(!(y<0||y>=1))for(let C=0;C<8;C++){const A=C/8*Math.PI*2+S*.7,z=k.size*(.2+y*.9),j=k.size*.18*(1-y*.5),P=k.x+Math.cos(A)*z/r,F=k.y+Math.sin(A)*z+y*y*k.size*.4;h.push({points:[[$e(P),$e(F)],[$e(P+Math.cos(A)*j/r+.002),$e(F+Math.sin(A)*j)],[$e(P+Math.cos(A)*j/r-.002),$e(F+Math.sin(A)*j+.003)]],fill:k.color,opacity:m(1-y),line:!1,smooth:!1})}}for(const S of o.ring){const k=(f-S.at)/.35;if(k<0||k>=1)continue;const y=S.size/2*(.2+k*.8),C=y*(.18*(1-k)+.04);h.push({points:[...ji(S.x,S.y,y/r,y*.55,20),...ji(S.x,S.y,(y-C)/r,(y-C)*.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 y=c[p].reduce((j,P)=>{const F=Math.hypot(P.b.cx-k.x,P.b.cy-k.y);return F<j.d?{d:F,q:P}:j},{d:1e9,q:null}).q??{b:{cx:k.x,cy:k.y,w:k.size*.35/r,h:k.size*.8}},C=.85+.15*Math.sin(f*40+S),A=(y.b.w/2+k.size*.15/r)*C,z=(y.b.h/2+k.size*.12)*C;s.push({points:ji(y.b.cx,y.b.cy,A,z,18),fill:k.color,opacity:.35,line:!1,smooth:!0},{points:ji(y.b.cx,y.b.cy,A*.75,z*.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 u;const v=Math.max(0,a-u.parts.length),x=[...h,...s].slice(0,v),E=s.filter(S=>x.includes(S)),$=h.filter(S=>x.includes(S));return{...u,parts:[...E,...u.parts,...$]}})}const XA={hits:.2,dust:.6,slash:.25,speed:0,sparks:.35,ring:.35,aura:0,flash:.1},UA={points:[[.5,.5],[.501,.5],[.5,.501]],fill:"#000000",opacity:.02,line:!1};function qT(t,e,o={},{fps:r=30,label:a}={}){const n=as[t];if(!n)throw Error(`fxLayerOp kind: ${Object.keys(as).join(" | ")}`);const i=n.span?o.span??(t==="aura"?1:.4):0,c=Math.ceil((XA[t]+i+.05)*r),u={at:.01,x:o.x??.5,y:o.y??.5,...o.size!=null?{size:o.size}:{},...n.color&&o.color?{color:o.color}:{},...n.angle&&o.angle!=null?{angle:o.angle}:{},...n.span?{span:i}:{}};return{op:"drawFrames",start:e,fps:r,frames:Array.from({length:c},()=>({parts:[UA]})),fx:{shadow:!1,trail:!1,[t]:[u]},width:0,brush:"none",...a?{label:a}:{}}}function YA(t){const e=String(t).match(/[MLCSQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi)??[],o=[];let r=0,a="M",n=[0,0],i=[0,0],c=null,u=!1;const p=()=>Number(e[r++]),s=(h,f,m,g)=>{for(let v=1;v<=8;v++){const x=v/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*g[0],E*E*E*h[1]+3*E*E*x*f[1]+3*E*x*x*m[1]+x*x*x*g[1]])}};for(;r<e.length;){if(/^[MLCSQZ]$/i.test(e[r])&&(a=e[r++].toUpperCase()),a==="Z"){u=!0,n=i,c=null;continue}if(a==="M")n=[p(),p()],i=n,o.push(n),a="L",c=null;else if(a==="L")n=[p(),p()],o.push(n),c=null;else if(a==="C"){const h=[p(),p()],f=[p(),p()],m=[p(),p()];s(n,h,f,m),c=f,n=m}else if(a==="S"){const h=c?[2*n[0]-c[0],2*n[1]-c[1]]:n,f=[p(),p()],m=[p(),p()];s(n,h,f,m),c=f,n=m}else if(a==="Q"){const h=[p(),p()],f=[p(),p()];s(n,[n[0]+2/3*(h[0]-n[0]),n[1]+2/3*(h[1]-n[1])],[f[0]+2/3*(h[0]-f[0]),f[1]+2/3*(h[1]-f[1])],f),c=null,n=f}else r++;if(!Number.isFinite(n[0]))break}return{pts:o.filter(h=>h.every(Number.isFinite)),closed:u}}function $g(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 a=[0];for(let u=1;u<r.length;u++)a.push(a[u-1]+Math.hypot(r[u][0]-r[u-1][0],r[u][1]-r[u-1][1]));const n=a.at(-1)||1,i=[];let c=1;for(let u=0;u<e;u++){const p=o?n*u/e:n*u/(e-1);for(;c<r.length-1&&a[c]<p;)c++;const s=r[c-1],h=r[c],f=(p-a[c-1])/(a[c]-a[c-1]||1);i.push([s[0]+(h[0]-s[0])*f,s[1]+(h[1]-s[1])*f])}return i}function qA(t,e){const o=e.length;let r=0,a=1,n=1/0;for(const i of[1,-1])for(let c=0;c<o;c++){let u=0;for(let p=0;p<o;p+=Math.max(1,o>>3)){const s=e[((c+i*p)%o+o)%o];u+=Math.hypot(s[0]-t[p][0],s[1]-t[p][1])}u<n&&(n=u,r=c,a=i)}return Array.from({length:o},(i,c)=>e[((r+a*c)%o+o)%o])}const Eg=Object.freeze(["draw","erase","undoLine","duplicate","insert","delete","hold","clear","transform","clone","unlink","fill","warp","mark","inbetween"]),Sg=Object.freeze(["key","breakdown","inbetween"]),Ig=Object.freeze(["even","slow-out","slow-in","slow-in-out"]),Ag=Object.freeze(["ramp","ramp-down","bump","hold"]),Nn=Object.freeze({strokes:32,points:400,hold:48,fps:[4,60]}),_u=/^#[0-9a-f]{6}$/i,qi=Number.isFinite,Ye=t=>Math.round(Math.round(t*120)/120*1e4)/1e4,ZA=t=>Array.isArray(t?.size)?t.size:t?.square?[720,720]:[1280,720];function Wb(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 ZT=t=>Wb(t).length>0,ec=t=>{let e=t.length+1;for(;t.some(o=>o.id===`s${e}`);)e++;return`s${e}`},Va=(t,e,o)=>t.map(r=>r.span&&r.span[0]>=e-1e-6?{...r,span:[Ye(r.span[0]+o),Ye(r.span[1]+o)]}:r);function kp(t,e){if(!Array.isArray(t)||t.length<1||t.length>Nn.points)throw Error(`${e}.points: 1–${Nn.points} [x, y] pairs`);return t.map((o,r)=>{if(!Array.isArray(o)||o.length!==2||!o.every(qi))throw Error(`${e}.points[${r}]: [x, y]`);return[o[0],o[1]]})}function JA(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},(a,n)=>o[Math.round(n*r)])}for(let r=0;r<1;r++)o=o.map((a,n)=>n===0||n===o.length-1?a:[(o[n-1][0]+2*a[0]+o[n+1][0])/4,(o[n-1][1]+2*a[1]+o[n+1][1])/4]);return ps(o,e&&o.length>2)}function QA(t,e,o=null){let r=t.length===1?[t[0],[t[0][0]+.6,t[0][1]]]:t,a=o&&o.length===t.length?o:null;if(r.length>80){const u=(r.length-1)/79,p=Array.from({length:80},(s,h)=>Math.round(h*u));r=p.map(s=>r[s]),a&&(a=p.map(s=>a[s]))}const n=r.length,i=[],c=[];for(let u=0;u<n;u++){const p=r[Math.max(0,u-1)],s=r[Math.min(n-1,u+1)],h=s[0]-p[0],f=s[1]-p[1],m=Math.hypot(h,f)||1,g=n>1?u/(n-1):.5,v=Math.max(.25,Math.min(1,Math.min(g,1-g)*5)),x=e/2*(a?Math.max(.12,Math.min(1.3,.2+a[u]*1.1))*Math.max(.5,v):v);i.push([r[u][0]-f/m*x,r[u][1]+h/m*x]),c.push([r[u][0]+f/m*x,r[u][1]-h/m*x])}return ps([...i,...c.reverse()],!0)}const tC=t=>"M"+t.map(([e,o])=>`${Math.round(e)} ${Math.round(o)}`).join(" L")+" Z",oh=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 Cg(t,e,o,{units:r,toShape:a,where:n,k:i}){if(!t||t.type!=="art"||!Array.isArray(t.params.parts))throw Error(`${n}: frame ${i+1} is not a drawing`);const c=Tc(ga(t)),u=V=>{const et=a(V);return Xs(c,et[0],et[1])};if(e.tag!=null&&!gh.test(e.tag))throw Error(`${n} tag: a part name (armR, head…)`);const p=e.tag!=null?null:kp(e.lasso,`${n} lasso`).map(u);if(p&&p.length<3)throw Error(`${n} 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(qi)||m<=0||m>10)throw Error(`${n}: dx, dy (frame fractions), rotate (degrees), scale (0–10)`);const g=([V,et])=>{let U=!1;for(let at=0,W=p.length-1;at<p.length;W=at++){const[_,J]=p[at],[tt,rt]=p[W];J>et!=rt>et&&V<(tt-_)*(et-J)/(rt-J)+_&&(U=!U)}return U},v=V=>e.tag!=null?V.tag===e.tag:(()=>{const et=oh(V.d);return et.length>0&&et.filter(g).length>=et.length*.6})(),x=t.params.parts.filter(v);if(!x.length)return{item:t,moved:0};const[E,$]=e.pivot!=null?u(kp([e.pivot],`${n} pivot`)[0]):p?[p.reduce((V,et)=>V+et[0],0)/p.length,p.reduce((V,et)=>V+et[1],0)/p.length]:oh(x[0].d)[0],S=u([0,0]),k=u([s,h]),y=(k[0]-S[0])*o,C=(k[1]-S[1])*o,A=f*o*Math.PI/180,z=Math.pow(m,o),j=Math.cos(A)*z,P=Math.sin(A)*z,F=(V,et)=>[Math.round(E+(V-E)*j-(et-$)*P+y),Math.round($+(V-E)*P+(et-$)*j+C)];let N=0;const G=t.params.parts.map(V=>{if(!v(V))return V;N++;let et=0,U=0;const at=V.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,W=>{const _=Number(W);if(et++%2===0)return U=_,"\0";const[J,tt]=F(U,_);return`${J} ${tt}`}).replace(/\u0000[\s,]*/g,"");return{...V,d:at}});return{item:{...t,params:{...t.params,parts:G,box:mr(G.map(V=>V.d).join(" "))}},moved:N}}function Hb(t,e,{units:o="frame",ink:r="#1d1a17",width:a=4}={}){const n="editFrames";if(!t||!Array.isArray(t.items))throw Error(`${n}: not a shape layer`);if(!Eg.includes(e?.action))throw Error(`${n} action: ${Eg.join(" | ")}`);const i=e.fps??24;if(!(qi(i)&&i>=Nn.fps[0]&&i<=Nn.fps[1]))throw Error(`${n} fps: ${Nn.fps.join("–")}`);const c=e.hold??1;if(!(Number.isInteger(c)&&c>=1&&c<=Nn.hold))throw Error(`${n} hold: 1–${Nn.hold} frames`);const u=Ye(c/i);let p=t.items.map(k=>({...k}));const s=Wb({items:p});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(`${n} 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(`${n} fill: frame (1-based) — the drawing to fill`);if(!(qi(e.at)&&e.at>=0&&e.at<=600))throw Error(`${n}: 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,g=m?p.findIndex(k=>k.id===m.id):-1,v=ZA(t),x=on(v),E=k=>o==="shape"?k:x.pt(k);let $="";if(e.action==="fill"){if(!Array.isArray(e.region))throw Error(`${n} 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(!_u.test(e.color??""))throw Error(`${n} fill color: #RRGGBB`);const k=Hb(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:a});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>Nn.strokes)throw Error(`${n} draw lines: 1–${Nn.strokes} [{points, width?, fill?}]`);let y=g>=0?p[g]:null;if(y&&y.type!=="art")throw Error(`${n}: frame ${h+1} is a ${y.type} item, not a drawing — draw on a drawFrames / frame-editor layer`);if(y?.params?.rig)throw Error(`${n}: frame ${h+1} is a character played from its skeleton — it cannot take lines`);const C=k.map((F,N)=>({...F,pts:kp(F?.points,`${n} lines[${N}]`).map(E)}));if(!y){if(p.length>=tr.items)throw Error(`${n}: this layer already holds ${tr.items} drawings — continue on a new frame layer`);const F=s.find(at=>at.t0>f+1e-6),N=Ye(f),G=Ye(Math.min(f+u,F?F.t0:f+u)),V=C.flatMap(at=>at.pts),et=Math.round((Math.min(...V.map(at=>at[0]))+Math.max(...V.map(at=>at[0])))/2),U=Math.round((Math.min(...V.map(at=>at[1]))+Math.max(...V.map(at=>at[1])))/2);y={id:ec(p),name:`Frame ${s.filter(at=>at.t0<N).length+1}`,type:"art",params:{parts:[],box:[0,0,1,1]},pos:[et,U],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:r},stroke:{color:r,width:a,cap:"round",join:"round"},role:7,span:[N,G>N?G:Ye(N+u)]},p.push(y)}const A=Tc(ga(y)),z=y.stroke?.width||a,j=[...y.params.parts??[]];for(const[F,N]of C.entries()){const G=N.pts.map(rt=>Xs(A,rt[0],rt[1])),V=N.fill??null;if(V!==null&&!_u.test(V))throw Error(`${n} lines[${F}].fill: #RRGGBB or omitted (an ink line)`);const et=N.width==null?null:o==="shape"?N.width:x.len(N.width);if(et!=null&&!(qi(et)&&et>0))throw Error(`${n} lines[${F}].width: a fraction of the frame width (e.g. 0.004)`);const U=et==null?1:Math.max(.1,Math.min(5,Math.round(et/z*100)/100)),at=N.color??null;if(at!==null&&!_u.test(at))throw Error(`${n} lines[${F}].color: #RRGGBB`);const W=N.tag??null;if(W!==null&&!gh.test(W))throw Error(`${n} lines[${F}].tag: a part name — a letter then letters / digits / dashes, ≤ 24 (armR, head)`);const _=W?{tag:W}:{},J=N.pressures==null?null:Array.isArray(N.pressures)&&N.pressures.length===N.points.length&&N.pressures.every(rt=>qi(rt)&&rt>=0&&rt<=1)?N.pressures:(()=>{throw Error(`${n} lines[${F}].pressures: one 0..1 value per point (the pen's pressure)`)})();if(V&&N.under===!0){const rt=j.findIndex(D=>!(D.eo===!0&&D.line===!1));j.splice(rt<0?j.length:rt,0,{d:tC(G),fill:V,line:!1,eo:!0,role:7,..._});continue}const tt=Math.hypot(A[0],A[1])||1;if(!V&&(J||at&&at.toLowerCase()!==String(y.stroke?.color??r).toLowerCase())){j.push({d:QA(G,(et??z)*tt,J),fill:at??y.stroke?.color??r,line:!1,role:7,..._});continue}j.push({d:JA(G,!!V||N.closed===!0),fill:V,...V&&N.line===!1?{line:!1}:{},...U!==1?{lw:U}:{},role:7,..._})}if(j.length>us.parts)throw Error(`${n}: frame ${h+1} would hold ${j.length} lines (max ${us.parts}) — fewer, longer lines`);const P=mr(j.map(F=>F.d).join(" "));p=p.map(F=>F.id===y.id?{...y,params:{...y.params,parts:j,box:P}}:F),$=`${k.length} line(s) on frame ${(m?h:s.filter(F=>F.t0<f).length)+1}`;break}case"erase":case"undoLine":{if(g<0)throw Error(`${n}: no drawing on that frame to ${e.action==="erase"?"erase":"undo"}`);const k=p[g];if(k.type!=="art"||!Array.isArray(k.params.parts))throw Error(`${n}: frame ${h+1} is not a drawing`);let y=k.params.parts;if(e.action==="undoLine")y=y.slice(0,-1);else{const A=Array.isArray(e.lines)?e.lines:[];if(!A.length)throw Error(`${n} erase lines: the eraser's path [{points}]`);const z=Tc(ga(k)),j=A.flatMap((F,N)=>kp(F?.points,`${n} lines[${N}]`).map(E).map(G=>Xs(z,G[0],G[1]))),P=e.radius==null?12:o==="shape"?e.radius:x.len(e.radius);y=y.filter(F=>!oh(F.d).some(N=>j.some(G=>Math.hypot(N[0]-G[0],N[1]-G[1])<=P)))}const C=k.params.parts.length-y.length;p=y.length?p.map((A,z)=>z===g?{...A,params:{...A.params,parts:y,box:mr(y.map(j=>j.d).join(" "))}}:A):p.filter((A,z)=>z!==g),$=`${C} line(s) taken out of frame ${h+1}${y.length?"":" (now blank)"}`;break}case"duplicate":{if(g<0)throw Error(`${n}: no drawing on that frame to duplicate`);if(p.length>=tr.items)throw Error(`${n}: this layer already holds ${tr.items} drawings — continue on a new frame layer`);const k=p[g],y=Ye(k.span[1]-k.span[0]);p=Va(p,k.span[1],y),p.push({...structuredClone(k),id:ec(p),name:`${k.name} copy`.slice(0,40),span:[k.span[1],Ye(k.span[1]+y)]}),$=`frame ${h+1} duplicated`;break}case"insert":{p=Va(p,m?m.t0:f,u),$=`blank frame put in at ${Ye(m?m.t0:f)}s`;break}case"delete":{if(!m){const y=s.find(z=>z.t0>f+1e-6);if(!y)throw Error(`${n}: nothing to take out there`);const C=s.filter(z=>z.t1<=f+1e-6).reduce((z,j)=>Math.max(z,j.t1),0),A=Math.min(u,Ye(y.t0-C));p=Va(p,y.t0,-A),$="blank frame taken out";break}const k=Ye(m.t1-m.t0);p=Va(p.filter((y,C)=>C!==g),m.t1,-k),$=`frame ${h+1} taken out`;break}case"hold":{if(g<0)throw Error(`${n}: no drawing on that frame to hold`);const k=p[g],y=Ye(k.span[1]-k.span[0]),C=Ye(u-y);p=Va(p,k.span[1],C).map((A,z)=>z===g?{...A,span:[k.span[0],Ye(k.span[0]+u)]}:A),$=`frame ${h+1} lasts ${c} frame(s)`;break}case"clear":{if(g<0)throw Error(`${n}: that frame is already blank`);p=p.filter((k,y)=>y!==g),$=`frame ${h+1} cleared (blank)`;break}case"transform":{if(g<0)throw Error(`${n}: no drawing on that frame to transform`);const k=Cg(p[g],e,1,{units:o,toShape:E,where:n,k:h});if(!k.moved)throw Error(`${n}: the ${e.tag?`part "${e.tag}"`:"lasso"} holds no line of frame ${h+1}`);p=p.map((y,C)=>C===g?k.item:y),$=`${k.moved} line(s) of frame ${h+1} transformed`;break}case"warp":{const k=(e.from??e.frame)-1,y=(e.to??e.from??e.frame)-1;if(!(Number.isInteger(k)&&Number.isInteger(y)&&k>=0&&y>=k&&y<s.length))throw Error(`${n} warp: from / to = frame numbers 1–${s.length} (from ≤ to)`);const C=e.ease??"ramp";if(!Ag.includes(C))throw Error(`${n} warp ease: ${Ag.join(" | ")}`);let A=0,z=0;for(let j=k;j<=y;j++){const P=y===k?1:(j-k)/(y-k),F=C==="hold"?1:C==="ramp"?P:C==="ramp-down"?1-P:Math.sin(Math.PI*P);if(F<=1e-4)continue;const N=p.findIndex(V=>V.id===s[j].id),G=Cg(p[N],e,F,{units:o,toShape:E,where:n,k:j});G.moved&&(p=p.map((V,et)=>et===N?G.item:V),A+=G.moved,z++)}if(!z)throw Error(`${n}: the ${e.tag?`part "${e.tag}"`:"lasso"} holds no line in frames ${k+1}–${y+1}`);$=`warp over frames ${k+1}–${y+1} (${C}): ${A} line(s) in ${z} frame(s)`;break}case"mark":{if(g<0)throw Error(`${n}: no drawing on that frame to mark`);const k=e.mark??null;if(k!==null&&!Sg.includes(k))throw Error(`${n} mark: ${Sg.join(" | ")} | null (no mark)`);p=p.map((y,C)=>{if(C!==g)return y;const{mark:A,...z}=y;return k?{...z,mark:k}:z}),$=`frame ${h+1} ${k?`marked ${k}`:"unmarked"}`;break}case"inbetween":{if(g<0)throw Error(`${n}: 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(`${n} inbetween: to = a later drawing (frame ${h+2}–${s.length}); default the next one`);const y=e.count??1;if(!(Number.isInteger(y)&&y>=1&&y<=12))throw Error(`${n} inbetween count: 1–12 drawings between the two keys`);const C=e.ease??"even";if(!Ig.includes(C))throw Error(`${n} inbetween ease: ${Ig.join(" | ")}`);if(p.length+y>tr.items)throw Error(`${n}: ${y} more drawings would pass ${tr.items} on this layer — fewer, or continue on a new frame layer`);const A=p[g],z=p.find(_=>_.id===s[k].id);if(A.type!=="art"||z.type!=="art"||!A.params.parts||!z.params.parts)throw Error(`${n} inbetween: both frames must be drawings`);const j=e.hold!=null?u:Ye(A.span[1]-A.span[0]),P=ga(A),F=ga(z),N=_=>_.fill===null?"line":"fill",G=[],V=new Set,et=(_,J)=>_.map((tt,rt)=>({q:tt,i:rt})).filter(({q:tt})=>!tt.tag&&N(tt)===J);for(const[_,J]of A.params.parts.entries()){let tt=-1;if(J.tag)tt=z.params.parts.findIndex((rt,D)=>rt.tag===J.tag&&!V.has(D));else{const rt=et(A.params.parts,N(J)),D=et(z.params.parts,N(J)).filter(({i:pt})=>!V.has(pt)),q=rt.findIndex(pt=>pt.i===_);tt=D[Math.min(q,D.length-1)]?.i??-1,q>=D.length&&(tt=-1)}tt>=0?(V.add(tt),G.push([J,z.params.parts[tt]])):G.push([J,null])}const U=z.params.parts.filter((_,J)=>!V.has(J)),at=(_,J)=>{const tt=YA(_.d);return{pts:tt.pts.map(rt=>Xs(J,rt[0],rt[1])),closed:tt.closed||!!_.fill}},W=_=>C==="even"?_:C==="slow-out"?_*_:C==="slow-in"?1-(1-_)*(1-_):_*_*(3-2*_);p=Va(p,A.span[1],Ye(y*j));for(let _=1;_<=y;_++){const J=W(_/(y+1)),tt=[Math.round(A.pos[0]+(z.pos[0]-A.pos[0])*J),Math.round(A.pos[1]+(z.pos[1]-A.pos[1])*J)],rt=[];for(const[q,pt]of G){if(!pt){J<.5&&rt.push({...q,d:q.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,(()=>{let I=0;return O=>{const L=Number(O)+(I++%2?A.pos[1]-tt[1]:A.pos[0]-tt[0]);return String(Math.round(L))}})())});continue}const yt=at(q,P),Mt=at(pt,F),l=yt.closed?48:40,lt=$g(yt.pts,l,yt.closed),K=$g(Mt.pts,l,yt.closed),d=yt.closed?qA(lt,K):K,w=yt.closed?lt.map((I,O)=>[I[0]+(d[O][0]-I[0])*J-tt[0],I[1]+(d[O][1]-I[1])*J-tt[1]]):(()=>{const I=[[lt[0][0]+(d[0][0]-lt[0][0])*J,lt[0][1]+(d[0][1]-lt[0][1])*J]];for(let O=1;O<lt.length;O++){const L=[lt[O][0]-lt[O-1][0],lt[O][1]-lt[O-1][1]],B=[d[O][0]-d[O-1][0],d[O][1]-d[O-1][1]],H=Math.atan2(L[1],L[0]),Z=Math.atan2(B[1],B[0]),ot=(Z-H+3*Math.PI)%(2*Math.PI)-Math.PI,st=H+ot*J,Y=Math.hypot(...L)+(Math.hypot(...B)-Math.hypot(...L))*J;I.push([I[O-1][0]+Math.cos(st)*Y,I[O-1][1]+Math.sin(st)*Y])}return I.map(O=>[O[0]-tt[0],O[1]-tt[1]])})(),T=q.lw!=null||pt.lw!=null?Math.round(((q.lw??1)+((pt.lw??1)-(q.lw??1))*J)*100)/100:null;rt.push({...q,d:yt.closed?ps(w,!0):ps(w,!1),fill:J<.5?q.fill:pt.fill,...T!=null&&T!==1?{lw:T}:{}})}for(const q of U)J>=.5&&rt.push({...q,d:q.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,(()=>{let pt=0;return yt=>{const Mt=Number(yt)+(pt++%2?z.pos[1]-tt[1]:z.pos[0]-tt[0]);return String(Math.round(Mt))}})())});if(!rt.length)continue;const D=Ye(A.span[1]+(_-1)*j);p.push({...structuredClone(A),id:ec(p),name:`${A.name} · ${_}/${y+1}`.slice(0,40),params:{...A.params,parts:rt,box:mr(rt.map(q=>q.d).join(" "))},pos:tt,mark:"inbetween",span:[D,Ye(D+j)],...A.group?{group:void 0}:{}})}p=p.map(_=>_.id===A.id||_.id===z.id?{..._,mark:_.mark??"key"}:_).map(_=>{if(_.group===void 0&&"group"in _){const{group:J,...tt}=_;return tt}return _}),$=`${y} in-between(s) drawn between frames ${h+1} and ${k+1} (${C})`;break}case"clone":{if(g<0)throw Error(`${n}: no drawing on that frame to clone`);if(p.length>=tr.items)throw Error(`${n}: this layer already holds ${tr.items} drawings — continue on a new frame layer`);const k=p[g],y=Ye(k.span[1]-k.span[0]),C=k.group??`ln${k.id}`.slice(0,16);p=Va(p,k.span[1],y).map((A,z)=>z===g?{...A,group:C}:A),p.push({...structuredClone(k),id:ec(p),group:C,name:`${k.name} ↻`.slice(0,40),span:[k.span[1],Ye(k.span[1]+y)]}),$=`frame ${h+1} cloned (live)`;break}case"unlink":{if(g<0||!p[g].group)throw Error(`${n}: frame ${h+1} is not a live copy`);const{group:k,...y}=p[g];p=p.map((C,A)=>A===g?y:C),$=`frame ${h+1} is its own drawing again`;break}}if(["draw","erase","undoLine","transform"].includes(e.action)){const k=m?p.find(y=>y.id===m.id):p.at(-1);if(k?.group)p=p.map(y=>y.group===k.group&&y.id!==k.id?{...y,params:structuredClone(k.params),pos:k.pos,stroke:k.stroke}:y);else if(m&&!k&&t.items.find(y=>y.id===m.id)?.group){const y=t.items.find(C=>C.id===m.id).group;p=p.filter(C=>C.group!==y)}}if(p.some(k=>k.span&&k.span[0]<0))throw Error(`${n}: a frame would start before the layer`);const S=p.reduce((k,y)=>Math.max(k,y.span?.[1]??0),0);return{shape:{...t,items:p},end:Ye(S),note:$}}const Vu=Object.freeze(["ink","sweep","speed","tear","swirl"]),JT=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"]}),eC=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"}}),Gu=Object.freeze({duration:[.4,2.5],fps:[12,24]}),jg=/^#[0-9a-f]{6}$/i,Ku=Number.isFinite,xp=t=>Math.round(t*1e4)/1e4,si=(t,e)=>[xp(Math.max(-1,Math.min(2,t))),xp(Math.max(-1,Math.min(2,e)))],An=t=>t<=0?0:t>=1?1:t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;function ks(t){let e=t*2654435761>>>0||1;return()=>(e^=e<<13,e>>>=0,e^=e>>>17,e^=e<<5,e>>>=0,e/4294967296)}function Di(t,e,o,r,a,n,i=40){const c=ks(a),u=[c()*6.3,c()*6.3,c()*6.3],p=[];for(let s=0;s<i;s++){const h=s/i*2*Math.PI,f=o*(1+r*(.5*Math.sin(3*h+u[0])+.28*Math.sin(5*h+u[1])+.16*Math.sin(11*h+u[2])+.1*Math.sin(19*h+u[0]*2)+(c()-.5)*.35));p.push(si(t+Math.cos(h)*f/n,e+Math.sin(h)*f))}return p}const gs=[[-.05,-.05],[1.05,-.05],[1.05,1.05],[-.05,1.05]],Xb=t=>({points:gs,fill:t,line:!1,smooth:!1});function oC(t,{c1:e,c2:o,o:r,A:a,seed:n}){const i=[],c=t<.5,u=An(c?t*2:(t-.5)*2),p=1.2*Math.max(...[[0,0],[1,0],[0,1],[1,1]].map(([s,h])=>Math.hypot((s-r[0])*a,h-r[1])));if(c){const s=Math.max(.02,p*u);i.push({points:Di(r[0],r[1],s*1.12+.02,.22,n+1,a),fill:o,opacity:.45,line:!1}),i.push({points:Di(r[0],r[1],s,.22,n,a,56),fill:e,line:!1});const h=ks(n+7);for(let f=0;f<10;f++){const m=h()*6.3,g=s*(.25+h()*.5),v=.012+h()*.03,x=s*.92,E=[r[0]+Math.cos(m)*(x+g)/a,r[1]+Math.sin(m)*(x+g)],$=[r[0]+Math.cos(m-v/Math.max(.05,x))*x/a,r[1]+Math.sin(m-v/Math.max(.05,x))*x],S=[r[0]+Math.cos(m+v/Math.max(.05,x))*x/a,r[1]+Math.sin(m+v/Math.max(.05,x))*x];i.push({points:[si(...$),si(...E),si(...S)],fill:e,line:!1,smooth:!1})}for(let f=0;f<14;f++){const m=h()*6.3,g=s*(1.1+h()*.7),v=(.006+h()*.035)*(.5+u);i.push({points:Di(r[0]+Math.cos(m)*g/a,r[1]+Math.sin(m)*g,v,.3,n+20+f,a,12),fill:e,line:!1})}u>.92&&i.push(Xb(e))}else{const s=Math.max(.01,p*u);i.push({loops:[gs,Di(r[0],r[1],s*.94,.16,n+3,a)],fill:o,opacity:.5,line:!1,eo:!0}),i.push({loops:[gs,Di(r[0],r[1],s,.18,n+2,a)],fill:e,line:!1,eo:!0})}return i}function rC(t,{c1:e,c2:o,angle:r,seed:a}){const n=r*Math.PI/180,i=Math.cos(n),c=Math.sin(n),u=t<.5,p=An(u?t*2:(t-.5)*2),s=1.6,h=-.8+s*p,f=([x,E])=>si(.5+x*i-E*c,.5+x*c+E*i),m=ks(a),g=[],v=(x,E)=>{const $=[];for(let S=0;S<=24;S++){const k=-.9+1.8*S/24;$.push([x+E*(Math.sin(S*1.7+a)*.012+(m()-.5)*.02),k])}return $};if(u){const x=v(h,1);g.push({points:[[-1,-.9],...x,[-1,.9]].map(f),fill:e,line:!1,smooth:!1});for(let E=0;E<16;E++){const $=-.9+1.8*(E+.5)/16+(m()-.5)*.04,S=.03+m()*.12*(1-Math.abs(p-.5)),k=.006+m()*.01;g.push({points:[[h-.02,$-k],[h+S,$],[h-.02,$+k]].map(f),fill:E%3?e:o,line:!1,smooth:!1})}p>.05&&p<.95&&g.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=v(h,-1);g.push({points:[...x,[1,.9],[1,-.9]].map(f),fill:e,line:!1,smooth:!1});for(let E=0;E<12;E++){const $=-.9+1.8*(E+.5)/12+(m()-.5)*.05,S=.04+m()*.1,k=.005+m()*.009;g.push({points:[[h+.02,$-k],[h-S,$],[h+.02,$+k]].map(f),fill:e,line:!1,smooth:!1})}}return g}function nC(t,{c1:e,c2:o,o:r,A:a,seed:n}){const i=t<.5,c=An(i?t*2:(t-.5)*2),u=ks(n),p=[],s=26,h=i?1.4*(1-c):1.4*c,f=i?c:1-c;f>.05&&p.push({points:gs,fill:o,opacity:Math.max(.02,Math.min(1,f*1.1)),line:!1,smooth:!1});for(let m=0;m<s;m++){const g=(m+u()*.6)/s*2*Math.PI,v=.025+u()*.04,x=h*(.7+u()*.5),E=2,$=(S,k)=>si(r[0]+Math.cos(g+k)*S/a,r[1]+Math.sin(g+k)*S);p.push({points:[$(E,-v),$(Math.max(.001,x),0),$(E,v)],fill:m%4===0?o:e,opacity:i?Math.min(1,.4+c):Math.max(.05,1-c),line:!1,smooth:!1})}return Math.abs(t-.5)<.06&&p.push({points:gs,fill:e,line:!1,smooth:!1}),p.slice(0,64)}function aC(t,{c1:e,c2:o,seed:r}){const a=[],n=t<.5,i=An(n?t*2:(t-.5)*2),c=(u,p,s)=>{const h=ks(p),f=[];for(let m=0;m<=30;m++)f.push([u+s*((h()-.5)*.03+(m%2?.012:0)),-.05+1.1*m/30]);return f};if(n){const u=1.08-1.13*i,p=(1-i)*.03,s=c(u,r,1).map(([h,f])=>[h+p*(f-.5),f]);a.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}),a.push({points:[...s,[1.1,1.05],[1.1,-.05]],fill:e,line:!1,smooth:!1}),a.push({points:[...s,...s.slice().reverse().map(([h,f])=>[h+.012,f])],fill:o,opacity:.8,line:!1,smooth:!1})}else{const u=.62*i,p=c(.5,r+5,1),s=[[-.1,-.05],...p.map(([f,m])=>[f-u-0+(m-.5)*i*.06,m]),[-.1,1.05]],h=[...p.map(([f,m])=>[f+u+(m-.5)*-i*.06,m]),[1.1,1.05],[1.1,-.05]];for(const f of[s,h])a.push({points:f,fill:e,line:!1,smooth:!1});a.push({points:[...p.map(([f,m])=>[f-u+(m-.5)*i*.06,m]),...p.slice().reverse().map(([f,m])=>[f-u-.012+(m-.5)*i*.06,m])],fill:"#ffffff",opacity:.85,line:!1,smooth:!1}),a.push({points:[...p.map(([f,m])=>[f+u-(m-.5)*i*.06,m]),...p.slice().reverse().map(([f,m])=>[f+u+.012-(m-.5)*i*.06,m])],fill:"#ffffff",opacity:.85,line:!1,smooth:!1})}return a}function Tg(t,e,o,r,a,n,i,c,u){const s=[],h=[],f=Math.cos(a),m=Math.sin(a);for(let g=0;g<=18;g++){const v=g/18,x=n+i*v,E=c*Math.pow(Math.sin(Math.PI*Math.min(1,v*1.15)),.7);for(const[$,S]of[[s,1],[h,1-E]]){const k=Math.cos(x)*o*S,y=Math.sin(x)*r*S;$.push(si(t+(k*f-y*m)/u,e+k*m+y*f))}}return[...s,...h.reverse()]}function iC(t,{c1:e,c2:o,o:r,A:a,seed:n}){const i=t<.5,c=An(i?t*2:(t-.5)*2),u=[],p=ks(n),s=(i?c:1+c)*Math.PI*2.4,h=.35+(i?c:1-c)*.6,f=i?.25+c*.75:1-c*.8;for(let m=0;m<4;m++){const g=h*(.55+m*.17),v=s+m*1.3+p()*.2,x=Math.PI*(1.1+.25*m);u.push({points:Tg(r[0],r[1],g*1.06,g*.62,.25,v-.1,x*1.03,Math.min(.95,f*1.1),a),fill:e,opacity:.28,line:!1}),u.push({points:Tg(r[0],r[1],g,g*.58,.25,v,x,Math.min(.95,f),a),fill:m%2?o:e,line:!1})}if(i&&c>.85&&u.push(Xb(e)),!i){const m=Math.max(.01,c*1.4);u.unshift({loops:[gs,Di(r[0],r[1],m,.12,n+9,a)],fill:e,line:!1,eo:!0})}return u}const sC={ink:oC,sweep:rC,speed:nC,tear:aC,swirl:iC};function lC(t,{aspect:e=16/9}={}){const o="drawnTransition";if(!t||typeof t!="object")throw Error(`${o}: {kind ${Vu.join("|")}, duration?, …}`);const r=t.kind??"ink";if(!Vu.includes(r))throw Error(`${o} kind: ${Vu.join(" | ")}`);const a=t.duration??1;if(!(Ku(a)&&a>=Gu.duration[0]&&a<=Gu.duration[1]))throw Error(`${o} duration: ${Gu.duration.join("–")} s (the frame is covered at the middle, on the cut)`);const n=t.fps??24;if(![12,24].includes(n))throw Error(`${o} fps: 24 (every frame) | 12 (on twos, the anime look)`);const i=eC[r],c=t.color??i.color,u=t.color2??i.color2;if(!jg.test(c)||!jg.test(u))throw Error(`${o} color / color2: #RRGGBB`);const p=t.from??[.5,.5];if(!Array.isArray(p)||p.length!==2||!p.every(m=>Ku(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(!(Ku(s)&&s>=-80&&s<=80))throw Error(`${o} angle: −80..80 degrees (the sweep's tilt)`);const h=Math.max(6,Math.round(a*n)),f=e;return Array.from({length:h},(m,g)=>{const v=h>1?g/(h-1):.5,x=1e3+Math.floor(g/(n===24?2:1))*37,$=sC[r](v,{c1:c,c2:u,o:p,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:y,...C}=S;return C}return{...S,opacity:Math.max(.02,k)}});return{parts:$.length?$:[{points:[[.5,.5],[.501,.5],[.5,.501]],fill:c,opacity:.02,line:!1}]}})}const cC=(t,e)=>({start:Math.max(0,xp(t-e/2)),cut:xp(t)}),Og=Object.freeze([...x1,...yh,"still","morph","boil","step"]),Te=Object.freeze({paths:tr.items,points:tr.points,d:4e3,items:tr.items}),vo=/^#[0-9a-fA-F]{6}$/,Ht=t=>Number.isFinite(t),jo=(t,e,o)=>Math.max(e,Math.min(o,t)),Le=t=>Math.round(t*10)/10;function Ub(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,a]of Object.entries(t||{}))a!=null&&r!=="prompt"&&(o[r]=a);return o}const Rn=t=>Array.isArray(t?.size)?t.size:t?.square?[720,720]:[1280,720],cn=(t,e,o)=>{if(!Array.isArray(t)||t.length!==2||!t.every(r=>Ht(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},Mn=/-?\d*\.?\d+(?:e[-+]?\d+)?/gi;function Yb(t,e){if(typeof t!="string"||t.length>Te.d||!/^\s*M[MLCQZ0-9eE.,\s+-]*$/.test(t))throw Error(`drawShape d: absolute SVG path data (M L C Q Z only), at most ${Te.d} characters, coordinates 0..1 of the frame`);const o=[...t.matchAll(Mn)].map(n=>Number(n[0]));if(o.length%2||!o.length)throw Error("drawShape d: coordinates come in x y pairs");const r=[];for(let n=0;n<o.length;n+=2){const i=e.pt(cn([o[n],o[n+1]],n/2,"drawShape d"));r.push(Math.round(i[0]),Math.round(i[1]))}let a=0;return t.replace(Mn,()=>String(r[a++]))}function pC(t){const[e,o,r,a]=mr(t),n=Le((e+r)/2),i=Le((o+a)/2);let c=0;const u=t.replace(Mn,p=>String(Math.round(Number(p)-(c++%2?i:n))));return{d:u,pos:[n,i],box:mr(u)}}function qb(t,e,o,r,a){if(!t||typeof t!="object"||Array.isArray(t))throw Error(`drawShape paths[${r}] must be an object`);const n=t.color??"#2d3142",i=t.fill??null,c=t.brush??"marker";if(!vo.test(n))throw Error(`drawShape paths[${r}].color must be #RRGGBB`);const u=i&&typeof i=="object"&&!Array.isArray(i);if(u&&!(Array.isArray(i.stops)&&i.stops.length>=2&&i.stops.length<=8&&i.stops.every(E=>Array.isArray(E)&&E.length===2&&vo.test(E[0])&&Ht(E[1])&&E[1]>=0&&E[1]<=1)&&(i.angle==null||Ht(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&&!u&&!vo.test(i))throw Error(`drawShape paths[${r}].fill must be #RRGGBB, a gradient {stops, angle?} or null`);if(t.opacity!=null&&!(Ht(t.opacity)&&t.opacity>=0&&t.opacity<=1))throw Error(`drawShape paths[${r}].opacity is 0–1`);if(c!=="none"&&!ol.includes(c))throw Error(`drawShape brush must be none | ${ol.join(" | ")}`);if(t.texture!=null&&(!$2(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 p=t.width==null?.006:Number(t.width);if(!Ht(p)||p<0||p>.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&&!(Ht(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=li(e);let h,f;if(t.d!=null){const E=pC(Yb(t.d,o));if(!E2(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>Te.points)throw Error(`drawShape paths[${r}]: points [[x,y]…] (2–${Te.points}, 0..1 of the frame) or d`);const $=E.map((z,j)=>o.pt(cn(z,j,`drawShape paths[${r}]`))),S=$.map(z=>z[0]),k=$.map(z=>z[1]),y=Le((Math.min(...S)+Math.max(...S))/2),C=Le((Math.min(...k)+Math.max(...k))/2),A=t.closed??!!i;h={pts:v1($.map(z=>[z[0]-y,z[1]-C]),{smooth:t.smooth!==!1,closed:A}),closed:A},f=[y,C]}const m=c==="none"?void 0:{style:c,...t.taper!=null?{taper:t.taper}:{},...t.press!=null?{press:t.press}:{},...t.boil?{boil:t.boil}:{},seed:r+1},g=o.len(p),v=()=>u?{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??(a?`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?v():{type:"none"},stroke:g>0?{color:n,width:jo(Le(g),.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 uC(t,e,o,r){if(t.solids==null)return[];if(!Array.isArray(t.solids)||t.solids.length>Js.solids)throw Error(`drawShape solids: [{kind, at, size, …}] (≤ ${Js.solids})`);if(t.view!=null&&!wp[t.view]&&t.view!=="perspective")throw Error(`drawShape view: ${[...Object.keys(wp),"perspective"].join(" | ")}`);if(t.view==="perspective"){const[c,u]=[o.k*1e3+2*o.ox,o.k*1e3+2*o.oy].map(Math.round),p=Zb(t),s=t.solids.map((m,g)=>Vb(m,g)),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:g}of Gb(s,{vanish:p,W:c,H:u})){if(!g.length)continue;const v=g.map(A=>({d:"M"+A.pts.map(z=>o.pt(z).map(Math.round).join(" ")).join(" L")+" Z",fill:A.fill,line:!1,role:7})),x=v.flatMap(A=>A.d.match(/-?\d+/g).map(Number)),E=x.filter((A,z)=>z%2===0),$=x.filter((A,z)=>z%2===1),S=Math.round((Math.min(...E)+Math.max(...E))/2),k=Math.round((Math.min(...$)+Math.max(...$))/2),y=v.map(A=>{let z=0;return{...A,d:A.d.replace(/-?\d+/g,j=>String(Number(j)-(z++%2?k:S)))}}),C=li([...e,...h]);h.push({id:C,name:m.name??`${f[m.kind][r?0:1]} ${e.length+h.length+1}`,type:"art",params:{parts:y,box:[Math.min(...E)-S,Math.min(...$)-k,Math.max(...E)-S,Math.max(...$)-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&&!vo.test(t.shadowColor))throw Error("drawShape shadowColor: #RRGGBB");const a=t.solids.map((c,u)=>({s:zA(c,u),i:u}));t.order!=="given"&&a.sort((c,u)=>(u.s.kind==="plane"&&!u.s.z)-(c.s.kind==="plane"&&!c.s.z)||c.s.at[1]-u.s.at[1]||c.s.z-u.s.z||c.i-u.i);const n=[],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:c}of a){const u=PA(c,o,{view:t.view??"iso",light:t.light??"left",shadowColor:t.shadowColor??"#1e1719"}),p=li([...e,...n]);n.push({id:p,name:c.name??`${i[c.kind][r?0:1]} ${e.length+n.length+1}`,type:"art",params:{parts:u.parts,box:u.box,outline:!1},pos:u.pos,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:c.color},stroke:null,role:7})}return n}const Wu=Object.freeze(["band","brush","iris","slats","grid"]);function dC(t,{target:e,B:o,size:r,en:a,finish:n}){const i=t.wipe;if(!i||typeof i!="object"||Array.isArray(i))throw Error(`drawShape wipe: {style ${Wu.join("|")}, duration?, color?, color2?, count?, at?}`);const c=i.style??"band";if(!Wu.includes(c))throw Error(`drawShape wipe.style: ${Wu.join(" | ")}`);const u=i.duration??t.duration??.9;if(!(Ht(u)&&u>=.2&&u<=4))throw Error("drawShape wipe.duration: 0.2–4 s (the frame is covered at the middle)");const p=i.color??"#c8202f",s=i.color2??p;if(!vo.test(p)||!vo.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=>Ht(k)&&k>=-.5&&k<=1.5))throw Error("drawShape wipe.at: [x, y] (the iris centre, 0..1)");const f=i.count??(c==="slats"?7:c==="grid"||c==="brush"?6:4);if(!(Number.isInteger(f)&&f>=2&&f<=12))throw Error("drawShape wipe.count: 2–12");const m=u/2,g=[...e.items],v=[],x=[],E=(k,y)=>{const C=qb({brush:"none",width:0,smooth:!1,...k},g,o,g.length,a);g.push(C),v.push(C.id),x.push(y)},$=Yt["expo-in-out"];if(c==="band"){const k=Math.tan((i.angle??20)*Math.PI/180)*.7,y=.5+k+.05;E({points:[[.5-y+k,-.2],[.5+y+k,-.2],[.5+y-k,1.2],[.5-y-k,1.2]],fill:p},{move:[{t:0,dx:-(2*y+k),ease:"ease-in-out"},{t:u,dx:2*y+k}]})}else if(c==="brush"){const k=1/f;for(let y=0;y<f;y++){const C=k*(y+.5),A=y%2?.012:-.012;E({points:[[-.15,C+A],[.3,C-A],[.7,C+A],[1.15,C-A]],color:y%2?s:p,width:.06,brush:"marker",smooth:!0},{trim:[y*m/f*.55,m*.55+y*m/f*.45,m+y*m/f*.45,u]});const z=g.length-1;g[z]={...g[z],stroke:{...g[z].stroke,width:Math.min(240,Math.round(o.len(k*1.25*.5625)))}}}}else if(c==="iris"){const y=h[0],C=h[1],A=Array.from({length:24},(z,j)=>{const P=j/24*2*Math.PI;return[y+Math.cos(P)*1.25*.5625,C+Math.sin(P)*1.25]});E({points:A,fill:p,smooth:!0},{scale:[{t:0,v:0,ease:"expo-in"},{t:m,v:1,ease:"expo-out"},{t:u,v:0}]})}else if(c==="slats")for(let k=0;k<f;k++){const y=k/f,C=(k+1)/f+.002;E({points:[[y,-.05],[C,-.05],[C,1.05],[y,1.05]],fill:k%2?s:p},{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(u,m+m*.6+k*m*.4/f),sx:0,sy:1}]})}else{const k=f,y=Math.max(2,Math.round(f*9/16));for(let C=0;C<y;C++)for(let A=0;A<k;A++){const z=A/k,j=C/y,P=(A+1)/k+.003,F=(C+1)/y+.003,N=(A+C)/(k+y-2);if(g.length-e.items.length>=Te.items)break;E({points:[[z,j],[P,j],[P,F],[z,F]],fill:(A+C)%2?s:p},{scale:[{t:0,v:0,ease:"back-out"},{t:m*.5+N*m*.5,v:1},{t:m+N*m*.45,v:1,ease:"expo-in"},{t:Math.min(u,m+m*.5+N*m*.45),v:0}]})}}if(g.length>Te.items)throw Error(`drawShape wipe: too many pieces (max ${Te.items})`);let S={...e,items:g};return v.forEach((k,y)=>{const C=x[y];if(C.trim){const[A,z,j,P]=C.trim.map(F=>Math.round(F*1e4)/1e4);S={...S,items:S.items.map(F=>F.id!==k?F:{...F,ops:[{op:"trim",start:0,end:1,offset:0}],keys:{"ops.0.end":[{time:A,value:0,ease:$},{time:z,value:1}],"ops.0.start":[{time:j,value:0,ease:$},{time:P,value:1}]}})}}else S={...S,items:Qb(S,[k],C,{stagger:0,add:!1,dur:u,B2:o})}}),{patches:[],layer:{shape:n(S,v,{colors:"keep"}),label:String(t.label??(a?"Transition":"Chuyển cảnh")).slice(0,60),duration:u},note:`drawShape wipe ${c}: covers at ${Math.round((hC(t.start)+m)*100)/100}s (cut there), ${u}s`}}const hC=t=>Number.isFinite(t)?t:0,Zb=t=>{const e=t.vanish??[.5,.45];if(!Array.isArray(e)||e.length!==2||!e.every(o=>Ht(o)&&o>=-.5&&o<=1.5))throw Error("drawShape vanish: [x, y] of the vanishing point (0..1 of the frame)");return e};function fC(t,{size:e,en:o,finish:r,W:a,H:n}){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>ma.solids)throw Error(`drawShape solids: 1–${ma.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[c,u]=ma.fly;for(const S of["to","from"])if(i[S]!=null&&!(Ht(i[S])&&i[S]>=c&&i[S]<=u))throw Error(`drawShape fly.${S}: ${c}–${u} depth units`);if(!(Ht(i.duration)&&i.duration>=.2&&i.duration<=20))throw Error("drawShape fly.duration: 0.2–20 s");const p=i.fps??24;if(!(Number.isInteger(p)&&p>=8&&p<=24))throw Error("drawShape fly.fps: 8–24");const s=Jb(i.ease??"easy-ease","drawShape fly"),h=Zb(t),f=t.solids.map((S,k)=>Vb(S,k)),m=i.from??0,g=i.to??2,v=Math.max(2,Math.min(wo.frames,Math.round(i.duration*p))),x=[],E=Array.isArray(s)?s:null;for(let S=0;S<v;S++){const k=S/(v-1),y=E?mC(E,k):k,C=Gb(f,{vanish:h,cam:m+(g-m)*y,W:a,H:n}).flatMap(A=>A.parts).filter(A=>A.pts.length>=3).map(A=>({points:A.pts,fill:A.fill,smooth:!1,line:!1}));if(C.length>wo.parts)throw Error(`drawShape fly: ${C.length} shapes in a frame (max ${wo.parts}) — fewer doors / lines / copies`);x.push({parts:C.length?C:[{points:[[0,0],[0,0],[0,0]],fill:"#000000",smooth:!1}]})}const $=Bi({start:t.start,fps:p,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{...$,note:`drawShape fly: camera ${m}→${g} in ${i.duration}s — ${$.note}`}}function mC([t,e,o,r],a){const n=(u,p,s)=>3*u*(1-s)**2*s+3*p*(1-s)*s*s+s**3;let i=0,c=1;for(let u=0;u<30;u++){const p=(i+c)/2;n(t,o,p)<a?i=p:c=p}return n(e,r,(i+c)/2)}const zg=Object.freeze(["move","rot","scale","opacity","color","morph"]),Jb=(t,e)=>{if(t==null)return;const o=typeof t=="string"?Yt[t]:t;if(o==null)throw Error(`${e}.ease: ${Object.keys(Yt).join(" | ")} or [x1,y1,x2,y2]`);return od(o)};function gC(t,e,o){const r=o?[...t,t[0]]:t,a=[];let n=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]);a.push(h),n+=h}if(!(n>0))return Array.from({length:e},()=>[...t[0]]);const i=[],c=n/(o?e:e-1);let u=0,p=0;for(let s=0;s<e;s++){const h=Math.min(n,s*c);for(;u<a.length-1&&p+a[u]<h;)p+=a[u],u++;const f=a[u]?(h-p)/a[u]:0;i.push([r[u][0]+(r[u+1][0]-r[u][0])*f,r[u][1]+(r[u+1][1]-r[u][1])*f])}return i}function Qb(t,e,o,{stagger:r,add:a,dur:n,B2:i}){if(!o||typeof o!="object"||Array.isArray(o)||!Object.keys(o).length||Object.keys(o).some(g=>!zg.includes(g)))throw Error(`animateShape keys: {${zg.join(" | ")}: [{t (clip s), …, ease?}]}`);const[c,u]=Rn(t),p=i.k,s=g=>(g*c-i.ox)/p,h=g=>(g*u-i.oy)/p,f=g=>Math.round(g*100)/100;let m=0;return t.items.map(g=>{if(!e.includes(g.id))return g;const v=r*m++,x={...g.keys||{}},E=($,S)=>{const k=a?(x[$]||[]).filter(y=>!S.some(C=>Math.abs(C.time-y.time)<.008333333333333333)):[];if(x[$]=[...k,...S].sort((y,C)=>y.time-C.time),x[$].length>tr.keys)throw Error(`animateShape keys: at most ${tr.keys} keys per property`)};for(const[$,S]of Object.entries(o)){const k=`animateShape keys.${$}`;if(!Array.isArray(S)||!S.length||S.length>tr.keys)throw Error(`${k}: 1–${tr.keys} keys [{t, …}]`);let y=-1;const C=S.map((z,j)=>{if(!z||typeof z!="object"||!Ht(z.t)||z.t<0||z.t>600)throw Error(`${k}[${j}].t: clip-local seconds (0 = the layer's start)`);const P=Math.round(Math.min(z.t+v,Math.max(0,n))*1e4)/1e4;if(P<=y)throw Error(`${k}: times must increase`);return y=P,{q:z,time:P,ease:Jb(z.ease,`${k}[${j}]`)}}),A=z=>C.map(({q:j,time:P,ease:F},N)=>({time:P,value:z(j,N),...F!==void 0?{ease:F}:{}}));if($==="move"){const z=A((P,F)=>{if(P.x!=null){if(!Ht(P.x))throw Error(`${k}[${F}].x`);return f(s(P.x))}if(P.dx!=null&&!Ht(P.dx))throw Error(`${k}[${F}].dx`);return f(g.pos[0]+(P.dx??0)*c/p)}),j=A((P,F)=>{if(P.y!=null){if(!Ht(P.y))throw Error(`${k}[${F}].y`);return f(h(P.y))}if(P.dy!=null&&!Ht(P.dy))throw Error(`${k}[${F}].dy`);return f(g.pos[1]+(P.dy??0)*u/p)});E("pos.0",z),E("pos.1",j)}else if($==="rot")E("rot",A((z,j)=>{if(!Ht(z.v))throw Error(`${k}[${j}].v: degrees added to its rest rotation`);return f((g.rot||0)+z.v)}));else if($==="scale"){const z=j=>(P,F)=>{const N=P[j]??P.v;if(!(Ht(N)&&Math.abs(N)<=10))throw Error(`${k}[${F}]: v (× its size) or sx / sy, -10..10`);return f((g.scale?.[j==="sx"?0:1]??1)*N)};E("scale.0",A(z("sx"))),E("scale.1",A(z("sy")))}else if($==="opacity")E("opacity",A((z,j)=>{if(!(Ht(z.v)&&z.v>=0&&z.v<=1))throw Error(`${k}[${j}].v: 0–1`);return z.v}));else if($==="color"){const z=g.fill?.type==="color"&&g.type!=="art"?"fill.color":g.stroke?"stroke.color":null;if(!z)throw Error(`${k}: item ${g.id} has no plain fill or line colour to key`);E(z,A((j,P)=>{if(!vo.test(j.v??""))throw Error(`${k}[${P}].v: #RRGGBB`);return j.v}))}else if($==="morph"){if(g.type!=="path"||!g.params?.pts)throw Error(`${k}: item ${g.id} is not a point path (draw it with points)`);const z=C.map(({q:F},N)=>{if(!Array.isArray(F.points)||F.points.length<2||F.points.length>Te.points)throw Error(`${k}[${N}].points: [[x,y]…] (0..1 of the frame)`);return F.points.map((G,V)=>(cn(G,V,`${k}[${N}]`),[s(G[0])-g.pos[0],h(G[1])-g.pos[1]]))}),j=Math.min(Te.points,Math.max(...z.map(F=>F.length),g.params.closed?12:4)),P=z.map(F=>v1(gC(F,j,!!g.params.closed).map(N=>[f(N[0]),f(N[1])]),{smooth:!0,closed:!!g.params.closed}));E("params.pts",A((F,N)=>P[N]))}}return{...g,keys:x}})}const Ti=t=>{if(!t||!bh(t.shape))throw Error("Needs a Shape layer (clipId of a shape v2 layer)");return t.shape},Hu=(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(a=>a.id===r))throw Error(`${o}: no item ${String(r).slice(0,20)} in this layer`);return e};function Fh(t,e){const o=Ub(t),r=!!e.en,a=x2(e.W||1280,e.H||720);if(o.style!=null&&!_p(o.style))throw Error(`Unknown 2D style "${String(o.style).slice(0,40)}". Styles: ${Hh.join(", ")}`);const n=o.clipId?e.find(o.clipId):null;if(o.clipId&&!n)throw Error("Clip not found");const i=n&&o.op!=="traceMotion"&&o.op!=="rotoscope"?Ti(n):{v:2,size:a,items:[]},c=on(Rn(i)),u=(p,s,{colors:h=null}={})=>{const f=o.style??p.style2d,m=f?qh(p,f,{itemIds:n?s:null,timing:!n||o.style!=null,colors:h??(o.colors==="keep"?"keep":null)}):p;return Ze(m)};switch(o.op){case"drawShape":{if(o.fly!=null)return fC(o,{size:a,en:r,finish:u,W:e.W||1280,H:e.H||720});if(o.wipe!=null)return dC(o,{target:i,B:c,size:a,en:r,finish:u});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 p=Array.isArray(o.paths)?o.paths:o.d!=null||o.points!=null?[o]:o.solids!=null?[]:null;if(!p)throw Error("drawShape needs paths [{points | d, …}] or solids [{kind, at, size, …}]");if(p.length>Te.paths)throw Error(`drawShape: at most ${Te.paths} paths per op`);const s=[...i.items],h=[];for(const m of uC(o,s,c,r))s.push(m),h.push(m.id);if(p.forEach((m,g)=>{const v=qb(m,s,c,g,r);s.push(v),h.push(v.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[$,S,k]of[["at",0,600],["duration",.05,10],["stagger",0,5]])if(m[$]!=null&&!(Ht(m[$])&&m[$]>=S&&m[$]<=k))throw Error(`drawShape write.${$}: ${S}–${k} s`);const g=m.at??0,v=m.duration??.5,x=m.stagger??v*.6;let E=0;for(let $=0;$<s.length;$++){const S=s[$];if(!h.includes(S.id)||S.type!=="path")continue;const k=g+x*E++;let y=S.stroke?Yh(S,"draw-on",{at:k,duration:v}):S;m.fill!==!1&&y.fill?.type==="color"&&(y={...y,keys:{...y.keys||{},"fill.opacity":[{time:Math.round(k*1e4)/1e4,value:0},{time:Math.round((k+v*.65)*1e4)/1e4,value:0,ease:Yt["ease-out"]},{time:Math.round((k+v)*1e4)/1e4,value:1}]}}),s[$]=y}}if(s.length>Te.items)throw Error(`A Shape layer holds up to ${Te.items} items — draw into a new layer (leave clipId out)`);const f=u({...i,items:s},h);return n?{patches:[{id:n.id,shape:f}],note:`drawShape: ${h.length} item(s) → ${n.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 p=Array.isArray(o.items)&&o.items.length&&typeof o.items[0]=="object"?o.items:o.libraryId||o.id?[o]:null;if(!p)throw Error("addLibraryShape needs items [{id (from search_shape_library), x, y, size?}]");if(p.length>Te.items)throw Error(`addLibraryShape: at most ${Te.items} items per op`);const s=[...i.items],h=[],[f,m]=Rn(i),g=Math.min(f,m)/1e3;if(p.forEach((x,E)=>{const $=x.libraryId??x.id,S=x.x??.5,k=x.y??.5;cn([S,k],E,"addLibraryShape");const y=x.size??.25;if(!(Ht(y)&&y>=.02&&y<=1.5))throw Error("addLibraryShape size = height as a fraction of the frame, 0.02–1.5");const C=x.rotation??0;if(!(Ht(C)&&Math.abs(C)<=360))throw Error("addLibraryShape rotation is degrees");const A=Lb($,{id:li(s),pos:c.pt([S,k]),colors:x.colors??null,en:r}),z=Math.max(1,A.params.box[3]-A.params.box[1]),j=jo(Le(y*m/g/z*100)/100,.02,10),P={...A,rot:Le(C),scale:[x.flip?-j:j,j],...x.name?{name:String(x.name).slice(0,40)}:{},...Array.isArray(x.span)?{span:x.span}:{}};s.push(P),h.push(P.id)}),s.length>Te.items)throw Error(`A Shape layer holds up to ${Te.items} items — add into a new layer (leave clipId out)`);const v=u({...i,items:s},h);return n?{patches:[{id:n.id,shape:v}],note:`addLibraryShape: ${h.length} → ${n.label}`}:{patches:[],layer:{shape:v,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: ${Hh.join(", ")}`);const s=(Array.isArray(o.clipIds)&&o.clipIds.length?o.clipIds:o.clipId?[o.clipId]:e.clips.filter(m=>bh(m.shape)&&!tw(m)).map(m=>m.id)).map(m=>{const g=e.find(m);if(!g)throw Error(`Clip ${String(m).slice(0,30)} not found`);return Ti(g),g}).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:Ze(qh(m.shape,o.style,{itemIds:o.itemIds&&o.clipId?Hu(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(v=>v.start)),g=Math.max(...s.map(v=>v.start+v.duration));f={shape:Ze(k2(o.style,a)),label:`${r?"Paper":"Giấy"} · ${r?_p(o.style).en:_p(o.style).vi}`.slice(0,60),start:m,duration:g-m}}return{patches:h,paper:f,note:`applyStyle2d ${o.style}: ${h.length} layer(s)${f?" + paper":""}`}}case"animateShape":{let p=Ti(n);const s=Hu(p,o.itemIds,"animateShape"),h=S=>Math.max(0,Math.min(n.duration,(S??n.start)-n.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(!b2(S))throw Error("animateShape boil = {amount 0–24 (frame units ×1000), fps 1–24}");const k={...p,boil:S};return S.amount||delete k.boil,{patches:[{id:n.id,shape:Ze(k)}],note:`boil ${S.amount}@${S.fps}fps: ${n.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={...p,step:S};return S===1&&delete k.step,{patches:[{id:n.id,shape:Ze(k)}],note:`on ${S}s: ${n.label}`}}const m=h(o.at),g=Ht(o.duration)?o.duration:1,v=Ht(o.stagger)?jo(o.stagger,0,5):0;if(o.keys!=null){const S=Qb(p,s,o.keys,{stagger:v,add:o.add===!0,dur:n.duration,B2:on(Rn(p))});return{patches:[{id:n.id,shape:Ze({...p,items:S})}],note:`keys ${Object.keys(o.keys).join(", ")}: ${s.length} item(s) of ${n.label}`}}if(f==null&&o.pivot==null&&o.parent==null)throw Error(`animateShape preset: ${Og.join(" | ")}`);const x=yh.includes(f)||f==="still"||f==null;if(x||o.pivot!=null||o.parent!=null){if(o.parent!=null&&!(typeof o.parent=="string"&&p.items.some(P=>P.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=on(Rn(p)),k=M1[f],y=Ht(o.amount)?jo(o.amount,0,8):1,C=Ht(o.period)?jo(o.period,.1,60):null,A=s.length;let z=0;const j=p.items.map(P=>{if(!s.includes(P.id))return P;let F={...P};o.parent!=null&&(F.parent=o.parent);const N=o.pivot??(k&&!P.pivot?k.pivot:null);if(N!=null&&(F=nh(F,rh(F,N,S))),f==="still"){const{motion:G,...V}=F;return V}if(k&&x){const G=C??k.period,V=A>1?v?z*v/G%1:f==="rise"?z/A:0:0,et={type:f,...y!==1?{amount:Math.round(k.amount*y*1e4)/1e4}:{},...C?{period:C}:{},...V?{phase:Math.round(V*1e3)/1e3}:{},...o.at!=null&&m>0?{delay:Math.round(m*1e3)/1e3}:{}},U=[...(F.motion||[]).filter(at=>at.type!==f),et];if(U.length>Uh.perItem)throw Error(`An item takes up to ${Uh.perItem} looping motions (preset still clears them)`);F.motion=U}return z++,F});if(x)return{patches:[{id:n.id,shape:Ze({...p,items:j})}],note:`${f??"rig"}: ${s.length} item(s) of ${n.label}`};p={...p,items:j}}if(f==="morph"){if(s.length!==1)throw Error("animateShape morph takes one itemId");const S=p.items.find(A=>A.id===s[0]),k=on(Rn(p));let y;if(o.toItemId){const A=p.items.find(z=>z.id===o.toItemId);if(!A?.params?.pts)throw Error("morph toItemId must be a point path");y=A.params.pts.map(z=>[z[0]+A.pos[0]-S.pos[0],z[1]+A.pos[1]-S.pos[1]])}else{if(!Array.isArray(o.to)||o.to.length<2||o.to.length>Te.points)throw Error("morph needs to [[x,y]…] (0..1 of the frame) or toItemId");y=o.to.map((A,z)=>{cn(A,z,"morph");const j=k.pt(A);return[j[0]-S.pos[0],j[1]-S.pos[1]]})}const C=p.items.map(A=>A.id===S.id?w2(A,y,{at:m,duration:g}):A);return{patches:[{id:n.id,shape:Ze({...p,items:C})}],note:`morph ${S.name}`}}if(!x1.includes(f))throw Error(`animateShape preset: ${Og.join(" | ")}`);let E=0;const $=p.items.map(S=>s.indexOf(S.id)<0?S:Yh(S,f,{at:Math.min(n.duration-1/30,m+v*E++),duration:g,amount:Ht(o.amount)?o.amount:1,count:Ht(o.count)?o.count:1}));return{patches:[{id:n.id,shape:Ze({...p,items:$})}],note:`${f}: ${s.length} item(s) of ${n.label}`}}case"editFrames":{if(!n)throw Error("editFrames needs clipId: a frame layer (drawFrames, Vẽ Animation, or one drawn in the frame editor)");const p=Ti(n),s=o.ink??"#1d1a17";if(!vo.test(s))throw Error("editFrames ink: #RRGGBB");const h=o.width??.004;if(!(Ht(h)&&h>0&&h<=.03))throw Error("editFrames width: ink line width, a fraction of the frame width (e.g. 0.004)");const f=Hb(p,{...o,at:o.at},{ink:s,width:jo(Le(on(Rn(p)).len(h)),.5,240)});return{patches:[{id:n.id,shape:Ze(f.shape),...f.end>n.duration+1e-6?{duration:Math.ceil(f.end*30)/30}:{}}],note:`editFrames ${o.action}: ${f.note}`}}case"drawnTransition":{if(!Ht(o.at)||o.at<0)throw Error("drawnTransition at: the cut, timeline seconds");const p=lC(o,{aspect:a[0]/a[1]}),s=o.duration??1,{start:h}=cC(o.at,s),f=Bi({op:"drawFrames",fps:o.fps??24,frames:p,width:0,brush:"none",outline:!1,label:o.label??(r?"Transition":"Chuyển cảnh")},{size:a,en:r,finish:u});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"}: ${p.length} drawings, covers the frame at ${o.at}s (cut there)${o.motion!==!1?", the shots shake at the cut":""}`}}case"traceImage":return MC(o,{into:n,target:i,size:a,ctx:e,en:r,finish:u});case"drawFrames":return Bi(o,{size:a,en:r,finish:u});case"animatePuppet":{const p=o.look==="stick"||o.character?.startsWith?.("stick")||Array.isArray(o.cast)&&o.cast.some(N=>String(N?.character??"").startsWith("stick")),s=o.fps??(p?30:Ya[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,g=e.H||720,v=N=>h?N.map(G=>({...G,parts:G.parts.map(V=>V.fill?{...V,line:!1}:V)})):N,x=(N,G)=>{const V=!!Ya[N.character],et=V?sA:ad,U=N.colors??null;if(U!=null&&(typeof U!="object"||Array.isArray(U)||Object.entries(U).some(([at,W])=>!et.includes(at)||!vo.test(W))))throw Error(`${G} colors: {${et.join(" | ")}: '#RRGGBB'}`);for(const[at,W,_]of[["x",-.5,1.5],["ground",.2,1.2],["size",.04,1.2]])if(N[at]!=null&&!(Ht(N[at])&&N[at]>=W&&N[at]<=_))throw Error(`${G} ${at}: ${W}–${_} (fractions of the frame)`);if(N.facing!=null&&!["left","right"].includes(N.facing))throw Error(`${G} facing: left | right`);if(N.hair!=null&&!zc.includes(N.hair))throw Error(`${G} hair: ${zc.join(" | ")} (stick figures)`);if(N.eyes!=null&&!Pc.includes(N.eyes))throw Error(`${G} eyes: ${Pc.join(" | ")} (stick figures)`);if(N.grip!=null&&!Gf.includes(N.grip))throw Error(`${G} grip: ${Gf.join(" | ")} (how the weapon is held when resting, walking, waiting)`);if(N.height!=null&&!(Ht(N.height)&&N.height>=.6&&N.height<=1.4))throw Error(`${G} height: 0.6–1.4 (× size)`);if(N.weight!=null&&!(Ht(N.weight)&&N.weight>=.6&&N.weight<=2))throw Error(`${G} weight: 0.6–2 (how thick a stick figure is drawn)`);return{pres:V,colors:U}},E=[];let $=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&&!(Ht(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",y=k?Math.min(y2.frames,1800):480,C=[];if(o.scene!=null&&!th.includes(o.scene))throw Error(`animatePuppet scene: ${th.join(" | ")} (a painted backdrop in depth layers that moves with the camera)`);const A=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((N,G)=>{if(!N||typeof N!="object")throw Error(`animatePuppet cast[${G}] must be an object`);x(N,`animatePuppet cast[${G}]`)}),o.beats!=null){if(o.cast.some(G=>Ya[G.character]))throw Error("animatePuppet beats: fighters are side-view puppets (fighter | monk | villager | brawler)");if(o.accent!=null&&!vo.test(o.accent))throw Error("animatePuppet accent: #RRGGBB (the impact sparks)");if(o.energy!=null&&!vo.test(o.energy))throw Error("animatePuppet energy: #RRGGBB (the glow of beams, energy slashes, teleports)");if(o.dust!=null&&!vo.test(o.dust))throw Error("animatePuppet dust: #RRGGBB (the dust puffs on the ground)");if(o.tempo!=null&&!(Ht(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 N=wA({cast:o.cast,beats:o.beats,fps:s,fx:o.fx!==!1,accent:o.accent??"#ffd23f",W:m,H:g,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:y});S={camera:N.camera,duration:N.duration,ground:Math.max(...o.cast.map(G=>G.ground??.9))},N.actors.forEach((G,V)=>E.push({frames:G.frames,track:N.tracks[V],start:0,label:`${A} ${V+1}`})),C.push(...N.reports),N.fx.forEach((G,V)=>E.push({frames:G.frames,start:G.start,label:`${r?"Impact":"Va chạm"} ${V+1}`,ink:o.accent??"#ffd23f",width:.0022})),$=`fight: ${o.beats.length} beat(s), impacts at ${N.impacts.map(G=>G.t+"s").join(" ").slice(0,160)} (add impact sfx / cameraShake there)`}else o.cast.forEach((N,G)=>{const V=Ya[N.character]?hg({...N,fps:s,W:m,H:g}):Vf({...N,character:N.character??"fighter",fps:s,W:m,H:g,stick:o.look==="stick",mocap:o.mocapClips??null,toon:o.toon??null,maxFrames:y});E.push({frames:V.frames,...V.track?{track:V.track}:{},start:0,label:`${A} ${G+1}`}),V.report&&C.push(V.report)})}else if(x(o,"animatePuppet"),Ya[o.character]){if(o.speech!=null&&(!Array.isArray(o.speech)||o.speech.length>200||o.speech.some(G=>!G||typeof G.text!="string"||!Ht(G.start)||!Ht(G.end)||G.end<=G.start)))throw Error("animatePuppet speech: [{text, start, end}] (s from the op start; a line, or each word from get_transcript)");const N=hg({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:g});E.push({frames:N.frames,start:0,label:A})}else{const N=Vf({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:g,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:y});E.push({frames:N.frames,track:N.track,start:0,label:A}),C.push(N.report)}const z=[];let j=[];if(o.scene){const N=S?.duration??Math.max(...E.map(G=>G.start+G.frames.length/s));for(const G of AA(o.scene,{size:a,camera:S?.camera??null,fps:s,duration:N,ground:S?.ground??o.ground??.9,finish:u,en:r}))z.push(G)}for(const N of E){if(k&&N.track){const V=Lg(N.track,{label:N.label,size:a,clean:h,width:f,ink:o.ink,brush:o.brush,finish:u});z.push({...V,start:V.start+N.start}),j.push(V.note);continue}const G=Bi({start:o.start,fps:s,frames:N.ink?N.frames:v(N.frames),width:N.width??f,ink:N.ink??o.ink,brush:N.ink?"none":o.brush,label:N.label},{size:a,en:r,finish:u});for(const V of G.layers)z.push({...V,start:V.start+N.start});j.push(G.note)}const P=o.cast?`${o.cast.length} character(s)`:o.character??"fighter",F=C.length?` — ${f3(C)}`:"";return{patches:[],layers:z,frameLayers:!0,note:`animatePuppet ${P}${$?` — ${$}`:`: ${(o.actions||[]).map(N=>N.move??N.mocap).join(" → ").slice(0,120)}`} — ${j[0]}${E.length>1?` (+${E.length-1} more sequence(s))`:""}${F}`}}case"editPose":{if(!n)throw Error("editPose needs clipId: a character layer made by animatePuppet (store rig)");const p=Ti(n),s=p.items.findIndex(C=>C.type==="art"&&C.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=p.items[s],f=d3(h.params.rig),m=f.frames.length/f.fps;if(!_f[o.joint])throw Error(`editPose joint: ${Object.keys(_f).join(" | ")}`);if(!(Ht(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 g=o.dx??0,v=o.dy??0,x=o.span??.3;if(!Ht(g)||!Ht(v)||Math.abs(g)>.5||Math.abs(v)>.5)throw Error("editPose dx, dy: how far the joint moves, fractions of the frame (−0.5..0.5; dy < 0 = up)");if(!(Ht(x)&&x>=.04&&x<=3))throw Error("editPose span: s the change eases in and out over around `at`, 0.04–3");if(!g&&!v)throw Error("editPose: give dx and / or dy");const E=g*f.W/(f.fs*f.k),$=v*f.H/f.k;let S=0;f.frames.forEach((C,A)=>{const z=A/f.fps,j=Math.abs(z-o.at)/x;if(j>=1)return;const P=1-j*j*j*(j*(6*j-15)+10);C.J=h3(C.J,o.joint,[E*P,$*P]),S++});const k=A1(f),y=p.items.map((C,A)=>A===s?{...C,params:{...C.params,rig:k}}:C);return{patches:[{id:n.id,shape:Ze({...p,items:y})}],note:`editPose ${o.joint} at ${o.at}s: ${S} drawing(s) changed`}}case"traceMotion":{if(!n||n.kind!=="video")throw Error("traceMotion needs clipId: a video clip on the timeline (the person whose motion the character copies)");const p=o.character??"stickman";if(!ya[p])throw Error(`traceMotion character: a side-view character (${Object.keys(ya).join(" | ")})`);kC(o,"traceMotion");const s=o.from??0,h=n.duration,f=o.duration??Math.min(60,h-s),m=o.fps??30,g=o.person??1;if(!(Ht(s)&&s>=0&&s<h))throw Error(`traceMotion from: s into the video clip, 0–${Math.round(h*100)/100}`);if(!(Ht(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(!(g===1||g===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 v=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"&&ya[p].look!=="stick"?{stick:!0}:{}},E=e.W||1280,$=e.H||720,S=I1({character:p,...x,x:v?.x??.5,ground:v?.ground??.9,size:v?.size??.5,fps:m,W:E,H:$,actions:[{move:"idle",duration:.2}],toon:0,law:!1});S.frames=S.frames.slice(0,1);const k=Lg(S,{label:String(o.label??(r?"Character from video":"Người theo video")).slice(0,40),size:a,clean:o.look==="clean",width:o.width??.0028,ink:o.ink,brush:o.brush,finish:u});k.shape.items[0].opacity=.45,k.shape.items[0].span=[0,Math.round(f*1e4)/1e4];const y=n.start+s-(Ht(o.start)?o.start:0);return{patches:[],frameLayers:!0,layers:[{...k,start:y,duration:f,clientJob:{kind:"pose-track",op:"traceMotion",params:{source:n.id,from:s,duration:f,fps:m,person:g,character:p,style:x,place:v,W:E,H:$}}}],note:`traceMotion: a ${p} layer following the person in "${String(n.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(!n||n.kind!=="video")throw Error("rotoscope needs clipId: a 2D video clip on the timeline (its figures are drawn frame by frame)");const p=!!BA(o).flat,s=VA(o),{fps:h,from:f,duration:m,n:g}=_A(o,n.duration,wo.frames),v=o.ink??"#1a0508";if(!vo.test(v))throw Error("rotoscope ink: #RRGGBB");if(Kb(o.fx,"rotoscope"),typeof o.job!="string"||!bC.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=n.start+f-(Ht(o.start)?o.start:0),$=e.W||1280,S=e.H||720,k=[];if(p&&s==="plate"){const y=Bi({op:"rotoscope",fps:h,width:0,brush:"none",label:x,frames:[{parts:[Pg],hold:1}]},{size:a,en:r,finish:u}).layers[0];y.shape.items[0].span=[0,Math.round(g/h*1e4)/1e4],k.push({...y,label:`${x} · ${r?"backdrop":"nền"}`.slice(0,60),start:E,duration:g/h,clientJob:{kind:"rotoscope",op:"rotoscope",params:{job:o.job,backdrop:!0,first:0,count:g,fps:h,ink:v,W:$,H:S,label:`${x} · ${r?"backdrop":"nền"}`.slice(0,40)}}})}for(const y of p&&s==="keep"?[0,1]:[null])for(let C=0,A=0;C<g;C+=Te.items,A++){const z=Math.min(Te.items,g-C),j=Bi({op:"rotoscope",fps:h,width:0,brush:"none",label:x,frames:[{parts:[Pg],hold:z}]},{size:a,en:r,finish:u}).layers[0],P=`${g>Te.items?`${x} ${A+1}`:x}${y===1?` · ${r?"front":"trước"}`:""}`;k.push({...j,label:P,start:E+C/h,duration:z/h,clientJob:{kind:"rotoscope",op:"rotoscope",params:{job:o.job,first:C,count:z,fps:h,ink:v,fx:y===1?null:o.fx??null,W:$,H:S,label:P.slice(0,40),...y!=null?{half:y}:{}}}})}return{patches:[],frameLayers:!0,layers:k,rotoscope:{job:o.job,clipId:n.id,fps:h,from:f,duration:m,n:g},note:`rotoscope: ${g} drawing(s) of "${String(n.label??"video").slice(0,40)}" at ${h} fps on ${k.length} layer(s)${p&&s==="plate"?" (the first: the backdrop)":""} — drawn by the Vẽ Animation job`}}case"arrangeShape":{const p=Ti(n),s=Hu(p,o.itemIds,"arrangeShape"),h=o.action;let f=[...p.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(g=>s.includes(g.id)?{...g,group:m}:g)}else if(h==="ungroup")f=f.map(m=>{if(!s.includes(m.id))return m;const{group:g,...v}=m;return v});else if(h==="front"||h==="back"){const m=f.filter(v=>s.includes(v.id)),g=f.filter(v=>!s.includes(v.id));f=h==="front"?[...g,...m]:[...m,...g]}else if(h==="forward"||h==="backward")for(const m of h==="forward"?[...s].reverse():s){const g=f.findIndex(x=>x.id===m),v=h==="forward"?g+1:g-1;v>=0&&v<f.length&&([f[g],f[v]]=[f[v],f[g]])}else if(Xh.includes(h))f=f.map(m=>{if(!s.includes(m.id))return m;const g=(m.ops||[]).filter(v=>v.op!=="merge");if(g.length>=8)throw Error("An item takes up to 8 operators");return{...m,ops:[...g,{...Bs("merge"),mode:h}]}});else if(h==="move"){const m=o.dx??0,g=o.dy??0;if(!Ht(m)||!Ht(g)||Math.abs(m)>1||Math.abs(g)>1)throw Error("arrangeShape move: dx, dy are fractions of the frame (−1..1)");const[v,x]=Rn(p),E=Math.min(v,x)/1e3;f=f.map($=>s.includes($.id)?{...$,pos:[Le($.pos[0]+m*v/E),Le($.pos[1]+g*x/E)]}:$)}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:g,...v}=m;return v});else throw Error(`arrangeShape action: group | ungroup | front | back | forward | backward | move | hide | show | ${Xh.join(" | ")}`);return{patches:[{id:n.id,shape:Ze({...p,items:f})}],note:`arrange ${h}: ${s.length} item(s)`}}}throw Error(`Unknown 2D op ${o.op}`)}function rh(t,e,o){if(typeof e=="string"){const a=M2(e,v2(t));if(!a)throw Error(`pivot: ${Zh.join(" | ")} or [x, y] of the frame`);return a}if(!Array.isArray(e)||e.length!==2)throw Error(`pivot: ${Zh.join(" | ")} or [x, y] of the frame`);cn(e,0,"pivot");const r=Xs(Tc(ga({...t})),...o.pt(e));return[Le(r[0]),Le(r[1])]}function nh(t,e){const o=ga(t),r=ga({...t,pivot:e}),a=o[4]-r[4],n=o[5]-r[5],i={...t,pivot:e,pos:[Le(t.pos[0]+a),Le(t.pos[1]+n)]};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(c=>({...c,value:Le(c.value+a)}))),t.keys["pos.1"]&&(i.keys["pos.1"]=t.keys["pos.1"].map(c=>({...c,value:Le(c.value+n)})))),i}const Pg={points:[[0,0],[1,0],[1,1],[0,1]],fill:"#000000",opacity:.06,line:!1,smooth:!1},yC={points:[[.5,.5],[.501,.5],[.5,.501]],fill:"#000000",opacity:.02,line:!1,smooth:!1},bC=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function QT(t,e,{en:o=!1}={}){const r=e||{},a=Array.isArray(t)?{frames:t}:t||{},n=r.fps??24;if(r.backdrop){if(!Array.isArray(a.backdrop)||!a.backdrop.length)throw Error("rotoscope: the job has no backdrop for this layer");const p=Fh({op:"drawFrames",fps:n,ink:r.ink??"#1a0508",width:.0028,brush:"none",label:r.label,frames:[{parts:a.backdrop}]},{clips:[],find:()=>null,W:r.W||1280,H:r.H||720,en:o}).layers[0].shape;return p.items[0].span=[0,Math.round((r.count??1)/n*1e4)/1e4],{shape:p}}const i=(Array.isArray(a.frames)?a.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 c=r.half==null?i:i.map(u=>{const p=Number.isInteger(u?.split)?u.split:u?.parts?.length??0;return{parts:r.half===1?(u?.parts??[]).slice(p):(u?.parts??[]).slice(0,p)}});return{shape:wC(c,r,{en:o})}}function wC(t,e,{en:o}){return Fh({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(a=>({parts:Array.isArray(a?.parts)&&a.parts.length?a.parts:[yC]}))},{clips:[],find:()=>null,W:e.W||1280,H:e.H||720,en:o}).layers[0].shape}function kC(t,e){if(t.hair!=null&&!zc.includes(t.hair))throw Error(`${e} hair: ${zc.join(" | ")} (stick figures)`);if(t.eyes!=null&&!Pc.includes(t.eyes))throw Error(`${e} eyes: ${Pc.join(" | ")} (stick figures)`);if(t.weight!=null&&!(Ht(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])=>!ad.includes(o)||!vo.test(r))))throw Error(`${e} colors: {${ad.join(" | ")}: '#RRGGBB'}`);for(const[o,r,a]of[["x",-.5,1.5],["ground",.2,1.2],["size",.04,1.2]])if(t[o]!=null&&!(Ht(t[o])&&t[o]>=r&&t[o]<=a))throw Error(`${e} ${o}: ${r}–${a} (fractions of the frame)`)}function Lg(t,{label:e,size:o,clean:r,width:a,ink:n="#2a1d14",brush:i="ink",finish:c}){const u=A1(t),p=u.n/u.fps,s=on(o),h=s.pt([.5,.5]),f=s.pt([0,0]),m=s.pt([1,1]),g=t.ch.look==="stick",v=s.len(a);if(!vo.test(n))throw Error("animatePuppet ink: #RRGGBB");const x=!g&&v>0?{color:n,width:jo(Le(v),.5,240),cap:"round",join:"round",...i&&i!=="none"&&ol.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:u,box:[Le(f[0]-h[0]),Le(f[1]-h[1]),Le(m[0]-h[0]),Le(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(p*1e4)/1e4]};return{shape:c({v:2,size:o,items:[E]},null,{colors:"keep"}),label:String(e).slice(0,60),start:0,duration:p,note:`rig layer: ${u.n} drawing(s) at ${u.fps} fps = ${Math.round(p*100)/100}s from ${Math.round(u.data.length/1e3)}k chars of skeletons`}}const wo=Object.freeze({frames:480,parts:64,points:256,chars:3e6,fps:[4,30],cycles:8});function Bi(t,{size:e,en:o,finish:r}){const a=t.fps??12;if(!(Number.isInteger(a)&&a>=wo.fps[0]&&a<=wo.fps[1]))throw Error("drawFrames fps: 4–30 drawings per second (30 = every timeline frame, smoothest; 12 = on twos, 8 = on threes)");const n=Array.isArray(t.frames)?t.frames:null;if(!n||!n.length||n.length>wo.frames)throw Error(`drawFrames frames: 1–${wo.frames} drawings [{parts:[{points | d, fill?, line?}], hold?}]`);const i=t.cycles??1;if(!(Number.isInteger(i)&&i>=1&&i<=wo.cycles))throw Error(`drawFrames cycles: 1–${wo.cycles} (the whole drawing sequence repeated)`);const c=t.ink??"#2a1d14";if(!vo.test(c))throw Error("drawFrames ink: #RRGGBB");const u=t.width??.0035;if(!(Ht(u)&&u>=0&&u<=.03))throw Error("drawFrames width: ink line width, a fraction of the frame width (0–0.03; 0 = no ink lines)");const p=t.brush??"ink";if(p!=="none"&&!ol.includes(p))throw Error(`drawFrames brush: none | ${ol.join(" | ")}`);const s=on(e),h=y=>Math.round(y),f=Kb(t.fx,t.op==="rotoscope"?"rotoscope":"drawFrames"),m=f?HA(n.map((y,C)=>{if(!Array.isArray(y?.parts))throw Error(`drawFrames frames[${C}].parts: 1–${wo.parts} shapes`);return y}),a,f,{aspect:e[0]/e[1],maxParts:wo.parts}):n;let g=0;const v=m.map((y,C)=>{const A=Array.isArray(y?.parts)?y.parts:null;if(!A||!A.length||A.length>wo.parts)throw Error(`drawFrames frames[${C}].parts: 1–${wo.parts} shapes`);const z=y.hold??1;if(!(Number.isInteger(z)&&z>=1&&z<=48))throw Error(`drawFrames frames[${C}].hold: how many frames it stays, 1–48`);const j=A.map((V,et)=>{if(!V||typeof V!="object")throw Error(`drawFrames frames[${C}].parts[${et}] must be an object`);const U=V.fill??null;if(U!==null&&!vo.test(U))throw Error(`drawFrames frames[${C}].parts[${et}].fill: #RRGGBB or null (an ink line)`);let at;if(Array.isArray(V.loops)){if(!V.loops.length||V.loops.length>24||V.loops.some(W=>!Array.isArray(W)||W.length<3||W.length>1500))throw Error(`drawFrames frames[${C}].parts[${et}].loops: 1–24 closed outlines of 3–1500 points`);at=V.loops.map((W,_)=>"M"+W.map((J,tt)=>{const rt=s.pt(cn(J,tt,`drawFrames frames[${C}].parts[${et}].loops[${_}]`));return`${h(rt[0])} ${h(rt[1])}`}).join(" L")+" Z").join(" ")}else if(V.d!=null)at=Yb(V.d,s);else{const W=Array.isArray(V.points)?V.points:null;if(!W||W.length<2||W.length>wo.points)throw Error(`drawFrames frames[${C}].parts[${et}]: points [[x,y]…] (2–${wo.points}) or d`);const _=W.map((tt,rt)=>s.pt(cn(tt,rt,`drawFrames frames[${C}].parts[${et}]`))),J=V.closed??!!U;at=V.smooth===!1?"M"+_.map(tt=>`${h(tt[0])} ${h(tt[1])}`).join(" L")+(J?" Z":""):ps(_,J&&_.length>2)}if(!U&&V.line===!1)throw Error(`drawFrames frames[${C}].parts[${et}] needs a fill or a line`);if(V.lw!=null&&!(Ht(V.lw)&&V.lw>=.1&&V.lw<=5))throw Error(`drawFrames frames[${C}].parts[${et}].lw: line weight 0.1–5 (× width)`);if(V.opacity!=null&&!(Ht(V.opacity)&&V.opacity>=.02&&V.opacity<=1))throw Error(`drawFrames frames[${C}].parts[${et}].opacity: 0.02–1`);if(V.tag!=null&&!gh.test(V.tag))throw Error(`drawFrames frames[${C}].parts[${et}].tag: a name — a letter then letters / digits / dashes, ≤ 24 (armR, head, leg-left)`);return{d:at,fill:U,...V.tag!=null?{tag:V.tag}:{},...U&&V.line===!1?{line:!1}:{},...V.lw!=null&&V.lw!==1?{lw:Math.round(V.lw*100)/100}:{},...V.eo===!0&&U?{eo:!0}:{},...V.opacity!=null&&V.opacity<1?{o:Math.round(V.opacity*100)/100}:{},role:7}}),P=j.reduce((V,et)=>{const U=mr(et.d);return[Math.min(V[0],U[0]),Math.min(V[1],U[1]),Math.max(V[2],U[2]),Math.max(V[3],U[3])]},[1/0,1/0,-1/0,-1/0]),F=Math.round((P[0]+P[2])/2),N=Math.round((P[1]+P[3])/2),G=j.map(V=>{let et=0;return{...V,d:V.d.replace(Mn,U=>String(Math.round(Number(U)-(et++%2?N:F))))}});for(const V of G){if(V.d.length>us.d)throw Error(`drawFrames frames[${C}]: a shape is too long (max ${us.d} characters)`);g+=V.d.length}return{parts:G,pos:[F,N],hold:z}});if(g*i>wo.chars)throw Error(`drawFrames: ${g*i} characters of drawing (max ${wo.chars}) — fewer frames, cycles or points`);const x=s.len(u),E=x>0?{color:c,width:jo(Le(x),.5,240),cap:"round",join:"round",...p!=="none"?{hand:{style:p,taper:.7,press:.6,seed:7}}:{}}:null,$=[];let S=0;for(let y=0;y<i;y++)for(const C of v)$.push({...C,t0:S,t1:S+C.hold/a}),S+=C.hold/a;const k=[];for(let y=0;y<$.length;y+=Te.items){const C=$.slice(y,y+Te.items),A=C[0].t0,z=C.at(-1).t1,j=C.map((P,F)=>({id:`s${F+1}`,name:`${o?"Frame":"Khung"} ${y+F+1}`,type:"art",params:{parts:P.parts,box:mr(P.parts.map(N=>N.d).join(" ")),outline:t.outline!==!1},pos:P.pos,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:P.parts.find(N=>N.fill)?.fill??c},stroke:E,role:7,span:[Math.round((P.t0-A)*1e4)/1e4,Math.round((P.t1-A)*1e4)/1e4]}));k.push({shape:r({v:2,size:e,items:j},null,{colors:"keep"}),label:`${String(t.label??(o?"Frames":"Khung vẽ")).slice(0,48)}${$.length>Te.items?` ${k.length+1}`:""}`,start:A,duration:z-A})}return{patches:[],layers:k,frameLayers:!0,note:`drawFrames: ${n.length} drawing(s)${i>1?` × ${i}`:""} at ${a} fps = ${Math.round(S*100)/100}s on ${k.length} layer(s), ${Math.round(g/1e3)}k chars`}}const xC=13;function MC(t,{into:e,target:o,size:r,ctx:a,en:n,finish:i}){const c=t.traced;if(!c||typeof c!="object")throw Error("traceImage needs materialId (an image in the Media bin); the picture is traced when the plan is applied");const u=c.width,p=c.height,s=c.unit;if(!(Number.isInteger(u)&&Number.isInteger(p)&&u>=8&&p>=8&&u<=2048&&p<=2048&&(s===.5||s===1)&&Array.isArray(c.groups)&&c.groups.length&&c.groups.length<=xC))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,g]=Rn(o),v=on([m,g]),x=a.W||1280,E=a.H||720;let $;if(t.background==="remove"&&(t.x!=null||t.y!=null||t.size!=null)){const G=t.x??.5,V=t.y??.5,et=t.size??.6;if(cn([G,V],0,"traceImage"),!(Ht(et)&&et>=.02&&et<=1.5))throw Error("traceImage size = height of the subject as a fraction of the frame, 0.02–1.5");const U=c.groups.reduce((J,tt)=>tt.parts.reduce((rt,D)=>{const q=mr(D.d);return[Math.min(rt[0],q[0]),Math.min(rt[1],q[1]),Math.max(rt[2],q[2]),Math.max(rt[3],q[3])]},J),[1/0,1/0,-1/0,-1/0]).map(J=>J*s),at=Math.max(1,U[3]-U[1]),W=et/at,_=W*E/x;$={x0:G-(U[0]+U[2])/2*_,y0:V-(U[1]+U[3])/2*W,sx:_,sy:W}}else{const G=u/p,V=x/E,et=h==="cover",U=et?G>V:G<V,at=U?et?G/V:1:et?1:G/V,W=U?et?1:V/G:et?V/G:1;$={x0:(1-at)/2,y0:(1-W)/2,sx:at/u,sy:W/p}}const k=(G,V)=>v.pt([$.x0+G*s*$.sx,$.y0+V*s*$.sy]),y=!e&&t.layers!==!1&&c.groups.length>1,C=[...o.items],A=[],z=[];if(!y&&C.length+c.groups.length>Te.items)throw Error(`A Shape layer holds up to ${Te.items} items — trace into a new layer (leave clipId out)`);const j=([G,V])=>[(G*v.k+v.ox)/m,(V*v.k+v.oy)/g];let P=0;for(const G of c.groups){if(!G||!Array.isArray(G.parts)||!G.parts.length||G.parts.length>us.parts)throw Error("traceImage: bad traced group");const V=G.parts.map(rt=>{if(!rt||typeof rt.d!="string"||!/^\s*M[MLCQZ0-9eE.,\s+-]*$/.test(rt.d)||!vo.test(rt.fill??""))throw Error("traceImage: bad traced part");const D=[...rt.d.matchAll(Mn)].map(yt=>Number(yt[0]));if(D.length%2)throw Error("traceImage: bad traced part");const q=[];for(let yt=0;yt<D.length;yt+=2){const Mt=k(D[yt],D[yt+1]);q.push(Math.round(Mt[0]),Math.round(Mt[1]))}let pt=0;return{d:rt.d.replace(Mn,()=>String(q[pt++])),fill:rt.fill}}),et=V.reduce((rt,D)=>{const q=mr(D.d);return[Math.min(rt[0],q[0]),Math.min(rt[1],q[1]),Math.max(rt[2],q[2]),Math.max(rt[3],q[3])]},[1/0,1/0,-1/0,-1/0]),U=Math.round((et[0]+et[2])/2),at=Math.round((et[1]+et[3])/2),W=V.map(rt=>{let D=0;return{d:rt.d.replace(Mn,q=>String(Math.round(Number(q)-(D++%2?at:U)))),fill:rt.fill,role:7,eo:!0}});P+=W.reduce((rt,D)=>rt+D.d.length,0);const _=li(C),J=Number.isInteger(G.region)&&G.region>=0?f[G.region]:null;let tt={id:_,name:String(G.name||(n?"Traced":"Hình vẽ lại")).slice(0,40),type:"art",params:{parts:W,box:mr(W.map(rt=>rt.d).join(" ")),outline:!1},pos:[U,at],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:W[0].fill},stroke:null,role:7};if(y){const rt=tt.name,D=[...j([et[0],et[1]]),...j([et[2],et[3]])];let q=null,pt=null,yt=null;if(J){if(J.motion!=null){if(!Yn[J.motion])throw Error(`traceImage regions[].motion (layers): ${Fb.join(" | ")}`);pt={preset:J.motion,...Ht(J.amount)?{amount:jo(J.amount,0,8)}:{},...Ht(J.period)?{period:jo(J.period,.1,60)}:{},...Ht(J.phase)?{phase:jo(J.phase,0,1)}:{}}}const Q=J.pivot??(pt?Yn[pt.preset].anchor:null);if(Array.isArray(Q)?(cn(Q,0,"traceImage regions[].pivot"),q=[$.x0+Q[0]*u*$.sx,$.y0+Q[1]*p*$.sy]):Q!=null&&(q=Q),J.parent!=null){const nt=f.findIndex(dt=>dt&&dt.name===J.parent);if(nt<0)throw Error(`traceImage regions[].parent "${String(J.parent).slice(0,40)}": the name of another region`);yt=nt}}if(G.region===-1){z.push({shape:{v:2,size:[m,g],items:[{...tt,id:"s1"}]},label:String(rt).slice(0,60),region:null,anchor:q,box:D,parent:yt,motion:pt});continue}const Mt=D[0]-3/x,l=D[1]-3/E,lt=D[2]+3/x,K=D[3]+3/E,d=(lt-Mt)*x,w=(K-l)*E,T=Math.min(Math.max(1.5,64/Math.max(1,Math.min(d,w))),2560/Math.max(d,w)),I=jo(Math.round(d*T),64,2560),O=jo(Math.round(w*T),64,2560),L=on([I,O]),B=Math.min(x/I,E/O),H=(Q,nt)=>L.pt([($.x0+Q*s*$.sx-Mt)/(lt-Mt),($.y0+nt*s*$.sy-l)/(K-l)]),Z=G.parts.map(Q=>{const nt=[...Q.d.matchAll(Mn)].map(It=>Number(It[0])),dt=[];for(let It=0;It<nt.length;It+=2){const xt=H(nt[It],nt[It+1]);dt.push(Math.round(xt[0]),Math.round(xt[1]))}let vt=0;return{d:Q.d.replace(Mn,()=>String(dt[vt++])),fill:Q.fill}}),ot=Z.reduce((Q,nt)=>{const dt=mr(nt.d);return[Math.min(Q[0],dt[0]),Math.min(Q[1],dt[1]),Math.max(Q[2],dt[2]),Math.max(Q[3],dt[3])]},[1/0,1/0,-1/0,-1/0]),st=Math.round((ot[0]+ot[2])/2),Y=Math.round((ot[1]+ot[3])/2),ct=Z.map(Q=>{let nt=0;return{d:Q.d.replace(Mn,dt=>String(Math.round(Number(dt)-(nt++%2?Y:st)))),fill:Q.fill,role:7,eo:!0}}),mt={...tt,id:"s1",pos:[st,Y],params:{parts:ct,box:mr(ct.map(Q=>Q.d).join(" ")),outline:!1}};z.push({shape:{v:2,size:[I,O],items:[mt]},label:String(rt).slice(0,60),region:Number.isInteger(G.region)?G.region:null,anchor:q,box:D,parent:yt,motion:pt,place:{posX:Math.round(((Mt+lt)/2-.5)*1e4)/1e4,posY:Math.round(((l+K)/2-.5)*1e4)/1e4,scale:Math.round(d/(I*B)*1e5)/1e5}});continue}if(J&&(J.pivot!=null&&(tt=nh(tt,Array.isArray(J.pivot)?(()=>{cn(J.pivot,0,"traceImage regions[].pivot");const rt=k(J.pivot[0]*u/s,J.pivot[1]*p/s);return[Le(rt[0]-U),Le(rt[1]-at)]})():rh(tt,J.pivot,v))),J.motion!=null)){const rt=M1[J.motion];if(!rt)throw Error(`traceImage regions[].motion: ${yh.join(" | ")}`);J.pivot==null&&(tt=nh(tt,rh(tt,rt.pivot,v)));const D=Ht(J.amount)?jo(J.amount,0,8):1;tt.motion=[{type:J.motion,...D!==1?{amount:Math.round(rt.amount*D*1e4)/1e4}:{},...Ht(J.period)?{period:jo(J.period,.1,60)}:{},...Ht(J.phase)?{phase:jo(J.phase,0,1)}:{}}]}C.push(tt),A.push(_)}if(P>us.layer)throw Error("traceImage: the drawing is too big for one layer — fewer colours or less detail");if(y){const G=new Map(z.map((et,U)=>[et.region,U]));for(const et of z)et.parent=et.parent==null?null:G.get(et.parent)??null,et.shape=i(et.shape,null,{colors:"keep"}),delete et.region;let V=null;if(t.camera!=null){const et=typeof t.camera=="string"?{preset:t.camera}:t.camera;if(!et||!fp.includes(et.preset))throw Error(`traceImage camera: ${fp.join(" | ")} (or {preset, amount})`);V={preset:et.preset,...Ht(et.amount)?{amount:jo(et.amount,0,8)}:{}}}return{patches:[],layers:z,camera:V,note:`traceImage: ${z.length} layers (${z.map(et=>et.label).join(", ").slice(0,140)}), ${c.palette?.length??"?"} colours, ${Math.round(P/1e3)}k chars`}}const F=i({...o,items:C},A,{colors:"keep"}),N=`traceImage: ${c.groups.length} part(s) (${c.groups.map(G=>G.name).join(", ").slice(0,120)}), ${c.palette?.length??"?"} colours, ${Math.round(P/1e3)}k chars`;return e?{patches:[{id:e.id,shape:F}],note:N}:{patches:[],layer:{shape:F,label:String(t.label??(n?"Traced drawing":"Vẽ lại từ ảnh")).slice(0,60)},note:N}}const tw=t=>bh(t?.shape)&&t.shape.items.length===1&&t.shape.items[0].name==="Paper"&&t.zIndex===-1,ah=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"}]),Fg=ah.map(t=>t.id),ih=Object.freeze(["stack","split","focus"]),oi=Object.freeze({shots:12,seconds:60,labels:40}),vC={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"}},$C={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}}},Wt=t=>Math.round(t*1e3)/1e3,xo=t=>Math.round(t*1e4)/1e4,sh=t=>Yt[t],EC=/^#[0-9a-fA-F]{6}$/,Xu=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 SC(t,e,o){const{track:r}=Kt(t,e,o.start,o.start+o.duration),a={...o,track:r};return t.push(a),a}function IC(t,e){const o=ah.find(r=>r.id===t)??ah[0];return EC.test(e??"")?{...o,accent:e.toLowerCase(),rim:o.glow?e.toLowerCase():o.rim}:o}function Mp(t,e){return qn(t)?Math.abs(S2(t,e)):an(t)?I2(t,e):t.playbackRate||1}function AC(t,e,o){const r=t[e],a=t[e-1],n=a&&Math.abs(a.start+a.duration-r.start)<.05?a.transition:null,i=n?.ramp?.preset||n?.name||r.seam?.style||r.join?.style||a?.join?.style||(an(r)||qn(r)?o.ramp:null);return String(i||o.cut).replace(/\s*\([^)]*\)\s*/g," ").replace(/[-_]+/g," ").trim().toUpperCase().slice(0,oi.labels)}function CC(t,e,o,r){const a=e.find(i=>i.id===t.nodeId),n=a?.width>1&&a?.height>1?a.width/a.height:t.kind==="video"?o/r:1;return Math.min(1,o/n/r)}function jC(t,e,o){const r=e.find(n=>n.id===t.nodeId);if(!(Number.isInteger(r?.width)&&r.width>1&&Number.isInteger(r?.height)&&r.height>1))return;const a=pa(r.width,r.height,t.crop);return fr({mw:r.width,mh:r.height},[Dn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:o},a.w,a.h)])}function TC(t,{x:e,y:o,s:r}){const a={...t,...pn(t)},n=(a.motionKeys??[]).map(i=>({...i,...Number.isFinite(i.x)?{x:xo(e+r*i.x)}:{},...Number.isFinite(i.y)?{y:xo(o+r*i.y)}:{},...Number.isFinite(i.zoom)?{zoom:xo(r*i.zoom)}:{}}));return{motionV:2,posX:xo(e+r*(a.posX??0)),posY:xo(o+r*(a.posY??0)),scale:xo(r*(a.scale??1)),motionKeys:n}}const oc=(t,e=0)=>{const o=Wt(Math.min(t,e)),r=Wt(Math.min(t,e+.35));return r>o?[{time:o,opacity:0,ease:{opacity:sh("ease-out")}},{time:r,opacity:1}]:[]};function OC(t,e){const o=t.map(r=>({...r}));for(const r of e){const a=o.find(n=>Math.abs(n.time-r.time)<.008333333333333333);a?Object.assign(a,{...r,ease:{...a.ease,...r.ease}}):o.push({...r})}return o.sort((r,a)=>r.time-a.time)}function Fr(t,e,o,r,a,{x:n,y:i,size:c=30,color:u,font:p,italic:s=!1,weight:h=700,anim:f="word-blur",track:m=0,glow:g=!0,k:v=1}){const x=u??a.label,E=ri({text:r,fontSize:Math.max(24,Math.min(96,c)),color:x,placement:"center",fontFamily:p??a.font,align:"center",animation:f,design:{lines:[{scale:1,fill:x,font:p??a.font,italic:s,weight:h,tracking:.06}],layers:[{type:"text",fill:"{color}",...g&&a.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:xo(n),posY:xo(i),scale:Wt(v),motionKeys:[]}}function zC(t,e){const o=t.duration,r=40,a=Array.from({length:r+1},(f,m)=>Mp(t,o*m/r)),n=Math.max(2,...a)*1.12,i=f=>Wt(90+820*f),c=f=>Wt(740-430*Math.min(1,f/n)),u=a.map((f,m)=>[i(m/r),c(f)]),p=Math.min(24,Math.max(2,Math.round(o*4))),s=Array.from({length:p+1},(f,m)=>({t:Wt(o*m/p),p:[i(m/p),c(Mp(t,o*m/p))]})),h=c(1);return Ze({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:u,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:Wt(o),value:1}]}},{id:"c",name:"Curve",type:"path",params:{pts:u,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:Wt(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 PC(t,e,o,r){const a=Math.min(1777.7777777777778,1e3*e),n=v=>Wt(500+(v-.5)*a),i=[],c=(v,x,E)=>({color:t.floor,width:x,...E?{blur:E}:{},opacity:v});if(o==null){const x=[],E=[];for(let S=0;S<=8;S++){const k=n(S/8);x.push(...S%2?[[k,1e3],[k,0]]:[[k,0],[k,1e3]])}const $=Math.round(8/e);for(let S=0;S<=$;S++){const k=Wt(1e3*S/$);E.push(...S%2?[[n(1),k],[n(0),k]]:[[n(0),k],[n(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:c(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:c(1,2)}),Ze({v:2,items:i})}const u=Wt(1e3*o),p=[500,Wt(u-120)],s=14,h=[];for(let v=0;v<=s;v++){const x=n(-.7+2.4*v/s),E=(u-1e3)/(p[1]-1e3),$=Wt(x+(p[0]-x)*E);h.push(...v%2?[[$,u],[x,1e3]]:[[x,1e3],[$,u]])}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:c(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 v=1;v<=8;v++){const x=1+v*.55,E=Wt(u+(1e3-u)*(1/x-1/(1+8*.55))/(1-1/(1+8*.55)));i.push({id:`h${v}`,name:`Row ${v}`,type:"path",params:{pts:[[n(-.2),E],[n(1.2),E]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:Wt(.25+.6*(1-v/8)),fill:{type:"none"},stroke:c(1,v<3?4:2.5,v<3?4:0)})}i.push({id:"hz",name:"Horizon",type:"path",params:{pts:[[n(-.2),u],[n(1.2),u]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.9,fill:{type:"none"},stroke:c(1,5,10)});const f=1.6,m=[];for(let v=0;v<=r+1e-6&&m.length<60;v+=f)m.push({time:Wt(v),value:u},{time:Wt(Math.min(r,v+f-1/30)),value:1e3});const g=m.filter((v,x,E)=>!x||v.time>E[x-1].time);return i.push({id:"scan",name:"Scan",type:"rect",params:{w:Wt(a*1.4),h:8,round:4},pos:[500,u],rot:0,scale:[1,1],opacity:.8,fill:{type:"color",color:t.floor},stroke:{color:t.floor,width:6,blur:14},...g.length>1?{keys:{"pos.1":g}}:{}}),Ze({v:2,items:i})}const Ng={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"}},LC=["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"];function FC(t){const e=Math.min(1777.7777777777778,1e3*t);return{X:o=>Wt(500+(o-.5)*e),Y:o=>Wt(o*1e3),w:e}}const Jo=(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}),_i=(t,e,o,r,a,n,i=null,c={})=>({id:t,name:t,type:"rect",params:{w:Wt(r),h:Wt(a),round:c.round??0},pos:[Wt(e),Wt(o)],rot:0,scale:[1,1],opacity:c.opacity??1,fill:n,stroke:i,...c.keys?{keys:c.keys}:{}});function NC(t,e){const o=t.duration,r=Math.min(24,Math.max(2,Math.round(o*4))),a=8,n=p=>Wt(-120+240*Math.min(1,Math.log(Math.max(.1,p)/.1)/Math.log(a/.1))),i=[];for(let p=0;p<=40;p++){const s=(-210+240*p/40)*Math.PI/180;i.push([Wt(500+Math.cos(s)*380),Wt(560+Math.sin(s)*380)])}const c=[];[.1,.5,1,2,4,8].forEach((p,s)=>{const h=(n(p)-90)*Math.PI/180,f=[[Wt(500+Math.cos(h)*330),Wt(560+Math.sin(h)*330)],[Wt(500+Math.cos(h)*380),Wt(560+Math.sin(h)*380)]];c.push(...s%2?f.reverse():f)});const u=Array.from({length:r+1},(p,s)=>({time:Wt(o*s/r),value:n(Mp(t,o*s/r))}));return Ze({v:2,square:!0,items:[_i("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}),Jo("a",i,{color:e.text,width:10,cap:"round",opacity:.35}),Jo("t",c,{color:e.text,width:8}),{id:"n",name:"Needle",type:"path",params:{pts:[[500,560],[500,230]],closed:!1},pos:[0,0],rot:u[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:u}},{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 RC(t,e,o,r={}){const{newId:a,W:n=1280,H:i=720,materials:c=[]}=r,u=new Map(t.map(lt=>[lt.id,lt])),p=(o??[]).map(lt=>u.get(lt)).filter(Boolean);let s;if(p.length>1)s=p.filter(Xu);else{const lt=p[0]??t.filter(Xu).sort((K,d)=>K.track-d.track||K.start-d.start)[0];if(!lt)throw Error("breakdownShowcase needs the edit: a video / picture clip (clipId) or the shots (clipIds)");s=t.filter(K=>K.track===lt.track&&Xu(K))}if(s=s.sort((lt,K)=>lt.start-K.start).slice(0,oi.shots),!s.length)throw Error("breakdownShowcase: no video / picture shots in that edit");const h=s[0].start,f=Math.max(...s.map(lt=>lt.start+lt.duration)),m=Wt(f-h);if(m>oi.seconds+1e-6)throw Error(`breakdownShowcase: the edit is ${m}s — at most ${oi.seconds}s (pick fewer shots)`);const g=Math.max(0,...t.map(lt=>lt.start+lt.duration)),v=Wt(Number.isFinite(r.at)&&r.at>=0?r.at:g),x=Wt(v+m),E=v-h,$=IC(r.style,r.color),S=vC[r.lang==="vi"?"vi":"en"],k=ih.includes(r.layout)?r.layout:$.layout??"stack",y=$C[i>n*1.05?"portrait":"landscape"][k],C=Array.isArray(r.labels)?r.labels.map(lt=>typeof lt=="string"?lt.trim().slice(0,oi.labels).toUpperCase():""):[],A=[...t],z=[],j=lt=>{const K=SC(A,e,lt);return z.push(K),K},P=new Set($.sig??[]),F=r.lang==="vi"?"vi":"en",N=Ng[F],G=FC(n/i),V=(lt,K,d=v,w=m,T={})=>j({id:a(),nodeId:"",kind:"image",url:"",label:lt,track:0,start:d,duration:w,volume:0,motionV:2,fit:"cover",shape:Ze({v:2,items:K}),...T}),et=CC(s[0],c,n,i),U=i>n*1.05,at=U?2.2:1.15,W=lt=>xo(lt.h/et),_=lt=>xo(lt.y-lt.h/2-.03);if(j({...Sp({id:a(),track:0,start:v,duration:m,label:"Breakdown · nền",fill:{type:"linear",from:$.bg[0],to:$.bg[1],angle:$.bg[2]},aspect:n/i})}),$.floor){const lt=PC($,n/i,y.floor?y.horizon??.5:null,m);j({id:a(),nodeId:"",kind:"image",url:"",label:y.floor?"Breakdown · sàn":"Breakdown · lưới",track:0,start:v,duration:m,volume:0,motionV:2,fit:"cover",shape:lt})}const J=c.find(lt=>lt.id===s[0].nodeId),tt=J?.width>1&&J?.height>1?J.width/J.height:s[0].kind==="video"?n/i:1,rt=lt=>{const K=lt.h,d=W(lt)*Math.min(1,tt*i/n);return{x0:.5+lt.x-d/2,x1:.5+lt.x+d/2,y0:.5+lt.y-K/2,y1:.5+lt.y+K/2}},{X:D,Y:q}=G;if(P.has("sun")){const lt=(y.horizon??.5)-.02,K=.2,d=[{id:"sun",name:"Sun",type:"ellipse",params:{w:Wt(K*2*1e3),h:Wt(K*2*1e3)},pos:[D(.5),q(lt)],rot:0,scale:[1,1],opacity:.9,fill:{type:"linear",angle:90,stops:[["#ffd85a",0],[$.accent,1]]},stroke:null}];for(let w=0;w<6;w++)d.push(_i(`b${w}`,D(.5),q(lt+K*(.1+w*.15)),K*2.2*1e3,4+w*3,{type:"color",color:$.bg[1]}));V("Breakdown · mặt trời",d)}if(P.has("frost")){const lt=[],d=(w,T)=>lt.push(_i(w,D((T.x0+T.x1)/2),q((T.y0+T.y1)/2),D(T.x1)-D(T.x0)+40,q(T.y1)-q(T.y0)+40,{type:"color",color:"#ffffff",opacity:.1},{color:"#ffffff",width:2,opacity:.35},{round:40}));if(y.final&&d("f",rt(y.final)),y.raw&&d("r",rt(y.raw)),y.start&&y.end){const w=rt(y.start),T=rt(y.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)})}lt.length&&V("Breakdown · kính mờ",lt)}const pt=lt=>{const K=jC(lt,c,$.round);return K?{mask:K}:{}},yt={color:$.rim,width:.012,glow:$.glow||0,amount:.9},Mt={...kn,opacity:$.glow?.55:.25,blur:24,distance:$.glow?12:8};if(y.final){const lt=y.final,K=W(lt),d=Kt(A,e,v,x).track;s.forEach((w,T)=>{const{id:I,parentId:O,...L}=w,B=TC(w,{x:lt.x,y:lt.y,s:K}),H={...L,...B,id:a(),track:d,start:Wt(w.start+E),...pt(w),edge:yt,shadow:Mt,motionKeys:T===0?OC(B.motionKeys,oc(w.duration,0)):B.motionKeys};A.push(H),z.push(H)}),P.has("headline")?j(Fr(a(),v,m,N.head,$,{x:lt.x,y:xo(_(lt)-.004),size:30,color:$.accent,font:$.move,italic:$.italic,weight:800,k:at})):j(Fr(a(),v,m,S.final,$,{x:lt.x,y:_(lt),size:26,k:at}))}if(y.raw){const lt=y.raw,K=W(lt),d=Kt(A,e,v,x).track;s.forEach((w,T)=>{const I=c.find(Z=>Z.id===w.nodeId),O=w.kind==="video"?w.sourceDuration??I?.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,H={id:a(),nodeId:w.nodeId,kind:w.kind,url:w.url,...w.gcsUri?{gcsUri:w.gcsUri}:{},label:w.label,track:d,start:Wt(w.start+E),duration:w.duration,inPoint:L,...O!=null?{sourceDuration:O}:{},volume:0,...B!==1?{playbackRate:Wt(B)}:{},...w.crop?{crop:w.crop}:{},motionV:2,posX:lt.x,posY:lt.y,scale:K,motionKeys:T===0?oc(w.duration,.08):[],...pt(w),edge:yt,shadow:Mt};A.push(H),z.push(H)}),j(Fr(a(),v,m,S.raw,$,{x:lt.x,y:_(lt),size:24,k:at}))}if(y.graph){const lt=y.graph,K=xo(P.has("gauge")?Math.min(lt.w/.96,.3/(.76*n/i)):lt.w/.96),d=Kt(A,e,v,x).track;s.forEach((T,I)=>{const O={id:a(),nodeId:"",kind:"image",url:"",label:`Speed graph · ${I+1}`,track:d,start:Wt(T.start+E),duration:T.duration,volume:0,motionV:2,fit:"contain",posX:lt.x,posY:lt.y,scale:K,motionKeys:I===0?oc(T.duration,.16):[],shape:P.has("gauge")?NC(T,$):zC(T,$)};A.push(O),z.push(O)});const w=K*(P.has("gauge")?.76:.6)*n/i;j(Fr(a(),v,m,P.has("gauge")?Ng[F].speed:S.graph,$,{x:lt.x,y:xo(lt.y-w/2-.028),size:24,k:at}))}if(y.start&&y.end){const lt=Kt(A,e,v,x).track,K=(d,w,T)=>{const I=W(w),O=d.kind==="video"?Wt(Math.max(0,c1(d,Math.min(d.duration,Math.max(0,T))))):null;return{id:a(),nodeId:d.nodeId,kind:d.kind,url:d.url,...d.gcsUri?{gcsUri:d.gcsUri}:{},label:d.label,start:Wt(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:Wt(d.duration),source:O}],blend:"none"}}:{},motionV:2,posX:w.x,posY:w.y,scale:I,motionKeys:[{time:0,opacity:.25,zoom:xo(I*.92),ease:{opacity:sh("ease-out"),zoom:sh("back-out")}},{time:Wt(Math.min(d.duration,.2)),opacity:1,zoom:I}],...pt(d),edge:yt,shadow:Mt}};s.forEach((d,w)=>{const T=K(d,y.start,0),I=K(d,y.end,d.duration-1/30);T.track=lt,A.push(T),z.push(T),I.track=Kt(A,e,I.start,I.start+I.duration).track,A.push(I),z.push(I)}),y.stillLabels!==!1&&j(Fr(a(),v,m,S.start,$,{x:y.start.x,y:_(y.start),size:22,k:at})),y.stillLabels!==!1&&j(Fr(a(),v,m,S.end,$,{x:y.end.x,y:_(y.end),size:22,k:at}))}if(y.move&&s.forEach((lt,K)=>{const d=C[K]||AC(s,K,S);if(P.has("log")){const T=Array.from({length:25},(B,H)=>Mp(lt,lt.duration*H/24)),I=Math.min(...T),O=Math.max(...T),L=`> ${N.shot} ${String(K+1).padStart(2,"0")}/${String(s.length).padStart(2,"0")} ${lt.duration.toFixed(1)}s
335
+ > ${N.speed} ${I.toFixed(1)}× → ${O.toFixed(1)}×
336
+ > ${N.move}: ${d}`;j(Fr(a(),Wt(lt.start+E),lt.duration,L,$,{x:y.move.x,y:y.move.y,size:20,color:$.accent,font:"Courier New",weight:700,anim:"type-on",k:at}))}else j(Fr(a(),Wt(lt.start+E),lt.duration,d,$,{x:y.move.x,y:y.move.y,size:32,color:$.accent,font:$.move,italic:$.italic,weight:800,k:at}))}),P.has("scan")){const lt=(K,d)=>{const w=[];for(let T=0;T<128;T++){const I=Wt(d+T*7.8);w.push(...T%2?[[D(1),I],[D(0),I]]:[[D(0),I],[D(1),I]])}return Jo(K,w,{color:"#000000",width:2,opacity:.35})};V("Breakdown · scanline",[lt("s1",2),lt("s2",2+128*7.8)])}const l=y.final?rt(y.final):null;if(P.has("brackets")&&l){const d={color:$.accent,width:6,join:"miter",...$.glow?{blur:6}:{}},w=l.x0-.018,T=l.x1+.018,I=l.y0-.018,O=l.y1+.018;V("Breakdown · ngoặc góc",[Jo("tl",[[D(w),q(I+.05)],[D(w),q(I)],[D(w+.05*i/n),q(I)]],d),Jo("tr",[[D(T-.05*i/n),q(I)],[D(T),q(I)],[D(T),q(I+.05)]],d),Jo("bl",[[D(w),q(O-.05)],[D(w),q(O)],[D(w+.05*i/n),q(O)]],d),Jo("br",[[D(T-.05*i/n),q(O)],[D(T),q(O)],[D(T),q(O-.05)]],d)])}if(P.has("rings")&&l){const lt=(l.x0+l.x1)/2,K=(l.y0+l.y1)/2,d=Math.max(l.y1-l.y0,(l.x1-l.x0)*n/i)*.62*1e3,w=(T,I,O,L,B)=>({id:T,name:T,type:"ellipse",params:{w:Wt(I*2),h:Wt(I*2)},pos:[D(lt),q(K)],rot:0,scale:[1,1],opacity:.7,fill:{type:"none"},stroke:{color:$.accent,width:B,dash:O,...$.glow?{blur:6}:{}},keys:{rot:[{time:0,value:0},{time:Wt(m),value:Wt(L*m*24)}]}});V("Breakdown · vòng HUD",[w("r1",d,[40,26],1,4),w("r2",d*1.07,[8,18],-1,3)])}if(P.has("index")&&l&&s.forEach((lt,K)=>{const d=$.id==="dark-luxury"?LC[K]:String(K+1).padStart(2,"0");j(Fr(a(),Wt(lt.start+E),lt.duration,d,$,{x:xo(l.x0-.5+.07),y:xo(l.y0-.5+.06),size:48,color:$.accent,font:$.move,italic:$.italic,weight:800,k:at,glow:!1}))}),P.has("dims")&&l){const lt={color:$.text,width:3},K=.012,d=l.y1+.03,w=l.x0-.035*i/n;V("Breakdown · kích thước",[Jo("h",[[D(l.x0),q(d)],[D(l.x1),q(d)]],lt),Jo("ha",[[D(l.x0+K),q(d-K)],[D(l.x0),q(d)],[D(l.x0+K),q(d+K)]],lt),Jo("hb",[[D(l.x1-K),q(d-K)],[D(l.x1),q(d)],[D(l.x1-K),q(d+K)]],lt),Jo("v",[[D(w),q(l.y0)],[D(w),q(l.y1)]],lt),Jo("va",[[D(w-K),q(l.y0+K)],[D(w),q(l.y0)],[D(w+K),q(l.y0+K)]],lt),Jo("vb",[[D(w-K),q(l.y1-K)],[D(w),q(l.y1)],[D(w+K),q(l.y1-K)]],lt)]);const T=J?.width>1?`${J.width} × ${J.height}`:"";s.forEach((I,O)=>{const L=j(Fr(a(),Wt(I.start+E),I.duration,`${T?T+" · ":""}${I.duration.toFixed(1)} s`,$,{x:xo((w+l.x0)/2-.5-.012*i/n),y:xo((l.y0+l.y1)/2-.5),size:16,color:$.text,weight:500,k:at,glow:!1}));L.rotation=-90})}if(P.has("arrows")&&l&&y.raw){const lt=rt(y.raw),K=[lt.x0<l.x0?lt.x1+.01:lt.x0-.01,(lt.y0+lt.y1)/2],d=[l.x0<lt.x0?l.x1+.01:l.x0-.01,(l.y0+l.y1)/2+.03],w=[(K[0]+d[0])/2,Math.min(K[1],d[1])-.08],T=[];for(let st=0;st<=16;st++){const Y=st/16,ct=(1-Y)*(1-Y)*K[0]+2*Y*(1-Y)*w[0]+Y*Y*d[0],mt=(1-Y)*(1-Y)*K[1]+2*Y*(1-Y)*w[1]+Y*Y*d[1];T.push([D(ct),q(mt)])}const I=T[16][0]-T[15][0],O=T[16][1]-T[15][1],L=Math.hypot(I,O)||1,B=I/L,H=O/L,Z=26,ot=T[16];V("Breakdown · mũi tên",[Jo("c",T,{color:$.accent,width:6,cap:"round",dash:[18,12]}),Jo("hd",[[Wt(ot[0]-B*Z-H*Z*.6),Wt(ot[1]-H*Z+B*Z*.6)],ot,[Wt(ot[0]-B*Z+H*Z*.6),Wt(ot[1]-H*Z-B*Z*.6)]],{color:$.accent,width:6,cap:"round"})],v,m,{motionKeys:oc(m,.3)})}if(P.has("strip")){const lt=U?.965:.955,K=.06,d=.94,w=[_i("bg",D(.5),q(lt),D(d)-D(K),18,{type:"color",color:$.text,opacity:.15})];s.forEach((T,I)=>{const O=K+(d-K)*(T.start-h)/m,L=K+(d-K)*(T.start+T.duration-h)/m;w.push(_i(`s${I}`,D((O+L)/2),q(lt),D(L)-D(O)-4,14,{type:"color",color:I%2?$.accent:$.rim,opacity:.85}))}),w.push(_i("ph",D(K),q(lt),5,44,{type:"color",color:"#ff3b3b"},null,{keys:{"pos.0":[{time:0,value:D(K)},{time:Wt(m),value:D(d)}]}})),V("Breakdown · timeline",w)}return P.has("osd")&&(j(Fr(a(),v,m,N.play,$,{x:-.33,y:.465,size:22,color:"#ffffff",font:"Courier New",weight:700,k:at,glow:!1})),V("Breakdown · REC",[{id:"rec",name:"Rec",type:"ellipse",params:{w:22,h:22},pos:[D(.06),q(.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)},(lt,K)=>({time:Wt(K*.5),value:K%2?0:1}))}}]),s.forEach((lt,K)=>{const d=lt.start-h,w=Math.floor(d/60),T=(d%60).toFixed(1).padStart(4,"0");j(Fr(a(),Wt(lt.start+E),lt.duration,`${N.shot} ${String(K+1).padStart(2,"0")} 00:${String(w).padStart(2,"0")}:${T}`,$,{x:.22,y:.465,size:20,color:"#ffffff",font:"Courier New",weight:700,k:at,glow:!1}))})),{add:z,shots:s.map(lt=>lt.id),start:v,end:x,style:$.id,layout:k}}const DC=String.raw`
337
+ const L=S.look
338
+ 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'}
339
+ function FF(env,k){const f=env.fonts||{};return (k!=='mono'&&f[k])||FONTS[k]||FONTS.mont}
340
+ 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']]
341
+ const LIGHT=['widget','paper','comic'].includes(L.frame)
342
+ 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()}
343
+ 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()}
344
+ 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}
345
+ // the panel's body in its design: x, y, w, h in the element canvas; role = chip | box | card | key
346
+ function box(g,x,y,w,h,role,a,t){
347
+ g.save();g.globalAlpha=a;const s=Math.min(w,h),lw=Math.max(1.5,s*.018)
348
+ const F=L.frame
349
+ 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)}
350
+ 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)
351
+ 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()})
352
+ 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)}}
353
+ 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()
354
+ 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()})}}
355
+ 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'}
356
+ 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()
357
+ 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)})}
358
+ 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}
359
+ 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'
360
+ 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()}}
361
+ 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)
362
+ 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()}}
363
+ 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)
364
+ 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)}
365
+ 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)
366
+ 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()}
367
+ 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()}}
368
+ 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)}}
369
+ 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()}}
370
+ 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)}}
371
+ 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)}}
372
+ 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()}}
373
+ g.restore()
374
+ }
375
+ // text inside a panel: dark on the light designs, mono / caps per design
376
+ function inkOf(){return L.text}
377
+ 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('')}
378
+ function txt(s){return ['cut','notch','film','pixel'].includes(L.frame)?String(s).toUpperCase():String(s)}
379
+ 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}
380
+ function typedAt(t){let n=0;for(let i=0;i<TT.length;i++)if(TT[i]<=t)n=i+1;return n}
381
+ function draw(g,t,DW,DH,env){
382
+ const pad=DH*.08
383
+ 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}
384
+ if(S.kind==='prompt'){
385
+ const ch=DH*.18,n=typedAt(t)
386
+ // the model line: a chip over the box, or the window title (terminal), or the slate (film)
387
+ 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)}
388
+ 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)}
389
+ 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)}
390
+ const by=L.frame==='terminal'?DH*.15:ch+DH*.05,bh=DH-by-4,bx=L.frame==='radial'?DH*.42:0
391
+ if(L.frame!=='terminal')box(g,2,by,DW-4-(L.frame==='bubble'?DH*.08:0),bh,'box',1,t)
392
+ 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)}
393
+ // chat: three bouncing dots until the first letter
394
+ 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}
395
+ 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'
396
+ const lead=L.frame==='terminal'?'> ':'',maxW=DW-pad*2.4-bx-(L.frame==='bubble'?DH*.08:0)
397
+ const lines=wrap(g,lead+txt(shown),maxW).slice(-4)
398
+ 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)})
399
+ 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
400
+ 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)}
401
+ return}
402
+ if(S.kind==='grid')return drawGrid(g,t,DW,DH,env)
403
+ if(S.kind==='cta'){
404
+ 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)
405
+ 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))
406
+ g.save();g.translate(DW/2,DH*.28);g.scale(pop,pop)
407
+ 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()}
408
+ 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')
409
+ 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()
410
+ const n=C.chips.length,cw=DW*.32,chh=DH*.16,gap=DW*.04,x0=DW/2-(n*cw+(n-1)*gap)/2
411
+ 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)
412
+ 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()})
413
+ 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()}
414
+ 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()}}
415
+ return}
416
+ if(S.kind==='keyboard')return drawKeys(g,t,DW,DH,env)
417
+ }
418
+ 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)}}
419
+ if(n>=S.text.length&&TT.length&&t-TT[TT.length-1]>.25&&t-TT[TT.length-1]<.6)lit.enter=1;return lit}
420
+ function drawKeys(g,t,DW,DH,env){
421
+ const lit=litMap(t),K=L.keys
422
+ 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)
423
+ 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)})
424
+ 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}
425
+ const kw=DW/10.6,kh=DH/4.6,g1=kw*.12
426
+ const key=(x,y,w,h,label,v)=>{
427
+ g.save()
428
+ 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()}
429
+ 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()}
430
+ 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}
431
+ 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'
432
+ 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)}}
433
+ 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()}}
434
+ 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()}}
435
+ 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)}}
436
+ 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)}}
437
+ 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)}
438
+ g.restore()}
439
+ 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))})
440
+ 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)
441
+ }
442
+ function drawGrid(g,t,DW,DH,env){
443
+ 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))
444
+ 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)
445
+ g.save();g.translate(cx,cy);g.rotate(rot*(me?1-pk:1));g.scale(s,s);g.globalAlpha=Math.min(1,e)*dim
446
+ 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
447
+ box(g,x,y,cw,chh+(pol?cw*.18:0),'card',1,t)
448
+ 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()
449
+ 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)}
450
+ 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)}
451
+ g.restore()
452
+ if(pol){g.fillStyle='#333';g.font=fontOf(env,500,cw*.09);g.textAlign='center';g.fillText('#'+(k+1),0,chh/2+cw*.09)}
453
+ 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()}
454
+ g.restore()}
455
+ const appear=k=>M.ease.outBack(M.clamp((t-.08-k*.09)/.4,0,1))
456
+ 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
457
+ 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)}}
458
+ 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)}}
459
+ 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
460
+ 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)
461
+ 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()}}
462
+ 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)}}
463
+ 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)}}
464
+ 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
465
+ 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)}
466
+ for(let k=0;k<n;k++)card(k,cw*.55+k*cw*1.05+slide+pickShift,DH/2,cw,chh,0,1,1)}
467
+ 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})}
468
+ 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))}
469
+ }
470
+ // 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
471
+ // tiltX (top away) / tiltY (right side away) degrees, in perspective; stuck on a surface it fills the layer
472
+ function quad(W,H,DW,DH){
473
+ if(S.fill)return [[W*.04,H*.04],[W*.96,H*.04],[W*.04,H*.96],[W*.96,H*.96]]
474
+ 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
475
+ 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]})
476
+ }
477
+ 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
478
+ 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]
479
+ 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]]){
480
+ 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]}
481
+ 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()
482
+ 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])
483
+ 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
484
+ 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
485
+ 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
486
+ ctx.transform(A,B,C,Dd,E,F);ctx.drawImage(img,0,0)}
487
+ ctx.restore()}}}
488
+ function size(){const k=S.kind
489
+ if(k==='keyboard')return L.keys==='radial'?[1100,560]:[1100,520]
490
+ if(k==='chip')return [Math.round(260+S.text.length*15),L.frame==='comic'?130:100]
491
+ if(k==='cta')return [900,760]
492
+ 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]
493
+ return [1000,560]}
494
+ function render(ctx,t,env){
495
+ const W=env.width,H=env.height,dur=env.duration,E=L.enter
496
+ const len=E==='step'?.5:E==='drop'?.6:E==='spring'?.7:E==='track'?.9:E==='scan'?.55:E==='strip'?.55:.35
497
+ const on=M.clamp((t-.02)/len,0,1),off=M.clamp((dur-t)/.3,0,1);if(on<=0||off<=0)return
498
+ const [DW,DH]=size(),cv=typeof OffscreenCanvas!=='undefined'?new OffscreenCanvas(DW,DH):null;if(!cv)return
499
+ draw(cv.getContext('2d'),t,DW,DH,env)
500
+ 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
501
+ const eo=M.ease.outCubic(on)
502
+ if(E==='flicker'){a*=eo*(t<.3?(.55+.45*Math.abs(Math.sin(t*90))):1);sx=sy=.86+.14*M.ease.outBack(on)}
503
+ 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)}
504
+ else if(E==='slide'){dy=(1-eo)*H*.08;a*=eo}
505
+ else if(E==='spring'){sx=sy=M.ease.outElastic?M.ease.outElastic(on)*.999+.001:eo;a*=Math.min(1,on*4)}
506
+ else if(E==='glitch'){a*=Math.min(1,on*3);slices=on<1?1-on:0}
507
+ 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}
508
+ else if(E==='drop'){dy=-(1-M.ease.outBounce(on))*H*.25;rot+=(1-on)*.15;a*=Math.min(1,on*4)}
509
+ else if(E==='scan'){clipY=eo}
510
+ else if(E==='step'){const s=Math.ceil(on*4)/4;sx=sy=s;a*=on>0?1:0}
511
+ else if(E==='burst'){sx=sy=M.ease.outBack(on)*1.0;a*=Math.min(1,on*3)}
512
+ else if(E==='fade'){a*=eo;dy=(1-eo)*H*.015}
513
+ else if(E==='iris'){iris=eo}
514
+ else if(E==='strip'){dx=-(1-eo)*W*.6;a*=Math.min(1,on*2)}
515
+ else if(E==='track'){a*=eo}
516
+ 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)
517
+ 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]})
518
+ ctx.save();ctx.globalAlpha=Math.max(0,a)
519
+ 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()}
520
+ if(E==='iris'&&iris<1){ctx.beginPath();ctx.arc(mx,my,Math.hypot(W,H)*.5*iris,0,7);ctx.clip()}
521
+ 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)}}
522
+ else warp(ctx,cv,DW,DH,q,0,0,1,clipY)
523
+ 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()}
524
+ ctx.restore()
525
+ }`,qo=(t,e,o,r,a,n,i,c,u)=>({id:t,vi:e,en:o,frame:r,enter:a,keys:n,grid:i,font:c,...u}),lh=Object.freeze([qo("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}),qo("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}),qo("terminal","Terminal","Terminal","terminal","slide","mono","list","mono",{line:"#2bff6a",fill:"rgba(4,10,6,0.86)",text:"#b9ffcf",accent:"#2bff6a",glow:10}),qo("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}),qo("wireframe","Khung dây","Wireframe","wire","glitch","dots","grid","mono",{line:"#7fb8ff",fill:"rgba(0,0,0,0)",text:"#cfe4ff",accent:"#7fb8ff",glow:12}),qo("neon","Ống neon","Neon tube","neon","buzz","outline","fan","bungee",{line:"#ff4fd8",fill:"rgba(0,0,0,0)",text:"#ffe6fa",accent:"#ff4fd8",glow:26}),qo("paper","Giấy & polaroid","Paper & polaroid","paper","drop","round","polaroid","play",{line:"#2b2b2b",fill:"#f6f1e4",text:"#1e1e1e",accent:"#d9472b",glow:0}),qo("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}),qo("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}),qo("comic","Truyện tranh","Comic","comic","burst","round","polaroid","bungee",{line:"#111111",fill:"#ffffff",text:"#111111",accent:"#ff2e4d",glow:0}),qo("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}),qo("chat","Bong bóng chat","Chat bubbles","bubble","slide","ios","stack","bevn",{line:"#2f80ff",fill:"#2f80ff",text:"#ffffff",accent:"#2f80ff",glow:0}),qo("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}),qo("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}),qo("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})]),Rg=lh.map(t=>t.id),Dg=Object.freeze(["chip","prompt","grid","cta","keyboard"]),pr=Object.freeze({maxSeconds:30,text:160,chip:48,items:9,chips:3,cps:[4,40],tilt:75,width:[.1,1]}),ew=/^#[0-9a-fA-F]{6}$/,vc=t=>Math.round(t*1e3)/1e3,is=t=>Math.round(t*1e4)/1e4,gn=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,Pn=(t,e)=>typeof t=="string"?t.replace(/[\u0000-\u001f]/g," ").trim().slice(0,e):"";function ow(t,e){const o=lh.find(r=>r.id===t)??lh[0];return ew.test(e??"")?{...o,accent:e.toLowerCase(),...o.glow?{line:e.toLowerCase()}:{}}:o}function rw(t,e=.4,o=14){const r=[],a=1/gn(o,...pr.cps,14);let n=e;for(let i=0;i<t.length;i++){r.push(vc(n));const c=t[i],u=(Math.sin((i+1)*12.9898)*43758.5453%1+1)%1;n+=a*(.7+.6*u)*(c===" "?1.4:/[,.!?]/.test(c)?2.2:1)}return r}const Bg=(t,e)=>`const ${t}=${JSON.stringify(e)};`;function BC(t,e=[],o){return Qe({code:[Bg("S",t),Bg("TT",e),DC].join(`
526
+ `),params:{color:t.look.accent},preset:`hud-${t.kind}`,...o&&Object.keys(o).length?{assets:o}:{}})}function _C(t,e,{materials:o=[],locale:r="vi",fill:a=!1}={}){if(!Dg.includes(t))throw Error(`hudPanel kind: ${Dg.join(" | ")}`);if(e.look!=null&&!Rg.includes(e.look))throw Error(`HUD look: ${Rg.join(" | ")}`);if(e.color!=null&&!ew.test(e.color))throw Error("HUD color must be #RRGGBB");const n=ow(e.look,e.color),i=r==="en",c={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],u={kind:t,look:n,fill:!!a,x:is(gn(Number(e.posX),-.5,.5,c[0])),y:is(gn(Number(e.posY),-.5,.5,c[1])),w:is(gn(Number(e.width),...pr.width,c[2])),tiltX:vc(gn(Number(e.tiltX),-pr.tilt,pr.tilt,c[3])),tiltY:vc(gn(Number(e.tiltY),-pr.tilt,pr.tilt,c[4]))};let p=[],s={},h;if(t==="chip"&&(u.text=Pn(e.text,pr.chip)||(i?"Random photos → AI Edit":"Ảnh bất kỳ → AI Edit"),h=`HUD · ${u.text}`),t==="prompt"||t==="keyboard"){if(u.text=Pn(e.text,pr.text),!u.text)throw Error(`hudPanel ${t} needs text (the prompt that types in)`);p=rw(u.text,gn(Number(e.typeAt),0,pr.maxSeconds,.5),Number(e.cps)),t==="prompt"&&(u.label=Pn(e.label,30)||(i?"Image model:":"Model ảnh:"),u.model=Pn(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,pr.items):null,m=f?f.length:Math.round(gn(Number(e.count),2,pr.items,6));if(m<2)throw Error("hudPanel grid needs 2–9 items");u.items=[];for(let g=0;g<m;g++){const v=f?.[g],x=typeof v=="string"?v:v?.materialId,E={title:Pn(typeof v=="object"?v?.title:"",30)||`${g+1}`};if(x!=null){const $=o.find(k=>k.id===x);if(!$||$.kind!=="image"||typeof $.gcsUri!="string")throw Error(`hudPanel grid item ${g+1}: "${String(x).slice(0,40)}" is not a picture in the Media bin`);const S=`grid${g}.img`;s[S]=$.gcsUri,E.img=S}u.items.push(E)}u.cols=Math.round(gn(Number(e.cols),1,3,m<=4?2:3)),u.pick=Number.isInteger(e.pick)&&e.pick>=0&&e.pick<m?e.pick:-1,u.pickAt=vc(gn(Number(e.pickAt),0,pr.maxSeconds,1.6)),h=`HUD · ${m} ảnh`}if(t==="cta"){const f=Array.isArray(e.chips)?e.chips.slice(0,pr.chips).map(m=>Pn(m,48)).filter(Boolean):[];u.cta={lead:Pn(e.lead,30)||(i?"comment":"bình luận"),word:Pn(e.keyword,20).toUpperCase()||"CLIPOOX",chips:f,doc:e.doc===!1?"":Pn(e.doc,20)||(i?"FULL GUIDE":"HƯỚNG DẪN")},h=`HUD · comment ${u.cta.word}`}return{S:u,TT:p,assets:s,label:h}}function VC(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 GC(t,e,o,r){if(!e||t.fill)return"";const a=e.y-.15,n=e.y+.13,i=r>o*1.1?.3:.17,c=f=>f*VC(t)*(o/r)*Math.cos(t.tiltX*Math.PI/180),u=(f,m)=>[.5+f-c(m)/2,.5+f+c(m)/2],p=f=>[.5+t.x-f/2,.5+t.x+f/2];if(!((f,m)=>{const[g,v]=u(f,m),[x,E]=p(m);return v>a&&g<n&&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=is(f*.9)){const m=c(f),g=a-.012-m/2-.5,v=n+.012+m/2-.5,x=$=>.5+$-m/2>=.02&&.5+$+m/2<=.98,E=[g,v].filter(x).sort(($,S)=>Math.abs($-h)-Math.abs(S-h))[0];if(E!=null)return t.y=is(E),t.w=f,`moved ${E<h?"up":"down"} off the face${f<.999*t.w,""}`}return t.w=.3,t.y=is(.48-c(.3)/2),"shrunk to the bottom edge, off the face"}const mo=1/30,ue=(t,e,o)=>Math.max(e,Math.min(o,t)),ye=t=>+t.toFixed(4),Ce=(t,e)=>Number.isFinite(t)?t:e,KC=/^#[0-9a-f]{6}$/i,gl=t=>!!t&&(t.kind==="video"||t.kind==="image")&&!t.title&&!t.shape&&!t.motion&&!t.solid,nw=["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","join","shocks","impacts","trail","pendingPin","pin","bubble","layout"],pe=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 WC(t,{at:e,steps:o=pe.step.defaults.steps,frames:r=pe.step.defaults.frames,amount:a=pe.step.defaults.amount,point:n=null,back:i=!0}={}){if(!gl(t))throw Error("stepPunch needs a video or image clip");const c=pe.step,u=Math.round(ue(Ce(o,c.defaults.steps),...c.steps)),p=Math.round(ue(Ce(r,c.defaults.frames),...c.frames)),s=ue(Ce(a,c.defaults.amount),...c.amount);if(!Number.isFinite(e)||e<0||e>=t.duration-mo)throw Error("stepPunch must start inside the clip");const h=ut(e),f=u*p*mo;let m=ut(h+f),g=!i;if(m>=t.duration-mo/2&&(m=t.duration,g=!0),h+p*mo>t.duration+1e-6)throw Error("stepPunch is too long for the clip");const v=Yt.hold,x=Array.isArray(n)?ue(Number(n[0])-.5,-.5,.5):0,E=Array.isArray(n)?ue(Number(n[1])-.5,-.5,.5):0,$={...t,...pn(t)},S=[];h>=mo&&S.push({time:ut(h-mo),f:0});for(let z=1;z<=u;z++){const j=ut(h+(z-1)*p*mo);j<t.duration-1e-6&&S.push({time:j,f:z/u})}g||S.push({time:m,f:0});const k=S[0].time,y=g?t.duration:m,C=(z,j)=>{const P=Qt($,"zoom",j.time)||1,F=Math.min(bs,P*(1+(s-1)*j.f));if(z==="zoom")return ye(F);const N=Math.max(0,(F-1)/2),G=-(F-P)*(z==="x"?x:E);return ye(ue(Qt($,z,j.time)+ue(G,-N,N),-1,1))};let A={...$};for(const z of x||E?["zoom","x","y"]:["zoom"]){const j=Ee($,z).filter(F=>F.time<k-.001||F.time>y+.001),P=S.map(F=>({time:F.time,value:C(z,F),ease:v}));A={...A,...ge(A,z,[...j,...P].sort((F,N)=>F.time-N.time))}}return jn(A),{motionV:A.motionV,motionKeys:A.motionKeys,...A.posX!==void 0?{posX:A.posX,posY:A.posY,scale:A.scale}:{}}}const _g=Object.freeze(["white","red","magenta","yellow","lime"]);function HC(t,{frames:e=pe.matte.default,side:o="in",aspect:r=16/9,color:a="white",background:n="black"}={},i){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");if(!_g.includes(a))throw Error(`matteFlash color: ${_g.join(" | ")}`);if(n!=="black"&&n!=="plate")throw Error("matteFlash background: black | plate");const c=Math.round(ue(Ce(e,pe.matte.default),...pe.matte.frames)),u=ut(c*mo);if(t.duration<u+mo)throw Error("matteFlash: the clip is shorter than the flash");const p=o==="in"?t.start:ut(t.start+t.duration-u);let s=Jn(t,i());for(const m of nw)delete s[m];if(delete s.enter,delete s.exit,o==="in"){const[m]=_e(s,ut(t.start+u),i());s={...m,id:s.id}}else{const[,m]=_e(s,p,i());s={...m??s,id:s.id}}const h={...s,label:`${t.label||"Clip"} · bóng`,volume:0,effects:[{type:"fade",amount:1},{type:"threshold",amount:.02},...a==="white"?[]:[{type:`wash-${a}`,amount:1}]],opacity:1};delete h.saturation;for(const m of["colorBypass","blend","grade","edge","shadow","glow"])delete h[m];return n==="plate"?[h]:[Sp({id:i(),track:t.track,start:p,duration:u,label:"Nền đen",fill:{type:"color",color:"#000000"},aspect:r}),h]}function XC(t,{at:e,duration:o=pe.drain.default}={},r){if(!gl(t))throw Error("endingDrain needs a video or image clip");const a=ut(ue(Ce(e,t.start),t.start,t.start+t.duration-2*mo)),n=t.start+t.duration,i=ut(ue(Ce(o,pe.drain.default),pe.drain.duration[0],Math.min(pe.drain.duration[1],n-a)));if(i<2*mo)throw Error("endingDrain: not enough of the clip left after `at`");let c={...t,id:r(),volume:0};for(const p of nw)delete c[p];if(delete c.enter,delete c.exit,a>t.start+1e-6){const[,p]=_e(c,a,r());p&&(c={...p,id:c.id})}c={...c,label:`${t.label||"Clip"} · rút màu`,saturation:0};const u=[{time:0,value:0,ease:Yt["ease-in-out"]},{time:ye(Math.min(i,c.duration)),value:1}];return{...c,...ge(c,"opacity",u)}}function UC(t,e,{at:o,radius:r=pe.iris.defaults.radius,push:a=pe.iris.defaults.push,cx:n=.5,cy:i=.5,feather:c=.006,W:u=1280,H:p=720,material:s=null,newId:h}={}){const f=t.find(F=>F.id===e);if(!gl(f))throw Error("irisHold needs a video or image clip");const m=pe.iris,g=Math.round(s?.width)||u,v=Math.round(s?.height)||p,x=ue(Ce(r,m.defaults.radius),...m.radius)*Math.min(g,v)/g,E=x*g/v,$=ue(Ce(a,m.defaults.push),...m.push),S=ue(Ce(n,.5),x,1-x),k=ue(Ce(i,.5),Math.min(E,.5),Math.max(1-E,.5));let y=t,C=f;const A=ut(ue(Ce(o,f.start),f.start,f.start+f.duration-3*mo));if(A>f.start+1e-6){const[F,N]=_e(f,A,h?.()??`${f.id}-iris`);N&&(y=y.flatMap(G=>G.id===f.id?[F,N]:[G]),C=N)}const z={...C,...pn(C)},j=Qt(z,"zoom",0)||1;let P={...z,mask:{v:1,mw:g,mh:v,keys:[{t:0,pts:Yy(S,k,x,g,v,32)}],smooth:!0,feather:ue(Ce(c,.006),0,.1)}};for(const F of["person","roto","planar","bubble"])delete P[F];return $>1.0005&&(P={...P,...ge(P,"zoom",[{time:0,value:ye(j),ease:Yt["ease-out"]},{time:ye(C.duration),value:ye(Math.min(bs,j*$))}])}),jn(P),{clips:y.map(F=>F.id===C.id?P:F),irisId:C.id}}function YC({W:t,H:e,width:o,cx:r=.5,cy:a=.5,aspect:n}){const i=pe.card,c=.02*Math.min(t,e);let u=t*ue(Ce(o,i.defaults.width),...i.width),p=u/ue(n,...i.aspect);return p>e-2*c&&(p=e-2*c,u=p*ue(n,...i.aspect)),{x:ue(t*Ce(r,.5)-u/2,c,Math.max(c,t-c-u)),y:ue(e*Ce(a,.5)-p/2,c,Math.max(c,e-c-p)),w:u,h:p}}function qC(t,{W:e,H:o,mw:r,mh:a,rect:n,round:i=pe.card.defaults.round}){const c=n.w/n.h;let u=r,p=u/c;p>a&&(p=a,u=p*c);const s=t.fit==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a),h=n.w/(u*s),f=ue(2*ue(Ce(i,pe.card.defaults.round),...pe.card.round)*n.w/Math.min(n.w,n.h),0,1),m=Dn({kind:"rect",cx:.5,cy:.5,w:ye(u/r),h:ye(p/a),rot:0,round:ye(f)},r,a);return{mask:fr({mw:r,mh:a},[m]),posX:ye((n.x+n.w/2-e/2)/e),posY:ye((n.y+n.h/2-o/2)/o),scale:ye(h)}}function aw(t,{W:e=1280,H:o=720,material:r=null,width:a,cx:n,cy:i,aspect:c,round:u,rim:p=pe.card.defaults.rim,glow:s=.25,zIndex:h=pe.card.zIndex,enter:f=!0}={}){if(!gl(t))throw Error("mediaCard needs a video or image clip");if(p!==!1&&!KC.test(String(p)))throw Error("mediaCard rim must be #RRGGBB or false");const m=Math.round(r?.width)||e,g=Math.round(r?.height)||o,v=YC({W:e,H:o,width:a,cx:n,cy:i,aspect:Ce(c,m/g)}),x=qC(t,{W:e,H:o,mw:m,mh:g,rect:v,round:u}),E={...t,motionV:2,motionKeys:[],posX:x.posX,posY:x.posY,scale:x.scale,mask:x.mask,zIndex:h,shadow:{...kn,opacity:.5,blur:22,distance:8},...p===!1?{}:{edge:{color:String(p).toLowerCase(),width:.004,glow:ue(Ce(s,.25),0,2)}},...f?{enter:{type:"pop",duration:.3},exit:{type:"fade",duration:.2}}:{}};p===!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];jn(E);const $={};for(const S of["motionV","motionKeys","posX","posY","scale","mask","zIndex","shadow","edge","enter","exit"])$[S]=E[S];for(const S of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])$[S]=void 0;return{patch:$,rect:{x:ye(v.x/e),y:ye(v.y/o),w:ye(v.w/e),h:ye(v.h/o)}}}function ZC(t,{W:e=1280,H:o=720,area:r=pe.board.area,gap:a=pe.board.gap,cols:n}={}){if(!Number.isInteger(t)||t<1||t>pe.board.max)throw Error(`mediaBoard takes 1–${pe.board.max} clips`);const i=o>e,c=ue(Math.round(Ce(n,i?Math.min(2,t):Math.min(t,t<=3?t:Math.ceil(t/2)))),1,t),u=Math.ceil(t/c),p=a*Math.min(e,o),s=r.w*e,h=r.h*o,f=(s-p*(c-1))/c,m=(h-p*(u-1))/u;return Array.from({length:t},(g,v)=>{const x=Math.floor(v/c),E=x===u-1?t-x*c:c,$=v-x*c,S=r.x*e+(s-(E*f+(E-1)*p))/2;return{cx:ye((S+$*(f+p)+f/2)/e),cy:ye((r.y*o+x*(m+p)+m/2)/o),width:ye(f/e),aspect:ye(f/m)}})}function JC(t,{W:e=1280,H:o=720,materials:r=[],area:a,gap:n,cols:i,step:c=pe.board.step,rim:u,round:p}={}){const s=ZC(t.length,{W:e,H:o,area:a,gap:n,cols:i}),h=new Map,f=[];return t.forEach((m,g)=>{const v=r.find(P=>P.id===m.nodeId)??null,x=Math.round(v?.width)||e,E=Math.round(v?.height)||o,$=s[g],S=x/E,k=S>=$.aspect?$.width:$.width*S/$.aspect,{patch:y,rect:C}=aw(m,{W:e,H:o,material:v,width:k,cx:$.cx,cy:$.cy,aspect:S,rim:u,round:p,enter:!1,zIndex:pe.card.zIndex-g%8}),A=ye(Math.min(Math.max(0,m.duration-.4),g*ue(Ce(c,pe.board.step),0,1))),z=Yt["expo-out"];let j={...m,...y};for(const P of Object.keys(y))y[P]===void 0&&delete j[P];j={...j,...ge(j,"y",[{time:A,value:ye(y.posY+.05),ease:z},{time:ye(A+.32),value:y.posY}])},j={...j,...ge(j,"opacity",[...A>mo/2?[{time:0,value:0,ease:Yt.hold}]:[],{time:A,value:0,ease:z},{time:ye(A+.24),value:1}])},jn(j),h.set(m.id,{...y,motionV:j.motionV,motionKeys:j.motionKeys,posX:j.posX,posY:j.posY,scale:j.scale}),f.push({id:m.id,...C})}),{patches:h,rects:f}}function QC(t,{moves:e}={}){if(!gl(t))throw Error("screenCamera needs a video or image clip");const o=pe.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,...pn(t)},a=Ce(r.scale,1),n=Ce(r.posX,0),i=Ce(r.posY,0),c=e.map(g=>{const v=Number(g?.at),x=ue(Ce(Number(g?.zoom),1.6),...o.zoom),E=ue(Ce(Number(g?.ramp),o.defaultRamp),...o.ramp);if(!Number.isFinite(v)||v<0||v>t.duration)throw Error("screenCamera: every move needs `at` inside the clip (seconds from its start)");const $=Array.isArray(g?.point)&&g.point.length===2&&g.point.every(Number.isFinite)?[ue(g.point[0],0,1),ue(g.point[1],0,1)]:[.5,.5],S=ye(Math.min(bs,a*x)),k=Math.max(0,(x-1)/2);return{at:ut(v),ramp:E,z:S,x:ye(n+ue(-($[0]-.5)*x,-k,k)),y:ye(i+ue(-($[1]-.5)*x,-k,k))}}).sort((g,v)=>g.at-v.at);for(let g=1;g<c.length;g++)if(c[g].at-c[g-1].at<2*mo)throw Error("screenCamera: moves must be at least 2 frames apart");const u=Yt["easy-ease"],p=Yt.hold,s=g=>{const v=g==="zoom"?a:g==="x"?n:i,x=[];let E=v;return c.forEach(($,S)=>{const k=ut(Math.max(S?c[S-1].at:0,$.at-$.ramp)),y=g==="zoom"?$.z:$[g];$.at-k>=mo&&x.push({time:k,value:ye(E),ease:u}),x.push({time:$.at,value:y,ease:p}),E=y}),x.filter(($,S,k)=>!S||$.time>k[S-1].time+1e-6)},h=Math.max(0,c[0].at-c[0].ramp),f=c.at(-1).at;let m={...r};for(const g of["zoom","x","y"]){const v=Ee(r,g).filter(x=>x.time<h-.001||x.time>f+.001);m={...m,...ge(m,g,[...v,...s(g)].sort((x,E)=>x.time-E.time))}}return jn(m),{motionV:m.motionV,motionKeys:m.motionKeys,posX:m.posX,posY:m.posY,scale:m.scale}}const tj=(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 ej(t,e,{point:o="palm",side:r="any",dir:a="auto",feather:n=pe.wipe.defaultFeather,finish:i=pe.wipe.finish,W:c=1280,H:u=720,mw:p,mh:s}={}){if(!e?.hands)throw Error("The footage has no hand track yet");if(!pe.wipe.dirs.includes(a))throw Error(`handWipe dir: ${pe.wipe.dirs.join(" | ")}`);const h=fl(e.hands),f=Math.max(t.start,e.start),m=Math.min(t.start+t.duration,e.start+e.duration);if(!(m-f>=4*mo))throw Error("The layer and the footage do not play at the same time");const g=Math.max(2,Math.min(De.maxFrames-10,Math.ceil((m-f)/sb))),v=[];for(let D=0;D<=g;D++){const q=f+(m-f)*D/g,pt=Xi(e,h,q,{point:o,side:r,W:c,H:u});pt&&v.push({T:q,x:pt.x/c,y:pt.y/u})}if(v.length<2)throw Error("No hand is seen while the layer plays");let x=a;if(x==="auto"){const D=v.map(l=>l.x),q=v.map(l=>l.y),pt=Math.max(...D)-Math.min(...D),yt=Math.max(...q)-Math.min(...q),Mt=pt>=yt?v.at(-1).x-v[0].x:v.at(-1).y-v[0].y;x=pt>=yt?Mt>=0?"right":"left":Mt>=0?"down":"up"}const E=x==="right"||x==="left",$=x==="right"||x==="down",S=D=>E?D.x:D.y;let k=$?-1/0:1/0;const y=v.map(D=>(k=$?Math.max(k,S(D)):Math.min(k,S(D)),{T:D.T,e:k}));let C=y.findIndex(D=>Math.abs(D.e-y[0].e)>.004);if(C<0)throw Error("The hand does not move across the picture while the layer plays");C=Math.max(0,C-1);let A=y.length-1;for(;A>C+1&&Math.abs(y[A].e-y[A-1].e)<1e-4;)A--;const z=$?-.02:1.02,j=y.slice(C,A+1),P=j[0],F=j.at(-1),N=.3,G=D=>D*D*(3-2*D),V=D=>z+(D.e-z)*G(ue((D.T-P.T)/N,0,1)),et=Math.round(p)||c,U=Math.round(s)||u,at=D=>ye(D-t.start),W=(D,q,pt)=>{const yt=f1(t,D*c,q*u,pt-t.start,c,u,et,U);return[yt.u,yt.v]},_=(D,q)=>{const pt=z,yt=ue(D,-.02,1.02);return(E?[[pt,-.02],[yt,-.02],[yt,1.02],[pt,1.02]]:[[-.02,pt],[1.02,pt],[1.02,yt],[-.02,yt]]).map(([l,lt])=>W(l,lt,q).map(K=>ye(ue(K,-1,2))))},J=[],tt=(D,q)=>{(!J.length||D>J.at(-1).t+1e-4)&&J.push({t:D,pts:q})};P.T-t.start>mo/2&&tt(0,_(z,t.start));for(const D of j)tt(at(D.T),_(V(D),D.T));const rt=Math.min(t.start+t.duration,F.T+ue(Ce(i,pe.wipe.finish),mo,2));return rt-F.T>=mo/2?tt(at(rt),_($?1.02:-.02,rt)):J[J.length-1]={t:J.at(-1).t,pts:_($?1.02:-.02,F.T)},{patch:{mask:{v:1,mw:et,mh:U,keys:J,smooth:!1,feather:ue(Ce(n,pe.wipe.defaultFeather),...pe.wipe.feather)}},dir:x,from:ye(P.T),to:ye(rt)}}const Vg=["track","planar"],ys=t=>+Number(t).toFixed(5),oj=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 rj(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(ys))}const o=oj(t),r=(o.x1-o.x0)*.1+.01,a=(o.y1-o.y0)*.1+.01,n=s=>Math.max(0,Math.min(1,s)),i=n(o.x0-r),c=n(o.x1+r),u=n(o.y0-a),p=n(o.y1+a);return[[i,u],[c,u],[c,p],[i,p]].map(s=>s.map(ys))}function nj(t,e){for(const a of[t.mask,t.person,t.colorPerson,t.planar,t.roto])if(a&&Number.isInteger(a.mw)&&Number.isInteger(a.mh)&&a.mw>=2&&a.mh>=2)return{mw:a.mw,mh:a.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 aj(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(A2(t.mask))throw Error("this clip's masks are stored large (frame-by-frame roto) — edit them in the Clipoox editor");const a=r.masks===void 0?[]:r.masks;if(!Array.isArray(a)||a.length>bl)throw Error(`masks: up to ${bl}`);const n=r.remove===void 0?[]:r.remove;if(!Array.isArray(n)||n.some(s=>typeof s!="string"))throw Error("remove: mask ids");if(!a.length&&!n.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 c=r.replace===!0?[]:ui(t.mask).filter(s=>!n.includes(s.id));const u=[];for(const[s,h]of a.entries()){if(!h||typeof h!="object")throw Error(`masks[${s}]: an object`);const f=Object.fromEntries(Object.entries(h).filter(([,$])=>$!==null)),m=f.mode??"add";if(!Jh.includes(m))throw Error(`masks[${s}].mode: ${Jh.join("|")}`);if(!Array.isArray(f.keys)||!f.keys.length||f.keys.length>rd)throw Error(`masks[${s}].keys: 1–${rd} keys {t, pts}`);const g=[...f.keys].map($=>({t:ys(Number($?.t)),pts:Array.isArray($?.pts)?$.pts.map(S=>Array.isArray(S)?S.map(ys):S):$?.pts})).sort(($,S)=>$.t-S.t);for(const $ of g)if(!Array.isArray($.pts)||$.pts.length<3||$.pts.length>Qu)throw Error(`masks[${s}]: every key has 3–${Qu} points [u,v] (0..1 of the source frame)`);const v=typeof f.id=="string"?c.find($=>$.id===f.id):null,x=v?v.id:typeof f.id=="string"&&/^[a-zA-Z0-9_-]{1,24}$/.test(f.id)?f.id:C2(c),E={id:x,name:String(f.name??v?.name??`Mask ${x.replace(/^m(?=\d)/,"")}`).slice(0,40).trim()||"Mask",mode:m,keys:g,...f.feather!==void 0?{feather:Number(f.feather)}:v?.feather!==void 0?{feather:v.feather}:{},...f.invert!==void 0?{invert:f.invert}:{},...f.smooth!==void 0?{smooth:f.smooth}:{}};if(f.follow!==void 0&&f.follow!==null){if(!Vg.includes(f.follow))throw Error(`masks[${s}].follow: ${Vg.join(" | ")}`);if(t.kind!=="video")throw Error("follow needs a video clip");const $=f.follow==="track"?"translate":f.planarMode??"perspective";if(!Qh.includes($))throw Error(`masks[${s}].planarMode: ${Qh.join("|")}`);u.push({id:x,at:g[0].t,region:rj(g[0].pts,f.region),mode:$})}c=v?c.map($=>$.id===x?E:$):[...c,E]}if(c.length>bl)throw Error(`at most ${bl} masks per clip`);const p=c.length?fr(i,c):void 0;return p&&j2(p,t.duration),{mask:p,follow:u}}function tO(t,e,o,r,{maxKeys:a=rd,maxPoints:n=6e4}={}){if(!e.length)return t.keys;const i={frames:e},c=t.keys.find(v=>Math.abs(v.t-o)<.001)??t.keys[0],u=tf(i,o),p=c.pts.length,s=Math.max(2,Math.min(a,Math.floor(n/p))),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},(v,x)=>+(h+(f-h)*x/(m-1)).toFixed(4)),+o.toFixed(4)])].sort((v,x)=>v-x).map(v=>{const x=tf(i,v),E=Math.abs(v-o)<1e-4?null:T2(r,u,x);return{t:v,pts:c.pts.map($=>{if(!E)return $;const[S,k]=O2(E,$[0],$[1]);return[ys(S),ys(k),...$.slice(2)]})}})}const ij=3,xs=(t,e)=>!!t?.[e.track]?.locked;function eO(t,e,o,r,{tracks:a={},makeId:n=()=>crypto.randomUUID()}={}){const i=t.find(v=>v.id===e);if(!i)throw Error("Không tìm thấy clip");if(xs(a,i))throw Error("Track đã khóa");const c=_e(i,o,n());if(c.length<2)throw Error("Đặt playhead trong clip");const[u,p]=c,s=r==="left"?u:p,h=r==="left"?p:u,f=s.duration,m=i.start+i.duration;return{clips:t.flatMap(v=>v.id===i.id?[r==="left"?{...h,start:i.start}:h]:[v.track===i.track&&v.start>=m-1/60?{...v,start:ut(Math.max(0,v.start-f))}:v]),kept:h.id}}function oO(t,e,{tracks:o={},makeId:r}={}){const a=t.filter(i=>e.includes(i.id));if(!a.length)return{clips:t,pasted:[]};const n=Math.max(...a.map(i=>i.start+i.duration));return cw(t,a,ut(n),{insert:!0,tracks:o,...r?{makeId:r}:{}})}function rO(t,e,o,{tracks:r={},seconds:a=ij,makeId:n=()=>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(xs(r,i))throw Error("Track đã khóa");const c=ut(Math.max(i.start,Math.min(i.start+i.duration,o))),u=i.playbackRate||1,p=_e(i,c,n()),s=p[0],h=p[1],f=ut(Math.min(i.duration-1/30,c-i.start)),m=qn(i)?z2(i,f):an(i)?(i.inPoint||0)+ls(i,f):(i.inPoint||0)+f*u,g={...i,id:n(),start:c,duration:ut(a),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 g[E];const v=ut(a),x=t.flatMap(E=>E.id===i.id?h?[s,{...h,start:ut(h.start+v)}]:[s]:[E.track===i.track&&E.start>=c-1/60?{...E,start:ut(E.start+v)}:E]);return p.length===1&&c<=i.start+1/60&&x.splice(x.findIndex(E=>E.id===i.id),1,{...i,start:ut(i.start+v)}),{clips:[...x,g],hold:g.id}}function iw(t,e,{tracks:o={},makeId:r=()=>crypto.randomUUID()}={}){const a=t.find(u=>u.id===e);if(!a)throw Error("Không tìm thấy clip");if(a.kind!=="video")throw Error("Chỉ tách được âm thanh của clip video");if(a.freeze)throw Error("Khung dừng hình không có âm thanh");if((a.volume??1)<=0)throw Error("Clip này đã tắt tiếng");if(xs(o,a))throw Error("Track đã khóa");if(an(a))throw Error("Clip có speed ramp không có âm thanh — đặt tốc độ cố định trước khi tách âm thanh");const n=a.start+a.duration,i=Ji.find(u=>!o[u]?.locked&&!t.some(p=>p.track===u&&p.start<n-1/60&&p.start+p.duration>a.start+1/60));if(i===void 0)throw Error("Không còn track âm thanh trống ở đoạn này");const c={id:r(),nodeId:a.nodeId,track:i,start:a.start,duration:a.duration,kind:"audio",url:a.url,label:`${a.label} · audio`,inPoint:a.inPoint||0,...a.sourceDuration!==void 0?{sourceDuration:a.sourceDuration}:{},...a.gcsUri?{gcsUri:a.gcsUri}:{},...a.playbackRate&&a.playbackRate!==1?{playbackRate:a.playbackRate}:{},volume:a.volume??1,...qn(a)?{timeRemap:a.timeRemap}:{},...Object.fromEntries(["audioFadeIn","audioFadeOut","duck"].filter(u=>a[u]!==void 0).map(u=>[u,a[u]]))};return{clips:[...t.map(u=>u.id===a.id?{...u,volume:0}:u),c],audio:c.id}}function nO(t,e,{tracks:o={}}={}){const r=t.find(a=>a.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(xs(o,r))throw Error("Track đã khóa");return{clips:t.map(a=>{if(a.id!==e)return a;const n={...a,volume:0};for(const i of["audioFadeIn","audioFadeOut","duck","volumeKeys"])delete n[i];return n})}}function aO(t,e,o,{tracks:r={},makeId:a=()=>crypto.randomUUID()}={}){const n=t.find(p=>p.id===e);if(!n)throw Error("Không tìm thấy clip");if(!(o>n.start+1/60&&o<n.start+n.duration-1/60))throw Error("Đặt playhead trong clip để cắt");const i=iw(t,e,{tracks:r,makeId:a}),c=i.clips.find(p=>p.id===i.audio),u=_e(c,o,a());return{clips:i.clips.flatMap(p=>p.id===c.id?u:[p]),audio:u.map(p=>p.id)}}function iO(t,e,{tracks:o={}}={}){const r=t.filter(i=>e.includes(i.id)&&!xs(o,i)),a=r.some(i=>!i.disabled),n=new Set(r.map(i=>i.id));return t.map(i=>{if(!n.has(i.id))return i;const c={...i};return a?c.disabled=!0:delete c.disabled,c})}const ch=3,ss=1/30,sj=new Set(["id","start","duration","inPoint","label","captions","captionWords"]),lj=(t,e)=>{const o=new Set([...Object.keys(t),...Object.keys(e)].filter(r=>!sj.has(r)));for(const r of o)if(JSON.stringify(t[r])!==JSON.stringify(e[r]))return!1;return!0};function ul(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 a=e.start-(t.start+t.duration);return a<-ss/2||a>o+ss/2?!1:Math.abs((e.inPoint||0)-((t.inPoint||0)+(t.duration+Math.max(0,a))*r))<=ss/2*r+1e-6}function sw(t,e){if(!ul(t,e,{gap:ch*ss})||t.transition||!lj(t,e))return null;const o=ut(e.start-t.start),r=ut(o+e.duration),a=i=>i.map(c=>({...c,start:+(c.start+o).toFixed(3),end:+(c.end+o).toFixed(3)})),n={...t,duration:r};return(t.captions||e.captions)&&(n.captions=[...t.captions||[],...a(e.captions||[])]),(t.captionWords||e.captionWords)&&(n.captionWords=[...t.captionWords||[],...a(e.captionWords||[])]),n}function sO(t,e,{tracks:o={}}={}){const r=t.find(s=>s.id===e);if(!r)throw Error("Không tìm thấy clip");if(xs(o,r))throw Error("Track đã khóa");const a=t.filter(s=>s.track===r.track&&s.id!==r.id),n=a.filter(s=>ul(r,s,{gap:ch*ss})).sort((s,h)=>s.start-h.start)[0],i=a.filter(s=>ul(s,r,{gap:ch*ss})).sort((s,h)=>h.start-s.start)[0],[c,u]=n?[r,n]:i?[i,r]:[];if(!c)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 p=sw(c,u);if(!p)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!==u.id).map(s=>s.id===c.id?p:s),kept:c.id}}function lO(t,e){const o=t.find(p=>p.id===e);if(!o)return{clips:t,joined:!1};const r=t.filter(p=>p.track===o.track&&p.id!==o.id),a=r.find(p=>ul(o,p)),n=r.find(p=>ul(p,o)),[i,c]=a?[o,a]:n?[n,o]:[],u=i&&sw(i,c);return u?{clips:t.filter(p=>p.id!==c.id).map(p=>p.id===i.id?u:p),joined:!0,kept:i.id}:{clips:t,joined:!1}}function cO(t,e,o,{playhead:r,pps:a,px:n=8}={}){const c=[0,...r===void 0?[]:[r],...t.filter(u=>u.id!==e.id&&u.track===e.track).flatMap(u=>[u.start,u.start+u.duration])].sort((u,p)=>Math.abs(u-o)-Math.abs(p-o))[0];return c!==void 0&&Math.abs(c-o)*a<n?ut(c):null}function pO(t,e,{tracks:o={},makeId:r=()=>crypto.randomUUID()}={}){const a=t.filter(c=>e.includes(c.id)&&c.kind!=="audio");if(!a.length)throw Error("Chọn clip hình để nhân bản");let n=t;const i=[];for(const c of a){const u=h=>!o[h]?.locked&&!o[h]?.hidden&&!n.some(f=>f.track===h&&f.start<c.start+c.duration-1e-6&&f.start+f.duration>c.start+1e-6);let p=xn(c.track)+1;for(;p<40&&!u(en(p));)p++;if(p>=40)throw Error("Không còn track trống phía trên");const s={...c,id:r(),track:en(p),volume:0};delete s.transition,n=[...n,s],i.push(s.id)}return{clips:n,pasted:i}}function Gg(t,e,o){return Array.isArray(t)?t.slice(0,E1.models).map(r=>{const a=u=>Number.isFinite(Number(u))?Number(u):void 0,n=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 u=J4(String(r.project));if(!u)throw Error(`Map model: no project "${String(r.project).slice(0,60)}" in the map project library (list_map_projects)`);return{...Q4(u,{show:a(r.show)??0,rise:r.rise!==!1,at:n?.every(Number.isFinite)?n:void 0,height:a(r.height),rotation:a(r.rotation)}),...r.reveal?{reveal:r.reveal}:{},...r.color?{color:r.color}:{}}}const i=e.find(u=>u.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 c=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(c)||!c.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:c,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 Kg(t,e,o){return Array.isArray(t)?t.slice(0,E1.images).map(r=>{const a=e.find(u=>u.id===r?.materialId);if(!a||a.kind!=="image"||typeof a.gcsUri!="string")throw Error(`Map picture: "${String(r?.materialId??"").slice(0,40)}" is not an image in the Media bin`);const n=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(n)||!n.every(Number.isFinite))throw Error("Map picture needs lonlat (or lat + lng)");const i=Number(a.width)>0&&Number(a.height)>0?Number(a.height)/Number(a.width):Number(r.aspect)||1,c=(u,p)=>Number.isFinite(Number(u))?Number(u):p;return{gcsUri:a.gcsUri,label:String(r.label||a.label||"").slice(0,60),at:n,width:c(r.width,120),aspect:i,tilt:c(r.tilt,90),rotation:c(r.rotation,0),face:r.face==="fixed"?"fixed":"camera",show:c(r.show,0),...r.reveal?{reveal:r.reveal}:{}}}):null}const cj=["fit","posX","posY","scale","scaleX","scaleY","anchorX","anchorY","rotation","tiltX","tiltY","flipX","flipY","crop","opacity","blend","brightness","contrast","exposure","saturation","hue","grade"],Wg=new Set(xb.map(t=>t.id)),Xe=t=>Math.round(t*1e4)/1e4;function pj(t){const e=n=>Number.isFinite(n)?n:void 0,o=(Array.isArray(t.hits)?t.hits:e(t.at)!=null?[t.at]:[]).filter(Number.isFinite).slice(0,cc.max),r={...e(t.start)!=null?{start:t.start}:{},...e(t.duration)!=null?{duration:t.duration}:{}},a=typeof t.color=="string"?{color:t.color}:{};return[{op:"personElectric",clipId:t.clipId,...a,...r},...o.map(n=>({op:"addImpact",clipId:t.clipId,at:n,...Array.isArray(t.hitPoint)?{point:t.hitPoint}:{}})),{op:"speedBolt",clipId:t.clipId,...Array.isArray(t.point)?{point:t.point}:{},...a,...r.start!=null?{at:r.start}:{},...r.duration!=null?{duration:r.duration}:{}}]}function Jt(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,a]of Object.entries(t||{}))a!=null&&r!=="prompt"&&(o[r]=a);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 Hg=t=>{try{return Za(t,{})}catch{return null}},Gs=500,Ks=500,Bt=tl;function uj(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 Xg(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 Re=Xn,rc=2,nc=V1,dj=3;function Ug(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 lw=["addBroll","addText","estateText","lockup","addCard","addShape","addSolid","addAdjustmentLayer","addFlash","addElement","addMotion","addMap","generateElement","generateBroll"],it=t=>Number.isFinite(t)?Number(t):null,kt=t=>it(t)??void 0,Yg=t=>t.sourceDuration??Re;function qg(t,e,o,r=[]){const a=r.find(c=>c.id===e?.nodeId),n=r.find(c=>c.id===o?.nodeId),i=e?(e.inPoint||0)+ls(e,e.duration||0):0;return L8(a,i,n,o?.inPoint||0)>0?ax(t):t}function Uu(t,e,o){const r=t.findIndex(i=>i.id===e);if(r<0||o===null)return r;const a=t[r];if(!a.nodeId||o>=a.start-1e-6&&o<a.start+a.duration-1e-6)return r;const n=t.findIndex(i=>i.nodeId===a.nodeId&&i.track===a.track&&i.kind===a.kind&&(!i.mask||i.speakerLayout)&&o>=i.start-1e-6&&o<i.start+i.duration-1e-6);return n>=0?n:r}const Ws=t=>Array.isArray(t?.words)&&t.words.length?t.words.length:Number.isInteger(t?.wordCount)&&t.wordCount>0?t.wordCount:0;function hj(t,e,o){const r=Array.isArray(t)?t:[],a=typeof o=="string"?o.trim():"",n=a&&r.find(p=>p.id===a);if(n)return n;if(a){const p=r.find(m=>m.id.split(":").slice(1).join(":")===a||m.label===a);if(p)return p;const s=(e||[]).find(m=>m.id===a),h=s&&r.find(m=>m.id===s.nodeId);if(h)return h;const f=a.length>=40?r.filter(m=>m.id.startsWith(a)):[];if(f.length===1)return f[0]}const i=r.filter(p=>Ws(p)>0),c=i.filter(p=>p.role==="aroll"),u=c.length?c:i;return u.length===1?u[0]:void 0}function Zg(t){const e=t.shape,[o,r]=Array.isArray(e.size)?e.size:e.square?[720,720]:[1280,720],a=Math.min(o,r)/1e3,n=(o-1e3*a)/2,i=(r-1e3*a)/2;let c=1/0,u=1/0,p=-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]),g=Math.abs(h.scale[1]);f&&(c=Math.min(c,h.pos[0]+f[0]*m),u=Math.min(u,h.pos[1]+f[1]*g),p=Math.max(p,h.pos[0]+f[2]*m),s=Math.max(s,h.pos[1]+f[3]*g))}return Number.isFinite(c)?[(c*a+n)/o,(u*a+i)/r,(p*a+n)/o,(s*a+i)/r]:null}const Jg=t=>Array.isArray(t?.masks)?t.masks.map(e=>e.id):t?["m1"]:[];function fj(t,e,o){if(typeof t.prompt=="string"&&t.prompt.trim().startsWith("{"))try{const v=JSON.parse(t.prompt);t={...v,...t,presetId:t.presetId??v.presetId,params:t.params??v.params}}catch{throw Error("addVfxPreset: prompt must be JSON {presetId, params}")}const r=t.preset&&typeof t.preset=="object"&&t.preset.id?t.preset:av(String(t.presetId??""));if(!r)throw Error(`addVfxPreset: unknown presetId "${String(t.presetId??"").slice(0,64)}" — search_vfx_presets`);const a=ov(r,t.params&&typeof t.params=="object"?t.params:{}),n=Math.max(0,it(t.start)??it(t.at)??0),i=(v,x)=>{const E=(o??[]).find($=>$.id===v);if(!E||E.kind!=="video"||typeof E.url!="string")throw Error(`addVfxPreset: ${v} is not a video of the Media bin (the move's ${x}: clipoox vfx-render … then add_media)`);return{url:E.url,...typeof E.gcsUri=="string"?{gcsUri:E.gcsUri}:{}}};let c={url:qM(r.id)},u=!1;typeof t.materialId=="string"&&(c=i(t.materialId,"render"),u=!0);const p=XM(r),s={name:r.name,duration:p,width:r.width,height:r.height,anchorU:r.emit[0],anchorV:r.emit[1]},h={id:`preset:${r.id}`,...c,...s,bg:"alpha"},f={};if(r.scene&&t.passes!==!1)for(const v of JM){const x=t[`${v}MaterialId`],E=typeof x=="string"?i(x,`${v} pass`):!u&&!t.preset?{url:ZM(r.id,v)}:null;E&&(f[v]={id:`preset:${r.id}:${v}`,...E,...s,name:`${r.name} · ${v==="light"?"ánh sáng hắt":"sóng khí"}`,bg:"black"})}const m=[{op:"addVfxPreset",_footage:h,...f.light?{_light:f.light}:{},...f.distort?{_distort:f.distort}:{},_preset:{id:r.id,params:a,rendered:u},_impact:r.impact,start:n,track:t.track,point:t.point,scale:t.scale}],g=n+r.impact;if(t.sfx!==!1)for(const v of r.sfx)m.push({op:"addSfx",sfxId:v.id,at:Math.round((n+v.at)*1e3)/1e3,volume:.8});if(t.shake!==!1&&r.shake){const v=(e??[]).filter(x=>x.kind==="video"&&!x.vfxFootage&&!x.vfx&&x.start<=g&&x.start+x.duration>g).sort((x,E)=>(x.track??0)-(E.track??0))[0];v&&m.push({op:"cameraShake",clipId:v.id,at:Math.round((n+r.shake.at)*1e3)/1e3,duration:r.shake.duration,numberValue:r.shake.intensity})}return m}function mj(t,e,o){const r=Math.max(0,it(t.start)??0),a=(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(g=>g.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}}),n=CI({...t,stations:a}),i=n.stations.some(s=>s.say)?wy(e,o,r,r+ar.maxSeconds+30,typeof t.voiceClipId=="string"?t.voiceClipId:null):[],c=jI(n,(s,h)=>{if(!i.length)return null;const f=xd(s,i,r+h);return f?f.at-r:null}),u=[],p=n.style==="map"?n.stations.find(s=>s.kind==="place"&&Array.isArray(s.lonlat)):null;p&&t.map!==!1&&u.push({op:"addMap",start:r,duration:c.total,label:p.label,geo:$1({places:[{label:"",center:p.lonlat,zoom:Math.min(14,Math.max(2,it(t.mapZoom)??6))}],duration:c.total,style:"dark",route:!1,pins:!1})}),u.push({op:"documentary",_plan:c,start:r,label:typeof t.label=="string"?t.label.slice(0,60):""});for(const[s,h]of c.sfx)h<c.total&&u.push({op:"addSfx",sfxId:s,at:Math.round((r+h)*1e3)/1e3,volume:.6});return u}function Ua(t,e,o=[],r={},a=null,n={}){const i=n.seamFrame??n,c=i.W>0&&i.H>0?{W:i.W,H:i.H}:{};let u=a?structuredClone(a):null;const p=n.motion?vh(n.motion):{in:.5,out:.5,settle:"none"};e=X6(e,{clips:t,materials:o,brand:n.brand??null,portrait:n.H>n.W*1.1,en:n.locale==="en",simulate:D=>Ua(t,D,o,r,a,n).clips}),e=Z6(e,{materials:o,portrait:n.H>n.W*1.1}),e=LE(e,{clips:t,materials:o,brand:n.brand??null,W:n.W||1280,H:n.H||720,en:n.locale==="en"?!0:null,maxOps:Math.min(Ks,n?.maxOps??Gs),simulate:D=>Ua(t,D,o,r,a,n).clips}),e=aS(e,{clips:t,materials:o,W:n.W||1280,H:n.H||720,maxOps:Math.min(Ks,n?.maxOps??Gs),simulate:D=>Ua(t,D,o,r,a,n).clips}),e=qE(e,{W:n.W||1280,H:n.H||720}),e=yS(e,{clips:t,materials:o,brand:n.brand??null,portrait:n.H>n.W*1.1,en:n.locale==="en",maxOps:Math.min(Ks,n?.maxOps??Gs),simulate:D=>Ua(t,D,o,r,a,n).clips}),e=ZS(P3(e,{brand:n.brand??null,portrait:n.H>n.W*1.1}),{portrait:n.H>n.W*1.1});let s=t.map(D=>({...D}));r=structuredClone(r);const h=[],f=[],m=[],g=[],v=[],x=[],E=[],$=[],S=[],k=[],y=D=>s.find(q=>q.id===D),C=(D,q,pt=null)=>{let yt=$.find(T=>T.clipId===D.id&&!T.object);yt||(yt={clipId:D.id,behind:[]},$.push(yt)),q&&!yt.behind.includes(q)&&yt.behind.push(q);const Mt=jf(D.personPending),l=Mt?.behind??[],lt=Mt?.job,K=Mt?.ready,d=Mt?.then??[],w=pt?[...d,pt].slice(-cx):d;D.personPending={behind:[...new Set([...l,...yt.behind])].slice(0,Tf),...lt?{job:lt}:{},...lt&&K?{ready:K}:{},...w.length?{then:w}:{},...Mt?.objects?{objects:Mt.objects,person:!0}:{}}},A=(D,q=null)=>pt=>!r[pt]?.locked&&!s.some(yt=>yt.id!==q&&yt.track===pt&&yt.start<D.start+D.duration&&yt.start+yt.duration>D.start),z=(D,q,pt)=>{const yt={...jf(D.personPending)??{behind:[]}},Mt=(yt.objects??[]).map(K=>({...K,behind:[...K.behind]}));D.personPending&&!D.personPending.object&&!D.personPending.objects&&(yt.person=!0);let l=Mt.find(K=>K.id===q.id);if(l)q.pts&&q.pts!==l.pts&&(l.pts=q.pts,l.at=q.at);else{if(Mt.length>=Of)throw Error(`"${D.label||D.id}" already waits for ${Of} object cut-outs`);l={id:q.id,name:q.name,pts:q.pts,at:q.at,behind:[],...q.layer?{layer:q.layer}:{}},Mt.push(l)}if(pt&&!l.behind.includes(pt)){if(l.behind.length>=Tf)throw Error("Too many layers behind one object");l.behind.push(pt)}D.personPending={...yt,objects:Mt};let lt=$.find(K=>K.clipId===D.id&&K.object?.id===q.id);lt||(lt={clipId:D.id,behind:[],object:{id:l.id,name:l.name,pts:l.pts,at:l.at,...l.layer?{layer:l.layer}:{}}},$.push(lt)),lt.behind=[...l.behind]},j=(D,q,pt)=>{const yt=n.objectMattes?.get?.(`${D.id}|${q.id}`);if(!yt)return null;const Mt={id:q.id,name:q.name,...q.pts?{pts:q.pts,at:q.at}:{}},l=I=>I.id===D.id?px(I,q.id):I,lt=q.layer?y(q.layer):null;if(lt&&Kp(lt)){const I=ix(lt,yt,Mt);return s=s.map(O=>O.id===lt.id?I:l(O)),Ml(s),I}const K=xl(pt??D,D,{index:xn,at:en,isFree:A(D)});if(K===null)throw Error(`No free track above ${D.label||D.id} for "${q.name}"`);let d=`${D.id}-${q.id}`,w=2;for(;y(d);)d=`${D.id}-${q.id}-${w++}`;const T=sx(s,D,yt,{id:d,track:K,label:lx(D,q.name,s),target:pt,obj:Mt});return s=T.clips.map(l),Ml(s),T.layer},P=(D,q,pt)=>{const yt=xl(q,pt,{index:xn,at:en,isFree:A(D,D.id)});if(yt===null)throw Error(`No free track above ${q.label||q.id} for "${Wp(D).name}"`);s=s.map(Mt=>Mt.id!==D.id?Mt:{...Mt,track:yt,...(q.zIndex??0)>(Mt.zIndex??0)?{zIndex:q.zIndex}:{}})};let F=null,N=null,G,V=null;const et=()=>V??(Array.isArray(n?.markers)?n.markers:[]),U=[],at=new Map,W=(D,q)=>({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)??q))});Array.isArray(e)&&e.some(D=>D?.op==="speedster")&&(e=e.flatMap(D=>D?.op==="speedster"?pj(Jt(D)):[D])),Array.isArray(e)&&e.some(D=>D?.op==="beautyFace")&&(e=e.flatMap(D=>{if(D?.op!=="beautyFace")return[D];const q=Jt(D),pt=Array.isArray(q.clipIds)?q.clipIds:q.clipId!=null?[q.clipId]:[],yt=q.booleanValue===!1?[]:L$(P$(q),n.locale);return[{op:"beautyStrip",clipIds:pt,_off:q.booleanValue===!1},...yt.length?[{op:"colorGrade",clipIds:pt,windows:{mode:"add",custom:yt}}]:[]]})),Array.isArray(e)&&e.some(D=>D?.op==="energyAura")&&(e=e.flatMap(D=>{if(D?.op!=="energyAura")return[D];const q=Jt(D);if(q._auraId||Array.isArray(q.path)||q.behind===!1)return[q];const pt=zt();return[{...q,_auraId:pt},{op:"placeBehindPerson",clipId:pt,sourceClipId:q.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 fj(Jt(D),t,o)}catch(q){return[{op:"addVfxPreset",_footage:null,_error:q?.message||String(q)}]}})),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 mj(Jt(D),t,o)}catch(q){return[{op:"documentary",_plan:null,_error:q?.message||String(q)}]}})),Array.isArray(e)&&e.some(D=>D?.op==="animePower")&&(e=e.flatMap(D=>D?.op==="animePower"?V$(Jt(D)):[D]));const _=(Array.isArray(e)?e:[]).slice(0,Math.min(Ks,n?.maxOps??Gs)),J=D=>Ys.includes(D?.op),tt=D=>D?.op==="speakerBubble"||D?.op==="speakerWindow",rt=[..._.filter(D=>!tt(D)&&!J(D)),..._.filter(tt),..._.filter(J)];for(const[D,q]of rt.entries()){const pt=U.length,yt=typeof q?.clipId=="string"&&/^new:(\d+)$/.exec(q.clipId),Mt=K=>{const d=typeof K=="string"&&/^new:(\d+)$/.exec(K);return d?U[Number(d[1])-1]??K:K};let l=yt||Array.isArray(q?.clipIds)?{...q,clipId:yt?U[Number(yt[1])-1]??q.clipId:q.clipId,...Array.isArray(q.clipIds)?{clipIds:q.clipIds.map(Mt)}:{}}:q;typeof l?.parentClipId=="string"&&/^new:\d+$/.test(l.parentClipId)&&(l={...l,parentClipId:Mt(l.parentClipId)});let lt=null;try{if(l?.op==="lockup"&&(lt=cI(l,{clips:s,materials:o,W:n.W||1280,H:n.H||720}),l=lt.addText),l?.op==="estateText"){if(typeof l.text!="string"||!l.text.trim())throw Error("estateText needs its text");l=NI(l,{portrait:(n.H||720)>(n.W||1280)*1.1})}if(l?.op==="syncMapToVoice"){const d=y(l.clipId);if(!d?.geo)throw Error("syncMapToVoice needs an animated map clip (addMap)");const w=Jt(l),T=d.start,I=d.start+d.duration,O=Array.isArray(w.times)?w.times:null,L=O?[]:wy(s,o,T,I,typeof w.voiceClipId=="string"?w.voiceClipId:null);if(!O&&!L.length){if(s.some(H=>H.start<I&&H.start+H.duration>T&&Ws(o.find(Z=>Z.id===H.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=CM(ef(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: ${jM(B.report)}`),l={op:"updateMap",clipId:d.id,places:B.places,placesResolved:!0,icons:B.icons}}if(l?.op==="addMotionCode"){if(typeof l.code!="string"||!/\brender\b/.test(l.code))throw Error("Motion code must define function render(ctx, t, env)");const{kind:d,...w}=l;l={...w,op:"addMotion",...d==="three"?{motionKind:"three"}:{}}}if(l?.clipId&&r[y(l.clipId)?.track]?.locked||l?.track!==void 0&&r[l.track]?.locked&&!lw.includes(l.op)&&!(l.op==="setTrackProperty"&&l.property==="locked"&&l.booleanValue===!1))throw Error("Track đã khóa");const K=l?.clipId?y(l.clipId)?.label||l.clipId:"";if(Ys.includes(l?.op)){if(rt.indexOf(q)!==rt.length-1)throw Error("Control action must follow all edits");if(["undo","redo","analyzeFootage"].includes(l.op)&&e.length!==1)throw Error("History/analysis actions must be requested alone");if(l.op==="seek"&&(!Number.isFinite(l.at)||l.at<0||l.at>Math.max(0,...s.map(d=>d.start+d.duration))))throw Error("Seek outside timeline");if(["play","exportVideo"].includes(l.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(l.op)){if(l.resolution!=null&&!["720p","1080p"].includes(l.resolution)||l.aspectRatio!=null&&!["16:9","9:16","1:1","4:5"].includes(l.aspectRatio)||l.fps!=null&&![24,25,30,60].includes(l.fps)||l.loudness!=null&&![-14,-16,0].includes(l.loudness))throw Error("Invalid export format");if(F&&l.aspectRatio!=null&&l.aspectRatio!==F)throw Error("Export aspect ratio must match the reframe")}m.push({op:l.op,at:l.at,...["exportVideo","setExportFormat"].includes(l.op)?{...Object.fromEntries(["resolution","aspectRatio","fps","loudness"].filter(d=>l[d]!=null).map(d=>[d,l[d]])),...F&&l.aspectRatio==null?{aspectRatio:F}:{}}:{}});continue}if(l?.op!=="matchReference"&&typeof l?.materialId=="string"&&o.find(d=>d.id===l.materialId)?.role==="reference")throw Error("Video mẫu chỉ để phân tích nhịp — không đưa vào timeline");switch(l?.op){case"setExportRange":{const d=w=>w==null?null:typeof w=="number"&&Number.isFinite(w)?w:NaN;try{G=Yx(d(l.in),d(l.out))}catch{throw Error("setExportRange needs in / out in timeline seconds, 0 ≤ in < out ≤ 600 (both omitted = the whole film)")}h.push(G?`export range ${G.in}s–${G.out>=Re?"the end":`${G.out}s`}`:"export range: whole film");break}case"addMarker":{if(l.color!=null&&!Xc.includes(l.color))throw Error(`addMarker color must be one of ${Xc.join(", ")}`);let d;if(l.onBeats!=null){if(!Vm.includes(l.onBeats))throw Error(`addMarker onBeats must be ${Vm.join(" | ")}`);if(d=Gm(s,o,{density:l.onBeats}).filter(I=>l.onBeats==="beats"||I.kind!=="beat").map(I=>I.t),!d.length)throw Error("No beats found: add the song with add_media (its beats are found automatically) first")}else d=Array.isArray(l.times)?l.times:[l.at];if(d.length>200)throw Error("addMarker: at most 200 times per op");let w=et(),T=0;for(const I of d){const O=E$(w,{t:it(I)??NaN,label:l.label,color:l.color??void 0,id:`mk${zt().replace(/[^A-Za-z0-9]/g,"").slice(0,12)}`});w=O.markers,O.added&&T++}V=w,h.push(`markers: +${T}${d.length>T?` (${d.length-T} already there)`:""}`);break}case"updateMarker":{V=S$(et(),l.markerId,{...l.at!==void 0?{t:it(l.at)??NaN}:{},...l.label!==void 0?{label:l.label??""}:{},...l.color!==void 0?{color:l.color}:{}}),h.push(`marker ${l.markerId} updated`);break}case"removeMarker":{if(l.all===!0){h.push(`markers: −${et().length}`),V=[];break}V=I$(et(),l.markerId),h.push(`marker ${l.markerId} removed`);break}case"cutAtMarkers":{const d=Array.isArray(l.markerIds)?et().filter(O=>l.markerIds.includes(O.id)):et();if(!d.length)throw Error("No markers: add some first (addMarker, or the M key in the editor)");const w=Array.isArray(l.clipIds)?l.clipIds:null,T=s.filter(O=>!r[O.track]?.locked&&(w?w.includes(O.id):l.track!=null?O.track===l.track:(l.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 I=0;for(const O of T){let L=O;for(const B of A$(O,d.map(H=>H.t))){if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const H=_e(L,B,zt());H.length!==1&&(s=s.flatMap(Z=>Z.id===L.id?H:[Z]),L=H[1],I++)}}h.push(`cut at markers: ${I} cut${I===1?"":"s"}`);break}case"setCamera":{u={...u??{...jr,motionKeys:[]},enabled:l.booleanValue!==!1};const d=Object.hasOwn(l,"parentClipId")?l.parentClipId:l.clipId;if(d!==void 0)if(d===null||d==="")delete u.parentId;else{const w=y(d);if(!w||w.kind==="audio")throw Error(`Camera parent ${d} not found`);u.parentId=w.id}_r(u),h.push(`camera ${u.enabled?"on":"off"}${u.parentId?` · follows ${y(u.parentId)?.label??u.parentId}`:""}`);break}case"setPath":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error(`Không tìm thấy layer ${l.clipId}`);const w=l.points==null||Array.isArray(l.points)&&!l.points.length,T=$8(d,w?null:{points:l.points,...it(l.start)!=null?{start:it(l.start)}:{},...it(l.end)!=null?{end:it(l.end)}:{},...typeof l.ease=="string"&&l.ease!=="linear"?{ease:l.ease}:{},...l.booleanValue===!0?{orient:!0}:{},...l.closed===!0?{closed:!0}:{}},{W:n.W||1280,H:n.H||720});Object.assign(d,T),T.path===void 0&&delete d.path,h.push(w?`path off ${K}`:`path ${K}: ${l.points.length} points${l.booleanValue===!0?" · auto-orient":""}`);break}case"linkProperty":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error(`Không tìm thấy layer ${l.clipId}`);if(!$l.includes(l.property))throw Error(`property must be one of ${$l.join("/")}`);const w=(d.links??[]).filter(L=>L.prop!==l.property),T=Mt(l.fromClipId),I=T?{prop:l.property,from:T,...l.fromProperty?{fromProp:l.fromProperty}:{},...it(l.factor)!=null?{factor:it(l.factor)}:{},...it(l.offset)!=null?{offset:it(l.offset)}:{},...it(l.delay)!=null?{delay:it(l.delay)}:{},...l.booleanValue===!0?{add:!0}:{}}:null,O=Qx(s,d,I?[...w,I]:w);Object.assign(d,O),O.links===void 0&&delete d.links,h.push(I?`link ${K}.${l.property} ← ${y(T)?.label??T}.${I.fromProp??l.property}`:`unlink ${K}.${l.property}`);break}case"setExpression":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error(`Không tìm thấy layer ${l.clipId}`);if(!Object.hasOwn(Vr,l.property))throw Error(`property must be one of ${Object.keys(Vr).join("/")}`);const w=l.expression!==void 0?l.expression:l.text,T=typeof l.enabled=="boolean"?l.enabled:typeof l.booleanValue=="boolean"?l.booleanValue:void 0;if(w!=null){if(typeof w!="string")throw Error("expression must be text");tx(w)}if(w==null&&T===void 0&&l.expression!==null&&l.text!==null)throw Error("expression (text) or enabled is required");const I=ex(d,l.property,w===void 0?void 0:w,T);Object.assign(d,I),I.expr===void 0&&delete d.expr;let O=null;d.expr?.[l.property]&&!d.expr[l.property].off&&(ox(s),O=rx(d,l.property,0)),h.push(w===null?`expression off ${K}.${l.property}`:`expression ${K}.${l.property}${d.expr?.[l.property]?.off?" (disabled)":""}: ${d.expr?.[l.property]?.src.slice(0,80)}${O?` — warning: ${O}`:""}`);break}case"followChain":{const d=y(l.clipId);if(!d)throw Error(`Không tìm thấy layer ${l.clipId}`);const w=Array.isArray(l.properties)&&l.properties.length?l.properties:["x","y","rot"];if(w.some(I=>!$l.includes(I)))throw Error(`properties must be from ${$l.join("/")}`);const T=Jx(s,d.id,(l.clipIds||[]).filter(I=>I!==d.id),w,it(l.numberValue)??.08);for(const[I,O]of Object.entries(T))Object.assign(y(I),O);h.push(`followChain ${Object.keys(T).length} layer(s) after ${K} on ${w.join("/")}`);break}case"addNull":{const d=ut(Math.max(0,it(l.start)??0)),w=ut(Math.max(1/30,it(l.duration)??5)),{track:T}=Kt(s,r,d,d+w),I=typeof l.text=="string"&&l.text.trim()?l.text.trim().slice(0,80):Qk(s),O={...Cr({id:zt(),track:T,start:d,duration:w,label:I,is3D:l.booleanValue===!0}),...Number.isFinite(l.posX)?{posX:l.posX}:{},...Number.isFinite(l.posY)?{posY:l.posY}:{},...l.booleanValue===!0&&Number.isFinite(l.numberValue)?{spatialDepth:l.numberValue}:{}};s.push(O),U.push(O.id);const L=(Array.isArray(l.clipIds)?l.clipIds:[]).filter(B=>B!==O.id);if(L.length){const B=n.W||1280,H=n.H||720;for(const ot of L){const st=y(ot);if(!st||st.kind==="audio")throw Error(`addNull clipIds: ${ot} is not a visual layer`);if(r[st.track]?.locked)throw Error("That layer is locked")}dr(s);const Z=Ul(s,Ou(s,L),B,H);for(const ot of L){const st=y(ot),Y=s.indexOf(st);s[Y]=Ba(s,st,{parentClipId:O.id,at:Math.max(0,Math.min(st.duration,d-st.start)),W:B,H})}s=Fs(s,Z,B,H)}h.push(`addNull ${O.is3D?"3D ":""}"${I}" (${O.id})${L.length?` with ${L.length} layer(s) linked`:""}`);break}case"setCameraKeys":{if(!Cf.includes(l.property))throw Error(`Camera property must be ${Cf.join("/")}`);if(!Array.isArray(l.propertyKeys)||l.propertyKeys.length>30)throw Error("Provide 0–30 camera keys");const{min:d,max:w}=Zn[l.property],T={...u??{...jr,motionKeys:[]},enabled:!0},I=l.propertyKeys.map(O=>{if(!Number.isFinite(O?.time)||O.time<0||O.time>Re)throw Error("Camera key time must be timeline seconds");if(!Number.isFinite(O.value)||O.value<d||O.value>w)throw Error(`${l.property} must be ${d}..${w}`);const L=O.ease&&O.ease!=="linear"?Yt[O.ease]:void 0;if(O.ease&&O.ease!=="linear"&&!L)throw Error(`Unknown easing "${O.ease}"`);return{time:ut(O.time),value:O.value,...L?{ease:L}:{}}}).sort((O,L)=>O.time-L.time);u=I.length?In(T,l.property,I):{...In(T,l.property,[]),[l.property]:dl(T,l.property,0)},_r(u),h.push(`camera ${l.property}: ${I.length} key`);break}case"cameraMove":{const d=l.ease&&l.ease!=="linear"?Yt[l.ease]:void 0;u=Jk(u,l.preset,it(l.at)??0,it(l.duration)??2,{amount:it(l.numberValue)??1,ease:d}),h.push(`camera ${l.preset} ${it(l.at)??0}s → ${(it(l.at)??0)+(it(l.duration)??2)}s`);break}case"cutPauses":{const d=y(l.clipId),w=d&&o.find(I=>I.id===d.nodeId);if(!d)throw Error("Clip not found");const T=nM(s,l.clipId,w,{minGap:l.numberValue??.6,padding:.12,fillers:l.booleanValue===!0,maxClips:Bt,isBed:I=>I.kind==="audio"&&I.nodeId!==d.nodeId&&!o.find(O=>O.id===I.nodeId)?.transcript?.length},r,zt);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: ${K} −${T.removed} (${T.saved}s)${T.skipped?`, ${T.skipped} skipped`:""}`);break}case"removeRetakes":{if(l.keep!=null&&!hy.includes(l.keep))throw Error("keep must be best, last or first");const d=n.locale==="en",w=AM(s,o,{clipIds:Array.isArray(l.clipIds)&&l.clipIds.length?l.clipIds:null,window:it(l.window)??void 0,minSimilarity:it(l.minSimilarity)??void 0,keep:l.keep??"best",tracks:r,maxClips:Bt,makeId:zt,en:d,isBed:T=>T.kind==="audio"&&!o.find(I=>I.id===T.nodeId)?.transcript?.length&&!o.find(I=>I.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(I=>I.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=y(l.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(Ws(w)>0){h.push(`script edit ${K}: 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 I=Array.isArray(l.scriptLines)&&l.scriptLines.length?l.scriptLines.slice(0,$a.maxLines).map(Y=>typeof Y=="string"?Um(Y)[0]??{text:Y}:{text:String(Y?.text??""),...it(Y?.duration)>0?{duration:it(Y.duration)}:{}}).filter(Y=>Y.text.trim()):Um(l.script??l.prompt??"");if(!I.length)throw Error("The script is empty");const O=l.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)&&!Ws(L))throw Error("Transcribe the reference video first: its pace comes from its words");const B=d.inPoint||0,H=B+d.duration*(d.playbackRate||1),Z=r6(I,T.filter(Y=>Y.start>=B-.05&&Y.end<=H+.05),{pace:L?.words?.length?o6(L.words):null,cutPauses:l.cutPauses!==!1,speed:typeof l.speed=="boolean"?l.speed:l.booleanValue!==!1,maxPause:it(l.maxPause)??it(l.numberValue)??void 0,skip:Array.isArray(l.skipLines)?l.skipLines.filter(Number.isInteger):[],silences:uy(w)??[]}),ot=n.locale==="en";if(h.push(...i6(Z,ot)),l.dryRun===!0){h.push(ot?`script edit (preview): ${Z.found} / ${Z.lines.length} lines found → ${Z.length.toFixed(1)}s`:`dựng theo kịch bản (xem trước): thấy ${Z.found} / ${Z.lines.length} câu → ${Z.length.toFixed(1)}s`);break}const st=a6(s,d.id,Z,{tracks:r,maxClips:Bt,makeId:zt,isBed:Y=>Y.kind==="audio"&&!o.find(ct=>ct.id===Y.nodeId)?.transcript?.length&&!o.find(ct=>ct.id===Y.nodeId)?.words?.length});s=st.clips,h.push(ot?`script edit: ${Z.found} / ${Z.lines.length} lines, ${st.pieces} pieces → ${st.length.toFixed(1)}s (${st.delta>=0?"+":""}${st.delta.toFixed(1)}s)`:`dựng theo kịch bản: ${Z.found} / ${Z.lines.length} câu, ${st.pieces} đoạn → ${st.length.toFixed(1)}s (${st.delta>=0?"+":""}${st.delta.toFixed(1)}s)`);break}case"audioTool":{if(!Af.includes(l.tool))throw Error(`audioTool: tool must be one of ${Af.join(", ")}`);if(!Array.isArray(l.processed)||!l.processed.length)throw Error("audioTool runs through Clipoox MCP edit_timeline only (the server processes the sound first)");for(const d of l.processed){let w=at.get(d.clipId)??d.clipId,T=y(w);if(!T)throw Error(`Không thấy clip ${d.clipId}`);if(T.kind==="video"){const L=iw(s,T.id,{tracks:r,makeId:zt});s=L.clips,at.set(d.clipId,L.audio),w=L.audio,T=y(w)}if(T?.kind!=="audio")throw Error("audioTool: only video and audio clips have sound");const I=[...T.audioTools??[],l.tool];Zk(I);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:I}:{...L,url:d.url,...typeof d.gcsUri=="string"?{gcsUri:d.gcsUri}:{},inPoint:0,sourceDuration:+O.toFixed(3),audioTools:I}),h.push(`${l.tool} ${T.label||w}${at.get(d.clipId)===w&&d.clipId!==w?" (sound detached from the video)":""}`)}break}case"muffleAudio":{s=qk(s,l.clipId,l.booleanValue===!1?{remove:!0}:{at:it(l.at),duration:it(l.duration)}),h.push(l.booleanValue===!1?`unmuffle ${K}`:`muffle ${K} ${it(l.at)}–${(it(l.at)+it(l.duration)).toFixed(2)} s`);break}case"duckAudio":{const d=l.clipId?[l.clipId]:s.filter(T=>T.kind==="audio"&&!T.sfx&&(l.track===void 0||T.track===l.track)&&!o.find(I=>I.id===T.nodeId)?.transcript?.length).map(T=>T.id);if(l.booleanValue===!1){let T=0;if(s=s.map(I=>{if(!d.includes(I.id)||!I.duck)return I;T++;const{duck:O,...L}=I;return L}),!T)throw Error("Nothing is ducked");h.push(`unduck ${T} clip`);break}const w=iM(s,d,o,l.numberValue??.25,r);if(!w.ducked)throw Error("The music does not overlap any speech");s=w.clips,h.push(`duck ${w.ducked} clip → ${l.numberValue??.25} under speech`);break}case"punchIn":{const d=it(l.at);if(d===null)throw Error("punchIn needs at (timeline seconds)");const w=Uu(s,l.clipId,d);if(w<0)throw Error("Clip not found");const T=s[w];if(l.punchStyle!=null&&!Qo.styles.includes(l.punchStyle))throw Error(`Punch-in style must be ${Qo.styles.join(" or ")}`);s[w]={...T,...u0(T,{at:ut(d-T.start),duration:it(l.duration)??void 0,amount:it(l.numberValue)??void 0,style:l.punchStyle??void 0,anchor:qc(T,o.find(I=>I.id===T.nodeId))})},h.push(`punch-in ${K} @ ${ut(d)}s`);break}case"makeRoom":{const d=it(l.at);if(d===null)throw Error("makeRoom needs at (timeline seconds)");const w=Uu(s,l.clipId,d);if(w<0)throw Error("Clip not found");const T=s[w];if(!D0.includes(l.preset))throw Error(`Make room preset must be ${D0.join("/")}`);s[w]={...T,...HS(T,{at:ut(d-T.start),duration:it(l.duration)??void 0,preset:l.preset,amount:it(l.numberValue)??void 0})},h.push(`make room ${l.preset} ${K} @ ${ut(d)}s`);break}case"speakerBubble":{const d=it(l.at),w=y(l.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>Bt)throw Error(`Tối đa ${Bt} clip`);const I=it(l.at);if(I===null)throw Error("speakerBubble needs at (timeline seconds)");const O=l.corner??"bottom-left";if(!fo.corners.includes(O))throw Error(`Bubble corner must be ${fo.corners.join("/")}`);for(const B of["posX","posY"])if(l[B]!=null&&!(Number.isFinite(l[B])&&l[B]>=0&&l[B]<=1))throw Error(`speakerBubble ${B} must be 0..1 (the bubble centre)`);if(l.color!=null&&!/^#[0-9a-fA-F]{6}$/.test(String(l.color)))throw Error("speakerBubble color must be #RRGGBB");s=J6(s,T.id,{at:I,duration:it(l.duration)??void 0,corner:O,size:it(l.numberValue)??void 0,posX:it(l.posX),posY:it(l.posY),color:l.color!=null?String(l.color).toLowerCase():null,W:n?.W||1280,H:n?.H||720,material:o.find(B=>B.id===T.nodeId)??null,newId:zt}).clips,h.push(`speaker bubble ${K} @ ${ut(I)}s`);break}case"stepPunch":{l=Jt(l);const d=it(l.at);if(d===null)throw Error("stepPunch needs at (timeline seconds)");const w=Uu(s,l.clipId,d);if(w<0)throw Error("Clip not found");const T=s[w];s[w]={...T,...WC(T,{at:ut(d-T.start),steps:kt(l.steps),frames:kt(l.frames),amount:kt(l.amount)??kt(l.numberValue),point:Array.isArray(l.point)?l.point:null,back:l.back!==!1})},h.push(`stepPunch ${K} @ ${ut(d)}s`);break}case"matteFlash":{l=Jt(l);let d=y(l.clipId);if(!d||d.kind!=="video"&&d.kind!=="image")throw Error("matteFlash needs a video or image clip");if(!d.person){const I=d,O=s.find(L=>L.id!==I.id&&L.kind===I.kind&&L.person&&L.url===I.url);O&&(d={...I,person:O.person})}if(!d.person){if(d.kind!=="video"||n.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:I,...O}=l;C(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 I=zt();for(;y(I);)I=zt();return I},T=HC(d,{frames:kt(l.frames)??kt(l.numberValue),side:l.side==="out"?"out":"in",aspect:n.W&&n.H?n.W/n.H:void 0,color:l.color??"white",background:l.background??"black"},w);if(s.length+T.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const I of T){const{track:O}=Kt(s,r,I.start,I.start+I.duration);s.push({...I,track:O}),U.push(I.id)}h.push(`matteFlash ${d.label||d.id}: ${Math.round(T[0].duration*30)} frame(s) of ${l.color??"white"} silhouette on ${l.background==="plate"?"the shot":"black"} at ${T[0].start}s`);break}case"endingLook":{l=Jt(l);const d=l.style??l.preset??"drain";if(!["drain","iris","drain-iris"].includes(d))throw Error("endingLook style: drain | iris | drain-iris");const w=y(l.clipId);if(!w)throw Error("Clip not found");const T=it(l.at),I=()=>{let L=zt();for(;y(L);)L=zt();return L};if(s.length+2>Bt)throw Error(`Tối đa ${Bt} clip`);let O=w;if(d!=="drain"){const L=s.length,B=UC(s,w.id,{at:T??void 0,radius:kt(l.radius),push:kt(l.push),cx:Array.isArray(l.point)?Number(l.point[0]):kt(l.posX),cy:Array.isArray(l.point)?Number(l.point[1]):kt(l.posY),W:n.W||1280,H:n.H||720,material:o.find(H=>H.id===w.nodeId)??null,newId:I});s=B.clips,O=s.find(H=>H.id===B.irisId),s.length>L&&U.push(B.irisId)}if(d!=="iris"){const L=XC(O,{at:d==="drain"?T??void 0:it(l.drainAt)??void 0,duration:kt(l.duration)},I);if(d==="drain-iris"&&L.mask?.keys?.length===1){const H=L.mask.keys[0].pts,Z=H.reduce((st,Y)=>st+Y[0],0)/H.length,ot=H.reduce((st,Y)=>st+Y[1],0)/H.length;L.mask={...L.mask,keys:[{t:0,pts:H.map(([st,Y])=>[Xe(Z+(st-Z)*1.04),Xe(ot+(Y-ot)*1.04)])}]}}const{track:B}=Kt(s,r,L.start,L.start+L.duration);s.push({...L,track:B}),U.push(L.id)}h.push(`endingLook ${d}: ${K}`);break}case"mediaCard":{l=Jt(l);const d=y(l.clipId);if(!d)throw Error("Clip not found");for(const I of["posX","posY"])if(l[I]!=null&&!(Number.isFinite(l[I])&&l[I]>=0&&l[I]<=1))throw Error(`mediaCard ${I} must be 0..1 (the card centre)`);const{patch:w,rect:T}=aw(d,{W:n.W||1280,H:n.H||720,material:o.find(I=>I.id===d.nodeId)??null,width:kt(l.width)??kt(l.numberValue),cx:kt(l.posX),cy:kt(l.posY),aspect:kt(l.aspect),round:kt(l.round),rim:l.rim===!1?!1:l.color??void 0});for(const[I,O]of Object.entries(w))O===void 0?delete d[I]:d[I]=O;h.push(`mediaCard ${K}: card at x ${T.x}, y ${T.y}, w ${T.w}, h ${T.h} (fractions of the frame)`);break}case"mediaBoard":{l=Jt(l);const d=Array.isArray(l.clipIds)?l.clipIds:[],w=d.map(B=>y(B));if(!w.length||w.some(B=>!B)||new Set(d).size!==d.length)throw Error(`mediaBoard needs clipIds: 1–${pe.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=l.area&&["x","y","w","h"].every(B=>Number.isFinite(l.area[B])&&l.area[B]>=0&&l.area[B]<=1)&&l.area.w>.1&&l.area.h>.1?{x:l.area.x,y:l.area.y,w:Math.min(l.area.w,1-l.area.x),h:Math.min(l.area.h,1-l.area.y)}:void 0,L=JC(w,{W:n.W||1280,H:n.H||720,materials:o,area:O,cols:kt(l.cols),step:kt(l.step),round:kt(l.round),rim:l.rim===!1?!1:l.color??void 0});for(const B of w)for(const[H,Z]of Object.entries(L.patches.get(B.id)))Z===void 0?delete B[H]:B[H]=Z;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":{l=Jt(l);const d=y(l.clipId);if(!d)throw Error("Clip not found");const w=(Array.isArray(l.moves)?l.moves:[]).map(T=>({...T,at:Number(T?.at)-d.start}));Object.assign(d,QC(d,{moves:w})),h.push(`screenCamera ${K}: ${w.length} move(s)`);break}case"outlineObject":{l=Jt(l);const d=y(l.clipId);if(!d||!d.person&&!d.mask)throw Error("outlineObject needs a cut-out layer (cutOutObject / segmentPerson, or a masked layer)");if(l.booleanValue===!1){delete d.edge,h.push(`outlineObject ${K}: removed`);break}const w=(T,I,O,L)=>Math.max(I,Math.min(O,Number.isFinite(T)?T:L));d.edge=Zu({color:String(l.color??"#a3ff00").toLowerCase(),width:w(kt(l.width),.002,.08,.006),glow:w(kt(l.glow),0,2,1),...l.run===!0?{cover:.35,sweep:180,comet:!0}:{}}),h.push(`outlineObject ${K}: outline ${d.edge.color}`);break}case"handWipe":{l=Jt(l);const d=y(l.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=y(l.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=R0({...l,point:l.point??"palm"}),I=l.dir??"auto",O=kt(l.feather);if(!pe.wipe.dirs.includes(I))throw Error(`handWipe dir: ${pe.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>Bt)throw Error(`Tối đa ${Bt} clip`);const H=n.W||1280,Z=n.H||720,ot=o.find(vt=>vt.id===d.nodeId),st=Math.round(ot?.width)||H,Y=Math.round(ot?.height)||Z;let ct=zt();for(;y(ct);)ct=zt();let mt={...w,id:ct};if(L>mt.start+1e-6){const[,vt]=_e(mt,L,`${ct}-a`);vt&&(mt={...vt,id:ct})}if(B<mt.start+mt.duration-1e-6){const[vt]=_e(mt,B,`${ct}-b`);mt={...vt,id:ct}}const Q=mt,nt={...mt,label:`${w.label||"Video"} · tay`,volume:0,mask:Xd(w.hands?.mw,w.hands?.mh)};for(const vt of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","enter","exit","shocks","impacts","trail","pendingPin","pin","person"])delete nt[vt];nt.track=Kt(s,r,nt.start,nt.start+nt.duration).track,s.push(nt),U.push(ct);const dt={source:w.id,mode:"wipe",cutout:ct,point:T.point,side:T.side,dir:I,...O!=null?{feather:O}:{},from:Xe(L-w.start),duration:Xe(B-L)};if(lu(w,L-w.start,B-L)){const vt=ej(d,w,{point:T.point,side:T.side,dir:I,feather:O??void 0,W:H,H:Z,mw:st,mh:Y});d.mask=vt.patch.mask;const It=N0(Q);It&&(nt.mask=It),Object.assign(d,Fe(d,{kind:"hand-track",op:"handWipe",params:dt})),h.push(`handWipe ${K}: revealed by the hand moving ${vt.dir} (${vt.from}–${vt.to}s), hand in front`);break}d.mask=tj(st,Y),Object.assign(d,Fe(d,{kind:"hand-track",op:"handWipe",params:dt})),h.push(`handWipe ${K}: the hands are tracked in the editor, then the layer is revealed along the swipe`);break}case"beautyStrip":{const d=Array.isArray(l.clipIds)?l.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 I=y(Mt(T));if(!I)throw Error(`Clip not found: ${String(T).slice(0,60)}`);if(I.kind!=="video"&&I.kind!=="image"||I.title||I.shape||I.motion||I.card)throw Error(`beautyFace: ${I.label||I.id} is not footage (a video / image clip)`);const O=ph(I.grade),L=O.filter(B=>!z$(B));if(w+=O.length-L.length,L.length!==O.length){const B=uh(I.grade||{},L);Object.keys(B).length?I.grade=B:delete I.grade}}h.push(l._off?`beautyFace: removed ${w} beauty node(s)`:`beautyFace: ${d.length} clip(s)${w?` (replaced ${w} earlier beauty node(s))`:""}`);break}case"trackFace3D":{const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("trackFace3D needs clipId = a video clip");if(gi(d)&&l.booleanValue!==!0){h.push(`trackFace3D ${d.label||d.id}: already tracked in 3D (${d.face.n} samples)`);break}Object.assign(d,Fe(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":{l=Jt(l);const d=y(l.clipId),w=y(l.sourceClipId);if(!d||!Yk(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?(n.W||1280)/(n.H||720):O.width/O.height;delete d.pendingPin,d.pin={clip:w.id,face:Qp(l.place??"front",L,l)},gi(w)||Object.assign(w,Fe(w,{kind:"face-3d",op:"pinToFace"})),h.push(`pinToFace ${d.label||d.id} → ${w.label||w.id} (${l.place??"front"}${gi(w)?"":", face tracked in 3D in the open editor"})`);break}case"faceHologram":{l=Jt(l);const d=y(l.sourceClipId??l.clipId);if(!d||d.kind!=="video")throw Error("faceHologram needs sourceClipId = the footage with the face");const w=ey[l.set??"call"];if(!w)throw Error(`faceHologram set must be one of ${r4.join(", ")}`);if(l.place!=null&&!ud.includes(l.place))throw Error(`faceHologram place must be one of ${ud.join(", ")}`);const T=l.at==null?d.start:Number(l.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 I=Math.min(to.maxDuration,d.start+d.duration-T,l.duration==null?1/0:Number(l.duration));if(!(I>=1/ve))throw Error("faceHologram duration is too short");if(s.length+w.layers.length>Bt)throw Error(`Tối đa ${Bt} clip`);const O=(n.W||1280)/(n.H||720),L=ut(T),B=ut(I),H=[];for(const Z of w.layers){const ot=Za(Z.preset,{text:l.text,subText:l.subText??l.subtitle,numberValue:l.numberValue,color:l.color}),st=Qe({code:ot.code,params:ot.params,preset:ot.preset,kind:ot.kind});let Y=zt();for(;y(Y);)Y=zt();const{track:ct}=Kt(s,r,L,L+B);s.push({id:Y,nodeId:"",kind:"image",url:"",label:`Hologram · ${ot.name}`,volume:0,motion:st,blend:"add",start:L,duration:B,track:ct,motionKeys:[],pin:{clip:d.id,face:Qp(l.place??Z.place,O,l)}}),U.push(Y),H.push(Y)}gi(d)||Object.assign(d,Fe(d,{kind:"face-3d",op:"faceHologram"})),h.push(`faceHologram ${l.set??"call"} on ${d.label||d.id}: ${H.length} layer(s) ${H.join(", ")}${gi(d)?"":" — the face is tracked in 3D in the open editor"}`);break}case"faceGag":case"cartoonGag":{l=Jt(l);const d=y(l.clipId??l.sourceClipId);if(!d||d.kind!=="video")throw Error(`${l.op} needs clipId = the footage with the face (a video clip)`);if(!Vp(d))throw Error(`${l.op}: this clip cannot be warped (adjustment / generated layer)`);const w=d.label||d.id;if(l.op==="faceGag"&&l.booleanValue===!1){const mt={...d.distort||{}};delete mt.face;const Q=Gp(mt);Q?d.distort=Q:delete d.distort,h.push(`faceGag ${w}: gags removed`);break}const T=l.at==null?d.start:Number(l.at);if(!Number.isFinite(T)||T<d.start-1e-6||T>=d.start+d.duration)throw Error(`${l.op} at must be a timeline time inside the footage`);const I=Math.min(d.start+d.duration-T,l.duration==null?2.5:Number(l.duration));if(!(I>=ja.minDur))throw Error(`${l.op} duration must be at least ${ja.minDur} s inside the footage`);const O=l.amount==null?l.numberValue==null?1:Number(l.numberValue):Number(l.amount);if(!(O>0&&O<=ja.maxAmount))throw Error(`${l.op} amount must be 0.1–${ja.maxAmount}`);const L=+(T-d.start).toFixed(4),B=+I.toFixed(4);let H,Z=[],ot=null;if(l.op==="faceGag"){const mt=l.gag??l.style??l.kind;if(!If.includes(mt))throw Error(`faceGag gag must be one of ${If.join(", ")}`);H=[{type:mt,a:O}]}else{const mt=l.gag??l.style??"awooga";if(ot=Xk[mt],!ot)throw Error(`cartoonGag gag must be one of ${Uk.join(", ")}`);H=ot.warp.map(Q=>({type:Q.type,a:+Math.min(ja.maxAmount,Q.a*O).toFixed(3)})),Z=l.props===!1?[]:ot.props}const st=[...d.distort?.face||[],...H.map(mt=>({type:mt.type,t:L,d:B,a:mt.a}))];if(st.length>ja.gags)throw Error(`At most ${ja.gags} face gags on one clip`);d.distort=rf(Gp({...d.distort||{},face:st}));const Y=[];if(Z.length){if(s.length+Z.length>Bt)throw Error(`Tối đa ${Bt} clip`);const mt=(n.W||1280)/(n.H||720),Q=ut(T),nt=ut(Math.min(I,to.maxDuration));for(const dt of Z){const vt=Za(dt.preset,{color:l.color}),It=Qe({code:vt.code,params:vt.params,preset:vt.preset,kind:vt.kind});let xt=zt();for(;y(xt);)xt=zt();const{track:Et}=Kt(s,r,Q,Q+nt);s.push({id:xt,nodeId:"",kind:"image",url:"",label:`Gag · ${vt.name}`,volume:0,motion:It,start:Q,duration:nt,track:Et,motionKeys:[],pin:{clip:d.id,face:Qp(dt.place,mt,l)}}),U.push(xt),Y.push(xt)}}const ct=Y.length?gi(d):!!d.face;ct||Object.assign(d,Fe(d,{kind:"face-3d",op:l.op})),h.push(`${l.op} ${l.op==="faceGag"?H[0].type:l.gag??"awooga"} on ${w} at ${Xe(T)}s for ${Xe(I)}s: ${H.map(mt=>`${mt.type} ${mt.a}`).join(", ")}${Y.length?`, ${Y.length} prop layer(s) ${Y.join(", ")}`:""}${ct?"":" — the face is tracked in the open editor first"}`);break}case"fixFace":{l=Jt(l);const d=y(l.clipId);if(!d?.face)throw Error("fixFace needs clipId = a video with a face track (trackFace3D)");if(l.booleanValue===!1){delete d.face.fix,d.face={...d.face},h.push(`fixFace ${d.label||d.id}: corrections removed`);break}const w=l.at==null?d.start:Number(l.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=Hk(d,w-d.start,{dx:kt(l.dx),dy:kt(l.dy),ds:kt(l.scale),droll:kt(l.roll),dyaw:kt(l.yaw),dpitch:kt(l.pitch)});d.face={...d.face,fix:T.fix},h.push(`fixFace ${d.label||d.id} at ${Xe(w)}s: ${T.text}`);break}case"speakerWindow":{const d=it(l.at);if(d===null)throw Error("speakerWindow needs at (timeline seconds)");const w=y(l.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>Bt)throw Error(`Tối đa ${Bt} clip`);for(const O of["posX","posY"])if(l[O]!=null&&!(Number.isFinite(l[O])&&l[O]>=0&&l[O]<=1))throw Error(`speakerWindow ${O} must be 0..1 (the window centre)`);if(l.aspect!=null&&!(Number.isFinite(l.aspect)&&l.aspect>=.4&&l.aspect<=2))throw Error("speakerWindow aspect must be .4–2 (width / height)");s=tE(s,T.id,{at:d,duration:it(l.duration)??void 0,width:it(l.numberValue)??void 0,cx:it(l.posX)??void 0,cy:it(l.posY)??void 0,aspect:it(l.aspect)??void 0,color:l.color??void 0,W:n?.W||1280,H:n?.H||720,material:o.find(O=>O.id===T.nodeId)??null,newId:zt}).clips,h.push(`speaker window ${K} @ ${ut(d)}s`);break}case"speakerLayout":{if(l.error)throw Error(l.error);const d=Ah(l,"speakerLayout"),w=y(d.clipId);if(!w)throw Error("Clip not found");const T=WE(s,w.id,{beats:d.beats,morph:d.morph,W:n?.W||1280,H:n?.H||720,material:o.find(I=>I.id===w.nodeId)??null});s=T.clips,h.push(`speaker layout ${K}: ${d.beats.length} beat${d.beats.length>1?"s":""} on ${T.pieces} piece${T.pieces>1?"s":""}`);break}case"courseStyle":{const d=y(l.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,I=Number.isInteger(w?.height)&&w.height>1?w.height:1e3;if(l.crop!=null){const{left:O=0,right:L=0,top:B=0,bottom:H=0}=l.crop;if(![O,L,B,H].every(Z=>Number.isFinite(Z)&&Z>=0&&Z<=.9)||O+L>.9||B+H>.9)throw Error("Invalid crop");d.crop={left:O,right:L,top:B,bottom:H}}if(l.rotation!=null){const O=it(l.rotation);if(O===null||Math.abs(O)>Hs)throw Error(`rotation must be -${Hs}..${Hs}`);d.rotation=O}if(l.mask!=null){if(!["circle","rounded","none"].includes(l.mask))throw Error("Course style mask must be circle / rounded / none");if(l.mask==="none")delete d.mask;else{const O=pa(T,I,d.crop),L=Math.min(O.w,O.h),B=l.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=fr({mw:T,mh:I},[Dn(B,O.w,O.h)])}}if(l.color!=null){if(!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("Course style color must be #RRGGBB");d.edge={color:l.color.toLowerCase(),width:Math.max(.002,Math.min(.08,it(l.numberValue)??.008)),glow:.7}}if(l.shadow===!0&&(d.shadow={...kn,opacity:.55,blur:18,distance:8}),l.fit!=null){if(!["contain","cover"].includes(l.fit))throw Error("Course style fit must be contain / cover");l.fit==="cover"?d.fit="cover":delete d.fit}h.push(`course style ${K}`);break}case"luxuryCard":{const d=y(l.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(H=>H.id===d.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,I=Number.isInteger(w?.height)&&w.height>1?w.height:1e3;if(l.color!=null&&!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("luxuryCard color must be #RRGGBB");const O=Math.max(0,Math.min(.3,it(l.numberValue)??.04)),L=pa(T,I,d.crop),B=(l.color??"#ffd56a").toLowerCase();if(d.mask=fr({mw:T,mh:I},[Dn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:O},L.w,L.h)]),l.booleanValue===!0)d.edge={color:B,width:.01,glow:1.2,cover:.45,sweep:120,comet:!0};else{const H=[];for(let Z=0;Z<=d.duration+1e-6&&H.length<30;Z+=.6)H.push({time:+Z.toFixed(3),value:H.length%2?1:.45,ease:Yt["ease-in-out"]});d.edge={color:B,width:.01,glow:1.2,...H.length>1?{keys:H}:{}}}d.shadow={...kn,opacity:.5,blur:22,distance:10},h.push(`gold card ${d.label||d.id}${l.booleanValue===!0?" (running light)":""}`);break}case"floatCard":{const d=[...new Set([...Array.isArray(l.clipIds)?l.clipIds:[],...l.clipId?[l.clipId]:[]])];if(!d.length||d.length>6)throw Error("floatCard needs 1–6 picture / video clips (clipId or clipIds)");if(l.color!=null&&!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("floatCard color must be #RRGGBB");const w=(l.color??"#ffffff").toLowerCase(),T=Math.max(0,Math.min(20,it(l.numberValue)??6)),I=l.booleanValue!==!1,O=d.length;d.forEach((L,B)=>{const H=y(L);if(!H||!["image","video"].includes(H.kind)||H.motion||H.title||H.shape||H.card||H.geo)throw Error(`floatCard needs photo / video clips (${L})`);if(r[H.track]?.locked)throw Error("Track đã khóa");const Z=o.find(xt=>xt.id===H.nodeId),ot=Number.isInteger(Z?.width)&&Z.width>1?Z.width:1e3,st=Number.isInteger(Z?.height)&&Z.height>1?Z.height:1e3;H.mask=fr({mw:ot,mh:st},[Dn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:.06},pa(ot,st,H.crop).w,pa(ot,st,H.crop).h)]),H.edge={color:w,width:.009,glow:1.3,amount:.9},H.shadow={...kn,opacity:.6,blur:26,distance:16};const Y=O>1?+((B-(O-1)/2)*Math.min(.3,.9/O)).toFixed(4):Qt(H,"x",0),ct=O>1?B%2?.035:-.035:Qt(H,"y",0),mt=O>1?+Math.min(.62,1.5/O).toFixed(3):Math.abs(Qt(H,"zoom",0)-1)<1e-6?.62:Qt(H,"zoom",0),Q=(B%2?-1:1)*T,nt=H.duration,dt=xt=>+Math.min(nt,xt).toFixed(3),vt="ease-in-out",It=(xt,Et)=>{Object.assign(H,ca(H,xt,Et.filter((Ct,Gt,ee)=>!Gt||Ct.time-ee[Gt-1].time>=1/30)))};if(It("zoom",[{time:0,value:+(mt*.82).toFixed(4),ease:"back-out"},{time:dt(.38),value:mt}]),It("opacity",[{time:0,value:0},{time:dt(.22),value:1}]),It("x",[{time:0,value:Y}]),I&&nt>1){const xt=[],Et=[];for(let Ct=0,Gt=0;Ct<=nt+1e-6&&xt.length<30;Ct+=1.4,Gt++)xt.push({time:dt(Ct),value:+(ct+(Gt%2?.012:-.012)).toFixed(4),ease:vt}),Et.push({time:dt(Ct),value:+(Q+(Gt%2?-1:1)*Math.max(.6,T*.3)).toFixed(3),ease:vt});It("y",xt),It("rot",Et)}else It("y",[{time:0,value:ct}]),It("rot",[{time:0,value:Q}])}),h.push(`floatCard: ${O} floating card${O>1?"s":""} (tilt ${T}°${I?", drifting":""})`);break}case"breakdownShowcase":{if(l.color!=null&&!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("breakdownShowcase color must be #RRGGBB");if(l.style!=null&&!Fg.includes(l.style))throw Error(`breakdownShowcase style: ${Fg.join(" | ")}`);if(l.layout!=null&&l.layout!=="auto"&&!ih.includes(l.layout))throw Error(`breakdownShowcase layout: auto | ${ih.join(" | ")}`);if(l.labels!=null&&(!Array.isArray(l.labels)||l.labels.length>oi.shots||l.labels.some(T=>typeof T!="string")))throw Error(`breakdownShowcase labels: up to ${oi.shots} strings`);const d=[...new Set([...Array.isArray(l.clipIds)?l.clipIds:[],...l.clipId?[l.clipId]:[]])];for(const T of d)if(!y(T))throw Error(`Không thấy clip ${T}`);const w=RC(s,r,d,{style:l.style,color:l.color,layout:l.layout,lang:l.lang??(n.locale==="vi"?"vi":void 0),labels:l.labels,at:it(l.at)??void 0,newId:zt,W:n.W||1280,H:n.H||720,materials:o});if(s.length+w.add.length>Bt)throw Error(`Tối đa ${Bt} 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(l.clipIds)?l.clipIds:[])];if(d.length<2||d.length>16)throw Error("portfolioWall needs 2–16 picture / video clips (clipIds)");const w=l.style??"grid";if(!["grid","arc","mosaic"].includes(w))throw Error("portfolioWall style must be grid, arc or mosaic");const T=l.shape??(w==="mosaic"?"landscape":"portrait");if(!["portrait","landscape","square"].includes(T))throw Error("portfolioWall shape must be portrait, landscape or square");if(l.color!=null&&!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("portfolioWall color must be #RRGGBB");const I=it(l.numberValue);if(I!==null&&!(Number.isInteger(I)&&I>=1&&I<=4))throw Error("portfolioWall rows (numberValue) must be 1–4");let O=null;if(l.sourceClipId!=null&&(O=y(l.sourceClipId),!O||O.kind!=="video"))throw Error("portfolioWall sourceClipId must be the speaker video");const L=n.W>0?n.W:1280,B=n.H>0?n.H:720,H=d.length,Z=T==="portrait"?9/16:T==="square"?1:16/9,ot=(l.color??"#ffffff").toLowerCase(),st=l.booleanValue!==!1,Y=I??(w==="mosaic"?Math.max(2,Math.round(Math.sqrt(H*Z*B/L))):H<=5?1:H<=10?2:3),ct=Math.ceil(H/Y),mt=L*(w==="mosaic"?1.04:w==="arc"?1.02:.95),Q=B*(w==="mosaic"?1.06:w==="arc"?.88:.9),nt=mt/ct,dt=Q/Y,vt=w==="mosaic"?.94:w==="arc"?.86:.9,It=Math.min(nt*vt,dt*vt*Z);if(d.forEach((xt,Et)=>{const Ct=y(xt);if(!Ct||!["image","video"].includes(Ct.kind)||Ct.motion||Ct.title||Ct.shape||Ct.card||Ct.geo||Ct.vfx)throw Error(`portfolioWall needs photo / video clips (${xt})`);if(O&&Ct.id===O.id)throw Error("portfolioWall cannot use the speaker video as a card");if(r[Ct.track]?.locked)throw Error("Track đã khóa");const Gt=o.find(Rt=>Rt.id===Ct.nodeId),ee=Number.isInteger(Gt?.width)&&Gt.width>1?Gt.width:1280,re=Number.isInteger(Gt?.height)&&Gt.height>1?Gt.height:720,Me=pa(ee,re,Ct.crop),qt=Me.w/Me.h,Nt=Z<qt?Z/qt:1,_t=Z<qt?1:qt/Z;Ct.mask=fr({mw:ee,mh:re},[Dn({kind:"rect",cx:.5,cy:.5,w:Nt,h:_t,rot:0,round:.08},Me.w,Me.h)]),Ct.edge={color:ot,width:.006,glow:.8,amount:.85},Ct.shadow={...kn,opacity:.45,blur:18,distance:8},Ct.fit==="cover"&&delete Ct.fit,w==="mosaic"&&(Ct.exposure=-.75,Ct.saturation=.9);const Vt=Math.floor(Et/ct),he=Vt===Y-1?H-Vt*ct:ct,ne=Et-Vt*ct+(ct-he)/2,be=Math.min(L/Me.w,B/Me.h)*Me.w,ir=+(It/(be*Nt)).toFixed(4),zr=+(((ne+.5)/ct-.5)*mt/L).toFixed(4),Ur=+(((Vt+.5)/Y-.5)*Q/B).toFixed(4),No=Ct.duration,ro=Rt=>+Math.min(No,Math.max(0,Rt)).toFixed(3),So=ro(Et*(w==="mosaic"?.035:.07)),X=ro(So+(w==="mosaic"?.4:.55)),gt=w==="mosaic"?1.07:1.03,bt=(Rt,Dt)=>{Object.assign(Ct,ca(Ct,Rt,Dt.filter((Ft,Xt,Zt)=>!Xt||Ft.time-Zt[Xt-1].time>=1/30)))};if(w==="arc"){const Rt=L*1.25,Dt=Br(L,B),Ft=(ne-(ct-1)/2)*nt/Rt,Xt=Math.abs(Ft)>1e-6?Math.sign(Ft):Et%2?1:-1,Zt=Ft+Xt*.95,te=Ft+.06,se=ae=>({x:+(Rt*Math.sin(ae)/L).toFixed(4),depth:+(Rt*(1-Math.cos(ae))/Dt).toFixed(4),tiltY:+(-ae*180/Math.PI).toFixed(3)}),ce=se(Zt),Ut=se(Ft),oe=se(te);Ct.is3D=!0;for(const ae of["x","depth","tiltY"])bt(ae,[{time:0,value:ce[ae]},{time:So,value:ce[ae],ease:"ease-out"},{time:X,value:Ut[ae],ease:"ease-in-out"},{time:ro(No),value:oe[ae]}]);bt("y",[{time:0,value:Ur}]),bt("zoom",[{time:0,value:ir}]),bt("rot",[{time:0,value:0}]),bt("opacity",[{time:0,value:0},{time:So,value:0},{time:ro(So+.25),value:1},...st&&No>X+.5?[{time:ro(No-.35),value:1},{time:ro(No),value:0}]:[]]);return}const St=w==="mosaic"?.035:0;bt("x",[{time:0,value:zr},{time:X,value:zr,ease:"ease-in-out"},{time:ro(No),value:+(zr*gt-St).toFixed(4)}]),bt("y",w==="grid"?[{time:0,value:+(Ur+.75).toFixed(4)},{time:So,value:+(Ur+.75).toFixed(4),ease:"ease-out"},{time:X,value:Ur,ease:"ease-in-out"},{time:ro(No),value:+(Ur*gt).toFixed(4)}]:[{time:0,value:Ur},{time:ro(No),value:+(Ur*gt).toFixed(4)}]),bt("zoom",[{time:0,value:+(ir*(w==="grid"?.8:1.25)).toFixed(4)},{time:So,value:+(ir*(w==="grid"?.8:1.25)).toFixed(4),ease:"back-out"},{time:X,value:ir,ease:"ease-in-out"},{time:ro(No),value:+(ir*gt).toFixed(4)}]),bt("rot",w==="grid"?[{time:0,value:Et%2?7:-7},{time:So,value:Et%2?7:-7,ease:"ease-out"},{time:X,value:0}]:[{time:0,value:0}]),bt("opacity",[{time:0,value:0},{time:So,value:0},{time:ro(So+.18),value:1},...st&&No>X+.5?[{time:ro(No-.35),value:1},{time:ro(No),value:0}]:[]])}),w==="arc"&&!u?.enabled&&(u={...u??jr,enabled:!0,motionV:2,motionKeys:u?.motionKeys??[]}),O){const xt=d.reduce((Et,Ct)=>ra(y(Ct),y(Et))>0?Ct:Et);rt.splice(D+1,0,{op:"placeBehindPerson",clipId:xt,sourceClipId:O.id})}h.push(`portfolioWall: ${H} cards, ${w} ${Y}×${ct}${w==="arc"?" (3D, timeline camera on)":""}${O?", behind the speaker":""}`);break}case"promoShot":{const d=[...new Set(Array.isArray(l.clipIds)?l.clipIds:l.clipId!=null?[l.clipId]:[])],w=String(l.shot??"");if(!np.includes(w))throw Error(`promoShot shot must be ${np.join(" | ")}`);if(l.color!=null&&!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("promoShot color must be #RRGGBB");const T=it(l.size??l.cardSize);if(T!==null&&!(T>=.3&&T<=1))throw Error("promoShot size must be 0.3–1 (share of the frame width)");const I=n.W>0?n.W:1280,O=n.H>0?n.H:720,L=(l.color??"#ffffff").toLowerCase(),B=T??(w==="deck-deal"?.5:w==="zoom-detail"||w==="paparazzi"?.9:.78),H=(dt,vt)=>{const It=o.find(ee=>ee.id===dt.nodeId),xt=Number.isInteger(It?.width)&&It.width>1?It.width:1280,Et=Number.isInteger(It?.height)&&It.height>1?It.height:720,Ct=pa(xt,Et,vt),Gt=Math.min(I/Ct.w,O/Ct.h);return{mw:xt,mh:Et,sp:Ct,fitW:Gt*Ct.w,fitH:Gt*Ct.h}},Z=d.map(dt=>{const vt=y(dt);if(!vt||!["image","video"].includes(vt.kind)||vt.motion||vt.title||vt.shape||vt.card||vt.geo||vt.vfx)throw Error(`promoShot needs picture / video clips (${dt})`);if(r[vt.track]?.locked)throw Error("Track đã khóa");const It=H(vt,vt.crop),xt=+Math.min(B*I/It.fitW,.92*O/It.fitH).toFixed(4);return{c:vt,f:It,card:{id:vt.id,duration:vt.duration,zoom:xt,dispW:It.fitW/I,dispH:It.fitH/O}}}),ot=Z[0]?.c,st=dt=>it(dt)===null?null:it(dt)-(ot?.start??0),Y=l.focus??(it(l.focusX)!==null||it(l.focusY)!==null||it(l.focusSize)!==null?{x:it(l.focusX)??void 0,y:it(l.focusY)??void 0,size:it(l.focusSize)??void 0}:void 0),ct=Array.isArray(l.points)?l.points.map(dt=>Array.isArray(dt)?{x:dt[0],y:dt[1]}:dt):void 0,mt=bS(w,Z.map(dt=>dt.card),{focus:Y,points:ct,times:Array.isArray(l.times)?l.times.map(st).filter(dt=>dt!==null):void 0,at:st(l.at)??void 0,bStart:Z[1]?Z[1].c.start-ot.start:0,slices:it(l.numberValue)??void 0}),Q=(dt,vt)=>{dt.mask=fr({mw:vt.mw,mh:vt.mh},[Dn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:.045},vt.sp.w,vt.sp.h)]),dt.edge={color:L,width:.004,glow:.5,amount:.6},dt.shadow={...kn,opacity:.5,blur:26,distance:14},dt.fit==="cover"&&delete dt.fit},nt=(dt,vt,It=1)=>{vt.is3D&&(dt.is3D=!0);for(const[xt,Et]of Object.entries(vt.keys)){const Ct=xt==="zoom"&&It!==1?Et.map(Gt=>({...Gt,value:+(Gt.value*It).toFixed(4)})):Et;Object.assign(dt,ca(dt,xt,Ct.filter(Gt=>Gt.time<=dt.duration+1e-6)))}for(const[xt,Et]of Object.entries(vt.effects??{}))Object.assign(dt,ca(dt,xt,Et.filter(Ct=>Ct.time<=dt.duration+1e-6)))};if(w==="exploded"){const{c:dt,f:vt}=Z[0],It=mt.slices,xt=dt.crop??{left:0,right:0,top:0,bottom:0},Et=1-xt.top-xt.bottom,Ct=[];for(let ee=xn(dt.track)+1;Ct.length<It-1&&ee<40;ee++){const re=en(ee);re!=null&&A(dt)(re)&&Ct.push(re)}if(Ct.length<It-1)throw Error("promoShot exploded needs free video tracks above the clip");const Gt=[];for(const ee of mt.cards){const re=ee.slice,Me={...xt,top:+(xt.top+Et*re/It).toFixed(4),bottom:+(xt.bottom+Et*(It-1-re)/It).toFixed(4)};let qt=zt();for(;y(qt);)qt=zt();const Nt=re===It-1?dt:{...structuredClone(dt),id:qt,track:Ct[It-2-re]};Nt.crop=Me;const _t=H(Nt,Me);Q(Nt,_t),nt(Nt,ee,vt.fitW/_t.fitW),Nt!==dt&&(s.push(Nt),Gt.push(Nt.id),U.push(Nt.id))}h.push(`promoShot exploded: ${It} bands (${Gt.length} copies on the tracks above), timeline camera on`)}else{for(const dt of mt.cards){const vt=Z.find(It=>It.c.id===dt.id);Q(vt.c,vt.f),nt(vt.c,dt)}h.push(`promoShot ${w}: ${Z.length} card${Z.length>1?"s":""}${mt.camera?", timeline camera on":""}`)}mt.camera&&!u?.enabled&&(u={...u??jr,enabled:!0,motionV:2,motionKeys:u?.motionKeys??[]});break}case"avatarBadge":{const d=y(l.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(l.color!=null&&!/^#[0-9a-f]{6}$/i.test(l.color))throw Error("avatarBadge color must be #RRGGBB");const w=o.find(ct=>ct.id===d.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,I=Number.isInteger(w?.height)&&w.height>1?w.height:1e3,O=pa(T,I,d.crop),L=Math.min(O.w,O.h),B=(l.color??"#ffd56a").toLowerCase();d.mask=fr({mw:T,mh:I},[Dn({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=l.booleanValue===!1?{color:B,width:.03,glow:1.6}:{color:B,width:.03,glow:1.6,cover:.7,sweep:200,comet:!0},d.shadow={...kn,opacity:.5,blur:20,distance:8};const H=Math.max(.1,Math.min(1,it(l.numberValue)??.32)),Z=Math.max(-.5,Math.min(.5,it(l.posX)??0)),ot=Math.max(-.5,Math.min(.5,it(l.posY)??0)),st=d.duration,Y=(ct,mt)=>{Object.assign(d,ca(d,ct,mt.filter(Q=>Q.time<=st+1e-6)))};Y("x",[{time:0,value:Z}]),Y("y",[{time:0,value:ot}]),Y("zoom",st>.5?[{time:0,value:+(H*.3).toFixed(4),ease:"back-out"},{time:+Math.min(st,.42).toFixed(3),value:H}]:[{time:0,value:H}]),h.push(`avatarBadge ${K}: round badge${l.booleanValue===!1?"":" with a running ring light"}`);break}case"beatRamp":{const d=[...new Set([...Array.isArray(l.clipIds)?l.clipIds:[],...l.clipId?[l.clipId]:[]])];if(!d.length||d.length>60)throw Error("beatRamp needs 1–60 video clips (clipIds)");const w=d.map(Y=>{const ct=y(Y);if(!ct)throw Error(`Clip not found: ${Y}`);if(ct.kind!=="video")throw Error(`beatRamp: ${ct.label||Y} is not a video clip`);if(r[ct.track]?.locked)throw Error("Track đã khóa");return ct}).sort((Y,ct)=>Y.start-ct.start||Y.track-ct.track),T=it(l.every)??it(l.numberValue)??1;if(!xm.includes(T))throw Error(`beatRamp every must be one of ${xm.join(", ")} beats`);const I=l.preset??"peak-burst",O=VM(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=KM(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,H=new Set(w.map(Y=>Y.id)),Z=L.at(-1).start+L.at(-1).duration,ot=s.find(Y=>Y.track===B&&!H.has(Y.id)&&Y.start<Z-1e-6&&Y.start+Y.duration>L[0].start+1e-6);if(ot)throw Error(`beatRamp would cover "${ot.label||ot.id}" on the same row (${L[0].start}–${+Z.toFixed(2)} s) — move it or pick the shots on a free row`);const st=it(l.peak)??void 0;L.forEach((Y,ct)=>{const mt=w[ct],Q={...mt,start:Y.start,track:B},nt=sm(Q,I,Y.duration,{peak:st}),dt=s.findIndex(vt=>vt.id===mt.id);s[dt]=nt}),h.push(`beatRamp ${I}: ${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(l.clipIds)?l.clipIds:[],...l.clipId?[l.clipId]:[]])];if(!d.length)throw Error("setAnchor needs clipId or clipIds");if(!Mm.includes(l.preset))throw Error(`setAnchor preset must be one of ${Mm.join(", ")}`);const w=n.W||1280,T=n.H||720,I={tl:"top-left",t:"top",tr:"top-right",l:"left",c:"center",r:"right",bl:"bottom-left",b:"bottom",br:"bottom-right"}[l.preset];for(const O of d){const L=y(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(l.at)??L.start)-L.start)),H=o.find(xt=>xt.id===L.nodeId),Z=H?.width>0&&H?.height>0?H.width/H.height:w/T,ot=w/T,st=L.fit==="cover"?1:Math.min(1,Z/ot),Y=L.fit==="cover"?1:Math.min(1,ot/Z),ct=Qt(L,"zoom",B),mt=.5+Qt(L,"x",B),Q=.5+Qt(L,"y",B),nt=st*ct/2,dt=Y*ct/2,vt=L.shape?.v===2?Zg(L):[mt-nt,Q-dt,mt+nt,Q+dt];dr(s);const It=s.indexOf(L);s[It]=Ba(s,L,{anchor:I,at:B,W:w,H:T,box:vt})}h.push(`setAnchor ${l.preset} (${xy[l.preset].join(", ")}): ${d.length} layer(s)`);break}case"zoomMove":{const d=[...new Set([...Array.isArray(l.clipIds)?l.clipIds:[],...l.clipId?[l.clipId]:[]])];if(!d.length)throw Error("zoomMove needs clipId or clipIds");if(!_c.includes(l.preset))throw Error(`zoomMove preset must be one of ${_c.join(", ")}`);for(const w of d){const T=y(w);if(!T||T.kind==="audio")throw Error("Clip not found");if(r[T.track]?.locked)throw Error("That layer is locked");const I=l.preset.endsWith("start"),O=Qt(T,"zoom",I?T.duration:0),L=HM(l.preset,T.duration,O,it(l.numberValue)??void 0,it(l.duration)??void 0),B=L[0].time,H=L.at(-1).time,Z=Ee(T,"zoom").filter(Y=>Y.time<B-1e-6||Y.time>H+1e-6).map(Y=>({time:Y.time,value:Y.value})),ot=ca(T,"zoom",[...Z,...L].sort((Y,ct)=>Y.time-ct.time)),st=s.indexOf(T);s[st]=ot}h.push(`zoomMove ${l.preset}: ${d.length} clip(s)`);break}case"stabilize":{const d=y(l.clipId);if(!d)throw Error("Clip not found");if(l.booleanValue===!1){if(!d.stabilized)throw Error("That clip is not stabilized");const{url:L,gcsUri:B,inPoint:H,sourceDuration:Z}=d.stabilized,ot=s.indexOf(d),st={...d,url:L,inPoint:H,sourceDuration:Z};delete st.stabilized,B?st.gcsUri=B:delete st.gcsUri,s[ot]=st,h.push(`stabilize off: ${K}`);break}const w=Array.isArray(l.processed)?l.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 ${K} (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 I=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:{...I,amount:w.amount}},h.push(`stabilize ${K} (${Math.round((w.amount??.5)*100)}%)`);break}case"logoLight":{const d=y(l.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(l.at)??0)),T=Math.max(.4,Math.min(4,it(l.duration)??1.2,d.duration-w)),I=(L,B,H)=>[{time:+w.toFixed(3),value:0,ease:Yt["ease-out"]},{time:+(w+T*L).toFixed(3),value:B,ease:Yt["ease-in-out"]},{time:+(w+T).toFixed(3),value:H}],O=[...(d.effects||[]).filter(L=>L.type!=="glow"&&L.type!=="exposure"),{type:"glow",amount:.35,keys:I(.45,.9,.35)},{type:"exposure",amount:0,keys:I(.4,.55,0)}];if(O.length>yn)throw Error(`At most ${yn} 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"beatStrobe":{const d=["hits","beats","bars"].includes(l.on??l.onBeats)?l.on??l.onBeats:"hits",w=Gm(s,o,{density:d}).filter(I=>d==="beats"||I.kind!=="beat").map(I=>I.t);if(!w.length&&l.booleanValue!==!0)throw Error("beatStrobe: no analysed music on the timeline (add_media the song first) — booleanValue true cuts on the maxShot grid without music");const T=xS(s,r,{clipIds:l.clipIds,at:it(l.at)??void 0,duration:it(l.duration)??void 0,times:w,maxShot:it(l.maxShot)??void 0,flashEvery:it(l.flashEvery)??void 0,bwEvery:it(l.bwEvery)??void 0,newId:()=>{let I=zt();for(;y(I);)I=zt();return I},overlayTrack:Kt,locale:n.locale,aspect:n.W&&n.H?n.W/n.H:void 0});if(T.clips.length>Bt)throw Error(`Tối đa ${Bt} clip`);s=T.clips,U.push(...T.created),h.push(`beatStrobe: ${T.shots} shots on the ${d}, ${T.flashes.length} flash frame(s)`);break}case"dipHold":{let d=l.clipId?y(l.clipId):null;if(!d){const I=it(l.at);I!==null&&(d=s.find(O=>Math.abs(O.start-I)<1/60&&es(O)&&s.some(L=>L.track===O.track&&Math.abs(L.start+L.duration-O.start)<1/60&&es(L))))}if(!d)throw Error("dipHold needs clipId (the clip after the cut) or at (the cut, timeline s)");const w=s.find(I=>I.id!==d.id&&I.track===d.track&&Math.abs(I.start+I.duration-d.start)<1/60&&es(I));if(!w)throw Error("dipHold: no clip ends right where that clip starts on its track");if(r[d.track]?.locked)throw Error("Track đã khóa");const T=MS(w,d,{hold:it(l.hold)??it(l.numberValue)??void 0,fade:it(l.fade)??void 0});for(const[I,O]of[[w,T.a],[d,T.b]]){Object.assign(I,O);for(const L of Object.keys(O))O[L]===void 0&&delete I[L]}h.push(`dipHold ${w.label||w.id} → ${d.label||d.id}: black ${(T.b.start-(w.start+w.duration)).toFixed(2)}s, fades ${T.a.visualFadeOut}s`);break}case"logoSting":{const d=y(l.clipId);if(!d)throw Error("Clip not found");if(r[d.track]?.locked)throw Error("Track đã khóa");const w=o.find(O=>O.id===d.nodeId),T=()=>{let O=zt();for(;y(O);)O=zt();return O},I=vS(d,{style:l.style??l.preset??"metal-sweep",at:it(l.at)??void 0,duration:it(l.duration)??void 0,tagline:l.tagline??l.text,color:l.color??"#ffffff",font:l.fontFamily??"Be Vietnam Pro",mw:w?.width||1e3,mh:w?.height||1e3,newId:T,W:n.W||1280,H:n.H||720});if(Object.assign(d,I.patch),s.length+I.layers.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const O of I.layers){const{track:L}=Kt(s,r,O.start,O.start+O.duration);s.push({...O,track:L}),U.push(O.id)}h.push(`logoSting ${l.style??l.preset??"metal-sweep"} on ${d.label||d.id}${I.layers.some(O=>O.title)?" + tagline":""}`);break}case"lyricStack":{const d=()=>{let T=zt();for(;y(T);)T=zt();return T},w=$S(l.lines,{end:it(l.end)??void 0,side:l.side??"left",size:it(l.size)??it(l.fontSize)??void 0,color:l.color??"#ffffff",font:l.fontFamily??"Oswald",newId:d,H:n.H||720});if(s.length+w.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const T of w){const{track:I}=Kt(s,r,T.start,T.start+T.duration);s.push({...T,track:I}),U.push(T.id)}h.push(`lyricStack: ${w.length} lines`);break}case"addCredits":{const d=()=>{let T=zt();for(;y(T);)T=zt();return T},w=ES(l.items,{at:it(l.at)??0,every:it(l.every)??it(l.numberValue)??void 0,color:l.color??"#ffffff",font:l.fontFamily??"Be Vietnam Pro",newId:d});if(s.length+w.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const T of w){const{track:I}=Kt(s,r,T.start,T.start+T.duration);s.push({...T,track:I}),U.push(T.id)}h.push(`credits: ${w.length} from ${w[0].start}s`);break}case"logoBug":{const d=y(l.clipId);if(!d)throw Error("Clip not found");if(r[d.track]?.locked)throw Error("Track đã khóa");const w=o.find(B=>B.id===d.nodeId),T=s.filter(B=>B.kind!=="audio"&&B.id!==d.id).map(B=>B.start+B.duration),I=T.length?Math.max(...T):d.start+d.duration,O=SS(d,{corner:l.corner??"top-right",size:it(l.size)??void 0,opacity:it(l.opacity)??void 0,from:it(l.from)??0,to:it(l.to)??I,W:n.W||1280,H:n.H||720,mw:w?.width||1e3,mh:w?.height||1e3}),{track:L}=Kt(s.filter(B=>B.id!==d.id),r,O.start,O.start+O.duration);Object.assign(d,O,{track:L});for(const B of Object.keys(O))O[B]===void 0&&delete d[B];h.push(`logoBug ${d.label||d.id} ${l.corner??"top-right"} ${O.start}–${(O.start+O.duration).toFixed(2)}s`);break}case"addSfx":{if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const d=vn(l.sfxId)??Z5(l);if(!d)throw Error(`Unknown sound effect "${l.sfxId}"`);const w=it(l.at);if(w===null||w<0||w+d.duration>Re)throw Error("addSfx needs at (timeline seconds) inside the timeline");const T=it(l.volume);if(T!==null&&(T<0||T>1))throw Error("SFX volume must be 0..1");const I=(d.music?Q5:ha)(s,r,d,w,{volume:T??void 0,track:it(l.track),id:zt()});d.gcsUri&&(I.gcsUri=d.gcsUri),s.push(I),h.push(`sfx ${d.name} → ${I.start}s`);break}case"reframe":{if(!["16:9","9:16","1:1","4:5"].includes(l.aspectRatio))throw Error("Reframe needs aspectRatio");const d=lM(s,o,l.aspectRatio,{clipId:l.clipId},r);if(!d.reframed)throw Error(d.skipped.join("; ")||"Nothing to reframe");s=d.clips,F=l.aspectRatio,h.push(`reframe ${l.aspectRatio}: ${d.reframed} clip${d.skipped.length?` (skipped: ${d.skipped.join("; ")})`:""}`);break}case"rippleDelete":s=lm(s,l.clipId,null,r),h.push(`ripple delete: ${K}`);break;case"setTransition":{if(l.nearestCut===!0&&l.transitionId&&Number.isFinite(l.at)){const d=y(l.clipId);if(!d)throw Error("Clip not found");const T=s.filter(I=>I.nodeId===d.nodeId&&I.track===d.track&&I.kind===d.kind&&!I.mask&&s.some(O=>O.id!==I.id&&O.track===I.track&&O.kind!=="audio"&&Math.abs(O.start-(I.start+I.duration))<1/60)).sort((I,O)=>Math.abs(I.start+I.duration-l.at)-Math.abs(O.start+O.duration-l.at))[0];if(!T||Math.abs(T.start+T.duration-l.at)>1.5)throw Error("No cut near that time");l={...l,clipId:T.id}}try{if(l.transitionId){if(!l.spec||l.spec.id!==l.transitionId)throw Error(`Unknown transition "${l.transitionId}"`);const d=y(l.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=sf(s,l.clipId,l.spec.id==="match-walk"?qg(l.spec,d,w,o):l.spec,it(l.duration)??void 0),h.push(`transition ${l.spec.name}: ${K}`);break}y(l.clipId)?.transition&&(s=$f(s,l.clipId)),y(l.clipId)?.join&&(s=s.map(d=>{if(d.id!==l.clipId)return d;const{join:w,...T}=d;return T})),s=h4(s,l.clipId,l.preset,l.duration??0,r),h.push(`transition: ${K}`);break}catch(d){const w=gj(s,l,p,r);if(!w)throw d;s=w.clips,h.push(`transition → ${w.note}: ${K}`);break}}case"addSubtitles":{const d=y(l.clipId),w=d&&o.find(O=>O.id===d.nodeId);if(!d||!w?.transcript?.length)throw Error("Analyze speech first");const T=Ec(d,Sf(w.transcript)),I=Ef(T,d.duration);d.captionWords?.length&&(d.captionWords=kl(Wk(d.captions,I,d.captionWords,d.duration),d.duration)),d.captions=I,h.push(`subtitles: ${K}`);break}case"addSocialCaptions":{const d=y(l.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=l.captionStyle??"social";if(!["social","karaoke","classic","lesson"].includes(T))throw Error("Invalid caption preset");if(l.captionPosition!=null&&!["top","center","bottom"].includes(l.captionPosition))throw Error("Invalid caption position");if(l.emphasis!=null&&typeof l.emphasis!="boolean")throw Error("Invalid emphasis flag");if(l.perGroup!=null&&![1,2,3].includes(l.perGroup))throw Error("Words per group must be 1–3");if(l.look!=null&&!ny(l.look))throw Error(`Unknown caption look; use one of ${ry.map(L=>L.id).join(", ")}`);if(!d.captions?.length){if(!w?.transcript?.length)throw Error("Analyze speech first");d.captions=Ef(Ec(d,Sf(w.transcript)),d.duration)}const I={...l.cueWords!=null?{cueWords:l.cueWords}:{},...l.lineWords!=null?{lineWords:l.lineWords}:{}};if(T==="classic"){d.captionStyle=Oi({...l.look?cm({style:"classic"},l.look):{style:"classic"},...I}),h.push(`captions classic: ${K}`);break}if(d.captionWords=kl((w?.words?.length?dh(d,kl(w.words,1/0,af)):$p(d.captions)).slice(0,Gk),d.duration),!d.captionWords.length)throw Error("No words to caption");if(d.captionStyle=Oi({...Kk,...T==="lesson"?oE:{style:T},...l.captionPosition?{position:l.captionPosition}:{},...l.emphasis!=null?{emphasis:l.emphasis}:{},...l.perGroup!=null?{perGroup:l.perGroup}:{},...typeof l.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(l.color)?{emphasisColor:l.color,emphasisColor2:l.color}:{}}),l.look&&(d.captionStyle=cm(d.captionStyle,l.look)),Object.keys(I).length&&(d.captionStyle=Oi({...d.captionStyle,...I})),l.highlight!=null){if(!iy(l.highlight))throw Error(`Unknown highlight look; use one of ${ay.map(H=>H.id).join(", ")}`);const L=b4(l.highlight,d.captionStyle),B={...d.captionStyle,...L};for(const H of Object.keys(B))B[H]===void 0&&delete B[H];d.captionStyle=Oi(B)}const O={...l.emphasisScale!=null?{emphasisScale:l.emphasisScale}:{},...l.anim!=null?{anim:l.anim}:{},...l.rowWords!=null?{rowWords:l.rowWords}:{},...l.lineGap!=null?{lineGap:l.lineGap}:{},...l.rowShift!=null?{rowShift:l.rowShift}:{}};Object.keys(O).length&&(d.captionStyle=Oi({...d.captionStyle,...O})),h.push(`${T} captions: ${K}`);break}case"editCaptions":{h.push(...PM(s,l));break}case"rippleTrim":{const d=y(l.clipId);if(!d)throw Error("Clip not found");const w=Ua([d],[{...l,op:"trim"}],o,r);if(w.errors.length)throw Error(w.errors.join("; "));s=lm(s,d.id,w.clips[0],r),h.push(`ripple trim: ${K}`);break}case"speedRampTransition":{const d=(ot,st)=>ot&&st&&ot.id!==st.id&&ot.track===st.track&&ot.kind!=="audio"&&st.kind!=="audio"&&Math.abs(st.start-(ot.start+ot.duration))<.016666666666666666;let w=l.clipId!=null?y(l.clipId):null,T=w?s.find(ot=>d(ot,w)):null;if(w&&!T){const ot=s.find(st=>d(w,st));ot&&(T=w,w=ot)}if(!w&&Number.isFinite(l.at)){const st=s.flatMap(Y=>s.filter(ct=>d(Y,ct)&&(Y.kind==="video"||Y.kind==="image")&&(ct.kind==="video"||ct.kind==="image")).map(ct=>[Y,ct])).sort((Y,ct)=>Math.abs(Y[1].start-l.at)-Math.abs(ct[1].start-l.at)||Y[0].track-ct[0].track)[0];st&&Math.abs(st[1].start-l.at)<=.25&&([T,w]=st)}if(!T||!w)throw Error(l.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(l.remove===!0||l.preset==="none"||l.booleanValue===!1){if(!T.transition?.ramp)throw Error("No speed ramp transition on that cut");s=$f(s,T.id),h.push(`speed ramp off: ${T.label||T.id} → ${w.label||w.id}`);break}const I=l.rampFx&&typeof l.rampFx=="object"?l.rampFx:{},O=ot=>l[ot]!==void 0&&l[ot]!==null&&!(ot==="align"&&!["center","end","start"].includes(l[ot]))?l[ot]:I[ot]??void 0,L=Object.fromEntries(["preset","duration","align","peak","zoomCenter","curve",...Dk].map(ot=>[ot,ot==="curve"&&l.curve===null?null:O(ot)]).filter(([,ot])=>ot!==void 0)),B=Bk(T,w,L,T.transition?.ramp?T.transition:null);s=s.map(ot=>ot.id===T.id?{...ot,transition:B,join:void 0,visualFadeOut:void 0,fadeOutColor:void 0}:ot.id===w.id?{...ot,visualFadeIn:void 0,fadeInColor:void 0}:ot),_k(s.find(ot=>ot.id===T.id),s);const H=Vk(s).plans.get(T.id),Z=[["A",H?.peakA],["B",H?.peakB]].filter(([,ot])=>ot!=null&&ot<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}${Z.length?` (not enough spare footage: peak ${Z.map(([ot,st])=>`${ot} ${st}×`).join(", ")})`:""}`);break}case"speedRamp":{const d=y(l.clipId);if(!d)throw Error("Clip not found");const w=Array.isArray(l.keys)&&l.keys.length?l.keys:null;if(!w&&l.preset==null)throw Error("speedRamp needs a preset or keys");const T=!w&&it(l.at)!==null?it(l.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 I=it(l.peak)??void 0,L=(l.fit===!0||l.booleanValue===!0)&&!w&&l.preset!=null&&l.preset!=="normal"?sm(d,l.preset,d.duration,{peak:I}):p4(d,{preset:l.preset??void 0,keys:w,hitAt:T,peak:I});s=s.map(B=>B.id===d.id?L:B),h.push(`speed ramp ${w?"keys":l.preset}${T!==void 0?" (hit placed)":""}: ${K}`);break}case"setTimeRemap":{const d=y(l.clipId);if(!d)throw Error("Clip not found");let w;if(l.booleanValue===!1)w=Ms(d,{off:!0});else{const T=Array.isArray(l.keys)&&l.keys.length?l.keys:void 0,I=it(l.duration);w=Ms(d,{preset:l.preset??void 0,keys:T,blend:l.blend??void 0,duration:I??void 0});const O=it(l.freezeAt);if(O!==null){const L=hf(w,O,it(l.hold)??1);w=Ms(w,{keys:L.keys,duration:L.duration})}}s=s.map(T=>T.id===d.id?w:T),h.push(`time remap ${l.booleanValue===!1?"off":l.preset??(l.keys?"keys":l.freezeAt!=null?"freeze":l.blend?`blend ${l.blend}`:"on")}: ${K}`);break}case"setClipProperty":case"setSpeed":case"setCrop":case"setKeyframes":{const d=y(l.clipId);if(!d)throw Error("Clip not found");const w=FM(d,l);s=s.map(T=>T.id===d.id?w:T),h.push(`${l.op}: ${K}`);break}case"colorGrade":{const d=Array.isArray(l.clipIds)?l.clipIds:l.clipId!=null?[l.clipId]:[];if(!d.length||d.length>40)throw Error("needs clipId or clipIds (1–40)");const w=st=>Array.isArray(st)?st.map(Y=>Array.isArray(Y)?{x:Y[0],y:Y[1]}:Y):st,T=st=>st&&typeof st=="object"?{x:it(st.x)??0,y:it(st.y)??0,l:it(st.l)??0}:null,I=l.nodes??l.windows,O=Array.isArray(I)?{mode:"add",custom:I}:I,L={...Object.fromEntries([...xc,"temperature","tint","shadows","highlights","sharpness"].map(st=>[st,it(l[st])])),recipe:typeof l.recipe=="string"?l.recipe:null,wheels:l.wheels&&typeof l.wheels=="object"?Object.fromEntries(["lift","gamma","gain","offset"].map(st=>[st,T(l.wheels[st])])):null,curves:l.curves&&typeof l.curves=="object"?Object.fromEntries(["master","r","g","b"].map(st=>[st,l.curves[st]?w(l.curves[st]):null])):null,mixer:l.mixer&&typeof l.mixer=="object"?l.mixer:null,lut:l.lut&&typeof l.lut=="object"&&!Array.isArray(l.lut)?l.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&&!Wg.has(L.recipe))throw Error(`recipe: ${[...Wg].join(" | ")}`);const B=[],H=new Set,Z=new Set;let ot=null;if(l.copyFrom!=null&&(ot=y(Mt(l.copyFrom)),!ot))throw Error(`copyFrom clip not found: ${String(l.copyFrom).slice(0,60)}`);for(const st of d){const Y=y(Mt(st));if(!Y)throw Error(`Clip not found: ${String(st).slice(0,60)}`);const ct=vf(Y);if(!ct&&!(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(ct&&L.windows)throw Error("an adjustment layer takes no power windows — put the windows on the clip");let mt=l.reset||ot?Object.fromEntries(Object.entries(Y).filter(([Et])=>Et!=="grade"&&!xc.includes(Et))):Y;if(ot&&ot.id!==Y.id){if(ct!==vf(ot))throw Error("copyFrom: copy between two footage clips or two adjustment layers");if(mt={...mt,...Object.fromEntries(xc.filter(Et=>ot[Et]!=null).map(Et=>[Et,ot[Et]])),...ot.grade?{grade:JSON.parse(JSON.stringify(ot.grade))}:{}},ct&&mt.grade?.secondaries)throw Error("an adjustment layer takes no power windows")}const Q=[],nt=eI({...mt,hasFace:!!Y.face,hasPerson:!!Y.colorPerson,hasDepth:!!Y.depthMap},L,{notes:Q,queue:Y.kind==="video"&&!ct});for(const Et of Q)Et.startsWith("skipped:")&&H.add(Et.slice(8));const dt=Q.filter(Et=>Et.startsWith("pending:")).map(Et=>Et.slice(8)),vt=s.findIndex(Et=>Et.id===Y.id),It={...mt,...nt};nt.grade||delete It.grade,(L.windows?.presets?.includes("depth-ai")||L.windows?.custom?.some(Et=>Et?.shape==="depth"))&&!Y.depthMap&&(Y.kind==="video"||Y.kind==="image")&&Object.assign(It,Fe(It,{kind:"depth-map",op:"colorGrade",params:{upgrade:"depth-ai"}}));let xt=It;for(const Et of dt)xt=Fe(xt,{kind:Et==="face"?"color-face":"color-person",op:"colorGrade"}),Z.add(Et);s[vt]=xt,B.push(Y.label||Y.id)}h.push(`colorGrade: ${B.join(", ").slice(0,160)}${H.size?` — skipped (needs the clip's face track / person matte, made in the open editor): ${[...H].join(", ")}`:""}${Z.size?` — pending: the ${[...Z].map(st=>st==="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(l.track))throw Error("Missing track ID");const d=["gain","pan"].includes(l.property)?l.numberValue:l.booleanValue,w={...r,[l.track]:{...r[l.track],[l.property]:d}};Rk(w),r=w,h.push(`track ${l.track}: ${l.property}`);break}case"updateText":{const d=y(l.clipId);if(!d?.title)throw Error("Clip is not an editable title");if(typeof l.templateId=="string"&&l.design==null)throw Error(`Unknown text template "${l.templateId.slice(0,64)}"`);const w=l.design!=null?{design:l.design,animation:l.animation??void 0,templateId:l.templateId,styleId:"classic"}:{},T=ri({...d.title,...w,...Object.fromEntries(["text","fontSize","color","placement","fontFamily","align","accentColor"].filter(B=>l[B]!=null).map(B=>[B,l[B]]))}),I=it(l.posX),O=it(l.posY),L=I!==null||O!==null?{...pn(d),...I!==null?{posX:Math.max(-1,Math.min(1,I))}:{},...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: ${K}${O!==null&&Math.abs(d.posY)>.45?" (posY past ±0.45: the text may leave the frame)":""}`);break}case"addTextAnimator":case"removeTextAnimator":{const d=Jt(l),w=y(d.clipId);if(!w?.title)throw Error(`${l.op} needs a text layer (clipId)`);const T=[...w.title.animators||[]],I=it(d.index)??it(d.numberValue),O=()=>{if(I===null||!Number.isInteger(I)||I<0||I>=T.length)throw Error(T.length?`index: 0–${T.length-1}`:"the text has no animators");return I};if(l.op==="removeTextAnimator")d.all===!0?T.length=0:T.splice(O(),1);else{const B=typeof d.preset=="string"&&d.preset?Kx(d.preset,w.duration):[Wx({...typeof d.name=="string"?{name:d.name}:{},properties:d.properties,selectors:d.selectors})];if(I!==null?T.splice(O(),1,...B):T.push(...B),T.length>Lf)throw Error(`at most ${Lf} animators on a text layer`)}const L=ri({...w.title,animators:T});Object.assign(w,{title:L,url:"",gcsUri:void 0}),h.push(`text animators (${T.length}): ${K}`);break}case"duplicateClip":{const d=y(l.clipId);if(!d)throw Error("Clip not found");const w=cw(s,[d],l.at,{tracks:r,insert:l.booleanValue===!0});if(!Number.isFinite(l.at)||l.at<0||w.error)throw Error(w.error||"Invalid paste time");s=w.clips,h.push(`duplicate: ${K}`);break}case"move":{const d=y(l.clipId);if(!d)throw Error(`Không thấy clip ${l.clipId}`);const w=it(l.start);w!==null&&(d.start=ut(Math.max(0,Math.min(Re-d.duration,w))));const T=it(l.track);if(T!==null){if(!Mf(d.kind,T))throw Error("Track không hợp lệ cho loại clip này");d.track=T}h.push(`move ${K} → ${d.start}s${l.track!==void 0?` (track ${Ji.includes(d.track)?"A"+(Ji.indexOf(d.track)+1):"V"+(xn(d.track)+1)})`:""}`);break}case"trim":{const d=y(l.clipId);if(!d)throw Error(`Không thấy clip ${l.clipId}`);Object.assign(d,Lk(d));const w={...d};if(qn(d)){const ot=it(l.inPoint),st=it(l.duration);if(ot!==null){const Y=ut(Math.max(0,Math.min(d.duration-1/ve,ot)));Object.assign(d,Fk(d,Y)),d.start=ut(d.start+Y),d.duration=ut(d.duration-Y)}st!==null&&(d.duration=ut(Math.max(1/ve,Math.min(Re-d.start,st)))),Object.assign(d,ac(w,ot!==null?ut(Math.max(0,Math.min(w.duration-1/ve,ot))):0,d.duration)),h.push(`trim ${K} → ${d.duration}s (time remap)`);break}if(an(d)&&!d.reverse){const ot=d.kind!=="image"?o.find(nt=>nt.id===d.nodeId)?.words:null,st=nt=>{const dt=nu(ot,nt);return Math.abs(dt-nt)<=ts.reach?dt:nt};let Y=it(l.inPoint),ct=0;if(Y!==null&&ot?.length&&(Y=st(Y)),Y!==null){const nt=Math.max(0,Math.min(Yg(d)-1/ve,Y));ct=Ja(d,nt-(d.inPoint||0)),Object.assign(d,Nk(d,ct)),d.inPoint=nt,an(d)||delete d.speedRamp}let mt=it(l.duration);mt!==null&&ot?.length&&(mt=Ja(d,st((d.inPoint||0)+ls(d,mt))-(d.inPoint||0)));const Q=Ja(d,Yg(d)-(d.inPoint||0));d.duration=ut(Math.max(1/ve,Math.min(Q,mt??d.duration))),d.start+d.duration>Re&&(d.duration=ut(Re-d.start)),Object.assign(d,ac(w,ct,d.duration)),h.push(`trim ${K} → ${d.duration}s (in ${+(d.inPoint||0).toFixed(3)}s)`);break}const T=d.playbackRate||1,I=d.sourceDuration??d.motion?.duration??Re,O=d.kind!=="image"&&!d.reverse?o.find(ot=>ot.id===d.nodeId)?.words:null,L=ot=>{const st=nu(O,ot);return Math.abs(st-ot)<=ts.reach?st:ot};let B=it(l.inPoint);B!==null&&O?.length&&(B=L(B)),B!==null&&(d.inPoint=ut(Math.max(0,Math.min(I-1/ve,B))));let H=it(l.duration);H!==null&&O?.length&&(H=(L((d.inPoint||0)+H*T)-(d.inPoint||0))/T),H!==null?d.duration=ut(Math.max(1/ve,Math.min((I-(d.inPoint||0))/T,H))):d.duration=ut(Math.max(1/ve,Math.min((I-(d.inPoint||0))/T,d.duration))),d.start+d.duration>Re&&(d.duration=ut(Re-d.start));const Z=w.reverse?w.duration-d.duration-((d.inPoint||0)-(w.inPoint||0))/T:((d.inPoint||0)-(w.inPoint||0))/T;Object.assign(d,ac(w,Z,d.duration)),h.push(`trim ${K} → ${d.duration}s (in ${d.inPoint||0}s)`);break}case"split":{const d=y(l.clipId);if(!d)throw Error(`Không thấy clip ${l.clipId}`);if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);let w=it(l.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)+ls(d,w-d.start),L=nu(T,O),B=d.start+Ja(d,L-(d.inPoint||0));Math.abs(L-O)<=ts.reach&&B>d.start+1/ve&&B<d.start+d.duration-1/ve&&(w=B)}const I=_e(d,w,zt());if(I.length===1)throw Error("Điểm cắt phải nằm trong clip");s=s.flatMap(O=>O.id===d.id?I:[O]),h.push(`split ${K} tại ${ut(w)}s`);break}case"delete":{if(!y(l.clipId))throw Error(`Không thấy clip ${l.clipId}`);s=s.filter(d=>d.id!==l.clipId),h.push(`delete ${K}`);break}case"setVolume":{const d=y(l.clipId);if(!d)throw Error(`Không thấy clip ${l.clipId}`);const w=it(l.volume);if(w===null)throw Error("Thiếu volume");d.volume=Math.max(0,Math.min(1,w)),h.push(`volume ${K} → ${Math.round(d.volume*100)}%`);break}case"addClip":{if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const d=o.find(B=>B.id===l.materialId);if(!d||!d.url)throw Error(`Không thấy material ${l.materialId}`);if(d.kind==="lottie"){const B=Ok(d.lottie),H=it(l.start)??0,Z=ut(Math.max(1/ve,it(l.duration)??Math.min(120,zk(B))));if(H<0||H+Z>Re)throw Error("Vượt giới hạn 20 phút");const{track:ot}=Kt(s,r,ut(H),ut(H)+Z,it(l.track)),st=zt();U.push(st),s.push({id:st,nodeId:d.id,track:ot,start:ut(H),duration:Z,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||""} → ${ut(H)}s`);break}const w=it(l.track)??(d.kind==="audio"?Pk:0);if(!Mf(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 I=it(l.duration)??(d.kind==="image"?dj:T);if(I===null)throw Error("Material chưa có thời lượng — hãy nêu duration cụ thể");T!==null&&(I=Math.min(I,T)),I=ut(Math.max(1/ve,I));const O=it(l.start)??s.filter(B=>B.track===w).reduce((B,H)=>Math.max(B,H.start+H.duration),0);if(O<0||O+I>Re)throw Error("Vượt giới hạn 20 phút");if(r[w]?.locked)throw Error("Track đã khóa");const L=zt();U.push(L),s.push({id:L,nodeId:d.id,track:w,start:ut(O),duration:I,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} → ${ut(O)}s`);break}case"addVfxPreset":{if(l._error)throw Error(l._error);const d=l._footage;if(!d)throw Error("addVfxPreset needs presetId (search_vfx_presets)");if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const w=ut(Math.max(0,it(l.start)??0)),T=ut(Number(d.duration));if(w+T>Re)throw Error("Vượt giới hạn 20 phút");const I=Array.isArray(l.point)&&l.point.length===2&&l.point.every(Y=>Number.isFinite(Y))?l.point.map(Y=>Math.max(0,Math.min(1,Y))):null,O={W:c.W||1280,H:c.H||720},L=it(l.scale)??1,B=(Y,ct,mt)=>fm({id:ct,track:mt,start:w,duration:T,footage:Y,frame:O,at:I,scale:L}),H=w+Math.min(T,Number(l._impact)||0),Z=s.filter(Y=>Y.kind==="video"&&!Y.vfxFootage&&!Y.vfx&&!Y.vfxPreset&&Y.start<=H&&Y.start+Y.duration>H).sort((Y,ct)=>(Y.track??0)-(ct.track??0))[0]??null;if(l._light){if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const Y=zt(),{track:ct}=Kt(s,r,w,w+T,null);U.push(Y);const{blend:mt,...Q}=B(l._light,Y,ct);s.push({...Q,blend:"light",opacity:.9,vfxPreset:{id:l._preset.id,pass:"light"}})}const{track:ot}=Kt(s,r,w,w+T,it(l.track)),st=zt();if(U.push(st),s.push({...B(d,st,ot),vfxPreset:{...l._preset}}),h.push(`addVfxPreset: ${String(d.name).slice(0,40)}${l._preset?.rendered?"":" (preview — render it with Cycles: clipoox vfx-render)"} → ${w}s${l._light?" + light pass":""}`),l._distort){if(!Z||!Vp(Z))h.push("air shock skipped: no filmed video under the hit");else if(Z.distort?.displace)h.push(`air shock skipped: ${Z.label||Z.id} already has a displacement map`);else if(s.length<Bt){const Y=zt(),{track:ct}=Kt(s,r,w,w+T,null);U.push(Y);const{blend:mt,...Q}=B(l._distort,Y,ct);s.push({...Q,opacity:0,vfxPreset:{id:l._preset.id,pass:"distort"}});const nt=O.W/O.H,dt=l._distort.width/l._distort.height,vt=(dt>=nt?1:dt/nt)*Q.scale,It=(dt>=nt?nt/dt:1)*Q.scale,xt=.5+Q.posX,Et=.5+Q.posY,Ct=re=>Math.round(re*1e4)/1e4,Gt=Math.round(.025*O.W),ee=s.findIndex(re=>re.id===Z.id);s[ee]={...Z,distort:{...Z.distort??{},displace:{map:Y,x:Gt,y:Gt,channel:"rg",rect:[Ct(xt-vt/2),Ct(Et-It/2),Ct(xt+vt/2),Ct(Et+It/2)]}}},h.push(`air shock → ${Z.label||Z.id}`)}}break}case"addVfxFootage":{const d=l.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>=Bt)throw Error(`Tối đa ${Bt} clip`);const w=ut(Math.max(0,it(l.start)??0)),T=ut(Math.max(1/ve,Math.min(it(l.duration)??Number(d.duration),Number(d.duration))));if(w+T>Re)throw Error("Vượt giới hạn 20 phút");const I=Array.isArray(l.point)&&l.point.length===2&&l.point.every(B=>Number.isFinite(B))?l.point.map(B=>Math.max(0,Math.min(1,B))):null,{track:O}=Kt(s,r,w,w+T,it(l.track)),L=zt();U.push(L),s.push(fm({id:L,track:O,start:w,duration:T,footage:d,frame:{W:c.W||1280,H:c.H||720},at:I,scale:it(l.scale)??1,sound:l.booleanValue===!0})),h.push(`addVfxFootage: ${String(d.name||"VFX").slice(0,40)} → ${w}s`);break}case"vfxFootageFollow":{const d=y(l.clipId);if(!d||!d.vfxFootage)throw Error("vfxFootageFollow needs clipId = a Footage VFX layer (addVfxFootage)");if(l.booleanValue===!1){const O=Math.max(0,Math.min(d.duration,it(l.time)??0));for(const[L,B]of Object.entries(Hv(d,O)))B===void 0?delete d[L]:d[L]=B;h.push(`vfxFootageFollow ${K}: stopped`);break}const w=l.sourceClipId?y(l.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 l.point=="string"?l.point:typeof l.handPoint=="string"?l.handPoint:"palm",I=Wv(d,w,{source:l.source,hand:l.hand==="left"?"left":"right",point:T,...l.object!=null?{object:l.object}:{},scale:l.scale===!0||l.followScale===!0,offset:Array.isArray(l.offset)&&l.offset.length>=2?l.offset:null,W:n.W||1280,H:n.H||720});for(const[O,L]of Object.entries(I.patch))L===void 0?delete d[O]:d[O]=L;h.push(`vfxFootageFollow ${K}: follows the ${l.source}${l.source==="hand"?` (${l.hand==="left"?"left":"right"} ${T})`:""} of ${w.label||w.id} — ${I.keys} keys ${I.from}–${I.to}s`);break}case"addVfxLayer":{let d=y(l.clipId);if(!d||d.kind!=="video"||d.vfx)throw Error("VFX needs the filmed video clip");if(d.person){const H=d,Z=s.find(ot=>ot.id!==H.id&&ot.kind==="video"&&!ot.person&&!ot.vfx&&ot.url===H.url&&ot.start===H.start&&ot.duration===H.duration);Z&&(d=Z)}if(!xf.includes(l.layer))throw Error(`VFX layer must be ${xf.join(" / ")}`);const w=o.find(H=>H.id===l.materialId);if(!w||!w.url||w.kind!=="video")throw Error(`Không thấy video ${l.materialId}`);const T=it(w.duration),I=ut(Math.max(1/ve,Math.min(d.duration,T??d.duration))),O=Ak(s,d.id,l.layer);if(O){Ck(O,w,{duration:I,blend:l.blend}),U.push(O.id),h.push(`addVfxLayer: ${l.layer} pass of ${K} replaced`);break}if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const L=jk(s,r,d,l.layer,d.start,d.start+I),B=zt();U.push(B),s.push(Tk({id:B,material:w,src:d,layer:l.layer,track:L,start:d.start,duration:I,blend:l.blend})),h.push(`addVfxLayer: ${l.layer} pass over ${K}`),l.layer==="behind"&&rt.splice(D+1,0,{op:"placeBehindPerson",clipId:B,sourceClipId:d.id});break}case"finishVfx":{const d=Sk(s,y(l.clipId));if(!d||d.kind!=="video"||d.vfx)throw Error("VFX needs the filmed video clip");const w=Ik(s,d,{strength:it(l.numberValue)??1,off:l.booleanValue===!1,newId:zt,tracks:r,maxClips:Bt});s=w.clips,U.push(...w.added),h.push(`finishVfx ${K}: ${w.notes.join(", ")}`);break}case"set3DLayer":case"setLayerOrder":case"setPropertyKeys":case"setEase":case"setAnimation":case"setReveal":case"setShapeStyle":{const d=s.findIndex(I=>I.id===l.clipId);if(d<0)throw Error("Clip not found");const w=s[d],T=[];s[d]=l.op==="set3DLayer"?xk(w,l.booleanValue!==!1,l.numberValue):l.op==="setLayerOrder"?Mk(w,l.numberValue):l.op==="setPropertyKeys"?ca(w,l.property,Array.isArray(l.propertyKeys)?vk(w,l.propertyKeys,T):l.propertyKeys):l.op==="setEase"?$k(w,l.property,l.ease,l.times):l.op==="setReveal"?bf(w,l.preset,{start:it(l.at),duration:it(l.duration),ease:l.ease}):l.op==="setShapeStyle"?Ek(w,{color:l.color,fill:l.fill,strokeWidth:it(l.numberValue)}):Oc(w,l.property,l.preset,{duration:l.duration??(l.property==="exit"?p.out:p.in),amount:l.numberValue,fade:l.booleanValue,ease:l.ease??(n.motion?p.ease:void 0)}),h.push(`${l.op}${l.property?` ${l.property}`:""}: ${K}${T.length?` (${T.join("; ")})`:""}`);break}case"addPins":{const d=hj(o,s,l.materialId);if(!d)throw Error("Pins need the A-roll material");const w=Array.isArray(d.words)?d.words.length:Ws(d)||1/0,T=(Array.isArray(l.pins)?l.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 I=N??n?.pins??[],O=I.filter(L=>!T.some(B=>B.mediaId===L.mediaId&&B.from<=L.to&&B.to>=L.from));N=y$([...O,...T]),h.push(`pins: +${T.length}`);break}case"setTrackMatte":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");if(!l.sourceClipId){delete d.matte,h.push(`setTrackMatte off: ${K}`);break}const w=y(l.sourceClipId);if(!w)throw Error("Matte source not found");const T=Number.isFinite(l.numberValue)?qx(l.numberValue):d.matte?.feather,I=Zx.includes(l.matteMode)?l.matteMode:"alpha";d.matte={source:w.id,mode:I,...T?{feather:T}:{},...I==="depth"?{depth:d.matte?.depth??.5}:{}},Nf(s),h.push(`setTrackMatte: ${K}`);break}case"modelMove":{const d=s.findIndex(T=>T.id===l.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(!Lm.includes(l.preset))throw Error(`Unknown 3D move (${Lm.join(", ")})`);s[d]=l$(w.kind==="model"||w.is3D?w:{...w,is3D:!0},l.preset,{at:it(l.at)??0,duration:it(l.duration),amount:it(l.numberValue)??1}),h.push(`modelMove ${l.preset}: ${K}`);break}case"setModelAnimation":{const d=y(l.clipId);if(!d||d.kind!=="model")throw Error("GLB animations need a 3D model clip");const w=typeof l.text=="string"?l.text.trim():"";if(!w||w==="none"){delete d.modelAnim,h.push(`model animation off: ${K}`);break}const T={clip:w,...it(l.numberValue)!==null?{speed:it(l.numberValue)}:{},...typeof l.booleanValue=="boolean"?{loop:l.booleanValue}:{},...it(l.at)!==null?{offset:Math.max(0,it(l.at))}:{}};kk(T),d.modelAnim=T,h.push(`model animation ${w}: ${K}`);break}case"modelBuild":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="model")throw Error("modelBuild needs a 3D model clip (a GLB layer)");if(l.booleanValue===!1||l.style==="none"){delete d.modelBuild,h.push(`model build off: ${K}`);break}const w=Math.max(0,Math.min(d.duration,(it(l.at)??d.start)-d.start));d.modelBuild=wk({style:l.style,order:l.order,at:w,duration:it(l.duration)??void 0,stagger:it(l.stagger)??void 0,dust:l.dust,dustColor:l.dustColor??l.color,seed:Number.isInteger(l.seed)?l.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: ${K}`);break}case"modelLook":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="model")throw Error("modelLook needs a 3D model clip (a GLB layer)");const w=bk(d.modelLook,l);if(!w){delete d.modelLook,h.push(`model look off: ${K}`);break}d.modelLook=w,h.push(`model look ${w.preset??"custom"}${w.shadow!==void 0?` shadow ${w.shadow}`:""}: ${K}`);break}case"modelLaunch":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="model")throw Error("modelLaunch needs a 3D model clip (a GLB layer)");const w=gk(d,l);if(!w){delete d.modelLaunch,h.push(`model launch off: ${K}`);break}d.modelLaunch=w,h.push(`model launch ${w.land} at ${(d.start+w.at).toFixed(2)} s, lands at ${(d.start+yk(w)).toFixed(2)} s on [${w.to.map(T=>T.toFixed(2)).join(", ")}] (height ${w.height}): ${K}`);break}case"modelPlace":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="model")throw Error("modelPlace needs a 3D model clip (a GLB layer)");const w={x:it(l.x)??void 0,y:it(l.y)??void 0,lift:it(l.lift)??void 0,scale:it(l.scale)??void 0,yaw:it(l.yaw)??void 0,tilt:it(l.tilt)??void 0,roll:it(l.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(l.at)??d.start)-d.start)),I=u$(d,w,T,l.key===!0);Object.assign(d,I),h.push(`model placed${l.key===!0||I.motionKeys?` (key at ${(d.start+T).toFixed(2)} s)`:""}: ${K}`);break}case"trackCamera3D":{l=Jt(l);const d=y(l.clipId),w=Dx(l,d);Object.assign(d,Fe(d,{kind:"camera-track",op:"trackCamera3D",params:w})),h.push(`trackCamera3D ${K}: the camera is solved in the open editor${w.lens?` (lens ${w.lens} mm)`:""}`);break}case"placeOnTrack":{l=Jt(l);const d=y(l.clipId),w=Rx(l,d,y(l.sourceClipId));Object.assign(d,Fe(d,{kind:"camera-place",op:"placeOnTrack",params:w})),d.kind==="model"&&!d.modelLook&&(d.modelLook={preset:"overcast"}),h.push(`placeOnTrack ${K}: placed on the 3D camera track of ${y(l.sourceClipId).label||l.sourceClipId} in the open editor${d.kind==="model"?" (modelLook overcast: shadow on the ground)":""}`);break}case"trackObject3D":{l=Jt(l);const d=y(l.clipId),w=Nv(l,d);Object.assign(d,Fe(d,{kind:"object-track",op:"trackObject3D",params:w})),h.push(`trackObject3D ${K}: the object is tracked in 3D in the open editor`);break}case"placeOnObject":{l=Jt(l);const d=y(l.clipId),w=Rv(l,d,y(l.sourceClipId));Object.assign(d,Fe(d,{kind:"object-place",op:"placeOnObject",params:w})),h.push(`placeOnObject ${K}: glued to the tracked object of ${y(l.sourceClipId).label||l.sourceClipId} in the open editor`);break}case"segmentPerson":{const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("segmentPerson needs a video clip");if(l.quality!==void 0&&l.quality!=="free"&&l.quality!=="hq")throw Error("segmentPerson quality: free | hq");if(l.quality==="hq"){if(typeof l.job!="string"||!/^[A-Za-z0-9-]{8,64}$/.test(l.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: ${K} already has an HQ person matte`);break}C(d,null),d.personPending={behind:d.personPending.behind,job:l.job},h.push(`segmentPerson: ${K} (HQ person matte, made on the server)`);break}if(d.person&&d.person.src!=="object"){h.push(`segmentPerson: ${K} already has an AI person matte`);break}if(n.noPendingMatte)throw Error(`"${K}" has no AI person matte yet — open Roto → Tách người bằng AI on it`);C(d,null),h.push(`segmentPerson: ${K} (AI person matte computed in the editor)`);break}case"samCutout":{const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("samCutout needs a video clip");if(typeof l.job!="string"||!/^[A-Za-z0-9-]{8,64}$/.test(l.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=mk(l.prompts);if(d.samPending&&d.samPending.job!==l.job)throw Error(`"${K}" is already being cut out by AI Pro — wait for it (get_pending_jobs)`);d.samPending={job:l.job,prompts:w.map(T=>({id:T.id,name:wf(T.name)}))},h.push(`samCutout: ${K} (${w.length} AI Pro cut-out${w.length>1?"s":""}, made on the server)`);break}case"placeBehindPerson":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");let w=y(l.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 Q=w,nt=s.find(dt=>dt.id!==Q.id&&dt.kind==="video"&&dt.person&&dt.person.src!=="object"&&dt.url===Q.url);nt&&(w={...Q,person:nt.person})}if(ra(d,w)<0){h.push(`placeBehindPerson: ${K} already behind`);break}if(!w.person){if(n.noPendingMatte||!t.some(Q=>Q.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`);C(w,d.id),U.push(`${w.id}-person-pending`),h.push(`placeBehindPerson: ${K} (waits for the AI person matte of ${w.label||w.id})`);break}const I=xl(d,w,{index:xn,at:en,isFree:Q=>!r[Q]?.locked&&!s.some(nt=>nt.track===Q&&nt.start<w.start+w.duration&&nt.start+nt.duration>w.start)});if(I===null)throw Error("No free track above the person");let O=`${w.id}-person`,L=2;for(;y(O);)O=`${w.id}-person-${L++}`;const B=yf(s,w,{id:O,track:I,label:`${w.label||"Video"} · ${w.person.src==="object"?"vật thể":"người"}`,target:d}),H=!w.motionKeys?.length&&!w.speedRamp&&!w.timeRemap&&!w.reverse&&!(w.playbackRate&&w.playbackRate!==1);let Z=Math.max(w.start,d.start),ot=Math.min(w.start+w.duration,d.start+d.duration);const st=B.clips.find(Q=>Q.id===O),Y=w.start+w.duration,ct=Z,mt=ot;for(const Q of B.clips)Q.id!==O&&Q.id!==w.id&&Q.kind!=="audio"&&!Q.person&&Q.start<mt&&Q.start+Q.duration>ct&&ra(Q,st)<0&&ra(Q,w)>0&&(Z=Math.min(Z,Math.max(w.start,Q.start)),ot=Math.max(ot,Math.min(Y,Q.start+Q.duration)));if(H&&ot-Z>1/30&&(Z>w.start+1e-6||ot<w.start+w.duration-1e-6)){const Q=B.clips.find(nt=>nt.id===O);Q.inPoint=+((w.inPoint||0)+(Z-w.start)).toFixed(4),Q.start=+Z.toFixed(4),Q.duration=+(ot-Z).toFixed(4)}Ml(B.clips),s=B.clips,U.push(O),h.push(`placeBehindPerson: ${K}`);break}case"placeBehindObject":case"cutOutObject":{const d=l.op==="placeBehindObject",w=d?y(l.clipId):null,T=l.op;if(d&&(!w||w.kind==="audio"))throw Error("Clip not found");let I=y(d?l.sourceClipId:l.clipId);if(!I||I.kind!=="video")throw Error("Object video not found");if(w&&I.id===w.id)throw Error("A layer cannot go behind its own video");const O=uj(l.points),L=wf(l.objectName??l.name);let B=typeof l.objectId=="string"?l.objectId.trim().slice(0,120):"";if(d&&I.person?.src==="object"&&!I.person.obj&&!L&&!B){if(ra(w,I)<0){h.push(`placeBehindObject: ${K} already behind`);break}rt.splice(D+1,0,{op:"placeBehindPerson",clipId:w.id,sourceClipId:I.id}),h.push(`placeBehindObject: ${K}`);break}Kp(I)&&!B&&!L&&(B=Wp(I).id);const H=O?Xg(I,it(l.at)??(w??I).start):void 0,Z=pk(s,I,{id:B||void 0,name:L||void 0,...O&&!L&&!B?{pts:O,at:H}:{}});if(B&&!Z)throw Error(`No object "${B}" on ${I.label||I.id}`);let ot;if(Z?.layer){const Y=Z.layer,ct=Wp(Y);if(d){if(ra(w,Y)<0){h.push(`placeBehindObject: ${K} already behind "${ct.name}"`);break}P(Y,w,I),h.push(`placeBehindObject: ${K} behind "${ct.name}"`);break}if(!O||kf(O,uk(Y).obj?.pts)){U.push(Y.id),h.push(`cutOutObject: "${ct.name}" is already its own layer`);break}ot={...ct,pts:O,at:H,layer:Y.id}}else if(Z?.pending)ot=Z.pending,I=Z.clip,!d&&O&&!kf(O,ot.pts)&&(ot={...ot,pts:O,at:H});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(n.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:I.id,name:L,at:Xg(I,it(l.at)??w.start)}),h.push(`placeBehindObject: ${K} (finds "${L}" after Accept)`);break}if(Kp(I)){const Y=s.find(ct=>ct.id!==I.id&&ct.kind==="video"&&ct.url===I.url&&!ct.person&&!ct.mask);Y&&(I=Y)}ot={id:fk(s,I),name:L||dk(hk(s,I)+1),pts:O,at:H}}const st=j(I,ot,w);if(st){ot.layer||U.push(st.id),d&&ra(w,st)>=0&&P(st,w,I),h.push(d?`placeBehindObject: ${K} behind "${ot.name}"`:ot.layer?`cutOutObject: "${ot.name}" re-picked`:`cutOutObject: "${ot.name}" of ${I.label||I.id}`);break}if(n.noPendingMatte||!t.some(Y=>Y.id===I.id))throw Error(`"${I.label||I.id}" has no AI matte for the object "${ot.name}" yet — open Roto → Tách vật thể bằng AI on it`);z(I,ot,w?.id??null),U.push(`${I.id}-${ot.id}-pending`),h.push(d?`placeBehindObject: ${K} (waits for the AI matte of "${ot.name}" in ${I.label||I.id})`:`${T}: "${ot.name}" of ${I.label||I.id} (AI object matte computed in the editor)`);break}case"placeBehindDepth":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");let w=y(l.sourceClipId);if(!w||w.kind==="audio")throw Error("Depth map or footage not found");if(l.materialId){const O=o.find(Z=>Z.id===l.materialId);if(!O||!O.url||!["video","image"].includes(O.kind))throw Error(`Không thấy bản đồ độ sâu ${l.materialId}`);const L=w,B=d.matte?.source&&y(d.matte.source),H=B&&B.nodeId===O.id&&B.start===L.start?B:null;if(H)w=H;else{if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const Z=Kt(s,r,L.start,L.start+L.duration,null).track,ot=zt();U.push(ot);const st=["inPoint","playbackRate","speedRamp","posX","posY","scale","scaleX","scaleY","rotation","flipX","flipY","crop","motionKeys","reverse","fit"];w={id:ot,nodeId:O.id,track:Z,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(st.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(l.numberValue)??d.matte?.depth??.5)),I=d.matte?.source===w.id?d.matte.feather:void 0;d.matte={source:w.id,mode:"depth",depth:+T.toFixed(3),...I?{feather:I}:{}},Nf(s),h.push(`placeBehindDepth: ${K} at depth ${Math.round(T*100)}%`);break}case"collageStyle":{const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("Collage style needs a visual clip");if(l.back&&(d.zIndex=-100),l.sticker!=null)if(l.sticker==="none")delete d.sticker;else{const w=U6[l.sticker];if(!w)throw Error("Unknown sticker edge");d.sticker=structuredClone(w)}if(l.torn!=null){const w=l.torn==="all"?ap:[l.torn];if(!w.every(L=>ap.includes(L)))throw Error("Unknown torn side");const T=o.find(L=>L.id===d.nodeId),I=Number.isInteger(T?.width)&&T.width>1?T.width:1600,O=Number.isInteger(T?.height)&&T.height>1?T.height:1e3;d.mask=jS(d.mask,{mw:I,mh:O,crop:d.crop,sides:w,seed:Number.isInteger(l.seed)?l.seed:1})}if(l.watercolor){const w=bf(d,"watercolor",{start:0,duration:Math.min(1.2,d.duration/2)});Object.assign(d,w)}if(l.cutout!=null){if(!["person","object"].includes(l.cutout)||d.kind!=="image"||!d.url)throw Error("Background removal needs a photo and person / object");E.push({clipId:d.id,mode:l.cutout})}h.push(`collage ${K}`);break}case"rotoMask":{const d=y(l.clipId);if(!d)throw Error("rotoMask needs clipId (a video / image clip)");const{mask:w,follow:T}=aj(d,l,{size:nj(d,o.find(B=>B.id===d.nodeId))});w?d.mask=w:delete d.mask;const I=new Set(Jg(w)),L=[...((d.clientJobs??[]).find(B=>B?.kind==="mask-track"&&(B.state==="pending"||B.state==="running"))?.params?.masks??[]).filter(B=>I.has(B.id)&&!T.some(H=>H.id===B.id)),...T];L.length?Object.assign(d,Fe(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 ${K}: ${Jg(w).length} mask(s)${T.length?`, ${T.length} to track in the editor`:""}`);break}case"runAnalyzer":{const d=y(l.clipId);if(!d)throw Error("Clip not found");if(d.kind!=="video")throw Error("runAnalyzer needs a video clip");const w=l.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=l.values&&typeof l.values=="object"&&!Array.isArray(l.values)?l.values:{};if(JSON.stringify(T).length>4096)throw Error("runAnalyzer: values too large");Object.assign(d,Fe(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}`:""}: ${K} (in the open editor)`);break}case"bakeMap":{const d=y(l.clipId);if(!d)throw Error("Clip not found");if(!d.geo)throw Error("bakeMap needs an animated map layer (addMap)");Object.assign(d,Fe(d,{kind:"map-bake",op:"bakeMap"})),h.push(`bakeMap: ${K} → video (in the open editor)`);break}case"portalDive":{const d=y(l.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 H=s4(s,d.id);s.splice(0,s.length,...H)}const I=y(l.clipId),O=w?I.pendingPin:I.pin;if(l.booleanValue===!1){h.push(`portalDive off: ${K}`);break}const L=ck(I,y(O.clip??O.source),{at:it(l.at)??null,dur:it(l.duration)??1.2}),B=i4(L);if(w?I.pendingPin={...I.pendingPin,dive:B}:I.pin={...I.pin,dive:B},!w&&n.W&&n.H){const H=oy(s,I.id,n.W,n.H);s.splice(0,s.length,...H)}h.push(`portalDive: the camera pushes into ${K} from ${L.at.toFixed(2)}s, the screen fills the frame at ${(L.at+L.dur).toFixed(2)}s`);break}case"pinToSurface":{const d=y(l.clipId),w=y(l.sourceClipId),T=wl(d,w,l);delete d.pin,Object.assign(d,T),S.push({clipId:d.id,...T.pendingPin});let I="";if(w.person&&l.booleanValue!==!1&&ra(d,w)>=0){const L=xl(d,w,{index:xn,at:en,isFree:B=>!r[B]?.locked&&!s.some(H=>H.track===B&&H.start<w.start+w.duration&&H.start+H.duration>w.start)});if(L!==null){let B=`${w.id}-person`,H=2;for(;y(B);)B=`${w.id}-person-${H++}`;const Z=yf(s,w,{id:B,track:L,label:`${w.label||"Video"} · người`,target:d});Ml(Z.clips),s=Z.clips,U.push(B),I=", person in front"}}h.push(`pinToSurface ${K} → ${w.label||w.id} (${T.pendingPin.mode}${I})`);break}case"addFlash":{const d=Array.isArray(l.times)&&l.times.length?l.times.map(it):[it(l.at)];if(!d.length||d.length>Km||d.some(L=>L===null||L<0||L>Re))throw Error(`addFlash: at (timeline s) or times [≤${Km} instants]`);const w=l.flashStyle??l.style??"white";if(!Object.hasOwn(_n,w))throw Error(`addFlash style: ${Object.keys(_n).join("|")}`);const T=Ld(w,it(l.strength)??it(l.numberValue)??1),I=ut(Pd(w)),O=_n[w][n.locale==="en"?"en":"vi"];for(const L of d){if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const B=ut(L),{track:H}=Kt(s,r,B,B+I,it(l.track)),Z=zt();U.push(Z),s.push({...ic({id:Z,track:H,start:B,duration:I,label:`${n.locale==="en"?"Flash":"Chớp"} · ${O}`}),motionKeys:[],effects:T.map(ot=>({...ot,keys:ot.keys.map(st=>({...st}))}))})}h.push(`flash ${w} ×${d.length} (${d.map(L=>ut(L)).join(", ")}s)`);break}case"setEffect":{const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("Effects need a 2D visual clip");if(!Object.hasOwn(Ac,l.property))throw Error("Unknown effect");const w=it(l.numberValue);if(w===null||w<0||w>1)throw Error("Effect amount must be 0..1");let T=null;if(l.property==="glow-pro"){const B=l.glow??(typeof l.prompt=="string"&&l.prompt.trim().startsWith("{")?(()=>{try{return JSON.parse(l.prompt)}catch{throw Error("Glow Pro settings (prompt) must be JSON")}})():void 0),H=(d.effects||[]).find(Z=>Z.type==="glow-pro")?.params;B!==void 0?T=lk({...H||{},...B}):H&&(T=H)}const I={type:l.property,amount:w,...T?{params:T}:{}},O=(d.effects||[]).filter(B=>B.type!==l.property),L=(d.effects||[]).findIndex(B=>B.type===l.property);if(w>0&&(L>=0?O.splice(L,0,I):O.push(I)),O.length>yn)throw Error(`At most ${yn} effects per clip`);O.length?d.effects=O:delete d.effects,h.push(`effect ${l.property} ${w?Math.round(w*100)+"%":"off"}: ${K}`);break}case"personEcho":case"clonePerson":{l=Jt(l);let d=y(l.clipId);if(!d||d.kind!=="video")throw Error(`${l.op} needs the filmed video clip of the person`);if(!d.person){const L=d,B=s.find(H=>H.id!==L.id&&H.kind==="video"&&H.person&&H.person.src!=="object"&&H.url===L.url);B&&(d={...L,person:B.person})}if(!d.person){if(n.noPendingMatte||!t.some(H=>H.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}=l;C(d,null,{...B,clipId:d.id}),h.push(`${l.op} ${d.label||d.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=[],T=()=>{let L=zt();for(;y(L);)L=zt();return w.push(L),L},I=l.op==="personEcho"?{layers:Xv(d,{copies:kt(l.copies)??kt(l.numberValue),gap:kt(l.gap),fade:kt(l.fade),opacity:kt(l.opacity),spread:kt(l.spread),look:typeof l.look=="string"&&l.look?l.look:null,start:kt(l.start),duration:kt(l.duration)},T),poofs:[]}:Yv(d,{count:kt(l.count)??kt(l.numberValue),layout:l.layout,spread:kt(l.spread),depth:kt(l.depth),delay:kt(l.delay),mirror:l.mirror!==!1,feet:Array.isArray(l.feet)?l.feet:void 0,horizon:kt(l.horizon),start:kt(l.start),duration:kt(l.duration),smoke:l.smoke!==!1},T);if(s.length+I.layers.length+I.poofs.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const L of[...I.layers,...I.poofs]){const{track:B}=Kt(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(l.op==="personEcho"?`personEcho ${d.label||d.id}: ${I.layers.length-1} copies + the person on top`:`clonePerson ${d.label||d.id}: ${I.layers.length-1} clones${I.poofs.length?` (${I.poofs.length} smoke poofs)`:""} + the person in front`);break}case"addShock":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind==="audio")throw Error("addShock needs a visual clip");if(l.booleanValue===!1){delete d.shocks,h.push(`addShock ${K}: rings removed`);break}const w=kt(l.at)??d.start,T=Array.isArray(l.point)?l.point:[kt(l.u)??.5,kt(l.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)>=gf.max)throw Error(`A clip holds up to ${gf.max} shockwaves`);const I=ik({t:w-d.start,u:kt(T[0])??.5,v:kt(T[1])??.8,radius:kt(l.radius),strength:kt(l.strength),duration:kt(l.duration),squash:kt(l.squash),light:kt(l.light)});if(d.shocks=sk([...d.shocks??[],I].sort((O,L)=>O.t-L.t),d.duration),l.cracks===!0){let O=zt();for(;y(O);)O=zt();const L=n.W||1280,B=n.H||720,H=d.scale??1,Z=.5+(d.posX??0)+(I.u-.5)*H,ot=.5+(d.posY??0)+(I.v-.5)*H,st=n$({id:O,at:w,duration:Math.min(Math.max(1.2,I.duration*1.8),d.start+d.duration-w+.5),u:Z,v:ot,size:I.radius*.65*H,squash:I.squash,seed:Math.round(w*1e3)%9973+1,W:L,H:B}),{track:Y}=Kt(s,r,st.start,st.start+st.duration);s.push({...st,track:Y}),U.push(O)}h.push(`addShock ${K}: ring at ${(+w).toFixed(2)} s${l.cracks===!0?" + ground cracks":""}`);break}case"smoothSlowMo":{const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("smoothSlowMo needs a video clip");if(l.booleanValue===!1){delete d.smoothSlow,h.push(`smoothSlowMo ${K}: off`);break}d.smoothSlow=!0,h.push(`smoothSlowMo ${K}: on${Ly(d)?"":" (slow it below 1× with setSpeed / speedRamp to see it)"}`);break}case"objectTrail":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("objectTrail needs a video clip");const w=Array.isArray(l.path)&&l.path.length>=2&&l.path.every(Z=>Array.isArray(Z)&&(Z.length===3||Z.length===4)&&Z.every(Number.isFinite)&&Z[1]>=-.2&&Z[1]<=1.2&&Z[2]>=-.2&&Z[2]<=1.2)?[...l.path].sort((Z,ot)=>Z[0]-ot[0]):null;if(l.path!==void 0&&l.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(l.point)?l.point:null;if(!T||!T.every(Z=>Number.isFinite(Z)&&Z>=0&&Z<=1))throw Error("objectTrail point [u, v] (0..1 of the picture)");const I=kt(l.at)??(w?w[0][0]:d.start),O=Math.min(kt(l.duration)??(w?w.at(-1)[0]-I+(kt(l.length)??.45):d.start+d.duration-I),d.start+d.duration-I);if(!(O>=.2)||I<d.start-1e-6)throw Error("objectTrail must lie inside the footage");let L=zt();for(;y(L);)L=zt();const B=Fx({id:L,at:I,duration:O,color:l.color,width:kt(l.width),length:kt(l.length),source:d.id,point:T,style:l.style==="energy"||l.style==="ribbon"||l.style==="wheel"?l.style:void 0,aspect:kt(l.ringAspect),rot:kt(l.ringRot),wind:Array.isArray(l.wind)?l.wind:void 0,stretch:kt(l.stretch),taper:kt(l.taper),vanish:Array.isArray(l.vanish)?l.vanish:void 0,flow:kt(l.flow),ring:kt(l.ring),spread:kt(l.spread)}),{track:H}=Kt(s,r,B.start,B.start+B.duration);if(w){const Z=n.W||1280,ot=n.H||720,st=(nt,dt,vt,It,xt)=>.5*(2*dt+(vt-nt)*xt+(2*nt-5*dt+4*vt-It)*xt*xt+(3*dt-nt-3*vt+It)*xt*xt*xt),Y=nt=>w[Math.max(0,Math.min(w.length-1,nt))],ct=[];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 dt=0;for(;dt<w.length-2&&w[dt+1][0]<nt;)dt++;const vt=Math.min(1,Math.max(0,(nt-Y(dt)[0])/(Y(dt+1)[0]-Y(dt)[0]||1)));ct.push([+(nt-B.start).toFixed(4),st(Y(dt-1)[1],Y(dt)[1],Y(dt+1)[1],Y(dt+2)[1],vt)*Z,st(Y(dt-1)[2],Y(dt)[2],Y(dt+1)[2],Y(dt+2)[2],vt)*ot,...w.every(It=>It.length===4)?[(Y(dt)[3]+(Y(dt+1)[3]-Y(dt)[3])*vt)*ot]:[]])}const{pendingPin:mt,...Q}=B;if(s.push({...Q,track:H,...Nx({...Q,track:H},ct,Z,ot),pendingPin:void 0}),U.push(L),l.split===!0&&l.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 dt=zt();for(;y(dt);)dt=zt();const vt=Kt(s,r,nt.start,nt.start+nt.duration).track;s.push({...nt,id:dt,track:Math.max(vt,nt.track+2),label:"Bánh xe năng lượng · lốp",motion:{...nt.motion,params:{...nt.motion.params,part:"front"}}}),U.push(dt)}h.push(`objectTrail on ${d.label||d.id}: drawn along the given path (${w.length} points)`);break}s.push({...B,track:H}),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":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("addImpact needs a visual clip");if(l.booleanValue===!1){delete d.impacts,h.push(`addImpact ${K}: hits removed`);break}const w=kt(l.at)??d.start,T=Array.isArray(l.point)?l.point:[kt(l.u)??.5,kt(l.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)>=cc.max)throw Error(`A clip holds up to ${cc.max} impact hits`);const I=ff({t:w-d.start,u:kt(T[0])??.5,v:kt(T[1])??.5,strength:kt(l.strength),duration:kt(l.duration),blur:kt(l.blur),rgb:kt(l.rgb),flash:kt(l.flash)});d.impacts=mf([...d.impacts??[],I].sort((nt,dt)=>nt.t-dt.t),d.duration);const O=ed(d,"rot")||Math.abs(d.rotation??0)>1e-6,L=n.W||1280,B=n.H||720,H=O?Ic(d,I.u,I.v,w-d.start,L,B,L,B):null,Z=d.scale??1,ot=H?H.px/L:.5+(d.posX??0)+(I.u-.5)*Z,st=H?H.py/B:.5+(d.posY??0)+(I.v-.5)*Z,Y=[];let ct=()=>{let nt=zt();for(;y(nt)||Y.some(dt=>dt.id===nt);)nt=zt();return nt};l.debris!==!1&&Y.push(Zv({id:ct(),at:w,u:ot,v:st,size:.6+.6*(kt(l.strength)??.8),seed:Math.round(w*1e3)%9973+1})),l.pillars===!0&&Y.push(_$({id:ct(),at:w,u:ot,v:st,size:.7+.5*(kt(l.strength)??.8),color:/^#[0-9a-fA-F]{6}$/.test(l.color??"")?l.color:void 0}));const mt=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 Q=null;if(l.keepPerson!==!1&&mt&&d.kind==="video"){const nt=Math.min(d.start+d.duration,w+I.duration+.05);Q=Jn({...d,person:mt},ct(),{start:Xe(w),duration:Xe(nt-w),inPoint:Xe((d.inPoint||0)+(w-d.start)*(d.playbackRate||1)),label:`${d.label||"Video"} · người nét`}),delete Q.impacts,delete Q.motionKeys,H&&Object.assign(Q,Gy(d,w,nt-w)),Y.push(Q)}if(l.shake!==!1){const nt=Math.max(.15,Math.min(1,.35+.5*(kt(l.strength)??.8))),dt=w-d.start,vt=Math.min(d.duration,dt+.35),It=Math.round(w*1e3)+d.id.length;Object.assign(d,fi(d,{amount:nt,freq:14,from:dt,to:vt,seed:It,props:["x","y"]})),Q&&Object.assign(Q,fi(Q,{amount:nt,freq:14,from:0,to:vt-dt,seed:It,props:["x","y"]}))}if(s.length+Y.length>Bt)throw Error(`Tối đa ${Bt} clip`);if(H){const nt=Math.round(Qt(d,"rot",w-d.start)*100)/100;for(const dt of Y)dt.motion&&(dt.rotation=nt)}for(const nt of Y){const{track:dt}=Kt(s,r,nt.start,nt.start+nt.duration);s.push({...nt,track:dt}),U.push(nt.id)}h.push(`addImpact ${K}: hit at ${(+w).toFixed(2)} s${l.debris!==!1?" + debris":""}${l.pillars===!0?" + a pillar of light":""}${Q?" + the person sharp on top":""}`);break}case"speedBolt":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("speedBolt needs a video clip");const w=Array.isArray(l.point)?l.point:null;if(w&&!w.every(Z=>Number.isFinite(Z)&&Z>=0&&Z<=1))throw Error("speedBolt point [u, v] (0..1 of the picture)");const T=kt(l.at)??d.start,I=Math.min(kt(l.duration)??d.start+d.duration-T,d.start+d.duration-T);if(!(I>=.2)||T<d.start-1e-6)throw Error("speedBolt must lie inside the footage");if(!w&&d.personPending&&!(d.person&&d.person.src!=="object")&&!n.noPendingMatte&&t.some(Z=>Z.id===d.id)&&!s.some(Z=>Z.id!==d.id&&Z.kind==="video"&&Z.person&&Z.person.src!=="object"&&Z.url===d.url)){const{clipId:Z,...ot}=l;C(d,null,{...ot,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(Z=>Z.id!==d.id&&Z.kind==="video"&&Z.person&&Z.person.src!=="object"&&Z.url===d.url)??d:d;let L=zt();for(;y(L);)L=zt();const B=Lx({id:L,at:T,duration:I,color:l.color,width:kt(l.width),length:kt(l.length),jag:kt(l.jag),source:O.id,point:w??void 0}),{track:H}=Kt(s,r,B.start,B.start+B.duration);s.push({...B,track:H}),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"addQiVfx":{l=Jt(l);const d=l.style??"core";if(!Object.hasOwn(Lc,d))throw Error(`addQiVfx style: ${L1.join("|")}`);const w=Lc[d],T=l.clipId?y(l.clipId):null;if(l.clipId&&(!T||T.kind==="audio"||T.kind==="model"))throw Error("addQiVfx clipId needs a visual clip");const I=kt(l.at)??T?.start??0;if(I<0||I>Re)throw Error("addQiVfx at must be inside timeline");const O=kt(l.duration)??(T?Math.min(w.duration,Math.max(.5,T.start+T.duration-I)):w.duration),L=Array.isArray(l.point)?l.point:[kt(l.u),kt(l.v)],B={...l.params&&typeof l.params=="object"?l.params:{},...l.color?{color:l.color}:{},...l.color2?{color2:l.color2}:{},...l.core?{core:l.core}:{},...l.colorA?{colorA:l.colorA}:{},...l.colorB?{colorB:l.colorB}:{},...l.mistColor?{mistColor:l.mistColor}:{},...kt(l.size)!==null?{size:kt(l.size)}:{},...kt(l.glow)!==null?{glow:kt(l.glow)}:{},...kt(l.speed)!==null?{speed:kt(l.speed)}:{},...kt(l.intensity)!==null?{intensity:kt(l.intensity)}:{}};if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);let H=zt();for(;y(H);)H=zt();const Z=N3({id:H,style:d,at:I,duration:O,u:kt(L[0]),v:kt(L[1]),params:B}),{track:ot}=Kt(s,r,Z.start,Z.start+Z.duration);if(s.push({...Z,track:ot}),U.push(H),l.sfx!==!1){const st=vn(w.sfx);if(st)try{const Y=ha(s,r,st,I,{id:zt(),volume:.7});s.push(Y),U.push(Y.id)}catch{}}h.push(`addQiVfx (${d}) at ${(+I).toFixed(2)}s (${Z.duration}s)`);break}case"addTvcVfx":{l=Jt(l);const d=l.style??"speedflow";if(!Object.hasOwn(Fc,d))throw Error(`addTvcVfx style: ${B1.join("|")}`);const w=Fc[d],T=l.clipId?y(l.clipId):null;if(l.clipId&&(!T||T.kind==="audio"||T.kind==="model"))throw Error("addTvcVfx clipId needs a visual clip");const I=kt(l.at)??T?.start??0;if(I<0||I>Re)throw Error("addTvcVfx at must be inside timeline");const O=kt(l.duration)??(T?Math.min(w.duration,Math.max(.5,T.start+T.duration-I)):w.duration),L=Array.isArray(l.point)?l.point:[kt(l.u),kt(l.v)],B={...l.params&&typeof l.params=="object"?l.params:{},...l.color?{color:l.color}:{},...l.color2?{color2:l.color2}:{},...l.core?{core:l.core}:{},...kt(l.size)!==null?{size:kt(l.size)}:{},...kt(l.glow)!==null?{glow:kt(l.glow)}:{},...kt(l.speed)!==null?{speed:kt(l.speed)}:{},...kt(l.intensity)!==null?{intensity:kt(l.intensity)}:{},...kt(l.chroma)!==null?{chroma:kt(l.chroma)}:{},...kt(l.density)!==null?{density:kt(l.density)}:{},...kt(l.bokeh)!==null?{bokeh:kt(l.bokeh)}:{}};if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);let H=zt();for(;y(H);)H=zt();const Z=B3({id:H,style:d,at:I,duration:O,u:kt(L[0]),v:kt(L[1]),params:B}),{track:ot}=Kt(s,r,Z.start,Z.start+Z.duration);if(s.push({...Z,track:ot}),U.push(H),l.sfx!==!1){const st=vn(w.sfx);if(st)try{const Y=ha(s,r,st,I,{id:zt(),volume:.7});s.push(Y),U.push(Y.id)}catch{}}h.push(`addTvcVfx (${d}) at ${(+I).toFixed(2)}s (${Z.duration}s)`);break}case"addCombatHit":{l=Jt(l);let d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("addCombatHit needs a visual clip");const w=l.style??"slash";if(!Object.hasOwn(ld,w))throw Error(`addCombatHit style: ${_3.join("|")}`);const T=ld[w],I=kt(l.at)??d.start,O=Array.isArray(l.point)?l.point:[kt(l.u)??.5,kt(l.v)??.5];if(I<d.start-1e-6||I>d.start+d.duration+1e-6)throw Error("addCombatHit at must be a timeline time inside the clip");const L=Math.max(.1,Math.min(1,kt(l.strength)??.85)),B=kt(l.size)??.85+.35*L,H=ed(d,"rot")||Math.abs(d.rotation??0)>1e-6,Z=n.W||1280,ot=n.H||720,st=H?Ic(d,kt(O[0])??.5,kt(O[1])??.5,I-d.start,Z,ot,Z,ot):null,Y=d.scale??1,ct=st?st.px/Z:.5+(d.posX??0)+((kt(O[0])??.5)-.5)*Y,mt=st?st.py/ot:.5+(d.posY??0)+((kt(O[1])??.5)-.5)*Y,Q=[],nt=[];let dt=()=>{let Et=zt();for(;y(Et)||Q.some(Ct=>Ct.id===Et);)Et=zt();return Et};const vt=Math.round(I*1e3)%9973+1;Q.push(Xf({id:dt(),presetId:T.preset,label:T.label,at:I,u:ct,v:mt,color:l.color??T.color,core:l.core??T.core,angle:kt(l.angle),arc:kt(l.arc),flip:l.flip,spread:kt(l.spread),width:kt(l.width),size:B,sparks:l.sparks,seed:vt,duration:kt(l.duration)??T.duration})),T.extraPreset&&Q.push(Xf({id:dt(),presetId:T.extraPreset,label:"Tia lửa va chạm",at:I,u:ct,v:mt,color:l.color??T.color,core:l.core??T.core,size:B*.95,seed:vt+11}));let It=0;const xt=l.hitstop===!1||l.hitstop===0?0:kt(l.hitstop)??T.hitstop;if(xt>0&&d.kind==="video"&&!d.freeze&&!d.speedCurve){const Et=Math.max(.04,Math.min(.5,xt));try{const Ct=d.timeRemap?d:Ms(d,{}),Gt=hf(Ct,Math.max(0,I-d.start),Et);d=Ms(Ct,{keys:Gt.keys,duration:Gt.duration}),s=s.map(ee=>ee.id===d.id?d:ee),It=Et,nt.push(`hitstop ${Et.toFixed(2)}s`)}catch{}}if(l.impactFrame!==!1){const Et=typeof l.impactFrame=="string"?l.impactFrame:T.impactFrame;if(!Object.hasOwn(_n,Et))throw Error(`addCombatHit impactFrame: ${Object.keys(_n).join("|")} | false`);const Ct=Ld(Et,L),Gt=ut(Pd(Et)),ee=_n[Et][n.locale==="en"?"en":"vi"];Q.push({...ic({id:dt(),track:0,start:ut(I),duration:Gt,label:`Impact · ${ee}`}),motionKeys:[],effects:Ct.map(re=>({...re,keys:re.keys.map(Me=>({...Me}))}))}),nt.push(`flash ${Et}`)}if(l.impact!==!1&&(d.impacts?.length??0)<cc.max){const Et=ff({t:I-d.start,u:kt(O[0])??.5,v:kt(O[1])??.5,strength:L,duration:Math.max(.22,Math.min(.75,kt(l.duration)??.38))});d.impacts=mf([...d.impacts??[],Et].sort((Ct,Gt)=>Ct.t-Gt.t),d.duration),nt.push("impact blur")}if(l.shake!==!1){const Et=Math.max(.2,Math.min(1,.35+.55*L)),Ct=I-d.start,Gt=Math.min(d.duration,Ct+.32);Object.assign(d,fi(d,{amount:Et,freq:16,from:Ct,to:Gt,seed:vt+d.id.length,props:["x","y"]})),nt.push("shake")}if(s.length+Q.length>Bt)throw Error(`Tối đa ${Bt} clip`);if(st){const Et=Math.round(Qt(d,"rot",I-d.start)*100)/100;for(const Ct of Q)Ct.motion&&(Ct.rotation=Et)}for(const Et of Q){const{track:Ct}=Kt(s,r,Et.start,Et.start+Et.duration);s.push({...Et,track:Ct}),U.push(Et.id)}if(l.sfx!==!1){let Et=0;for(const Ct of T.sfx){const Gt=vn(Ct.id);if(!Gt)continue;const ee=Math.max(0,I+Ct.offset);try{const re=ha(s,r,Gt,ee,{id:dt(),volume:.85});s.push(re),U.push(re.id),Et++}catch{}}Et&&nt.push(`sfx ×${Et}`)}h.push(`addCombatHit (${w}) on ${K} at ${(+I).toFixed(2)}s${nt.length?` [${nt.join(", ")}]`:""}`);break}case"weaponTrail":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("weaponTrail needs a visual clip");const w=Array.isArray(l.path)&&l.path.length>=2,T=Array.isArray(l.point)?l.point:null;if(T&&!T.every(ot=>Number.isFinite(ot)&&ot>=0&&ot<=1))throw Error("weaponTrail point [u, v] (0..1 of the picture)");const I=kt(l.at)??d.start,O=Math.min(kt(l.duration)??(w?.75:d.start+d.duration-I),d.start+d.duration-I);if(!(O>=.15)||I<d.start-1e-6)throw Error("weaponTrail must lie inside the clip");if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);let L=zt();for(;y(L);)L=zt();const B=!w&&!T&&!(d.person||d.personPending)?s.find(ot=>ot.id!==d.id&&ot.kind==="video"&&ot.person&&ot.person.src!=="object"&&ot.url===d.url)??d:d,H=G3({id:L,at:I,duration:O,color:l.color,core:l.core,width:kt(l.width),length:kt(l.length),sparks:l.sparks,source:B.id,point:T??void 0,path:w?l.path:void 0}),{track:Z}=Kt(s,r,H.start,H.start+H.duration);s.push({...H,track:Z}),U.push(L),H.pendingPin&&S.push({clipId:L,...H.pendingPin}),h.push(`weaponTrail on ${d.label||d.id}: ${w?`scripted path (${l.path.length} pts)`:"tracked energy ribbon"}`);break}case"personElectric":{l=Jt(l);let d=y(l.clipId);if(!d||d.kind!=="video")throw Error("personElectric needs the filmed video of the person");if(!d.person){const ot=d,st=s.find(Y=>Y.id!==ot.id&&Y.kind==="video"&&Y.person&&Y.person.src!=="object"&&Y.url===ot.url);st&&(d={...ot,person:st.person})}if(!d.person){if(n.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:ot,...st}=l;C(d,null,{...st,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,kt(l.start)??d.start),T=Math.min(d.start+d.duration,kt(l.duration)!=null?w+kt(l.duration):d.start+d.duration);if(!(T-w>.1))throw Error("personElectric must lie inside the person clip");let I=zt();for(;y(I);)I=zt();const O=/^#[0-9a-fA-F]{6}$/.test(l.color??"")?l.color:"#ffc23d",L=Math.max(.1,Math.min(1,kt(l.crackle)??.75)),B=Jn(d,I,{start:Xe(w),duration:Xe(T-w),inPoint:Xe((d.inPoint||0)+(w-d.start)*(d.playbackRate||1)),label:`${d.label||"Video"} · điện`,edge:Zu({color:O,width:.009,glow:1.6,crackle:L,amount:1})});delete B.impacts;const{track:H}=Kt(s,r,B.start,B.start+B.duration);s.push({...B,track:H}),U.push(I),s.some(ot=>ot.id!==d.id&&ot.kind==="video"&&ot.url===d.url&&!ot.person&&!ot.mask&&ot.start===d.start&&ot.duration===d.duration&&(ot.inPoint||0)===(d.inPoint||0))||(s=s.map(ot=>{if(ot.id!==d.id)return ot;const st={...ot};return delete st.person,delete st.mask,st})),h.push(`personElectric ${d.label||d.id}: electricity on the person`);break}case"worldFlip":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("worldFlip needs a 2D visual clip");const w=kt(l.at)??d.start,T=w-d.start,I=kt(l.duration)??.6;if(T<-1e-6||T>d.duration)throw Error("worldFlip at must be a timeline time inside the clip");Object.assign(d,R$(d,{from:Math.max(0,T),to:T+I,turn:kt(l.turn)??kt(l.numberValue)??180,back:l.back===!0,W:n.W||1280,H:n.H||720})),h.push(`worldFlip ${K}: turns ${kt(l.turn)??kt(l.numberValue)??180}° at ${(+w).toFixed(2)} s`);break}case"lightBurst":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("lightBurst needs a 2D visual clip");const w=(Array.isArray(l.hits)?l.hits:[kt(l.at)??d.start]).filter(Number.isFinite).slice(0,ml.maxHits),T=G$(d,w);if(!T.length)throw Error("lightBurst hits must be timeline times inside the clip");const I=[...d.effects||[]].filter(O=>O.type!=="light-burst");if(I.length>=yn)throw Error(`At most ${yn} effects per clip`);d.effects=ak([...I,{type:"light-burst",amount:0,keys:T}]),h.push(`lightBurst ${K}: ${w.length} burst(s) of light`);break}case"breathMist":{l=Jt(l);const d=y(l.clipId),w=kt(l.at)??d?.start??0,T=Array.isArray(l.point)?l.point:[kt(l.u)??.5,kt(l.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 I=zt();for(;y(I);)I=zt();const O=B$({id:I,at:w,u:kt(T[0])??.5,v:kt(T[1])??.35,angle:kt(l.angle)??200,length:kt(l.length)??1,size:kt(l.size)??1,duration:kt(l.duration)??1.6,color:/^#[0-9a-fA-F]{6}$/.test(l.color??"")?l.color:void 0}),{track:L}=Kt(s,r,O.start,O.start+O.duration);s.push({...O,track:L}),U.push(I),h.push(`breathMist at ${(+w).toFixed(2)} s`);break}case"documentary":{if(l._error)throw Error(l._error);const d=l._plan;if(!d||!Array.isArray(d.S)||!Array.isArray(d.K))throw Error("documentary needs stations");const w=Math.max(0,it(l.start)??0),T=Math.ceil(d.total/ar.layerSeconds-1e-6),I=[];for(let B=0;B<T;B++){let H=zt();for(;y(H)||I.includes(H);)H=zt();I.push(H)}const O=zI({ids:I,at:w,plan:d,label:l.label||void 0}),{track:L}=Kt(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":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind!=="video")throw Error("energyAura needs a video clip (the footage of the person / thing)");const w=Array.isArray(l.path)&&l.path.length>=2&&l.path.every(ot=>Array.isArray(ot)&&ot.length===4&&ot.every(Number.isFinite))?[...l.path].sort((ot,st)=>ot[0]-st[0]):null;if(l.path!==void 0&&l.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,kt(l.start)??(w?w[0][0]:d.start)),I=Math.min(d.start+d.duration,T+(kt(l.duration)??(w?w.at(-1)[0]-T:d.start+d.duration-T)));if(!(I-T>=.2))throw Error("energyAura must lie inside the footage");const O={look:l.look,color:l.color,hot:l.hot,size:kt(l.size),intensity:kt(l.intensity),wind:Array.isArray(l.wind)?l.wind:void 0,speed:kt(l.speed),stretch:kt(l.stretch),taper:kt(l.taper)};let L=typeof l._auraId=="string"&&!y(l._auraId)?l._auraId:zt();for(;!l._auraId&&y(L);)L=zt();const B=w?w.map(ot=>[+(ot[0]-T).toFixed(4),ot[1],ot[2],ot[3]]):[];let H=o$({id:L,at:T,duration:I-T,settings:O,body:B,kind:w?"thing":"person"});w||(H=Fe(H,{kind:"aura-pose",op:"energyAura",params:{source:d.id,from:+(T-d.start).toFixed(4),duration:+(I-T).toFixed(4),person:Number.isInteger(l.person)?l.person:1}}));const{track:Z}=Kt(s,r,H.start,H.start+H.duration);s.push({...H,track:Z}),U.push(L),h.push(`energyAura ${Mh(O).look} on ${d.label||d.id}${w?" (along the given path)":": the body tracked in the editor"}`);break}case"personAura":{l=Jt(l);let d=y(l.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(n.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}=l;C(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=D$(d,()=>{let O=zt();for(;y(O)||s.some(L=>L.id===O);)O=zt();return O},{start:kt(l.start),duration:kt(l.duration),color:/^#[0-9a-fA-F]{6}$/.test(l.color??"")?l.color:void 0,silhouette:l.silhouette===!0,style:l.style==="fresnel"?"fresnel":"rainbow"});if(s.length+T.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const O of T){const{track:L}=Kt(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${l.silhouette===!0?" + coloured figure":""}`);break}case"hudWall":{l=Jt(l);const d=l.sourceClipId!=null?y(l.sourceClipId):null;if(l.sourceClipId!=null&&(!d||d.kind!=="video"))throw Error("hudWall sourceClipId must be the footage (a video clip)");const w=kt(l.start)??d?.start??0,T=Math.min(En.maxSeconds,kt(l.duration)??(d?d.start+d.duration-w:6)),{cards:I,assets:O}=PS(l,o,n.locale),L=l.region!=null&&typeof l.region=="object"?l.region:null,B=n.W||1280,H=n.H||720,Z=LS({cards:I,cols:kt(l.cols),rows:kt(l.rows),curve:kt(l.curve),color:l.color,look:l.look,toolbar:l.toolbar,...L&&Number(L.w)>0&&Number(L.h)>0&&(l.mode??"plane")==="plane"?{W:B*L.w,H:H*L.h,fill:!0}:{W:B,H}});let ot=zt();for(;y(ot);)ot=zt();const st=DS({id:ot,at:w,duration:T,cfg:Z,assets:O});if(l.region!=null){if(!d)throw Error("hudWall region needs sourceClipId (the footage to stick the wall to)");Object.assign(st,wl(st,d,{region:l.region,mode:l.mode??"plane",at:l.at}))}const{track:Y}=Kt(s,r,st.start,st.start+st.duration);s.push({...st,track:Y}),U.push(ot),st.pendingPin&&S.push({clipId:ot,...st.pendingPin}),h.push(`hudWall: ${I.length} card(s), ${Z.cols}×${Z.rows}${st.pendingPin?`, stuck to ${d.label||d.id} (${st.pendingPin.mode}, tracked in the editor)`:""}`);break}case"hudPanel":{l=Jt(l);const d=l.sourceClipId!=null?y(l.sourceClipId):null;if(l.sourceClipId!=null&&(!d||d.kind!=="video"))throw Error("hudPanel sourceClipId must be the footage (a video clip)");if(l.region!=null&&!d)throw Error("hudPanel region needs sourceClipId (the footage to stick the panel to)");const w=ut((kt(l.start)??d?.start??0)+Math.max(0,kt(l.delay)??0)),T=Math.min(pr.maxSeconds,kt(l.duration)??(l.kind==="prompt"||l.kind==="keyboard"?Math.max(4,rw(String(l.text??""),kt(l.typeAt)??.5,kt(l.cps)??14).at(-1)+1.6||4):4));if(!(T>=.5))throw Error("hudPanel: duration ≥ 0.5 s");const I=l.kind==="prompt"&&l.keyboard===!0?["prompt","keyboard"]:[l.kind],O=[],L=[];for(const B of I){const H=_C(B,B==="keyboard"&&l.kind==="prompt"?{...l,posX:void 0,posY:l.keyboardY,width:void 0,tiltX:void 0,tiltY:void 0}:l,{materials:o,locale:n.locale,fill:l.region!=null&&B!=="keyboard"});if(l.region==null){const Y=n.W||1280,ct=n.H||720,mt=d??s.filter(dt=>dt.kind==="video"&&!dt.motion&&dt.start<=w+1e-6&&dt.start+dt.duration>w&&!r[dt.track]?.hidden).sort((dt,vt)=>dt.track-vt.track)[0],Q=mt?Jc(mt,o.find(dt=>dt.id===mt.nodeId),w+T/2,{W:Y,H:ct})??{...ct>Y*1.1?Ie.face.portrait:Ie.face.landscape,assumed:!0}:null,nt=GC(H.S,Q,Y,ct);nt&&L.push(`${B} ${nt}`)}let Z=zt();for(;y(Z);)Z=zt();const ot={id:Z,nodeId:"",kind:"image",url:"",volume:0,start:w,duration:ut(T),label:H.label,motionV:2,posX:0,posY:0,scale:1,motion:BC(H.S,H.TT,H.assets)};l.region!=null&&B!=="keyboard"&&Object.assign(ot,wl(ot,d,{region:l.region,mode:l.mode??"plane",at:l.at}));const{track:st}=Kt(s,r,ot.start,ot.start+ot.duration);s.push({...ot,track:st}),U.push(Z),O.push(B),ot.pendingPin&&S.push({clipId:Z,...ot.pendingPin})}h.push(`hudPanel: ${O.join(" + ")} (${ow(l.look,l.color).id}) ${w.toFixed(2)}–${(w+T).toFixed(2)}s${L.length?` — ${L.join(", ")}`:""}${l.region!=null?`, stuck to ${d.label||d.id} (tracked in the editor)`:""}`);break}case"hudInteract":{l=Jt(l);const d=y(Mt(l.wallClipId??l.clipId));if(!ib(d))throw Error("hudInteract needs wallClipId = a HUD wall layer (hudWall)");const w=y(l.sourceClipId);if(!w||w.kind!=="video")throw Error("hudInteract needs sourceClipId = the footage with the hands");const T=Math.max(d.start,w.start),I=Math.min(d.start+d.duration,w.start+w.duration);if(!(I-T>=.3))throw Error("The HUD wall and the footage do not play at the same time");const O=Ed.includes(l.hand)?l.hand:"any",L=l.grab===!1?!1:Number.isInteger(l.grab)?l.grab:"auto",B=kt(l.fly),H=Array.isArray(l.events)?l.events.slice(0,64).map(qt=>({t:it(qt?.t),type:qt?.type,...Array.isArray(qt?.point)?{point:qt.point.map(Number)}:{}})):null,Z=l.matteClipId!=null?y(l.matteClipId):null;if(l.matteClipId!=null&&!Z?.person)throw Error("hudInteract matteClipId must be a clip with an AI person / object cut-out of the hands");s=s.filter(qt=>qt.hud?.wall!==d.id);const ot=()=>{let qt=zt();for(;y(qt);)qt=zt();return qt},{HUD:st}=Th(d.motion),Y=d.motion.params?.color??st.color,ct=d.motion.params?.look??st.look,mt=n.W||1280,Q=n.H||720,nt=w.hands?.mw??mt,dt=w.hands?.mh??Q,vt=VS(d,w,s,{cam:u,W:mt,H:Q}),It=ot();let xt=null;if(l.shadow===!0){const qt={...w,id:It,volume:0,hud:{wall:d.id,role:"hands"},label:`${w.label||"Video"} · tay`};for(const Nt of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","shocks","impacts","trail","pendingPin","pin","person","mask"])delete qt[Nt];xt=GS(qt,{id:It,wallMask:vt,mw:nt,mh:dt}),xt.track=Kt(s,r,xt.start,xt.start+xt.duration).track,s.push(xt),U.push(It)}const Et=ot(),Ct={id:Et,nodeId:"",kind:"image",url:"",volume:0,start:Xe(T),duration:Xe(I-T),label:"HUD · thẻ kéo ra",motionV:2,posX:0,posY:0,scale:1,motion:Kd({color:Y,look:ct}),hud:{wall:d.id,role:"grab"}};Ct.track=Kt(s,r,Ct.start,Ct.start+Ct.duration).track,s.push(Ct),U.push(Et);const Gt=ot(),ee={...w,id:Gt,label:`${w.label||"Video"} · tay`,volume:0,hud:{wall:d.id,role:"hands",src:w.id},mask:Xd(w.hands?.mw,w.hands?.mh)};for(const qt of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","shocks","impacts","trail","pendingPin","pin"])delete ee[qt];const re=Z?.person??(w.person&&w.person.src!=="object"?w.person:s.find(qt=>qt.id!==w.id&&qt.kind==="video"&&qt.url===w.url&&qt.person&&qt.person.src!=="object")?.person);re?ee.person=re:delete ee.person,ee.track=Kt(s,r,w.start,w.start+w.duration).track,s.push(ee),U.push(Gt);const Me={source:w.id,mode:"hud",wall:d.id,cutout:Gt,...xt?{shadow:It}:{},side:O,grab:L,...Z?{matte:Z.id}:{},...B!=null?{fly:B}:{},...H?{events:H}:{},from:Xe(T-w.start),duration:Xe(I-T)};if(lu(w,T-w.start,I-T)||H?.every(qt=>Array.isArray(qt.point))){const qt=_S({wall:d,layer:Ct,src:w,clips:s,cam:u,W:n.W||1280,H:n.H||720,events:H,grab:L,side:O,fly:B});if(d.motion=qt.wall,Ct.motion=qt.grab,w.hands){const Nt=N0(w,{until:qt.cutoutUntil});Nt&&(ee.mask=Nt,xt&&(xt.mask={...Nt,masks:[...Nt.masks,{...vt,mode:"intersect"}]}))}h.push(`hudInteract ${d.label||d.id}: ${qt.report.taps} tap(s), ${qt.report.pinches} pinch(es)${qt.report.grabbed!=null?`, card ${qt.report.grabbed+1} pulled out`:""}, hands in front${w.hands?" (the open editor then cuts them out pixel by pixel)":""}`),w.hands&&Object.assign(Ct,Fe(Ct,{kind:"hand-track",op:"hudInteract",params:Me}));break}Object.assign(Ct,Fe(Ct,{kind:"hand-track",op:"hudInteract",params:Me})),h.push(`hudInteract ${d.label||d.id}: the hands are tracked in the editor, then the HUD reacts`);break}case"handAttach":{l=Jt(l);const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("handAttach needs a visual layer (clipId)");const w=y(l.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:I}=R0(l),O=l.scale===!0,L=Array.isArray(l.offset)&&l.offset.length===2&&l.offset.every(Number.isFinite)?l.offset:null,B=Math.max(d.start,w.start),H=Math.min(d.start+d.duration,w.start+w.duration);if(!(H-B>=1/30))throw Error("The layer and the footage do not play at the same time");if(lu(w,B-w.start,H-B)){for(const[Z,ot]of Object.entries(BS(d,w,{point:T,side:I,scale:O,offset:L,W:n.W||1280,H:n.H||720})))ot===void 0?delete d[Z]:d[Z]=ot;h.push(`handAttach ${K}: follows the ${I==="any"?"":I+" "}hand's ${T}`);break}Object.assign(d,Fe(d,{kind:"hand-track",op:"handAttach",params:{source:w.id,mode:"attach",point:T,side:I,scale:O,...L?{offset:L}:{},from:Xe(B-w.start),duration:Xe(H-B)}})),h.push(`handAttach ${K}: the hands are tracked in the editor, then it follows the ${T}`);break}case"fixMatte":{l=Jt(l);const d=y(l.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(H=>H?.kind==="matte-fix"&&H.state==="pending"),T=w?.params?.strokes??[];if(l.clear===!0){Object.assign(d,Fe(d,{kind:"matte-fix",op:"fixMatte",params:{clear:!0,strokes:[]}})),h.push(`fixMatte ${K}: back to the AI cut-out (in the editor)`);break}if(l.roto===!0){Object.assign(d,Fe(d,{kind:"matte-fix",op:"fixMatte",params:{...w?.params??{},roto:!0}})),h.push(`fixMatte ${K}: traced into Roto splines (in the editor)`);break}const I=it(l.at),O=l.mode??"add";if(I===null||I<d.start-1e-6||I>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(l.points)?l.points:null;if(!L||!L.length||L.length>120||!L.every(H=>Array.isArray(H)&&H.length===2&&H.every(Z=>Number.isFinite(Z)&&Z>=-.2&&Z<=1.2)))throw Error("fixMatte points: [[x, y] …] 0..1 of the frame (≤ 120)");const B={local:Xe(I-d.start),mode:O,points:L.map(H=>H.map(Xe)),size:Math.max(.002,Math.min(.3,it(l.size)??.015)),spread:Math.round(Math.max(0,Math.min(60,it(l.spread)??8)))};Object.assign(d,Fe(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 ${K}: ${O} stroke at ${(+I).toFixed(2)}s, followed ±${B.spread} frames (in the editor)`);break}case"cameraShake":{const d=y(l.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("Camera shake needs a 2D visual clip");const w=it(l.at)??0,T=it(l.duration)??Math.min(1.5,d.duration-w),I=Math.max(.1,Math.min(1,it(l.numberValue)??.5)),O=Math.round(w*1e3)+d.id.length;if(l.preset!=null&&!vd.includes(l.preset))throw Error(`cameraShake preset (axis) must be one of ${vd.join(", ")}`);const L=l.preset!=null?WM(l.preset,I,{amountX:it(l.amountX)??void 0,amountY:it(l.amountY)??void 0,amountRot:it(l.amountRot)??void 0,freq:it(l.freq)??void 0}):null;Object.assign(d,fi(d,L?{props:L.props,amp:L.amp,freq:L.freq,from:w,to:w+T,seed:O}:{amount:I,freq:12,from:w,to:w+T,seed:O})),h.push(`camera shake${l.preset?` ${l.preset}`:""} ${K}: ${w}s +${T}s`);break}case"writeMotion":{const d=typeof l.prompt=="string"?l.prompt.trim():"";if(d.length<6||d.length>6e3)throw Error("Motion brief must be 6–6000 characters");if(g.length>=rc)throw Error(`At most ${rc} Claude motion jobs per request`);if(l.clipId){const L=y(l.clipId);if(!L?.motion)throw Error("writeMotion clipId must be a Motion Code layer");g.push({clipId:L.id,prompt:d}),h.push(`Claude motion (sửa) ${K}`);break}const w=l.fromClipId?y(l.fromClipId):null;if(l.fromClipId&&!w?.motion)throw Error("writeMotion fromClipId must be a Motion Code layer");const T=it(l.start)??(w?w.start+w.duration:null),I=it(l.duration)??6;if(T===null||T<0||I<1||I>nc+1e-6||T+I>Re)throw Error(`Motion layer timing: start ≥ 0, 1–${nc}s`);const O=g.filter(L=>!L.clipId&&L.join==null).reduce((L,B)=>L+(B.duration||0),0);if(O+I>nc+1e-6)throw Error(`Claude motion: at most ${nc}s of new layers per request (this plan asks for ${ut(O+I)}s) — split it into several requests`);g.push({prompt:d,start:ut(T),duration:ut(I),...w?{fromClipId:w.id}:{},...l.preset==="motion3d"?{kind:"three"}:{}}),h.push(`Claude motion (${w?`nối tiếp ${w.label}`:"mới"}) → ${ut(T)}s / ${ut(I)}s`);break}case"setMotionCode":{const d=y(l.clipId);if(!d?.motion)throw Error("setMotionCode clipId must be a Motion Code layer");if(typeof l.code!="string"||!/\brender\b/.test(l.code))throw Error("Motion code must define function render(ctx, t, env)");const w=l.motionKind==="three"?"three":l.motionKind==="2d"?void 0:d.motion.kind,T=Qe({code:l.code,params:l.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,l.space===null||l.space===""?delete d.space:l.space!==void 0&&Object.assign(d,Ug(l)),h.push(`motion code ${K}`);break}case"setMotion":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error("Motion requires a visual clip");const w=pc(l.preset,d.duration);d.motionKeys=qu(d,w),delete d.posX,delete d.posY,delete d.scale,d.motionV=2,h.push(`motion ${K}: ${l.preset}`);break}case"generateBroll":{if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);if(s.filter(O=>O.gen?.status==="pending"&&!t.some(L=>L.id===O.id)).length>=vl)throw Error(`At most ${vl} generated B-roll per request`);const d=l.layout??"cutaway";if(!a1.includes(d))throw Error("Unsupported B-roll layout");const w=zt(),{clip:T,trackNote:I}=B4({clips:s,tracks:r,materials:o,generator:l.generator,prompt:l.prompt,start:it(l.start),duration:it(l.duration),layout:d,preset:l.preset,track:it(l.track),trackFallback:!0,newId:()=>w,refs:l.refs??void 0});U.push(w),s.push(T),h.push(`generateBroll → ${T.start}s / ${T.duration}s${I?` (${I})`:""}`);break}case"redrawVideo":{if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);const d=y(l.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<dn.minSeconds-1e-6)throw Error(`the clip must be at least ${dn.minSeconds}s`);if(l.style!==void 0&&!df.includes(l.style))throw Error(`style: one of ${df.join(", ")}`);if(l.mode!==void 0&&!tk.includes(l.mode))throw Error("mode: keyframes or fast");if(l.resolution!==void 0&&!ek.includes(l.resolution))throw Error("resolution: 720p or 1080p");if(l.keyframes!==void 0&&(!Number.isInteger(l.keyframes)||l.keyframes<dn.minKeyframes||l.keyframes>dn.maxKeyframes))throw Error(`keyframes: ${dn.minKeyframes}–${dn.maxKeyframes}`);const w=typeof l.character=="string"?l.character.trim():"";if(w.length>dn.maxCharacterText)throw Error(`character: at most ${dn.maxCharacterText} characters`);const T=Array.isArray(l.characterIds)?l.characterIds:[],I=[...new Set([...T.map(Y=>{const ct=o.find(mt=>mt.id===Y)||s.find(mt=>mt.id===Y&&mt.kind==="image");if(!ct||ct.kind!=="image"||!Pi(ct.gcsUri))throw Error(`character picture ${String(Y).slice(0,40)} is not a stored image`);return ct.gcsUri}),...Array.isArray(l.refs)?l.refs:[]])];if(I.length>dn.maxCharacterRefs||!I.every(Pi))throw Error(`at most ${dn.maxCharacterRefs} stored character pictures`);if(!w&&!I.length)throw Error("needs a character (description and / or picture)");const O=ok(d.duration),L=rk(l.style),B=ut(Math.min(d.duration,O)),{moved:H,...Z}=fd(s,r,d.start,d.start+B,it(l.track),{fallback:!0}),ot=zt(),st=`${n.locale==="en"?"Redraw":"Vẽ lại"} · ${n.locale==="en"?L.en:L.vi}`;s.push({nodeId:"",kind:"video",url:"",label:st,inPoint:0,sourceDuration:O,volume:0,fit:"cover",...Z,id:ot,start:d.start,duration:B,gen:{status:"pending",generator:nk,prompt:w,duration:O,finish:{colorMatch:!1},...I.length?{refs:I}:{},redraw:{src:d.gcsUri,inPoint:ut(d.inPoint??0),seconds:O,style:L.id,mode:l.mode??"keyframes",...l.keyframes!==void 0?{keyframes:l.keyframes}:{},resolution:l.resolution??"720p"}}}),U.push(ot),h.push(`redrawVideo ${st} → ${d.start}s / ${B}s (${l.mode??"keyframes"})${H?` (track ${Z.track})`:""}`);break}case"regionEdit":{const d=y(l.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||an(d)||qn(d)||d.reverse)throw Error("regionEdit needs the clip at normal speed (not reversed, sped up or ramped)");if(l.aspectRatio!=null&&!cf.includes(l.aspectRatio))throw Error(`aspectRatio: one of ${cf.join(", ")}`);const w=Array.isArray(l.regions)?l.regions.map(L=>L&&typeof L=="object"?{...L,start:Number.isFinite(L.start)?ut(L.start):L.start,end:Number.isFinite(L.end)?ut(L.end):L.end}:L):l.regions;if(U2(w,d.duration),s.length+w.length>Bt)throw Error(`Tối đa ${Bt} clip`);const T=Object.fromEntries(cj.filter(L=>d[L]!==void 0).map(L=>[L,structuredClone(d[L])])),I=n.locale==="en",O=new Set;for(const[L,B]of[...w].sort((H,Z)=>H.start-Z.start).entries()){const H=typeof B.prompt=="string"?B.prompt.trim():"",Z=B.action??(H?"custom":null),ot=B.model??Y2;if(!Z)throw Error(`region ${L+1}: action (scene, camera, character, relight, dof) or prompt (custom)`);if(Z==="custom"&&!H)throw Error(`region ${L+1}: custom needs prompt (what to change)`);let st=null;if(B.imageMaterialId!=null){const Ct=o.find(Gt=>Gt.id===B.imageMaterialId)||s.find(Gt=>Gt.id===B.imageMaterialId&&Gt.kind==="image");if(!Ct||Ct.kind!=="image"||!Pi(Ct.gcsUri))throw Error(`region ${L+1}: imageMaterialId ${String(B.imageMaterialId).slice(0,40)} is not a stored image in Media`);st=Ct.gcsUri}if(pf(Z).image==="required"&&!st)throw Error(`region ${L+1}: ${Z} needs imageMaterialId (one front view of the new character from Media)`);let Y;try{Y=q2({inPoint:d.inPoint??0,length:d.duration,start:B.start,end:B.end,model:ot})}catch(Ct){throw Error(`region ${L+1}: ${Ct.message}`)}const ct=B.exact===!0&&H?H.slice(0,uf.maxPrompt):Z2(Z,H,{hasImage:!!st}),mt=ut(d.start+B.start),Q=ut(B.end-B.start),nt=Math.max(.05,Math.min(uf.fade,Q/4)),{moved:dt,...vt}=fd(s,r,mt,mt+Q,it(l.track),{fallback:!0}),It=zt(),xt=pf(Z),Et=J2[ot];s.push({nodeId:"",kind:"video",url:"",label:`${I?xt.en:xt.vi} · ${Et.label}`,...T,inPoint:Y.offset,sourceDuration:Y.seconds,volume:0,...vt,id:It,start:mt,duration:Q,enter:{type:"fade",duration:nt},exit:{type:"fade",duration:nt},gen:{status:"pending",generator:Q2,prompt:ct,duration:Y.seconds,finish:{colorMatch:!1},...st?{refs:[st]}:{},region:{src:d.gcsUri,action:Z,model:ot,winStart:Y.winStart,seconds:Y.seconds,offset:Y.offset,...l.aspectRatio!=null?{aspect:l.aspectRatio}:{}}}}),U.push(It),O.add(vt.track)}h.push(`regionEdit ${K} → ${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>=Bt)throw Error(`Tối đa ${Bt} clip`);const d=it(l.start),w=it(l.duration);if(d===null||w===null||d<0||w<1/ve||d+w>Re)throw Error("Invalid creative clip timing");const T=ut(d),I=ut(w),O=it(l.track),{track:L,moved:B}=Kt(s,r,T,T+I,O);let H;if(l.op==="addAdjustmentLayer"){const{id:mt,track:Q,start:nt,duration:dt,...vt}=ic({id:"x",track:0,start:0,duration:1,label:B2(s)}),It=it(l.numberValue);H={...vt,...It!==null&&It>=0&&It<1?{opacity:It}:{}}}else if(l.op==="addSolid"){const mt=["linear","radial"].includes(l.preset)?l.preset:"color",Q=l.color??"#d93a3a",{id:nt,track:dt,start:vt,duration:It,...xt}=Sp({id:"x",track:0,start:0,duration:1,aspect:n.W&&n.H?n.W/n.H:void 0,label:_2(s),fill:mt==="color"?{type:mt,color:Q}:{type:mt,from:Q,to:l.fill??"#0d0f12",angle:it(l.angle)??90}}),Et=it(l.numberValue);H={...xt,...Et!==null&&Et>=0&&Et<1?{opacity:Et}:{}}}else if(l.op==="addBroll"){const mt=o.find(nt=>nt.id===l.materialId);if(!mt?.url||!["image","video"].includes(mt.kind))throw Error("B-roll requires an existing image or video material");const Q=it(l.inPoint)??0;if(Q<0||mt.kind==="image"&&Q!==0||mt.kind==="video"&&(!Number.isFinite(mt.duration)||Q+I>mt.duration+1e-6))throw Error("B-roll range exceeds known source duration");H={nodeId:mt.id,kind:mt.kind,url:mt.url,label:mt.label||"B-roll",inPoint:Q,sourceDuration:mt.kind==="video"?mt.duration:void 0,volume:0,fit:"cover"}}else if(l.op==="generateElement"){const mt=l.generator??zx;if(!Px[mt])throw Error("Unsupported element generator");const nt=typeof l.prompt=="string"?l.prompt.trim():"";if(nt.length<6||nt.length>1200)throw Error("Element prompt must be 6–1200 characters");if(s.filter(dt=>dt.gen?.status==="pending"&&!t.some(vt=>vt.id===dt.id)).length>=vl)throw Error(`At most ${vl} generated items per request`);H={nodeId:"",kind:"image",url:"",label:`AI element · ${nt.slice(0,40)}`,volume:0,gen:{status:"pending",generator:mt,prompt:nt,duration:I},...W(l,.45)},l.anim!=null&&(H.element={},H.pendingAnim=l.anim)}else if(l.op==="addElement"){if(l.elementId!=null){const mt=e1(l.elementId);if(!mt)throw Error("Unknown element");const Q={id:mt.id,...l.primary?{primary:l.primary}:{},...l.secondary?{secondary:l.secondary}:{}};H={nodeId:"",kind:"image",url:"",label:`Element · ${mt.name}`,volume:0,shape:V2(mt.id,Q),element:Q,...W(l,.25)}}else{const mt=o.find(Q=>Q.id===l.materialId);if(!mt?.url||mt.kind!=="image")throw Error("Element requires a library id or an image material");H={nodeId:mt.id,kind:"image",url:mt.url,...mt.gcsUri?{gcsUri:mt.gcsUri}:{},label:mt.label||"Element",volume:0,element:{},...W(l,.25)}}H.pendingAnim=l.anim??{}}else if(l.op==="addMotion"){if(I>to.maxDuration+1e-6)throw Error(`Motion Code layers: at most ${to.maxDuration}s`);const mt=!l.code&&l.motionPreset?Za(l.motionPreset,l):null,Q=Qe(mt?{code:mt.code,params:{...mt.params,...l.params??{}},preset:mt.preset,kind:mt.kind}:{code:l.code,params:l.params??{},preset:l.motionPreset??void 0,prompt:l.prompt??void 0,kind:l.motionKind??void 0,assets:l.motionAssets??void 0});H={nodeId:"",kind:"image",url:"",label:typeof l.label=="string"&&l.label.trim()?l.label.trim().slice(0,60):mt?`Motion · ${String(l.text||mt.name).slice(0,40)}`:"Motion code",volume:0,motion:Q,...Ug(l)}}else if(l.op==="addMap"){const mt=Gg(l.models,o,l.geo?.stops??[]),Q=Kg(l.images,o,l.geo?.stops??[]),nt=nf({...l.geo,...mt?{models:mt}:{},...Q?{images:Q}:{},...l.buildings!==void 0&&l.buildings!==null?{buildings:l.buildings}:{}},I),dt=typeof l.label=="string"&&l.label.trim()?l.label.trim().slice(0,60):[...nt.stops.map(vt=>vt.label),...nt.areas.map(vt=>vt.name),...nt.pins.map(vt=>vt.label)].find(Boolean)||"";H={nodeId:"",kind:"image",url:"",label:`Bản đồ${dt?` · ${dt.slice(0,40)}`:""}`,volume:0,geo:nt}}else if(l.op==="addCard"){const mt=G2({html:l.html,width:it(l.width)??lf.width,height:it(l.height)??lf.height,...l.fill?{bg:l.fill}:{}}),Q=720/Math.min(n.W||1280,n.H||720),nt=(n.W||1280)*Q,dt=(n.H||720)*Q;H={nodeId:"",kind:"image",url:"",label:`Card · ${H2(mt.html).slice(0,40)||"HTML"}`,volume:0,card:mt,posX:Math.max(-1,Math.min(1,it(l.posX)??0)),posY:Math.max(-1,Math.min(1,it(l.posY)??W2(mt,l.placement,nt,dt))),scale:Math.max(.05,Math.min(4,it(l.scale)??K2(mt,nt,dt))),enter:{type:"fade",duration:Math.min(.4,I/4)},exit:{type:"fade",duration:Math.min(.3,I/4)}}}else if(l.op==="addShape"){const mt=l.shape&&Object.hasOwn($h,l.shape),Q=mt?T$(l.shape,{color:l.color??"#c6f432",accent:l.fill??"#2bd4c9",duration:I}):X2({preset:l.shape??void 0,d:l.path??void 0,stroke:l.color??"#c6f432",fill:l.fill??null,strokeWidth:it(l.numberValue)??18});H={nodeId:"",kind:"image",url:"",label:`Shape · ${l.shape??"custom"}`,volume:0,shape:Q,...W(l,mt?1:.6)}}else{const mt=ri(l);H={nodeId:"",kind:"image",url:"",label:mt.text.slice(0,40),title:mt,volume:0,...it(l.posX)!==null||it(l.posY)!==null?W(l,1):{},...l.decor===!0?{decor:!0}:{}}}const Z=l.op==="addSolid"||l.op==="addAdjustmentLayer"||l.op==="addMap"?[]:pc(l.preset??"none",I),ot=zt();U.push(ot);const{pendingAnim:st,...Y}=H,ct={...Y,id:ot,start:T,duration:I,track:L,motionKeys:Z,...H.posX!==void 0?{motionV:2}:{}};s.push(st?E4(ct,st):lt?Oc(ct,"exit","fade",{duration:Math.min(.3,I/4)}):ct),h.push(`${lt?"lockup":l.op} → ${T}s / ${I}s${lt?` (${lt.placement.mode==="side"?lt.placement.side:lt.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=Fh(l,{clips:s,find:y,W:n.W||1280,H:n.H||720,en:n.locale==="en",isLocked:T=>!!r[T.track]?.locked});for(const T of d.patches){const I=s.findIndex(O=>O.id===T.id);s[I]={...s[I],shape:T.shape,...T.duration?{duration:T.duration}:{}}}const w=(T,I,O,L,B={})=>{if(s.length>=Bt)throw Error(`Tối đa ${Bt} clip`);if(O===null||L===null||O<0||L<1/ve||O+L>Re)throw Error("Invalid creative clip timing");const H=ut(O),Z=ut(L),{track:ot}=Kt(s,r,H,H+Z,B.zIndex===-1?null:it(l.track)),st=zt();return U.push(st),s.push({id:st,nodeId:"",kind:"image",url:"",label:I,volume:0,shape:T,posX:0,posY:0,scale:1,motionV:2,start:H,duration:Z,track:ot,motionKeys:[],...B}),st};if(d.layer&&w(d.layer.shape,d.layer.label,it(l.start),d.layer.duration??it(l.duration)),d.frameLayers){const T=d.startAbs?0:it(l.start)??0;for(const I of d.layers){const O=w(I.shape,I.label,T+I.start,I.duration,l.track!=null?{}:{});if(I.clientJob){const L=s.findIndex(B=>B.id===O);s[L]=Fe(s[L],I.clientJob)}}if(d.shakeAt!=null){const I=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 H=Math.abs(B.start+B.duration-I)<.05,Z=Math.abs(B.start-I)<.05;if(!H&&!Z)continue;const ot=H?Math.max(0,B.duration-.25):0,st=H?B.duration:Math.min(B.duration,.4);if(st-ot>=.2)try{s[L]={...B,...fi(B,{amount:H?.3:.45,freq:16,from:ot,to:st,seed:Math.round(I*1e3)+L})}}catch{}}}}else if(d.layers){const T=n.W||1280,I=n.H||720,O=d.layers.map(H=>w(H.shape,H.label,it(l.start),it(l.duration),H.place??{})),L=H=>s.findIndex(Z=>Z.id===O[H]);d.layers.forEach((H,Z)=>{H.anchor!=null&&(dr(s),s[L(Z)]=Ba(s,s[L(Z)],{anchor:H.anchor,box:H.box,W:T,H:I}))});const B=Ul(s,O,T,I);if(d.layers.forEach((H,Z)=>{H.parent!=null&&H.parent!==Z&&(dr(s),s[L(Z)]=Ba(s,s[L(Z)],{parentClipId:O[H.parent],W:T,H:I}))}),d.camera){const H=ut(it(l.start)??0),Z=ut(it(l.duration)??1),{track:ot}=Kt(s,r,H,H+Z,null),st=zt();s.push(Cr({id:st,track:ot,start:H,duration:Z,label:"Camera 2D"})),U.push(st);const Y=s.length-1;s[Y]=Yl(s[Y],d.camera.preset,{W:T,H:I,amount:d.camera.amount??1}),O.forEach((ct,mt)=>{d.layers[mt].parent==null&&(dr(s),s[L(mt)]=Ba(s,s[L(mt)],{parentClipId:st,W:T,H:I}))})}dr(s),d.layers.forEach((H,Z)=>{if(H.motion){const{preset:ot,...st}=H.motion;s[L(Z)]=Yl(s[L(Z)],ot,{...st,W:T,H:I})}}),s=Fs(s,B,T,I)}if(d.paper){const T=s.find(I=>tw(I)&&I.start<=d.paper.start+1e-6&&I.start+I.duration>=d.paper.start+d.paper.duration-1e-6&&!r[I.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=Ub(l),w=n.W||1280,T=n.H||720;if(l.op==="rigLayer"){const Z=y(d.clipId);if(!Z||Z.kind==="audio")throw Error("Clip not found");if(r[Z.track]?.locked)throw Error("That layer is locked");const ot=Object.hasOwn(l,"parentClipId")?l.parentClipId:d.parentClipId,st=ot===void 0?void 0:ot===null||ot===""?null:ot;if(st===void 0&&d.anchor==null)throw Error("rigLayer needs parentClipId (null = unlink) and / or anchor");dr(s);const Y=Math.max(0,Math.min(Z.duration,(it(d.at)??Z.start)-Z.start)),ct=Z.shape?.v===2?Zg(Z):null,mt=Ul(s,Ou(s,[Z.id]),w,T),Q=s.indexOf(Z);s[Q]=Ba(s,Z,{parentClipId:st,anchor:d.anchor,at:Y,W:w,H:T,box:ct}),s=Fs(s,mt,w,T),h.push(`rigLayer: ${Z.label}${st!==void 0?` → ${st?y(st)?.label:"no parent"}`:""}`);break}const I=Array.isArray(d.clipIds)&&d.clipIds.length?d.clipIds:d.clipId?[d.clipId]:null;if(!I)throw Error("animateLayer needs clipId (or clipIds)");if(!Yn[d.preset])throw Error(`animateLayer preset: ${Object.keys(Yn).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");dr(s);const H=Ul(s,Ou(s,I.map(Z=>y(Z)?.id).filter(Boolean)),w,T);if(d.camera===!0){if(!fp.includes(d.preset))throw Error(`animateLayer camera: true takes a camera preset (${fp.join(" | ")})`);const Z=I.map(dt=>{const vt=y(dt);if(!vt||vt.kind==="audio")throw Error("Clip not found");if(r[vt.track]?.locked)throw Error("That layer is locked");return vt}),ot=Math.min(...Z.map(dt=>dt.start)),st=Math.max(...Z.map(dt=>dt.start+dt.duration)),{track:Y}=Kt(s,r,ut(ot),ut(st),null),ct=zt();s.push(Cr({id:ct,track:Y,start:ut(ot),duration:ut(st-ot),label:"Camera 2D"})),U.push(ct);const mt=s.length-1,Q=Math.max(0,(it(d.at)??ot)-ot),nt=it(d.duration);s[mt]=Yl(s[mt],d.preset,{W:w,H:T,amount:B??1,a:Q,b:nt!==null?Math.min(st-ot,Q+nt):st-ot});for(const dt of Z)if(!dt.parentId){dr(s);const vt=s.findIndex(It=>It.id===dt.id);s[vt]=Ba(s,s[vt],{parentClipId:ct,W:w,H:T})}dr(s),s=Fs(s,H,w,T),h.push(`animateLayer ${d.preset}: Camera 2D over ${Z.length} layer(s)`);break}I.forEach((Z,ot)=>{const st=y(Z);if(!st||st.kind==="audio")throw Error("Clip not found");if(r[st.track]?.locked)throw Error("That layer is locked");const Y=Math.max(0,Math.min(st.duration-1/ve,(it(d.at)??st.start)-st.start)),ct=it(d.duration),mt=L??Yn[d.preset].period,Q=s.indexOf(st);s[Q]=Yl(st,d.preset,{W:w,H:T,amount:B??1,...L!==null?{period:L}:{},a:Y,b:ct!==null?Math.min(st.duration,Y+ct):st.duration,phase:O?ot*O/mt%1:0})}),s=Fs(s,H,w,T),h.push(`animateLayer ${d.preset}: ${I.length} layer(s)`);break}case"setEasing":case"loopKeys":case"addBounce":{const d=y(l.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");const w=l.property?[l.property]:void 0,T=h$(n.motion),I=(Z,ot)=>Z==null?ot:Math.max(0,Math.min(1,it(Z)??ot)),O=Math.max(.05,Math.min(1,it(l.numberValue)??.5)),L=l.op==="setEasing"&&Array.isArray(l.times)&&l.times.length?l.times:null,B=l.easeIn!=null||l.easeOut!=null,H=L?vx(d,{in:l.easeIn!=null||!B?I(l.easeIn,T.in):null,out:l.easeOut!=null||!B?I(l.easeOut,T.out):null},L,w):l.op==="setEasing"?$x(d,{in:I(l.easeIn,T.in),out:I(l.easeOut,T.out)},w?Ee(d,w[0]).map(Z=>({prop:w[0],time:Z.time})):void 0):l.op==="loopKeys"?Ex(d,["cycle","pingpong","offset"].includes(l.loopMode)?l.loopMode:"cycle",{props:w}):Sx(d,(l.settle??p.settle)==="bounce"?"bounce":"elastic",{amount:O,...w?{props:w}:{}});if(!w&&!L&&l.op==="setEasing")for(const Z of["enter","exit"])d[Z]&&(H[Z]={...d[Z],ease:od([I(l.easeOut,T.out),0,1-I(l.easeIn,T.in),1])});if(!w&&l.op==="addBounce"&&!Object.keys(H).length&&d.enter&&(H.enter={...d.enter,ease:od([.34,1+O*1.2,.64,1])}),!Object.keys(H).length)throw Error(L?"No key at those times (clip-local seconds)":l.op==="addBounce"?"Needs a property with at least 2 keys and room after the last key, or an enter animation":l.op==="setEasing"?"Layer has no keys or enter / exit animation":"Layer has no keys");Object.assign(d,H),h.push(`${l.op}: ${K}`);break}case"matchReference":{const d=o.find(Nt=>Nt.id===l.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(l.picks)?l.picks:Array.isArray(l.items)?l.items:[]).slice(0,I8).map(D8);for(const Nt of w){const _t=o.find(Vt=>Vt.id===Nt.materialId);if(!_t)throw Error(`Không thấy material ${Nt.materialId}`);if(_t.role==="reference"||_t.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(_t.kind))throw Error(`${_t.label||_t.id}: chỉ dùng video / ảnh`)}const T=ut(Math.max(0,it(l.start)??0));let I=l.fromClipId?y(Mt(l.fromClipId)):null,O=null;if(l.fromClipId&&(!I||I.kind!=="audio"))throw Error("fromClipId phải là clip nhạc (audio)");if(I)O=o.find(Nt=>Nt.id===I.nodeId)??null;else{const Nt=o.filter(_t=>_t.kind==="audio"&&_t.role==="music");O=Nt.length===1?Nt[0]:null}let L=null;try{L=O?.beats?BM(O.beats):null}catch{L=null}const B=Nt=>{const _t=o.find(Vt=>Vt.id===Nt);return _t?.kind==="image"?1/0:it(_t?.duration)??1/0},H=I?I.start-(I.inPoint||0)-T:0,Z=Nt=>!I||Nt>=(I.inPoint||0)&&Nt<(I.inPoint||0)+I.duration,ot=L?{...L,beats:L.beats.filter(Z).map(Nt=>Nt+H).filter(Nt=>Nt>=0),drops:L.drops.filter(Z).map(Nt=>Nt+H).filter(Nt=>Nt>=0)}:null,st=(Nt,_t,Vt)=>{const he=o.find(be=>be.id===Nt),ne=be=>Number.isFinite(be?.start)&&Number.isFinite(be?.end)&&be.end>_t&&be.start<Vt;return Array.isArray(he?.words)&&he.words.length?he.words.filter(ne).map(be=>be.word).join(" "):(Array.isArray(he?.transcript)?he.transcript:[]).filter(ne).map(be=>be.text).join(" ")},Y=B8({recipe:d.refRecipe,picks:w,beats:ot,duration:it(l.duration),start:T,sourceDuration:B,copy:l.copy,spoken:st}),ct=T+Y.duration;if(s.length+Y.segments.length+1>Bt)throw Error(`Tối đa ${Bt} clip`);if(ct>Re)throw Error("Vượt giới hạn 20 phút");const Q=!(Nt=>s.some(_t=>_t.kind!=="audio"&&_t.track===Nt&&_t.start<ct-1e-6&&_t.start+_t.duration>T+1e-6))(0)&&!r[0]?.locked?0:Kt(s,r,T,ct,null).track,nt=Math.max(0,Math.min(2,it(l.volume)??(O?0:1))),dt=[];for(const Nt of Y.segments){const _t=o.find(ne=>ne.id===Nt.materialId),Vt=zt();U.push(Vt),dt.push(Vt);const he=_t.kind==="image"?null:it(_t.duration);s.push({id:Vt,nodeId:_t.id,track:Q,start:ut(Nt.start),duration:ut(Nt.duration),inPoint:_t.kind==="image"?0:Nt.inPoint,volume:_t.kind==="image"?0:nt,url:_t.url,..._t.gcsUri?{gcsUri:_t.gcsUri}:{},kind:_t.kind,label:`${_t.label||_t.kind} · ${Nt.role}`,...he!==null?{sourceDuration:he}:{}})}if(O&&!I){const Nt=Ji.find(Vt=>!r[Vt]?.locked&&!s.some(he=>he.track===Vt&&he.start<ct-1e-6&&he.start+he.duration>T+1e-6));if(Nt===void 0)throw Error("Không còn hàng audio trống cho nhạc");const _t=zt();U.push(_t),s.push({id:_t,nodeId:O.id,track:Nt,start:T,duration:ut(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 vt={punch:0,move:0,shake:0,look:0,text:0},It=[];Y.segments.forEach((Nt,_t)=>{const Vt=y(dt[_t]),he=o.find(be=>be.id===Nt.materialId),ne=(be,ir)=>{try{ir(),vt[be]++}catch{It.push(be)}};Nt.move&&ne("move",()=>{Vt.motionKeys=qu(Vt,pc(Nt.move,Vt.duration)),delete Vt.posX,delete Vt.posY,delete Vt.scale,Vt.motionV=2}),Nt.punch&&ne("punch",()=>Object.assign(Vt,u0(Vt,{at:0,duration:Math.min(Qo.maxDuration,Vt.duration),amount:Nt.punch.amount,style:Nt.punch.style,anchor:qc(Vt,he)}))),Nt.shake&&ne("shake",()=>Object.assign(Vt,fi(Vt,{amount:Nt.shake,freq:12,from:0,to:Vt.duration,seed:_t+1}))),Y.look&&ne("look",()=>{const be=[...(Vt.effects||[]).filter(ir=>ir.type!==Y.look.effect),{type:Y.look.effect,amount:Y.look.amount}];if(be.length>yn)throw Error("effects");Vt.effects=be})});const xt=l.specs&&typeof l.specs=="object"?l.specs:{},Et=[];Y.segments.forEach((Nt,_t)=>{if(!_t||!Nt.transition)return;let Vt=xt[Nt.transition];if(!Vt){Et.push(Nt.transition);return}const he=y(dt[_t-1]),ne=y(dt[_t]);try{Vt.id==="match-walk"&&(Vt=qg(Vt,he,ne,o)),s=sf(s,dt[_t-1],Vt,Math.min(Vt.duration,.45*Math.min(he.duration,ne.duration)))}catch{Et.push(Nt.transition)}});const{W:Ct=1280,H:Gt=720}=n,ee=Gt>Ct*1.1,re=ee?Ie.bands.portrait:Ie.bands.landscape,Me=[];if(Y.segments.forEach((Nt,_t)=>{if(!Nt.text)return;const Vt=y(dt[_t]),he=Jc(Vt,o.find(be=>be.id===Nt.materialId),Vt.start+Vt.duration/2,{W:Ct,H:Gt});let ne=Nt.text.placement;he&&!(he.assumed&&ne!=="center")&&y0(re[ne],he,ee)&&(ne=["top","lower","center"].find(be=>!y0(re[be],he,ee))??ne),Me.push({op:"addText",text:Nt.text.text,start:Vt.start,duration:Math.max(.5,Vt.duration),placement:ne,fontFamily:"Anton",fontSize:ee?72:64,color:"#ffffff",styleId:"classic",preset:Nt.energy>=4?"pop-in":"none"})}),Me.length){const Nt=new Set(s.map(Vt=>Vt.id)),_t=Ua(s,Me,o,r,u,{...n,maxOps:Me.length});s=_t.clips,vt.text=Me.length-_t.errors.length;for(let Vt=0;Vt<_t.errors.length;Vt++)It.push("text");for(const Vt of s)Nt.has(Vt.id)||U.push(Vt.id)}const qt=Object.entries(vt).filter(([,Nt])=>Nt).map(([Nt,_t])=>`${_t} ${Nt}`).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`:""}${qt?`; style: ${qt}${Y.look?` (${Y.look.effect})`:""}`:""}${Et.length?` (${Et.length} chuyển cảnh thành cắt thẳng)`:""}${It.length?` (${It.length} style bỏ qua)`:""}`);break}case"multicam":{const d=xI(s,l,o,r,{newId:zt});s=d.clips,U.push(...d.created),h.push(d.note);break}case"kineticEdit":{const d=l.fromClipId?y(Mt(l.fromClipId)):null,w=d&&o.find(xt=>xt.id===d.nodeId);let T=[];if(d&&(T=Sc(d,w?.words?.length?kl(w.words,1/0,af):null).map(Et=>({word:Et.word,start:d.start+Et.start,end:d.start+Et.end}))),!T.length&&typeof(l.text??l.prompt)=="string"&&(T=u5(l.text??l.prompt,it(l.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 I=it(l.start),O=I!=null&&it(l.duration)!=null?I+it(l.duration):null;I!=null&&(T=T.filter(xt=>xt.start>=I-1e-6&&(O==null||xt.start<O)));const L=n.H>n.W*1.1,B=n.brand?.colors??[],H=l.color&&/^#[0-9a-f]{6}$/i.test(l.color)?l.color:B[0]??"#e8141c",Z=T.map(xt=>xt.word).join(" "),ot=typeof l.preset=="string"&&l.preset.startsWith("poox-")?l.preset.slice(5):"auto",st=[...new Set([...C1(Z).industries,...W1(Z),...n.brand?.industry&&n.brand.industry!=="general"?[n.brand.industry]:[]])];let Y=ni[ot]?ot:y5(Z,{industries:st,tone:n.brand?.tone??null,seed:T.length});ot==="auto"&&ni[Y].kind==="scenes"&&!Hg(ni[Y].caption)&&(Y="punch");const ct=F5(T,{palette:{accent:H,dark:"#0b0b0d",light:"#f4f4f1"},io:Math.max(.08,Math.min(.4,it(l.numberValue)??.16)),portrait:L,orb:!1,seed:1,industry:n.brand?.industry??null,genre:Y,known:xt=>!!Hg(xt)});if(s.length+ct.beats.length+ct.els.length+ct.carriers.length+ct.orbs.length+ct.texture.length+ct.sfx.length>Bt)throw Error(`Kinetic Edit: ${ct.beats.length} nhịp vượt giới hạn ${Bt} clip — chọn đoạn ngắn hơn (start / duration)`);const mt=ct.beats[0].start,Q=Math.max(...ct.beats.map(xt=>xt.start+xt.duration)),nt=[];let dt=s;for(let xt=0;xt<(ct.orbs.length?6:5);xt++){const{track:Et}=Kt(dt,r,mt,Q,null);nt.push(Et),dt=[...dt,{id:`probe${xt}`,kind:"image",track:Et,start:mt,duration:Q-mt}]}const vt=(xt,Et,Ct,Gt,ee,re)=>{const Me=Za(xt,{}),qt=zt();U.push(qt),s.push({id:qt,nodeId:"",kind:"image",url:"",label:ee,volume:0,track:re,start:Ct,duration:Gt,motionKeys:[],motion:Qe({code:D2+xt,params:{...Me.params,...Et},preset:xt})})};ct.beats.forEach((xt,Et)=>vt(xt.preset??"kin-beat",xt.params,xt.start,xt.duration,`Kinetic · ${String(xt.params.text).split(" ").slice(xt.params.n-xt.params.k,xt.params.n).join(" ").slice(0,40)}`,nt[Et%2])),ct.els.forEach(xt=>vt(xt.preset,xt.params,xt.start,xt.duration,`Kinetic · ${xt.library?xt.preset:xt.params.el}`,nt[2])),ct.carriers.forEach(xt=>vt(xt.preset,xt.params,xt.start,xt.duration,`Kinetic · ${xt.preset!=="kin-carry"?xt.preset:xt.params.mode==="line"?"line":"match cut"}`,nt[3])),ct.texture.forEach(xt=>vt("kin-texture",xt.params,xt.start,xt.duration,"Kinetic · grain",nt[4])),ct.orbs.forEach(xt=>vt("kin-orb",xt.params,xt.start,xt.duration,"Kinetic · orb",nt[5]));let It=0;for(const xt of ct.sfx){const Et=vn(xt.id);if(Et)try{s.push(ha(s,r,Et,xt.at,{id:zt()})),It++}catch{}}h.push(`Poox 1.1 (${ct.genre}): ${ct.lines} lines, ${ct.beats.length} beats, ${It} whooshes (${mt.toFixed(1)}–${Q.toFixed(1)} s)`);break}case"parallax":{const d=(l.clipIds||[]).filter(T=>y(T));if(d.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");const w=o8(s,d,{strength:it(l.numberValue)??1});for(const[T,I]of Object.entries(w))Object.assign(y(T),I);h.push(`parallax ${Object.keys(w).length} layers`);break}case"stations":{const d=(l.clipIds||[]).filter(T=>y(T));if(d.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");const w=e8(s,d,u,{style:l.preset??"fly-truck",travel:it(l.duration)??1,spacing:it(l.numberValue)??1.2,swing:l.booleanValue!==!1});for(const[T,I]of Object.entries(w.patches))Object.assign(y(T),I);u=w.camera,h.push(`stations ${l.preset??"fly-truck"}: camera flies through ${w.stations} stations`);break}case"arrange3D":{const d=(l.clipIds||[]).filter(T=>y(T));if(d.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");const w=ub(s,d,l.preset??"wall",{W:n.W||1280,H:n.H||720,spread:it(l.numberValue)??1});for(const[T,I]of Object.entries(w))Object.assign(y(T),I);h.push(`arrange3D ${l.preset??"wall"}: ${Object.keys(w).length} layers`);break}case"cameraTour":{const d=(l.clipIds||[]).filter(I=>y(I)),w=it(l.at)??Math.min(...d.map(I=>y(I).start)),T=Yd(s,d,u,{at:Number.isFinite(w)?w:0,flight:it(l.duration)??1,hold:it(l.numberValue)??1.5,W:n.W||1280,H:n.H||720});u=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=y(l.clipId);if(!d)throw Error(`Không tìm thấy clip ${l.clipId}`);if(r[d.track]?.locked)throw Error("Track đã khóa");const w=typeof l.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(l.color)?l.color:void 0,T=g1(s,r,d,l.preset??"phone",{id:zt(),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=(l.clipIds||[]).filter(T=>y(T));if(d.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");if(y8.includes(l.preset)){const T=w8(s,r,d,u,l.preset,{at:it(l.at)??void 0,newId:zt,W:n.W||1280,H:n.H||720,duration:it(l.duration)??void 0,angle:it(l.numberValue)??void 0,angleTo:it(l.angleTo)??void 0,angleKeys:Array.isArray(l.angleKeys)?l.angleKeys:void 0,axis:l.axis==="y"?"y":l.axis==="x"?"x":void 0,anchor:["center","start","end"].includes(l.anchor)?l.anchor:void 0,media:o});for(const I of T.remove??[]){const O=s.findIndex(L=>L.id===I);O>=0&&s.splice(O,1)}for(const[I,O]of Object.entries(T.patches))Object.assign(y(I),O);for(const I of T.add)s.push(I),U.push(I.id);u=T.camera,h.push(`scene3D ${l.preset}: ${T.add.length} rig layer(s), to ${T.end.toFixed(1)} s`);break}if(mb.includes(l.preset)){const T=typeof l.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(l.color)?l.color:void 0,I=x8(s,r,d,u,l.preset,{at:it(l.at)??void 0,newId:zt,W:n.W||1280,H:n.H||720,duration:it(l.duration)??void 0,color:T,media:o});for(const[O,L]of Object.entries(I.patches))Object.assign(y(O),L);for(const O of I.add)s.push(O),U.push(O.id);u=I.camera,h.push(`scene3D ${l.preset}: ${I.add.length} rig layer(s), to ${I.end.toFixed(1)} s`);break}if(N2.includes(l.preset)){const T=typeof l.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(l.color)?l.color:void 0,I=R2(s,r,d,u,l.preset,{at:it(l.at)??void 0,newId:zt,color:T});for(const[O,L]of Object.entries(I.patches))Object.assign(y(O),L);for(const O of I.add)s.push(O),U.push(O.id);u=I.camera,h.push(`scene3D ${l.preset}: ${I.add.length} device(s), camera to ${I.end.toFixed(1)} s`);break}const w=l8(s,d,u,l.preset??"photo-wall-tour",{at:it(l.at)??void 0,W:n.W||1280,H:n.H||720});for(const[T,I]of Object.entries(w.patches))Object.assign(y(T),I);u=w.camera,h.push(`scene3D ${l.preset??"photo-wall-tour"}: ${Object.keys(w.patches).length} layers, camera to ${w.end.toFixed(1)} s`);break}case"anchorMontage":{s=EI(s,r,{clipIds:l.clipIds,at:it(l.at)??void 0,frames:it(l.numberValue)??void 0,polarity:l.booleanValue===!0,style:l.preset==="strobe"?"strobe":"anchor",newId:zt}),h.push(`montage of ${l.clipIds.length} shots`);break}case"stagger":{const d=(l.clipIds||[]).filter(O=>y(O));if(d.length<2)throw Error("stagger needs at least 2 clipIds");if(d.some(O=>r[y(O).track]?.locked))throw Error("Track đã khóa");const w=Math.max(0,Math.min(10,it(l.numberValue)??.1)),T=["forward","reverse","center","random"].includes(l.order)?l.order:"forward",I=Mx(s,d,w,T,7);for(const O of I){const L=y(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(!wx.includes(l.gridPoint))throw Error("Unknown grid point");const d=l.clipIds?.length?l.clipIds:l.clipId?[l.clipId]:[],w=n.W??1280,T=n.H??720;if(!d.length)throw Error("alignLayers needs clipIds");for(const I of d){const O=y(I);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,l.at!=null?it(l.at)-O.start:0));Object.assign(O,kx(O,n.rectOf?.(O)??xx(O,L,w,T),l.gridPoint,ut(L),w,T))}h.push(`align ${d.length} layer(s) → ${l.gridPoint}`);break}case"physicsDrop":{const d=l.clipIds?.length?l.clipIds:l.clipId?[l.clipId]:[];if(!d.length)throw Error("physicsDrop needs clipIds");for(const O of d){const L=y(O);if(!L)throw Error("Clip not found");if(r[L.track]?.locked)throw Error("Track đã khóa")}const w=it(l.at)??Math.min(...d.map(O=>y(O).start)),T=it(l.numberValue),I=bx(s,d,{at:w,W:n.W??1280,H:n.H??720,rectOf:n.rectOf,mode:l.mode==="above"?"above":"here",bounciness:T!=null?Math.max(0,Math.min(.95,T)):"normal",duration:it(l.duration)??3,walls:l.booleanValue===!0});s=s.map(O=>d.includes(O.id)?I.clips.find(L=>L.id===O.id)??O:O),h.push(`physics drop: ${d.length} layer(s) from ${ut(w)}s`);break}case"applyPalette":{const d=l.clipIds?.length?l.clipIds:l.clipId?[l.clipId]:[];if(!d.length)throw Error("applyPalette needs clipIds");for(const w of d){const T=y(w);if(!T)throw Error("Clip not found");if(r[T.track]?.locked)throw Error("Track đã khóa");Object.assign(T,yx(T,l.colors))}h.push(`palette (${(l.colors||[]).length} colours) → ${d.length} layer(s)`);break}case"makeSeamless":{if(l.booleanValue===!1){h.push("seamless: off");break}const d=it(l.numberValue),w=Eh(s,r,u,{overlap:d!==null&&d>0&&d<=.6?d:void 0,accent:typeof l.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(l.color)?l.color:void 0,newId:zt,...c});s=w.clips,u=w.camera,h.push(`seamless: ${w.notes.join("; ")}`);break}case"setJoin":{const d=z6(s,r,u,{join:it(l.numberValue),style:l.preset,duration:it(l.duration),ease:l.ease,newId:zt,...c});if(s=d.clips,u=d.camera,h.push(`join ${it(l.numberValue)}: ${d.style}${typeof l.text=="string"&&l.text.trim()?` — ${l.text.trim().slice(0,200)}`:""}${d.notes.length>1?` (${d.notes.slice(1).join("; ")})`:""}`),l.booleanValue===!0&&typeof l.prompt=="string"&&l.prompt.trim().length>=6){if(g.length>=rc)throw Error(`At most ${rc} Claude motion jobs per request`);g.push({join:it(l.numberValue),prompt:l.prompt.trim().slice(0,1200)})}break}case"joinCut":{s=F2(s,l.clipId,l.preset,{duration:it(l.duration)??void 0,color:typeof l.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(l.color)?l.color:void 0}),h.push(l.preset==="none"?`join removed: ${K}`:`join ${l.preset}: ${K}`);break}case"silhouetteReveal":{const d=L2(s,r,l.clipId,{duration:it(l.duration)??void 0,newId:zt});s=d.clips,E.push({clipId:d.copyId,mode:l.preset==="object"?"object":"person"}),h.push(`silhouette reveal: ${K}`);break}case"setJoinMotion":{const d=L6(s,r,u,{join:it(l.numberValue),code:l.code,params:l.params??{},prompt:l.prompt??"",duration:it(l.duration),newId:zt,...c});s=d.clips,u=d.camera,h.push(`join ${it(l.numberValue)}: Claude Motion layer`);break}case"separateText":{const d=Bd(s,{tracks:r});s=d.clips,h.push(`text guard: ${d.notes.length?d.notes.join("; "):"no overlapping text"}`);break}case"precompose":{const d=Jt(l),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(!y(O))throw Error(`Không tìm thấy clip ${O}`);let T=zt();for(;y(T);)T=zt();const I=Xx(s,w,{id:T,label:typeof d.label=="string"&&d.label.trim()?d.label.trim().slice(0,80):Ux(s),tracks:r,W:n.W||1280,H:n.H||720});s=I.clips,U.push(I.id),h.push(`precompose ${w.length} layer(s) → comp ${y(I.id).label} (${I.id}) on track ${I.track}`);break}case"uncompose":{const d=y(l.clipId);if(!Ff(d))throw Error("uncompose needs a comp layer (clipId)");const w=Hx(s,d.id,{tracks:r,W:n.W||1280,H:n.H||720,newId:zt});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(l.track)!==null?[it(l.track)]:[...new Set(s.map(w=>w.track))]).filter(w=>!r[w]?.locked);for(const w of d){let T=0;for(const I of s.filter(O=>O.track===w).sort((O,L)=>O.start-L.start))I.start=ut(T),T=ut(T+I.duration)}h.push(`compact ${it(l.track)!==null?"track "+l.track:"tất cả track"}`);break}case"courseEdit":throw Error(l.error||"courseEdit could not be built");case"framedEdit":throw Error(l.error||"framedEdit could not be built");case"appAdEdit":if(l.note&&!l.error){h.push(`appAdEdit: ${l.note}`);break}throw Error(l.error||"appAdEdit could not be built");case"updateMap":{const d=y(l.clipId);if(!d?.geo)throw Error("updateMap needs an animated map clip (addMap)");if(Array.isArray(l.places)&&!l.placesResolved)throw Error("updateMap places must be resolved first");const w=d.geo,T=w.plan??{},I=Array.isArray(l.places)?l.places:ef(w),O=(st,Y)=>st??Y,L=$1({places:I,duration:d.duration,style:O(l.mapStyle,w.style),route:O(l.route,T.route??!!w.route),routeLook:O(l.routeLook,T.routeLook??w.route?.look??"saber"),color:O(l.color,T.color??w.route?.color??"#ff3b30"),pins:O(l.pins,T.pins??w.pins.length>0),drawnRoute:l.routePoints!==void 0?l.routePoints:T.drawnRoute,drawnAreas:l.areas!==void 0?l.areas:T.drawnAreas,icons:Array.isArray(l.icons)?l.icons:w.icons??null}),B=l.models!==void 0?Gg(l.models,o,I)??[]:w.models,H=l.images!==void 0?Kg(l.images,o,I)??[]:w.images??[],Z=l.buildings===void 0||l.buildings===null?w.buildings:l.buildings,ot=s.indexOf(d);s[ot]={...d,geo:nf({...L,models:B,images:H,...w.hd?{hd:w.hd}:{},...Z?{buildings:Z}:{}},d.duration)},h.push(`map ${d.id}: ${L.stops.length} stop(s)${s[ot].geo.buildings?", 3D buildings":""}${L.route?`, ${L.route.look} route`:""}${L.areas.length?`, ${L.areas.length} area(s)`:""}${B.length?`, ${B.length} model(s)`:""}${H.length?`, ${H.length} picture(s)`:""}${L.icons?.length?`, ${L.icons.length} icon(s)`:""}`);break}case"annotateMap":case"flyTo":case"setMapBounds":{const d=Jt(l),w=y(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=jx(d.bounds)),l.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 I=n.W||1280,O=n.H||720;if(l.op==="flyTo"){const B=Tx(w,d,{W:I,H:O,cam:u});B.camera?u=B.camera:Object.assign(w,B.patch),h.push(B.applied);break}const L=Ox(d,{base:w,W:I,H:O,cam:u,materials:o});if(s.length+L.layers.length>Bt)throw Error(`Tối đa ${Bt} clip`);for(const B of L.layers){const{track:H}=Kt(s,r,B.start,B.start+B.duration),Z=zt();if(U.push(Z),d.kind==="icon"&&w.kind==="video"){const[ot,st]=B.mapAnno.follow,Y=.07,ct={x:Math.max(0,Math.min(1-2*Y,ot-Y)),y:Math.max(0,Math.min(1-2*Y,st-Y)),w:2*Y,h:2*Y},mt={...B,id:Z,track:H},Q=wl(mt,w,{region:ct,mode:d.follow==="point"?"point":"scene",at:B.start});s.push({...mt,...Q}),S.push({clipId:Z,...Q.pendingPin})}else s.push({...B,id:Z,track:H})}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=Pf(s,u,n.W||1280,n.H||720),h.push("map items re-glued to the camera");break}case"meshWarp":case"puppet":case"liquify":case"displace":case"clearDistort":{const d=Jt(l),w=y(d.clipId);if(!w)throw Error(`Không tìm thấy layer ${d.clipId}`);if(!Vp(w))throw Error("Distort needs a video / picture / text / shape layer");const T={...w.distort||{}};if(l.op==="meshWarp"){const O=Math.round(it(d.rows)??3),L=Math.round(it(d.cols)??3),B=O*L,H=(Array.isArray(d.keys)?d.keys:[]).map(Z=>{const ot=Z?.offsets??Z?.d;if(ot!=null&&(!Array.isArray(ot)||ot.length!==B))throw Error(`meshWarp offsets: ${B} [dx, dy] pairs (rows × cols, row by row)`);return{t:it(Z?.t)??0,d:ot==null?new Array(B*2).fill(0):ot.flatMap(st=>Array.isArray(st)?[Number(st[0]),Number(st[1])]:[Number(st),NaN])}});T.mesh={rows:O,cols:L,keys:H.sort((Z,ot)=>Z.t-ot.t)},h.push(`mesh warp ${K}: ${O}×${L}, ${H.length} key${H.length===1?"":"s"}`)}else if(l.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 ${K}: ${d.pins.length} pin${d.pins.length===1?"":"s"}`)}else if(l.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(!of.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 ${of.join(" | ")}, points [[u,v]…] (0..1 of the picture)`);T.liquify=P2(d.reset?null:T.liquify,d.strokes,{aspect:it(d.aspect)??1}),h.push(`liquify ${K}: ${d.strokes.length} stroke${d.strokes.length===1?"":"s"}`)}else if(l.op==="displace")if(d.mapClipId==null)delete T.displace,h.push(`displacement map off ${K}`);else{const O=y(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 ${K} ← ${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 ${K}${O?` (${O})`:""}`)}const I=Gp(rf(T));I?w.distort=I:delete w.distort,jn(w);break}default:throw Error(`Op không hỗ trợ: ${l?.op}`)}for(const d of[l?.clipId,...Array.isArray(l?.clipIds)?l.clipIds:[]]){const w=typeof d=="string"?y(d):null;if(Ff(w)){const T=nx(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=pt;d<U.length;d++)x.push(D)}catch(K){U.length=pt,v.push(D),f.push(`${l?.op||"?"}: ${K.message}`)}}if(s=t3(s),s.some(D=>D.mapAnno?.follow)&&(JSON.stringify(u)!==JSON.stringify(a)||rt.some(D=>D?.op==="flyTo"||D?.op==="move"||D?.op==="setPropertyKeys"))&&(s=Pf(s,u,n.W||1280,n.H||720)),U.length){const D=new Set(U.filter(pt=>!s.find(yt=>yt.id===pt)?.mapAnno)),q=Bd(s,{tracks:r,movable:D});q.notes.length&&(s=q.clips,h.push(`text guard: ${q.notes.join("; ")}`))}return F&&!m.length&&m.push({op:"setExportFormat",aspectRatio:F}),{clips:s,tracks:r,actions:m,motionJobs:g,applied:h,errors:f,failed:v,createdBy:x,camera:u,...N?{pins:N}:{},...V?{markers:V}:{},...G!==void 0?{exportRange:G}:{},...E.length?{cutouts:E}:{},...$.length?{mattes:$}:{},...k.length?{lookups:k}:{},...S.length?{surfacePins:S}:{}}}function gj(t,e,o={in:.5,out:.5},r={}){const a=t.find(v=>v.id===e?.clipId);if(!a||a.kind==="audio"||a.kind==="model"||e.preset==="none")return null;const n=a.start+a.duration,i=v=>v.id!==a.id&&v.kind!=="audio"&&v.kind!=="model"&&!r[v.track]?.locked&&Math.abs(v.start-n)<=.1,c=t.find(v=>i(v)&&v.track===a.track)??t.filter(i).sort((v,x)=>Math.abs(v.start-n)-Math.abs(x.start-n)||x.track-v.track)[0]??null,u=`${e.transitionId??""} ${e.spec?.name??""} ${e.preset??""} ${(e.spec?.tags??[]).join(" ")}`.toLowerCase(),p=/slide|push|wipe|whip|trượt|đẩy/.test(u)?"slide":/zoom|phóng/.test(u)?"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=p==="slide"?"slide-left":p==="zoom"?"zoom-in":"fade",m=p==="slide"?"slide-left":p==="zoom"?"zoom-out":"fade";return{clips:t.map(v=>v.id===a.id?Oc(v,"exit",f,{duration:h}):c&&v.id===c.id?Oc(v,"enter",m,{duration:h}):v),note:`${f} out${c?` / ${m} in on ${c.label||c.id}`:""} (no footage cut to transition)`}}const yj=new Set(["addClip","placeBehindPerson","cutOutObject","annotateMap",...lw]);function uO(t,e,o=[],r={},a=null,n={}){const i=Math.min(Ks,n?.maxOps??Gs);let c=(Array.isArray(e)?e:[]).slice(0,i).map((p,s)=>({op:p,index:s}));const u=[];for(let p=0;p<=i+1;p++){const s=Ua(t,c.map(k=>k.op),o,r,a,n);if(!s.errors.length){if(u.length&&c.some(k=>Ys.includes(k.op?.op))){for(const k of c.filter(y=>Ys.includes(y.op?.op)))u.push({index:k.index,op:k.op?.op,error:"skipped: part of the plan could not be applied"});c=c.filter(k=>!Ys.includes(k.op?.op));continue}return u.sort((k,y)=>k.index-y.index),{ops:c.map(k=>k.op),skipped:u,result:s}}const h=new Set(s.failed),f=new Map(s.failed.map((k,y)=>[k,s.errors[y]])),m=new Set(s.createdBy),g=c.map((k,y)=>y).filter(k=>m.has(k)||h.has(k)&&yj.has(c[k].op?.op)),v=k=>[k?.clipId,...Array.isArray(k?.clipIds)?k.clipIds:[]].filter(y=>typeof y=="string"&&/^new:\d+$/.test(y)),x=k=>g[Number(k.slice(4))-1];let E,$,S;for(let k=new Set;;){E=new Set([...h].filter(A=>!k.has(A))),S=new Set;for(let A=!0;A;)A=!1,c.forEach((z,j)=>{!E.has(j)&&v(z.op).some(P=>x(P)!==void 0&&E.has(x(P)))&&(E.add(j),S.add(j),A=!0)});const y=g.filter(A=>!E.has(A));$=A=>{if(typeof A!="string"||!/^new:\d+$/.test(A))return A;const z=x(A);return z===void 0?A:`new:${y.indexOf(z)+1}`};const C=[...E].filter(A=>h.has(A)&&!S.has(A)&&!k.has(A)&&v(c[A].op).some(z=>$(z)!==z));if(!C.length)break;C.forEach(A=>k.add(A))}for(const k of[...E].sort((y,C)=>y-C))u.push({index:c[k].index,op:c[k].op?.op??"?",error:S.has(k)?`${c[k].op?.op??"?"}: targets a layer that could not be created`:f.get(k)});if(c=c.flatMap((k,y)=>E.has(y)?[]:[{index:k.index,op:k.op&&(typeof k.op.clipId=="string"||Array.isArray(k.op.clipIds))?{...k.op,...typeof k.op.clipId=="string"?{clipId:$(k.op.clipId)}:{},...Array.isArray(k.op.clipIds)?{clipIds:k.op.clipIds.map($)}:{}}:k.op}]),!c.length)break}return u.sort((p,s)=>p.index-s.index),{ops:[],skipped:u,result:null}}function cw(t,e,o,{insert:r=!1,makeId:a=zt,tracks:n={}}={}){if(!Array.isArray(e)||!e.length)return{clips:t,pasted:[]};if(t.length+e.length>Bt)return{clips:t,pasted:[],error:`Tối đa ${Bt} clip`};if(e.some(s=>n[s.track]?.locked))return{clips:t,pasted:[],error:"Track đã khóa"};const i=Math.min(...e.map(s=>s.start)),c=Math.max(0,Number(o)||0),u=e.map(s=>({...s,id:a(),start:ut(c+(s.start-i))}));let p=t.map(s=>({...s}));if(r){const s={};for(const h of u)s[h.track]=Math.max(s[h.track]||0,ut(h.start+h.duration-c));for(const h of p)s[h.track]&&h.start>=c-1/(2*ve)&&(h.start=ut(h.start+s[h.track]))}return p=[...p,...u],p.some(s=>s.start+s.duration>Re)?{clips:t,pasted:[],error:"Vượt giới hạn 20 phút"}:{clips:p,pasted:u.map(s=>s.id)}}let bj=0;function zt(){try{return crypto.randomUUID()}catch{return`op-${Date.now()}-${bj++}`}}export{I$ as $,og as A,E3 as B,Oj as C,ar as D,pT as E,hm as F,nv as G,ay as H,ov as I,Zj as J,qM as K,f4 as L,K3 as M,$d as N,qj as O,ni as P,Cj as Q,w$ as R,pd as S,T1 as T,xT as U,V4 as V,vT as W,kT as X,f$ as Y,M$ as Z,S$ as _,w3 as a,jS as a$,ET as a0,eE as a1,fo as a2,$I as a3,Z0 as a4,J0 as a5,EI as a6,Dr as a7,mI as a8,pI as a9,ey as aA,Kc as aB,dT as aC,_j as aD,KT as aE,GT as aF,VT as aG,fT as aH,mT as aI,gT as aJ,u$ as aK,Fb as aL,Yn as aM,Ru as aN,eh as aO,as as aP,qT as aQ,ST as aR,$h as aS,T$ as aT,vh as aU,h$ as aV,yT as aW,bT as aX,P0 as aY,jT as aZ,CT as a_,Y0 as aa,vy as ab,TT as ac,OT as ad,zT as ae,s4 as af,i4 as ag,lT as ah,Go as ai,jv as aj,iT as ak,cT as al,sT as am,Fv as an,eT as ao,xh as ap,Ty as aq,oT as ar,rT as as,Cv as at,aT as au,nT as av,gi as aw,ud as ax,Qp as ay,r4 as az,Aj as b,Xy as b$,Wb as b0,eC as b1,Vu as b2,JT as b3,lC as b4,C$ as b5,_n as b6,Pd as b7,Ld as b8,_y as b9,_8 as bA,NT as bB,N4 as bC,Kj as bD,P6 as bE,ev as bF,Lm as bG,l$ as bH,Fj as bI,V1 as bJ,MT as bK,Vj as bL,uO as bM,Gj as bN,Pj as bO,Lj as bP,S4 as bQ,EM as bR,xM as bS,uy as bT,o6 as bU,Um as bV,r6 as bW,a6 as bX,nM as bY,iM as bZ,Qo as b_,p8 as ba,db as bb,fb as bc,k8 as bd,LT as be,pb as bf,w8 as bg,l8 as bh,x8 as bi,ub as bj,Yd as bk,FT as bl,$8 as bm,QS as bn,PT as bo,cb as bp,o8 as bq,e8 as br,p5 as bs,Qa as bt,Nj as bu,G8 as bv,RT as bw,Eb as bx,ll as by,xb as bz,jj as c,cv as c$,Q1 as c0,Dj as c1,IT as c2,Rj as c3,ha as c4,J5 as c5,GM as c6,xm as c7,vd as c8,Uj as c9,E$ as cA,cw as cB,Hb as cC,cO as cD,lO as cE,eO as cF,sO as cG,ij as cH,rO as cI,nO as cJ,aO as cK,iO as cL,QT as cM,tO as cN,Ka as cO,hT as cP,t$ as cQ,BS as cR,ej as cS,N0 as cT,_S as cU,lu as cV,De as cW,fl as cX,Wc as cY,tT as cZ,Jj as c_,Mm as ca,Yj as cb,Xj as cc,np as cd,O0 as ce,wT as cf,Ks as cg,e4 as ch,vn as ci,X5 as cj,Bj as ck,VM as cl,Vm as cm,Gm as cn,$T as co,lM as cp,AT as cq,d4 as cr,wy as cs,lm as ct,_T as cu,ZT as cv,hd as cw,oO as cx,pO as cy,iw as cz,Tj as d,Qj as d0,dA as d1,HT as d2,UT as d3,XT as d4,Np as d5,YT as d6,WT as d7,uT as d8,Hc as d9,_v as da,DT as db,BT as dc,L3 as e,R3 as f,ry as g,b4 as h,zj as i,D4 as j,v4 as k,g4 as l,Wj as m,E4 as n,CM as o,M3 as p,Z4 as q,J4 as r,p4 as s,Hj as t,Q4 as u,Ly as v,cm as w,Ua as x,ib as y,Q0 as z};