clipoox-render 0.4.5 → 0.4.6

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 (115) hide show
  1. package/package.json +1 -1
  2. package/scripts/render-local.mjs +999 -779
  3. package/web/assets/{FxEmbed-DbfuM8Yo.js → FxEmbed-ROS6C_HI.js} +1 -1
  4. package/web/assets/{MotionEmbed-CBQ-8Tzh.js → MotionEmbed-E2hCysi-.js} +1 -1
  5. package/web/assets/{PluginStore-OOEx0lP5.js → PluginStore-CwUSpwPp.js} +1 -1
  6. package/web/assets/{ShotComposer-Cng515xa.js → ShotComposer-DLxWpdYH.js} +8 -8
  7. package/web/assets/{TemplateEmbed-hjwM2b0o.js → TemplateEmbed-qG1AXdtf.js} +1 -1
  8. package/web/assets/{TimelinePlugins-D-NakABP.js → TimelinePlugins-CB1b6-Cb.js} +3 -3
  9. package/web/assets/{TimelineShotFx-D3kGhHN3.js → TimelineShotFx-CyHTgJHj.js} +2 -2
  10. package/web/assets/{TransitionEmbed-DR26yI3a.js → TransitionEmbed-Dym9P7--.js} +1 -1
  11. package/web/assets/{Whiteboard-BhxY0D0Z.js → Whiteboard-BdGjJZXW.js} +1 -1
  12. package/web/assets/{aerial-BisYSXzG.js → aerial-yLD_gDzw.js} +2 -2
  13. package/web/assets/{agentTools-CPFQeiDP.js → agentTools-B7g6tXTR.js} +2 -2
  14. package/web/assets/{aiInbetween-AOOM1e6p.js → aiInbetween-6eKDYbYS.js} +2 -2
  15. package/web/assets/{analyzerRun-Dtp2o7gT.js → analyzerRun-Cr-_79RH.js} +1 -1
  16. package/web/assets/{analyzerSandbox-BG_3Cea1.js → analyzerSandbox-N92T6amg.js} +1 -1
  17. package/web/assets/{api-BFN7blbw.js → api-Dnl2uaKO.js} +3 -3
  18. package/web/assets/auraTrack-C8eAEIWQ.js +1 -0
  19. package/web/assets/{breakthrough-0qFpZW-V.js → breakthrough-DSiuVwEX.js} +2 -2
  20. package/web/assets/{cameraPresets-eK3mP7qb.js → cameraPresets-Cfn7qhXK.js} +1 -1
  21. package/web/assets/{cameraTracker-BAQHuTV-.js → cameraTracker-DHdF8Zqx.js} +5 -5
  22. package/web/assets/{captionLayout-CWPcbid-.js → captionLayout-cckQ7p-t.js} +1 -1
  23. package/web/assets/{clientExport-DvpTTndR.js → clientExport-pkLbOmEF.js} +1 -1
  24. package/web/assets/{clientJobs-CIrYTMpn.js → clientJobs-CcsLDqFM.js} +2 -2
  25. package/web/assets/{depthEstimate-B7D7cGCl.js → depthEstimate-Cav4MmQ1.js} +1 -1
  26. package/web/assets/{directorTools-CJD4Huqk.js → directorTools-DMsatulF.js} +1 -1
  27. package/web/assets/{distortFrames-BLt1icUb.js → distortFrames-D_v-aSVO.js} +2 -2
  28. package/web/assets/{distortGL-BA5molk-.js → distortGL-vhnBRB59.js} +1 -1
  29. package/web/assets/domino-DBrinEUu.js +1 -0
  30. package/web/assets/{editTools-NKLsWZD1.js → editTools-BNnAvCw-.js} +1 -1
  31. package/web/assets/{engine-DioUF2mX.js → engine-Co-ivzlQ.js} +1 -1
  32. package/web/assets/{exportGlb-BOdI9cVS.js → exportGlb-D3PrWUvi.js} +1 -1
  33. package/web/assets/{faceTracker-D7CbF-qX.js → faceTracker-ClR-lS6Y.js} +1 -1
  34. package/web/assets/fightDirector-BlpVAURl.js +1 -0
  35. package/web/assets/{fightDrama-DIPcRKnc.js → fightDrama-BK0QidpM.js} +2 -2
  36. package/web/assets/{focusTool-vfabPqQ5.js → focusTool-sVOb2GGS.js} +1 -1
  37. package/web/assets/{frameSink-DYs2gTzq.js → frameSink-CSRqCnwI.js} +3 -3
  38. package/web/assets/{glTransitionSources.generated-DM5sRMX2.js → glTransitionSources.generated-q0H-ZbnZ.js} +2 -2
  39. package/web/assets/{gpuCompose-DbnZuelB.js → gpuCompose-B5bgbHdQ.js} +1 -1
  40. package/web/assets/{gpuExport-CQ7ZhpsX.js → gpuExport-oA2mUsdm.js} +7 -7
  41. package/web/assets/{handMatte-DIbMuqCu.js → handMatte-Dj2taFoC.js} +1 -1
  42. package/web/assets/handTracker-c6_rvuwA.js +2 -0
  43. package/web/assets/i18n-C9zFX25m.js +3 -0
  44. package/web/assets/{index-BfrDwjDI.js → index-Ds_8isyf.js} +1 -1
  45. package/web/assets/{layer-worker-DK67WH1a.js → layer-worker-ClVZG6ZW.js} +3 -3
  46. package/web/assets/library-BK0QVG4O.js +1 -0
  47. package/web/assets/{lottieLayer-C2YbiXhK.js → lottieLayer-Cv8ub9f6.js} +1 -1
  48. package/web/assets/{main-B27kf5aL.css → main-B_MAOvi6.css} +1 -1
  49. package/web/assets/{main-BKatDoGw.js → main-CwrkBJ63.js} +104 -104
  50. package/web/assets/{mapBake-C-G7WpFM.js → mapBake-DtQboFIX.js} +1 -1
  51. package/web/assets/{maskTrack-LMrwm5ub.js → maskTrack-D4QZfMWc.js} +1 -1
  52. package/web/assets/{matteFixRun-B38CbeEt.js → matteFixRun-CytaeRzS.js} +1 -1
  53. package/web/assets/{objectLocate-CKi3OTnL.js → objectLocate-XuAcemlO.js} +1 -1
  54. package/web/assets/{objectSegmenter-CziPuM61.js → objectSegmenter-D66spD7o.js} +1 -1
  55. package/web/assets/{objectTrack.worker-b7DJ-ub6.js → objectTrack.worker-BZS6WZ6l.js} +547 -327
  56. package/web/assets/{pathTracer-bqau16sX.js → pathTracer-DykgPkkh.js} +2 -2
  57. package/web/assets/{pendingMatte-CQb7jPg1.js → pendingMatte-BWBIWajI.js} +2 -2
  58. package/web/assets/{personAi-CQntGDqK.js → personAi-EhBknW6X.js} +2 -2
  59. package/web/assets/{personHq-B1c0QVJT.js → personHq-Ca351o06.js} +2 -2
  60. package/web/assets/{plateCamera-D7iLiNBy.js → plateCamera-BcdXD1uI.js} +1 -1
  61. package/web/assets/{plateCameraMatch-BM88dx-a.js → plateCameraMatch-GPZl1fQQ.js} +2 -2
  62. package/web/assets/{plateFollow-4iGUDTu1.js → plateFollow-CJUilsNV.js} +2 -2
  63. package/web/assets/{plateMatte-zTyuHHqh.js → plateMatte-CoEoVjxZ.js} +2 -2
  64. package/web/assets/{pluginAutomation-DSg-sYLF.js → pluginAutomation-DAPHWZPN.js} +1 -1
  65. package/web/assets/{poseTracker-DZl8l2qS.js → poseTracker-CzEKvJph.js} +1 -1
  66. package/web/assets/{productTools-B-jh8ukh.js → productTools-ce-zyZO0.js} +2 -2
  67. package/web/assets/remote-8XzEAnAJ.js +974 -0
  68. package/web/assets/{rigTrack-XaMj1yaH.js → rigTrack-DMyqb0pb.js} +1 -1
  69. package/web/assets/{rotoMaskStore-DdpmT9C3.js → rotoMaskStore-pE1AIt3I.js} +1 -1
  70. package/web/assets/{rotoMatte-i-cJTYmK.js → rotoMatte-7b7Ow64f.js} +1 -1
  71. package/web/assets/{rotoscope-DqRSWmHR.js → rotoscope-BUqNTKLd.js} +1 -1
  72. package/web/assets/{sceneTrack-DIPzBmMK.js → sceneTrack-CA21MCOP.js} +1 -1
  73. package/web/assets/{sceneTrack-Bbov7zET.js → sceneTrack-DlAH5s74.js} +1 -1
  74. package/web/assets/{sceneTrack.worker-Bav9h0pv.js → sceneTrack.worker-COlhlHRe.js} +547 -327
  75. package/web/assets/{shot-worker-m-q77W9f.js → shot-worker-DL1ZoIym.js} +1 -1
  76. package/web/assets/{shotFxAgent-DIMS7BGA.js → shotFxAgent-DqngnGFb.js} +1 -1
  77. package/web/assets/{skin-DrUzJE1u.js → skin-xFScwS3T.js} +1 -1
  78. package/web/assets/{spark.module-Y1SEI8Xz.js → spark.module-DjaIF6J1.js} +1 -1
  79. package/web/assets/{spellDuel-DNnyQDVr.js → spellDuel-BYNtnE8f.js} +2 -2
  80. package/web/assets/{store-GFMJzaWS.js → store-CpqHUcA2.js} +1 -1
  81. package/web/assets/{surfaceLight-C--moyc9.js → surfaceLight-C7YI9SV8.js} +1 -1
  82. package/web/assets/{surfacePin-B4-1UqXD.js → surfacePin-CzpUj1Cw.js} +2 -2
  83. package/web/assets/{textAnimators-BVXTl8bU.js → textAnimators-B9vO_hbP.js} +1 -1
  84. package/web/assets/{thumb-CTfDJgLp.js → thumb-BTFsBS1u.js} +1 -1
  85. package/web/assets/{timeline3d-Dn7PqmEe.js → timeline3d-DrFaMPPB.js} +2 -2
  86. package/web/assets/{timeline3dExport-DCOr6ARB.js → timeline3dExport-Uo0S0CR0.js} +1 -1
  87. package/web/assets/{timelineComp-Dx_kED5V.js → timelineComp-i-zdaoB2.js} +1 -1
  88. package/web/assets/timelineOps-DSSaDsU2.js +525 -0
  89. package/web/assets/{timelineProps-eYgO6gs5.js → timelineProps-0v-s69pw.js} +1 -1
  90. package/web/assets/{timelineText-RKyRP988.js → timelineText-DurRhyuh.js} +1 -1
  91. package/web/assets/{titleArt-CUtA0C3I.js → titleArt-CnC0A7x7.js} +3 -3
  92. package/web/assets/{titleFrameBudget-X7HLSDre.js → titleFrameBudget-DsM0V482.js} +801 -581
  93. package/web/assets/{titleFrames-aMG7HdVe.js → titleFrames-C8kvflgT.js} +1 -1
  94. package/web/assets/{tool-DpFjybaq.js → tool-D1FpErrX.js} +1 -1
  95. package/web/assets/{tools-CeOU0p13.js → tools-DIvrRu-5.js} +1 -1
  96. package/web/assets/toonTools-D9MNdRty.js +2 -0
  97. package/web/assets/{trackAnchor-hAOtEhKO.js → trackAnchor-XvUuvkWP.js} +1 -1
  98. package/web/assets/{userFonts-1kuRjWOo.js → userFonts-Djka6RJX.js} +1 -1
  99. package/web/assets/{vfxAlpha-DxS5-QwY.js → vfxAlpha-B-JzzRI1.js} +1 -1
  100. package/web/assets/vfxBackground-b053ziDK.js +2 -0
  101. package/web/assets/{videoExport-Cg4B2Nyh.js → videoExport-NN-QijHd.js} +1 -1
  102. package/web/assets/{views-CUXyRb9x.js → views-RQBs4zva.js} +1 -1
  103. package/web/assets/{weaponDuel-nFECu9nk.js → weaponDuel-DKAEYJjO.js} +1 -1
  104. package/web/assets/{windowFrames-1wAkkWnv.js → windowFrames-DhhJLIs-.js} +1 -1
  105. package/web/layer-worker.html +3 -3
  106. package/web/shot-worker.html +23 -23
  107. package/web/assets/auraTrack-D_gxHNVe.js +0 -1
  108. package/web/assets/fightDirector-CYP8jxo8.js +0 -1
  109. package/web/assets/handTracker-DY_g5Xmg.js +0 -2
  110. package/web/assets/i18n-BJppIrtF.js +0 -3
  111. package/web/assets/library-B6KsZUKq.js +0 -1
  112. package/web/assets/remote-DJd9xWjn.js +0 -963
  113. package/web/assets/timelineOps-afzSo188.js +0 -525
  114. package/web/assets/toonTools-DLmo37Z_.js +0 -2
  115. package/web/assets/vfxBackground-CYpaQaTa.js +0 -2
@@ -0,0 +1,525 @@
1
+ import{G as ma,I as kb,t as xb,hj as to,l as fn,hi as ko,hI as Ni,au as ft,kI as Fi,cm as Mb,F as Me,gE as Ri,dH as vb,dG as yp,c_ as me,kJ as $b,kK as ld,dW as Ee,dE as bg,dY as Zt,aG as Bn,kL as ic,kM as Eb,iw as rp,kN as Sb,s as Ui,kO as Ib,kP as wg,kQ as Ab,ax as cd,aw as pd,h as Zr,f as Fn,kR as Cb,ay as ud,kS as Ba,kT as jb,U as Nh,ao as Fh,v as yi,bm as kg,kU as Tb,kV as xg,kW as Mg,kX as vg,aB as Qt,kY as kn,dZ as ns,d4 as qt,kZ as $g,aX as Rh,b5 as np,dK as $u,k_ as Ob,k$ as Dh,l0 as zb,ib as Fe,b4 as sc,l1 as Pb,M as Fs,gQ as lc,at as hd,l2 as Cs,dU as dd,l3 as Eu,l4 as Lb,l5 as Nb,l6 as Eg,l7 as Fb,fa as Or,eU as Rs,fd as Ys,eW as Rb,i7 as Bh,i6 as Db,l8 as tn,l9 as tl,kp as Bb,la as Sg,kq as _b,lb as Gb,dk as Ig,h7 as Kb,dn as Vb,dm as Wb,dN as Hb,lc as en,cw as cc,B as pc,z as cn,ld as Xb,aN as Ub,bh as Ag,fP as Qn,dX as ap,le as Cg,fW as Es,im as Ue,fy as Ya,lf as Su,lg as jg,lh as Bl,jq as Tg,li as fd,hh as uc,lj as Yb,lk as qb,ll as Zb,lm as Jb,ln as Qb,h$ as tw,iy as Og,gN as xr,lo as ew,lp as ow,lq as rw,lr as nw,ls as aw,lt as iw,fb as Mr,gI as bn,gH as _n,lu as zr,lv as Iu,g2 as hn,cQ as Cn,cz as cr,lw as zg,lx as sw,hH as bp,ly as lw,lz as cw,lA as pw,lB as uw,cp as Ja,cT as Au,b$ as Pg,eV as hw,fh as dw,lC as fw,ff as Pr,gG as Yi,lD as Lg,eX as _l,gP as Ng,aE as md,lE as ip,hf as Fg,bg as wp,lF as Rg,al as pn,h1 as Ss,hb as Gl,aj as hc,ac as mw,hd as gd,lG as gw,h3 as yw,lH as bw,h8 as ww,am as Cu,ak as kw,aV as Dg,eB as sr,ig as xw,ih as Mw,iB as vw,iO as $w,cb as ju,cc as Ew,ca as Bg,lI as Ur,lJ as qi,lK as pr,fO as qo,g9 as aa,gc as dc,gb as js,lL as _h,lM as Zi,fw as _g,lN as Gh,fu as kp,lO as yd,fT as bd,lP as Sw,lQ as Iw,lR as Gg,lS as wd,lT as Aw,fD as kd,fL as Kh,fv as xd,lU as Cw,lV as Ds,lW as jw,lX as Kg,lY as Tw,ga as Ow,lZ as Md,l_ as zw,l$ as Pw,m0 as Tu,ii as Vh,aI as Lw,av as Nw,cB as ta,cs as Fw,cx as el,m1 as vd,cG as Ou,cy as Rw,dr as $d,ka as Dw,dl as Ed,m2 as Bw,dt as _w,m as Oa,aJ as Gw,m3 as Sd,c0 as Kw,c2 as Id,cd as Vw,c5 as Ww,m4 as Hw,m5 as ol,bA as Vg,m6 as Ad,m7 as Xw,m8 as Uw,m9 as Yw,gO as qw,i as rl,aW as Cd,ma as Zw,cj as ti,ix as jd,ik as xp,il as Jw,ij as Qw,bo as t2,bp as e2,E as Td,mb as o2,mc as r2,md as n2,me as a2,mf as fc,q as Od,mg as i2,D as s2,e as zd,c as l2,R as Pd,n as c2,a as p2,d as u2,fE as rn,mh as Ld,mi as h2,mj as d2,fF as f2,mk as m2,fI as g2,C as y2,aO as ls,aM as Nd,ml as Kl,mm as Fd,mn as Rd,mo as Dd,mp as b2,mq as w2,mr as k2,iv as Xn,cY as nl,io as Bd,ms as al,ds as x2,g4 as _d,d7 as Gd,dc as Mp,dh as vp,mt as M2,mu as Kd,ip as v2,df as $2,dg as E2,ir as S2,mv as I2,mw as A2,mx as C2,my as j2,fk as T2,hk as O2,mz as z2,mA as P2,mB as L2,mC as N2,hF as F2,iz as R2,mD as D2,mE as Vd,mF as B2,mG as _2,mH as G2,mI as K2,k7 as V2,gZ as W2,A as H2,gF as Wd,mJ as X2,mK as U2,mL as Y2,mM as q2,i9 as Hd,i3 as Xd,mN as Z2,mO as J2,mP as Q2,go as tk,j as Ud,mQ as Yd,b6 as ek,g as ok,mR as rk,dR as nk,dq as ak,co as ik,mS as qd,mT as sk,mU as lk,gR as Zd,g0 as ck,mV as pk,fp as uk,mW as hk,mX as dk,hT as fk,bz as Wg,mY as mk,mZ as Jd,m_ as Qd,is as gk,it as yk,iu as bk,m$ as tf,n0 as wk,ky as kk}from"./titleFrameBudget-DsM0V482.js";import{C as xk,N as Mk,b as ef,O as vk,E as $k,F as Ek,s as Sk,Q as Ik,R as Ak,G as Ck,o as jk,T as Tk,h as Ok,U as zk,q as Pk,l as Lk,j as Nk}from"./sceneTrack-DlAH5s74.js";import{h as Fk,i as Rk,B as Hg,m as Vl,s as Dk,t as Wl,r as of,j as Bk,k as _k,n as Gk,D as Kk,E as Vk,o as il,q as Wk,u as Hk,f as Xk,v as Uk,w as Yk}from"./cameraTracker-DHdF8Zqx.js";import{A as qk,H as Zk,h as Jk,j as Qk,p as tx,C as ex,M as rf}from"./textAnimators-B9vO_hbP.js";import{i as nf,u as ox,p as rx,f as nx,m as ax}from"./timelineComp-i-zdaoB2.js";import{bP as af,aK as ix,aI as sx}from"./api-Dnl2uaKO.js";import{L as sl,f as lx,s as cx,r as px}from"./store-CpqHUcA2.js";import{n as ux,P as ia,o as Cr,q as sf,A as zu,t as Xg,u as lf,v as Di,x as hx,y as dx,B as $p,z as fx,C as mx,D as gx,E as yx,F as bx,G as wx,H as kx,I as Ep,J as xx,K as cf,L as Mx,N as pf,O as vx,Q as Ug,R as uf,T as $x,U as mc,V as gc,W as Pu,X as hf}from"./rigTrack-DMyqb0pb.js";import{addClientJob as De}from"./clientJobs-CuuUyhEy.js";const Ex={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"},df={"hist-window-light":"look","hist-film-look":"look","hist-year-wall":"scene","hist-stitch-card":"scene","hist-depth-words":"scene","sc-dot-screen":"look","lr-purple-flash":"transition","lr-light-ribbon":"overlay","lr-name-spark":"overlay","lr-flag-wave":"scene","mx-code-rain":"background","mx-data-tunnel":"background","mx-crt-screen":"look","mx-code-wipe":"transition","cs-callout":"overlay","cs-timer-ring":"overlay","cs-confetti-bg":"background","fr-backdrop":"background","fr-v-backdrop":"background","fr-definition":"overlay","fr-v-definition":"overlay","fr-lower-third":"overlay","fr-v-lower-third":"overlay","tl-4k-split":"overlay","tl-v-4k-split":"overlay","creator-chapter-bar":"scene","creator-quote-end":"scene","creator-thumb-wall":"scene","creator-phone-duo":"scene","course-compare-board":"scene","aiw-race-hud":"overlay","aiw-v-race-hud":"overlay","aiw-pause-menu":"overlay","aiw-v-pause-menu":"overlay","aiw-end-subtitle":"overlay","aiw-v-end-subtitle":"overlay","course-chapter-card":"scene","rv-packshot-title":"scene","clipoox-v-top-banner":"overlay","c3d-orbit-shapes":"background","clipoox-title-sparkle":"overlay","clipoox-publish-btn":"overlay","clipoox-status-log":"overlay","clipoox-zoom-burst":"transition","clipoox-slot-word":"overlay","clipoox-pill-lower":"overlay","clipoox-jelly-wipe":"transition","clipoox-star-flip":"transition","clipoox-skill-header":"overlay","clipoox-before-after":"overlay","clipoox-heat-flash":"transition","clipoox-bar-lower":"overlay","morph-caption":"overlay","promo-caption":"overlay","promo-glass-icon":"overlay","promo-star-flare":"overlay","fluid-caption":"overlay","fluid-blob-el":"overlay","fluid-drip-el":"overlay","rebound-caption":"overlay","rebound-ball":"overlay","rebound-bricks":"overlay","lumen-caption":"overlay","lumen-orb":"overlay","lumen-critter":"overlay","lumen-spark-trail":"overlay","story-caption":"overlay","cine-caption":"overlay","cine-spark":"overlay","pulse-word":"overlay","tvc-backdrop":"background","kin-beat":"scene","kin-orb":"overlay","kin-texture":"look","kin-el":"overlay","kin-el2":"overlay","kin-carry":"transition","bridge-portal":"overlay","aurora-bg":"background",vignette:"look","film-grain":"look","light-leak":"look",letterbox:"look",vhs:"look","launch-wipe":"transition","pop-circle-wipe":"transition","noir-chapter-wave":"transition","creator-flash":"transition","mono-ribbon-wipe":"transition","mono-grid-paper":"background","exp-backdrop":"background","info-backdrop":"background","info-ring-carousel":"scene","info-tilted-dashboard":"scene","cyber-backdrop":"background","cyber-plexus":"background","cyber-trace-lines":"background","cyber-slab-wipe":"transition","cyber-pixel-dissolve":"transition","cyber-orbit-cards":"scene","cyber-circuit-chip":"scene","cyber-logo-reveal":"scene","mono-blob-frame":"look","mono-spotlight-panels":"scene","noir-caption":"overlay","studio-click-callout":"overlay","launch-question":"scene","launch-logo":"scene","launch-prompt":"scene","biz-section-title":"scene","biz-logo-reveal":"scene","fxo-paper-bg":"background"};function Sx(t,e){const o=typeof t=="string"?t:t?.id,r=typeof t=="string"?e:t?.pack;return/^fxo-/.test(o||"")?df[o]||"look":df[o]||Ex[r]||"overlay"}const Ix=Object.freeze(["general","creator","education","commerce","corporate","finance","tech","ai","saas","gaming","data","product","luxury","beauty","food","event","realestate","health","fitness","travel","auto"]),ff=Object.freeze({bold:{industries:["general","creator","commerce"],tone:"any",energy:3},clean:{industries:["corporate","tech","beauty","luxury"],tone:"any",energy:1},neon:{industries:["gaming","event","creator"],tone:"dark",energy:3},podcast:{industries:["creator","education"],tone:"any",energy:2},sale:{industries:["commerce"],tone:"any",energy:3},business:{industries:["corporate","finance","saas","data"],tone:"any",energy:2},launch:{industries:["tech","product","saas"],tone:"light",energy:2},glow:{industries:["finance","creator","education"],tone:"dark",energy:2},noir:{industries:["luxury","finance","corporate"],tone:"dark",energy:2},pop:{industries:["creator","commerce","education"],tone:"light",energy:3},illus:{industries:["education","general"],tone:"light",energy:2},studio:{industries:["tech","saas","product"],tone:"dark",energy:2},creator:{industries:["creator","commerce"],tone:"dark",energy:3},mono:{industries:["product","luxury","corporate"],tone:"light",energy:1},ai:{industries:["ai","tech","saas"],tone:"dark",energy:2},fin:{industries:["finance"],tone:"dark",energy:2},explain:{industries:["education","creator","commerce"],tone:"dark",energy:2},info:{industries:["data","saas","corporate","education"],tone:"light",energy:1},cyber:{industries:["gaming","tech","event"],tone:"dark",energy:3},kinetic:{industries:["creator","commerce","education"],tone:"any",energy:3},bridge:{industries:["general"],tone:"any",energy:2},tvc:{industries:["corporate","commerce","product","beauty","food","luxury"],tone:"light",energy:2},home:{industries:["realestate","luxury","corporate"],tone:"any",energy:1},health:{industries:["health","education"],tone:"any",energy:1},fit:{industries:["fitness","event","creator"],tone:"dark",energy:3},travel:{industries:["travel","luxury","event"],tone:"any",energy:2},menu:{industries:["food","commerce"],tone:"any",energy:2},auto:{industries:["auto","luxury"],tone:"dark",energy:3},cine:{industries:["general","creator","event","luxury"],tone:"dark",energy:1},pulse:{industries:["general","tech","gaming","event","creator"],tone:"dark",energy:2},story:{industries:["general","creator","event","education"],tone:"dark",energy:2},lumen:{industries:["tech","ai","creator","gaming","beauty","event"],tone:"dark",energy:2},rebound:{industries:["tech","gaming","fitness","creator","product","event"],tone:"dark",energy:2},join:{industries:["general","creator","commerce","tech","event","education","product"],tone:"dark",energy:3},fluid:{industries:["beauty","creator","product","food","event","general"],tone:"dark",energy:2},promo:{industries:["tech","ai","saas","product","creator","data"],tone:"dark",energy:2},morph:{industries:["general","creator","product","tech","corporate","event"],tone:"dark",energy:2},glass:{industries:["finance","saas","tech","data"],tone:"dark",energy:2},clipooxmotion:{industries:["tech","ai","saas","product","creator","general"],tone:"any",energy:3},editorial3d:{industries:["general","creator","education","commerce","data"],tone:"light",energy:2},clipoox3d:{industries:["saas","tech","product","ai","data"],tone:"dark",energy:2},prodreview:{industries:["beauty","commerce","product","creator","health","food"],tone:"any",energy:1},course:{industries:["education","tech","ai","saas","creator"],tone:"dark",energy:1},aiworkflow:{industries:["ai","saas","tech","gaming"],tone:"any",energy:3},techlaunch:{industries:["ai","saas","tech","product"],tone:"light",energy:3},framed:{industries:["creator","education"],tone:"dark",energy:2},uibeats:{industries:["tech","saas","product","education"],tone:"dark",energy:2},clipooxstudio:{industries:["tech","ai","saas","product","education","creator"],tone:"any",energy:2},matrix:{industries:["tech","gaming","ai","data","event"],tone:"dark",energy:3},lightfx:{industries:["finance","corporate","event","auto","general"],tone:"dark",energy:3},sportcine:{industries:["fitness","creator","event","tech","education"],tone:"any",energy:3},faceholo:{industries:["tech","creator","ai","event","general"],tone:"dark",energy:2},history:{industries:["general","education","creator"],tone:"dark",energy:2},basic:{industries:["general"],tone:"any",energy:2}}),Ax=[[/\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"]],Cx=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}]]))}),jx=t=>{const e=String(t||"").match(/\/\/ ([^\n]+)/);return e?e[1].trim():""},Tx={text:"text",sub:"subText",items:"items",number:"numberValue",icon:"icon",glyph:"icon",posX:"posX"};function Ox(t){const e=t.pack||"basic",o=ff[e]||ff.basic,r=Sx(t),a=jx(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 Ax)f.test(n)&&!i.includes(m)&&i.push(m);i.length||(i=[r==="scene"?"explain":"decor"]);const l=Cx[t.id];l?.beats&&(i=[...l.beats]);const u=t.params?.position,c=["scene","background","look","transition"].includes(r)?"full":["top","center","lower"].includes(u)?u:"center",s=[...new Set(Object.keys(t.params||{}).map(f=>Tx[f]).filter(Boolean))],d=Array.isArray(t.formats)&&t.formats.includes("portrait")?"portrait":"any";return Object.freeze({id:t.id,pack:e,role:r,beats:i,zone:c,fields:s,energy:o.energy,tone:o.tone,industries:o.industries,dur:t.duration,about:a,fmt:d})}let Sp=null;function Hl(){return Sp||(Sp=Object.freeze(ma.filter(t=>kb.includes(t.id)).map(Ox))),Sp}const zx={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ễ"]},Px={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"]},mf=(t,e)=>t.includes(e);function Yg(t){const e=` ${String(t||"").toLowerCase()} `,o=Object.entries(zx).filter(([,a])=>a.some(n=>mf(e,n))).map(([a])=>a),r=Object.entries(Px).filter(([,a])=>a.some(n=>mf(e,n))).map(([a])=>a);return{industries:o,beats:r}}const Lx=Object.freeze(["minimal","luxury","friendly","bold","tech"]),Nx=Object.freeze({minimal:["iris","slab"],luxury:["iris","ink"],friendly:["shapes","stripes"],bold:["slab","flash","whip"],tech:["glitch","tunnel","whip"]}),Fx=/^#[0-9a-f]{6}$/i,ei=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function qg(t){if(!t||typeof t!="object")return null;const e=new Set(xb.map(a=>a.id)),o={name:ei(t.name,60),tagline:ei(t.tagline,80),website:ei(t.website,80),phone:ei(t.phone,40),address:ei(t.address,100),industry:Ix.includes(t.industry)?t.industry:"general",tone:Lx.includes(t.tone)?t.tone:"minimal",colors:(Array.isArray(t.colors)?t.colors:[]).filter(a=>Fx.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:ei(t.logoMaterialId,200)||null},r=Object.fromEntries(["heading","body"].filter(a=>qk(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 Rx=t=>[t?.website,t?.phone,t?.address].filter(Boolean);function lC(t){const e=qg(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}),Zg=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")]}}),Dx=Object.freeze(Object.keys(Zg)),Bx={flash:.8,whip:.8,glitch:.8,slab:1,iris:1,stripes:1,ink:1.2,shapes:1.2,tunnel:1.2},xa=t=>+(+t).toFixed(3),Ip=t=>String(t??"").slice(0,60);function _x(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),l=Array.isArray(r.items)?r.items:t.name==="cta"?Rx(o):void 0;return n&&(a.text=Ip(n)),i&&(a.subText=Ip(i)),l?.length&&(a.items=l.map(Ip).slice(0,5)),Number.isFinite(+r.number)&&r.number!==null&&r.number!==""&&(a.numberValue=+r.number),a}function Gx({recipe:t="tvc-15",copy:e={},brand:o=null,start:r=0,portrait:a=!1,dark:n=!1,base:i=0}={}){const l=Zg[t];if(!l)throw Error(`TVC recipe must be ${Dx.join("/")}`);const u=o?.colors?.[0],c=[],s=l.beats.reduce((g,v)=>g+v.dur,0),d=Nx[o?.tone||"minimal"];for(let g=0;g<s-.001;g+=to.maxDuration)c.push({op:"addMotion",motionPreset:"tvc-backdrop",start:xa(r+g),duration:xa(Math.min(to.maxDuration,s-g)),numberValue:n?1:0,...u?{color:u}:{}});let f=r,m=null;if(l.beats.forEach((g,v)=>{const x=e?.[g.name]?.preset,$=g.presets.includes(x)?x:g.presets[0];if(c.push({op:"addMotion",motionPreset:$,start:xa(f),duration:xa(g.dur),placement:"center",..._x(g,e,o),...u?{color:u}:{}}),$==="tvc-logo-sting"&&(m={start:f,dur:g.dur}),v>0){const E=d[(v-1)%d.length],S=Bx[E];c.push({op:"addMotion",motionPreset:`bridge-${E}`,start:xa(Math.max(r,f-S/2)),duration:S,...u?{color:u}:{}})}f+=g.dur}),o?.logoMaterialId&&m){const g=i+c.filter(v=>/^add/.test(v.op)).length+1;c.push({op:"addClip",materialId:o.logoMaterialId,start:xa(m.start+.25),duration:xa(m.dur-.25),track:fn(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 c}const Kx=t=>{try{const e=JSON.parse(String(t||"{}"));return e&&typeof e=="object"?e:{}}catch{return{}}};function Vx(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 l=u=>{const c=typeof u=="string"&&/^new:(\d+)$/.exec(u);if(!c)return u;const s=+c[1];let d=0;for(const f of a)s>f.after&&(d+=f.by);return`new:${s+d}`};for(const u of t){const c=u?.clipId||u?.fromClipId||u?.sourceClipId?{...u,...u.clipId?{clipId:l(u.clipId)}:{},...u.fromClipId?{fromClipId:l(u.fromClipId)}:{},...u.sourceClipId?{sourceClipId:l(u.sourceClipId)}:{}}:u;if(c?.op!=="tvc"){r.push(c),/^(add|lockup$)/.test(c?.op??"")&&(n++,i++);continue}const s=Gx({recipe:c.preset,copy:Kx(c.prompt),brand:e,start:+c.start||0,portrait:o,dark:c.booleanValue===!0,base:n}),d=s.filter(f=>/^add/.test(f.op)).length;r.push(...s),d&&a.push({after:i,by:d}),n+=d}return r}const Lu="vfx-weapon-slash",Jg="vfx-cross-slash",Nu="vfx-clash-sparks",bi="vfx-energy-ribbon",cC=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"})}),pC=Object.freeze([Lu,Jg,Nu,bi]),uC=t=>t==="n"||t==="fps"||t==="t0"||/^p\d+$/.test(t),yc=/^#[0-9a-fA-F]{6}$/,Ao=t=>Math.round(t*1e4)/1e4,Kr=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,Fu=Object.freeze({slash:Object.freeze({preset:Lu,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:Jg,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:Nu,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:Lu,extraPreset:Nu,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}])})}),Wx=Object.freeze(Object.keys(Fu));function gf({id:t,presetId:e,label:o,at:r,u:a=.5,v:n=.5,color:i,core:l,angle:u,arc:c,flip:s,spread:d,width:f,size:m=1,sparks:g,seed:v,duration:x}){const $=ma.find(k=>k.id===e);if(!$)throw Error(`Unknown combat preset ${e}`);const E=Ao(Kr(x,[.2,2.5],$.duration)),S={...$.params,x:Ao(Kr(a,[-.2,1.2],.5)),y:Ao(Kr(n,[-.2,1.2],.5)),color:yc.test(i??"")?i:$.params.color,core:yc.test(l??"")?l:$.params.core,size:Ao(Kr(m,[.3,3],1)),...Number.isFinite(f)&&"width"in $.params?{width:Ao(Kr(f,[.3,3],1))}:{},...Number.isFinite(u)&&"angle"in $.params?{angle:Math.round(u)}:{},...Number.isFinite(c)&&"arc"in $.params?{arc:Math.round(Kr(c,[40,280],155))}:{},...s!==void 0&&"flip"in $.params?{flip:!!s}:{},...Number.isFinite(d)&&"spread"in $.params?{spread:Math.round(Kr(d,[25,140],78))}:{},...g!==void 0&&"sparks"in $.params?{sparks:typeof $.params.sparks=="boolean"?!!g:Math.round(Kr(Number(g),[0,80],$.params.sparks))}:{},...Number.isFinite(v)&&"seed"in $.params?{seed:Math.max(1,Math.round(v))}:{}};return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Ao(Math.max(0,r)),duration:E,label:o||$.name,motionV:2,posX:0,posY:0,scale:1,opacity:1,motion:ko({code:`@preset:${e}`,params:S,preset:e})}}function Hx(t,e,o=Rk.fps){if(!Array.isArray(t)||t.length<2)throw Error("weaponTrail path needs at least 2 [u, v] points");const r=t.map(l=>{if(!Array.isArray(l)||l.length<2||!Number.isFinite(Number(l[0]))||!Number.isFinite(Number(l[1])))throw Error("weaponTrail path points must be [u, v] in 0..1");return[Math.max(0,Math.min(1,Number(l[0]))),Math.max(0,Math.min(1,Number(l[1])))]}),a=Math.max(6,Math.min(240,Math.round(e*o))),n=r.length-1,i=[];for(let l=0;l<=a;l++){const u=l/a,c=u*n,s=Math.min(n-1,Math.floor(c)),d=c-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=d*d,$=x*d,E=(y,A,I,z)=>.5*(2*A+(-y+I)*d+(2*y-5*A+4*I-z)*x+(-y+3*A-3*I+z)*$),S=Math.max(0,Math.min(1,E(f[0],m[0],g[0],v[0]))),k=Math.max(0,Math.min(1,E(f[1],m[1],g[1],v[1])));i.push([Ao(u*e),Ao(S),Ao(k)])}return i}function Xx({id:t,at:e,duration:o,color:r,core:a,width:n,length:i,sparks:l,source:u,point:c,path:s}){const d=ma.find($=>$.id===bi),f=Ao(Kr(o,[.15,20],1.5)),m={...d.params,color:yc.test(r??"")?r:d.params.color,core:yc.test(a??"")?a:d.params.core,width:Ao(Kr(n,[.3,3],1)),length:Ao(Kr(i,[.08,1.5],.35)),sparks:l!==!1};if(Array.isArray(s)&&s.length>=2){const $=Fk(Hx(s,f));return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Ao(Math.max(0,e)),duration:f,label:d.name,motionV:2,posX:0,posY:0,scale:1,opacity:1,motion:ko({code:`@preset:${bi}`,params:{...m,...$},preset:bi})}}const g=.03,v=c??[.5,.5],x={x:Ao(Math.max(0,Math.min(1-2*g,v[0]-g))),y:Ao(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:Ao(Math.max(0,e)),duration:f,label:d.name,motionV:2,posX:0,posY:0,scale:1,opacity:0,motion:ko({code:`@preset:${bi}`,params:m,preset:bi}),pendingPin:{source:u,at:Ao(e),region:x,mode:"bolt",...c?{}:{person:!0}}}}const Qg=15,Ux=7.5,Ap=1e-6,cs=t=>Math.round(t*30)/30;function hC(t){const e=Number(t);if(!Number.isFinite(e)||e<1-Ap||e>Qg+Ap)return null;const o=Math.max(1,Math.ceil(e/Ux-Ap)),r=e/o;return Array.from({length:o},(a,n)=>({k:n+1,n:o,from:cs(n*r),to:cs((n+1)*r),duration:cs(cs((n+1)*r)-cs(n*r))}))}const Cp=t=>String(+t.toFixed(2));function dC(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 ${Cp(e.from)}–${Cp(e.to)} giây của cảnh ${Cp(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 Bs="(\\d+(?:[.,]\\d+)?)",t1="(s|secs?|seconds?|giây|giay|phút|phut|min|mins|minutes?)(?![\\p{L}\\p{N}])",Yx=new RegExp(`${Bs}\\s*(?:–|—|-|đến|tới|to)\\s*${Bs}\\s*${t1}`,"giu"),qx=new RegExp(`(?:từ\\s+)?(?:giây|giay|second)\\s*${Bs}\\s*(?:–|—|-|đến|tới|to)\\s*(?:giây|giay|second)?\\s*${Bs}(?![\\p{L}\\p{N}])`,"giu"),Zx=new RegExp(`${Bs}\\s*${t1}`,"giu"),ps=t=>Number(t.replace(",",".")),jp=t=>/^(phút|phut|min)/i.test(t)?60:1;function fC(t){let e=String(t||"").toLowerCase();const o=[];e=e.replace(Yx,(l,u,c,s)=>(o.push([ps(u)*jp(s),ps(c)*jp(s)])," ")),e=e.replace(qx,(l,u,c)=>(o.push([ps(u),ps(c)])," "));const r=[...e.matchAll(Zx)].map(l=>ps(l[1])*jp(l[2])).filter(l=>l>0),a=o.filter(([l,u])=>u>l),n=a.length?Math.max(...a.map(l=>l[1]))-Math.min(...a.map(l=>l[0])):0,i=Math.max(0,n,...r);return i>0?Math.round(i*100)/100:null}const Jx=Object.freeze(["left","zoom","strips","up","glitch","right","zoom","down","strips","left","glitch","up"]),Qx={left:"whoosh-fast-swish",right:"whoosh-fast-swish",up:"whoosh-short-up",down:"whoosh-short-down",zoom:"zoom-whoosh",strips:"whoosh-double",glitch:"glitch"},t3=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"]),e3=["cyber-slab-wipe","cyber-pixel-dissolve"],e1={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"]},yf=["rect","circle","diamond","bars"],o3=Object.freeze(["letters","solid","outline","streak","echo","solid","reflect","chrome","glitch","outline"]),r3=["chrome","echo","glitch"],n3=["reflect","streak"],bc=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],a3=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=>bc(t)||"",when:t=>(bc(t)||"").length>=5}]);function i3(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)),l=i*.56,u=o/2-i/2,c=r*(e?.6:.56),s={icon:[o/2,c+l*.45],photo:[o/2,c+l*.42],player:[o/2,c+l*.45],chat:[u+i*.92,c+l*.48],cube:[o/2,c+l*.5],nodes:[u+i*.18,c+l*.35],timeline:[u+i*.6,c+l*.55],chart:[u+i*.82,c+l*.3],render:[u+i*.9,c+l*.6],logo:[o/2,c+l*.35]}[t]||[o/2,r/2];return[+(s[0]/o).toFixed(3),+(s[1]/r).toFixed(3)]}const s3=[["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/]],l3=[[/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"]]],o1=t=>[...new Set(l3.filter(([e])=>e.test(t)).flatMap(([,e])=>e))],c3=[[/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/]],r1=t=>s3.find(([,e])=>e.test(t))?.[0]??null,bf=t=>String(t).toLowerCase().normalize("NFC").split(/[^\p{L}\p{N}]+/u).filter(e=>e.length>=3),n1=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 p3(t,{industries:e=[],dark:o=!0,used:r=new Set,pack:a=null,accent:n="#e8141c"}={}){const i=r1(t);if(!i)return null;const l=bf(t),u=i==="number"?"numberValue":i==="list"?"items":null,c=Hl().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(!c.length)return null;const s=c3.filter(([S])=>S.test(t)).map(([,S])=>S),d=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)+bf(d(S)).filter(k=>l.includes(k)).length+(S.industries.includes("general")?.5:0)+s.filter(k=>k.test(d(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=c.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=n1(v),$={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")&&($.numberValue=x),g.fields.includes("items")){const S=v.split(/,| và | and /).map(k=>k.trim()).filter(Boolean);$.items=(S.length>=2?S:v.split(" ").reduce((k,y,A)=>{const I=Math.floor(A/2);return k[I]=k[I]?k[I]+" "+y:y,k},[])).slice(0,4)}const E=Ni(v);E&&g.fields.includes("icon")&&($.icon=E);try{const S=Fi(g.id,$);return{preset:g.id,pack:g.pack,params:S.params,library:!0}}catch{return null}}function u3(t,e=!0){const o=Ni(t);if(!o)return null;const r=Mb[o];return{el:"icon",preset:"kin-el2",label:(e?r.name:r.en||r.name)||"",glyph:o}}function h3(t,{vi:e=!0,prev:o=null,last:r=!1}={}){if(r&&bc(t)&&o!=="logo")return{el:"logo",preset:"kin-el2",label:bc(t)};for(const a of a3)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 wc=/[.!?…:;,]$/,a1=/[.!?…]$/,d3=[[.91,.1],[.09,.9],[.91,.9],[.09,.1]],_a=Object.freeze({words:300,beatMin:.28,lineChars:{portrait:14,landscape:22},maxBeatWords:3}),f3=t=>String(t||"").split(/\s+/).filter(Boolean).length,i1=t=>`Vượt giới hạn ${_a.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 m3(t,e=0,{rate:o=2.6}={}){const r=[];let a=e;const n=f3(t);if(n>_a.words)throw Error(i1(n));for(const i of String(t||"").split(/\s+/).filter(Boolean)){const l=Math.max(.24,Math.min(.7,(.18+i.length*.035)*2.6/o));r.push({word:i,start:+a.toFixed(3),end:+(a+l).toFixed(3)}),a+=l+(a1.test(i)?.35:wc.test(i)?.15:0)}return r}const wf=t=>/[!?]$/.test(t)||/\d/.test(t)||t.length>2&&t===t.toUpperCase()&&/[A-ZÀ-Ỹ]/.test(t);function g3(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,_a.words).map(u=>({word:u.word.trim(),start:u.start,end:Number.isFinite(u.end)?u.end:u.start+.3})),n=_a.lineChars[e?"portrait":"landscape"]+(r?22:o?8:0),i=[];let l=null;return a.forEach((u,c)=>{const s=a[c-1],d=s?u.start-s.end:0,f=l?l.words.join(" ").length+1+u.word.length:0;(!l||wc.test(s?.word??"")||d>=.45||f>n+(wc.test(u.word)?10:0))&&(l={words:[],beats:[]},i.push(l));const m=l.beats.at(-1),g=l.words.length;l.words.push(u.word);const v=wf(u.word)||m&&wf(l.words[g-1]);m&&(u.start-m.start<_a.beatMin||!v&&u.word.length<=3&&m.k<_a.maxBeatWords)?(m.k++,m.n++,m.end=u.end):l.beats.push({n:g+1,k:1,start:u.start,end:u.end})}),i.map(u=>({text:u.words.join(" "),beats:u.beats}))}const Wa=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"]}}),mC=Object.keys(Wa),y3=/ướ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,b3={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]},w3={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 k3(t,{industries:e=[],tone:o=null}={}){const r={};for(const a of Object.keys(Wa))r[a]=0;for(const[a,[n,i]]of Object.entries(b3))r[a]+=Math.min(3,(String(t).match(n)||[]).length)*i;for(const[a,n]of Object.entries(w3))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 x3(t,e={}){const o=k3(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 kc=[[/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"]],kf=[[/đ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"]],M3=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",v3={l:"r",r:"l",t:"b",b:"t",c:"c"},xf=["r","t","l","b","r"],Ru=["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"],s1=["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"],Mf="lumen-white-flash",$3=["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"],E3=[[/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"]],S3=["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"],I3=["dot","ring","line","star","pill","diamond","square","bar","cross","heart"],A3=["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"],C3=[[/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"]],j3=new Set(["promo-prompt-bar","promo-icon-cloud","promo-dome-horizon","promo-cta-button","promo-aurora-card","promo-flare-card"]),T3=["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"],O3=[[/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"]],z3=[[/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 P3(t,e,{accent:o,seed:r,tail:a,known:n}){const i=[];let l=null;for(const A of t)(!l||l.end-l.start>=e.min)&&(l={lines:[],start:A.beats[0].start,end:0},i.push(l)),l.lines.push(A),l.end=A.beats.at(-1).end;if(i.length>1&&i.at(-1).end-i.at(-1).start<e.min*.6){const A=i.pop();i.at(-1).lines.push(...A.lines),i.at(-1).end=A.end}if(["lumen","rebound","fluid"].includes(e.pack)&&i.length>1&&i.at(-1).lines.length>1){const A=i.at(-1),I=A.lines.pop();A.end=A.lines.at(-1).beats.at(-1).end,i.push({lines:[I],start:I.beats[0].start,end:I.beats.at(-1).end})}const u=[],c=[],s=[],d=A=>!n||n(A),f=new Set,m=t.map(A=>A.text).join(" "),g=M3(m),v=t.find(A=>/\?$/.test(A.text)&&A.text.length<=40)?.text??"...";let x=null,$=r,E="l";const S=["dot"],k=(e.pack==="cine"?kc.map(A=>A[1]):e.pack==="story"?kf.map(A=>A[1]):e.pack==="lumen"?s1:e.pack==="rebound"?$3:e.pack==="fluid"?T3:e.pack==="promo"?A3:e.pack==="morph"?S3:Ru).filter(d);if(!k.length)throw Error(`Poox 1.1: the ${e.pack} scenes are not installed`);i.forEach((A,I)=>{const z=A.lines.map(ht=>ht.text).join(" "),j=e.pack==="cine"?kc:e.pack==="story"?kf:e.pack==="lumen"?z3:e.pack==="rebound"?E3:e.pack==="fluid"?O3:e.pack==="promo"?C3:null;let P=j?j.find(([ht,yt])=>ht.test(z)&&yt!==x&&!f.has(yt)&&d(yt))?.[1]:null;!P&&["story","lumen","rebound","fluid","promo","morph"].includes(e.pack)&&(P=k.find(ht=>!f.has(ht)&&ht!==x));const N=e.pack==="fluid"?"fluid-melt-word":e.pack+"-neon-word",F=["lumen","rebound","fluid"].includes(e.pack)&&I===i.length-1&&I>0&&d(N);F&&(P=N),e.pack==="promo"&&I===0&&d("promo-flare-card")&&(P="promo-flare-card"),e.pack==="morph"&&I===i.length-1&&I>0&&d("morph-logo-wings")&&(P="morph-logo-wings");for(let ht=0;!P&&ht<k.length*2;ht++){const yt=k[$++%k.length];yt!==x&&(P=yt)}P=P??k[0],x=P,F||f.add(P),f.size>=k.length&&f.clear();const K=e.pack==="promo"&&j3.has(P)&&(P==="promo-cta-button"?A.lines.at(-1).text.length<=24:A.lines.every(ht=>ht.text.length<=40)),_=e.pack==="story"||e.pack==="rebound",J=_?.7:0,X=I?A.start-J:Math.max(0,A.start-.15),rt=I<i.length-1?i[I+1].start:A.end+a,ot=e.colors[I%e.colors.length],G=I<i.length-1?e.colors[(I+1)%e.colors.length]:e.colors[0],tt=xf[I%xf.length],Q=(I?"i":"")+(I<i.length-1?"o":""),it=e.pack==="morph"?(()=>{const ht=S.at(-1),yt=I3.filter(p=>!S.slice(-2).includes(p)),Mt=yt[(I*3+r)%yt.length];return S.push(Mt),{formIn:ht,formOut:Mt}})():{},D=e.pack==="story"?{hero:g,heroIn:E,heroOut:tt,pan:Q}:e.pack==="rebound"?{ballIn:I?E:"c",ballOut:tt,pan:Q}:e.pack==="pulse"?{ballIn:E}:{};E=v3[tt],u.push({start:ft(X),duration:ft(Math.max(.6,rt-X)),line:I,preset:P,params:{bg:ot,next:G,fg:o,text:F?A.lines.at(-1).text.slice(0,60):K?P==="promo-cta-button"?A.lines.at(-1).text.slice(0,24):A.lines.map(ht=>ht.text).join(P==="promo-prompt-bar"?"|":" ").slice(0,80):"",...D,...it,...P==="story-phone-message"?{msg:v}:{}}});const U=_?[]:(e1[e.pack==="cine"?"cinematic":e.pack]||[]).filter(d);I&&I%2===1&&U.length&&!(e.pack==="lumen"&&I%3===2)&&c.push({start:ft(Math.max(0,X-.45)),duration:ft(.9),preset:U[(I>>1)%U.length],params:{fg2:e.colors[I%e.colors.length]}}),e.pack==="rebound"&&I%4===3&&d("rebound-gradient-flash")&&c.push({start:ft(Math.max(0,X+J-.35)),duration:ft(.7),preset:"rebound-gradient-flash",params:{bg:ot,next:ot,fg:o}}),e.pack==="lumen"&&I%3===2&&d(Mf)&&c.push({start:ft(Math.max(0,X-.3)),duration:ft(.6),preset:Mf,params:{bg:ot,next:ot,fg:o}}),(!F&&!K?A.lines:K&&P==="promo-cta-button"?A.lines.slice(0,-1):[]).forEach((ht,yt)=>{const Mt=Math.max(X+J+.25,ht.beats[0].start-.05),p=yt<A.lines.length-1?A.lines[yt+1].beats[0].start:rt-.35;p-Mt>.3&&c.push({start:ft(Mt),duration:ft(p-Mt),preset:e.caption,params:{text:ht.text.slice(0,120),position:"lower"}})}),I&&s.push({at:ft(Math.max(0,X+J-.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(([A,I,z])=>{const j=i[I];if(j&&d(A)&&I<i.length-1){const P=j.start+.4,N=i[I+1].start-.4;N-P>.8&&c.push({start:ft(P),duration:ft(N-P),preset:A,params:{position:z,fg:o}})}}),{beats:u,els:c,sfx:s}}const l1=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))),c1=(t,e)=>t.map(o=>Math.max(0,o-e).toFixed(2)).join(",").slice(0,300),L3=/[ăâđêôơưàáạảãằắặẳẵầấậẩẫèéẹẻẽềếệểễìíịỉĩòóọỏõồốộổỗờớợởỡùúụủũừứựửữỳýỵỷỹ]/i,Xl=t=>t.replace(/[.,;:…]+$/,""),N3=["glass-orb-rise","glass-balance","glass-coin-bars","glass-step-chart","glass-line-target","glass-candles","glass-progress","glass-emblem"],F3=[[/%|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"]],vf=new Set(["glass-balance","glass-progress","glass-emblem"]);function R3(t,e,{accent:o,tail:r,known:a}){const n=$=>!a||a($),i=[];let l=null;for(const $ of t){const E=l?l.end-l.start:0;(!l||E>=e.min&&wc.test(l.lines.at(-1).text)||E>=e.min*2.5)&&(l={lines:[],start:$.beats[0].start,end:0},i.push(l)),l.lines.push($),l.end=$.beats.at(-1).end}if(i.length>1&&i.at(-1).end-i.at(-1).start<1.2){const $=i.pop();i.at(-1).lines.push(...$.lines),i.at(-1).end=$.end}const u=N3.filter(n);if(!u.length)throw Error("Poox 1.1: the glass scenes are not installed");const c=[],s=[],d=[],f=new Set,m=e.colors[0],g=L3.test(t.map($=>$.text).join(" "));let v=null,x=0;return i.forEach(($,E)=>{const S=$.lines.map(j=>j.text).join(" "),k=n1(S);let y=F3.find(([j,P])=>j.test(S)&&P!==v&&!f.has(P)&&n(P)&&(!vf.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 A=E?$.start-.1:Math.max(0,$.start-.15),I=E<i.length-1?i[E+1].start-.1:$.end+r,z=k!=null&&vf.has(y)?{number:y==="glass-progress"?Math.min(100,k):k,...y==="glass-balance"?{from:Math.round(k*.86)}:{}}:{};c.push({start:ft(A),duration:ft(Math.max(.3,ft(I)-ft(A))),line:E,preset:y,params:{bg:m,next:m,accent:o,text:"",sub:"",...z}}),$.lines.forEach((j,P)=>{const N=Math.max(A+.05,j.beats[0].start-.08),F=P<$.lines.length-1?$.lines[P+1].beats[0].start-.04:I-.02;if(F-N<=.3)return;const K=j.text.split(" ").filter(Boolean),_=K.length<2?K.length:K.length>=4&&(g||K.at(-1).length<=3)?2:1,J=l1(j);s.push({start:ft(N),duration:ft(F-N),preset:e.caption,params:{text:K.slice(0,K.length-_).join(" ").slice(0,80),sub:Xl(K.slice(K.length-_).join(" ")).slice(0,40),marks:c1(J,N),panel:(E+P)%3===2,position:"top",accent:o}})}),E&&d.push({at:ft(Math.max(0,A-.15)),id:"whoosh-airy"})}),{beats:c,els:s,sfx:d}}function D3(t,e,{accent:o,tail:r}){const a=[];let n=null;for(const c of t)(!n||n.lines.length>=3||a1.test(n.lines.at(-1).text))&&(n={lines:[]},a.push(n)),n.lines.push(c);const i=[],l=[],u=e.palette.dark;return a.forEach((c,s)=>{const d=c.lines[0].beats[0].start,f=s?d-.08:Math.max(0,d-.12),m=a[s+1],g=m?m.lines[0].beats[0].start-.08:c.lines.at(-1).beats.at(-1).end+r,v=c.lines.map(($,E)=>{const S=$.text.split(" ").filter(Boolean),k=c.lines.length===1;let y=new Set(S.map((A,I)=>/\d/.test(A)?I:-1).filter(A=>A>=0));if(!y.size&&(E%2===1||k)){const A=k?S.length-1:S.reduce((I,z,j)=>Xl(z).length>Xl(S[I]).length?j:I,0);y.add(A),!k&&S.length>=3&&A+1<S.length&&Xl(S[A+1]).length>=4&&y.add(A+1)}return S.map((A,I)=>y.has(I)?`*${A}*`:A).join(" ").replace(/\* \*/g," ")}),x=c.lines.flatMap(l1);i.push({start:ft(f),duration:ft(Math.max(.3,ft(g)-ft(f))),line:s,preset:e.caption,params:{text:v.join("|").slice(0,240),marks:c1(x,f),bg:u,accent:o,position:"center"}}),s&&l.push({at:ft(Math.max(0,f-.1)),id:"whoosh-short-up"})}),{beats:i,els:[],sfx:l}}function B3(t,{palette:e={},io:o=.16,portrait:r=!0,seed:a=1,tail:n=.7,orb:i=!0,industry:l=null,genre:u="punch",known:c=null}={}){const s=Wa[u]||Wa.punch;if(s.palette&&(e={...s.palette,...e.accent&&!["luxury","neon","glass"].includes(u)?{accent:e.accent}:{}}),s.orb===!1&&(i=!1),(t||[]).length>_a.words)throw Error(i1(t.length));const d=(t||[]).length>120,f=g3(t,{portrait:r,dense:d,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"?R3:D3)(f,s,{accent:e.accent,tail:n,known:c}),orbs:[],texture:[],carriers:[],lines:f.length,genre:u};if(s.kind==="scenes")return{...P3(f,s,{accent:e.accent||s.colors[1],seed:a,tail:n,known:c}),orbs:[],texture:[],carriers:[],lines:f.length,genre:u};const m=e.dark||"#0b0b0d",g=e.light||"#f4f4f1",v=e.accent||"#e8141c",x=C=>{const O=parseInt(C.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 $=null;const E=f.map((C,O)=>{let B=(/[!?]$/.test(C.text)||/\d/.test(C.text))&&$!==v?v:(O+a)%2?g:m;return B===$&&(B=B===m?g:m),$=B,B}),S=[],k=[],y=f.flatMap((C,O)=>C.beats.map((L,B)=>({...L,li:O,bi:B,line:C}))),A=/[ăâđêôơưàáạảãằắặẳẵầấậẩẫèéẹẻẽềếệểễìíịỉĩòóọỏõồốộổỗờớợởỡùúụủũừứựửữỳýỵỷỹ]/i.test(f.map(C=>C.text).join(" "));let I=null;const z=f.map(C=>C.text).join(" "),j=Yg(z),P=[...new Set([...j.industries,...o1(z),...l&&l!=="general"?[l]:[]])],N=new Set;let F=null;const K=[],_=f.map((C,O)=>{const L=(C.beats.at(-1).end??C.beats.at(-1).start)-C.beats[0].start;if(L<.8)return I=null,null;let B=h3(C.text,{vi:A,prev:I,last:C===f.at(-1)});if(B?.el==="chart"&&(B=null),!B&&I!=="photo"){const H=ux(C.text,{exclude:K});H&&(K.push(H.id),B={el:"photo",preset:"kin-el2",label:A?H.vi:H.en,photo:H.id,glyph:Ni(C.text)||"sparkle"})}if(!B&&L>=.8&&I!=="library"){const H=et=>p3(C.text,{industries:P,dark:et,used:N,pack:F,accent:E[O]===v?"#ffffff":v});let q=H(E[O]!==g);if(E[O]===g){const et=H(!0);et&&(!q||P.some(st=>Hl().find(Y=>Y.id===et.preset)?.industries.includes(st))&&!P.some(st=>Hl().find(Y=>Y.id===q.preset)?.industries.includes(st)))&&(q=et,E[O]=m)}q&&(N.add(q.preset),F=F??q.pack,B={el:"library",...q})}if(!B&&r1(C.text)==="number"&&I!=="chart"&&(B={el:"chart",preset:"kin-el2",label:A?"Kết quả":"Results"}),!B){const H=u3(C.text,A);H&&H.glyph!==I&&(B=H)}return I=B?.el==="icon"?B.glyph:B?.el??null,B}),J=f.map(()=>null);if(s.interlude&&c){const C=y3.test(z),O=P.some(B=>["ai","tech","gaming","saas","data"].includes(B));let L=0;f.forEach((B,H)=>{const q=(B.beats.at(-1).end??B.beats.at(-1).start)-B.beats[0].start;if(!(H>0&&H<f.length-1&&H%3===2&&q>=1&&!J[H-1]))return;const et=C?"cine":O?L%2?"lumen":"pulse":["pulse","cine","lumen"][L%3];let st=(et==="pulse"?Ru:et==="lumen"?s1:kc.map(gt=>gt[1])).filter(gt=>c(gt));if(st.length||(st=Ru.filter(gt=>c(gt))),!st.length)return;const Y=et==="cine"?kc.find(([gt,Z])=>gt.test(B.text)&&c(Z))?.[1]:null,ct=Y??st[(L*5+a)%st.length];J[H]={preset:ct,caption:ct.startsWith("cine-")?"cine-caption":ct.startsWith("lumen-")&&c("lumen-caption")?"lumen-caption":"pulse-word"},_[H]=null,L++})}let X=null;const rt=f.map((C,O)=>{const L=/[!?]$/.test(C.text)||/\d/.test(C.text);let B=(s.looks||o3).filter(q=>q!==X&&(E[O]!==g||!n3.includes(q)));L&&(B=B.filter(q=>r3.includes(q)));const H=B[(O+a)%B.length];return X=H,H}),ot=s.joins||Jx,G=C=>ot[(C-1+a)%ot.length],tt=(C,O)=>`${O.n}|${O.k}|${_[C]?1:0}|${f[C].text}`;let Q=!1,it=0,D=0,U=0;const ht=P.some(C=>["ai","tech","gaming","saas","data"].includes(C)),yt=f.map((C,O)=>{if(!O)return null;if(J[O]||J[O-1])return Q=!0,{mode:"scene"};const L=f[O-1],B=tt(O-1,L.beats.at(-1)),H=tt(O,C.beats[0]),q=/[!?]$/.test(L.text),et=(e1[u]||[]).filter(Z=>!c||c(Z)),st=[...t3,...ht?e3:[],...et,...et],Y=()=>({mode:"lib",preset:st[(it+++a)%st.length]}),ct=_[O]&&!_[O].library?{mode:"cover",a:`word:${B}`,b:"panel"}:_[O-1]&&!_[O-1].library?{mode:"cover",a:`dot:${_[O-1].el}`,b:`word:${H}`}:q?{mode:"cover",a:`letter:${B}`,b:`word:${H}`}:null;let gt=null;if(_[O]?.library||_[O-1]?.library)gt=U++%2?Y():{mode:"cover",a:`word:${B}`,b:_[O]?.library?"none":`word:${H}`};else{const Z=["carrier","push","lib","line"][D++%4];Q?gt=!d&&(Z==="line"||Z==="carrier")?{mode:"line",a:`word:${B}`,b:`word:${H}`}:null:Z==="carrier"?gt=ct??Y():Z==="lib"?gt=Y():Z==="line"&&!d&&(gt={mode:"line",a:`word:${B}`,b:`word:${H}`})}return Q=gt?.mode==="cover"||gt?.mode==="lib",gt}),Mt=C=>["cover","lib","scene"].includes(yt[C]?.mode);y.forEach((C,O)=>{if(J[C.li])return;const L=y[O+1],B=C.bi===0,H=O===0?"zoom":B?Mt(C.li)?"cut":G(C.li):"build",q=L?L.bi===0?Mt(L.li)?"cut":G(L.li):"cut":"zoom",et=O===0?Math.max(0,C.start-.12):B&&!Mt(C.li)?C.start-o/2:C.start,st=L?L.bi===0&&!Mt(L.li)?L.start+o/2:L.start:C.end+n,Y=E[C.li],ct=rt[C.li];S.push({start:ft(et),duration:ft(Math.max(.1,st-et)),line:C.li,params:{...s.style?{style:s.style}:{},text:C.line.text,n:C.n,k:C.k,bg:Y+":"+(Y===g?"dust":Y===v?"glow":C.li%2?"dots":"glow")+(_[C.li]?":top":""),look:ct,color:x(Y),accent:Y===v?x(Y)==="#ffffff"?"#111111":"#ffffff":v,in:H,out:q,io:o,hit:B}}),B&&O>0&&(Mt(C.li)||!d&&C.li%2===0)?k.push({at:ft(Math.max(0,C.start-(Mt(C.li)?.3:o/2+.04))),id:Mt(C.li)?"whoosh-cinematic":Qx[H]||"swoosh"}):B&&O===0&&k.push({at:ft(Math.max(0,et)),id:"impact"})});{const C=[];for(const O of S){const L=C.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=ft(O.start+O.duration-L.start),L.params.out=O.params.out):C.push({...O,params:{...O.params},marks:[[0,O.params.n,O.params.k]]})}S.length=0;for(const O of C){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 p=[];f.forEach((C,O)=>{const L=J[O];if(!L)return;const B=C.beats[0].start,H=f[O+1]?.beats[0].start??C.beats.at(-1).end+n;S.push({start:ft(B),duration:ft(H-B),line:O,preset:L.preset,params:{bg:E[O-1]??m,next:E[O+1]??m,fg:v,text:""}}),H-B>.8&&p.push({start:ft(B+.25),duration:ft(H-B-.55),preset:L.caption,params:{text:C.text.slice(0,120),position:"lower"}}),k.push({at:ft(Math.max(0,B-.05)),id:"whoosh-cinematic"})});const lt=[];if(i&&S.length){const C=S[0].start,O=S.at(-1).start+S.at(-1).duration,L=(H,q)=>_[H]&&!_[H].library?[...i3(_[H].el,r),0]:[...d3[q%4],-1],B=f.map((H,q)=>({li:q,at:H.beats[0].start+(q?.3:0)})).filter(H=>H.li);for(let H=C;H<O-.05;H+=19){const q=Math.min(O,H+19),et=[...f.keys()].filter(Y=>f[Y].beats[0].start<=H+.2).at(-1)??0,st=[[0,...L(et,lt.length*3)]];B.filter(Y=>Y.at>H+.2&&Y.at<q-.05).forEach((Y,ct)=>st.push([+(Y.at-H).toFixed(2),...L(Y.li,lt.length*3+ct+1)])),lt.push({start:ft(H),duration:ft(q-H),params:{pts:st.slice(0,20).map(Y=>Y.map(ct=>+(+ct).toFixed(2)).join(",")).join("|"),accent:v}})}}const V=[...p];f.forEach((C,O)=>{const L=_[O];if(!L)return;const B=S.filter(et=>et.line===O),H=B[0],q=B.at(-1);if(H){if(L.library){V.push({start:H.start,duration:ft(q.start+q.duration-H.start),preset:L.preset,params:L.params,library:!0});return}V.push({start:H.start,duration:ft(q.start+q.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:q.params.out,io:o,dark:H.params.color==="#ffffff",accent:H.params.accent}})}});const h=[];let w=0;yt.forEach((C,O)=>{if(!C||C.mode==="scene")return;const L=f[O].beats[0].start,B=S.filter(et=>et.line===O-1).at(-1)?.params.accent??v;if(C.mode==="lib"){const et=Math.min(.9,(Hl().find(Y=>Y.id===C.preset)?.dur??1)*.8);let st={};try{st=Fi(C.preset,{color:v}).params}catch{}h.push({start:ft(Math.max(0,L-et/2)),duration:ft(et),preset:C.preset,params:st});return}const H=C.mode==="cover"?L-.24:L-o/2-.1,q=C.mode==="cover"?.46:o+.45;h.push({start:ft(Math.max(0,H)),duration:ft(q),preset:"kin-carry",params:{mode:C.mode,a:C.a.slice(0,290),b:C.b.slice(0,290),fill:B,...C.mode==="cover"?{shape:yf[w++%yf.length]}:{}}})});const T=[];if(S.length){const C=S[0].start,O=S.at(-1).start+S.at(-1).duration;for(let L=C;L<O-.05;L+=19)T.push({start:ft(L),duration:ft(Math.min(O,L+19)-L),params:{amount:.5}})}return{beats:S,orbs:lt,sfx:k,texture:T,els:V,carriers:h,lines:f.length,genre:u}}const _3={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"},G3=[{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"]}],K3={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"},V3=[{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}],W3={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"},H3=[{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}],$f={"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},_s={"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"},Ef={"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},X3=[{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}],gC={...W3,..._3,...K3},U3=t=>t.id in $f?{...t,duration:$f[t.id],stereo:!0}:t,Y3=t=>t.id in Ef?{...t,duration:Ef[t.id],stereo:!0,suno:!0}:t,Du=[...G3,...V3].map(U3).concat(H3.map(t=>({...t,stereo:!0}))).map(Y3).concat(X3.map(t=>({...t,stereo:!0}))).filter(t=>!(t.id in _s)),p1=.35,q3=.6,Z3=1.5;Du.map(t=>t.id);const da=t=>Du.find(e=>e.id===t)??(typeof t=="string"&&Object.hasOwn(_s,t)?Du.find(e=>e.id===_s[t]):void 0),J3=[7,6,2],Q3=t=>typeof t=="string"&&Object.hasOwn(_s,t)?_s[t]:null,t5=t=>{const e=typeof t=="string"&&/^\/sfx\/([a-z0-9-]+)\.mp3$/.exec(t);if(!e)return null;const o=Q3(e[1])||e[1];return da(o)?o:null};function e5(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 o5(t,e,o,r,a=null){const n=l=>!e[l]?.locked&&!t.some(u=>u.track===l&&u.start<o+r-1e-6&&u.start+u.duration>o+1e-6);if(a!=null){if(!Ri.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=J3.find(n);if(i===void 0)throw Error("No free audio track at that time — move or delete an overlapping clip");return i}function r5(t,e,o,r,a={}){const{sfx:n,...i}=Bi(t,e,o,r,a);return{...i,nodeId:`music:${o.id}`,label:`Nhạc · ${o.name}`,volume:Number.isFinite(a.volume)?i.volume:q3}}function Bi(t,e,o,r,{volume:a,track:n,id:i}={}){const l=ft(r),u=ft(Math.max(1/Me,o.duration)),c=Number.isFinite(a)?Math.max(0,Math.min(1,a)):p1;return{id:i,nodeId:`sfx:${o.id}`,track:o5(t,e,l,u,n),start:l,duration:u,inPoint:0,sourceDuration:o.duration,volume:c,url:o.url,kind:"audio",label:`SFX · ${o.name}`,sfx:o.id}}const n5={"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"},a5=t=>n5[t]??"pop";function yC({clips:t=[],punches:e=[],existing:o=[]}={},{gap:r=Z3,volume:a=p1}={}){const n=[...t.filter(u=>u&&(u.motion||u.title)&&Number.isFinite(u.start)).map(u=>({at:u.start,sfxId:u.motion?.preset?a5(u.motion.preset):"pop"})),...e.filter(u=>Number.isFinite(u?.at)).map(u=>({at:u.at,sfxId:u.sfxId??"punch"}))].sort((u,c)=>u.at-c.at),i=o.filter(u=>u.sfx||t5(u.url)).map(u=>u.start),l=[];for(const u of n)!da(u.sfxId)||i.some(c=>Math.abs(c-u.at)<r)||(i.push(u.at),l.push({op:"addSfx",sfxId:u.sfxId,at:+u.at.toFixed(3),volume:a}));return l}const u1=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}}),i5=2.6,Bu=Object.freeze(Object.keys(u1)),h1=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"}]}}),s5=Object.freeze(Object.keys(h1)),Sf=t=>+t.toFixed(3),If=(t,[e,o])=>Math.max(e,Math.min(o,t));function Af(t="front",e=16/9,o={}){const r=u1[t];if(!r)throw Error(`Face place must be one of ${Bu.join(", ")}`);const a=If(e,yp.a),{short:n,...i}=r,l={...vb,...i,s:n?n*Math.max(1,a):Math.min(r.s,i5*a),a:Sf(a)},u=c=>typeof c=="number"&&Number.isFinite(c);for(const[c,s]of[["s","s"],["x","x"],["y","y"],["z","z"],["ry","ry"],["rx","rx"],["r","r"],["follow","f"]])u(o[c])&&(l[s]=o[c]);o.mirror!==void 0&&o.mirror!==null&&(l.m=o.mirror===!0||o.mirror===1?1:0);for(const c of Object.keys(l))c in yp&&c!=="m"&&(l[c]=Sf(If(l[c],yp[c])));return l.m||delete l.m,l}const us=t=>t?.face?.v===2&&!!t.face.mesh,Cf=.7,l5=1/30,c5=t=>t<.5?4*t*t*t:1-(-2*t+2)**3/2;function p5({at:t,dur:e}){const o=Math.max(ld.dur[0]/(1-Cf),Number(e)||1.2),r=+(o*Cf).toFixed(3);return $b({at:+(Number(t)+r).toFixed(3),dur:+Math.max(ld.dur[0],o-r).toFixed(3),lead:r})}function _u(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 d1(t,e,o,r){const a=t.find(N=>N.id===e),n=a?.pin?.dive;if(!n?.lead||a.pin.scene)return t;const i=t.find(N=>N.id===a.pin.clip);if(!i)return t;const l=n.at-n.lead,u=n.at,c=n.at+n.dur;let s=i;for(const N of["x","y","zoom"])s={...s,...me(s,N,_u(s,N,l,c))};const d={...a,pin:{...a.pin,dive:void 0}},f=N=>bg(d,t.map(F=>F.id===i.id?s:F),N,o,r),m=f(u);if(!m||!m.every(N=>N.every(Number.isFinite)))return t;const g=N=>[(N[0][0]+N[1][0]+N[2][0]+N[3][0])/4,(N[0][1]+N[1][1]+N[2][1]+N[3][1])/4],[v,x]=g(m),$=Math.max(m[0][0],m[2][0]),E=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(!(E-v>1&&v-$>1&&k-x>1&&x-S>1))return t;const y=1.04*Math.max(o/2/(v-$),o/2/(E-v),r/2/(x-S),r/2/(k-x)),A={x:[],y:[],zoom:[]},I=(N,F,K)=>{const _=N-i.start,[J,X]=g(K),rt=1+(y-1)*F,ot=Zt(s,"x",_),G=Zt(s,"y",_),tt=Zt(s,"zoom",_),Q=[o/2+ot*o,r/2+G*r],it=[J+(o/2-J)*F,X+(r/2-X)*F],D=[it[0]-(J-Q[0])*rt,it[1]-(X-Q[1])*rt];A.x.push({time:+_.toFixed(4),value:+((D[0]-o/2)/o).toFixed(5)}),A.y.push({time:+_.toFixed(4),value:+((D[1]-r/2)/r).toFixed(5)}),A.zoom.push({time:+_.toFixed(4),value:+(tt*rt).toFixed(5)})},z=Math.max(2,Math.round(n.lead/l5));for(let N=0;N<=z;N++){const F=l+n.lead*N/z,K=f(F);K&&I(F,c5(N/z),K)}const j=f(c);j&&I(Math.min(c,i.start+i.duration),1,j);let P=s;for(const N of["x","y","zoom"])P={...P,...me(P,N,[..._u(s,N,l,c),...A[N]].sort((F,K)=>F.time-K.time))};return t.map(N=>N.id===i.id?{...N,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}:{}}:N.id===a.id?{...N,pin:{...N.pin,dive:{...n,keys:!0}}}:N)}function u5(t,e){const o=t.find(l=>l.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(l=>l.id===a):null;let i=n;if(n)for(const l of["x","y","zoom"])i={...i,...me(i,l,_u(i,l,r.at-r.lead,r.at+r.dur))};return t.map(l=>{if(n&&l.id===n.id)return{...l,motionKeys:i.motionKeys,motionV:2};if(l.id!==o.id)return l;if(l.pin?.dive){const{dive:s,...d}=l.pin;return{...l,pin:d}}const{dive:u,...c}=l.pendingPin;return{...l,pendingPin:c}})}function bC(t,e,o){let r=t;for(const a of t)a.pin?.dive?.lead&&!a.pin.dive.keys&&!a.pin.scene&&(r=d1(r,a.id,e,o));return r}const Wh=t=>Math.max(1/30,Math.floor(t*30+1e-6)/30),jf=t=>Math.round(t*1e3)/1e3;function Ts(t,e){if(t.start+e.duration>Fn+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,wg(o),!Zr(t)&&!Zr(o))Object.assign(o,Cb(t,o.duration));else{const r=a=>Math.max(0,Math.min(o.duration,Ba(o,Ui(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:jf(r(a.start)),end:jf(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 h5=t=>{if(["image","model"].includes(t.kind)&&!t.comp)throw Error("Invalid playback speed");if(Bn(t))throw Error("Time remap replaces speed, speed ramp, reverse and freeze frame")};function Gu(t,e){if(h5(t),!Number.isFinite(e)||e<cd||e>pd)throw Error(`Invalid playback speed (${cd}–${pd}×)`);const o=rp(t);return Ts(t,{playbackRate:e,duration:Zr(t)?Wh(o/e):ft(t.duration*(t.playbackRate||1)/e)})}function d5(t){if(!Array.isArray(t)||t.length<2||t.length>ud)throw Error(`Speed ramp needs 2–${ud} 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 f5(t,{preset:e,keys:o,hitAt:r,peak:a}={}){if(t.kind!=="video")throw Error("Speed ramp requires a video clip");if(Bn(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=rp(t);if(e==="normal")return Gu(t,1);if(e!=null&&!o?.length){if(!ic.includes(e))throw Error(`Unknown speed ramp preset (${ic.join(", ")})`);if(Number.isFinite(r)){const{duration:l,speedRamp:u}=Sb(e,n,Ui(t,r),a);return Ts(t,{duration:l,speedRamp:u})}return Ts(t,Ib(e,n,a))}const i=d5(o);return i.every(l=>l.speed===i[0].speed)?Gu(t,i[0].speed):(wg({kind:"video",speedRamp:i}),Ts(t,{speedRamp:i,duration:Wh(Ab(n,i))}))}function Tf(t,e,o,{peak:r}={}){if(t.kind!=="video")throw Error("Speed ramp requires a video clip");if(Bn(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(!ic.includes(e))throw Error(`Unknown speed ramp preset (${ic.join(", ")})`);const a=Wh(o),n=Number.isFinite(t.sourceDuration)?Math.max(.05,t.sourceDuration-(t.inPoint||0)):1/0,i=Eb(e,a,n,r);return Ts(t,{duration:a,speedRamp:i.speedRamp})}const m5=t=>+(+t).toFixed(4),Ma=(t,e)=>m5(Math.max(0,Math.min(t,t-e)));function g5(t){const e=t.duration,o={...jb(t)},r=n=>({...n,keys:n.keys.map(i=>({...i,t:Ma(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=Ma(e,n.out)),n.in!==void 0&&(i.out=Ma(e,n.in)),i})}),Array.isArray(t.planar?.frames)&&(o.planar={...t.planar,frames:t.planar.frames.map(n=>[Ma(e,n[0]),...n.slice(1)]).reverse(),...t.planar.surface?{surface:{...t.planar.surface,t:Ma(e,t.planar.surface.t)}}:{}}),t.roto?.points&&(o.roto={...t.roto,points:t.roto.points.map(n=>[Ma(e,n[0]),n[1],n[2],n[3]]).reverse()});const a=Nh(t.grade);return a.some(n=>n?.motion?.mode==="keys")&&(o.grade=Fh(t.grade,a.map(n=>n?.motion?.mode==="keys"?{...n,motion:{...n.motion,keys:n.motion.keys.map(i=>[Ma(e,i[0]),...i.slice(1)]).reverse()}}:n))),o}const Ul=t=>Math.round(t*30)/30;function Of(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=Ul(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=Ul((o?.duration||0)-a.duration),l=t.flatMap(u=>u.id===e?o?[{...o,start:a.start}]:[]:[{...u,...u.track===a.track&&u.start>=n-1/60?{start:Ul(u.start+i)}:{}}]);if(l.some(u=>u.start<0||u.start+u.duration>600))throw Error("Ripple exceeds timeline bounds");return l}function y5(t,e,o,r,a={}){const n=t.find(c=>c.id===e),i=n&&t.find(c=>c.id!==e&&c.track===n.track&&Math.abs(c.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 l=o==="none"?0:Ul(r/2),u=o==="fade-white"?"white":"black";return t.map(c=>c.id===e?{...c,visualFadeOut:l,fadeOutColor:u}:c.id===i.id?{...c,visualFadeIn:l,fadeInColor:u}:c)}function wC(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 b5=["font","color","emphasisColor","emphasisColor2","strokeColor","strokeWidth","shadow","glow","box","boxOpacity","boxShape","emphasisText","upper","trColor","hl"],ke=t=>({emphasisColor:t,emphasisColor2:t}),f1=[{id:"classic",label:"Cổ điển",font:"Noto Sans",color:"#ffffff",...ke("#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",...ke("#ffffff"),strokeWidth:1.6,upper:!0},{id:"green-hi",label:"Xanh nổi",font:"Montserrat ExtraBold",color:"#ffffff",...ke("#3dff4f"),upper:!0,strokeWidth:1.3},{id:"red-hi",label:"Đỏ nổi",font:"Montserrat ExtraBold",color:"#ffffff",...ke("#ff3b30"),upper:!0,strokeWidth:1.3},{id:"challenge",label:"Thử thách",font:"Paytone One",color:"#ffffff",...ke("#ffe600"),strokeWidth:2.2,shadow:"#000000"},{id:"comic",label:"Truyện tranh",font:"Bangers",color:"#ffffff",...ke("#ff3b30"),strokeWidth:1.8,shadow:"#000000"},{id:"black-box",label:"Hộp đen",font:"Be Vietnam Pro ExtraBold",color:"#ffffff",...ke("#ffe14a"),strokeWidth:0,box:"#000000",boxOpacity:.72,boxShape:"line"},{id:"white-box",label:"Hộp trắng",font:"Be Vietnam Pro ExtraBold",color:"#111111",...ke("#e5232b"),strokeWidth:0,box:"#ffffff",boxOpacity:1,boxShape:"line"},{id:"news-red",label:"Tin nóng",font:"Oswald Bold",color:"#ffffff",...ke("#ffe14a"),strokeWidth:0,box:"#d7141a",boxOpacity:.95,boxShape:"block",upper:!0},{id:"yellow-word",label:"Ô vàng",font:"Paytone One",color:"#ffffff",...ke("#ffd60a"),strokeWidth:1.2,box:"#ffd60a",boxShape:"word",emphasisText:"#111111"},{id:"blue-word",label:"Ô xanh dương",font:"Lexend Bold",color:"#ffffff",...ke("#2f6bff"),strokeWidth:1,box:"#2f6bff",boxShape:"word",emphasisText:"#ffffff"},{id:"pink-word",label:"Ô hồng",font:"Baloo 2",color:"#ffffff",...ke("#ff3ea5"),strokeWidth:1,box:"#ff3ea5",boxShape:"word",emphasisText:"#ffffff"},{id:"neon-yellow",label:"Neon vàng",font:"Lexend Bold",color:"#f6ff8a",...ke("#ffffff"),strokeWidth:0,glow:"#d4ff00"},{id:"neon-cyan",label:"Neon xanh",font:"Chakra Petch",color:"#e9feff",...ke("#00e5ff"),strokeWidth:0,glow:"#00c8ff"},{id:"neon-pink",label:"Neon hồng",font:"Lobster",color:"#fff0fb",...ke("#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",...ke("#c6f432"),strokeWidth:1.2,shadow:"#000000"},{id:"soft-shadow",label:"Bóng mềm",font:"Be Vietnam Pro ExtraBold",color:"#ffffff",...ke("#ffe14a"),strokeWidth:0,shadow:"#000000"},{id:"minimal",label:"Tối giản",font:"Be Vietnam Pro",color:"#ffffff",...ke("#ffffff"),strokeWidth:0,shadow:"#000000"},{id:"cinema",label:"Điện ảnh",font:"Playfair Display",color:"#f5f0e6",...ke("#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",...ke("#ffd1e8"),strokeColor:"#1a1a1a",strokeWidth:.6,shadow:"#000000"},{id:"hand",label:"Viết tay",font:"Patrick Hand",color:"#fff8e7",...ke("#ffd23f"),strokeColor:"#3a2a1a",strokeWidth:1},{id:"retro",label:"Retro",font:"Lobster",color:"#ffe9a8",...ke("#ff9b54"),strokeColor:"#7a2e00",strokeWidth:1.2},{id:"candy",label:"Kẹo ngọt",font:"Baloo 2",color:"#ffffff",...ke("#ffe14a"),strokeColor:"#ff4fa3",strokeWidth:1.6},{id:"orange-pop",label:"Cam rực",font:"Paytone One",color:"#ff8a1f",...ke("#ffe14a"),strokeColor:"#ffffff",strokeWidth:1.4,shadow:"#5a1a00"},{id:"aqua",label:"Xanh ngọc",font:"Lexend Bold",color:"#5ef3ff",...ke("#ffffff"),strokeColor:"#062a33",strokeWidth:1.2},{id:"gaming",label:"Game",font:"Chakra Petch",color:"#ffffff",...ke("#a6ff00"),strokeWidth:1.3,upper:!0},{id:"pastel",label:"Pastel",font:"Baloo 2",color:"#4a1d3a",...ke("#c2185b"),strokeWidth:0,box:"#ffc4dc",boxOpacity:.92,boxShape:"line"},{id:"karaoke-green",label:"Karaoke xanh",font:"Bungee",color:"#ffffff",...ke("#39ff14"),strokeWidth:1.2},{id:"kinetic-red",label:"Chữ nhấn đỏ khổng lồ",font:"Montserrat ExtraBold",color:"#ffffff",...ke("#e8251a"),strokeWidth:0,shadow:"#000000",emphasisScale:1.9},{id:"surf",label:"Biển xanh",font:"Pacifico",color:"#ffffff",...ke("#7ee8fa"),strokeColor:"#0b4f6c",strokeWidth:1}],w5=new Map(f1.map(t=>[t.id,t])),m1=t=>w5.get(t)||null;function k5(t){const e=m1(t);if(!e)throw Error(`Unknown caption look "${t}"`);const o={look:t};for(const r of b5)o[r]=e[r];return e.emphasisScale&&(o.emphasisScale=e.emphasisScale),o}function zf(t,e){const o={...t||{style:"classic"},...k5(e)};for(const r of Object.keys(o))o[r]===void 0&&delete o[r];return yi(o)}const g1=[{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"}],x5=new Map(g1.map(t=>[t.id,t])),y1=t=>x5.get(t)||null;function M5(t,e){const o=y1(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 v5=[.3,1.9,.5,1],Tp={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:v5}},Op={fade:{type:"fade",duration:.3},pop:{type:"pop",duration:.3,amount:.5},slide:{type:"slide-down",duration:.4,amount:.25}},Pf=.5,$5=.8,E5=.6,S5=28,ll=(t,e,o)=>Math.max(e,Math.min(o,t));function I5(t){const e=t?.element?.anim??{};return{in:xg.includes(e.in)?e.in:"none",out:Mg.includes(e.out)?e.out:"none",loop:vg.includes(e.loop)?e.loop:"none"}}const A5=(t,e)=>[...e.in==="spin"||e.loop==="wiggle"?["rot"]:[],...e.loop==="pulse"?["zoom"]:[],...e.loop==="float"?["y"]:[]].includes(t);function zp(t,e,o,r,a,n){const i=[];for(let l=0,u=t;u<=e+1e-6&&i.length<S5;l++,u=t+l*a)i.push({time:ft(Math.min(u,e)),value:l%2?r:o,...l%2===0?{ease:n}:{}});return i.filter((l,u)=>!u||l.time>i[u-1].time+1/60)}function C5(t,e={}){const o=I5(t),r=!!t.element?.anim,a=kg(t.element?.id)?.anim??Tb,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(!xg.includes(n.in)||!Mg.includes(n.out)||!vg.includes(n.loop))throw Error("Unknown element animation preset");let i={...t};for(const f of["rot","zoom","y"])A5(f,o)&&(i={...i,...me(i,f,[])});if(o.in==="wipe"||o.out==="wipe"){const{revealType:f,reveal:m,...g}=i;i={...g,...me(g,"reveal",[])}}o.in==="draw"&&(i={...i,...me(i,"trimEnd",[])}),delete i.enter,delete i.exit;const l=i.duration;Tp[n.in]&&(i.enter={...Tp[n.in],duration:Math.min(Tp[n.in].duration,l/2)}),Op[n.out]&&(i.exit={...Op[n.out],duration:Math.min(Op[n.out].duration,l/2)});const u=ll(Zt(i,"rot",0),-180,180),c=ft(Math.min(E5,l)),s=n.in==="spin"?[{time:0,value:-180,ease:Qt["ease-out"]}]:[];let d=s;if(n.loop==="wiggle"?d=[...s,...zp(s.length?c:0,l,u,ll(u+5,-180,180),.2,Qt["ease-in-out"])]:s.length&&(d=[...s,{time:c,value:u}]),d.length>1&&(i={...i,...me(i,"rot",d)}),n.loop==="pulse"){const f=Zt(i,"zoom",0);i={...i,...me(i,"zoom",zp(0,l,f,ll(f*1.08,0,ns),.4,Qt["ease-in-out"]))}}if(n.loop==="float"){const f=Zt(i,"y",0);i={...i,...me(i,"y",zp(0,l,f,ll(f-.03,-1,1),.8,Qt["ease-in-out"]))}}if(n.in==="wipe"||n.out==="wipe"){const f=[];n.in==="wipe"&&f.push({time:0,value:0,ease:Qt["ease-out"]},{time:ft(Math.min(Pf,l/2)),value:1}),n.out==="wipe"&&f.push({time:ft(l-Math.min(Pf,l/2)),value:1,ease:Qt["ease-in"]},{time:ft(l),value:0}),i={...i,revealType:"wipe-left",...me(i,"reveal",f.filter((m,g)=>!g||m.time>f[g-1].time+1/60))}}return n.in==="draw"&&i.shape&&(i={...i,...me(i,"trimEnd",[{time:0,value:0,ease:Qt["ease-out"]},{time:ft(Math.min($5,l/2)),value:1}])}),i.element={...i.element??{},anim:n},kn(i),i}[...Object.keys(Hg)];const j5=4,T5=/^gs:\/\/[\w.-]+\/(uploads|assets|outputs)\/[^\s?#\\]+$/,wi=t=>typeof t=="string"&&t.length<=400&&!t.includes("..")&&T5.test(t),kC=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 O5(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 xC=(t,e)=>t.map(o=>{if(o?.op!=="generateBroll"||o.refs?.length||!Number.isFinite(o.start)||!Number.isFinite(o.duration))return o;const r=O5(e,o.start,o.duration);return r?{...o,refs:r.refs.map(a=>a.gcsUri)}:o}),z5=["dissolve","cut","whip"],P5=.12,L5=.08,N5=1.06,F5=.2,R5=.12,b1=.35,D5=.7,w1=/[.!?…。]["')\]]*$/,B5=/[,;:,]["')\]]*$/,Pp=t=>Math.floor(t*Me+1e-6)/Me,hs=t=>Math.ceil(t*Me-1e-6)/Me,Lf=t=>Math.round(t*1e3)/1e3;function _5(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(l=>l.id===a.nodeId);Array.isArray(i?.words)&&i.words.length?n=Rh(a,i.words):a.captions?.length&&(n=np(a.captions))}for(const i of n??[])o.push({start:Lf(a.start+i.start),end:Lf(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 Nf(t,{gap:e=b1,maxWords:o=14,soft:r=!0}={}){const a=[];let n=[];return t.forEach((i,l)=>{n.push(i);const u=t[l+1];(!u||u.start-i.end>=e||w1.test(i.word)||r&&B5.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(l=>l.word).join(" "),words:i}))}function MC(t,e){const o=Nf(t);if(!o.length)return null;let r=o.findIndex(l=>e>=l.start-.05&&e<=l.end+.05);r<0&&(r=o.findIndex(l=>l.start>e)),r<0&&(r=o.length-1);const a=Nf(t,{gap:D5,maxWords:60,soft:!1}),n=Math.max(0,a.findIndex(l=>o[r].start>=l.start-.001&&o[r].start<=l.end+.001)),i=a.slice(Math.max(0,n-1),n+2).map(l=>l.text).join(" ").slice(0,600);return{start:o[r].start,end:o[r].end,text:o[r].text,context:i}}function G5(t,e,o,{min:r=2,max:a=8,lead:n=P5,tail:i=L5}={}){const l=Math.min(e,o),u=Math.max(e,o),c=a-1/Me,s=()=>{const z=Pp(Math.max(0,l)),j=ft(Math.min(a,Math.max(r,u-l)));return{start:z,end:ft(z+j),duration:j,snapped:!1,words:[]}},d=t.filter(z=>z.end>z.start),f=d.findIndex(z=>z.end>l+.02);if(f<0||d[f].start>=u-.02)return s();let m=f;for(;m+1<d.length&&d[m+1].start<u-.02;)m++;const g=d[f-1],v=d[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 $=Pp(x);g&&$<g.end-1e-6&&($=Math.min(v.start,hs(g.end)));const E=z=>z===d.length-1||d[z+1].start-d[z].end>=b1||w1.test(d[z].word),S=z=>d[z].end+i-$;let k=m;if(!E(m)){let z=m+1;for(;z<d.length&&S(z)<=c&&d[z].end-u<=1.5&&!E(z);)z++;if(z<d.length&&S(z)<=c&&d[z].end-u<=1.5&&E(z))k=z;else{let j=m-1;for(;j>f&&!E(j);)j--;j>=f&&E(j)&&d[j].end-$>=r*.6&&(k=j)}}const y=z=>{const j=d[z+1];let P=d[z].end+i;j&&j.start>=d[z].end&&(P=Math.min(P,(d[z].end+j.start)/2));let N=hs(P);return j&&N>j.start+1e-6&&j.start>=d[z].end&&hs(d[z].end)<=j.start&&(N=hs(d[z].end)),N};for(;k>f&&y(k)-$>c;)k--;let A=y(k);if(A-$<r-1e-6){const z=hs($+r);for(;k+1<d.length&&d[k+1].start<z-1e-6&&y(k+1)-$<=c;)k++;A=Math.max(z,y(k))}let I=!1;return A-$>a+1e-6&&(A=Pp($+a),I=!0),d.some(z=>z.start<A-1e-6&&z.end>A+1e-6)&&(I=!0),{start:ft($),end:ft(A),duration:ft(A-$),snapped:!0,clipped:I,words:d.slice(f,k+1)}}function Ku(t,e,o,r,a=null,{fallback:n=!1}={}){const{track:i,moved:l}=qt(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),c=Math.max(0,...u.map(s=>s.zIndex??0));return{track:i,...c>0?{zIndex:Math.min(100,c)}:{},...l?{moved:l}:{}}}function vC(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 K5(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:ft(t),zoom:N5}],a.motionV=2),e==="dissolve"){const n=Math.max(.05,Math.min(F5,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(R5,t/4));a.enter={type:"slide-left",amount:1,duration:n},a.exit={type:"slide-left",amount:1,duration:n}}return a}function V5({clips:t,tracks:e={},materials:o=[],generator:r,prompt:a,start:n,duration:i,layout:l="cutaway",transition:u="dissolve",pushIn:c,colorMatch:s=!0,preset:d,track:f=null,trackFallback:m=!1,newId:g,refs:v}){const x=Hg[r];if(!x)throw Error("Unsupported B-roll generator");const $=typeof a=="string"?a.trim():"";if($.length<12||$.length>1200)throw Error("B-roll prompt must be 12–1200 characters");if(!$g.includes(l))throw Error("Unsupported B-roll layout");if(v!==void 0&&(!Array.isArray(v)||v.length>j5||!v.every(wi)))throw Error("Invalid B-roll reference images");if(!z5.includes(u))throw Error("Unsupported B-roll transition");if(!Number.isFinite(n)||!Number.isFinite(i)||n<0||i<1/Me||n+i>Fn)throw Error("Invalid creative clip timing");const E=_5(t,o),S=E.length?G5(E,n,n+i,{min:x.min,max:x.max}):null,k=S?.snapped?S.start:ft(n),y=S?.snapped?S.duration:ft(i);if(y<x.min-1e-6||y>x.max+1e-6)throw Error(`${x.label}: ${x.min}–${x.max}s`);if(k+y>Fn)throw Error("Invalid creative clip timing");const{moved:A,...I}=Ku(t,e,k,k+y,f,{fallback:m}),z=c??!0,j=K5(y,{transition:u,pushIn:z,layout:l});d&&d!=="none"?j.motionKeys=Vl(d,y):d==="none"&&(delete j.motionKeys,delete j.motionV);const P={nodeId:"",kind:"video",url:"",label:`AI B-roll · ${$.slice(0,40)}`,inPoint:0,sourceDuration:y,volume:0,fit:"cover",layout:l,...I,...j,id:g(),start:k,duration:y,gen:{status:"pending",generator:r,prompt:$,duration:y,finish:{transition:u,pushIn:z&&l==="cutaway",colorMatch:s},...v?.length?{refs:[...v]}:{}}};return{clip:P,snap:S,...A?{trackNote:`track ${f} → ${P.track} (${A})`}:{}}}const W5=["green","black","alpha"],H5=[{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"}];H5.map(t=>t.id);const Vu=[.5,.85],Ff=[.1,4],X5=/^#[0-9a-f]{6}$/i,U5=(t,e,o)=>Math.min(o,Math.max(e,t)),Ga=t=>Math.round(t*1e4)/1e4;function Y5(t){if(!t||typeof t!="object")throw Error("Footage VFX: thiếu nền (green / black / alpha)");if(!W5.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??$u.color;if(typeof a!="string"||!X5.test(a))throw Error("Footage VFX: màu key không hợp lệ");e.keyColor=a.toLowerCase()}const o=Number(t.anchorU??Vu[0]),r=Number(t.anchorV??Vu[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=Ga(o),e.anchorV=Ga(r),e}const q5=t=>({...$u,color:(t||$u.color).toLowerCase(),similarity:.14,blend:.1,spill:.7});function Z5(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,l=n>=a?a/n:1,u=U5(Number(r)||1,Ff[0],Ff[1]);if(!o)return{posX:0,posY:0,scale:Ga(u)};const[c,s]=o;return{posX:Ga(c-.5-(e.anchorU-.5)*i*u),posY:Ga(s-.5-(e.anchorV-.5)*l*u),scale:Ga(u)}}const J5=(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 Rf({id:t,track:e,start:o,duration:r,footage:a,frame:n,at:i,scale:l,sound:u=!1}){const c=Y5(a),s=Z5(n,{...a,...c},i,l);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}:{},...J5(a.proxy,c.bg)??{},label:String(a.name||"VFX").slice(0,80),volume:u?1:0,motionV:2,...s,...c.bg==="green"?{key:q5(c.keyColor)}:c.bg==="black"?{blend:"screen"}:{},vfxFootage:{...a.id?{id:a.id}:{},bg:c.bg,anchor:[c.anchorU,c.anchorV],...a.width>0&&a.height>0?{aspect:Ga(a.width/a.height)}:{}}}}const Q5="clipoox-canvas-assets",t4=t=>`gs://${Q5}/library/models/${t}/model.glb`,e4=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:t4(t.sha)})));function o4(t){return e4.find(e=>e.id===t)??null}function r4(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 $C(t){return{label:t.name.slice(0,60),center:[...t.at],zoom:t.zoom??16.4,pitch:55,bearing:t.bearing??0}}const Wu=1e3,sp=["ờ","ơ","ừm","ưm","ừ","ờm","hừm","hmm","hm","ừa","um","umm","uh","uhm","erm","er","ah","eh","mm"],k1=t=>String(t||"").normalize("NFC").toLowerCase().replace(/[^\p{L}]/gu,""),qs=t=>{const e=k1(t);return!!e&&sp.includes(e)};function n4(t=[]){return t.flatMap(e=>sp.includes(k1(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 a4(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<=Wu?o:[...o].sort((n,i)=>r(n)-r(i)||i.end-i.start-(n.end-n.start)||n.start-i.start).slice(0,Wu)).sort((n,i)=>n.start-i.start)}function i4(t){if(!Array.isArray(t)||t.length>Wu||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 Yl=Object.freeze({min:.3,lead:.05,tail:.08,long:.6,minShare:.25,minWords:10}),x1=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 s4(t,e,{min:o,lead:r,tail:a}=Yl){const n=x1(t).filter(u=>!qs(u.word)),i=[],l=(u,c)=>{c-u>=o-r-a&&c-u>.05&&i.push({start:Math.max(0,u),end:c})};if(!n.length)return i;n[0].start>=o&&l(0,n[0].start-a);for(let u=1;u<n.length;u++)n[u].start-n[u-1].end>=o&&l(n[u-1].end+r,n[u].start-a);return Number.isFinite(e)&&e-n.at(-1).end>=o&&l(n.at(-1).end+r,e),i}function M1(t){const e=Array.isArray(t?.pauses)?t.pauses:null,o=x1(t?.words).filter(l=>!qs(l.word));if(o.length<Yl.minWords)return e;const r=[];for(let l=1;l<o.length;l++)o[l].start-o[l-1].end>=Yl.long&&r.push({start:o[l-1].end,end:o[l].start});if(!r.length)return e;const a=(e||[]).filter(l=>l?.kind==="silence"),n=r.filter(l=>a.some(u=>Math.min(u.end,l.end)-Math.max(u.start,l.start)>=.5*(l.end-l.start))).length;if(e&&n>=Yl.minShare*r.length)return e;const i=[...(e||[]).filter(l=>l?.kind==="filler").map(l=>({start:l.start,end:l.end,text:String(l.text||"")})),...n4(t.words)].filter((l,u,c)=>c.findIndex(s=>Math.abs(s.start-l.start)<.05)===u);return a4(s4(t.words,Number(t.duration)),i)}function l4(t,e,o,{minGap:r=.6,padding:a=.12,fillers:n=!1,maxClips:i=100,isBed:l=s=>s.kind==="audio"&&s.nodeId!==o?.id}={},u={},c=()=>Math.random().toString(36).slice(2,10)){const s=t.find(I=>I.id===e);if(!s||!["video","audio"].includes(s.kind))throw Error("Pause removal needs a video or audio clip");if(s.reverse)throw Error("Pause removal does not support reversed clips");if(u[s.track]?.locked)throw Error("Track is locked");const d=M1(o);if(!d)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=Dh(i4(d).flatMap(I=>I.kind==="filler"?n?[{start:I.start-.02,end:I.end+.02}]:[]:I.end-I.start>=r?[{start:I.start+a,end:I.end-a}]:[]).map(I=>({start:Math.max(I.start,m),end:Math.min(I.end,g)})).filter(I=>I.end-I.start>=2/30)).map(I=>({start:ft(s.start+(I.start-m)/f),end:ft(s.start+(I.end-m)/f)})).filter(I=>I.end-I.start>=2/30);const $=Math.max(0,i-t.length),E=Math.max(0,x.length-$);E&&(x=[...x].sort((I,z)=>z.end-z.start-(I.end-I.start)).slice(0,$)),x.sort((I,z)=>z.start-I.start);let S=t.map(I=>({...I})),k=0,y=E,A=0;for(const I of x){const z=S.find(X=>X.track===s.track&&X.nodeId===s.nodeId&&X.start<=I.start+1e-6&&X.start+X.duration>=I.end-1e-6),j=!z||S.some(X=>X.track!==s.track&&!l(X)&&X.start<I.end-1/60&&X.start+X.duration>I.start+1/60)||S.some(X=>u[X.track]?.locked&&X.start>=I.end-1/60),P=z&&I.start<=z.start+1/30,N=z&&I.end>=z.start+z.duration-1/30;if(j||P&&N){y++;continue}let F=null,K=null;if(P)K=Fe(z,I.end,c())[1];else if(N)F=Fe(z,I.start,c())[0];else{const[X,rt]=Fe(z,I.start,c());F=X,K=rt&&Fe(rt,I.end,c())[1]}if(!F&&!K){y++;continue}const _=ft(I.end-I.start),J=[...F?[F]:[],...K?[{...K,id:F?K.id:z.id,start:I.start}]:[]];S=S.flatMap(X=>X.id===z.id?J:[X.start>=I.end-1/60&&!(l(X)&&X.start<I.end+1/60&&X.start>I.start)?{...X,start:ft(X.start-_)}:X]),k++,A+=_}return{clips:S,removed:k,skipped:y,saved:ft(A)}}function c4(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(l=>l.id===n.nodeId);for(const l of sc(n,Array.isArray(i?.transcript)?i.transcript:[]))a.push({start:n.start+l.start,end:n.start+l.end})}return Dh(a,.4)}function p4(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=c4(t,o,a,n);if(!i.length)throw Error("No analysed speech to duck under — analyze the talking-head clip first");let l=0;return{clips:t.map(c=>{if(!n.has(c.id))return c;if(a[c.track]?.locked)throw Error("Track is locked");if(!["audio","video"].includes(c.kind))throw Error("Only audio/video clips can be ducked");const s=Dh(i.flatMap(d=>{const f=Math.max(0,d.start-c.start),m=Math.min(c.duration,d.end-c.start);return m>f?[{start:+f.toFixed(3),end:+m.toFixed(3)}]:[]}),2*Pb).slice(0,zb);if(!s.length){const{duck:d,...f}=c;return f}return l++,{...c,duck:{level:+r.toFixed(3),ranges:s}}}),ducked:l}}function u4(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)),l=Number.isFinite(o)?Math.max(0,Math.min(1,o)):.5,u=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,c=(i-1)/2,s=a>n?Math.max(-c,Math.min(c,i*(.5-l))):0,d=a<n?Math.max(-c,Math.min(c,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,d)).toFixed(4)}}function h4(t,e,o,{clipId:r}={},a={}){const n=Ob(o);let i=0;const l=[];return{clips:t.map(c=>{if(r?c.id!==r:c.kind!=="video"&&c.kind!=="image"||c.title)return c;const s=e.find(g=>g.id===c.nodeId),d=c.label||c.id;if(a[c.track]?.locked)return l.push(`${d}: locked`),c;if(!(s?.width>0&&s?.height>0))return l.push(`${d}: size unknown (analyze first)`),c;if(Ee(c,"x").length||Ee(c,"zoom").length||Ee(c,"y").length)return l.push(`${d}: has position keyframes`),c;const f=(c.inPoint||0)+c.duration*(c.playbackRate||1)/2,m=(s.scenes||[]).find(g=>g.start<=f&&g.end>f)||(s.scenes||[]).find(g=>Number.isFinite(g.subjectX));return i++,{...c,...u4(s.width/s.height,n,m?.subjectX,m?.subjectY),motionV:2}}),reframed:i,skipped:l}}const _i=Object.freeze({reach:.6,breath:.08,near:.04});function Lp(t,e){if(!Array.isArray(t)||!t.length||!Number.isFinite(e))return e;const o=t.findIndex(c=>c.start<e&&e<c.end),r=c=>{const s=t[c-1],d=t[c];return s?[s.end,d.start]:[Math.max(0,d.start-.3),d.start]},a=c=>{const s=t[c],d=t[c+1];return d?[s.end,d.start]:[s.end,s.end+.3]},n=([c,s],d)=>{const f=Math.max(0,s-c),m=Math.min(_i.breath,f/2);return d==="before"?s-m:c+m};if(o>=0){const c=t[o];return(c.start+c.end)/2>e?n(r(o),"before"):n(a(o),"after")}const i=t.findIndex(c=>c.start>=e),l=i>0?t[i-1]:i<0?t[t.length-1]:null,u=i>=0?t[i]:null;return u&&u.start-e<_i.near?n([l?l.end:u.start-.3,u.start],"before"):l&&e-l.end<_i.near?n([l.end,u?u.start:l.end+.3],"after"):e}const Co=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}),v1=Object.freeze(["best","last","first"]),d4=/[.?!…。]["'”’)\]]*$/u,$1=t=>String(t||"").normalize("NFC").toLowerCase().replace(/[^\p{L}\p{N}]/gu,""),as=t=>$1(t).normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d"),f4=new Set(sp),m4=new Set([...sp,"à","like","kiểu"]),g4=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(" ")),Df=t=>(t.kind==="video"||t.kind==="audio")&&!t.reverse&&!t.title&&!t.motion&&!t.shape,Bf=t=>!!(t&&(Array.isArray(t.words)&&t.words.length||Array.isArray(t.transcript)&&t.transcript.length));function y4(t){return Array.isArray(t.words)&&t.words.length?t.words.filter(e=>e&&Number.isFinite(e.start)&&Number.isFinite(e.end)&&e.end>e.start&&typeof e.word=="string"):t.transcript.flatMap(e=>{const o=String(e?.text||"").split(/\s+/).filter(Boolean);if(!o.length||!(e.end>e.start))return[];const r=(e.end-e.start)/o.length;return o.map((a,n)=>({start:e.start+n*r,end:e.start+(n+1)*r,word:a,...n===o.length-1?{cueEnd:!0}:{}}))})}const E1=t=>(Array.isArray(t?.pauses)?t.pauses:[]).filter(e=>e?.kind==="filler"&&Number.isFinite(e.start)&&e.end>e.start),S1=(t,e,o,r)=>Math.max(0,Math.min(e,r)-Math.max(t,o));function Hu(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 d=1;d<=a;d++)i[s*n+d]=t[s-1]===e[d-1]?i[(s-1)*n+d-1]+1:Math.max(i[(s-1)*n+d],i[s*n+d-1]);let l=r,u=a,c=0;for(;l>0&&u>0;)t[l-1]===e[u-1]?(o[l-1]&&c++,l--,u--):i[(l-1)*n+u]>=i[l*n+u-1]?l--:u--;return{len:i[r*n+a],mc:c}}const Np=t=>t.reduce((e,o)=>e+(o?1:0),0);function _f(t,e,o=Co.minSimilarity){const r=t.keys,a=e.keys;if(r.length<2||a.length<2)return null;let n=null;const[i,l]=r.length<=a.length?[t,e]:[e,t];if(i.keys.length<l.keys.length&&i.keys[0]===l.keys[0]){const u=Hu(i.keys,l.keys.slice(0,i.keys.length+1),i.content),c=i.keys.length-(i.keys.length>=4?1:0);u.len>=c&&u.mc>=1&&u.mc===Np(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=Np(t.content),c=Np(e.content);if(u>=2&&c>=2){const s=Hu(r,a,t.content),d=+(2*s.len/(r.length+a.length)).toFixed(4);d>=o&&s.mc>=.8*Math.min(u,c)-1e-9&&s.mc>=.5*Math.max(u,c)-1e-9&&(!n||d>n.sim)&&(n={kind:"full",sim:d})}}return n}function I1(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 l of[0,1]){const u=a+i+l;if(u+i>r)continue;let c=!0;for(let s=0;s<i&&c;s++)c=t[a+s]===t[u+s];if(c&&(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 b4(t,e,o,r){const a=s=>e.find(d=>d.id===s);let n;if(Array.isArray(o)&&o.length){n=o.map(d=>{const f=t.find(m=>m.id===d);if(!f)throw Error(`Clip not found: ${d}`);return f});const s=n.find(d=>!Df(d)||!Bf(a(d.nodeId)));if(s)throw Error(`"${s.label||s.id}" has no analysed speech (video / audio with a transcript)`)}else n=t.filter(s=>Df(s)&&Bf(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,l=[...n].sort((s,d)=>Number(i(d))-Number(i(s))||(s.kind==="audio")-(d.kind==="audio")||s.track-d.track||s.start-d.start),u=[],c=[];for(const s of l)(u.filter(f=>f.track!==s.track).reduce((f,m)=>f+S1(s.start,s.start+s.duration,m.start,m.start+m.duration),0)>=s.duration*.5?c:u).push(s);return{primary:u,companions:c}}function w4(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,l=i+r.duration*n,u=r.start+r.duration,c=o.get(r.track)??[];o.set(r.track,c);for(const s of y4(a)){const d=(s.start+s.end)/2;if(d<i-1e-6||d>=l-1e-6)continue;const f=$1(s.word),m=as(s.word),g=!m||m4.has(f);c.push({t:r.start+(Math.max(s.start,i)-i)/n,te:r.start+(Math.min(s.end,l)-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&&!g4.has(f),filler:f4.has(f),stop:d4.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 k4(t,e){const o=new Map,r=[];let a=null;const n=(i,l)=>{if(i.node!==l.node)return 0;let u=o.get(i.node);return u||(u=E1(e.find(c=>c.id===i.node)),o.set(i.node,u)),u.reduce((c,s)=>c+S1(i.e,l.s,s.start,s.end),0)/(i.rate||1)};t.forEach((i,l)=>{const u=t[l-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)>=Co.pause||a.keys.length>=Co.maxWords)&&(a?.keys.length&&r.push(a),a={w0:l,w1:l,keys:[],content:[],keyWord:[]}),a.w1=l,i.key&&(a.keys.push(i.key),a.content.push(i.content),a.keyWord.push(l))}),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 x4(t,{window:e,minSimilarity:o}){const r=new Array(t.length).fill(-1),a=[];for(let i=0;i<t.length;i++){let l=null;for(let c=i-1;c>=0&&i-c<=Co.lookBack&&!(t[i].t-t[c].te>e);c--){const s=_f(t[c],t[i],o);if(!s)continue;let d=0;for(let f=c+1;f<i;f++)t[f].keys.length>=4&&(r[c]<0||r[f]!==r[c])&&d++;(s.kind==="prefix"?d>0||t[i].t-t[c].te>Co.restartGap:d>Co.maxBetween)||(!l||s.sim>l.rel.sim+1e-9)&&(l={i:c,rel:s})}if(!l)continue;let u=r[l.i];u<0&&(u=a.length,a.push([l.i]),r[l.i]=u),a[u].push(i),r[i]=u}const n=[];for(let i=1;i<t.length;i++){const l=t[i-1],u=t[i];if(r[i-1]>=0||u.t-l.te>Co.restartGap)continue;const c=l.keys.lastIndexOf(u.keys[0]);c<2||l.keys.length-c<3||_f({keys:l.keys.slice(c),content:l.content.slice(c)},u,o)&&n.push({i:i-1,j:i,p:c})}return{groups:a,gid:r,tails:n}}function M4(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+=E1(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=I1(n,e.content).length;for(let f=1;f<n.length;f++)n[f]===n[f-1]&&i++;const l=r.filter(f=>f.key);let u=0;for(let f=1;f<l.length;f++)u+=Math.max(0,l[f].t-l[f-1].te-.3);const c=l.slice(1).map((f,m)=>f.t-l[m].t),s=c.reduce((f,m)=>f+m,0)/(c.length||1),d=c.length>=2&&s>0?Math.sqrt(c.reduce((f,m)=>f+(m-s)**2,0)/c.length)/s:0;return{fillers:a,restarts:i,longPause:+u.toFixed(3),steady:+Math.max(0,1-Math.min(1,d)).toFixed(3)}}const A1=(t,e=5)=>{const o=t.split(/\s+/).filter(Boolean);return o.length>e?`${o.slice(0,e).join(" ")}…`:o.join(" ")};function v4(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 $4(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 E4(t,e=[],o={}){const r=o.keep??"best";if(!v1.includes(r))throw Error("keep must be best, last or first");const a=o.window??Co.window,n=o.minSimilarity??Co.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:l,companions:u}=b4(t,e,o.clipIds,i),c=w4(l,e),s=[];for(const[m,g]of[...c].sort((v,x)=>v[0]-x[0])){const v=k4(g,e),{groups:x,gid:$,tails:E}=x4(v,{window:a,minSimilarity:Math.max(.4,n)}),S=[];for(const k of x){const y=k.map(A=>({w0:v[A].w0,w1:v[A].w1,keys:v[A].keys,content:v[A].content}));S.push({kind:"repeat",track:m,takes:y,between:[],utt:k})}for(const{i:k,j:y,p:A}of E){const I=v[k],z={w0:I.keyWord[A],w1:I.w1,keys:I.keys.slice(A),content:I.content.slice(A)};$[y]>=0&&S[$[y]].utt[0]===y?(S[$[y]].takes.unshift(z),S[$[y]].utt.unshift(-1)):$[y]<0&&($[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 A of I1(k.keys,k.content)){const I=$[y]>=0?S[$[y]]:null,z={w0:k.keyWord[A.i]===k.keyWord[0]?k.w0:k.keyWord[A.i],w1:k.keyWord[A.j]-1,keys:k.keys.slice(A.i,A.j),content:k.content.slice(A.i,A.j)},j={w0:k.keyWord[A.j],w1:k.w1,keys:k.keys.slice(A.j),content:k.content.slice(A.j)};S.push({kind:"restart",track:m,takes:[z,j],between:[],parentRef:I?{g:I,take:I.utt.indexOf(y)}:null})}});for(const k of S){const y=new Set(k.takes.flatMap(I=>I.keys));for(const I of k.takes)Object.assign(I,M4(g,I,e)),I.completeness=+(new Set(I.keys.filter(z=>y.has(z))).size/y.size).toFixed(3);const A=Math.max(...k.takes.map(I=>I.completeness));for(const I of k.takes)I.full=I.completeness>=Math.max(.6,A-.3)-1e-9,I.score=+(.6*I.completeness+.1*I.steady-.06*I.fillers-.08*I.restarts-.15*Math.min(1,I.longPause)).toFixed(4);if(k.kind==="repeat"){const I=k.takes.map((z,j)=>j<k.takes.length-1&&z.full&&!g[z.w1].stop&&g[k.takes[j+1].w0].t-g[z.w1].te<=Co.abandonGap);k.takes.some((z,j)=>z.full&&!I[j])&&k.takes.forEach((z,j)=>{I[j]&&(z.full=!1)})}if(k.kind==="repeat")for(let I=1;I<k.takes.length;I++){const z=k.takes[I-1].w1+1,j=k.takes[I].w0-1;if(j<z)continue;const P=v.filter(F=>F.w0>=z&&F.w1<=j),N=F=>!g[F.w1].stop&&F.keys.length>=2&&Hu(F.keys,k.takes[I].keys,F.content).len>=.7*F.keys.length;P.every(F=>F.keys.length<=Co.junkWords||N(F))&&g[j].te-g[z].t<=Co.junkSeconds&&k.between.push({w0:z,w1:j})}}for(const k of S)s.push(k)}const d=s.map(m=>{const g=c.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)=>c.get(m.track)[m.takes[0].w0].t-c.get(g.track)[g.takes[0].w0].t||m.track-g.track),f={groups:[],streams:Object.fromEntries(c),primary:l.map(Gf),companions:u.map(Gf),speechNodes:[...new Set([...l,...u].map(m=>m.nodeId))]};for(const m of d){const g=c.get(m.track),v=v4(m.takes,r),x=m.takes.map(E=>({w0:E.w0,w1:E.w1,text:g.slice(E.w0,E.w1+1).map(S=>S.text).join(" "),start:+g[E.w0].t.toFixed(3),end:+g[E.w1].te.toFixed(3),clipId:g[E.w0].clipId,score:E.score,completeness:E.completeness,fillers:E.fillers,restarts:E.restarts,longPause:E.longPause,steady:E.steady,full:E.full})),$=m.parentRef?{id:d.find(E=>E.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:A1(x[v].text),takes:x,kept:v,reasons:x.map((E,S)=>$4(m,S,v,r)),between:m.between,parent:$?.id?$: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:S4(f,Xu(f.streams[m.track],m.takes[v].w0,m.takes[v].w1),m.track)}]);return f}const Gf=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 Xu(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(Co.breath,Math.max(0,r.t-n.te)/2):r.t-r.cs<=Co.closeGap?r.cs:r.t-Co.breath,c=i?i.t:a.ce,s=Math.max(0,c-a.te),d=s<=Co.closeGap?i?i.t-Math.min(Co.breath,s/2):c:a.te+.12;return{start:Math.max(0,u),end:Math.max(u,d)}}function Uu(t,e,o){return t.primary.filter(r=>r.track===o).flatMap(r=>{const a=ft(r.start+r.duration);let n=ft(Math.max(e.start,r.start)),i=ft(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 S4=(t,e,o)=>Uu(t,e,o).map(r=>({clipId:r.clipId,start:r.srcStart,end:r.srcEnd}));function I4(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=Fe(t,o,r())[1];return s?[{...s,id:t.id,start:t.start}]:[t]}if(i)return[Fe(t,e,r())[0]];const[l,u]=Fe(t,e,r()),c=u&&Fe(u,o,r())[1];return c?[l,{...c,start:ft(e)}]:[l]}const A4=t=>t.label||t.id;function C4(t,e,o={}){const r=o.tracks??{},a=o.makeId??(()=>Math.random().toString(36).slice(2,10)),n=o.maxClips??Fs,i=o.isBed??(j=>j.kind==="audio"&&!e.speechNodes.includes(j.nodeId)),l=o.choose??{},u=new Set(o.skip??[]),c=new Map(e.groups.map(j=>[j.id,j])),s=j=>{const P=l[j.id];return Number.isInteger(P)&&P>=0&&P<j.takes.length?P:j.kept},d=(j,P)=>{const N=c.get(j);return!!N&&!u.has(j)&&s(N)!==P},f=[],m=[];for(const j of e.groups){if(u.has(j.id)||j.parent&&d(j.parent.id,j.parent.take))continue;const P=s(j),N=j.takes.map((_,J)=>J).filter(_=>_!==P),F=e.streams[j.track],K={id:j.id,label:j.kind==="restart"?j.label:j4(j,P),kind:j.kind,takes:j.takes.length,kept:P,cut:N,blocked:[]};f.push(K);for(const _ of N)m.push({...Xu(F,j.takes[_].w0,j.takes[_].w1),track:j.track,who:[[K,_]]});if(N.length)for(const _ of j.between)m.push({...Xu(F,_.w0,_.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,N)=>j.start<=P+1e-6&&j.start+j.duration>=N-1e-6,$=j=>{if(r[j.track]?.locked)return"locked";for(const P of Uu(e,j,j.track)){const N=K=>K.start<P.end-.016666666666666666&&K.start+K.duration>P.start+.016666666666666666,F=t.find(K=>K.id!==P.clipId&&N(K)&&(K.track===j.track?!g.has(K.id):!i(K)&&!(v.has(`${K.track}|${K.nodeId}`)&&x(K,P.start,P.end))));if(F)return`"${A4(F)}"`;if(t.some(K=>r[K.track]?.locked&&(K.start>=P.end-1/60||N(K)&&v.has(`${K.track}|${K.nodeId}`))))return"locked"}return null},E=[];for(const j of m.sort((P,N)=>P.track-N.track||P.start-N.start)){const P=$(j);if(P){for(const[F,K]of j.who)F.blocked.push({take:K,reason:P});continue}const N=E.at(-1);N&&N.track===j.track&&j.start<=N.end+1/60?(N.end=Math.max(N.end,j.end),N.who.push(...j.who)):E.push({...j,who:[...j.who]})}const S=[];let k=0;for(const j of E){const P=Uu(e,j,j.track);let N=null;if(!P.length)continue;const F=P.reduce((K,_)=>{const J=t.find(rt=>rt.id===_.clipId),X=J&&_.start>J.start+1/30&&_.end<J.start+J.duration-1/30;return K+(X?1+t.filter(rt=>rt.track!==j.track&&v.has(`${rt.track}|${rt.nodeId}`)&&x(rt,_.start,_.end)).length:0)},0);if(!N&&t.length+k+F>n&&(N="limit"),N){for(const[K,_]of j.who)K.blocked.push({take:_,reason:N});continue}k+=F,S.push(...P)}let y=t.map(j=>({...j})),A=0,I=0;for(const j of S.sort((P,N)=>N.start-P.start)){const P=y.filter(K=>(K.track===j.track&&K.nodeId===j.nodeId||K.track!==j.track&&v.has(`${K.track}|${K.nodeId}`))&&x(K,j.start,j.end));if(!P.some(K=>K.track===j.track))continue;const N=ft(j.end-j.start),F=new Set(P.map(K=>K.id));y=y.flatMap(K=>F.has(K.id)?I4(K,j.start,j.end,a):[K.start>=j.end-1/60&&!(i(K)&&K.start<j.end+1/60&&K.start>j.start)?{...K,start:ft(K.start-N)}:K]),A++,I+=N}const z=f.filter(j=>j.cut.length).map(j=>T4(j,o.en));return{clips:y,groups:f,removed:A,saved:ft(I),lines:z}}const j4=(t,e)=>A1(t.takes[e].text);function T4(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 O4(t,e,o={}){const r=E4(t,e,o);return{...C4(t,r,o),found:r}}const va=Object.freeze({lead:.3,iconLead:.2,minGap:.8,maxLead:2}),Kf=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(" ")),Yu=t=>String(t??"").split(",")[0].split(/[\s\-–—/.]+/).map(as).filter(Boolean);function C1(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 l=(e??[]).find(u=>u.id===i.nodeId);for(const u of lc(i,Array.isArray(l?.words)?l.words:null)){const c=i.start+u.start;c>=o-1e-6&&c<r&&n.push({start:c,end:i.start+u.end,word:u.word,key:as(u.word)})}}return n.sort((i,l)=>i.start-l.start)}function qu(t,e,o=-1/0){const r=Yu(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 l=0;for(;n+l<e.length&&i+l<r.length&&e[n+l].key===r[i+l];)l++;if(!l)continue;const u=r.filter(s=>!Kf.has(s)),c=r.slice(i,i+l).filter(s=>!Kf.has(s)).length;l<r.length&&!(c&&(c===u.length||c>=2))||(!a||l>a.n)&&(a={n:l,at:e[n].start,said:e.slice(n,n+l).map(s=>s.word).join(" ")})}if(a?.n===r.length)break}return a&&{at:a.at,said:a.said}}const cl=t=>Math.round(t*100)/100,Fp=(t,e,o)=>Math.min(o,Math.max(e,t));function z4(t,e,{words:o=[],times:r=null,start:a=0,duration:n,lead:i=va.lead}){const l=n,u=Fp(Number.isFinite(i)?i:va.lead,0,va.maxLead),c=[],s=Array.isArray(r)?r.filter(y=>y&&Number.isFinite(Number(y.at))):null,d=(y,A,I)=>{const z=I[A];if(Number.isInteger(z))return z>=1&&z<=y.length?z-1:-1;const j=Yu(z).join(" ");return j?y.findIndex(P=>Yu(P.label).join(" ")===j):-1},f=t.map(()=>null);let m=a-1e-6;t.forEach((y,A)=>{const I=s?.find(j=>j.place!=null&&d(t,"place",j)===A),z=I?{at:Number(I.at),said:null}:s?null:qu(y.label,o,m);z&&(f[A]=z,m=z.at+.001),c.push({kind:"place",name:y.label||`#${A+1}`,at:z?cl(z.at):null,...z?.said?{said:z.said}:{}})});const g=(e??[]).map((y,A)=>{const I=s?.find(j=>j.icon!=null&&d(e,"icon",j)===A),z=I?{at:Number(I.at),said:null}:s||!y.label?null:qu(y.label,o,a-1e-6);return c.push({kind:"icon",name:y.label||y.icon,at:z?cl(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?l*.85:0,$=f.map(y=>y?Fp(y.at-a-u,0,l-.3):null);for(let y=1;y<v;y++)if($[y]!=null){const A=$.slice(0,y).reverse().find(I=>I!=null);A!=null&&$[y]<A+va.minGap&&($[y]=Math.min(l-.3,A+va.minGap))}const E=$.map((y,A)=>y==null?null:A).filter(y=>y!=null);for(let y=0;y<v;y++){if($[y]!=null)continue;const A=[...E].reverse().find(z=>z<y),I=E.find(z=>z>y);A!=null&&I!=null?$[y]=$[A]+($[I]-$[A])*(y-A)/(I-A):I!=null?$[y]=$[I]*y/I:A!=null?$[y]=Math.min(l-.3,$[A]+Math.max(va.minGap,(x-$[A])/(v-1-A))*(y-A)):$[y]=v>1?x*y/(v-1):0}const S=t.map((y,A)=>({...y,at:cl($[A])})),k=(e??[]).map((y,A)=>{const I=g[A],{show:z,...j}=y;return I?{...j,show:cl(Fp(I.at-a-va.iconLead,0,l-.5))}:j});return{places:S,icons:k,report:c}}function P4(t){return t.map(e=>e.at==null?`${e.name} not said`:`${e.name} ${e.at} s${e.said?` («${e.said}»)`:""}`).join("; ")}const nn=Object.freeze({maxReplace:60,maxCues:300,maxText:300,near:.35}),L4=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),N4=(t,e)=>new RegExp(`(?<![\\p{L}\\p{N}])${L4(t.normalize("NFC"))}(?![\\p{L}\\p{N}])`,e?"gu":"giu");function F4(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 R4(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>nn.maxReplace)throw Error(`at most ${nn.maxReplace} replacements`);if(r.length>nn.maxCues)throw Error(`at most ${nn.maxCues} cues per edit`);const a=F4(t,e.clipIds);if(!a.length)throw Error("No subtitles on the timeline yet (addSocialCaptions first)");const n=[],i=o.map((c,s)=>{if(!c||typeof c.from!="string"||!c.from.trim()||typeof c.to!="string")throw Error(`replace[${s}] needs from and to (text)`);if(c.from.length>120||c.to.length>120)throw Error(`replace[${s}]: from / to ≤ 120 characters`);return{re:N4(c.from.trim(),c.matchCase===!0),to:c.to.normalize("NFC"),from:c.from.trim(),n:0}});if(i.length){for(const c of a)c.captions.forEach((s,d)=>{let f=s.text.normalize("NFC");for(const m of i)f=f.replace(m.re,()=>(m.n++,m.to));if(f=f.replace(/\s{2,}/g," ").trim(),f!==s.text){if(!f)throw Error(`replace would leave an empty subtitle ("${s.text.slice(0,40)}") — use cues [{at, text: null}] to delete it`);Object.assign(c,hd(c,d,{text:f.slice(0,nn.maxText)}))}});n.push(...i.map(c=>`replace "${c.from.slice(0,40)}" → "${c.to.slice(0,40)}": ${c.n} time${c.n===1?"":"s"}`))}const l=r.map((c,s)=>{if(!c||!Number.isFinite(c.at))throw Error(`cues[${s}].at must be timeline seconds`);if(c.text!=null&&typeof c.text!="string")throw Error(`cues[${s}].text must be text (null = delete the cue)`);if(typeof c.text=="string"&&c.text.length>nn.maxText)throw Error(`cues[${s}].text ≤ ${nn.maxText} characters`);let d=null;for(const f of a){const m=c.at-f.start;m<-nn.near||m>f.duration+nn.near||f.captions.forEach((g,v)=>{const x=m<g.start?g.start-m:m>=g.end?m-g.end:0;x<=nn.near&&(!d||x<d.d||x===d.d&&(f.track??0)>(d.c.track??0))&&(d={c:f,k:v,d:x})})}if(!d)throw Error(`cues[${s}]: no subtitle shows at ${c.at} s`);return{...d,i:s,text:typeof c.text=="string"?c.text.normalize("NFC").trim():""}}),u=new Set;for(const c of l){const s=`${c.c.id}#${c.k}`;if(u.has(s))throw Error(`cues[${c.i}]: the same subtitle is edited twice`);u.add(s)}for(const c of[...l].sort((s,d)=>s.c.id<d.c.id?-1:s.c.id>d.c.id?1:d.k-s.k)){const s=c.c.captions[c.k].text,d=+(c.c.start+c.c.captions[c.k].start).toFixed(2);Object.assign(c.c,hd(c.c,c.k,c.text?{text:c.text}:null)),n.push(c.text?`subtitle @${d}s: "${s.slice(0,40)}" → "${c.text.slice(0,40)}"`:`subtitle @${d}s deleted: "${s.slice(0,40)}"`)}return n}const Zu={rotation:[-Cs,Cs],brightness:[0,2],contrast:[0,2],exposure:[-3,3],saturation:[0,2],hue:[-180,180],audioFadeIn:[0,600],audioFadeOut:[0,600],volume:[0,1]},D4=["flipX","flipY","reverse","colorBypass","motionBlur","disabled"],Os=["analyzeFootage","exportVideo","setExportFormat","play","pause","seek","undo","redo"];function B4(t,e){const o=structuredClone(t),r=e.property;if(e.op==="setClipProperty"){if(r in Zu){const[a,n]=Zu[r],i=e.numberValue;if(!Number.isFinite(i)||i<a||i>n)throw Error("Invalid clip value");o[r]=i}else if(D4.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(!dd.includes(a))throw Error(`blend must be ${dd.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=Gu(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=Eu(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,g5(o)),kn(o),o}const lp=.35,_4=2e3,G4=1200;function K4(t,e,o=.25){const r=t?.beats;if(!Array.isArray(r)||!r.length||!((t.confidence??0)>=lp))return e;let a=0,n=r.length-1;for(;a<n;){const l=a+n>>1;r[l]<e?a=l+1:n=l}const i=[r[a],r[a-1]].filter(l=>l!==void 0).sort((l,u)=>Math.abs(l-e)-Math.abs(u-e))[0];return Math.abs(i-e)<=o?i:e}function V4(t){if(t==null)return null;const e=i=>Array.isArray(i)&&i.length<=_4&&i.every((l,u)=>Number.isFinite(l)&&l>=0&&l<=3600&&(u===0||l>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<=G4&&t.hits.every((i,l)=>Number.isFinite(i)&&i>=0&&i<=3600&&(l===0||i>t.hits[l-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 W4=t=>Math.round(t*1e3)/1e3;function H4(t,e){const o=[];for(const r of t){const a=e.find(l=>l.id===r.nodeId)?.beats;if(!Array.isArray(a?.beats)||!((a.confidence??0)>=lp)||r.reverse)continue;const n=Number(r.playbackRate)||1,i=Number(r.inPoint)||0;for(const l of a.beats)l>=i-1e-6&&l<i+r.duration*n-1e-6&&o.push(W4(r.start+(l-i)/n))}return[...new Set(o)].sort((r,a)=>r-a)}const X4=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"}))]);X4.map(t=>t.id);function EC(t,e="speed",o=30,r=20,a=24){const n=t==="montage"?[{u:0,speed:3},{u:1,speed:3}]:Lb[t];if(!n)throw Error(`Unknown curve ${t}`);const i=n.map(s=>({t:s.u,speed:s.speed,...s.ease?{ease:s.ease}:{}})),l=Array.from({length:a+1},(s,d)=>Nb(i,d/a));let u;if(e==="value"){let s=0;u=l.map((f,m)=>m?s+=(f+l[m-1])/2/a:0).map(f=>f/(s||1))}else{const s=Math.max(...l),d=Math.min(...l);u=l.map(f=>s-d<1e-6?.5:(f-d)/(s-d))}const c=2;return u.map((s,d)=>[+(c+(o-2*c)*d/a).toFixed(2),+(r-c-(r-2*c)*s).toFixed(2)])}const Vf=Object.freeze([.5,1,2,4]);function U4(t,e,o,r=1){const a=(t||[]).filter(Number.isFinite);if(a.length<2||!(e>0))return[];const n=r===.5?a.flatMap((c,s)=>s<a.length-1?[c,(c+a[s+1])/2]:[c]):a,i=r===.5?1:r;let l=0;for(let c=1;c<n.length;c++)Math.abs(n[c]-o)<Math.abs(n[l]-o)&&(l=c);const u=[];for(let c=0;c<e;c++){const s=l+c*i,d=s+i;if(d>=n.length)break;u.push({start:+n[s].toFixed(3),duration:+(n[d]-n[s]).toFixed(3)})}return u}const j1=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}}),Ju=Object.keys(j1);function Y4(t="all",e=.5,o={}){const r=j1[t];if(!r)throw Error(`Shake axis must be one of ${Ju.join(", ")}`);const a=Math.max(.1,Math.min(1,Number.isFinite(e)?e:.5)),n=(i,l)=>Math.max(0,Math.min(1,Number.isFinite(i)?i:l));if(t==="custom"){const i={x:.03*n(o.amountX,.5),y:.03*n(o.amountY,.5),rot:3.2*n(o.amountRot,.3)},l=["x","y","rot"].filter(u=>i[u]>1e-6);if(!l.length)throw Error("Custom shake needs some amountX, amountY or amountRot");return{props:l,amp:Object.fromEntries(l.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 T1=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]}),Wf=Object.keys(T1),SC=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"}]),xc=Object.freeze(["zoom-in-start","zoom-in-end","zoom-out-start","zoom-out-end"]);function q4(t,e,o=1,r=.25,a){if(!xc.includes(t))throw Error(`zoomMove preset must be one of ${xc.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))),l=t.startsWith("zoom-in"),u=t.endsWith("start"),c=+(o*(1+n)).toFixed(4),s=+o.toFixed(4),d=l?u?+(o/(1+n)).toFixed(4):c:u?c:+(o/(1+n)).toFixed(4);return u?[{time:0,value:d,ease:"expo-out"},{time:+i.toFixed(3),value:s}]:[{time:+(e-i).toFixed(3),value:s,ease:"expo-in"},{time:+e.toFixed(3),value:d}]}const IC=Object.freeze({min:.1,max:1}),Rp=1,Hf=Object.freeze(["color","number","bool","choice"]),Xf=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}),AC=Object.freeze(["draft","standard","film"]),Z4=t=>`/vfx-presets/${t}/preview.webm`,CC=t=>`/vfx-presets/${t}/poster.jpg`,J4=/^[a-z0-9][a-z0-9-]{1,63}$/,Uf=/^[a-z][a-zA-Z0-9_]{0,31}$/,O1=/^#[0-9a-fA-F]{6}$/,$e=(t,e)=>{throw Error(`${t}: ${e}`)},Vr=t=>typeof t=="number"&&Number.isFinite(t),mn=(t,e)=>typeof t=="string"&&t.trim()&&t.length<=e;function Q4(t,e){const o=`params[${e}]`;(!t||typeof t!="object")&&$e(o,"object"),Uf.test(t.key??"")||$e(`${o}.key`,"a-z start, letters / digits / _ (≤ 32)"),Hf.includes(t.type)||$e(`${o}.type`,Hf.join(" | ")),(!mn(t.label,40)||!mn(t.labelEn,40))&&$e(`${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"&&(O1.test(t.default??"")||$e(`${o}.default`,"#RRGGBB"),r.default=t.default.toLowerCase()),t.type==="bool"&&(typeof t.default!="boolean"&&$e(`${o}.default`,"true | false"),r.default=t.default),t.type==="number"&&((!Vr(t.min)||!Vr(t.max)||!(t.min<t.max))&&$e(`${o}.min`,"min < max"),(!Vr(t.default)||t.default<t.min||t.default>t.max)&&$e(`${o}.default`,`${t.min}..${t.max}`),Object.assign(r,{min:t.min,max:t.max,default:t.default,step:Vr(t.step)&&t.step>0?t.step:(t.max-t.min)/100}),t.unit!==void 0&&(mn(t.unit,8)||$e(`${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||!Uf.test(n.value??"")||!mn(n.label,40)||!mn(n.labelEn,40)))&&$e(`${o}.options`,"2–12 {value, label, labelEn}"),a.some(n=>n.value===t.default)||$e(`${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 tM(t,{allowScript:e=!1}={}){(!t||typeof t!="object"||Array.isArray(t))&&$e("chieu.json","object"),J4.test(t.id??"")||$e("id","lowercase a-z0-9-, 2–64 chars"),(t.version??1)!==Rp&&$e("version",`must be ${Rp}`),(!mn(t.name,60)||!mn(t.nameEn,60))&&$e("name","name + nameEn (1–60 chars)"),Xf.includes(t.entry)||$e("entry",Xf.join(" | ")),t.entry==="generator.py"&&!e&&$e("entry","a Plug-in Store move is a .blend (no Python runs from a partner's file)"),(!Vr(t.duration)||t.duration<.2||t.duration>Sr.seconds)&&$e("duration",`0.2..${Sr.seconds} s`);const o=t.fps??30;Sr.fps.includes(o)||$e("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)&&$e("width","even 64..3840");const n=t.impact??0;(!Vr(n)||n<0||n>t.duration)&&$e("impact","0..duration");const i=t.emit??[.5,.5];(!Array.isArray(i)||i.length!==2||!i.every(f=>Vr(f)&&f>=0&&f<=1))&&$e("emit","[u, v] 0..1");const l=t.tags??[];(!Array.isArray(l)||l.length>Sr.tags||l.some(f=>!mn(f,30)))&&$e("tags",`≤ ${Sr.tags} short strings`);const u=t.sfx??[];(!Array.isArray(u)||u.length>Sr.sfx||u.some(f=>!f||!/^[a-z0-9-]{2,64}$/.test(f.id??"")||!Vr(f.at)||f.at<0||f.at>t.duration))&&$e("sfx",`≤ ${Sr.sfx} {id, at}`);let c=null;if(t.shake!=null){const f=t.shake;(!Vr(f.at)||!Vr(f.duration)||!Vr(f.intensity)||f.at<0||f.duration<=0||f.duration>2||f.intensity<=0||f.intensity>1)&&$e("shake","{at, duration ≤ 2, intensity 0..1}"),c={at:f.at,duration:f.duration,intensity:f.intensity}}const s=Array.isArray(t.params)?t.params:$e("params","array");s.length>Sr.params&&$e("params",`≤ ${Sr.params}`);const d=s.map(Q4);return new Set(d.map(f=>f.key)).size!==d.length&&$e("params","keys must be unique"),{id:t.id,version:Rp,name:t.name.trim(),nameEn:t.nameEn.trim(),...mn(t.desc,200)?{desc:t.desc.trim()}:{},...mn(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:l.map(f=>f.trim().toLowerCase()),sfx:u.map(f=>({id:f.id,at:f.at})),...c?{shake:c}:{},params:d}}function eM(t,e={}){if(e&&typeof e!="object")throw Error("params: object");const o=new Set(t.params.map(a=>a.key));for(const a of Object.keys(e||{}))if(!o.has(a))throw Error(`params.${a}: unknown — ${[...o].join(", ")}`);const r={};for(const a of t.params){const n=e?.[a.key];if(n==null){r[a.key]=a.default;continue}if(a.type==="color"){if(!O1.test(String(n)))throw Error(`params.${a.key}: #RRGGBB`);r[a.key]=String(n).toLowerCase()}else if(a.type==="bool"){if(typeof n!="boolean")throw Error(`params.${a.key}: true | false`);r[a.key]=n}else if(a.type==="choice"){if(!a.options.some(i=>i.value===n))throw Error(`params.${a.key}: ${a.options.map(i=>i.value).join(" | ")}`);r[a.key]=n}else{const i=Number(n);if(!Number.isFinite(i))throw Error(`params.${a.key}: number ${a.min}..${a.max}`);r[a.key]=Math.round(Math.min(a.max,Math.max(a.min,i))*1e4)/1e4}}return r}const oM=[{id:"huyet-loi-xoan",version:1,name:"Huyết Lôi Xoắn 3D",nameEn:"Crimson-Cyan 3D Vortex",desc:"7 dải plasma xoắn 3D đỏ huyết viền xanh điện, hồ quang lôi xoay, sương thể tích và tàn lửa",descEn:"Seven layered crimson-cyan UV-scrolling 3D plasma ribbons, swirling lightning arcs, volumetric mist and embers",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.3,emit:[.5,.5],tags:["huyet loi","huyết lôi","xoắn","vortex","plasma","đỏ","xanh điện","crimson","cyan","donghua","wuxia","võ hiệp"],sfx:[{id:"sp-whoosh-transition-1",at:.1},{id:"sp-sub-hit-1",at:.3}],shake:{at:.3,duration:.45,intensity:.55},params:[{key:"color",type:"color",default:"#f20538",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#0a94ff",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:-45,max:45,step:1,default:0,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{id:"kiem-khi-bang-lam",version:1,name:"Kiếm Khí Băng Lam Trảm",nameEn:"Ice-Blue Sword Slash",desc:"3 tầng kiếm khí bán nguyệt băng lam quét 3D, tia băng điện, sương lạnh thể tích và tàn lửa",descEn:"Three sweeping 3D crescent ice-blue plasma sword-slash ribbons, frost lightning arcs, volumetric mist and sparks",entry:"generator.py",duration:2.2,fps:30,width:1920,height:1080,impact:.2,emit:[.5,.5],tags:["kiem khi","kiếm khí","băng lam","trảm","sword","slash","ice","cyan","donghua","wuxia","võ hiệp"],sfx:[{id:"sp-slice-1",at:.15},{id:"sp-impact-2",at:.2}],shake:{at:.2,duration:.3,intensity:.65},params:[{key:"color",type:"color",default:"#2edbff",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#f2fcff",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:-45,max:45,step:1,default:0,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{id:"thien-loi-giang-the",version:1,name:"Thiên Lôi Giáng Thế",nameEn:"Heavenly Lightning Strike",desc:"3 đợt thiên lôi giáng xuống mặt đất kèm 22 nhánh sét, vòng xung điện plasma, sương bão và tia lửa",descEn:"Three pulsing heavenly lightning strikes with 22 branching bolts, swirling electric ground plasma ring, storm mist and sparks",entry:"generator.py",duration:2.5,fps:30,width:1920,height:1080,impact:.2,emit:[.5,.85],tags:["thien loi","thiên lôi","sấm sét","tia chớp","lôi điện","lightning","strike","storm","thunder","donghua","wuxia","võ hiệp"],sfx:[{id:"thunder",at:.15},{id:"sp-impact-1",at:.2},{id:"sp-sub-hit-3",at:.2}],shake:{at:.2,duration:.5,intensity:.85},params:[{key:"color",type:"color",default:"#4ddbff",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#e8fcff",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:-30,max:30,step:1,default:0,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{id:"kim-quang-shockwave",version:1,name:"Sóng Xung Kích Kim Quang",nameEn:"Golden Shockwave",desc:"Chớp lõi vàng, vòng sóng ánh kim bung rộng, tia lửa văng và bụi sáng",descEn:"A golden core flash, a ring of golden light bursting outward, flying sparks and glowing dust",entry:"generator.py",duration:1.4,fps:30,width:1920,height:1080,impact:.05,emit:[.5,.56],tags:["kim quang","shockwave","sóng xung kích","vàng","nổ","golden","impact","wuxia","võ hiệp"],sfx:[{id:"sp-impact-3",at:.05},{id:"sp-sub-hit-2",at:.05}],shake:{at:.05,duration:.35,intensity:.6},params:[{key:"color",type:"color",default:"#ffc83a",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#fff4cf",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:10,max:85,step:1,default:62,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{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"}]},{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"}]},{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"}]},{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"}]}],rM=Object.freeze(oM.map(t=>Object.freeze(tM(t,{allowScript:!0})))),nM=t=>rM.find(e=>e.id===t)??null,Le=Object.freeze({points:21,slots:2,maxSeconds:20,maxFrames:600,fps:[15,30]}),pl=Object.freeze({wrist:0,thumb:4,index:8,middle:12,ring:16,pinky:20,indexBase:5,middleBase:9}),Mc=Object.freeze(["pinch","index","thumb","middle","ring","pinky","wrist","palm"]),Qu=Object.freeze(["any","right","left"]),vc=1+Le.points*4,th=-.5,eh=2,ho=t=>Math.round(t*1e4)/1e4,Is="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",ul=Object.fromEntries([...Is].map((t,e)=>[t,e]));function Yf(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+=Is[i>>18&63]+Is[i>>12&63]+(o+1<t.length?Is[i>>6&63]:"=")+(o+2<t.length?Is[i&63]:"=")}return e}function qf(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=ul[e[a]]<<18|ul[e[a+1]]<<12|(ul[e[a+2]]??0)<<6|(ul[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 jC({mw:t,mh:e,fps:o,s0:r,frames:a}){const n=Math.min(Le.maxFrames,a.length),i=new Uint8Array(n*Le.slots*vc),l=new DataView(i.buffer);for(let c=0;c<n;c++)for(let s=0;s<Le.slots;s++){const d=a[c]?.[s],f=(c*Le.slots+s)*vc;if(!(!d?.lm||d.lm.length<Le.points)){i[f]=Math.max(1,Math.min(255,Math.round((Number.isFinite(d.score)?d.score:1)*255)));for(let m=0;m<Le.points;m++)for(let g=0;g<2;g++){const v=Math.max(0,Math.min(65535,Math.round((d.lm[m][g]-th)/eh*65535)));l.setUint16(f+1+(m*2+g)*2,v,!0)}}}let u=null;if(a.slice(0,n).some(c=>c?.some(s=>Array.isArray(s?.edge)))){const c=new Int8Array(n*Le.slots*qr);for(let s=0;s<n;s++)for(let d=0;d<Le.slots;d++){const f=a[s]?.[d]?.edge;if(Array.isArray(f))for(let m=0;m<qr;m++)c[(s*Le.slots+d)*qr+m]=Math.max(-127,Math.min(127,Math.round((f[m]||0)*Ai.unit)))}u=Yf(new Uint8Array(c.buffer))}return aM({v:1,mw:Math.round(t),mh:Math.round(e),fps:o,s0:ho(r),n,data:Yf(i),...u?{edge:u}:{}})}function aM(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||!Le.fps.includes(t.fps)||!Number.isFinite(t.s0)||t.s0<0||t.s0>36e3||!Number.isInteger(t.n)||t.n<1||t.n>Le.maxFrames||typeof t.data!="string"||!/^[A-Za-z0-9+/]*={0,2}$/.test(t.data)||Math.floor(t.data.replace(/=+$/,"").length*3/4)!==t.n*Le.slots*vc||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*Le.slots*qr))throw Error("Invalid hand track");return t}const ds=new Map;function Zs(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=ds.get(e);if(o)return o;const r=qf(t.data),a=new DataView(r.buffer),n=[],i=t.edge?new Int8Array(qf(t.edge).buffer):null;for(let u=0;u<t.n;u++){const c=[];for(let s=0;s<Le.slots;s++){const d=(u*Le.slots+s)*vc;if(!r[d]){c.push(null);continue}const f=[];for(let g=0;g<Le.points;g++)f.push([th+a.getUint16(d+1+g*4,!0)/65535*eh,th+a.getUint16(d+3+g*4,!0)/65535*eh]);const m=i?Array.from(i.subarray((u*Le.slots+s)*qr,(u*Le.slots+s+1)*qr),g=>g/Ai.unit):null;c.push({lm:f,score:r[d]/255,...m?{edge:m}:{}})}n.push(c)}const l={fps:t.fps,s0:t.s0,n:t.n,mw:t.mw,mh:t.mh,frames:n};return ds.size>16&&ds.delete(ds.keys().next().value),ds.set(e,l),l}const $c=(t,e)=>(t.inPoint||0)+e*(t.playbackRate||1),z1=(t,e)=>(e-(t.inPoint||0))/(t.playbackRate||1);function Dp(t,e,o){const r=t?.hands;if(!r)return!1;const a=$c(t,e),n=$c(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 P1=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o];function Ec(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)),l=t.frames[a][o],u=t.frames[n][o];if(l&&u)return l.lm.map((s,d)=>P1(s,u.lm[d],i));const c=i<.5?l:u;return c?c.lm:null}function iM(t,e,o="any"){return o==="right"?0:o==="left"?1:Ec(t,e,0)?0:Ec(t,e,1)?1:0}const L1=(t,e,o)=>Math.hypot((t[0][0]-t[9][0])*e,(t[0][1]-t[9][1])*o);function Ii(t,e="index"){if(e==="pinch")return P1(t[pl.thumb],t[pl.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[pl[e]??pl.index]}const Un=Object.freeze({on:.3,off:.46,hold:2,minHold:.2}),oi=Object.freeze({fast:2.2,back:1,cos:-.25,gap:.35,window:3});function sM(t){const e=[];for(let o=0;o<Le.slots;o++){let r=!1,a=!1,n=0,i=0,l=-1/0;const u=[],c=[],s=[];for(let f=0;f<t.n;f++){const m=t.frames[f][o];if(!m){u.push(null),c.push(null),s.push(!1);continue}const g=L1(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),c.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 d=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 N=t.frames[f-i]?.[o],F=N?Ii(N.lm,"pinch"):[.5,.5];e.push({type:"release",s:ho(d(f-i)),slot:o,u:ho(F[0]),v:ho(F[1])}),r=!1}n=0;continue}if(i=0,r){if(n=g>Un.off?n+1:0,n>=Un.hold){const N=f-Un.hold+1,F=Ii(t.frames[N][o].lm,"pinch");e.push({type:"release",s:ho(d(N)),slot:o,u:ho(F[0]),v:ho(F[1])}),r=!1,n=0}}else if(g>Un.off&&(a=!0),n=a&&g<Un.on?n+1:0,n>=Un.hold){const N=f-Un.hold+1,F=Ii(t.frames[N][o].lm,"pinch");e.push({type:"pinch",s:ho(d(N)),slot:o,u:ho(F[0]),v:ho(F[1])}),r=!0,a=!1,n=0}const v=Math.max(1,Math.round(oi.window*t.fps/30)),x=f-v,$=f+v;if(r||x<0||$>=t.n||!s[x]||!s[$]||!c[f]||u[f]<Un.off||c[f][2]<.55||d(f)-l<oi.gap)continue;const E=v/t.fps,S=[(c[f][0]-c[x][0])/E,(c[f][1]-c[x][1])/E],k=[(c[$][0]-c[f][0])/E,(c[$][1]-c[f][1])/E],y=Math.hypot(...S),A=Math.hypot(...k);if(y<oi.fast||A<oi.back||(S[0]*k[0]+S[1]*k[1])/(y*A)>oi.cos)continue;let z=f,j=-1/0;for(let N=x;N<=$;N++)if(c[N]){const F=c[N][0]*S[0]+c[N][1]*S[1];F>j&&(j=F,z=N)}if(d(z)-l<oi.gap)continue;const P=t.frames[z][o].lm[8];e.push({type:"tap",s:ho(d(z)),slot:o,u:ho(P[0]),v:ho(P[1])}),l=d(z)}if(r){const f=[...t.frames].reverse().find(g=>g[o])?.[o],m=f?Ii(f.lm,"pinch"):[.5,.5];e.push({type:"release",s:ho(t.s0+(t.n-1)/t.fps),slot:o,u:ho(m[0]),v:ho(m[1])})}}return e.sort((o,r)=>o.s-r.s||(o.type==="release"?-1:1))}const ki=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]],oh=[2.4,1.6,.8],qr=ki.length*9+4+2*oh.length,TC=Object.freeze([0,1,2,3,4,5,qr-4,qr-3,qr-2,qr-1]);function N1(t,e,o,{width:r=.17,arm:a=3.2}={}){const n=t.map(([P,N])=>[P*e,N*o]),i=Math.hypot(n[0][0]-n[9][0],n[0][1]-n[9][1])||1,l=(P,N)=>[P[0]-N[0],P[1]-N[1]],u=(P,N)=>[P[0]+N[0],P[1]+N[1]],c=(P,N)=>[P[0]*N,P[1]*N],s=P=>{const N=Math.hypot(P[0],P[1])||1;return[P[0]/N,P[1]/N]},d=P=>[-P[1],P[0]],f=(P,N)=>P[0]*N[0]+P[1]*N[1],m=[],g=(P,N,F,K=!0)=>m.push({anchor:P,dir:N,dist:F,snap:K}),v=s(l(n[0],n[9])),x=d(v),$=.36*i,E=f(x,l(n[1],n[0]))>0?1:-1,S=c(x,E),k=c(x,-E),y=u(n[0],c(v,a*i)),A=P=>u(n[0],c(v,P*i)),I=P=>$*(1+.1*P);g(y,k,I(a),!1),g(y,S,I(a),!1);for(const P of oh)g(A(P),S,I(P));g(n[0],S,$);const z=u(n[0],c(S,$)),j=u(n[0],c(k,$));for(let P=0;P<ki.length;P++){const N=ki[P],F=N.map(Q=>n[Q]),K=P?n[ki[P-1][0]]:z,_=P<ki.length-1?n[ki[P+1][0]]:j,J=s(l(F[3],F[0])),X=d(J),rt=f(X,l(K,F[0]))-f(X,l(_,F[0]))>=0?1:-1,ot=c(X,rt),G=c(ot,-1),tt=Q=>r*(P===0?1.15:1)*(1-.18*Q/3)*i/2;for(let Q=0;Q<3;Q++)g(F[Q],ot,tt(Q));g(F[3],ot,tt(3)),g(F[3],s(l(F[3],F[2])),tt(3)*1.2),g(F[3],G,tt(3));for(let Q=2;Q>=0;Q--)g(F[Q],G,tt(Q))}g(n[0],k,$);for(const P of[...oh].reverse())g(A(P),k,I(P));return{pts:m,S:i}}function lM(t,e,o,{width:r=.17,arm:a=3.2,edge:n=null,scale:i=1,grow:l=0}={}){const{pts:u,S:c}=N1(t,e,o,{width:r,arm:a});return u.map((s,d)=>{const f=Math.max(0,s.dist*i+(n?.[d]??0)*c+l*c);return[ho((s.anchor[0]+s.dir[0]*f)/e),ho((s.anchor[1]+s.dir[1]*f)/o)]})}const Ai=Object.freeze({in:.6,out:.1,unit:200});function OC(t,e,o,r,a={}){const{pts:n,S:i}=N1(t,e,o,a),l=t.map(([S,k])=>[S*e,k*o]),u=(S,k)=>{let y=0,A=0,I=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],A+=P[1],I+=P[2]}return[y/9,A/9,I/9]},c=(S,k)=>(S[0]-k[0])**2+(S[1]-k[1])**2+(S[2]-k[2])**2,s=(S,k)=>Math.min(...k.map(y=>c(S,y))),d=S=>[0,1,2].map(k=>S.map(y=>y[k]).sort((y,A)=>y-A)[S.length>>1]);let f=[[1,2],[2,3],[5,6],[6,7],[9,10],[10,11],[13,14],[14,15],[17,18],[18,19]].map(([S,k])=>u((l[S][0]+l[k][0])/2,(l[S][1]+l[k][1])/2));const m=[0,5,9,13,17].reduce((S,k)=>[S[0]+l[k][0]/5,S[1]+l[k][1]/5],[0,0]);f.push(u(m[0],m[1]));const g=d(f);if(f=f.filter(S=>c(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=>c(S,g))))+12;if(v=v.filter(S=>Math.sqrt(s(S,f))>x),v.length<4)return null;const $=S=>s(S,f)<s(S,v),E=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(!$(k(S.dist*.3)))return 0;const y=S.dist*(1-Ai.in),A=S.dist+Ai.out*i;let I=Math.max(S.dist*.3,y);for(;I<A&&$(k(I+E));)I+=E;return Math.round((Math.max(y,I+E/2)-S.dist)/i*Ai.unit)/Ai.unit})}const Do=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}}),rh=Object.freeze(["x","y","z","rx","ry","rz","s"]),F1={x:0,y:0,z:0,rx:0,ry:0,rz:0,s:1},Ro=t=>Math.round(t*1e6)/1e6,Fo=t=>Math.round(t*1e3)/1e3,Bo=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],vr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Ne=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],kr=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Hh=(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]],qa=t=>{const e=Math.hypot(...t)||1;return Ne(t,1/e)},hr=(t,e)=>[kr(t[0],e),kr(t[1],e),kr(t[2],e)],Pn=t=>[0,1,2].map(e=>[t[0][e],t[1][e],t[2][e]]),Zo=(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])),R1=()=>[[1,0,0],[0,1,0],[0,0,1]],hl=[[1,0,0],[0,-1,0],[0,0,-1]],nh=t=>[t[0],-t[1],-t[2]],dl=t=>{if(!t.length)return 0;const e=[...t].sort((o,r)=>o-r);return e[e.length>>1]},yn=Math.PI/180,cM=t=>[[1,0,0],[0,Math.cos(t),-Math.sin(t)],[0,Math.sin(t),Math.cos(t)]],pM=t=>[[Math.cos(t),0,Math.sin(t)],[0,1,0],[-Math.sin(t),0,Math.cos(t)]],uM=t=>[[Math.cos(t),-Math.sin(t),0],[Math.sin(t),Math.cos(t),0],[0,0,1]],D1=(t,e,o)=>Zo(Zo(cM(t*yn),pM(e*yn)),uM(o*yn));function B1(t,e,o){let r=!1;for(let a=0,n=t.length-1;a<t.length;n=a++){const[i,l]=t[a],[u,c]=t[n];l>o!=c>o&&e<(u-i)*(o-l)/(c-l)+i&&(r=!r)}return r}function hM(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,l)=>(i[0]-n[0])*(l[1]-n[1])-(i[1]-n[1])*(l[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 dM(t,e,o,r){if(B1(t,e,o))return!0;for(let a=0,n=t.length-1;a<t.length;n=a++){const[i,l]=t[n],[u,c]=t[a],s=u-i,d=c-l,f=s*s+d*d,m=f?Math.max(0,Math.min(1,((e-i)*s+(o-l)*d)/f)):0;if(Math.hypot(i+m*s-e,l+m*d-o)<=r)return!0}return!1}function fM(t,e,o,{n:r=Do.seeds,minScore:a=1e-4,taken:n=[]}={}){const{w:i,h:l,data:u}=t,c=4,s=Math.max(c,Math.floor(o[0])),d=Math.max(c,Math.floor(o[1])),f=Math.min(i-c-1,Math.ceil(o[2])),m=Math.min(l-c-1,Math.ceil(o[3]));if(!(f>s&&m>d))return[];let g=0;for(let E=d;E<=m;E+=2)for(let S=s;S<=f;S+=2)e(S,E)&&(g+=4);const v=Math.max(5,Math.sqrt(g/Math.max(1,r))),x=[],$=(E,S)=>n.some(k=>Math.abs(k[0]-E)<v*.7&&Math.abs(k[1]-S)<v*.7);for(let E=d;E<=m;E+=v)for(let S=s;S<=f;S+=v){let k=null;for(let y=Math.round(E);y<Math.min(m+1,E+v);y++)for(let A=Math.round(S);A<Math.min(f+1,S+v);A++){if(!e(A,y))continue;let I=0,z=0,j=0;for(let N=-2;N<=2;N++)for(let F=-2;F<=2;F++){const K=(y+N)*i+A+F,_=(u[K+1]-u[K-1])/2,J=(u[K+i]-u[K-i])/2;I+=_*_,z+=_*J,j+=J*J}const P=(I+j)/2-Math.sqrt(((I-j)/2)**2+z*z);P>a&&(!k||P>k[2])&&(k=[A,y,P])}k&&!$(k[0],k[1])&&x.push([k[0],k[1]])}return x}const mM=(t,e,o,r,a)=>{const n=hr(t.R,Bo(e,t.C));return n[2]>-1e-6?null:[r+o*n[0]/-n[2],a-o*n[1]/-n[2]]},za=(t,e,o,r,a,n)=>{const i=mM(t,e,r,a,n);return i?Math.hypot(i[0]-o[0],i[1]-o[1]):1e3},Zf=(t,e,o,r,a,n)=>vr(t.C,hr(Pn(t.R),[(e[0]-a)/r*o,-(e[1]-n)/r*o,-o]));function gM(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 yM(t,e){if(e.length<4)return null;const o=Ne(e.reduce((g,v)=>vr(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=Bo(g,o);for(let x=0;x<3;x++)for(let $=0;$<3;$++)r[x][$]+=v[x]*v[$]}const{values:a,vectors:n}=Gs(r),i=[0,1,2].reduce((g,v)=>a[v]<a[g]?v:g,0),l=hr(t.R,Bo(o,t.C)),u=qa(l),c=hr(t.R,n.map(g=>g[i])),s=Bo(Ne(u,2*kr(c,u)),c),d=Hh(c,s),f=Math.hypot(...d);if(f<Math.sin(.5*yn))return null;const m=Zo(gM(Ne(d,1/f),Math.atan2(f,kr(c,s))),t.R);return{R:m,C:Bo(o,hr(Pn(m),l))}}function bM(t){const e=t.length,o=t.map(n=>[...n]),r=Array.from({length:e},(n,i)=>Array.from({length:e},(l,u)=>i===u?1:0));for(let n=0;n<60;n++){let i=0;for(let l=0;l<e;l++)for(let u=l+1;u<e;u++)i+=o[l][u]**2;if(i<1e-24)break;for(let l=0;l<e;l++)for(let u=l+1;u<e;u++){if(Math.abs(o[l][u])<1e-300)continue;const c=(o[u][u]-o[l][l])/(2*o[l][u]),s=Math.sign(c||1)/(Math.abs(c)+Math.sqrt(c*c+1)),d=1/Math.sqrt(s*s+1),f=s*d;for(let m=0;m<e;m++){const g=o[m][l],v=o[m][u];o[m][l]=d*g-f*v,o[m][u]=f*g+d*v}for(let m=0;m<e;m++){const g=o[l][m],v=o[u][m];o[l][m]=d*g-f*v,o[u][m]=f*g+d*v}for(let m=0;m<e;m++){const g=r[m][l],v=r[m][u];r[m][l]=d*g-f*v,r[m][u]=f*g+d*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 wM(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[A,I]=t[y],[z,j]=e[y];for(const P of[[A,I,1,0,0,0,-z*A,-z*I,-z],[0,0,0,A,I,1,-j*A,-j*I,-j]])for(let N=0;N<9;N++)for(let F=0;F<9;F++)o[N][F]+=P[N]*P[F]}const r=bM(o),a=[[r[0],r[1],r[2]],[r[3],r[4],r[5]],[r[6],r[7],r[8]]],{values:n}=Gs(Zo(Pn(a),a)),i=Math.sqrt([...n].sort((y,A)=>y-A)[1]);let l=a.map(y=>y.map(A=>A/i)),u=0;for(let y=0;y<t.length;y++)u+=kr([e[y][0],e[y][1],1],hr(l,[t[y][0],t[y][1],1]))>0?1:-1;u<0&&(l=l.map(y=>y.map(A=>-A)));const{values:c,vectors:s}=Gs(Zo(Pn(l),l)),d=[0,1,2].sort((y,A)=>c[A]-c[y]),f=c[d[0]],m=c[d[2]],g=s.map(y=>y[d[0]]),v=s.map(y=>y[d[1]]),x=s.map(y=>y[d[2]]);if(!(f-m>1e-9))return[];const $=Math.sqrt(f-m),E=Math.sqrt(Math.max(0,1-m))/$,S=Math.sqrt(Math.max(0,f-1))/$,k=[];for(const y of[vr(Ne(g,E),Ne(x,S)),Bo(Ne(g,E),Ne(x,S))]){let A=qa(Hh(v,y));A[2]>0&&(A=Ne(A,-1)),k.push(A)}return k}function kM(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,l=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 A=0;A<3;A++)g[y][A]+=k[y]*k[A]}}const $=Jf(g,v),E=Jf(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 c=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=l(g);if(!v)continue;const x=u(v).filter($=>$<r).length;x>s&&(s=x,c=v)}if(!c)return null;const d=u(c),f=l(d.map((m,g)=>m<r*1.5?g:-1).filter(m=>m>=0))??c;return u(f)}function xM(t){if(t.length<8)return null;const e=Ne(t.reduce((i,l)=>vr(i,l),[0,0,0]),1/t.length),o=[[0,0,0],[0,0,0],[0,0,0]];for(const i of t){const l=Bo(i,e);for(let u=0;u<3;u++)for(let c=0;c<3;c++)o[u][c]+=l[u]*l[c]}const{values:r,vectors:a}=Gs(o),n=[0,1,2].sort((i,l)=>r[i]-r[l]);return r[n[0]]<.15**2*r[n[1]]?{O:e,n:qa(a.map(i=>i[n[0]]))}:null}function MM(t,e,{w:o,h:r,f:a,region:n,follow:i,seed:l,onProgress:u=null,seeds:c=Do.seeds}){const s=o/2,d=r/2,f=Do.minPoints,m=Array.from({length:t},()=>new Map),g=new Map,v=new Map,x=new Map,$=new Map,E=new Array(t).fill(null);let S=0,k=0;const y=ot=>[Math.min(...ot.map(G=>G[0])),Math.min(...ot.map(G=>G[1])),Math.max(...ot.map(G=>G[0])),Math.max(...ot.map(G=>G[1]))];E[e]={R:R1(),C:[0,0,0]};for(const ot of l(e,(G,tt)=>B1(n,G,tt),[],y(n))){const G=S++;m[e].set(G,ot),g.set(G,Zf(E[e],ot,1,a,s,d)),v.set(G,e)}if(g.size<10)throw Error("FLAT");const A=(ot,G)=>g.has(ot)&&(v.get(ot)===e||Math.abs(G-v.get(ot))>=3),I=ot=>{g.delete(ot);for(const G of m)G.delete(ot)},z=(ot,G)=>{const tt=[...m[ot]].filter(([Q])=>A(Q,ot)).map(([Q,it])=>[Math.hypot(it[0]-G[0],it[1]-G[1]),-hr(E[ot].R,Bo(g.get(Q),E[ot].C))[2]]).sort((Q,it)=>Q[0]-it[0]).slice(0,6);return tt.length?dl(tt.map(Q=>Q[1])):1},j=()=>{const ot=E.map((tt,Q)=>tt&&Q!==e?Q:-1).filter(tt=>tt>=0),G=Math.max(1,Math.ceil(ot.length/20));tl(E,g,m,[e,...ot.filter((tt,Q)=>Q%G===0||Q===ot.length-1)],a,s,d,4)},P=(ot,G,tt=!0)=>{const Q=ht=>ht&&ht.R.flat().every(Number.isFinite)&&ht.C.every(Number.isFinite),it=ht=>{let yt;try{yt=Gb(ot,ht,a,s,d,1).pose}catch{return null}if(!Q(yt))return null;const Mt=ot.map(p=>za(yt,p.X,p.px,a,s,d));return{pose:yt,res:Mt,e:Mt.reduce((p,lt)=>p+Math.min(lt,3),0)/Mt.length}};let D=it(G);const U=tt&&yM(G,ot.map(ht=>ht.X));if(Q(U)){const ht=it(U);ht&&(!D||ht.e<D.e*.98)&&(D=ht)}return D??{pose:G,res:ot.map(ht=>za(G,ht.X,ht.px,a,s,d)),e:1/0}},N=ot=>{let G=new Map([...m[e]].filter(([Q])=>g.has(Q))),tt=0;for(let Q=e+ot;Q>=0&&Q<t;Q+=ot){const it=[...G.keys()],D=i(Q-ot,Q,it.map(lt=>G.get(lt))),U=new Map;it.forEach((lt,V)=>{D[V]&&U.set(lt,D[V])});{const lt=[...U.keys()],V=lt.map(T=>G.get(T)),h=lt.map(T=>U.get(T)),w=kM(V,h);if(w){const T=Math.max(1,3*dl(w));lt.forEach((C,O)=>{const L=w[O]>T?($.get(C)??0)+1:0;$.set(C,L),L>=2&&(I(C),U.delete(C))})}}const ht=()=>{const lt=[...U].filter(([h])=>A(h,Q));if(lt.length<f)return null;const V=lt.map(([h,w])=>({X:g.get(h),px:w}));return{...P(V,E[Q-ot],Q%3===0),use:lt}};let yt=ht();if(!yt)break;const Mt=Math.max(1.5,3*dl(yt.res));let p=0;for(const[lt,V]of U){const T=za(yt.pose,g.get(lt),V,a,s,d)>(A(lt,Q)?Mt:3*Mt+4)?(x.get(lt)??0)+1:0;x.set(lt,T),T>=2&&(I(lt),U.delete(lt),p++)}if(p&&(yt=ht(),!yt))break;E[Q]=yt.pose;for(const[lt,V]of U)m[Q].set(lt,V);if(G=U,G.size<c*.7){const lt=hM([...G].filter(([V])=>A(V,Q)).map(([,V])=>V));if(lt.length>=3){const V=Math.max(3,o*.012);for(const h of l(Q,(w,T)=>dM(lt,w,T,V),[...G.values()],y(lt).map((w,T)=>w+(T<2?-V:V)))){const w=S++;g.set(w,Zf(E[Q],h,z(Q,h),a,s,d)),v.set(w,Q),G.set(w,h),m[Q].set(w,h)}}}++tt>=15&&(tt=0,j()),u?.(++k/t)}};N(1),N(-1);const F=E.map((ot,G)=>ot?G:-1).filter(ot=>ot>=0),K=Math.max(1,Math.ceil(F.length/36)),_=[e,...F.filter((ot,G)=>ot!==e&&(G%K===0||G===F.length-1))],J=(ot=!1,G=!1)=>{for(const tt of F){if(!ot&&_.includes(tt))continue;const Q=[];for(const[it,D]of m[tt])g.has(it)&&Q.push({X:g.get(it),px:D});Q.length>=f&&tt!==e&&(E[tt]=P(Q,E[tt],G).pose)}},X=()=>{let ot=0;for(const G of _)for(const[tt,Q]of m[G])if(g.has(tt)){const it=za(E[G],g.get(tt),Q,a,s,d);ot+=it<=2?it*it:4*it-4}return ot},rt=xM([...m[e].keys()].filter(ot=>g.has(ot)).map(ot=>g.get(ot)));if(rt){const ot=()=>({P:E.map(p=>p&&{R:p.R.map(lt=>[...lt]),C:[...p.C]}),X:new Map([...g].map(([p,lt])=>[p,[...lt]]))}),G=p=>{p.P.forEach((lt,V)=>{E[V]=lt&&{R:lt.R.map(h=>[...h]),C:[...lt.C]}}),g.clear();for(const[lt,V]of p.X)g.set(lt,[...V])},tt=p=>{let lt=0;for(const V of p)for(const[h,w]of m[V])if(g.has(h)){const T=za(E[V],g.get(h),w,a,s,d);lt+=T<=2?T*T:4*T-4}return lt},Q=()=>{for(const p of[1,-1])for(let lt=e+p;E[lt];lt+=p){const V=[];for(const[h,w]of m[lt])g.has(h)&&V.push({X:g.get(h),px:w});E[lt]=V.length>=f?P(V,E[lt-p],!0).pose:{...E[lt-p]}}},it=p=>[...m[e].keys()].filter(lt=>m[p].has(lt)&&g.has(lt)),U=[F.find(p=>it(p).length>=12),[...F].reverse().find(p=>it(p).length>=12)].filter(p=>p!==void 0&&p!==e).map(p=>{const lt=it(p),V=h=>[(h[0]-s)/a,(h[1]-d)/a];return wM(lt.map(h=>V(m[e].get(h))),lt.map(h=>V(m[p].get(h))))}).filter(p=>p.length),ht=[];if(U.length===2)for(const p of U[0]){const lt=U[1].reduce((V,h)=>kr(h,p)>kr(V,p)?h:V);kr(p,lt)>Math.cos(15*yn)&&ht.push(qa(vr(p,lt)))}else U.length===1&&ht.push(...U[0]);const yt=ot();let Mt={cost:tt(F),st:yt};for(const p of ht){const lt=[p[0],-p[1],-p[2]];G(yt);for(const h of m[e].keys()){const w=g.get(h);if(!w)continue;const T=qa(w),C=kr(lt,T);if(Math.abs(C)>.05){const O=kr(lt,rt.O)/C;O>0&&g.set(h,Ne(T,O))}}Q(),tl(E,g,m,_,a,s,d,8),J(!0,!0);const V=tt(F);V<Mt.cost&&(Mt={cost:V,st:ot()})}G(Mt.st)}for(let ot=0;ot<4;ot++){J(!0,ot===0);const G=new Map;for(const it of F)for(const[D,U]of m[it])g.has(D)&&G.set(D,Math.max(G.get(D)??0,za(E[it],g.get(D),U,a,s,d)));const tt=Math.max(1.5,2.5*dl([...G.values()]));let Q=0;for(const[it,D]of G)D>tt&&(I(it),Q++);if(tl(E,g,m,_,a,s,d,8),J(),!Q&&ot)break}for(let ot=0,G=X();ot<8;ot++){tl(E,g,m,_,a,s,d,5);const tt=X();if(tt>G*.998)break;G=tt}return J(!0),u?.(1),{poses:E,points:g,obs:m,ref:e}}function vM(t,e,{w:o,h:r,mw:a,mh:n,f:i,region:l,smooth:u=Do.smooth,id:c="o1",name:s=""}){const{poses:d,points:f,obs:m,ref:g}=t,v=o/2,x=r/2,$=[...f.values()];if($.length<Do.minPoints)throw Error("FLAT");const E=Ne($.reduce((U,ht)=>vr(U,ht),[0,0,0]),1/$.length),S=d[g].C,k=d[g].R,y=Math.hypot(...Bo(E,S))||1,A=[[0,0,0],[0,0,0],[0,0,0]];for(const U of $){const ht=Bo(U,E);for(let yt=0;yt<3;yt++)for(let Mt=0;Mt<3;Mt++)A[yt][Mt]+=ht[yt]*ht[Mt]}const{values:I,vectors:z}=Gs(A),j=[0,1,2].sort((U,ht)=>I[U]-I[ht]),P=I[j[0]]<.08**2*I[j[1]];let N=Pn(k);if(P){let U=qa(z.map(p=>p[j[0]]));kr(U,Bo(S,E))<0&&(U=Ne(U,-1));const ht=hr(Pn(k),[1,0,0]),yt=qa(Bo(ht,Ne(U,kr(U,ht)))),Mt=Hh(U,yt);N=Pn([yt,Mt,U])}const F=U=>Ne(hr(Pn(N),Bo(U,E)),1/y),K=d.map((U,ht)=>U?ht:-1).filter(U=>U>=0),_=Math.min(...K),J=Math.max(...K),X=[];for(let U=_;U<=J;U++){const ht=d[U]??d[X.length?U-1:g];d[U]=ht;const yt=Zo(ht.R,N),Mt=Ne(hr(ht.R,Bo(E,ht.C)),1/y);let p=0,lt=0;for(const[V,h]of m[U]){const w=f.get(V);w&&(p+=za(ht,w,h,i,v,x),lt++)}X.push({t:e[U],R:yt,T:Mt,err:lt?p/lt:0,n:lt})}const rt=new Map;for(const U of m)for(const ht of U.keys())f.has(ht)&&rt.set(ht,(rt.get(ht)??0)+1);const ot=[...rt].sort((U,ht)=>ht[1]-U[1]).slice(0,Do.points).map(([U])=>F(f.get(U))),G=ot.map(U=>U[0]).sort((U,ht)=>U-ht),tt=Math.max(1e-4,G[Math.floor(G.length*.98)]-G[Math.floor(G.length*.02)]),Q=$M(X,ot,i,u);let it=0,D=0;for(const U of X)it+=U.err*U.n,D+=U.n;return{v:1,id:c,...s?{name:String(s).slice(0,40)}:{},w:o,h:r,mw:a||o,mh:n||r,f:Ro(i),ref:Ro(e[g]),region:l.map(U=>[Fo(U[0]),Fo(U[1])]),plane:P,width:Ro(tt),err:Ro(D?it/D:0),smooth:u,frames:Q.map((U,ht)=>[Ro(U.t),...Sg(U.R).map(Ro),...U.T.map(Ro),Fo(X[ht].err),X[ht].n]),points:ot.map(U=>U.map(Ro))}}function $M(t,e,o,r){if(!(r>0)||t.length<3)return t;const a=r*Do.smoothFrames,n=Math.ceil(a*2.5),i=Do.smoothTolPx,l=e.filter((d,f)=>f%Math.max(1,Math.floor(e.length/40))===0),u=(d,f)=>{const m=vr(hr(d.R,f),d.T);return m[2]>-1e-6?null:[o*m[0]/-m[2],o*m[1]/-m[2]]},c=(d,f)=>{let m=0;for(const g of l){const v=u(d,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(d=>Sg(d.R));return t.map((d,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)),A=ah(s[k],s[f])<0?s[k].map(I=>-I):s[k];m+=y,g=vr(g,Ne(t[k].T,y)),v=v.map((I,z)=>I+A[z]*y)}const x=k=>{const y=s[f].map((I,z)=>I+(v[z]/m-I)*k),A=Math.hypot(...y);return{...d,R:Eg(y.map(I=>I/A)),T:vr(d.T,Ne(Bo(Ne(g,1/m),d.T),k))}};let $=1,E=x(1),S=c(d,E);for(let k=0;k<6&&S>i;k++)$*=Math.max(.3,i/S*.95),E=x($),S=c(d,E);return S>i?d:E})}const ah=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3];function Jf(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((l,u)=>u===a?e[i]:l)))/r):null}function Gs(t){const e=t.map(r=>[...r]),o=R1();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 l=(e[i][i]-e[n][n])/(2*e[n][i]),u=Math.sign(l||1)/(Math.abs(l)+Math.sqrt(l*l+1)),c=1/Math.sqrt(u*u+1),s=u*c;for(let d=0;d<3;d++){const f=e[d][n],m=e[d][i];e[d][n]=c*f-s*m,e[d][i]=s*f+c*m}for(let d=0;d<3;d++){const f=e[n][d],m=e[i][d];e[n][d]=c*f-s*m,e[i][d]=s*f+c*m}for(let d=0;d<3;d++){const f=o[d][n],m=o[d][i];o[d][n]=c*f-s*m,o[d][i]=s*f+c*m}}}return{values:[e[0][0],e[1][1],e[2][2]],vectors:o}}const EM=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 zC(t,e,{ref:o,region:r,f:a,mw:n,mh:i,smooth:l,onProgress:u=null,id:c,name:s}={}){if(t.length<3)throw Error("FLAT");const d=t[0].w,f=t[0].h,m=new Map,g=x=>{let $=m.get(x);return $||(m.size>3&&m.delete(m.keys().next().value),$=_b(EM(t[x])),m.set(x,$)),$},v=MM(t.length,o,{w:d,h:f,f:a,region:r,onProgress:u,follow:(x,$,E)=>Bb(g(x),g($),E),seed:(x,$,E,S)=>fM(g(x)[0],$,S,{taken:E})});if(v.poses.filter(Boolean).length<Math.min(t.length,3))throw Error("LOST");return vM(v,e,{w:d,h:f,mw:n,mh:i,f:a,region:r,smooth:l,id:c,name:s})}function SM(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)],l=i[0]>n[0]?Math.max(0,Math.min(1,(e-n[0])/(i[0]-n[0]))):0;let u=n.slice(1,5),c=i.slice(1,5);ah(u,c)<0&&(c=c.map(f=>-f));const s=Math.min(1,Math.max(-1,ah(u,c)));let d;if(s>.9995){d=u.map((m,g)=>m+(c[g]-m)*l);const f=Math.hypot(...d);d=d.map(m=>m/f)}else{const f=Math.acos(s),m=Math.sin(f);d=u.map((g,v)=>g*Math.sin((1-l)*f)/m+c[v]*Math.sin(l*f)/m)}return{R:Eg(d),T:[0,1,2].map(f=>n[5+f]+(i[5+f]-n[5+f])*l),err:n[8]+(i[8]-n[8])*l,n:Math.round(n[9]+(i[9]-n[9])*l)}}function IM(t,e,o){const r=(t.keys??[]).filter(l=>Number.isFinite(l[e])).sort((l,u)=>l.t-u.t);if(!r.length)return t.fix?.[e]??F1[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 AM=(t,e)=>Object.fromEntries(rh.map(o=>[o,IM(t,o,e)]));function Xh(t,e,{raw:o=!1}={}){const r=SM(t,e);if(o)return{...r,s:1};const a=AM(t,e);return{...r,R:Zo(r.R,D1(a.rx,a.ry,a.rz)),T:vr(r.T,Ne(nh([a.x,a.y,a.z]),t.width)),s:a.s}}function _1(t,e,o,r=Xh(t,o)){const a=vr(hr(r.R,Ne(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 PC(t,e,o=.5){const r=Xh(t,e),a=t.width*o,n=i=>_1(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 LC(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 NC(t,e,o,r=!1){let a=(t.keys??[]).map(i=>({...i})),n={...t.fix};o=Fo(o);for(const i of rh){const l=e[i];if(typeof l!="number"||!Number.isFinite(l))continue;if(a.some(c=>Number.isFinite(c[i]))||r){let c=a.find(s=>Math.abs(s.t-o)<.016666666666666666);c||(c={t:o},a.push(c)),c[i]=Fo(l)}else n[i]=Fo(l)}for(const i of rh)n[i]===F1[i]&&delete n[i];return a=a.sort((i,l)=>i.t-l.t),{...t,keys:a.length?a:void 0,fix:Object.keys(n).length?n:void 0}}function FC(t,e){const o=(t.keys??[]).filter(r=>Math.abs(r.t-e)>=.016666666666666666);return{...t,keys:o.length?o:void 0}}function RC(t){const e=new Set((t?.objectTracks??[]).map(r=>r.id));let o=1;for(;e.has(`o${o}`);)o++;return`o${o}`}function G1(t,e,o,r,a){const n=ef(t,e,t.w/2,t.h/2,o,r,a),i=ef(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 CM(t,e,o,r,a,n,i=null){return i?Fb(i,e.w,e.w/e.h):5*Or(r,a)*(Rs(n)?Ys(n,"zoom",t.start+o):1)/G1(e,t,o,r,a)}function DC(t,e,o,r,a=t.f){return a*G1(t,e,t.ref,o,r)/(5*Or(o,r))}function jM(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,l=t.region.map(g=>g[0]),u=t.region.map(g=>g[1]),c=[(Math.min(...l)+Math.max(...l))/2*i,Math.max(...u)*i],s=[l.reduce((g,v)=>g+v,0)/l.length*i,u.reduce((g,v)=>g+v,0)/u.length*i],d=vk(n,t.ref).C,f=$k(n,c[0],c[1],t.ref)??Ek(n,s[0],s[1],t.ref),m=Math.hypot(...Bo(f,d));if(m>0)return m*Sk(n,e,o,r).k}return 5*Or(o,r)*(Rs(a)?Ys(a,"zoom",e.start+t.ref):1)}function TM(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 l=[[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)]],c=Zo(Pn(Zo(u,l)),t);return[n/yn,i/yn,Math.atan2(c[1][0],c[0][0])/yn]});return K1(a,e)}function OM(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 K1([[r,o,a],[r+Math.PI,Math.PI-o,a+Math.PI]].map(n=>n.map(i=>i/yn)),e)}function K1(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,l,u)=>i+Math.abs(l-e[u]),0)<a.reduce((i,l,u)=>i+Math.abs(l-e[u]),0)?n:a):r[0]}const zM=["x","y","depth","zoom","rot","tiltX","tiltY","rx","ry","rz"],PM=t=>t.kind==="model"?"model":t.nullLayer?"null":t.title?"text":"plane";function LM(t,e,o,r,a,n,i={},{scene:l=null}={}){const u=Math.max(t.start,e.start+o.frames[0][0]),c=Math.min(t.start+t.duration,e.start+o.frames.at(-1)[0]),s=Math.max(t.start,e.start),d=Math.min(t.start+t.duration,e.start+e.duration);if(!(d>s))throw Error("TIME");const f=Rs(n)?n:{enabled:!0,motionV:2,motionKeys:[]},m=CM(e,o,o.ref,r,a,f);if(Math.abs(m/o.f-1)>.03)throw Error("LENS");const g=Or(r,a),v=jM(o,e,r,a,f,l),x=PM(t),$=Number.isFinite(i.size)&&i.size>0?i.size:Do.glue[x],E=(i.offset??[0,0,0]).map(Q=>Q*o.width),S=i.turn??[0,0,0],k=D1(S[0],S[1],S[2]),y=[Math.max(s,Math.min(d,u)),...o.frames.map(Q=>e.start+Q[0]).filter(Q=>Q>u+1e-4&&Q<c-1e-4),Math.min(d,Math.max(s,c))],A=y.filter((Q,it)=>it===0||Q>y[it-1]+1e-4),I=[];let z,j;for(const Q of A){const it=Q-e.start,D=Xh(o,it),U=Rb(f,Q,r,a),ht=Zo(Zo(D.R,k),hl),yt=vr(hr(D.R,Ne(nh(E),D.s)),D.T),Mt=Ne(nh(yt),v),p=vr(hr(U.R,Mt),U.pos),lt=Zo(U.R,Zo(hl,ht)),V=-p[2]/g;if(!(V>=Bh&&V<=Db)||!(Mt[2]>1))throw Error("FAR");const h={time:+(Q-t.start).toFixed(4),x:p[0]/r,y:p[1]/a,depth:V,zoom:$*o.width*D.s*v/(x==="model"?1.8*g:r),d:Mt[2],f:U.f};if(x==="model"){const w=OM(Zo(Zo(hl,lt),hl),j);j=w,Object.assign(h,{rx:w[0],ry:w[1],rz:w[2]})}else{const w=TM(lt,z);z=w,Object.assign(h,{tiltX:w[0],tiltY:w[1],rot:w[2]})}I.push(h)}const P=Do.keyTolPx,N=Math.max(1,...I.map(Q=>Q.zoom*(x==="model"?1.8*g:r)*Q.f/Q.d)),F=Math.min(...I.map(Q=>Q.d)),K=2*P/N/yn,_={x:P/r,y:P/a,depth:P*F/N/g,zoom:P/N*I[0].zoom,rot:K,tiltX:K,tiltY:K,rx:K,ry:K,rz:K};let J={...t,motionV:2};for(const Q of zM)(J.motionKeys??[]).some(it=>it[Q]!==void 0)&&(J={...J,motionKeys:tn(J,Q,[])});const X=x==="model"?["x","y","depth","zoom","rx","ry","rz"]:["x","y","depth","zoom","rot","tiltX","tiltY"],rt={},ot=I.map(Q=>Q.time);for(const Q of X){const it=I.map(D=>D[Q]);if(Math.max(...it)-Math.min(...it)<=_[Q]){rt[Q]=Ro(it[0]);continue}J={...J,motionKeys:tn(J,Q,Mk(ot,it,_[Q],1/0).sort((D,U)=>D-U).map(D=>({time:ot[D],value:Ro(it[D])})))}}const G=I[0],tt={is3D:!0,motionV:2,motionKeys:J.motionKeys??[],posX:Ro(G.x),posY:Ro(G.y),spatialDepth:Ro(G.depth),scale:Ro(rt.zoom??G.zoom),objectGlue:{source:e.id,object:o.id,...Number.isFinite(i.size)?{size:Fo(i.size)}:{},...i.offset?{offset:i.offset.map(Fo)}:{},...i.turn?{turn:i.turn.map(Fo)}:{}}};return x==="model"?Object.assign(tt,{modelDepth:tt.spatialDepth,modelGround:void 0,modelRotation:{x:Fo(rt.rx??G.rx),y:Fo(rt.ry??G.ry),z:Fo(rt.rz??G.rz)}}):Object.assign(tt,{rotation:Fo(rt.rot??G.rot),tiltX:Fo(rt.tiltX??G.tiltX),tiltY:Fo(rt.tiltY??G.tiltY)}),{camera:Rs(n)?null:f,patch:tt}}function BC(t,e,o,r,a,n,{scene:i=null}={}){const l=t.find(m=>m.id===e),u=l?.objectTracks?.find(m=>m.id===o);let c=n,s=null;const d=[];return u?{clips:t.map(m=>{if(m.objectGlue?.source!==e||m.objectGlue.object!==o)return m;try{const g=LM(m,l,u,r,a,c,m.objectGlue,{scene:i});return g.camera&&(c=s=g.camera),{...m,...g.patch}}catch{return d.push(m.id),m}}),camera:s,failed:d}:{clips:t,camera:null,failed:d}}const Gr=t=>typeof t=="number"&&Number.isFinite(t)?t:null,Qf=(t,e,o)=>{if(t!=null){if(!(Array.isArray(t)&&t.length===3&&t.every(r=>Gr(r)!==null&&Math.abs(r)<=o)))throw Error(`placeOnObject ${e}: [x, y, z] (each within ±${o})`);return t.map(Fo)}};function NM(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=>Gr(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]=Do.regionPoints;if(!(Array.isArray(r)&&r.length>=a&&r.length<=n&&r.every(g=>Array.isArray(g)&&g.length===2&&g.every(v=>Gr(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 l=Math.max(0,Math.min(e.duration,(Gr(t.at)??e.start)-e.start)),u=Math.max(0,Math.min(e.duration,(Gr(t.from)??Gr(t.start)??e.start)-e.start)),c=Math.min(e.duration-u,Gr(t.duration)??e.duration-u);if(!(c>=.3))throw Error("trackObject3D: at least 0.3 s of the footage");if(l<u-.001||l>u+c+.001)throw Error("trackObject3D: `at` (the frame the region is drawn on) must be inside from … from + duration");const s=Gr(t.size),d=Gr(t.lens),f=Gr(t.smooth);if(s!==null&&!(s>=Do.size[0]&&s<=Do.size[1]))throw Error(`trackObject3D size: ${Do.size.join("–")} (the object's width as a share of the frame width)`);if(d!==null&&d!==0&&!(d>=8&&d<=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)>=Do.max)throw Error(`trackObject3D: at most ${Do.max} objects per clip (remove one first)`);const m=u<.001&&c>e.duration-.001;return{region:r.map(g=>[Ro(g[0]),Ro(g[1])]),at:+l.toFixed(4),...m?{}:{from:+u.toFixed(4),duration:+c.toFixed(4)},...s!==null?{size:s}:{},...d?{lens:d}:{},...f!==null?{smooth:f}:{},...t.name?{name:String(t.name).slice(0,40)}:{}}}function FM(t,e,o){if(!e||e.kind==="audio")throw Error("placeOnObject needs a visual layer (text, null, solid, picture, video, 3D model)");if(!o||o.kind!=="video"||o.id===e.id)throw Error("placeOnObject needs sourceClipId = the footage with the tracked object (a video clip, not the layer itself)");const r=Math.max(e.start,o.start);if(!(Math.min(e.start+e.duration,o.start+o.duration)>r))throw Error("placeOnObject: the layer and the footage must play at the same time");const 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 l=Gr(t.size);if(l!==null&&!(l>.01&&l<=100))throw Error("placeOnObject size: 0.01–100 (× the object's width)");const u=Qf(t.offset,"offset",50),c=Qf(t.turn,"turn",3600);return{source:o.id,...n?{object:n}:{},...l!==null?{size:l}:{},...u?{offset:u}:{},...c?{turn:c}:{}}}const _C=(t,e,o)=>o.map(([r,a])=>xk(t,e,r,a)),Sc=Object.freeze(["hand","roto","planar","face","object"]),V1=15,ih=900,RM=t=>t?.crop??{left:0,right:0,top:0,bottom:0},DM=(t,e,o)=>{const r=RM(t);return[r.left+e*(1-r.left-r.right),r.top+o*(1-r.top-r.bottom)]},fl=t=>Math.round(t*1e4)/1e4;function GC(t){if(!t||t.kind!=="video")return[];const e=[];t.hands?.data&&e.push({source:"hand",label:"Tay (tracking tay)",points:Mc,sides:["right","left"]}),t.roto?.points?.length&&e.push({source:"roto",label:"Điểm Roto"}),t.planar?.frames?.length&&!Ig(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 BM(t,e,{side:o="right",point:r="palm",object:a,from:n=0,to:i,fps:l=V1}={}){if(!t||t.kind!=="video")throw Error("VFX tracks come from a filmed video clip");if(!Sc.includes(e))throw Error(`source must be ${Sc.join(" / ")}`);const u=Math.min(t.duration,i??t.duration),c=1/Math.max(1,Math.min(30,l)),s=[];let d,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=Zs(t.hands),v=o==="left"?1:0,x=Mc.includes(r)?r:"palm";f=g.mw,m=g.mh,d=$=>{const E=Ec(g,$c(t,$),v);return E?[...Ii(E,x),L1(E,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,d=g=>Kb(t,g)}else if(e==="planar"){if(!t.planar?.frames?.length)throw Error(Ig(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;d=v=>{if(!Vb(t.planar,v))return null;const x=Wb(t.planar,v).map(([$,E])=>DM(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,d=g=>{const v=Hb(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,d=v=>{if(v<g.frames[0][0]-1e-6||v>g.frames.at(-1)[0]+1e-6)return null;const x=_1(g,[0,0,0],v);return x?[x[0]/g.w,x[1]/g.h]:null}}for(let g=0;s.length<ih;g++){const v=Math.max(0,n)+g*c;if(v>u+1e-6)break;const x=d(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([fl(Math.min(v,u)),fl(x[0]),fl(x[1]),...Number.isFinite(x[2])&&x[2]>0?[fl(x[2])]:[]])}if(s.length<2)throw Error(`the ${e} track does not see its target in this clip (fewer than 2 samples)`);return{fps:Math.round(1/c),points:s,...f>0&&m>0?{mw:f,mh:m}:{}}}function KC(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>ih)throw Error(`track: 2 to ${ih} 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,l]=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||l<-.5||l>1.5)throw Error("track u / v are fractions of the picture (−0.5..1.5)");return o=n,[n,i,l]});return{fps:Number.isFinite(Number(t.fps))?Number(t.fps):V1,points:r}}const _M=15,jn=t=>Math.round(t*1e4)/1e4,GM=new Set(["hand","face","planar"]);function KM(t,e,o){const r=t.vfxFootage||{},a=Array.isArray(r.anchor)&&r.anchor.length===2&&r.anchor.every(Number.isFinite)?r.anchor:Vu,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 VM(t,e,{source:o,hand:r="right",point:a="palm",object:n,scale:i=!1,offset:l=null,W:u=1280,H:c=720}={}){if(!t?.vfxFootage)throw Error("vfxFootageFollow: clipId must be a Footage VFX layer (addVfxFootage)");if(!e||e.kind!=="video"||e.vfxFootage||e.vfx)throw Error("vfxFootageFollow: sourceClipId must be the filmed video clip with the track");if(!Sc.includes(o))throw Error(`vfxFootageFollow: source must be ${Sc.join(" / ")}`);if(i&&!GM.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),d=Math.min(t.start+t.duration,e.start+e.duration);if(!(d-s>=1/30))throw Error("vfxFootageFollow: the effect and the filmed clip do not play at the same time");const f=BM(e,o,{side:r==="left"?"left":"right",point:a,...n!=null?{object:String(n)}:{},from:s-e.start,to:d-e.start,fps:_M}),m=f.mw||Number(e.proxy?.width)||u,g=f.mh||Number(e.proxy?.height)||c,v=e.crop??{left:0,right:0,top:0,bottom:0},x=1-v.left-v.right||1,$=1-v.top-v.bottom||1,E=f.points.map(([rt,ot,G,tt])=>{const Q=cc(e,(ot-v.left)/x,(G-v.top)/$,rt,u,c,m,g);return{T:e.start+rt,fx:Q.px/u,fy:Q.py/c,size:tt}});if(i&&E.some(rt=>!(rt.size>0)))throw Error(`vfxFootageFollow: the ${o} track has no size to scale with`);const S={...t,...en(t)},k=E[0],y=rt=>jn(rt-t.start),{anchor:A,aspect:I}=KM(t,u,c),z=u/c,j=I>=z?1:I/z,P=I>=z?z/I:1,N=Array.isArray(l)&&Number.isFinite(Number(l[0]))?Number(l[0]):0,F=Array.isArray(l)&&Number.isFinite(Number(l[1]))?Number(l[1]):0,K=Zt(S,"zoom",k.T-t.start)||1,_=E.map(rt=>i?Math.max(.05,K*rt.size/k.size):Zt(S,"zoom",rt.T-t.start)||1);let J={...S,motionV:2};delete J.posX,delete J.posY,J={...J,...me(J,"x",E.map((rt,ot)=>({time:y(rt.T),value:jn(rt.fx+N-.5-(A[0]-.5)*j*_[ot])})))},J={...J,...me(J,"y",E.map((rt,ot)=>({time:y(rt.T),value:jn(rt.fy+F-.5-(A[1]-.5)*P*_[ot])})))},i&&(J={...J,...me(J,"zoom",E.map((rt,ot)=>({time:y(rt.T),value:jn(_[ot])})))});const X={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:J.motionKeys,posX:void 0,posY:void 0,vfxFootage:{...t.vfxFootage,follow:X}},keys:E.length,from:jn(E[0].T),to:jn(E.at(-1).T)}}function WM(t,e=0){const o=t?.vfxFootage?.follow;if(!o)throw Error("vfxFootageFollow: this effect follows nothing");const r={...t,...en(t)},a=Zt(r,"x",e),n=Zt(r,"y",e),i=Zt(r,"zoom",e),l=(r.motionKeys||[]).map(s=>{const{x:d,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(d=>d!=="time")),{follow:u,...c}=t.vfxFootage;return{motionV:2,motionKeys:l,posX:jn(a),posY:jn(n),...o.scale?{scale:jn(i)}:{},vfxFootage:c}}const sa=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"]}),Wr=(t,[e,o],r)=>{const a=Number(t);return Number.isFinite(a)?Math.min(o,Math.max(e,a)):r},Te=t=>Math.round(t*1e4)/1e4,tm=Object.freeze({grow:-.35,feather:.004});function Gn(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,tm.grow),feather:Math.max(r.person.feather??0,tm.feather)}),delete r.roto,delete r.planar,delete r.personPending,delete r.sceneTrack,delete r.shocks,delete r.impacts,r}function HM(t,{copies:e=5,gap:o=.07,fade:r=.35,opacity:a=.85,spread:n=0,look:i=null,start:l=null,duration:u=null}={},c){const s=Math.round(Wr(e,sa.echo.copies,5)),d=Wr(o,sa.echo.gap,.07),f=Wr(r,sa.echo.fade,.35),m=Wr(n,sa.echo.spread,0);if(i!=null&&!Object.hasOwn(pc,i))throw Error(`personEcho: look must be a clip effect (${Object.keys(pc).join(", ")})`);const g=i?[...(t.effects??[]).slice(0,cn-1),{type:i,amount:.85}]:null,v=Math.max(t.start,Number.isFinite(l)?l: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 $=[];for(let S=s;S>=1;S--){const k=S*d,y=v+k;if(y>=x-.05)continue;const A=(t.inPoint||0)+(v-t.start)*(t.playbackRate||1);$.push(Gn(t,c(),{start:Te(y),duration:Te(x-y),inPoint:Te(A),opacity:Te(a*(1-f)**(S-1)*(1-.5*S/(s+1))),label:`${t.label||"Video"} · vệt ${S}`,...m?{motionV:2,posX:Te((t.posX??0)+S*m)}:{},...g?{effects:g}:{}}))}const E=(t.inPoint||0)+(v-t.start)*(t.playbackRate||1);return $.push(Gn(t,c(),{start:Te(v),duration:Te(x-v),inPoint:Te(E),label:`${t.label||"Video"} · người`})),$}function XM(t,e="wedge",o=.22,r=.25,a=7){const n=[];let i=a;const l=()=>(i=i*1664525+1013904223>>>0)/2**32;for(let u=1;u<=t;u++){const c=u%2?1:-1,s=Math.ceil(u/2);e==="row"?n.push([c*o*s,0]):e==="wedge"?n.push([c*o*s*.8,-r*s*.35]):n.push([(l()*2-1)*o*3,-r*(.15+l()*.85)])}return n}function UM(t,{count:e=6,layout:o="wedge",spread:r=.2,depth:a=.25,delay:n=.12,mirror:i=!0,feet:l=[.5,.9],horizon:u=.4,start:c=null,duration:s=null,smoke:d=!0,appear:f=.12}={},m){const g=Math.round(Wr(e,sa.clone.count,6)),v=sa.layouts.includes(o)?o:"wedge",x=Wr(r,sa.clone.spread,.2),$=Wr(a,sa.clone.depth,.25),E=Wr(n,[-2,2],.12),S=[Wr(l?.[0],[0,1],.5),Wr(l?.[1],[.05,1],.9)],k=Wr(u,[-1,S[1]-.05],Math.min(.4,S[1]-.1)),y=Math.max(t.start,Number.isFinite(c)?c:t.start),A=Math.min(t.start+t.duration,Number.isFinite(s)?y+s:t.start+t.duration);if(!(A-y>.2))throw Error("clonePerson: the clones must lie inside the person clip");const I=XM(g,v,x,$).map(([N,F],K)=>({i:K,T:[S[0]+N,S[1]+F]})).filter(N=>N.T[1]>k+.02);I.sort((N,F)=>N.T[1]-F.T[1]);const z=[],j=[],P=(t.inPoint||0)+(y-t.start)*(t.playbackRate||1);for(const{i:N,T:F}of I){const K=N+1,_=(F[1]-k)/(S[1]-k),J=Te(F[0]-.5-_*(S[0]-.5)),X=Te(F[1]-.5-_*(S[1]-.5)),rt=Math.abs(E)*K,ot=E>=0?y+Math.min(rt,(A-y)*.6):y,G=E>=0?P:P+Math.min(rt,(A-y)*.6)*(t.playbackRate||1),tt=Te(ot+(f>0?f*(K-1)*.5:0));tt>=A-.1||(z.push(Gn(t,m(),{start:tt,duration:Te(A-tt),inPoint:Te(G+(tt-ot)*(t.playbackRate||1)),motionV:2,posX:J,posY:X,scale:Te((t.scale??1)*_),...i&&K%2===0?{flipX:!t.flipX}:{},enter:{type:"fade",duration:.18},label:`${t.label||"Video"} · bản sao ${K}`})),d&&j.push({at:tt,u:F[0],v:F[1]-.18*_,size:_}))}return z.push(Gn(t,m(),{start:Te(y),duration:Te(A-y),inPoint:Te(P),label:`${t.label||"Video"} · người`})),{layers:z,poofs:j.map(N=>YM(N,m))}}const Bp="vfx-smoke-poof";function YM({at:t,u:e,v:o,size:r=1,duration:a=1.1},n){const i=ma.find(l=>l.id===Bp);return{id:n(),nodeId:"",kind:"image",url:"",volume:0,start:Te(Math.max(0,t-.12)),duration:a,label:"Khói bụp",motionV:2,posX:Te(e-.5),posY:Te(o-.5),scale:Te(Math.max(.2,Math.min(3,r))),motion:ko({code:`@preset:${Bp}`,params:{...i.params},preset:Bp})}}const _p="vfx-debris-burst";function qM({id:t,at:e,u:o,v:r,size:a=1,seed:n=7,duration:i=1.2}){const l=ma.find(u=>u.id===_p);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Te(Math.max(0,e)),duration:i,label:"Mảnh vụn",motionV:2,posX:Te(o-.5),posY:Te(r-.5),scale:Te(Math.max(.2,Math.min(3,a))),motion:ko({code:`@preset:${_p}`,params:{...l.params,seed:n},preset:_p})}}function W1(t){if(t?.kind!=="video")return!1;const e=Xb(t);return e?e.some(o=>o.speed<.999):(t.playbackRate||1)<.999}function VC(t,e,o=30){if(Ub(t)==="none"&&(!t?.smoothSlow||!W1(t)))return null;const r=Ag(t,e)*o,a=Math.floor(r+1e-6);return{frame:a,phase:Math.min(1,Math.max(0,r-a))}}const ZM=Object.freeze(["flame","spirit","electric","smoke","burst"]),Pa=Object.freeze({fps:15,maxFrames:900,color:"#b44dff",hot:"#fff1ff",size:[.3,3],intensity:[.2,2.5],stretch:[.2,4],taper:.75}),JM=Object.freeze([0,11,12,13,14,15,16,23,24,25,26,27,28]),oa=t=>Math.round(t*1e3)/1e3,sh=t=>Math.round(t*1e4)/1e4,ri=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,em=/^#[0-9a-fA-F]{6}$/;function Uh(t={}){const e=ZM.includes(t.look)?t.look:"flame",o=Array.isArray(t.wind)&&t.wind.length===2&&t.wind.every(Number.isFinite)?t.wind.map(r=>oa(ri(r,-1,1,0))):[0,0];return{look:e,color:em.test(t.color??"")?t.color.toLowerCase():Pa.color,hot:em.test(t.hot??"")?t.hot.toLowerCase():Pa.hot,size:oa(ri(t.size,...Pa.size,1)),intensity:oa(ri(t.intensity,...Pa.intensity,1)),wind:o,speed:oa(ri(t.speed,0,2,1)),stretch:oa(ri(t.stretch,...Pa.stretch,1)),taper:oa(ri(t.taper,0,1,Pa.taper))}}function WC(t,e=o=>o){const o=[];for(const r of t){if(!r?.lm)continue;const a=[sh(r.t)];for(const n of JM){const i=r.lm[n];if(!i||(i[3]??1)<.35){a.push(-1,-1);continue}const[l,u]=e([i[0],i[1]]);a.push(oa(l),oa(u))}if(o.push(a),o.length>=Pa.maxFrames)break}return o}function QM(t,e,o="person"){const r=Uh(e),a="const SK="+JSON.stringify(t??[])+";const KIND="+JSON.stringify(o==="thing"?"thing":"person")+";"+tv;return ko({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 tv=`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 ev({id:t,at:e,duration:o,settings:r,body:a=[],kind:n="person",label:i}){const l=Uh(r);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:sh(e),duration:sh(o),label:i||`Aura · ${l.look}`,motionV:2,posX:0,posY:0,scale:1,motion:QM(a,l,n)}}const fs=Object.freeze({count:[3,8],size:[.05,.8],open:[.03,.6],items:24,head:.4}),ml=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,$a=t=>Math.round(t*1e4)/1e4;function ov({x:t,y:e,radius:o,squash:r=.38,count:a=8,seed:n=3}){let i=n>>>0||1;const l=()=>(i=i*1664525+1013904223>>>0)/2**32,u=[],c=(s,d,f,m,g,v)=>{const x=[[s,d]];let $=s,E=d,S=f;for(let k=1;k<=g;k++){S+=(l()-.5)*.9;const y=m/g*(.7+.6*l());$+=Math.cos(S)*y,E+=Math.sin(S)*y*r,x.push([$,E]),v<1&&k>1&&k<g&&l()<.28&&c($,E,S+(l()<.5?-1:1)*(.5+.5*l()),m*(.35+.25*l()),Math.max(2,g-k),v+1)}u.push({pts:x,depth:v})};for(let s=0;s<a;s++)c(t,e,(s+l()*.7)/a*Math.PI*2,o*(.55+.45*l()),7,0);return u}function om(t,e){const o=t.slice(1).reduce((i,l,u)=>i+Math.hypot(l[0]-t[u][0],l[1]-t[u][1]),0),r=o*e,a=[t[0]];let n=0;for(let i=1;i<t.length;i++){const l=Math.hypot(t[i][0]-t[i-1][0],t[i][1]-t[i-1][1]);if(n+l>=r){const u=(r-n)/(l||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+=l,a.push(t[i])}return a}function rv({id:t,at:e,duration:o=1.6,u:r,v:a,size:n=.3,squash:i=.38,count:l=6,open:u=.12,color:c="#1a120c",seed:s=3,W:d=1280,H:f=720}){const m=Dk(d,f),g=Math.round(ml(l,fs.count,6)),v=ml(n,fs.size,.3)*d,x=ml(u,fs.open,.12),$=Math.max(x+.3,o),E=ov({x:r*d,y:a*f,radius:v,squash:ml(i,[.15,1],.38),count:g,seed:s}),S=Math.max(1.2,d/900),k=[],y=E.filter(j=>j.depth===0),A=E.filter(j=>j.depth>0).slice(0,Math.max(0,fs.items-3*y.length)),I=(j,P,N,F,K,_,J=[0,0])=>k.push({id:j,name:P,type:"path",params:{pts:N.map(X=>m.pt(X)),closed:!1},pos:J,rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:K,width:$a(m.len(F)),cap:"round",join:"round",opacity:_}});y.forEach(({pts:j},P)=>{I(`c${P}l`,`crack ${P+1} lip`,om(j,.7),S*1.6,"#ffffff",.18,[0,$a(m.len(S*1.4))]),I(`c${P}`,`crack ${P+1}`,j,S,c,.85),I(`c${P}w`,`crack ${P+1} wide`,om(j,fs.head),S*3.2,c,.9)}),A.forEach(({pts:j},P)=>I(`f${P}`,`crack fork ${P+1}`,j,S*.8,c,.75));let z={id:t,nodeId:"",kind:"image",url:"",volume:0,start:$a(e),duration:$a($),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,...me(z,"trimEnd",[{time:0,value:0},{time:$a(x),value:1}])},z={...z,...me(z,"opacity",[{time:0,value:1},{time:$a($*.55),value:.85},{time:$a($),value:0}])},z}const rm=Object.freeze(["float","turntable","drop-bounce","flip","fly-in","hero-spin","tilt-to-camera","exit-spin"]),nv=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}),nm=t=>+t.toFixed(3);function av(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 iv={rx:"tiltX",ry:"tiltY",rz:"rot"},am=t=>t==null?void 0:typeof t=="string"?t:Object.entries(Qt).find(([,e])=>JSON.stringify(e)===JSON.stringify(t))?.[0];function sv(t,e,{at:o=0,duration:r,amount:a=1}={}){const n=av(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:nv[e]),l=Math.max(0,+o||0),u=Math.min(t.duration,l+i);if(!(u-l>=.2))throw Error("3D move outside the clip");let c=t;for(const[s,d]of Object.entries(n)){const f=t.kind==="model"?s:iv[s]||s,m=["rx","ry","rz","tiltX","tiltY","rot"].includes(f);let g=Zt(c,f,l);m&&(g=(g%360+540)%360-180);const v=Ee(c,f).filter($=>$.time<l-1/60||$.time>u+1/60).map($=>({time:$.time,value:$.value,...am($.ease)?{ease:am($.ease)}:{}})),x=d.map($=>({time:nm(l+(u-l)*$.t),value:nm($.abs?$.v:g+$.v),...$.ease?{ease:$.ease}:{}}));c=Qn(c,f,[...v,...x].sort(($,E)=>$.time-E.time))}return c}const cp=Object.freeze({x:"x",y:"y",lift:"depth",scale:"zoom",yaw:"ry",tilt:"rx",roll:"rz"}),lv=(t,e)=>t==="tilt"?90+e:e,cv=(t,e)=>t==="tilt"?e-90:e,ql=t=>Math.round(t*1e3)/1e3;function HC(t,e){const o={};for(const[r,a]of Object.entries(cp))o[r]=ql(cv(r,Zt(t,a,e)));return o}function XC(t){const e=[];for(const o of Object.values(cp))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 pv(t,e,o,r=!1){let a={...t,...en(t)};for(const[i,l]of Object.entries(cp)){const u=e[i];if(typeof u!="number"||!Number.isFinite(u))continue;const c=ql(lv(i,u)),s=r&&!Ee(a,l).length?{motionKeys:tn(a,l,[{time:ql(o),value:c}])}:ap(a,l,c,ql(o));a={...a,...s},l==="depth"&&!Ee(a,l).length&&(a.modelDepth=c)}const n={};for(const i of["motionKeys","posX","posY","scale","spatialDepth","modelDepth","modelRotation"])a[i]!==t[i]&&(n[i]=a[i]);return n}function UC(t,e){let o={...t};for(const r of Object.values(cp)){const a=Ee(o,r);a.some(n=>Math.abs(n.time-e)<1/60)&&(o={...o,motionKeys:tn(o,r,a.filter(n=>Math.abs(n.time-e)>=1/60))})}return{motionKeys:o.motionKeys??[]}}const YC=["easy-ease","ease-out","ease-in-out","expo-out","back-out","linear"],qC=["none","elastic","bounce"],uv=Object.freeze({ease:"easy-ease",in:.5,out:.4,settle:"none"}),Yh=t=>({...uv,...t||{}}),ZC=t=>{const e=Qt[Yh(t).ease];return Array.isArray(e)&&!(e[0]===0&&e[1]===0&&e[2]===1&&e[3]===1)?[...e]:void 0};function hv(t){const e=Qt[Yh(t).ease];return Array.isArray(e)?{in:+(1-e[2]).toFixed(2),out:+e[0].toFixed(2)}:{in:0,out:0}}const dv=Object.freeze(["hero","icon","broll","motion","text"]),JC=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"}}),im=300,fv=300,mv=/^[A-Za-z0-9_-]{1,40}$/;function gv(t){if(!Array.isArray(t)||t.length>im)throw Error(`At most ${im} 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(!mv.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(!dv.includes(o.kind))throw Error("Invalid pin kind");if(o.note!==void 0&&(typeof o.note!="string"||o.note.length>fv))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 yv(t,e){const o=e?.[t.from],r=e?.[t.to];return o&&r?{start:o.start,end:r.end}:null}const H1=(t,e)=>!t.some(o=>o.nodeId===e&&o.kind!=="audio"&&!o.reverse),X1=(t,e,o)=>t.nodeId!==e||t.kind==="audio"!==o||t.reverse;function sm(t,e,o){const r=H1(t,e);for(const a of t){if(X1(a,e,r))continue;const n=a.inPoint||0,i=n+rp(a);if(o>=n-1e-6&&o<i-1e-6)return+(a.start+Ba(a,o-n)).toFixed(3)}return null}function QC(t,e,o){const r=(o.start+o.end)/2,a=H1(t,e);for(const n of t){if(X1(n,e,a))continue;const i=n.inPoint||0,l=i+rp(n);if(r>=i-1e-6&&r<l-1e-6)return+(n.start+Ba(n,Math.max(o.start,i)-i)).toFixed(3)}return null}function tj(t,e,o){const r=yv(t,o);if(!r)return null;const a=sm(e,t.mediaId,r.start),n=sm(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 bv(t,e=.6){const o=[];let r=0;return(t||[]).forEach((a,n)=>{const i=t[n+1],l=/[.?!…]["'”)]?$/.test(String(a.word).trim()),u=i&&i.start-a.end>=e;(!i||l||u)&&(o.push({from:r,to:n}),r=n+1)}),o}const wv=/\d/,lm=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(" ")),kv=new Set("xin chào cảm ơn hello hi".split(" "));function ej(t,e,{existing:o=[],newId:r}={}){const a=new Set(o.flatMap(l=>Array.from({length:l.to-l.from+1},(u,c)=>l.from+c))),n=r||(()=>{let l=0;return()=>`p${Date.now().toString(36)}${(l++).toString(36)}`})(),i=[];for(const l of bv(t)){const u=Array.from({length:l.to-l.from+1},(g,v)=>l.from+v).filter(g=>!a.has(g)),c=u.find(g=>wv.test(t[g].word));if(c!==void 0){const g=Math.min(l.to,c+(t[c+1]&&/^(%|triệu|tỷ|nghìn|k|đ|đồng|usd|\$)/i.test(t[c+1].word)?1:0));i.push({id:n(),mediaId:e,from:c,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||lm.has(x)||kv.has(x)?0:Cg(v)+(g>l.from&&/^\p{Lu}/u.test(v)?3:0)+(g-l.from)/(l.to-l.from+1)},d=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=d!==void 0&&d>l.from&&u.includes(d-1)&&/^\p{Ll}/u.test(f(d))&&/^\p{Ll}/u.test(f(d-1))&&!lm.has(f(d-1).toLowerCase())?d-1:d;d!==void 0&&l.to-l.from>=3&&i.push({id:n(),mediaId:e,from:m,to:d,kind:"hero",status:"idea"})}return i}const cm=500,xv=60,Ic=Object.freeze(["#ffd23f","#ff5d73","#4fb3ff","#3ddc84","#b18cff","#ff9f43"]),pm=Object.freeze(["beats","bars","drops","hits"]),U1=(t,e)=>t.t-e.t||t.id.localeCompare(e.id),Y1=t=>typeof t=="string"?t.trim().slice(0,xv):void 0,q1=t=>{if(typeof t!="number"||!Number.isFinite(t)||t<0||t>Fn)throw Error(`Marker time must be 0–${Fn} s`);return ft(t)};let Mv=0;const vv=()=>`m${Date.now().toString(36)}${(Mv++).toString(36)}`;function $v(t,{t:e,label:o,color:r,id:a=vv()}={}){const n=q1(e),i=t.find(c=>Math.abs(c.t-n)<1e-6);if(i)return{markers:t,id:i.id,added:!1};if(t.length>=cm)throw Error(`Tối đa ${cm} marker`);if(r!==void 0&&!Ic.includes(r))throw Error("Màu marker không hợp lệ");const l=Y1(o),u={id:a,t:n,...l?{label:l}:{},...r?{color:r}:{}};return{markers:[...t,u].sort(U1),id:a,added:!0}}function Ev(t,e,{t:o,label:r,color:a}={}){const n=t.find(l=>l.id===e);if(!n)throw Error(`Không thấy marker ${e}`);if(a!=null&&!Ic.includes(a))throw Error("Màu marker không hợp lệ");const i={...n};if(o!==void 0&&(i.t=q1(o)),r!==void 0){const l=Y1(r);l?i.label=l:delete i.label}return a!==void 0&&(a?i.color=a:delete i.color),t.map(l=>l.id===e?i:l).sort(U1)}function Sv(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 Iv(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(d=>d.id===n.nodeId)?.beats;if(!Array.isArray(i?.beats)||!((i.confidence??0)>=lp))continue;const l=Number(n.playbackRate)||1,u=Number(n.inPoint)||0,c=u+n.duration*l,s=[["drop",i.drops],...o==="drops"?[]:[["bar",i.downbeats]],...o==="beats"?[["beat",i.beats]]:[],...o==="hits"?[["hit",i.hits]]:[]];for(const[d,f]of s)for(const m of Array.isArray(f)?f:[]){if(m<u-1e-6||m>=c-1e-6)continue;const g=ft(n.start+(m-u)/l),v=g.toFixed(3),x=a.get(v);(!x||r[d]>r[x.kind])&&a.set(v,{t:g,kind:d})}}return[...a.values()].sort((n,i)=>n.t-i.t)}function oj(t,e=[]){return[...new Set([...(t??[]).map(o=>o.t),...e.map(o=>o.t)])].sort((o,r)=>o-r)}function rj(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 Av(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 $o=t=>Object.freeze(t),Tn=Object.freeze({white:$o({vi:"Chớp trắng",en:"White flash",fx:[["exposure",[[0,1,"hold"],[1,.75,"ease-out"],[5,0]]]]}),"white-double":$o({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:$o({vi:"Bật sáng",en:"Exposure pop",fx:[["exposure",[[0,.55,"ease-out"],[6,0]]]]}),negative:$o({vi:"Âm bản 2 khung",en:"Negative (2 frames)",fx:[["invert",[[0,1,"hold"],[2,0]]]]}),"negative-double":$o({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":$o({vi:"Âm bản 1 khung",en:"Negative blink (1 frame)",fx:[["invert",[[0,1,"hold"],[1,0]]]]}),"luma-negative":$o({vi:"Âm bản giữ màu",en:"Hue-keeping negative",fx:[["luma-invert",[[0,1,"hold"],[3,0]]]]}),"flash-negative":$o({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:$o({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:$o({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:$o({vi:"Giật tách màu",en:"RGB hit",fx:[["rgb-split",[[0,1,"ease-out"],[6,0]]]]}),blur:$o({vi:"Nhoè giật",en:"Blur hit",fx:[["blur",[[0,.8,"ease-out"],[6,0]]]]}),threshold:$o({vi:"Đen trắng gắt 2 khung",en:"Hard black & white (2 frames)",fx:[["threshold",[[0,.5,"hold"],[2,0]]]]}),"threshold-blink":$o({vi:"Đen trắng gắt 1 khung",en:"Hard black & white blink (1 frame)",fx:[["threshold",[[0,.5,"hold"],[1,0]]]]}),"poster-bw":$o({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":$o({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":$o({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]]]]})}),Cv=Object.freeze(Object.keys(Tn)),Z1=30,um=32,hm=t=>(Math.max(...Tn[t].fx.map(([,e])=>e.at(-1)[0]))+1)/Z1;function dm(t,e=1){const o=Tn[t];if(!o)throw Error(`addFlash style: ${Cv.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(pc,r))throw Error(`Unknown effect ${r}`);return{type:r,amount:1,keys:a.map(([n,i,l])=>({time:+(n/Z1).toFixed(4),value:+Math.min(1,i*e).toFixed(3),...l?{ease:Qt[l]}:{}}))}})}const Be=(t,e)=>({id:Ya(t),rot:0,scale:[1,1],opacity:1,...e}),gr=t=>({type:"color",color:t}),Yn={type:"none"},qn=(t,e,o={})=>({color:t,width:e,cap:"round",join:"round",...o});function Ir(t){const e=[];for(const o of t)e.push({...o,id:Ya(e)});return{v:2,items:e}}const qh={callout:{vi:"Callout",en:"Callout",build:({color:t})=>Ir([Be([],{name:"Khung",type:"rect",params:{w:520,h:240,round:36},pos:[500,440],fill:gr(t),stroke:null}),Be([],{name:"Đuôi",type:"path",params:{pts:[[-40,-30],[40,-30],[-30,60]],closed:!0},pos:[420,590],fill:gr(t),stroke:null})])},"chat-bubble":{vi:"Bong bóng chat",en:"Chat bubble",build:({color:t})=>Ir([Be([],{name:"Bóng",type:"rect",params:{w:560,h:260,round:130},pos:[500,450],fill:gr(t),stroke:null}),Be([],{name:"Đuôi",type:"path",params:{pts:[[-20,-60],[60,-40,0,0,-20,40],[-70,60]],closed:!0},pos:[330,600],fill:gr(t),stroke:null})])},badge:{vi:"Huy hiệu",en:"Badge",build:({color:t,accent:e})=>Ir([Be([],{name:"Răng cưa",type:"star",params:{points:16,outer:260,inner:225,round:6},pos:[500,500],fill:gr(t),stroke:null}),Be([],{name:"Lõi",type:"ellipse",params:{w:380,h:380},pos:[500,500],fill:Yn,stroke:qn(e,10)})])},"lower-third":{vi:"Lower third",en:"Lower third",build:({color:t,accent:e})=>Ir([Be([],{name:"Vạch nhấn",type:"rect",params:{w:22,h:150,round:4},pos:[-60,790],fill:gr(e),stroke:null}),Be([],{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}),Be([],{name:"Dòng phụ",type:"rect",params:{w:420,h:56,round:6},pos:[170,895],fill:gr("#0d0f12"),stroke:null})])},"progress-bar":{vi:"Thanh tiến trình",en:"Progress bar",build:({color:t,duration:e})=>{const o=Ir([Be([],{name:"Rãnh",type:"rect",params:{w:800,h:44,round:22},pos:[500,500],fill:gr("#1f2622"),stroke:null}),Be([],{name:"Tiến trình",type:"rect",params:{w:800,h:44,round:22},pos:[500,500],fill:gr(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})=>Ir([Be([],{name:"Tia",type:"star",params:{points:18,outer:300,inner:170,round:0},pos:[500,500],fill:gr(t),stroke:null})])},"loading-ring":{vi:"Vòng loading",en:"Loading ring",build:({color:t,duration:e})=>{const o=Ir([Be([],{name:"Rãnh",type:"ellipse",params:{w:300,h:300},pos:[500,500],fill:Yn,stroke:qn("#1f2622",26)}),Be([],{name:"Vòng chạy",type:"ellipse",params:{w:300,h:300},pos:[500,500],fill:Yn,stroke:qn(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})=>Ir([Be([],{name:"Viền ngoài",type:"rect",params:{w:760,h:520,round:12},pos:[500,500],fill:Yn,stroke:qn(t,28,{join:"miter",cap:"butt"})}),Be([],{name:"Viền trong",type:"rect",params:{w:690,h:450,round:6},pos:[500,500],fill:Yn,stroke:qn(e,4,{join:"miter",cap:"butt"})})])},"arrow-curved":{vi:"Mũi tên cong",en:"Curved arrow",build:({color:t})=>Ir([Be([],{name:"Thân",type:"path",params:{pts:[[-280,160],[0,-120,-200,40,200,-40],[260,-40]],closed:!1},pos:[500,520],fill:Yn,stroke:qn(t,22)}),Be([],{name:"Đầu",type:"path",params:{pts:[[-60,-70],[0,0],[-80,40]],closed:!1},pos:[760,480],fill:Yn,stroke:qn(t,22)})])},"arrow-bold":{vi:"Mũi tên đậm",en:"Bold arrow",build:({color:t})=>Ir([Be([],{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:gr(t),stroke:null})])},"hand-underline":{vi:"Gạch chân vẽ tay",en:"Hand-drawn underline",build:({color:t,duration:e})=>{const o=Ir([Be([],{name:"Nét",type:"path",params:{pts:[[-380,10],[0,-6,-150,10,150,-14],[380,4]],closed:!1},pos:[500,620],fill:Yn,stroke:qn(t,18),ops:[{...Es("wiggle"),size:8,detail:24,speed:0,seed:3},{...Es("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})=>Ir([Be([],{name:"Nhãn",type:"path",params:{pts:[[-300,-120],[180,-120],[300,0],[180,120],[-300,120]],closed:!0},pos:[500,500],fill:gr(t),stroke:null,ops:[{...Es("round"),radius:24}]}),Be([],{name:"Lỗ",type:"ellipse",params:{w:48,h:48},pos:[740,500],fill:gr("#000000"),stroke:null,ops:[{...Es("merge"),mode:"subtract"}]})])}},nj=Object.keys(qh),jv={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 Tv(t,{color:e="#c6f432",accent:o="#2bd4c9",duration:r=5,en:a=!1}={}){const n=qh[t];if(!n)throw Error(`Unknown library shape "${t}"`);const i=n.build({color:e,accent:o,duration:r});if(a)for(const l of i.items)l.name=jv[l.name]??l.name;return Ue(i)}const J1={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"]},gl=Object.freeze({smooth:.5,brighten:.4,even:.3,eyes:!0}),Ov=new Set(Object.values(J1).flat().map(t=>`✨ ${t}`)),zv=t=>Ov.has(t?.name),Ea=t=>+t.toFixed(3),Gp=(t,e)=>{const o=Number(t);return Number.isFinite(o)?Math.max(0,Math.min(1,o)):e};function Pv(t={}){return{smooth:Gp(t.smooth,gl.smooth),brighten:Gp(t.brighten,gl.brighten),even:Gp(t.even,gl.even),eyes:t.eyes==null?gl.eyes:t.eyes===!0||t.eyes==="true"||Number(t.eyes)>0}}function Lv(t,e="vi"){const o=u=>`✨ ${J1[u][e==="en"?1:0]}`,{smooth:r,brighten:a,even:n,eyes:i}=t,l=[];return r>0&&l.push({name:o("smooth"),shape:"skin",fx:{type:"denoise",amount:Ea(Math.min(1,.45+.6*r)),size:Ea(Math.min(1,.45+.6*r))},blur:Ea(.1*r),contrast:Ea(1-.06*r)}),n>0&&l.push({name:o("even"),shape:"skin",saturation:Ea(1-.2*n)}),a>0&&l.push({name:o("brighten"),shape:"face",exposure:Ea(.05+.3*a),contrast:Ea(1-.06*a)}),i&&(r>0||a>0)&&l.push({name:o("eyes"),shape:"eyes",exposure:.08,contrast:1.1,sharpen:30}),l}const Qe=t=>Math.round(t*1e4)/1e4,Ha=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,Nv=t=>t*t*(3-2*t),Js=Object.freeze({flipKeys:16,auraColors:["#ffd23f","#7dff6a","#3ff2ff","#e85dff"],maxHits:8}),Fv=(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 Rv(t,{from:e=0,to:o=.6,turn:r=180,back:a=!1,W:n=1280,H:i=720}={}){const l=en(t),u={...t,...l};if(e=Math.max(0,Math.min(t.duration,e)),o=Math.max(e,Math.min(t.duration,o)),o-e<.15)throw Error("worldFlip needs at least 0.15 s");r=Ha(r,-720,720,180);const c=Js.flipKeys,s=Array.from({length:c+1},(E,S)=>Qe(e+(o-e)*S/c)),d=E=>a?r*Math.sin(Math.PI*E):r*Nv(E),f=E=>Zt(u,"rot",E),m=E=>Zt(u,"zoom",E),g=E=>Ee(u,E).filter(S=>S.time<e-1e-6||S.time>o+1e-6),v=s.map((E,S)=>({time:E,value:Qe(f(E)+d(S/c))})),x=s.map((E,S)=>{const k=Fv(d(S/c),n,i);return{time:E,value:Qe(m(E)*(k>1+1e-6?k*1.01:1))}});let $=tn(u,"rot",[...g("rot"),...v].sort((E,S)=>E.time-S.time));return $=tn({...u,motionKeys:$},"zoom",[...g("zoom"),...x].sort((E,S)=>E.time-S.time)),{...l,motionKeys:$,rotFit:"frame"}}function fm(t,e,o="rainbow",r=Js.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,cn);const a=Math.min(jg,Math.max(2,Math.round(t*3)+1)),n=Array.from({length:a},(l,u)=>({time:Qe(t*u/(a-1)),value:Qe(.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,cn)}function Dv(t,e,{start:o,duration:r,color:a=Js.auraColors[0],silhouette:n=!1,style:i="rainbow"}={}){const l=Math.max(t.start,o??t.start),u=Math.min(t.start+t.duration,l+(r??t.start+t.duration-l));if(!(u-l>.2))throw Error("personAura must lie inside the person clip");const c=i==="fresnel",s=Qe(u-l),d=Qe((t.inPoint||0)+(l-t.start)*(t.playbackRate||1)),f=t.scale??1,m=Q1(t,l,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},(A,I)=>Qe(s*I/(g-1))),$=c?1.012:1.035,E=c?.008:.025;let S=tn(v,"zoom",x.map((A,I)=>({time:A,value:Qe(Zt(v,"zoom",A)*($+E*Math.sin(I*1.7)))})));S=tn({...v,motionKeys:S},"opacity",x.map((A,I)=>({time:A,value:I===0||I===g-1?0:c?.96:.92})));const k=Gn(t,e(),{start:Qe(l),duration:s,inPoint:d,label:`${t.label||"Video"} · ${c?"viền nội lực":"hào quang"}`,...m,motionV:2,motionKeys:S,edge:Su({color:a,width:c?.018:.03,glow:2,amount:1}),effects:fm(s,!1,i,a)});delete k.impacts;const y=Gn(t,e(),{start:Qe(l),duration:s,inPoint:d,label:`${t.label||"Video"} · ${n?"bóng màu":"người nét"}`,...m,...n?{effects:fm(s,!0,i,a).filter(A=>A.type!=="light-burst")}:{}});return n||delete y.effects,m.motionKeys||delete y.motionKeys,delete y.impacts,delete y.edge,[k,y]}function Q1(t,e,o){if(!t.motionKeys?.length)return{motionKeys:void 0};const r=Bl(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 ty=(t,e,{at:o,u:r,v:a,size:n=1,duration:i,label:l,params:u={}})=>{const c=ma.find(s=>s.id===e);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Qe(Math.max(0,o)),duration:Qe(i??c.duration),label:l,motionV:2,posX:Qe(r-.5),posY:Qe(a-.5),scale:Qe(Ha(n,.2,3,1)),motion:ko({code:`@preset:${e}`,params:{...c.params,...u},preset:e})}},Bv=({id:t,at:e,u:o,v:r,angle:a=200,length:n=1,size:i=1,duration:l=1.6,color:u})=>ty(t,"vfx-breath-mist",{at:e,u:o,v:r,size:i,duration:l,label:"Hơi thở",params:{angle:Ha(a,-360,360,200),length:Ha(n,.2,3,1),seed:Math.round(e*1e3)%997+1,...u?{color:u}:{}}}),_v=({id:t,at:e,u:o,v:r,size:a=1,color:n})=>({...ty(t,"vfx-light-pillar",{at:e,u:.5,v:.5,size:1,label:"Cột sáng",params:{x:Qe(Ha(o,0,1,.5)),y:Qe(Ha(r,0,1,.5)),size:Qe(Ha(a,.2,3,1)),seed:Math.round(e*1e3)%997+1,...n?{color:n}:{}}})});function Gv(t){const e=(Array.isArray(t.hits)?t.hits:Number.isFinite(t.at)?[t.at]:[]).filter(Number.isFinite).slice(0,Js.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 Kv(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 l=Qe(a+n);l>=0&&l<=t.duration&&(!o.length||l-o.at(-1).time>=1/60)&&o.push({time:l,value:i})}}return o.slice(0,jg)}const fa=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}),lh="\\d+(?:[.,]\\d+)?",Vv="(?:\\d{1,2}:)?\\d{1,2}:\\d{2}(?:[.,]\\d+)?",mm=`(?:${Vv}|${lh})`,Ac="\\s*(?:s|sec|secs|giây|seconds?)\\b",Wv=new RegExp(`(${mm})(?:${Ac})?\\s*(?:-|–|—|→|->|~|đến|to)\\s*(${mm})(?:${Ac})?`,"iu"),Hv=new RegExp(`[([]\\s*(${lh})${Ac}\\s*[)\\]]|^\\s*(${lh})${Ac}\\s*[:\\-–—]`,"iu"),Kp=/^\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,yl=/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,Vp=/giây|giay|thời gian|thoi gian|time|tc\b|timecode|\bs\b|duration|độ dài|do dai/iu;function gm(t){const e=String(t).trim().replace(",",".");return e.includes(":")?e.split(":").reduce((o,r)=>o*60+Number(r),0):Number(e)}const bl=t=>String(t).replace(/\*\*|__|`/g,"").replace(/^[\s|"“”'‘’«»>*•\-–—]+|[\s"“”'‘’«»]+$/g,"").replace(/\s{2,}/g," ").trim();function Wp(t){const e=Wv.exec(t);if(e){const r=gm(e[1]),a=gm(e[2]);if(Number.isFinite(r)&&a>r)return{time:{start:r,end:a},rest:t.replace(e[0]," ")}}const o=Hv.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 Xv=t=>t.includes(" ")?t.split(" "):t.trim().startsWith("|")?t.trim().replace(/^\||\|$/g,"").split("|"):null,wl=t=>/\p{L}{2}/u.test(t);function ym(t){const o=String(t??"").slice(0,fa.maxChars).replace(/\r\n?/g,`
98
+ `).split(`
99
+ `),r=o.map(Xv);let a=-1,n=-1;const i=r.filter(c=>c&&c.length>1&&!c.every(s=>/^\s*:?-{2,}:?\s*$/.test(s)));if(i.length){const c=i[0],s=i.length>=2&&c.every(f=>!/\d/.test(f)||Vp.test(f))&&c.some(f=>yl.test(f)||Vp.test(f));s&&(a=c.findIndex(f=>yl.test(f)),n=c.findIndex(f=>Vp.test(f)&&!yl.test(f)));const d=s?i.slice(1):i;if(a<0){const f=Math.max(...d.map(g=>g.length)),m=g=>d.reduce((v,x)=>v+(wl(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 l=[];let u=null;for(const[c,s]of o.entries()){const d=r[c];if(d&&d.length>1){if(d.every(y=>/^\s*:?-{2,}:?\s*$/.test(y)))continue;const x=bl(d[a]??"");if(!x||yl.test(x)&&x.split(/\s+/).length<=3&&i[0]===d)continue;let $=null;for(const[y,A]of d.entries()){if(y===a)continue;const I=Wp(A).time;if(I){$=I;break}}!$&&n>=0&&/^\s*\d+(?:[.,]\d+)?\s*$/.test(d[n]??"")&&($={duration:Number(d[n].replace(",","."))});const{time:E,rest:S}=Wp(x),k=bl(S.replace(Kp,""));wl(k)&&l.push({text:k,...E??$??{}});continue}if(!s.trim()||/^\s*(#{1,6}\s|={3,}|-{3,}\s*$)/.test(s)&&!wl(s.replace(/^#+/,"").trim())||/^\s*#{1,6}\s/.test(s))continue;const{time:f,rest:m}=Wp(s);if(!f&&/\p{Lu}/u.test(s)&&s===s.toUpperCase()&&s.trim().split(/\s+/).length<=4)continue;let g=bl(m.replace(Kp,"").replace(Kp,""));const v=/(?:lời|loi|thoại|thoai|vo|voice ?over)\s*[::]\s*(.+)$/iu.exec(m);if(v&&(g=bl(v[1])),!wl(g)){f&&(u=f);continue}if(l.push({text:g,...f??u??{}}),u=null,l.length>=fa.maxLines)break}return l.slice(0,fa.maxLines).map(c=>{const s={text:c.text.slice(0,600)};return Number.isFinite(c.start)&&Number.isFinite(c.end)&&c.end>c.start?(s.start=+c.start.toFixed(3),s.end=+c.end.toFixed(3),s.duration=+(c.end-c.start).toFixed(3)):c.duration>0&&(s.duration=+c.duration.toFixed(3)),s})}const Uv=t=>String(t).split(/\s+/).filter(e=>!qs(e)).map(as).filter(Boolean);function Yv(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 qv=2,Zv=1,Jv=-1,Qv=-1,t$=-.5;function bm(t,e,o,r){const a=t.length,n=r-o;if(!a||n<=0)return null;let i=new Float64Array(n+1),l=new Float64Array(n+1);const u=new Uint8Array((a+1)*(n+1)),c=new Uint8Array((a+1)*(n+1));let s=0,d=0,f=0;for(let $=1;$<=a;$++){l[0]=0;for(let E=1;E<=n;E++){const S=Yv(t[$-1],e[o+E-1]),k=i[E-1]+(S===2?qv:S===1?Zv:Jv),y=i[E]+Qv,A=l[E-1]+t$;let I=0,z=0;k>I&&(I=k,z=1),y>I&&(I=y,z=2),A>I&&(I=A,z=3),l[E]=I,u[$*(n+1)+E]=z,c[$*(n+1)+E]=z===1?S:0,I>s&&(s=I,d=$,f=E)}[i,l]=[l,i]}if(s<=0)return null;let m=d,g=f,v=0,x=f;for(;m>0&&g>0;){const $=u[m*(n+1)+g];if($===0)break;$===1?(v+=c[m*(n+1)+g]/2,x=g,m--,g--):$===2?m--:g--}return{score:s,a:o+x-1,b:o+f-1,matched:v,coverage:v/a}}function e$(t,e,o=e.map(r=>as(r.word))){const r=Uv(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)),l=[],u=s=>{if(!s||s.coverage<fa.minCoverage)return;const d=l.find(f=>s.a<=f.b&&s.b>=f.a);d?s.score>d.score&&Object.assign(d,s):l.push(s)},c=s=>l.some(d=>s>d.a&&s<=d.b);for(let s=0;s<o.length;s++)n.has(o[s])&&!c(s)&&u(bm(r,o,s,Math.min(o.length,s+a))),i.has(o[s])&&!c(s)&&u(bm(r,o,Math.max(0,s-a+1),s+1));return l.sort((s,d)=>s.a-d.a)}function o$(t,{maxPause:e=fa.maxPause}={}){const o=(Array.isArray(t)?t:[]).filter(l=>Number.isFinite(l?.start)&&Number.isFinite(l?.end)&&!qs(l.word)).sort((l,u)=>l.start-u.start);if(o.length<12)return null;let r=0,a=o[0].start;const n=[];for(let l=1;l<=o.length;l++){const u=l<o.length?o[l].start-o[l-1].end:1/0;u>e&&(r+=o[l-1].end-a,l<o.length&&(u<3&&n.push(u),a=o[l].start))}if(!(r>0))return null;n.sort((l,u)=>l-u);const i=n.length?n[n.length>>1]:fa.pause;return{wordsPerSecond:+(o.length/r).toFixed(3),pause:+Math.min(.8,Math.max(.12,i)).toFixed(3)}}const kl=(t,e,o)=>Math.min(o,Math.max(e,t)),nr=t=>+t.toFixed(3);function r$(t,e,o={}){const r={...fa,...o.maxPause?{maxPause:kl(o.maxPause,.2,3)}:{}},a=o.pace??null;a?.pause&&(r.pause=kl(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,l=new Set(o.skip??[]),u=(Array.isArray(e)?e:[]).filter($=>Number.isFinite($?.start)&&Number.isFinite($?.end)&&$.end>=$.start&&!qs($.word)).sort(($,E)=>$.start-E.start),c=u.map($=>as($.word)),s=(Array.isArray(o.silences)?o.silences:[]).filter($=>$&&$.kind!=="filler"&&Number.isFinite($.start)&&$.end>$.start).sort(($,E)=>$.start-E.start),d=$=>s.find(E=>E.start>=$-.05&&E.start<=$+r.snap),f=$=>[...s].reverse().find(E=>E.end<=$+.05&&E.end>=$-r.snap),m=($,E)=>s.find(S=>S.start<E&&S.end>$),g=[],v=[];for(const[$,E]of t.entries()){const S={index:$,text:E.text,...E.duration?{target:E.duration}:{}};if(l.has($)){v.push({...S,status:"skipped"});continue}const k=e$(E,u,c);if(!k.length){v.push({...S,status:"missing",takes:0});continue}const y=k.filter(D=>!g.some(U=>D.a<=U.b&&D.b>=U.a)),A=y.length?y:k,I=Math.max(...A.map(D=>D.coverage)),z=A.filter(D=>D.coverage>=I-r.tieCoverage).at(-1);g.push(z);const j=u.slice(z.a,z.b+1),P=u[z.a-1],N=u[z.b+1],F=(D,U)=>u.filter((ht,yt)=>(yt<z.a||yt>z.b)&&ht.end>D+.02&&ht.start<U-.02).length;let K=f(j[0].start),_=d(j.at(-1).end);K&&F(K.end,j[0].start)>0&&(K=null),_&&F(j.at(-1).end,_.start)>2&&(_=null);const J=K?Math.max(K.start,K.end-Math.min(r.lead,(K.end-K.start)/2)):Math.max(j[0].start-r.lead,P?P.end+.02:0,0),X=_?Math.min(_.end,_.start+Math.min(r.tail,(_.end-_.start)/2)):Math.min(j.at(-1).end+r.tail,N?N.start-.02:1/0),rt=[];let ot=J,G=0,tt=0;for(let D=1;D<j.length;D++){const U=j[D].start-j[D-1].end;if(n&&U>r.maxPause){const ht=m(j[D-1].end,j[D].start),yt=ht?Math.max(ht.start,j[D-1].end):j[D-1].end,Mt=ht?Math.min(ht.end,j[D].start):j[D].start;if(Mt-yt<=r.pause)continue;const p=r.pause/2;rt.push({start:nr(ot),end:nr(yt+p)}),ot=Mt-p,G++,tt+=Mt-yt-r.pause}}rt.push({start:nr(ot),end:nr(X)});const Q=rt.reduce((D,U)=>D+U.end-U.start,0);let it=1;if(i&&E.duration>0)it=kl(Q/E.duration,r.minRate,r.maxRate);else if(i&&a?.wordsPerSecond){const D=rt.reduce((U,ht)=>U+ht.end-ht.start,0)-(r.lead+r.tail);D>.5&&(it=kl(a.wordsPerSecond/(j.length/D),r.minRate,r.maxRate))}Math.abs(it-1)<r.rateStep&&(it=1),it=+it.toFixed(2),v.push({...S,status:"ok",takes:k.length,take:k.indexOf(z),coverage:+z.coverage.toFixed(2),source:{start:nr(J),end:nr(X)},heard:j.map(D=>D.word).join(" "),pieces:rt,pausesCut:G,pauseSaved:nr(tt),rate:it,natural:nr(Q),final:nr(Q/it)})}const x=v.filter($=>$.status==="ok");for(const $ of x)for(const E of x){if($===E||!(E.source.start<$.source.end&&E.source.start>=$.source.start))continue;const S=E.pieces[0];$.source.end>=S.end-.05||(S.start=E.source.start=nr($.source.end),E.natural=nr(E.pieces.reduce((k,y)=>k+y.end-y.start,0)),E.final=nr(E.natural/E.rate))}return{lines:v,found:x.length,missing:v.filter($=>$.status==="missing").length,length:nr(x.reduce(($,E)=>$+E.final,0)),pause:r.pause,maxPause:r.maxPause,...a?{pace:a}:{}}}const n$=t=>t.label||t.id;function a$(t,e,o,r={}){const a=r.tracks??{},n=r.makeId??(()=>Math.random().toString(36).slice(2,10)),i=r.maxClips??Fs,l=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(Zr(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 c=o.lines.filter(y=>y.status==="ok");if(!c.length)throw Error("No script line was found in the clip");const s=u.start+u.duration,d=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(d.map(y=>y.id)),m=t.filter(y=>y.id!==u.id&&!f.has(y.id)&&y.track!==u.track&&!l(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(n$).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=c.flatMap(y=>y.pieces.map(A=>({...A,rate:y.rate,line:y.index}))),v=(g.length-1)*(1+d.length);if(t.length+v>i)throw Error(`Too many clips: the script edit needs ${g.length} pieces (limit ${i})`);const x=(y,A)=>{let I=u.start;return g.map((z,j)=>{const P=ft((z.end-z.start)/z.rate),N={...y,id:j===0?A:n(),start:ft(I),inPoint:nr(z.start),duration:P,playbackRate:z.rate};return N.playbackRate===1&&delete N.playbackRate,I+=P,N})},$=x(u,u.id),E=$.reduce((y,A)=>y+A.duration,0),S=ft(E-u.duration);return{clips:t.flatMap(y=>y.id===u.id?$:f.has(y.id)?x(y,y.id).map((A,I)=>({...A,track:y.track,start:$[I].start,duration:$[I].duration})):y.start>=s-1/60&&!(l(y)&&y.track!==u.track)?[{...y,start:ft(Math.max(0,y.start+S))}]:[y]),pieces:g.length,length:ft(E),delta:S}}function i$(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 ch=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})}),s$=new Set(["ai-scan-frame","aiw-end-subtitle","aiw-gen-checklist","aiw-pause-menu","aiw-race-hud","aiw-race-title","aiw-scan","aiw-select","aiw-style-pick","aiw-v-end-subtitle","aiw-v-gen-checklist","aiw-v-pause-menu","aiw-v-race-hud","aiw-v-race-title","aiw-v-scan","aiw-v-select","aiw-v-style-pick","bridge-portal","cine-crown-rain","cine-door","cine-eye","cine-flame","cine-heart","cine-hourglass","cine-key","cine-lighthouse","cine-moon","cine-night-house","cine-planet","cine-rocket","cine-sword","cine-tree","clipoox-bar-lower","clipoox-card-cube","clipoox-card-row","clipoox-claim-block","clipoox-coin-rain","clipoox-connect","clipoox-core-orbit","clipoox-count-ruler","clipoox-counter-dots","clipoox-discount","clipoox-dot-grid-stat","clipoox-end-card","clipoox-end-credit","clipoox-fine-print","clipoox-gen-cards","clipoox-giant-word","clipoox-glass-thanks","clipoox-glitch-slam","clipoox-holo-button","clipoox-holo-mesh","clipoox-line-stat","clipoox-notch-frame","clipoox-number-rush","clipoox-phone-build","clipoox-pill-lower","clipoox-pixel-face","clipoox-price-dial","clipoox-product-pick","clipoox-prompt-box","clipoox-ray-logo","clipoox-skill-header","clipoox-stat-dome","clipoox-sticker-stack","clipoox-trace-label","clipoox-ui-stack","clipoox-url-analyze","clipoox-v-card-cube","clipoox-v-core-orbit","clipoox-v-cta","clipoox-v-end-credit","clipoox-v-glitch-slam","clipoox-v-holo-mesh","clipoox-v-hook","clipoox-v-marquee","clipoox-v-phone","clipoox-v-pixel-face","clipoox-v-plans","clipoox-v-prompt-box","clipoox-v-ray-logo","clipoox-v-split","clipoox-v-stack","clipoox-v-stat","clipoox-v-steps","clipoox-v-top-banner","clipoox-v-window-burst","clipoox-window-burst","course-brand-bug","course-callout","course-chapter-card","course-cover-insert","course-framework-stack","course-journey-line","course-map-pins","course-photo-pop","course-pip-frame","course-screen-frame","creator-3d-glyph","creator-behind-title","creator-chapter-bar","creator-coin-flip","creator-news-cards","creator-phone-duo","creator-quote-end","cs-card-fan","cs-doc-stamp","cs-file-window","cs-flip-board","cs-generating","cs-graph-editor","cs-pen-logo","cs-phone-trio","cs-prompt","cs-render-card","cs-route-map","cs-timeline-fix","cs-title-curve","exp-checklist-x","exp-comment-thread","exp-cta-button","exp-expert-stamp","exp-fame-meter","exp-id-badge","exp-kicker-title","exp-mood-gauge","exp-notifications","exp-price-up","exp-profile-card","exp-question-banner","exp-toggle-on","exp-triple-meters","fh-call-panel","fh-data-ring","fh-keypad","fh-music-player","fh-profile-card","fh-radar-map","fh-target-lock","fh-text-column","fh-translate","fh-weather","fluid-melt-word","fr-chapter","fr-comment-cta","fr-headline","fr-paper","fr-recap","fr-v-chapter","fr-v-comment-cta","fr-v-headline","fr-v-paper","fr-v-recap","fr-v-window","fr-window","glass-balance","glass-candles","glass-coin-bars","glass-line-target","glass-orb-rise","glass-step-chart","hist-depth-words","hist-year-wall","home-money-rain","home-news-stack","home-sticky-cta","illus-callout","illus-steps","illus-timeline","illus-versus","join-type-wall","kin-beat","kin-ribbon-nodes","lr-chrome-logo","lr-name-spark","lumen-neon-word","mono-ribbon-wipe","mono-spotlight-panels","morph-arrow-ring","morph-diamond-frame","morph-gradient-card","morph-light-pole","morph-light-thread","morph-loading-dots","morph-logo-wings","morph-path-tag","morph-pill-band","morph-sparkle-glow","morph-sun-flood","mx-crt-screen","mx-data-tunnel","pod-icon-burst","promo-aurora-card","promo-card-pill","promo-cta-button","promo-dome-horizon","promo-feature-cards","promo-flare-card","promo-glass-orbit","promo-icon-cloud","promo-logo-spark","promo-prompt-bar","pulse-end-title","rebound-atom-arches","rebound-brick-tower","rebound-chevron-field","rebound-dots-merge","rebound-frame-in-frame","rebound-gradient-flash","rebound-gradient-tile","rebound-neon-word","rebound-piston-launch","rebound-radial-web","rebound-ramp-shot","rebound-skyline-hop","rebound-tube-slide","rv-packshot-title","rv-product-callout","sc-card-label","sc-named-cursor","sc-scan-boxes","studio-ai-command","studio-asset-wall","studio-before-after","studio-brand-kit","studio-click-callout","studio-drag-asset","studio-endcard","studio-export","studio-feature-grid","studio-hero-tilt","studio-keyframe-curve","studio-monitor-play","studio-multi-format","studio-panels-explode","studio-sales-growth","studio-sfx-drop","studio-team-collab","studio-template-flip","studio-time-saved","studio-timeline-build","tl-4k-split","tl-end-card","tl-feature-panel","tl-player","tl-title-lockup","tl-v-4k-split","tl-v-end-card","tl-v-feature-panel","tl-v-player","tl-v-title-lockup","travel-city-poster","travel-name-wall"]);let l$=null;const c$=()=>l$??=new Function("return "+Tg)(),Hp=new Map;function p$(t){if(Hp.has(t))return Hp.get(t);const e=ma.find(r=>r.id===t&&!r.kind);let o=null;if(e)try{o=new Function("M",'"use strict";'+e.code+`
100
+ ;return render`)(c$())}catch{o=null}return Hp.set(t,o),o}const ph=t=>ma.find(e=>e.id===t&&!e.kind)??null,xl=(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]],_r=(t,e,o)=>[t[0]*e+t[2]*o+t[4],t[1]*e+t[3]*o+t[5]],wm=t=>{const e=/(\d+(?:\.\d+)?)px/.exec(String(t||""));return e?+e[1]:10},u$=t=>typeof t=="string"?t:t&&t.stops?.length?t.stops[Math.floor(t.stops.length/2)]:null;function h$(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])),l=(x,$)=>{const[E,S]=_r(r.m,x,$);n.push({t:"pt",x:E,y:S})},u=()=>{const x={stops:[],addColorStop($,E){x.stops.push(E)}};return x},c=x=>{let $=1/0,E=1/0,S=-1/0,k=-1/0;for(const[y,A]of x)$=Math.min($,y),E=Math.min(E,A),S=Math.max(S,y),k=Math.max(k,A);return{x:$,y:E,w:S-$,h:k-E}},s=x=>{const $=E=>x.reduce((S,k)=>E(k)>E(S)?k:S);return[$(E=>-(E[0]+E[1])),$(E=>E[0]-E[1]),$(E=>E[0]+E[1]),$(E=>E[1]-E[0])]},d=()=>{const x=[],$=[],E=[];let S=0,k=[],y=0,A=!1,I=0,z=!1,j=null;for(const _ of n)_.t==="pt"?(x.push([_.x,_.y]),$.push([_.x,_.y])):_.t==="move"?(I++,x.push([_.x,_.y]),$.push([_.x,_.y])):_.t==="rect"?(y++,j=_.pts,x.push(..._.pts)):_.t==="arc"?(S++,A||=_.full,x.push([_.cx-_.r,_.cy-_.r],[_.cx+_.r,_.cy+_.r])):_.t==="arcTo"?(k.push(_.r),E.push([_.x,_.y]),x.push([_.x,_.y])):_.t==="close"&&(z=!0);if(!x.length)return null;const P=c(x);let N="path",F=0,K=null;if(y===1&&!S&&!k.length&&I<=1)N="rect",K=s(j);else if(k.length>=4&&I<=1&&!S)N="rrect",F=Math.min(...k),K=s(E.slice(0,4));else if(S===1&&A&&!k.length&&!y&&x.length<=4)N="circle",F=P.w/2;else if(!S&&!k.length&&!y&&I===1&&(z||$.length>=4)){const _=$.length;if(_===4)N="quad",K=s($);else if(_>=8&&_%4===0){const J=_/4,X=[];let rt=0;for(let ot=0;ot<4;ot++){const G=$.slice(ot*J,ot*J+J),tt=G[0],Q=G[J-1],it=[(tt[0]+Q[0])/2,(tt[1]+Q[1])/2];if(J>=4){const D=[G[1][0]+G[J-2][0],G[1][1]+G[J-2][1]],U=[(D[0]-tt[0]-Q[0])/.366,(D[1]-tt[1]-Q[1])/.366];X.push([it[0]+U[0]/2,it[1]+U[1]/2])}else X.push(it);rt+=Math.hypot(tt[0]-Q[0],tt[1]-Q[1])/Math.SQRT2}N="rrect",F=rt/4,K=s(X)}}return{...P,kind:N,r:F,...K?{quad:K}:{}}},f=(x,$,E={})=>{if(!$||!($.w>0||$.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({...$,op:x,color:u$(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,...E})},m=(x,$,E,S)=>{if($=String($??""),!$.trim())return;const k=wm(r.font),y=$.length*k*.56,A=r.textAlign,I=r.textBaseline,z=A==="center"?E-y/2:A==="right"||A==="end"?E-y:E,j=I==="top"||I==="hanging"?S:I==="middle"?S-k/2:I==="bottom"||I==="ideographic"?S-k:S-k*.8,P=[[z,j],[z+y,j],[z,j+k],[z+y,j+k]].map(([N,F])=>_r(r.m,N,F));f(x,{...c(P),kind:"text",r:0},{text:$,size:k*i()})},g={save(){a.push({...r,m:[...r.m]})},restore(){a.length&&(r=a.pop())},translate(x,$){r.m=xl(r.m,[1,0,0,1,x,$])},scale(x,$){r.m=xl(r.m,[x,0,0,$,0,0])},rotate(x){const $=Math.cos(x),E=Math.sin(x);r.m=xl(r.m,[$,E,-E,$,0,0])},transform(x,$,E,S,k,y){r.m=xl(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,$){const[E,S]=_r(r.m,x,$);n.push({t:"move",x:E,y:S})},lineTo(x,$){l(x,$)},quadraticCurveTo(x,$,E,S){l(x,$),l(E,S)},bezierCurveTo(x,$,E,S,k,y){l(x,$),l(E,S),l(k,y)},arcTo(x,$,E,S,k){const[y,A]=_r(r.m,x,$);n.push({t:"arcTo",x:y,y:A,r:k*i()}),l(E,S)},arc(x,$,E,S,k,y){const[A,I]=_r(r.m,x,$);n.push({t:"arc",cx:A,cy:I,r:Math.abs(E)*i(),full:Math.abs((k??0)-(S??0))>=Math.PI*2-.001||!!y&&!1})},ellipse(x,$,E,S){const[k,y]=_r(r.m,x,$);n.push({t:"arc",cx:k,cy:y,r:Math.max(E,S)*i(),full:!1})},rect(x,$,E,S){n.push({t:"rect",pts:[[x,$],[x+E,$],[x,$+S],[x+E,$+S]].map(([k,y])=>_r(r.m,k,y))})},roundRect(x,$,E,S,k){const y=Array.isArray(k)?k[0]:k,A=typeof y=="object"?y.x:y||0,I=[[x,$],[x+E,$],[x,$+S],[x+E,$+S]].map(([z,j])=>_r(r.m,z,j));if(n.push({t:"rect",pts:I}),A>0){n.pop(),n.push({t:"move",x:I[0][0],y:I[0][1]});for(const z of I)n.push({t:"arcTo",x:z[0],y:z[1],r:A*i()})}},fill(){f("fill",d())},stroke(){f("stroke",d())},clip(){},fillRect(x,$,E,S){const k=[[x,$],[x+E,$],[x,$+S],[x+E,$+S]].map(([y,A])=>_r(r.m,y,A));f("fill",{...c(k),kind:"rect",r:0})},strokeRect(x,$,E,S){const k=[[x,$],[x+E,$],[x,$+S],[x+E,$+S]].map(([y,A])=>_r(r.m,y,A));f("stroke",{...c(k),kind:"rect",r:0})},clearRect(){},fillText(x,$,E){m("fill",x,$,E)},strokeText(x,$,E){m("stroke",x,$,E)},measureText(x){const $=wm(r.font);return{width:String(x).length*$*.56,actualBoundingBoxAscent:$*.8,actualBoundingBoxDescent:$*.2}},drawImage(x,...$){const[E,S,k,y]=$.length>=8?$.slice(4):$.length>=4?$:[$[0],$[1],x?.width||0,x?.height||0],A=[[E,S],[E+k,S],[E,S+y],[E+k,S+y]].map(([I,z])=>_r(r.m,I,z));f("fill",{...c(A),kind:"image",r:0})},createLinearGradient:u,createRadialGradient:u,createConicGradient:u,createPattern:()=>({stops:[]}),getImageData:(x,$,E,S)=>({data:new Uint8ClampedArray(Math.max(4,(E|0)*(S|0)*4)),width:E,height:S}),putImageData(){},createImageData:(x,$)=>({data:new Uint8ClampedArray(Math.max(4,(x|0)*($|0)*4)),width:x,height:$}),setLineDash(){},getLineDash:()=>[],isPointInPath:()=>!1};return new Proxy({},{get:(x,$)=>$==="canvas"?{width:t,height:e}:$==="draws"?o:$ in g?g[$]:$ in r?r[$]:void 0,set:(x,$,E)=>($!=="m"&&(r[$]=E),!0)})}function d$(t,e,{W:o=1280,H:r=720,params:a={},duration:n}={}){const i=p$(t),l=ph(t);if(!i||!l)return[];const u=h$(o,r),c=n??l.duration;try{i(u,e,Object.freeze({width:o,height:r,duration:c,fps:30,progress:c?e/c:0,params:Object.freeze({...l.params,...a}),fonts:{}}))}catch{return u.draws.slice()}return u.draws.slice()}const Ci=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},f$=t=>{if(!t)return null;const e=/^#([0-9a-f]{6})([0-9a-f]{2})$/i.exec(t);if(e)return[Ci("#"+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=Ci(t);return r?[r,1]:null},km=[14,16,19],xm=(t,e,o)=>t.map((r,a)=>r+(e[a]-r)*o),ms=t=>{if(!t)return 0;const e=Math.max(...t),o=Math.min(...t);return e?(e-o)/e:0},Ml=t=>t?(.2126*t[0]+.7152*t[1]+.0722*t[2])/255:0,m$=(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)},gs=t=>t?"#"+t.map(e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")).join(""):null;function g$(t,{W:e=1280,H:o=720,accent:r}={}){const a=e*o,n=Ci(r),i=[];for(const c of t){if(c.kind==="text"||c.kind==="image"||c.kind==="path")continue;const s=c.w*c.h;if(s>a*.85||c.w<6||c.h<6||s<a*8e-4||Math.max(0,Math.min(e,c.x+c.w)-Math.max(0,c.x))*Math.max(0,Math.min(o,c.y+c.h)-Math.max(0,c.y))/s<.7||c.w>e*.92&&c.op==="fill"&&!c.glow||c.alpha<.3||c.gradient&&c.kind==="circle"&&c.op==="fill"&&c.alpha<.8)continue;const f=i.find(x=>m$(x,c)>.88),m=f$(c.color),g=m?m[0]:null,v=m?m[1]*c.alpha:0;if(f){c.op==="fill"&&g&&(f.fillRgb=xm(f.fillRgb??km,g,v)),c.op==="stroke"&&g&&(f.borderRgb=g),c.glow&&(f.glow=c.glow),f.z=Math.max(f.z,c.z);continue}i.push({x:c.x,y:c.y,w:c.w,h:c.h,kind:c.kind,r:c.r,quad:c.quad,fillRgb:c.op==="fill"&&g?xm(km,g,v):null,borderRgb:c.op==="stroke"?g:null,glow:c.glow,z:c.z,alpha:c.alpha})}const l=[];for(const c of i){const s=c.w*c.h/a,d=Math.min(c.w,c.h),f=c.w/c.h;let m;if(c.kind==="circle"||c.kind==="rrect"&&c.r>=d*.45&&f>.8&&f<1.25?m="circle":c.kind==="rrect"&&c.r>=d*.38&&f>=1.6?m="pill":s<=.03&&f>=1.4&&f<=5&&(ms(c.fillRgb)>.3||Ml(c.fillRgb)>.55)?m="button":s<.008?m="chip":s<.42?m="card":m="panel",m==="chip"&&!c.borderRgb&&!c.glow&&ms(c.fillRgb)<.25)continue;const g=c.borderRgb??c.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(Ml(c.fillRgb)>.55?.7:ms(c.fillRgb)*Ml(c.fillRgb)*1.6,c.borderRgb?.8:0,c.glow?1:0)<.12)continue;const E=x+.7*Math.max(v,ms(g)*Ml(g))+(c.glow?.45:0)+(c.borderRgb?.25:0)+(m==="pill"||m==="button"?.35:m==="card"?.2:m==="circle"?.15:0)+.15*(c.z/Math.max(1,t.length));l.push({role:m,x:c.x,y:c.y,w:c.w,h:c.h,r:Math.min(c.r||0,d/2),...c.quad?{quad:c.quad.map(S=>S.map(k=>+k.toFixed(1)))}:{},fill:gs(c.fillRgb),border:gs(c.borderRgb),glow:c.glow?gs(Ci(c.glow))??null:null,score:+E.toFixed(3)})}const u=t.filter(c=>c.kind==="text"&&c.alpha>.5&&c.size>=o*.035);for(const c of u){const s=Ci(c.color),d=l.find(f=>f.role==="headline"&&Math.abs(f.y-c.y)<c.size*.6&&Math.abs(f.size-c.size)<2);if(d){const f=Math.min(d.x,c.x),m=Math.max(d.x+d.w,c.x+c.w);d.x=f,d.w=m-f,d.text+=" "+c.text;continue}l.push({role:"headline",x:c.x,y:c.y,w:c.w,h:c.h,r:0,fill:gs(s),border:null,glow:c.glow?gs(Ci(c.glow)):null,text:c.text,size:c.size,score:+(.5+c.size/o*4+(ms(s)>.4?.3:0)).toFixed(3)})}return l.sort((c,s)=>s.score-c.score).slice(0,8)}function y$(t,e,{W:o=1280,H:r=720,accent:a}={}){const n=t?.motion?.preset;if(!n||!ph(n))return[];const i=t.motion.duration??ph(n).duration,l=Math.max(0,Math.min(i-1/30,e+(t.inPoint||0)));return g$(d$(n,l,{W:o,H:r,params:t.motion.params||{},duration:i}),{W:o,H:r,accent:a??t.motion.params?.accent})}const b$={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}},On={minScore:.32,ease:"easy-ease",maxZoom:4},w$=t=>t.w*t.h,Mm=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],ey=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]],ji=t=>Math.sqrt(w$(t)),k$=t=>t.filter(e=>e.kind!=="audio"&&e.motion?.preset&&!e.seam?.hero),uh=(t,e)=>({x:Zt(t,"x",e),y:Zt(t,"y",e),zoom:Zt(t,"zoom",e)});function x$(t,e,o,r){const a=([u,c])=>[o/2+e.x*o+(u-o/2)*e.zoom,r/2+e.y*r+(c-r/2)*e.zoom],n=ey(t).map(a),i=n.map(u=>u[0]),l=n.map(u=>u[1]);return{...t,quad:n,x:Math.min(...i),y:Math.min(...l),w:Math.max(...i)-Math.min(...i),h:Math.max(...l)-Math.min(...l),r:t.r*e.zoom}}function vm(t,e,{W:o=1280,H:r=720,accent:a}={}){const n=[];for(const i of k$(t)){const l=e-i.start;if(l<-1e-6||l>i.duration+1e-6)continue;const u=uh(i,l);for(const c of y$(i,l,{W:o,H:r,accent:a}))n.push({...x$(c,u,o,r),layer:i.id})}return n.sort((i,l)=>l.score-i.score)}function $m(t,e,o,r,{W:a=1280,H:n=720,accent:i}={}){const l=vm(t,o,{W:a,H:n,accent:i}).slice(0,5),u=vm(e,r,{W:a,H:n,accent:i}).slice(0,5);if(!l.length||!u.length)return null;const c=m=>Math.max(...m.map(g=>g.score)),s=c(l),d=c(u);let f=null;for(const m of l)for(const g of u){const v=b$[m.role]?.[g.role]??0;if(!v)continue;const x=y=>y.w/y.h,$=Math.min(x(m),x(g))/Math.max(x(m),x(g)),E=Math.min(ji(m),ji(g))/Math.max(ji(m),ji(g)),S=m.score/s*(g.score/d),k=v*(.7+.3*$)*(.65+.35*Math.sqrt(E))*S*(E<1/On.maxZoom?.6:1);(!f||k>f.score)&&(f={a:m,b:g,score:+k.toFixed(3)})}return f&&f.score>=On.minScore?f:null}const la=t=>Math.round(t*1e4)/1e4;function M$(t,e,o,r,a,{W:n=1280,H:i=720,ease:l=On.ease}={}){const u=new Map,c=a-r,s=Object.hasOwn(Qt,l)?l:On.ease,[d,f]=Mm(t.a),[m,g]=Mm(t.b),v=Math.max(1/On.maxZoom,Math.min(On.maxZoom,ji(t.b)/ji(t.a))),x=(E,S,k,y)=>{y=Math.min(y,On.maxZoom/Math.max(.01,E.zoom));const A=E.zoom*y,I=n/2+E.x*n,z=i/2+E.y*i;return{x:la((k[0]-n/2-(S[0]-I)*y)/n),y:la((k[1]-i/2-(S[1]-z)*y)/i),zoom:la(A)}},$=(E,S,k,y,A)=>{const I=E.duration,z=j=>Math.min(I,Math.max(0,la(j-E.start)));for(const j of["x","y","zoom"])E=fd(E,j,[{time:z(S),value:k[j],ease:s},{time:z(S+c),value:y[j]}]);return fd(E,"opacity",A.map(([j,P])=>({time:z(S+j*c),value:P})))};for(const E of e){if(E.kind==="audio")continue;const S=ft(a-E.start);if(S<c+1/30)continue;let k={...E,duration:S};delete k.exit;const y=uh(E,r-E.start);k=$(k,r,{...y},x(y,[d,f],[m,g],v),[[.22,1],[.5,0]]),u.set(k.id,{...k,seam:{...k.seam,out:!0,excl:!0}})}for(const E of o){if(E.kind==="audio")continue;const S=ft(E.start+E.duration-r);if(S<c+1/30)continue;let k={...E,start:ft(r),duration:S};delete k.enter;const y=uh(E,a-E.start);k=$(k,r,x(y,[m,g],[d,f],1/v),{...y},[[.5,0],[.78,1]]),u.set(k.id,{...k,seam:{...k.seam,in:!0,excl:!0}})}return u}const v$=`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 $$(t,e,o,r,{W:a=1280,H:n=720,accent:i="#c6f432",ease:l=On.ease,id:u}={}){const c=$=>ey($).map(([E,S])=>`${la(E/a)},${la(S/n)}`).join(","),s=Qt[l]??Qt[On.ease],d=ft(r-o),f=$=>({fill:$.fill??$.border??i,line:$.border??$.fill??i}),m=f(t.a),g=f(t.b),v={qa:c(t.a),qb:c(t.b),ra:la(t.a.r/Math.min(a,n)),rb:la(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=ko({code:v$,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:ft(o),duration:d,track:0,motion:{...x,duration:d},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 Cc={overlap:ch.overlap[1],collide:1/30,world:.75,worldMin:6},Em="#c6f432",Sm=["whoosh-short-up","swoosh"],Im=["top","center","lower"],Ks=t=>Math.round(t*1e3)/1e3,Ye=t=>t.start+t.duration,E$=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 xi(t){if(t?.kind==="audio")return null;if(t?.title)return{band:Im.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||!Iu(e,"text")||s$.has(e))return null;const o=Iu(e,"placement"),r=o?t.motion.params?.[o]:null;return!o||!Im.includes(r)?null:{band:r,set:a=>({...t,motion:{...t.motion,params:{...t.motion.params,[o]:a}}})}}const S$=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 Xp(t){if(S$.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=xi(t);return e?e.band:t?.kind!=="audio"&&(t?.title||t?.motion?.preset&&Iu(t.motion.preset,"text"))?"full":null}const pp=(t,e)=>Math.min(Ye(t),Ye(e))-Math.max(t.start,e.start);function Am(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(Ye(t)-a-e.start)<1/60&&Math.abs(a-n)<1/60&&Math.abs(pp(t,e)-a)<1/60}const Cm=t=>t&&t.fade!==!1&&t.duration||0,I$=.15,jm=(t,e)=>{const o=Math.max(e.start>=t.start-1e-6?Cm(e.enter):0,Ye(t)<=Ye(e)+1e-6?Cm(t.exit):0);return o>0&&pp(t,e)<=o+I$},Tm=(t,e)=>!!(t.seam?.out&&e.seam?.in&&t.seam.excl&&e.seam.excl&&e.seam.scene===t.seam.scene+1),Om=t=>Math.max(...String(t.title.text).split(`
117
+ `).map(e=>e.length))*t.title.fontSize*.62+t.title.fontSize,A$=(t,e)=>!!(t.title&&e.title)&&[t.title.align,e.title.align].sort().join()==="left,right"&&Om(t)+Om(e)<=1040;function C$(t,e={}){const o=t.filter(a=>!e[a.track]?.hidden&&Xp(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 l=Xp(i),u=Xp(a),c=i.seam?.scene!==void 0&&a.seam?.scene!==void 0&&i.seam.scene!==a.seam.scene;(l===u||(l==="full"||u==="full")&&c)&&(pp(i,a)<=Cc.collide||Am(i,a)||Am(a,i)||Tm(i,a)||Tm(a,i)||l===u&&A$(i,a)||(l==="full"||u==="full")&&(jm(i,a)||jm(a,i))||r.push({a:i,b:a,at:Ks(Math.max(i.start,a.start))}))}}),r}const j$={center:["lower","top"],lower:["top","center"],top:["lower","center"]},T$=.8;function hh(t,{tracks:e={},movable:o=null}={}){let r=t.slice();const a=[],n=new Set,i=new Set,l=u=>!o||o.has(u.id);for(let u=0;u<80;u++){const c=C$(r,e),s=c.find(v=>xi(v.b)&&!n.has(v.b.id)&&l(v.b));if(s){const v=r.filter($=>$.id!==s.b.id&&xi($)&&pp($,s.b)>Cc.collide).map($=>xi($).band),x=j$[xi(s.b).band].find($=>!v.includes($));if(!x){n.add(s.b.id);continue}r=r.map($=>$.id===s.b.id?xi($).set(x):$),a.push(`"${s.b.label}" moved to ${x} (was over "${s.a.label}")`);continue}const d=c.find(v=>!i.has(v.a.id+"|"+v.b.id)&&(l(v.a)||l(v.b)));if(!d)break;const{a:f,b:m}=d,g=Ks(m.start-f.start);l(f)&&g>=T$?(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)`)):l(m)?(r=r.map(v=>v.id===m.id?{...v,start:Ks(Ye(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 O$(t){const e=Math.min(...t.map(s=>s.start)),o=Math.max(...t.map(Ye)),r=o-e,a=t.filter(s=>r>=Cc.worldMin&&s.duration>=Cc.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 l=[...i.values()].map(s=>({s:Math.min(...s.map(d=>d.start)),e:Math.max(...s.map(Ye)),list:s})),u=[];for(const s of n.filter(d=>!Number.isInteger(d.seam?.scene)).sort((d,f)=>d.start-f.start)){const d=l.map(m=>({k:m,o:Math.min(Ye(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(d){d.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,Ye(s))):u.push({s:s.start,e:Ye(s),list:[s]})}const c=[...l,...u].map(s=>s.list).sort((s,d)=>Math.min(...s.map(f=>f.start))-Math.min(...d.map(f=>f.start)));return{world:a,scenes:c}}function Zh(t,e={},o=null,{overlap:r,accent:a,newId:n,seed:i="clipoox",W:l=1280,H:u=720}={}){if(t.some(G=>E$(G)))throw Error("makeSeamless is for motion / text timelines (no footage or 3D models)");a=a??t.find(G=>G.seam?.hero&&G.shape)?.shape?.paths?.[0]?.stroke??t.find(G=>G.seam?.match)?.motion?.params?.glow??t.find(G=>Number.isInteger(G.seam?.deco))?.motion?.params?.accent??Em;const c=t.filter(G=>Number.isInteger(G.seam?.joinFx)),s=t.filter(G=>!G.seam?.hero&&!G.seam?.join&&!Number.isInteger(G.seam?.joinFx)).map(G=>G.seam?.raw?Yb(G):G),d=s.filter(G=>G.kind!=="audio");if(!d.length)throw Error("Nothing to link: add motion / text layers first");if(d.some(G=>e[G.track]?.locked))throw Error("Track đã khóa");const{world:f,scenes:m}=O$(d),g=new Set(f.map(G=>G.id)),v=[],x={};m.forEach((G,tt)=>{const Q=G.find(it=>it.seam&&(it.seam.style||it.seam.dur||it.seam.ease||it.seam.shuffle||it.seam.not))?.seam;Q&&(x[tt]={style:Q.style,dur:Q.dur,ease:Q.ease,shuffle:Q.shuffle,not:Q.not})});const $={};for(let G=1;G<m.length;G++){const tt=x[G]??{};if(tt.style&&tt.style!=="match-morph")continue;const Q=m[G-1].filter(ht=>!g.has(ht.id)),it=m[G].filter(ht=>!g.has(ht.id)),D=Number.isFinite(tt.dur)?tt.dur:uc("match-morph").dur,U=Q.length&&it.length?$m(Q,it,Math.max(...Q.map(Ye))-D,Math.min(...it.map(ht=>ht.start))+D,{accent:a,W:l,H:u}):null;U?$[G]=U:tt.style==="match-morph"&&(v.push(`join ${G}: no element pair to morph — kept a plain style`),x[G]={...tt,style:void 0})}const E=qb(m.map(Zb),{seed:i,overrides:x}).map((G,tt)=>uc($[tt+1]?"match-morph":G)),S=G=>{const tt=E[G-1],Q=x[G]??{},it=Number.isFinite(Q.dur)?Q.dur:Number.isFinite(r)?r:tt.dur;return Math.max(.2,Math.min(1.2,it))},k=s.filter(G=>G.kind==="audio"&&G.sfx),y=new Map(k.map(G=>[G.id,m.findIndex(tt=>tt.some(Q=>G.start>=Q.start-1e-6&&G.start<Ye(Q)))])),A=new Map;let I=null;m.forEach((G,tt)=>{const Q=Math.min(...G.map(U=>U.start)),it=Math.max(...G.map(Ye)),D=tt===0?0:Math.max(-Q,ft(I-S(tt)-Q));A.set(tt,D),I=it+D});const z=new Map(m.flatMap((G,tt)=>G.map(Q=>[Q.id,tt])));let j=s.map(G=>{if(G.kind==="audio"){const D=y.get(G.id);return D>=0&&A.get(D)?{...G,start:ft(Math.max(0,G.start+A.get(D)))}:G}const tt=z.get(G.id);if(tt===void 0)return G;const Q=x[tt]??{},it={...G,start:ft(G.start+A.get(tt))};return{...it,seam:{scene:tt,...Object.fromEntries(Object.entries(Q).filter(([,D])=>D!==void 0)),raw:Jb(it)}}});const P=G=>j.filter(tt=>tt.seam?.scene===G&&tt.kind!=="audio"&&!g.has(tt.id)),N=G=>{const tt=P(G);return[Math.min(...tt.map(Q=>Q.start)),Math.max(...tt.map(Ye))]},F=[];for(let G=1;G<m.length;G++){const tt=E[G-1],Q=N(G-1)[1],it=ft(Q-S(G)),D=tt.kind==="match"?$m(P(G-1),P(G),it,Q,{accent:a,W:l,H:u})??$[G]:null;F.push({k:G,b0:it,b1:Q,style:tt,pair:D});const U=D?M$(D,P(G-1),P(G),it,Q,{W:l,H:u,ease:x[G]?.ease??tt.ease}):Qb(tt,{out:P(G-1),inn:P(G),b0:it,b1:Q,ease:x[G]?.ease});if(j=j.map(ht=>U.get(ht.id)??ht),tt.kind==="sequence"){const ht=ft(it+(Q-it)/2);j=j.map(yt=>yt.kind==="audio"&&yt.sfx&&y.get(yt.id)===G&&yt.start<ht-1e-6?{...yt,start:ft(ht+(yt.start-it))}:yt)}}const K=Math.min(...j.filter(G=>G.kind!=="audio").map(G=>G.start)),_=Math.max(...j.filter(G=>G.kind!=="audio"&&!g.has(G.id)).map(Ye),K+.5);j=j.map(G=>g.has(G.id)&&Ye(G)>_+1e-6?{...G,duration:ft(Math.max(1/30,_-G.start))}:G);const J=[...j.filter(G=>g.has(G.id)).sort((G,tt)=>G.track-tt.track),...m.flatMap((G,tt)=>P(tt).sort((Q,it)=>Q.track-it.track||Q.start-it.start))],X=j.filter(G=>G.kind==="audio");for(const G of J){const{track:tt}=qt(X,e,G.start,Ye(G),G.track);X.push({...G,track:tt})}j=X,j=j.map(G=>{if(!G.transition)return G;const tt=tw(j,G);if(tt&&Og(tt))return G;const{transition:Q,...it}=G;return v.push(`transition on "${G.label}" removed (layers re-timed)`),it});let rt=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 G=[];for(const D of F){const U=D.pair?$$(D.pair,D.k,D.b0,D.b1,{W:l,H:u,accent:a,ease:x[D.k]?.ease??D.style.ease,...n?{id:n()}:{}}):{...xr({id:n?n():`seam-flight-${D.k}`,track:0,start:ft(D.b0),duration:ft(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)};U.track=qt([...j,...G],e,U.start,Ye(U)).track,G.push(U)}j.push(...G);for(const D of c){const U=F.find(Mt=>Mt.k===D.seam.joinFx);if(!U){v.push(`Claude Motion layer of join ${D.seam.joinFx} removed (that join is gone)`);continue}const ht=ft(Math.max(0,(U.b0+U.b1)/2-D.duration/2)),yt={...D,start:ht,zIndex:Math.min(99,U.k),is3D:!0};yt.track=qt(j,e,yt.start,Ye(yt)).track,j.push(yt)}for(const D of F){const U=D.style.pack==="urban",ht=D.style.pack==="techlaunch",yt=ht?ew(D.style.deco):U?ow(D.style.deco):rw(D.style.deco);if(!yt)continue;const Mt=(D.b0+D.b1)/2,p=ft(Math.min(2*Mt,to.maxDuration,Math.max(yt.min,(D.b1-D.b0)*yt.k+yt.add))),lt=Qt[x[D.k]?.ease??D.style.ease],V=lt==="hold"?[-1,0,0,0]:Array.isArray(lt)?lt:[0,0,1,1],h=ko({code:yt.code,params:ht?{...nw,...a&&a!==Em?{accent:a}:{},e0:V[0],e1:V[1],e2:V[2],e3:V[3]}:U?{accent:a,...aw,e0:V[0],e1:V[1],e2:V[2],e3:V[3]}:{accent:a,...iw,e0:V[0],e1:V[1],e2:V[2],e3:V[3],w:D.b1-D.b0,flash:"#ffffff"},preset:D.style.id}),w={id:n?n():`seam-deco-${D.k}`,nodeId:"",kind:"image",url:"",label:`${ht?"Tech Launch":U?"Urban":"Editorial"} · nối ${D.k}`,volume:0,start:ft(Mt-p/2),duration:p,track:0,motion:{...h,duration:p},motionKeys:[],seam:{join:!0,deco:D.k},zIndex:Math.min(99,D.k),is3D:!!yt.cam};w.track=qt(j,e,w.start,Ye(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 tt={...o??{...Mr,motionKeys:[]},enabled:!0},Q=_n.cz.base(tt),it=Qt["sine-in-out"];rt=bn(tt,"cz",[{time:ft(K),value:Q,ease:it},{time:ft(_),value:Ks(Math.min(_n.cz.max,Q+ch.camera.push))}]),rt=bn(rt,"roll",[{time:ft(K),value:0,ease:it},{time:ft(_),value:ch.camera.roll}]),zr(rt),F.forEach((D,U)=>{const ht=Math.max(0,D.b0-.05);if(j.some(Mt=>Mt.kind==="audio"&&/whoosh|swoosh|glitch/.test(Mt.sfx||"")&&Math.abs(Mt.start-ht)<.35))return;const yt=da(D.style.sfx)??da(Sm[U%Sm.length]);yt&&j.push({...Bi(j,e,yt,ht,{id:n?n():`seam-join-${U}`}),seam:{join:!0}})})}const ot=hh(j,{tracks:e});return j=ot.clips,v.push(...ot.notes),v.unshift(m.length>=2?`${m.length} scenes linked: ${F.map(G=>`${G.k}: ${G.style.id}${G.pair?` (${G.pair.a.role} → ${G.pair.b.role})`:""} ${Ks(G.b1-G.b0)}s`).join(", ")} — camera + whoosh`:"one scene so far — it will link to the next one"),{clips:j,camera:rt,notes:v,scenes:m.length,joins:F.map(G=>({k:G.k,start:G.b0,end:G.b1,style:G.style.id,...G.pair?{match:{a:G.pair.a.role,b:G.pair.b.role,score:G.pair.score}}:{}}))}}function z$(t,e={},o=null,{join:r,style:a,duration:n=null,ease:i=null,newId:l,seed:u,W:c,H:s}={}){const d=t.filter(S=>S.seam?.scene===r&&!S.seam.hero&&S.kind!=="audio");if(!Number.isInteger(r)||r<1||!d.length)throw Error("No such join — link the scenes first (makeSeamless)");const f=t.find(S=>S.seam?.flight===r)?.seam?.style??null,m=d.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(!uc(a))throw Error(`Unknown join style "${a}"`);if(uc(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(Qt,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:A,shuffle:I,not:z,...j}=S.seam;return{...S,seam:{...j,...v}}}),$=Zh(x,e,o,{newId:l,seed:u,W:c,H:s}),E=$.joins.find(S=>S.k===r)?.style;return v.style&&E!==v.style&&$.notes.push(`"${v.style}" does not fit these scenes — kept ${E}`),{...$,style:E}}const P$=t=>/\b(fillText|strokeText)\b/.test(String(t));function L$(t,e={},o=null,{join:r,code:a,params:n={},prompt:i="",duration:l,newId:u,seed:c,W:s,H:d}={}){if(!t.some(x=>x.seam?.flight===r))throw Error("No such join — link the scenes first (makeSeamless)");if(P$(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(l)||1.2)),m=ko({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:ft(f),track:0,motion:{...m,duration:ft(f)},motionKeys:[],seam:{joinFx:r}},v=Zh([...t.filter(x=>x.seam?.joinFx!==r),g],e,o,{newId:u,seed:c,W:s,H:d});return{...v,layer:v.clips.find(x=>x.seam?.joinFx===r)?.id}}const Yo={minDuration:.4,maxDuration:3,defaultDuration:1.2,minAmount:1.05,maxAmount:1.3,defaultAmount:1.12,ramp:.35,defaultStyle:"smooth",styles:["cut","smooth","push"]},Hr=1/30,ni=.4,N$=.7,Ti=(t,e,o)=>Math.max(e,Math.min(o,t)),zm=t=>+t.toFixed(4);function jc(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:Ti(a.subjectX,0,1),y:Number.isFinite(a.subjectY)?Ti(a.subjectY,0,1):.5}:null}function F$(t,e,o,r,a){const n=[];if(r==="cut"){if(t>=Hr&&n.push({time:ft(t-Hr),f:0,ease:"hold"}),n.push({time:t,f:1}),a)for(let l=t+ni;l<e-Hr-.05;l+=ni)n.push({time:ft(l),f:1});e>=o-1e-6?n.push({time:o,f:1}):n.push({time:ft(e-Hr),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 l=t+ni;l<e-Hr-.05;l+=ni)n.push({time:ft(l),f:(l-t)/(e-Hr-t)});e>=o-1e-6?n.push({time:o,f:1}):n.push({time:ft(e-Hr),f:1,ease:"hold"},{time:e,f:0})}else{const l=Math.min(Yo.ramp,(e-t)/3);if(n.push({time:t,f:0,ease:"easy-ease"},{time:ft(t+l),f:1}),a)for(let u=t+l+ni;u<e-l-.05;u+=ni)n.push({time:ft(u),f:1});e>=o-1e-6?n.push({time:o,f:1}):n.push({time:ft(e-l),f:1,ease:"easy-ease"},{time:e,f:0})}const i=[];for(const l of n)(!i.length||l.time>i.at(-1).time+1e-6)&&i.push(l);return i}function Pm(t,{at:e,duration:o=Yo.defaultDuration,amount:r=Yo.defaultAmount,style:a=Yo.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(!Yo.styles.includes(a))throw Error(`Punch-in style must be ${Yo.styles.join("/")}`);if(!Number.isFinite(e)||e<0||e>=t.duration-Hr)throw Error("Punch-in must start inside the clip");const i=Ti(Number.isFinite(o)?o:Yo.defaultDuration,Yo.minDuration,Yo.maxDuration),l=Ti(Number.isFinite(r)?r:Yo.defaultAmount,Yo.minAmount,Yo.maxAmount),u=ft(e);let c=ft(Math.min(t.duration,u+i));if(t.duration-c<Hr&&(c=t.duration),c-u<Hr*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),d=F$(u,c,t.duration,a,s),f=d[0].time,m=d.at(-1).time,g=n?n.x-.5:0,v=n?n.y-.5:0,x=(E,S)=>{const k=Zt(t,E,S.time),y=Zt(t,"zoom",S.time),A=Math.min(ns,y*(1+(l-1)*S.f));if(E==="zoom")return zm(A);const I=Math.max(0,(A-1)/2),z=-(A-y)*(E==="x"?g:v)*N$;return zm(Ti(k+Ti(z,-I,I),-1,1))};let $={...t};for(const E of n?["zoom","x","y"]:["zoom"]){const S=Ee(t,E).filter(I=>I.time<f-.001||I.time>m+.001),k=d.map(I=>({time:I.time,value:x(E,I),...I.ease?{ease:Qt[I.ease]}:{}})),y=[...S,...k].sort((I,z)=>I.time-z.time),A=me($,E,y);$={...$,...A}}return kn($),{motionV:$.motionV,motionKeys:$.motionKeys,...$.posX!==void 0?{posX:$.posX,posY:$.posY,scale:$.scale}:{}}}const R$=/[!?]$/;function oy(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 l=t.map((c,s)=>{const d=String(c.word??""),f=t[s-1];let m=0;return c.kw===!0?m+=6:c.kw!==!1&&(m+=Math.max(0,Cg(d)-1)),(!f||/[.!?…]$/.test(f.word)||c.start-f.end>.6)&&(m+=2),c.end-c.start>=.45&&(m+=1),R$.test(d)&&(m+=1),{at:Math.max(a,+(c.start-r).toFixed(3)),word:d,score:m,start:c.start}}).filter(c=>c.at>=a),u=[];for(;!(u.length>=o);){const c=u.length?u.at(-1).at+n:a,s=u.length?u.at(-1).at+i:a+i,d=l.filter(m=>m.at>=c-1e-9&&m.at<=s+1e-9);if(!d.length){const m=l.find(g=>g.at>s);if(!m)break;u.push({at:m.at,word:m.word,score:m.score});continue}const f=d.reduce((m,g)=>g.score>m.score?g:m);u.push({at:f.at,word:f.word,score:f.score})}return u}function ry(t,e){try{if(Array.isArray(t.captionWords)&&t.captionWords.length)return t.captionWords;if(Array.isArray(e?.words)&&e.words.length)return Rh(t,e.words);const o=t.captions?.length?t.captions:Array.isArray(e?.transcript)?sc(t,e.transcript):[];return o.length?np(o):[]}catch{return[]}}function aj(t,e,o={}){const r=Ee(t,"zoom");return oy(ry(t,e),{from:.5,...o}).filter(a=>!r.some(n=>Math.abs(n.time-a.at)<=2.5*Hr)).map(a=>({...a,at:+(t.start+a.at).toFixed(3)}))}const he=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}),be=t=>+(+t).toFixed(3),Ko=t=>String(t??"").trim().slice(0,40),Qo=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}]+/gu,"").trim(),Tc=t=>/[.!?…:;]$/u.test(String(t??"").trim()),D$={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},Up={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6,đầu:1},Yp=new Set(["cuối","cuối cùng","final","last"]),dh=t=>{const e=Qo(t);return/^\d{1,2}$/.test(e)?+e:D$[e]??null},B$=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"]),_$=new Set(["rồi","và","sau","then","and","xong","nhé","nha"]),Lm=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 Jh(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=>ry(i,n).map(l=>({start:be(i.start+l.start),end:be(i.start+l.end),word:String(l.word)}))).sort((i,l)=>i.start-l.start)}function ny(t){const e=[];return t.forEach((o,r)=>{const a=Qo(o.word),n=t[r+1],i=t[r-1];let l=null,u=r+2,c=o.start,s=a==="step"?"Step":"Bước";if((a==="bước"||a==="step")&&n&&(l=dh(n.word),l===null)){const f=Qo(n.word),m=f+" "+Qo(t[r+2]?.word);Up[f]===1&&a==="bước"?l=1:Yp.has(m)?(l=-1,u=r+3):Yp.has(f)&&(l=-1)}if(l===null&&a==="step"&&i){const f=Qo(i.word);Up[f]?(l=Up[f],c=i.start,u=r+1):Yp.has(f)&&(l=-1,c=i.start,u=r+1)}if(l===null||(l===-1&&(l=(e.at(-1)?.number??0)+1),e.some(f=>f.number===l)))return;const d=[];for(let f=u;f<t.length&&d.length<3;f++){const m=Qo(t[f].word);if(!d.length&&B$.has(m)){if(Tc(t[f].word))break;continue}if(!(dh(t[f].word)!==null&&!d.length)&&(["bước","step"].includes(m)||(d.push(String(t[f].word).replace(/[.,!?…:;"“”]+$/u,"")),Tc(t[f].word)||t[f+1]&&t[f+1].start-t[f].end>.5)))break}e.push({i:r,at:c,number:l,label:s,auto:d.join(" ")})}),e}function G$(t,e=new Set){const o=[];for(let r=0;r<t.length;r++){if(e.has(r)||!Lm.has(Qo(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=Qo(t[n+1]?.word);if(Tc(t[n].word)||/,$/u.test(t[n].word)||t[n+1]&&t[n+1].start-t[n].end>.45||Lm.has(i)||_$.has(i))break}["đợi","chờ","wait"].includes(Qo(t[r].word))&&!a.slice(1).some(i=>dh(i)!==null||/phút|giây|minute|second|chút|lát/u.test(Qo(i)))||a.length<2||(o.push({i:r,at:t[r].start,text:a.join(" ")}),r=n)}return o}function K$(t,e,o=0){const r=String(e||"").split(/\s+/u).map(Qo).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&&Qo(t[n+i].word)===r[i];)i++;if(i>=a)return t[n].start}return null}function Nm(t,e,o,r){const a=[...t].sort((i,l)=>i[0]-l[0]);let n=e;for(const[i,l]of a){if(n+o<=i+1e-6)break;l>n&&(n=l+.05)}return n+o<=r+1e-6?be(n):null}const ys=(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],l=Math.abs(n.start-e)-(i&&(Tc(i.word)||n.start-i.end>.25)?.6:0);(!a||l<a.score)&&(a={at:n.start,score:l})}return a?a.at:e},V$=t=>{try{const e=typeof t=="string"?JSON.parse(t||"{}"):t;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}},W$=/sản phẩm|san pham|product|packshot|chai|lọ|tuýp|hộp|bottle|serum|kem|dầu|son/iu;function H$({clips:t=[],materials:e=[],clipId:o,copy:r={},brand:a=null,en:n=!1,portrait:i=!0}={}){const l=(()=>{const V=t.find(h=>h.id===o);return V?t.filter(h=>h.id===o||V.nodeId&&h.nodeId===V.nodeId&&h.track===V.track&&h.kind===V.kind&&!h.mask).sort((h,w)=>h.start-w.start):[]})();if(!l.length)throw Error("productReview: the speaker clip was not found");const u=Jh(t,o,e),c=l[0].start,s=l.at(-1).start+l.at(-1).duration,d=s-c;if(d<6)throw Error("productReview: the clip is too short for a review (≥ 6 s)");const f=V=>{const h=e.find(w=>w.id===V);return h&&h.kind==="image"&&h.url?h.id:null},m=Ko(r.brand??a?.name??""),g=Ko(r.tagline??a?.tagline??""),v=f(r.logoImage)||f(a?.logoMaterialId),x=Ko(r.product??""),$=Ko(r.stepLabel??""),E=e.filter(V=>V.kind==="image"&&V.url&&V.id!==v&&V.role!=="reference"&&W$.test(`${V.label||""} ${(V.labels||[]).join(" ")} ${V.description||""}`)).map(V=>V.id),S=f(r.productImage)||E[0]||null,k=[],y=[],A=[],I=V=>(k.push(V),V),z=ny(u),j=new Set(z.flatMap(V=>[V.i,V.i+1,V.i+2,V.i+3,V.i+4])),P=Array.isArray(r.steps)?r.steps:[];for(const V of z){const h=P[V.number-1],w=Ko(typeof h=="string"?h:h?.name??V.auto);A.push({kind:"step",at:be(Math.max(c,V.at-he.caption.lead)),number:V.number,label:$||(V.label==="Step"||n?"Step":"Bước"),text:w,image:f(typeof h=="object"?h?.image:null)||(E.length>=Math.max(2,z.length)?E[V.number-1]??null:null)})}const N=Array.isArray(r.instructions)?r.instructions.map(Ko).filter(Boolean):null;if(N){let V=0;for(const h of N){const w=h.split(/\s+/u).slice(0,2).map(Qo),T=u.findIndex((C,O)=>C.start>=V&&Qo(C.word)===w[0]&&(!w[1]||Qo(u[O+1]?.word)===w[1]));T<0||(V=u[T].end,A.push({kind:"do",at:be(Math.max(c,u[T].start-he.caption.lead)),text:h}))}}else for(const V of G$(u,j))A.push({kind:"do",at:be(Math.max(c,V.at-he.caption.lead)),text:Ko(V.text)});A.sort((V,h)=>V.at-h.at||(V.kind==="step"?-1:1));const F=be(Math.max(c+he.logo+2,s-he.cta)),K=be(c+he.logo),_=[];for(const V of A){if(V.at<K-.3||V.at>F-he.caption.min)continue;const h=_.at(-1);if(h&&V.at-h.at<he.caption.min)if(V.kind==="step"&&h.kind!=="step")_.pop();else continue;_.push(V)}_.forEach((V,h)=>{const w=_[h+1]?.at??F;V.dur=be(Math.max(he.caption.min,Math.min(he.caption.max,w-he.caption.gap-V.at)))});const J=Number.isFinite(+r.rating)&&r.rating!==null&&r.rating!==""?Math.max(0,Math.min(5,+r.rating)):null;let X=null;if(J!==null||r.verdict){const V=[..._].reverse().find(T=>T.at+T.dur>F-he.rating),h=be(Math.max(F-he.rating-.05,V?V.at+he.caption.min+he.caption.gap:0,K)),w=be(F-.05-h);if(w>=2.4){X={at:h,dur:w};for(const T of _)T.at+T.dur>h-he.caption.gap&&(T.dur=be(h-he.caption.gap-T.at))}}for(const V of _)y.push([V.at,V.at+V.dur]);X&&y.push([X.at,X.at+X.dur]);const rt=K$(u,x,c),ot=rt!==null&&rt>=K?rt:ys(u,c+d*.28,K,c+d*.5);let G=x||m?Nm(y,Math.max(K+.2,ot-.1),he.packshot,F-.5):null,tt=he.logo,Q=he.packshot;if(G===null&&(x||m)){const V=_[0]?.at??F,h=be(Math.max(c+1.4,Math.min(rt??c+1.4,K)-.1)),w=V-h-.05>=2?h:be(c+1.4),T=be(Math.min(he.packshot,V-w-.05));T>=2&&(G=w,Q=T,tt=be(w-c))}G!==null&&y.push([G,G+Q]);{const V=G!==null?[[G,G+Q]]:[];for(const h of _)if(h.image){if(V.some(([w,T])=>h.at<T+2&&h.at+h.dur>w-2)){h.image=null;continue}V.push([h.at,h.at+h.dur])}}const it=[...G!==null?[[G,G+Q]]:[],..._.filter(V=>V.image).map(V=>[V.at,V.at+V.dur])],D=(V,h)=>it.some(([w,T])=>V<T-.05&&h>w+.05),U=V=>l.find(h=>V>=h.start-1e-6&&V<h.start+h.duration-1e-6);let ht=ys(u,c+2.4,c+he.wide[0],c+he.wide[1]),yt=0,Mt=c;for(;ht<F-he.close[0];){const V=Math.min(F-.1,ys(u,ht+2.5,ht+he.close[0],ht+he.close[1])),h=U(ht);let w=h?Math.min(V,h.start+h.duration):V;const T=it.find(([C,O])=>ht<O-.05&&w>C+.05);if(T&&T[0]-ht>=1.2)w=T[0];else if(T){ht=ys(u,T[1]+.15,T[1]+.05,T[1]+.6),Mt=T[1];continue}if(h&&w-ht>=he.pieceMin&&!D(ht,w)&&I({op:"punchIn",clipId:o,at:be(ht),duration:be(Math.min(3,w-ht)),numberValue:he.closeAmount,punchStyle:"cut",accent:!1}),yt++,yt%he.pushEvery===0){const C=U(Mt+.05),O=be(Mt+.05),L=Math.min(ht-.05,C?C.start+C.duration:ht,O+3);C&&L-O>=1&&!D(O,L)&&I({op:"punchIn",clipId:o,at:O,duration:be(L-O),numberValue:he.pushAmount,punchStyle:"push",accent:!1})}Mt=V,ht=ys(u,V+2.4,V+he.wide[0],V+he.wide[1])}if(v)I({op:"addElement",materialId:v,start:K,duration:be(s-K),posX:0,posY:i?.3:.385,scale:i?.16:.1,anim:{in:"fade",out:"fade"}});else if(m){const V=s-K,h=Math.ceil(V/to.maxDuration-1e-9);for(let w=0;w<h;w++){const T=K+V*w/h,C=K+V*(w+1)/h;I({op:"addMotion",motionPreset:"rv-brand-watermark",start:be(T),duration:be(C-T),placement:"lower",text:m,...w>0?{numberValue:w<h-1?3:1}:h>1?{numberValue:2}:{}})}}(m||v)&&(I({op:"addMotion",motionPreset:"rv-logo-open",start:be(c),duration:tt,placement:"center",text:m||x||" ",...g?{subText:g}:{},...v?{numberValue:1}:{}}),v&&I({op:"addElement",materialId:v,start:be(c+.15),duration:be(tt-.3),posX:0,posY:i?-.02:-.06,scale:i?.3:.2,anim:{in:"pop",out:"fade"}})),G!==null&&(I({op:"addMotion",motionPreset:"rv-packshot-title",start:G,duration:Q,placement:"center",text:x||m,subText:r.tag===""?" ":Ko(r.tag??(n?"New":"Mới")),items:[m||" ",...g?[g]:[]]}),S&&I({op:"addElement",materialId:S,start:be(G+.2),duration:be(Q-.2),posX:i?0:.2,posY:i?.1:.08,scale:i?.62:.5,anim:{in:"pop",out:"none"}}));for(const V of _){if(V.image){const w=V.dur;I({op:"addMotion",motionPreset:"rv-packshot-title",start:V.at,duration:w,placement:"center",text:x||" ",numberValue:1}),I({op:"addElement",materialId:V.image,start:be(V.at+.05),duration:be(w-.05),posX:i?0:.2,posY:i?.1:.08,scale:i?.62:.5,anim:{in:"fade",out:"none"}})}const h=V.image?{params:{color:"#2b2230"}}:{};V.kind==="step"?I({op:"addMotion",motionPreset:"rv-step-caption",start:V.at,duration:V.dur,placement:V.image?"top":"center",text:V.text||" ",subText:V.label,numberValue:V.number,...h}):I({op:"addMotion",motionPreset:"rv-instruction",start:V.at,duration:V.dur,placement:"center",text:V.text,...h})}const p=(V,h)=>{const w=Nm(y,Number.isFinite(+h)?Math.max(K,+h):K+.5,V,F-.2);return w!==null&&y.push([w,w+V]),w},lt=(Array.isArray(r.benefits)?r.benefits:[]).map(Ko).filter(Boolean).slice(0,4);if(lt.length){const V=p(he.benefits,r.benefitsAt);V!==null&&I({op:"addMotion",motionPreset:"rv-benefit-list",start:V,duration:he.benefits,placement:"center",text:Ko(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 V=p(he.callout,r.callout.at);V!==null&&I({op:"addMotion",motionPreset:"rv-product-callout",start:V,duration:he.callout,placement:"center",text:Ko(r.callout.text),...r.callout.sub?{subText:Ko(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 X&&I({op:"addMotion",motionPreset:"rv-rating",start:X.at,duration:X.dur,placement:"center",text:Ko(r.verdict??(n?"Worth it":"Đáng mua")),numberValue:J??0,...r.ratingNote?{subText:Ko(r.ratingNote)}:{}}),I({op:"addMotion",motionPreset:"rv-cta-end",start:F,duration:be(s-F),placement:"lower",text:x||m||(n?"Shop now":"Mua ngay"),subText:Ko(r.cta??(n?"Shop now · Link in bio":"Mua ngay · Link ở bio"))}),k}function X$(t,{clips:e=[],materials:o=[],brand:r=null,portrait:a=!0,en:n=!1,simulate:i=null}={}){if(!Array.isArray(t)||!t.some(d=>d?.op==="productReview"))return t;const l=[],u=[];let c=0;const s=d=>{const f=typeof d=="string"&&/^new:(\d+)$/.exec(d);if(!f)return d;const m=+f[1];let g=0;for(const v of u)m>v.after&&(g+=v.by);return`new:${m+g}`};for(const d of t){const f=d&&(d.clipId||d.fromClipId||d.sourceClipId)?{...d,...d.clipId?{clipId:s(d.clipId)}:{},...d.fromClipId?{fromClipId:s(d.fromClipId)}:{},...d.sourceClipId?{sourceClipId:s(d.sourceClipId)}:{}}:d;if(f?.op!=="productReview"){l.push(f),/^(add|lockup$)/.test(f?.op??"")&&c++;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&&!l.some(k=>k?.op==="cutPauses"&&k.clipId===m)&&x.push({op:"cutPauses",clipId:m,numberValue:.5,booleanValue:!0});let $=e;if(i&&(x.length||l.some(k=>["cutPauses","removeRetakes","split","trim","delete","move","compact","ripple"].includes(k?.op))))try{$=i([...l,...x])??e}catch{$=e}const E=[...x,...H$({clips:$,materials:o,clipId:m,copy:V$(f.prompt),brand:r,en:n,portrait:a})],S=E.filter(k=>/^add/.test(k.op)).length;l.push(...E),S&&u.push({after:c,by:S})}return l}const ca=Object.freeze({beat:{min:2.5,max:6,base:2.8,perWord:.2},maxBeats:8,gap:0,photoScale:.5,photoScaleTall:.62}),U$=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}}),qp="#2a241c",Zp="#d62b25",Fm="#f6efdd",Ve=t=>+(+t).toFixed(3),bs=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function Y$(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,ca.maxBeats).map(n=>({materialId:n.materialId,label:bs(n.label,40),year:bs(n.year,12),caption:bs(n.caption,140),keys:(Array.isArray(n.keys)?n.keys:[]).map(i=>bs(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:bs(o?.title,60),beats:a}}function Rm(t){const e=`${t.caption} ${t.keys.join(" ")}`.split(/\s+/).filter(Boolean).length;return Ve(Math.max(ca.beat.min,Math.min(ca.beat.max,ca.beat.base+e*ca.beat.perWord)))}function q$({prompt:t,materials:e,start:o=0,portrait:r=!1}){const{beats:a}=Y$(t,e),n=[],i={n:0},l=d=>(n.push(d),["addElement","addText","addMotion"].includes(d.op)&&i.n++,`new:${i.n}`),u=a.reduce((d,f)=>d+Rm(f),0),c=Ve(Math.max(0,o));for(let d=0;d<u-.001;d+=to.maxDuration){const f=l({op:"addMotion",motionPreset:"fxo-paper-bg",start:Ve(c+d),duration:Ve(Math.min(to.maxDuration,u-d)),label:"Motion · Nền giấy"});n.push({op:"collageStyle",clipId:f,back:!0})}let s=c;a.forEach((d,f)=>{const m=Rm(d),g=f%2===0,v=g?-1:1,x=d.cutout!=="none",$=r?0:v*.24,E=r?-.14:.04,S=r?ca.photoScaleTall:ca.photoScale,k=l({op:"addElement",materialId:d.materialId,start:Ve(s),duration:m,posX:$,posY:E,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:d.cutout}:{torn:"all",watercolor:!0,seed:f+1}}),d.old&&n.push({op:"setEffect",clipId:k,property:"mono",numberValue:.95}),x&&l({op:"addElement",elementId:"doodle-circle",start:Ve(s+.6),duration:Ve(m-.6),posX:$,posY:E,scale:Ve(S*.95),primary:"#e2382f"}),d.label&&l({op:"addText",text:d.label,styleId:"tape-label",accentColor:"#e6d9b8",color:qp,fontFamily:"Oswald",fontSize:40,placement:"top",align:g?"left":"right",start:Ve(s+.15),duration:Ve(m-.15),preset:"slide-left"}),d.year&&(l({op:"addText",text:d.year,styleId:"serif-year",accentColor:Zp,color:Zp,fontFamily:"Playfair Display",fontSize:96,placement:"top",align:g?"right":"left",start:Ve(s+.35),duration:Ve(m-.35),preset:"pop-in"}),l({op:"addElement",elementId:"doodle-underline",start:Ve(s+.7),duration:Ve(m-.7),posX:r?0:-v*.62,posY:-.46,scale:.22,primary:Zp})),d.keys.length&&l({op:"addText",text:d.keys.join(`
118
+ `),styleId:"accent-bar",accentColor:Fm,color:qp,fontFamily:"Oswald",fontSize:44,placement:"center",align:r?"center":g?"right":"left",start:Ve(s+.9),duration:Ve(m-.9),preset:"slide-left"}),d.caption&&l({op:"addText",text:d.caption,styleId:"accent-bar",accentColor:Fm,color:qp,fontFamily:"Noto Serif",fontSize:30,placement:"lower",align:"center",start:Ve(s+.5),duration:Ve(m-.5),preset:"slide-up"}),s=Ve(s+m+ca.gap)});for(let d=0;d<u-.001;d+=to.maxDuration)l({op:"addMotion",motionPreset:"fxo-paper-grain",start:Ve(c+d),duration:Ve(Math.min(to.maxDuration,u-d)),label:"Motion · Vân giấy"});return n}const Dm=["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement"];function Z$(t,{materials:e=[],portrait:o=!1}={}){if(!Array.isArray(t)||!t.some(l=>l?.op==="voxCollage"))return t;const r=[],a=[];let n=0;const i=l=>{const u=typeof l=="string"&&/^new:(\d+)$/.exec(l);if(!u)return l;const c=Number(u[1]);return`new:${c+a.filter(([s])=>s<c).reduce((s,[,d])=>s+d,0)}`};for(const l of t){if(l?.op!=="voxCollage"){r.push(l&&(l.clipId||Array.isArray(l.clipIds))?{...l,...l.clipId?{clipId:i(l.clipId)}:{},...Array.isArray(l.clipIds)?{clipIds:l.clipIds.map(i)}:{}}:l),Dm.includes(l?.op)&&n++;continue}const u=q$({prompt:l.prompt,materials:e,start:Number.isFinite(l.start)?l.start:0,portrait:o}),c=n+a.reduce((d,[,f])=>d+f,0),s=d=>{const f=typeof d=="string"&&/^new:(\d+)$/.exec(d);return f?`new:${Number(f[1])+c}`:d};for(const d of u)r.push(d.clipId?{...d,clipId:s(d.clipId)}:d);a.push([n,u.filter(d=>Dm.includes(d.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 Oc(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),l=n.find($=>$.start<=i&&$.end>i&&Number.isFinite($.subjectX))||n.find($=>Number.isFinite($.subjectX)),u=!!(t.captions?.length||t.captionWords?.length||e?.transcript?.length||e?.words?.length);if(!l&&!u)return null;const c=a>r*1.1,s=c?Ie.face.portrait:Ie.face.landscape;if(!l)return{...s,assumed:!0};const d=e?.width&&e?.height?e.width/e.height:r/a,f=r/a,m=t.scale??1,g=d>f?d/f:1,v=d<f?f/d:1,x=Number.isFinite(l.subjectY)?l.subjectY:.4;return{x:.5+(l.subjectX-.5)*g*m+(t.posX??0),y:.5+(x-.5)*v*m+(t.posY??0)}}function Bm(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 co=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})}),tr=(t,e,o)=>Math.max(e,Math.min(o,t)),Ae=t=>+t.toFixed(4);function ay(t,e,o,r,a,n=co.points){const i=o*r/a;return Array.from({length:n},(l,u)=>{const c=u/n*2*Math.PI;return[Ae(t+Math.cos(c)*o),Ae(e+Math.sin(c)*i)]})}function fh(t,{W:e,H:o,mw:r,mh:a,corner:n="bottom-left",size:i=co.size,anchor:l=null,cx:u,cy:c,ru:s,posX:d=null,posY:f=null}){const m=r<=a,g=Math.min(.5,.5*a/r),v=tr(Number.isFinite(s)?s:Math.min(m?.34:.34*a/r,g),co.minFace*Math.min(1,a/r),g),x=v*r/a,$=tr(Number.isFinite(u)?u:l?.x??.5,v,1-v),E=tr(Number.isFinite(c)?c:l?.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,A=tr(i,co.minSize,co.maxSize),I=A/2*Math.min(e,o),z=I/(v*k),j=n.endsWith("left"),P=n.startsWith("bottom"),N=co.margin*Math.min(e,o),F=(J,X)=>tr(J*X,I,X-I)-X/2,K=Number.isFinite(d)?F(d,e):(j?-1:1)*(e/2-N-I),_=Number.isFinite(f)?F(f,o):(P?1:-1)*(o/2-N-I);return{mask:{v:1,mw:r,mh:a,keys:[{t:0,pts:ay($,E,v,r,a)}],smooth:!0,feather:.004},posX:Ae((K-z*($-.5)*k)/e),posY:Ae((_-z*(E-.5)*y)/o),scale:Ae(z),bubble:{cx:Ae($),cy:Ae(E),ru:Ae(v),size:Ae(A),corner:n}}}function J$(t,e,{at:o,duration:r,corner:a="bottom-left",size:n,W:i=1080,H:l=1920,material:u=null,newId:c,posX:s=null,posY:d=null,color:f=null}){const m=t.find(I=>I.id===e);if(!m||m.kind!=="video"||m.title||m.shape||m.motion||m.gen)throw Error("Speaker bubble needs a video clip of the speaker");if(!co.corners.includes(a))throw Error(`Bubble corner must be ${co.corners.join("/")}`);const g=ft(Math.max(m.start,o)),v=ft(Math.min(m.start+m.duration,g+tr(Number.isFinite(r)?r:5,co.minDuration,co.maxDuration)));if(v-g<co.minDuration-1e-6)throw Error("Speaker bubble must start at least 1 s before the clip ends");const x=Math.round(u?.width)||(i<=l?1080:1920),$=Math.round(u?.height)||(i<=l?1920:1080);let E=t,S=m;const k=[c?.()??`${m.id}-b`,c?.()??`${m.id}-a`];if(g>m.start+1e-6){const[I,z]=Fe(S,g,k[0]);z&&(E=E.flatMap(j=>j.id===S.id?[I,z]:[j]),S=z)}if(v<S.start+S.duration-1e-6){const[I,z]=Fe(S,v,k[1]);z&&(E=E.flatMap(j=>j.id===S.id?[I,z]:[j]),S=I)}const y=fh(S,{W:i,H:l,mw:x,mh:$,corner:a,size:n,anchor:jc(S,u),posX:s,posY:d}),A={...S,motionV:2,motionKeys:[],posX:y.posX,posY:y.posY,scale:y.scale,mask:y.mask,bubble:y.bubble,zIndex:co.zIndex,edge:{...co.rim,...f?{color:f}:{}},shadow:{...hn,opacity:.55,blur:18,distance:8},enter:{type:"pop",duration:.3},exit:{type:"zoom-out",duration:.2}};for(const I of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout"])delete A[I];return{clips:E.map(I=>I.id===S.id?A:I),bubbleId:S.id}}const wr=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 mh({W:t,H:e,width:o,cx:r,cy:a,aspect:n=wr.aspect}={}){const i=e>t*1.1,l=i?wr.portrait:wr,u=wr.margin*Math.min(t,e),c=t*tr(Number.isFinite(o)?o:l.width,wr.minWidth,wr.maxWidth),s=Math.min(e*.86,c/tr(n,.4,2)),d=tr(t*(Number.isFinite(r)?r:l.x)-c/2,u,t-u-c),f=tr(e*(Number.isFinite(a)?a:l.y)-s/2,u,e-u-s);return{x:d,y:f,w:c,h:s,params:{posX:Ae((d+c/2)/t),posY:Ae((f+s/2)/e),pw:Ae(c/t),ph:Ae(s/e),radius:wr.radius}}}function Q$(t,{W:e,H:o,mw:r,mh:a,rect:n,anchor:i=null}){const l=n.w/n.h,u=r<=a;let c=a*(u?.42:.74),s=c*l;s>r&&(s=r,c=s/l),c>a&&(c=a,s=c*l);const d=i?.x??.5,f=i?.y??(u?.36:.4),m=tr(d,s/r/2,1-s/r/2),g=tr(f+c/a*.24,c/a/2,1-c/a/2),v=t.fit==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a),x=r*v,$=a*v,E=n.w/(s*v),S=tr(2*wr.radius*n.w/Math.min(n.w,n.h),0,1),k=Cn({kind:"rect",cx:Ae(m),cy:Ae(g),w:Ae(s/r),h:Ae(c/a),rot:0,round:Ae(S)},r,a);return{mask:cr({mw:r,mh:a},[k]),posX:Ae((n.x+n.w/2-e/2-E*(m-.5)*x)/e),posY:Ae((n.y+n.h/2-o/2-E*(g-.5)*$)/o),scale:Ae(E)}}function t6(t,e,{at:o,duration:r,width:a,cx:n,cy:i,aspect:l,color:u="#ff2d3f",W:c=1280,H:s=720,material:d=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=ft(Math.max(m.start,o)),v=ft(Math.min(m.start+m.duration,g+tr(Number.isFinite(r)?r:5,wr.minDuration,wr.maxDuration)));if(v-g<wr.minDuration-1e-6)throw Error("Speaker window must start at least 1 s before the clip ends");const x=Math.round(d?.width)||(c<=s?1080:1920),$=Math.round(d?.height)||(c<=s?1920:1080);let E=t,S=m;const k=[f?.()??`${m.id}-wb`,f?.()??`${m.id}-wa`];if(g>m.start+1e-6){const[z,j]=Fe(S,g,k[0]);j&&(E=E.flatMap(P=>P.id===S.id?[z,j]:[P]),S=j)}if(v<S.start+S.duration-1e-6){const[z,j]=Fe(S,v,k[1]);j&&(E=E.flatMap(P=>P.id===S.id?[z,j]:[P]),S=z)}const y=mh({W:c,H:s,width:a,cx:n,cy:i,...Number.isFinite(l)?{aspect:l}:{}}),A=Q$(S,{W:c,H:s,mw:x,mh:$,rect:y,anchor:jc(S,d)}),I={...S,motionV:2,motionKeys:[],posX:A.posX,posY:A.posY,scale:A.scale,mask:A.mask,zIndex:wr.zIndex,edge:{color:u.toLowerCase(),...wr.rim},shadow:{...hn,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 I[z];return{clips:E.map(z=>z.id===S.id?I:z),windowId:S.id}}function e6(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!==co.points||t.zIndex!==co.zIndex)return null;const a=r.map(m=>m[0]),n=r.map(m=>m[1]),i=(Math.min(...a)+Math.max(...a))/2,l=(Math.min(...n)+Math.max(...n))/2,u=(Math.max(...a)-Math.min(...a))/2,{mw:c,mh:s}=t.mask,d=t.fit==="cover"?Math.max(e/c,o/s):Math.min(e/c,o/s),f=2*(t.scale??1)*u*c*d/Math.min(e,o);return{cx:Ae(i),cy:Ae(l),ru:Ae(u),size:Ae(tr(f,co.minSize,co.maxSize)),corner:`${(t.posY??0)<0?"top":"bottom"}-${(t.posX??0)>0?"right":"left"}`}}function ij(t,e,{W:o,H:r}){const a=e6(t,{W:o,H:r});if(!a)throw Error("Not a speaker bubble");const{mw:n,mh:i}=t.mask,l={...a,...e},u=fh(t,{W:o,H:r,mw:n,mh:i,...a}),c=fh(t,{W:o,H:r,mw:n,mh:i,...l}),s=e.corner===void 0||e.corner===a.corner,d=s?(t.posX??0)-u.posX:0,f=s?(t.posY??0)-u.posY:0;return{mask:c.mask,posX:Ae(c.posX+d),posY:Ae(c.posY+f),scale:c.scale,bubble:c.bubble}}const Ct=Object.freeze({nav:{dur:5,min:2.5,max:7},steps:{dur:4,min:1.5},tool:{dur:4,min:2,max:8,maxCount:12},takeaway:5,card:3.5,questionGap:20,questionPause:.6,stepGap:120,punch:{every:[8,15],amount:1.1,max:3,maxCount:60},lift:.1,maxItems:6,screen:{landscape:{w:.84,h:.8,cy:.535},portrait:{w:.92,h:.62,cy:.45}},fade:.4,overhead:{min:2,max:120,fade:.25,maxCount:12},label:{dur:4,w:.22,gap:30,maxAuto:2},journey:{dur:8,min:3,a:.6,b:.8,delay:.3,r:{landscape:.06,portrait:.07}},photo:{dur:4,min:2,group:2.5,size:[.34,.27,.22],minSize:.14,rot:[-6,5,-3],maxCount:12},cover:{dur:4.5,min:2,size:.52,rot:6},framework:{w:.26,minW:.17,min:2,max:6,hold:4,gap:30,step:1.2,lead:.3,within:180,maxCount:3},split:{dur:6,min:2,max:20,fade:.25,maxCount:12,landscape:{m:[.35,.5,.6,.78],p:[.815,.5,.27,.78]},portrait:{m:[.5,.27,.88,.36],p:[.5,.7,.44,.4]}},compare:{dur:9,min:4,max:20,within:90,side:30,lines:3,maxAuto:2},doc:{dur:5,min:2,max:20,zoom:.05,w:.8,h:.8,cy:.52,fade:.3,maxCount:8},map:{dur:7,min:3,max:20,pins:4,fade:.35},brand:{h:.06,maxW:.16,margin:[.045,.05]}}),_m=Object.freeze(Object.keys(zg)),Gm=Object.freeze(["questions","chapters","steps","none"]),o6=Object.freeze({style:"karaoke",position:"bottom",font:"Be Vietnam Pro",perGroup:3,emphasis:!0,emphasisColor:"#8fc4ff",emphasisColor2:"#3d7bff",size:.8}),Pt=t=>+(+t).toFixed(3),Xo=(t,e,o)=>Math.max(e,Math.min(o,t)),Jr=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}]+/gu,"").trim(),r6=t=>/[.!?…]$/u.test(String(t??"").trim()),Ji=t=>String(t??"").replace(/[.,!?…:;"“”]+$/u,""),Za=t=>{const e=String(t??"").trim().replace(/[.,:;…"“”]+$/u,"");return e.charAt(0).toUpperCase()+e.slice(1)},we=(t,e)=>String(t??"").replace(/\s+/gu," ").trim().slice(0,e),Ln=(t,e=24)=>{let o="";for(const r of Ji(String(t??"")).split(/[\s,;:]+/u).filter(Boolean)){const a=o?o+" "+r:r;if(a.length>e)break;o=a}return Ji(o)},n6=/[ăâđêôơưạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ]/iu,a6={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},Vs=t=>{const e=Jr(t);return/^\d{1,2}$/u.test(e)?+e:a6[e]??null},up=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"]),zc={nhất:1,hai:2,ba:3,tư:4,năm:5,sáu:6},Pc={first:1,firstly:1,second:2,secondly:2,third:3,thirdly:3,fourth:4,fourthly:4,fifth:5,finally:-1,lastly:-1},i6=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"}]),s6=/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 l6(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||r6(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 Qi=(t,e,o=12)=>{const r=t.words.slice(e).map(a=>String(a.word));for(;r.length&&up.has(Jr(r[0]));)r.shift();return r.slice(0,o).join(" ").replace(/^[,:–-]+\s*/u,"")},Km={tiếp:null,đầu:1,cuối:null};function c6(t){const e=t.words.map(o=>Jr(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=Vs(t.words[r]?.word);if(a!==null)return{j:r+1,number:a};if(e[r]in Km&&["theo","tiên","cùng"].includes(e[r+1]))return{j:r+2,number:Km[e[r]]};continue}if(e[o]==="question"){let r=o+1;["number","no"].includes(e[r])&&r++;const a=Vs(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 p6(t){const e=[];if(t.forEach((r,a)=>{const n=c6(r);if(!n)return;let i=Qi(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:we(Za(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>=Ct.questionPause)&&r!==t[0]||o.length&&r.start-o.at(-1).at<Ct.questionGap||o.push({at:r.start,text:we(Za(r.text),90)});return o}function u6(t){const e=[];for(const o of t){const r=o.words.map(a=>Jr(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=Vs(o.words[a+1].word);if(n!==null){e.some(i=>i.number===n)||e.push({at:o.start,number:n,title:we(Ji(Qi(o,a+2,8)),60)});break}}}return e}function h6(t,e){const o=(i,l)=>{const u=e.find(c=>i>=c.i0&&i<c.i0+c.words.length);return u?Ln(Qi(u,l-u.i0,6)):""},r=ny(t).map(i=>({at:i.at,number:i.number,label:o(i.i,i.i+(Vs(t[i.i+1]?.word)!==null||Jr(t[i.i]?.word)==="bước"?2:1))||we(i.auto,24)}));for(const i of e){const l=Jr(i.words[0]?.word),u=Jr(i.words[1]?.word);let c=null,s=1;l==="thứ"&&zc[u]?(c=zc[u],s=2):Pc[l]&&(c=Pc[l]),c!==null&&(c===-1&&(c=(r.filter(d=>d.at<i.start).at(-1)?.number??0)+1),!r.some(d=>Math.abs(d.at-i.start)<1.5)&&r.push({at:i.start,number:c,label:Ln(Qi(i,s,6))}))}r.sort((i,l)=>i.at-l.at);const a=[];for(const i of r){const l=a.at(-1),u=l?.at(-1);!l||i.number===1&&u.number!==1||i.number<=u.number||i.at-u.at>Ct.stepGap?a.push([i]):l.push(i)}const n=[];for(const i of a){if(i.length<2)continue;const l=Math.min(Ct.maxItems,Math.max(...i.map(c=>c.number))),u=Array.from({length:l},(c,s)=>i.find(d=>d.number===s+1)?.label||String(s+1));i.forEach((c,s)=>{if(c.number>l)return;const d=i[s+1]?.at;n.push({at:Pt(c.at),duration:Pt(Xo((d??c.at+Ct.steps.dur)-c.at-.1,Ct.steps.min,Ct.steps.dur)),labels:u,current:c.number})})}return n}const d6=/(?<![\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,f6=/(?<![\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,m6=/(?<![\p{L}\p{N}])(mô hình|khung|framework|model|the)?\s*([3-6])\s?([APCSM])(?:'?s)?(?![\p{L}\p{N}])/u,Vm=/(?:^|\s)(mô hình|khung|framework|model)\s*$/iu;function Lc(t){const e=t.words.map(o=>Jr(o.word));for(let o=0;o<Math.min(6,e.length);o++){if(e[o]==="thứ"&&zc[e[o+1]])return{num:zc[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&&Pc[e[o]])return{num:Pc[e[o]],j:o+1}}return null}const g6=/^(tức là|nghĩa là|có nghĩa là|là|which means|that is|meaning|means|is)\s+/iu,y6=new Set([...up,"one","chữ","cái","yếu","tố","điều","step","bước","nguyên","tắc","letter","then"]);function b6(t){const e=String(t??"").split(/\s+/u).filter(Boolean);for(;e.length&&y6.has(Jr(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(g6,""):"",i=a.split(/\s+/u).filter(Boolean),l=i.length<=3?Ji(a):Ji(i.slice(0,3).join(" ")),u=i.length<=3?Ln(n,30):Ln(i.slice(3).join(" ")+" "+n,30);return{title:Za(Ln(l,20)),sub:Ln(u,30),short:!!r&&i.length<=3}}function w6(t){const e=[],o=new Set,r=(a,n)=>{const i=[];for(let l=a;l<t.length;l++){const u=t[l];if(u.start>n)break;if(o.has(l))continue;const c=Lc(u);if(!c)continue;const s=c.num===-1?i.length+1:c.num;if(s!==i.length+1){if(i.length>=2)break;if(s===1)i.length=0;else continue}if(i.push({k:l,at:Pt(u.start),...b6(Qi(u,c.j,16))}),i.length>=Ct.framework.max)break}return i.filter(l=>l.title)};t.forEach((a,n)=>{if(e.length>=Ct.framework.maxCount||o.has(n))return;const i=a.text,l=d6.exec(i),u=f6.exec(i),c=m6.exec(i),s=l||u||c;if(!s)return;const d=c&&!l&&!u?+c[2]:Vs(s[1]);if(!(d>=3&&d<=Ct.framework.max))return;const f=r(n,a.start+Ct.framework.within).slice(0,d);if(f.length<Math.min(3,d))return;const m=i.slice(0,s.index),g=c&&!l&&!u?`${c[1]&&c[1]!=="the"?c[1]+" ":""}${c[2]}${c[3]}`:(Vm.exec(m)?.[1]?Vm.exec(m)[1]+" ":"")+s[0].trim();f.forEach(v=>o.add(v.k)),o.add(n),e.push({at:Pt(a.start),title:we(Za(g),32),items:f.map(({k:v,short:x,...$})=>$)})});for(let a=0;a<t.length&&e.length<Ct.framework.maxCount;a++){if(o.has(a)||!Lc(t[a]))continue;const n=r(a,t[a].start+Ct.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:l,...u})=>u)}))}return e.sort((a,n)=>a.at-n.at)}const k6=/(?<![\p{L}])(video|tập|bài|số|clip)\s+(trước|lần trước|vừa rồi)(?![\p{L}])/iu,x6=/(?<![\p{L}])(previous|last|earlier)\s+(video|episode|lesson|part)(?![\p{L}])/iu,M6=new Set([...up,"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 v6(t){const e=[];for(const o of t){if(e.length>=Ct.label.maxAuto)break;const r=k6.exec(o.text)||x6.exec(o.text);if(!r||e.length&&o.start-e.at(-1).at<Ct.label.gap)continue;const a=o.text.slice(r.index+r[0].length).split(/\s+/u).filter(Boolean);for(;a.length&&M6.has(Jr(a[0]));)a.shift();e.push({at:Pt(o.start),sub:Ln(a.join(" "),30)})}return e}const $6=/(?<![\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,E6=/(?<![\p{L}\p{N}])(two|2)\s+(ways|paths|options|routes|kinds|types|models|approaches)(?![\p{L}\p{N}])/iu,S6=new Set([...up,"cách","con","đường","lựa","chọn","hướng","đi","kiểu","loại","phương","án","way","path","option","route","approach","one","to","be","của","một","a"]),I6=/(?:từ\s+)?(\d+(?:[.,]\d+)?)\s*(?:(?:đến|tới|-|–)\s*(\d+(?:[.,]\d+)?)\s*)?(triệu|tr|nghìn|ngàn|tỷ|tỉ|usd|đô|đồng)(?![\p{L}])/iu,A6=/\$\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,Wm=t=>t?/^(k|thousand)$/i.test(t)?"K":"M":"";function Jp(t){const e=String(t??""),o=I6.exec(e);if(o)return`${o[1]}${o[2]?"–"+o[2]:""} ${o[3].toLowerCase()}`;const r=A6.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],l=r[2]??r[6]??(r[5]?i:void 0);return`$${a}${Wm(l)}${n?` – $${n}${Wm(i)}`:""}`}function C6(t){const e=String(t??"").split(/\s+/u).filter(Boolean);for(;e.length&&S6.has(Jr(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:Za(Ji(n.slice(0,5).join(" "))),rest:r?r[2]:n.slice(5).join(" ")}}function j6(t){const e=[];return t.forEach((o,r)=>{if(e.length>=Ct.compare.maxAuto||e.length&&o.start<e.at(-1).end)return;const a=$6.exec(o.text)||E6.exec(o.text);if(!a)return;const n=[];let i=r;for(;i<t.length&&t[i].start<=o.start+Ct.compare.within&&n.length<3;i++){const f=t[i],m=i===r?null:Lc(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 l=1;const u=(f,m)=>{const g=t[f.k],{head:v,rest:x}=C6(Qi(g,f.m.j,24)),$=m===0?t[n[1].k].start:g.start+Ct.compare.side,E=t.slice(f.k+1).filter(I=>I.start<$&&!Lc(I)).slice(0,m===0?Ct.compare.lines:Math.max(1,l)).map(I=>I.text),S=[x,...E].filter(Boolean);m===0&&(l=E.length);const k=S.map(Jp).find(Boolean)||Jp(g.text),y=[...new Set(S.filter(I=>!Jp(I)).map(I=>Za(Ln(I,40))).filter(I=>I.split(" ").length>=2))].slice(0,Ct.compare.lines),A=t[f.k+E.length];return{head:we(v,28),amount:k,lines:y,end:A?.end??g.end}},c=u(n[0],0),s=u(n[1],1);if(!c.head||!s.head)return;const d=we(Za(Ln(o.text.slice(a.index),48)).toUpperCase(),48);e.push({at:Pt(o.start),end:Pt(s.end),title:d,left:{head:c.head,amount:c.amount,lines:c.lines},right:{head:s.head,amount:s.amount,lines:s.lines}})}),e}function T6(t,e=!1){const o=[];for(const r of t)for(const a of i6)o.some(n=>n.kind===a)||a.re.test(r.text)&&o.push({kind:a,at:Pt(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,Ct.tool.maxCount)}const O6=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")}},Vo=(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:Pt(n),duration:Pt(i-n),fade:o===1?"both":a===0?"in":a===o-1?"out":"none"})}return r},Zl=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),Hm=/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 Xm(t,e){const o=Math.min(t,e)/Math.max(t,e),r=1-o;return t>=e?{left:Pt(r/2),right:Pt(r/2),top:0,bottom:0}:{left:0,right:0,top:Pt(r*.3),bottom:Pt(r*.7)}}function z6(t,e,o){const r=t/e;if(r>o){const n=Pt((1-o/r)/2);return{left:n,right:n,top:0,bottom:0}}const a=1-r/o;return{left:0,right:0,top:Pt(a*.4),bottom:Pt(a*.6)}}function ai(t,e,o,r,a,n){const i=g=>Math.max(2,Math.floor(g/2)*2),l=i(t),u=i(e),c=Math.abs(r*Math.PI/180),s=Math.abs(Math.cos(c)),d=Math.abs(Math.sin(c)),f=c?Math.ceil((l*s+u*d)/2)*2:l,m=c?Math.ceil((l*d+u*s)/2)*2:u;return Pt(Xo(o/Math.min(a/f,n/m),.02,4))}function P6({clips:t=[],materials:e=[],op:o={},W:r=1280,H:a=720,en:n=null,maxOps:i=1/0,brand:l=null}={}){const u={...O6(o.prompt),...Object.fromEntries(Object.entries(o).filter(([W,mt])=>!["op","prompt"].includes(W)&&mt!==null&&mt!==void 0))},c=t.find(W=>W.id===u.clipId);if(!c||c.kind!=="video"||c.motion||c.title||c.shape)throw Error("clipId must be the main lesson video on the timeline");if(u.navigator!=null&&!Gm.includes(u.navigator))throw Error(`navigator must be ${Gm.join(" / ")}`);if(u.theme!=null&&!_m.includes(u.theme))throw Error(`theme must be ${_m.join(" / ")}`);for(const W of["chapters","steps","tools","screenClips","overhead","photos","labels","split","docs"])if(u[W]!=null&&!Array.isArray(u[W]))throw Error(`${W} must be a list`);for(const W of["framework","journey","cover","map"])if(u[W]!=null&&(typeof u[W]!="object"||Array.isArray(u[W])))throw Error(`${W} 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=zg[u.theme??sw],d=t.filter(W=>W.id===c.id||c.nodeId&&W.nodeId===c.nodeId&&W.track===c.track&&W.kind===c.kind&&!W.mask).sort((W,mt)=>W.start-mt.start),f=d[0].start,m=d.at(-1).start+d.at(-1).duration,g=Math.max(.001,m-f),v=W=>W>=f-1e-6&&W<m-.5,x=Jh(t,c.id,e),$=l6(x),E=x.map(W=>W.word).join(" "),S=E?!n6.test(E)&&n!==!1:!!n,k=a>r*1.1,y=W=>e.find(mt=>mt.id===W),A=Math.min(r,a),I=(W,mt)=>{if(!Number.isFinite(+W))throw Error(`${mt} needs at (timeline seconds)`);return Pt(Xo(+W,f,m-.5))},z=W=>`${y(W.nodeId)?.label||W.label||""} ${(y(W.nodeId)?.labels||[]).join(" ")}`,j=(W,mt)=>{const bt=y(W);if(!bt||bt.kind!=="image"||!bt.url)throw Error(`${mt} must be an image from Media`);return bt},P=(u.chapters??[]).slice(0,30).map((W,mt)=>({at:I(W?.at,`chapters[${mt}]`),title:we(W?.title,80),sub:we(W?.sub,80),takeaways:(Array.isArray(W?.takeaways)?W.takeaways:[]).map(bt=>we(bt,48)).filter(Boolean).slice(0,3),number:mt+1})).sort((W,mt)=>W.at-mt.at),N=P.length?[]:u6($).filter(W=>v(W.at)),F=P.length?P:N.map((W,mt)=>({...W,number:W.number??mt+1,sub:"",takeaways:[]})),K=(W,mt,bt)=>{const Et=W&&typeof W=="object",Ft=Et?`${W.title??""}${W.sub?" — "+W.sub:""}`:String(W??""),Rt=Ft.split(/\s+[—–-]\s+|\s*:\s+/u),Lt=we(Et?W.title:Rt[0],20),Ht=we(Et?W.sub:Rt.slice(1).join(" "),30);if(!Lt)throw Error(`framework.items[${mt}] needs a title`);return{at:Et&&Number.isFinite(+W.at)?I(W.at,`framework.items[${mt}]`):Pt(bt+Ct.framework.lead*2+mt*Ct.framework.step),title:Lt,sub:Ht,icon:Et&&bp(W.icon)?W.icon:null}},_=u.framework?(()=>{const W=u.framework,mt=I(W.at,"framework"),bt=Array.isArray(W.items)?W.items.slice(0,Ct.framework.max):[];if(bt.length<Ct.framework.min)throw Error(`framework needs ${Ct.framework.min}–${Ct.framework.max} items`);return[{at:mt,title:we(W.title,32),items:bt.map((Et,Ft)=>K(Et,Ft,mt)).sort((Et,Ft)=>Et.at-Ft.at)}]})():w6($).filter(W=>v(W.at)).map(W=>({...W,items:W.items.map(mt=>({...mt,icon:null}))})),J=W=>[W.at-1,W.items.at(-1).at+Ct.framework.hold],X=(W,mt)=>{if(!W||typeof W!="object"||!we(W.head,28))throw Error(`compare.${mt} needs head`);return{head:we(W.head,28),amount:we(W.amount,24),lines:(Array.isArray(W.lines)?W.lines:[]).map(bt=>we(bt,40).replace(/[|]+/gu," ")).filter(Boolean).slice(0,4)}},rt=u.compare===!1?[]:u.compare?[(()=>{const W=u.compare,mt=I(W.at,"compare");return{at:mt,end:mt+(Number.isFinite(+W.duration)?+W.duration:Ct.compare.dur),title:we(W.title,48),left:X(W.left,"left"),right:X(W.right,"right"),given:!0}})()]:j6($).filter(W=>v(W.at)),ot=W=>[W.at-.5,W.end+.5],G=(u.steps?u.steps.slice(0,40).map((W,mt)=>{const bt=(Array.isArray(W?.labels)?W.labels:[]).map(Et=>we(Et,24)).filter(Boolean).slice(0,Ct.maxItems);if(!bt.length)throw Error(`steps[${mt}] needs labels`);return{at:I(W?.at,`steps[${mt}]`),duration:Pt(Xo(Number.isFinite(+W?.duration)?+W.duration:Ct.steps.dur,Ct.steps.min,8)),labels:bt,current:Xo(Math.round(+W?.current||1),1,bt.length)}}):h6(x,$).filter(W=>v(W.at))).filter(W=>u.steps||!_.some(mt=>{const[bt,Et]=J(mt);return W.at>=bt&&W.at<=Et})&&!rt.some(mt=>{const[bt,Et]=ot(mt);return W.at>=bt&&W.at<=Et})),tt=u.tools?u.tools.slice(0,Ct.tool.maxCount).map((W,mt)=>{const bt=we(W?.label,32);if(!bt)throw Error(`tools[${mt}] needs label`);return{at:I(W?.at,`tools[${mt}]`),duration:Number.isFinite(+W?.duration)?Xo(+W.duration,Ct.tool.min,Ct.tool.max):Ct.tool.dur,label:bt,url:we(W?.url,40),icon:bp(W?.icon)?W.icon:Ni(`${W?.label??""} ${W?.url??""}`)||"sparkle"}}):T6($,S).filter(W=>v(W.at)).map(W=>({...W,duration:Ct.tool.dur,url:""})),Q=p6($).filter(W=>v(W.at)),it=u.navigator??(F.length?"chapters":Q.length>=2?"questions":G.length?"steps":"none");if(!x.length&&!F.length&&!G.length&&!tt.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(W=>["video","image"].includes(W.kind)&&!d.includes(W)&&!W.motion&&!W.title&&!W.shape&&Hm.test(z(W))&&W.start<m-1&&W.start+W.duration>f+1).map(W=>({clipId:W.id})),U=[],ht=new Map;D.slice(0,Ct.overhead.maxCount).forEach((W,mt)=>{const bt=t.find(ie=>ie.id===W?.clipId),Et=bt&&y(bt.nodeId);if(!bt||!["video","image"].includes(bt.kind)||bt.motion||bt.title||bt.shape||!Et?.url)throw Error(`overhead[${mt}] clipId must be a whiteboard / B-roll video or image clip from Media`);if(d.includes(bt))throw Error("the lesson video cannot be its own overhead shot");const Ft=I(W.at??bt.start,`overhead[${mt}]`),Rt=(bt.inPoint||0)+(ht.get(bt.id)||0),Lt=bt.kind==="video"&&Number.isFinite(Et.duration)?Et.duration-Rt:1/0;let Ht=Math.min(Number.isFinite(+W.duration)?+W.duration:bt.duration,m-Ft,Ct.overhead.max);const Yt=Lt>=Math.min(Ht,Ct.overhead.min)?Rt:bt.inPoint||0;bt.kind==="video"&&Number.isFinite(Et.duration)&&(Ht=Math.min(Ht,Et.duration-Yt));const Jt=U.at(-1);Jt&&Ft<Jt.a+Jt.d&&(Ht=0),!(Ht<Ct.overhead.min)&&(ht.set(bt.id,(ht.get(bt.id)||0)+Ht),U.push({c:bt,m:Et,a:Ft,d:Pt(Ht),inPoint:Pt(bt.kind==="video"?Yt:0)}))});const yt=U.map(W=>[W.a,W.a+W.d]),Mt=mh({W:r,H:a}),p=new Set(U.map(W=>W.c.id)),V=(u.screenClips??t.filter(W=>W.kind==="video"&&!d.includes(W)&&!W.motion&&!p.has(W.id)&&!Hm.test(z(W))&&s6.test(z(W))).map(W=>W.id)).map(W=>{const mt=t.find(bt=>bt.id===W);if(!mt||!["video","image"].includes(mt.kind)||mt.motion||mt.title)throw Error(`screen clip ${String(W).slice(0,40)} not found`);if(d.includes(mt))throw Error("the lesson video cannot be its own screen recording");return mt}),h=V.map(W=>[W.start,W.start+W.duration]),w=W=>{if(Vo(yt,W,W+.01))return{x:Mt.params.posX,y:Mt.params.posY-Mt.params.ph*.2,window:!0};const mt=d.find(bt=>W>=bt.start&&W<bt.start+bt.duration)??d[0];return Oc(mt,y(mt.nodeId),W,{W:r,H:a})??(k?Ie.face.portrait:Ie.face.landscape)},T=(W,mt,bt)=>{const Et=w(W);return mt<Et.y+Ie.chin&&bt>Et.y-Ie.head},C=u.captions===!0?Ct.lift:0,O=(W,mt,bt)=>T(W,mt-C,bt-C)&&!T(W,k?.08:.06,k?.3:.24)?"top":"lower",L=[],B=[],H=[],q=[],et=[...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=W=>(L.push(W),Zl.has(W.op)&&Y++,W),gt=()=>`new:${Y}`,Z=W=>{const mt=w(W),bt=mt.window?Mt.params.pw/2:Ie.halfWidth.landscape,Et=mt.x-bt-.07-.03,Ft=.93-(mt.x+bt)-.03;return Ft>=Et?{side:"right",x0:mt.x+bt+.03,w:Ft,f:mt}:{side:"left",x0:.07,w:Et,f:mt}},nt=(W,mt)=>{H.push([W,W+mt]),ct({op:"addMotion",motionPreset:"course-chapter-card",start:W,duration:mt,placement:"center",params:{text:"",sub:"",number:0,label:"",...u.theme?{bg:s.bg}:{}}})};for(const W of p)ct({op:"delete",clipId:W});for(const W of U){ct({op:"addBroll",materialId:W.m.id,start:Pt(W.a),duration:W.d,inPoint:W.inPoint});const mt=gt();ct({op:"setAnimation",clipId:mt,property:"enter",preset:"fade",duration:Ct.overhead.fade}),ct({op:"setAnimation",clipId:mt,property:"exit",preset:"fade",duration:Ct.overhead.fade}),ct({op:"speakerWindow",clipId:c.id,at:Pt(W.a),duration:W.d,numberValue:Mt.params.pw,posX:Mt.params.posX,posY:Mt.params.posY,color:s.accent});for(const bt of vl(W.a,W.a+W.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?F.map(W=>({at:W.at,end:Pt(Math.min(m,W.at+Ct.card))})):[]).forEach((W,mt)=>{const bt=F[mt];H.push([W.at,W.end]),ct({op:"addMotion",motionPreset:"course-chapter-card",start:W.at,duration:Pt(W.end-W.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=[],At=W=>Math.floor(W*30+1e-6)/30,xt=W=>Math.floor(W*1e3)/1e3,St=W=>+(+W).toFixed(4),jt=(W,mt)=>!Vo([...H,...yt,...h,...vt],W,mt),Kt=(W,mt,bt)=>At(Math.min(m-bt,Xo(Number.isFinite(+W)?+W:mt.dur,mt.min,mt.max))),ee=(W,mt)=>{H.push([W,W+mt]),et.push([W,W+mt]),vt.push([W,W+mt])},le=(W,mt)=>{ct({op:"setAnimation",clipId:W,property:"enter",preset:"fade",duration:mt}),ct({op:"setAnimation",clipId:W,property:"exit",preset:"fade",duration:mt})},xe=k?Ct.split.portrait:Ct.split.landscape,Ut=new Set;(u.split??[]).slice(0,Ct.split.maxCount).forEach((W,mt)=>{const bt=W?.clipId!=null?t.find(wb=>wb.id===W.clipId):null;if(W?.clipId!=null&&(!bt||!["video","image"].includes(bt.kind)||bt.motion||bt.title||bt.shape))throw Error(`split[${mt}] clipId must be a B-roll video or image clip`);if(bt&&d.includes(bt))throw Error("the lesson video cannot be its own split card");const Et=y(bt?bt.nodeId:W?.materialId);if(!Et||!["video","image"].includes(Et.kind)||!Et.url)throw Error(`split[${mt}] needs clipId or materialId (a video / image from Media)`);const Ft=I(W.at??bt?.start,`split[${mt}]`),Rt=Et.kind==="video"?Pt(bt?bt.inPoint||0:Xo(+W.inPoint||0,0,Math.max(0,(Et.duration||0)-1))):0;let Lt=Kt(W.duration??bt?.duration,Ct.split,Ft);if(Et.kind==="video"&&Number.isFinite(Et.duration)&&(Lt=At(Math.min(Lt,Et.duration-Rt))),Lt<Ct.split.min||!jt(Ft,Ft+Lt))return;bt&&!Ut.has(bt.id)&&(Ut.add(bt.id),ct({op:"delete",clipId:bt.id}));const[Ht,Yt,Jt,ie]=xe.m,ce=Et.width||1920,Xt=Et.height||1080,oe=z6(ce,Xt,Jt*r/(ie*a)),ne=ce*(1-oe.left-oe.right),fr=ai(ne,Xt*(1-oe.top-oe.bottom),Jt*r/ne,0,r,a);ct({op:"addBroll",materialId:Et.id,start:Ft,duration:Lt,inPoint:Rt});const uo=gt();ct({op:"courseStyle",clipId:uo,crop:oe,fit:"contain",mask:"rounded"}),ct({op:"setKeyframes",clipId:uo,motionKeys:[{time:0,x:Pt(Ht-.5),y:Pt(Yt-.5),zoom:fr},{time:xt(Lt),x:Pt(Ht-.5),y:Pt(Yt-.5),zoom:fr}]}),le(uo,Ct.split.fade);const[on,Er,mr,wa]=xe.p,ka=St(mr*r/(wa*a)),Hn=mh({W:r,H:a,width:mr,cx:on,cy:Er,aspect:ka});ct({op:"speakerWindow",clipId:c.id,at:Ft,duration:Lt,numberValue:mr,posX:on,posY:Er,aspect:ka,color:s.accent}),ct({op:"addMotion",motionPreset:"course-split-cards",start:Ft,duration:Lt,placement:"center",params:{mx:Ht,my:Yt,mw:Jt,mh:ie,px:Hn.params.posX,py:Hn.params.posY,pw:Hn.params.pw,ph:Hn.params.ph,bg:s.bg}}),ee(Ft,Lt)});for(const W of rt){const mt=W.at,bt=Kt(W.given?W.end-W.at:Math.max(Ct.compare.min,W.end-W.at+1.2),Ct.compare,mt);bt<Ct.compare.min||!jt(mt,mt+bt)||(ct({op:"addMotion",motionPreset:"course-compare-board",start:mt,duration:bt,placement:"center",params:{title:W.title,leftHead:W.left.head,leftAmount:W.left.amount,leftLines:W.left.lines.join("|"),rightHead:W.right.head,rightAmount:W.right.amount,rightLines:W.right.lines.join("|"),vs:"VS",bg:s.bg}}),ee(mt,bt))}if((u.docs??[]).slice(0,Ct.doc.maxCount).forEach((W,mt)=>{const bt=j(W?.materialId,`docs[${mt}].materialId`),Et=I(W.at,`docs[${mt}]`),Ft=Kt(W.duration,Ct.doc,Et),Rt=W.highlight;if(Rt!=null&&!(["x","y","w","h"].every(ne=>Number.isFinite(+Rt[ne]))&&Rt.x>=0&&Rt.y>=0&&Rt.w>0&&Rt.h>0&&Rt.x+Rt.w<=1.001&&Rt.y+Rt.h<=1.001))throw Error(`docs[${mt}].highlight must be {x, y, w, h} (0..1 of the document)`);if(Ft<Ct.doc.min||!jt(Et,Et+Ft))return;const Lt=bt.width||1200,Ht=bt.height||1600,Yt=Math.min(Ct.doc.w*r/Lt,Ct.doc.h*a/Ht),Jt=St(Lt*Yt/r),ie=St(Ht*Yt/a),ce=Ct.doc.cy,Xt=ai(Lt,Ht,Yt,0,r,a);ct({op:"addBroll",materialId:bt.id,start:Et,duration:Ft});const oe=gt();ct({op:"courseStyle",clipId:oe,fit:"contain"}),ct({op:"setKeyframes",clipId:oe,motionKeys:[{time:0,x:0,y:Pt(ce-.5),zoom:Xt},{time:xt(Ft),x:0,y:Pt(ce-.5),zoom:St(Xt*(1+Ct.doc.zoom*xt(Ft)/Ft))}]}),le(oe,Ct.doc.fade),ct({op:"addMotion",motionPreset:"course-doc-highlight",start:Et,duration:Ft,placement:"center",params:{cx:.5,cy:ce,cw:Jt,ch:ie,...Rt?{posX:St(.5+(+Rt.x+Rt.w/2-.5)*Jt),posY:St(ce+(+Rt.y+Rt.h/2-.5)*ie),bw:St(Rt.w*Jt),bh:St(Rt.h*ie)}:{bw:0,bh:0},text:we(W.note,30)}}),ee(Et,Ft)}),u.map){const W=u.map,mt=I(W.at,"map"),bt=W.materialId!=null?j(W.materialId,"map.materialId"):null,Et=Array.isArray(W.pins)?W.pins.slice(0,Ct.map.pins):[];if(!Et.length)throw Error(`map needs 1–${Ct.map.pins} pins [{x, y, label}]`);const Ft=Et.map((Lt,Ht)=>{let Yt=+Lt?.x,Jt=+Lt?.y;if(!(Lt?.x!=null&&Lt?.y!=null)&&!bt&&Number.isFinite(+Lt?.lat)&&Number.isFinite(+Lt?.lon)&&(Yt=(+Lt.lon+180)/360,Jt=(85-Lt.lat)/145),!(Yt>=0&&Yt<=1&&Jt>=0&&Jt<=1))throw Error(`map.pins[${Ht}] needs x, y (0..1 of the map)${bt?"":" or lat / lon"}`);if(bt){const ie=bt.width||1920,ce=bt.height||1080,Xt=Math.max(r/ie,a/ce);Yt=.5+(Yt-.5)*ie*Xt/r,Jt=.5+(Jt-.5)*ce*Xt/a}return{x:Pt(Yt),y:Pt(Jt),label:we(Lt.label,24).replace(/[|@]+/gu," ")}}).filter(Lt=>Lt.x>=0&&Lt.x<=1&&Lt.y>=0&&Lt.y<=1),Rt=Kt(W.duration,Ct.map,mt);Ft.length&&Rt>=Ct.map.min&&jt(mt,mt+Rt)&&(bt&&(ct({op:"addBroll",materialId:bt.id,start:mt,duration:Rt}),le(gt(),Ct.map.fade)),ct({op:"addMotion",motionPreset:"course-map-pins",start:mt,duration:Rt,placement:"center",params:{items:Ft.map(Lt=>`${Lt.label}@${Lt.x},${Lt.y}`).join("|"),map:bt?0:1,text:we(W.title,30),route:Ft.length>1?1:0,bg:s.bg}}),ee(mt,Rt))}const Nt=u.journey,Bt=Nt?(()=>{const W=I(Nt.at,"journey"),mt=Pt(Math.min(to.maxDuration,m-W,Number.isFinite(+Nt.duration)?Xo(+Nt.duration,Ct.journey.min,to.maxDuration):Ct.journey.dur));return mt>=Ct.journey.min?{a:W,d:mt,avatar:Nt.avatarMaterialId!=null?j(Nt.avatarMaterialId,"journey.avatarMaterialId"):null,from:Xo(Number.isFinite(+Nt.from)?+Nt.from:0,0,1),to:Xo(Number.isFinite(+Nt.to)?+Nt.to:1,0,1),labels:(Array.isArray(Nt.labels)?Nt.labels:[]).map(bt=>we(bt,22)).filter(Boolean).slice(0,6),text:we(Nt.text,32)}:null})():null,_t=Bt?[Bt.a,Bt.a+Bt.d]:null,de=it==="chapters"?F.map(W=>({at:W.at,text:W.title,badge:st.ch,n:W.number})):it==="questions"?Q.map((W,mt)=>({at:W.at,text:W.text,badge:st.q,n:W.number??mt+1})):it==="steps"?G.map(W=>({at:W.at,text:W.labels[W.current-1],badge:st.step,n:W.current,total:W.labels.length})):[],re=Math.max(1,...de.map(W=>W.n)),ye=de.slice(1).map(W=>Pt((W.at-f)/g)).filter(W=>W>0&&W<1).slice(0,40).join("|");if(de.forEach((W,mt)=>{const bt=H.find(([Ht,Yt])=>W.at>=Ht-.05&&W.at<Yt),Et=Pt(bt?bt[1]+.1:W.at),Ft=de[mt+1]?.at??m,Rt=Pt(Math.min(Ct.nav.dur,Ft-.15-Et,m-Et));if(Rt<Ct.nav.min)return;B.push([Et,Et+Rt]);const Lt=_t&&Vo([_t],Et,Et+Rt)?"top":O(Et+Rt/2,k?.62:.68,k?.8:.9);ct({op:"addMotion",motionPreset:"course-question-nav",start:Et,duration:Rt,text:we(W.text,90),numberValue:W.n,placement:Lt,params:{sub:W.badge,total:W.total??re,lift:C}}),u.progress!==!1&&it!=="steps"&&ct({op:"addMotion",motionPreset:"course-progress-bar",start:Et,duration:Rt,params:{from:Pt(Xo((Et-f)/g,0,1)),to:Pt(Xo((Et+Rt-f)/g,0,1)),ticks:ye,text:"",position:Lt==="top"||w(Et+Rt/2).y-Ie.head<.16?"lower":"top"}})}),it!=="steps")for(const W of G)Vo(B,W.at,W.at+W.duration)||Vo(H,W.at,W.at+W.duration)||_t&&Vo([_t],W.at,W.at+W.duration)||(B.push([W.at,W.at+W.duration]),ct({op:"addMotion",motionPreset:"course-step-tiles",start:W.at,duration:W.duration,items:W.labels,numberValue:W.current,placement:O(W.at+W.duration/2,k?.7:.78,k?.8:.92),params:{lift:C}}));if(Bt){const{a:W,d:mt}=Bt,bt=T(W+mt/2,.74,.86),Et=Pt(bt?.2:.8-C*.6),Ft=A*(k?Ct.journey.r.portrait:Ct.journey.r.landscape),Rt=k?.075:.07,Lt=1-Rt,Ht=Yt=>Pt(Rt+(Lt-Rt)*Yt-.5);if(Bt.avatar){const Yt=Bt.avatar,Jt=Yt.width||1e3,ie=Yt.height||1e3,ce=Ct.journey.delay,Xt=Pt(2*Ft/A),oe=Pt(mt-ce),ne=Pt(Ct.journey.a-ce),fr=Pt(Math.max(ne+.1,mt-Ct.journey.b-ce));ct({op:"addElement",materialId:Yt.id,start:Pt(W+ce),duration:oe,posX:Ht(Bt.from),posY:Pt(Et-.5),scale:.25,anim:{in:"pop",out:"fade",loop:"none"}});const uo=gt();ct({op:"courseStyle",clipId:uo,crop:Xm(Jt,ie),mask:"circle"}),ct({op:"setKeyframes",clipId:uo,motionKeys:[{time:0,x:Ht(Bt.from),y:Pt(Et-.5),zoom:Xt},{time:ne,x:Ht(Bt.from),y:Pt(Et-.5),zoom:Xt},{time:fr,x:Ht(Bt.to),y:Pt(Et-.5),zoom:Xt},{time:oe,x:Ht(Bt.to),y:Pt(Et-.5),zoom:Xt}]})}ct({op:"addMotion",motionPreset:"course-journey-line",start:W,duration:mt,placement:"lower",...Bt.text?{text:Bt.text}:{},...Bt.labels.length?{items:Bt.labels}:{},params:{from:Bt.from,to:Bt.to,posY:Et,ring:Bt.avatar?1:0,glyph:"user",...Bt.labels.length?{}:{items:""}}}),B.push([W,W+mt]),et.push([W,W+mt])}for(const W of _){const mt=W.items.filter(Xt=>Xt.at<m-.5),bt=mt.length;if(bt<Ct.framework.min)continue;const Et=mt.map(Xt=>Xt.icon||Ni(`${Xt.title} ${Xt.sub}`)),Ft=Et.every(Boolean)?Et:mt.map(Xt=>Xt.icon),Rt=Xt=>mt.map((oe,ne)=>`${Ft[ne]?Ft[ne]+":":""}${oe.title}${oe.sub?" — "+oe.sub.slice(0,Xt):""}`.replace(/[|]+/gu," ")).join("|");let Lt=30;for(;Rt(Lt).length>290&&Lt>0;)Lt-=4;const Ht=[];mt.forEach((Xt,oe)=>{const ne=Ht.at(-1);ne&&Xt.at-mt[oe-1].at<=Ct.framework.gap?ne.last=oe:Ht.push({first:oe,last:oe})});const Yt=[...H,...q],Jt=Z((W.at+mt.at(-1).at)/2),ie=Math.min(Ct.framework.w,Jt.w/(1+.08*(bt-1))),ce=!k&&ie<Ct.framework.minW;for(const Xt of Ht){const oe=Pt(Xt.first===0?W.at:mt[Xt.first].at-Ct.framework.lead),ne=Pt(Math.min(m,mt[Xt.last].at+Ct.framework.hold,(mt[Xt.last+1]?.at??1/0)-Ct.framework.lead-.1));if(ne-oe<Ct.framework.min||Vo(Yt,oe,ne))continue;ce&&nt(oe,Pt(ne-oe));const fr=Vo(B,oe,ne)?.44:.5;for(const uo of vl(oe,ne)){const on=mt.map((Er,mr)=>mr<Xt.first?-1:mr>Xt.last?999:Pt(Er.at-uo.start)).join("|");ct({op:"addMotion",motionPreset:"course-framework-stack",start:uo.start,duration:uo.duration,placement:"center",...W.title?{text:W.title}:{},params:{items:Rt(Lt),at:on,fade:uo.fade,...W.title?{}:{text:""},...ce?{position:"left",posX:.5,posY:.5,width:.3}:{position:k?"left":Jt.side,...k?{}:{width:Pt(ie),posY:fr}}}})}q.push([oe,ne]),et.push([oe,ne])}}const or=(u.photos??[]).slice(0,Ct.photo.maxCount).map((W,mt)=>({at:I(W?.at,`photos[${mt}]`),m:j(W?.materialId,`photos[${mt}].materialId`),scribble:W?.scribble===!0})).sort((W,mt)=>W.at-mt.at),$r=[];for(const W of or){const mt=$r.at(-1);mt&&!W.scribble&&!mt[0].scribble&&mt.length<3&&W.at-mt[0].at<Ct.photo.group?mt.push(W):$r.push([W])}if($r.forEach((W,mt)=>{const bt=W[0].at,Et=Pt(Math.min(m,W.at(-1).at+Ct.photo.dur,($r[mt+1]?.[0].at??1/0)-.15));if(Et-bt<Ct.photo.min||Vo([...H,...q],bt,Et))return;let Ft=Z((bt+Et)/2),Rt=!1;const Lt=W.length,Ht=Ct.photo.size[Lt-1]*a,Yt=Math.min(Ht,Ft.w*r/Lt*.86);(Yt<Ct.photo.minSize*a||W[0].scribble&&Ft.w<.22)&&(Rt=!0,Ft={side:"right",x0:.15,w:.7}),Rt&&nt(bt,Pt(Et-bt)),W.forEach((Jt,ie)=>{const ce=Jt.m,Xt=ce.width||1e3,oe=ce.height||1e3,ne=Ft.x0+Ft.w*(ie+.5)/Lt,fr=(k?.36:.42)+(Lt>1?ie%2?.05:-.03:0),uo=Ct.photo.rot[ie%3]*(Ft.side==="left"?-1:1),on=Pt(Et-Jt.at);if(!(on<1))if(Jt.scribble){const Er=Math.min(a*(k?.36:.5),Ft.w*r*.9*oe/Xt),mr=ai(Xt,oe,Er/oe,uo,r,a),wa=Er*Xt/oe,ka=Pt(Math.max(wa/2/.74,Er/2/.68)*1.06/A);ct({op:"addElement",materialId:ce.id,start:Jt.at,duration:on,posX:Pt(ne-.5),posY:Pt(fr-.5),scale:Math.max(.25,mr),anim:{in:"pop",out:"fade",loop:"none"}});const Hn=gt();mr<.25&&ct({op:"setKeyframes",clipId:Hn,motionKeys:[{time:0,x:Pt(ne-.5),y:Pt(fr-.5),zoom:mr}]}),ct({op:"collageStyle",clipId:Hn,sticker:"white",cutout:"person"}),ct({op:"courseStyle",clipId:Hn,rotation:uo}),ct({op:"addMotion",motionPreset:"course-photo-pop",start:Jt.at,duration:on,placement:"center",params:{tile:0,scribble:1,posX:Pt(ne),posY:Pt(fr),size:ka,rot:uo,text:""}})}else{const Er=Math.min(Xt,oe),mr=Rt?Ht:Yt,wa=ai(Er,Er,mr/Er,uo,r,a);ct({op:"addElement",materialId:ce.id,start:Jt.at,duration:on,posX:Pt(ne-.5),posY:Pt(fr-.5),scale:Math.max(.25,wa),anim:{in:"pop",out:"fade",loop:"none"}});const ka=gt();wa<.25&&ct({op:"setKeyframes",clipId:ka,motionKeys:[{time:0,x:Pt(ne-.5),y:Pt(fr-.5),zoom:wa}]}),ct({op:"courseStyle",clipId:ka,crop:Xm(Xt,oe),rotation:uo,shadow:!0}),ct({op:"addMotion",motionPreset:"course-photo-pop",start:Jt.at,duration:on,placement:"center",params:{tile:1,scribble:0,posX:Pt(ne),posY:Pt(fr),size:Pt(mr/A),rot:uo,text:""}})}}),q.push([bt,Et]),et.push([bt,Et])}),u.cover){const W=u.cover,mt=j(W.materialId,"cover.materialId"),bt=I(W.at,"cover"),Et=Pt(Math.min(m-bt,Number.isFinite(+W.duration)?Xo(+W.duration,Ct.cover.min,to.maxDuration):Ct.cover.dur));if(Et>=Ct.cover.min&&!Vo([...H,...q],bt,bt+Et)){let Ft=Z(bt+Et/2);const Rt=mt.width||800,Lt=mt.height||1200;let Ht=Math.min(a*(k?.4:Ct.cover.size),Ft.w*r*.85*Lt/Rt);Ht<a*.28&&(Ft={side:"right",x0:.2,w:.6},nt(bt,Et),Ht=a*Ct.cover.size);const Yt=Ft.x0+Ft.w/2,Jt=k?.36:.46,ie=Ft.side==="right"?-Ct.cover.rot:Ct.cover.rot,ce=ai(Rt,Lt,Ht/Lt,ie,r,a);ct({op:"addElement",materialId:mt.id,start:bt,duration:Et,posX:Pt(Yt-.5),posY:Pt(Jt-.5),scale:Math.max(.25,ce),anim:{in:"pop",out:"fade",loop:"none"}});const Xt=gt();ce<.25&&ct({op:"setKeyframes",clipId:Xt,motionKeys:[{time:0,x:Pt(Yt-.5),y:Pt(Jt-.5),zoom:ce}]}),ct({op:"courseStyle",clipId:Xt,rotation:ie,shadow:!0}),ct({op:"addMotion",motionPreset:"course-cover-insert",start:bt,duration:Et,placement:"center",params:{cover:1,text:"",sub:we(W.title,28),posX:Pt(Yt),posY:Jt,size:Pt(Ht/a),aspect:Pt(Rt/Lt),rot:ie}}),q.push([bt,bt+Et]),et.push([bt,bt+Et])}}const Br=W=>w(W).x>=.5?"left":"right";for(const W of tt){const mt=Pt(Math.min(W.duration,m-W.at));if(mt<Ct.tool.min||Vo([...H,...q],W.at,W.at+mt))continue;const bt=w(W.at+mt/2),Et=Br(W.at+mt/2),Ft=k?bt.y-Ie.head>.19?`top-${Et}`:`bottom-${Et}`:Et;ct({op:"addMotion",motionPreset:"course-tool-badge",start:W.at,duration:mt,text:W.label,...W.url?{subText:W.url}:{},icon:W.icon,params:{position:Ft,...k?{}:{posY:Pt(Xo(bt.y-.02,.2,.6))}}})}F.forEach((W,mt)=>{if(!W.takeaways.length)return;const bt=F[mt+1]?.at??m,Et=Pt(Math.max(W.at+1,bt-Ct.takeaway-.2)),Ft=Pt(Math.min(Ct.takeaway,bt-.1-Et));if(Ft<2||Vo([...H,...q],Et,Et+Ft))return;const Rt=w(Et+Ft/2),Lt=Ie.halfWidth.landscape,Ht=.93-(Rt.x+Lt)-.02,Yt=Rt.x-Lt-.07-.02,Jt=Math.min(.34,Math.max(Ht,Yt)),ie={op:"addMotion",motionPreset:"course-key-takeaway",start:Et,duration:Ft,text:st.take,items:W.takeaways};if(k){ct({...ie,params:{position:"lower"}});return}if(Jt>=.26){ct({...ie,params:{position:Ht>=Yt?"right":"left",width:Pt(Jt)}});return}nt(Et,Ft),ct({...ie,params:{position:"center",width:.5}})});const zo=u.labels?u.labels.slice(0,20).map((W,mt)=>{const bt=we(W?.title,28);if(!bt)throw Error(`labels[${mt}] needs title`);return{at:I(W?.at,`labels[${mt}]`),title:bt,sub:we(W?.sub,40),icon:bp(W?.icon)?W.icon:Ni(`${bt} ${W?.sub??""}`)||"flag"}}):v6($).filter(W=>v(W.at)).map(W=>({at:W.at,title:st.prev,sub:W.sub,icon:"play"}));for(const W of zo){const mt=Pt(Math.min(Ct.label.dur,m-W.at));if(mt<2||Vo(H,W.at,W.at+mt))continue;const bt=w(W.at+mt/2),Et=bt.window||bt.x>=.5?"left":"right",Ft=!Vo([...B,...q],W.at,W.at+mt)&&!T(W.at+mt/2,.76,.88),Rt=Math.max(A*.085,Math.min(A*.13,r*Ct.label.w*.27))/a;ct({op:"addMotion",motionPreset:"course-label-tag",start:W.at,duration:mt,text:W.title,...W.sub?{subText:W.sub}:{},icon:W.icon,params:{position:`${Ft?"lower":"top"}-${Et}`,...Ft&&C?{posY:Pt((k?.8:.86)-C-Rt/2)}:{}}})}const Ze=k?Ct.screen.portrait:Ct.screen.landscape;for(const W of V){const mt=y(W.nodeId),bt=mt?.width&&mt?.height?mt.width/mt.height:16/9,Et=r/a,Ft=W.fit==="cover",Rt=bt>Et!==Ft?r:a*bt,Lt=bt>Et!==Ft?r/bt:a,Ht=Pt(Math.min(Ze.w*r/Rt,Ze.h*a/Lt)),Yt=Pt(Ht*Rt/r),Jt=Pt(Ht*Lt/a),ie=Pt(Ze.cy-.5),ce=tt.find(Xt=>Xt.url&&Xt.at>=W.start-3&&Xt.at<W.start+W.duration)?.url??"";ct({op:"setKeyframes",clipId:W.id,motionKeys:[{time:0,x:0,y:ie,zoom:Ht},{time:Pt(W.duration),x:0,y:ie,zoom:Ht}]}),ct({op:"setAnimation",clipId:W.id,property:"enter",preset:"fade",duration:Ct.fade}),ct({op:"setAnimation",clipId:W.id,property:"exit",preset:"fade",duration:Ct.fade});for(const Xt of vl(W.start,W.start+W.duration))ct({op:"addMotion",motionPreset:"course-screen-frame",start:Xt.start,duration:Xt.duration,placement:"center",params:{cw:Yt,ch:Jt,cy:Ze.cy,text:ce,fade:Xt.fade,...u.theme?{bg:s.screenBg}:{}}})}if(u.captions===!0&&(y(c.nodeId)?.transcript?.length||c.captions?.length)&&ct({op:"addSocialCaptions",clipId:c.id,captionStyle:"lesson",...u.theme&&u.theme!=="blue"?{color:s.accent}:{}}),u.punchIns!==!1&&$.length){const W=$.map(Et=>({start:Et.start,end:Et.start+.3,word:String(Et.words[0].word),kw:Et.gap>=.4})),mt=Math.max(0,i-L.length),bt=oy(W,{every:Ct.punch.every,max:Math.min(Ct.punch.maxCount,mt),lead:.04,from:f+1});for(const Et of bt){const Ft=$.find(Lt=>Math.abs(Lt.start-Et.at)<.1)??$.find(Lt=>Lt.start>=Et.at),Rt=Pt(Math.min(Ct.punch.max,Math.max(.8,(Ft?Ft.end:Et.at+2)-Et.at)));Et.at+Rt>m-.1||Vo([...H,...h,...et],Et.at,Et.at+Rt)||!d.some(Lt=>Et.at>=Lt.start&&Et.at+Rt<=Lt.start+Lt.duration)||ct({op:"punchIn",clipId:c.id,at:Pt(Et.at),duration:Rt,numberValue:Ct.punch.amount,punchStyle:"cut",accent:!1})}}const vo=u.brand===!0?qg(l):null;if(vo){const W=w(f+g/2),mt=Ie.halfWidth[k?"portrait":"landscape"]??Ie.halfWidth.landscape,[bt,Et]=Ct.brand.margin,Ft=W.x+mt>1-bt-Ct.brand.maxW&&W.y-Ie.head<Et+Ct.brand.h+.02,Rt=vo.logoMaterialId?y(vo.logoMaterialId):null;if(Rt?.kind==="image"&&Rt.url){const Lt=Rt.width||600,Ht=Rt.height||600,Yt=Math.min(Ct.brand.h*a/Ht,Ct.brand.maxW*r/Lt),Jt=ai(Lt,Ht,Yt,0,r,a),ie=Ft?bt+Lt*Yt/r/2:1-bt-Lt*Yt/r/2,ce=Et+Ht*Yt/a/2;ct({op:"addElement",materialId:Rt.id,start:f,duration:At(m-f),posX:Pt(ie-.5),posY:Pt(ce-.5),scale:Math.max(.25,Jt),anim:{in:"fade",out:"fade",loop:"none"}});const Xt=gt();Jt<.25&&ct({op:"setKeyframes",clipId:Xt,motionKeys:[{time:0,x:Pt(ie-.5),y:Pt(ce-.5),zoom:Jt}]})}else if(vo.name)for(const Lt of vl(f,m))ct({op:"addMotion",motionPreset:"course-brand-bug",start:Lt.start,duration:Lt.duration,placement:"top",text:we(vo.name,40),params:{fade:Lt.fade,position:Ft?"top-left":"top-right"}})}for(const W of L)W.op==="addMotion"&&(W.color||(W.color=s.accent),s.look&&(W.params={...W.params,look:s.look}));return L.length>i?L.filter(W=>W.op!=="punchIn").slice(0,i):L}function L6(t,{clips:e=[],materials:o=[],W:r=1280,H:a=720,en:n=null,maxOps:i=1/0,simulate:l=null,brand:u=null}={}){if(!Array.isArray(t)||!t.some(m=>m?.op==="courseEdit"&&!m.error))return t;const c=[],s=[];let d=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 $ of s)v>$.after&&(x+=$.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){c.push(g),Zl.has(g?.op)&&d++;continue}let v=e;if(l&&c.some(x=>["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"].includes(x?.op)))try{v=l([...c])??e}catch{v=e}try{const x=P6({clips:v,materials:o,op:g,W:r,H:a,en:n,maxOps:Math.max(1,i-t.length),brand:u}),$=x.filter(k=>Zl.has(k.op)).length,E=c.filter(k=>Zl.has(k?.op)).length,S=k=>{const y=typeof k=="string"&&/^new:(\d+)$/.exec(k);return y?`new:${+y[1]+E}`:k};c.push(...x.map(k=>typeof k.clipId=="string"?{...k,clipId:S(k.clipId)}:k)),$&&s.push({after:d,by:$})}catch(x){c.push({op:"courseEdit",error:String(x?.message||x).slice(0,300)})}}return c}const Nn=(t,e,o)=>Math.max(e,Math.min(o,t)),ur=t=>+(+t).toFixed(4),La=t=>+(+t).toFixed(3),N6=new Function("return "+Tg)(),Qh=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]}),F6=Object.fromEntries(Object.entries(Qh).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;"+lw(o)+"const "+cw[e]+",r="+pw+";return {x:wx,y:wy,w:ww,h:wh,r:Math.min(r,ww/2,wh/2)}")]));function Nc(t,e,o){const r=F6[t];return r?r(N6,{width:e,height:o}):null}const Um=(t,e,o)=>({x:ur(t.x/e),y:ur(t.y/o),w:ur(t.w/e),h:ur(t.h/o),r:ur(t.r/Math.min(e,o))});Object.freeze(Object.fromEntries(Object.keys(Qh).map(t=>[t,Object.freeze({landscape:Um(Nc(t,1920,1080),1920,1080),portrait:Um(Nc(t,1080,1920),1080,1920)})])));const Ym=Object.freeze(["full","center","left","right","small","corner"]),lo=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}})}),iy=(t,e)=>e>t*1.1;function sy(t,e,o){const r=iy(e,o),a=Math.min(e,o);if(t==="full")return{x:0,y:0,w:e,h:o,r:0};if(lo.scenes[t])return Nc(lo.scenes[t][r?1:0],e,o);if(t==="corner"){const n=a*.028;if(r){const s=lo.corner.portrait,d=e*s.w,f=d/s.aspect;return{x:e-e*.06-d,y:o*s.bottom-f,w:d,h:f,r:n}}const i=lo.corner.landscape,l=e*i.w,u=l*o/e,c=i.margin*a;return{x:e-c-l,y:o-c-u,w:l,h:u,r:n}}if(typeof t=="string"&&/^fr-/.test(t)){const n=Nc(t,e,o);if(n)return n;throw Error(`${t.slice(0,40)} has no speaker window — use ${Ym.join(" / ")} or a window scene (${Object.keys(Qh).filter(i=>!i.startsWith("fr-v-")).join(", ")})`)}throw Error(`layout must be ${Ym.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 R6=t=>t!=="full",D6=t=>1-Math.pow(1-t,3),ii=(t,e,o)=>t+(e-t)*o;function B6(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:Nn(r.subjectX,0,1),y:Number.isFinite(r.subjectY)?Nn(r.subjectY,0,1):.42}:null}function ly(t,{W:e,H:o,morph:r=lo.morph}={}){if(!Array.isArray(t)||!t.length)throw Error("needs beats [{start, end, layout}]");if(t.length>lo.maxBeats)throw Error(`at most ${lo.maxBeats} beats`);const a=Number.isFinite(+r)?Nn(+r,0,lo.maxMorph):lo.morph,n=t.map((i,l)=>{if(!i||typeof i!="object")throw Error(`beats[${l}] must be an object`);const u=+i.start,c=+i.end;if(!Number.isFinite(u)||!Number.isFinite(c)||u<0)throw Error(`beats[${l}] needs start and end (timeline s)`);if(c-u<lo.minBeat)throw Error(`beats[${l}]: end must be at least ${lo.minBeat} s after start`);if(i.zoom!=null&&!(Number.isFinite(+i.zoom)&&+i.zoom>=1&&+i.zoom<=lo.zoomMax))throw Error(`beats[${l}].zoom must be 1–${lo.zoomMax}`);if(i.morph!=null&&!(Number.isFinite(+i.morph)&&+i.morph>=0&&+i.morph<=lo.maxMorph))throw Error(`beats[${l}].morph must be 0–${lo.maxMorph} s`);let s;try{s=sy(i.layout??"full",e,o)}catch(d){throw Error(`beats[${l}]: ${d.message}`)}return{i:l,start:ft(u),end:ft(c),layout:i.layout??"full",rect:s,zoom:i.zoom!=null?+i.zoom:1,morph:i.morph!=null?+i.morph:a}}).sort((i,l)=>i.start-l.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 _6(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],l=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 c=D6(Nn((e-i.start)/u,0,1)),s=l.rect,d=i.rect;return{rect:{x:ii(s.x,d.x,c),y:ii(s.y,d.y,c),w:ii(s.w,d.w,c),h:ii(s.h,d.h,c),r:ii(s.r,d.r,c)},zoom:ii(l.zoom,i.zoom,c)}}function G6(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),l=a.rect,u=n.rect;(Math.abs(l.x-u.x)+Math.abs(l.y-u.y)+Math.abs(l.w-u.w)+Math.abs(l.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 K6(t,{rect:e,zoom:o},{W:r,H:a,mw:n,mh:i,face:l}){const u=t.fit==="cover"?Math.max(r/n,a/i):Math.min(r/n,a/i),c=n*u,s=i*u,d=e.w/e.h;let f=d<=n/i?i:n/d,m=f*d;f/=o,m/=o;const g=l?.x??.5,v=l?.y??(n<=i?.36:.42),x=Nn(g*n,m/2,n-m/2),$=Nn(v*i+f*.08,f/2,i-f/2),E=e.w/(m*u),S=t.flipX?-1:1,k=t.flipY?-1:1,y=(e.x+e.w/2-r/2-S*E*(x/n-.5)*c)/r,A=(e.y+e.h/2-a/2-k*E*($/i-.5)*s)/a,I=1/(E*u),z=.02*Math.min(r,a)*I,j=e.x<=.5?z:0,P=e.y<=.5?z:0,N=e.x+e.w>=r-.5?z:0,F=e.y+e.h>=a-.5?z:0,K=(x-m/2-j)/n,_=(x+m/2+N)/n,J=($-f/2-P)/i,X=($+f/2+F)/i,rt=Math.min(e.r*I,m/2,f/2),ot=rt/n,G=rt/i,tt=.5523*ot,Q=.5523*G,it=ht=>ur(Nn(ht,-1,2)),D=ht=>ur(Nn(ht,-1,1)),U=[[K+ot,J,-tt,0,0,0],[_-ot,J,0,0,tt,0],[_,J+G,0,-Q,0,0],[_,X-G,0,0,0,Q],[_-ot,X,tt,0,0,0],[K+ot,X,0,0,-tt,0],[K,X-G,0,Q,0,0],[K,J+G,0,0,0,-Q]].map(ht=>[it(ht[0]),it(ht[1]),D(ht[2]),D(ht[3]),D(ht[4]),D(ht[5])]);return{x:ur(y),y:ur(A),zoom:ur(E),pts:U}}function V6(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 W6(t,e,{beats:o,morph:r,W:a=1280,H:n=720,material:i=null}={}){const l=V6(t,e),u=ly(o,{W:a,H:n,morph:r}),c=l[0].start,s=l.at(-1).start+l.at(-1).duration;if(u[0].start>=s-1e-6||u.at(-1).end<=c+1e-6)throw Error("beats must fall inside the speaker clip");const d=Math.round(i?.width)||(a<=n?1080:1920),f=Math.round(i?.height)||(a<=n?1920:1080),m=G6(u,a,n),g=new Map;for(const v of l){const x=v.start,$=v.start+v.duration,E=m.filter(([P,N])=>N>x-1e-6&&P<$+1e-6);if(!(u.some(P=>P.start<$&&P.end>x)||E.length||u[0].start<$))continue;const S=Nn(Math.floor((lo.keysMax-2)/Math.max(1,E.length*2))-1,2,8),k=new Set([0,La(v.duration)]);for(const[P,N]of E){if(P-x>1/30&&k.add(La(P-x)),N>P)for(let F=0;F<=S;F++){const K=P+(N-P)*F/S;K>x&&K<$&&k.add(La(K-x))}N-x<v.duration&&k.add(La(Math.max(0,N-x))),N<=P&&P-x>1/30&&k.add(La(Math.max(0,P-x-1/30)))}const y=v.playbackRate||1,A=P=>(v.inPoint||0)+P*y,z=[...k].filter(P=>P>=0&&P<=v.duration+1e-6).sort((P,N)=>P-N).map(P=>{const N=_6(u,v.start+P,a,n);return{t:P,...K6(v,N,{W:a,H:n,mw:d,mh:f,face:B6(i,A(P))})}});let j={...v,...en(v)};for(const P of["sx","sy","ax","ay","rot"])Ee(j,P).length&&(j={...j,motionKeys:tn(j,P,[])});for(const P of["x","y","zoom"])j={...j,motionKeys:tn(j,P,z.map(N=>({time:N.t,value:N[P]})))};if(j.motionKeys.length>uw)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:d,mh:f,masks:[{id:"m1",name:"Khung người nói",mode:"add",feather:lo.maskFeather,smooth:!1,keys:H6(z.map(P=>({t:La(Math.min(P.t,v.duration)),pts:P.pts})))}]},j.speakerLayout={beats:u.filter(P=>P.start<$&&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 H6(t){const e=(o,r)=>o.pts.every((a,n)=>a.every((i,l)=>i===r.pts[n][l]));return t.filter((o,r)=>!(r>0&&r<t.length-1&&e(o,t[r-1])&&e(o,t[r+1])))}const X6=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),td=(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))}},U6=/^#[0-9a-f]{6}$/i;function Y6(t,e,{W:o,H:r}){const a=iy(o,r),n=[],i=U6.test(String(t.accent??""))?t.accent:null;if(t.frame!=null&&t.frame!=="brackets"&&t.frame!=="none")throw Error("frame must be brackets or none");for(const l of e){const u=t.beats[l.i],c=u.motion,s=La(Math.min(l.end-l.start,to.maxDuration));if(c!=null){if(typeof c!="object"||Array.isArray(c))throw Error(`beats[${l.i}].motion must be an object`);const d=c.preset??c.motionPreset??(typeof l.layout=="string"&&l.layout.startsWith("fr-")?l.layout:null);if(!d)throw Error(`beats[${l.i}].motion needs preset (a layout like "${l.layout}" names no scene)`);const{preset:f,motionPreset:m,...g}=c;n.push({op:"addMotion",motionPreset:d,start:l.start,duration:s,...g,...i&&!g.color?{color:i}:{}})}else if(t.frame==="brackets"&&R6(l.layout)){const d=l.rect;n.push({op:"addMotion",motionPreset:a?"fr-v-window":"fr-window",start:l.start,duration:s,...i?{color:i}:{},params:{bg:!1,text:typeof u.label=="string"?u.label.slice(0,40):"",sub:"",wx:ur(d.x/o),wy:ur(d.y/r),ww:ur(d.w/o),wh:ur(d.h/r)}})}}return n}function q6(t,{W:e=1280,H:o=720}={}){if(!Array.isArray(t)||!t.some(l=>l?.op==="speakerLayout"&&!l.error))return t;const r=[],a=[];let n=0;const i=l=>{const u=typeof l=="string"&&/^new:(\d+)$/.exec(l);if(!u)return l;const c=+u[1];let s=0;for(const d of a)c>d.after&&(s+=d.by);return`new:${c+s}`};for(const l of t){const u=l&&typeof l=="object"?{...l,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(c=>typeof l[c]=="string").map(c=>[c,i(l[c])])),...Array.isArray(l.clipIds)?{clipIds:l.clipIds.map(i)}:{}}:l;if(u?.op!=="speakerLayout"||u.error){r.push(u),X6.has(u?.op)&&n++;continue}try{const c=td(u,"speakerLayout");if(c.frame!=null&&c.frame!=="brackets"&&c.frame!=="none")throw Error("frame must be brackets or none");if(!(c.frame==="brackets"||Array.isArray(c.beats)&&c.beats.some($=>$&&$.motion!=null))){r.push(u);continue}const d=ly(c.beats,{W:e,H:o,morph:c.morph}),f=Y6(c,d,{W:e,H:o}),{frame:m,accent:g,prompt:v,...x}=c;r.push({...x,op:"speakerLayout",beats:c.beats.map($=>{const{motion:E,label:S,...k}=$;return k})},...f),f.length&&a.push({after:n,by:f.length})}catch(c){r.push({op:"speakerLayout",error:String(c?.message||c).slice(0,300)})}}return r}const fo=t=>+(+t).toFixed(3),qm=(t,e,o)=>Math.max(e,Math.min(o,t)),Fc=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}*/]+/gu,"").trim(),un=(t,e)=>typeof t=="string"?t.replace(/\s+/gu," ").trim().slice(0,e):"",Z6=/^#[0-9a-f]{6}$/i,Jl=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"}}),J6=Object.freeze(Object.keys(Jl)),no=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 Q6(t,e,o=0){const r=String(e??"").split(/\s+/u).map(Fc).filter(Boolean);if(!r.length)return null;const a=t.map(u=>Fc(u.word)),n=(u,c)=>u===c||c.length>2&&u.startsWith(c)||u.length>2&&c.startsWith(u),i=u=>{for(let c=u;c<=a.length-r.length;c++)if(r.every((s,d)=>n(a[c+d],s)))return[c,c+r.length-1];return null},l=i(o)??i(0);if(l)return l;for(const u of[o,0])for(let c=u;c<a.length;c++)if(n(a[c],r[0])){for(let s=c+1;s<Math.min(a.length,c+r.length+3);s++)if(n(a[s],r.at(-1)))return[c,s]}return null}function cy(t,e,o,r){const a=e.filter(c=>c.start>=o-.1&&c.start<r),n=t.map(c=>{const s=String(c),d=s.indexOf(":");return Fc((d>0&&!/\s/.test(s.slice(0,d))?s.slice(d+1):s).split(/\s+/u)[0])});let i=0;const l=n.map(c=>{for(let s=i;s<a.length;s++){const d=Fc(a[s].word);if(c&&(d===c||c.length>2&&d.startsWith(c)||d.length>2&&c.startsWith(d)))return i=s+1,fo(Math.max(0,a[s].start-o))}return null});if(l.every(c=>c===null))return null;for(let c=0;c<l.length;c++)if(l[c]===null){let s=c-1;for(;s>=0&&l[s]===null;)s--;let d=c+1;for(;d<l.length&&l[d]===null;)d++;const f=s>=0?l[s]:null,m=d<l.length?l[d]:null;l[c]=fo(f!==null&&m!==null?f+(m-f)*(c-s)/(d-s):f!==null?f+.4*(c-s):Math.max(0,m-.4*(d-c)))}let u=0;return l.map(c=>{const s=fo(Math.max(u,c));return u=s+.05,s})}const tE=t=>String(t??"").split("/").flatMap(e=>e.split(" ").filter(Boolean)).map(e=>e.replace(/[*]/g,"")).filter(Boolean);function Zm(t,e,o,r,a=0){const n=cy(tE(t),e,o,r);if(!n)return null;let i=0;return n.map(l=>{const u=fo(Math.max(a,i,l));return i=u+.05,u})}const eE=["label","caret","total","position","times"];function oE(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=un(String(t.text),120));const o=t.sub??t.subText;o!=null&&(e.subText=un(String(o),160)),Array.isArray(t.items)&&(e.items=t.items.filter(n=>typeof n=="string").map(n=>un(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(eE.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 rE({clips:t=[],materials:e=[],op:o={},W:r=1280,H:a=720}={}){const n=td(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&&!Z6.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>no.maxBeats)throw Error(`at most ${no.maxBeats} beats`);const l=n.aspect?n.aspect==="9:16":a>r*1.1,u=j=>j&&l?j.replace(/^fr-/,"fr-v-"):j,c=n.accent?String(n.accent).toLowerCase():no.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),d=s[0].start,f=s.at(-1).start+s.at(-1).duration,m=Jh(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(!Jl[j.kind])throw Error(`beats[${P}].kind must be ${J6.join(" / ")}`);let N=j.start!=null?+j.start:null,F=null;if(j.start!=null&&!Number.isFinite(N))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 _=Q6(m,j.say,g);if(!_)throw Error(`beats[${P}].say "${un(String(j.say),60)}" is not in the transcript`);F={start:m[_[0]].start,end:m[_[1]].end,first:_[0]},g=_[1]+1,N===null&&(N=Math.max(d,F.start-no.lead))}if(N===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 K;try{K=oE(j.fields)}catch(_){throw Error(`beats[${P}].${_.message}`)}return{i:P,kind:j.kind,start:fo(qm(N,d,f)),end:j.end!=null?+j.end:null,said:F,fields:K}}).sort((j,P)=>j.start-P.start);if(v[0].start-d<no.snap&&(v[0].start=fo(d)),n.flavor==="course"&&n.instructor&&typeof n.instructor=="object"&&un(n.instructor.name,60)&&!v.some(j=>j.kind==="lowerThird")){const j=d+.3,P=Math.min(d+.3+no.lower.dur,v[0].start);P-j>=no.lower.min&&v.unshift({i:-1,kind:"lowerThird",start:fo(j),end:fo(P),said:null,fields:{text:un(n.instructor.name,60),...un(n.instructor.role,80)?{subText:un(n.instructor.role,80)}:{},...un(n.instructor.label,24)?{params:{label:un(n.instructor.label,24)}}:{}}})}const x=v.map((j,P)=>{const N=v[P+1],F=N?N.start:f;let K=j.end!==null?Math.min(j.end,F):N?N.start:Math.min(f,(j.said?.end??j.start+3)+no.tail);if(K=fo(Math.min(K,f)),K-j.start<no.minBeat-1e-6)throw Error(`beats[${j.i}] (${j.kind}) is too short (${fo(K-j.start)} s) — the next beat starts right after it`);return{...j,end:K}});v.at(-1).end===null&&f-x.at(-1).end<no.closeGap&&(x.at(-1).end=fo(f));let $=null;const E=x.map(j=>{const P=Jl[j.kind],N=P.sit==="window"?u(P.scene):P.sit==="cover"?$??u("fr-window"):"full";return $=N,N}),S=E.map(j=>sy(j,r,a)),k=(j,P)=>{if(!j||!P)return!1;const N=F=>F.w>=r-1&&F.h>=a-1;return N(j)!==N(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)>no.jump},y=n.whip!==!1,A=[],I=[],z=x.map((j,P)=>{const N=P>0&&k(S[P-1],S[P])&&E[P]!==E[P-1];return N&&y&&I.push(fo(Math.max(0,j.start-.05))),{start:j.start,end:j.end,layout:E[P],...N&&y?{morph:no.whipMorph}:{}}});if(A.push({op:"speakerLayout",clipId:i.id,beats:z,morph:Number.isFinite(+n.morph)?qm(+n.morph,0,lo.maxMorph):lo.morph}),n.backdrop!==!1){const j=x[0].start,P=x.at(-1).end;let N=0;for(let F=j;F<P-.001;F+=to.maxDuration){const K=fo(Math.min(to.maxDuration,P-F));A.push({op:"addMotion",motionPreset:no.backdrop[l?1:0],start:fo(F),duration:K,params:{offset:fo(F-j)}}),N++}for(let F=1;F<=N;F++)A.push({op:"setLayerOrder",clipId:`new:${F}`,numberValue:-1})}for(const j of x){const P=Jl[j.kind];if(!P.scene)continue;const N={...j.fields,params:{...j.fields.params??{}}};if(j.kind==="chips"&&N.items?.length&&N.params.times==null){const F=cy(N.items,m,j.start,j.end);F&&(N.params.times=F.join(","))}if(j.kind==="headline"&&N.text&&N.params.times==null){const F=Zm(N.text,m,j.start,j.end);F&&(N.params.times=F.join(","))}if(j.kind==="question"&&N.subText&&N.params.times==null){const F=Zm(N.subText,m,j.start,j.end,no.replyFrom);F&&(N.params.times=F.join(","))}Object.keys(N.params).length||delete N.params,A.push({op:"addMotion",motionPreset:u(P.scene),start:j.start,duration:fo(Math.min(j.end-j.start,to.maxDuration)),color:c,...N})}if(n.punch!==!1){for(const j of x)if(j.kind==="full"&&j.end-j.start>=no.punch.min){const P=fo(Math.max(j.start,j.said?j.said.start:j.start+.1)),N=fo(Math.min(no.punch.max,j.end-P-.25));N>=.4&&A.push({op:"punchIn",clipId:i.id,at:P,duration:N,numberValue:no.punch.amount,punchStyle:"smooth"})}}for(const j of I)A.push({op:"addSfx",sfxId:no.whipSfx,at:j,volume:no.whipVolume});return A}const Qp=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),nE=["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"];function aE(t,{clips:e=[],materials:o=[],W:r=1280,H:a=720,maxOps:n=1/0,simulate:i=null}={}){if(!Array.isArray(t)||!t.some(d=>d?.op==="framedEdit"&&!d.error))return t;const l=[],u=[];let c=0;const s=d=>{const f=typeof d=="string"&&/^new:(\d+)$/.exec(d);if(!f)return d;const m=+f[1];let g=0;for(const v of u)m>v.after&&(g+=v.by);return`new:${m+g}`};for(const d of t){const f=d&&typeof d=="object"?{...d,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(g=>typeof d[g]=="string").map(g=>[g,s(d[g])])),...Array.isArray(d.clipIds)?{clipIds:d.clipIds.map(s)}:{}}:d;if(f?.op!=="framedEdit"||f.error){l.push(f),Qp.has(f?.op)&&c++;continue}let m=e;if(i&&l.some(g=>nE.includes(g?.op)))try{m=i([...l])??e}catch{m=e}try{const g=rE({clips:m,materials:o,op:f,W:r,H:a}),v=g.filter(E=>Qp.has(E.op)).length;if(l.length+g.length>n)throw Error(`makes ${g.length} ops — over the plan's ${n}; fewer beats`);const x=l.filter(E=>Qp.has(E?.op)).length,$=E=>{const S=typeof E=="string"&&/^new:(\d+)$/.exec(E);return S?`new:${+S[1]+x}`:E};l.push(...g.map(E=>typeof E.clipId=="string"?{...E,clipId:$(E.clipId)}:E)),v&&u.push({after:c,by:v})}catch(g){l.push({op:"framedEdit",error:String(g?.message||g).slice(0,300)})}}return l}const Rc=Object.freeze(["tilt-reveal","float-hero","zoom-detail","paparazzi","deck-deal","flip-swap","exploded"]),Jm=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"}}),Qm=t=>Math.round(t*1e4)/1e4,Wo=(t,e,o)=>Math.min(o,Math.max(e,t)),Sa=t=>typeof t=="number"&&Number.isFinite(t),ae=(...t)=>t.filter(Boolean).map(([e,o,r])=>({time:Qm(e),value:Qm(o),...r?{ease:r}:{}})).filter((e,o,r)=>!o||e.time-r[o-1].time>=1/30);function iE(t,e,o={}){if(!Rc.includes(t))throw Error(`promoShot shot must be ${Rc.join(" | ")}`);const[r,a]=Jm[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:Jm[t].camera},i=e[0],l=i.duration,u=c=>Wo(c,0,l);if(l<.8)throw Error("promoShot needs a clip of at least 0.8 s");if(t==="tilt-reveal"){const c=u(Math.min(1.1,l*.45)),s=i.zoom;n.cards.push({id:i.id,is3D:!0,keys:{tiltX:ae([0,58,"expo-out"],[c,0]),depth:ae([0,-7,"expo-out"],[c,0]),y:ae([0,.3,"expo-out"],[c,0]),zoom:ae([0,s],[c,s,"ease-in-out"],[l,s*1.05]),opacity:ae([0,0],[u(.25),1]),x:ae([0,0]),rot:ae([0,0])}})}else if(t==="float-hero"){const c=i.zoom,s=l/4;n.cards.push({id:i.id,is3D:!0,keys:{tiltY:ae([0,-16,"sine-in-out"],[s*2,-7,"sine-in-out"],[l,-13]),tiltX:ae([0,9,"sine-in-out"],[l,4]),y:ae([0,.012,"sine-in-out"],[s,-.012,"sine-in-out"],[s*2,.012,"sine-in-out"],[s*3,-.012,"sine-in-out"],[l,.006]),zoom:ae([0,c*.96,"ease-out"],[l,c*1.04]),opacity:ae([0,0],[u(.2),1]),x:ae([0,0]),rot:ae([0,0])}})}else if(t==="zoom-detail"){const c=o.focus??{},s=Wo(Sa(c.x)?c.x:.5,0,1),d=Wo(Sa(c.y)?c.y:.35,0,1),f=Wo(Sa(c.size)?c.size:.4,.15,1),m=i.zoom,g=Wo(1/f,1,3.5),v=m*g,x=u(.25),$=u(Math.max(x+.4,l*.65)),E=-(s-.5)*i.dispW*v,S=-(d-.5)*i.dispH*v;n.cards.push({id:i.id,is3D:!1,keys:{zoom:ae([0,m],[x,m,"expo-in-out"],[$,v],[l,v*1.03]),x:ae([0,0],[x,0,"expo-in-out"],[$,E],[l,E*1.03]),y:ae([0,0],[x,0,"expo-in-out"],[$,S],[l,S*1.03]),rot:ae([0,0])}})}else if(t==="paparazzi"){const c=(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>=c.length?o.times.slice(0,c.length):c.map((S,k)=>l*(.12+.24*k))).map(S=>u(S)).sort((S,k)=>S-k),d=u(Math.max(s[s.length-1]+.5,l*.82)),f=i.zoom,m=f*2.3,g=[[0,f,"hold"]],v=[[0,0,"hold"]],x=[[0,0,"hold"]],$=[[0,0]],E=[[0,0]];c.forEach((S,k)=>{const y=s[k],A=Wo(Sa(S?.x)?S.x:.5,0,1),I=Wo(Sa(S?.y)?S.y:.5,0,1);g.push([y,m,"hold"]),v.push([y,-(A-.5)*i.dispW*m,"hold"]),x.push([y,-(I-.5)*i.dispH*m,"hold"]),$.push([Math.max(0,y-.04),0],[y,1],[u(y+.14),0]),E.push([Math.max(0,y-.04),0],[y,.8],[u(y+.2),0])}),g.push([d,f]),v.push([d,0]),x.push([d,0]),$.push([Math.max(0,d-.04),0],[d,.8],[u(d+.14),0]),E.push([Math.max(0,d-.04),0],[d,.6],[u(d+.2),0]),n.cards.push({id:i.id,is3D:!1,keys:{zoom:ae(...g),x:ae(...v),y:ae(...x),rot:ae([0,0])},effects:{exposure:ae(...$),warm:ae(...E)}})}else if(t==="deck-deal"){const c=e.length;e.forEach((s,d)=>{const f=s.duration,m=Wo(d*.16,0,f),g=Wo(m+.5,0,f),v=d-(c-1)/2,x={x:v*.07,y:Math.abs(v)*.012,rot:v*5},$=d===c-1,E=Wo(Math.max(g+.4,f*.6),0,f),S=Wo(E+.5,0,f);n.cards.push({id:s.id,is3D:!1,keys:{x:ae([0,.75],[m,.75,"expo-out"],[g,x.x],...$?[[E,x.x,"ease-in-out"],[S,0]]:[[f,x.x*1.2]]),y:ae([0,.7],[m,.7,"expo-out"],[g,x.y],...$?[[E,x.y,"ease-in-out"],[S,0]]:[[f,x.y]]),rot:ae([0,24],[m,24,"expo-out"],[g,x.rot],...$?[[E,x.rot,"ease-in-out"],[S,0]]:[[f,x.rot*1.15]]),zoom:ae([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:ae([0,0],[m,0],[Wo(m+.12,0,f),1])}})})}else if(t==="flip-swap"){const[c,s]=e,d=Wo(Sa(o.at)?o.at:c.duration/2,.3,c.duration-.05),f=.22,m=Wo(d-(o.bStart??0),.05,s.duration-.05);n.cards.push({id:c.id,is3D:!0,keys:{tiltY:ae([0,0],[Math.max(0,d-f),0,"ease-in"],[d,90]),opacity:ae([0,1],[d,1,"hold"],[Math.min(c.duration,d+.05),0]),zoom:ae([0,c.zoom],[d,c.zoom*.94])}}),n.cards.push({id:s.id,is3D:!0,keys:{tiltY:ae([0,-90],[m,-90,"ease-out"],[Math.min(s.duration,m+f),0]),opacity:ae([0,0],[Math.max(0,m-.05),0,"hold"],[m,1]),zoom:ae([0,s.zoom*.94],[m,s.zoom*.94,"ease-out"],[Math.min(s.duration,m+f+.3),s.zoom])}})}else if(t==="exploded"){const c=Wo(Math.round(Sa(o.slices)?o.slices:3),2,4),s=i.zoom,d=s*.8,f=u(.15),m=u(Math.min(1.1,l*.35)),g=u(Math.max(m+.3,l-.9)),v=u(l-.3);n.slices=c;for(let x=0;x<c;x++){const $=((x+.5)/c-.5)*i.dispH,E=-(c-1-x)*2.2,S=(c-1-x)*.035,k=u(m+.6+x*.08);n.cards.push({id:`${i.id}#${x}`,slice:x,is3D:!0,keys:{tiltY:ae([0,0],[f,0,"expo-in-out"],[m,-34],[g,-34,"expo-in-out"],[v,0]),depth:ae([0,0],[m,0,"back-out"],[k,E],[g,E,"expo-in-out"],[v,0]),x:ae([0,0],[m,0,"back-out"],[k,S],[g,S,"expo-in-out"],[v,0]),y:ae([0,$*s],[f,$*s,"expo-in-out"],[m,$*d],[g,$*d,"expo-in-out"],[v,$*s]),zoom:ae([0,s],[f,s,"expo-in-out"],[m,d],[g,d,"expo-in-out"],[v,s]),rot:ae([0,0])}})}}return n}const ts="torn",Dc=["top","right","bottom","left"],t0=Object.freeze({depth:.03,seed:1}),sE=30;function lE(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 si=t=>Math.round(t*1e4)/1e4;function cE({sides:t=Dc,depth:e=t0.depth,seed:o=t0.seed,aspect:r=16/9}={}){const a=new Set(t.filter(v=>Dc.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=lE(o),i=e/Math.max(1,r),l=e*Math.min(1,r),u=(v,x,$,E)=>[si(a.has($)?v?1-i*(.4+n()*.6):i*(.4+n()*.6):v),si(a.has(E)?x?1-l*(.4+n()*.6):l*(.4+n()*.6):x)],c=u(0,0,"left","top"),s=u(1,0,"right","top"),d=u(1,1,"right","bottom"),f=u(0,1,"left","bottom"),m=(v,x,$)=>{if(!a.has($))return[];const E=[],S=sE,k=$==="top"||$==="bottom";for(let y=1;y<S;y++){const A=y/S+(n()-.5)*.6/S,I=n()**1.6,z=v[0]+(x[0]-v[0])*A,j=v[1]+(x[1]-v[1])*A;k?E.push([si(z),si($==="top"?I*l:1-I*l)]):E.push([si($==="left"?I*i:1-I*i),si(j)])}return E},g=[c,...m(c,s,"top"),s,...m(s,d,"right"),d,...m(d,f,"bottom"),f,...m(f,c,"left")];if(g.length>Au)throw Error("Torn outline too long");return g}function pE(t,{mw:e,mh:o,crop:r,sides:a,depth:n,seed:i}){const l=Ja(t).filter(d=>d.id!==ts),u=r||{left:0,right:0,top:0,bottom:0},c=e*(1-u.left-u.right)/Math.max(1,o*(1-u.top-u.bottom)),s={id:ts,name:"Mép xé",mode:l.length?"intersect":"add",keys:[{t:0,pts:cE({sides:a,depth:n,seed:i,aspect:c})}],feather:.0015};return cr(t?{mw:t.mw,mh:t.mh}:{mw:e,mh:o},[...l,s])}function sj(t){const e=Ja(t).filter(o=>o.id!==ts);return t&&e.length?cr(t,e.map((o,r)=>r===0&&o.mode==="intersect"?{...o,mode:"add"}:o)):void 0}const lj=t=>Ja(t).some(e=>e.id===ts),py="cut",ed=t=>new RegExp(`^${py}\\d+$`).test(t.id);function cj(t,{mw:e,mh:o},r){if(!r.length)throw Error("Nothing to cut out");const a=Ja(t).filter(c=>!ed(c)),n=a.filter(c=>c.id===ts),i=a.filter(c=>c.id!==ts),l=r.slice(0,Math.max(1,8-a.length)).map((c,s)=>({id:`${py}${s+1}`,name:"Tách nền",mode:"add",keys:[{t:0,pts:c}],smooth:!0,feather:.0012})),u=[...i,...l,...n.map(c=>({...c,mode:"intersect"}))].map((c,s)=>s===0&&c.mode!=="add"?{...c,mode:"add"}:c);return cr(t?{mw:t.mw,mh:t.mh}:{mw:e,mh:o},u)}const pj=t=>Ja(t).some(ed);function uj(t){const e=Ja(t).filter(o=>!ed(o));return t&&e.length?cr(t,e.map((o,r)=>r===0&&o.mode!=="add"?{...o,mode:"add"}:o)):void 0}const gn=Object.freeze({maxCards:24,cols:[1,8],rows:[1,6],curve:[0,1],maxSeconds:20,fly:[.25,2],color:"#5ee7ff"}),uE=Object.freeze(["glass","neon","mono"]),tu=Object.freeze(["chart","play","photo","music","chat","map","cart","stats","calendar","mail","code","camera"]),uy=/^#[0-9a-fA-F]{6}$/,se=t=>Math.round(t*1e4)/1e4,Ql=t=>Math.round(t*1e3)/1e3,zs=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,hE={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"]]},e0=["#5ee7ff","#7c8cff","#ff6bd6","#ffd166","#6dffb3","#ff8f5e"];function Gi(t,e,o,r){var a=Math.max(1e-4,(t.curve||0)*1.75),n=1.55,i=(e-.5)*a,l=t.w/a,u=l*Math.sin(i),c=l*(1-Math.cos(i)),s=(o-.5)*t.h,d=n/(n-c);return[t.cx+u*d,t.cy+s*d*r,d]}function dE(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 l=Gi(t,a,n,r),u=1e-4,c=Gi(t,a+u,n,r),s=Gi(t,a,n+u,r),d=(c[0]-l[0])/u,f=(s[0]-l[0])/u,m=(c[1]-l[1])/u,g=(s[1]-l[1])/u,v=d*g-f*m||1e-9,x=e-l[0],$=o-l[1];a+=(g*x-f*$)/v,n+=(-m*x+d*$)/v}return[a,n]}function hy(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 o0(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 fE(t,e=[],o="vi"){const r=Array.isArray(t?.cards)?t.cards.slice(0,gn.maxCards):null,a=r?r.length:Math.round(zs(Number(t?.count),1,gn.maxCards,12));if(!a)throw Error("hudWall needs at least one card");const n=hE[o==="en"?"en":"vi"],i={},l=[];for(let u=0;u<a;u++){const c=r?.[u]??{},s=n[u%n.length],d={title:String(c.title??s[0]).slice(0,40),sub:String(c.sub??(r?"":s[1])).slice(0,60),color:uy.test(c.color??"")?c.color.toLowerCase():e0[u%e0.length],icon:tu.includes(c.icon)?c.icon:tu[u%tu.length]};if(c.materialId!=null){const f=e.find(g=>g.id===c.materialId);if(!f||f.kind!=="image"||typeof f.gcsUri!="string")throw Error(`hudWall card ${u+1}: "${String(c.materialId).slice(0,40)}" is not a picture in the Media bin`);const m=`card${u}.img`;i[m]=f.gcsUri,d.img=m}l.push(d)}return{cards:l,assets:i}}function mE({cards:t,cols:e,rows:o,curve:r,color:a,look:n,toolbar:i=!0,W:l=1280,H:u=720,fill:c=!1}){const s=t.length,d=l/u,f=i!==!1,m=Math.round(zs(e,...gn.cols,Math.min(s,d>=1?4:2))),g=Math.round(zs(o,...gn.rows,Math.ceil(s/m)));if(m*g<s)throw Error(`hudWall: ${s} cards do not fit ${m} × ${g}`);const v=1.45,x=c?f?.84:.92:d>=1?.64:.82,$=(c?.84:.58)/d*m/g*v,E=Math.min(x,$),S=E/m*g/v;return{cols:m,rows:g,curve:Ql(zs(r,...gn.curve,.45)),color:uy.test(a??"")?a.toLowerCase():gn.color,look:uE.includes(n)?n:"glass",toolbar:f,cx:.5+(f?c?.045:.02:0),cy:c?.5:.4,w:se(E),h:se(S),cards:t,...c?{asp:se(d)}:{}}}function dy(t,e,o,r,a,n,i){var l=Math.min(o,r)*(i?.02:.09),u=Math.min(o,r*1.45),c=function(yt,Mt,p,lt,V){t.beginPath(),t.moveTo(yt+V,Mt),t.arcTo(yt+p,Mt,yt+p,Mt+lt,V),t.arcTo(yt+p,Mt+lt,yt,Mt+lt,V),t.arcTo(yt,Mt+lt,yt,Mt,V),t.arcTo(yt,Mt,yt+p,Mt,V),t.closePath()},s=e.color||a,d=e.img&&typeof M<"u"&&M.asset?M.asset(e.img):null;t.save(),c(0,0,o,r,l),t.clip();var f=t.createLinearGradient(0,0,o,r),m=i?1:0;if(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)",$=o*.07,E=r*.36,S=o*.86,k=r*.56;if(d){var y=Math.max(o/d.width,r/d.height),A=d.width*y,I=d.height*y;t.drawImage(d,(o-A)/2,(r-I)/2,A,I);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)},N=e.icon;if(N==="chart"||N==="stats"){t.globalAlpha=.9,t.beginPath();for(var F=0;F<=8;F++){var K=$+S*F/8,_=E+k*(.85-.6*(.3+.7*P(F))*(.4+F/12));F?t.lineTo(K,_):t.moveTo(K,_)}t.stroke(),t.globalAlpha=.18,t.lineTo($+S,E+k),t.lineTo($,E+k),t.closePath(),t.fill(),t.globalAlpha=1}else if(N==="play"||N==="camera"){var J=t.createLinearGradient($,E,$+S,E+k);J.addColorStop(0,s),J.addColorStop(1,"#101a30"),t.globalAlpha=.55,t.fillStyle=J,c($,E,S,k,l*.5),t.fill(),t.globalAlpha=1,t.fillStyle=v,t.beginPath();var X=$+S/2,rt=E+k/2,ot=k*.22;N==="play"?(t.moveTo(X-ot*.6,rt-ot),t.lineTo(X+ot,rt),t.lineTo(X-ot*.6,rt+ot)):t.arc(X,rt,ot,0,Math.PI*2),t.closePath(),t.fill()}else if(N==="photo")t.globalAlpha=.5,t.fillStyle=s,c($,E,S,k,l*.5),t.fill(),t.globalAlpha=1,t.fillStyle="rgba(255,255,255,0.85)",t.beginPath(),t.moveTo($,E+k),t.lineTo($+S*.35,E+k*.35),t.lineTo($+S*.6,E+k*.7),t.lineTo($+S*.75,E+k*.5),t.lineTo($+S,E+k),t.closePath(),t.fill(),t.beginPath(),t.arc($+S*.78,E+k*.25,k*.1,0,Math.PI*2),t.fill();else if(N==="music"){for(var F=0;F<18;F++){var G=k*(.15+.75*P(F));t.globalAlpha=.35+.65*P(F+30),t.fillRect($+S*F/18,E+k/2-G/2,S/18*.55,G)}t.globalAlpha=1}else if(N==="chat"||N==="mail"){for(var F=0;F<3;F++){var tt=E+k*(.05+F*.33),Q=S*(.45+.4*P(F));t.globalAlpha=F%2?.85:.35,c(F%2&&N==="chat"?$+S-Q:$,tt,Q,k*.24,k*.1),t.fill()}t.globalAlpha=1}else if(N==="map"){t.globalAlpha=.25;for(var F=1;F<5;F++)t.beginPath(),t.moveTo($,E+k*F/5),t.lineTo($+S,E+k*(F/5+.08)),t.stroke();t.globalAlpha=1,t.beginPath(),t.moveTo($+S*.1,E+k*.85),t.bezierCurveTo($+S*.4,E+k*.2,$+S*.6,E+k*.9,$+S*.88,E+k*.2),t.stroke(),t.beginPath(),t.arc($+S*.88,E+k*.2,k*.09,0,Math.PI*2),t.fill()}else if(N==="calendar"){for(var F=0;F<14;F++)t.globalAlpha=F===9?1:.28,c($+S*(F%7)/7,E+k*Math.floor(F/7)*.5,S/7*.82,k*.4,k*.06),t.fill();t.globalAlpha=1}else if(N==="cart"){for(var F=0;F<7;F++){var G=k*.45*(.3+.7*(F+1)/7*(.7+.3*P(F)));t.globalAlpha=.35+.08*F,t.fillRect($+S*(.55+F*.064),E+k*.5-G,S*.04,G)}t.globalAlpha=1}else{for(var F=0;F<4;F++)t.globalAlpha=.3+.5*P(F),t.fillRect($+S*.06*(F%2),E+k*F/4,S*(.4+.5*P(F+9)),k*.12);t.globalAlpha=1}(N==="stats"||N==="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 it=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 "+it;var D=o*.17,U=o*.78;t.fillText(e.title||"",D,r*.16,U),(e.sub&&e.icon!=="stats"&&e.icon!=="cart"||d)&&(t.fillStyle=x,t.font="500 "+Math.round(u*(i?.032:.056))+"px "+it,t.fillText(e.sub||"",D,r*.26,U)),t.restore(),c(.5,.5,o-1,r-1,l),t.lineWidth=Math.max(1,u*.008),t.strokeStyle=n==="neon"?s:"rgba(255,255,255,0.28)",t.stroke();var ht=t.createLinearGradient(0,0,0,r*.2);ht.addColorStop(0,"rgba(255,255,255,0.16)"),ht.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=ht,c(1,1,o-2,r*.2,l),t.fill()}function gE(t,e,o,r,a){for(var n=function(g,v,x,$,E,S){t.save(),t.beginPath();var k=($[0]+E[0]+S[0])/3,y=($[1]+E[1]+S[1])/3,A=function(rt){var ot=rt[0]-k,G=rt[1]-y,tt=Math.hypot(ot,G)||1;return[rt[0]+ot/tt*.7,rt[1]+G/tt*.7]},I=A($),z=A(E),j=A(S);t.moveTo(I[0],I[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 N=($[0]*(v[1]-x[1])+E[0]*(x[1]-g[1])+S[0]*(g[1]-v[1]))/P,F=($[1]*(v[1]-x[1])+E[1]*(x[1]-g[1])+S[1]*(g[1]-v[1]))/P,K=($[0]*(x[0]-v[0])+E[0]*(g[0]-x[0])+S[0]*(v[0]-g[0]))/P,_=($[1]*(x[0]-v[0])+E[1]*(g[0]-x[0])+S[1]*(v[0]-g[0]))/P,J=($[0]*(v[0]*x[1]-x[0]*v[1])+E[0]*(x[0]*g[1]-g[0]*x[1])+S[0]*(g[0]*v[1]-v[0]*g[1]))/P,X=($[1]*(v[0]*x[1]-x[0]*v[1])+E[1]*(x[0]*g[1]-g[0]*x[1])+S[1]*(g[0]*v[1]-v[0]*g[1]))/P;t.transform(N,F,K,_,J,X),t.drawImage(e,0,0),t.restore()},i=2,l=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 c=0;c<i;c++){var s=c/i,d=(c+1)/i,f=u/i,m=(u+1)/i;n([s*o,f*r],[d*o,f*r],[s*o,m*r],l(s,f),l(d,f),l(s,m)),n([d*o,f*r],[d*o,m*r],[s*o,m*r],l(d,f),l(d,m),l(s,m))}}const yE=`const GEO=${Gi.toString()};const CARD=${dy.toString()};
119
+ const CW=360,CH=248,cache=globalThis.__hudCards||(globalThis.__hudCards=new Map())
120
+ function cardCanvas(k,col,look){const c=HUD.cards[k],key=JSON.stringify([c,col,look]);let cv=cache.get(key);if(!cv&&typeof OffscreenCanvas!=='undefined'){cv=new OffscreenCanvas(CW,CH);CARD(cv.getContext('2d'),c,CW,CH,col,look,false);if(!c.img||M.asset(c.img))cache.set(key,cv)}return cv}
121
+ const CELL=${hy.toString()},cell=k=>CELL(HUD,k)
122
+ function render(ctx,t,env){
123
+ const W=env.width,H=env.height,asp=HUD.asp||W/H,p=env.params||{},col=p.color||HUD.color,look=p.look||HUD.look,P=(a,b)=>{const q=GEO(HUD,a,b,asp);return [q[0]*W,q[1]*H,q[2]]}
124
+ const ease=x=>1-Math.pow(1-M.clamp(x,0,1),3),grow=ease((t-.05)/.6),fade=M.clamp((env.duration-t)/.35,0,1)
125
+ if(grow<=0||fade<=0)return
126
+ ctx.globalAlpha=fade
127
+ // the wall's glass back plate + grid lines
128
+ const ring=(a0,b0,a1,b1,n)=>{const pts=[];for(let i=0;i<=n;i++)pts.push(P(a0+(a1-a0)*i/n,b0));for(let i=0;i<=n;i++)pts.push(P(a1-(a1-a0)*i/n,b1));return pts}
129
+ const plate=ring(-.025,-.05,1.025,1.05,24),mid=.5
130
+ ctx.save();ctx.beginPath();plate.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath()
131
+ ctx.globalAlpha=fade*grow*.16;ctx.fillStyle=col;ctx.fill();ctx.globalAlpha=fade*grow*.55;ctx.lineWidth=1.4;ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=14;ctx.stroke();ctx.restore()
132
+ ctx.save();ctx.globalAlpha=fade*grow*.12;ctx.strokeStyle=col;ctx.lineWidth=1
133
+ for(let r=1;r<HUD.rows;r++){ctx.beginPath();for(let i=0;i<=20;i++){const q=P(-.02+1.04*i/20,r/HUD.rows);i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1])}ctx.stroke()}
134
+ ctx.restore()
135
+ // the side toolbar
136
+ if(HUD.toolbar){const a0=-.085,a1=-.045,bar=ring(a0,.12,a1,.88,4);ctx.save();ctx.beginPath();bar.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath();ctx.globalAlpha=fade*grow*.5;ctx.fillStyle='rgba(10,16,30,0.8)';ctx.fill();ctx.globalAlpha=fade*grow;ctx.strokeStyle=col;ctx.lineWidth=1.2;ctx.stroke()
137
+ for(let i=0;i<6;i++){const q=P((a0+a1)/2,.2+i*.12),r=Math.max(3,(P(a1,.5)[0]-P(a0,.5)[0])*.28);ctx.beginPath();ctx.arc(q[0],q[1],r,0,Math.PI*2);ctx.globalAlpha=fade*grow*(i===0?1:.55);ctx.fillStyle=i===0?col:'rgba(234,246,255,0.7)';ctx.fill()}
138
+ ctx.restore()}
139
+ // the finger's hover point on the wall
140
+ let hov=null,best=.07;for(let i=0;i<FP.length;i++){const d=Math.abs(FP[i][0]-t);if(d<best){best=d;hov=FP[i]}}
141
+ for(let k=0;k<HUD.cards.length;k++){
142
+ let [a0,b0,a1,b1]=cell(k)
143
+ const cv=cardCanvas(k,col,look);if(!cv)continue
144
+ const enter=ease((t-.12-.035*k)/.45);if(enter<=0)continue
145
+ const held=G&&G.k===k&&t>=G.t0
146
+ // press: the card dips in for 0.3 s at each tap / pinch on it; glow after
147
+ let press=0,glow=0
148
+ for(const e of EV){if(e.k!==k)continue;const d=t-e.t;if(d>=0&&d<.3)press=Math.max(press,Math.sin(Math.PI*d/.3));if(d>=-.15&&d<1.2)glow=Math.max(glow,d<0?1+d/.15:1-d/1.2)}
149
+ if(hov&&hov[1]>=a0&&hov[1]<=a1&&hov[2]>=b0&&hov[2]<=b1)glow=Math.max(glow,.6)
150
+ const sc=(.82+.18*enter)*(1-.07*press),ca=(a0+a1)/2,cb=(b0+b1)/2
151
+ a0=ca+(a0-ca)*sc;a1=ca+(a1-ca)*sc;b0=cb+(b0-cb)*sc;b1=cb+(b1-cb)*sc
152
+ if(held){ // the empty slot the card was pulled out of
153
+ const r=ring(a0,b0,a1,b1,6);ctx.save();ctx.beginPath();r.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath();ctx.setLineDash([6,5]);ctx.globalAlpha=fade*.7;ctx.strokeStyle=col;ctx.lineWidth=1.5;ctx.stroke();ctx.globalAlpha=fade*.08;ctx.fillStyle=col;ctx.fill();ctx.restore();continue
154
+ }
155
+ ctx.save();ctx.globalAlpha=fade*enter*(.92+.08*glow)
156
+ const N=5;for(let s=0;s<N;s++){
157
+ const u0=s/N,u1=(s+1)/N,A0=a0+(a1-a0)*u0,A1=a0+(a1-a0)*u1,tl=P(A0,b0),tr=P(A1,b0),bl=P(A0,b1),sw=CW/N
158
+ ctx.save();ctx.setTransform((tr[0]-tl[0])/sw,(tr[1]-tl[1])/sw,(bl[0]-tl[0])/CH,(bl[1]-tl[1])/CH,tl[0],tl[1]);ctx.drawImage(cv,u0*CW,0,sw+.6,CH,0,0,sw+.6,CH);ctx.restore()
159
+ }
160
+ if(glow>0||press>0){const r=ring(a0,b0,a1,b1,6);ctx.beginPath();r.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath();ctx.globalCompositeOperation='lighter';ctx.globalAlpha=fade*Math.max(glow,press);ctx.strokeStyle=col;ctx.lineWidth=2.4;ctx.shadowColor=col;ctx.shadowBlur=22;ctx.stroke();ctx.globalAlpha=fade*.18*Math.max(glow,press);ctx.fillStyle=col;ctx.fill()}
161
+ ctx.restore()
162
+ }
163
+ // ripples where the finger touched
164
+ for(const e of EV){const d=t-e.t;if(d<0||d>.75)continue;const q=P(e.a,e.b),u=d/.75,r=(.012+.11*ease(u))*W*q[2]*HUD.w
165
+ ctx.save();ctx.globalCompositeOperation='lighter';ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=16
166
+ for(let i=0;i<2;i++){const rr=r*(1-i*.35);ctx.globalAlpha=fade*(1-u)*(i?0.5:0.9);ctx.lineWidth=2.5*(1-u)+.6;ctx.beginPath();ctx.ellipse(q[0],q[1],rr,rr*.62,0,0,Math.PI*2);ctx.stroke()}
167
+ ctx.globalAlpha=fade*(1-u);ctx.fillStyle='#ffffff';ctx.beginPath();ctx.arc(q[0],q[1],3.5*(1-u)+1,0,Math.PI*2);ctx.fill();ctx.restore()}
168
+ }`,bE=`const CARD=${dy.toString()};const QUAD=${gE.toString()};
169
+ const CW=720,CH=496,cache=globalThis.__hudGrab||(globalThis.__hudGrab=new Map())
170
+ function canvasOf(w,h,hero,col,look){const key=JSON.stringify([C,w,h,hero,col,look]);let cv=cache.get(key);if(!cv&&typeof OffscreenCanvas!=='undefined'){cv=new OffscreenCanvas(w,h);CARD(cv.getContext('2d'),C,w,h,col,look,hero);if(!C.img||M.asset(C.img))cache.set(key,cv)}return cv}
171
+ function at(T){const p=G.path;if(!p.length)return [0,0,1];if(T<=p[0][0])return p[0].slice(1);for(let i=1;i<p.length;i++)if(T<=p[i][0]){const a=p[i-1],b=p[i],k=(T-a[0])/((b[0]-a[0])||1);return [a[1]+(b[1]-a[1])*k,a[2]+(b[2]-a[2])*k,a[3]+(b[3]-a[3])*k]}return p[p.length-1].slice(1)}
172
+ // the card's corners while it is held: the slot's quad carried with the pinch, standing up and coming closer as it lifts
173
+ function held(T,W,H){
174
+ const q0=G.q.map(p=>[p[0]*W,p[1]*H]),a=at(G.t0),b=at(T),dx=(b[0]-a[0])*W,dy=(b[1]-a[1])*H,depth=M.clamp(b[2]/(a[2]||1),.6,1.9)
175
+ const lift=1-Math.pow(1-M.clamp((T-G.t0)/.32,0,1),3),cx=(q0[0][0]+q0[1][0]+q0[2][0]+q0[3][0])/4+dx,cy=(q0[0][1]+q0[1][1]+q0[2][1]+q0[3][1])/4+dy
176
+ const w=(Math.hypot(q0[1][0]-q0[0][0],q0[1][1]-q0[0][1])+Math.hypot(q0[3][0]-q0[2][0],q0[3][1]-q0[2][1]))/2*(1+.16*lift)*depth,h=w*CH/CW
177
+ // swing: the card leans with the hand's sideways speed (3D feel)
178
+ const c=at(T+.05),v=M.clamp((c[0]-b[0])/.05*.06,-.22,.22)*lift,rect=[[cx-w/2,cy-h/2+v*h],[cx+w/2,cy-h/2-v*h],[cx-w/2,cy+h/2-v*h*.4],[cx+w/2,cy+h/2+v*h*.4]]
179
+ return q0.map((p,i)=>[p[0]+dx+(rect[i][0]-p[0]-dx)*lift,p[1]+dy+(rect[i][1]-p[1]-dy)*lift])
180
+ }
181
+ function render(ctx,t,env){
182
+ if(!G||t<G.t0)return
183
+ const W=env.width,H=env.height,p=env.params||{},col=p.color||COL,look=p.look||LOOK
184
+ let q,fly=0
185
+ if(t<G.t1)q=held(t,W,H)
186
+ else{const r=held(G.t1,W,H),u=M.clamp((t-G.t1)/G.fly,0,1);fly=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2
187
+ const over=1+.04*Math.sin(Math.PI*M.clamp((t-G.t1)/G.fly*1.15,0,1)),full=[[0,0],[W,0],[0,H],[W,H]].map(p=>[W/2+(p[0]-W/2)*over,H/2+(p[1]-H/2)*over])
188
+ q=r.map((p,i)=>[p[0]+(full[i][0]-p[0])*fly,p[1]+(full[i][1]-p[1])*fly])}
189
+ const card=canvasOf(CW,CH,false,col,look);if(!card)return
190
+ // shadow under the held card
191
+ if(fly<1){ctx.save();ctx.globalAlpha=.42*(1-fly);ctx.fillStyle='#000';ctx.filter='blur('+Math.round(H*.025)+'px)';ctx.beginPath();const o=H*.035;ctx.moveTo(q[0][0],q[0][1]+o);ctx.lineTo(q[1][0],q[1][1]+o);ctx.lineTo(q[3][0],q[3][1]+o);ctx.lineTo(q[2][0],q[2][1]+o);ctx.closePath();ctx.fill();ctx.restore()}
192
+ if(fly<1)QUAD(ctx,card,CW,CH,q)
193
+ if(fly>0){const hero=canvasOf(W,H,true,col,look);if(hero){ctx.save();ctx.globalAlpha=M.clamp(fly*1.6-.25,0,1);QUAD(ctx,hero,W,H,q);ctx.restore()}}
194
+ // light: the card's edge glows while held, streaks while it flies
195
+ ctx.save();ctx.globalCompositeOperation='lighter';ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=24;ctx.lineWidth=2.4;ctx.globalAlpha=(1-fly)*.95
196
+ ctx.beginPath();ctx.moveTo(q[0][0],q[0][1]);ctx.lineTo(q[1][0],q[1][1]);ctx.lineTo(q[3][0],q[3][1]);ctx.lineTo(q[2][0],q[2][1]);ctx.closePath();ctx.stroke()
197
+ if(fly>0&&fly<1){const cx=W/2,cy=H/2;ctx.shadowBlur=0;for(let i=0;i<14;i++){const a=i*2.399,r0=Math.min(W,H)*(.15+.5*fly),r1=r0+Math.min(W,H)*.25*(1-fly);ctx.globalAlpha=(1-fly)*.5;ctx.lineWidth=1.5;ctx.beginPath();ctx.moveTo(cx+Math.cos(a)*r0,cy+Math.sin(a)*r0*.6);ctx.lineTo(cx+Math.cos(a)*r1,cy+Math.sin(a)*r1*.6);ctx.stroke()}}
198
+ ctx.restore()
199
+ }`,pa=(t,e)=>`const ${t}=${JSON.stringify(e)};`;function fy({cfg:t,events:e=[],grab:o=null,hover:r=[],assets:a}){const n=[pa("HUD",t),pa("EV",e),pa("G",o),pa("FP",r),yE].join(`
200
+ `);return ko({code:n,params:{color:t.color,look:t.look},preset:"hud-wall",...a&&Object.keys(a).length?{assets:a}:{}})}function gh({card:t=null,grab:e=null,color:o=gn.color,look:r="glass",assets:a}){const n=[pa("C",t),pa("G",e),pa("COL",o),pa("LOOK",r),bE].join(`
201
+ `);return ko({code:n,params:{color:o,look:r},preset:"hud-grab",...a&&Object.keys(a).length?{assets:a}:{}})}function od(t){const e={};for(const o of String(t?.code??"").split(`
202
+ `,4)){const r=/^const ([A-Z]+)=(.*);$/.exec(o);if(r)try{e[r[1]]=JSON.parse(r[2])}catch{}}return e}const my=t=>t?.motion?.preset==="hud-wall";function wE({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:se(e),duration:se(Math.min(gn.maxSeconds,o)),label:n||"Tường HUD",motionV:2,posX:0,posY:0,scale:1,motion:fy({cfg:r,assets:a})}}function yh(t,e,o,r,a,n=null){if(t.pin&&!t.pin.scene){const l=bg(t,e,o,r,a,n);if(l)return l}const i=Math.max(0,Math.min(t.duration,o-t.start));if(Rs(n)&&hw(t)){const l=dw(t,i,n,o,r,a);if(l)return l.quad}return fw(t,i,r,a)}function bh(t){const[e,o,r,a]=t,n=o[0]-a[0],i=r[0]-a[0],l=o[1]-a[1],u=r[1]-a[1],c=e[0]-o[0]+a[0]-r[0],s=e[1]-o[1]+a[1]-r[1];let d=0,f=0;const m=n*u-i*l||1e-12;(Math.abs(c)>1e-9||Math.abs(s)>1e-9)&&(d=(c*u-i*s)/m,f=(n*s-c*l)/m);const g=o[0]-e[0]+d*o[0],v=r[0]-e[0]+f*r[0],x=e[0],$=o[1]-e[1]+d*o[1],E=r[1]-e[1]+f*r[1],S=e[1],k=(J,X)=>{const rt=d*J+f*X+1;return[(g*J+v*X+x)/rt,($*J+E*X+S)/rt]},y=E-S*f,A=x*f-v,I=v*S-x*E,z=S*d-$,j=g-x*d,P=x*$-g*S,N=$*f-E*d,F=v*d-g*f,K=g*E-v*$;return{apply:k,inverse:(J,X)=>{const rt=N*J+F*X+K;return[(y*J+A*X+I)/rt,(z*J+j*X+P)/rt]}}}const tc=(t,e,o,r,a,n)=>{const i=t.crop||{left:0,right:0,top:0,bottom:0},l=1-i.left-i.right||1,u=1-i.top-i.bottom||1,c=cc(t,(o[0]-i.left)/l,(o[1]-i.top)/u,r,a,n,e.mw,e.mh);return[c.px,c.py]};function Oi(t,e,o,{point:r="index",side:a="any",W:n=1280,H:i=720}={}){const l=o-t.start,u=$c(t,l),c=iM(e,u,a),s=Ec(e,u,c);if(!s)return null;const d=tc(t,e,Ii(s,r),l,n,i),f=tc(t,e,s[9],l,n,i),m=tc(t,e,s[0],l,n,i);return{x:d[0],y:d[1],size:Math.hypot(f[0]-m[0],f[1]-m[1]),slot:c}}const gy=1/15;function kE(t,e,{point:o="index",side:r="any",scale:a=!1,offset:n=null,W:i=1280,H:l=720}={}){if(!e?.hands)throw Error("The footage has no hand track yet");const u=Zs(e.hands),c=Math.max(t.start,e.start),s=Math.min(t.start+t.duration,e.start+e.duration);if(!(s-c>=1/30))throw Error("The layer and the footage do not play at the same time");const d=Math.max(1,Math.min(Le.maxFrames,Math.ceil((s-c)/gy))),f=[];for(let k=0;k<=d;k++){const y=c+(s-c)*k/d,A=Oi(e,u,y,{point:o,side:r,W:i,H:l});A&&f.push({T:y,...A})}if(!f.length)throw Error("No hand is seen while the layer plays");const m={...t,...en(t)},g=f[0],v=k=>se(k-t.start),x=Array.isArray(n)?Number(n[0])||0:Zt(m,"x",g.T-t.start)-(g.x-i/2)/i,$=Array.isArray(n)?Number(n[1])||0:Zt(m,"y",g.T-t.start)-(g.y-l/2)/l,E=Zt(m,"zoom",g.T-t.start)||1;let S={...m,motionV:2};return delete S.posX,delete S.posY,S={...S,...me(S,"x",f.map(k=>({time:v(k.T),value:se((k.x-i/2)/i+x)})))},S={...S,...me(S,"y",f.map(k=>({time:v(k.T),value:se((k.y-l/2)/l+$)})))},a&&(S={...S,...me(S,"zoom",f.map(k=>({time:v(k.T),value:se(Math.max(.05,E*k.size/(g.size||1)))})))}),{motionV:2,motionKeys:S.motionKeys,posX:void 0,posY:void 0}}function r0(t,{until:e=1/0}={}){const o=Zs(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)),l=[];for(let u=0;u<Le.slots;u++){const c=[];let s=null,d=null,f=null;for(let g=0;g<o.n;g+=i){const v=se(z1(t,o.s0+g/o.fps));if(v<0||v>t.duration+.001)continue;const x=o.frames[g][u];let $;if(x)$=lM(x.lm,o.mw,o.mh,{edge:x.edge}).map(([E,S])=>[se(Math.max(-.95,Math.min(1.95,(E-r.left)/a))),se(Math.max(-.95,Math.min(1.95,(S-r.top)/n)))]),s===null&&(s=v),d=v,f=$;else{const E=f?f.reduce((S,k)=>[S[0]+k[0]/f.length,S[1]+k[1]/f.length],[0,0]):[.5,.5];$=Array.from({length:qr},()=>[se(E[0]),se(E[1])])}c.length&&c.at(-1).t>=v||c.push({t:v,pts:$})}if(s===null)continue;const m=Math.min(d+1/o.fps,e);m<=s||l.push({id:`h${u+1}`,name:u?"Tay trái":"Tay phải",mode:"add",keys:c,feather:.0035,in:se(s),out:se(Math.min(t.duration,m))})}return l.length?{v:2,mw:o.mw,mh:o.mh,masks:l}:null}const wh=(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 xE({wall:t,layer:e,src:o,clips:r,cam:a=null,W:n=1280,H:i=720,events:l=null,grab:u="auto",side:c="any",fly:s=.7}){if(!my(t))throw Error("hudInteract needs a HUD wall layer (hudWall)");const d=od(t.motion),f=d.HUD;if(!f)throw Error("The HUD wall has no settings");const m=o.hands?Zs(o.hands):null,g=f.asp||n/i,v=zs(s,...gn.fly,.7),x=Math.max(t.start,o.start,e.start),$=Math.min(t.start+t.duration,o.start+o.duration,e.start+e.duration),E=(X,rt,ot)=>{const G=bh(yh(t,r,ot,n,i,a)),[tt,Q]=G.inverse(X,rt);return dE(f,tt,Q,g)},S=(X,rt,ot)=>{const G=bh(yh(t,r,ot,n,i,a)),tt=Gi(f,X,rt,g),[Q,it]=G.apply(tt[0],tt[1]);return[Q/n,it/i]};let k;if(Array.isArray(l)&&l.length)k=l.map(X=>{const rt=Number(X.t);if(!Number.isFinite(rt)||!["tap","pinch","release"].includes(X.type))throw Error("hudInteract events: [{t (timeline s), type tap | pinch | release, point? [x, y]}]");let ot,G;if(Array.isArray(X.point)&&X.point.length===2&&X.point.every(Number.isFinite))ot=X.point[0]*n,G=X.point[1]*i;else{const tt=m&&Oi(o,m,rt,{point:X.type==="tap"?"index":"pinch",side:c,W:n,H:i});if(!tt)throw Error(`hudInteract event at ${rt}s: give point [x, y] (no hand seen there)`);ot=tt.x,G=tt.y}return{type:X.type,T:rt,x:ot,y:G}}).sort((X,rt)=>X.T-rt.T);else{if(!m)throw Error("The footage has no hand track yet");const X=rt=>c==="any"||(c==="right"?rt===0:rt===1);k=sM(m).filter(rt=>X(rt.slot)).map(rt=>{const ot=z1(o,rt.s),G=o.start+ot,[tt,Q]=tc(o,m,[rt.u,rt.v],ot,n,i);return{type:rt.type,T:G,x:tt,y:Q,slot:rt.slot}})}k=k.filter(X=>X.T>=x-1e-6&&X.T<=$+1e-6);const y=[],A={taps:0,pinches:0,grabbed:null};let I=null,z=null;const j=X=>X.slot===1?"left":X.slot===0?"right":c,P=X=>{const rt=k[X],ot=k.slice(X+1).find(G=>G.type==="release"&&(G.slot===void 0||G.slot===rt.slot));return Math.min($-.05,ot?ot.T:$-v)};let N=-1,F=-1/0;u!==!1&&k.forEach((X,rt)=>{if(X.type!=="pinch"||X.T<t.start+.6)return;const[ot,G]=E(X.x,X.y,X.T),tt=o0(f,ot,G,.25),Q=P(rt);if(tt<0&&!Number.isInteger(u)||Q-X.T<.3||$-Q<Math.min(.5,v))return;const it=m&&Oi(o,m,Q,{point:"pinch",side:j(X),W:n,H:i}),D=it?Math.hypot(it.x-X.x,it.y-X.y)/n:0,U=Math.min(1.5,Q-X.T)+3*D;U>F&&(F=U,N=rt)});for(let X=0;X<k.length;X++){const rt=k[X];if(rt.type==="release")continue;const[ot,G]=E(rt.x,rt.y,rt.T);let tt=o0(f,ot,G,rt.type==="pinch"?.25:0);const Q=se(rt.T-t.start);if(X===N){Number.isInteger(u)&&(tt=Math.max(0,Math.min(f.cards.length-1,u)));const it=P(X),[D,U,ht,yt]=hy(f,tt),Mt=[[D,U],[ht,U],[D,yt],[ht,yt]].map(([V,h])=>S(V,h,rt.T).map(se)),p=[],lt=Math.max(2,Math.ceil((it+.15-rt.T)*30));for(let V=0;V<=lt;V++){const h=rt.T+(it+.15-rt.T)*V/lt,w=m&&Oi(o,m,h,{point:"pinch",side:j(rt),W:n,H:i});w&&p.push([se(h-e.start),se(w.x/n),se(w.y/i),se(w.size/n)])}p.length||p.push([se(rt.T-e.start),se(rt.x/n),se(rt.y/i),1]),I={k:tt,t0:se(rt.T-e.start),t1:se(it-e.start),fly:Ql(v),q:Mt,path:p},z=gh({card:f.cards[tt],grab:I,color:t.motion.params?.color??f.color,look:t.motion.params?.look??f.look,assets:t.motion.assets}),y.push({k:tt,t:Q,a:se(ot),b:se(G)}),A.pinches++,A.grabbed=tt;continue}rt.T<t.start+.35||ot<-.05||ot>1.05||G<-.05||G>1.05||(y.push({k:tt,t:Q,a:se(ot),b:se(G)}),rt.type==="tap"?A.taps++:A.pinches++)}if(I)for(let X=y.length-1;X>=0;X--)y[X].k===I.k&&y[X].t>I.t0+e.start-t.start+1e-6&&y.splice(X,1);const K=[];if(m)for(let X=x;X<=$;X+=1/15){const rt=Oi(o,m,X,{point:"index",side:c,W:n,H:i});if(!rt)continue;const[ot,G]=E(rt.x,rt.y,X);if(!(ot<0||ot>1||G<0||G>1)&&(K.push([se(X-t.start),Ql(ot),Ql(G)]),K.length>=300))break}const _=fy({cfg:f,events:y,grab:I?{k:I.k,t0:se(I.t0+e.start-t.start)}:null,hover:K,assets:t.motion.assets});_.params={..._.params,...t.motion.params??{}},z||(z=gh({card:null,grab:null,color:t.motion.params?.color??f.color,look:t.motion.params?.look??f.look}));const J=I?se(I.t1+e.start+v*.55-o.start):1/0;return{wall:_,grab:z,cutoutUntil:J,report:A}}function n0(t){const e=t.point??"index",o=t.hand??"any";if(!Mc.includes(e))throw Error(`handAttach point: ${Mc.join(" | ")}`);if(!Qu.includes(o))throw Error(`hand: ${Qu.join(" | ")}`);return{point:e,side:o}}const Na=Object.freeze({dx:.01,dy:.035,opacity:.3,blur:.65,feather:.025});function ME(t,e,o,{cam:r=null,W:a=1280,H:n=720}={}){const i=od(t.motion).HUD,l=i.asp||a/n,u=e.hands?.mw??a,c=e.hands?.mh??n,s=Math.max(t.start,e.start),d=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 $ of[s,(s+d)/2,d-.001]){const E=bh(yh(t,o,$,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=Gi(i,S,k,l),[A,I]=E.apply(y[0],y[1]),z=Pg(e,A,I,$-e.start,a,n,u,c);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=$=>se(Math.max(-.95,Math.min(1.95,$)));return{id:"wall",name:"Màn hình HUD",mode:"add",feather:Na.feather,keys:[{t:0,pts:[[x(f),x(m)],[x(g),x(m)],[x(g),x(v)],[x(f),x(v)]]}]}}function vE(t,{id:e,wallMask:o,mw:r=1280,mh:a=720}){const{mask:n,person:i,...l}=t,u={...l,id:e,label:`${t.label?.replace(/ · tay$/,"")||"Video"} · bóng tay`,volume:0,hud:{...t.hud,role:"shadow"},brightness:0,opacity:Na.opacity,effects:[{type:"blur",amount:Na.blur}]};return Array.isArray(l.motionKeys)&&l.motionKeys.some(s=>Number.isFinite(s.x)||Number.isFinite(s.y))?u.motionKeys=l.motionKeys.map(s=>({...s,...Number.isFinite(s.x)?{x:se(s.x+Na.dx)}:{},...Number.isFinite(s.y)?{y:se(s.y+Na.dy)}:{}})):(u.posX=se((l.posX||0)+Na.dx),u.posY=se((l.posY||0)+Na.dy)),u.mask=i?{v:2,mw:r,mh:a,masks:[o]}:{v:2,mw:r,mh:a,masks:[{...wh(r,a).masks[0]},{...o,mode:"intersect"}]},i&&(u.person=i),u}const go=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}),a0=go.presets,Bc=1/30,eu=.4,$l=(t,e,o)=>Math.max(e,Math.min(o,t)),$E=t=>+t.toFixed(4);function EE(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+Bc*2<o&&n.push({time:ft(e+Bc*2),d:0});else if(r.startsWith("push")){const l=r==="push-left"?-1:1,u=Math.min(go.push,(e-t)/3);n.push({time:t,d:0,ease:"expo-in"},{time:ft(t+u),d:l,ease:"hold"}),e>=o-1e-6?n.push({time:o,d:l}):n.push({time:ft(e-u),d:-l,ease:"expo-out"},{time:e,d:0})}else{const l=r==="down"||r==="right"?1:-1,u=Math.min(go.ramp,(e-t)/3);n.push({time:t,d:0,ease:"expo-out"},{time:ft(t+u),d:l*a}),e>=o-1e-6?n.push({time:o,d:l*a}):n.push({time:ft(e-u),d:l*a,ease:"ease-in-out"},{time:e,d:0})}const i=[];for(const l of n)(!i.length||l.time>i.at(-1).time+1e-6)&&i.push(l);return i}function SE(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(!go.presets.includes(r))throw Error(`Make room preset must be ${go.presets.join("/")}`);if(!Number.isFinite(e)||e<0||e>=t.duration-Bc)throw Error("Make room must start inside the clip");const n=r==="rush",i=$l(Number.isFinite(o)?o:3,n?.3:go.minDuration,go.maxDuration),l=n?$l(Number.isFinite(a)?a:go.defaults.rush,go.rush.min,go.rush.max):$l(Number.isFinite(a)?a:go.defaults[r],go.minAmount,go.maxAmount),u=ft(e);let c=ft(Math.min(t.duration,u+i));if(t.duration-c<Bc&&(c=t.duration),c-u<(n?.3:go.minDuration)-1e-6&&c<t.duration)throw Error("Make room is too short for the clip");const s=n?"zoom":r==="down"?"y":"x",d=EE(u,c,t.duration,r,l),f=d[0].time,m=d.at(-1).time,g=Ee(t,s).some(z=>z.time>f+.001&&z.time<m-.001),v=[...d];if(g)for(let z=f+eu;z<m-eu/2;z+=eu){const j=ft(z);if(!v.some(P=>Math.abs(P.time-j)<.001)){const P=v.findIndex(K=>K.time>j),N=v[P-1],F=v[P];v.splice(P,0,{time:j,d:N.ease==="hold"?N.d:N.d+(F.d-N.d)*(j-N.time)/(F.time-N.time)})}}const x=Ee(t,s).filter(z=>z.time<f-.001||z.time>m+.001),$=v.map(z=>({time:z.time,value:$E(n?Math.min(ns,Zt(t,s,z.time)*(1+z.d)):$l(Zt(t,s,z.time)+z.d,-1,1)),...z.ease?{ease:Qt[z.ease]}:{}})),E={...t,...me(t,s,[...x,...$].sort((z,j)=>z.time-j.time))};kn(E);const{motionV:S,motionKeys:k,posX:y,posY:A,scale:I}=E;return{motionV:S,motionKeys:k,...y!==void 0?{posX:y,posY:A,scale:I}:{}}}const ir=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}}}),rr=t=>+t.toFixed(3),IE=t=>Math.max(-1,Math.min(1,t)),i0=(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 AE({speakerClipId:t,portrait:e=!0,at:o,handoff:r,end:a,card:n,scene:i,rows:l=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+ir.minCard),a=Math.max(+a,r+ir.grow+ir.minScene),!Number.isFinite(o)||o<0||!Number.isFinite(a))throw Error("Bridge times must be timeline seconds");const c=E=>fn(l+E),s=e?ir.centre.portrait:ir.centre.landscape,d=ir.zoom,f=rr(Math.max(0,o-ir.lead)),m=rr(r+ir.grow),g=rr(r+ir.grow*.6),v=rr(g+ir.sceneIn+.05),x=Math.min(go.maxDuration,rr(v+go.ramp+.2-f)),$=E=>`new:${u+E}`;return[{op:"makeRoom",clipId:t,at:f,duration:x,preset:e?"down":"left"},{op:"addMotion",motionPreset:"exp-room-panel",start:f,duration:rr(v-f),track:c(0),placement:"top"},{op:"addMotion",motionPreset:n.preset,start:rr(o),duration:rr(v-o),track:c(1),placement:"top",...i0(n)},{op:"setPropertyKeys",clipId:$(2),property:"zoom",propertyKeys:[{time:rr(r-o),value:1,ease:"ease-in"},{time:rr(m-o),value:d}]},{op:"setPropertyKeys",clipId:$(2),property:s.prop,propertyKeys:[{time:rr(r-o),value:0,ease:"ease-in"},{time:rr(m-o),value:rr(IE(s.off*d))}]},{op:"addMotion",motionPreset:i.preset,start:g,duration:rr(a-g),track:c(2),placement:"center",...i0(i)},{op:"setAnimation",clipId:$(3),property:"enter",preset:"zoom-in",duration:ir.sceneIn,numberValue:.35}]}const yy={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"},s0=Object.freeze(["zoom-through","push","match-zoom",...Object.keys(yy)]),CE={flash:.8,whip:.8,glitch:.8,slab:1,iris:1,stripes:1,ink:1.2,shapes:1.2,tunnel:1.2},Ia=t=>+(+t).toFixed(3),l0=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},_c=t=>/^(add|lockup$)/.test(t?.op??"");function jE(t,{portrait:e=!1,rows:o=1,base:r=0}={}){const a=t.preset,n=+t.at,i=Math.max(1,+t.duration||4),l=t.booleanValue!==!1,u=t.fromClipId;if(!s0.includes(a))throw Error(`Bridge kind must be ${s0.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 c=x=>fn(o+x),s=x=>`new:${r+x}`,d=Ia(n+i),f=[],m=(x,$,E)=>t.clipId?t.clipId:(f.push({op:"addMotion",motionPreset:t.motionPreset,start:Ia(x),duration:Ia($),track:E,placement:"center",...l0(t)}),s(f.filter(_c).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(ir.minCard,n-ir.grow*.6),$=AE({speakerClipId:u,portrait:e,at:Math.max(0,x-ir.minCard),handoff:x,end:d,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(...$.map(E=>E.op==="addMotion"&&E.motionPreset===t.motionPreset?{...E,...l0(t)}:E)),l){const E=f.filter(_c).length;f.push({op:"setAnimation",clipId:s(E),property:"exit",preset:"zoom-out",duration:.4,numberValue:.3})}return f}if(a==="push"){const x=go.push;f.push({op:"makeRoom",clipId:u,at:Ia(Math.max(0,n-x*.5)),duration:Ia(Math.min(go.maxDuration,i+x)),preset:"push-left"});const $=m(n-x*.5,i+x*.5,c(0));return f.push({op:"setAnimation",clipId:$,property:"enter",preset:"slide-left",duration:x,numberValue:1,booleanValue:!1}),l&&f.push({op:"setAnimation",clipId:$,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 $=m(n,i,c(0));return f.push({op:"setAnimation",clipId:$,property:"enter",preset:"zoom-out",duration:.45,numberValue:.45,booleanValue:!1}),l&&f.push({op:"setAnimation",clipId:$,property:"exit",preset:"zoom-in",duration:.35,numberValue:.4,booleanValue:!1}),f}const g=CE[a],v=yy[a];return m(n,i,c(0)),f.push({op:"addMotion",motionPreset:v,start:Ia(Math.max(0,n-g/2)),duration:g,track:c(1),...t.color?{color:t.color}:{}}),l&&f.push({op:"addMotion",motionPreset:v,start:Ia(Math.max(0,d-g/2)),duration:g,track:c(1),...t.color?{color:t.color}:{}}),f}function TE(t,{portrait:e=!1}={}){if(!t.some(l=>l?.op==="bridge"))return t;const o=[],r=[];let a=0,n=0;const i=l=>{const u=s=>{const d=typeof s=="string"&&/^new:(\d+)$/.exec(s);if(!d)return s;const f=+d[1];let m=0;for(const g of r)f>g.after&&(m+=g.by);return`new:${f+m}`},c={...l};return c.clipId&&(c.clipId=u(c.clipId)),c.fromClipId&&(c.fromClipId=u(c.fromClipId)),c.sourceClipId&&(c.sourceClipId=u(c.sourceClipId)),Array.isArray(c.clipIds)&&(c.clipIds=c.clipIds.map(u)),c};for(const l of t){const u=i(l);if(u?.op!=="bridge"){o.push(u),_c(u)&&(a++,n++);continue}const c=jE(u,{portrait:e,base:a}),s=c.filter(_c).length;o.push(...c),s&&r.push({after:n,by:s}),a+=s}return o}const by=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]}}),hj=Object.keys(by),c0=8,OE=.25,ua=t=>Math.round(t*1e3)/1e3,kh=(t,e)=>Math.max(Pr[t].min,Math.min(Pr[t].max,e));function zE(t,e,o){const r=n=>n.map(i=>t.find(l=>l.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 l=n.at(-1);return l&&i.start-l[0].start<OE?l.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 PE(t,e,o){if(!o)return{};const r=Ee(t,e);return r.length?me(t,e,r.map(a=>({...a,value:ua(kh(e,a.value+o))}))):ap(t,e,ua(kh(e,Zt(t,e,0)+o)),0)}function LE(t,e,o,{style:r="fly-truck",travel:a=1,spacing:n=1.2,swing:i=!0,push:l=!0,groups:u}={}){const c=by[r];if(!c)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=zE(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>c0)throw Error(`At most ${c0} stations`);const d=s.length,f=s.map((j,P)=>c.at(P,n));if(f.some(j=>Math.abs(j[0])>Pr.x.max||Math.abs(j[1])>Pr.y.max||j[2]<Bh+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 N=(Q,it)=>it?Math.round(Q.reduce((D,U)=>D+U,0)/Q.length/it)*it:0,F=j.clips.filter(Q=>!Q.parentId||!v.has(Q.parentId));if(!F.length)return;const[K,_,J]=f[P],X=c.at(1,n)[0]||0,rt=c.at(1,n)[1]||c.at(2,n)[1]||0,ot=c.at(1,n)[2]||0,G=[N(F.map(Q=>Zt(Q,"x",0)),X),N(F.map(Q=>Zt(Q,"y",0)),Math.abs(rt)),N(F.map(Q=>Zt(Q,"depth",0)),Math.abs(ot))];for(const Q of F){let it={...Q,is3D:!0},D={is3D:!0};for(const[U,ht]of[[0,"x"],[1,"y"],[2,"depth"]]){const yt=ua([K,_,J][U]-G[U]),Mt=PE(it,ht,yt);it={...it,...Mt},D={...D,...Mt}}m[Q.id]=D}const tt=P<d-1?s[P+1].time+a:null;if(tt!=null)for(const Q of j.clips)Q.kind!=="video"&&Q.start+Q.duration<tt&&(m[Q.id]={...m[Q.id],duration:ua(tt-Q.start)},g.push(Q.id))});const x=Qt["expo-in-out"],$=Qt.linear,E=s[0].time,S=s.at(-1).time+a;let k={...o??{...Mr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]};const y=Ys(k,"roll",E),A=j=>({cx:f[j][0],cy:f[j][1],cz:-5-f[j][2]}),I={cx:[],cy:[],cz:[],roll:[]},z=(j,P,N,F)=>I[j].push({time:ua(P),value:ua(Math.max(_n[j].min,Math.min(_n[j].max,N))),...F?{ease:F}:{}});if(s.forEach((j,P)=>{const N=A(P),F=P?j.time+a:E,K=P<d-1?s[P+1].time:null;for(const _ of["cx","cy","cz"])z(_,F,N[_],l&&_==="cz"?$:x);if(K!=null&&K-F>.3){const _=l?Math.min(.35,(K-F)*.12):0;for(const J of["cx","cy"])z(J,K,N[J],x);z("cz",K,N.cz+_,x)}}),i){const j=(N,F)=>Math.sign(F[0]-N[0]||F[1]-N[1]||1),P=Qt["sine-in-out"];z("roll",E,y),s.forEach((N,F)=>{if(!F)return;const K=j(f[F-1],f[F]);z("roll",N.time,y,P),z("roll",N.time+a/2,y-6*K,P),z("roll",N.time+a,y)})}for(const[j,P]of Object.entries(I)){if(!P.length)continue;const F=[...Yi(k,j).filter(K=>K.time<E-1e-6||K.time>S+1e-6),...P].sort((K,_)=>K.time-_.time).filter((K,_,J)=>!_||Math.abs(K.time-J[_-1].time)>1/120);k=bn(k,j,F)}return{patches:m,camera:zr(k),stations:d,extended:g}}function NE(t,e,{strength:o=1}={}){if(!(o>=.25&&o<=3))throw Error("Parallax strength must be 0.25–3");const r=t.filter(c=>e.includes(c.id)&&c.kind!=="audio");if(r.length<2)throw Error("Chọn ít nhất 2 layer để tách lớp parallax");const a=Lg(r,()=>0),n=a.length,i=Math.min(3,1.2*o),l=Math.max(Bh+1,-6*o),u={};return a.forEach((c,s)=>{const d=ua(l+(i-l)*s/(n-1)),f=Zt(c,"depth",0),m=(5-d)/(5-Math.min(4.5,f));let g={...c,is3D:!0},v={is3D:!0};for(const x of["depth","zoom","x","y"]){const $=k=>ua(kh(x,x==="depth"?k+d-f:k*m)),E=Ee(g,x),S=E.length?me(g,x,E.map(k=>({...k,value:$(k.value)}))):ap(g,x,$(Zt(g,x,0)),0);g={...g,...S},v={...v,...S}}u[c.id]=v}),u}const wy=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"}}),dj=Object.keys(wy),p0=48,FE=["x","y","depth","zoom","rot","tiltX","tiltY"],No=t=>Math.round(t*1e3)/1e3,Xa=t=>t*Math.PI/180,Ki=t=>t*180/Math.PI,u0=(t,e)=>Math.max(Pr[t].min,Math.min(Pr[t].max,e));function RE(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 DE(t,e,{rot:o=0,tiltX:r=0,tiltY:a=0}){const n=Xa(o),i=Xa(r),l=Xa(a),u=t*Math.cos(n)-e*Math.sin(n),c=t*Math.sin(n)+e*Math.cos(n),s=c*Math.cos(i),d=-c*Math.sin(i);return[u*Math.cos(l)-d*Math.sin(l),s,u*Math.sin(l)+d*Math.cos(l)]}function BE(t,e,{W:o=1280,H:r=720,spread:a=1,ids:n=[]}={}){const i=Or(o,r),l=[],u=([c,s,d],f)=>({x:c/o,y:s/r,depth:-d/i,...f});if(e==="wall"){const c=Math.max(1,Math.min(t,Math.ceil(Math.sqrt(t*1.4)))),s=Math.ceil(t/c),d=.1*a,f=Math.min(.6,1.6/(c*(1+d))),m={rot:-8,tiltX:26,tiltY:-20};for(let g=0;g<t;g++){const v=g%c,x=Math.floor(g/c);l.push(u(DE((v-(c-1)/2)*o*f*(1+d),(x-(s-1)/2)*r*f*(1+d),m),{zoom:f,...m}))}}else if(e==="arc"){const c=Math.min(.75,2.4/t),s=o*c*(1+.012*a),d=4.2*i/Math.max(.5,a),f=s/d;for(let m=0;m<t;m++){const g=(m-(t-1)/2)*f;l.push(u([d*Math.sin(g),0,d*(Math.cos(g)-1)],{zoom:c,rot:0,tiltX:0,tiltY:-Ki(g)}))}}else if(e==="fan"){const s=Math.min(14,70/Math.max(1,t-1))*a,d=r*.42*1.15;for(let f=0;f<t;f++){const m=(f-(t-1)/2)*s,g=Xa(m);l.push(u([d*Math.sin(g),r*.12+d*(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 d=RE(n[s]??s),f=Math.min(2,a);l.push({x:(d()-.5)*.9*f,y:(d()-.5)*.7*f,depth:-3.5*d()*f+1.2,zoom:.32,rot:(d()-.5)*50,tiltX:(d()-.5)*70,tiltY:(d()-.5)*80})}else if(e==="stack")for(let c=0;c<t;c++)l.push({x:.05*c*a,y:-.035*c*a,depth:-1.4*c*a,zoom:1,rot:c%2?-2:2,tiltX:0,tiltY:-10});else if(e==="boards")for(let c=0;c<t;c++){const s=c%2?1:-1;l.push({x:1.25*c*a,y:s*.12*a,depth:-2.2*c*a,zoom:1,rot:s*-3,tiltX:s*-6,tiltY:s*28})}else throw Error(`Unknown 3D layout "${e}"`);return l}function ky(t,e,o,{W:r=1280,H:a=720,spread:n=1}={}){if(!wy[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 l=e.map(s=>i.get(s)).filter(s=>s&&s.kind!=="audio");if(l.length<2)throw Error("Chọn ít nhất 2 layer để sắp xếp 3D");if(l.length>p0)throw Error(`At most ${p0} layers`);o==="stack"&&(l=Lg(l,()=>0).reverse());const u=BE(l.length,o,{W:r,H:a,spread:n,ids:l.map(s=>s.id)}),c={};return l.forEach((s,d)=>{let f={...s,is3D:!0},m={is3D:!0};for(const g of FE){const v=No(u0(g,u[d][g])),x=Ee(f,g),$=x.length?me(f,g,x.map(E=>({...E,value:No(u0(g,E.value+v-x[0].value))}))):ap(f,g,v,0);f={...f,...$},m={...m,...$}}c[s.id]=m}),c}function h0(t,e,o,r,{margin:a=1}={}){const n=Or(o,r),{center:i,corners:[l,u,c]}=_l(t,e,o,r),s=(N,F)=>N.map((K,_)=>K-F[_]),d=N=>Math.hypot(...N),f=N=>{const F=d(N)||1;return N.map(K=>K/F)},m=s(u,l),g=s(c,l),v=d(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]]),$=5*n*v/o*a,E=i.map((N,F)=>N-x[F]*$),S=Ki(Math.asin(Math.max(-1,Math.min(1,-x[1])))),k=Ki(Math.atan2(x[0],x[2])),y=Xa(k),A=Xa(S),I=[Math.cos(y),0,-Math.sin(y)],z=[Math.sin(y)*Math.sin(A),Math.cos(A),Math.cos(y)*Math.sin(A)],j=f(m),P=Ki(Math.atan2(j[0]*z[0]+j[1]*z[1]+j[2]*z[2],j[0]*I[0]+j[1]*I[1]+j[2]*I[2]));return{cx:E[0]/o,cy:E[1]/r,cz:E[2]/n,pan:k,tilt:S,roll:P}}const _E=(t,e)=>e==null?t:t+360*Math.round((e-t)/360);function xh(t,e,o,{at:r=0,flight:a=1,hold:n=1.5,margin:i=1,push:l=!0,W:u=1280,H:c=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])),d=e.map(y=>s.get(y)).filter(y=>y&&y.kind!=="audio");if(!d.length)throw Error("Chọn layer để camera bay tới");if(d.length>24)throw Error("At most 24 layers in one tour");const f={...o??{...Mr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},m=["cx","cy","cz","pan","tilt","roll"],g=Object.fromEntries(m.map(y=>[y,[]])),v=(y,A,I,z)=>g[y].push({time:No(A),value:No(Math.max(_n[y].min,Math.min(_n[y].max,I))),...z?{ease:z}:{}}),x=Qt["expo-in-out"],$=Qt.linear,E=Object.fromEntries(m.map(y=>[y,Ys(f,y,r)]));for(const y of m)v(y,r,E[y],x);let S=r;d.forEach((y,A)=>{const I=S+a,z=Math.max(0,Math.min(y.duration,I-y.start)),j=h0({...y,is3D:!0},z,u,c,{margin:i});for(const N of["pan","roll"])j[N]=_E(j[N],E[N]);const P=A===d.length-1;for(const N of m)v(N,I,j[N],N==="cz"&&l&&n>0?$:x);if(n>0){const N=I+n,F=l?Math.min(.04,n*.015):0,K=h0({...y,is3D:!0},z,u,c,{margin:i*(1-F)});for(const _ of m)v(_,N,_==="pan"||_==="roll"?j[_]:K[_],P?void 0:x);S=N}else S=I;Object.assign(E,j)});let k=f;for(const y of m){const A=Yi(k,y).filter(I=>I.time<r-1e-6||I.time>S+1e-6);k=bn(k,y,[...A,...g[y]].sort((I,z)=>I.time-z.time).filter((I,z,j)=>!z||Math.abs(I.time-j[z-1].time)>1/120))}return{camera:zr(k),end:No(S)}}const xy=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}]);xy.map(t=>t.id);function GE(t,e,o,r,{at:a,W:n=1280,H:i=720}={}){const l=xy.find(g=>g.id===r);if(!l)throw Error(`Unknown 3D scene "${r}"`);const u=ky(t,e,l.layout,{W:n,H:i}),c=new Map(t.map(g=>[g.id,g])),s=e.filter(g=>u[g]),d=t.map(g=>u[g.id]?{...g,...u[g.id]}:g),f=Number.isFinite(a)?a:Math.min(...s.map(g=>c.get(g).start));let m;if(l.camera==="tour")m=xh(d,l.layout==="stack"?[...s].sort((g,v)=>Zt({...c.get(v),...u[v]},"depth",0)-Zt({...c.get(g),...u[g]},"depth",0)):s,o,{at:f,flight:l.flight,hold:l.hold,margin:l.margin,W:n,H:i});else if(l.camera==="glide"||l.camera==="sweep"){const g=Or(n,i),v=s.map(I=>{const z=d.find(j=>j.id===I);return _l(z,0,n,i).center}),x=Math.min(12,Math.max(4,s.length*.8)),$=f+x,E={...o??{...Mr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},S=Qt["sine-in-out"],k={cx:[],cy:[],cz:[],pan:[],tilt:[],roll:[]},y=(I,z,j,P)=>k[I].push({time:No(z),value:No(Math.max(_n[I].min,Math.min(_n[I].max,j))),...P?{ease:P}:{}});if(l.camera==="glide"){const I=d.find(F=>F.id===s[0]),z=Math.hypot(..._l(I,0,n,i).corners[1].map((F,K)=>F-_l(I,0,n,i).corners[0][K])),j=5*g*z/n*l.margin,P=v[0],N=v.at(-1);y("cx",f,P[0]/n,S),y("cx",$,N[0]/n),y("cy",f,P[1]/i,S),y("cy",$,N[1]/i),y("cz",f,(P[2]-j)/g,S),y("cz",$,(N[2]-j)/g);for(const F of["pan","tilt"])y(F,f,0);y("roll",f,-3,S),y("roll",$,2)}else{const z=j=>Ki(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",$,z(v.at(-1)))}let A=E;for(const[I,z]of Object.entries(k))z.length&&(A=bn(A,I,[...Yi(A,I).filter(j=>j.time<f-1e-6||j.time>$+1e-6),...z].sort((j,P)=>j.time-P.time)));m={camera:zr(A),end:No($)}}else if(l.camera==="push")m=xh(d,[s[Math.floor(s.length/2)]],o,{at:f,flight:l.flight,hold:l.hold,margin:l.margin,W:n,H:i});else{const g={...o??{...Mr},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},v=Math.max(4,s.length*1.2),x=5,$=f+v,E=Qt["sine-in-out"],S={cx:[],cz:[],pan:[]};for(let y=0;y<=4;y++){const A=Xa(-40+y*20),I=f+v*y/4,z=x-1.2*y/4;S.cx.push({time:No(I),value:No(Math.sin(A)*z*Or(n,i)/n),ease:E}),S.cz.push({time:No(I),value:No(-Math.cos(A)*z),ease:E}),S.pan.push({time:No(I),value:No(-Ki(A)),ease:E})}let k=g;for(const[y,A]of Object.entries(S))k=bn(k,y,[...Yi(k,y).filter(I=>I.time<f-1e-6||I.time>$+1e-6),...A].sort((I,z)=>I.time-z.time));m={camera:zr(k),end:No($)}}for(const g of s){const v=c.get(g);v.kind!=="video"&&v.start+v.duration<m.end&&(u[g]={...u[g],duration:No(m.end-v.start)})}return{patches:u,camera:m.camera,end:m.end}}const Aa=Object.freeze({angle:300,strips:[3,10],samples:16}),KE=Object.freeze(["center","start","end"]),ou=["posX","posY","scale","scaleX","scaleY","rotation","tiltX","tiltY","spatialDepth","anchorX","anchorY","motionKeys","motionV","parentId","zIndex"],Lo=t=>Math.round(t*1e4)/1e4;function VE(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 My(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 WE(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 HE(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 l=r/n,u=n/e,c=(i-a)*n,s=l*Math.cos(u/2);return{along:a*r+s*Math.sin(c),depth:l-s*Math.cos(c),turn:c*180/Math.PI,chord:Math.abs(2*l*Math.sin(u/2))/(r/e)}}function XE(t,e,o,r,{angle:a=60,angleTo:n,angleKeys:i,axis:l,anchor:u,strips:c,aspect:s,media:d,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)>Aa.angle||n!=null&&(!v(n)||Math.abs(n)>Aa.angle))throw Error("Góc uốn từ −300° đến 300°");const x=VE(t,o),$=new Map(t.map(Y=>[Y.id,Y])),E=x?$.get(x.bend.source):$.get(o);if(!E)throw Error("Không thấy layer để uốn");if(E.kind!=="image"||E.nullLayer||E.solid||E.fit==="cover"||E.geo||E.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={},A=[],I=UE(x?S[0]?.motionKeys:E.motionKeys),z=x?$.get(x.bend.source):$.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)>Aa.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=d0(x.motionKeys,I);y[E.id]={disabled:void 0,...Object.fromEntries(ou.map(ct=>[ct,x[ct]])),motionKeys:Y.length?Y:void 0}}return{add:A,patches:y,remove:k,camera:r??null,end:E.start+E.duration}}const N=l==="y"||!l&&x?.bend.axis==="y"?"y":"x";if(u!=null&&!KE.includes(u))throw Error("Điểm giữ: center, start hoặc end");const F=u??x?.bend.anchor??"center",K=F==="start"?-.5:F==="end"?.5:0,_=Math.max(Aa.strips[0],Math.min(Aa.strips[1],Math.round(c??x?.bend.strips??8))),J=E.crop??{left:0,right:0,top:0,bottom:0},X=1-J.left-J.right,rt=1-J.top-J.bottom,ot=(v(s)&&s>0?+s:My(E,m,g,d))*X/rt,G=Y=>Y<=m/g?[g*Y,g]:[m,m/Y],[tt,Q]=G(ot),it=N==="x"?tt:Q,D=Math.min(_,Math.floor((N==="x"?X:rt)/.1+1e-9));if(D<Aa.strips[0])throw Error("Layer đã cắt quá hẹp để uốn");const U=Or(m,g),ht=Math.min(E.motionBlur?.05:.012,.3/D),yt=t.filter(Y=>!k.includes(Y.id)),Mt=Y=>{const{track:ct}=qt(yt,e,Y.start,Y.start+Y.duration),gt={...Y,track:ct};return yt.push(gt),gt},p=x?{...x}:Mt({...xr({id:f(),track:0,start:E.start,duration:E.duration,label:`Uốn cong · ${String(E.label||"").slice(0,40)}`,is3D:!0}),...Object.fromEntries(ou.filter(Y=>E[Y]!==void 0).map(Y=>[Y,E[Y]])),...E.motionKeys?{motionKeys:YE(E.motionKeys)}:{},is3D:!0}),lt={source:E.id,angle:Lo(j?j[0].angle:+a),axis:N,strips:D,...K?{anchor:F}:{},...j?{angleKeys:j.map(Y=>({time:Lo(Y.time),angle:Lo(Y.angle)}))}:v(n)?{angleTo:Lo(+n)}:{}};x?y[x.id]={bend:lt}:(p.bend=lt,A.push(p));const V=WE(E,m,g,d)?.[N==="x"?0:1],h=N==="x"?J.left:J.top,w=N==="x"?X:rt,T=Y=>{if(!V)return Y;const ct=Math.round((h+Y*w)*V/2)*2/V;return Math.max(0,Math.min(1,(ct-h)/w))},C=Y=>Math.round(Y*1e6)/1e6,O=(Y,ct)=>{const gt=C(h+Y*w),Z=C(1-(h+ct*w));if(!V)return{lo:Y,hi:ct,a0:gt,b0:Z};const nt=Math.trunc(V*gt/2)*2,dt=Math.max(2,Math.trunc(V*(1-gt-Z)/2)*2);return{lo:(nt/V-h)/w,hi:((nt+dt)/V-h)/w,a0:gt,b0:Z}},L=Y=>{const{lo:ct,hi:gt,a0:Z,b0:nt}=O(T(Math.max(0,Y/D-(Y?ht:0))),T(Math.min(1,(Y+1)/D+(Y<D-1?ht:0)))),[dt,vt]=G(N==="x"?ot*(gt-ct):ot/(gt-ct));return{lo:ct,hi:gt,a0:Z,b0:nt,zoom:N==="x"?Q/vt:tt/dt}},B=(Y,ct)=>{const gt=HE(Y,D,ct,it,K),{lo:Z,hi:nt,zoom:dt}=L(Y),vt=((Z+nt)/2-(Y+.5)/D)*it,At=gt.turn*Math.PI/180,xt=gt.along+vt*gt.chord*Math.cos(At),St=gt.depth+vt*gt.chord*Math.sin(At);return N==="x"?{x:Lo(xt/m),depth:Lo(St/U),tiltY:Lo(-gt.turn),zoom:Lo(dt),sx:Lo(gt.chord)}:{y:Lo(xt/g),depth:Lo(St/U),tiltX:Lo(gt.turn),zoom:Lo(dt),sy:Lo(gt.chord)}},H=Qt["sine-in-out"],q=j?j.map(Y=>[Y.time,Y.angle]):v(n)&&+n!=+a?[[0,+a],[E.duration,+n]]:null,et=q?q.slice(1).flatMap(([Y,ct],gt)=>{const[Z,nt]=q[gt],dt=Math.max(2,Math.floor(Aa.samples*2/q.length));return Array.from({length:dt+(gt?0:1)},(vt,At)=>{const xt=(At+(gt?1:0))/dt;return[Z+(Y-Z)*xt,nt+(ct-nt)*qE(H,xt)]})}):null,st=Object.fromEntries(Object.entries(E).filter(([Y])=>!ou.includes(Y)&&!["id","track","disabled","bendStrip"].includes(Y)));for(let Y=0;Y<D;Y++){const{a0:ct,b0:gt}=L(Y),Z=N==="x"?{left:ct,right:gt,top:J.top,bottom:J.bottom}:{left:J.left,right:J.right,top:ct,bottom:gt},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=et?et.map(([St,jt])=>{const{zoom:Kt,...ee}=B(Y,jt);return{time:Lo(St),...Object.fromEntries(Object.entries(ee).filter(([,le])=>le!==void 0))}}):[],At=d0(vt,I),xt=Mt({...st,id:f(),label:`${String(E.label||"Layer").slice(0,40)} · ${Y+1}/${D}`,start:E.start,duration:E.duration,parentId:p.id,is3D:!0,bendStrip:!0,crop:Z,...Object.fromEntries(Object.entries(dt).filter(([,St])=>St!==void 0)),...At.length?{motionV:2,motionKeys:At}:{}});A.push(xt)}return x||(y[E.id]={disabled:!0}),{add:A,patches:y,remove:k,camera:zr({...r??{...Mr,motionKeys:[]},enabled:!0}),end:E.start+E.duration}}const UE=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 YE(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 d0(t,e){const o=new Map;for(const r of[...t??[],...e??[]]){const a=Lo(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 qE(t,e){const[o,r,a,n]=t,i=(c,s,d)=>3*c*d*(1-d)**2+3*s*d*d*(1-d)+d**3;let l=0,u=1;for(let c=0;c<30;c++){const s=(l+u)/2;i(o,a,s)<e?l=s:u=s}return i(r,n,(l+u)/2)}const vy=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"}]),ZE=vy.map(t=>t.id),Ge=t=>Math.round(t*1e3)/1e3,JE=Qt.linear,ru=Qt["sine-in-out"];function li(t,e,o){const{track:r}=qt(t,e,o.start,o.start+o.duration),a={...o,track:r};return t.push(a),a}const nu=t=>({motionV:2,motionKeys:t.map(([e,o,r])=>({time:Ge(e),...o,...r?{ease:Object.fromEntries(Object.keys(o).map(a=>[a,r]))}:{}}))});function QE(t,e,o,r,a,{at:n,newId:i,W:l=1280,H:u=720,duration:c,angle:s,angleTo:d,angleKeys:f,axis:m,anchor:g,media:v}={}){if(!vy.some(N=>N.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 XE(t,e,o[0],r,{angle:s??60,angleTo:d,angleKeys:f,axis:m,anchor:g,newId:i,W:l,H:u,media:v})}const x=new Map(t.map(N=>[N.id,N])),$=o.map(N=>x.get(N)).filter(N=>N&&N.kind!=="audio"&&!N.nullLayer);if(a!=="cube-spin"&&!$.length)throw Error("Chọn layer để dựng rig null 3D");const E=Number.isFinite(n)?n:$.length?Math.min(...$.map(N=>N.start)):0,S=Ge(Math.max(2,Math.min(30,c??6))),k=Ge(E+S),y=Or(l,u),A=[...t],I=[],z={},j=N=>{z[N.id]={...z[N.id]??{},is3D:!0,...N.kind!=="video"&&N.start+N.duration<k?{duration:Ge(k-N.start)}:{}}};let P=r;if(a==="orbit-system"){const N=li(A,e,{...xr({id:i(),track:0,start:E,duration:S,label:"Quỹ đạo",is3D:!0}),posY:.06,tiltX:-70});I.push(N);const F=li(A,e,{...xr({id:i(),track:0,start:E,duration:S,label:"Vòng quay",is3D:!0}),parentId:N.id,...nu([[0,{tiltY:0},JE],[S,{tiltY:360}]])});I.push(F);const K=.3,_=$.length;$.forEach((J,X)=>{const rt=2*Math.PI*X/_;z[J.id]={parentId:F.id,is3D:!0,posX:Ge(K*Math.cos(rt)),posY:0,spatialDepth:Ge(K*Math.sin(rt)*l/y),scale:Ge(Math.min(.24,.9/Math.max(3,_))),tiltX:70,rotation:0,tiltY:0},j(J)})}else if(a==="cube-spin"){const N=li(A,e,{...xr({id:i(),track:0,start:E,duration:S,label:"Khối",is3D:!0}),...nu([[0,{tiltY:-25,tiltX:18},ru],[S,{tiltY:335,tiltX:-22}]])});I.push(N);const F=.56*u,K=F/2,_=Ge(F/(u*.96)),J=Ue({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"}}]}),X=[["Mặt trước",{spatialDepth:Ge(K/y)}],["Mặt sau",{spatialDepth:Ge(-K/y),tiltY:180}],["Mặt phải",{posX:Ge(K/l),tiltY:90}],["Mặt trái",{posX:Ge(-K/l),tiltY:-90}],["Mặt trên",{posY:Ge(-K/u),tiltX:90}],["Mặt dưới",{posY:Ge(K/u),tiltX:-90}]];for(const[ot,G]of X){const tt=li(A,e,{id:i(),nodeId:"",kind:"image",url:"",label:ot,track:0,start:E,duration:S,volume:0,motionV:2,fit:"contain",shape:structuredClone(J),is3D:!0,parentId:N.id,scale:_,...G});I.push(tt)}const rt=Ue({v:2,square:!0,items:[{id:"g",name:"Glow",type:"rect",params:{w:960,h:960,round:4},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#e8f0ff",width:44,blur:24,join:"round",cap:"round"}},{id:"r",name:"Light",type:"rect",params:{w:960,h:960,round:4},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#ffffff",width:14,join:"round",cap:"round"}}]});for(const[ot,G,tt]of[["Tia cạnh phải",X[2][1],2],["Tia cạnh trái",X[3][1],3]]){const it=[];for(let D=0;D<tt;D++)it.push({time:Ge(S*D/tt),trimStart:0,trimEnd:.14},{time:Ge(S*(D+1)/tt-(D<tt-1?.001:0)),trimStart:1-.14,trimEnd:1});I.push(li(A,e,{id:i(),nodeId:"",kind:"image",url:"",label:ot,track:0,start:E,duration:S,volume:0,motionV:2,motionKeys:it,fit:"contain",shape:structuredClone(rt),is3D:!0,parentId:N.id,scale:_,...G}))}$.forEach((ot,G)=>{z[ot.id]={parentId:N.id,is3D:!0,posX:0,posY:0,spatialDepth:Ge((G-($.length-1)/2)*.4),scale:Ge(Math.min(.26,.6/Math.max(1,$.length))),tiltX:0,tiltY:0},j(ot)})}else{const N=$[0],F=Math.max(0,Math.min(N.duration,E-N.start)),K=li(A,e,{...xr({id:i(),track:0,start:E,duration:S,label:"Tâm camera",is3D:!0}),posX:Ge(Zt(N,"x",F)),posY:Ge(Zt(N,"y",F)),spatialDepth:Ge(Zt(N,"depth",F)),tiltX:-10,...nu([[0,{tiltY:-40},ru],[S,{tiltY:40}]])});I.push(K);for(const J of $)j(J);P={...r??{...Mr},enabled:!0,motionV:2,motionKeys:r?.motionKeys??[],parentId:K.id};for(const[J,X]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=bn(P,J,[...Yi(P,J).filter(rt=>rt.time<E-1e-6||rt.time>k+1e-6),...X.map(([rt,ot],G)=>({time:Ge(E+rt),value:ot,...G===0&&X.length>1?{ease:ru}:{}}))].sort((rt,ot)=>rt.time-ot.time));P=zr(P)}return a!=="camera-orbit"&&(P=zr({...r??{...Mr,motionKeys:[]},enabled:!0})),{add:I,patches:z,camera:P,end:k}}const tS=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"}]),$y=tS.map(t=>t.id),Xe=t=>Math.round(t*1e3)/1e3,Ps=t=>Qt[t];function Zn(t,e,o){const{track:r}=qt(t,e,o.start,o.start+o.duration),a={...o,track:r};return t.push(a),a}const ws=t=>({motionV:2,motionKeys:t.map(([e,o,r])=>({time:Xe(e),...o,...r?{ease:Object.fromEntries(Object.keys(o).map(a=>[a,Ps(r)]))}:{}}))}),El=(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:Ue({v:2,square:!0,items:a}),...n});function Sl(t,e,o){const r=(t.motionKeys??[]).map(a=>{const{[e]:n,ease:i,...l}=a;if(i){const{[e]:u,...c}=i;Object.keys(c).length&&(l.ease=c)}return l}).filter(a=>Object.keys(a).some(n=>n!=="time"&&n!=="ease"));for(const[a,n,i]of o){let l=r.find(u=>Math.abs(u.time-a)<.008333333333333333);l||r.push(l={time:Xe(a)}),l[e]=Xe(n),i&&(l.ease={...l.ease,[e]:Ps(i)})}return r.sort((a,n)=>a.time-n.time)}function eS(t,e,o,r,a,{at:n,newId:i,W:l=1280,H:u=720,duration:c,color:s,media:d}={}){if(!$y.includes(a))throw Error(`Unknown 3D null rig "${a}"`);const f=new Map(t.map(I=>[I.id,I])),m=o.map(I=>f.get(I)).filter(I=>I&&I.kind!=="audio"&&!I.nullLayer),g=Number.isFinite(n)?n:m.length?Math.min(...m.map(I=>I.start)):0,v=Xe(Math.max(2,Math.min(30,c??6))),x=Xe(g+v),$=[...t],E=[],S={},k=I=>({is3D:!0,...I.kind!=="video"&&I.start+I.duration<x?{duration:Xe(x-I.start)}:{}});let y=zr({...r??{...Mr,motionKeys:[]},enabled:!0});const A=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 I=m.slice(0,6),z=I.length,j=(z-1)/2,P=Zn($,e,{...xr({id:i(),track:0,start:g,duration:v,label:"Quạt thẻ",is3D:!0}),tiltX:-8,...ws([[0,{tiltY:-10},"sine-in-out"],[v,{tiltY:10}]])});E.push(P);const N=Xe(Math.min(.42,1.1/Math.max(2.4,z)));I.forEach((F,K)=>{const _=K-j,J=Xe(_*Math.min(.17,.8/Math.max(1,z))),X=Xe(_*9),rt=Xe(Math.abs(_)*.025),ot=g-F.start,G=Math.max(0,ot)+K*.09,tt=G+.7;let Q={parentId:P.id,...k(F),posX:J,posY:rt,scale:N,rotation:X,tiltX:0,tiltY:Xe(-_*8),spatialDepth:Xe(K*.12),opacity:1,motionV:2},it=Sl(F,"x",[[G,0,"back-out"],[tt,J]]);it=Sl({motionKeys:it},"y",[[G,.45,"expo-out"],[tt,rt]]),it=Sl({motionKeys:it},"rot",[[G,0,"back-out"],[tt,X]]),it=Sl({motionKeys:it},"opacity",[[G,0,"ease-out"],[G+.25,1]]),S[F.id]={...Q,motionKeys:it}})}else if(a==="coin-beam"){const I=Zn($,e,El(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:[[`${A}00`,0],[`${A}66`,.5],[`${A}00`,1]]},stroke:null},{id:"b",name:"Beam",type:"rect",params:{w:240,h:1e3,round:0},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"linear",angle:0,stops:[[`${A}10`,0],[`${A}cc`,.35],["#e8ffffee",.5],[`${A}cc`,.65],[`${A}10`,1]]},stroke:null}],{...ws([[0,{opacity:0},"ease-out"],[.5,{opacity:1}]])}));E.push(I);const z=Zn($,e,El(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:[[`${A}aa`,0],[`${A}00`,1]]},stroke:null}],{posY:.3,scale:.8}));E.push(z);const j=Zn($,e,{...xr({id:i(),track:0,start:g,duration:v,label:"Đồng xu",is3D:!0}),...ws([[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}]])});E.push(j);const P=.46;if(E.push(Zn($,e,El(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],[A,.45],["#0b4f55",1]]},stroke:{color:"#e9ffff",width:16}},{id:"r",name:"Rim",type:"ellipse",params:{w:800,h:800},pos:[500,500],rot:0,scale:[1,1],opacity:.5,fill:{type:"none"},stroke:{color:"#0b4f55",width:10}}],{is3D:!0,parentId:j.id,scale:P,spatialDepth:0}))),m[0]){const N=m[0],{track:F}=qt($.filter(X=>X.id!==N.id),e,Math.min(N.start,g),Math.max(N.start+N.duration,x)),K=My(N,l,u,d),_=.6*P*.94*u,J=K>=l/u?_/l:_/(u*Math.max(1,K));S[N.id]={parentId:j.id,...k(N),track:F,posX:0,posY:0,scale:Xe(J),rotation:0,tiltX:0,tiltY:0,spatialDepth:.02}}}else if(a==="grid-floor"){const j=[],P=[];for(let _=0;_<=10;_++){const J=Xe(_*100),X=_%2?[J,1e3]:[J,0],rt=_%2?[J,0]:[J,1e3];j.push(X,rt)}for(let _=0;_<=10;_++){const J=Xe(_*100),X=_%2?[1e3,J]:[0,J],rt=_%2?[0,J]:[1e3,J];P.push(X,rt)}const N=(_,J,X,rt)=>({id:_,name:J,type:"path",params:{pts:X,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:rt?.35:.9,fill:{type:"none"},stroke:{color:rt?A:"#cfe9ff",width:rt?10:2.5,...rt?{blur:10}:{},join:"miter"}}),F=Zn($,e,{...xr({id:i(),track:0,start:g,duration:v,label:"Sàn lưới",is3D:!0}),posY:.28,tiltX:-78,...ws([[0,{y:.1},"linear"],[v,{y:0}]])});E.push(F),E.push(Zn($,e,El(i(),g,v,"Lưới",[N("gv","Glow V",j,!0),N("gh","Glow H",P,!0),N("v","Lines V",j),N("h","Lines H",P)],{is3D:!0,parentId:F.id,scale:2.6,opacity:.8})));const K=m.length;m.forEach((_,J)=>{S[_.id]={...k(_),posX:Xe((J-(K-1)/2)*.28),posY:-.04,spatialDepth:Xe(-.3*(J%2)),scale:Xe(Math.min(.3,.9/Math.max(3,K))),tiltX:0,tiltY:0}})}else{const I=m.find(F=>["image","video"].includes(F.kind)&&F.url);if(!I)throw Error("Chọn một clip ảnh hoặc video để đưa lên màn hình điện thoại");const z=Zn($,e,{...xr({id:i(),track:0,start:g,duration:v,label:"Điện thoại",is3D:!0}),...ws([[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}]])});E.push(z);const{clip:j,sourcePatch:P}=Ng($,e,I,"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:Ps("expo-out")}},{time:1.6,ry:-14,ease:{ry:Ps("sine-in-out")}},{time:Xe(v),ry:12}]}});j.duration=v,$.push(j),E.push(j),S[I.id]={...P,...I.kind==="image"&&I.start+I.duration<x?{duration:Xe(x-I.start)}:{}};let N={...y,motionV:2,motionKeys:y.motionKeys??[]};N=bn(N,"cz",[...Yi(N,"cz").filter(F=>F.time<g-1e-6||F.time>x+1e-6),{time:Xe(g),value:-6,ease:Ps("sine-in-out")},{time:x,value:-4.8}].sort((F,K)=>F.time-K.time)),y=zr(N)}return{add:E,patches:S,camera:y,end:x}}const zi=Object.freeze({points:[2,24],samples:[8,48]}),oS=Object.freeze(["x","y","depth","rot","tiltY"]),ea=t=>Math.round(t*1e4)/1e4,Ka=(t,e)=>Math.max(Pr[t].min,Math.min(Pr[t].max,e));function Ey(t){if(!t||typeof t!="object")throw Error("Invalid motion path");const e=t.points;if(!Array.isArray(e)||e.length<zi.points[0]||e.length>zi.points[1])throw Error(`Motion path needs ${zi.points[0]}–${zi.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[Ka("x",a[0]),Ka("y",a[1]),...a.length===3?[Ka("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]=ea(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"||!Qt[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 rS(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,c)=>{const s=r(u-1),d=r(u),f=r(u+1),m=r(u+2),g=(I,z)=>Math.max(1e-6,Math.sqrt(Math.hypot(...I.map((j,P)=>j-z[P])))),v=g(s,d),x=v+g(d,f),$=x+g(f,m),E=v+(x-v)*c,S=(I,z,j,P)=>I.map((N,F)=>(P-E)/(P-j)*N+(E-j)/(P-j)*z[F]),k=S(s,d,0,v),y=S(d,f,v,x),A=S(f,m,x,$);return S(S(k,y,0,x),S(y,A,v,$),v,x)},i=[{s:0,p:t[0].slice()}];for(let u=0;u<a;u++)for(let c=1;c<=24;c++){const s=n(u,c/24),d=i.at(-1);i.push({s:d.s+Math.hypot(...s.map((f,m)=>f-d.p[m])),p:s})}const l=i.at(-1).s||1;return u=>{const c=Math.max(0,Math.min(1,u))*l;let s=1;for(;s<i.length-1&&i[s].s<c;)s++;const d=i[s-1],f=i[s],m=f.s>d.s?(c-d.s)/(f.s-d.s):0;return d.p.map((g,v)=>g+(f.p[v]-g)*m)}}function Sy(t,e,{W:o=1280,H:r=720}={}){const a=Ey(e),n=Or(o,r),i=a.points.some($=>$.length===3),l=a.points.map($=>[$[0]*o,$[1]*r,($[2]??0)*n]),u=rS(l,!!a.closed),c=Math.min(a.start??0,Math.max(0,t.duration-.1)),s=Math.min(t.duration,a.end??t.duration),d=Math.max(.1,s-c),f=Math.max(zi.samples[0],Math.min(zi.samples[1],Math.max(Math.round(d*6),a.points.length*4))),m=Qt[a.ease??"linear"],g=[];for(let $=0;$<=f;$++)g.push(u(md(m,$/f)));const v=$=>ea(c+d*$/f),x={x:[],y:[],...i?{depth:[]}:{}};if(g.forEach(($,E)=>{const S=E<f?{ease:"auto"}:{};x.x.push({time:v(E),value:ea(Ka("x",$[0]/o)),...S}),x.y.push({time:v(E),value:ea(Ka("y",$[1]/r)),...S}),i&&x.depth.push({time:v(E),value:ea(Ka("depth",$[2]/n)),...S})}),a.orient){const $=y=>{const A=u(Math.max(0,y-.004)),I=u(Math.min(1,y+.004));return[I[0]-A[0],I[1]-A[1],I[2]-A[2]]},E=y=>{for(let A=1;A<y.length;A++){let I=y[A].value-y[A-1].value;for(;I>180;)y[A].value-=360,I-=360;for(;I<-180;)y[A].value+=360,I+=360}return y},S=[],k=[];for(let y=0;y<=f;y++){const[A,I,z]=$(md(m,y/f)),j=y<f?{ease:"auto"}:{};if(i){const P=Math.hypot(A,z);k.push({time:v(y),value:ea(Math.atan2(-z,A||1e-9)*180/Math.PI),...j}),S.push({time:v(y),value:ea(Math.atan2(I,P||1e-9)*180/Math.PI),...j})}else S.push({time:v(y),value:ea(Math.atan2(I,A||1e-9)*180/Math.PI),...j})}x.rot=E(S),i&&(x.tiltY=E(k));for(const y of oS)x[y]&&(x[y]=x[y].map(A=>({...A,value:Ka(y,A.value)})))}return x}function nS(t,e,{W:o=1280,H:r=720}={}){let a={...t},n={};const i=t.path?aS(t.path):[];for(const c of i){const s=me(a,c,[]);a={...a,...s},n={...n,...s}}if(!e)return{...n,path:void 0};const l=Ey(e),u=Sy(a,l,{W:o,H:r});for(const[c,s]of Object.entries(u)){const d=me(a,c,s);a={...a,...d},n={...n,...d}}return{...n,path:l}}function aS(t){const e=t.points?.some(o=>o.length===3);return["x","y",...e?["depth"]:[],...t.orient?e?["rot","tiltY"]:["rot"]:[]]}function fj(t,{W:e=1280,H:o=720}={}){if(!t.path)return!1;try{const r=Sy(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((l,u)=>Math.abs(l.time-n[u].time)<.001&&Math.abs(l.value-n[u].value)<.001)})}catch{return!1}}const iS=1,Iy=100,sS=40,lS=60,rd=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"}),Ay=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"]}),cS=(t,e=3)=>Ay[t]?.[e<=2?0:e>=4?2:1]??rd[t]??null;Object.freeze([...new Set([...Object.values(rd),...Object.values(Ay).flat()].filter(Boolean))]);const pS=Object.freeze(["hook","build","payoff","reaction","outro"]),uS=Object.freeze(["text","framing","motion","color"]),hS=Object.freeze({"extreme-close":1.3,close:1.15,insert:1.2}),f0=["luma","sat","warmth","contrast","shadowTint","highlightTint"],zn=t=>Math.round(t*1e3)/1e3,Gc=(t,e,o)=>Math.max(e,Math.min(o,t)),Cy=t=>t&&typeof t=="object"&&f0.every(e=>Number.isFinite(t[e])&&Math.abs(t[e])<=1)?Object.fromEntries(f0.map(e=>[e,zn(t[e])])):null;function dS(t){const e=Cy(t);return e?e.sat<.07?{effect:"mono",amount:.8}:e.shadowTint>.03&&e.highlightTint>.04?{effect:"teal-orange",amount:.6}:e.warmth>.08?{effect:"warm",amount:zn(Gc((e.warmth-.04)*6,.3,.8))}:e.warmth<-.04?{effect:"cool",amount:zn(Gc(-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 fS(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(l=>/\d/.test(l)):-1,n=Gc(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 mS(t,e,o,r){const a=(i,l)=>(Array.isArray(i?.scenes)?i.scenes:[]).find(u=>u.start<=l&&u.end>l&&Number.isFinite(u.flowX))?.flowX??0;return a(t,Math.max(0,e-.05))+a(o,r+.05)>.02?1:-1}function gS(t){if(!t||typeof t!="object"||t.v!==iS||!(t.duration>0&&t.duration<=3600)||!Array.isArray(t.shots)||!t.shots.length||t.shots.length>Iy)throw Error("Invalid reference recipe");for(const e of t.shots)if(!(e?.len>0&&e.len<=3600)||!Object.hasOwn(rd,e.transition)||!pS.includes(e.role))throw Error("Invalid reference shot");if(t.color!==void 0&&!Cy(t.color))throw Error("Invalid reference colour");return t}function yS(t){return Object.fromEntries(uS.map(e=>[e,!(t&&typeof t=="object"&&t[e]===!1)]))}function bS(t,e,o,r,a){const n={punch:null,move:null,shake:null,text:null},i=hS[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=zn(Gc(.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={...fS(t.text,a),placement:t.textPlacement==="bottom"?"lower":t.textPlacement==="top"?"top":"center"}),n}function wS(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 kS({recipe:t,picks:e,beats:o=null,duration:r=null,start:a=0,sourceDuration:n=()=>1/0,copy:i=null,spoken:l=()=>""}){const u=yS(i);if(gS(t),!Array.isArray(e)||!e.length)throw Error("Choose at least one moment of your footage");const c=Math.max(3,Math.min(lS,Number(r)>0?Number(r):t.duration)),s=t.shots.map(k=>({...k}));for(let k=0,y=t.duration;y<c-1e-6&&s.length<Iy;k++){const A=t.shots[k%t.shots.length];s.push({...A}),y+=A.len}const d=o?.beats?.length&&(o.confidence??0)>=lp?o:null,f=d?(d.drops||[]).find(k=>k>c*.25&&k<c*.9)??null:null;let m=-1;if(f!=null&&s.length>1){const k=s.findIndex((y,A)=>A>0&&y.role==="payoff");m=k>0?k:s.reduce((y,A,I)=>I>0&&A.energy>s[y].energy?I:y,1)}const g=(k,y,A)=>{const I=k.reduce((P,N)=>P+N.len,0),z=[];let j=y;for(const P of k)j+=P.len*(A-y)/I,z.push(j);return z};let v=m>0?[...g(s.slice(0,m),0,f),...g(s.slice(m),f,c)].slice(0,-1):g(s,0,c).slice(0,-1);if(d){const k=60/(d.bpm||120),y=Math.max(.25,Math.min(k,.6));v=v.map(I=>I===f?I:K4(d,I,k/2));const A=[];for(const I of v)if((I-(A.at(-1)??0)>=y||I===f)&&c-I>=y){if(I===f)for(;A.length&&f-A.at(-1)<y;)A.pop();A.push(I)}v=A}const x=[0,...v,c],$=e.map(k=>({...k,cursor:k.start})),E=[];let S=0;for(let k=0;k<x.length-1;k++){const y=zn(x[k+1]-x[k]),A=s[Math.min(k,s.length-1)];let I=null;for(let j=0;j<$.length*2&&!I;j++){const P=$[S%$.length];(P.cursor>=P.end-.05||n(P.materialId)-P.cursor<y-.001)&&(P.cursor=P.start),n(P.materialId)-P.cursor>=y-.001?I=P:S++}if(!I)throw Error("The chosen moments are too short for this edit");const z=zn(I.cursor);E.push({materialId:I.materialId,inPoint:z,duration:y,start:zn(a+x[k]),transition:k===0?null:cS(A.transition,A.energy),role:A.role,energy:A.energy,...bS(A,k,y,u,A.text&&u.text?l(I.materialId,z,z+y):"")}),I.cursor+=y,S++}return{segments:E,look:u.color?dS(t.color):null,snapped:!!d,drop:f!=null?zn(f):null,duration:zn(c)}}const jy=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]]}}]),Ty=new Map(jy.map(t=>[t.id,t])),Oy=(t,[e,o])=>Math.max(e,Math.min(o,t)),Mh=t=>+t.toFixed(3);function xS(t,e){const o=typeof e=="string"?Ty.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 l={...a[n]||{}};for(const[u,c]of Object.entries(i)){const s=Mh(Oy((l[u]??0)+c,ip[u]));s?l[u]=s:delete l[u]}Object.keys(l).length?a[n]=l: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 mj(t,e,o,r){const a=typeof t=="string"?Ty.get(t):t;if(!a)return[e,o,r];const n={curves:a.curves};return a.curves&&(e=wp(n,"r",e),o=wp(n,"g",o),r=wp(n,"b",r)),a.mixer?Rg(a.mixer,e,o,r):[e,o,r]}const zy=20,MS=4;function vS(t,e,o){const{h:r,c:a,l:n}=Fg(t,e,o);if(a<.03||n<.05)return null;const i=(r-zy+540)%360-180;return{hue:+r.toFixed(1),delta:+i.toFixed(1),ok:Math.abs(i)<=MS,chroma:+a.toFixed(3),luma:+n.toFixed(3)}}function gj(t,e){const o=vS(...e);if(!o||o.ok)return null;const r=t?.mixer||{},a={red:r.red?.shift??0,yellow:r.yellow?.shift??0},n=d=>{const[f,m,g]=Rg({red:{shift:d},yellow:{shift:d}},...e);return(Fg(f,m,g).h-zy+540)%360-180};let i=-1,l=1;n(i)>0||n(l)<0;for(let d=0;d<30;d++){const f=(i+l)/2;n(f)>0?l=f:i=f}const u=(i+l)/2,c={...r};for(const d of["red","yellow"]){const f=Mh(Oy(a[d]+u,ip.shift)),m={...c[d]||{}};f?m.shift=f:delete m.shift,Object.keys(m).length?c[d]=m:delete c[d]}const s={...t||{}};return Object.keys(c).length?s.mixer=c:delete s.mixer,{grade:s,shift:Mh(u),before:o}}const Jn=t=>({...pn,type:"ellipse",...t}),_e=(t,e,o)=>o==="en"?e:t,Py=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:_e("Sáng mặt","Face",e),window:Ss("face"),adjust:{exposure:.3}}:{name:_e("Sáng giữa","Centre",e),window:Jn({cx:.5,cy:.42,w:.34,h:.5,feather:.5}),adjust:{exposure:.3}},{name:_e("Tối quanh","Surround",e),window:Jn({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:_e("Vignette","Vignette",t),window:Jn({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:_e("Tối trời","Sky",t),window:{...pn,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:_e("Đè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:_e("Nền","Background",e),window:Gl(),invert:!0,adjust:{saturation:.7,exposure:-.3}}:{name:_e("Nền","Background",e),window:Jn({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:_e("Sáng mặt","Brighter face",t),window:Ss("face"),adjust:{exposure:.2}},{name:_e("Mịn da","Smooth skin",t),window:Ss("skin"),blur:.1,adjust:{contrast:.97}},{name:_e("Mắt sáng","Bright eyes",t),window:Ss("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:_e("Xa (trên)","Far (top)",t),window:{...pn,type:"gradient",cx:.5,cy:.45,w:1,h:1,rot:0,feather:.5},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.08}},{name:_e("Gần (dưới)","Near (bottom)",t),window:{...pn,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:_e("Xa (giữa)","Far (centre)",t),window:Jn({cx:.5,cy:.45,w:.32,h:.45,feather:.6}),adjust:{contrast:.84,saturation:.85,temperature:-12,exposure:.05}},{name:_e("Gần (viền)","Near (edges)",t),window:Jn({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:_e("Nền (xa)","Background (far)",e),window:t?Gl():Jn({cx:.5,cy:.5,w:.5,h:.8,feather:.5}),invert:!0,adjust:{contrast:.85,saturation:.85,temperature:-12,exposure:-.1}},{name:_e("Người (gần)","Subject (near)",e),window:t?Gl():Jn({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:_e("Xa (AI)","Far (AI)",e),window:{...pn,type:"depth",range:[0,.42],feather:.35},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.06}},{name:_e("Gần (AI)","Near (AI)",e),window:{...pn,type:"depth",range:[.58,1],feather:.35},adjust:{contrast:1.08,saturation:1.05,temperature:8}}]:[{name:_e("Xa (trên)","Far (top)",e),window:{...pn,type:"gradient",cx:.5,cy:.45,w:1,h:1,rot:0,feather:.5},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.07}},{name:_e("Gần (dưới)","Near (bottom)",e),window:{...pn,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:_e("Đè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}}]}]),Ly=new Map(Py.map(t=>[t.id,t])),Ny=t=>Ly.get(t);function Ws(t,{face:e=!1,person:o=!1,depth:r=!1,locale:a="vi"}={}){const n=Ly.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 $S(t){const e=n=>JSON.stringify([n.window,n.adjust??null,!!n.invert]);let o=0;const r=["vi","en"].map(n=>[Ws("depth-ai",{depth:!1,locale:n}),Ws("depth-ai",{depth:!0,locale:n})]),a=t.map(n=>{for(const[i,l]of r)for(let u=0;u<i.length;u++)if(e(n)===e(i[u]))return o++,{...l[u],...n.on===!1?{on:!1}:{},name:n.name===i[u].name?l[u].name:n.name};return n});return{list:o?a:t,upgraded:o}}function ES(t,e,o){const r=Ws(e,o);if(!r)throw Error("This preset needs a face track — detect faces first");if(t.length+r.length>hc)throw Error(`Up to ${hc} power windows per clip`);return[...t,...r]}const yj=Object.freeze(Object.defineProperty({__proto__:null,WINDOW_PRESETS:Py,presetWindows:Ws,upgradeDepthWindows:$S,windowPreset:Ny,withPreset:ES},Symbol.toStringTag,{value:"Module"})),ec=["exposure","contrast","saturation","brightness","hue"],SS=mw.map(t=>t[0]),IS=Object.keys(ip),AS=Object.keys(Cu),CS=["exposure","contrast","saturation","hue","temperature","tint"],bo=t=>Math.round(t*1e4)/1e4,lr=(t,e,o)=>Math.max(e,Math.min(o,t)),jS={cx:[-.5,1.5],cy:[-.5,1.5],w:[.02,3],h:[.02,3],rot:[-180,180],feather:[0,1]};function Fy(t,e={}){const o={...e};if(!t||typeof t!="object")return o;for(const r of SS){const a=t[r];if(!a||typeof a!="object")continue;const n={};for(const i of IS)if(a[i]!=null){const[l,u]=ip[i],c=Math.round(lr(Number(a[i])||0,l,u)*1e3)/1e3;c&&(n[i]=c)}Object.keys(n).length?o[r]=n:delete o[r]}return o}function TS(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(Cu,e.preset))throw Error(`qualifier: ${AS.join(" | ")} or {hue, hueWidth, satMin, satMax, lumMin, lumMax, soft}`);const o=e.preset!=null?Cu[e.preset]:kw,r=(n,i,l,u)=>{const c=e[n]??(u?e[u]:void 0);return c==null||!Number.isFinite(+c)?o[n]:bo(lr(+c,i,l))},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 OS(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=lr(Number(r.x)||0,-1,1),n=lr(Number(r.y)||0,-1,1);const i=Math.hypot(a,n);i>1&&(a/=i,n/=i);const l={x:bo(a),y:bo(n),l:bo(lr(Number(r.l)||0,-1,1))};(l.x||l.y||l.l)&&(e[o]=l)}return Object.keys(e).length?e:void 0}function zS(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,l)=>i.x-l.x)){const i=bo(lr(+n.x,0,1)),l=bo(lr(+n.y,0,1));(!a.length||i>a.at(-1)[0]+.001)&&a.push([i,l])}a.length>=2&&a.length<=16&&(e[o]=a)}return Object.keys(e).length?e:void 0}function PS(t,{hasFace:e=!1,hasPerson:o=!1,pending:r=null}={}){const a=(f,m,g,v)=>t[f]==null?v:bo(lr(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=Ss(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=Gl()}else if(t.shape==="depth"){const f=a("from",0,.99,0),m=a("to",.01,1,.42);n={...pn,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}:{...pn};n={type:t.shape==="rect"?"rect":t.shape==="gradient"?"gradient":"ellipse",...Object.fromEntries(Object.entries(jS).map(([m,[g,v]])=>[m,a(m,g,v,f[m])]))}}const i={};for(const f of CS)if(t[f]!=null){const{min:m,max:g,base:v}=ww[f],x=bo(lr(t[f],m,g));x!==v&&(i[f]=f==="hue"||f==="temperature"||f==="tint"?Math.round(x):x)}const l=OS(t.wheels??{lift:t.lift,gamma:t.gamma,gain:t.gain}),u=zS(t.curves),s=t.shape==="qualifier"||t.qualifier!=null&&n&&["ellipse","rect","gradient"].includes(n.type)?TS(t.qualifier??"skin"):null,d={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}:{},...l?{wheels:l}:{},...u?{curves:u}:{},...t.on===!1?{on:!1}:{}};if(t.blur!=null&&t.blur>0&&(d.blur=bo(lr(t.blur,0,1))),t.sharpen!=null&&t.sharpen>0&&(d.sharpen=Math.round(lr(t.sharpen,0,100))),t.cst?d.cst={from:typeof t.cst=="string"?t.cst:t.cst.from}:t.look&&(d.look=typeof t.look=="string"?{preset:t.look}:{preset:t.look.preset,...t.look.mix!=null?{mix:bo(lr(t.look.mix,0,1))}:{}}),t.fx){const f=typeof t.fx=="string"?{type:t.fx}:t.fx;d.fx={type:f.type,...f.amount!=null?{amount:bo(lr(f.amount,0,1))}:{},...f.size!=null?{size:bo(lr(f.size,0,1))}:{}}}if((t.branch==="parallel"||t.branch==="layer")&&(d.branch=t.branch),t.mixer){const f=Fy(t.mixer);Object.keys(f).length&&(d.mixer=f)}return d.name||delete d.name,d}function LS(t,e,{locale:o="vi",notes:r=[],queue:a=!1}={}){const n={};for(const l of ec)if(e[l]!=null){const[u,c]=Zu[l];n[l]=bo(Math.max(u,Math.min(c,e[l])))}let i={...t.grade||{}};if(e.recipe&&(i=xS(i,e.recipe),r.push(`recipe:${e.recipe}`)),e.mixer){const l=Fy(e.mixer,i.mixer||{});Object.keys(l).length?i.mixer=l:delete i.mixer,r.push("mixer")}for(const[l,{min:u,max:c}]of Object.entries(gd))e[l]!=null&&(i[l]=Math.round(Math.max(u,Math.min(c,e[l]))));if(e.lut&&(i.lut=gw({id:e.lut.id,name:String(e.lut.name??"LUT").slice(0,80),...e.lut.mix!=null?{mix:Math.max(0,Math.min(1,Number(e.lut.mix)||0))}:{}}),r.push("lut")),e.wheels){const l={...i.wheels||{}};for(const u of yw){const c=e.wheels[u];if(!c)continue;let s=Math.max(-1,Math.min(1,c.x)),d=Math.max(-1,Math.min(1,c.y));const f=Math.hypot(s,d);f>1&&(s/=f,d/=f),l[u]={x:bo(s),y:bo(d),l:bo(Math.max(-1,Math.min(1,c.l)))}}i.wheels=l}if(e.curves){const l={...i.curves||{}};for(const u of["master","r","g","b"]){const c=e.curves[u];if(!c)continue;const s=[];for(const d of[...c].sort((f,m)=>f.x-m.x)){const f=bo(Math.max(0,Math.min(1,d.x))),m=bo(Math.max(0,Math.min(1,d.y)));(!s.length||f>s.at(-1)[0]+.001)&&s.push([f,m])}s.length>=2&&s.length<=16&&(l[u]=s)}i.curves=l}if(e.windows){const l=a?new Set:null,u={face:!!t.hasFace,person:!!t.hasPerson,depth:!!t.hasDepth,locale:o},c=[];for(const d of e.windows.presets||[]){const f=l?Ny(d)?.needs:null,m=f==="face"?!u.face:f==="person"?!u.person:!1,g=Ws(d,m?{...u,[f]:!0}:u);g?(c.push(...g),r.push(`preset:${d}`),m&&l.add(f)):r.push(`skipped:${d}`)}for(const d of e.windows.custom||[]){const f=PS(d,{hasFace:u.face,hasPerson:u.person,pending:l});f?c.push(f):r.push(`skipped:${d.shape}`)}if(l)for(const d of l)r.push(`pending:${d}`);const s=[...e.windows.mode==="replace"?[]:Nh(i),...c];if(s.length>hc)throw Error(`Up to ${hc} nodes (power windows) per clip`);i=Fh(i,s),c.length&&r.push(`windows:${c.length}`)}for(const l of Object.keys(gd))i[l]||delete i[l];return bw(i),n.grade=Object.keys(i).length?i:void 0,n}const Eo=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}),NS={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}}},FS={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}}},Xr=t=>Math.round(t*1e3)/1e3,Kc=(t,e,o)=>Math.max(e,Math.min(o,t)),Yr=t=>{throw Error(`lockup: ${t}`)};function Ry(t,e){if(t==null||t==="")return null;if(t==="accent")return e;if(Object.hasOwn(Eo.accents,t))return Eo.accents[t];if(typeof t=="string"&&Zk.test(t))return t.toLowerCase();Yr(`colour "${String(t).slice(0,20)}" must be #rrggbb, red, green or accent`)}function RS(t,e){(!Array.isArray(t)||!t.length||t.length>Eo.maxLines)&&Yr(`lines needs 1–${Eo.maxLines} entries`);const o=t.map((r,a)=>{const n=typeof r=="string"?{text:r}:r;(!n||typeof n!="object")&&Yr(`lines[${a}] must be {text, role}`);const i=typeof n.text=="string"?n.text.replace(/\s+/g," ").trim():"";return(!i||i.length>Eo.maxChars)&&Yr(`lines[${a}].text needs 1–${Eo.maxChars} characters`),n.role!=null&&!Eo.roles.includes(n.role)&&Yr(`lines[${a}].role must be lead, hero or tail`),{text:i,role:n.role??(t.length===1||a>0?"hero":"lead"),color:Ry(n.color,e)}});if(o.some(r=>r.role==="hero")||Yr("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 DS(t,e,o,r,{W:a,H:n}){const i=n>a*1.1,l=i?Ie.halfWidth.portrait:Ie.halfWidth.landscape,u=[o,(o+r)/2,Math.max(o,r-.05)].map(c=>Oc(t,e,Kc(c,t.start,t.start+t.duration-.001),{W:a,H:n})).filter(Boolean);return u.length?{x0:Math.min(...u.map(c=>c.x))-l,x1:Math.max(...u.map(c=>c.x))+l,top:Math.min(...u.map(c=>c.y))-Ie.head,faceY:Math.max(...u.map(c=>c.y)),assumed:u.every(c=>c.assumed),port:i}:null}function BS(t,e="auto",{W:o=1280,H:r=720}={}){const{margin:a,gap:n,minColumn:i,maxColumn:l}=Eo,u=r>o*1.1,c=t??{x0:.5-Ie.halfWidth.landscape,x1:.5+Ie.halfWidth.landscape,top:.24,faceY:.38},s={left:Math.max(0,c.x0-n-a),right:Math.max(0,1-a-(c.x1+n))},d=x=>!u&&s[x]>=i,f=e==="left"||e==="right"?e:s.left>=s.right?"left":"right",m=f==="left"?"right":"left",g=d(f)?f:d(m)?m:null;if(g){const x=Math.min(l,s[g]),$=g==="left"?a:c.x1+n,E=g==="left"?c.x0-n:1-a,S=g==="left"?Math.min(($+E)/2,E-x/2):Math.max(($+E)/2,$+x/2);return{mode:"side",side:g,cx:Xr(S),width:Xr(x),moved:g!==f&&e!=="auto"}}const v=c.top>(u?.3:.36);return{mode:"band",band:v?"top":"lower",cy:Xr(v?Math.max(.12,c.top/2):Math.min(.86,(c.faceY+Ie.chin+1)/2)),width:.86,moved:e!=="auto"}}function _S(t,e){let o=lc(t,Array.isArray(e?.words)&&e.words.length?e.words:null);return!o.length&&Array.isArray(e?.transcript)&&e.transcript.length&&(o=lc(t,np(e.transcript))),o.map(r=>({start:t.start+r.start,end:t.start+r.end,key:Dg(r.word)}))}function GS(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 l=0,u=0;if(t.forEach((s,d)=>{const f=Dg(s);for(let m=l;m<Math.min(n.length,l+8);m++)if(f&&(n[m].key===f||f.length>2&&n[m].key.startsWith(f))){i[d]=n[m].start-o,l=m+1,u++;break}}),!u)return{times:t.map((s,d)=>Xr(Kc(.15+d*.28,0,a))),matched:0};for(let s=0;s<i.length;s++){if(i[s]!==null)continue;let d=s-1;for(;d>=0&&i[d]===null;)d--;let f=s+1;for(;f<i.length&&i[f]===null;)f++;const m=d>=0?i[d]:null,g=f<i.length?i[f]:null;i[s]=m!==null&&g!==null?m+(g-m)*(s-d)/(f-d):m!==null?m+.25*(s-d):g-.25*(f-s)}let c=0;return{times:i.map(s=>{const d=Xr(Kc(Math.max(c,s),0,a));return c=d,d}),matched:u}}function KS(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)&&Yr("clipId must be the speaker's video clip");const i=Number.isFinite(t.at)?t.at:Number.isFinite(t.start)?t.start:n.start,l=Number.isFinite(t.duration)?t.duration:3;(l<Eo.minDuration||l>Eo.maxDuration)&&Yr(`duration ${Eo.minDuration}–${Eo.maxDuration} s`),(i<n.start-.05||i>=n.start+n.duration)&&Yr("at must fall inside the speaker clip");const u=t.style==null?"condensed":t.style;Eo.styles.includes(u)||Yr("style must be condensed, serif or script");const c=t.side==null?"auto":t.side;Eo.sides.includes(c)||Yr("side must be auto, left or right");const s=Ry(t.color,Eo.accents.red)??Eo.accents.red,d=RS(t.lines,s),f=NS[u],m=o.find(P=>P.id===n.nodeId),g=BS(DS(n,m,i,i+l,{W:r,H:a}),c,{W:r,H:a}),v=d.map(P=>f[P.role].caps?P.text.toLocaleUpperCase("vi"):P.text),x=v.flatMap(P=>P.split(" ").filter(Boolean)),{times:$}=GS(x,_S(n,m),i,l);let E=0;const S=v.map((P,N)=>{const F=P.split(" ").filter(Boolean).length,K=d[N].role,_=FS[K],J=$.slice(E,E+F).map(X=>Xr(Math.max(0,K==="hero"?X-.06:X)));return E+=F,K==="tail"?{lines:[N],unit:"line",at:[J[0]],duration:_.duration,easing:_.easing,from:{..._.from,x:g.mode==="side"&&g.side==="right"?_.from.x:-_.from.x}}:{lines:[N],unit:"word",at:J,duration:_.duration,easing:_.easing,from:_.from}}),k=g.mode==="band"?.55:1,y={weight:700,lineHeight:1.25,uppercase:!1,stack:"ink",gap:.12,maxWidth:g.width,lines:d.map(P=>{const N=f[P.role];return{scale:Xr(N.scale*k),font:N.font,weight:N.weight,...N.italic?{italic:!0}:{},...N.tracking!==void 0?{tracking:N.tracking}:{},...P.color?{fill:P.color}:{}}}),layers:[{type:"text",fill:"{color}",shadow:{color:"#000000",blur:.22,x:0,y:.03},opacity:1}]},A=Math.min(1,r*720/1280/a),I=A>.99,z=g.mode==="side"?{posX:Xr(g.cx-.5),posY:0}:I?{posX:0,posY:0}:{posX:0,posY:Xr(Kc(g.cy-.5,-.5+A/2,.5-A/2))},j=g.mode==="band"&&I?g.band:"center";return{addText:{op:"addText",text:v.join(`
203
+ `),start:Xr(i),duration:Xr(l),fontSize:Eo.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 VS=Object.freeze(["wide","medium","close","side","phone"]),m0=Object.freeze(["speaker","sentence","beat","mixed"]),Tr=Object.freeze({minShot:2.5,maxShot:8,minAngles:2,maxAngles:8,lead:.12,turnGap:.6}),Vc=t=>String(t??"").normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d").replace(/Đ/g,"D").toLowerCase(),WS=(t,e)=>t.test(e),HS=[["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])/]],XS=[["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)/]],US=t=>{const e=t.filter(Number.isFinite).sort((o,r)=>o-r);return e.length?e[Math.floor(e.length/2)]:null};function YS(t,e=[]){if(VS.includes(t?.angle))return{role:t.angle,from:"user"};const o=Vc(t?.label).replace(/\.[a-z0-9]{2,4}$/,"").replace(/[_.]+/g," ");for(const[l,u]of HS)if(WS(u,o))return{role:l,from:"name"};const r=Vc([t?.description,...Array.isArray(t?.scenes)?t.scenes.slice(0,20).map(l=>l?.description):[]].filter(Boolean).join(" ")),a=XS.map(([l,u])=>[l,(r.match(new RegExp(u.source,"g"))||[]).length]).filter(([,l])=>l>0).sort((l,u)=>u[1]-l[1]);if(a.length)return{role:a[0][0],from:"analysis"};const n=US((Array.isArray(t?.scenes)?t.scenes:[]).map(l=>Number(l?.subjectH)));return n!=null?{role:n>=.3?"close":n>=.16?"medium":"wide",from:"size"}:(l=>Number(l?.height)>Number(l?.width)*1.1)(t)&&e.some(l=>l!==t&&Number(l?.width)>Number(l?.height))?{role:"phone",from:"shape"}:{role:null,from:null}}const Dy=/\?|(?<![\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,By=/!|(?<![\p{L}])(quan trong|nhat dinh|tuyet doi|chac chan|never|always|must|important|really|absolutely)(?![\p{L}])/u;function qS(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],l=i?n.start-i.end:1/0;(!r||l>=Tr.turnGap||/[.?!…]["”')\]]*$/.test(i?.word??""))&&(r&&o.push(r),r={start:n.start,end:n.end,words:[],gapBefore:l}),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=Vc(n);return{start:a.start,end:a.end,text:n,words:a.words.length,gapBefore:a.gapBefore,question:Dy.test(i),emphasis:By.test(i)||a.words.length<=5}})}function ZS(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=Vc(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:Dy.test(a),emphasis:By.test(a)||n<=5}})}const JS={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 QS({angles:t,span:e,sentences:o=[],beats:r=[],gaps:a=[],mode:n="sentence",minShot:i=Tr.minShot,maxShot:l=Tr.maxShot,wideEvery:u=null,crowd:c=()=>!1}){const[s,d]=e,f=1e-6,m=[],g=A=>A.start-Math.min(Tr.lead,Number.isFinite(A.gapBefore)?A.gapBefore/2:Tr.lead);if(n==="sentence"||n==="mixed")for(const A of o)m.push({t:g(A),strength:Math.min(1,Number.isFinite(A.gapBefore)?A.gapBefore:1)+.5});if(n==="speaker"){const A=o.filter(I=>!(I.gapBefore<Tr.turnGap));for(const I of A.length>=2?A:o)m.push({t:g(I),strength:1.5})}if(n==="beat"||n==="mixed")for(const A of r)m.push({t:A,strength:n==="beat"?1.2:.4});for(const A of t)for(const I of[A.from,A.to])m.push({t:I,strength:.3});const v=m.filter(A=>A.t>s+f&&A.t<d-f).sort((A,I)=>A.t-I.t||I.strength-A.strength),x=Math.min(l,Math.max(i,(i+l)/2-.5)),$=(A,I,z)=>{let j=null;for(const P of a){const N=(P.start+P.end)/2;if(!(N>A&&N<I))continue;const F=Math.min(1,P.end-P.start)-Math.abs(N-z)*.02;(!j||F>j.s+1e-9)&&(j={t:N,s:F})}return j?j.t:null},E=[s];for(let A=s;A<d-f;){const I=d-A;let z;if(I<=l+f)z=d;else if(I<2*i)z=A+I/2;else{const j=A+i,P=Math.min(A+l,d-i),N=v.filter(F=>F.t>=j-f&&F.t<=P+f);N.length?z=N.reduce((F,K)=>{const _=K.strength*1.5-Math.abs(K.t-A-x)/2;return!F||_>F.s+1e-9?{t:K.t,s:_}:F},null).t:z=$(j,P,A+x)??Math.min(A+x,P),z>A+f||(z=Math.min(d,A+l))}E.push(z),A=z}const S=(A,I)=>{const z=o.filter(j=>j.end>A+.05&&j.start<I-.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)||I-A>6&&z.length<=1&&z.some(j=>j.words>10),crowd:!!c((A+I)/2)}},k=[];let y=-1/0;for(let A=0;A+1<E.length;A++){const I=E[A],z=E[A+1],j=S(I,z),P=t.filter(ot=>ot.from<=I+.02&&ot.to>=z-.02),N=P.length?P:t.filter(ot=>ot.to>I&&ot.from<z).sort((ot,G)=>Math.min(G.to,z)-Math.max(G.from,I)-(Math.min(ot.to,z)-Math.max(ot.from,I))).slice(0,1);if(!N.length)continue;const F=k.at(-1),K=k.at(-2);let _=null;N.forEach(ot=>{const G=ot.role??"medium";let tt=JS[G](j);G==="wide"&&(A===0||u&&I-y>=u)&&(tt+=A===0?2.5:6),F&&F.id===ot.id&&F.end>=I-.02&&(tt-=100),K&&K.id===ot.id&&(tt-=.8),(!_||tt>_.s+1e-9)&&(_={x:ot,s:tt,role:G})});const J=j.question?"question":j.emphasis?"emphasis":j.long?"explanation":j.crowd?"group":_.role==="wide"&&A===0?"opening":"rhythm",X=Math.max(I,_.x.from),rt=Math.min(z,_.x.to);if(F&&F.id===_.x.id&&Math.abs(F.end-X)<.02&&rt-F.start<=l+f){F.end=rt;continue}k.push({id:_.x.id,start:X,end:rt,role:_.role,why:J}),_.role==="wide"&&(y=z)}return k}const io=t=>Number.isFinite(t)?Number(t):null,t8={wide:"toàn",medium:"trung",close:"cận",side:"bên",phone:"điện thoại"};function ci(t){if(!t||typeof t.syncGroup!="string"||!t.syncGroup)return null;const e=t.syncMain?0:io(t.syncOffset);return e===null?null:{o:e,d:(io(t.syncDrift)??0)*1e-6,group:t.syncGroup}}const an=(t,e)=>e*(1+t.d)+t.o,g0=(t,e)=>(e-t.o)/(1+t.d);function e8(t,e,o=[],r={},{newId:a}={}){const n=[...new Set((Array.isArray(e?.materials)?e.materials:Array.isArray(e?.materialIds)?e.materialIds:[]).filter(C=>typeof C=="string"))];if(n.length<Tr.minAngles||n.length>Tr.maxAngles)throw Error(`multicam needs ${Tr.minAngles}–${Tr.maxAngles} video materials (the synced camera angles)`);const i=n.map(C=>{const O=o.find(B=>B.id===C);if(!O)throw Error(`Không thấy material ${C}`);if(O.kind!=="video"||!O.url)throw Error(`${O.label||C}: multicam angles must be videos`);if(!(io(O.duration)>0))throw Error(`${O.label||C}: unknown duration — open it in Media first`);const L=ci(O);if(!L)throw Error(`${O.label||C} chưa được đồng bộ — Media → Multicam → Đồng bộ nhiều góc máy trước (or MCP sync_multicam)`);return{m:O,s:L}}),l=i[0].s.group;if(i.some(C=>C.s.group!==l))throw Error("These videos were synced in different groups — sync them together first");const u=e.mode??null;if(u!==null&&!m0.includes(u))throw Error(`multicam mode must be ${m0.join(" / ")}`);const c=io(e.minShot)??Tr.minShot,s=io(e.maxShot)??Tr.maxShot,d=io(e.wideEvery);if(c<1||c>20)throw Error("minShot must be 1–20 s");if(s<c+.5||s>60)throw Error("maxShot must be ≥ minShot + 0.5 and ≤ 60 s");if(d!==null&&(d<5||d>300))throw Error("wideEvery must be 5–300 s");const f=o.filter(C=>ci(C)?.group===l&&(C.kind==="video"||C.kind==="audio")&&io(C.duration)>0&&C.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(C=>C.m.id===m)??i.find(C=>C.m.syncMain)??i[0];let v=null;if(typeof e.audioFrom=="string"){const C=f.find(O=>O.id===e.audioFrom);if(!C)throw Error("audioFrom must be a synced video / audio of the same group");v={m:C,s:ci(C)}}else{const C=L=>io(L.syncAudio)??-1/0,O=[...f].sort((L,B)=>C(B)-C(L)||(B.id===g.m.id)-(L.id===g.m.id)||(L.id<B.id?-1:1))[0];v=O&&C(O)>C(g.m)?{m:O,s:ci(O)}:{m:g.m,s:g.s}}const x=C=>({from:C.s.o,to:an(C.s,io(C.m.duration))}),$=i.map(C=>({...C,role:YS(C.m,i.map(O=>O.m)).role,...x(C)})),E=x(v);let S=null,k=Math.max(E.from,Math.min(...$.map(C=>C.from))),y=Math.min(E.to,Math.max(...$.map(C=>C.to)));if(e.clipId){if(S=t.find(L=>L.id===e.clipId),!S)throw Error("Clip not found");const C=o.find(L=>L.id===S.nodeId),O=ci(C);if(!O||O.group!==l||!["video","audio"].includes(S.kind))throw Error("clipId must be a clip of one of the synced videos");if(S.speedRamp?.length||S.timeRemap||(S.playbackRate??1)!==1||S.reverse)throw Error("The clip to replace must play at normal speed");k=Math.max(k,an(O,S.inPoint||0)),y=Math.min(y,an(O,(S.inPoint||0)+S.duration))}io(e.inPoint)!==null&&(k=Math.max(k,io(e.inPoint))),io(e.duration)!==null&&(y=Math.min(y,k+Math.max(0,io(e.duration))));let A=t.filter(C=>C!==S);const I=ft(Math.max(0,io(e.start)??(S?S.start:A.filter(C=>C.track===0).reduce((C,O)=>Math.max(C,O.start+O.duration),0))));let z="";if(I+(y-k)>Fn&&(y=k+Fn-I,z=` (cut at the ${Fn/60}-minute timeline limit)`),!(y-k>=c))throw Error("The synced videos do not overlap the sound long enough for a multicam edit");const j=[g,v,...i].find(C=>C.m.words?.length)??[g,v,...i].find(C=>C.m.transcript?.length)??null,P=C=>(Array.isArray(C)?C:[]).filter(O=>Number.isFinite(O?.start)&&Number.isFinite(O?.end)).map(O=>({...O,start:an(j.s,O.start),end:an(j.s,O.end)})),N=j?.m.words?.length?P(j.m.words):[],F=N.length?qS(N):j?ZS(P(j.m.transcript)):[],K=[];for(let C=1;C<N.length;C++)N[C].start-N[C-1].end>=.12&&K.push({start:N[C-1].end,end:N[C].start});if(!N.length)for(const C of[g,v])for(const O of Array.isArray(C.m.pauses)?C.m.pauses:[])Number.isFinite(O?.start)&&Number.isFinite(O?.end)&&K.push({start:an(C.s,O.start),end:an(C.s,O.end)});const _=[v,...f.map(C=>({m:C,s:ci(C)}))].find(C=>Array.isArray(C.m.beats?.beats)&&C.m.beats.beats.length&&(C.m.beats.confidence??0)>=.35),J=_?_.m.beats.beats.map(C=>an(_.s,C)):[],X=u??(F.length?"sentence":J.length?"beat":"sentence");if(X==="beat"&&!J.length)throw Error("mode beat needs a song with a beat grid in the group (Media → Nhạc, analysed)");const rt=$.filter(C=>C.role==="wide"||C.m.id===g.m.id),ot=C=>rt.some(O=>(O.m.scenes||[]).some(L=>Number(L?.people)>=2&&an(O.s,L.start)<=C&&an(O.s,L.end)>C)),G=QS({angles:$.map(C=>({id:C.m.id,role:C.role,from:C.from,to:C.to})),span:[k,y],sentences:F,beats:J,gaps:K,mode:X,minShot:c,maxShot:s,wideEvery:d,crowd:ot});if(!G.length)throw Error("No camera angle covers the synced sound");const tt=I+(y-k),Q=C=>A.some(O=>O.track===C&&O.start<tt-1e-6&&O.start+O.duration>I+1e-6),it=io(e.track),D=it!==null&&!Q(it)&&!r[it]?.locked?it:!Q(0)&&!r[0]?.locked&&!r[0]?.hidden?0:qt(A,r,I,tt,null).track,U=Ri.find(C=>!r[C]?.locked&&!Q(C));if(U===void 0)throw Error("Không còn hàng audio trống cho âm thanh multicam");if(A.length+G.length+1>Fs)throw Error(`Tối đa ${Fs} clip — chọn đoạn ngắn hơn (inPoint / duration) hoặc maxShot dài hơn`);const ht=[],yt=[],Mt=(C,O)=>C<=O+.001?ft(C):Math.floor(O*Me+1e-6)/Me,p=+Math.max(0,g0(v.s,k)).toFixed(4),lt=Mt(y-k,io(v.m.duration)-p),V={id:a(),nodeId:v.m.id,track:U,start:I,duration:lt,inPoint:p,volume:1,url:v.m.url,...v.m.gcsUri?{gcsUri:v.m.gcsUri}:{},kind:"audio",label:`${v.m.label||"Audio"} · multicam audio`,sourceDuration:io(v.m.duration)};ht.push(V.id),yt.push(V);const h={};for(const C of G){const O=$.find(st=>st.m.id===C.id),L=ft(I+C.start-k),B=ft(I+C.end-k),H=+Math.max(0,g0(O.s,k+(L-I))).toFixed(4),q=Mt(B-L,io(O.m.duration)-H);if(q<1/Me)continue;const et={id:a(),nodeId:O.m.id,track:D,start:L,duration:q,inPoint:H,volume:0,url:O.m.url,...O.m.gcsUri?{gcsUri:O.m.gcsUri}:{},kind:"video",label:`${O.m.label||"Video"} · ${t8[C.role]??C.role}`,sourceDuration:io(O.m.duration)};ht.push(et.id),yt.push(et),h[C.role]=(h[C.role]||0)+1}const T=`multicam: ${yt.length-1} shots from ${new Set(G.map(C=>C.id)).size} angles (${Object.entries(h).map(([C,O])=>`${C} ${O}`).join(", ")}), cut on ${X}${F.length?"":" (no transcript: pauses / rhythm)"}, audio from ${v.m.label||v.m.id}, ${ft(y-k)}s${z}`;return{clips:[...A,...yt],created:ht,note:T,plan:G}}const y0=3,b0=40,Il=[1,6],ks={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},o8={rgb:"invert",luma:"luma-invert"},r8=30,n8=t=>!!t&&Og(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 a8(t,e={},{clipIds:o,at:r,frames:a,polarity:n=!1,style:i="anchor",newId:l=()=>`mt-${Math.random().toString(36).slice(2,9)}`}={}){const u=i==="strobe",c=[...new Set(Array.isArray(o)?o:[])];if(c.length<y0||c.length>b0)throw Error(`A montage needs ${y0}–${b0} clips`);const s=c.map(A=>t.find(I=>I.id===A));if(s.some(A=>!A))throw Error("Clip not found");if(s.some(A=>!n8(A)))throw Error("A montage takes filmed clips or photos only (no motion, text, shape or generator layers)");if(s.some(A=>e[A.track]?.locked))throw Error("Track đã khóa");const d=Math.round(Number.isFinite(a)?a:u?ks.frames:2);if(d<Il[0]||d>Il[1])throw Error(`Frames per shot must be ${Il[0]}–${Il[1]}`);const f=u?s.flatMap((A,I)=>ks.invert(I)?[{c:A,copy:!0,inv:"luma"},{c:A,inv:null}]:[{c:A,inv:null}]):s.map((A,I)=>({c:A,inv:n&&I%2?"rgb":null})),m=ft(d/r8),g=s[0].track,v=ft(Number.isFinite(r)?Math.max(0,r):Math.min(...s.map(A=>A.start))),x=v+m*f.length,$=t.find(A=>!c.includes(A.id)&&A.track===g&&A.kind!=="audio"&&A.start<x-1e-6&&A.start+A.duration>v+1e-6);if($)throw Error(`No room for the montage on that track (${$.label??$.id} is in the way from ${v.toFixed(2)} to ${x.toFixed(2)} s)`);const E=(A,I,z,j)=>{const{transition:P,join:N,visualFadeIn:F,visualFadeOut:K,fadeInColor:_,fadeOutColor:J,enter:X,exit:rt,audioFadeIn:ot,audioFadeOut:G,...tt}=A;let Q={...tt,id:j,track:g,start:ft(v+I*m),duration:m,posX:0,posY:0,volume:0};const it=A.playbackRate||1;A.kind==="video"&&Number.isFinite(A.sourceDuration)&&(A.inPoint||0)+m*it>A.sourceDuration&&(Q.inPoint=Math.max(0,A.sourceDuration-m*it));for(const U of["x","y"])Ee(Q,U).length&&(Q={...Q,motionKeys:tn(Q,U,[])});const D=(Q.effects??[]).filter(U=>U.type!=="invert"&&U.type!=="luma-invert");return z&&D.push({type:o8[z],amount:1}),D.length?Q.effects=D:delete Q.effects,Q},S=f.map((A,I)=>E(A.c,I,A.inv,A.copy?l():A.c.id)),k=new Map(S.filter(A=>c.includes(A.id)).map(A=>[A.id,A]));let y=[...t.map(A=>k.get(A.id)??A),...S.filter(A=>!c.includes(A.id))];return u&&S.forEach((A,I)=>{const z=da(ks.ticks[I%ks.ticks.length]);if(z)try{y=[...y,Bi(y,e,z,A.start,{volume:ks.volume,id:l()})]}catch{}}),y}const i8=Object.freeze(["map","cork","wall","paper"]),w0=Object.freeze(["year","place","photo","file","news","type","counter","portrait"]),er=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}}),k0=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]]}),so=t=>Math.round(t*100)/100,vh=t=>Math.round(t*1e3)/1e3,s8=/^#[0-9a-fA-F]{6}$/,Po=(t,e=er.text)=>typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,e):"",au=t=>typeof t=="number"&&Number.isFinite(t)?t:typeof t=="string"&&t.trim()&&Number.isFinite(+t)?+t:null;function l8(t={},e=0){const o=w0.includes(t?.kind)?t.kind:null;if(!o)throw Error(`documentary station ${e+1}: kind must be one of ${w0.join(" | ")}`);const r={kind:o},a=au(t.at),n=au(t.hold),i=Po(t.say,120);a!==null&&(r.at=so(Math.max(0,a))),n!==null&&(r.hold=so(Math.min(12,Math.max(1,n)))),i&&(r.say=i);const l=(u,c)=>{const s=Po(t[u],c);if(!s)throw Error(`documentary station ${e+1} (${o}) needs ${u}`);return s};if(o==="year"){r.text=l("text",24);const u=Po(t.sub,60);u&&(r.sub=u)}if(o==="place"){r.label=l("label",48);const u=Po(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(vh));const c=Po(t.query,120);c&&(r.query=c)}if(o==="photo"){const u=Po(t.caption,48);u&&(r.caption=u)}if(o==="file"){r.title=Po(t.title,40)||"HỒ SƠ",r.text=l("text");const u=Po(t.sub,60);u&&(r.sub=u)}if(o==="news"){r.headline=l("headline",90),r.paper=Po(t.paper,40)||"NHẬT BÁO";const u=Po(t.date,48),c=Po(t.deck,90),s=Po(t.stamp,22);u&&(r.date=u),c&&(r.deck=c),s&&(r.stamp=s)}if(o==="type"){r.text=l("text",60);const u=Po(t.then,40);u&&(r.then=u)}if(o==="counter"){r.label=l("label",48);const u=au(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 c=Po(t.unit,16);c&&(r.unit=c)}if(o==="portrait"){const u=Po(t.title,40),c=Po(t.sub,60);u&&(r.title=u),c&&(r.sub=c)}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 c8(t={}){const e=Array.isArray(t.stations)?t.stations:[];if(!e.length)throw Error("documentary needs stations [{kind, …}]");if(e.length>er.maxStations)throw Error(`documentary: at most ${er.maxStations} stations`);return{style:i8.includes(t.style)?t.style:"map",accent:s8.test(t.accent??"")?t.accent.toLowerCase():er.accent,sfx:t.sfx!==!1,stations:e.map(l8)}}function p8(t,e=()=>null){const o=[];let r=.2;for(const[d,f]of t.stations.entries()){const m={...f},g=m.hold??er.hold[m.kind];let v=m.at??(m.say?e(m.say,r-.5):null);v=v==null?r:Math.max(v-.35,d?o[d-1].t0+1.1:0),m.t0=so(v),m.t1=so(v+g),r=m.t1,o.push(m)}for(let d=0;d<o.length-1;d++)o[d].t1=so(Math.max(o[d].t1,Math.min(o[d].t1,o[d+1].t0)));const a=Math.min(er.maxSeconds,so(o.at(-1).t1+.6));let n=0;const i=d=>{const f=Math.sin(d*127.1+311.7)*43758.5453;return f-Math.floor(f)};for(const[d,f]of o.entries()){const m=er.width[f.kind],g=f.kind==="place"&&t.style==="map";f.x=so(g?n:n+m/2),f.y=so(d?(i(d)-.5)*70:0),f.rot=so((i(d+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${d}`)}const l=[];for(const[d,f]of o.entries()){const m=er.zoom[f.kind],g=d?Math.min(1.05,Math.max(.5,(f.t0-o[d-1].t0)*.42)):0,v=f.x,x=f.y+(f.kind==="news"?-20:0),$=d&&t.style==="map"&&o[d-1].kind==="place";$&&l.push([so(f.t0+.9),o[d-1].x,o[d-1].y,er.zoom.place]);const E=d?$?f.t0+1.7:f.t0+g*.55:0;l.push([so(E),v,x,m]),f.kind==="file"&&l.push([so(f.t0+1.4),v,x-20,m*1.05],[so(f.t0+2.1),v-10,x-30,m*1.45]),f.kind==="news"&&l.push([so(f.t0+1.6),v,x+30,m*1.2]),l.push([so(Math.max(E+.3,f.t1-(d<o.length-1?Math.min(.9,(o[d+1].t0-f.t0)*.3):0))),v+6,x-4,l.at(-1)[3]*1.04])}for(let d=1;d<l.length;d++)l[d][0]<=l[d-1][0]&&(l[d][0]=so(l[d-1][0]+.05));const u=new Set(["photo","file","news","place"]);for(const[d,f]of o.entries())if(f.kind==="place"&&t.style==="map"){const m=o.findIndex((g,v)=>v>d&&u.has(g.kind)&&g.kind!=="place");m>0&&(f.q=m,f.t2=so(o[m].t0+1.3))}const c=[];if(t.sfx)for(const d of o){for(const[f,m]of k0[d.kind]??[])c.push([f,so(d.t0+m)]);d.kind==="news"&&d.stamp&&c.push([k0.stamp[0][0],so(d.t0+2.05)])}const s=t.style==="map"?o.find(d=>d.kind==="place"):null;return{style:t.style,accent:t.accent,total:a,K:l,S:o,sfx:c,place:s?{lonlat:s.lonlat??null,query:s.query??s.label}:null}}const u8=`
204
+ const ACC=SPEC.accent,INK='#2a2622',PAPER='#e8e2d2',CREAM='#ece6d8',LIGHT=SPEC.style==='paper',WARM=SPEC.style==='wall'||LIGHT,FG=LIGHT?INK:CREAM
205
+ const cl=(x,a=0,b=1)=>x<a?a:x>b?b:x,sm=x=>{x=cl(x);return x*x*(3-2*x)},seg=(t,a,b)=>cl((t-a)/(b-a)),eo=x=>1-Math.pow(1-cl(x),3)
206
+ const back=x=>{x=cl(x);const c=1.9;return 1+(c+1)*Math.pow(x-1,3)+c*Math.pow(x-1,2)}
207
+ const hash=i=>{const s=Math.sin(i*127.1+311.7)*43758.5453;return s-Math.floor(s)}
208
+ const K=SPEC.K
209
+ function cam(t){
210
+ if(t<=K[0][0])return {x:K[0][1],y:K[0][2],z:K[0][3]}
211
+ if(t>=K[K.length-1][0]){const k=K[K.length-1];return {x:k[1],y:k[2],z:k[3]}}
212
+ let i=0;while(i<K.length-2&&t>K[i+1][0])i++
213
+ const a=K[i],b=K[i+1],h=b[0]-a[0],u=cl((t-a[0])/h)
214
+ const tan=(j,k,lg)=>{if(j<=0||j>=K.length-1)return 0;const p=K[j-1],n=K[j+1],f=v=>lg?Math.log(v):v;return (f(n[k])-f(p[k]))/(n[0]-p[0])*0.85}
215
+ const H=(k,lg)=>{const f=v=>lg?Math.log(v):v,p0=f(a[k]),p1=f(b[k]),m0=tan(i,k,lg),m1=tan(i+1,k,lg),u2=u*u,u3=u2*u
216
+ const r=(2*u3-3*u2+1)*p0+(u3-2*u2+u)*h*m0+(-2*u3+3*u2)*p1+(u3-u2)*h*m1;return lg?Math.exp(r):r}
217
+ return {x:H(1),y:H(2),z:H(3,true)}
218
+ }
219
+ const typed=(s,p)=>s.slice(0,Math.floor(s.length*cl(p)))
220
+ const plain=s=>s.replace(/\\*/g,'')
221
+ function shadowCard(ctx,x,y,w,h,col){ctx.save();ctx.shadowColor='rgba(0,0,0,.55)';ctx.shadowBlur=28;ctx.shadowOffsetY=12;ctx.fillStyle=col;ctx.fillRect(x,y,w,h);ctx.restore()}
222
+ function pin(ctx,x,y){ctx.save();ctx.shadowColor='rgba(0,0,0,.6)';ctx.shadowBlur=6;ctx.shadowOffsetY=3;const g=ctx.createRadialGradient(x-2,y-2,1,x,y,7);g.addColorStop(0,'#ff8a7a');g.addColorStop(1,'#a01810');ctx.fillStyle=g;ctx.beginPath();ctx.arc(x,y,6.5,0,7);ctx.fill();ctx.restore()}
223
+ function lines(ctx,x,y,w,n,gap,seed,al){ctx.fillStyle='rgba(42,38,34,'+al+')';for(let i=0;i<n;i++){const L=w*(i===n-1?.45:.78+.22*hash(seed+i));ctx.fillRect(x,y+i*gap,L,2.2)}}
224
+ // wrapped text with *marked* words: draws it, returns the marked words' boxes [[x,y,w,h]] (one per line)
225
+ function wrap(ctx,s,x,y,w,lh,draw){const toks=[];let mark=false;for(const part of s.split('*')){for(const wd of part.split(' '))if(wd)toks.push({wd,mark});mark=!mark}
226
+ const sp=ctx.measureText(' ').width,boxes=[];let cx=x,cy=y,cur=null
227
+ for(const k of toks){const tw=ctx.measureText(k.wd).width;if(cx>x&&cx+tw>x+w){cx=x;cy+=lh;cur=null}
228
+ if(draw!==false)ctx.fillText(k.wd,cx,cy)
229
+ if(k.mark){if(cur&&cur[1]===cy)cur[2]=cx+tw-cur[0];else{cur=[cx,cy,tw,lh];boxes.push(cur)}}else cur=null
230
+ cx+=tw+sp}
231
+ return {boxes,bottom:cy+lh}}
232
+ function circle(ctx,b,p,seed){if(p<=0||!b)return;const cx=b[0]+b[2]/2,cy=b[1]-b[3]*.32,rx=b[2]/2+16,ry=b[3]*.62;ctx.save();ctx.strokeStyle=ACC;ctx.lineWidth=3.2;ctx.lineCap='round';ctx.beginPath();const a0=-2.6,span=Math.PI*2*1.12*p
233
+ for(let k=0;k<=64;k++){const a=a0+span*k/64,j=1+.05*Math.sin(a*3+seed)+.03*Math.sin(a*7+seed*2),g=1+.06*(a-a0)/(Math.PI*2),x=cx+Math.cos(a)*rx*j*g,y=cy+Math.sin(a)*ry*j*g;k?ctx.lineTo(x,y):ctx.moveTo(x,y)}ctx.stroke();ctx.restore()}
234
+ function under(ctx,b,p,dy,wid){if(p<=0||!b)return;ctx.save();ctx.strokeStyle=ACC;ctx.lineWidth=wid||3.4;ctx.lineCap='round';ctx.beginPath();ctx.moveTo(b[0],b[1]+dy);for(let k=1;k<=24;k++){const v=k/24*p;ctx.lineTo(b[0]+b[2]*v,b[1]+dy+Math.sin(v*9)*1.6)}ctx.stroke();ctx.restore()}
235
+ const STAMPS=new Map()
236
+ function stampImg(text,font){const key=text;if(STAMPS.has(key))return STAMPS.get(key);const c=new OffscreenCanvas(540,170),g=c.getContext('2d');g.font=font;const w=Math.min(500,g.measureText(text).width+70)
237
+ g.strokeStyle=ACC;g.fillStyle=ACC;g.lineWidth=9;g.strokeRect(270-w/2,10,w,150);g.lineWidth=3;g.strokeRect(270-w/2+14,24,w-28,122);g.textAlign='center';g.textBaseline='middle';g.fillText(text,270,88)
238
+ g.globalCompositeOperation='destination-out';for(let i=0;i<900;i++){const r=hash(i)*2.6+.4;g.globalAlpha=.35+hash(i+9)*.65;g.beginPath();g.arc(hash(i+3)*540,hash(i+7)*170,r,0,7);g.fill()}
239
+ STAMPS.set(key,c);return c}
240
+ const GREY=new Map()
241
+ function grey(name){if(GREY.has(name))return GREY.get(name);let out=null;try{const bm=M.asset(name);if(bm){const W=84,H=103,c=new OffscreenCanvas(W,H),g=c.getContext('2d'),s=Math.max(W/bm.width,H/bm.height),w=bm.width*s,h=bm.height*s
242
+ g.drawImage(bm,(W-w)/2,(H-h)*.3,w,h);const d=g.getImageData(0,0,W,H).data,L=new Float32Array(W*H);for(let i=0;i<W*H;i++)L[i]=(d[i*4]*.3+d[i*4+1]*.59+d[i*4+2]*.11)/255;out={W,H,L}}}catch(e){out=null}GREY.set(name,out);return out}
243
+ function photo(ctx,name,x,y,w,h){let bm=null;try{bm=name?M.asset(name):null}catch(e){bm=null}
244
+ if(!bm){ctx.fillStyle='#3a3a3a';ctx.fillRect(x,y,w,h);ctx.fillStyle='#565656';ctx.beginPath();ctx.arc(x+w/2,y+h*.38,w*.2,0,7);ctx.fill();ctx.fillRect(x+w*.22,y+h*.62,w*.56,h*.38);return}
245
+ const s=Math.max(w/bm.width,h/bm.height),dw=bm.width*s,dh=bm.height*s;ctx.save();ctx.beginPath();ctx.rect(x,y,w,h);ctx.clip();ctx.filter='grayscale(1) contrast(1.12) brightness(.96)';ctx.drawImage(bm,x+(w-dw)/2,y+(h-dh)*.25,dw,dh);ctx.filter='none'
246
+ const vg=ctx.createLinearGradient(0,y,0,y+h);vg.addColorStop(0,'rgba(60,40,20,.08)');vg.addColorStop(1,'rgba(60,40,20,.22)');ctx.fillStyle=vg;ctx.fillRect(x,y,w,h);ctx.restore()}
247
+ function anchor(s){if(s.kind==='photo')return [s.x,s.y-150];if(s.kind==='file')return [s.x,s.y-235];if(s.kind==='news')return [s.x,s.y-262];if(s.kind==='place')return [s.x,s.y-56];return null}
248
+ function drawStation(ctx,s,T,F,shake){
249
+ const u=T-s.t0,out=s.kind==='year'||s.kind==='type'||s.kind==='counter'?1-sm(seg(T,s.t1-.1,s.t1+.5)):1
250
+ if(out<=0)return
251
+ ctx.save();ctx.globalAlpha*=out;ctx.translate(s.x,s.y);ctx.rotate(s.rot*Math.PI/180)
252
+ if(s.kind==='year'){const a=sm(seg(u,.05,.5));ctx.globalAlpha*=a;ctx.font='200 92px '+F.mont;ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillStyle=CREAM
253
+ const yr=s.text,n=Math.min(yr.length,Math.floor(seg(u,.1,.1+.25*yr.length)*(yr.length+.999)));let o='';for(let i=0;i<yr.length;i++)o+=i<n?yr[i]:(i===n&&/[0-9]/.test(yr[i])?String(Math.floor(hash(Math.floor(T*24)+i)*10)):(i===n?yr[i]:' '))
254
+ if(WARM){ctx.save();ctx.transform(1,0,-.17,1,0,0);const k=1+.25*(1-eo(seg(u,.05,.5)));ctx.scale(k,k);ctx.font='700 150px '+F.oswald;ctx.shadowColor=LIGHT?'rgba(0,0,0,.25)':'rgba(70,22,0,.6)';ctx.shadowBlur=18;ctx.shadowOffsetY=6;ctx.fillStyle=LIGHT?INK:'#fff4e6';ctx.fillText(o,0,0);ctx.restore()}
255
+ else{ctx.fillText(o.split('').join(' '),0,0);const w=ctx.measureText(yr.split('').join(' ')).width/2+20,tl=eo(seg(u,.35,1.2))*170;ctx.fillStyle='rgba(236,230,216,.55)';ctx.fillRect(-w-tl,-1,tl,1.4);ctx.fillRect(w,-1,tl,1.4)}
256
+ if(s.sub){ctx.font='500 13px '+F.mont;ctx.fillStyle=ACC;ctx.fillText(typed(s.sub,seg(u,.8,1.6)),0,WARM?98:64)}}
257
+ if(s.kind==='place'&&SPEC.style!=='map'){const a=seg(u,0,.5);ctx.globalAlpha*=sm(a);ctx.scale(1.1-.1*back(a),1.1-.1*back(a));shadowCard(ctx,-110,-56,220,92,'#efe6c8');ctx.fillStyle=INK;ctx.font='800 22px '+F.mont;ctx.textAlign='center';ctx.fillText(s.label,0,-10);if(s.sub){ctx.font='500 12px '+F.mont;ctx.fillStyle='rgba(42,38,34,.7)';ctx.fillText(s.sub,0,14)}pin(ctx,0,-56)}
258
+ if(s.kind==='photo'){const a=seg(u,0,.55),k=1.18-.18*back(a);ctx.globalAlpha*=sm(a);ctx.rotate((-3+3*eo(a))*Math.PI/180);ctx.scale(k,k);shadowCard(ctx,-118,-150,236,300,'#f1ede4');photo(ctx,s.a,-104,-136,208,255)
259
+ if(s.caption){ctx.fillStyle=INK;ctx.font='700 15px '+F.mont;ctx.textAlign='center';ctx.fillText(s.caption,0,138)}pin(ctx,0,-140)}
260
+ if(s.kind==='file'){const a=seg(u,0,.6);ctx.globalAlpha*=sm(a);ctx.translate(0,30*(1-eo(a)));shadowCard(ctx,-190,-240,380,480,PAPER)
261
+ ctx.fillStyle=INK;ctx.font='800 22px '+F.mont;ctx.fillText(s.title,-160,-196);ctx.fillStyle=ACC;ctx.fillRect(-160,-182,80,3);if(s.sub){ctx.font='500 12px '+F.mont;ctx.fillStyle='rgba(42,38,34,.75)';ctx.fillText(s.sub,-160,-160)}
262
+ lines(ctx,-160,-128,320,5,16,11,.28);ctx.font='600 21px '+F.mont;ctx.fillStyle=INK;const r=wrap(ctx,s.text,-160,-16,320,30);lines(ctx,-160,r.bottom+18,320,6,16,41,.28)
263
+ circle(ctx,r.boxes[0],eo(seg(u,1.5,2.2)),3);if(r.boxes[1])circle(ctx,r.boxes[1],eo(seg(u,2.0,2.6)),5);pin(ctx,0,-235)}
264
+ if(s.kind==='news'){const a=seg(u,0,.6);ctx.globalAlpha*=sm(a);ctx.translate(0,24*(1-eo(a)));shadowCard(ctx,-215,-265,430,530,'#ebe5d6')
265
+ ctx.textAlign='center';ctx.fillStyle=INK;ctx.font='800 28px '+F.bevn;ctx.fillText(s.paper,0,-222);ctx.fillRect(-190,-208,380,2);ctx.font='500 11px '+F.mont;if(s.date)ctx.fillText(s.date,0,-192);ctx.fillRect(-190,-184,380,1)
266
+ ctx.font='400 46px '+F.anton;ctx.textAlign='left';const hw=[];const words=plain(s.headline);let lns=[],cur='';for(const wd of words.split(' ')){const tst=cur?cur+' '+wd:wd;if(ctx.measureText(tst).width>380&&cur){lns.push(cur);cur=wd}else cur=tst}lns.push(cur);lns=lns.slice(0,3)
267
+ let y=-138;const marks=[];let mk=false,rawWords=[];for(const part of s.headline.split('*')){for(const wd of part.split(' '))if(wd)rawWords.push({wd,mk});mk=!mk}let wi=0
268
+ for(const ln of lns){const lw=ctx.measureText(ln).width;let cx=-lw/2;ctx.fillText(ln,cx,y);for(const wd of ln.split(' ')){const tw=ctx.measureText(wd).width,rw=rawWords[wi++];if(rw&&rw.mk){const m=marks[marks.length-1];if(m&&m[1]===y)m[2]=cx+tw-m[0];else marks.push([cx,y,tw,48])}cx+=tw+ctx.measureText(' ').width}y+=52}
269
+ ctx.textAlign='center';if(s.deck){ctx.font='italic 500 14px '+F.mont;ctx.fillStyle='rgba(42,38,34,.8)';ctx.fillText(s.deck,0,y+4)}ctx.textAlign='left'
270
+ lines(ctx,-190,y+30,180,13,15,71,.3);lines(ctx,10,y+30,180,13,15,97,.3);for(const [j,m] of marks.entries())under(ctx,m,eo(seg(u,1.0+j*.3,1.5+j*.3)),12,3.6)
271
+ if(s.stamp){const sa=seg(u,2.0,2.2);if(sa>0){const im=stampImg(s.stamp,'900 64px '+F.anton),k=2.3-1.3*back(sa);ctx.save();ctx.translate(40,150);ctx.rotate(-11*Math.PI/180);ctx.scale(k*.62,k*.62);ctx.globalAlpha*=sm(sa*1.6)*.9;ctx.drawImage(im,-270,-85);ctx.restore()}}pin(ctx,0,-262)}
272
+ if(s.kind==='type'){ctx.textAlign='left';ctx.font='500 46px '+F.oswald;ctx.fillStyle=FG;const l1=plain(s.text),dur=Math.min(1.6,.05*l1.length+.4),t1=typed(l1,seg(u,.3,.3+dur)),full=ctx.measureText(l1).width
273
+ ctx.fillText(t1+(Math.floor(T*3)%2&&t1.length<l1.length?'▍':''),-full/2,s.then?-50:0);const st=eo(seg(u,.5+dur,.85+dur));if(st>0&&s.then){ctx.fillStyle=ACC;ctx.fillRect(-full/2-8,-65,(full+16)*st,5)}
274
+ if(s.then){const b=eo(seg(u,1+dur,1.9+dur));if(b>0){ctx.globalAlpha*=b;ctx.font='200 88px '+F.mont;ctx.letterSpacing=(14*(1-b)+4)+'px';const w=ctx.measureText(s.then).width;ctx.fillStyle=LIGHT?INK:'#f4efe4';ctx.fillText(s.then,-w/2,60);ctx.letterSpacing='0px'}}}
275
+ if(s.kind==='counter'){const a=seg(u,0,.4);ctx.globalAlpha*=sm(a);const p=eo(seg(u,.2,2.4)),n=Math.floor(Math.pow(p,2.2)*s.value);ctx.textAlign='left';ctx.font='600 17px '+F.mont;ctx.fillStyle=ACC;ctx.fillText(s.label,-200,-70)
276
+ ctx.font='500 64px '+F.oswald;ctx.fillText(n.toLocaleString('en-US')+(s.unit?' '+s.unit:''),-200,0);ctx.strokeStyle='rgba(236,230,216,.12)';ctx.lineWidth=1
277
+ for(let i=0;i<5;i++)for(let j=0;j<5;j++){ctx.beginPath();ctx.moveTo(-200,40+i*26);ctx.lineTo(60,40+j*26);ctx.stroke()}ctx.fillStyle='rgba(236,230,216,.45)';for(let i=0;i<5;i++){ctx.beginPath();ctx.arc(-200,40+i*26,3.5,0,7);ctx.arc(60,40+i*26,3.5,0,7);ctx.fill()}}
278
+ if(s.kind==='portrait'){const G=s.a?grey(s.a):null,form=sm(seg(u,.9,2.7)),fw=280,fh=G?fw*G.H/G.W:200,fx=-fw/2,fy=-fh/2-30,N=G?G.W*G.H:0
279
+ if(G){for(let j=0;j<G.H;j+=2)for(let i=0;i<G.W;i+=2){const v=G.L[j*G.W+i],id=j*G.W+i,r1=hash(id),r2=hash(id+5),q=r1*1.4-.2,sx=-460+q*560,sy=60+Math.sin(q*5+T*1.3)*40-q*90+(r2-.5)*36,tx=fx+i/G.W*fw,ty=fy+j/G.H*fh
280
+ const e=sm(cl(form*1.35-r2*.35)),x=sx+(tx-sx)*e,y=sy+(ty-sy)*e,rad=(.6+v*2.1)*(.4+.6*e)+(1-e)*.5,al=(1-e)*.55*cl(u*2)+e*(.15+v*.85);if(al<.03)continue
281
+ ctx.fillStyle=e>.6?'rgba(240,236,226,'+al+')':'rgba(255,'+(120+v*100|0)+',90,'+al+')';ctx.fillRect(x-rad,y-rad,rad*2,rad*2)}}
282
+ else{for(let i=0;i<900;i++){const r1=hash(i),r2=hash(i+5),q=r1*1.4-.2,sx=-460+q*560,sy=60+Math.sin(q*5+T*1.3)*40-q*90+(r2-.5)*36,a=Math.PI*2*r2,rr=60+r1*60,tx=Math.cos(a)*rr,ty=Math.sin(a)*rr*.6-30,e=sm(cl(form*1.3-r2*.3))
283
+ ctx.fillStyle='rgba(255,'+(150+r1*90|0)+',110,'+(.6*cl(u*2))+')';ctx.fillRect(sx+(tx-sx)*e-1,sy+(ty-sy)*e-1,2,2)}}
284
+ const ta=sm(seg(u,2.6,3.2));if(ta>0&&(s.title||s.sub)){ctx.globalAlpha*=ta;ctx.textAlign='center';if(s.title){ctx.font='800 26px '+F.mont;ctx.fillStyle='#f4efe4';ctx.fillText(s.title,0,fy+fh+44)}if(s.sub){ctx.font='500 13px '+F.mont;ctx.fillStyle=ACC;ctx.fillText(s.sub,0,fy+fh+68)}}}
285
+ ctx.restore()
286
+ }
287
+ function cork(ctx,W,H,c,S){ctx.fillStyle='#5a3d22';ctx.fillRect(0,0,W,H);const z=c.z*S,cs=26,x0=c.x-W/2/z,y0=c.y-H/2/z,i0=Math.floor(x0/cs)-1,j0=Math.floor(y0/cs)-1,ni=Math.ceil(W/z/cs)+2,nj=Math.ceil(H/z/cs)+2
288
+ for(let j=j0;j<j0+nj;j++)for(let i=i0;i<i0+ni;i++){const h=hash(i*7919+j*104729),x=(i*cs-c.x)*z+W/2,y=(j*cs-c.y)*z+H/2;ctx.fillStyle=h>.5?'rgba(140,96,52,'+(.18+h*.2)+')':'rgba(40,24,10,'+(.15+h*.2)+')';ctx.fillRect(x+hash(i+j*3)*cs*z*.5,y+hash(j+i*5)*cs*z*.5,(2+h*5)*z,(2+h*4)*z)}
289
+ const g=ctx.createRadialGradient(W/2,H*.45,H*.1,W/2,H/2,W*.65);g.addColorStop(0,'rgba(255,214,150,.16)');g.addColorStop(1,'rgba(0,0,0,.55)');ctx.fillStyle=g;ctx.fillRect(0,0,W,H)}
290
+ // wall: warm plaster (its specks travel with the camera); windowLight: the light of a 2 x 3 pane window falling across the
291
+ // frame (screen space: the light stays while the camera glides), drawn over the stations so it falls across the photos too
292
+ function wall(ctx,W,H,c,S){const g=ctx.createLinearGradient(0,0,W*.4,H);g.addColorStop(0,'#d99150');g.addColorStop(.55,'#b8641f');g.addColorStop(1,'#5a2a0b');ctx.fillStyle=g;ctx.fillRect(0,0,W,H)
293
+ const z=c.z*S,cs=34,x0=c.x-W/2/z,y0=c.y-H/2/z,i0=Math.floor(x0/cs)-1,j0=Math.floor(y0/cs)-1,ni=Math.ceil(W/z/cs)+2,nj=Math.ceil(H/z/cs)+2
294
+ for(let j=j0;j<j0+nj;j++)for(let i=i0;i<i0+ni;i++){const h=hash(i*7919+j*104729);if(h<.5)continue;const x=(i*cs-c.x)*z+W/2,y=(j*cs-c.y)*z+H/2;ctx.fillStyle=h>.8?'rgba(255,222,170,.12)':'rgba(70,30,5,.13)';ctx.fillRect(x+hash(i+j*3)*cs*z,y+hash(j+i*5)*cs*z,(1.4+h*2.4)*z,(1.4+h*2)*z)}}
295
+ function windowLight(ctx,W,H,T){const u=Math.min(W,H),pr=cl(T/Math.max(1,SPEC.total)),ww=u*.95,wh=u*1.25,b=u*.05,ps=[];for(let i=0;i<2;i++)for(let j=0;j<3;j++)ps.push([-ww/2+i*ww/2+b/2,-wh/2+j*wh/3+b/2,ww/2-b,wh/3-b])
296
+ ctx.save();ctx.translate(W*(.12+.68*pr),H*.44);ctx.rotate(-.12);ctx.transform(1,.16,-.5,1,0,0);ctx.filter='blur('+Math.round(u*.012)+'px)'
297
+ ctx.beginPath();ctx.rect(-W*4,-H*4,W*8,H*8);ps.forEach(q=>ctx.rect(q[0],q[1],q[2],q[3]));ctx.fillStyle='rgba(30,13,2,.3)';ctx.fill('evenodd')
298
+ ctx.beginPath();ps.forEach(q=>ctx.rect(q[0],q[1],q[2],q[3]));ctx.fillStyle='rgba(255,199,122,.28)';ctx.fill();ctx.filter='none';ctx.restore()}
299
+ // paper: grid paper that travels with the camera, soft crumple light; torn: red and navy torn paper over the corners, slid in
300
+ function paper(ctx,W,H,c,S){ctx.fillStyle='#e8e8e4';ctx.fillRect(0,0,W,H);const z=c.z*S,step=30*z,ox=W/2-c.x*z,oy=H/2-c.y*z,x0=((ox%step)+step)%step,y0=((oy%step)+step)%step
301
+ ctx.strokeStyle='rgba(80,105,130,.24)';ctx.lineWidth=Math.max(1,z*.8);ctx.beginPath();for(let x=x0;x<W;x+=step){ctx.moveTo(x,0);ctx.lineTo(x,H)}for(let y=y0;y<H;y+=step){ctx.moveTo(0,y);ctx.lineTo(W,y)}ctx.stroke()
302
+ for(let i=0;i<9;i++){const x=hash(i*3+1)*W,y=hash(i*5+2)*H,r=(.2+hash(i+9)*.35)*Math.max(W,H),g=ctx.createRadialGradient(x,y,0,x,y,r);g.addColorStop(0,i%2?'rgba(255,255,255,.2)':'rgba(50,60,75,.1)');g.addColorStop(1,'rgba(0,0,0,0)');ctx.fillStyle=g;ctx.fillRect(0,0,W,H)}}
303
+ function torn(ctx,W,H,T){const u=Math.min(W,H),k=1-eo(seg(T,0,.9))
304
+ const jag=(ax,ay,bx,by,n,a,seed,off)=>{const dx=bx-ax,dy=by-ay,L=Math.hypot(dx,dy)||1,nx=-dy/L,ny=dx/L,o=[];for(let i=0;i<=n;i++){const q=i/n,d=(hash(seed+i)-.5)*2*a+off;o.push([ax+dx*q+nx*d,ay+dy*q+ny*d])}return o}
305
+ const piece=(corner,edge,col,seed,dx,dy)=>{ctx.save();ctx.translate(dx*k,dy*k);for(const [off,fill] of [[u*.014,'#f3f0e8'],[0,col]]){ctx.beginPath();corner.forEach((p,i)=>i?ctx.lineTo(p[0],p[1]):ctx.moveTo(p[0],p[1]));jag(edge[0],edge[1],edge[2],edge[3],34,u*.009,seed,off).forEach(p=>ctx.lineTo(p[0],p[1]));ctx.closePath();ctx.fillStyle=fill;ctx.shadowColor='rgba(0,0,0,.28)';ctx.shadowBlur=u*.02;ctx.fill()}
306
+ ctx.shadowColor='transparent';ctx.clip();for(let i=0;i<60;i++){ctx.fillStyle=i%2?'rgba(255,255,255,.05)':'rgba(0,0,0,.08)';ctx.fillRect(hash(seed+i*3)*W,hash(seed+i*7)*H,u*.05*hash(i),u*.004)}ctx.restore()}
307
+ piece([[0,H*.36],[0,0],[W*.58,0]],[W*.58,0,0,H*.36],'#8b1c22',11,-W*.6,-H*.4)
308
+ piece([[W*.62,H],[0,H],[0,H*.74]],[0,H*.74,W*.62,H],'#1c2a52',37,-W*.6,H*.4)}
309
+ function render(ctx,t,env){
310
+ const W=env.width,H=env.height,S=W/1280,F=env.fonts,T=t+(+env.params.off||0),tot=SPEC.total,fin=sm(seg(T,0,.6))*(1-sm(seg(T,tot-.6,tot)))
311
+ const c=cam(T);let shake=0;for(const s of SPEC.S)if(s.kind==='news'&&s.stamp){const d=T-(s.t0+2.1);if(d>0&&d<.5)shake+=Math.sin(d*90)*6*(1-d/.5)}
312
+ if(SPEC.style==='cork')cork(ctx,W,H,c,S);else if(SPEC.style==='wall')wall(ctx,W,H,c,S);else if(LIGHT)paper(ctx,W,H,c,S);else{ctx.fillStyle='rgba(8,20,22,.42)';ctx.fillRect(0,0,W,H)}
313
+ // the place ping: on the map's centre (style map — the map layer below holds still)
314
+ if(SPEC.style==='map')for(const s of SPEC.S){if(s.kind!=='place')continue;const pE=s.t2||s.t1,pA=sm(seg(T,s.t0,s.t0+.5))*(1-sm(seg(T,pE-.2,pE+.4)));if(pA<=0)continue
315
+ ctx.save();ctx.globalAlpha=pA*fin;const px=W/2,py=H/2
316
+ for(let k=0;k<3;k++){const q=((T*.8+k/3)%1);ctx.strokeStyle='rgba(230,70,55,'+((1-q)*.8)+')';ctx.lineWidth=2*S;ctx.beginPath();ctx.arc(px,py,(6+q*46)*S,0,7);ctx.stroke()}
317
+ const gl=ctx.createRadialGradient(px,py,0,px,py,26*S);gl.addColorStop(0,'rgba(255,90,70,.9)');gl.addColorStop(1,'rgba(255,90,70,0)');ctx.fillStyle=gl;ctx.beginPath();ctx.arc(px,py,26*S,0,7);ctx.fill();ctx.fillStyle='#ff5a46';ctx.beginPath();ctx.arc(px,py,5*S,0,7);ctx.fill()
318
+ ctx.font='600 '+(14*S)+'px '+F.mont;ctx.fillStyle='rgba(235,230,220,.92)';ctx.textBaseline='middle';ctx.fillText(typed(s.label,seg(T,s.t0+.1,s.t0+.8)),px+16*S,py-18*S);if(s.sub){ctx.fillStyle='rgba(235,230,220,.55)';ctx.font='400 '+(11*S)+'px '+F.mont;ctx.fillText(typed(s.sub,seg(T,s.t0+.5,s.t0+1.1)),px+16*S,py-1*S)}ctx.restore()}
319
+ const z=c.z*S,ox=W/2-z*c.x+(Math.sin(T*.7)*3+shake)*S,oy=H/2-z*c.y+(Math.cos(T*.53)*2+shake*.5)*S,vw=W/2/z+40,vh=H/2/z+40
320
+ // red string: cork = from each pinned thing to the next; map = from the place ping (the frame centre) to the next pinned thing
321
+ const str=(A,B,p)=>{if(p<=0)return;const mx=(A[0]+B[0])/2,my=Math.max(A[1],B[1])+40*S;ctx.beginPath();ctx.moveTo(A[0],A[1]);const N=30,m=Math.floor(N*p);for(let k=1;k<=m;k++){const q=k/N;ctx.lineTo((1-q)*(1-q)*A[0]+2*q*(1-q)*mx+q*q*B[0],(1-q)*(1-q)*A[1]+2*q*(1-q)*my+q*q*B[1])}ctx.stroke()}
322
+ ctx.save();ctx.globalAlpha=fin;ctx.strokeStyle='rgba(190,34,26,.92)';ctx.lineWidth=2.6*S
323
+ if(SPEC.style==='cork'){let prev=null;for(const s of SPEC.S){const a=anchor(s);if(!a)continue;if(prev&&T>s.t0+.3)str([ox+prev[0]*z,oy+prev[1]*z],[ox+a[0]*z,oy+a[1]*z],eo(seg(T,s.t0+.3,s.t0+1.1)));prev=a}}
324
+ else for(const s of SPEC.S){if(s.kind!=='place'||!s.q)continue;const q=SPEC.S[s.q],a=anchor(q),al=1-sm(seg(T,s.t2-.2,s.t2+.4));if(!a||al<=0||T<q.t0+.2)continue;ctx.globalAlpha=fin*al;str([W/2,H/2],[ox+a[0]*z,oy+a[1]*z],eo(seg(T,q.t0+.2,q.t0+.9)))}
325
+ ctx.restore()
326
+ ctx.save();ctx.globalAlpha=fin;ctx.setTransform(z,0,0,z,ox,oy)
327
+ for(const s of SPEC.S){if(T<s.t0-.05)continue;if(SPEC.style==='map'&&s.kind==='place')continue;if(Math.abs(s.x-c.x)>vw+DOCW[s.kind]/2||Math.abs(s.y-c.y)>vh+300)continue;drawStation(ctx,s,T,F,shake)}
328
+ ctx.restore()
329
+ if(SPEC.style==='wall')windowLight(ctx,W,H,T);if(LIGHT)torn(ctx,W,H,T)
330
+ ctx.save();const fr=Math.floor(T*24);for(let i=0;i<420;i++){const h1=hash(fr*997+i),h2=hash(fr*991+i*3);ctx.fillStyle=h1>.5?'rgba(255,255,255,.05)':'rgba(0,0,0,.08)';ctx.fillRect(h1*W,h2*H,1.6*S,1.6*S)}
331
+ const vg=ctx.createRadialGradient(W/2,H/2,H*.35,W/2,H/2,W*.75);vg.addColorStop(0,'rgba(0,0,0,0)');vg.addColorStop(1,'rgba(0,0,0,'+(LIGHT?.22:WARM?.45:.62)+')');ctx.fillStyle=vg;ctx.fillRect(0,0,W,H);ctx.fillStyle='rgba(255,240,220,'+(.015+.015*hash(fr))+')';ctx.fillRect(0,0,W,H);ctx.restore()
332
+ }`;function h8(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:l,...u})=>u)};return`const SPEC=${JSON.stringify(e)};const DOCW=${JSON.stringify(er.width)};
333
+ ${u8}`}function d8({ids:t,at:e,plan:o,label:r}){const a=h8(o),n={};for(const u of o.S)u.a&&u.asset&&(n[u.a]=u.asset);const i=Math.ceil(o.total/er.layerSeconds-1e-6),l=[];for(let u=0;u<i;u++){const c=u*er.layerSeconds,s=Math.min(er.layerSeconds,o.total-c);l.push({id:t[u],nodeId:"",kind:"image",url:"",volume:0,start:vh(e+c),duration:vh(s),label:`${r||"Phim tư liệu"}${i>1?` · ${u+1}/${i}`:""}`,motionV:2,posX:0,posY:0,scale:1,motion:ko({code:a,params:{off:c},assets:n})})}return l}const iu=(t,e=.45)=>({color:t,blur:e,x:0,y:0}),f8={"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:iu("{accent}",.6),opacity:.85},{type:"text",fill:"{color}",shadow:iu("{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:iu("{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}}},$h=Object.freeze(Object.fromEntries(Object.entries(f8).map(([t,e])=>[t,Object.freeze({...e,design:Qk(e.design,`estateText.${t}`),animation:Jk(e.animation,`estateText.${t}`)})])));Object.freeze(Object.keys($h));const m8={top:-.3,center:0,lower:.24},g8=1.7;function y8(t,{portrait:e=!1}={}){const o=$h[t.preset]??$h["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??m8[a]*(e?.8:1),scale:t.scale??(e?g8:1),...t.track!=null?{track:t.track}:{}}}const ha=t=>Math.round(t*10)/10,b=(t,e)=>`${ha(t)} ${ha(e)}`,En=.5523,Se=(t,e,o,r)=>`M${b(t+o,e)} C${b(t+o,e+r*En)} ${b(t+o*En,e+r)} ${b(t,e+r)} C${b(t-o*En,e+r)} ${b(t-o,e+r*En)} ${b(t-o,e)} C${b(t-o,e-r*En)} ${b(t-o*En,e-r)} ${b(t,e-r)} C${b(t+o*En,e-r)} ${b(t+o,e-r*En)} ${b(t+o,e)} Z`,kt=(t,e,o)=>Se(t,e,o,o);function b8(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-En);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 ut=(t,e,o,r,a=0)=>b8(t-o/2,e-r/2,o,r,a),zt=(t,e=!0)=>"M"+t.map(o=>b(o[0],o[1])).join(" L")+(e?" Z":"");function ga(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 l=a(i-1),u=a(i),c=a(i+1),s=a(i+2),d=o/6;n+=` C${b(u[0]+(c[0]-l[0])*d,u[1]+(c[1]-l[1])*d)} ${b(c[0]-(s[0]-u[0])*d,c[1]-(s[1]-u[1])*d)} ${b(...c)}`}return e?n+" Z":n}const Je=t=>t*Math.PI/180,Wc=(t,e,o,r,a,n,i=10)=>Array.from({length:i+1},(l,u)=>{const c=Je(a+(n-a)*u/i);return[t+Math.cos(c)*o,e+Math.sin(c)*r]}),Ke=(t,e,o,r,a,n=o)=>ga(Wc(t,e,o,n,r,a),!1),_y=(t,e,o,r,a=-90)=>Array.from({length:o},(n,i)=>{const l=Je(a+i*360/o);return[t+Math.cos(l)*r,e+Math.sin(l)*r]}),Re=(t,e,o,r,a,n=-90)=>zt(Array.from({length:o*2},(i,l)=>{const u=Je(n+l*180/o),c=l%2?a:r;return[t+Math.cos(u)*c,e+Math.sin(u)*c]})),It=(t,e,o,r)=>`M${b(t,e)} L${b(o,r)}`,wt=(...t)=>t.join(" ");function Jo(t,e,o,r,a){const n=Math.atan2(r-e,o-t)*180/Math.PI,i=a/2;return zt([...Wc(o,r,i,i,n-90,n+90,6),...Wc(t,e,i,i,n+90,n+270,6)])}function xo(t,e,o,r,a=6){const n=[],i=a*6;for(let l=0;l<i;l++){const u=l/i,c=Math.PI*2*u,s=Math.max(0,-Math.sin(c)),d=Math.abs(Math.sin(c*a/2)),f=1+(.18*s+.06)*d;n.push([t+Math.cos(c)*o/2*f,e+Math.sin(c)*r/2*(Math.sin(c)>0?.82:f)])}return ga(n,!0)}function w8(t,e,o,r=1,a=9,n=.18){const i=[];for(let l=0;l<a;l++){const u=Math.PI*2*l/a,c=Math.sin(r*12.9898+l*78.233)*43758.5453,s=(c-Math.floor(c))*2-1;i.push([t+Math.cos(u)*o*(1+n*s),e+Math.sin(u)*o*(1+n*s)])}return ga(i,!0)}const Hc=(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`,Rn=(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}),hp=(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}),Al=(t,e)=>({d:t,fill:e,role:7}),nd=Object.freeze(["#f4efe6","#4a90d9","#f2b33d","#e5534b","#ffffff","#2d3142"]),k8=t=>nd[1+((t-1)%5+5)%5];function x8(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:k8(e.role),role:e.role,...e.eo?{eo:!0}:{},...e.line===!1?{line:!1}:{}})}const Gy=[],Xc={};function eo(t,e,o){Xc[t]=[e,o]}function pt(t,e,o,r,a,n,i={}){Gy.push({id:t,cat:e,vi:o,en:r,words:a,parts:n,human:!!i.human,outline:i.outline??!0,tags:i.tags})}eo("people","Người (biểu tượng)","People (pictograms)");const M8=["#f1c7a5","#c68c62","#8d5524"];function Hs({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)],l=r(-40),u=30*o.w,c=[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],d=(k,[y,A],I,z,j)=>{const P=Je(y),N=Je(A),F=[k[0]+Math.sin(P)*I,k[1]+Math.cos(P)*I],K=[F[0]+Math.sin(N)*z,F[1]+Math.cos(N)*z];return{d:wt(Jo(k[0],k[1],F[0],F[1],j),Jo(F[0],F[1],K[0],K[1],j*.92)),end:K}},f=r(30),m=r(36),g=u/2-o.limb*.35,v=d([i[0]+g,l],s.la,f,f*.95,o.limb),x=d([i[0]-g,l],s.ra,f,f*.95,o.limb),$=d([n[0]+u*.22,n[1]-2],s.ll,m,m,o.limb*1.12),E=d([n[0]-u*.22,n[1]-2],s.rl,m,m,o.limb*1.12),S=ga([[i[0]-u/2,l-6],[i[0]+u/2,l-6],[n[0]+u*.44,n[1]+4],[n[0]-u*.44,n[1]+4]],!0,.35);return{head:kt(c[0],c[1],o.head),torso:S,la:v,ra:x,ll:$,rl:E}}const ra=(t,e=1)=>[R(wt(t.ll.d,t.rl.d,t.la.d,t.torso,t.ra.d,t.head),e)],v8=[["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"]],Kn={role:["explain","overlay"],style:["clean","minimal","corporate"]};for(const[t,e,o]of v8){const r=Hs({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(ut(a,n-14,58,40,4),2)]:t==="sit"?[R(wt(ut(-14,30,72,10,3),ut(-44,56,8,44,2),ut(18,22,8,112,2)),5)]:t==="present"?[R(ut(-130,-40,90,64,4),4),Ot(wt(It(-160,-20,-102,-20),It(-160,-4,-110,-4),It(-160,12,-120,12)),5)]:[];pt(`person-${t}`,"people",`Người ${e}`,`Person ${o}`,["người","person","human","pictogram",e,o],t==="present"||t==="sit"?[...i,...ra(r)]:[...ra(r),...i],{human:!0,tags:Kn})}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=Hs({pose:t==="elder"?"elder":"stand",body:t}),a=t==="elder"?[R(Jo(-34,-6,-40,72,5),5)]:[];pt(`person-${t}`,"people",`Người ${e}`,`Person ${o}`,["người","person","human","pictogram","body",e,o],[...ra(r,t==="child"?3:1),...a],{human:!0,tags:Kn})}{const t=Hs({pose:"stand"}),e=Hs({pose:"stand",body:"child"}),o=(r,a)=>r.replace(/(-?\d*\.?\d+) (-?\d*\.?\d+)/g,(n,i,l)=>`${ha(+i+a)} ${l}`);pt("people-family","people","Gia đình","Family",["gia đình","family","parent","child","người","people"],[...ra(t).map(r=>({...r,d:o(r.d,-34)})),...ra(e,3).map(r=>({...r,d:o(r.d.replace(/(-?\d*\.?\d+) (-?\d*\.?\d+)/g,(a,n,i)=>`${n} ${ha(+i+16)}`),34)}))],{human:!0,tags:Kn}),pt("people-group","people","Nhóm người","Group of people",["nhóm","group","team","đội","people","người"],[...ra(t,2).map(r=>({...r,d:o(r.d,-52)})),...ra(t,3).map(r=>({...r,d:o(r.d,52)})),...ra(t,1)],{human:!0,tags:Kn})}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=Hs({pose:t});pt(`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:Kn})}function dp({skin:t=0,hair:e="short",top:o=1,bottom:r=5,arm:a="down"}){const n=M8[t],i=[];i.push(R(Jo(-14,40,-16,96,17),r),R(Jo(14,40,16,96,17),r)),i.push(R(ut(-17,100,26,10,5),5),R(ut(17,100,26,10,5),5));const l=a==="wave"?wt(Jo(-30,-14,-44,30,13)):Jo(-30,-14,-40,34,13),u=a==="wave"?Jo(30,-14,56,-50,13):Jo(30,-14,40,34,13);return i.push(R(l,o),R(u,o),Al(kt(-41,38,8),n),Al(kt(a==="wave"?58:41,a==="wave"?-56:38,8),n)),i.push(R(ga([[-30,-24],[30,-24],[34,46],[-34,46]],!0,.4),o)),i.push(Al(ut(0,-30,14,12,3),n),Al(kt(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(ut(14,-64,34,8,4),3)),i.push({...R(wt(kt(-9,-58,2.6),kt(9,-58,2.6)),5),line:!1},Ot(Ke(0,-50,8,20,160),5)),i}pt("character-a","people","Nhân vật phẳng A","Flat character A",["nhân vật","character","người","person","flat"],dp({skin:0,hair:"short",top:1}),{human:!0,tags:Kn});pt("character-b","people","Nhân vật phẳng B","Flat character B",["nhân vật","character","người","person","flat"],dp({skin:1,hair:"long",top:3,bottom:2}),{human:!0,tags:Kn});pt("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"],dp({skin:2,hair:"cap",top:2,arm:"wave"}),{human:!0,tags:Kn});pt("character-d","people","Nhân vật phẳng D","Flat character D",["nhân vật","character","người","person","flat"],dp({skin:1,hair:"short",top:4,bottom:1,arm:"wave"}),{human:!0,tags:Kn});eo("hands","Bàn tay & cử chỉ","Hands & gestures");const fp=(t=0,e=10)=>ut(t,e,56,58,18),_o=(t,e,o,r=0,a=14)=>Jo(t,e,t+Math.sin(Je(r))*o,e-Math.cos(Je(r))*o,a),ya={role:["explain","sticker"],style:["playful","clean"]};pt("hand-thumbs-up","hands","Like (giơ ngón cái)","Thumbs up",["like","thích","ngón cái","thumb"],[R(ut(0,14,52,56,14),4),R(_o(-18,-6,40,-8,18),4),R(wt(ut(18,0,22,12,6),ut(18,14,22,12,6),ut(18,28,22,12,6)),4),R(ut(0,60,58,22,4),1)],{tags:ya});pt("hand-point","hands","Tay chỉ","Pointing hand",["chỉ","point","tay","hand"],[R(ut(6,14,50,48,14),4),R(Jo(-10,0,-70,-4,15),4),R(wt(ut(26,0,18,12,6),ut(26,13,18,12,6),ut(26,26,18,12,6)),4),R(ut(14,52,40,20,4),1)],{tags:ya});pt("hand-open","hands","Bàn tay mở","Open palm",["bàn tay","palm","stop","dừng","hi"],[R(fp(),4),R(wt(_o(-20,-10,40,-6),_o(-6,-14,46,-2),_o(8,-14,44,2),_o(21,-10,36,8),_o(-30,16,30,-60)),4),R(ut(0,52,52,18,4),1)],{tags:ya});pt("hand-ok","hands","Tay OK","OK hand",["ok","tốt","được"],[R(fp(4,14),4),R(wt(_o(-2,-12,44,2),_o(12,-10,40,8),_o(24,-4,32,14)),4),R(wt(kt(-22,-10,16)),4),Ot(kt(-22,-10,7),5)],{tags:ya});pt("hand-peace","hands","Tay chữ V","Peace sign",["peace","chiến thắng","victory","v"],[R(fp(0,16),4),R(wt(_o(-10,-8,50,-14),_o(8,-8,50,12)),4),R(ut(0,54,52,18,4),1)],{tags:ya});pt("hand-fist","hands","Nắm tay","Fist",["nắm tay","fist","power","sức mạnh"],[R(ut(0,4,60,54,16),4),Ot(wt(It(-14,-22,-14,-6),It(2,-22,2,-6),It(18,-22,18,-6)),5),R(ut(0,48,52,22,4),1)],{tags:ya});pt("hand-wave","hands","Tay vẫy","Waving hand",["vẫy","wave","hello","xin chào"],[R(fp(),4),R(wt(_o(-20,-10,40,-16),_o(-6,-14,46,-8),_o(8,-14,44,-2),_o(21,-10,36,4),_o(-30,16,30,-70)),4),Ot(wt(Ke(48,-30,16,-60,40),Ke(48,-30,28,-60,40)),3)],{tags:ya});pt("hand-clap","hands","Vỗ tay","Clapping hands",["vỗ tay","clap","applause"],[R(ut(-14,4,40,70,16),4),R(ut(14,0,40,70,16),4),Ot(wt(It(-48,-40,-38,-30),It(-30,-56,-26,-42),It(46,-44,36,-32)),3)],{tags:ya});eo("faces","Mặt & biểu cảm","Faces & emoji");const $8={role:["sticker","social"],style:["playful"]},Lr=(t,e,o,r,a)=>pt(`face-${t}`,"faces",e,o,["mặt","face","emoji","biểu cảm",...r],[R(kt(0,0,60),2),...a],{tags:$8}),Qa=(t=-12,e=7)=>R(wt(kt(-20,t,e),kt(20,t,e)),5);Lr("smile","Mặt cười","Smile",["vui","happy","cười"],[Qa(),Ot(Ke(0,4,28,25,155),5)]);Lr("grin","Cười toe","Grin",["toe","grin","haha"],[Qa(),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)]);Lr("sad","Buồn","Sad",["buồn","sad"],[Qa(-8),Ot(Ke(0,38,24,205,335),5)]);Lr("wink","Nháy mắt","Wink",["nháy mắt","wink"],[R(kt(-20,-12,7),5),Ot(Ke(20,-10,9,200,340),5),Ot(Ke(0,4,28,25,155),5)]);Lr("surprised","Ngạc nhiên","Surprised",["ngạc nhiên","wow","surprised","bất ngờ"],[Qa(-14,8),R(Se(0,24,12,16),5)]);Lr("love","Mắt tim","Heart eyes",["yêu","love","tim"],[R(wt(Hc(-21,-12,13),Hc(21,-12,13)),3),Ot(Ke(0,4,28,25,155),5)]);Lr("cool","Đeo kính","Cool",["ngầu","cool","kính"],[R(wt(ut(-21,-12,34,20,8),ut(21,-12,34,20,8)),5),Ot(It(-4,-14,4,-14),5),Ot(Ke(0,10,22,30,150),5)]);Lr("angry","Giận","Angry",["giận","angry","tức"],[Qa(-6),Ot(wt(It(-34,-30,-10,-20),It(34,-30,10,-20)),5),Ot(Ke(0,38,20,210,330),5)]);Lr("laugh","Cười lớn","Laugh",["cười lớn","laugh","lol"],[Ot(wt(Ke(-20,-10,9,200,340),Ke(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)]);Lr("think","Suy nghĩ","Thinking",["nghĩ","thinking","hmm"],[Qa(-12,6),Ot(It(-16,24,18,18),5),Ot(wt(It(-28,-30,-10,-26)),5)]);Lr("sleepy","Buồn ngủ","Sleepy",["ngủ","sleepy","zzz"],[Ot(wt(It(-28,-10,-12,-10),It(12,-10,28,-10)),5),R(Se(0,24,8,10),5),Ot(wt(zt([[40,-60],[56,-60],[40,-44],[56,-44]],!1)),5)]);Lr("neutral","Bình thường","Neutral",["bình thường","neutral","meh"],[Qa(),Ot(It(-20,22,20,22),5)]);eo("nature","Thiên nhiên","Nature");const oo={role:["overlay","background","explain"],style:["playful","soft","clean"]};pt("tree-round","nature","Cây tán tròn","Round tree",["cây","tree","xanh"],[R(ut(0,50,18,70,4),5),R(xo(0,-20,140,120,5),1)],{tags:oo});pt("tree-pine","nature","Cây thông","Pine tree",["thông","pine","cây","noel"],[R(ut(0,78,16,34,3),5),R(zt([[0,-96],[46,-28],[24,-28],[60,30],[30,30],[70,82],[-70,82],[-30,30],[-60,30],[-24,-28],[-46,-28]]),1)],{tags:oo});pt("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:oo});pt("bush","nature","Bụi cây","Bush",["bụi","bush","cỏ"],[R(xo(0,10,170,90,6),1)],{tags:oo});pt("flower","nature","Bông hoa","Flower",["hoa","flower"],[R(Jo(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(..._y(0,-30,6,30).map(([t,e])=>kt(t,e,20))),3),R(kt(0,-30,16),2)],{tags:oo});pt("tulip","nature","Hoa tulip","Tulip",["tulip","hoa","flower"],[R(Jo(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:oo});pt("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)}`,It(-24,16,-30,-10),It(4,-12,2,-40),It(-24,16,4,22),It(4,-12,30,-6)),5)],{tags:oo});pt("cactus","nature","Xương rồng","Cactus",["xương rồng","cactus","sa mạc"],[R(ut(0,80,70,30,4),3),R(wt(ut(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:oo});pt("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(kt(-36,-20,10),kt(10,-40,12),kt(44,-10,8)),4)],{tags:oo});pt("grass","nature","Đám cỏ","Grass tuft",["cỏ","grass"],[R(zt([[-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:oo});pt("mountain","nature","Núi","Mountain",["núi","mountain"],[R(zt([[-110,70],[-20,-70],[90,70]]),1),R(zt([[-20,-70],[-44,-32],[-30,-38],[-18,-26],[-4,-40],[8,-30]]),4),R(zt([[20,70],[70,-10],[120,70]]),2)],{tags:oo});pt("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:oo});pt("rock","nature","Hòn đá","Rock",["đá","rock","stone"],[R(ga([[-60,40],[-50,-10],[-14,-34],[30,-26],[58,8],[60,40]],!0,.5),5)],{tags:oo});pt("sun","nature","Mặt trời","Sun",["mặt trời","sun","nắng"],[R(Re(0,0,12,96,70,-90),3),R(kt(0,0,58),2)],{tags:oo});pt("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(Re(50,-40,4,10,4,0),Re(60,20,4,7,3,0)),4)],{tags:oo});pt("cloud","nature","Đám mây","Cloud",["mây","cloud"],[R(xo(0,0,190,100,6),4)],{tags:oo});pt("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:oo});pt("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:oo});pt("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:oo});pt("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(xo(-80,46,70,36,4),4),R(xo(80,46,70,36,4),4)],{tags:oo});eo("weather","Thời tiết","Weather");const Vn={role:["overlay","explain","sticker"],style:["playful","clean"]};pt("weather-sun-cloud","weather","Nắng có mây","Sun and cloud",["nắng","mây","partly cloudy"],[R(Re(-26,-24,10,62,46,-90),3),R(kt(-26,-24,38),2),R(xo(20,20,150,80,5),4)],{tags:Vn});pt("weather-rain","weather","Mây mưa","Rain cloud",["mưa","rain"],[R(xo(0,-20,170,90,6),4),R(wt(Rn(-40,58,12),Rn(0,72,12),Rn(40,58,12)),1)],{tags:Vn});pt("weather-storm","weather","Giông bão","Storm",["bão","sấm","storm","thunder"],[R(xo(0,-24,170,90,6),5),R(zt([[6,10],[-20,56],[0,56],[-12,96],[30,40],[10,40],[24,10]]),2)],{tags:Vn});pt("weather-snow","weather","Tuyết rơi","Snow",["tuyết","snow","lạnh"],[R(xo(0,-24,170,90,6),4),Ot(wt(...[[-40,60],[0,74],[40,60]].flatMap(([t,e])=>[It(t-9,e,t+9,e),It(t-5,e-8,t+5,e+8),It(t-5,e+8,t+5,e-8)])),1)],{tags:Vn});pt("snowflake","weather","Bông tuyết","Snowflake",["tuyết","snowflake","noel"],[Ot(wt(...[0,60,120].map(t=>{const e=Math.cos(Je(t)),o=Math.sin(Je(t));return It(-80*e,-80*o,80*e,80*o)}),...[0,60,120,180,240,300].flatMap(t=>{const e=Math.cos(Je(t)),o=Math.sin(Je(t)),r=50*e,a=50*o;return[It(r,a,r+Math.cos(Je(t+40))*22,a+Math.sin(Je(t+40))*22),It(r,a,r+Math.cos(Je(t-40))*22,a+Math.sin(Je(t-40))*22)]})),1)],{tags:Vn});pt("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:Vn});pt("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:Vn});pt("thermometer","weather","Nhiệt kế","Thermometer",["nhiệt độ","nóng","thermometer","temperature"],[R(wt(ut(0,-20,30,130,15)),4),R(kt(0,56,26),3),R(ut(0,10,12,80,6),3),Ot(wt(It(18,-60,28,-60),It(18,-36,28,-36),It(18,-12,28,-12)),5)],{tags:Vn});pt("lightning","weather","Tia sét","Lightning bolt",["sét","lightning","điện","energy"],[R(zt([[14,-96],[-46,10],[-6,10],[-22,96],[48,-20],[6,-20]]),2)],{tags:Vn});eo("city","Nhà cửa & phố","Buildings & city");const jo={role:["background","explain","overlay"],style:["clean","playful"]},Go=(t,e,o=18,r=22)=>ut(t,e,o,r,2);pt("house","city","Ngôi nhà","House",["nhà","house","home"],[R(ut(0,30,140,100,2),4),R(zt([[-86,-16],[0,-90],[86,-16]]),3),R(ut(40,-70,18,36,1),5),R(ut(-30,50,34,60,3),1),R(wt(Go(28,20,30,28)),2),Ot(wt(It(28,6,28,34),It(13,20,43,20)),5)],{tags:jo});pt("house-two-storey","city","Nhà hai tầng","Two-storey house",["nhà","nhà phố","townhouse","house"],[R(ut(0,10,120,160,2),4),R(zt([[-72,-70],[0,-118],[72,-70]]),3),R(wt(Go(-30,-40,26,30),Go(30,-40,26,30),Go(30,30,26,30)),2),R(ut(-30,56,30,68,3),1),R(ut(0,-2,130,8,2),5)],{tags:jo});pt("apartment","city","Chung cư","Apartment block",["chung cư","căn hộ","apartment"],[R(ut(0,0,130,200,4),1),R(wt(...[-70,-30,10,50].flatMap(t=>[-38,0,38].map(e=>Go(e,t,22,24)))),4),R(ut(0,88,34,24,2),5)],{tags:jo});pt("skyscraper","city","Toà nhà cao tầng","Skyscraper",["cao ốc","tòa nhà","office tower","skyscraper"],[R(zt([[-40,110],[-40,-80],[0,-110],[40,-80],[40,110]]),2),R(wt(...Array.from({length:8},(t,e)=>ut(0,-60+e*20,56,8,1))),4),R(ut(0,-120,4,30,1),5)],{tags:jo});pt("shop","city","Cửa hàng","Shop",["cửa hàng","shop","store","tiệm"],[R(ut(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(ut(0,-36,160,22,3),1),R(ut(-36,46,40,60,2),2),R(ut(30,36,50,40,2),2)],{tags:jo});pt("factory","city","Nhà máy","Factory",["nhà máy","factory","sản xuất","industry"],[R(zt([[-100,80],[-100,-10],[-50,-40],[-50,-10],[0,-40],[0,-10],[50,-40],[50,-10],[100,-10],[100,80]]),4),R(ut(70,-60,22,100,2),5),R(xo(84,-100,50,30,4),4),R(wt(Go(-70,30),Go(-30,30),Go(10,30)),2)],{tags:jo});pt("school","city","Trường học","School",["trường","school","học","education"],[R(ut(0,30,170,100,2),4),R(zt([[-50,-20],[0,-70],[50,-20]]),3),R(ut(0,0,100,40,2),4),R(kt(0,-30,12),2),R(wt(Go(-62,30),Go(-32,30),Go(32,30),Go(62,30)),2),R(ut(0,56,24,48,2),1),Ot(It(0,-70,0,-100),5),R(zt([[0,-100],[24,-92],[0,-84]]),3)],{tags:jo});pt("hospital","city","Bệnh viện","Hospital",["bệnh viện","hospital","y tế","health"],[R(ut(0,20,170,140,4),4),R(wt(ut(0,-20,40,12,2),ut(0,-20,12,40,2)),3),R(wt(Go(-56,30),Go(-26,30),Go(26,30),Go(56,30)),2),R(ut(0,68,30,44,2),1)],{tags:jo});pt("bank","city","Ngân hàng","Bank",["ngân hàng","bank","tài chính","finance"],[R(zt([[-90,-40],[0,-90],[90,-40]]),3),R(ut(0,-34,170,14,2),5),R(wt(...[-60,-20,20,60].map(t=>ut(t,20,16,90,2))),4),R(ut(0,72,180,14,2),5)],{tags:jo});pt("pagoda","city","Chùa / tháp","Pagoda",["chùa","tháp","pagoda","temple","đình"],[R(ut(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(ut(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(ut(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:jo});pt("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=>It(t,10,t,10-Math.max(0,62-Math.abs(t)*.6)))),1),R(wt(ut(-80,48,20,44,2),ut(80,48,20,44,2)),5)],{tags:jo});pt("streetlamp","city","Đèn đường","Street lamp",["đèn đường","street lamp","đèn"],[R(ut(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(ut(0,98,30,10,3),5)],{tags:jo});pt("traffic-light","city","Đèn giao thông","Traffic light",["đèn giao thông","traffic light","đèn xanh đỏ"],[R(ut(0,-10,50,130,12),5),R(kt(0,-50,15),3),R(kt(0,-10,15),2),R(kt(0,30,15),1),R(ut(0,90,10,70,3),5)],{tags:jo});pt("skyline","city","Đường chân trời thành phố","City skyline",["thành phố","city","skyline","phố"],[R(zt([[-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])=>ut(t,e,8,10,1))),2)],{tags:jo});pt("tent","city","Lều trại","Tent",["lều","cắm trại","tent","camping"],[R(zt([[-90,60],[0,-70],[90,60]]),3),R(zt([[-26,60],[0,0],[26,60]]),5),Ot(wt(It(0,-70,-10,-90),It(0,-70,10,-90)),5)],{tags:jo});pt("castle","city","Lâu đài","Castle",["lâu đài","castle","cổ tích"],[R(wt(ut(-60,10,40,130,0),ut(60,10,40,130,0),ut(0,30,90,90,0)),4),R(wt(...[-74,-46,46,74].map(t=>ut(t,-62,12,16,0)),...[-30,0,30].map(t=>ut(t,-22,14,14,0))),4),R(wt(zt([[-84,-70],[-60,-110],[-36,-70]]),zt([[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:jo});pt("cafe-front","city","Quán cà phê","Café front",["quán","cà phê","cafe","coffee shop"],[R(ut(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(ut(0,-40,170,14,2),1),R(ut(-40,40,46,64,2),2),R(ut(34,40,60,44,2),2),R(wt(kt(40,-60,4),It(30,-66,50,-66)),5)],{tags:jo});eo("transport","Phương tiện","Transport");const Nr={role:["explain","overlay"],style:["playful","clean"]},dr=(t,e,o=16)=>[R(kt(t,e,o),5),R(kt(t,e,o*.4),4)];pt("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),...dr(-54,32,20),...dr(56,32,20)],{tags:Nr});pt("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(ut(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),...dr(-54,32,20),...dr(56,32,20)],{tags:Nr});pt("bus","transport","Xe buýt","Bus",["xe buýt","bus"],[R(ut(0,-10,220,100,14),1),R(wt(...[-80,-40,0,40].map(t=>ut(t,-30,30,30,4)),ut(86,-20,26,50,4)),4),R(ut(0,24,220,8,2),4),...dr(-64,46,20),...dr(64,46,20)],{tags:Nr});pt("truck","transport","Xe tải","Truck",["xe tải","truck","giao hàng","delivery"],[R(ut(-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),...dr(-60,38,18),...dr(70,38,18)],{tags:Nr});pt("bicycle","transport","Xe đạp","Bicycle",["xe đạp","bicycle","bike"],[Ot(wt(kt(-56,30,34),kt(56,30,34),zt([[-56,30],[-14,-26],[36,-26],[56,30]],!1),zt([[-14,-26],[0,30],[36,-26]],!1),It(0,30,-56,30),It(-20,-40,-4,-40),It(36,-26,30,-46),It(22,-48,42,-48)),5)],{tags:Nr});pt("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(ut(-30,-30,60,14,6),5),...dr(-56,30,22),...dr(64,30,22),Ot(It(56,-60,76,-70),5),R(kt(78,-40,6),2)],{tags:Nr});pt("train","transport","Tàu hoả","Train",["tàu hỏa","tàu","train","metro"],[R(ut(0,-10,200,110,24),1),R(ut(0,-36,160,40,8),4),R(ut(0,40,200,14,4),5),R(wt(kt(-60,10,8),kt(60,10,8)),2),...dr(-50,60,14),...dr(50,60,14)],{tags:Nr});pt("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(zt([[-10,-14],[30,-90],[50,-90],[30,-14]]),zt([[-10,14],[30,90],[50,90],[30,14]]),zt([[-100,-12],[-110,-56],[-92,-56],[-70,-14]])),1),R(wt(...[50,70,90].map(t=>kt(t,-2,4))),5)],{tags:Nr});pt("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(ut(0,-20,6,124,2),5),R(zt([[6,-80],[6,30],[76,30]]),4),R(zt([[-6,-60],[-6,30],[-60,30]]),2)],{tags:Nr});pt("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(ut(10,-4,120,48,4),4),R(ut(40,-48,30,40,3),3),R(wt(kt(-20,-4,7),kt(10,-4,7),kt(40,-4,7)),2)],{tags:Nr});pt("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(kt(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:Nr});pt("delivery-scooter","transport","Xe giao hàng","Delivery scooter",["giao hàng","shipper","delivery","xe máy"],[R(ut(-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),...dr(-56,30,22),...dr(64,30,22),Ot(It(56,-56,76,-66),5)],{tags:Nr});eo("food","Đồ ăn & thức uống","Food & drink");const To={role:["sticker","explain","overlay"],style:["playful"]};pt("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(ut(0,-40,112,20,8),3),R(ut(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:To});pt("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(ut(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(kt(-50,-24,12),kt(40,-26,10)),1),Ot(wt(It(40,-90,100,-40),It(58,-96,110,-50)),5)],{tags:To});pt("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(It(-60,-22,-44,-10),It(-20,-26,-4,-14),It(20,-26,36,-14),It(60,-22,76,-10)),5)],{tags:To});pt("pizza","food","Lát pizza","Pizza slice",["pizza"],[R(zt([[-70,-70],[70,-70],[0,90]]),2),R(ut(0,-74,150,22,10),3),R(wt(kt(-24,-36,12),kt(18,-20,10),kt(-4,22,10)),3)],{tags:To});pt("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(ut(0,26,190,22,10),5),R(ut(0,54,180,30,14),2)],{tags:To});pt("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(Jo(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:To});pt("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(ut(-80,-58,14,20,3),5)],{tags:To});pt("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:To});pt("cake","food","Bánh kem","Cake",["bánh kem","sinh nhật","birthday","cake"],[R(ut(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(ut(-30,-14,10,40,3),ut(0,-14,10,40,3),ut(30,-14,10,40,3)),1),R(wt(Rn(-30,-44,9),Rn(0,-44,9),Rn(30,-44,9)),2)],{tags:To});pt("ice-cream","food","Kem ốc quế","Ice cream",["kem","ice cream","mùa hè"],[R(zt([[-40,-10],[40,-10],[0,100]]),2),Ot(wt(It(-24,10,14,64),It(24,10,-14,64)),5),R(xo(0,-40,100,80,5),3),R(kt(0,-84,10),3)],{tags:To});pt("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:To});pt("rice-bowl","food","Bát cơm","Rice bowl",["cơm","rice","bát"],[R(xo(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(It(30,-90,80,-10),It(46,-96,92,-18)),5)],{tags:To});pt("cupcake","food","Bánh cupcake","Cupcake",["cupcake","bánh"],[R(zt([[-50,0],[50,0],[36,80],[-36,80]]),1),Ot(wt(It(-20,4,-14,76),It(0,4,0,76),It(20,4,14,76)),5),R(xo(0,-20,120,70,5),4),R(kt(0,-60,12),3)],{tags:To});pt("egg","food","Trứng ốp la","Fried egg",["trứng","egg","bữa sáng"],[R(w8(0,0,80,3,10,.16),4),R(kt(10,-6,32),2)],{tags:To});pt("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(zt([[60,0],[110,-40],[100,0],[110,40]]),1),R(kt(-44,-10,7),5),Ot(Ke(-14,0,20,-60,60),5)],{tags:To});pt("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(zt([[-4,-50],[-30,-100],[0,-60]]),zt([[0,-52],[0,-110],[10,-56]]),zt([[4,-50],[34,-96],[10,-56]])),1),Ot(wt(It(-16,-14,0,-12),It(4,20,14,22)),5)],{tags:To});pt("bubble-tea","food","Trà sữa","Bubble tea",["trà sữa","bubble tea","boba","milk tea"],[R(zt([[-40,-40],[40,-40],[30,90],[-30,90]]),4),R(ut(0,-48,96,18,8),1),R(wt(...[[-16,64],[4,72],[18,58],[-2,50],[-20,40]].map(([t,e])=>kt(t,e,7))),5),R(ut(10,-90,10,90,4),3)],{tags:To});eo("tech","Công nghệ","Tech");const Mo={role:["explain","overlay"],style:["tech","clean"]};pt("laptop","tech","Máy tính xách tay","Laptop",["laptop","máy tính","computer"],[R(ut(0,-20,170,110,8),5),R(ut(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:Mo});pt("phone","tech","Điện thoại","Phone",["điện thoại","phone","smartphone","mobile"],[R(ut(0,0,90,170,16),5),R(ut(0,-4,76,140,6),1),R(ut(0,-78,24,5,2),4),R(kt(0,78,5),4)],{tags:Mo});pt("monitor","tech","Màn hình máy tính","Desktop monitor",["màn hình","monitor","pc","desktop"],[R(ut(0,-20,200,124,8),5),R(ut(0,-24,184,104,4),1),R(zt([[-16,42],[16,42],[26,80],[-26,80]]),5),R(ut(0,82,90,10,4),5)],{tags:Mo});pt("tablet","tech","Máy tính bảng","Tablet",["máy tính bảng","tablet","ipad"],[R(ut(0,0,130,170,14),5),R(ut(0,0,114,146,6),1)],{tags:Mo});pt("camera","tech","Máy ảnh","Camera",["máy ảnh","camera","chụp ảnh","photo"],[R(ut(0,10,180,110,14),5),R(ut(-40,-50,60,22,6),5),R(kt(0,14,40),4),R(kt(0,14,26),1),R(kt(60,-24,7),2)],{tags:Mo});pt("video-camera","tech","Máy quay","Video camera",["máy quay","video","quay phim","camcorder"],[R(ut(-20,0,130,90,12),5),R(zt([[46,-16],[100,-44],[100,44],[46,16]]),5),R(kt(-50,-62,22),4),R(kt(10,-62,22),4),R(kt(40,-24,6),3)],{tags:Mo});pt("headphones","tech","Tai nghe","Headphones",["tai nghe","headphones","âm nhạc","music"],[Ot(Ke(0,10,70,180,360),5),R(wt(ut(-70,30,30,64,10),ut(70,30,30,64,10)),1)],{tags:Mo});pt("microphone","tech","Micro","Microphone",["micro","mic","podcast","thu âm"],[R(ut(0,-40,52,90,26),5),Ot(wt(`M${b(-44,-20)} C${b(-44,40)} ${b(44,40)} ${b(44,-20)}`,It(0,30,0,70),It(-30,70,30,70)),5),Ot(wt(It(-14,-60,14,-60),It(-14,-44,14,-44),It(-14,-28,14,-28)),4)],{tags:Mo});pt("gear","tech","Bánh răng","Gear",["bánh răng","gear","cài đặt","settings"],[R(Re(0,0,10,90,70,0),5),R(kt(0,0,30),4)],{tags:Mo});pt("cloud-upload","tech","Đám mây tải lên","Cloud upload",["tải lên","upload","cloud","đám mây"],[R(xo(0,0,190,110,6),4),R(zt([[0,-40],[30,-6],[12,-6],[12,36],[-12,36],[-12,-6],[-30,-6]]),1)],{tags:Mo});pt("wifi","tech","Wi-Fi","Wi-Fi",["wifi","mạng","internet","kết nối"],[Ot(wt(Ke(0,40,30,225,315),Ke(0,40,60,225,315),Ke(0,40,90,225,315)),1),R(kt(0,40,10),1)],{tags:Mo});pt("battery","tech","Pin","Battery",["pin","battery","năng lượng"],[R(ut(-6,0,150,70,10),5),R(ut(76,0,12,30,3),5),R(ut(-30,0,90,52,4),1)],{tags:Mo});pt("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(ut(0,52,52,12,4),ut(0,68,46,12,4)),5),Ot(wt(It(-80,-90,-96,-104),It(80,-90,96,-104),It(0,-118,0,-136),It(-92,-40,-112,-40),It(92,-40,112,-40)),3)],{tags:Mo});pt("robot","tech","Rô-bốt","Robot",["robot","ai","trí tuệ nhân tạo","bot"],[R(ut(0,10,130,100,20),4),R(wt(kt(-30,0,14),kt(30,0,14)),1),R(ut(0,38,50,10,4),5),Ot(It(0,-40,0,-62),5),R(kt(0,-68,9),3),R(wt(ut(-74,10,14,40,5),ut(74,10,14,40,5)),5)],{tags:Mo});pt("chip","tech","Vi mạch","Chip",["chip","vi mạch","processor","cpu"],[R(ut(0,0,110,110,10),5),R(ut(0,0,60,60,6),1),Ot(wt(...[-30,0,30].flatMap(t=>[It(t,-55,t,-80),It(t,55,t,80),It(-55,t,-80,t),It(55,t,80,t)])),5)],{tags:Mo});pt("play-button","tech","Nút phát","Play button",["play","phát","video","youtube"],[R(ut(0,0,170,120,30),3),R(zt([[-20,-30],[34,0],[-20,30]]),4)],{tags:Mo});pt("cursor","tech","Con trỏ chuột","Mouse cursor",["con trỏ","cursor","click","chuột"],[R(zt([[-30,-60],[40,10],[6,14],[26,56],[10,64],[-10,22],[-30,44]]),4)],{tags:Mo});pt("browser","tech","Cửa sổ trình duyệt","Browser window",["trình duyệt","browser","website","web"],[R(ut(0,0,220,150,10),4),R(ut(0,-62,220,26,10),5),R(wt(kt(-92,-62,5),kt(-76,-62,5),kt(-60,-62,5)),3),R(ut(-40,0,100,60,4),1),Ot(wt(It(30,-20,90,-20),It(30,0,90,0),It(30,20,70,20)),5)],{tags:Mo});eo("office","Văn phòng & kinh doanh","Office & business");const ro={role:["explain","stat","list"],style:["corporate","clean"]};pt("briefcase","office","Cặp tài liệu","Briefcase",["cặp","briefcase","công việc","work"],[R(ut(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(ut(0,4,180,8,2),5),R(ut(0,4,24,22,4),3)],{tags:ro});pt("document","office","Tài liệu","Document",["tài liệu","document","giấy tờ","file"],[R(zt([[-60,-80],[30,-80],[60,-50],[60,80],[-60,80]]),4),R(zt([[30,-80],[30,-50],[60,-50]]),1),Ot(wt(It(-38,-30,38,-30),It(-38,-6,38,-6),It(-38,18,38,18),It(-38,42,10,42)),5)],{tags:ro});pt("clipboard","office","Bảng kẹp hồ sơ","Clipboard",["clipboard","checklist","danh sách"],[R(ut(0,10,130,170,10),3),R(ut(0,14,110,140,4),4),R(ut(0,-72,56,24,6),5),Ot(wt(...[-30,0,30].flatMap(t=>[zt([[-40,t],[-32,t+8],[-18,t-8]],!1),It(-4,t,36,t)])),1)],{tags:ro});pt("calendar","office","Lịch","Calendar",["lịch","calendar","ngày","date","sự kiện"],[R(ut(0,10,170,150,12),4),R(ut(0,-48,170,34,12),3),R(wt(ut(-44,-70,10,26,4),ut(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])=>ut(t,e,22,20,3))),1)],{tags:ro});pt("bar-chart","office","Biểu đồ cột","Bar chart",["biểu đồ","chart","số liệu","growth","tăng trưởng"],[R(ut(-54,40,30,70,3),1),R(ut(-14,20,30,110,3),2),R(ut(26,-10,30,170,3),3),R(ut(66,-34,30,218,3),1),Ot(wt(It(-90,76,100,76),It(-90,76,-90,-110)),5)],{tags:ro});pt("pie-chart","office","Biểu đồ tròn","Pie chart",["biểu đồ tròn","pie chart","tỉ lệ","percent"],[R(kt(0,0,80),1),R(`M${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:ro});pt("line-chart","office","Biểu đồ đường","Line chart",["biểu đồ đường","line chart","xu hướng","trend"],[Ot(wt(It(-100,70,100,70),It(-100,70,-100,-80)),5),Ot(zt([[-84,40],[-40,10],[0,24],[40,-30],[84,-60]],!1),3),R(wt(...[[-84,40],[-40,10],[0,24],[40,-30],[84,-60]].map(([t,e])=>kt(t,e,8))),1)],{tags:ro});pt("pencil","office","Bút chì","Pencil",["bút chì","pencil","viết","write"],[R(zt([[-90,30],[60,-36],[80,-6],[-70,60]]),2),R(zt([[60,-36],[100,-30],[80,-6]]),4),R(zt([[-90,30],[-104,62],[-70,60]]),5)],{tags:ro});pt("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(ut(0,8,180,104,6),2)],{tags:ro});pt("envelope","office","Phong bì / email","Envelope",["thư","email","mail","phong bì"],[R(ut(0,0,180,120,8),4),Ot(zt([[-90,-60],[0,10],[90,-60]],!1),5)],{tags:ro});pt("clock","office","Đồng hồ","Clock",["đồng hồ","clock","thời gian","time"],[R(kt(0,0,86),4),R(kt(0,0,74),1),Ot(wt(It(0,0,0,-48),It(0,0,34,18)),5),R(kt(0,0,7),5)],{tags:ro});pt("magnifier","office","Kính lúp","Magnifier",["tìm kiếm","search","kính lúp","magnifier"],[R(Jo(34,34,86,86,22),5),R(kt(-14,-14,62),5),R(kt(-14,-14,46),4)],{tags:ro});pt("target","office","Mục tiêu","Target",["mục tiêu","target","goal","kpi"],[R(kt(0,0,86),3),R(kt(0,0,62),4),R(kt(0,0,38),3),R(kt(0,0,14),4)],{tags:ro});pt("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(ut(0,46,20,44,2),2),R(ut(0,80,90,22,4),5)],{tags:ro});pt("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(zt([[-30,-60],[-40,-90],[0,-76],[40,-90],[30,-60]]),1),R(ut(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)}`,It(0,-14,0,56)),4)],{tags:ro});pt("coin","office","Đồng xu","Coin",["xu","coin","tiền"],[R(kt(0,0,70),2),R(kt(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)}`,It(0,-36,0,40)),5)],{tags:ro});pt("banknote","office","Tờ tiền","Banknote",["tiền mặt","cash","banknote"],[R(ut(0,0,200,100,8),1),R(ut(0,0,170,74,6),4),R(kt(0,0,26),1),R(wt(kt(-66,0,8),kt(66,0,8)),1)],{tags:ro});pt("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(ut(-50,70,18,26,4),ut(40,70,18,26,4)),3),R(zt([[-34,-44],[-20,-74],[-6,-50]]),3),R(ut(86,10,22,30,8),3),R(kt(-40,-6,6),5),R(ut(10,-48,40,8,4),5)],{tags:ro});pt("handshake","office","Bắt tay hợp tác","Handshake",["hợp tác","handshake","deal","đối tác"],[R(wt(ut(-80,0,40,40,8),ut(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(It(20,0,30,14),It(6,10,18,26)),5)],{tags:ro});pt("presentation-board","office","Bảng trình chiếu","Presentation board",["thuyết trình","presentation","bảng","slide"],[R(ut(0,-20,200,130,6),4),R(ut(0,-90,210,14,4),5),Ot(wt(It(0,45,0,90),It(0,60,-40,96),It(0,60,40,96)),5),R(wt(ut(-50,-6,26,60,2),ut(-14,-26,26,100,2),ut(22,-16,26,80,2)),1)],{tags:ro});eo("home","Nhà & nội thất","Home & interior");const Fr={role:["explain","background"],style:["soft","clean"]};pt("sofa","home","Ghế sofa","Sofa",["sofa","ghế","phòng khách","living room"],[R(ut(0,-20,180,70,16),1),R(wt(ut(-96,10,30,70,12),ut(96,10,30,70,12)),1),R(ut(0,24,170,40,10),2),R(wt(ut(-80,62,10,20,3),ut(80,62,10,20,3)),5)],{tags:Fr});pt("chair","home","Ghế","Chair",["ghế","chair"],[R(ut(-30,-40,14,120,4),2),R(ut(0,20,80,14,4),2),R(wt(ut(-30,60,10,70,3),ut(30,60,10,70,3)),2)],{tags:Fr});pt("table","home","Bàn","Table",["bàn","table"],[R(ut(0,-20,200,18,4),2),R(wt(ut(-80,30,14,90,3),ut(80,30,14,90,3)),2)],{tags:Fr});pt("bed","home","Giường","Bed",["giường","bed","ngủ","phòng ngủ"],[R(ut(-90,-10,20,110,4),2),R(ut(10,20,200,40,6),4),R(ut(-50,0,50,24,10),4),R(ut(30,10,130,30,8),1),R(wt(ut(-86,56,10,22,3),ut(104,56,10,22,3)),2)],{tags:Fr});pt("lamp","home","Đèn bàn","Table lamp",["đèn","lamp"],[R(zt([[-40,-70],[40,-70],[60,-10],[-60,-10]]),2),R(ut(0,30,10,80,3),5),R(ut(0,72,70,12,5),5)],{tags:Fr});pt("plant-pot","home","Chậu cây","Potted plant",["chậu cây","plant","cây cảnh"],[R(zt([[-40,20],[40,20],[30,90],[-30,90]]),3),R(ut(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:Fr});pt("window","home","Cửa sổ","Window",["cửa sổ","window"],[R(ut(0,0,150,170,4),4),R(wt(ut(-36,-40,62,70,2),ut(36,-40,62,70,2),ut(-36,40,62,70,2),ut(36,40,62,70,2)),1),R(ut(0,92,170,12,3),5)],{tags:Fr});pt("door","home","Cửa ra vào","Door",["cửa","door","lối vào"],[R(ut(0,0,110,200,6),2),R(wt(ut(0,-50,80,70,4),ut(0,40,80,70,4)),2),R(kt(38,6,6),3)],{tags:Fr});pt("key","home","Chìa khoá","Key",["chìa khóa","key","bảo mật"],[R(kt(-50,0,40),2),R(kt(-50,0,16),4),R(wt(ut(30,0,120,18,4),ut(70,20,14,24,2),ut(46,20,14,18,2)),2)],{tags:Fr});pt("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(ut(0,30,120,90,12),2),R(wt(kt(0,20,10),ut(0,38,8,24,3)),5)],{tags:Fr});pt("mug","home","Cốc","Mug",["cốc","mug","ly"],[R(ut(0,0,100,120,10),1),Ot(`M${b(50,-30)} C${b(96,-30)} ${b(96,30)} ${b(50,30)}`,1),R(ut(0,-30,70,10,4),4)],{tags:Fr});pt("picture-frame","home","Khung tranh","Picture frame",["tranh","khung","picture","frame"],[R(ut(0,0,170,130,4),2),R(ut(0,0,140,100,2),4),R(zt([[-60,40],[-20,-10],[10,20],[30,0],[60,40]]),1),R(kt(36,-26,12),3)],{tags:Fr});eo("icons","Biểu tượng","Icons");const qe={role:["sticker","overlay","social"],style:["clean","playful"]};pt("heart","icons","Trái tim","Heart",["tim","heart","yêu","love","like"],[R(Hc(0,0,80),3)],{tags:qe});pt("star","icons","Ngôi sao","Star",["sao","star","đánh giá","rating"],[R(Re(0,6,5,92,40),2)],{tags:qe});pt("check","icons","Dấu tích","Check mark",["đúng","check","tick","xong","done"],[R(kt(0,0,80),1),Ot(zt([[-36,0],[-10,28],[40,-30]],!1),4)],{tags:qe});pt("cross","icons","Dấu X","Cross mark",["sai","cross","x","không"],[R(kt(0,0,80),3),Ot(wt(It(-30,-30,30,30),It(30,-30,-30,30)),4)],{tags:qe});pt("plus","icons","Dấu cộng","Plus",["cộng","plus","thêm","add"],[R(wt(ut(0,0,40,150,10),ut(0,0,150,40,10)),1)],{tags:qe});pt("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(kt(0,-30,26),4)],{tags:qe});pt("home-icon","icons","Biểu tượng nhà","Home icon",["nhà","home","trang chủ"],[R(wt(zt([[-80,-4],[0,-80],[80,-4],[60,-4],[60,70],[-60,70],[-60,-4]])),1),R(ut(0,40,30,60,4),4)],{tags:qe});pt("user-icon","icons","Biểu tượng người dùng","User icon",["người dùng","user","tài khoản","account","profile"],[R(kt(0,-36,36),1),R(`M${b(-70,80)} C${b(-70,10)} ${b(70,10)} ${b(70,80)} Z`,1)],{tags:qe,human:!1});pt("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(kt(0,56,14),2),R(kt(0,-86,8),2)],{tags:qe});pt("flag","icons","Lá cờ","Flag",["cờ","flag","đích","milestone"],[R(ut(-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:qe});pt("gift","icons","Hộp quà","Gift box",["quà","gift","khuyến mãi","present"],[R(ut(0,30,150,110,6),3),R(ut(0,-34,170,34,6),3),R(wt(ut(0,30,24,110,2),ut(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:qe});pt("cart","icons","Giỏ hàng","Shopping cart",["giỏ hàng","cart","mua sắm","shopping"],[Ot(zt([[-100,-70],[-70,-70],[-40,40],[70,40]],!1),5),R(zt([[-62,-46],[96,-46],[78,20],[-46,20]]),2),R(wt(kt(-30,66,14),kt(56,66,14)),5)],{tags:qe});pt("price-tag","icons","Nhãn giá","Price tag",["giá","sale","tag","giảm giá"],[R(zt([[-90,-40],[40,-40],[90,0],[40,40],[-90,40]]),3),R(kt(50,0,10),4)],{tags:qe});pt("bookmark","icons","Đánh dấu","Bookmark",["bookmark","lưu","save"],[R(zt([[-50,-90],[50,-90],[50,90],[0,50],[-50,90]]),1)],{tags:qe});pt("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:qe});pt("water-drop","icons","Giọt nước","Water drop",["giọt nước","water","drop","nước"],[R(Rn(0,0,90),1),Ot(Ke(-20,20,30,110,170),4)],{tags:qe});pt("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(ut(-16,-10,10,140,2),ut(74,-30,10,140,2)),5),R(zt([[-21,-80],[79,-100],[79,-74],[-21,-54]]),5)],{tags:qe});pt("speaker","icons","Loa","Speaker",["loa","âm thanh","speaker","sound","volume"],[R(zt([[-70,-30],[-30,-30],[20,-70],[20,70],[-30,30],[-70,30]]),5),Ot(wt(Ke(30,0,30,-50,50),Ke(30,0,56,-50,50)),3)],{tags:qe});pt("lightning-icon","icons","Tia chớp","Lightning icon",["nhanh","fast","flash","power"],[R(kt(0,0,80),2),R(zt([[10,-56],[-30,8],[-2,8],[-14,56],[30,-10],[2,-10]]),4)],{tags:qe});pt("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(zt([[-30,0],[-6,26],[36,-26]],!1),4)],{tags:qe});pt("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(kt(0,0,32),1),R(kt(0,0,14),5)],{tags:qe});eo("arrows","Mũi tên","Arrows");const Rr={role:["explain","overlay"],style:["clean","bold"]};pt("arrow-right","arrows","Mũi tên phải","Arrow right",["mũi tên","arrow","phải"],[R(zt([[-100,-20],[30,-20],[30,-56],[100,0],[30,56],[30,20],[-100,20]]),3)],{tags:Rr});pt("arrow-up","arrows","Mũi tên lên","Arrow up",["mũi tên","arrow","lên","tăng","up"],[R(zt([[-20,100],[-20,-30],[-56,-30],[0,-100],[56,-30],[20,-30],[20,100]]),1)],{tags:Rr});pt("arrow-down","arrows","Mũi tên xuống","Arrow down",["mũi tên","arrow","xuống","giảm","down"],[R(zt([[-20,-100],[-20,30],[-56,30],[0,100],[56,30],[20,30],[20,-100]]),3)],{tags:Rr});pt("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(zt([[46,-52],[84,-28],[56,6]],!1),5)],{tags:Rr});pt("arrow-double","arrows","Mũi tên hai chiều","Double arrow",["hai chiều","double arrow","trao đổi","exchange"],[R(zt([[-100,0],[-50,-44],[-50,-16],[50,-16],[50,-44],[100,0],[50,44],[50,16],[-50,16],[-50,44]]),1)],{tags:Rr});pt("arrow-circle","arrows","Mũi tên vòng","Circular arrow",["vòng lặp","refresh","cycle","lặp lại"],[Ot(Ke(0,0,70,-60,230),5),R(zt([[34,-74],[50,-40],[14,-38]]),5)],{tags:Rr});pt("arrow-zigzag","arrows","Mũi tên gấp khúc","Zigzag arrow",["zigzag","gấp khúc","tăng trưởng"],[Ot(zt([[-100,60],[-40,0],[0,30],[80,-50]],!1),3),R(zt([[50,-60],[96,-66],[90,-20]]),3)],{tags:Rr});pt("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(zt([[-72,20],[-40,70],[-8,20]]),5)],{tags:Rr});pt("chevrons","arrows","Mũi tên kép","Chevrons",["chevron","tiếp theo","next","fast forward"],[R(wt(zt([[-90,-60],[-50,-60],[0,0],[-50,60],[-90,60],[-40,0]]),zt([[0,-60],[40,-60],[90,0],[40,60],[0,60],[50,0]])),3)],{tags:Rr});pt("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(It(96,-40,70,-60),It(96,-40,74,-14)),5)],{tags:Rr});pt("arrow-block-left","arrows","Mũi tên trái","Arrow left",["mũi tên","arrow","trái","left"],[R(zt([[100,-20],[-30,-20],[-30,-56],[-100,0],[-30,56],[-30,20],[100,20]]),2)],{tags:Rr});pt("arrow-dotted","arrows","Đường chấm mũi tên","Dotted path arrow",["đường đi","path","hành trình","journey"],[R(wt(...Array.from({length:7},(t,e)=>{const o=e/7;return kt(-100+o*170,40-Math.sin(o*Math.PI)*70,6)})),5),R(zt([[70,10],[100,40],[60,52]]),5)],{tags:Rr});eo("frames","Khung","Frames");const Dr={role:["overlay","title","background"],style:["clean","editorial"]};pt("frame-rounded","frames","Khung bo góc","Rounded frame",["khung","frame","viền"],[hp(wt(ut(0,0,240,160,24),ut(0,0,212,132,14)),1)],{tags:Dr});pt("frame-circle","frames","Khung tròn","Circle frame",["khung tròn","circle frame","avatar"],[hp(wt(kt(0,0,100),kt(0,0,84)),3)],{tags:Dr});pt("banner-ribbon","frames","Băng rôn","Ribbon banner",["băng rôn","ribbon","banner","tiêu đề"],[R(wt(zt([[-130,-10],[-96,-10],[-96,40],[-130,40],[-112,15]]),zt([[130,-10],[96,-10],[96,40],[130,40],[112,15]])),5),R(ut(0,0,200,50,2),3)],{tags:Dr});pt("scroll","frames","Cuộn giấy","Scroll",["cuộn giấy","scroll","thông báo"],[R(ut(0,0,180,120,2),4),R(wt(ut(-96,0,22,140,11),ut(96,0,22,140,11)),2)],{tags:Dr});pt("polaroid","frames","Ảnh polaroid","Polaroid frame",["polaroid","ảnh","photo"],[R(ut(0,0,170,200,4),4),R(ut(0,-18,146,140,2),5)],{tags:Dr});pt("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(It(50,-40,50,40),4)],{tags:Dr});pt("brackets","frames","Ngoặc vuông","Brackets",["ngoặc","brackets","nhấn mạnh"],[Ot(wt(zt([[-60,-80],[-100,-80],[-100,80],[-60,80]],!1),zt([[60,-80],[100,-80],[100,80],[60,80]],!1)),5)],{tags:Dr});pt("filmstrip","frames","Cuộn phim","Film strip",["phim","film","cuộn phim","cinema"],[R(ut(0,0,240,120,4),5),R(wt(...[-80,0,80].map(t=>ut(t,0,64,70,3))),4),R(wt(...Array.from({length:10},(t,e)=>ut(-108+e*24,-50,10,10,2)),...Array.from({length:10},(t,e)=>ut(-108+e*24,50,10,10,2))),4)],{tags:Dr});pt("phone-frame","frames","Khung điện thoại","Phone frame",["khung điện thoại","phone mockup","mockup"],[hp(wt(ut(0,0,120,230,20),ut(0,0,104,200,8)),5),R(ut(0,-104,30,6,3),4)],{tags:Dr});pt("sticky-note","frames","Giấy ghi chú","Sticky note",["ghi chú","note","sticky","post-it"],[R(zt([[-80,-80],[80,-80],[80,40],[40,80],[-80,80]]),2),R(zt([[80,40],[40,40],[40,80]]),5),R(ut(0,-80,60,18,2),4)],{tags:Dr});pt("frame-wavy","frames","Khung lượn sóng","Wavy frame",["khung","wavy","dễ thương"],[R(Re(0,0,24,100,90,0),1),R(kt(0,0,80),4)],{tags:Dr});pt("frame-stamp","frames","Khung tem","Stamp frame",["tem","stamp","bưu thiếp"],[hp(wt(ut(0,0,170,210,0),...Array.from({length:7},(t,e)=>kt(-72+e*24,-105,8)),...Array.from({length:7},(t,e)=>kt(-72+e*24,105,8)),...Array.from({length:9},(t,e)=>kt(-85,-96+e*24,8)),...Array.from({length:9},(t,e)=>kt(85,-96+e*24,8))),4),R(ut(0,0,140,180,2),1)],{tags:Dr});eo("bubbles","Bong bóng thoại","Speech bubbles");const xn={role:["caption","quote","overlay"],style:["playful","clean"]};pt("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:xn});pt("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:xn});pt("bubble-thought","bubbles","Bóng suy nghĩ","Thought bubble",["suy nghĩ","thought","nghĩ"],[R(xo(0,-14,220,140,7),4),R(wt(kt(-70,80,14),kt(-96,104,8)),4)],{tags:xn});pt("bubble-shout","bubbles","Bóng hét","Shout bubble",["hét","shout","wow","bất ngờ","boom"],[R(Re(0,0,14,110,76,-90),2)],{tags:xn});pt("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(kt(-40,-10,10),kt(0,-10,10),kt(40,-10,10)),4)],{tags:xn});pt("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:xn});pt("caption-box","bubbles","Hộp chú thích","Caption box",["chú thích","caption","box"],[R(ut(0,0,240,70,6),4),R(ut(-112,0,16,70,3),3)],{tags:xn});pt("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:xn});pt("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 ga(Wc(0,0,100,64,o,r,2),!1)})),5)],{tags:xn});pt("bubble-heart","bubbles","Bóng thoại trái tim","Heart bubble",["yêu","love","trái tim","tim"],[R(Hc(0,-10,74),3),R(zt([[-10,50],[-40,96],[14,62]]),3)],{tags:xn});eo("badges","Huy hiệu & nhãn","Badges & labels");const Mn={role:["proof","cta","sticker"],style:["bold","playful"]};pt("badge-seal","badges","Con dấu răng cưa","Seal badge",["huy hiệu","seal","chất lượng","badge"],[R(Re(0,0,18,100,86,0),3),R(kt(0,0,70),4),R(kt(0,0,58),3)],{tags:Mn});pt("badge-ribbon","badges","Huy chương ruy băng","Ribbon badge",["huy chương","ribbon","giải thưởng","award"],[R(wt(zt([[-40,30],[-70,110],[-36,94],[-20,120],[0,40]]),zt([[40,30],[70,110],[36,94],[20,120],[0,40]])),3),R(kt(0,-10,70),2),R(kt(0,-10,52),4),R(Re(0,-10,5,34,15),2)],{tags:Mn});pt("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(Re(0,-4,5,40,17),2)],{tags:Mn});pt("badge-stamp","badges","Tem tròn","Round stamp",["tem","stamp","chứng nhận","approved"],[Ot(wt(kt(0,0,96),kt(0,0,80)),3),R(Re(0,0,5,36,15),3),Ot(wt(It(-60,40,60,40),It(-60,-40,60,-40)),3)],{tags:Mn});pt("badge-new","badges","Nhãn MỚI (nổ)","NEW burst",["mới","new","sale","nổ"],[R(Re(0,0,16,100,74,0),3),R(Re(0,0,16,80,60,11),2)],{tags:Mn});pt("badge-check","badges","Huy hiệu tích xanh","Verified badge",["xác minh","verified","tích xanh","uy tín"],[R(Re(0,0,12,90,78,0),1),Ot(zt([[-30,0],[-8,24],[34,-24]],!1),4)],{tags:Mn});pt("medal","badges","Huy chương","Medal",["huy chương","medal","vàng","winner"],[R(wt(zt([[-50,-100],[-20,-100],[10,-30],[-20,-30]]),zt([[50,-100],[20,-100],[-10,-30],[20,-30]])),1),R(kt(0,30,62),2),R(kt(0,30,46),2),R(Re(0,30,5,30,13),4)],{tags:Mn});pt("label-tag","badges","Nhãn dán","Label",["nhãn","label","tag"],[R(ut(0,0,220,70,35),2),R(kt(-84,0,10),4)],{tags:Mn});pt("badge-percent","badges","Nhãn phần trăm","Percent badge",["giảm giá","percent","%","sale","khuyến mãi"],[R(kt(0,0,90),3),Ot(It(-30,40,30,-40),4),R(wt(kt(-30,-26,14),kt(30,26,14)),4)],{tags:Mn});pt("badge-crown","badges","Huy hiệu vương miện","Crown badge",["vương miện","crown","vip","premium"],[R(kt(0,0,90),5),R(zt([[-56,30],[-60,-30],[-30,0],[0,-50],[30,0],[60,-30],[56,30]]),2)],{tags:Mn});eo("doodles","Hoạ tiết vẽ tay","Doodles & decor");const Oo={role:["overlay","sticker"],style:["playful","soft"]};pt("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:Oo});pt("swirl","doodles","Xoáy","Swirl",["xoáy","swirl","spiral"],[Ot(ga(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:Oo});pt("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:Oo});pt("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:Oo});pt("stars-cluster","doodles","Chùm sao","Star cluster",["sao","stars","lấp lánh"],[R(wt(Re(-40,-20,5,40,17),Re(40,30,5,26,11),Re(50,-50,5,16,7)),2)],{tags:Oo});pt("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(Je(o)),n=Math.sin(Je(o)),i=r%2?6:9,l=r%2?18:9;return zt([[t-i*a+l*n,e-i*n-l*a],[t+i*a+l*n,e+i*n-l*a],[t+i*a-l*n,e+i*n+l*a],[t-i*a-l*n,e-i*n+l*a]])})),3),R(wt(kt(-40,0,6),kt(30,-20,5),kt(-20,40,5)),1)],{tags:Oo});pt("dots-pattern","doodles","Chấm bi","Polka dots",["chấm bi","dots","hoạ tiết"],[R(wt(...Array.from({length:25},(t,e)=>kt(-80+e%5*40+Math.floor(e/5)%2*20,-80+Math.floor(e/5)*40,8))),1)],{tags:Oo});pt("zigzag-line","doodles","Đường răng cưa","Zigzag line",["răng cưa","zigzag"],[Ot(zt(Array.from({length:11},(t,e)=>[-100+e*20,e%2?-16:16]),!1),3)],{tags:Oo});pt("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:Oo});pt("crown","doodles","Vương miện","Crown",["vương miện","crown","king","queen"],[R(zt([[-80,50],[-90,-40],[-44,0],[0,-70],[44,0],[90,-40],[80,50]]),2),R(wt(kt(-90,-46,10),kt(0,-76,10),kt(90,-46,10)),2)],{tags:Oo});pt("emphasis-lines","doodles","Vạch nhấn","Emphasis lines",["nhấn mạnh","emphasis","pop","chú ý"],[Ot(wt(It(-60,-60,-90,-90),It(0,-70,0,-110),It(60,-60,90,-90)),3)],{tags:Oo});pt("motion-lines","doodles","Vệt chuyển động","Speed lines",["tốc độ","speed lines","motion","nhanh"],[Ot(wt(It(-100,-40,40,-40),It(-70,0,80,0),It(-100,40,40,40)),5)],{tags:Oo});pt("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:Oo});pt("flower-doodle","doodles","Hoa vẽ tay","Doodle flower",["hoa","flower","doodle"],[Ot(wt(..._y(0,0,6,40).map(([t,e])=>kt(t,e,20)),kt(0,0,16)),3)],{tags:Oo});pt("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(Je(o)),a=Math.sin(Je(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:Oo});pt("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`,kt(0,66,16)),3)],{tags:Oo});pt("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(kt(0,62,14),1)],{tags:Oo});eo("animals","Con vật","Animals");const ba={role:["sticker","explain"],style:["playful","soft"]};pt("cat","animals","Con mèo","Cat",["mèo","cat","thú cưng","pet"],[R(Se(0,40,70,56),1),R(kt(0,-40,48),1),R(wt(zt([[-44,-60],[-40,-104],[-12,-82]]),zt([[44,-60],[40,-104],[12,-82]])),1),R(wt(Se(-18,-44,6,9),Se(18,-44,6,9)),5),R(zt([[-6,-24],[6,-24],[0,-16]]),3),Ot(`M${b(66,60)} C${b(110,60)} ${b(110,0)} ${b(90,-10)}`,1)],{tags:ba});pt("dog","animals","Con chó","Dog",["chó","dog","thú cưng","pet","cún"],[R(Se(0,40,74,54),2),R(kt(0,-34,50),2),R(wt(Se(-50,-30,16,34),Se(50,-30,16,34)),5),R(wt(kt(-18,-42,7),kt(18,-42,7)),5),R(Se(0,-16,14,10),5),Ot(Ke(0,-8,10,20,160),5)],{tags:ba});pt("bird","animals","Chim","Bird",["chim","bird"],[R(Se(0,0,70,50),1),R(kt(46,-34,30),1),R(zt([[74,-36],[100,-28],[74,-22]]),2),R(kt(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:ba});pt("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(ut(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:ba});pt("chicken","animals","Con gà","Chicken",["gà","chicken","rooster"],[R(Se(0,20,70,60),4),R(kt(40,-40,32),4),R(wt(kt(36,-76,10),kt(50,-80,9),kt(24,-74,8)),3),R(zt([[68,-42],[90,-36],[68,-30]]),2),R(kt(46,-46,5),5),R(wt(ut(-16,90,6,30,2),ut(16,90,6,30,2)),2)],{tags:ba});pt("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(zt([[-60,0],[-110,-40],[-100,0],[-110,40]]),3),R(wt(ut(-10,0,14,96,6),ut(24,0,14,80,6)),4),R(kt(46,-10,7),5)],{tags:ba});pt("elephant","animals","Con voi","Elephant",["voi","elephant"],[R(Se(-10,20,80,56),5),R(kt(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(ut(-60,70,24,40,6),ut(30,70,24,40,6)),5),R(kt(62,-28,5),1)],{tags:ba});pt("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(It(-50,-24,-36,16),It(0,-44,0,16),It(40,-24,30,16)),5),R(kt(96,-6,4),5)],{tags:ba});eo("scenery","Cảnh nền","Scenery");const Wn={role:["background"],style:["soft","playful","clean"]};pt("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:Wn,outline:!1});pt("road","scenery","Con đường","Road",["đường","road","phố","street"],[R(ut(0,0,600,70,0),5),R(wt(...Array.from({length:8},(t,e)=>ut(-262+e*75,0,40,6,2))),4)],{tags:Wn,outline:!1});pt("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:Wn,outline:!1});pt("city-band","scenery","Dải thành phố","City band",["thành phố","city","skyline","background"],[R(zt([[-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:Wn,outline:!1});pt("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:Wn,outline:!1});pt("sky-clouds","scenery","Trời nhiều mây","Sky with clouds",["bầu trời","sky","mây","clouds"],[R(wt(xo(-180,-10,140,60,5),xo(30,-40,180,70,6),xo(210,10,120,50,4)),4)],{tags:Wn,outline:!1});pt("mountain-range","scenery","Dãy núi","Mountain range",["dãy núi","mountains","range"],[R(zt([[-300,70],[-220,-50],[-150,20],[-60,-90],[30,10],[110,-70],[200,0],[260,-40],[300,0],[300,70]]),2),R(wt(zt([[-60,-90],[-84,-54],[-70,-58],[-56,-48],[-40,-62]]),zt([[110,-70],[94,-44],[108,-48],[122,-40],[130,-50]])),4)],{tags:Wn,outline:!1});pt("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:Wn,outline:!1});pt("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])=>Re(t,e,4,o*2,o*.6,0))),2),R(kt(170,-60,26),4)],{tags:Wn,outline:!1});eo("emotes","Biểu cảm hoạt hình","Cartoon emotes");const vn={role:["overlay","sticker"],style:["playful","soft"]};pt("sweat-drops","emotes","Giọt mồ hôi","Sweat drops",["mồ hôi","sweat","lo lắng","nervous","ngại"],[R(wt(Rn(-20,-30,46),Rn(34,10,30)),4)],{tags:vn});pt("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:vn});pt("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:vn});pt("idea-bulb","emotes","Ý tưởng","Idea bulb",["ý tưởng","idea","bóng đèn","nghĩ ra","aha"],[R(wt(kt(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(It(-80,-20,-60,-20),It(60,-20,80,-20),It(0,-100,0,-80),It(-58,-78,-44,-64),It(58,-78,44,-64)),3)],{tags:vn});pt("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(Re(-60,-50,5,20,9),Re(64,-36,5,16,7),Re(0,46,5,14,6)),3)],{tags:vn});pt("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=Je(e*45),r=Math.cos(o),a=Math.sin(o);return It(r*44,a*44,r*(e%2?78:96),a*(e%2?78:96))})),3)],{tags:vn});pt("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:vn});pt("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=>It(t,50,t+30,-50))),3)],{tags:vn});pt("steam-puff","emotes","Xì khói (bực)","Steam puff",["xì khói","steam","bực","tức","huff"],[R(wt(kt(-44,10,26),kt(-14,-6,30),kt(22,4,24),kt(40,-30,18),kt(62,-54,12)),4)],{tags:vn});pt("music-notes-pop","emotes","Nốt nhạc (vui)","Happy notes",["vui","hát","notes","happy","nhạc"],[R(wt(kt(-40,40,16),kt(30,20,14)),1),Ot(wt(It(-26,40,-26,-50),It(44,20,44,-60),`M${b(-26,-50)} L${b(44,-60)}`),1)],{tags:vn});const mp=Gy.map(t=>({...t,parts:x8(t.parts)})),E8=new Map(mp.map(t=>[t.id,t])),S8=Object.freeze(Object.entries(Xc).map(([t,[e,o]])=>({id:t,vi:e,en:o,count:mp.filter(r=>r.cat===t).length}))),Ky=Object.freeze(mp.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"]}})}))),I8=Object.freeze(mp.map(t=>t.id)),A8=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 l=0;l+1<i.length;l+=2)e=Math.min(e,i[l]),r=Math.max(r,i[l]),o=Math.min(o,i[l+1]),a=Math.max(a,i[l+1])}return[ha(e),ha(o),ha(r),ha(a)]},x0=t=>String(t).toLowerCase().normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d");function Vy(t,{id:e="s1",pos:o=[500,500],scale:r=1,rot:a=0,colors:n=null,en:i=!1,stroke:l=null}={}){const u=E8.get(t);if(!u)throw Error(`Unknown 2D library shape "${String(t).slice(0,48)}" — search_shape_library lists the ids`);const c=Array.isArray(n)?Object.fromEntries(n.map((d,f)=>[f+1,d])):n||{};for(const d of Object.values(c))if(!/^#[0-9a-fA-F]{6}$/.test(d))throw Error("Library colours are #RRGGBB");const s=u.parts.map(d=>d.role!==7&&d.fill!==null&&c[d.role]?{...d,fill:c[d.role],role:7}:d);return{id:e,name:(i?u.en:u.vi).slice(0,40),type:"art",params:{parts:s,box:A8(s),...u.outline?{}:{outline:!1},lib:u.id},pos:[...o],rot:a,scale:[r,r],opacity:1,fill:{type:"color",color:s.find(d=>d.fill)?.fill??"#4a90d9"},stroke:l??{color:c[5]??nd[5],width:5,cap:"round",join:"round"}}}function C8({query:t="",cat:e=null,human:o=null,limit:r=24}={}){const a=x0(t).split(/[^a-z0-9]+/).filter(i=>i.length>1);return Ky.filter(i=>(!e||i.cat===e)&&(o==null||i.human===!!o)).map(i=>{const l=x0([i.id.replace(/-/g," "),i.vi,i.en,...i.words,Xc[i.cat][0],Xc[i.cat][1]].join(" ")),u=a.length?a.reduce((c,s)=>c+(` ${l} `.includes(` ${s} `)?3:l.includes(s)?1:0),0):1;return{e:i,score:u}}).filter(i=>i.score>0).sort((i,l)=>l.score-i.score).slice(0,Math.max(1,Math.min(100,r))).map(i=>i.e)}const bj=Object.freeze(Object.defineProperty({__proto__:null,LIB2D:Ky,LIB2D_CATEGORIES:S8,LIB2D_IDS:I8,LIB_PALETTE:nd,libraryArt:Vy,searchLibrary2d:C8},Symbol.toStringTag,{value:"Module"})),M0=(t,e,o,r,a)=>t==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a);function j8(t,e){if(!(t>0)||!(e>0))return 0;const o=t/e;return 1-Math.min(o,1/o)}const v0=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},T8=.4,wj=(t,e,o=T8)=>j8(v0(t),v0(e))>o;function O8(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),l=a*Math.sin(r)+n*Math.cos(r);return Math.abs(i)<=t.w/2&&Math.abs(l)<=t.h/2}function kj(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&&O8(n.rect,e,o))return n.id}return null}const xj=(t,e=.012)=>Math.abs(t)<e?0:t,Mj=(t,e)=>Math.abs(t)>=Math.abs(e)?{dx:t,dy:0}:{dx:0,dy:e},pi=[.37,0,.63,1],$0=[.33,0,.67,1],Dn=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}}),Uc=Object.freeze(Object.keys(Dn).filter(t=>Dn[t].move)),Wy=Object.freeze(Object.keys(Dn)),z8=60,Yc=t=>Math.round(t*1e4)/1e4,P8=t=>Math.round(t*30)/30,Hy=(t,e)=>Math.max(Pr[t].min,Math.min(Pr[t].max,e));function L8(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 N8(t,e,{amount:o=1,period:r,a=0,b:n=t.duration,phase:i=0}={}){const l=Dn[e];if(!l)throw Error(`animateLayer preset: ${Wy.join(" | ")}`);const u=l.amount*o,c=Math.max(.1,r??l.period),s={},d=x=>Zt(t,x,a),f=Math.max(a+1/30,n),m=(x,$,E,S)=>{const k=s[x]??=[];if(k.length>=z8||$>f+1e-6)return!1;const y=Yc(P8($));return k.length&&y-k.at(-1).time<1/45||k.push({time:y,value:Yc(Hy(x,E)),...S?{ease:S}:{}}),!0},g=a-i*c,v=(x,$,E=!1)=>{const S=d(x),k=y=>E?S*(1+$*y):S+$*y;m(x,a,S,pi);for(let y=0;;y++){const A=g+c/4+y*c/2;if(!(A<=a+1/30)&&(A>f-c/4||!m(x,A,k(y%2?-1:1),pi)))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=d("sy");m("sy",a,x,pi);for(let $=0;;$++){const E=g+c/2+$*c/2;if(!(E<=a+1/30)&&(E>f-c/4||!m("sy",E,x*(1+($%2?0:u)),pi)))break}m("sy",f,x);break}case"bob":{const x=d("y");m("y",a,x,pi);for(let $=0;;$++){const E=g+c/2+$*c/2;if(!(E<=a+1/30)&&(E>f-c/4||!m("y",E,x-($%2?0:u),pi)))break}m("y",f,x);break}case"drift":v("x",u);break;case"blink":{const x=d("sy");m("sy",a,x);for(let $=0;;$++){const E=g+c*($+.6);if(!(E<a+.1)&&(E+.16>f||!m("sy",E,x)||!m("sy",E+.07,x*(1-u))||!m("sy",E+.15,x)))break}m("sy",f,x);break}case"rise":{const x=d("y"),$=d("zoom");for(let E=0;;E++){const S=g+E*c;if(S+c<=a)continue;if(S>=f)break;const k=Math.max(a,S+(S>a?1/30:0)),y=(k-S)/c,A=Math.min(f,S+c);if(!m("y",k,x-u*y)||!m("opacity",k,Math.sin(Math.PI*y)**1.2,[.4,0,.6,1])||!m("zoom",k,$*(.7+.5*y)))break;S+c/2>k+1/30&&S+c/2<A&&m("opacity",S+c/2,1,[.4,0,.6,1]),m("y",A,x-u*(A-S)/c,"hold"),m("opacity",A,Math.sin(Math.PI*(A-S)/c)**1.2,"hold"),m("zoom",A,$*(.7+.5*(A-S)/c),"hold")}break}case"wiggle":{for(const[x,$]of[["x",11],["y",23]]){const E=d(x);m(x,a,E,"auto");for(let S=1;;S++){const k=a+S*c/2;if(k>=f-c/4||!m(x,k,E+u*(L8(S,$+(t.id?.length??0))*2-1),"auto"))break}m(x,f,E)}break}case"spin":{const x=d("rot");m("rot",a,x),m("rot",f,x+360*u*(f-a)/c);break}case"push-in":case"pull-out":{const x=d("zoom"),[$,E]=e==="push-in"?[x,x*(1+u)]:[x*(1+u),x];m("zoom",a,$,$0),m("zoom",f,E);break}case"pan-left":case"pan-right":{const x=d("x");m("x",a,x,$0),m("x",f,x+(e==="pan-left"?-u:u));break}}return s}const F8=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 Xy(t,e,o){const r=F8(t);if(!r)return null;const a=$w(t,t.start,t.start+t.duration,e,o),n=!a&&(ju(t,"rot")||!!Ew(t))&&t.rotFit!=="frame",[i,l]=r,u=Math.ceil(Math.hypot(i,l)/2)*2;return i*(n?M0("contain",e,o,u,u):M0("contain",e,o,i,l))*Bg(t,0,e,o).zoom}function su(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 Cl(t,e,o=1280,r=720){sr(t);const a=new Map;for(const n of e){const i=t.find(u=>u.id===n),l=i&&Xy(i,o,r);l&&a.set(n,l)}return a}const E0=(t,e)=>{let o=t;for(const[r,a]of e){const n=Ee(o,r);n.length&&(o={...o,...me(o,r,n.map(i=>({...i,value:Math.round(Hy(r,i.value*a)*1e6)/1e6})))})}return o},ui=t=>Math.round(t*1e6)/1e6;function xs(t,e,o=1280,r=720){let a=t.slice();const n=i=>{let l=0,u=a.find(c=>c.id===i);for(;u?.parentId&&l<9;)u=a.find(c=>c.id===u.parentId),l++;return l};for(const i of[...e.keys()].sort((l,u)=>n(l)-n(u))){sr(a);const l=a.findIndex(d=>d.id===i);if(l<0)continue;const u=Xy(a[l],o,r),c=u?e.get(i)/u:1;if(!(Math.abs(c-1)>1e-6))continue;const s=a[l];a[l]=E0({...s,scale:ui((s.scale??1)*c),...s.anchorX!==void 0?{anchorX:ui(s.anchorX/c)}:{},...s.anchorY!==void 0?{anchorY:ui(s.anchorY/c)}:{}},[["zoom",c],["ax",1/c],["ay",1/c]]),a=a.map(d=>d.parentId!==i?d:E0({...d,posX:ui((d.posX??0)/c),posY:ui((d.posY??0)/c),scale:ui((d.scale??1)/c)},[["x",1/c],["y",1/c],["zoom",1/c]]))}return sr(a),a}function jl(t,e,o={}){if(t.kind==="audio")throw Error("animateLayer needs a visual layer");const r=N8(t,e,o);let a={...t};for(const[n,i]of Object.entries(r))i.length>=2&&(a={...a,...me(a,n,i)});return a}function R8(t,e,o,r=1280,a=720,n=null){let i,l;if(Array.isArray(o))[i,l]=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+(E-x)*k[0],l=$+(S-$)*k[1]}if(![i,l].every(x=>Number.isFinite(x)&&x>=-1&&x<=2))throw Error("anchor: x, y are 0..1 of the frame");const u=Bg(t,e,r,a),c=.5+u.x,s=.5+u.y,d=-u.rot*Math.PI/180,f=(i-c)*r,m=(l-s)*a,g=(f*Math.cos(d)-m*Math.sin(d))/(u.sx||1),v=(f*Math.sin(d)+m*Math.cos(d))/(u.sy||1);return[Yc(g/(r*u.zoom)),Yc(v/(a*u.zoom))]}function Ca(t,e,{parentClipId:o,anchor:r,at:a=0,W:n=1280,H:i=720,box:l=null}){let u={...e};if(o!==void 0){if(o!==null){const c=t.find(s=>s.id===o);if(!c||c.kind==="audio")throw Error("rigLayer parentClipId: a visual layer of this timeline");if(xw(t,e.id,c.id))throw Error("rigLayer: that parent would make a loop")}u={...u,...Mw(t,u,o,a,n,i)},u.parentId||delete u.parentId,sr(t.map(c=>c.id===e.id?u:c))}if(r!=null){const[c,s]=R8(u,a,r,n,i,l);u={...u,...vw(u,a,c,s,n,i)}}return u}const qc=t=>t*Math.PI/180,Tt=(t,e)=>[t[0]+e[0],t[1]+e[1]],Xs=(t,e)=>[t[0]-e[0],t[1]-e[1]],So=(t,e)=>[t[0]*e,t[1]*e],ad=t=>Math.hypot(t[0],t[1]),id=t=>{const e=ad(t)||1;return[t[0]/e,t[1]/e]},Uy=t=>[-t[1],t[0]],es=(t,e,o)=>t+(e-t)*o,Eh=(t,e,o)=>[es(t[0],e[0],o),es(t[1],e[1],o)],Pi=(t,e,o)=>Math.max(e,Math.min(o,t)),Mi=t=>t<.5?2*t*t:1-2*(1-t)**2,Ms=t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,D8=300,S0={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"},Ra=Object.freeze({host:{vi:"MC nữ",en:"Female host",hair:"bob",outfit:"blazer",palette:S0},hostman:{vi:"MC nam",en:"Male host",hair:"short",outfit:"shirt",palette:{...S0,top:"#f6eee8",topS:"#d9cbc2",inner:"#f6eee8",accent:"#c8202f",bottom:"#2a3550",bottomS:"#1e2740",hair:"#1c1412"}}}),B8=Object.freeze(Object.keys(Ra)),_8=Object.freeze(["skin","hair","top","inner","bottom","shoe","accent","lip","prop","propLabel"]),I0=Object.freeze(["neutral","smile","grin","surprised","wink","think","sad"]),A0=Object.freeze(["box","bottle","phone","card"]),G8={sway:0,lean:0,tilt:0,turn:0,bounce:0,hR:[42,-128],hL:[-42,-128],shR:"open",shL:"open"},Oe=t=>({...G8,...t}),Yy=Object.freeze({idle:{vi:"Đứng thở",en:"Idle",dur:2,face:"smile",cyc:t=>Oe({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 Oe({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,Oe({hR:[70,-292],shR:"wave",tilt:-3,lean:-2})],[1,Oe({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,Oe({hR:[128,-232],shR:"point",lean:3,turn:.45,tilt:2})],[1,Oe({hR:[126,-230],shR:"point",lean:3,turn:.45,tilt:2})]],ease:[Ms,Mi]},"point-up":{vi:"Chỉ lên",en:"Point up",dur:1.4,face:"smile",keys:[[0,null],[.3,Oe({hR:[66,-318],shR:"point",turn:.2,tilt:-4})],[1,Oe({hR:[66,-316],shR:"point",turn:.2,tilt:-4})]],ease:[Ms,Mi]},present:{vi:"Mời xem",en:"Present",dur:1.6,face:"grin",keys:[[0,null],[.35,Oe({hR:[124,-178],shR:"open",hL:[-36,-150],lean:2,turn:.4,tilt:3})],[1,Oe({hR:[120,-182],shR:"open",hL:[-36,-150],lean:2,turn:.4,tilt:3})]],ease:[Ms,Mi]},thumbs:{vi:"Giơ ngón cái",en:"Thumbs up",dur:1.3,face:"grin",keys:[[0,null],[.3,Oe({hR:[52,-212],shR:"thumb",tilt:-3,bounce:-3})],[1,Oe({hR:[50,-210],shR:"thumb",tilt:-3})]],ease:[Ms,Mi]},clap:{vi:"Vỗ tay",en:"Clap",dur:1.6,face:"grin",cyc:t=>{const e=Math.abs(Math.sin(t*7));return Oe({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,Oe({hR:[24,-170],hL:[-24,-166],shR:"hold",shL:"hold",lean:-2,tilt:3,elDown:1})],[1,Oe({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,Oe({hR:[70,-276],shR:"hold",hL:[-38,-150],turn:.3,tilt:-2})],[1,Oe({hR:[70,-280],shR:"hold",hL:[-38,-150],turn:.3,tilt:-2})]],ease:[Ms,Mi],prop:!0,one:!0},think:{vi:"Suy nghĩ",en:"Think",dur:1.8,face:"think",keys:[[0,null],[.35,Oe({hR:[14,-240],shR:"fist",hL:[-6,-188],shL:"fist",tilt:7,turn:-.2,elDown:1})],[1,Oe({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,Oe({hR:[78,-170],hL:[-78,-170],shR:"open",shL:"open",bounce:-5,tilt:6})],[.75,Oe({hR:[78,-170],hL:[-78,-170],shR:"open",shL:"open",bounce:-5,tilt:6})],[1,Oe({})]]},nod:{vi:"Gật đầu",en:"Nod",dur:1,face:"smile",cyc:t=>Oe({tilt:0,bounce:Math.max(0,Math.sin(t*9))*-3,nod:Math.max(0,Math.sin(t*9))})}}),C0=Object.freeze(Object.keys(Yy)),K8={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 V8(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":K8[n]??"C"}}function yr(t,e,o,r){const a=id(Xs(e,t)),n=Uy(a),i=ad(Xs(e,t)),l=[];for(let u=0;u<=3;u++){const c=u/3*.94;l.push(Tt(Tt(t,So(a,i*c)),So(n,es(o,r,c)/2)))}l.push(Tt(e,So(a,r/2)));for(let u=3;u>=0;u--){const c=u/3*.94;l.push(Tt(Tt(t,So(a,i*c)),So(n,-es(o,r,c)/2)))}return l.push(Tt(t,So(a,-o/2))),l}const Pe=(t,e,o,r=0,a=10)=>Array.from({length:a},(n,i)=>{const l=i/a*2*Math.PI,u=Math.cos(l)*e,c=Math.sin(l)*o,s=qc(r);return[t[0]+u*Math.cos(s)-c*Math.sin(s),t[1]+u*Math.sin(s)+c*Math.cos(s)]}),Tl=(t,e,o,r,a,n=6)=>Array.from({length:n+1},(i,l)=>{const u=qc(es(r,a,l/n));return[t[0]+Math.cos(u)*e,t[1]+Math.sin(u)*o]});function j0(t,e,o,r,a){const n=Xs(e,t),i=Pi(ad(n),Math.abs(o-r)+1,o+r-.5),l=Math.atan2(n[1],n[0]),u=Math.acos(Pi((o*o+i*i-r*r)/(2*o*i),-1,1)),c=Tt(t,So([Math.cos(l+a*u),Math.sin(l+a*u)],o));return{joint:c,end:Tt(c,So(id(Xs(e,c)),r))}}function W8(t,e,o,r,a,n,i){const l=[],u=(D,U,ht={})=>l.push({points:D.map(n),fill:U,...ht}),c=(D,U=.6)=>l.push({points:D.map(n),fill:null,closed:!1,lw:U}),s=o.bounce,d=[o.sway,-140+s],f=[Math.sin(qc(o.lean)),-Math.cos(qc(o.lean))],m=[-f[1],f[0]],g=(D,U)=>Tt(Tt(d,So(f,D)),So(m,U));g(78,0);const v=g(98,0),x=Tt(g(132,0),[o.turn*3,(o.nod??0)*4]),$=g(90,30),E=g(90,-30);u(Pe([o.sway*.5,2],44,6),e.shadow,{line:!1});const S=g(-2,13),k=g(-2,-13),y=[17,-4],A=[-17,-4];t.outfit==="blazer"?(u(yr(S,y,20,13),e.skin),u(yr(k,A,20,13),e.skinB)):(u(yr(S,y,24,18),e.bottom,{lw:1.1}),u(yr(k,A,24,18),e.bottomS,{lw:1.1})),u(Pe([y[0]+4,-2],13,6),e.shoe),u(Pe([A[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}),c([g(96,-11),g(54,0),g(10,-2)],.7),c([g(96,11),g(54,0)],.7),u(Pe(g(40,-4),2.2,2.2),e.topS,{line:!1}),u(Pe(g(26,-4),2.2,2.2),e.topS,{line:!1})):(c([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(yr(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 I=o.tilt;u(Pe(Tt(x,[-26,4]),6,8),e.skin,{lw:.8}),u(Pe(Tt(x,[26,4]),6,8),e.skin,{lw:.8}),u(Pe(x,26,30,I,12),e.skin,{lw:1.2});const z=o.turn*7,j=(D,U)=>Tt(x,[D+z,U]),P=r.blink,N=(D,U,ht)=>{if(U||ht==="happy"){c(ht==="happy"?Tl(j(D,-1),4.5,3.5,200,340):Tl(j(D,-2),4.5,2.5,20,160),.7);return}const yt=ht==="wide",Mt=yt?4:3.4,p=yt?5.6:4.4;u(Pe(j(D,-2),Mt,p),e.eye,{line:!1}),u(Pe(j(D+1.2,-3.6),1.2,1.2,0,6),"#ffffff",{line:!1})},F=r.expr,K=F==="grin"?"happy":F==="surprised"?"wide":null;N(10,P,K),N(-10,P||F==="wink",K);const _=F==="surprised"?-17:F==="sad"?-12:-14;c(F==="think"?[j(5,-15),j(10,-18),j(15,-16)]:[j(5,_+1),j(10,_-(F==="sad"?-1:1)),j(15,_+(F==="sad"?-2:1))],.65),c(F==="think"?[j(-15,-14),j(-10,-14),j(-5,-14)]:[j(-15,_+(F==="sad"?-2:1)),j(-10,_-(F==="sad"?-1:1)),j(-5,_+1)],.65),c([j(1,4),j(2,9),j(-1,10)],.5),u(Pe(j(15,9),4.5,2.6,0,8),e.blush,{line:!1}),u(Pe(j(-15,9),4.5,2.6,0,8),e.blush,{line:!1});const J=j(0,17),X=r.mouth;X==="A"?(u(Pe(J,6,5.5),e.mouth,{lw:.6}),u(Pe(Tt(J,[0,2.6]),3.6,2),e.tongue,{line:!1})):X==="E"?(u(Pe(J,7,2.8),e.mouth,{lw:.6}),u([Tt(J,[-5,-1.6]),Tt(J,[5,-1.6]),Tt(J,[4,-.4]),Tt(J,[-4,-.4])],e.teeth,{line:!1})):X==="O"?u(Pe(J,4,4.8),e.mouth,{lw:.6}):X==="C"?u(Pe(J,5,2.2),e.mouth,{lw:.55}):X==="X"?c([Tt(J,[-5,0]),Tt(J,[0,.8]),Tt(J,[5,0])],.6):F==="grin"||F==="surprised"?F==="surprised"?u(Pe(J,4.2,5),e.mouth,{lw:.6}):(u([Tt(J,[-8,-2]),Tt(J,[8,-2]),Tt(J,[5,4]),Tt(J,[0,6]),Tt(J,[-5,4])],e.mouth,{lw:.6}),u([Tt(J,[-7,-1.6]),Tt(J,[7,-1.6]),Tt(J,[6,.4]),Tt(J,[-6,.4])],e.teeth,{line:!1})):F==="sad"?c(Tl(Tt(J,[0,3]),6,3,200,340),.65):F==="think"?c([Tt(J,[-4,0]),Tt(J,[4,-1])],.6):c(Tl(Tt(J,[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 rt=(D,U,ht,yt,Mt,p)=>{const lt=j0(D,U,52,48,1),V=j0(D,U,52,48,-1),h=C=>C.joint[0]*ht+C.joint[1]*(o.elDown?4:.9),w=h(lt)>=h(V)?lt:V,T=Mt?e.topS:e.top;u(yr(D,w.joint,19,16),T,{lw:1.15}),u(yr(w.joint,w.end,16,13),T,{lw:1.15}),u(yr(Eh(w.joint,w.end,.82),w.end,13,12),t.outfit==="blazer"?e.inner:e.top,{lw:.8}),ot(w.end,id(Xs(w.end,w.joint)),yt,p)},ot=(D,U,ht,yt)=>{const Mt=Uy(U),p=e.skin;if(ht==="point"){u(yr(D,Tt(D,So(U,18)),6,5),p,{lw:.9}),u(Pe(D,8,7),p,{lw:.9});return}if(ht==="thumb"){u(Pe(D,8.5,8),p,{lw:.9}),u(yr(Tt(D,[0,-4]),Tt(D,[0,-19]),6,5),p,{lw:.9});return}if(ht==="fist"){u(Pe(D,8.5,8),p,{lw:.9});return}if(ht==="wave"){const lt=[0,-1];u(Pe(Tt(D,[0,-3]),9,10),p,{lw:.9});for(const V of[-6,-2,2,6])u(yr(Tt(D,[V,-9]),Tt(D,[V*1.3,-21]),4.2,3.6),p,{lw:.8});u(yr(Tt(D,[yt?7:-7,0]),Tt(D,Tt(So(lt,8),[yt?15:-15,-2])),4.6,4),p,{lw:.8});return}u(Pe(Tt(D,So(U,3)),9,10,Math.atan2(U[1],U[0])*180/Math.PI),p,{lw:.9});for(const lt of[-5,-1.6,1.8,5.2])u(yr(Tt(Tt(D,So(U,9)),So(Mt,lt)),Tt(Tt(D,So(U,ht==="hold"?13:19)),So(Mt,lt*1.15)),4,3.4),p,{lw:.8})},G=o.shR==="hold",tt=D=>{const U=i.kind;U==="bottle"?(u([[-13,28],[13,28],[14,-14],[7,-27],[6,-40],[-6,-40],[-7,-27],[-14,-14]].map(ht=>Tt(D,ht)),e.prop,{lw:1}),u([[-6,-50],[6,-50],[6,-40],[-6,-40]].map(ht=>Tt(D,ht)),e.propLabel,{lw:.9}),u([[-14,-4],[14,-4],[14,14],[-14,14]].map(ht=>Tt(D,ht)),e.propLabel,{line:!1}),u([[-9,-12],[-6,-12],[-6,22],[-9,22]].map(ht=>Tt(D,ht)),"#ffffff",{line:!1})):U==="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})):U==="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}))},Q=Tt(o.hR,[o.sway,s]),it=Tt(o.hL,[o.sway,s]);return G&&i&&o.shL==="hold"&&tt(Tt(Eh(Q,it,.5),[0,-6])),rt(E,it,-1,o.shL,!0,!0),rt($,Q,1,o.shR,!1,!1),G&&i&&o.shL!=="hold"&&tt(Tt(Q,[0,-30])),l}const T0=(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)?Eh(n,i,o):typeof i=="number"?es(n,i,o):o<.5?n:i}return r},O0=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 z0({character:t="host",colors:e=null,x:o=.5,ground:r=.95,size:a=.8,fps:n=24,actions:i=[],speech:l=null,W:u=1280,H:c=720}){const s=Ra[t];if(!s)throw Error(`animatePuppet presenter character: ${B8.join(" | ")}`);const d={...s.palette,...e||{}},f=a*c/D8,m=(Array.isArray(i)?i:[]).slice(0,40);if(!m.length)throw Error(`animatePuppet actions: [{move: ${C0.join(" | ")}, duration?, face?, side?, prop?}]`);let g=0;const v=m.map((k,y)=>{const A=Yy[k?.move];if(!A)throw Error(`animatePuppet actions[${y}].move (presenter): ${C0.join(" | ")}`);if(k.face!=null&&!I0.includes(k.face))throw Error(`animatePuppet actions[${y}].face: ${I0.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&&!A0.includes(k.prop))throw Error(`animatePuppet actions[${y}].prop: ${A0.join(" | ")}`);const I=Number.isFinite(k.duration)?Pi(k.duration,.3,20):A.dur,z={g:A,a:k,t0:g,dur:I,face:k.face??A.face,mirror:k.side==="left",prop:A.prop?{kind:k.prop??"box"}:null};return g+=I,z});v.forEach((k,y)=>{k.from=y?v[y-1].at(1,v[y-1].dur):Oe({}),k.at=(A,I)=>{let z;if(k.g.cyc)z=T0(k.from,k.mirror?O0(k.g.cyc(I)):k.g.cyc(I),Pi(I/.35,0,1));else{const j=k.g.keys.map(([X,rt])=>[X,rt?k.mirror?O0(rt):rt:k.from]);let P=0;for(;P<j.length-2&&A>j[P+1][0];)P++;const[N,F]=j[P],[K,_]=j[P+1],J=(k.g.ease?.[P]??Mi)(Pi((A-N)/(K-N),0,1));if(z=T0(F,_,J),k.g.wave&&A>.22){const X=Math.sin(I*13)*14;z=k.mirror?{...z,hL:[z.hL[0]-X,z.hL[1]]}:{...z,hR:[z.hR[0]+X,z.hR[1]]}}}return{...z,bounce:(z.bounce||0)+Math.sin(I*3)*.8}}});const x=V8(l),$=g,E=Math.min(Math.round($*n),480),S=[];for(let k=0;k<E;k++){const y=k/n,A=v.find(J=>y<J.t0+J.dur-1e-9)??v.at(-1),I=y-A.t0,z=Pi(I/A.dur,0,1),j=A.at(z,I),P=(y+.7)%3.4,N=P<2/n&&A.face!=="wink"&&A.face!=="grin",F={expr:A.face,mouth:x(y),blink:N},K=[o*u,r*c],_=([J,X])=>[Math.round((K[0]+J*f)/u*1e4)/1e4,Math.round((K[1]+X*f)/c*1e4)/1e4];S.push({parts:W8(s,d,j,F,y,_,A.prop)})}return{frames:S,duration:E/n}}const gp=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 H8(t,e,o,r=gp){const a=[...t].filter(c=>c.time>e+1e-6&&c.time<o-1e-6).sort((c,s)=>c.time-s.time),n=[],i=(c,s,d,f)=>{s-c>1e-6&&n.push({from:c,to:s,kind:d,...f?{beat:f}:{}})},l=c=>{n.length&&(n[n.length-1].to=Math.max(n[n.length-1].to,c))};let u=e;for(let c=0;c<a.length;c++){const s=a[c],d=a[c+1],f=Math.max(u,s.time-r.cutBefore),m=d?d.time-r.cutBefore:o,g=s.result==="head"||s.result==="body";if(f-u>=r.minShot||!n.length?i(u,f,"wide"):l(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"):l(o));for(let c=n.length-1;c>0;c--)n[c].to-n[c].from<r.minShot-1e-6&&(n[c-1].to=n[c].to,n.splice(c,1));return n}function vj(t,e=[]){const o=t.map(i=>i.to-i.from).sort((i,l)=>i-l),r=t.length?t[t.length-1].to-t[0].from:0,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 Fa=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]},Da=(t,e,o=1)=>[t[0]+e[0]*o,t[1]+e[1]*o,t[2]+e[2]*o],Zc=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],P0=t=>Math.min(t.atk?.[1]??0,t.def?.[1]??0),L0=t=>Math.atan(18/t);function $j(t,e,o=gp){const r=Fa([e.side[0],0,e.side[2]]),a=Fa([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(L0(f)),g=Fa(Da(r,a,o.insertAxis??.9)),v=[e.contact[0],e.contact[1],e.contact[2]],x=Da(v,g,m);return x[1]=Math.max(P0(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 E=Fa([e.defFace[0],0,e.defFace[2]]),S=E[0]*r[0]+E[2]*r[2],k=[E[0]-r[0]*S,0,E[2]-r[2]*S];Math.hypot(k[0],k[2])>.2&&(g=Fa(k)),g=[g[0]*(1+2.5*Math.max(0,-S)),0,g[2]*(1+2.5*Math.max(0,-S))]}const v=Fa(Da(r.map(E=>E*o.reactionSide),g,o.reactionBack)),x=Math.hypot(o.reactionSide,o.reactionBack),$=Da(m,v,x);return $[1]=e.defHead[1]+.15,{position:$,target:m,lens:f}}const i=o.lens.finisher,l=P0(e),u=[(e.atk[0]+e.def[0])/2,l,(e.atk[2]+e.def[2])/2],c=Math.max(2.2,(e.sep+2)/2/Math.tan(L0(i))),s=[u[0],l+.8,u[2]],d=Da(s,r,c);return d[1]=l+.45,{position:d,target:s,lens:i}}function Ej(t,e,o=gp.clearance,r=1.5){const a=Fa(Zc(t.position,t.target)),n=Math.hypot(...Zc(t.position,t.target));let i=0;for(let c=0;c<6;c++){const s=Da(t.target,a,n+i);let d=1/0;for(const f of e)d=Math.min(d,Math.hypot(f[0]-s[0],f[1]-s[1],f[2]-s[2]));if(d>=o-1e-6||i>=r)return{...t,position:s,backed:+i.toFixed(3),near:+d.toFixed(3)};i=Math.min(r,i+(o-d)+.05)}const l=Da(t.target,a,n+i);let u=1/0;for(const c of e)u=Math.min(u,Math.hypot(c[0]-l[0],c[1]-l[1],c[2]-l[2]));return{...t,position:l,backed:+i.toFixed(3),near:+u.toFixed(3)}}const Sj=Object.freeze([.4,0,.9,-.4,-.8]);function Ij(t,e,o,{radius:r=.13,margin:a=.05,skip:n=.06}={}){const i=Zc(e,t),l=Math.hypot(...i),u=[i[0]/l,i[1]/l,i[2]/l];let c=0;for(const s of o){if(Math.hypot(s[0]-e[0],s[1]-e[1],s[2]-e[2])<n)continue;const d=Zc(s,t),f=d[0]*u[0]+d[1]*u[1]+d[2]*u[2];if(f<.1||f>l-a)continue;Math.hypot(d[0]-u[0]*f,d[1]-u[1]*f,d[2]-u[2]*f)<r&&c++}return c}const Sn=(t,e,o)=>Math.max(e,Math.min(o,t)),X8=300,lu=Object.freeze(["jab","cross","combo","front-kick","roundhouse","flying-kick","thrust","smash","staff-spin","sweep","spin-kick","uppercut","slash","beam","energy-slash","whip","bolt"]),cu=Object.freeze(["block","dodge","hit","knockdown","launched","roll","parry","ko","hurt"]),Ol=Object.freeze(["backflip","frontflip","cartwheel","roll","taunt","guard","teleport","approach","dash"]),Jc=Object.freeze({fighters:4,beats:24}),zl={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},U8={hurt:.014,ko:.02,hit:.011,knockdown:.018,launched:.02,block:.005,clash:.008,dodge:0,roll:0},Y8={hurt:.08,ko:.12,hit:.07,knockdown:.1,launched:.12,block:.04,clash:.09,dodge:0,roll:0},q8={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]},N0=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"]}),Z8=new Set(["slash","smash","thrust","parry"]);function J8(t,e){const o=e.length;if(!Array.isArray(t)||!t.length||t.length>Jc.beats)throw Error(`animatePuppet beats: [{by 0–${o-1}, target?, attack ${lu.join("|")} | move ${Ol.join("|")}, react? ${cu.join("|")}, pause?}] (1–${Jc.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 l=r.target??(i===0?1:0);if(!(Number.isInteger(l)&&l>=0&&l<o&&l!==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(!Ol.includes(r.move))throw Error(`${n}.move: ${Ol.join(" | ")}`);return{by:i,target:l,move:r.move,pause:u,...r.stop!=null?{stop:r.stop}:{}}}if(!lu.includes(r.attack))throw Error(`${n}.attack: ${lu.join(" | ")} (or move: ${Ol.join(" | ")})`);if(Cr[r.attack]?.prop==="staff"&&!zu(e[i].character??"fighter"))throw Error(`${n}: ${r.attack} needs a fighter with a weapon (${Object.keys(ia).filter(zu).join(", ")})`);const c=r.react??"block";if(!cu.includes(c))throw Error(`${n}.react: ${cu.join(" | ")}`);return{by:i,target:l,attack:r.attack,react:c,pause:u}})}function Q8({cast:t,beats:e,fps:o=12,fx:r=!0,accent:a="#ffd23f",W:n=1280,H:i=720,stick:l=!1,dust:u="#c9bfb2",tempo:c=null,camera:s=null,mocap:d=null,energyColor:f="#ff4fd8",toon:m=null,law:g=!0,maxFrames:v=480}){if(!Array.isArray(t)||t.length<2||t.length>Jc.fighters)throw Error(`animatePuppet cast: 2–${Jc.fighters} fighters for beats [{character, x?, facing?, …}, {…}]`);const x=t.length,$=t.map((Z,nt)=>Z.x??(nt?.64+(nt-1)*.12:.36)),E=Z=>$[Z===0?1:0]>=$[Z]?"right":"left",S=t.map((Z,nt)=>({character:Z.character??(nt?"brawler":"fighter"),x:$[nt],ground:Z.ground??.9,size:(Z.size??.5)*(Z.height??1),facing:Z.facing??E(nt),colors:Z.colors??null,grip:Z.grip??"guard",hair:Z.hair??null,eyes:Z.eyes??null,weight:Z.weight??null}));for(const Z of S)if(!ia[Z.character])throw Error(`animatePuppet cast character: ${Object.keys(ia).join(" | ")}`);const k=J8(e,S),y=S.map(Z=>Z.size*i/X8),A=Z=>Z.facing==="left"?-1:1,I=S.map(()=>[]),z=S.map(Z=>Z.x*n),j=S.map(()=>!1),P=S.map(()=>!1),N=[],F=[],K=[],_=Z=>l||ia[S[Z].character].look==="stick",J={},X=(Z,nt)=>{const dt=d?N0[Z]:null;if(dt&&!(Z8.has(Z)&&S[nt].character&&ia[S[nt].character].prop!=="sword")){const xt=dt.filter(St=>d[St]);if(xt.length){const St=J[Z]=(J[Z]??-1)+1,jt=xt[St%xt.length];return{...sf(jt,d),name:Z}}}const vt={ko:"knockdown",hurt:"hit",whip:"energy-slash",bolt:"beam"},At=Cr[Z]??Cr[vt[Z]];return At?{...At,name:Cr[Z]?Z:vt[Z]}:null},rt=(Z,nt={})=>Z.mocap?{mocap:Z.mocap,...nt}:{move:Z.name,...nt},ot=S.some((Z,nt)=>_(nt)),G=c??(ot?1.35:1),tt=Z=>Z.dur/G,Q=(Z,nt,dt)=>A(S[Z])*(dt??nt?.dx??0)*y[Z],it=(Z,nt,dt,vt)=>{I[Z].push({...rt(nt,dt),at:Math.round(vt*1e4)/1e4}),z[Z]+=Q(Z,nt,dt.dx)};let D=.3;const U=S.map(()=>.3);for(const Z of k){const nt=Z.by,dt=Z.target;if(P[nt])throw Error(`animatePuppet beats: fighter ${nt} was knocked out (ko) — it cannot act again`);for(const mt of[nt,dt])if(j[mt]&&!P[mt]){const bt=X(_(mt)?"kipup":"getup",mt);it(mt,bt,{duration:tt(bt)},Math.max(U[mt],D)),U[mt]=Math.max(U[mt],D)+tt(bt),j[mt]=!1}if(D=Math.max(D,U[nt],U[dt]-.25),Z.move==="dash"){const mt=Z.stop!=null?Z.stop*n/y[nt]:zl.jab*.85,bt=Math.abs(z[dt]-z[nt])/y[nt],Et=Math.sign(z[dt]-z[nt])*A(S[nt])||1,Ft=Et*Math.max(0,bt-mt),Rt={...Cr.dash,name:"dash"},Lt=tt(Rt);it(nt,Rt,{dx:Ft,duration:Lt},D),K.push({kind:"dash",t:D,dur:Lt,by:nt}),U[nt]=D+Lt,D=U[nt]+Z.pause;continue}if(Z.move==="approach"||Z.move==="teleport"){const mt=Z.stop!=null?Z.stop*n/y[nt]:zl.jab*.95,bt=Math.abs(z[dt]-z[nt])/y[nt],Et=Math.sign(z[dt]-z[nt])*A(S[nt])||1,Ft=Et*Math.max(0,bt-mt);if(Z.move==="approach"){const Rt=Math.abs(Ft)>300,Lt=X(Rt?"run":"walk",nt);if(Lt?.mocap&&Et>0){const ie=Lt.dx||1,ce=Sn(Math.round(Math.abs(Ft)/ie),1,8),Xt=sf(Lt.mocap,d,0,ce),oe=Xt.dur*(Rt?1:1.05),ne=Math.max(U[nt],D-oe*.8-Z.pause);it(nt,{...Xt,name:Lt.name},{dx:Ft,duration:oe,repeat:ce},ne),U[nt]=ne+oe,D=Math.max(D,U[nt]+Z.pause);continue}const Ht=Rt?Cr.run:Cr.walk,Yt=Sn(Math.abs(Ft)/(Ht.speed*(Rt?1.3:1.15)),.5,3.5),Jt=Math.max(U[nt],D-Yt*.8-Z.pause);it(nt,{...Ht,name:Rt?"run":"walk"},{dx:Ft,distance:Ft*y[nt]/n,duration:Yt},Jt),U[nt]=Jt+Yt,D=Math.max(D,U[nt]+Z.pause);continue}else{const Rt={...Cr.teleport,name:"teleport"},Lt=tt(Rt);it(nt,Rt,{dx:Ft,duration:Lt},D),K.push({kind:"teleport",t:D,dur:Lt,by:nt}),U[nt]=D+Lt}D=U[nt]+Z.pause;continue}if(Z.move){const mt=X(Z.move,nt),bt=z[nt]+Q(nt,mt),Et=Sn(bt,n*.08,n*.92),Ft=(mt.dx??0)*(bt===z[nt]?1:(Et-z[nt])/(bt-z[nt]));it(nt,mt,{dx:Ft,duration:tt(mt)},D),U[nt]=D+tt(mt),(mt.air||mt.mocap&&Z.move!=="guard"||Z.move==="roll")&&F.push({t:D+tt(mt)*.97,by:nt}),D=U[nt]+Z.pause;continue}const vt=Z.attack==="beam"||Z.attack==="whip"||Z.attack==="bolt",At=["ko","knockdown","launched","hurt"].includes(Z.react)?.85:1,xt=Math.abs(z[dt]-z[nt])/y[nt],St=vt?Math.min(xt,zl[Z.attack]):zl[Z.attack]*(_(nt)?.92:1)*At;if(Math.abs(xt-St)>18&&Z.attack!=="flying-kick"&&!(vt&&xt>200)){const mt=Sn(xt-St,-160,220),bt=X(mt>0?"step-in":"step-out",nt)??Cr.step,Et=bt.mocap?Sn(bt.dur*.6,.35,.8)/G:Sn(.25+Math.abs(mt)/500,.3,.7)/G;it(nt,bt.name?bt:{...Cr.step,name:"step"},{dx:mt,duration:Et},D),D+=Et}const jt=X(Z.attack,nt),Kt=tt(jt),ee=Z.attack==="flying-kick"?Sn(xt-150,60,260):void 0;it(nt,jt,{...ee!=null?{dx:ee}:{},duration:Kt},D);const le=(jt.hits??[.5]).map(mt=>D+mt*Kt),xe=jt.limbs??(jt.hits??[.5]).map(()=>jt.mlimb??jt.limb??(jt.prop==="staff"?"staff":"fist"));["beam","energy-slash","whip","bolt"].includes(Z.attack)&&K.push({kind:Z.attack,t:D,dur:Kt,hit:le[0],by:nt,target:dt,limb:xe[0],react:Z.react});const Ut=X(Z.react,dt)??Cr[Z.react],Nt=le[0],Bt=le.at(-1),_t=Math.max(tt(Ut),Bt-Nt+.45/G),de=Math.max(U[dt],Nt-(Ut.peak??.3)*_t),re=Z.react==="parry"&&!zu(S[dt].character)?"block":Z.react,ye=re===Z.react?Ut:X(re,dt),or=re==="knockdown"||re==="launched"||re==="ko"||re==="hurt"?.06:.08,$r=z[dt]+Q(dt,ye),Br=Sn($r,n*or,n*(1-or)),zo=(ye.dx??0)*($r===z[dt]?1:(Br-z[dt])/($r-z[dt]));it(dt,ye,{duration:re===Z.react?_t:Math.max(tt(ye),_t),dx:zo,...["ko","knockdown","launched"].includes(re)?{still:!0}:{}},de),(re==="knockdown"||re==="launched"||re==="ko")&&(j[dt]=!0,F.push({t:de+_t*.97,by:dt})),re==="ko"&&(P[dt]=!0),re==="roll"&&F.push({t:de+_t*.9,by:dt}),Z.attack==="sweep"&&F.push({t:le[0],by:nt,at:"foot"});const Ze=mt=>re==="dodge"||re==="roll"?"dodge":re==="block"?"block":re==="parry"?"clash":mt===le.length-1?re:"hit";le.forEach((mt,bt)=>N.push({t:mt,by:nt,target:dt,attack:Z.attack,j:bt,limb:xe[bt],kind:Ze(bt)})),U[nt]=D+Kt,U[dt]=de+_t,D=Math.max(U[nt],U[dt])+Z.pause;const vo=(z[0]+z[1])/2,W=n/2-vo;if(x===2&&Math.abs(W)>n*.1){const mt=.45/G;for(const bt of[0,1])j[bt]||it(bt,{...Cr.step,name:"step"},{dx:W*A(S[bt])/y[bt],duration:mt},D);U[0]=U[1]=D+mt,D+=mt}}const ht=Math.max(...U)+.6,yt=ot&&r?N.map(Z=>({t:Z.t,h:Y8[Z.kind]??0})).filter(Z=>Z.h>0).sort((Z,nt)=>Z.t-nt.t):[],Mt=Z=>Z+yt.filter(nt=>nt.t<Z-1e-9).reduce((nt,dt)=>nt+dt.h,0),p=Z=>{const nt=Z/o;let dt=0;for(const vt of yt){const At=vt.t+dt;if(nt<At)return nt-dt;if(nt<At+vt.h)return vt.t;dt+=vt.h}return nt-dt},lt=Math.min(v,Math.round((ht+yt.reduce((Z,nt)=>Z+nt.h,0))*o));for(const Z of N)Z.real=Mt(Z.t);const V=Z=>{const nt=Z/o;let dt=0,vt=0;for(const At of N){const xt=(nt-At.real)/.3,St=r?U8[At.kind]??0:0;if(xt>=0&&xt<1&&St){const jt=(Math.round(xt*o*.3)%2?-1:1)*St*(1-xt);dt+=jt,vt+=jt*.6}}return[dt,vt*n/i]},h=Z=>{if(!d)return null;const nt=t[Z].idle??(S[Z].character==="stick-hero"?"guard":"relaxed");return nt==="none"?null:nt==="relaxed"?"relaxed":N0.guard.find(dt=>d[dt])??null};I.forEach(Z=>{Z.length||Z.push({move:"guard",at:0,duration:.3})});const w=S.map((Z,nt)=>{const dt=h(nt);return Xg({...Z,size:Z.size,fps:o,actions:I[nt],W:n,H:i,shake:V,total:ht,stick:_(nt),clock:{n:lt,at:p},mocap:d,toon:m,law:g,maxFrames:v,...dt?{idle:dt}:{}})}),T=oI(w,N,{fps:o}),C=w.map(Z=>({track:Z}));for(const Z of N){const nt=Math.min(w[Z.by].frames.length-1,Math.round(Z.real*o)),dt=w[Z.by].frames[nt],vt=dt?lf(dt.J,Z.limb)??dt.J.haF:null;Z.at=vt?Di(w[Z.by],nt,vt):null}const O=Z=>Z.frames.map((nt,dt)=>{const vt={};for(const At of["fist","back","foot","staff","head","chest",...Object.keys(nt.J.sides??{})]){const xt=lf(nt.J,At);xt&&(vt[At]=Di(Z,dt,xt))}return vt});C.forEach((Z,nt)=>{Z.ends=O(w[nt]),Z.frames=w[nt].frames});const L=r?N.filter(Z=>Z.at&&Z.kind!=="dodge").map(Z=>({start:Math.round(Z.real*o)/o,frames:iI(Z,{fps:o,accent:a,W:n,H:i,size:S[Z.by].size})})):[],B=r?F.map(Z=>{const nt=Math.min(C[Z.by].ends.length-1,Math.round(Mt(Z.t)*o)),dt=C[Z.by].ends[nt],vt=S[Z.by].ground,At=w[Z.by].frames[nt],xt=Z.at==="foot"&&dt?.foot?dt.foot[0]:At?Di(w[Z.by],nt,[(At.J.anF[0]+At.J.anB[0])/2,0])[0]:S[Z.by].x;return{start:Math.round(Mt(Z.t)*o)/o,frames:sI(xt,vt,{fps:o,W:n,H:i,size:S[Z.by].size,color:u})}}):[],q=[...r?K.map(Z=>aI(Z,{actors:C,fps:o,W:n,H:i,realOf:Mt,color:f,size:S[Z.by].size})).filter(Boolean):[],...L,...B],et=s??(ot?"follow":"fixed"),st=Math.max(...S.map(Z=>Z.ground)),Y=et==="follow"||et==="director"?tI(w,N,{fps:o,W:n,H:i,n:lt,fx:r,ground:st}):null,ct=et==="director"?rI(Y,w,N,{fps:o,n:lt,ground:st}):Y;if(ct){for(const Z of w)Z.cam=ct;for(const Z of q){const nt=Math.round(Z.start*o);Z.frames=Z.frames.map((dt,vt)=>nI(dt,ct[Math.min(nt+vt,ct.length-1)],n,i))}}C.forEach((Z,nt)=>{Z.frames=hx(w[nt]).frames});const gt=w.map((Z,nt)=>dx(Z,T[nt],`fighter ${nt}: `));return{actors:C,fx:q,impacts:N.map(({real:Z,kind:nt,at:dt})=>({t:Math.round(Z*100)/100,kind:nt,at:dt})),duration:lt/o,camera:ct,tracks:w,reports:gt}}function tI(t,e,{fps:o,W:r,H:a,n,fx:i,ground:l}){const u=k=>{let y=1/0,A=1/0,I=-1/0,z=-1/0;for(const j of t){const P=Math.min(k,j.frames.length-1),N=j.frames[P];if(!N)continue;const F=N.J,K=26*j.k/j.H,_=[F.head,F.neck,F.pelvis,F.haF,F.haB,F.anF,F.anB,F.knF,F.knB,...F.weapon?[F.weapon.a,F.weapon.b]:[]];for(const J of _){if(!J)continue;const X=Di(j,P,J);y=Math.min(y,X[0]-K*j.H/j.W),I=Math.max(I,X[0]+K*j.H/j.W),A=Math.min(A,X[1]-K),z=Math.max(z,X[1]+K*.4)}}return Number.isFinite(y)?[y,A,I,z]:[.3,.3,.7,.9]},c=k=>{const[y,A,I,z]=u(k),j=I-y+.08,P=z-A+.08,N=Sn(Math.min(.74/j,.72/P),1,1.8);return[(y+I)/2,Math.min((A+z)/2,l-.32/N),N]};let[s,d,f]=c(0),m=0,g=0,v=0;const x=[],$=1/o,E=6.5,S=3.2;for(let k=0;k<n;k++){const[y,A,I]=c(k);for(let N=0;N<2;N++){const F=$/2;m+=(E*E*(y-s)-2*E*m)*F,s+=m*F,g+=(E*E*(A-d)-2*E*g)*F,d+=g*F,v+=(S*S*(I-f)-2*S*v)*F,f+=v*F}let z=0,j=0;i&&e.forEach((N,F)=>{const K=(k/o-N.real)/.45;if(K<0||K>=1)return;const[_,J]=q8[N.kind]??[0,0];z+=_*(1-K)**2,j+=(F%2?-1:1)*J*Math.sin(Math.PI*Math.min(1,K*1.6))*(1-K)});const P=Math.min(2,f*(1+z));x.push({cx:Math.round(s*1e4)/1e4,cy:Math.round(d*1e4)/1e4,z:Math.round(P*1e4)/1e4,r:Math.round(j*100)/100})}return x}const eI={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 oI(t,e,{fps:o}){const r=t.map(()=>[]),a=$p.reach.window;for(const n of e){const i=eI[n.attack];if(!i||n.kind==="dodge")continue;const l=t[n.by],u=t[n.target];if(!l||!u)continue;const c=n.kind==="block"||n.kind==="clash"?"guard":Array.isArray(i)?i[n.j%i.length]:i,s=j=>P=>{const N=u.frames[Math.min(P,u.frames.length-1)].J,F=j==="guard"?N.haF:j==="shin"?oc(N.knF,N.anF,.6):j==="chest"?oc(N.neck,N.pelvis,.3):j==="belly"?oc(N.neck,N.pelvis,.7):N.head;return Di(u,Math.min(P,u.frames.length-1),F)},d=Math.min(l.frames.length-1,Math.round(n.real*o)),f=l.frames[d].J,m=fx(f,n.limb),g=Object.values(mx).find(j=>j[2]===m),v=g?f[g[0]]:m==="weapon"?f.weapon.grip:f.pelvis,x=gx(f,n.limb)*$p.reach.stretch*.97,$=j=>{const P=Ep(l,d,j(d)),N=P[0]-v[0],F=P[1]-v[1];if(Math.hypot(N,F)<=x)return{lunge:0,left:0};const K=Math.abs(F)<x?Math.abs(N)-Math.sqrt(x*x-F*F):Math.abs(N),_=Math.min($p.reach.glide,Math.max(0,K));return{lunge:Math.sign(N)*_,left:Math.max(0,Math.hypot(Math.abs(N)-_,F)-x)}},E=c==="guard"||c==="shin"?[c]:c==="head"?["head","chest","belly"]:[c,"belly"];let S=E[0],k=1/0;for(const j of E){const P=$(s(j));if(P.left<=1){S=j;break}P.left<k&&(k=P.left,S=j)}const y=s(S),A=$(y).lunge;for(let j=0;j<l.frames.length;j++){const P=l.frames[j],N=P.tt-n.t;if(N<-.3||N>.5)continue;let F=P.J;if(A){const _=N<=0?cf((N+.25)/.25):1-cf((N-.1)/.35);if(_>0){const J={};for(const[X,rt]of Object.entries(F)){if(X==="sides"){J.sides=rt;continue}if(X==="weapon"){J.weapon={...rt,a:[rt.a[0]+A*_,rt.a[1]],b:[rt.b[0]+A*_,rt.b[1]],grip:[rt.grip[0]+A*_,rt.grip[1]]};continue}J[X]=[rt[0]+A*_,rt[1]]}F=yx(J,F,{planted:bx(F)})}}const K=wx(N,a);K>0&&(F=kx(F,n.limb,Ep(l,j,y(j)),K)),P.J=F}const I=xx(l.frames[d].J,n.limb),z=Ep(l,d,y(d));r[n.by].push({t:n.real,limb:n.limb,miss:I?Math.hypot(I[0]-z[0],I[1]-z[1])/300:1})}return r}const oc=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o];function rI(t,e,o,{fps:r,n:a,ground:n}){const i=o.map((s,d)=>({time:s.real,im:s,result:s.kind==="dodge"?"miss":s.kind==="block"||s.kind==="clash"?"blocked":"head",last:d===o.length-1&&["ko","knockdown","launched"].includes(s.kind)})),l=H8(i,0,a/r,gp),u=[],c=(s,d,f)=>{const m=e[s],g=Math.min(d,m.frames.length-1),v=m.frames[g].J;return Di(m,g,oc(v.neck,v.pelvis,.35))};for(let s=0;s<a;s++){const d=s/r,f=l.find(E=>d>=E.from-1e-9&&d<E.to)??l.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 $;if(f.kind==="insert"){const E=g.at??c(g.target,v);$={cx:E[0],cy:Math.min(E[1],n-.2),z:2.3*(1+.04*x),r:m.r}}else if(f.kind==="reaction"){const E=c(g.target,v);$={cx:E[0],cy:Math.min(E[1],n-.27),z:1.75*(1+.03*x),r:0}}else $={...m,z:Math.max(1,m.z*.92),cy:Math.min(m.cy+.03,n-.3),r:0};u.push({cx:Math.round($.cx*1e4)/1e4,cy:Math.round($.cy*1e4)/1e4,z:Math.round($.z*1e4)/1e4,r:Math.round(($.r??0)*100)/100})}return u}function F0(t,e,o,r){const a=e.r*Math.PI/180,n=Math.cos(a),i=Math.sin(a),l=(t[0]-e.cx)*o,u=(t[1]-e.cy)*r;return[Math.round((.5+(l*n-u*i)*e.z/o)*1e4)/1e4,Math.round((.5+(l*i+u*n)*e.z/r)*1e4)/1e4]}function nI(t,e,o,r){return{...t,parts:t.parts.map(a=>a.loops?{...a,loops:a.loops.map(n=>n.map(i=>F0(i,e,o,r)))}:a.points?{...a,points:a.points.map(n=>F0(n,e,o,r))}:a)}}const Vi=(t,e,o,r,a=14)=>Array.from({length:a},(n,i)=>{const l=i/a*2*Math.PI;return[t[0]+Math.cos(l)*e*r/o,t[1]+Math.sin(l)*e]});function sn(t,e,o,r,a,n=1){const i=[],l=u=>Math.max(.02,Math.round(Math.min(1,u)*100)/100);for(const[u,c]of[[3.2,.08],[2.2,.14],[1.5,.24]])i.push({points:Vi(t,e*u,r,a),fill:o,line:!1,opacity:l(c*n)});return i.push({points:Vi(t,e,r,a),fill:o,line:!1,...n<1?{opacity:l(n)}:{}},{points:Vi(t,e*.55,r,a,10),fill:"#ffffff",line:!1,...n<1?{opacity:l(n)}:{}}),i}function R0(t,e,o,r,a,n){const i=e[0]-t[0],l=(e[1]-t[1])*n/a,u=Math.hypot(i,l)||1,c=-l/u,s=i/u,d=(f,m,g)=>{const v=o*f;return{points:[[t[0]+c*v*n/a,t[1]+s*v],[e[0]+c*v*n/a,e[1]+s*v],[e[0]-c*v*n/a,e[1]-s*v],[t[0]-c*v*n/a,t[1]-s*v]],fill:m,line:!1,smooth:!1,...g<1?{opacity:g}:{}}};return[d(3.4,r,.1),d(2.2,r,.18),d(1.3,r,.4),d(.8,r,1),d(.32,"#ffffff",1)]}function aI(t,{actors:e,fps:o,W:r,H:a,realOf:n,color:i,size:l}){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},c=l*.06,s=[],d=(f,m=Math.round(o*.55))=>{const g=[];for(let v=0;v<=m;v++){const x=f+v,$=v/m,E=u(t.target,x,"chest")||u(t.target,x,"head");if(!E){g.push({parts:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]});continue}const S=[];$<.25&&S.push(...sn(E,c*(2.6-$*4),"#ffffff",r,a,1-$*3)),S.push(...sn(E,c*(1.2+$*1.4),i,r,a,(1-$)*.9));const k=c*(1.2+$*5),y=k-c*.5*(1-$);S.push({points:[...Vi(E,k,r,a,24),...Vi(E,y,r,a,24).reverse()],fill:i,line:!1,eo:!0,opacity:Math.max(.02,Math.round((1-$)*.8*100)/100)});for(let A=0;A<7;A++){const I=A*2.4+.6,z=c*(1.5+$*6)*(.7+.3*Math.sin(A*3.7)),j=[E[0]+Math.cos(I)*z*a/r,E[1]+Math.sin(I)*z];S.push({points:Vi(j,c*.18*(1-$*.6),r,a,6),fill:"#1a1a1a",line:!1,...$>.6?{opacity:Math.max(.02,Math.round((1-$)*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 $=u(t.by,x,t.limb)||u(t.by,x,"back"),E=u(t.target,x,"head")||u(t.target,x,"chest"),S=[];if($){if(x<m){const k=(x-f)/Math.max(1,m-f);S.push(...sn($,c*(.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,A=1+.25*Math.sin(x*2.3);E&&S.push(...R0($,E,c*.55*A*y,i,r,a)),S.push(...sn($,c*1.2*y,i,r,a,y)),E&&S.push(...sn(E,c*(1.4+k*.8)*y,i,r,a,y))}s.push({parts:S})}}const v=d(m);for(let x=0;x<v.length;x++){const $=m-f+x;s[$]?s[$]={parts:[...s[$].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 $=u(t.by,x,t.limb);$&&v.push($)}if(v.length<3)return null;for(let x=f;x<=g;x++){const $=Math.min(v.length,x-f+1),E=v.slice(0,$),S=x>m?1-(x-m)/(g-m+1):1,k=[];if(E.length>=2)for(const[y,A,I]of[[2.4,.18,i],[1.4,.4,i],[.7,1,i],[.28,1,"#ffffff"]]){const z=[],j=[],P=E.length-1;E.forEach((N,F)=>{const K=E[Math.max(0,F-1)],_=E[Math.min(P,F+1)],J=_[0]-K[0],X=(_[1]-K[1])*a/r,rt=Math.hypot(J,X)||1,ot=c*y*Math.sin(Math.PI*Math.min(1,(F+.5)/(P+.5)));z.push([N[0]-X/rt*ot*a/r,N[1]+J/rt*ot]),j.push([N[0]+X/rt*ot*a/r,N[1]-J/rt*ot])}),k.push({points:[...z,...j.reverse()],fill:I,line:!1,opacity:Math.max(.02,Math.round(A*S*100)/100)})}s.push({parts:k.length?k:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:s}}if(t.kind==="whip"){const f=Math.round(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 $=u(t.by,x,"chest"),E=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 A=[-.9,.5,1.3][y],I=Math.hypot((E[0]-$[0])*r/a,E[1]-$[1]),z=[($[0]+E[0])/2,($[1]+E[1])/2-A*I*.22],j=16,P=[];for(let N=0;N<=j*k;N++){const F=N/j,K=1-F;P.push([K*K*$[0]+2*K*F*z[0]+F*F*E[0],K*K*$[1]+2*K*F*z[1]+F*F*E[1]+Math.sin(F*9+x*.7+y)*c*.15])}if(!(P.length<3)){for(const[N,F,K]of[[2,.16,i],[1.1,.45,i],[.5,1,i]]){const _=[],J=[],X=P.length-1;P.forEach((rt,ot)=>{const G=P[Math.max(0,ot-1)],tt=P[Math.min(X,ot+1)],Q=tt[0]-G[0],it=(tt[1]-G[1])*a/r,D=Math.hypot(Q,it)||1,U=c*N*(.35+.65*ot/X);_.push([rt[0]-it/D*U*a/r,rt[1]+Q/D*U]),J.push([rt[0]+it/D*U*a/r,rt[1]-Q/D*U])}),S.push({points:[..._,...J.reverse()],fill:K,line:!1,...F<1?{opacity:F}:{}})}S.push(...sn(P.at(-1),c*.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=d(m);for(let x=0;x<v.length;x++){const $=m-f+x;s[$]?s[$]={parts:[...s[$].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"),$=[];if(v&&x){const E=(g-f)/Math.max(1,m-f),S=[v[0]+(x[0]-v[0])*E,v[1]+(x[1]-v[1])*E],k=Math.max(0,E-.45);for(const y of[0,Math.PI]){const A=[];for(let z=0;z<=14;z++){const j=k+(E-k)*z/14,P=[v[0]+(x[0]-v[0])*j,v[1]+(x[1]-v[1])*j],N=Math.sin(j*22+y+g*.4)*c*.5*(z/14);A.push([P[0],P[1]+N])}for(const[z,j,P]of[[1,.3,i],[.4,1,i],[.15,1,"#ffffff"]]){const N=[],F=[],K=A.length-1;A.forEach((_,J)=>{const X=A[Math.max(0,J-1)],rt=A[Math.min(K,J+1)],ot=rt[0]-X[0],G=(rt[1]-X[1])*a/r,tt=Math.hypot(ot,G)||1,Q=c*z*(.2+.8*J/K);N.push([_[0]-G/tt*Q*a/r,_[1]+ot/tt*Q]),F.push([_[0]+G/tt*Q*a/r,_[1]-ot/tt*Q])}),$.push({points:[...N,...F.reverse()],fill:P,line:!1,...j<1?{opacity:j}:{}})}}$.push(...sn(S,c*.9,i,r,a,1.3))}s.push({parts:$.length?$:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:[...s,...d(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 $=u(t.by,Math.min(x,m),"chest"),E=[];if(v&&$){const S=x>m?1-(x-m)/(g-m+1):1,k=[v[0]+($[0]-v[0])*Math.max(0,(x-m)/(g-m+1)),v[1]];E.push(...R0(k,$,c*1.5*S,i,r,a).map((y,A)=>A===4?{...y,fill:"#f3dcff"}:y)),E.push(...sn($,c*1.6*S,i,r,a,S))}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}}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 $=f;$<=g;$++){const E=[],S=($-f)/Math.max(1,m-f),k=($-m)/Math.max(1,g-m);v&&$<=m+3&&E.push(...sn(v,c*(1+S*2.2)*($>m?.5:1),i,r,a,1-Math.max(0,S-.7))),x&&$>=m-1&&E.push(...sn(x,c*(2.6-k*1.8),i,r,a,1-k*.8)),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}}return null}function iI(t,{fps:e,accent:o,W:r,H:a,size:n}){const i=Math.max(3,Math.round(e*.25)),[l,u]=t.at,c=n*.16*(t.kind==="knockdown"||t.kind==="launched"?1.4:t.kind==="clash"?1.2:t.kind==="block"?.7:1),s=t.kind==="block",d=t.kind==="clash",f=s||d?"#e8f6ff":"#fffbe8",m=s?"#8fd3ff":d?"#ffffff":o,g=(x,$)=>[l+Math.cos($)*x*a/r,u+Math.sin($)*x],v=[];for(let x=0;x<i;x++){const $=x/(i-1),E=c*(.55+$*.9),S=[],k=s?8:12;if(x<i-1){const y=[];for(let A=0;A<k*2;A++){const I=A/(k*2)*2*Math.PI+(A%4===1?.08:0);y.push(g(A%2?E*.38:E*(A%3===0?1.1:.85),I))}S.push({points:y,fill:m,line:!1}),S.push({points:Array.from({length:10},(A,I)=>g(E*.28,I/10*2*Math.PI)),fill:f,line:!1})}for(let y=0;y<8;y++){const A=y/8*2*Math.PI+.2;S.push({points:[g(E*(.9+$*.5),A),g(E*(1.3+$*.9),A)],fill:null,closed:!1,lw:Math.max(.3,1.4-$)})}v.push({parts:S})}return v}function sI(t,e,{fps:o,W:r,H:a,size:n,color:i}){const l=Math.max(3,Math.round(o*.4)),u=n*.05,c=[];for(let s=0;s<l;s++){const d=s/(l-1),f=[];for(const[m,g]of[[-1,1],[-.45,1.25],[.45,1.25],[1,1]]){const v=u*g*(1-d*.65),x=t+m*u*(1.4+d*2.6)*a/r,$=e-v*.7-d*u*.5;f.push({points:Array.from({length:10},(E,S)=>{const k=S/10*2*Math.PI;return[x+Math.cos(k)*v*a/r,$+Math.sin(k)*v*.75]}),fill:i,line:!1})}c.push({parts:f})}return c}const Pl=t=>Math.round(t*10)/10,pu=(t,e,o,r,a,n,i=0)=>{const l=[];for(let u=0;u<=a*3;u++){const c=u/(a*3),s=t+(e-t)*c,d=o-r*(.55+.45*Math.sin(c*a*2*Math.PI+i)*Math.cos(c*a*.7*Math.PI+i*2));l.push([s,d])}return[...l,[e,n],[t,n]]},uu=(t,e,o,r=9,a=1)=>Array.from({length:r},(n,i)=>{const l=i/r*2*Math.PI,u=1+.18*Math.sin(i*2.7+a);return[t[0]+Math.cos(l)*e*u,t[1]+Math.sin(l)*o*u*(Math.sin(l)>0?.55:1)]}),br=(t,e,o,r)=>[[t,e],[o,e],[o,r],[t,r]],qy=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:uu([e,.36+o%2*.06],.26,.11,10,o),fill:o%2?"#d8b4dc":"#c69fd3"})),{pts:pu(-1.2,2.2,t-.2,.22,7,t+.1,.4),fill:"#b48ac8"}]},{p:.5,parts:[{pts:pu(-1.3,2.3,t-.06,.12,5,t+.12,1.3),fill:"#8f2f2c"},{pts:pu(-1.3,2.3,t-.03,.05,9,t+.12,2.1),fill:"#a8413a"}]},{p:1,parts:[{pts:br(-1.6,t,2.6,t+.9),fill:"#4e3423",smooth:!1},{pts:br(-1.6,t-.004,2.6,t+.022),fill:"#d9c6a8",smooth:!1},{pts:uu([.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:br(e-.035,-.4,e+.035,t),fill:"#6b4423",smooth:!1})),{pts:br(-1.5,.08,2.5,.12),fill:"#5a381c",smooth:!1},...[-.85,-.35,.15,.65,1.15,1.65].map(e=>({pts:br(e-.17,.2,e+.17,t-.08),fill:"#f3ead6",smooth:!1}))]},{p:1,parts:[{pts:br(-1.6,t,2.6,t+.9),fill:"#a8743f",smooth:!1},...[0,1,2,3].map(e=>({pts:br(-1.6,t+.03+e*.05,2.6,t+.034+e*.05),fill:"#8c5d30",smooth:!1})),{pts:br(-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:uu([.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:br(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:br(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:br(r,a,r+.025,a+.03),fill:"#e8c66a",smooth:!1}})]},{p:1,parts:[{pts:br(-1.6,t,2.6,t+.9),fill:"#10142a",smooth:!1},{pts:br(-1.6,t-.006,2.6,t+.01),fill:"#3a4470",smooth:!1}]}]}}),Sh=Object.freeze(Object.keys(qy));function lI(t,{size:e,camera:o,fps:r,duration:a,ground:n=.9,finish:i,en:l=!1}){const u=qy[t];if(!u)throw Error(`animatePuppet scene: ${Sh.join(" | ")}`);const c=Ur(e),s=c.pt([.5,.5]),d=c.k,f=u.layers(n).map((y,A)=>{const I=y.parts.map(z=>{const j=z.pts.map(P=>{const N=c.pt(P);return[N[0]-s[0],N[1]-s[1]]});return{d:z.smooth===!1?"M"+j.map(P=>`${Math.round(P[0])} ${Math.round(P[1])}`).join(" L")+" Z":qi(j,!0),fill:z.fill,line:!1,role:7}});return{p:y.p,it:{id:`d${A+1}`,name:`${l?"Depth":"Lớp"} ${A+1}`,type:"art",params:{parts:I,box:pr(I.map(z=>z.d).join(" ")),outline:!1},pos:[s[0],s[1]],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:I[0].fill},stroke:null,role:7}}}),[m,g]=e,v={id:"sky",name:l?"Sky":"Bầu trời",type:"rect",params:{w:Pl(m/d*1.6),h:Pl(g/d*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,A)=>{const I=1+(A.z-1)*y,z=A.r*Math.PI/180,j=Math.cos(z),P=Math.sin(z),N=c.pt([.5+(A.cx-.5)*y,.5+(A.cy-.5)*y]),F=s[0]-N[0],K=s[1]-N[1];return{x:Pl(s[0]+(F*j-K*P)*I),y:Pl(s[1]+(F*P+K*j)*I),z:Math.round(I*1e4)/1e4,r:Math.round(A.r*100)/100}},$=`${l?"Scene":"Cảnh nền"} · ${l?u.en:u.vi}`;if(!o?.length){const y=f.map(({p:A,it:I})=>({...I,...(()=>{const z=x(A,{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:$,start:0,duration:a}]}const E=[],S=o.length,k=Math.max(1,Math.round(6*r));for(let y=0;y<S;y+=k){const A=Math.min(S,y+k),I=y/r,z=(A-y)/r,j=Math.min(60,A-y-1)||1,P=[...new Set(Array.from({length:j+1},(F,K)=>Math.min(A-1,y+Math.round(K*(A-1-y)/j))))],N=f.map(({p:F,it:K})=>{const _=P.map(X=>({t:Math.round((X-y)/r*1e4)/1e4,q:x(F,o[X])})),J=X=>_.map(({t:rt,q:ot},G)=>({time:rt,value:X(ot),...G<_.length-1?{ease:"auto"}:{}}));return{...K,pos:[_[0].q.x,_[0].q.y],scale:[_[0].q.z,_[0].q.z],rot:_[0].q.r,keys:{"pos.0":J(X=>X.x),"pos.1":J(X=>X.y),"scale.0":J(X=>X.z),"scale.1":J(X=>X.z),rot:J(X=>X.r)}}});E.push({shape:i({v:2,size:e,items:[v,...N]},null,{colors:"keep"}),label:$,start:I,duration:z})}return E}const Ll=/^#[0-9a-fA-F]{6}$/,vs=Number.isFinite,cI=t=>[1,3,5].map(e=>parseInt(t.slice(e,e+2),16)),pI=t=>"#"+t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join(""),jr=(t,e)=>pI(cI(t).map(o=>e>=0?o+(255-o)*e:o*(1+e))),D0=Object.freeze(["box","stairs","cylinder","plane","panel"]),Qc=Object.freeze({iso:[Math.cos(Math.PI/6),.5],dimetric:[2/Math.sqrt(5),1/Math.sqrt(5)]}),Ls=Object.freeze({solids:24,steps:24,size:[.002,2]}),Ns=t=>Math.round(t),uI=(t,e=!0)=>"M"+t.map(o=>`${Ns(o[0])} ${Ns(o[1])}`).join(" L")+(e?" Z":"");function hI(t){const e=[...t].sort((n,i)=>n[0]-i[0]||n[1]-i[1]),o=(n,i,l)=>(i[0]-n[0])*(l[1]-n[1])-(i[1]-n[1])*(l[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 dI(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(!D0.includes(r))throw Error(`${o}.kind: ${D0.join(" | ")}`);if(!Array.isArray(t.at)||t.at.length!==2||!t.at.every(u=>vs(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]=Ls.size;if(!Array.isArray(t.size)||t.size.length!==3||!t.size.every((u,c)=>vs(u)&&u<=n&&(u>=a||c===2&&r==="plane"&&u>=0||c===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&&!(vs(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(!Ll.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,c])=>!["top","left","right"].includes(u)||!Ll.test(c))))throw Error(`${o}.colors: {top?, left?, right?: #RRGGBB}`);if(t.steps!=null&&!(Number.isInteger(t.steps)&&t.steps>=2&&t.steps<=Ls.steps))throw Error(`${o}.steps: 2–${Ls.steps}`);for(const[u,c]of[["rise",["left","right"]],["face",["left","right"]]])if(t[u]!=null&&!c.includes(t[u]))throw Error(`${o}.${u}: ${c.join(" | ")}`);if(t.inset!=null&&!(vs(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&&!Ll.test(t.inner))throw Error(`${o}.inner: #RRGGBB (the panel's inside: screen, mirror, window)`);const l=t.shadow;if(l!=null&&typeof l!="boolean"&&(typeof l!="object"||Array.isArray(l)||Object.keys(l).some(u=>!["length","side","color"].includes(u))||l.length!=null&&!(vs(l.length)&&l.length>=0&&l.length<=4)||l.side!=null&&!["left","right"].includes(l.side)||l.color!=null&&!Ll.test(l.color)))throw Error(`${o}.shadow: true | false | {length? 0–4 (× its height), side? left|right, color? #RRGGBB}`);return{kind:r,at:[...t.at],z:t.z??0,size:[...t.size],color:i,colors:t.colors??null,steps:t.steps??8,rise:t.rise??"left",face:t.face??"left",inset:t.inset??.08,inner:t.inner??null,shadow:l??!0,name:t.name!=null?String(t.name).slice(0,40):null}}function fI(t,e,{view:o="iso",light:r="left",shadowColor:a="#1e1719"}={}){const[n,i]=Qc[o]??Qc.iso,l=e.pt(t.at),u=ot=>e.len(ot),[c,s,d]=t.size.map(u),f=u(t.z||0),m=([ot,G,tt])=>[l[0]+(ot-G)*n,l[1]+(ot+G)*i-tt-f],g=t.colors?.left??t.color,v={top:t.colors?.top??jr(t.color,.18),lit:g,dark:t.colors?.right??jr(t.color,-.28)},x=r==="left"?v.lit:v.dark,$=r==="left"?v.dark:v.lit,E=[],S=(ot,G)=>E.push({d:uI(ot),fill:G,line:!1,role:7}),k=t.shadow,y=k===!1?0:typeof k=="object"?k.length??1:1,I=(typeof k=="object"&&k.side?k.side:r==="left"?"right":"left")==="right"?[1,-.35]:[-.35,1],z=t.kind==="plane"?0:(t.kind==="panel",d);if(y>0&&z>0){let ot;if(t.kind==="cylinder"){ot=[];for(let Q=0;Q<16;Q++){const it=Q/16*2*Math.PI;ot.push([Math.cos(it)*c/2,Math.sin(it)*c/2])}}else t.kind==="panel"?ot=t.face==="left"?[[-c/2,0],[c/2,0]]:[[0,-c/2],[0,c/2]]:ot=[[-c/2,-s/2],[c/2,-s/2],[c/2,s/2],[-c/2,s/2]];const G=[I[0]*z*y,I[1]*z*y],tt=hI([...ot,...ot.map(Q=>[Q[0]+G[0],Q[1]+G[1]])]);S(tt.map(([Q,it])=>m([Q,it,0])),typeof k=="object"&&k.color?k.color:a)}const j=(ot,G,tt,Q,it,D,U=v)=>{const ht=[[ot,tt,D],[G,tt,D],[G,Q,D],[ot,Q,D]].map(m),yt=[[ot,Q,it],[G,Q,it],[G,Q,D],[ot,Q,D]].map(m),Mt=[[G,tt,it],[G,Q,it],[G,Q,D],[G,tt,D]].map(m);D-it>0&&(S(yt,U===v?x:U.left),S(Mt,U===v?$:U.right)),S(ht,U.top)};if(t.kind==="box")j(-c/2,c/2,-s/2,s/2,0,d);else if(t.kind==="plane")S([[-c/2,-s/2,d],[c/2,-s/2,d],[c/2,s/2,d],[-c/2,s/2,d]].map(m),v.top);else if(t.kind==="stairs"){const ot=t.steps;for(let G=ot-1;G>=0;G--){const tt=d*(G+1)/ot;t.rise==="left"?j(c/2-c*(G+1)/ot,c/2-c*G/ot,-s/2,s/2,0,tt):j(-c/2,c/2,s/2-s*(G+1)/ot,s/2-s*G/ot,0,tt)}}else if(t.kind==="cylinder"){const G=D=>Array.from({length:24},(U,ht)=>{const yt=ht/24*2*Math.PI;return m([Math.cos(yt)*c/2,Math.sin(yt)*c/2,D])}),tt=G(0),Q=G(d),it=(D,U)=>{const ht=[];for(let yt=D;yt<=U;yt++)ht.push(tt[yt%24]);for(let yt=U;yt>=D;yt--)ht.push(Q[yt%24]);return ht};d>0&&(S(it(0,24/4),$),S(it(24/4,24/2),x)),S(Q,v.top)}else if(t.kind==="panel"){const ot=(tt,Q)=>t.face==="left"?m([tt,s/2,Q]):m([s/2,tt,Q]),G=(tt,Q,it,D)=>[ot(tt,it),ot(Q,it),ot(Q,D),ot(tt,D)];if(s>0?j(...t.face==="left"?[-c/2,c/2,-s/2,s/2]:[-s/2,s/2,-c/2,c/2],0,d):S(G(-c/2,c/2,0,d),t.face==="left"?x:$),t.inner){const tt=Math.min(c,d)*t.inset;S(G(-c/2+tt,c/2-tt,tt,d-tt),t.inner)}}const P=E.flatMap(ot=>ot.d.match(/-?\d+(\.\d+)?/g).map(Number)),N=P.filter((ot,G)=>G%2===0),F=P.filter((ot,G)=>G%2===1),K=Ns((Math.min(...N)+Math.max(...N))/2),_=Ns((Math.min(...F)+Math.max(...F))/2),J=E.map(ot=>{let G=0;return{...ot,d:ot.d.replace(/-?\d+(\.\d+)?/g,tt=>String(Ns(Number(tt)-(G++%2?_:K))))}}),X=N.map(ot=>ot-K),rt=F.map(ot=>ot-_);return{parts:J,pos:[K,_],box:[Math.min(...X),Math.min(...rt),Math.max(...X),Math.max(...rt)]}}const ja=/^#[0-9a-fA-F]{6}$/,hi=Number.isFinite,B0=Object.freeze(["corridor","box","panel","wall-panel"]),na=Object.freeze({solids:24,depth:[0,60],repeat:24,fly:[0,40]}),$s=-.55;function Zy(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(!B0.includes(r))throw Error(`${o}.kind (perspective): ${B0.join(" | ")}`);const a=t.color??"#efe6df";if(!ja.test(a))throw Error(`${o}.color: #RRGGBB`);const n=(l,u,c)=>{if(l==null)return null;if(typeof l!="object"||Array.isArray(l)||Object.entries(l).some(([s,d])=>!u.includes(s)||!ja.test(d)))throw Error(`${o}.${c}: {${u.join(", ")}: #RRGGBB}`);return l};if(((l,u)=>{if(l!=null&&!(hi(l)&&l>=na.depth[0]&&l<=na.depth[1]))throw Error(`${o}.${u}: 0–${na.depth[1]} (0 = the picture plane, 1 = twice as far)`)})(t.depth,"depth"),r==="corridor"){const l=(d,f,m)=>{if(d==null)return null;if(typeof d!="object"||Array.isArray(d))throw Error(`${o}.${m} must be an object`);for(const g of Object.keys(d))if(!f.includes(g))throw Error(`${o}.${m}: ${f.join(", ")}`);return d},u=l(t.carpet,["color","width"],"carpet"),c=l(t.doors,["count","color","inner","height","width"],"doors"),s=l(t.lines,["count","color"],"lines");if(u&&(!ja.test(u.color??"")||u.width!=null&&!(hi(u.width)&&u.width>0&&u.width<=1)))throw Error(`${o}.carpet: {color #RRGGBB, width? 0–1 of the floor}`);if(c&&(!(Number.isInteger(c.count)&&c.count>=1&&c.count<=8)||c.color!=null&&!ja.test(c.color)||c.inner!=null&&!ja.test(c.inner)))throw Error(`${o}.doors: {count 1–8 per wall, color?, inner?, height? 0–1, width? depth units}`);if(s&&(!(Number.isInteger(s.count)&&s.count>=1&&s.count<=16)||s.color!=null&&!ja.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:c,lines:s}}if(!Array.isArray(t.at)||t.at.length!==2||!t.at.every(l=>hi(l)&&l>=-1&&l<=2))throw Error(`${o}.at: [x, y] of its front bottom centre on the picture plane (0..1 of the frame)`);if(!Array.isArray(t.size)||t.size.length!==3||!t.size.every((l,u)=>hi(l)&&l>=0&&l<=(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<=na.repeat)||!(hi(t.repeat.step)&&t.repeat.step>0&&t.repeat.step<=20)||t.repeat.dx!=null&&!hi(t.repeat.dx)))throw Error(`${o}.repeat: {count 2–${na.repeat}, step (depth units), dx? (frame width per copy)}`);if(t.inner!=null&&!ja.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 mI(t,{vanish:e=[.5,.45],cam:o=0,W:r=1280,H:a=720}={}){const n=[e[0]*r,e[1]*a],i=[],l=(d,f,m)=>{const g=1/(1+Math.max($s,m-o));return[(n[0]+(d-n[0])*g)/r,(n[1]+(f-n[1])*g)/a]},u=(d,f)=>i.push({pts:d.map(m=>[Math.round(m[0]*1e4)/1e4,Math.round(m[1]*1e4)/1e4]),fill:f}),c=d=>Math.max(d,o+$s);if(t.kind==="corridor"){const d=t.colors||{},f=t.depth,m=c(0),g=f,v=d.floor??jr(t.color,-.12),x=d.ceiling??jr(t.color,.1),$=d.left??t.color,E=d.right??jr(t.color,-.06),S=d.back??jr(t.color,-.2);if(g<=o+$s)return i;if(u([l(0,0,m),l(r,0,m),l(r,0,g),l(0,0,g)],x),u([l(0,a,m),l(r,a,m),l(r,a,g),l(0,a,g)],v),u([l(0,0,m),l(0,0,g),l(0,a,g),l(0,a,m)],$),u([l(r,0,m),l(r,0,g),l(r,a,g),l(r,a,m)],E),u([l(0,0,g),l(r,0,g),l(r,a,g),l(0,a,g)],S),t.lines){const k=t.lines.count;for(let y=1;y<=k;y++){const A=f*y/(k+1);if(A<=m)continue;const I=.006*r;u([l(0,a,A),l(r,a,A),l(r,a,A+I/r*f*.4),l(0,a,A+I/r*f*.4)],t.lines.color??jr(v,-.1))}}if(t.carpet){const k=(t.carpet.width??.3)*r/2;u([l(r/2-k,a,m),l(r/2+k,a,m),l(r/2+k,a,g),l(r/2-k,a,g)],t.carpet.color)}if(t.doors){const k=t.doors.count,y=(t.doors.height??.62)*a,A=t.doors.width??Math.min(.55,f/(k*2.2)),I=t.doors.color??jr($,-.25),z=t.doors.inner??jr($,-.45);for(let j=k-1;j>=0;j--){const P=f*(j+.35)/k,N=P+A;if(N<=o+$s)continue;const F=c(P);for(const K of[0,r]){u([l(K,a-y,F),l(K,a-y,N),l(K,a,N),l(K,a,F)],I);const _=A*.14;N-_>F+_&&u([l(K,a-y*.9,F+_),l(K,a-y*.9,N-_),l(K,a,N-_),l(K,a,F+_)],z)}}}return i}const s=t.repeat?Array.from({length:t.repeat.count},(d,f)=>f):[0];for(const d of s.reverse()){const f=t.depth+(t.repeat?t.repeat.step*d:0),m=(t.repeat?.dx??0)*r*d,[g,v]=[t.at[0]*r+m,t.at[1]*a],x=t.size[0]*r,$=t.size[1],E=t.size[2]*r,S=g-x/2,k=g+x/2,y=v,A=v-E,I=f+$;if(I<=o+$s)continue;const z=c(f),j=t.colors||{},P=j.front??t.color,N=j.top??jr(t.color,.16),F=j.side??jr(t.color,-.22),K=j.bottom??jr(t.color,-.35);if(t.kind==="wall-panel"){if(u([l(g,A,z),l(g,A,I),l(g,y,I),l(g,y,z)],P),t.inner){const _=(I-z)*t.inset,J=E*t.inset;u([l(g,A+J,z+_),l(g,A+J,I-_),l(g,y-J,I-_),l(g,y-J,z+_)],t.inner)}continue}if($>0&&(A>n[1]&&u([l(S,A,z),l(k,A,z),l(k,A,I),l(S,A,I)],N),y<n[1]&&u([l(S,y,z),l(k,y,z),l(k,y,I),l(S,y,I)],K),S>n[0]&&u([l(S,A,z),l(S,A,I),l(S,y,I),l(S,y,z)],F),k<n[0]&&u([l(k,A,z),l(k,A,I),l(k,y,I),l(k,y,z)],F)),u([l(S,A,z),l(k,A,z),l(k,y,z),l(S,y,z)],P),t.kind==="panel"&&t.inner){const _=Math.min(x,E)*t.inset;u([l(S+_,A+_,z),l(k-_,A+_,z),l(k-_,y-_,z),l(S+_,y-_,z)],t.inner)}}return i}function Jy(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:mI(r,e)}))}const hu=Object.freeze({size:[6,16],size0:10,palette:[2,16],sampleFrames:16,parts:64,points:900,partPoints:200,backdropPoints:4e3}),gI=Object.freeze(["plate","none","keep"]),yI=/^#[0-9a-f]{6}$/i;function bI(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=>!yI.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??hu.size0;if(!(Number.isInteger(o)&&o>=hu.size[0]&&o<=hu.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 du=Object.freeze({seconds:30,fps:[8,12,24,30],width:640,plateFrames:48,parts:64,points:100}),_0=Object.freeze(["flash","glow","smoke","shadow","blood","cloth","eyes"]),fu=Object.freeze(["dark","mid","cloth","blood"]),Ih=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}}),wI=/^#[0-9a-f]{6}$/i;function kI(t={}){const e=Ih[t.look??"ninja"];if(!e)throw Error(`rotoscope look: ${Object.keys(Ih).join(" | ")}`);if(e.flat)return{flat:bI(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: {${fu.join(" | ")}: '#RRGGBB'}`);for(const[a,n]of Object.entries(t.colors)){if(!fu.includes(a)||!wI.test(String(n)))throw Error(`rotoscope colors: {${fu.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])=>!_0.includes(a)||typeof n!="boolean"))throw Error(`rotoscope effects: {${_0.join(" | ")}: true | false}`);Object.assign(r,t.effects)}return{colors:o,effects:r}}function xI(t,e,o=480){const r=Number.isFinite,a=t.fps??24;if(!du.fps.includes(a))throw Error(`rotoscope fps: ${du.fps.join(" | ")} drawings per second (24 = smooth, 12 = on twos)`);const n=t.from??0,i=Math.min(du.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 l=t.duration??Math.round(Math.min(i,e-n)*1e4)/1e4;if(!(r(l)&&l>=.25&&l<=i+1e-6&&n+l<=e+1e-6))throw Error(`rotoscope duration: 0.25–${i} s at ${a} fps, inside the video clip`);return{fps:a,from:n,duration:l,n:Math.max(1,Math.round(l*a))}}function MI(t={}){const e=!!Ih[t.look??"ninja"]?.flat,o=t.background??"plate";if(!(e?gI:["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 di=Object.freeze({events:24,size:[.02,.6]}),vI=/^#[0-9a-f]{6}$/i,fi=Number.isFinite,ve=t=>Math.round(t*1e3)/1e3,Wi=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"}}),mu=["shadow","trail",...Object.keys(Wi)];function Qy(t,e="drawFrames"){if(t==null||t===!1)return null;const o=Object.fromEntries(Object.keys(Wi).map(a=>[a,[]]));if(t===!0)return{shadow:!0,trail:!0,...o};if(typeof t!="object"||Array.isArray(t))throw Error(`${e} fx: true | {${mu.join("?, ")}?}`);for(const a of Object.keys(t))if(!mu.includes(a))throw Error(`${e} fx: ${mu.join("?, ")}? (unknown "${String(a).slice(0,20)}")`);const r=a=>{const n=Wi[a],i=t[a];if(i==null)return[];if(!Array.isArray(i)||i.length>di.events)throw Error(`${e} fx.${a}: up to ${di.events} [{at (s), x, y (0..1 of the frame), size?}]`);return i.map((l,u)=>{const c=l?.at,s=l?.x??.5,d=l?.y??.5,f=l?.size??n.size;if(!(fi(c)&&c>=0&&fi(s)&&s>=-.2&&s<=1.2&&fi(d)&&d>=-.2&&d<=1.2))throw Error(`${e} fx.${a}[${u}]: {at (s from the start), x, y (0..1 of the frame)}`);if(!(fi(f)&&f>=di.size[0]&&f<=(a==="flash"?1:di.size[1])))throw Error(`${e} fx.${a}[${u}].size: ${di.size[0]}–${a==="flash"?1:di.size[1]} of the frame height`);if(n.color&&l.color!=null&&!vI.test(l.color))throw Error(`${e} fx.${a}[${u}].color: #RRGGBB`);if(n.angle&&l.angle!=null&&!fi(l.angle))throw Error(`${e} fx.${a}[${u}].angle: degrees`);if(n.span&&l.span!=null&&!(fi(l.span)&&l.span>=.05&&l.span<=10))throw Error(`${e} fx.${a}[${u}].span: 0.05–10 s`);return{at:c,x:s,y:d,size:f,...n.color?{color:l.color??n.color}:{},...n.angle?{angle:l.angle??0}:{},...n.span?{span:l.span??(a==="aura"?1:.4)}:{}}})};return{shadow:t.shadow!==!1,trail:t.trail!==!1,...Object.fromEntries(Object.keys(Wi).map(a=>[a,r(a)]))}}const $I=t=>t.fill&&(t.opacity??1)>.9&&Array.isArray(t.points);function G0(t){let e=1e9,o=1e9,r=-1e9,a=-1e9;for(const n of t)for(const[i,l]of n.points)i<e&&(e=i),i>r&&(r=i),l<o&&(o=l),l>a&&(a=l);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 EI(t){const e=t.filter($I).map(r=>({p:r,b:G0([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=G0(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 mi=(t,e,o,r,a=16)=>Array.from({length:a},(n,i)=>{const l=i/a*Math.PI*2;return[ve(t+Math.cos(l)*o),ve(e+Math.sin(l)*r)]});function K0(t,e,o,r,a){const n=[];for(let i=0;i<r*2;i++){const l=i/(r*2)*Math.PI*2+a,u=i%2?.38:1+(Math.sin(a*7+i*3.1)+1)/2*.35;n.push([ve(t+Math.cos(l)*o*u),ve(e+Math.sin(l)*o*u*1.05)])}return n}function SI(t,e,o,{aspect:r=16/9,maxParts:a=64}={}){if(!o)return t;let n=0;const i=t.map(u=>{const c=n;return n+=(u.hold??1)/e,c}),l=t.map(u=>EI(u.parts));return t.map((u,c)=>{const s=[],d=[],f=i[c];if(o.shadow)for(const S of l[c]){const k=Math.max(.03,S.b.w*.55);s.push({points:mi(S.b.cx,S.b.y1+.006,k/2,Math.max(.006,k*r*.07)),fill:"#000000",opacity:.22,line:!1,smooth:!0})}if(o.trail&&c>0)for(const S of l[c]){const k=l[c-1].reduce((y,A)=>{const I=Math.hypot(A.b.cx-S.b.cx,(A.b.cy-S.b.cy)/r);return I<y.d?{d:I,q:A}: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 A=k.size*(.6+.6*Math.sin(Math.min(1,y*1.6)*Math.PI/2)),I=A/r;d.push({points:K0(k.x,k.y,1,9,S*1.7).map(([z,j])=>[ve(k.x+(z-k.x)*I*1.25),ve(k.y+(j-k.y)*A*1.25)]),fill:k.color,opacity:Math.max(.02,ve(.45*(1-y))),line:!1,smooth:!1}),d.push({points:K0(k.x,k.y,1,7,S*2.3).map(([z,j])=>[ve(k.x+(z-k.x)*I*.8),ve(k.y+(j-k.y)*A*.8)]),fill:"#ffffff",opacity:ve(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 A=0;A<3;A++){const I=(A-1)*k.size*.9*(.4+y)/r,z=k.size*(.35+y*.6)*(A===1?1.1:.8);d.push({points:mi(k.x+I,k.y-z*.45,z/r,z*.55,14),fill:"#d9d2cc",opacity:Math.max(.02,ve(.55*(1-y))),line:!1,smooth:!0})}}const m=S=>Math.max(.02,ve(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,A=2.6*Math.min(1,k*2.2),I=S.size/2,z=[],j=[];for(let P=0;P<=14;P++){const N=y+A*P/14,F=Math.sin(Math.PI*P/14)*I*.22;z.push([ve(S.x+Math.cos(N)*I/r),ve(S.y+Math.sin(N)*I)]),j.push([ve(S.x+Math.cos(N)*(I-F)/r),ve(S.y+Math.sin(N)*(I-F))])}d.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),A=Math.cos(y),I=Math.sin(y),z=-I,j=A;for(let P=0;P<7;P++){const N=Math.sin((S+1)*12.9898+P*78.233+Math.floor(f*24)*3.1)*43758.5453,F=N-Math.floor(N),K=(F-.5)*k.size,_=k.size*(.5+F*.6),J=.0025+F*.003,X=k.x+z*K/r,rt=k.y+j*K,ot=X-A*_/r,G=rt-I*_,tt=X+A*_*.2/r,Q=rt+I*_*.2;d.push({points:[[ve(ot),ve(G)],[ve(tt+z*J/r),ve(Q+j*J)],[ve(tt-z*J/r),ve(Q-j*J)]],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 A=0;A<8;A++){const I=A/8*Math.PI*2+S*.7,z=k.size*(.2+y*.9),j=k.size*.18*(1-y*.5),P=k.x+Math.cos(I)*z/r,N=k.y+Math.sin(I)*z+y*y*k.size*.4;d.push({points:[[ve(P),ve(N)],[ve(P+Math.cos(I)*j/r+.002),ve(N+Math.sin(I)*j)],[ve(P+Math.cos(I)*j/r-.002),ve(N+Math.sin(I)*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),A=y*(.18*(1-k)+.04);d.push({points:[...mi(S.x,S.y,y/r,y*.55,20),...mi(S.x,S.y,(y-A)/r,(y-A)*.55,20).reverse()],fill:S.color,opacity:m(.7*(1-k)),line:!1,smooth:!0})}for(const[S,k]of o.aura.entries()){if(f<k.at||f>=k.at+k.span)continue;const y=l[c].reduce((j,P)=>{const N=Math.hypot(P.b.cx-k.x,P.b.cy-k.y);return N<j.d?{d:N,q:P}:j},{d:1e9,q:null}).q??{b:{cx:k.x,cy:k.y,w:k.size*.35/r,h:k.size*.8}},A=.85+.15*Math.sin(f*40+S),I=(y.b.w/2+k.size*.15/r)*A,z=(y.b.h/2+k.size*.12)*A;s.push({points:mi(y.b.cx,y.b.cy,I,z,18),fill:k.color,opacity:.35,line:!1,smooth:!0},{points:mi(y.b.cx,y.b.cy,I*.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||d.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&&!d.length)return u;const v=Math.max(0,a-u.parts.length),x=[...d,...s].slice(0,v),$=s.filter(S=>x.includes(S)),E=d.filter(S=>x.includes(S));return{...u,parts:[...$,...u.parts,...E]}})}const II={hits:.2,dust:.6,slash:.25,speed:0,sparks:.35,ring:.35,aura:0,flash:.1},AI={points:[[.5,.5],[.501,.5],[.5,.501]],fill:"#000000",opacity:.02,line:!1};function Aj(t,e,o={},{fps:r=30,label:a}={}){const n=Wi[t];if(!n)throw Error(`fxLayerOp kind: ${Object.keys(Wi).join(" | ")}`);const i=n.span?o.span??(t==="aura"?1:.4):0,l=Math.ceil((II[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:l},()=>({parts:[AI]})),fx:{shadow:!1,trail:!1,[t]:[u]},width:0,brush:"none",...a?{label:a}:{}}}function CI(t){const e=String(t).match(/[MLCSQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi)??[],o=[];let r=0,a="M",n=[0,0],i=[0,0],l=null,u=!1;const c=()=>Number(e[r++]),s=(d,f,m,g)=>{for(let v=1;v<=8;v++){const x=v/8,$=1-x;o.push([$*$*$*d[0]+3*$*$*x*f[0]+3*$*x*x*m[0]+x*x*x*g[0],$*$*$*d[1]+3*$*$*x*f[1]+3*$*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,l=null;continue}if(a==="M")n=[c(),c()],i=n,o.push(n),a="L",l=null;else if(a==="L")n=[c(),c()],o.push(n),l=null;else if(a==="C"){const d=[c(),c()],f=[c(),c()],m=[c(),c()];s(n,d,f,m),l=f,n=m}else if(a==="S"){const d=l?[2*n[0]-l[0],2*n[1]-l[1]]:n,f=[c(),c()],m=[c(),c()];s(n,d,f,m),l=f,n=m}else if(a==="Q"){const d=[c(),c()],f=[c(),c()];s(n,[n[0]+2/3*(d[0]-n[0]),n[1]+2/3*(d[1]-n[1])],[f[0]+2/3*(d[0]-f[0]),f[1]+2/3*(d[1]-f[1])],f),l=null,n=f}else r++;if(!Number.isFinite(n[0]))break}return{pts:o.filter(d=>d.every(Number.isFinite)),closed:u}}function V0(t,e,o=!1){const r=o?[...t,t[0]]:t;if(r.length<2)return Array.from({length:e},()=>[...r[0]??[0,0]]);const 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 l=1;for(let u=0;u<e;u++){const c=o?n*u/e:n*u/(e-1);for(;l<r.length-1&&a[l]<c;)l++;const s=r[l-1],d=r[l],f=(c-a[l-1])/(a[l]-a[l-1]||1);i.push([s[0]+(d[0]-s[0])*f,s[1]+(d[1]-s[1])*f])}return i}function jI(t,e){const o=e.length;let r=0,a=1,n=1/0;for(const i of[1,-1])for(let l=0;l<o;l++){let u=0;for(let c=0;c<o;c+=Math.max(1,o>>3)){const s=e[((l+i*c)%o+o)%o];u+=Math.hypot(s[0]-t[c][0],s[1]-t[c][1])}u<n&&(n=u,r=l,a=i)}return Array.from({length:o},(i,l)=>e[((r+a*l)%o+o)%o])}const W0=Object.freeze(["draw","erase","undoLine","duplicate","insert","delete","hold","clear","transform","clone","unlink","fill","warp","mark","inbetween"]),H0=Object.freeze(["key","breakdown","inbetween"]),X0=Object.freeze(["even","slow-out","slow-in","slow-in-out"]),U0=Object.freeze(["ramp","ramp-down","bump","hold"]),In=Object.freeze({strokes:32,points:400,hold:48,fps:[4,60]}),gu=/^#[0-9a-f]{6}$/i,Li=Number.isFinite,We=t=>Math.round(Math.round(t*120)/120*1e4)/1e4,TI=t=>Array.isArray(t?.size)?t.size:t?.square?[720,720]:[1280,720];function tb(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 Cj=t=>tb(t).length>0,Nl=t=>{let e=t.length+1;for(;t.some(o=>o.id===`s${e}`);)e++;return`s${e}`},Ta=(t,e,o)=>t.map(r=>r.span&&r.span[0]>=e-1e-6?{...r,span:[We(r.span[0]+o),We(r.span[1]+o)]}:r);function tp(t,e){if(!Array.isArray(t)||t.length<1||t.length>In.points)throw Error(`${e}.points: 1–${In.points} [x, y] pairs`);return t.map((o,r)=>{if(!Array.isArray(o)||o.length!==2||!o.every(Li))throw Error(`${e}.points[${r}]: [x, y]`);return[o[0],o[1]]})}function OI(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 qi(o,e&&o.length>2)}function zI(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,c=Array.from({length:80},(s,d)=>Math.round(d*u));r=c.map(s=>r[s]),a&&(a=c.map(s=>a[s]))}const n=r.length,i=[],l=[];for(let u=0;u<n;u++){const c=r[Math.max(0,u-1)],s=r[Math.min(n-1,u+1)],d=s[0]-c[0],f=s[1]-c[1],m=Math.hypot(d,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]+d/m*x]),l.push([r[u][0]+f/m*x,r[u][1]-d/m*x])}return qi([...i,...l.reverse()],!0)}const PI=t=>"M"+t.map(([e,o])=>`${Math.round(e)} ${Math.round(o)}`).join(" L")+" Z",Ah=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 Y0(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 l=dc(aa(t)),u=_=>{const J=a(_);return js(l,J[0],J[1])};if(e.tag!=null&&!_h.test(e.tag))throw Error(`${n} tag: a part name (armR, head…)`);const c=e.tag!=null?null:tp(e.lasso,`${n} lasso`).map(u);if(c&&c.length<3)throw Error(`${n} lasso: at least 3 points round the lines to move`);const s=e.dx??0,d=e.dy??0,f=e.rotate??0,m=e.scale??1;if(![s,d,f,m].every(Li)||m<=0||m>10)throw Error(`${n}: dx, dy (frame fractions), rotate (degrees), scale (0–10)`);const g=([_,J])=>{let X=!1;for(let rt=0,ot=c.length-1;rt<c.length;ot=rt++){const[G,tt]=c[rt],[Q,it]=c[ot];tt>J!=it>J&&_<(Q-G)*(J-tt)/(it-tt)+G&&(X=!X)}return X},v=_=>e.tag!=null?_.tag===e.tag:(()=>{const J=Ah(_.d);return J.length>0&&J.filter(g).length>=J.length*.6})(),x=t.params.parts.filter(v);if(!x.length)return{item:t,moved:0};const[$,E]=e.pivot!=null?u(tp([e.pivot],`${n} pivot`)[0]):c?[c.reduce((_,J)=>_+J[0],0)/c.length,c.reduce((_,J)=>_+J[1],0)/c.length]:Ah(x[0].d)[0],S=u([0,0]),k=u([s,d]),y=(k[0]-S[0])*o,A=(k[1]-S[1])*o,I=f*o*Math.PI/180,z=Math.pow(m,o),j=Math.cos(I)*z,P=Math.sin(I)*z,N=(_,J)=>[Math.round($+(_-$)*j-(J-E)*P+y),Math.round(E+(_-$)*P+(J-E)*j+A)];let F=0;const K=t.params.parts.map(_=>{if(!v(_))return _;F++;let J=0,X=0;const rt=_.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,ot=>{const G=Number(ot);if(J++%2===0)return X=G,"\0";const[tt,Q]=N(X,G);return`${tt} ${Q}`}).replace(/\u0000[\s,]*/g,"");return{..._,d:rt}});return{item:{...t,params:{...t.params,parts:K,box:pr(K.map(_=>_.d).join(" "))}},moved:F}}function eb(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(!W0.includes(e?.action))throw Error(`${n} action: ${W0.join(" | ")}`);const i=e.fps??24;if(!(Li(i)&&i>=In.fps[0]&&i<=In.fps[1]))throw Error(`${n} fps: ${In.fps.join("–")}`);const l=e.hold??1;if(!(Number.isInteger(l)&&l>=1&&l<=In.hold))throw Error(`${n} hold: 1–${In.hold} frames`);const u=We(l/i);let c=t.items.map(k=>({...k}));const s=tb({items:c});let d=-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)`);d=e.frame-1,f=d<s.length?s[d].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(!(Li(e.at)&&e.at>=0&&e.at<=600))throw Error(`${n}: frame (1-based) or at (seconds into the layer)`);f=e.at,d=s.findIndex(k=>f>=k.t0-1e-6&&f<k.t1-1e-6)}const m=d>=0&&d<s.length?s[d]:null,g=m?c.findIndex(k=>k.id===m.id):-1,v=TI(t),x=Ur(v),$=k=>o==="shape"?k:x.pt(k);let E="";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(!gu.test(e.color??""))throw Error(`${n} fill color: #RRGGBB`);const k=eb(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>In.strokes)throw Error(`${n} draw lines: 1–${In.strokes} [{points, width?, fill?}]`);let y=g>=0?c[g]:null;if(y&&y.type!=="art")throw Error(`${n}: frame ${d+1} is a ${y.type} item, not a drawing — draw on a drawFrames / frame-editor layer`);if(y?.params?.rig)throw Error(`${n}: frame ${d+1} is a character played from its skeleton — it cannot take lines`);const A=k.map((N,F)=>({...N,pts:tp(N?.points,`${n} lines[${F}]`).map($)}));if(!y){if(c.length>=qo.items)throw Error(`${n}: this layer already holds ${qo.items} drawings — continue on a new frame layer`);const N=s.find(rt=>rt.t0>f+1e-6),F=We(f),K=We(Math.min(f+u,N?N.t0:f+u)),_=A.flatMap(rt=>rt.pts),J=Math.round((Math.min(..._.map(rt=>rt[0]))+Math.max(..._.map(rt=>rt[0])))/2),X=Math.round((Math.min(..._.map(rt=>rt[1]))+Math.max(..._.map(rt=>rt[1])))/2);y={id:Nl(c),name:`Frame ${s.filter(rt=>rt.t0<F).length+1}`,type:"art",params:{parts:[],box:[0,0,1,1]},pos:[J,X],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:r},stroke:{color:r,width:a,cap:"round",join:"round"},role:7,span:[F,K>F?K:We(F+u)]},c.push(y)}const I=dc(aa(y)),z=y.stroke?.width||a,j=[...y.params.parts??[]];for(const[N,F]of A.entries()){const K=F.pts.map(it=>js(I,it[0],it[1])),_=F.fill??null;if(_!==null&&!gu.test(_))throw Error(`${n} lines[${N}].fill: #RRGGBB or omitted (an ink line)`);const J=F.width==null?null:o==="shape"?F.width:x.len(F.width);if(J!=null&&!(Li(J)&&J>0))throw Error(`${n} lines[${N}].width: a fraction of the frame width (e.g. 0.004)`);const X=J==null?1:Math.max(.1,Math.min(5,Math.round(J/z*100)/100)),rt=F.color??null;if(rt!==null&&!gu.test(rt))throw Error(`${n} lines[${N}].color: #RRGGBB`);const ot=F.tag??null;if(ot!==null&&!_h.test(ot))throw Error(`${n} lines[${N}].tag: a part name — a letter then letters / digits / dashes, ≤ 24 (armR, head)`);const G=ot?{tag:ot}:{},tt=F.pressures==null?null:Array.isArray(F.pressures)&&F.pressures.length===F.points.length&&F.pressures.every(it=>Li(it)&&it>=0&&it<=1)?F.pressures:(()=>{throw Error(`${n} lines[${N}].pressures: one 0..1 value per point (the pen's pressure)`)})();if(_&&F.under===!0){const it=j.findIndex(D=>!(D.eo===!0&&D.line===!1));j.splice(it<0?j.length:it,0,{d:PI(K),fill:_,line:!1,eo:!0,role:7,...G});continue}const Q=Math.hypot(I[0],I[1])||1;if(!_&&(tt||rt&&rt.toLowerCase()!==String(y.stroke?.color??r).toLowerCase())){j.push({d:zI(K,(J??z)*Q,tt),fill:rt??y.stroke?.color??r,line:!1,role:7,...G});continue}j.push({d:OI(K,!!_||F.closed===!0),fill:_,..._&&F.line===!1?{line:!1}:{},...X!==1?{lw:X}:{},role:7,...G})}if(j.length>Zi.parts)throw Error(`${n}: frame ${d+1} would hold ${j.length} lines (max ${Zi.parts}) — fewer, longer lines`);const P=pr(j.map(N=>N.d).join(" "));c=c.map(N=>N.id===y.id?{...y,params:{...y.params,parts:j,box:P}}:N),E=`${k.length} line(s) on frame ${(m?d:s.filter(N=>N.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=c[g];if(k.type!=="art"||!Array.isArray(k.params.parts))throw Error(`${n}: frame ${d+1} is not a drawing`);let y=k.params.parts;if(e.action==="undoLine")y=y.slice(0,-1);else{const I=Array.isArray(e.lines)?e.lines:[];if(!I.length)throw Error(`${n} erase lines: the eraser's path [{points}]`);const z=dc(aa(k)),j=I.flatMap((N,F)=>tp(N?.points,`${n} lines[${F}]`).map($).map(K=>js(z,K[0],K[1]))),P=e.radius==null?12:o==="shape"?e.radius:x.len(e.radius);y=y.filter(N=>!Ah(N.d).some(F=>j.some(K=>Math.hypot(F[0]-K[0],F[1]-K[1])<=P)))}const A=k.params.parts.length-y.length;c=y.length?c.map((I,z)=>z===g?{...I,params:{...I.params,parts:y,box:pr(y.map(j=>j.d).join(" "))}}:I):c.filter((I,z)=>z!==g),E=`${A} line(s) taken out of frame ${d+1}${y.length?"":" (now blank)"}`;break}case"duplicate":{if(g<0)throw Error(`${n}: no drawing on that frame to duplicate`);if(c.length>=qo.items)throw Error(`${n}: this layer already holds ${qo.items} drawings — continue on a new frame layer`);const k=c[g],y=We(k.span[1]-k.span[0]);c=Ta(c,k.span[1],y),c.push({...structuredClone(k),id:Nl(c),name:`${k.name} copy`.slice(0,40),span:[k.span[1],We(k.span[1]+y)]}),E=`frame ${d+1} duplicated`;break}case"insert":{c=Ta(c,m?m.t0:f,u),E=`blank frame put in at ${We(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 A=s.filter(z=>z.t1<=f+1e-6).reduce((z,j)=>Math.max(z,j.t1),0),I=Math.min(u,We(y.t0-A));c=Ta(c,y.t0,-I),E="blank frame taken out";break}const k=We(m.t1-m.t0);c=Ta(c.filter((y,A)=>A!==g),m.t1,-k),E=`frame ${d+1} taken out`;break}case"hold":{if(g<0)throw Error(`${n}: no drawing on that frame to hold`);const k=c[g],y=We(k.span[1]-k.span[0]),A=We(u-y);c=Ta(c,k.span[1],A).map((I,z)=>z===g?{...I,span:[k.span[0],We(k.span[0]+u)]}:I),E=`frame ${d+1} lasts ${l} frame(s)`;break}case"clear":{if(g<0)throw Error(`${n}: that frame is already blank`);c=c.filter((k,y)=>y!==g),E=`frame ${d+1} cleared (blank)`;break}case"transform":{if(g<0)throw Error(`${n}: no drawing on that frame to transform`);const k=Y0(c[g],e,1,{units:o,toShape:$,where:n,k:d});if(!k.moved)throw Error(`${n}: the ${e.tag?`part "${e.tag}"`:"lasso"} holds no line of frame ${d+1}`);c=c.map((y,A)=>A===g?k.item:y),E=`${k.moved} line(s) of frame ${d+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 A=e.ease??"ramp";if(!U0.includes(A))throw Error(`${n} warp ease: ${U0.join(" | ")}`);let I=0,z=0;for(let j=k;j<=y;j++){const P=y===k?1:(j-k)/(y-k),N=A==="hold"?1:A==="ramp"?P:A==="ramp-down"?1-P:Math.sin(Math.PI*P);if(N<=1e-4)continue;const F=c.findIndex(_=>_.id===s[j].id),K=Y0(c[F],e,N,{units:o,toShape:$,where:n,k:j});K.moved&&(c=c.map((_,J)=>J===F?K.item:_),I+=K.moved,z++)}if(!z)throw Error(`${n}: the ${e.tag?`part "${e.tag}"`:"lasso"} holds no line in frames ${k+1}–${y+1}`);E=`warp over frames ${k+1}–${y+1} (${A}): ${I} 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&&!H0.includes(k))throw Error(`${n} mark: ${H0.join(" | ")} | null (no mark)`);c=c.map((y,A)=>{if(A!==g)return y;const{mark:I,...z}=y;return k?{...z,mark:k}:z}),E=`frame ${d+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:d+1;if(!(Number.isInteger(k)&&k>d&&k<s.length))throw Error(`${n} inbetween: to = a later drawing (frame ${d+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 A=e.ease??"even";if(!X0.includes(A))throw Error(`${n} inbetween ease: ${X0.join(" | ")}`);if(c.length+y>qo.items)throw Error(`${n}: ${y} more drawings would pass ${qo.items} on this layer — fewer, or continue on a new frame layer`);const I=c[g],z=c.find(G=>G.id===s[k].id);if(I.type!=="art"||z.type!=="art"||!I.params.parts||!z.params.parts)throw Error(`${n} inbetween: both frames must be drawings`);const j=e.hold!=null?u:We(I.span[1]-I.span[0]),P=aa(I),N=aa(z),F=G=>G.fill===null?"line":"fill",K=[],_=new Set,J=(G,tt)=>G.map((Q,it)=>({q:Q,i:it})).filter(({q:Q})=>!Q.tag&&F(Q)===tt);for(const[G,tt]of I.params.parts.entries()){let Q=-1;if(tt.tag)Q=z.params.parts.findIndex((it,D)=>it.tag===tt.tag&&!_.has(D));else{const it=J(I.params.parts,F(tt)),D=J(z.params.parts,F(tt)).filter(({i:ht})=>!_.has(ht)),U=it.findIndex(ht=>ht.i===G);Q=D[Math.min(U,D.length-1)]?.i??-1,U>=D.length&&(Q=-1)}Q>=0?(_.add(Q),K.push([tt,z.params.parts[Q]])):K.push([tt,null])}const X=z.params.parts.filter((G,tt)=>!_.has(tt)),rt=(G,tt)=>{const Q=CI(G.d);return{pts:Q.pts.map(it=>js(tt,it[0],it[1])),closed:Q.closed||!!G.fill}},ot=G=>A==="even"?G:A==="slow-out"?G*G:A==="slow-in"?1-(1-G)*(1-G):G*G*(3-2*G);c=Ta(c,I.span[1],We(y*j));for(let G=1;G<=y;G++){const tt=ot(G/(y+1)),Q=[Math.round(I.pos[0]+(z.pos[0]-I.pos[0])*tt),Math.round(I.pos[1]+(z.pos[1]-I.pos[1])*tt)],it=[];for(const[U,ht]of K){if(!ht){tt<.5&&it.push({...U,d:U.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,(()=>{let C=0;return O=>{const L=Number(O)+(C++%2?I.pos[1]-Q[1]:I.pos[0]-Q[0]);return String(Math.round(L))}})())});continue}const yt=rt(U,P),Mt=rt(ht,N),p=yt.closed?48:40,lt=V0(yt.pts,p,yt.closed),V=V0(Mt.pts,p,yt.closed),h=yt.closed?jI(lt,V):V,w=yt.closed?lt.map((C,O)=>[C[0]+(h[O][0]-C[0])*tt-Q[0],C[1]+(h[O][1]-C[1])*tt-Q[1]]):(()=>{const C=[[lt[0][0]+(h[0][0]-lt[0][0])*tt,lt[0][1]+(h[0][1]-lt[0][1])*tt]];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=[h[O][0]-h[O-1][0],h[O][1]-h[O-1][1]],H=Math.atan2(L[1],L[0]),q=Math.atan2(B[1],B[0]),et=(q-H+3*Math.PI)%(2*Math.PI)-Math.PI,st=H+et*tt,Y=Math.hypot(...L)+(Math.hypot(...B)-Math.hypot(...L))*tt;C.push([C[O-1][0]+Math.cos(st)*Y,C[O-1][1]+Math.sin(st)*Y])}return C.map(O=>[O[0]-Q[0],O[1]-Q[1]])})(),T=U.lw!=null||ht.lw!=null?Math.round(((U.lw??1)+((ht.lw??1)-(U.lw??1))*tt)*100)/100:null;it.push({...U,d:yt.closed?qi(w,!0):qi(w,!1),fill:tt<.5?U.fill:ht.fill,...T!=null&&T!==1?{lw:T}:{}})}for(const U of X)tt>=.5&&it.push({...U,d:U.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,(()=>{let ht=0;return yt=>{const Mt=Number(yt)+(ht++%2?z.pos[1]-Q[1]:z.pos[0]-Q[0]);return String(Math.round(Mt))}})())});if(!it.length)continue;const D=We(I.span[1]+(G-1)*j);c.push({...structuredClone(I),id:Nl(c),name:`${I.name} · ${G}/${y+1}`.slice(0,40),params:{...I.params,parts:it,box:pr(it.map(U=>U.d).join(" "))},pos:Q,mark:"inbetween",span:[D,We(D+j)],...I.group?{group:void 0}:{}})}c=c.map(G=>G.id===I.id||G.id===z.id?{...G,mark:G.mark??"key"}:G).map(G=>{if(G.group===void 0&&"group"in G){const{group:tt,...Q}=G;return Q}return G}),E=`${y} in-between(s) drawn between frames ${d+1} and ${k+1} (${A})`;break}case"clone":{if(g<0)throw Error(`${n}: no drawing on that frame to clone`);if(c.length>=qo.items)throw Error(`${n}: this layer already holds ${qo.items} drawings — continue on a new frame layer`);const k=c[g],y=We(k.span[1]-k.span[0]),A=k.group??`ln${k.id}`.slice(0,16);c=Ta(c,k.span[1],y).map((I,z)=>z===g?{...I,group:A}:I),c.push({...structuredClone(k),id:Nl(c),group:A,name:`${k.name} ↻`.slice(0,40),span:[k.span[1],We(k.span[1]+y)]}),E=`frame ${d+1} cloned (live)`;break}case"unlink":{if(g<0||!c[g].group)throw Error(`${n}: frame ${d+1} is not a live copy`);const{group:k,...y}=c[g];c=c.map((A,I)=>I===g?y:A),E=`frame ${d+1} is its own drawing again`;break}}if(["draw","erase","undoLine","transform"].includes(e.action)){const k=m?c.find(y=>y.id===m.id):c.at(-1);if(k?.group)c=c.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(A=>A.id===m.id).group;c=c.filter(A=>A.group!==y)}}if(c.some(k=>k.span&&k.span[0]<0))throw Error(`${n}: a frame would start before the layer`);const S=c.reduce((k,y)=>Math.max(k,y.span?.[1]??0),0);return{shape:{...t,items:c},end:We(S),note:E}}const yu=Object.freeze(["ink","sweep","speed","tear","swirl"]),jj=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"]}),LI=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"}}),bu=Object.freeze({duration:[.4,2.5],fps:[12,24]}),q0=/^#[0-9a-f]{6}$/i,wu=Number.isFinite,ep=t=>Math.round(t*1e4)/1e4,Ua=(t,e)=>[ep(Math.max(-1,Math.min(2,t))),ep(Math.max(-1,Math.min(2,e)))],wn=t=>t<=0?0:t>=1?1:t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;function is(t){let e=t*2654435761>>>0||1;return()=>(e^=e<<13,e>>>=0,e^=e>>>17,e^=e<<5,e>>>=0,e/4294967296)}function vi(t,e,o,r,a,n,i=40){const l=is(a),u=[l()*6.3,l()*6.3,l()*6.3],c=[];for(let s=0;s<i;s++){const d=s/i*2*Math.PI,f=o*(1+r*(.5*Math.sin(3*d+u[0])+.28*Math.sin(5*d+u[1])+.16*Math.sin(11*d+u[2])+.1*Math.sin(19*d+u[0]*2)+(l()-.5)*.35));c.push(Ua(t+Math.cos(d)*f/n,e+Math.sin(d)*f))}return c}const os=[[-.05,-.05],[1.05,-.05],[1.05,1.05],[-.05,1.05]],ob=t=>({points:os,fill:t,line:!1,smooth:!1});function NI(t,{c1:e,c2:o,o:r,A:a,seed:n}){const i=[],l=t<.5,u=wn(l?t*2:(t-.5)*2),c=1.2*Math.max(...[[0,0],[1,0],[0,1],[1,1]].map(([s,d])=>Math.hypot((s-r[0])*a,d-r[1])));if(l){const s=Math.max(.02,c*u);i.push({points:vi(r[0],r[1],s*1.12+.02,.22,n+1,a),fill:o,opacity:.45,line:!1}),i.push({points:vi(r[0],r[1],s,.22,n,a,56),fill:e,line:!1});const d=is(n+7);for(let f=0;f<10;f++){const m=d()*6.3,g=s*(.25+d()*.5),v=.012+d()*.03,x=s*.92,$=[r[0]+Math.cos(m)*(x+g)/a,r[1]+Math.sin(m)*(x+g)],E=[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:[Ua(...E),Ua(...$),Ua(...S)],fill:e,line:!1,smooth:!1})}for(let f=0;f<14;f++){const m=d()*6.3,g=s*(1.1+d()*.7),v=(.006+d()*.035)*(.5+u);i.push({points:vi(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(ob(e))}else{const s=Math.max(.01,c*u);i.push({loops:[os,vi(r[0],r[1],s*.94,.16,n+3,a)],fill:o,opacity:.5,line:!1,eo:!0}),i.push({loops:[os,vi(r[0],r[1],s,.18,n+2,a)],fill:e,line:!1,eo:!0})}return i}function FI(t,{c1:e,c2:o,angle:r,seed:a}){const n=r*Math.PI/180,i=Math.cos(n),l=Math.sin(n),u=t<.5,c=wn(u?t*2:(t-.5)*2),s=1.6,d=-.8+s*c,f=([x,$])=>Ua(.5+x*i-$*l,.5+x*l+$*i),m=is(a),g=[],v=(x,$)=>{const E=[];for(let S=0;S<=24;S++){const k=-.9+1.8*S/24;E.push([x+$*(Math.sin(S*1.7+a)*.012+(m()-.5)*.02),k])}return E};if(u){const x=v(d,1);g.push({points:[[-1,-.9],...x,[-1,.9]].map(f),fill:e,line:!1,smooth:!1});for(let $=0;$<16;$++){const E=-.9+1.8*($+.5)/16+(m()-.5)*.04,S=.03+m()*.12*(1-Math.abs(c-.5)),k=.006+m()*.01;g.push({points:[[d-.02,E-k],[d+S,E],[d-.02,E+k]].map(f),fill:$%3?e:o,line:!1,smooth:!1})}c>.05&&c<.95&&g.push({points:[[d-.35,-.9],[d-.05,-.9],[d-.05,.9],[d-.35,.9]].map(f),fill:o,opacity:.18,line:!1,smooth:!1})}else{const x=v(d,-1);g.push({points:[...x,[1,.9],[1,-.9]].map(f),fill:e,line:!1,smooth:!1});for(let $=0;$<12;$++){const E=-.9+1.8*($+.5)/12+(m()-.5)*.05,S=.04+m()*.1,k=.005+m()*.009;g.push({points:[[d+.02,E-k],[d-S,E],[d+.02,E+k]].map(f),fill:e,line:!1,smooth:!1})}}return g}function RI(t,{c1:e,c2:o,o:r,A:a,seed:n}){const i=t<.5,l=wn(i?t*2:(t-.5)*2),u=is(n),c=[],s=26,d=i?1.4*(1-l):1.4*l,f=i?l:1-l;f>.05&&c.push({points:os,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=d*(.7+u()*.5),$=2,E=(S,k)=>Ua(r[0]+Math.cos(g+k)*S/a,r[1]+Math.sin(g+k)*S);c.push({points:[E($,-v),E(Math.max(.001,x),0),E($,v)],fill:m%4===0?o:e,opacity:i?Math.min(1,.4+l):Math.max(.05,1-l),line:!1,smooth:!1})}return Math.abs(t-.5)<.06&&c.push({points:os,fill:e,line:!1,smooth:!1}),c.slice(0,64)}function DI(t,{c1:e,c2:o,seed:r}){const a=[],n=t<.5,i=wn(n?t*2:(t-.5)*2),l=(u,c,s)=>{const d=is(c),f=[];for(let m=0;m<=30;m++)f.push([u+s*((d()-.5)*.03+(m%2?.012:0)),-.05+1.1*m/30]);return f};if(n){const u=1.08-1.13*i,c=(1-i)*.03,s=l(u,r,1).map(([d,f])=>[d+c*(f-.5),f]);a.push({points:[...s.map(([d,f])=>[d-.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(([d,f])=>[d+.012,f])],fill:o,opacity:.8,line:!1,smooth:!1})}else{const u=.62*i,c=l(.5,r+5,1),s=[[-.1,-.05],...c.map(([f,m])=>[f-u-0+(m-.5)*i*.06,m]),[-.1,1.05]],d=[...c.map(([f,m])=>[f+u+(m-.5)*-i*.06,m]),[1.1,1.05],[1.1,-.05]];for(const f of[s,d])a.push({points:f,fill:e,line:!1,smooth:!1});a.push({points:[...c.map(([f,m])=>[f-u+(m-.5)*i*.06,m]),...c.slice().reverse().map(([f,m])=>[f-u-.012+(m-.5)*i*.06,m])],fill:"#ffffff",opacity:.85,line:!1,smooth:!1}),a.push({points:[...c.map(([f,m])=>[f+u-(m-.5)*i*.06,m]),...c.slice().reverse().map(([f,m])=>[f+u+.012-(m-.5)*i*.06,m])],fill:"#ffffff",opacity:.85,line:!1,smooth:!1})}return a}function Z0(t,e,o,r,a,n,i,l,u){const s=[],d=[],f=Math.cos(a),m=Math.sin(a);for(let g=0;g<=18;g++){const v=g/18,x=n+i*v,$=l*Math.pow(Math.sin(Math.PI*Math.min(1,v*1.15)),.7);for(const[E,S]of[[s,1],[d,1-$]]){const k=Math.cos(x)*o*S,y=Math.sin(x)*r*S;E.push(Ua(t+(k*f-y*m)/u,e+k*m+y*f))}}return[...s,...d.reverse()]}function BI(t,{c1:e,c2:o,o:r,A:a,seed:n}){const i=t<.5,l=wn(i?t*2:(t-.5)*2),u=[],c=is(n),s=(i?l:1+l)*Math.PI*2.4,d=.35+(i?l:1-l)*.6,f=i?.25+l*.75:1-l*.8;for(let m=0;m<4;m++){const g=d*(.55+m*.17),v=s+m*1.3+c()*.2,x=Math.PI*(1.1+.25*m);u.push({points:Z0(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:Z0(r[0],r[1],g,g*.58,.25,v,x,Math.min(.95,f),a),fill:m%2?o:e,line:!1})}if(i&&l>.85&&u.push(ob(e)),!i){const m=Math.max(.01,l*1.4);u.unshift({loops:[os,vi(r[0],r[1],m,.12,n+9,a)],fill:e,line:!1,eo:!0})}return u}const _I={ink:NI,sweep:FI,speed:RI,tear:DI,swirl:BI};function GI(t,{aspect:e=16/9}={}){const o="drawnTransition";if(!t||typeof t!="object")throw Error(`${o}: {kind ${yu.join("|")}, duration?, …}`);const r=t.kind??"ink";if(!yu.includes(r))throw Error(`${o} kind: ${yu.join(" | ")}`);const a=t.duration??1;if(!(wu(a)&&a>=bu.duration[0]&&a<=bu.duration[1]))throw Error(`${o} duration: ${bu.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=LI[r],l=t.color??i.color,u=t.color2??i.color2;if(!q0.test(l)||!q0.test(u))throw Error(`${o} color / color2: #RRGGBB`);const c=t.from??[.5,.5];if(!Array.isArray(c)||c.length!==2||!c.every(m=>wu(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(!(wu(s)&&s>=-80&&s<=80))throw Error(`${o} angle: −80..80 degrees (the sweep's tilt)`);const d=Math.max(6,Math.round(a*n)),f=e;return Array.from({length:d},(m,g)=>{const v=d>1?g/(d-1):.5,x=1e3+Math.floor(g/(n===24?2:1))*37,E=_I[r](v,{c1:l,c2:u,o:c,A:f,seed:x,angle:s}).slice(0,64).map(S=>{if(S.opacity==null)return S;const k=Math.round(S.opacity*100)/100;if(k>=.99){const{opacity:y,...A}=S;return A}return{...S,opacity:Math.max(.02,k)}});return{parts:E.length?E:[{points:[[.5,.5],[.501,.5],[.5,.501]],fill:l,opacity:.02,line:!1}]}})}const KI=(t,e)=>({start:Math.max(0,ep(t-e/2)),cut:ep(t)}),J0=Object.freeze([..._g,...Gh,"still","morph","boil","step"]),je=Object.freeze({paths:qo.items,points:qo.points,d:4e3,items:qo.items}),wo=/^#[0-9a-fA-F]{6}$/,Wt=t=>Number.isFinite(t),Io=(t,e,o)=>Math.max(e,Math.min(o,t)),ze=t=>Math.round(t*10)/10;function rb(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 An=t=>Array.isArray(t?.size)?t.size:t?.square?[720,720]:[1280,720],Qr=(t,e,o)=>{if(!Array.isArray(t)||t.length!==2||!t.every(r=>Wt(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},dn=/-?\d*\.?\d+(?:e[-+]?\d+)?/gi;function nb(t,e){if(typeof t!="string"||t.length>je.d||!/^\s*M[MLCQZ0-9eE.,\s+-]*$/.test(t))throw Error(`drawShape d: absolute SVG path data (M L C Q Z only), at most ${je.d} characters, coordinates 0..1 of the frame`);const o=[...t.matchAll(dn)].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(Qr([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(dn,()=>String(r[a++]))}function VI(t){const[e,o,r,a]=pr(t),n=ze((e+r)/2),i=ze((o+a)/2);let l=0;const u=t.replace(dn,c=>String(Math.round(Number(c)-(l++%2?i:n))));return{d:u,pos:[n,i],box:pr(u)}}function ab(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,l=t.brush??"marker";if(!wo.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($=>Array.isArray($)&&$.length===2&&wo.test($[0])&&Wt($[1])&&$[1]>=0&&$[1]<=1)&&(i.angle==null||Wt(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&&!wo.test(i))throw Error(`drawShape paths[${r}].fill must be #RRGGBB, a gradient {stops, angle?} or null`);if(t.opacity!=null&&!(Wt(t.opacity)&&t.opacity>=0&&t.opacity<=1))throw Error(`drawShape paths[${r}].opacity is 0–1`);if(l!=="none"&&!Ds.includes(l))throw Error(`drawShape brush must be none | ${Ds.join(" | ")}`);if(t.texture!=null&&(!zw(t.texture)||!i))throw Error(`drawShape paths[${r}].texture: {type hatch|crosshatch|halftone|grain|stipple|wash|paper|riso|grid, scale?, angle?, amount?, color?} on a filled path`);const c=t.width==null?.006:Number(t.width);if(!Wt(c)||c<0||c>.06)throw Error(`drawShape paths[${r}].width is a fraction of the frame width, 0–0.06`);for(const $ of["taper","press"])if(t[$]!=null&&!(Wt(t[$])&&t[$]>=0&&t[$]<=1))throw Error(`drawShape ${$} 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=Ya(e);let d,f;if(t.d!=null){const $=VI(nb(t.d,o));if(!Pw($.d))throw Error(`drawShape paths[${r}].d is not valid path data`);d={d:$.d,box:$.box,...t.closed!=null?{closed:!!t.closed}:{}},f=$.pos}else{const $=Array.isArray(t.points)?t.points:null;if(!$||$.length<2||$.length>je.points)throw Error(`drawShape paths[${r}]: points [[x,y]…] (2–${je.points}, 0..1 of the frame) or d`);const E=$.map((z,j)=>o.pt(Qr(z,j,`drawShape paths[${r}]`))),S=E.map(z=>z[0]),k=E.map(z=>z[1]),y=ze((Math.min(...S)+Math.max(...S))/2),A=ze((Math.min(...k)+Math.max(...k))/2),I=t.closed??!!i;d={pts:Kg(E.map(z=>[z[0]-y,z[1]-A]),{smooth:t.smooth!==!1,closed:I}),closed:I},f=[y,A]}const m=l==="none"?void 0:{style:l,...t.taper!=null?{taper:t.taper}:{},...t.press!=null?{press:t.press}:{},...t.boil?{boil:t.boil}:{},seed:r+1},g=o.len(c),v=()=>u?{type:i.type??"linear",stops:i.stops.map($=>[$[0],$[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:d,pos:f,rot:0,scale:[1,1],opacity:t.opacity??1,fill:i?v():{type:"none"},stroke:g>0?{color:n,width:Io(ze(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 WI(t,e,o,r){if(t.solids==null)return[];if(!Array.isArray(t.solids)||t.solids.length>Ls.solids)throw Error(`drawShape solids: [{kind, at, size, …}] (≤ ${Ls.solids})`);if(t.view!=null&&!Qc[t.view]&&t.view!=="perspective")throw Error(`drawShape view: ${[...Object.keys(Qc),"perspective"].join(" | ")}`);if(t.view==="perspective"){const[l,u]=[o.k*1e3+2*o.ox,o.k*1e3+2*o.oy].map(Math.round),c=ib(t),s=t.solids.map((m,g)=>Zy(m,g)),d=[],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 Jy(s,{vanish:c,W:l,H:u})){if(!g.length)continue;const v=g.map(I=>({d:"M"+I.pts.map(z=>o.pt(z).map(Math.round).join(" ")).join(" L")+" Z",fill:I.fill,line:!1,role:7})),x=v.flatMap(I=>I.d.match(/-?\d+/g).map(Number)),$=x.filter((I,z)=>z%2===0),E=x.filter((I,z)=>z%2===1),S=Math.round((Math.min(...$)+Math.max(...$))/2),k=Math.round((Math.min(...E)+Math.max(...E))/2),y=v.map(I=>{let z=0;return{...I,d:I.d.replace(/-?\d+/g,j=>String(Number(j)-(z++%2?k:S)))}}),A=Ya([...e,...d]);d.push({id:A,name:m.name??`${f[m.kind][r?0:1]} ${e.length+d.length+1}`,type:"art",params:{parts:y,box:[Math.min(...$)-S,Math.min(...E)-k,Math.max(...$)-S,Math.max(...E)-k],outline:!1},pos:[S,k],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:m.color},stroke:null,role:7})}return d}if(t.light!=null&&!["left","right"].includes(t.light))throw Error("drawShape light: left | right (the lit side)");if(t.shadowColor!=null&&!wo.test(t.shadowColor))throw Error("drawShape shadowColor: #RRGGBB");const a=t.solids.map((l,u)=>({s:dI(l,u),i:u}));t.order!=="given"&&a.sort((l,u)=>(u.s.kind==="plane"&&!u.s.z)-(l.s.kind==="plane"&&!l.s.z)||l.s.at[1]-u.s.at[1]||l.s.z-u.s.z||l.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:l}of a){const u=fI(l,o,{view:t.view??"iso",light:t.light??"left",shadowColor:t.shadowColor??"#1e1719"}),c=Ya([...e,...n]);n.push({id:c,name:l.name??`${i[l.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:l.color},stroke:null,role:7})}return n}const ku=Object.freeze(["band","brush","iris","slats","grid"]);function HI(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 ${ku.join("|")}, duration?, color?, color2?, count?, at?}`);const l=i.style??"band";if(!ku.includes(l))throw Error(`drawShape wipe.style: ${ku.join(" | ")}`);const u=i.duration??t.duration??.9;if(!(Wt(u)&&u>=.2&&u<=4))throw Error("drawShape wipe.duration: 0.2–4 s (the frame is covered at the middle)");const c=i.color??"#c8202f",s=i.color2??c;if(!wo.test(c)||!wo.test(s))throw Error("drawShape wipe.color / color2: #RRGGBB");const d=i.at??[.5,.5];if(!Array.isArray(d)||d.length!==2||!d.every(k=>Wt(k)&&k>=-.5&&k<=1.5))throw Error("drawShape wipe.at: [x, y] (the iris centre, 0..1)");const f=i.count??(l==="slats"?7:l==="grid"||l==="brush"?6:4);if(!(Number.isInteger(f)&&f>=2&&f<=12))throw Error("drawShape wipe.count: 2–12");const m=u/2,g=[...e.items],v=[],x=[],$=(k,y)=>{const A=ab({brush:"none",width:0,smooth:!1,...k},g,o,g.length,a);g.push(A),v.push(A.id),x.push(y)},E=Qt["expo-in-out"];if(l==="band"){const k=Math.tan((i.angle??20)*Math.PI/180)*.7,y=.5+k+.05;$({points:[[.5-y+k,-.2],[.5+y+k,-.2],[.5+y-k,1.2],[.5-y-k,1.2]],fill:c},{move:[{t:0,dx:-(2*y+k),ease:"ease-in-out"},{t:u,dx:2*y+k}]})}else if(l==="brush"){const k=1/f;for(let y=0;y<f;y++){const A=k*(y+.5),I=y%2?.012:-.012;$({points:[[-.15,A+I],[.3,A-I],[.7,A+I],[1.15,A-I]],color:y%2?s:c,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(l==="iris"){const y=d[0],A=d[1],I=Array.from({length:24},(z,j)=>{const P=j/24*2*Math.PI;return[y+Math.cos(P)*1.25*.5625,A+Math.sin(P)*1.25]});$({points:I,fill:c,smooth:!0},{scale:[{t:0,v:0,ease:"expo-in"},{t:m,v:1,ease:"expo-out"},{t:u,v:0}]})}else if(l==="slats")for(let k=0;k<f;k++){const y=k/f,A=(k+1)/f+.002;$({points:[[y,-.05],[A,-.05],[A,1.05],[y,1.05]],fill:k%2?s:c},{scale:[{t:0,sx:0,sy:1,ease:"expo-out"},{t:m*.6+k*m*.4/f,sx:1,sy:1},{t:m+k*m*.4/f,sx:1,sy:1,ease:"expo-in"},{t:Math.min(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 A=0;A<y;A++)for(let I=0;I<k;I++){const z=I/k,j=A/y,P=(I+1)/k+.003,N=(A+1)/y+.003,F=(I+A)/(k+y-2);if(g.length-e.items.length>=je.items)break;$({points:[[z,j],[P,j],[P,N],[z,N]],fill:(I+A)%2?s:c},{scale:[{t:0,v:0,ease:"back-out"},{t:m*.5+F*m*.5,v:1},{t:m+F*m*.45,v:1,ease:"expo-in"},{t:Math.min(u,m+m*.5+F*m*.45),v:0}]})}}if(g.length>je.items)throw Error(`drawShape wipe: too many pieces (max ${je.items})`);let S={...e,items:g};return v.forEach((k,y)=>{const A=x[y];if(A.trim){const[I,z,j,P]=A.trim.map(N=>Math.round(N*1e4)/1e4);S={...S,items:S.items.map(N=>N.id!==k?N:{...N,ops:[{op:"trim",start:0,end:1,offset:0}],keys:{"ops.0.end":[{time:I,value:0,ease:E},{time:z,value:1}],"ops.0.start":[{time:j,value:0,ease:E},{time:P,value:1}]}})}}else S={...S,items:lb(S,[k],A,{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 ${l}: covers at ${Math.round((XI(t.start)+m)*100)/100}s (cut there), ${u}s`}}const XI=t=>Number.isFinite(t)?t:0,ib=t=>{const e=t.vanish??[.5,.45];if(!Array.isArray(e)||e.length!==2||!e.every(o=>Wt(o)&&o>=-.5&&o<=1.5))throw Error("drawShape vanish: [x, y] of the vanishing point (0..1 of the frame)");return e};function UI(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>na.solids)throw Error(`drawShape solids: 1–${na.solids} perspective solids`);if(t.paths!=null)throw Error("drawShape fly: draw paths in their own drawShape (over the flying set)");const i=t.fly;if(!i||typeof i!="object")throw Error("drawShape fly: {to (depth units the camera travels), duration s, ease?, fps?, from?}");const[l,u]=na.fly;for(const S of["to","from"])if(i[S]!=null&&!(Wt(i[S])&&i[S]>=l&&i[S]<=u))throw Error(`drawShape fly.${S}: ${l}–${u} depth units`);if(!(Wt(i.duration)&&i.duration>=.2&&i.duration<=20))throw Error("drawShape fly.duration: 0.2–20 s");const c=i.fps??24;if(!(Number.isInteger(c)&&c>=8&&c<=24))throw Error("drawShape fly.fps: 8–24");const s=sb(i.ease??"easy-ease","drawShape fly"),d=ib(t),f=t.solids.map((S,k)=>Zy(S,k)),m=i.from??0,g=i.to??2,v=Math.max(2,Math.min(mo.frames,Math.round(i.duration*c))),x=[],$=Array.isArray(s)?s:null;for(let S=0;S<v;S++){const k=S/(v-1),y=$?YI($,k):k,A=Jy(f,{vanish:d,cam:m+(g-m)*y,W:a,H:n}).flatMap(I=>I.parts).filter(I=>I.pts.length>=3).map(I=>({points:I.pts,fill:I.fill,smooth:!1,line:!1}));if(A.length>mo.parts)throw Error(`drawShape fly: ${A.length} shapes in a frame (max ${mo.parts}) — fewer doors / lines / copies`);x.push({parts:A.length?A:[{points:[[0,0],[0,0],[0,0]],fill:"#000000",smooth:!1}]})}const E=$i({start:t.start,fps:c,frames:x,width:0,brush:"none",label:t.label??(o?"Fly-through":"Máy quay bay vào")},{size:e,en:o,finish:r});return{...E,note:`drawShape fly: camera ${m}→${g} in ${i.duration}s — ${E.note}`}}function YI([t,e,o,r],a){const n=(u,c,s)=>3*u*(1-s)**2*s+3*c*(1-s)*s*s+s**3;let i=0,l=1;for(let u=0;u<30;u++){const c=(i+l)/2;n(t,o,c)<a?i=c:l=c}return n(e,r,(i+l)/2)}const Q0=Object.freeze(["move","rot","scale","opacity","color","morph"]),sb=(t,e)=>{if(t==null)return;const o=typeof t=="string"?Qt[t]:t;if(o==null)throw Error(`${e}.ease: ${Object.keys(Qt).join(" | ")} or [x1,y1,x2,y2]`);return Tu(o)};function qI(t,e,o){const r=o?[...t,t[0]]:t,a=[];let n=0;for(let s=1;s<r.length;s++){const d=Math.hypot(r[s][0]-r[s-1][0],r[s][1]-r[s-1][1]);a.push(d),n+=d}if(!(n>0))return Array.from({length:e},()=>[...t[0]]);const i=[],l=n/(o?e:e-1);let u=0,c=0;for(let s=0;s<e;s++){const d=Math.min(n,s*l);for(;u<a.length-1&&c+a[u]<d;)c+=a[u],u++;const f=a[u]?(d-c)/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 lb(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=>!Q0.includes(g)))throw Error(`animateShape keys: {${Q0.join(" | ")}: [{t (clip s), …, ease?}]}`);const[l,u]=An(t),c=i.k,s=g=>(g*l-i.ox)/c,d=g=>(g*u-i.oy)/c,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[E]||[]).filter(y=>!S.some(A=>Math.abs(A.time-y.time)<.008333333333333333)):[];if(x[E]=[...k,...S].sort((y,A)=>y.time-A.time),x[E].length>qo.keys)throw Error(`animateShape keys: at most ${qo.keys} keys per property`)};for(const[E,S]of Object.entries(o)){const k=`animateShape keys.${E}`;if(!Array.isArray(S)||!S.length||S.length>qo.keys)throw Error(`${k}: 1–${qo.keys} keys [{t, …}]`);let y=-1;const A=S.map((z,j)=>{if(!z||typeof z!="object"||!Wt(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:sb(z.ease,`${k}[${j}]`)}}),I=z=>A.map(({q:j,time:P,ease:N},F)=>({time:P,value:z(j,F),...N!==void 0?{ease:N}:{}}));if(E==="move"){const z=I((P,N)=>{if(P.x!=null){if(!Wt(P.x))throw Error(`${k}[${N}].x`);return f(s(P.x))}if(P.dx!=null&&!Wt(P.dx))throw Error(`${k}[${N}].dx`);return f(g.pos[0]+(P.dx??0)*l/c)}),j=I((P,N)=>{if(P.y!=null){if(!Wt(P.y))throw Error(`${k}[${N}].y`);return f(d(P.y))}if(P.dy!=null&&!Wt(P.dy))throw Error(`${k}[${N}].dy`);return f(g.pos[1]+(P.dy??0)*u/c)});$("pos.0",z),$("pos.1",j)}else if(E==="rot")$("rot",I((z,j)=>{if(!Wt(z.v))throw Error(`${k}[${j}].v: degrees added to its rest rotation`);return f((g.rot||0)+z.v)}));else if(E==="scale"){const z=j=>(P,N)=>{const F=P[j]??P.v;if(!(Wt(F)&&Math.abs(F)<=10))throw Error(`${k}[${N}]: v (× its size) or sx / sy, -10..10`);return f((g.scale?.[j==="sx"?0:1]??1)*F)};$("scale.0",I(z("sx"))),$("scale.1",I(z("sy")))}else if(E==="opacity")$("opacity",I((z,j)=>{if(!(Wt(z.v)&&z.v>=0&&z.v<=1))throw Error(`${k}[${j}].v: 0–1`);return z.v}));else if(E==="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`);$(z,I((j,P)=>{if(!wo.test(j.v??""))throw Error(`${k}[${P}].v: #RRGGBB`);return j.v}))}else if(E==="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=A.map(({q:N},F)=>{if(!Array.isArray(N.points)||N.points.length<2||N.points.length>je.points)throw Error(`${k}[${F}].points: [[x,y]…] (0..1 of the frame)`);return N.points.map((K,_)=>(Qr(K,_,`${k}[${F}]`),[s(K[0])-g.pos[0],d(K[1])-g.pos[1]]))}),j=Math.min(je.points,Math.max(...z.map(N=>N.length),g.params.closed?12:4)),P=z.map(N=>Kg(qI(N,j,!!g.params.closed).map(F=>[f(F[0]),f(F[1])]),{smooth:!0,closed:!!g.params.closed}));$("params.pts",I((N,F)=>P[F]))}}return{...g,keys:x}})}const gi=t=>{if(!t||!Kh(t.shape))throw Error("Needs a Shape layer (clipId of a shape v2 layer)");return t.shape},xu=(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 sd(t,e){const o=rb(t),r=!!e.en,a=jw(e.W||1280,e.H||720);if(o.style!=null&&!kp(o.style))throw Error(`Unknown 2D style "${String(o.style).slice(0,40)}". Styles: ${yd.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"?gi(n):{v:2,size:a,items:[]},l=Ur(An(i)),u=(c,s,{colors:d=null}={})=>{const f=o.style??c.style2d,m=f?xd(c,f,{itemIds:n?s:null,timing:!n||o.style!=null,colors:d??(o.colors==="keep"?"keep":null)}):c;return Ue(m)};switch(o.op){case"drawShape":{if(o.fly!=null)return UI(o,{size:a,en:r,finish:u,W:e.W||1280,H:e.H||720});if(o.wipe!=null)return HI(o,{target:i,B:l,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 c=Array.isArray(o.paths)?o.paths:o.d!=null||o.points!=null?[o]:o.solids!=null?[]:null;if(!c)throw Error("drawShape needs paths [{points | d, …}] or solids [{kind, at, size, …}]");if(c.length>je.paths)throw Error(`drawShape: at most ${je.paths} paths per op`);const s=[...i.items],d=[];for(const m of WI(o,s,l,r))s.push(m),d.push(m.id);if(c.forEach((m,g)=>{const v=ab(m,s,l,g,r);s.push(v),d.push(v.id)}),!d.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[E,S,k]of[["at",0,600],["duration",.05,10],["stagger",0,5]])if(m[E]!=null&&!(Wt(m[E])&&m[E]>=S&&m[E]<=k))throw Error(`drawShape write.${E}: ${S}–${k} s`);const g=m.at??0,v=m.duration??.5,x=m.stagger??v*.6;let $=0;for(let E=0;E<s.length;E++){const S=s[E];if(!d.includes(S.id)||S.type!=="path")continue;const k=g+x*$++;let y=S.stroke?kd(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:Qt["ease-out"]},{time:Math.round((k+v)*1e4)/1e4,value:1}]}}),s[E]=y}}if(s.length>je.items)throw Error(`A Shape layer holds up to ${je.items} items — draw into a new layer (leave clipId out)`);const f=u({...i,items:s},d);return n?{patches:[{id:n.id,shape:f}],note:`drawShape: ${d.length} item(s) → ${n.label}`}:{patches:[],layer:{shape:f,label:String(o.label??(r?"Drawing":"Hình vẽ")).slice(0,60)},note:`drawShape: ${d.length} item(s), new layer`}}case"addLibraryShape":{const c=Array.isArray(o.items)&&o.items.length&&typeof o.items[0]=="object"?o.items:o.libraryId||o.id?[o]:null;if(!c)throw Error("addLibraryShape needs items [{id (from search_shape_library), x, y, size?}]");if(c.length>je.items)throw Error(`addLibraryShape: at most ${je.items} items per op`);const s=[...i.items],d=[],[f,m]=An(i),g=Math.min(f,m)/1e3;if(c.forEach((x,$)=>{const E=x.libraryId??x.id,S=x.x??.5,k=x.y??.5;Qr([S,k],$,"addLibraryShape");const y=x.size??.25;if(!(Wt(y)&&y>=.02&&y<=1.5))throw Error("addLibraryShape size = height as a fraction of the frame, 0.02–1.5");const A=x.rotation??0;if(!(Wt(A)&&Math.abs(A)<=360))throw Error("addLibraryShape rotation is degrees");const I=Vy(E,{id:Ya(s),pos:l.pt([S,k]),colors:x.colors??null,en:r}),z=Math.max(1,I.params.box[3]-I.params.box[1]),j=Io(ze(y*m/g/z*100)/100,.02,10),P={...I,rot:ze(A),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),d.push(P.id)}),s.length>je.items)throw Error(`A Shape layer holds up to ${je.items} items — add into a new layer (leave clipId out)`);const v=u({...i,items:s},d);return n?{patches:[{id:n.id,shape:v}],note:`addLibraryShape: ${d.length} → ${n.label}`}:{patches:[],layer:{shape:v,label:String(o.label??(r?"2D scene":"Cảnh 2D")).slice(0,60)},note:`addLibraryShape: ${d.length}, new layer`}}case"applyStyle2d":{if(!o.style)throw Error(`applyStyle2d needs style: ${yd.join(", ")}`);const s=(Array.isArray(o.clipIds)&&o.clipIds.length?o.clipIds:o.clipId?[o.clipId]:e.clips.filter(m=>Kh(m.shape)&&!cb(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 gi(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 d=s.map(m=>({id:m.id,shape:Ue(xd(m.shape,o.style,{itemIds:o.itemIds&&o.clipId?xu(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:Ue(Cw(o.style,a)),label:`${r?"Paper":"Giấy"} · ${r?kp(o.style).en:kp(o.style).vi}`.slice(0,60),start:m,duration:g-m}}return{patches:d,paper:f,note:`applyStyle2d ${o.style}: ${d.length} layer(s)${f?" + paper":""}`}}case"animateShape":{let c=gi(n);const s=xu(c,o.itemIds,"animateShape"),d=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(!Iw(S))throw Error("animateShape boil = {amount 0–24 (frame units ×1000), fps 1–24}");const k={...c,boil:S};return S.amount||delete k.boil,{patches:[{id:n.id,shape:Ue(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={...c,step:S};return S===1&&delete k.step,{patches:[{id:n.id,shape:Ue(k)}],note:`on ${S}s: ${n.label}`}}const m=d(o.at),g=Wt(o.duration)?o.duration:1,v=Wt(o.stagger)?Io(o.stagger,0,5):0;if(o.keys!=null){const S=lb(c,s,o.keys,{stagger:v,add:o.add===!0,dur:n.duration,B2:Ur(An(c))});return{patches:[{id:n.id,shape:Ue({...c,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: ${J0.join(" | ")}`);const x=Gh.includes(f)||f==="still"||f==null;if(x||o.pivot!=null||o.parent!=null){if(o.parent!=null&&!(typeof o.parent=="string"&&c.items.some(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=Ur(An(c)),k=Gg[f],y=Wt(o.amount)?Io(o.amount,0,8):1,A=Wt(o.period)?Io(o.period,.1,60):null,I=s.length;let z=0;const j=c.items.map(P=>{if(!s.includes(P.id))return P;let N={...P};o.parent!=null&&(N.parent=o.parent);const F=o.pivot??(k&&!P.pivot?k.pivot:null);if(F!=null&&(N=jh(N,Ch(N,F,S))),f==="still"){const{motion:K,..._}=N;return _}if(k&&x){const K=A??k.period,_=I>1?v?z*v/K%1:f==="rise"?z/I:0:0,J={type:f,...y!==1?{amount:Math.round(k.amount*y*1e4)/1e4}:{},...A?{period:A}:{},..._?{phase:Math.round(_*1e3)/1e3}:{},...o.at!=null&&m>0?{delay:Math.round(m*1e3)/1e3}:{}},X=[...(N.motion||[]).filter(rt=>rt.type!==f),J];if(X.length>wd.perItem)throw Error(`An item takes up to ${wd.perItem} looping motions (preset still clears them)`);N.motion=X}return z++,N});if(x)return{patches:[{id:n.id,shape:Ue({...c,items:j})}],note:`${f??"rig"}: ${s.length} item(s) of ${n.label}`};c={...c,items:j}}if(f==="morph"){if(s.length!==1)throw Error("animateShape morph takes one itemId");const S=c.items.find(I=>I.id===s[0]),k=Ur(An(c));let y;if(o.toItemId){const I=c.items.find(z=>z.id===o.toItemId);if(!I?.params?.pts)throw Error("morph toItemId must be a point path");y=I.params.pts.map(z=>[z[0]+I.pos[0]-S.pos[0],z[1]+I.pos[1]-S.pos[1]])}else{if(!Array.isArray(o.to)||o.to.length<2||o.to.length>je.points)throw Error("morph needs to [[x,y]…] (0..1 of the frame) or toItemId");y=o.to.map((I,z)=>{Qr(I,z,"morph");const j=k.pt(I);return[j[0]-S.pos[0],j[1]-S.pos[1]]})}const A=c.items.map(I=>I.id===S.id?Aw(I,y,{at:m,duration:g}):I);return{patches:[{id:n.id,shape:Ue({...c,items:A})}],note:`morph ${S.name}`}}if(!_g.includes(f))throw Error(`animateShape preset: ${J0.join(" | ")}`);let $=0;const E=c.items.map(S=>s.indexOf(S.id)<0?S:kd(S,f,{at:Math.min(n.duration-1/30,m+v*$++),duration:g,amount:Wt(o.amount)?o.amount:1,count:Wt(o.count)?o.count:1}));return{patches:[{id:n.id,shape:Ue({...c,items:E})}],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 c=gi(n),s=o.ink??"#1d1a17";if(!wo.test(s))throw Error("editFrames ink: #RRGGBB");const d=o.width??.004;if(!(Wt(d)&&d>0&&d<=.03))throw Error("editFrames width: ink line width, a fraction of the frame width (e.g. 0.004)");const f=eb(c,{...o,at:o.at},{ink:s,width:Io(ze(Ur(An(c)).len(d)),.5,240)});return{patches:[{id:n.id,shape:Ue(f.shape),...f.end>n.duration+1e-6?{duration:Math.ceil(f.end*30)/30}:{}}],note:`editFrames ${o.action}: ${f.note}`}}case"drawnTransition":{if(!Wt(o.at)||o.at<0)throw Error("drawnTransition at: the cut, timeline seconds");const c=GI(o,{aspect:a[0]/a[1]}),s=o.duration??1,{start:d}=KI(o.at,s),f=$i({op:"drawFrames",fps:o.fps??24,frames:c,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+d})),startAbs:!0,...o.motion!==!1?{shakeAt:o.at}:{},note:`drawnTransition ${o.kind??"ink"}: ${c.length} drawings, covers the frame at ${o.at}s (cut there)${o.motion!==!1?", the shots shake at the cut":""}`}}case"traceImage":return oA(o,{into:n,target:i,size:a,ctx:e,en:r,finish:u});case"drawFrames":return $i(o,{size:a,en:r,finish:u});case"animatePuppet":{const c=o.look==="stick"||o.character?.startsWith?.("stick")||Array.isArray(o.cast)&&o.cast.some(F=>String(F?.character??"").startsWith("stick")),s=o.fps??(c?30:Ra[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 d=o.look==="clean",f=d?o.width??.0022:o.width??.0028,m=e.W||1280,g=e.H||720,v=F=>d?F.map(K=>({...K,parts:K.parts.map(_=>_.fill?{..._,line:!1}:_)})):F,x=(F,K)=>{const _=!!Ra[F.character],J=_?_8:Pu,X=F.colors??null;if(X!=null&&(typeof X!="object"||Array.isArray(X)||Object.entries(X).some(([rt,ot])=>!J.includes(rt)||!wo.test(ot))))throw Error(`${K} colors: {${J.join(" | ")}: '#RRGGBB'}`);for(const[rt,ot,G]of[["x",-.5,1.5],["ground",.2,1.2],["size",.04,1.2]])if(F[rt]!=null&&!(Wt(F[rt])&&F[rt]>=ot&&F[rt]<=G))throw Error(`${K} ${rt}: ${ot}–${G} (fractions of the frame)`);if(F.facing!=null&&!["left","right"].includes(F.facing))throw Error(`${K} facing: left | right`);if(F.hair!=null&&!mc.includes(F.hair))throw Error(`${K} hair: ${mc.join(" | ")} (stick figures)`);if(F.eyes!=null&&!gc.includes(F.eyes))throw Error(`${K} eyes: ${gc.join(" | ")} (stick figures)`);if(F.grip!=null&&!hf.includes(F.grip))throw Error(`${K} grip: ${hf.join(" | ")} (how the weapon is held when resting, walking, waiting)`);if(F.height!=null&&!(Wt(F.height)&&F.height>=.6&&F.height<=1.4))throw Error(`${K} height: 0.6–1.4 (× size)`);if(F.weight!=null&&!(Wt(F.weight)&&F.weight>=.6&&F.weight<=2))throw Error(`${K} weight: 0.6–2 (how thick a stick figure is drawn)`);return{pres:_,colors:X}},$=[];let E=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&&!(Wt(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(Sw.frames,1800):480,A=[];if(o.scene!=null&&!Sh.includes(o.scene))throw Error(`animatePuppet scene: ${Sh.join(" | ")} (a painted backdrop in depth layers that moves with the camera)`);const I=String(o.label??(r?"Puppet":"Nhân vật")).slice(0,40);if(o.cast!=null){if(!Array.isArray(o.cast)||o.cast.length<1||o.cast.length>4)throw Error("animatePuppet cast: 1–4 characters [{character, x, facing?, actions?, …}] (beats: 2–4 fighters)");if(o.cast.forEach((F,K)=>{if(!F||typeof F!="object")throw Error(`animatePuppet cast[${K}] must be an object`);x(F,`animatePuppet cast[${K}]`)}),o.beats!=null){if(o.cast.some(K=>Ra[K.character]))throw Error("animatePuppet beats: fighters are side-view puppets (fighter | monk | villager | brawler)");if(o.accent!=null&&!wo.test(o.accent))throw Error("animatePuppet accent: #RRGGBB (the impact sparks)");if(o.energy!=null&&!wo.test(o.energy))throw Error("animatePuppet energy: #RRGGBB (the glow of beams, energy slashes, teleports)");if(o.dust!=null&&!wo.test(o.dust))throw Error("animatePuppet dust: #RRGGBB (the dust puffs on the ground)");if(o.tempo!=null&&!(Wt(o.tempo)&&o.tempo>=.5&&o.tempo<=2.5))throw Error("animatePuppet tempo: 0.5–2.5 (× speed of the whole fight; stick figures default 1.35)");if(o.motion!=null&&!["mocap","drawn"].includes(o.motion))throw Error("animatePuppet motion: mocap (real motion capture for stick fighters, the default) | drawn (the drawn moves)");if(o.camera!=null&&!["follow","fixed","director"].includes(o.camera))throw Error("animatePuppet camera: follow (frames the pair, glides after them, punches in on a hit; stick fights default) | director (cuts like a filmed fight: a close-up on each blow, a reaction shot, wide between exchanges) | fixed");const F=Q8({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:F.camera,duration:F.duration,ground:Math.max(...o.cast.map(K=>K.ground??.9))},F.actors.forEach((K,_)=>$.push({frames:K.frames,track:F.tracks[_],start:0,label:`${I} ${_+1}`})),A.push(...F.reports),F.fx.forEach((K,_)=>$.push({frames:K.frames,start:K.start,label:`${r?"Impact":"Va chạm"} ${_+1}`,ink:o.accent??"#ffd23f",width:.0022})),E=`fight: ${o.beats.length} beat(s), impacts at ${F.impacts.map(K=>K.t+"s").join(" ").slice(0,160)} (add impact sfx / cameraShake there)`}else o.cast.forEach((F,K)=>{const _=Ra[F.character]?z0({...F,fps:s,W:m,H:g}):uf({...F,character:F.character??"fighter",fps:s,W:m,H:g,stick:o.look==="stick",mocap:o.mocapClips??null,toon:o.toon??null,maxFrames:y});$.push({frames:_.frames,..._.track?{track:_.track}:{},start:0,label:`${I} ${K+1}`}),_.report&&A.push(_.report)})}else if(x(o,"animatePuppet"),Ra[o.character]){if(o.speech!=null&&(!Array.isArray(o.speech)||o.speech.length>200||o.speech.some(K=>!K||typeof K.text!="string"||!Wt(K.start)||!Wt(K.end)||K.end<=K.start)))throw Error("animatePuppet speech: [{text, start, end}] (s from the op start; a line, or each word from get_transcript)");const F=z0({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});$.push({frames:F.frames,start:0,label:I})}else{const F=uf({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});$.push({frames:F.frames,track:F.track,start:0,label:I}),A.push(F.report)}const z=[];let j=[];if(o.scene){const F=S?.duration??Math.max(...$.map(K=>K.start+K.frames.length/s));for(const K of lI(o.scene,{size:a,camera:S?.camera??null,fps:s,duration:F,ground:S?.ground??o.ground??.9,finish:u,en:r}))z.push(K)}for(const F of $){if(k&&F.track){const _=eg(F.track,{label:F.label,size:a,clean:d,width:f,ink:o.ink,brush:o.brush,finish:u});z.push({..._,start:_.start+F.start}),j.push(_.note);continue}const K=$i({start:o.start,fps:s,frames:F.ink?F.frames:v(F.frames),width:F.width??f,ink:F.ink??o.ink,brush:F.ink?"none":o.brush,label:F.label},{size:a,en:r,finish:u});for(const _ of K.layers)z.push({..._,start:_.start+F.start});j.push(K.note)}const P=o.cast?`${o.cast.length} character(s)`:o.character??"fighter",N=A.length?` — ${$x(A)}`:"";return{patches:[],layers:z,frameLayers:!0,note:`animatePuppet ${P}${E?` — ${E}`:`: ${(o.actions||[]).map(F=>F.move??F.mocap).join(" → ").slice(0,120)}`} — ${j[0]}${$.length>1?` (+${$.length-1} more sequence(s))`:""}${N}`}}case"editPose":{if(!n)throw Error("editPose needs clipId: a character layer made by animatePuppet (store rig)");const c=gi(n),s=c.items.findIndex(A=>A.type==="art"&&A.params?.rig);if(s<0)throw Error("editPose: this layer has no skeletons — make the character with animatePuppet (store: rig, the default) to edit its poses");const d=c.items[s],f=Mx(d.params.rig),m=f.frames.length/f.fps;if(!pf[o.joint])throw Error(`editPose joint: ${Object.keys(pf).join(" | ")}`);if(!(Wt(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(!Wt(g)||!Wt(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(!(Wt(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 $=g*f.W/(f.fs*f.k),E=v*f.H/f.k;let S=0;f.frames.forEach((A,I)=>{const z=I/f.fps,j=Math.abs(z-o.at)/x;if(j>=1)return;const P=1-j*j*j*(j*(6*j-15)+10);A.J=vx(A.J,o.joint,[$*P,E*P]),S++});const k=Ug(f),y=c.items.map((A,I)=>I===s?{...A,params:{...A.params,rig:k}}:A);return{patches:[{id:n.id,shape:Ue({...c,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 c=o.character??"stickman";if(!ia[c])throw Error(`traceMotion character: a side-view character (${Object.keys(ia).join(" | ")})`);tA(o,"traceMotion");const s=o.from??0,d=n.duration,f=o.duration??Math.min(60,d-s),m=o.fps??30,g=o.person??1;if(!(Wt(s)&&s>=0&&s<d))throw Error(`traceMotion from: s into the video clip, 0–${Math.round(d*100)/100}`);if(!(Wt(f)&&f>=.5&&f<=60&&s+f<=d+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"&&ia[c].look!=="stick"?{stick:!0}:{}},$=e.W||1280,E=e.H||720,S=Xg({character:c,...x,x:v?.x??.5,ground:v?.ground??.9,size:v?.size??.5,fps:m,W:$,H:E,actions:[{move:"idle",duration:.2}],toon:0,law:!1});S.frames=S.frames.slice(0,1);const k=eg(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-(Wt(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:c,style:x,place:v,W:$,H:E}}}],note:`traceMotion: a ${c} 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 c=!!kI(o).flat,s=MI(o),{fps:d,from:f,duration:m,n:g}=xI(o,n.duration,mo.frames),v=o.ink??"#1a0508";if(!wo.test(v))throw Error("rotoscope ink: #RRGGBB");if(Qy(o.fx,"rotoscope"),typeof o.job!="string"||!JI.test(o.job))throw Error("rotoscope is paid (Vẽ Animation, 0.2 credit a second): start it from the Shape tab, or through MCP edit_timeline (dry_run for the price, then max_credits)");const x=String(o.label??(r?"Animation":"Vẽ Animation")).slice(0,40),$=n.start+f-(Wt(o.start)?o.start:0),E=e.W||1280,S=e.H||720,k=[];if(c&&s==="plate"){const y=$i({op:"rotoscope",fps:d,width:0,brush:"none",label:x,frames:[{parts:[tg],hold:1}]},{size:a,en:r,finish:u}).layers[0];y.shape.items[0].span=[0,Math.round(g/d*1e4)/1e4],k.push({...y,label:`${x} · ${r?"backdrop":"nền"}`.slice(0,60),start:$,duration:g/d,clientJob:{kind:"rotoscope",op:"rotoscope",params:{job:o.job,backdrop:!0,first:0,count:g,fps:d,ink:v,W:E,H:S,label:`${x} · ${r?"backdrop":"nền"}`.slice(0,40)}}})}for(const y of c&&s==="keep"?[0,1]:[null])for(let A=0,I=0;A<g;A+=je.items,I++){const z=Math.min(je.items,g-A),j=$i({op:"rotoscope",fps:d,width:0,brush:"none",label:x,frames:[{parts:[tg],hold:z}]},{size:a,en:r,finish:u}).layers[0],P=`${g>je.items?`${x} ${I+1}`:x}${y===1?` · ${r?"front":"trước"}`:""}`;k.push({...j,label:P,start:$+A/d,duration:z/d,clientJob:{kind:"rotoscope",op:"rotoscope",params:{job:o.job,first:A,count:z,fps:d,ink:v,fx:y===1?null:o.fx??null,W:E,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:d,from:f,duration:m,n:g},note:`rotoscope: ${g} drawing(s) of "${String(n.label??"video").slice(0,40)}" at ${d} fps on ${k.length} layer(s)${c&&s==="plate"?" (the first: the backdrop)":""} — drawn by the Vẽ Animation job`}}case"arrangeShape":{const c=gi(n),s=xu(c,o.itemIds,"arrangeShape"),d=o.action;let f=[...c.items];if(d==="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(d==="ungroup")f=f.map(m=>{if(!s.includes(m.id))return m;const{group:g,...v}=m;return v});else if(d==="front"||d==="back"){const m=f.filter(v=>s.includes(v.id)),g=f.filter(v=>!s.includes(v.id));f=d==="front"?[...g,...m]:[...m,...g]}else if(d==="forward"||d==="backward")for(const m of d==="forward"?[...s].reverse():s){const g=f.findIndex(x=>x.id===m),v=d==="forward"?g+1:g-1;v>=0&&v<f.length&&([f[g],f[v]]=[f[v],f[g]])}else if(bd.includes(d))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,{...Es("merge"),mode:d}]}});else if(d==="move"){const m=o.dx??0,g=o.dy??0;if(!Wt(m)||!Wt(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]=An(c),$=Math.min(v,x)/1e3;f=f.map(E=>s.includes(E.id)?{...E,pos:[ze(E.pos[0]+m*v/$),ze(E.pos[1]+g*x/$)]}:E)}else if(d==="hide"||d==="show")f=f.map(m=>{if(!s.includes(m.id))return m;if(d==="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 | ${bd.join(" | ")}`);return{patches:[{id:n.id,shape:Ue({...c,items:f})}],note:`arrange ${d}: ${s.length} item(s)`}}}throw Error(`Unknown 2D op ${o.op}`)}function Ch(t,e,o){if(typeof e=="string"){const a=Tw(e,Ow(t));if(!a)throw Error(`pivot: ${Md.join(" | ")} or [x, y] of the frame`);return a}if(!Array.isArray(e)||e.length!==2)throw Error(`pivot: ${Md.join(" | ")} or [x, y] of the frame`);Qr(e,0,"pivot");const r=js(dc(aa({...t})),...o.pt(e));return[ze(r[0]),ze(r[1])]}function jh(t,e){const o=aa(t),r=aa({...t,pivot:e}),a=o[4]-r[4],n=o[5]-r[5],i={...t,pivot:e,pos:[ze(t.pos[0]+a),ze(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(l=>({...l,value:ze(l.value+a)}))),t.keys["pos.1"]&&(i.keys["pos.1"]=t.keys["pos.1"].map(l=>({...l,value:ze(l.value+n)})))),i}const tg={points:[[0,0],[1,0],[1,1],[0,1]],fill:"#000000",opacity:.06,line:!1,smooth:!1},ZI={points:[[.5,.5],[.501,.5],[.5,.501]],fill:"#000000",opacity:.02,line:!1,smooth:!1},JI=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Tj(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 c=sd({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 c.items[0].span=[0,Math.round((r.count??1)/n*1e4)/1e4],{shape:c}}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 l=r.half==null?i:i.map(u=>{const c=Number.isInteger(u?.split)?u.split:u?.parts?.length??0;return{parts:r.half===1?(u?.parts??[]).slice(c):(u?.parts??[]).slice(0,c)}});return{shape:QI(l,r,{en:o})}}function QI(t,e,{en:o}){return sd({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:[ZI]}))},{clips:[],find:()=>null,W:e.W||1280,H:e.H||720,en:o}).layers[0].shape}function tA(t,e){if(t.hair!=null&&!mc.includes(t.hair))throw Error(`${e} hair: ${mc.join(" | ")} (stick figures)`);if(t.eyes!=null&&!gc.includes(t.eyes))throw Error(`${e} eyes: ${gc.join(" | ")} (stick figures)`);if(t.weight!=null&&!(Wt(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])=>!Pu.includes(o)||!wo.test(r))))throw Error(`${e} colors: {${Pu.join(" | ")}: '#RRGGBB'}`);for(const[o,r,a]of[["x",-.5,1.5],["ground",.2,1.2],["size",.04,1.2]])if(t[o]!=null&&!(Wt(t[o])&&t[o]>=r&&t[o]<=a))throw Error(`${e} ${o}: ${r}–${a} (fractions of the frame)`)}function eg(t,{label:e,size:o,clean:r,width:a,ink:n="#2a1d14",brush:i="ink",finish:l}){const u=Ug(t),c=u.n/u.fps,s=Ur(o),d=s.pt([.5,.5]),f=s.pt([0,0]),m=s.pt([1,1]),g=t.ch.look==="stick",v=s.len(a);if(!wo.test(n))throw Error("animatePuppet ink: #RRGGBB");const x=!g&&v>0?{color:n,width:Io(ze(v),.5,240),cap:"round",join:"round",...i&&i!=="none"&&Ds.includes(i)?{hand:{style:i,taper:.7,press:.6,seed:7}}:{}}:null,$={id:"s1",name:String(e).slice(0,40),type:"art",params:{rig:u,box:[ze(f[0]-d[0]),ze(f[1]-d[1]),ze(m[0]-d[0]),ze(m[1]-d[1])],...r?{outline:!1}:{}},pos:d,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:t.C.stick??t.C.top??"#222222"},stroke:x,role:7,span:[0,Math.round(c*1e4)/1e4]};return{shape:l({v:2,size:o,items:[$]},null,{colors:"keep"}),label:String(e).slice(0,60),start:0,duration:c,note:`rig layer: ${u.n} drawing(s) at ${u.fps} fps = ${Math.round(c*100)/100}s from ${Math.round(u.data.length/1e3)}k chars of skeletons`}}const mo=Object.freeze({frames:480,parts:64,points:256,chars:3e6,fps:[4,30],cycles:8});function $i(t,{size:e,en:o,finish:r}){const a=t.fps??12;if(!(Number.isInteger(a)&&a>=mo.fps[0]&&a<=mo.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>mo.frames)throw Error(`drawFrames frames: 1–${mo.frames} drawings [{parts:[{points | d, fill?, line?}], hold?}]`);const i=t.cycles??1;if(!(Number.isInteger(i)&&i>=1&&i<=mo.cycles))throw Error(`drawFrames cycles: 1–${mo.cycles} (the whole drawing sequence repeated)`);const l=t.ink??"#2a1d14";if(!wo.test(l))throw Error("drawFrames ink: #RRGGBB");const u=t.width??.0035;if(!(Wt(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 c=t.brush??"ink";if(c!=="none"&&!Ds.includes(c))throw Error(`drawFrames brush: none | ${Ds.join(" | ")}`);const s=Ur(e),d=y=>Math.round(y),f=Qy(t.fx,t.op==="rotoscope"?"rotoscope":"drawFrames"),m=f?SI(n.map((y,A)=>{if(!Array.isArray(y?.parts))throw Error(`drawFrames frames[${A}].parts: 1–${mo.parts} shapes`);return y}),a,f,{aspect:e[0]/e[1],maxParts:mo.parts}):n;let g=0;const v=m.map((y,A)=>{const I=Array.isArray(y?.parts)?y.parts:null;if(!I||!I.length||I.length>mo.parts)throw Error(`drawFrames frames[${A}].parts: 1–${mo.parts} shapes`);const z=y.hold??1;if(!(Number.isInteger(z)&&z>=1&&z<=48))throw Error(`drawFrames frames[${A}].hold: how many frames it stays, 1–48`);const j=I.map((_,J)=>{if(!_||typeof _!="object")throw Error(`drawFrames frames[${A}].parts[${J}] must be an object`);const X=_.fill??null;if(X!==null&&!wo.test(X))throw Error(`drawFrames frames[${A}].parts[${J}].fill: #RRGGBB or null (an ink line)`);let rt;if(Array.isArray(_.loops)){if(!_.loops.length||_.loops.length>24||_.loops.some(ot=>!Array.isArray(ot)||ot.length<3||ot.length>1500))throw Error(`drawFrames frames[${A}].parts[${J}].loops: 1–24 closed outlines of 3–1500 points`);rt=_.loops.map((ot,G)=>"M"+ot.map((tt,Q)=>{const it=s.pt(Qr(tt,Q,`drawFrames frames[${A}].parts[${J}].loops[${G}]`));return`${d(it[0])} ${d(it[1])}`}).join(" L")+" Z").join(" ")}else if(_.d!=null)rt=nb(_.d,s);else{const ot=Array.isArray(_.points)?_.points:null;if(!ot||ot.length<2||ot.length>mo.points)throw Error(`drawFrames frames[${A}].parts[${J}]: points [[x,y]…] (2–${mo.points}) or d`);const G=ot.map((Q,it)=>s.pt(Qr(Q,it,`drawFrames frames[${A}].parts[${J}]`))),tt=_.closed??!!X;rt=_.smooth===!1?"M"+G.map(Q=>`${d(Q[0])} ${d(Q[1])}`).join(" L")+(tt?" Z":""):qi(G,tt&&G.length>2)}if(!X&&_.line===!1)throw Error(`drawFrames frames[${A}].parts[${J}] needs a fill or a line`);if(_.lw!=null&&!(Wt(_.lw)&&_.lw>=.1&&_.lw<=5))throw Error(`drawFrames frames[${A}].parts[${J}].lw: line weight 0.1–5 (× width)`);if(_.opacity!=null&&!(Wt(_.opacity)&&_.opacity>=.02&&_.opacity<=1))throw Error(`drawFrames frames[${A}].parts[${J}].opacity: 0.02–1`);if(_.tag!=null&&!_h.test(_.tag))throw Error(`drawFrames frames[${A}].parts[${J}].tag: a name — a letter then letters / digits / dashes, ≤ 24 (armR, head, leg-left)`);return{d:rt,fill:X,..._.tag!=null?{tag:_.tag}:{},...X&&_.line===!1?{line:!1}:{},..._.lw!=null&&_.lw!==1?{lw:Math.round(_.lw*100)/100}:{},..._.eo===!0&&X?{eo:!0}:{},..._.opacity!=null&&_.opacity<1?{o:Math.round(_.opacity*100)/100}:{},role:7}}),P=j.reduce((_,J)=>{const X=pr(J.d);return[Math.min(_[0],X[0]),Math.min(_[1],X[1]),Math.max(_[2],X[2]),Math.max(_[3],X[3])]},[1/0,1/0,-1/0,-1/0]),N=Math.round((P[0]+P[2])/2),F=Math.round((P[1]+P[3])/2),K=j.map(_=>{let J=0;return{..._,d:_.d.replace(dn,X=>String(Math.round(Number(X)-(J++%2?F:N))))}});for(const _ of K){if(_.d.length>Zi.d)throw Error(`drawFrames frames[${A}]: a shape is too long (max ${Zi.d} characters)`);g+=_.d.length}return{parts:K,pos:[N,F],hold:z}});if(g*i>mo.chars)throw Error(`drawFrames: ${g*i} characters of drawing (max ${mo.chars}) — fewer frames, cycles or points`);const x=s.len(u),$=x>0?{color:l,width:Io(ze(x),.5,240),cap:"round",join:"round",...c!=="none"?{hand:{style:c,taper:.7,press:.6,seed:7}}:{}}:null,E=[];let S=0;for(let y=0;y<i;y++)for(const A of v)E.push({...A,t0:S,t1:S+A.hold/a}),S+=A.hold/a;const k=[];for(let y=0;y<E.length;y+=je.items){const A=E.slice(y,y+je.items),I=A[0].t0,z=A.at(-1).t1,j=A.map((P,N)=>({id:`s${N+1}`,name:`${o?"Frame":"Khung"} ${y+N+1}`,type:"art",params:{parts:P.parts,box:pr(P.parts.map(F=>F.d).join(" ")),outline:t.outline!==!1},pos:P.pos,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:P.parts.find(F=>F.fill)?.fill??l},stroke:$,role:7,span:[Math.round((P.t0-I)*1e4)/1e4,Math.round((P.t1-I)*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)}${E.length>je.items?` ${k.length+1}`:""}`,start:I,duration:z-I})}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 eA=13;function oA(t,{into:e,target:o,size:r,ctx:a,en:n,finish:i}){const l=t.traced;if(!l||typeof l!="object")throw Error("traceImage needs materialId (an image in the Media bin); the picture is traced when the plan is applied");const u=l.width,c=l.height,s=l.unit;if(!(Number.isInteger(u)&&Number.isInteger(c)&&u>=8&&c>=8&&u<=2048&&c<=2048&&(s===.5||s===1)&&Array.isArray(l.groups)&&l.groups.length&&l.groups.length<=eA))throw Error("traceImage: bad traced data");const d=t.fit??"cover";if(!["cover","contain"].includes(d))throw Error("traceImage fit: cover | contain");const f=Array.isArray(t.regions)?t.regions:[],[m,g]=An(o),v=Ur([m,g]),x=a.W||1280,$=a.H||720;let E;if(t.background==="remove"&&(t.x!=null||t.y!=null||t.size!=null)){const K=t.x??.5,_=t.y??.5,J=t.size??.6;if(Qr([K,_],0,"traceImage"),!(Wt(J)&&J>=.02&&J<=1.5))throw Error("traceImage size = height of the subject as a fraction of the frame, 0.02–1.5");const X=l.groups.reduce((tt,Q)=>Q.parts.reduce((it,D)=>{const U=pr(D.d);return[Math.min(it[0],U[0]),Math.min(it[1],U[1]),Math.max(it[2],U[2]),Math.max(it[3],U[3])]},tt),[1/0,1/0,-1/0,-1/0]).map(tt=>tt*s),rt=Math.max(1,X[3]-X[1]),ot=J/rt,G=ot*$/x;E={x0:K-(X[0]+X[2])/2*G,y0:_-(X[1]+X[3])/2*ot,sx:G,sy:ot}}else{const K=u/c,_=x/$,J=d==="cover",X=J?K>_:K<_,rt=X?J?K/_:1:J?1:K/_,ot=X?J?1:_/K:J?_/K:1;E={x0:(1-rt)/2,y0:(1-ot)/2,sx:rt/u,sy:ot/c}}const k=(K,_)=>v.pt([E.x0+K*s*E.sx,E.y0+_*s*E.sy]),y=!e&&t.layers!==!1&&l.groups.length>1,A=[...o.items],I=[],z=[];if(!y&&A.length+l.groups.length>je.items)throw Error(`A Shape layer holds up to ${je.items} items — trace into a new layer (leave clipId out)`);const j=([K,_])=>[(K*v.k+v.ox)/m,(_*v.k+v.oy)/g];let P=0;for(const K of l.groups){if(!K||!Array.isArray(K.parts)||!K.parts.length||K.parts.length>Zi.parts)throw Error("traceImage: bad traced group");const _=K.parts.map(it=>{if(!it||typeof it.d!="string"||!/^\s*M[MLCQZ0-9eE.,\s+-]*$/.test(it.d)||!wo.test(it.fill??""))throw Error("traceImage: bad traced part");const D=[...it.d.matchAll(dn)].map(yt=>Number(yt[0]));if(D.length%2)throw Error("traceImage: bad traced part");const U=[];for(let yt=0;yt<D.length;yt+=2){const Mt=k(D[yt],D[yt+1]);U.push(Math.round(Mt[0]),Math.round(Mt[1]))}let ht=0;return{d:it.d.replace(dn,()=>String(U[ht++])),fill:it.fill}}),J=_.reduce((it,D)=>{const U=pr(D.d);return[Math.min(it[0],U[0]),Math.min(it[1],U[1]),Math.max(it[2],U[2]),Math.max(it[3],U[3])]},[1/0,1/0,-1/0,-1/0]),X=Math.round((J[0]+J[2])/2),rt=Math.round((J[1]+J[3])/2),ot=_.map(it=>{let D=0;return{d:it.d.replace(dn,U=>String(Math.round(Number(U)-(D++%2?rt:X)))),fill:it.fill,role:7,eo:!0}});P+=ot.reduce((it,D)=>it+D.d.length,0);const G=Ya(A),tt=Number.isInteger(K.region)&&K.region>=0?f[K.region]:null;let Q={id:G,name:String(K.name||(n?"Traced":"Hình vẽ lại")).slice(0,40),type:"art",params:{parts:ot,box:pr(ot.map(it=>it.d).join(" ")),outline:!1},pos:[X,rt],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:ot[0].fill},stroke:null,role:7};if(y){const it=Q.name,D=[...j([J[0],J[1]]),...j([J[2],J[3]])];let U=null,ht=null,yt=null;if(tt){if(tt.motion!=null){if(!Dn[tt.motion])throw Error(`traceImage regions[].motion (layers): ${Wy.join(" | ")}`);ht={preset:tt.motion,...Wt(tt.amount)?{amount:Io(tt.amount,0,8)}:{},...Wt(tt.period)?{period:Io(tt.period,.1,60)}:{},...Wt(tt.phase)?{phase:Io(tt.phase,0,1)}:{}}}const Z=tt.pivot??(ht?Dn[ht.preset].anchor:null);if(Array.isArray(Z)?(Qr(Z,0,"traceImage regions[].pivot"),U=[E.x0+Z[0]*u*E.sx,E.y0+Z[1]*c*E.sy]):Z!=null&&(U=Z),tt.parent!=null){const nt=f.findIndex(dt=>dt&&dt.name===tt.parent);if(nt<0)throw Error(`traceImage regions[].parent "${String(tt.parent).slice(0,40)}": the name of another region`);yt=nt}}if(K.region===-1){z.push({shape:{v:2,size:[m,g],items:[{...Q,id:"s1"}]},label:String(it).slice(0,60),region:null,anchor:U,box:D,parent:yt,motion:ht});continue}const Mt=D[0]-3/x,p=D[1]-3/$,lt=D[2]+3/x,V=D[3]+3/$,h=(lt-Mt)*x,w=(V-p)*$,T=Math.min(Math.max(1.5,64/Math.max(1,Math.min(h,w))),2560/Math.max(h,w)),C=Io(Math.round(h*T),64,2560),O=Io(Math.round(w*T),64,2560),L=Ur([C,O]),B=Math.min(x/C,$/O),H=(Z,nt)=>L.pt([(E.x0+Z*s*E.sx-Mt)/(lt-Mt),(E.y0+nt*s*E.sy-p)/(V-p)]),q=K.parts.map(Z=>{const nt=[...Z.d.matchAll(dn)].map(At=>Number(At[0])),dt=[];for(let At=0;At<nt.length;At+=2){const xt=H(nt[At],nt[At+1]);dt.push(Math.round(xt[0]),Math.round(xt[1]))}let vt=0;return{d:Z.d.replace(dn,()=>String(dt[vt++])),fill:Z.fill}}),et=q.reduce((Z,nt)=>{const dt=pr(nt.d);return[Math.min(Z[0],dt[0]),Math.min(Z[1],dt[1]),Math.max(Z[2],dt[2]),Math.max(Z[3],dt[3])]},[1/0,1/0,-1/0,-1/0]),st=Math.round((et[0]+et[2])/2),Y=Math.round((et[1]+et[3])/2),ct=q.map(Z=>{let nt=0;return{d:Z.d.replace(dn,dt=>String(Math.round(Number(dt)-(nt++%2?Y:st)))),fill:Z.fill,role:7,eo:!0}}),gt={...Q,id:"s1",pos:[st,Y],params:{parts:ct,box:pr(ct.map(Z=>Z.d).join(" ")),outline:!1}};z.push({shape:{v:2,size:[C,O],items:[gt]},label:String(it).slice(0,60),region:Number.isInteger(K.region)?K.region:null,anchor:U,box:D,parent:yt,motion:ht,place:{posX:Math.round(((Mt+lt)/2-.5)*1e4)/1e4,posY:Math.round(((p+V)/2-.5)*1e4)/1e4,scale:Math.round(h/(C*B)*1e5)/1e5}});continue}if(tt&&(tt.pivot!=null&&(Q=jh(Q,Array.isArray(tt.pivot)?(()=>{Qr(tt.pivot,0,"traceImage regions[].pivot");const it=k(tt.pivot[0]*u/s,tt.pivot[1]*c/s);return[ze(it[0]-X),ze(it[1]-rt)]})():Ch(Q,tt.pivot,v))),tt.motion!=null)){const it=Gg[tt.motion];if(!it)throw Error(`traceImage regions[].motion: ${Gh.join(" | ")}`);tt.pivot==null&&(Q=jh(Q,Ch(Q,it.pivot,v)));const D=Wt(tt.amount)?Io(tt.amount,0,8):1;Q.motion=[{type:tt.motion,...D!==1?{amount:Math.round(it.amount*D*1e4)/1e4}:{},...Wt(tt.period)?{period:Io(tt.period,.1,60)}:{},...Wt(tt.phase)?{phase:Io(tt.phase,0,1)}:{}}]}A.push(Q),I.push(G)}if(P>Zi.layer)throw Error("traceImage: the drawing is too big for one layer — fewer colours or less detail");if(y){const K=new Map(z.map((J,X)=>[J.region,X]));for(const J of z)J.parent=J.parent==null?null:K.get(J.parent)??null,J.shape=i(J.shape,null,{colors:"keep"}),delete J.region;let _=null;if(t.camera!=null){const J=typeof t.camera=="string"?{preset:t.camera}:t.camera;if(!J||!Uc.includes(J.preset))throw Error(`traceImage camera: ${Uc.join(" | ")} (or {preset, amount})`);_={preset:J.preset,...Wt(J.amount)?{amount:Io(J.amount,0,8)}:{}}}return{patches:[],layers:z,camera:_,note:`traceImage: ${z.length} layers (${z.map(J=>J.label).join(", ").slice(0,140)}), ${l.palette?.length??"?"} colours, ${Math.round(P/1e3)}k chars`}}const N=i({...o,items:A},I,{colors:"keep"}),F=`traceImage: ${l.groups.length} part(s) (${l.groups.map(K=>K.name).join(", ").slice(0,120)}), ${l.palette?.length??"?"} colours, ${Math.round(P/1e3)}k chars`;return e?{patches:[{id:e.id,shape:N}],note:F}:{patches:[],layer:{shape:N,label:String(t.label??(n?"Traced drawing":"Vẽ lại từ ảnh")).slice(0,60)},note:F}}const cb=t=>Kh(t?.shape)&&t.shape.items.length===1&&t.shape.items[0].name==="Paper"&&t.zIndex===-1,Th=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"}]),og=Th.map(t=>t.id),Oh=Object.freeze(["stack","split","focus"]),Va=Object.freeze({shots:12,seconds:60,labels:40}),rA={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"}},nA={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}}},Vt=t=>Math.round(t*1e3)/1e3,yo=t=>Math.round(t*1e4)/1e4,zh=t=>Qt[t],aA=/^#[0-9a-fA-F]{6}$/,Mu=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 iA(t,e,o){const{track:r}=qt(t,e,o.start,o.start+o.duration),a={...o,track:r};return t.push(a),a}function sA(t,e){const o=Th.find(r=>r.id===t)??Th[0];return aA.test(e??"")?{...o,accent:e.toLowerCase(),rim:o.glow?e.toLowerCase():o.rim}:o}function op(t,e){return Bn(t)?Math.abs(Lw(t,e)):Zr(t)?Nw(t,e):t.playbackRate||1}function lA(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||(Zr(r)||Bn(r)?o.ramp:null);return String(i||o.cut).replace(/\s*\([^)]*\)\s*/g," ").replace(/[-_]+/g," ").trim().toUpperCase().slice(0,Va.labels)}function cA(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 pA(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=ta(r.width,r.height,t.crop);return cr({mw:r.width,mh:r.height},[Cn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:o},a.w,a.h)])}function uA(t,{x:e,y:o,s:r}){const a={...t,...en(t)},n=(a.motionKeys??[]).map(i=>({...i,...Number.isFinite(i.x)?{x:yo(e+r*i.x)}:{},...Number.isFinite(i.y)?{y:yo(o+r*i.y)}:{},...Number.isFinite(i.zoom)?{zoom:yo(r*i.zoom)}:{}}));return{motionV:2,posX:yo(e+r*(a.posX??0)),posY:yo(o+r*(a.posY??0)),scale:yo(r*(a.scale??1)),motionKeys:n}}const Fl=(t,e=0)=>{const o=Vt(Math.min(t,e)),r=Vt(Math.min(t,e+.35));return r>o?[{time:o,opacity:0,ease:{opacity:zh("ease-out")}},{time:r,opacity:1}]:[]};function hA(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 Ar(t,e,o,r,a,{x:n,y:i,size:l=30,color:u,font:c,italic:s=!1,weight:d=700,anim:f="word-blur",track:m=0,glow:g=!0,k:v=1}){const x=u??a.label,$=Wl({text:r,fontSize:Math.max(24,Math.min(96,l)),color:x,placement:"center",fontFamily:c??a.font,align:"center",animation:f,design:{lines:[{scale:1,fill:x,font:c??a.font,italic:s,weight:d,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:$,volume:0,track:m,start:e,duration:o,motionV:2,posX:yo(n),posY:yo(i),scale:Vt(v),motionKeys:[]}}function dA(t,e){const o=t.duration,r=40,a=Array.from({length:r+1},(f,m)=>op(t,o*m/r)),n=Math.max(2,...a)*1.12,i=f=>Vt(90+820*f),l=f=>Vt(740-430*Math.min(1,f/n)),u=a.map((f,m)=>[i(m/r),l(f)]),c=Math.min(24,Math.max(2,Math.round(o*4))),s=Array.from({length:c+1},(f,m)=>({t:Vt(o*m/c),p:[i(m/c),l(op(t,o*m/c))]})),d=l(1);return Ue({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,d],[910,d]],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:Vt(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:Vt(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 fA(t,e,o,r){const a=Math.min(1777.7777777777778,1e3*e),n=v=>Vt(500+(v-.5)*a),i=[],l=(v,x,$)=>({color:t.floor,width:x,...$?{blur:$}:{},opacity:v});if(o==null){const x=[],$=[];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 E=Math.round(8/e);for(let S=0;S<=E;S++){const k=Vt(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:l(1,2)},{id:"h",name:"Grid H",type:"path",params:{pts:$,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.14,fill:{type:"none"},stroke:l(1,2)}),Ue({v:2,items:i})}const u=Vt(1e3*o),c=[500,Vt(u-120)],s=14,d=[];for(let v=0;v<=s;v++){const x=n(-.7+2.4*v/s),$=(u-1e3)/(c[1]-1e3),E=Vt(x+(c[0]-x)*$);d.push(...v%2?[[E,u],[x,1e3]]:[[x,1e3],[E,u]])}i.push({id:"vg",name:"Floor glow",type:"path",params:{pts:d,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.35,fill:{type:"none"},stroke:l(1,9,9)},{id:"v",name:"Floor lines",type:"path",params:{pts:d,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,$=Vt(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),$],[n(1.2),$]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:Vt(.25+.6*(1-v/8)),fill:{type:"none"},stroke:l(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:l(1,5,10)});const f=1.6,m=[];for(let v=0;v<=r+1e-6&&m.length<60;v+=f)m.push({time:Vt(v),value:u},{time:Vt(Math.min(r,v+f-1/30)),value:1e3});const g=m.filter((v,x,$)=>!x||v.time>$[x-1].time);return i.push({id:"scan",name:"Scan",type:"rect",params:{w:Vt(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}}:{}}),Ue({v:2,items:i})}const rg={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"}},mA=["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"];function gA(t){const e=Math.min(1777.7777777777778,1e3*t);return{X:o=>Vt(500+(o-.5)*e),Y:o=>Vt(o*1e3),w:e}}const Uo=(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}),Ei=(t,e,o,r,a,n,i=null,l={})=>({id:t,name:t,type:"rect",params:{w:Vt(r),h:Vt(a),round:l.round??0},pos:[Vt(e),Vt(o)],rot:0,scale:[1,1],opacity:l.opacity??1,fill:n,stroke:i,...l.keys?{keys:l.keys}:{}});function yA(t,e){const o=t.duration,r=Math.min(24,Math.max(2,Math.round(o*4))),a=8,n=c=>Vt(-120+240*Math.min(1,Math.log(Math.max(.1,c)/.1)/Math.log(a/.1))),i=[];for(let c=0;c<=40;c++){const s=(-210+240*c/40)*Math.PI/180;i.push([Vt(500+Math.cos(s)*380),Vt(560+Math.sin(s)*380)])}const l=[];[.1,.5,1,2,4,8].forEach((c,s)=>{const d=(n(c)-90)*Math.PI/180,f=[[Vt(500+Math.cos(d)*330),Vt(560+Math.sin(d)*330)],[Vt(500+Math.cos(d)*380),Vt(560+Math.sin(d)*380)]];l.push(...s%2?f.reverse():f)});const u=Array.from({length:r+1},(c,s)=>({time:Vt(o*s/r),value:n(op(t,o*s/r))}));return Ue({v:2,square:!0,items:[Ei("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}),Uo("a",i,{color:e.text,width:10,cap:"round",opacity:.35}),Uo("t",l,{color:e.text,width:8}),{id:"n",name:"Needle",type:"path",params:{pts:[[500,560],[500,230]],closed:!1},pos:[0,0],rot: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 bA(t,e,o,r={}){const{newId:a,W:n=1280,H:i=720,materials:l=[]}=r,u=new Map(t.map(lt=>[lt.id,lt])),c=(o??[]).map(lt=>u.get(lt)).filter(Boolean);let s;if(c.length>1)s=c.filter(Mu);else{const lt=c[0]??t.filter(Mu).sort((V,h)=>V.track-h.track||V.start-h.start)[0];if(!lt)throw Error("breakdownShowcase needs the edit: a video / picture clip (clipId) or the shots (clipIds)");s=t.filter(V=>V.track===lt.track&&Mu(V))}if(s=s.sort((lt,V)=>lt.start-V.start).slice(0,Va.shots),!s.length)throw Error("breakdownShowcase: no video / picture shots in that edit");const d=s[0].start,f=Math.max(...s.map(lt=>lt.start+lt.duration)),m=Vt(f-d);if(m>Va.seconds+1e-6)throw Error(`breakdownShowcase: the edit is ${m}s — at most ${Va.seconds}s (pick fewer shots)`);const g=Math.max(0,...t.map(lt=>lt.start+lt.duration)),v=Vt(Number.isFinite(r.at)&&r.at>=0?r.at:g),x=Vt(v+m),$=v-d,E=sA(r.style,r.color),S=rA[r.lang==="vi"?"vi":"en"],k=Oh.includes(r.layout)?r.layout:E.layout??"stack",y=nA[i>n*1.05?"portrait":"landscape"][k],A=Array.isArray(r.labels)?r.labels.map(lt=>typeof lt=="string"?lt.trim().slice(0,Va.labels).toUpperCase():""):[],I=[...t],z=[],j=lt=>{const V=iA(I,e,lt);return z.push(V),V},P=new Set(E.sig??[]),N=r.lang==="vi"?"vi":"en",F=rg[N],K=gA(n/i),_=(lt,V,h=v,w=m,T={})=>j({id:a(),nodeId:"",kind:"image",url:"",label:lt,track:0,start:h,duration:w,volume:0,motionV:2,fit:"cover",shape:Ue({v:2,items:V}),...T}),J=cA(s[0],l,n,i),X=i>n*1.05,rt=X?2.2:1.15,ot=lt=>yo(lt.h/J),G=lt=>yo(lt.y-lt.h/2-.03);if(j({...Vh({id:a(),track:0,start:v,duration:m,label:"Breakdown · nền",fill:{type:"linear",from:E.bg[0],to:E.bg[1],angle:E.bg[2]},aspect:n/i})}),E.floor){const lt=fA(E,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 tt=l.find(lt=>lt.id===s[0].nodeId),Q=tt?.width>1&&tt?.height>1?tt.width/tt.height:s[0].kind==="video"?n/i:1,it=lt=>{const V=lt.h,h=ot(lt)*Math.min(1,Q*i/n);return{x0:.5+lt.x-h/2,x1:.5+lt.x+h/2,y0:.5+lt.y-V/2,y1:.5+lt.y+V/2}},{X:D,Y:U}=K;if(P.has("sun")){const lt=(y.horizon??.5)-.02,V=.2,h=[{id:"sun",name:"Sun",type:"ellipse",params:{w:Vt(V*2*1e3),h:Vt(V*2*1e3)},pos:[D(.5),U(lt)],rot:0,scale:[1,1],opacity:.9,fill:{type:"linear",angle:90,stops:[["#ffd85a",0],[E.accent,1]]},stroke:null}];for(let w=0;w<6;w++)h.push(Ei(`b${w}`,D(.5),U(lt+V*(.1+w*.15)),V*2.2*1e3,4+w*3,{type:"color",color:E.bg[1]}));_("Breakdown · mặt trời",h)}if(P.has("frost")){const lt=[],h=(w,T)=>lt.push(Ei(w,D((T.x0+T.x1)/2),U((T.y0+T.y1)/2),D(T.x1)-D(T.x0)+40,U(T.y1)-U(T.y0)+40,{type:"color",color:"#ffffff",opacity:.1},{color:"#ffffff",width:2,opacity:.35},{round:40}));if(y.final&&h("f",it(y.final)),y.raw&&h("r",it(y.raw)),y.start&&y.end){const w=it(y.start),T=it(y.end);h("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&&_("Breakdown · kính mờ",lt)}const ht=lt=>{const V=pA(lt,l,E.round);return V?{mask:V}:{}},yt={color:E.rim,width:.012,glow:E.glow||0,amount:.9},Mt={...hn,opacity:E.glow?.55:.25,blur:24,distance:E.glow?12:8};if(y.final){const lt=y.final,V=ot(lt),h=qt(I,e,v,x).track;s.forEach((w,T)=>{const{id:C,parentId:O,...L}=w,B=uA(w,{x:lt.x,y:lt.y,s:V}),H={...L,...B,id:a(),track:h,start:Vt(w.start+$),...ht(w),edge:yt,shadow:Mt,motionKeys:T===0?hA(B.motionKeys,Fl(w.duration,0)):B.motionKeys};I.push(H),z.push(H)}),P.has("headline")?j(Ar(a(),v,m,F.head,E,{x:lt.x,y:yo(G(lt)-.004),size:30,color:E.accent,font:E.move,italic:E.italic,weight:800,k:rt})):j(Ar(a(),v,m,S.final,E,{x:lt.x,y:G(lt),size:26,k:rt}))}if(y.raw){const lt=y.raw,V=ot(lt),h=qt(I,e,v,x).track;s.forEach((w,T)=>{const C=l.find(q=>q.id===w.nodeId),O=w.kind==="video"?w.sourceDuration??C?.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:h,start:Vt(w.start+$),duration:w.duration,inPoint:L,...O!=null?{sourceDuration:O}:{},volume:0,...B!==1?{playbackRate:Vt(B)}:{},...w.crop?{crop:w.crop}:{},motionV:2,posX:lt.x,posY:lt.y,scale:V,motionKeys:T===0?Fl(w.duration,.08):[],...ht(w),edge:yt,shadow:Mt};I.push(H),z.push(H)}),j(Ar(a(),v,m,S.raw,E,{x:lt.x,y:G(lt),size:24,k:rt}))}if(y.graph){const lt=y.graph,V=yo(P.has("gauge")?Math.min(lt.w/.96,.3/(.76*n/i)):lt.w/.96),h=qt(I,e,v,x).track;s.forEach((T,C)=>{const O={id:a(),nodeId:"",kind:"image",url:"",label:`Speed graph · ${C+1}`,track:h,start:Vt(T.start+$),duration:T.duration,volume:0,motionV:2,fit:"contain",posX:lt.x,posY:lt.y,scale:V,motionKeys:C===0?Fl(T.duration,.16):[],shape:P.has("gauge")?yA(T,E):dA(T,E)};I.push(O),z.push(O)});const w=V*(P.has("gauge")?.76:.6)*n/i;j(Ar(a(),v,m,P.has("gauge")?rg[N].speed:S.graph,E,{x:lt.x,y:yo(lt.y-w/2-.028),size:24,k:rt}))}if(y.start&&y.end){const lt=qt(I,e,v,x).track,V=(h,w,T)=>{const C=ot(w),O=h.kind==="video"?Vt(Math.max(0,Ag(h,Math.min(h.duration,Math.max(0,T))))):null;return{id:a(),nodeId:h.nodeId,kind:h.kind,url:h.url,...h.gcsUri?{gcsUri:h.gcsUri}:{},label:h.label,start:Vt(h.start+$),duration:h.duration,inPoint:h.inPoint||0,...h.sourceDuration!=null?{sourceDuration:h.sourceDuration}:{},volume:0,...h.crop?{crop:h.crop}:{},...O!=null?{timeRemap:{keys:[{t:0,source:O},{t:Vt(h.duration),source:O}],blend:"none"}}:{},motionV:2,posX:w.x,posY:w.y,scale:C,motionKeys:[{time:0,opacity:.25,zoom:yo(C*.92),ease:{opacity:zh("ease-out"),zoom:zh("back-out")}},{time:Vt(Math.min(h.duration,.2)),opacity:1,zoom:C}],...ht(h),edge:yt,shadow:Mt}};s.forEach((h,w)=>{const T=V(h,y.start,0),C=V(h,y.end,h.duration-1/30);T.track=lt,I.push(T),z.push(T),C.track=qt(I,e,C.start,C.start+C.duration).track,I.push(C),z.push(C)}),y.stillLabels!==!1&&j(Ar(a(),v,m,S.start,E,{x:y.start.x,y:G(y.start),size:22,k:rt})),y.stillLabels!==!1&&j(Ar(a(),v,m,S.end,E,{x:y.end.x,y:G(y.end),size:22,k:rt}))}if(y.move&&s.forEach((lt,V)=>{const h=A[V]||lA(s,V,S);if(P.has("log")){const T=Array.from({length:25},(B,H)=>op(lt,lt.duration*H/24)),C=Math.min(...T),O=Math.max(...T),L=`> ${F.shot} ${String(V+1).padStart(2,"0")}/${String(s.length).padStart(2,"0")} ${lt.duration.toFixed(1)}s
334
+ > ${F.speed} ${C.toFixed(1)}× → ${O.toFixed(1)}×
335
+ > ${F.move}: ${h}`;j(Ar(a(),Vt(lt.start+$),lt.duration,L,E,{x:y.move.x,y:y.move.y,size:20,color:E.accent,font:"Courier New",weight:700,anim:"type-on",k:rt}))}else j(Ar(a(),Vt(lt.start+$),lt.duration,h,E,{x:y.move.x,y:y.move.y,size:32,color:E.accent,font:E.move,italic:E.italic,weight:800,k:rt}))}),P.has("scan")){const lt=(V,h)=>{const w=[];for(let T=0;T<128;T++){const C=Vt(h+T*7.8);w.push(...T%2?[[D(1),C],[D(0),C]]:[[D(0),C],[D(1),C]])}return Uo(V,w,{color:"#000000",width:2,opacity:.35})};_("Breakdown · scanline",[lt("s1",2),lt("s2",2+128*7.8)])}const p=y.final?it(y.final):null;if(P.has("brackets")&&p){const h={color:E.accent,width:6,join:"miter",...E.glow?{blur:6}:{}},w=p.x0-.018,T=p.x1+.018,C=p.y0-.018,O=p.y1+.018;_("Breakdown · ngoặc góc",[Uo("tl",[[D(w),U(C+.05)],[D(w),U(C)],[D(w+.05*i/n),U(C)]],h),Uo("tr",[[D(T-.05*i/n),U(C)],[D(T),U(C)],[D(T),U(C+.05)]],h),Uo("bl",[[D(w),U(O-.05)],[D(w),U(O)],[D(w+.05*i/n),U(O)]],h),Uo("br",[[D(T-.05*i/n),U(O)],[D(T),U(O)],[D(T),U(O-.05)]],h)])}if(P.has("rings")&&p){const lt=(p.x0+p.x1)/2,V=(p.y0+p.y1)/2,h=Math.max(p.y1-p.y0,(p.x1-p.x0)*n/i)*.62*1e3,w=(T,C,O,L,B)=>({id:T,name:T,type:"ellipse",params:{w:Vt(C*2),h:Vt(C*2)},pos:[D(lt),U(V)],rot:0,scale:[1,1],opacity:.7,fill:{type:"none"},stroke:{color:E.accent,width:B,dash:O,...E.glow?{blur:6}:{}},keys:{rot:[{time:0,value:0},{time:Vt(m),value:Vt(L*m*24)}]}});_("Breakdown · vòng HUD",[w("r1",h,[40,26],1,4),w("r2",h*1.07,[8,18],-1,3)])}if(P.has("index")&&p&&s.forEach((lt,V)=>{const h=E.id==="dark-luxury"?mA[V]:String(V+1).padStart(2,"0");j(Ar(a(),Vt(lt.start+$),lt.duration,h,E,{x:yo(p.x0-.5+.07),y:yo(p.y0-.5+.06),size:48,color:E.accent,font:E.move,italic:E.italic,weight:800,k:rt,glow:!1}))}),P.has("dims")&&p){const lt={color:E.text,width:3},V=.012,h=p.y1+.03,w=p.x0-.035*i/n;_("Breakdown · kích thước",[Uo("h",[[D(p.x0),U(h)],[D(p.x1),U(h)]],lt),Uo("ha",[[D(p.x0+V),U(h-V)],[D(p.x0),U(h)],[D(p.x0+V),U(h+V)]],lt),Uo("hb",[[D(p.x1-V),U(h-V)],[D(p.x1),U(h)],[D(p.x1-V),U(h+V)]],lt),Uo("v",[[D(w),U(p.y0)],[D(w),U(p.y1)]],lt),Uo("va",[[D(w-V),U(p.y0+V)],[D(w),U(p.y0)],[D(w+V),U(p.y0+V)]],lt),Uo("vb",[[D(w-V),U(p.y1-V)],[D(w),U(p.y1)],[D(w+V),U(p.y1-V)]],lt)]);const T=tt?.width>1?`${tt.width} × ${tt.height}`:"";s.forEach((C,O)=>{const L=j(Ar(a(),Vt(C.start+$),C.duration,`${T?T+" · ":""}${C.duration.toFixed(1)} s`,E,{x:yo((w+p.x0)/2-.5-.012*i/n),y:yo((p.y0+p.y1)/2-.5),size:16,color:E.text,weight:500,k:rt,glow:!1}));L.rotation=-90})}if(P.has("arrows")&&p&&y.raw){const lt=it(y.raw),V=[lt.x0<p.x0?lt.x1+.01:lt.x0-.01,(lt.y0+lt.y1)/2],h=[p.x0<lt.x0?p.x1+.01:p.x0-.01,(p.y0+p.y1)/2+.03],w=[(V[0]+h[0])/2,Math.min(V[1],h[1])-.08],T=[];for(let st=0;st<=16;st++){const Y=st/16,ct=(1-Y)*(1-Y)*V[0]+2*Y*(1-Y)*w[0]+Y*Y*h[0],gt=(1-Y)*(1-Y)*V[1]+2*Y*(1-Y)*w[1]+Y*Y*h[1];T.push([D(ct),U(gt)])}const C=T[16][0]-T[15][0],O=T[16][1]-T[15][1],L=Math.hypot(C,O)||1,B=C/L,H=O/L,q=26,et=T[16];_("Breakdown · mũi tên",[Uo("c",T,{color:E.accent,width:6,cap:"round",dash:[18,12]}),Uo("hd",[[Vt(et[0]-B*q-H*q*.6),Vt(et[1]-H*q+B*q*.6)],et,[Vt(et[0]-B*q+H*q*.6),Vt(et[1]-H*q-B*q*.6)]],{color:E.accent,width:6,cap:"round"})],v,m,{motionKeys:Fl(m,.3)})}if(P.has("strip")){const lt=X?.965:.955,V=.06,h=.94,w=[Ei("bg",D(.5),U(lt),D(h)-D(V),18,{type:"color",color:E.text,opacity:.15})];s.forEach((T,C)=>{const O=V+(h-V)*(T.start-d)/m,L=V+(h-V)*(T.start+T.duration-d)/m;w.push(Ei(`s${C}`,D((O+L)/2),U(lt),D(L)-D(O)-4,14,{type:"color",color:C%2?E.accent:E.rim,opacity:.85}))}),w.push(Ei("ph",D(V),U(lt),5,44,{type:"color",color:"#ff3b3b"},null,{keys:{"pos.0":[{time:0,value:D(V)},{time:Vt(m),value:D(h)}]}})),_("Breakdown · timeline",w)}return P.has("osd")&&(j(Ar(a(),v,m,F.play,E,{x:-.33,y:.465,size:22,color:"#ffffff",font:"Courier New",weight:700,k:rt,glow:!1})),_("Breakdown · REC",[{id:"rec",name:"Rec",type:"ellipse",params:{w:22,h:22},pos:[D(.06),U(.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,V)=>({time:Vt(V*.5),value:V%2?0:1}))}}]),s.forEach((lt,V)=>{const h=lt.start-d,w=Math.floor(h/60),T=(h%60).toFixed(1).padStart(4,"0");j(Ar(a(),Vt(lt.start+$),lt.duration,`${F.shot} ${String(V+1).padStart(2,"0")} 00:${String(w).padStart(2,"0")}:${T}`,E,{x:.22,y:.465,size:20,color:"#ffffff",font:"Courier New",weight:700,k:rt,glow:!1}))})),{add:z,shots:s.map(lt=>lt.id),start:v,end:x,style:E.id,layout:k}}const wA=String.raw`
336
+ const L=S.look
337
+ const FONTS={mont:'"Clipoox Montserrat", system-ui, sans-serif',anton:'"Clipoox Anton", Impact, sans-serif',oswald:'"Clipoox Oswald", "Arial Narrow", sans-serif',play:'"Clipoox Playfair Display", Georgia, serif',bevn:'"Clipoox Be Vietnam Pro", system-ui, sans-serif',bungee:'"Clipoox Bungee", Impact, sans-serif',mono:'"SF Mono", Menlo, "Courier New", monospace'}
338
+ function FF(env,k){const f=env.fonts||{};return (k!=='mono'&&f[k])||FONTS[k]||FONTS.mont}
339
+ const KEYS=[['q','w','e','r','t','y','u','i','o','p'],['a','s','d','f','g','h','j','k','l'],['z','x','c','v','b','n','m']]
340
+ const LIGHT=['widget','paper','comic'].includes(L.frame)
341
+ function rr(g,x,y,w,h,r){r=Math.max(0,Math.min(r,w/2,h/2));g.beginPath();g.moveTo(x+r,y);g.arcTo(x+w,y,x+w,y+h,r);g.arcTo(x+w,y+h,x,y+h,r);g.arcTo(x,y+h,x,y,r);g.arcTo(x,y,x+w,y,r);g.closePath()}
342
+ function poly(g,pts){g.beginPath();pts.forEach((p,i)=>i?g.lineTo(p[0],p[1]):g.moveTo(p[0],p[1]));g.closePath()}
343
+ function glowStroke(g,w,c,blur){g.lineWidth=w;g.strokeStyle=c||L.line;if(blur){g.shadowColor=c||L.line;g.shadowBlur=blur}g.stroke();g.shadowBlur=0}
344
+ // the panel's body in its design: x, y, w, h in the element canvas; role = chip | box | card | key
345
+ function box(g,x,y,w,h,role,a,t){
346
+ g.save();g.globalAlpha=a;const s=Math.min(w,h),lw=Math.max(1.5,s*.018)
347
+ const F=L.frame
348
+ if(F==='glass'){rr(g,x,y,w,h,role==='chip'?h/2:s*.12);g.fillStyle=L.fill;g.fill();const gr=g.createLinearGradient(x,y,x,y+h);gr.addColorStop(0,'rgba(255,255,255,0.16)');gr.addColorStop(.5,'rgba(255,255,255,0.02)');g.fillStyle=gr;g.fill();glowStroke(g,lw,L.line,L.glow)}
349
+ else if(F==='cut'){const c=s*.16;poly(g,[[x+c,y],[x+w,y],[x+w,y+h-c],[x+w-c,y+h],[x,y+h],[x,y+c]]);g.fillStyle=L.fill;g.fill();glowStroke(g,lw,L.line,L.glow)
350
+ const b=s*.12,o=lw*3;g.lineWidth=lw*1.6;g.strokeStyle=L.line;g.shadowColor=L.line;g.shadowBlur=L.glow*.6;[[x-o,y+b,x-o,y-o,x+b,y-o],[x+w+o-b,y+h+o,x+w+o,y+h+o,x+w+o,y+h+o-b]].forEach(p=>{g.beginPath();g.moveTo(p[0],p[1]);g.lineTo(p[2],p[3]);g.lineTo(p[4],p[5]);g.stroke()})
351
+ g.shadowBlur=0;g.globalAlpha=a*.5;for(let i=0;i<6;i++){g.fillStyle=L.line;g.fillRect(x+w*.62+i*w*.05,y+lw*2.5,w*.025,lw*1.4)}}
352
+ else if(F==='terminal'){rr(g,x,y,w,h,s*.05);g.fillStyle=L.fill;g.fill();g.lineWidth=lw*.8;g.strokeStyle=M.rgba(L.line,.5);g.stroke()
353
+ if(role!=='key'&&role!=='chip'){const bh=Math.max(10,h*.13);g.save();rr(g,x,y,w,h,s*.05);g.clip();g.fillStyle='rgba(255,255,255,0.08)';g.fillRect(x,y,w,bh);g.restore();['#ff5f57','#febc2e','#28c840'].forEach((c,i)=>{g.beginPath();g.arc(x+bh*.6+i*bh*.65,y+bh/2,bh*.2,0,7);g.fillStyle=c;g.fill()})}}
354
+ else if(F==='widget'){g.shadowColor='rgba(0,0,0,0.35)';g.shadowBlur=s*.18;g.shadowOffsetY=s*.05;rr(g,x,y,w,h,role==='key'?s*.18:role==='chip'?h/2:s*.2);g.fillStyle=L.fill;g.fill();g.shadowColor='transparent'}
355
+ else if(F==='wire'){g.setLineDash([]);rr(g,x,y,w,h,s*.04);glowStroke(g,lw*.8,L.line,L.glow*.6);g.save();rr(g,x,y,w,h,s*.04);g.clip();g.globalAlpha=a*.12;g.fillStyle=L.line;for(let yy=y;yy<y+h;yy+=4)g.fillRect(x,yy,w,1);g.restore()
356
+ g.fillStyle=L.line;[[x,y],[x+w,y],[x,y+h],[x+w,y+h]].forEach(p=>{g.fillRect(p[0]-lw*1.5,p[1]-lw*1.5,lw*3,lw*3)})}
357
+ else if(F==='neon'){rr(g,x,y,w,h,role==='chip'?h/2:s*.16);g.lineWidth=lw*3.2;g.strokeStyle=L.line;g.shadowColor=L.line;g.shadowBlur=L.glow*1.4;g.globalAlpha=a*.55;g.stroke();g.globalAlpha=a;g.shadowBlur=L.glow*.4;g.lineWidth=lw*1.1;g.strokeStyle='#ffffff';g.stroke();g.shadowBlur=0}
358
+ else if(F==='paper'){g.shadowColor='rgba(0,0,0,0.4)';g.shadowBlur=s*.08;g.shadowOffsetY=s*.03;g.fillStyle=L.fill;g.fillRect(x,y,w,h);g.shadowColor='transparent'
359
+ if(role!=='key'){g.fillStyle='rgba(255,236,170,0.75)';g.save();g.translate(x+w*.12,y);g.rotate(-.35);g.fillRect(-s*.12,-s*.035,s*.24,s*.07);g.restore();g.save();g.translate(x+w*.88,y);g.rotate(.35);g.fillRect(-s*.12,-s*.035,s*.24,s*.07);g.restore()}}
360
+ else if(F==='notch'){const c=s*.14;poly(g,[[x,y],[x+w-c,y],[x+w,y+c],[x+w,y+h],[x+c,y+h],[x,y+h-c]]);g.fillStyle=L.fill;g.fill();glowStroke(g,lw,L.line,L.glow*.5)
361
+ if(role!=='key'&&role!=='chip'){g.save();poly(g,[[x,y],[x+w-c,y],[x+w,y+c],[x+w,y+h],[x+c,y+h],[x,y+h-c]]);g.clip();g.globalAlpha=a*.5;g.fillStyle=L.line;for(let i=-4;i<24;i++){g.beginPath();g.moveTo(x+i*s*.06,y+h);g.lineTo(x+i*s*.06+s*.03,y+h);g.lineTo(x+i*s*.06+s*.03+h*.06,y+h-h*.06);g.lineTo(x+i*s*.06+h*.06,y+h-h*.06);g.fill()}g.restore()}}
362
+ else if(F==='pixel'){const p=Math.max(3,Math.round(s*.03));g.fillStyle=L.fill;g.fillRect(x+p,y,w-2*p,h);g.fillRect(x,y+p,w,h-2*p);g.fillStyle=L.line;g.fillRect(x+p,y,w-2*p,p);g.fillRect(x+p,y+h-p,w-2*p,p);g.fillRect(x,y+p,p,h-2*p);g.fillRect(x+w-p,y+p,p,h-2*p)
363
+ g.fillStyle='rgba(0,0,0,0.35)';g.fillRect(x+p,y+h,w-p,p);g.fillRect(x+w,y+p,p,h-p)}
364
+ else if(F==='comic'){if(role!=='key'){g.fillStyle='#111';g.fillRect(x+s*.04,y+s*.04,w,h)}g.fillStyle=L.fill;g.fillRect(x,y,w,h);g.lineWidth=Math.max(3,s*.035);g.strokeStyle='#111';g.strokeRect(x,y,w,h)
365
+ if(role==='box'||role==='chip'){g.save();g.beginPath();g.rect(x,y,w,h);g.clip();g.fillStyle=M.rgba(L.accent,.35);for(let yy=y;yy<y+h*.4;yy+=s*.05)for(let xx=x+w*.6;xx<x+w;xx+=s*.05){const r=s*.012*(1-(yy-y)/(h*.4));if(r>0){g.beginPath();g.arc(xx,yy,r,0,7);g.fill()}}g.restore()}
366
+ if(role==='chip'){g.fillStyle=L.fill;g.beginPath();g.moveTo(x+w*.2,y+h);g.lineTo(x+w*.15,y+h+h*.4);g.lineTo(x+w*.32,y+h);g.closePath();g.fill();g.lineWidth=Math.max(3,s*.035);g.strokeStyle='#111';g.beginPath();g.moveTo(x+w*.2,y+h);g.lineTo(x+w*.15,y+h+h*.4);g.lineTo(x+w*.32,y+h);g.stroke()}}
367
+ else if(F==='underline'){g.fillStyle=L.line;g.shadowColor=L.line;g.shadowBlur=L.glow;g.fillRect(x,y+h-lw,w*(role==='key'?1:M.ease.outCubic(M.clamp(t*2,0,1))),lw);g.shadowBlur=0;if(role!=='key'){g.fillRect(x,y+h*.2,lw*1.5,h*.6)}}
368
+ else if(F==='bubble'){const r=role==='key'?s*.2:Math.min(h*.45,s*.3);rr(g,x,y,w,h,r);g.fillStyle=role==='key'?'rgba(255,255,255,0.9)':L.fill;g.fill();if(role==='box'||role==='chip'){g.beginPath();g.moveTo(x+w-r*.4,y+h-r*.6);g.quadraticCurveTo(x+w+r*.35,y+h+r*.1,x+w+r*.45,y+h);g.quadraticCurveTo(x+w-r*.1,y+h+r*.05,x+w-r*1.1,y+h-r*.05);g.fill()}}
369
+ else if(F==='radial'){if(role==='chip'){rr(g,x,y,w,h,h/2);g.fillStyle=L.fill;g.fill();glowStroke(g,lw,L.line,L.glow)}else{rr(g,x,y,w,h,s*.08);g.fillStyle=L.fill;g.fill();glowStroke(g,lw*.7,M.rgba(L.line,.6),0)}}
370
+ else if(F==='film'){g.fillStyle=L.fill;g.fillRect(x,y,w,h);if(role!=='key'){const hs=Math.max(6,h*.07),gp=hs*1.8;g.fillStyle='rgba(255,255,255,0.85)';for(let xx=x+gp*.5;xx<x+w-hs;xx+=gp){rr(g,xx,y+hs*.5,hs,hs*.8,hs*.2);g.fill();rr(g,xx,y+h-hs*1.3,hs,hs*.8,hs*.2);g.fill()}}else{g.lineWidth=lw*.6;g.strokeStyle=M.rgba(L.line,.4);g.strokeRect(x,y,w,h)}}
371
+ else if(F==='luxe'){g.fillStyle=L.fill;g.fillRect(x,y,w,h);g.lineWidth=Math.max(1,lw*.5);g.strokeStyle=L.line;g.strokeRect(x,y,w,h);if(role!=='key'){const i=s*.04;g.strokeRect(x+i,y+i,w-2*i,h-2*i);g.fillStyle=L.line;g.save();g.translate(x+w/2,y);g.rotate(Math.PI/4);g.fillRect(-s*.025,-s*.025,s*.05,s*.05);g.restore()}}
372
+ g.restore()
373
+ }
374
+ // text inside a panel: dark on the light designs, mono / caps per design
375
+ function inkOf(){return L.text}
376
+ function fontOf(env,wt,px){const caps=['cut','notch','film','pixel'].includes(L.frame);return [(L.frame==='luxe'||L.frame==='paper')&&wt<700?'italic ':'',wt,' ',Math.round(px),'px ',FF(env,L.font)].join('')}
377
+ function txt(s){return ['cut','notch','film','pixel'].includes(L.frame)?String(s).toUpperCase():String(s)}
378
+ function wrap(g,text,maxW){const words=String(text).split(' '),lines=[];let cur='';for(const w of words){const n=cur?cur+' '+w:w;if(g.measureText(n).width>maxW&&cur){lines.push(cur);cur=w}else cur=n}if(cur||!lines.length)lines.push(cur);return lines}
379
+ function typedAt(t){let n=0;for(let i=0;i<TT.length;i++)if(TT[i]<=t)n=i+1;return n}
380
+ function draw(g,t,DW,DH,env){
381
+ const pad=DH*.08
382
+ if(S.kind==='chip'){box(g,4,4,DW-8,DH-8-(L.frame==='comic'?DH*.25:0),'chip',1,t);g.fillStyle=inkOf();g.font=fontOf(env,600,DH*.36);g.textBaseline='middle';g.textAlign='center';g.fillText(txt(S.text),DW/2,(DH-(L.frame==='comic'?DH*.25:0))/2,DW-DH*.6);return}
383
+ if(S.kind==='prompt'){
384
+ const ch=DH*.18,n=typedAt(t)
385
+ // the model line: a chip over the box, or the window title (terminal), or the slate (film)
386
+ if(L.frame==='terminal'){box(g,2,0,DW-4,DH-2,'box',1,t);g.fillStyle=M.rgba(L.text,.6);g.font=fontOf(env,500,DH*.05);g.textBaseline='middle';g.textAlign='center';g.fillText(S.label+' '+S.model,DW/2,DH*.065)}
387
+ else if(L.frame==='bubble'){g.fillStyle=M.rgba('#ffffff',.85);g.font=fontOf(env,600,ch*.4);g.textAlign='left';g.textBaseline='middle';g.fillText(S.label+' '+S.model,DW*.05,ch*.45)}
388
+ else{box(g,DW*.04,0,DW*.6,ch,'chip',1,t);g.textBaseline='middle';g.textAlign='left';g.font=fontOf(env,500,ch*.4);g.fillStyle=inkOf();const lab=txt(S.label)+' ',lw=g.measureText(lab).width;g.fillText(lab,DW*.08,ch/2);g.fillStyle=L.accent;g.font=fontOf(env,700,ch*.4);g.fillText(txt(S.model),DW*.08+lw,ch/2,DW*.52-lw)}
389
+ const by=L.frame==='terminal'?DH*.15:ch+DH*.05,bh=DH-by-4,bx=L.frame==='radial'?DH*.42:0
390
+ if(L.frame!=='terminal')box(g,2,by,DW-4-(L.frame==='bubble'?DH*.08:0),bh,'box',1,t)
391
+ if(L.frame==='radial'){const cx=bh*.42+8,cy=by+bh/2,r=bh*.3,p=TT.length?n/TT.length:0;g.lineWidth=bh*.07;g.strokeStyle=M.rgba(L.line,.2);g.beginPath();g.arc(cx,cy,r,0,7);g.stroke();g.strokeStyle=L.accent;g.shadowColor=L.accent;g.shadowBlur=L.glow;g.beginPath();g.arc(cx,cy,r,-Math.PI/2,-Math.PI/2+p*Math.PI*2);g.stroke();g.shadowBlur=0;g.fillStyle=L.text;g.font=fontOf(env,700,r*.55);g.textAlign='center';g.textBaseline='middle';g.fillText(Math.round(p*100)+'%',cx,cy)}
392
+ // chat: three bouncing dots until the first letter
393
+ if(L.frame==='bubble'&&TT.length&&t<TT[0]){for(let i=0;i<3;i++){const yy=by+bh/2-Math.max(0,Math.sin((t*8-i*.8)))*bh*.08;g.beginPath();g.arc(DW*.12+i*bh*.16,yy,bh*.05,0,7);g.fillStyle='rgba(255,255,255,0.9)';g.fill()}return}
394
+ const shown=S.text.slice(0,n),fs=Math.round(bh*(L.frame==='terminal'?.13:.15)),x0=pad*1.2+bx;g.font=fontOf(env,L.frame==='terminal'?500:500,fs);g.fillStyle=inkOf();g.textBaseline='top';g.textAlign='left'
395
+ const lead=L.frame==='terminal'?'> ':'',maxW=DW-pad*2.4-bx-(L.frame==='bubble'?DH*.08:0)
396
+ const lines=wrap(g,lead+txt(shown),maxW).slice(-4)
397
+ lines.forEach((l,i)=>{if(L.frame==='luxe'){const tr=Math.max(0,1-M.clamp((t-.1)/.8,0,1));g.fillText(l.split('').join(tr>0.05?' ':''),x0,by+pad+i*fs*1.3)}else g.fillText(l,x0,by+pad+i*fs*1.3)})
398
+ const typing=n>0&&n<S.text.length,blink=typing||Math.floor(t*2)%2===0,last=lines[lines.length-1]||'',cx=x0+g.measureText(last).width+3,cy=by+pad+(lines.length-1)*fs*1.3
399
+ if(blink&&TT.length&&t>=TT[0]-.6){g.fillStyle=L.accent;if(L.frame==='terminal'||L.frame==='pixel')g.fillRect(cx,cy,fs*.55,fs);else g.fillRect(cx,cy,Math.max(2,fs*.08),fs*1.05)}
400
+ return}
401
+ if(S.kind==='grid')return drawGrid(g,t,DW,DH,env)
402
+ if(S.kind==='cta'){
403
+ const C=S.cta;g.textAlign='center';g.textBaseline='middle';g.fillStyle=L.frame==='comic'||L.frame==='paper'?'#ffffff':L.text;g.font=fontOf(env,500,DH*.075);g.fillText(txt(C.lead),DW/2,DH*.1)
404
+ const pop=L.frame==='luxe'?M.ease.outCubic(M.clamp((t-.15)/.7,0,1)):M.ease.outBack(M.clamp((t-.15)/.45,0,1))
405
+ g.save();g.translate(DW/2,DH*.28);g.scale(pop,pop)
406
+ if(L.frame==='comic'){g.fillStyle='#ffd23f';g.beginPath();for(let i=0;i<24;i++){const r=i%2?DH*.13:DH*.24,a=i/24*Math.PI*2;g.lineTo(Math.cos(a)*r*2.2,Math.sin(a)*r)}g.closePath();g.fill();g.lineWidth=5;g.strokeStyle='#111';g.stroke()}
407
+ const big=L.frame==='luxe'||L.frame==='paper'?'italic 800 '+Math.round(DH*.17)+'px '+FF(env,'play'):L.frame==='terminal'?'700 '+Math.round(DH*.14)+'px '+FF(env,'mono'):L.frame==='pixel'||L.frame==='neon'||L.frame==='comic'?'400 '+Math.round(DH*.16)+'px '+FF(env,'bungee'):'italic 400 '+Math.round(DH*.2)+'px '+FF(env,'anton')
408
+ g.font=big;g.fillStyle=L.frame==='comic'?'#111':L.accent;if(L.glow){g.shadowColor=L.accent;g.shadowBlur=L.glow}g.fillText((L.frame==='terminal'?'$ ':'')+'“'+C.word+'”',0,0,DW*.96);g.restore()
409
+ const n=C.chips.length,cw=DW*.32,chh=DH*.16,gap=DW*.04,x0=DW/2-(n*cw+(n-1)*gap)/2
410
+ C.chips.forEach((tx,k)=>{const e=M.ease.outCubic(M.clamp((t-.45-k*.15)/.35,0,1));if(e<=0)return;const x=x0+k*(cw+gap),y=DH*.47+(1-e)*DH*.04;box(g,x,y,cw,chh,'card',e,t)
411
+ const parts=String(tx).split('|');g.save();g.globalAlpha=e;g.textAlign='center';parts.forEach((p,i)=>{g.fillStyle=i?inkOf():L.accent;g.font=i?fontOf(env,600,chh*.17):fontOf(env,800,chh*.25);g.fillText(txt(p.trim()),x+cw/2,y+chh*(parts.length>1?(.36+.34*i):.5),cw*.9)});g.restore()})
412
+ if(C.doc){const e=M.ease.outCubic(M.clamp((t-.45-n*.15)/.35,0,1));if(e>0){const w=DW*.2,h=DH*.2,x=DW/2-w/2,y=DH*.7;box(g,x,y,w,h,'card',e,t);g.save();g.globalAlpha=e;g.strokeStyle=inkOf();g.lineWidth=2.5;const ix=x+w/2-w*.12,iy=y+h*.14,iw=w*.24,ih=h*.42;rr(g,ix,iy,iw,ih,3);g.stroke();for(let i=0;i<3;i++){g.beginPath();g.moveTo(ix+iw*.2,iy+ih*(.35+i*.2));g.lineTo(ix+iw*.8,iy+ih*(.35+i*.2));g.stroke()}
413
+ g.fillStyle=inkOf();g.font=fontOf(env,600,h*.13);g.textAlign='center';g.fillText(txt(C.doc),x+w/2,y+h*.8,w*.92);g.restore()}}
414
+ return}
415
+ if(S.kind==='keyboard')return drawKeys(g,t,DW,DH,env)
416
+ }
417
+ function litMap(t){const lit={},n=typedAt(t);for(let i=0;i<TT.length;i++){const d=t-TT[i];if(d>=-.02&&d<.2){let ch=S.text[i].toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g,'').replace('đ','d');if(ch===' ')ch='space';lit[ch]=Math.max(lit[ch]||0,1-d/.2)}}
418
+ if(n>=S.text.length&&TT.length&&t-TT[TT.length-1]>.25&&t-TT[TT.length-1]<.6)lit.enter=1;return lit}
419
+ function drawKeys(g,t,DW,DH,env){
420
+ const lit=litMap(t),K=L.keys
421
+ if(K==='radial'){const cx=DW/2,cy=DH*1.05,R=DH*.92,all=KEYS.flat();all.forEach((k,i)=>{const a=Math.PI*(1.08+.84*i/(all.length-1)),x=cx+Math.cos(a)*R,y=cy+Math.sin(a)*R*.95,v=lit[k]||0,r=DH*.075*(1+.35*v)
422
+ g.beginPath();g.arc(x,y,r,0,7);g.fillStyle=v?M.rgba(L.accent,.5+.5*v):'rgba(255,255,255,0.08)';g.fill();g.lineWidth=2;g.strokeStyle=v?L.accent:M.rgba(L.line,.6);if(v){g.shadowColor=L.accent;g.shadowBlur=L.glow*1.5}g.stroke();g.shadowBlur=0;g.fillStyle=v?'#fff':L.text;g.font=fontOf(env,700,r*.9);g.textAlign='center';g.textBaseline='middle';g.fillText(k.toUpperCase(),x,y)})
423
+ const sv=lit.space||0;g.beginPath();g.arc(cx,cy,R*.55,Math.PI*1.15,Math.PI*1.85);g.lineWidth=DH*.08;g.strokeStyle=sv?L.accent:M.rgba(L.line,.25);g.lineCap='round';g.stroke();g.lineCap='butt';return}
424
+ const kw=DW/10.6,kh=DH/4.6,g1=kw*.12
425
+ const key=(x,y,w,h,label,v)=>{
426
+ g.save()
427
+ if(K==='flat'){rr(g,x,y,w,h,h*.18);g.fillStyle=v?M.rgba(L.accent,.35+.5*v):'rgba(255,255,255,0.10)';g.fill();g.lineWidth=v?2.5:1.3;g.strokeStyle=v?L.accent:M.rgba(L.line,.7);if(v){g.shadowColor=L.accent;g.shadowBlur=L.glow*1.4*v}g.stroke()}
428
+ else if(K==='outline'){rr(g,x,y,w,h,K==='outline'&&L.frame==='cut'?0:h*.25);if(v){g.fillStyle=M.rgba(L.accent,.6*v);g.fill()}g.lineWidth=2;g.strokeStyle=L.line;g.shadowColor=L.line;g.shadowBlur=v?L.glow*1.6:L.glow*.3;g.globalAlpha=.5+.5*v;g.stroke()}
429
+ else if(K==='mono'){g.font=fontOf(env,500,h*.42);g.fillStyle=v?L.accent:M.rgba(L.text,.55);g.textAlign='center';g.textBaseline='middle';if(label)g.fillText('['+label+']',x+w/2,y+h/2);if(v){g.fillStyle=M.rgba(L.accent,.25*v);g.fillRect(x,y,w,h)}g.restore();return}
430
+ else if(K==='ios'){g.shadowColor='rgba(0,0,0,0.35)';g.shadowBlur=3;g.shadowOffsetY=2;rr(g,x,y,w,h,h*.16);g.fillStyle='rgba(255,255,255,0.92)';g.fill();g.shadowColor='transparent'
431
+ if(v&&label){rr(g,x-w*.15,y-h*1.25,w*1.3,h*1.2,h*.2);g.fillStyle='#ffffff';g.fill();g.fillStyle='#111';g.font='500 '+Math.round(h*.75)+'px '+FF(env,'bevn');g.textAlign='center';g.textBaseline='middle';g.fillText(label.toLowerCase(),x+w/2,y-h*.65)}}
432
+ else if(K==='dots'){const n=4;for(let i=0;i<n;i++)for(let j=0;j<3;j++){g.beginPath();g.arc(x+w*(i+.5)/n,y+h*(j+.5)/3,Math.min(w,h)*.05*(1+2*v),0,7);g.fillStyle=v?L.accent:M.rgba(L.line,.35);g.fill()}}
433
+ else if(K==='round'){const r=Math.min(w,h)*.48;g.beginPath();g.arc(x+w/2,y+h/2,r,0,7);g.fillStyle=L.frame==='comic'?'#fff':'#2b2b2b';g.fill();g.lineWidth=Math.max(2,r*.16);g.strokeStyle=v?L.accent:L.frame==='comic'?'#111':'#c9b48a';g.stroke();if(v){g.beginPath();g.arc(x+w/2,y+h/2+r*.12,r*.92,0,7);g.fillStyle=M.rgba(L.accent,.35);g.fill()}}
434
+ else if(K==='pixel'){g.fillStyle=v?L.accent:'rgba(255,255,255,0.12)';g.fillRect(x,y+(v?3:0),w,h-3);if(!v){g.fillStyle='rgba(0,0,0,0.45)';g.fillRect(x,y+h-3,w,3)}}
435
+ else if(K==='minimal'){if(v){g.fillStyle=L.accent;g.shadowColor=L.accent;g.shadowBlur=L.glow*2;g.fillRect(x+w*.2,y+h-3,w*.6,2)}}
436
+ if(label){g.shadowBlur=0;const ink=K==='ios'?'#111':K==='round'&&L.frame!=='comic'?'#f6f1e4':K==='round'?'#111':v?'#ffffff':L.text;g.fillStyle=ink;g.globalAlpha=K==='minimal'?.55+.45*v:1;g.font=fontOf(env,K==='minimal'?400:700,h*(K==='minimal'?.5+.15*v:.36));g.textAlign='center';g.textBaseline='middle';g.fillText(label,x+w/2,y+h/2)}
437
+ g.restore()}
438
+ KEYS.forEach((row,ri)=>{const off=ri*kw*.5+(DW-10*kw-g1*9)/2;row.forEach((k,ci)=>key(off+ci*(kw+g1)+g1/2,ri*(kh+g1)+g1,kw-g1,kh-g1*.4,K==='mono'?k:k.toUpperCase(),lit[k]||0))})
439
+ key(DW*.27,3*(kh+g1)+g1,DW*.46,kh-g1*.4,K==='mono'?'space':'',lit.space||0);key(DW*.76,3*(kh+g1)+g1,DW*.2,kh-g1*.4,K==='mono'?'enter':'⏎',lit.enter||0)
440
+ }
441
+ function drawGrid(g,t,DW,DH,env){
442
+ const n=S.items.length,G=L.grid,picked=S.pick>=0&&t>=S.pickAt,pk=M.ease.outCubic(M.clamp((t-S.pickAt)/.4,0,1))
443
+ const card=(k,cx,cy,cw,chh,rot,e,z)=>{if(e<=0)return;const me=picked&&S.pick===k,dim=picked&&!me?.35:1,s=(G==='ring'?z:1)*(me?1+.14*pk:1)
444
+ g.save();g.translate(cx,cy);g.rotate(rot*(me?1-pk:1));g.scale(s,s);g.globalAlpha=Math.min(1,e)*dim
445
+ const it=S.items[k],img=it.img&&M.asset?M.asset(it.img):null,pol=G==='polaroid',bw=pol?cw*.06:0,x=-cw/2,y=-chh/2
446
+ box(g,x,y,cw,chh+(pol?cw*.18:0),'card',1,t)
447
+ const ix=x+bw,iy=y+bw,iw=cw-bw*2,ih=chh-bw*2;g.save();g.beginPath();g.rect(ix,iy,iw,ih);g.clip()
448
+ if(img&&img.width){const sc=Math.max(iw/img.width,ih/img.height);g.drawImage(img,ix+iw/2-img.width*sc/2,iy+ih/2-img.height*sc/2,img.width*sc,img.height*sc)}
449
+ else{const base=L.frame==='bubble'?'#ffffff':L.accent,gr=g.createLinearGradient(ix,iy,ix+iw,iy+ih);gr.addColorStop(0,M.rgba(base,LIGHT?.18:.12));gr.addColorStop(1,M.rgba(base,LIGHT?.45:.38));g.fillStyle=gr;g.fillRect(ix,iy,iw,ih);g.fillStyle=LIGHT?'#222':L.text;g.font=fontOf(env,700,Math.min(iw,ih)*.22);g.textAlign='center';g.textBaseline='middle';g.fillText(txt(it.title||''),0,iy+ih/2,iw*.9)}
450
+ g.restore()
451
+ if(pol){g.fillStyle='#333';g.font=fontOf(env,500,cw*.09);g.textAlign='center';g.fillText('#'+(k+1),0,chh/2+cw*.09)}
452
+ if(me){rr(g,x-3,y-3,cw+6,chh+6+(pol?cw*.18:0),cw*.05);g.lineWidth=4;g.strokeStyle=L.accent;g.shadowColor=L.accent;g.shadowBlur=(L.glow||8)*1.6;g.stroke()}
453
+ g.restore()}
454
+ const appear=k=>M.ease.outBack(M.clamp((t-.08-k*.09)/.4,0,1))
455
+ if(G==='grid'){const c=S.cols,r=Math.ceil(n/c),gap=DW*.035,cw=(DW-gap*(c+1))/c,chh=(DH-gap*(r+1))/r
456
+ for(let k=0;k<n;k++){const i=Math.floor(k/c),j=k%c,e=appear(k),x=gap+j*(cw+gap)+cw/2,y=gap+i*(chh+gap)+chh/2;card(k,x+(DW/2-x)*(1-e),y+(DH/2-y)*(1-e),cw*(.6+.4*e),chh*(.6+.4*e),0,e,1)}}
457
+ else if(G==='fan'){const cw=DW*.3,chh=cw*1.3;for(let k=0;k<n;k++){const e=appear(k),u=n>1?k/(n-1)-.5:0,ang=u*1.1*e,x=DW/2+Math.sin(ang)*DH*.9,y=DH*.95-Math.cos(ang)*DH*.6;card(k,x,y,cw,chh,ang,e,1)}}
458
+ else if(G==='list'){const rh=DH/(n+.5);for(let k=0;k<n;k++){const e=M.clamp((t-.1-k*.12)/.15,0,1);if(e<=0)continue;const y=rh*(k+.5),me=picked&&S.pick===k
459
+ g.save();g.globalAlpha=picked&&!me?.4:1;if(me){g.fillStyle=M.rgba(L.accent,.25);g.fillRect(0,y,DW,rh*.9)}g.fillStyle=L.accent;g.font=fontOf(env,500,rh*.4);g.textAlign='left';g.textBaseline='middle';g.fillText((me?'> ':' ')+'img_0'+(k+1)+'.png',DW*.03,y+rh*.45)
460
+ g.fillStyle=M.rgba(L.text,.6);g.textAlign='right';g.fillText((1.2+k*.37).toFixed(1)+' MB ✓',DW*.97,y+rh*.45);const tw=rh*.75;g.save();g.translate(DW*.55,y+rh*.45);card(k,0,0,tw*1.3,tw,0,1,1);g.restore();g.restore()}}
461
+ else if(G==='stack'){const cw=DW*.42,chh=cw*.72;for(let k=0;k<n;k++){const e=M.ease.outCubic(M.clamp((t-.1-k*.14)/.35,0,1)),col=k%2,row=Math.floor(k/2),x=DW*(col?.71:.29),y=DH*.16+row*chh*1.12+(1-e)*DH*.08;card(k,x,y,cw,chh,0,e,1)}}
462
+ else if(G==='polaroid'){const cw=DW*.3,chh=cw;for(let k=0;k<n;k++){const e=M.ease.outBack(M.clamp((t-.1-k*.12)/.35,0,1)),i=Math.floor(k/3),j=k%3,rot=((k*37)%7-3)*.06,x=DW*(.2+.3*j)+((k*13)%5-2)*6,y=DH*(.3+.42*i)-(1-e)*DH*.4;card(k,x,y,cw,chh,rot,e,1)}}
463
+ else if(G==='strip'){const cw=DW*.3,chh=cw*.7,hs=chh*.12,slide=(1-M.ease.outCubic(M.clamp((t-.05)/.7,0,1)))*DW*.8,pickShift=picked?(DW/2-(cw*.55+S.pick*cw*1.05))*pk:0
464
+ g.fillStyle='rgba(10,10,10,0.88)';g.fillRect(0,DH/2-chh*.75,DW,chh*1.5);g.fillStyle='rgba(255,255,255,0.8)';for(let x=6;x<DW;x+=hs*2){g.fillRect(x,DH/2-chh*.7,hs,hs*.8);g.fillRect(x,DH/2+chh*.7-hs*.8,hs,hs*.8)}
465
+ for(let k=0;k<n;k++)card(k,cw*.55+k*cw*1.05+slide+pickShift,DH/2,cw,chh,0,1,1)}
466
+ else if(G==='ring'){const rot=t*.5+(picked?pk*0:0),items=[];for(let k=0;k<n;k++){const a=k/n*Math.PI*2+rot-(picked?((S.pick/n*Math.PI*2+rot)%(Math.PI*2))*pk:0),z=(Math.cos(a)+1.6)/2.6;items.push({k,x:DW/2+Math.sin(a)*DW*.36,y:DH*.5,z})}
467
+ items.sort((a,b)=>a.z-b.z).forEach(o=>card(o.k,o.x,o.y,DW*.26,DW*.32,0,appear(o.k),o.z))}
468
+ }
469
+ // the element's 4 corners on screen (TL TR BL BR, px): a w (of the frame width) × its-aspect rectangle at (x, y), turned
470
+ // tiltX (top away) / tiltY (right side away) degrees, in perspective; stuck on a surface it fills the layer
471
+ function quad(W,H,DW,DH){
472
+ if(S.fill)return [[W*.04,H*.04],[W*.96,H*.04],[W*.04,H*.96],[W*.96,H*.96]]
473
+ const w=S.w*W,h=w*DH/DW,ax=S.tiltX*Math.PI/180,ay=S.tiltY*Math.PI/180,D=W*1.6,cx=(.5+S.x)*W,cy=(.5+S.y)*H
474
+ return [[-w/2,-h/2],[w/2,-h/2],[-w/2,h/2],[w/2,h/2]].map(([x,y])=>{const X=x*Math.cos(ay),Y=y*Math.cos(ax),Z=x*Math.sin(ay)-y*Math.sin(ax),s=D/(D+Z);return [cx+X*s,cy+Y*s]})
475
+ }
476
+ function warp(ctx,img,iw,ih,q,sx0,sy0,sx1,sy1){sx0=sx0||0;sy0=sy0||0;sx1=sx1==null?1:sx1;sy1=sy1==null?1:sy1;const N=6;for(let i=0;i<N;i++)for(let j=0;j<N;j++){const u0=sx0+(sx1-sx0)*j/N,u1=sx0+(sx1-sx0)*(j+1)/N,v0=sy0+(sy1-sy0)*i/N,v1=sy0+(sy1-sy0)*(i+1)/N
477
+ const P=(u,v)=>[q[0][0]*(1-u)*(1-v)+q[1][0]*u*(1-v)+q[2][0]*(1-u)*v+q[3][0]*u*v,q[0][1]*(1-u)*(1-v)+q[1][1]*u*(1-v)+q[2][1]*(1-u)*v+q[3][1]*u*v]
478
+ const a=P(u0,v0),b=P(u1,v0),c=P(u0,v1),d=P(u1,v1);for(const [s0,s1,s2,d0,d1,d2] of [[[u0,v0],[u1,v0],[u0,v1],a,b,c],[[u1,v0],[u1,v1],[u0,v1],b,d,c]]){
479
+ ctx.save();ctx.beginPath();const mx=(d0[0]+d1[0]+d2[0])/3,my=(d0[1]+d1[1]+d2[1])/3,gr=p=>{const dx=p[0]-mx,dy=p[1]-my,l=Math.hypot(dx,dy)||1;return [p[0]+dx/l*.7,p[1]+dy/l*.7]}
480
+ const e0=gr(d0),e1=gr(d1),e2=gr(d2);ctx.moveTo(e0[0],e0[1]);ctx.lineTo(e1[0],e1[1]);ctx.lineTo(e2[0],e2[1]);ctx.closePath();ctx.clip()
481
+ const S0=[s0[0]*iw,s0[1]*ih],S1=[s1[0]*iw,s1[1]*ih],S2=[s2[0]*iw,s2[1]*ih],den=S0[0]*(S1[1]-S2[1])+S1[0]*(S2[1]-S0[1])+S2[0]*(S0[1]-S1[1])
482
+ if(Math.abs(den)>1e-9){const A=(d0[0]*(S1[1]-S2[1])+d1[0]*(S2[1]-S0[1])+d2[0]*(S0[1]-S1[1]))/den,B=(d0[1]*(S1[1]-S2[1])+d1[1]*(S2[1]-S0[1])+d2[1]*(S0[1]-S1[1]))/den
483
+ const C=(d0[0]*(S2[0]-S1[0])+d1[0]*(S0[0]-S2[0])+d2[0]*(S1[0]-S0[0]))/den,Dd=(d0[1]*(S2[0]-S1[0])+d1[1]*(S0[0]-S2[0])+d2[1]*(S1[0]-S0[0]))/den
484
+ const E=(d0[0]*(S1[0]*S2[1]-S2[0]*S1[1])+d1[0]*(S2[0]*S0[1]-S0[0]*S2[1])+d2[0]*(S0[0]*S1[1]-S1[0]*S0[1]))/den,F=(d0[1]*(S1[0]*S2[1]-S2[0]*S1[1])+d1[1]*(S2[0]*S0[1]-S0[0]*S2[1])+d2[1]*(S0[0]*S1[1]-S1[0]*S0[1]))/den
485
+ ctx.transform(A,B,C,Dd,E,F);ctx.drawImage(img,0,0)}
486
+ ctx.restore()}}}
487
+ function size(){const k=S.kind
488
+ if(k==='keyboard')return L.keys==='radial'?[1100,560]:[1100,520]
489
+ if(k==='chip')return [Math.round(260+S.text.length*15),L.frame==='comic'?130:100]
490
+ if(k==='cta')return [900,760]
491
+ if(k==='grid')return L.grid==='stack'?[900,Math.round(900*.42*.72*1.12*Math.ceil(S.items.length/2)+900*.2)]:L.grid==='grid'?[900,Math.round(900*Math.ceil(S.items.length/S.cols)/S.cols*1.25)]:L.grid==='list'?[900,Math.round(110*(S.items.length+.5))]:L.grid==='strip'?[1000,420]:L.grid==='ring'?[1000,560]:[900,760]
492
+ return [1000,560]}
493
+ function render(ctx,t,env){
494
+ const W=env.width,H=env.height,dur=env.duration,E=L.enter
495
+ const len=E==='step'?.5:E==='drop'?.6:E==='spring'?.7:E==='track'?.9:E==='scan'?.55:E==='strip'?.55:.35
496
+ const on=M.clamp((t-.02)/len,0,1),off=M.clamp((dur-t)/.3,0,1);if(on<=0||off<=0)return
497
+ const [DW,DH]=size(),cv=typeof OffscreenCanvas!=='undefined'?new OffscreenCanvas(DW,DH):null;if(!cv)return
498
+ draw(cv.getContext('2d'),t,DW,DH,env)
499
+ let q=quad(W,H,DW,DH),a=off,sx=1,sy=1,dx=0,dy=0,rot=L.frame==='paper'?-.035:0,clipY=1,iris=1,slices=0
500
+ const eo=M.ease.outCubic(on)
501
+ if(E==='flicker'){a*=eo*(t<.3?(.55+.45*Math.abs(Math.sin(t*90))):1);sx=sy=.86+.14*M.ease.outBack(on)}
502
+ else if(E==='unfold'){sy=on<.4?.02:.02+.98*M.ease.outCubic((on-.4)/.6);sx=M.ease.outCubic(Math.min(1,on/.4));a*=Math.min(1,on*3)}
503
+ else if(E==='slide'){dy=(1-eo)*H*.08;a*=eo}
504
+ else if(E==='spring'){sx=sy=M.ease.outElastic?M.ease.outElastic(on)*.999+.001:eo;a*=Math.min(1,on*4)}
505
+ else if(E==='glitch'){a*=Math.min(1,on*3);slices=on<1?1-on:0}
506
+ else if(E==='buzz'){const f=t<.9?[1,0,1,1,0,0,1,.3,1,0,1,1,1][Math.floor(t*14)%13]:1;a*=f}
507
+ else if(E==='drop'){dy=-(1-M.ease.outBounce(on))*H*.25;rot+=(1-on)*.15;a*=Math.min(1,on*4)}
508
+ else if(E==='scan'){clipY=eo}
509
+ else if(E==='step'){const s=Math.ceil(on*4)/4;sx=sy=s;a*=on>0?1:0}
510
+ else if(E==='burst'){sx=sy=M.ease.outBack(on)*1.0;a*=Math.min(1,on*3)}
511
+ else if(E==='fade'){a*=eo;dy=(1-eo)*H*.015}
512
+ else if(E==='iris'){iris=eo}
513
+ else if(E==='strip'){dx=-(1-eo)*W*.6;a*=Math.min(1,on*2)}
514
+ else if(E==='track'){a*=eo}
515
+ const mx=(q[0][0]+q[3][0])/2,my=(q[0][1]+q[3][1])/2,cs=Math.cos(rot),sn=Math.sin(rot)
516
+ q=q.map(p=>{const x=(p[0]-mx)*sx,y=(p[1]-my)*sy;return [mx+x*cs-y*sn+dx,my+x*sn+y*cs+dy]})
517
+ ctx.save();ctx.globalAlpha=Math.max(0,a)
518
+ if(E==='burst'&&on<1){ctx.save();ctx.globalAlpha=(1-on)*.8;ctx.strokeStyle=L.accent;ctx.lineWidth=4;for(let i=0;i<16;i++){const an=i/16*Math.PI*2,r0=Math.hypot(q[1][0]-q[0][0],q[2][1]-q[0][1])*.35*(1+on),r1=r0*1.5;ctx.beginPath();ctx.moveTo(mx+Math.cos(an)*r0,my+Math.sin(an)*r0);ctx.lineTo(mx+Math.cos(an)*r1,my+Math.sin(an)*r1);ctx.stroke()}ctx.restore()}
519
+ if(E==='iris'&&iris<1){ctx.beginPath();ctx.arc(mx,my,Math.hypot(W,H)*.5*iris,0,7);ctx.clip()}
520
+ if(slices>0){const n=7;for(let i=0;i<n;i++){const off=(Math.sin(i*91.7+Math.floor(t*30)*3.1)*.5)*W*.08*slices,q2=q.map(p=>[p[0]+off,p[1]]);warp(ctx,cv,DW,DH,q2,0,i/n,1,(i+1)/n)}}
521
+ else warp(ctx,cv,DW,DH,q,0,0,1,clipY)
522
+ if(E==='scan'&&on<1){const y=q[0][1]+(q[2][1]-q[0][1])*clipY;ctx.globalCompositeOperation='lighter';ctx.strokeStyle=L.line;ctx.lineWidth=3;ctx.shadowColor=L.line;ctx.shadowBlur=14;ctx.beginPath();ctx.moveTo(q[0][0],y);ctx.lineTo(q[1][0],y);ctx.stroke()}
523
+ ctx.restore()
524
+ }`,Ho=(t,e,o,r,a,n,i,l,u)=>({id:t,vi:e,en:o,frame:r,enter:a,keys:n,grid:i,font:l,...u}),Ph=Object.freeze([Ho("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}),Ho("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}),Ho("terminal","Terminal","Terminal","terminal","slide","mono","list","mono",{line:"#2bff6a",fill:"rgba(4,10,6,0.86)",text:"#b9ffcf",accent:"#2bff6a",glow:10}),Ho("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}),Ho("wireframe","Khung dây","Wireframe","wire","glitch","dots","grid","mono",{line:"#7fb8ff",fill:"rgba(0,0,0,0)",text:"#cfe4ff",accent:"#7fb8ff",glow:12}),Ho("neon","Ống neon","Neon tube","neon","buzz","outline","fan","bungee",{line:"#ff4fd8",fill:"rgba(0,0,0,0)",text:"#ffe6fa",accent:"#ff4fd8",glow:26}),Ho("paper","Giấy & polaroid","Paper & polaroid","paper","drop","round","polaroid","play",{line:"#2b2b2b",fill:"#f6f1e4",text:"#1e1e1e",accent:"#d9472b",glow:0}),Ho("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}),Ho("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}),Ho("comic","Truyện tranh","Comic","comic","burst","round","polaroid","bungee",{line:"#111111",fill:"#ffffff",text:"#111111",accent:"#ff2e4d",glow:0}),Ho("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}),Ho("chat","Bong bóng chat","Chat bubbles","bubble","slide","ios","stack","bevn",{line:"#2f80ff",fill:"#2f80ff",text:"#ffffff",accent:"#2f80ff",glow:0}),Ho("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}),Ho("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}),Ho("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})]),ng=Ph.map(t=>t.id),ag=Object.freeze(["chip","prompt","grid","cta","keyboard"]),ar=Object.freeze({maxSeconds:30,text:160,chip:48,items:9,chips:3,cps:[4,40],tilt:75,width:[.1,1]}),pb=/^#[0-9a-fA-F]{6}$/,rc=t=>Math.round(t*1e3)/1e3,Hi=t=>Math.round(t*1e4)/1e4,ln=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,$n=(t,e)=>typeof t=="string"?t.replace(/[\u0000-\u001f]/g," ").trim().slice(0,e):"";function ub(t,e){const o=Ph.find(r=>r.id===t)??Ph[0];return pb.test(e??"")?{...o,accent:e.toLowerCase(),...o.glow?{line:e.toLowerCase()}:{}}:o}function hb(t,e=.4,o=14){const r=[],a=1/ln(o,...ar.cps,14);let n=e;for(let i=0;i<t.length;i++){r.push(rc(n));const l=t[i],u=(Math.sin((i+1)*12.9898)*43758.5453%1+1)%1;n+=a*(.7+.6*u)*(l===" "?1.4:/[,.!?]/.test(l)?2.2:1)}return r}const ig=(t,e)=>`const ${t}=${JSON.stringify(e)};`;function kA(t,e=[],o){return ko({code:[ig("S",t),ig("TT",e),wA].join(`
525
+ `),params:{color:t.look.accent},preset:`hud-${t.kind}`,...o&&Object.keys(o).length?{assets:o}:{}})}function xA(t,e,{materials:o=[],locale:r="vi",fill:a=!1}={}){if(!ag.includes(t))throw Error(`hudPanel kind: ${ag.join(" | ")}`);if(e.look!=null&&!ng.includes(e.look))throw Error(`HUD look: ${ng.join(" | ")}`);if(e.color!=null&&!pb.test(e.color))throw Error("HUD color must be #RRGGBB");const n=ub(e.look,e.color),i=r==="en",l={chip:[0,-.32,.6,8,-10],prompt:[0,-.12,.78,10,-8],grid:[0,-.12,.8,6,6],cta:[0,-.18,.86,0,0],keyboard:[0,.32,.9,52,0]}[t],u={kind:t,look:n,fill:!!a,x:Hi(ln(Number(e.posX),-.5,.5,l[0])),y:Hi(ln(Number(e.posY),-.5,.5,l[1])),w:Hi(ln(Number(e.width),...ar.width,l[2])),tiltX:rc(ln(Number(e.tiltX),-ar.tilt,ar.tilt,l[3])),tiltY:rc(ln(Number(e.tiltY),-ar.tilt,ar.tilt,l[4]))};let c=[],s={},d;if(t==="chip"&&(u.text=$n(e.text,ar.chip)||(i?"Random photos → AI Edit":"Ảnh bất kỳ → AI Edit"),d=`HUD · ${u.text}`),t==="prompt"||t==="keyboard"){if(u.text=$n(e.text,ar.text),!u.text)throw Error(`hudPanel ${t} needs text (the prompt that types in)`);c=hb(u.text,ln(Number(e.typeAt),0,ar.maxSeconds,.5),Number(e.cps)),t==="prompt"&&(u.label=$n(e.label,30)||(i?"Image model:":"Model ảnh:"),u.model=$n(e.model,30)||"Clipoox AI"),d=t==="prompt"?"HUD · prompt":"HUD · bàn phím"}if(t==="grid"){const f=Array.isArray(e.items)?e.items.slice(0,ar.items):null,m=f?f.length:Math.round(ln(Number(e.count),2,ar.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,$={title:$n(typeof v=="object"?v?.title:"",30)||`${g+1}`};if(x!=null){const E=o.find(k=>k.id===x);if(!E||E.kind!=="image"||typeof E.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]=E.gcsUri,$.img=S}u.items.push($)}u.cols=Math.round(ln(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=rc(ln(Number(e.pickAt),0,ar.maxSeconds,1.6)),d=`HUD · ${m} ảnh`}if(t==="cta"){const f=Array.isArray(e.chips)?e.chips.slice(0,ar.chips).map(m=>$n(m,48)).filter(Boolean):[];u.cta={lead:$n(e.lead,30)||(i?"comment":"bình luận"),word:$n(e.keyword,20).toUpperCase()||"CLIPOOX",chips:f,doc:e.doc===!1?"":$n(e.doc,20)||(i?"FULL GUIDE":"HƯỚNG DẪN")},d=`HUD · comment ${u.cta.word}`}return{S:u,TT:c,assets:s,label:d}}function MA(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 vA(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,l=f=>f*MA(t)*(o/r)*Math.cos(t.tiltX*Math.PI/180),u=(f,m)=>[.5+f-l(m)/2,.5+f+l(m)/2],c=f=>[.5+t.x-f/2,.5+t.x+f/2];if(!((f,m)=>{const[g,v]=u(f,m),[x,$]=c(m);return v>a&&g<n&&$>e.x-i&&x<e.x+i})(t.y,t.w))return"";const d=t.y;for(let f=t.w;f>=.3;f=Hi(f*.9)){const m=l(f),g=a-.012-m/2-.5,v=n+.012+m/2-.5,x=E=>.5+E-m/2>=.02&&.5+E+m/2<=.98,$=[g,v].filter(x).sort((E,S)=>Math.abs(E-d)-Math.abs(S-d))[0];if($!=null)return t.y=Hi($),t.w=f,`moved ${$<d?"up":"down"} off the face${f<.999*t.w,""}`}return t.w=.3,t.y=Hi(.48-l(.3)/2),"shrunk to the bottom edge, off the face"}const po=1/30,ue=(t,e,o)=>Math.max(e,Math.min(o,t)),ge=t=>+t.toFixed(4),Ce=(t,e)=>Number.isFinite(t)?t:e,$A=/^#[0-9a-f]{6}$/i,Qs=t=>!!t&&(t.kind==="video"||t.kind==="image")&&!t.title&&!t.shape&&!t.motion&&!t.solid,db=["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 EA(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(!Qs(t))throw Error("stepPunch needs a video or image clip");const l=pe.step,u=Math.round(ue(Ce(o,l.defaults.steps),...l.steps)),c=Math.round(ue(Ce(r,l.defaults.frames),...l.frames)),s=ue(Ce(a,l.defaults.amount),...l.amount);if(!Number.isFinite(e)||e<0||e>=t.duration-po)throw Error("stepPunch must start inside the clip");const d=ft(e),f=u*c*po;let m=ft(d+f),g=!i;if(m>=t.duration-po/2&&(m=t.duration,g=!0),d+c*po>t.duration+1e-6)throw Error("stepPunch is too long for the clip");const v=Qt.hold,x=Array.isArray(n)?ue(Number(n[0])-.5,-.5,.5):0,$=Array.isArray(n)?ue(Number(n[1])-.5,-.5,.5):0,E={...t,...en(t)},S=[];d>=po&&S.push({time:ft(d-po),f:0});for(let z=1;z<=u;z++){const j=ft(d+(z-1)*c*po);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,A=(z,j)=>{const P=Zt(E,"zoom",j.time)||1,N=Math.min(ns,P*(1+(s-1)*j.f));if(z==="zoom")return ge(N);const F=Math.max(0,(N-1)/2),K=-(N-P)*(z==="x"?x:$);return ge(ue(Zt(E,z,j.time)+ue(K,-F,F),-1,1))};let I={...E};for(const z of x||$?["zoom","x","y"]:["zoom"]){const j=Ee(E,z).filter(N=>N.time<k-.001||N.time>y+.001),P=S.map(N=>({time:N.time,value:A(z,N),ease:v}));I={...I,...me(I,z,[...j,...P].sort((N,F)=>N.time-F.time))}}return kn(I),{motionV:I.motionV,motionKeys:I.motionKeys,...I.posX!==void 0?{posX:I.posX,posY:I.posY,scale:I.scale}:{}}}function SA(t,{frames:e=pe.matte.default,side:o="in",aspect:r=16/9}={},a){if(!t||t.kind!=="video"&&t.kind!=="image")throw Error("matteFlash needs a video or image clip");if(!t.person)throw Error("matteFlash needs the AI cut-out of the subject on the clip (segmentPerson / cutOutObject first)");if(o!=="in"&&o!=="out")throw Error("matteFlash side: in | out");const n=Math.round(ue(Ce(e,pe.matte.default),...pe.matte.frames)),i=ft(n*po);if(t.duration<i+po)throw Error("matteFlash: the clip is shorter than the flash");const l=o==="in"?t.start:ft(t.start+t.duration-i);let u=Gn(t,a());for(const d of db)delete u[d];if(delete u.enter,delete u.exit,o==="in"){const[d]=Fe(u,ft(t.start+i),a());u={...d,id:u.id}}else{const[,d]=Fe(u,l,a());u={...d??u,id:u.id}}const c={...u,label:`${t.label||"Clip"} · bóng`,volume:0,effects:[{type:"fade",amount:1},{type:"threshold",amount:.02}],opacity:1};delete c.saturation;for(const d of["colorBypass","blend","grade","edge","shadow","glow"])delete c[d];return[Vh({id:a(),track:t.track,start:l,duration:i,label:"Nền đen",fill:{type:"color",color:"#000000"},aspect:r}),c]}function IA(t,{at:e,duration:o=pe.drain.default}={},r){if(!Qs(t))throw Error("endingDrain needs a video or image clip");const a=ft(ue(Ce(e,t.start),t.start,t.start+t.duration-2*po)),n=t.start+t.duration,i=ft(ue(Ce(o,pe.drain.default),pe.drain.duration[0],Math.min(pe.drain.duration[1],n-a)));if(i<2*po)throw Error("endingDrain: not enough of the clip left after `at`");let l={...t,id:r(),volume:0};for(const c of db)delete l[c];if(delete l.enter,delete l.exit,a>t.start+1e-6){const[,c]=Fe(l,a,r());c&&(l={...c,id:l.id})}l={...l,label:`${t.label||"Clip"} · rút màu`,saturation:0};const u=[{time:0,value:0,ease:Qt["ease-in-out"]},{time:ge(Math.min(i,l.duration)),value:1}];return{...l,...me(l,"opacity",u)}}function AA(t,e,{at:o,radius:r=pe.iris.defaults.radius,push:a=pe.iris.defaults.push,cx:n=.5,cy:i=.5,feather:l=.006,W:u=1280,H:c=720,material:s=null,newId:d}={}){const f=t.find(N=>N.id===e);if(!Qs(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)||c,x=ue(Ce(r,m.defaults.radius),...m.radius)*Math.min(g,v)/g,$=x*g/v,E=ue(Ce(a,m.defaults.push),...m.push),S=ue(Ce(n,.5),x,1-x),k=ue(Ce(i,.5),Math.min($,.5),Math.max(1-$,.5));let y=t,A=f;const I=ft(ue(Ce(o,f.start),f.start,f.start+f.duration-3*po));if(I>f.start+1e-6){const[N,F]=Fe(f,I,d?.()??`${f.id}-iris`);F&&(y=y.flatMap(K=>K.id===f.id?[N,F]:[K]),A=F)}const z={...A,...en(A)},j=Zt(z,"zoom",0)||1;let P={...z,mask:{v:1,mw:g,mh:v,keys:[{t:0,pts:ay(S,k,x,g,v,32)}],smooth:!0,feather:ue(Ce(l,.006),0,.1)}};for(const N of["person","roto","planar","bubble"])delete P[N];return E>1.0005&&(P={...P,...me(P,"zoom",[{time:0,value:ge(j),ease:Qt["ease-out"]},{time:ge(A.duration),value:ge(Math.min(ns,j*E))}])}),kn(P),{clips:y.map(N=>N.id===A.id?P:N),irisId:A.id}}function CA({W:t,H:e,width:o,cx:r=.5,cy:a=.5,aspect:n}){const i=pe.card,l=.02*Math.min(t,e);let u=t*ue(Ce(o,i.defaults.width),...i.width),c=u/ue(n,...i.aspect);return c>e-2*l&&(c=e-2*l,u=c*ue(n,...i.aspect)),{x:ue(t*Ce(r,.5)-u/2,l,Math.max(l,t-l-u)),y:ue(e*Ce(a,.5)-c/2,l,Math.max(l,e-l-c)),w:u,h:c}}function jA(t,{W:e,H:o,mw:r,mh:a,rect:n,round:i=pe.card.defaults.round}){const l=n.w/n.h;let u=r,c=u/l;c>a&&(c=a,u=c*l);const s=t.fit==="cover"?Math.max(e/r,o/a):Math.min(e/r,o/a),d=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=Cn({kind:"rect",cx:.5,cy:.5,w:ge(u/r),h:ge(c/a),rot:0,round:ge(f)},r,a);return{mask:cr({mw:r,mh:a},[m]),posX:ge((n.x+n.w/2-e/2)/e),posY:ge((n.y+n.h/2-o/2)/o),scale:ge(d)}}function fb(t,{W:e=1280,H:o=720,material:r=null,width:a,cx:n,cy:i,aspect:l,round:u,rim:c=pe.card.defaults.rim,glow:s=.25,zIndex:d=pe.card.zIndex,enter:f=!0}={}){if(!Qs(t))throw Error("mediaCard needs a video or image clip");if(c!==!1&&!$A.test(String(c)))throw Error("mediaCard rim must be #RRGGBB or false");const m=Math.round(r?.width)||e,g=Math.round(r?.height)||o,v=CA({W:e,H:o,width:a,cx:n,cy:i,aspect:Ce(l,m/g)}),x=jA(t,{W:e,H:o,mw:m,mh:g,rect:v,round:u}),$={...t,motionV:2,motionKeys:[],posX:x.posX,posY:x.posY,scale:x.scale,mask:x.mask,zIndex:d,shadow:{...hn,opacity:.5,blur:22,distance:8},...c===!1?{}:{edge:{color:String(c).toLowerCase(),width:.004,glow:ue(Ce(s,.25),0,2)}},...f?{enter:{type:"pop",duration:.3},exit:{type:"fade",duration:.2}}:{}};c===!1&&delete $.edge;for(const S of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])delete $[S];kn($);const E={};for(const S of["motionV","motionKeys","posX","posY","scale","mask","zIndex","shadow","edge","enter","exit"])E[S]=$[S];for(const S of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])E[S]=void 0;return{patch:E,rect:{x:ge(v.x/e),y:ge(v.y/o),w:ge(v.w/e),h:ge(v.h/o)}}}function TA(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,l=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/l),c=a*Math.min(e,o),s=r.w*e,d=r.h*o,f=(s-c*(l-1))/l,m=(d-c*(u-1))/u;return Array.from({length:t},(g,v)=>{const x=Math.floor(v/l),$=x===u-1?t-x*l:l,E=v-x*l,S=r.x*e+(s-($*f+($-1)*c))/2;return{cx:ge((S+E*(f+c)+f/2)/e),cy:ge((r.y*o+x*(m+c)+m/2)/o),width:ge(f/e),aspect:ge(f/m)}})}function OA(t,{W:e=1280,H:o=720,materials:r=[],area:a,gap:n,cols:i,step:l=pe.board.step,rim:u,round:c}={}){const s=TA(t.length,{W:e,H:o,area:a,gap:n,cols:i}),d=new Map,f=[];return t.forEach((m,g)=>{const v=r.find(P=>P.id===m.nodeId)??null,x=Math.round(v?.width)||e,$=Math.round(v?.height)||o,E=s[g],S=x/$,k=S>=E.aspect?E.width:E.width*S/E.aspect,{patch:y,rect:A}=fb(m,{W:e,H:o,material:v,width:k,cx:E.cx,cy:E.cy,aspect:S,rim:u,round:c,enter:!1,zIndex:pe.card.zIndex-g%8}),I=ge(Math.min(Math.max(0,m.duration-.4),g*ue(Ce(l,pe.board.step),0,1))),z=Qt["expo-out"];let j={...m,...y};for(const P of Object.keys(y))y[P]===void 0&&delete j[P];j={...j,...me(j,"y",[{time:I,value:ge(y.posY+.05),ease:z},{time:ge(I+.32),value:y.posY}])},j={...j,...me(j,"opacity",[...I>po/2?[{time:0,value:0,ease:Qt.hold}]:[],{time:I,value:0,ease:z},{time:ge(I+.24),value:1}])},kn(j),d.set(m.id,{...y,motionV:j.motionV,motionKeys:j.motionKeys,posX:j.posX,posY:j.posY,scale:j.scale}),f.push({id:m.id,...A})}),{patches:d,rects:f}}function zA(t,{moves:e}={}){if(!Qs(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,...en(t)},a=Ce(r.scale,1),n=Ce(r.posX,0),i=Ce(r.posY,0),l=e.map(g=>{const v=Number(g?.at),x=ue(Ce(Number(g?.zoom),1.6),...o.zoom),$=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 E=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=ge(Math.min(ns,a*x)),k=Math.max(0,(x-1)/2);return{at:ft(v),ramp:$,z:S,x:ge(n+ue(-(E[0]-.5)*x,-k,k)),y:ge(i+ue(-(E[1]-.5)*x,-k,k))}}).sort((g,v)=>g.at-v.at);for(let g=1;g<l.length;g++)if(l[g].at-l[g-1].at<2*po)throw Error("screenCamera: moves must be at least 2 frames apart");const u=Qt["easy-ease"],c=Qt.hold,s=g=>{const v=g==="zoom"?a:g==="x"?n:i,x=[];let $=v;return l.forEach((E,S)=>{const k=ft(Math.max(S?l[S-1].at:0,E.at-E.ramp)),y=g==="zoom"?E.z:E[g];E.at-k>=po&&x.push({time:k,value:ge($),ease:u}),x.push({time:E.at,value:y,ease:c}),$=y}),x.filter((E,S,k)=>!S||E.time>k[S-1].time+1e-6)},d=Math.max(0,l[0].at-l[0].ramp),f=l.at(-1).at;let m={...r};for(const g of["zoom","x","y"]){const v=Ee(r,g).filter(x=>x.time<d-.001||x.time>f+.001);m={...m,...me(m,g,[...v,...s(g)].sort((x,$)=>x.time-$.time))}}return kn(m),{motionV:m.motionV,motionKeys:m.motionKeys,posX:m.posX,posY:m.posY,scale:m.scale}}const PA=(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 LA(t,e,{point:o="palm",side:r="any",dir:a="auto",feather:n=pe.wipe.defaultFeather,finish:i=pe.wipe.finish,W:l=1280,H:u=720,mw:c,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 d=Zs(e.hands),f=Math.max(t.start,e.start),m=Math.min(t.start+t.duration,e.start+e.duration);if(!(m-f>=4*po))throw Error("The layer and the footage do not play at the same time");const g=Math.max(2,Math.min(Le.maxFrames-10,Math.ceil((m-f)/gy))),v=[];for(let D=0;D<=g;D++){const U=f+(m-f)*D/g,ht=Oi(e,d,U,{point:o,side:r,W:l,H:u});ht&&v.push({T:U,x:ht.x/l,y:ht.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(p=>p.x),U=v.map(p=>p.y),ht=Math.max(...D)-Math.min(...D),yt=Math.max(...U)-Math.min(...U),Mt=ht>=yt?v.at(-1).x-v[0].x:v.at(-1).y-v[0].y;x=ht>=yt?Mt>=0?"right":"left":Mt>=0?"down":"up"}const $=x==="right"||x==="left",E=x==="right"||x==="down",S=D=>$?D.x:D.y;let k=E?-1/0:1/0;const y=v.map(D=>(k=E?Math.max(k,S(D)):Math.min(k,S(D)),{T:D.T,e:k}));let A=y.findIndex(D=>Math.abs(D.e-y[0].e)>.004);if(A<0)throw Error("The hand does not move across the picture while the layer plays");A=Math.max(0,A-1);let I=y.length-1;for(;I>A+1&&Math.abs(y[I].e-y[I-1].e)<1e-4;)I--;const z=E?-.02:1.02,j=y.slice(A,I+1),P=j[0],N=j.at(-1),F=.3,K=D=>D*D*(3-2*D),_=D=>z+(D.e-z)*K(ue((D.T-P.T)/F,0,1)),J=Math.round(c)||l,X=Math.round(s)||u,rt=D=>ge(D-t.start),ot=(D,U,ht)=>{const yt=Pg(t,D*l,U*u,ht-t.start,l,u,J,X);return[yt.u,yt.v]},G=(D,U)=>{const ht=z,yt=ue(D,-.02,1.02);return($?[[ht,-.02],[yt,-.02],[yt,1.02],[ht,1.02]]:[[-.02,ht],[1.02,ht],[1.02,yt],[-.02,yt]]).map(([p,lt])=>ot(p,lt,U).map(V=>ge(ue(V,-1,2))))},tt=[],Q=(D,U)=>{(!tt.length||D>tt.at(-1).t+1e-4)&&tt.push({t:D,pts:U})};P.T-t.start>po/2&&Q(0,G(z,t.start));for(const D of j)Q(rt(D.T),G(_(D),D.T));const it=Math.min(t.start+t.duration,N.T+ue(Ce(i,pe.wipe.finish),po,2));return it-N.T>=po/2?Q(rt(it),G(E?1.02:-.02,it)):tt[tt.length-1]={t:tt.at(-1).t,pts:G(E?1.02:-.02,N.T)},{patch:{mask:{v:1,mw:J,mh:X,keys:tt,smooth:!1,feather:ue(Ce(n,pe.wipe.defaultFeather),...pe.wipe.feather)}},dir:x,from:ge(P.T),to:ge(it)}}const sg=["track","planar"],rs=t=>+Number(t).toFixed(5),NA=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 FA(t,e){if(e!==void 0){if(!Array.isArray(e)||e.length!==4||!e.every(s=>Array.isArray(s)&&s.length===2&&s.every(d=>Number.isFinite(d)&&d>=0&&d<=1)))throw Error("region: 4 corners [[u,v]…] inside 0..1");return e.map(s=>s.map(rs))}const o=NA(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),l=n(o.x1+r),u=n(o.y0-a),c=n(o.y1+a);return[[i,u],[l,u],[l,c],[i,c]].map(s=>s.map(rs))}function RA(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 DA(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(Fw(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>el)throw Error(`masks: up to ${el}`);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 l=r.replace===!0?[]:Ja(t.mask).filter(s=>!n.includes(s.id));const u=[];for(const[s,d]of a.entries()){if(!d||typeof d!="object")throw Error(`masks[${s}]: an object`);const f=Object.fromEntries(Object.entries(d).filter(([,E])=>E!==null)),m=f.mode??"add";if(!vd.includes(m))throw Error(`masks[${s}].mode: ${vd.join("|")}`);if(!Array.isArray(f.keys)||!f.keys.length||f.keys.length>Ou)throw Error(`masks[${s}].keys: 1–${Ou} keys {t, pts}`);const g=[...f.keys].map(E=>({t:rs(Number(E?.t)),pts:Array.isArray(E?.pts)?E.pts.map(S=>Array.isArray(S)?S.map(rs):S):E?.pts})).sort((E,S)=>E.t-S.t);for(const E of g)if(!Array.isArray(E.pts)||E.pts.length<3||E.pts.length>Au)throw Error(`masks[${s}]: every key has 3–${Au} points [u,v] (0..1 of the source frame)`);const v=typeof f.id=="string"?l.find(E=>E.id===f.id):null,x=v?v.id:typeof f.id=="string"&&/^[a-zA-Z0-9_-]{1,24}$/.test(f.id)?f.id:Rw(l),$={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(!sg.includes(f.follow))throw Error(`masks[${s}].follow: ${sg.join(" | ")}`);if(t.kind!=="video")throw Error("follow needs a video clip");const E=f.follow==="track"?"translate":f.planarMode??"perspective";if(!$d.includes(E))throw Error(`masks[${s}].planarMode: ${$d.join("|")}`);u.push({id:x,at:g[0].t,region:FA(g[0].pts,f.region),mode:E})}l=v?l.map(E=>E.id===x?$:E):[...l,$]}if(l.length>el)throw Error(`at most ${el} masks per clip`);const c=l.length?cr(i,l):void 0;return c&&Dw(c,t.duration),{mask:c,follow:u}}function Oj(t,e,o,r,{maxKeys:a=Ou,maxPoints:n=6e4}={}){if(!e.length)return t.keys;const i={frames:e},l=t.keys.find(v=>Math.abs(v.t-o)<.001)??t.keys[0],u=Ed(i,o),c=l.pts.length,s=Math.max(2,Math.min(a,Math.floor(n/c))),d=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)=>+(d+(f-d)*x/(m-1)).toFixed(4)),+o.toFixed(4)])].sort((v,x)=>v-x).map(v=>{const x=Ed(i,v),$=Math.abs(v-o)<1e-4?null:Bw(r,u,x);return{t:v,pts:l.pts.map(E=>{if(!$)return E;const[S,k]=_w($,E[0],E[1]);return[rs(S),rs(k),...E.slice(2)]})}})}const BA=3,ss=(t,e)=>!!t?.[e.track]?.locked;function zj(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(ss(a,i))throw Error("Track đã khóa");const l=Fe(i,o,n());if(l.length<2)throw Error("Đặt playhead trong clip");const[u,c]=l,s=r==="left"?u:c,d=r==="left"?c:u,f=s.duration,m=i.start+i.duration;return{clips:t.flatMap(v=>v.id===i.id?[r==="left"?{...d,start:i.start}:d]:[v.track===i.track&&v.start>=m-1/60?{...v,start:ft(Math.max(0,v.start-f))}:v]),kept:d.id}}function Pj(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 bb(t,a,ft(n),{insert:!0,tracks:o,...r?{makeId:r}:{}})}function Lj(t,e,o,{tracks:r={},seconds:a=BA,makeId:n=()=>crypto.randomUUID()}={}){const i=t.find($=>$.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(ss(r,i))throw Error("Track đã khóa");const l=ft(Math.max(i.start,Math.min(i.start+i.duration,o))),u=i.playbackRate||1,c=Fe(i,l,n()),s=c[0],d=c[1],f=ft(Math.min(i.duration-1/30,l-i.start)),m=Bn(i)?Gw(i,f):Zr(i)?(i.inPoint||0)+Ui(i,f):(i.inPoint||0)+f*u,g={...i,id:n(),start:l,duration:ft(a),inPoint:+m.toFixed(4),playbackRate:1,volume:0,freeze:!0,label:`${i.label} · freeze`};for(const $ of["speedRamp","timeRemap","transition","motionKeys","enter","exit","captions","captionWords","captionStyle","audioFadeIn","audioFadeOut","visualFadeIn","visualFadeOut","roto","duck"])delete g[$];const v=ft(a),x=t.flatMap($=>$.id===i.id?d?[s,{...d,start:ft(d.start+v)}]:[s]:[$.track===i.track&&$.start>=l-1/60?{...$,start:ft($.start+v)}:$]);return c.length===1&&l<=i.start+1/60&&x.splice(x.findIndex($=>$.id===i.id),1,{...i,start:ft(i.start+v)}),{clips:[...x,g],hold:g.id}}function mb(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(ss(o,a))throw Error("Track đã khóa");if(Zr(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=Ri.find(u=>!o[u]?.locked&&!t.some(c=>c.track===u&&c.start<n-1/60&&c.start+c.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 l={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,...Bn(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),l],audio:l.id}}function Nj(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(ss(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 Fj(t,e,o,{tracks:r={},makeId:a=()=>crypto.randomUUID()}={}){const n=t.find(c=>c.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=mb(t,e,{tracks:r,makeId:a}),l=i.clips.find(c=>c.id===i.audio),u=Fe(l,o,a());return{clips:i.clips.flatMap(c=>c.id===l.id?u:[c]),audio:u.map(c=>c.id)}}function Rj(t,e,{tracks:o={}}={}){const r=t.filter(i=>e.includes(i.id)&&!ss(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 l={...i};return a?l.disabled=!0:delete l.disabled,l})}const Lh=3,Xi=1/30,_A=new Set(["id","start","duration","inPoint","label","captions","captionWords"]),GA=(t,e)=>{const o=new Set([...Object.keys(t),...Object.keys(e)].filter(r=>!_A.has(r)));for(const r of o)if(JSON.stringify(t[r])!==JSON.stringify(e[r]))return!1;return!0};function Us(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<-Xi/2||a>o+Xi/2?!1:Math.abs((e.inPoint||0)-((t.inPoint||0)+(t.duration+Math.max(0,a))*r))<=Xi/2*r+1e-6}function gb(t,e){if(!Us(t,e,{gap:Lh*Xi})||t.transition||!GA(t,e))return null;const o=ft(e.start-t.start),r=ft(o+e.duration),a=i=>i.map(l=>({...l,start:+(l.start+o).toFixed(3),end:+(l.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 Dj(t,e,{tracks:o={}}={}){const r=t.find(s=>s.id===e);if(!r)throw Error("Không tìm thấy clip");if(ss(o,r))throw Error("Track đã khóa");const a=t.filter(s=>s.track===r.track&&s.id!==r.id),n=a.filter(s=>Us(r,s,{gap:Lh*Xi})).sort((s,d)=>s.start-d.start)[0],i=a.filter(s=>Us(s,r,{gap:Lh*Xi})).sort((s,d)=>d.start-s.start)[0],[l,u]=n?[r,n]:i?[i,r]:[];if(!l)throw Error("Không có đoạn liền mạch để nối (cần 2 đoạn của cùng một video, nguồn chạy tiếp nhau)");const c=gb(l,u);if(!c)throw Error("Hai đoạn khác nhau về hiệu ứng, keyframe hoặc chuyển cảnh nên không gộp được");return{clips:t.filter(s=>s.id!==u.id).map(s=>s.id===l.id?c:s),kept:l.id}}function Bj(t,e){const o=t.find(c=>c.id===e);if(!o)return{clips:t,joined:!1};const r=t.filter(c=>c.track===o.track&&c.id!==o.id),a=r.find(c=>Us(o,c)),n=r.find(c=>Us(c,o)),[i,l]=a?[o,a]:n?[n,o]:[],u=i&&gb(i,l);return u?{clips:t.filter(c=>c.id!==l.id).map(c=>c.id===i.id?u:c),joined:!0,kept:i.id}:{clips:t,joined:!1}}function _j(t,e,o,{playhead:r,pps:a,px:n=8}={}){const l=[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,c)=>Math.abs(u-o)-Math.abs(c-o))[0];return l!==void 0&&Math.abs(l-o)*a<n?ft(l):null}function Gj(t,e,{tracks:o={},makeId:r=()=>crypto.randomUUID()}={}){const a=t.filter(l=>e.includes(l.id)&&l.kind!=="audio");if(!a.length)throw Error("Chọn clip hình để nhân bản");let n=t;const i=[];for(const l of a){const u=d=>!o[d]?.locked&&!o[d]?.hidden&&!n.some(f=>f.track===d&&f.start<l.start+l.duration-1e-6&&f.start+f.duration>l.start+1e-6);let c=Oa(l.track)+1;for(;c<40&&!u(fn(c));)c++;if(c>=40)throw Error("Không còn track trống phía trên");const s={...l,id:r(),track:fn(c),volume:0};delete s.transition,n=[...n,s],i.push(s.id)}return{clips:n,pasted:i}}function lg(t,e,o){return Array.isArray(t)?t.slice(0,Wg.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=o4(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{...r4(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 l=Array.isArray(r.lonlat)&&r.lonlat.length===2?r.lonlat.map(Number):Number.isFinite(Number(r.lat))&&Number.isFinite(Number(r.lng))?[Number(r.lng),Number(r.lat)]:o.at(-1)?.center;if(!Array.isArray(l)||!l.every(Number.isFinite))throw Error("Map model needs lonlat (or lat + lng)");return{gcsUri:i.gcsUri,label:String(r.label||i.label||"GLB").slice(0,60),at:l,height:Number.isFinite(Number(r.height))?Number(r.height):40,rotation:Number(r.rotation)||0,show:Number.isFinite(Number(r.show))?Number(r.show):0,rise:r.rise!==!1,...r.reveal?{reveal:r.reveal}:{},...r.color?{color:r.color}:{}}}):null}function cg(t,e,o){return Array.isArray(t)?t.slice(0,Wg.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,l=(u,c)=>Number.isFinite(Number(u))?Number(u):c;return{gcsUri:a.gcsUri,label:String(r.label||a.label||"").slice(0,60),at:n,width:l(r.width,120),aspect:i,tilt:l(r.tilt,90),rotation:l(r.rotation,0),face:r.face==="fixed"?"fixed":"camera",show:l(r.show,0),...r.reveal?{reveal:r.reveal}:{}}}):null}const KA=["fit","posX","posY","scale","scaleX","scaleY","anchorX","anchorY","rotation","tiltX","tiltY","flipX","flipY","crop","opacity","blend","brightness","contrast","exposure","saturation","hue","grade"],pg=new Set(jy.map(t=>t.id)),ao=t=>Math.round(t*1e4)/1e4;function VA(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,Kl.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 te(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 ug=t=>{try{return Fi(t,{})}catch{return null}},nc=500,ac=500,Gt=Fs;function WA(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 hg(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 He=Fn,Rl=2,Dl=Qg,HA=3;function dg(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 yb=["addBroll","addText","estateText","lockup","addCard","addShape","addSolid","addAdjustmentLayer","addFlash","addElement","addMotion","addMap","generateElement","generateBroll"],at=t=>Number.isFinite(t)?Number(t):null,$t=t=>at(t)??void 0,fg=t=>t.sourceDuration??He;function mg(t,e,o,r=[]){const a=r.find(l=>l.id===e?.nodeId),n=r.find(l=>l.id===o?.nodeId),i=e?(e.inPoint||0)+Ui(e,e.duration||0):0;return mS(a,i,n,o?.inPoint||0)>0?mk(t):t}function vu(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 As=t=>Array.isArray(t?.words)&&t.words.length?t.words.length:Number.isInteger(t?.wordCount)&&t.wordCount>0?t.wordCount:0;function XA(t,e,o){const r=Array.isArray(t)?t:[],a=typeof o=="string"?o.trim():"",n=a&&r.find(c=>c.id===a);if(n)return n;if(a){const c=r.find(m=>m.id.split(":").slice(1).join(":")===a||m.label===a);if(c)return c;const s=(e||[]).find(m=>m.id===a),d=s&&r.find(m=>m.id===s.nodeId);if(d)return d;const f=a.length>=40?r.filter(m=>m.id.startsWith(a)):[];if(f.length===1)return f[0]}const i=r.filter(c=>As(c)>0),l=i.filter(c=>c.role==="aroll"),u=l.length?l:i;return u.length===1?u[0]:void 0}function gg(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 l=1/0,u=1/0,c=-1/0,s=-1/0;for(const d of e.items){const f=d.type==="art"?d.params.box:null,m=Math.abs(d.scale[0]),g=Math.abs(d.scale[1]);f&&(l=Math.min(l,d.pos[0]+f[0]*m),u=Math.min(u,d.pos[1]+f[1]*g),c=Math.max(c,d.pos[0]+f[2]*m),s=Math.max(s,d.pos[1]+f[3]*g))}return Number.isFinite(l)?[(l*a+n)/o,(u*a+i)/r,(c*a+n)/o,(s*a+i)/r]:null}const yg=t=>Array.isArray(t?.masks)?t.masks.map(e=>e.id):t?["m1"]:[];function UA(t,e,o){if(typeof t.prompt=="string"&&t.prompt.trim().startsWith("{"))try{const f=JSON.parse(t.prompt);t={...f,...t,presetId:t.presetId??f.presetId,params:t.params??f.params}}catch{throw Error("addVfxPreset: prompt must be JSON {presetId, params}")}const r=t.preset&&typeof t.preset=="object"&&t.preset.id?t.preset:nM(String(t.presetId??""));if(!r)throw Error(`addVfxPreset: unknown presetId "${String(t.presetId??"").slice(0,64)}" — search_vfx_presets`);const a=eM(r,t.params&&typeof t.params=="object"?t.params:{}),n=Math.max(0,at(t.start)??at(t.at)??0);let i=Z4(r.id),l=null,u=!1;if(typeof t.materialId=="string"){const f=(o??[]).find(m=>m.id===t.materialId);if(!f||f.kind!=="video"||typeof f.url!="string")throw Error(`addVfxPreset: ${t.materialId} is not a video of the Media bin (the move's render: clipoox render --vfx … then add_media)`);i=f.url,l=typeof f.gcsUri=="string"?f.gcsUri:null,u=!0}const s=[{op:"addVfxPreset",_footage:{id:`preset:${r.id}`,url:i,...l?{gcsUri:l}:{},name:r.name,duration:r.duration,width:r.width,height:r.height,bg:"alpha",anchorU:r.emit[0],anchorV:r.emit[1]},_preset:{id:r.id,params:a,rendered:u},start:n,track:t.track,point:t.point,scale:t.scale}],d=n+r.impact;if(t.sfx!==!1)for(const f of r.sfx)s.push({op:"addSfx",sfxId:f.id,at:Math.round((n+f.at)*1e3)/1e3,volume:.8});if(t.shake!==!1&&r.shake){const f=(e??[]).filter(m=>m.kind==="video"&&!m.vfxFootage&&!m.vfx&&m.start<=d&&m.start+m.duration>d).sort((m,g)=>(m.track??0)-(g.track??0))[0];f&&s.push({op:"cameraShake",clipId:f.id,at:Math.round((n+r.shake.at)*1e3)/1e3,duration:r.shake.duration,numberValue:r.shake.intensity})}return s}function YA(t,e,o){const r=Math.max(0,at(t.start)??0),a=(Array.isArray(t.stations)?t.stations:[]).map((s,d)=>{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 ${d+1}: ${s.materialId} is not a picture`);if(!m)throw Error(`documentary station ${d+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=c8({...t,stations:a}),i=n.stations.some(s=>s.say)?C1(e,o,r,r+er.maxSeconds+30,typeof t.voiceClipId=="string"?t.voiceClipId:null):[],l=p8(n,(s,d)=>{if(!i.length)return null;const f=qu(s,i,r+d);return f?f.at-r:null}),u=[],c=n.style==="map"?n.stations.find(s=>s.kind==="place"&&Array.isArray(s.lonlat)):null;c&&t.map!==!1&&u.push({op:"addMap",start:r,duration:l.total,label:c.label,geo:Vg({places:[{label:"",center:c.lonlat,zoom:Math.min(14,Math.max(2,at(t.mapZoom)??6))}],duration:l.total,style:"dark",route:!1,pins:!1})}),u.push({op:"documentary",_plan:l,start:r,label:typeof t.label=="string"?t.label.slice(0,60):""});for(const[s,d]of l.sfx)d<l.total&&u.push({op:"addSfx",sfxId:s,at:Math.round((r+d)*1e3)/1e3,volume:.6});return u}function Si(t,e,o=[],r={},a=null,n={}){const i=n.seamFrame??n,l=i.W>0&&i.H>0?{W:i.W,H:i.H}:{};let u=a?structuredClone(a):null;const c=n.motion?Yh(n.motion):{in:.5,out:.5,settle:"none"};e=X$(e,{clips:t,materials:o,brand:n.brand??null,portrait:n.H>n.W*1.1,en:n.locale==="en",simulate:D=>Si(t,D,o,r,a,n).clips}),e=Z$(e,{materials:o,portrait:n.H>n.W*1.1}),e=L6(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(ac,n?.maxOps??nc),simulate:D=>Si(t,D,o,r,a,n).clips}),e=aE(e,{clips:t,materials:o,W:n.W||1280,H:n.H||720,maxOps:Math.min(ac,n?.maxOps??nc),simulate:D=>Si(t,D,o,r,a,n).clips}),e=q6(e,{W:n.W||1280,H:n.H||720}),e=TE(Vx(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 d=[],f=[],m=[],g=[],v=[],x=[],$=[],E=[],S=[],k=[],y=D=>s.find(U=>U.id===D),A=(D,U,ht=null)=>{let yt=E.find(T=>T.clipId===D.id&&!T.object);yt||(yt={clipId:D.id,behind:[]},E.push(yt)),U&&!yt.behind.includes(U)&&yt.behind.push(U);const Mt=Jd(D.personPending),p=Mt?.behind??[],lt=Mt?.job,V=Mt?.ready,h=Mt?.then??[],w=ht?[...h,ht].slice(-wk):h;D.personPending={behind:[...new Set([...p,...yt.behind])].slice(0,Qd),...lt?{job:lt}:{},...lt&&V?{ready:V}:{},...w.length?{then:w}:{},...Mt?.objects?{objects:Mt.objects,person:!0}:{}}},I=(D,U=null)=>ht=>!r[ht]?.locked&&!s.some(yt=>yt.id!==U&&yt.track===ht&&yt.start<D.start+D.duration&&yt.start+yt.duration>D.start),z=(D,U,ht)=>{const yt={...Jd(D.personPending)??{behind:[]}},Mt=(yt.objects??[]).map(V=>({...V,behind:[...V.behind]}));D.personPending&&!D.personPending.object&&!D.personPending.objects&&(yt.person=!0);let p=Mt.find(V=>V.id===U.id);if(p)U.pts&&U.pts!==p.pts&&(p.pts=U.pts,p.at=U.at);else{if(Mt.length>=tf)throw Error(`"${D.label||D.id}" already waits for ${tf} object cut-outs`);p={id:U.id,name:U.name,pts:U.pts,at:U.at,behind:[],...U.layer?{layer:U.layer}:{}},Mt.push(p)}if(ht&&!p.behind.includes(ht)){if(p.behind.length>=Qd)throw Error("Too many layers behind one object");p.behind.push(ht)}D.personPending={...yt,objects:Mt};let lt=E.find(V=>V.clipId===D.id&&V.object?.id===U.id);lt||(lt={clipId:D.id,behind:[],object:{id:p.id,name:p.name,pts:p.pts,at:p.at,...p.layer?{layer:p.layer}:{}}},E.push(lt)),lt.behind=[...p.behind]},j=(D,U,ht)=>{const yt=n.objectMattes?.get?.(`${D.id}|${U.id}`);if(!yt)return null;const Mt={id:U.id,name:U.name,...U.pts?{pts:U.pts,at:U.at}:{}},p=C=>C.id===D.id?kk(C,U.id):C,lt=U.layer?y(U.layer):null;if(lt&&Mp(lt)){const C=gk(lt,yt,Mt);return s=s.map(O=>O.id===lt.id?C:p(O)),al(s),C}const V=nl(ht??D,D,{index:Oa,at:fn,isFree:I(D)});if(V===null)throw Error(`No free track above ${D.label||D.id} for "${U.name}"`);let h=`${D.id}-${U.id}`,w=2;for(;y(h);)h=`${D.id}-${U.id}-${w++}`;const T=yk(s,D,yt,{id:h,track:V,label:bk(D,U.name,s),target:ht,obj:Mt});return s=T.clips.map(p),al(s),T.layer},P=(D,U,ht)=>{const yt=nl(U,ht,{index:Oa,at:fn,isFree:I(D,D.id)});if(yt===null)throw Error(`No free track above ${U.label||U.id} for "${vp(D).name}"`);s=s.map(Mt=>Mt.id!==D.id?Mt:{...Mt,track:yt,...(U.zIndex??0)>(Mt.zIndex??0)?{zIndex:U.zIndex}:{}})};let N=null,F=null,K,_=null;const J=()=>_??(Array.isArray(n?.markers)?n.markers:[]),X=[],rt=new Map,ot=(D,U)=>({posX:Math.max(-1,Math.min(1,at(D.posX)??0)),posY:Math.max(-1,Math.min(1,at(D.posY)??0)),scale:Math.max(.25,Math.min(4,at(D.scale)??U))});Array.isArray(e)&&e.some(D=>D?.op==="speedster")&&(e=e.flatMap(D=>D?.op==="speedster"?VA(te(D)):[D])),Array.isArray(e)&&e.some(D=>D?.op==="beautyFace")&&(e=e.flatMap(D=>{if(D?.op!=="beautyFace")return[D];const U=te(D),ht=Array.isArray(U.clipIds)?U.clipIds:U.clipId!=null?[U.clipId]:[],yt=U.booleanValue===!1?[]:Lv(Pv(U),n.locale);return[{op:"beautyStrip",clipIds:ht,_off:U.booleanValue===!1},...yt.length?[{op:"colorGrade",clipIds:ht,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 U=te(D);if(U._auraId||Array.isArray(U.path)||U.behind===!1)return[U];const ht=Dt();return[{...U,_auraId:ht},{op:"placeBehindPerson",clipId:ht,sourceClipId:U.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 UA(te(D),t,o)}catch(U){return[{op:"addVfxPreset",_footage:null,_error:U?.message||String(U)}]}})),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 YA(te(D),t,o)}catch(U){return[{op:"documentary",_plan:null,_error:U?.message||String(U)}]}})),Array.isArray(e)&&e.some(D=>D?.op==="animePower")&&(e=e.flatMap(D=>D?.op==="animePower"?Gv(te(D)):[D]));const G=(Array.isArray(e)?e:[]).slice(0,Math.min(ac,n?.maxOps??nc)),tt=D=>Os.includes(D?.op),Q=D=>D?.op==="speakerBubble"||D?.op==="speakerWindow",it=[...G.filter(D=>!Q(D)&&!tt(D)),...G.filter(Q),...G.filter(tt)];for(const[D,U]of it.entries()){const ht=X.length,yt=typeof U?.clipId=="string"&&/^new:(\d+)$/.exec(U.clipId),Mt=V=>{const h=typeof V=="string"&&/^new:(\d+)$/.exec(V);return h?X[Number(h[1])-1]??V:V};let p=yt||Array.isArray(U?.clipIds)?{...U,clipId:yt?X[Number(yt[1])-1]??U.clipId:U.clipId,...Array.isArray(U.clipIds)?{clipIds:U.clipIds.map(Mt)}:{}}:U;typeof p?.parentClipId=="string"&&/^new:\d+$/.test(p.parentClipId)&&(p={...p,parentClipId:Mt(p.parentClipId)});let lt=null;try{if(p?.op==="lockup"&&(lt=KS(p,{clips:s,materials:o,W:n.W||1280,H:n.H||720}),p=lt.addText),p?.op==="estateText"){if(typeof p.text!="string"||!p.text.trim())throw Error("estateText needs its text");p=y8(p,{portrait:(n.H||720)>(n.W||1280)*1.1})}if(p?.op==="syncMapToVoice"){const h=y(p.clipId);if(!h?.geo)throw Error("syncMapToVoice needs an animated map clip (addMap)");const w=te(p),T=h.start,C=h.start+h.duration,O=Array.isArray(w.times)?w.times:null,L=O?[]:C1(s,o,T,C,typeof w.voiceClipId=="string"?w.voiceClipId:null);if(!O&&!L.length){if(s.some(H=>H.start<C&&H.start+H.duration>T&&As(o.find(q=>q.id===H.nodeId))>0)){d.push(`map ${h.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=z4(Sd(h.geo),h.geo.icons??[],{words:L,times:O,start:h.start,duration:h.duration,lead:Number(w.lead)});d.push(`map ${h.id} timed to the voice: ${P4(B.report)}`),p={op:"updateMap",clipId:h.id,places:B.places,placesResolved:!0,icons:B.icons}}if(p?.op==="addMotionCode"){if(typeof p.code!="string"||!/\brender\b/.test(p.code))throw Error("Motion code must define function render(ctx, t, env)");const{kind:h,...w}=p;p={...w,op:"addMotion",...h==="three"?{motionKind:"three"}:{}}}if(p?.clipId&&r[y(p.clipId)?.track]?.locked||p?.track!==void 0&&r[p.track]?.locked&&!yb.includes(p.op)&&!(p.op==="setTrackProperty"&&p.property==="locked"&&p.booleanValue===!1))throw Error("Track đã khóa");const V=p?.clipId?y(p.clipId)?.label||p.clipId:"";if(Os.includes(p?.op)){if(it.indexOf(U)!==it.length-1)throw Error("Control action must follow all edits");if(["undo","redo","analyzeFootage"].includes(p.op)&&e.length!==1)throw Error("History/analysis actions must be requested alone");if(p.op==="seek"&&(!Number.isFinite(p.at)||p.at<0||p.at>Math.max(0,...s.map(h=>h.start+h.duration))))throw Error("Seek outside timeline");if(["play","exportVideo"].includes(p.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(p.op)){if(p.resolution!=null&&!["720p","1080p"].includes(p.resolution)||p.aspectRatio!=null&&!["16:9","9:16","1:1","4:5"].includes(p.aspectRatio)||p.fps!=null&&![24,25,30,60].includes(p.fps)||p.loudness!=null&&![-14,-16,0].includes(p.loudness))throw Error("Invalid export format");if(N&&p.aspectRatio!=null&&p.aspectRatio!==N)throw Error("Export aspect ratio must match the reframe")}m.push({op:p.op,at:p.at,...["exportVideo","setExportFormat"].includes(p.op)?{...Object.fromEntries(["resolution","aspectRatio","fps","loudness"].filter(h=>p[h]!=null).map(h=>[h,p[h]])),...N&&p.aspectRatio==null?{aspectRatio:N}:{}}:{}});continue}if(p?.op!=="matchReference"&&typeof p?.materialId=="string"&&o.find(h=>h.id===p.materialId)?.role==="reference")throw Error("Video mẫu chỉ để phân tích nhịp — không đưa vào timeline");switch(p?.op){case"setExportRange":{const h=w=>w==null?null:typeof w=="number"&&Number.isFinite(w)?w:NaN;try{K=ax(h(p.in),h(p.out))}catch{throw Error("setExportRange needs in / out in timeline seconds, 0 ≤ in < out ≤ 600 (both omitted = the whole film)")}d.push(K?`export range ${K.in}s–${K.out>=He?"the end":`${K.out}s`}`:"export range: whole film");break}case"addMarker":{if(p.color!=null&&!Ic.includes(p.color))throw Error(`addMarker color must be one of ${Ic.join(", ")}`);let h;if(p.onBeats!=null){if(!pm.includes(p.onBeats))throw Error(`addMarker onBeats must be ${pm.join(" | ")}`);if(h=Iv(s,o,{density:p.onBeats}).filter(C=>p.onBeats==="beats"||C.kind!=="beat").map(C=>C.t),!h.length)throw Error("No beats found: add the song with add_media (its beats are found automatically) first")}else h=Array.isArray(p.times)?p.times:[p.at];if(h.length>200)throw Error("addMarker: at most 200 times per op");let w=J(),T=0;for(const C of h){const O=$v(w,{t:at(C)??NaN,label:p.label,color:p.color??void 0,id:`mk${Dt().replace(/[^A-Za-z0-9]/g,"").slice(0,12)}`});w=O.markers,O.added&&T++}_=w,d.push(`markers: +${T}${h.length>T?` (${h.length-T} already there)`:""}`);break}case"updateMarker":{_=Ev(J(),p.markerId,{...p.at!==void 0?{t:at(p.at)??NaN}:{},...p.label!==void 0?{label:p.label??""}:{},...p.color!==void 0?{color:p.color}:{}}),d.push(`marker ${p.markerId} updated`);break}case"removeMarker":{if(p.all===!0){d.push(`markers: −${J().length}`),_=[];break}_=Sv(J(),p.markerId),d.push(`marker ${p.markerId} removed`);break}case"cutAtMarkers":{const h=Array.isArray(p.markerIds)?J().filter(O=>p.markerIds.includes(O.id)):J();if(!h.length)throw Error("No markers: add some first (addMarker, or the M key in the editor)");const w=Array.isArray(p.clipIds)?p.clipIds:null,T=s.filter(O=>!r[O.track]?.locked&&(w?w.includes(O.id):p.track!=null?O.track===p.track:(p.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 C=0;for(const O of T){let L=O;for(const B of Av(O,h.map(H=>H.t))){if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const H=Fe(L,B,Dt());H.length!==1&&(s=s.flatMap(q=>q.id===L.id?H:[q]),L=H[1],C++)}}d.push(`cut at markers: ${C} cut${C===1?"":"s"}`);break}case"setCamera":{u={...u??{...Mr,motionKeys:[]},enabled:p.booleanValue!==!1};const h=Object.hasOwn(p,"parentClipId")?p.parentClipId:p.clipId;if(h!==void 0)if(h===null||h==="")delete u.parentId;else{const w=y(h);if(!w||w.kind==="audio")throw Error(`Camera parent ${h} not found`);u.parentId=w.id}zr(u),d.push(`camera ${u.enabled?"on":"off"}${u.parentId?` · follows ${y(u.parentId)?.label??u.parentId}`:""}`);break}case"setPath":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error(`Không tìm thấy layer ${p.clipId}`);const w=p.points==null||Array.isArray(p.points)&&!p.points.length,T=nS(h,w?null:{points:p.points,...at(p.start)!=null?{start:at(p.start)}:{},...at(p.end)!=null?{end:at(p.end)}:{},...typeof p.ease=="string"&&p.ease!=="linear"?{ease:p.ease}:{},...p.booleanValue===!0?{orient:!0}:{},...p.closed===!0?{closed:!0}:{}},{W:n.W||1280,H:n.H||720});Object.assign(h,T),T.path===void 0&&delete h.path,d.push(w?`path off ${V}`:`path ${V}: ${p.points.length} points${p.booleanValue===!0?" · auto-orient":""}`);break}case"linkProperty":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error(`Không tìm thấy layer ${p.clipId}`);if(!sl.includes(p.property))throw Error(`property must be one of ${sl.join("/")}`);const w=(h.links??[]).filter(L=>L.prop!==p.property),T=Mt(p.fromClipId),C=T?{prop:p.property,from:T,...p.fromProperty?{fromProp:p.fromProperty}:{},...at(p.factor)!=null?{factor:at(p.factor)}:{},...at(p.offset)!=null?{offset:at(p.offset)}:{},...at(p.delay)!=null?{delay:at(p.delay)}:{},...p.booleanValue===!0?{add:!0}:{}}:null,O=cx(s,h,C?[...w,C]:w);Object.assign(h,O),O.links===void 0&&delete h.links,d.push(C?`link ${V}.${p.property} ← ${y(T)?.label??T}.${C.fromProp??p.property}`:`unlink ${V}.${p.property}`);break}case"setExpression":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error(`Không tìm thấy layer ${p.clipId}`);if(!Object.hasOwn(Pr,p.property))throw Error(`property must be one of ${Object.keys(Pr).join("/")}`);const w=p.expression!==void 0?p.expression:p.text,T=typeof p.enabled=="boolean"?p.enabled:typeof p.booleanValue=="boolean"?p.booleanValue:void 0;if(w!=null){if(typeof w!="string")throw Error("expression must be text");pk(w)}if(w==null&&T===void 0&&p.expression!==null&&p.text!==null)throw Error("expression (text) or enabled is required");const C=uk(h,p.property,w===void 0?void 0:w,T);Object.assign(h,C),C.expr===void 0&&delete h.expr;let O=null;h.expr?.[p.property]&&!h.expr[p.property].off&&(hk(s),O=dk(h,p.property,0)),d.push(w===null?`expression off ${V}.${p.property}`:`expression ${V}.${p.property}${h.expr?.[p.property]?.off?" (disabled)":""}: ${h.expr?.[p.property]?.src.slice(0,80)}${O?` — warning: ${O}`:""}`);break}case"followChain":{const h=y(p.clipId);if(!h)throw Error(`Không tìm thấy layer ${p.clipId}`);const w=Array.isArray(p.properties)&&p.properties.length?p.properties:["x","y","rot"];if(w.some(C=>!sl.includes(C)))throw Error(`properties must be from ${sl.join("/")}`);const T=lx(s,h.id,(p.clipIds||[]).filter(C=>C!==h.id),w,at(p.numberValue)??.08);for(const[C,O]of Object.entries(T))Object.assign(y(C),O);d.push(`followChain ${Object.keys(T).length} layer(s) after ${V} on ${w.join("/")}`);break}case"addNull":{const h=ft(Math.max(0,at(p.start)??0)),w=ft(Math.max(1/30,at(p.duration)??5)),{track:T}=qt(s,r,h,h+w),C=typeof p.text=="string"&&p.text.trim()?p.text.trim().slice(0,80):ck(s),O={...xr({id:Dt(),track:T,start:h,duration:w,label:C,is3D:p.booleanValue===!0}),...Number.isFinite(p.posX)?{posX:p.posX}:{},...Number.isFinite(p.posY)?{posY:p.posY}:{},...p.booleanValue===!0&&Number.isFinite(p.numberValue)?{spatialDepth:p.numberValue}:{}};s.push(O),X.push(O.id);const L=(Array.isArray(p.clipIds)?p.clipIds:[]).filter(B=>B!==O.id);if(L.length){const B=n.W||1280,H=n.H||720;for(const et of L){const st=y(et);if(!st||st.kind==="audio")throw Error(`addNull clipIds: ${et} is not a visual layer`);if(r[st.track]?.locked)throw Error("That layer is locked")}sr(s);const q=Cl(s,su(s,L),B,H);for(const et of L){const st=y(et),Y=s.indexOf(st);s[Y]=Ca(s,st,{parentClipId:O.id,at:Math.max(0,Math.min(st.duration,h-st.start)),W:B,H})}s=xs(s,q,B,H)}d.push(`addNull ${O.is3D?"3D ":""}"${C}" (${O.id})${L.length?` with ${L.length} layer(s) linked`:""}`);break}case"setCameraKeys":{if(!Zd.includes(p.property))throw Error(`Camera property must be ${Zd.join("/")}`);if(!Array.isArray(p.propertyKeys)||p.propertyKeys.length>30)throw Error("Provide 0–30 camera keys");const{min:h,max:w}=_n[p.property],T={...u??{...Mr,motionKeys:[]},enabled:!0},C=p.propertyKeys.map(O=>{if(!Number.isFinite(O?.time)||O.time<0||O.time>He)throw Error("Camera key time must be timeline seconds");if(!Number.isFinite(O.value)||O.value<h||O.value>w)throw Error(`${p.property} must be ${h}..${w}`);const L=O.ease&&O.ease!=="linear"?Qt[O.ease]:void 0;if(O.ease&&O.ease!=="linear"&&!L)throw Error(`Unknown easing "${O.ease}"`);return{time:ft(O.time),value:O.value,...L?{ease:L}:{}}}).sort((O,L)=>O.time-L.time);u=C.length?bn(T,p.property,C):{...bn(T,p.property,[]),[p.property]:Ys(T,p.property,0)},zr(u),d.push(`camera ${p.property}: ${C.length} key`);break}case"cameraMove":{const h=p.ease&&p.ease!=="linear"?Qt[p.ease]:void 0;u=lk(u,p.preset,at(p.at)??0,at(p.duration)??2,{amount:at(p.numberValue)??1,ease:h}),d.push(`camera ${p.preset} ${at(p.at)??0}s → ${(at(p.at)??0)+(at(p.duration)??2)}s`);break}case"cutPauses":{const h=y(p.clipId),w=h&&o.find(C=>C.id===h.nodeId);if(!h)throw Error("Clip not found");const T=l4(s,p.clipId,w,{minGap:p.numberValue??.6,padding:.12,fillers:p.booleanValue===!0,maxClips:Gt,isBed:C=>C.kind==="audio"&&C.nodeId!==h.nodeId&&!o.find(O=>O.id===C.nodeId)?.transcript?.length},r,Dt);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,d.push(`cut pauses: ${V} −${T.removed} (${T.saved}s)${T.skipped?`, ${T.skipped} skipped`:""}`);break}case"removeRetakes":{if(p.keep!=null&&!v1.includes(p.keep))throw Error("keep must be best, last or first");const h=n.locale==="en",w=O4(s,o,{clipIds:Array.isArray(p.clipIds)&&p.clipIds.length?p.clipIds:null,window:at(p.window)??void 0,minSimilarity:at(p.minSimilarity)??void 0,keep:p.keep??"best",tracks:r,maxClips:Gt,makeId:Dt,en:h,isBed:T=>T.kind==="audio"&&!o.find(C=>C.id===T.nodeId)?.transcript?.length&&!o.find(C=>C.id===T.nodeId)?.words?.length});if(!w.found.groups.length){d.push(h?"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(C=>C.reason)))].join(", ")||"nothing to cut"}`);s=w.clips,d.push(...w.lines,h?`retakes: −${w.removed} cut (${+w.saved.toFixed(2)}s)`:`retakes: −${w.removed} đoạn (${+w.saved.toFixed(2)}s)`);break}case"scriptEdit":{const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=o.find(Y=>Y.id===h.nodeId),T=Array.isArray(w?.words)?w.words:[];if(!T.length){if(As(w)>0){d.push(`script edit ${V}: planned on the clip's words when applied`);break}throw Error("Transcribe the clip first: the script edit finds each line in its words")}const C=Array.isArray(p.scriptLines)&&p.scriptLines.length?p.scriptLines.slice(0,fa.maxLines).map(Y=>typeof Y=="string"?ym(Y)[0]??{text:Y}:{text:String(Y?.text??""),...at(Y?.duration)>0?{duration:at(Y.duration)}:{}}).filter(Y=>Y.text.trim()):ym(p.script??p.prompt??"");if(!C.length)throw Error("The script is empty");const O=p.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)&&!As(L))throw Error("Transcribe the reference video first: its pace comes from its words");const B=h.inPoint||0,H=B+h.duration*(h.playbackRate||1),q=r$(C,T.filter(Y=>Y.start>=B-.05&&Y.end<=H+.05),{pace:L?.words?.length?o$(L.words):null,cutPauses:p.cutPauses!==!1,speed:typeof p.speed=="boolean"?p.speed:p.booleanValue!==!1,maxPause:at(p.maxPause)??at(p.numberValue)??void 0,skip:Array.isArray(p.skipLines)?p.skipLines.filter(Number.isInteger):[],silences:M1(w)??[]}),et=n.locale==="en";if(d.push(...i$(q,et)),p.dryRun===!0){d.push(et?`script edit (preview): ${q.found} / ${q.lines.length} lines found → ${q.length.toFixed(1)}s`:`dựng theo kịch bản (xem trước): thấy ${q.found} / ${q.lines.length} câu → ${q.length.toFixed(1)}s`);break}const st=a$(s,h.id,q,{tracks:r,maxClips:Gt,makeId:Dt,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,d.push(et?`script edit: ${q.found} / ${q.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: ${q.found} / ${q.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(!qd.includes(p.tool))throw Error(`audioTool: tool must be one of ${qd.join(", ")}`);if(!Array.isArray(p.processed)||!p.processed.length)throw Error("audioTool runs through Clipoox MCP edit_timeline only (the server processes the sound first)");for(const h of p.processed){let w=rt.get(h.clipId)??h.clipId,T=y(w);if(!T)throw Error(`Không thấy clip ${h.clipId}`);if(T.kind==="video"){const L=mb(s,T.id,{tracks:r,makeId:Dt});s=L.clips,rt.set(h.clipId,L.audio),w=L.audio,T=y(w)}if(T?.kind!=="audio")throw Error("audioTool: only video and audio clips have sound");const C=[...T.audioTools??[],p.tool];sk(C);const O=at(h.duration);if(!h.dry&&(typeof h.url!="string"||!O||O<=0))throw Error("audioTool: the processed sound is missing");s=s.map(L=>L.id!==w?L:h.dry?{...L,audioTools:C}:{...L,url:h.url,...typeof h.gcsUri=="string"?{gcsUri:h.gcsUri}:{},inPoint:0,sourceDuration:+O.toFixed(3),audioTools:C}),d.push(`${p.tool} ${T.label||w}${rt.get(h.clipId)===w&&h.clipId!==w?" (sound detached from the video)":""}`)}break}case"muffleAudio":{s=ik(s,p.clipId,p.booleanValue===!1?{remove:!0}:{at:at(p.at),duration:at(p.duration)}),d.push(p.booleanValue===!1?`unmuffle ${V}`:`muffle ${V} ${at(p.at)}–${(at(p.at)+at(p.duration)).toFixed(2)} s`);break}case"duckAudio":{const h=p.clipId?[p.clipId]:s.filter(T=>T.kind==="audio"&&!T.sfx&&(p.track===void 0||T.track===p.track)&&!o.find(C=>C.id===T.nodeId)?.transcript?.length).map(T=>T.id);if(p.booleanValue===!1){let T=0;if(s=s.map(C=>{if(!h.includes(C.id)||!C.duck)return C;T++;const{duck:O,...L}=C;return L}),!T)throw Error("Nothing is ducked");d.push(`unduck ${T} clip`);break}const w=p4(s,h,o,p.numberValue??.25,r);if(!w.ducked)throw Error("The music does not overlap any speech");s=w.clips,d.push(`duck ${w.ducked} clip → ${p.numberValue??.25} under speech`);break}case"punchIn":{const h=at(p.at);if(h===null)throw Error("punchIn needs at (timeline seconds)");const w=vu(s,p.clipId,h);if(w<0)throw Error("Clip not found");const T=s[w];if(p.punchStyle!=null&&!Yo.styles.includes(p.punchStyle))throw Error(`Punch-in style must be ${Yo.styles.join(" or ")}`);s[w]={...T,...Pm(T,{at:ft(h-T.start),duration:at(p.duration)??void 0,amount:at(p.numberValue)??void 0,style:p.punchStyle??void 0,anchor:jc(T,o.find(C=>C.id===T.nodeId))})},d.push(`punch-in ${V} @ ${ft(h)}s`);break}case"makeRoom":{const h=at(p.at);if(h===null)throw Error("makeRoom needs at (timeline seconds)");const w=vu(s,p.clipId,h);if(w<0)throw Error("Clip not found");const T=s[w];if(!a0.includes(p.preset))throw Error(`Make room preset must be ${a0.join("/")}`);s[w]={...T,...SE(T,{at:ft(h-T.start),duration:at(p.duration)??void 0,preset:p.preset,amount:at(p.numberValue)??void 0})},d.push(`make room ${p.preset} ${V} @ ${ft(h)}s`);break}case"speakerBubble":{const h=at(p.at),w=y(p.clipId);if(!w)throw Error("Clip not found");const T=h!==null&&!(h>=w.start&&h<w.start+w.duration)?s.find(B=>B.nodeId===w.nodeId&&B.track===w.track&&!B.mask&&h>=B.start&&h<B.start+B.duration)??w:w;if(s.length+2>Gt)throw Error(`Tối đa ${Gt} clip`);const C=at(p.at);if(C===null)throw Error("speakerBubble needs at (timeline seconds)");const O=p.corner??"bottom-left";if(!co.corners.includes(O))throw Error(`Bubble corner must be ${co.corners.join("/")}`);for(const B of["posX","posY"])if(p[B]!=null&&!(Number.isFinite(p[B])&&p[B]>=0&&p[B]<=1))throw Error(`speakerBubble ${B} must be 0..1 (the bubble centre)`);if(p.color!=null&&!/^#[0-9a-fA-F]{6}$/.test(String(p.color)))throw Error("speakerBubble color must be #RRGGBB");s=J$(s,T.id,{at:C,duration:at(p.duration)??void 0,corner:O,size:at(p.numberValue)??void 0,posX:at(p.posX),posY:at(p.posY),color:p.color!=null?String(p.color).toLowerCase():null,W:n?.W||1280,H:n?.H||720,material:o.find(B=>B.id===T.nodeId)??null,newId:Dt}).clips,d.push(`speaker bubble ${V} @ ${ft(C)}s`);break}case"stepPunch":{p=te(p);const h=at(p.at);if(h===null)throw Error("stepPunch needs at (timeline seconds)");const w=vu(s,p.clipId,h);if(w<0)throw Error("Clip not found");const T=s[w];s[w]={...T,...EA(T,{at:ft(h-T.start),steps:$t(p.steps),frames:$t(p.frames),amount:$t(p.amount)??$t(p.numberValue),point:Array.isArray(p.point)?p.point:null,back:p.back!==!1})},d.push(`stepPunch ${V} @ ${ft(h)}s`);break}case"matteFlash":{p=te(p);let h=y(p.clipId);if(!h||h.kind!=="video"&&h.kind!=="image")throw Error("matteFlash needs a video or image clip");if(!h.person){const C=h,O=s.find(L=>L.id!==C.id&&L.kind===C.kind&&L.person&&L.url===C.url);O&&(h={...C,person:O.person})}if(!h.person){if(h.kind!=="video"||n.noPendingMatte||!t.some(L=>L.id===h.id))throw Error(`"${h.label||h.id}" has no AI cut-out yet — segmentPerson / cutOutObject on it first`);const{clipId:C,...O}=p;A(h,null,{...O,clipId:h.id}),d.push(`matteFlash ${h.label||h.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=()=>{let C=Dt();for(;y(C);)C=Dt();return C},T=SA(h,{frames:$t(p.frames)??$t(p.numberValue),side:p.side==="out"?"out":"in",aspect:n.W&&n.H?n.W/n.H:void 0},w);if(s.length+T.length>Gt)throw Error(`Tối đa ${Gt} clip`);for(const C of T){const{track:O}=qt(s,r,C.start,C.start+C.duration);s.push({...C,track:O}),X.push(C.id)}d.push(`matteFlash ${h.label||h.id}: ${Math.round(T[0].duration*30)} frame(s) of white silhouette on black at ${T[0].start}s`);break}case"endingLook":{p=te(p);const h=p.style??p.preset??"drain";if(!["drain","iris","drain-iris"].includes(h))throw Error("endingLook style: drain | iris | drain-iris");const w=y(p.clipId);if(!w)throw Error("Clip not found");const T=at(p.at),C=()=>{let L=Dt();for(;y(L);)L=Dt();return L};if(s.length+2>Gt)throw Error(`Tối đa ${Gt} clip`);let O=w;if(h!=="drain"){const L=s.length,B=AA(s,w.id,{at:T??void 0,radius:$t(p.radius),push:$t(p.push),cx:Array.isArray(p.point)?Number(p.point[0]):$t(p.posX),cy:Array.isArray(p.point)?Number(p.point[1]):$t(p.posY),W:n.W||1280,H:n.H||720,material:o.find(H=>H.id===w.nodeId)??null,newId:C});s=B.clips,O=s.find(H=>H.id===B.irisId),s.length>L&&X.push(B.irisId)}if(h!=="iris"){const L=IA(O,{at:h==="drain"?T??void 0:at(p.drainAt)??void 0,duration:$t(p.duration)},C);if(h==="drain-iris"&&L.mask?.keys?.length===1){const H=L.mask.keys[0].pts,q=H.reduce((st,Y)=>st+Y[0],0)/H.length,et=H.reduce((st,Y)=>st+Y[1],0)/H.length;L.mask={...L.mask,keys:[{t:0,pts:H.map(([st,Y])=>[ao(q+(st-q)*1.04),ao(et+(Y-et)*1.04)])}]}}const{track:B}=qt(s,r,L.start,L.start+L.duration);s.push({...L,track:B}),X.push(L.id)}d.push(`endingLook ${h}: ${V}`);break}case"mediaCard":{p=te(p);const h=y(p.clipId);if(!h)throw Error("Clip not found");for(const C of["posX","posY"])if(p[C]!=null&&!(Number.isFinite(p[C])&&p[C]>=0&&p[C]<=1))throw Error(`mediaCard ${C} must be 0..1 (the card centre)`);const{patch:w,rect:T}=fb(h,{W:n.W||1280,H:n.H||720,material:o.find(C=>C.id===h.nodeId)??null,width:$t(p.width)??$t(p.numberValue),cx:$t(p.posX),cy:$t(p.posY),aspect:$t(p.aspect),round:$t(p.round),rim:p.rim===!1?!1:p.color??void 0});for(const[C,O]of Object.entries(w))O===void 0?delete h[C]:h[C]=O;d.push(`mediaCard ${V}: card at x ${T.x}, y ${T.y}, w ${T.w}, h ${T.h} (fractions of the frame)`);break}case"mediaBoard":{p=te(p);const h=Array.isArray(p.clipIds)?p.clipIds:[],w=h.map(B=>y(B));if(!w.length||w.some(B=>!B)||new Set(h).size!==h.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=p.area&&["x","y","w","h"].every(B=>Number.isFinite(p.area[B])&&p.area[B]>=0&&p.area[B]<=1)&&p.area.w>.1&&p.area.h>.1?{x:p.area.x,y:p.area.y,w:Math.min(p.area.w,1-p.area.x),h:Math.min(p.area.h,1-p.area.y)}:void 0,L=OA(w,{W:n.W||1280,H:n.H||720,materials:o,area:O,cols:$t(p.cols),step:$t(p.step),round:$t(p.round),rim:p.rim===!1?!1:p.color??void 0});for(const B of w)for(const[H,q]of Object.entries(L.patches.get(B.id)))q===void 0?delete B[H]:B[H]=q;d.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":{p=te(p);const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=(Array.isArray(p.moves)?p.moves:[]).map(T=>({...T,at:Number(T?.at)-h.start}));Object.assign(h,zA(h,{moves:w})),d.push(`screenCamera ${V}: ${w.length} move(s)`);break}case"outlineObject":{p=te(p);const h=y(p.clipId);if(!h||!h.person&&!h.mask)throw Error("outlineObject needs a cut-out layer (cutOutObject / segmentPerson, or a masked layer)");if(p.booleanValue===!1){delete h.edge,d.push(`outlineObject ${V}: removed`);break}const w=(T,C,O,L)=>Math.max(C,Math.min(O,Number.isFinite(T)?T:L));h.edge=Su({color:String(p.color??"#a3ff00").toLowerCase(),width:w($t(p.width),.002,.08,.006),glow:w($t(p.glow),0,2,1),...p.run===!0?{cover:.35,sweep:180,comet:!0}:{}}),d.push(`outlineObject ${V}: outline ${h.edge.color}`);break}case"handWipe":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="video"&&h.kind!=="image"||h.motion||h.title)throw Error("handWipe needs clipId = the picture / video to reveal");const w=y(p.sourceClipId);if(!w||w.kind!=="video")throw Error("handWipe needs sourceClipId = the footage with the hand");if(w.id===h.id)throw Error("handWipe: the layer and the footage must be two clips");if(h.mask||h.person)throw Error("handWipe: the layer already has a mask / cut-out");const T=n0({...p,point:p.point??"palm"}),C=p.dir??"auto",O=$t(p.feather);if(!pe.wipe.dirs.includes(C))throw Error(`handWipe dir: ${pe.wipe.dirs.join(" | ")}`);const L=Math.max(h.start,w.start),B=Math.min(h.start+h.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>Gt)throw Error(`Tối đa ${Gt} clip`);const H=n.W||1280,q=n.H||720,et=o.find(vt=>vt.id===h.nodeId),st=Math.round(et?.width)||H,Y=Math.round(et?.height)||q;let ct=Dt();for(;y(ct);)ct=Dt();let gt={...w,id:ct};if(L>gt.start+1e-6){const[,vt]=Fe(gt,L,`${ct}-a`);vt&&(gt={...vt,id:ct})}if(B<gt.start+gt.duration-1e-6){const[vt]=Fe(gt,B,`${ct}-b`);gt={...vt,id:ct}}const Z=gt,nt={...gt,label:`${w.label||"Video"} · tay`,volume:0,mask:wh(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=qt(s,r,nt.start,nt.start+nt.duration).track,s.push(nt),X.push(ct);const dt={source:w.id,mode:"wipe",cutout:ct,point:T.point,side:T.side,dir:C,...O!=null?{feather:O}:{},from:ao(L-w.start),duration:ao(B-L)};if(Dp(w,L-w.start,B-L)){const vt=LA(h,w,{point:T.point,side:T.side,dir:C,feather:O??void 0,W:H,H:q,mw:st,mh:Y});h.mask=vt.patch.mask;const At=r0(Z);At&&(nt.mask=At),Object.assign(h,De(h,{kind:"hand-track",op:"handWipe",params:dt})),d.push(`handWipe ${V}: revealed by the hand moving ${vt.dir} (${vt.from}–${vt.to}s), hand in front`);break}h.mask=PA(st,Y),Object.assign(h,De(h,{kind:"hand-track",op:"handWipe",params:dt})),d.push(`handWipe ${V}: the hands are tracked in the editor, then the layer is revealed along the swipe`);break}case"beautyStrip":{const h=Array.isArray(p.clipIds)?p.clipIds:[];if(!h.length||h.length>40)throw Error("beautyFace needs clipId or clipIds (1–40)");let w=0;for(const T of h){const C=y(Mt(T));if(!C)throw Error(`Clip not found: ${String(T).slice(0,60)}`);if(C.kind!=="video"&&C.kind!=="image"||C.title||C.shape||C.motion||C.card)throw Error(`beautyFace: ${C.label||C.id} is not footage (a video / image clip)`);const O=Nh(C.grade),L=O.filter(B=>!zv(B));if(w+=O.length-L.length,L.length!==O.length){const B=Fh(C.grade||{},L);Object.keys(B).length?C.grade=B:delete C.grade}}d.push(p._off?`beautyFace: removed ${w} beauty node(s)`:`beautyFace: ${h.length} clip(s)${w?` (replaced ${w} earlier beauty node(s))`:""}`);break}case"trackFace3D":{const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("trackFace3D needs clipId = a video clip");if(us(h)&&p.booleanValue!==!0){d.push(`trackFace3D ${h.label||h.id}: already tracked in 3D (${h.face.n} samples)`);break}Object.assign(h,De(h,{kind:"face-3d",op:"trackFace3D"})),d.push(`trackFace3D ${h.label||h.id}: the face is tracked in 3D in the open editor`);break}case"pinToFace":{p=te(p);const h=y(p.clipId),w=y(p.sourceClipId);if(!h||!ak(h))throw Error("pinToFace needs clipId = an image / video / text / Motion layer");if(!w||w.kind!=="video"||w.id===h.id)throw Error("pinToFace needs sourceClipId = the footage with the face (a video clip)");const T=Math.max(h.start,w.start);if(Math.min(h.start+h.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===h.nodeId),L=h.motion||h.title||!O?.width?(n.W||1280)/(n.H||720):O.width/O.height;delete h.pendingPin,h.pin={clip:w.id,face:Af(p.place??"front",L,p)},us(w)||Object.assign(w,De(w,{kind:"face-3d",op:"pinToFace"})),d.push(`pinToFace ${h.label||h.id} → ${w.label||w.id} (${p.place??"front"}${us(w)?"":", face tracked in 3D in the open editor"})`);break}case"faceHologram":{p=te(p);const h=y(p.sourceClipId??p.clipId);if(!h||h.kind!=="video")throw Error("faceHologram needs sourceClipId = the footage with the face");const w=h1[p.set??"call"];if(!w)throw Error(`faceHologram set must be one of ${s5.join(", ")}`);if(p.place!=null&&!Bu.includes(p.place))throw Error(`faceHologram place must be one of ${Bu.join(", ")}`);const T=p.at==null?h.start:Number(p.at);if(!Number.isFinite(T)||T<h.start-1e-6||T>=h.start+h.duration)throw Error("faceHologram at must be a timeline time inside the footage");const C=Math.min(to.maxDuration,h.start+h.duration-T,p.duration==null?1/0:Number(p.duration));if(!(C>=1/Me))throw Error("faceHologram duration is too short");if(s.length+w.layers.length>Gt)throw Error(`Tối đa ${Gt} clip`);const O=(n.W||1280)/(n.H||720),L=ft(T),B=ft(C),H=[];for(const q of w.layers){const et=Fi(q.preset,{text:p.text,subText:p.subText??p.subtitle,numberValue:p.numberValue,color:p.color}),st=ko({code:et.code,params:et.params,preset:et.preset,kind:et.kind});let Y=Dt();for(;y(Y);)Y=Dt();const{track:ct}=qt(s,r,L,L+B);s.push({id:Y,nodeId:"",kind:"image",url:"",label:`Hologram · ${et.name}`,volume:0,motion:st,blend:"add",start:L,duration:B,track:ct,motionKeys:[],pin:{clip:h.id,face:Af(p.place??q.place,O,p)}}),X.push(Y),H.push(Y)}us(h)||Object.assign(h,De(h,{kind:"face-3d",op:"faceHologram"})),d.push(`faceHologram ${p.set??"call"} on ${h.label||h.id}: ${H.length} layer(s) ${H.join(", ")}${us(h)?"":" — the face is tracked in 3D in the open editor"}`);break}case"fixFace":{p=te(p);const h=y(p.clipId);if(!h?.face)throw Error("fixFace needs clipId = a video with a face track (trackFace3D)");if(p.booleanValue===!1){delete h.face.fix,h.face={...h.face},d.push(`fixFace ${h.label||h.id}: corrections removed`);break}const w=p.at==null?h.start:Number(p.at);if(!Number.isFinite(w)||w<h.start-1e-6||w>h.start+h.duration+1e-6)throw Error("fixFace at must be a timeline time inside the clip");const T=nk(h,w-h.start,{dx:$t(p.dx),dy:$t(p.dy),ds:$t(p.scale),droll:$t(p.roll),dyaw:$t(p.yaw),dpitch:$t(p.pitch)});h.face={...h.face,fix:T.fix},d.push(`fixFace ${h.label||h.id} at ${ao(w)}s: ${T.text}`);break}case"speakerWindow":{const h=at(p.at);if(h===null)throw Error("speakerWindow needs at (timeline seconds)");const w=y(p.clipId);if(!w)throw Error("Clip not found");const T=h>=w.start&&h<w.start+w.duration?w:s.find(O=>O.nodeId===w.nodeId&&O.track===w.track&&!O.mask&&h>=O.start&&h<O.start+O.duration)??w;if(s.length+2>Gt)throw Error(`Tối đa ${Gt} clip`);for(const O of["posX","posY"])if(p[O]!=null&&!(Number.isFinite(p[O])&&p[O]>=0&&p[O]<=1))throw Error(`speakerWindow ${O} must be 0..1 (the window centre)`);if(p.aspect!=null&&!(Number.isFinite(p.aspect)&&p.aspect>=.4&&p.aspect<=2))throw Error("speakerWindow aspect must be .4–2 (width / height)");s=t6(s,T.id,{at:h,duration:at(p.duration)??void 0,width:at(p.numberValue)??void 0,cx:at(p.posX)??void 0,cy:at(p.posY)??void 0,aspect:at(p.aspect)??void 0,color:p.color??void 0,W:n?.W||1280,H:n?.H||720,material:o.find(O=>O.id===T.nodeId)??null,newId:Dt}).clips,d.push(`speaker window ${V} @ ${ft(h)}s`);break}case"speakerLayout":{if(p.error)throw Error(p.error);const h=td(p,"speakerLayout"),w=y(h.clipId);if(!w)throw Error("Clip not found");const T=W6(s,w.id,{beats:h.beats,morph:h.morph,W:n?.W||1280,H:n?.H||720,material:o.find(C=>C.id===w.nodeId)??null});s=T.clips,d.push(`speaker layout ${V}: ${h.beats.length} beat${h.beats.length>1?"s":""} on ${T.pieces} piece${T.pieces>1?"s":""}`);break}case"courseStyle":{const h=y(p.clipId);if(!h||!["image","video"].includes(h.kind)||h.motion||h.title||h.shape||h.card)throw Error("Course style needs a photo / video clip");const w=o.find(O=>O.id===h.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,C=Number.isInteger(w?.height)&&w.height>1?w.height:1e3;if(p.crop!=null){const{left:O=0,right:L=0,top:B=0,bottom:H=0}=p.crop;if(![O,L,B,H].every(q=>Number.isFinite(q)&&q>=0&&q<=.9)||O+L>.9||B+H>.9)throw Error("Invalid crop");h.crop={left:O,right:L,top:B,bottom:H}}if(p.rotation!=null){const O=at(p.rotation);if(O===null||Math.abs(O)>Cs)throw Error(`rotation must be -${Cs}..${Cs}`);h.rotation=O}if(p.mask!=null){if(!["circle","rounded","none"].includes(p.mask))throw Error("Course style mask must be circle / rounded / none");if(p.mask==="none")delete h.mask;else{const O=ta(T,C,h.crop),L=Math.min(O.w,O.h),B=p.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};h.mask=cr({mw:T,mh:C},[Cn(B,O.w,O.h)])}}if(p.color!=null){if(!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("Course style color must be #RRGGBB");h.edge={color:p.color.toLowerCase(),width:Math.max(.002,Math.min(.08,at(p.numberValue)??.008)),glow:.7}}if(p.shadow===!0&&(h.shadow={...hn,opacity:.55,blur:18,distance:8}),p.fit!=null){if(!["contain","cover"].includes(p.fit))throw Error("Course style fit must be contain / cover");p.fit==="cover"?h.fit="cover":delete h.fit}d.push(`course style ${V}`);break}case"luxuryCard":{const h=y(p.clipId);if(!h||!["image","video"].includes(h.kind)||h.motion||h.title||h.shape||h.card||h.geo)throw Error("luxuryCard needs a photo / video clip");const w=o.find(H=>H.id===h.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,C=Number.isInteger(w?.height)&&w.height>1?w.height:1e3;if(p.color!=null&&!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("luxuryCard color must be #RRGGBB");const O=Math.max(0,Math.min(.3,at(p.numberValue)??.04)),L=ta(T,C,h.crop),B=(p.color??"#ffd56a").toLowerCase();if(h.mask=cr({mw:T,mh:C},[Cn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:O},L.w,L.h)]),p.booleanValue===!0)h.edge={color:B,width:.01,glow:1.2,cover:.45,sweep:120,comet:!0};else{const H=[];for(let q=0;q<=h.duration+1e-6&&H.length<30;q+=.6)H.push({time:+q.toFixed(3),value:H.length%2?1:.45,ease:Qt["ease-in-out"]});h.edge={color:B,width:.01,glow:1.2,...H.length>1?{keys:H}:{}}}h.shadow={...hn,opacity:.5,blur:22,distance:10},d.push(`gold card ${h.label||h.id}${p.booleanValue===!0?" (running light)":""}`);break}case"floatCard":{const h=[...new Set([...Array.isArray(p.clipIds)?p.clipIds:[],...p.clipId?[p.clipId]:[]])];if(!h.length||h.length>6)throw Error("floatCard needs 1–6 picture / video clips (clipId or clipIds)");if(p.color!=null&&!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("floatCard color must be #RRGGBB");const w=(p.color??"#ffffff").toLowerCase(),T=Math.max(0,Math.min(20,at(p.numberValue)??6)),C=p.booleanValue!==!1,O=h.length;h.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 q=o.find(xt=>xt.id===H.nodeId),et=Number.isInteger(q?.width)&&q.width>1?q.width:1e3,st=Number.isInteger(q?.height)&&q.height>1?q.height:1e3;H.mask=cr({mw:et,mh:st},[Cn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:.06},ta(et,st,H.crop).w,ta(et,st,H.crop).h)]),H.edge={color:w,width:.009,glow:1.3,amount:.9},H.shadow={...hn,opacity:.6,blur:26,distance:16};const Y=O>1?+((B-(O-1)/2)*Math.min(.3,.9/O)).toFixed(4):Zt(H,"x",0),ct=O>1?B%2?.035:-.035:Zt(H,"y",0),gt=O>1?+Math.min(.62,1.5/O).toFixed(3):Math.abs(Zt(H,"zoom",0)-1)<1e-6?.62:Zt(H,"zoom",0),Z=(B%2?-1:1)*T,nt=H.duration,dt=xt=>+Math.min(nt,xt).toFixed(3),vt="ease-in-out",At=(xt,St)=>{Object.assign(H,Qn(H,xt,St.filter((jt,Kt,ee)=>!Kt||jt.time-ee[Kt-1].time>=1/30)))};if(At("zoom",[{time:0,value:+(gt*.82).toFixed(4),ease:"back-out"},{time:dt(.38),value:gt}]),At("opacity",[{time:0,value:0},{time:dt(.22),value:1}]),At("x",[{time:0,value:Y}]),C&&nt>1){const xt=[],St=[];for(let jt=0,Kt=0;jt<=nt+1e-6&&xt.length<30;jt+=1.4,Kt++)xt.push({time:dt(jt),value:+(ct+(Kt%2?.012:-.012)).toFixed(4),ease:vt}),St.push({time:dt(jt),value:+(Z+(Kt%2?-1:1)*Math.max(.6,T*.3)).toFixed(3),ease:vt});At("y",xt),At("rot",St)}else At("y",[{time:0,value:ct}]),At("rot",[{time:0,value:Z}])}),d.push(`floatCard: ${O} floating card${O>1?"s":""} (tilt ${T}°${C?", drifting":""})`);break}case"breakdownShowcase":{if(p.color!=null&&!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("breakdownShowcase color must be #RRGGBB");if(p.style!=null&&!og.includes(p.style))throw Error(`breakdownShowcase style: ${og.join(" | ")}`);if(p.layout!=null&&p.layout!=="auto"&&!Oh.includes(p.layout))throw Error(`breakdownShowcase layout: auto | ${Oh.join(" | ")}`);if(p.labels!=null&&(!Array.isArray(p.labels)||p.labels.length>Va.shots||p.labels.some(T=>typeof T!="string")))throw Error(`breakdownShowcase labels: up to ${Va.shots} strings`);const h=[...new Set([...Array.isArray(p.clipIds)?p.clipIds:[],...p.clipId?[p.clipId]:[]])];for(const T of h)if(!y(T))throw Error(`Không thấy clip ${T}`);const w=bA(s,r,h,{style:p.style,color:p.color,layout:p.layout,lang:p.lang??(n.locale==="vi"?"vi":void 0),labels:p.labels,at:at(p.at)??void 0,newId:Dt,W:n.W||1280,H:n.H||720,materials:o});if(s.length+w.add.length>Gt)throw Error(`Tối đa ${Gt} clip`);s.push(...w.add),d.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 h=[...new Set(Array.isArray(p.clipIds)?p.clipIds:[])];if(h.length<2||h.length>16)throw Error("portfolioWall needs 2–16 picture / video clips (clipIds)");const w=p.style??"grid";if(!["grid","arc","mosaic"].includes(w))throw Error("portfolioWall style must be grid, arc or mosaic");const T=p.shape??(w==="mosaic"?"landscape":"portrait");if(!["portrait","landscape","square"].includes(T))throw Error("portfolioWall shape must be portrait, landscape or square");if(p.color!=null&&!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("portfolioWall color must be #RRGGBB");const C=at(p.numberValue);if(C!==null&&!(Number.isInteger(C)&&C>=1&&C<=4))throw Error("portfolioWall rows (numberValue) must be 1–4");let O=null;if(p.sourceClipId!=null&&(O=y(p.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=h.length,q=T==="portrait"?9/16:T==="square"?1:16/9,et=(p.color??"#ffffff").toLowerCase(),st=p.booleanValue!==!1,Y=C??(w==="mosaic"?Math.max(2,Math.round(Math.sqrt(H*q*B/L))):H<=5?1:H<=10?2:3),ct=Math.ceil(H/Y),gt=L*(w==="mosaic"?1.04:w==="arc"?1.02:.95),Z=B*(w==="mosaic"?1.06:w==="arc"?.88:.9),nt=gt/ct,dt=Z/Y,vt=w==="mosaic"?.94:w==="arc"?.86:.9,At=Math.min(nt*vt,dt*vt*q);if(h.forEach((xt,St)=>{const jt=y(xt);if(!jt||!["image","video"].includes(jt.kind)||jt.motion||jt.title||jt.shape||jt.card||jt.geo||jt.vfx)throw Error(`portfolioWall needs photo / video clips (${xt})`);if(O&&jt.id===O.id)throw Error("portfolioWall cannot use the speaker video as a card");if(r[jt.track]?.locked)throw Error("Track đã khóa");const Kt=o.find(Ft=>Ft.id===jt.nodeId),ee=Number.isInteger(Kt?.width)&&Kt.width>1?Kt.width:1280,le=Number.isInteger(Kt?.height)&&Kt.height>1?Kt.height:720,xe=ta(ee,le,jt.crop),Ut=xe.w/xe.h,Nt=q<Ut?q/Ut:1,Bt=q<Ut?1:Ut/q;jt.mask=cr({mw:ee,mh:le},[Cn({kind:"rect",cx:.5,cy:.5,w:Nt,h:Bt,rot:0,round:.08},xe.w,xe.h)]),jt.edge={color:et,width:.006,glow:.8,amount:.85},jt.shadow={...hn,opacity:.45,blur:18,distance:8},jt.fit==="cover"&&delete jt.fit,w==="mosaic"&&(jt.exposure=-.75,jt.saturation=.9);const _t=Math.floor(St/ct),de=_t===Y-1?H-_t*ct:ct,re=St-_t*ct+(ct-de)/2,ye=Math.min(L/xe.w,B/xe.h)*xe.w,or=+(At/(ye*Nt)).toFixed(4),$r=+(((re+.5)/ct-.5)*gt/L).toFixed(4),Br=+(((_t+.5)/Y-.5)*Z/B).toFixed(4),zo=jt.duration,Ze=Ft=>+Math.min(zo,Math.max(0,Ft)).toFixed(3),vo=Ze(St*(w==="mosaic"?.035:.07)),W=Ze(vo+(w==="mosaic"?.4:.55)),mt=w==="mosaic"?1.07:1.03,bt=(Ft,Rt)=>{Object.assign(jt,Qn(jt,Ft,Rt.filter((Lt,Ht,Yt)=>!Ht||Lt.time-Yt[Ht-1].time>=1/30)))};if(w==="arc"){const Ft=L*1.25,Rt=Or(L,B),Lt=(re-(ct-1)/2)*nt/Ft,Ht=Math.abs(Lt)>1e-6?Math.sign(Lt):St%2?1:-1,Yt=Lt+Ht*.95,Jt=Lt+.06,ie=ne=>({x:+(Ft*Math.sin(ne)/L).toFixed(4),depth:+(Ft*(1-Math.cos(ne))/Rt).toFixed(4),tiltY:+(-ne*180/Math.PI).toFixed(3)}),ce=ie(Yt),Xt=ie(Lt),oe=ie(Jt);jt.is3D=!0;for(const ne of["x","depth","tiltY"])bt(ne,[{time:0,value:ce[ne]},{time:vo,value:ce[ne],ease:"ease-out"},{time:W,value:Xt[ne],ease:"ease-in-out"},{time:Ze(zo),value:oe[ne]}]);bt("y",[{time:0,value:Br}]),bt("zoom",[{time:0,value:or}]),bt("rot",[{time:0,value:0}]),bt("opacity",[{time:0,value:0},{time:vo,value:0},{time:Ze(vo+.25),value:1},...st&&zo>W+.5?[{time:Ze(zo-.35),value:1},{time:Ze(zo),value:0}]:[]]);return}const Et=w==="mosaic"?.035:0;bt("x",[{time:0,value:$r},{time:W,value:$r,ease:"ease-in-out"},{time:Ze(zo),value:+($r*mt-Et).toFixed(4)}]),bt("y",w==="grid"?[{time:0,value:+(Br+.75).toFixed(4)},{time:vo,value:+(Br+.75).toFixed(4),ease:"ease-out"},{time:W,value:Br,ease:"ease-in-out"},{time:Ze(zo),value:+(Br*mt).toFixed(4)}]:[{time:0,value:Br},{time:Ze(zo),value:+(Br*mt).toFixed(4)}]),bt("zoom",[{time:0,value:+(or*(w==="grid"?.8:1.25)).toFixed(4)},{time:vo,value:+(or*(w==="grid"?.8:1.25)).toFixed(4),ease:"back-out"},{time:W,value:or,ease:"ease-in-out"},{time:Ze(zo),value:+(or*mt).toFixed(4)}]),bt("rot",w==="grid"?[{time:0,value:St%2?7:-7},{time:vo,value:St%2?7:-7,ease:"ease-out"},{time:W,value:0}]:[{time:0,value:0}]),bt("opacity",[{time:0,value:0},{time:vo,value:0},{time:Ze(vo+.18),value:1},...st&&zo>W+.5?[{time:Ze(zo-.35),value:1},{time:Ze(zo),value:0}]:[]])}),w==="arc"&&!u?.enabled&&(u={...u??Mr,enabled:!0,motionV:2,motionKeys:u?.motionKeys??[]}),O){const xt=h.reduce((St,jt)=>Xn(y(jt),y(St))>0?jt:St);it.splice(D+1,0,{op:"placeBehindPerson",clipId:xt,sourceClipId:O.id})}d.push(`portfolioWall: ${H} cards, ${w} ${Y}×${ct}${w==="arc"?" (3D, timeline camera on)":""}${O?", behind the speaker":""}`);break}case"promoShot":{const h=[...new Set(Array.isArray(p.clipIds)?p.clipIds:p.clipId!=null?[p.clipId]:[])],w=String(p.shot??"");if(!Rc.includes(w))throw Error(`promoShot shot must be ${Rc.join(" | ")}`);if(p.color!=null&&!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("promoShot color must be #RRGGBB");const T=at(p.size??p.cardSize);if(T!==null&&!(T>=.3&&T<=1))throw Error("promoShot size must be 0.3–1 (share of the frame width)");const C=n.W>0?n.W:1280,O=n.H>0?n.H:720,L=(p.color??"#ffffff").toLowerCase(),B=T??(w==="deck-deal"?.5:w==="zoom-detail"||w==="paparazzi"?.9:.78),H=(dt,vt)=>{const At=o.find(ee=>ee.id===dt.nodeId),xt=Number.isInteger(At?.width)&&At.width>1?At.width:1280,St=Number.isInteger(At?.height)&&At.height>1?At.height:720,jt=ta(xt,St,vt),Kt=Math.min(C/jt.w,O/jt.h);return{mw:xt,mh:St,sp:jt,fitW:Kt*jt.w,fitH:Kt*jt.h}},q=h.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 At=H(vt,vt.crop),xt=+Math.min(B*C/At.fitW,.92*O/At.fitH).toFixed(4);return{c:vt,f:At,card:{id:vt.id,duration:vt.duration,zoom:xt,dispW:At.fitW/C,dispH:At.fitH/O}}}),et=q[0]?.c,st=dt=>at(dt)===null?null:at(dt)-(et?.start??0),Y=p.focus??(at(p.focusX)!==null||at(p.focusY)!==null||at(p.focusSize)!==null?{x:at(p.focusX)??void 0,y:at(p.focusY)??void 0,size:at(p.focusSize)??void 0}:void 0),ct=Array.isArray(p.points)?p.points.map(dt=>Array.isArray(dt)?{x:dt[0],y:dt[1]}:dt):void 0,gt=iE(w,q.map(dt=>dt.card),{focus:Y,points:ct,times:Array.isArray(p.times)?p.times.map(st).filter(dt=>dt!==null):void 0,at:st(p.at)??void 0,bStart:q[1]?q[1].c.start-et.start:0,slices:at(p.numberValue)??void 0}),Z=(dt,vt)=>{dt.mask=cr({mw:vt.mw,mh:vt.mh},[Cn({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={...hn,opacity:.5,blur:26,distance:14},dt.fit==="cover"&&delete dt.fit},nt=(dt,vt,At=1)=>{vt.is3D&&(dt.is3D=!0);for(const[xt,St]of Object.entries(vt.keys)){const jt=xt==="zoom"&&At!==1?St.map(Kt=>({...Kt,value:+(Kt.value*At).toFixed(4)})):St;Object.assign(dt,Qn(dt,xt,jt.filter(Kt=>Kt.time<=dt.duration+1e-6)))}for(const[xt,St]of Object.entries(vt.effects??{}))Object.assign(dt,Qn(dt,xt,St.filter(jt=>jt.time<=dt.duration+1e-6)))};if(w==="exploded"){const{c:dt,f:vt}=q[0],At=gt.slices,xt=dt.crop??{left:0,right:0,top:0,bottom:0},St=1-xt.top-xt.bottom,jt=[];for(let ee=Oa(dt.track)+1;jt.length<At-1&&ee<40;ee++){const le=fn(ee);le!=null&&I(dt)(le)&&jt.push(le)}if(jt.length<At-1)throw Error("promoShot exploded needs free video tracks above the clip");const Kt=[];for(const ee of gt.cards){const le=ee.slice,xe={...xt,top:+(xt.top+St*le/At).toFixed(4),bottom:+(xt.bottom+St*(At-1-le)/At).toFixed(4)};let Ut=Dt();for(;y(Ut);)Ut=Dt();const Nt=le===At-1?dt:{...structuredClone(dt),id:Ut,track:jt[At-2-le]};Nt.crop=xe;const Bt=H(Nt,xe);Z(Nt,Bt),nt(Nt,ee,vt.fitW/Bt.fitW),Nt!==dt&&(s.push(Nt),Kt.push(Nt.id),X.push(Nt.id))}d.push(`promoShot exploded: ${At} bands (${Kt.length} copies on the tracks above), timeline camera on`)}else{for(const dt of gt.cards){const vt=q.find(At=>At.c.id===dt.id);Z(vt.c,vt.f),nt(vt.c,dt)}d.push(`promoShot ${w}: ${q.length} card${q.length>1?"s":""}${gt.camera?", timeline camera on":""}`)}gt.camera&&!u?.enabled&&(u={...u??Mr,enabled:!0,motionV:2,motionKeys:u?.motionKeys??[]});break}case"avatarBadge":{const h=y(p.clipId);if(!h||!["image","video"].includes(h.kind)||h.motion||h.title||h.shape||h.card||h.geo)throw Error("avatarBadge needs a photo / video clip");if(r[h.track]?.locked)throw Error("Track đã khóa");if(p.color!=null&&!/^#[0-9a-f]{6}$/i.test(p.color))throw Error("avatarBadge color must be #RRGGBB");const w=o.find(ct=>ct.id===h.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,C=Number.isInteger(w?.height)&&w.height>1?w.height:1e3,O=ta(T,C,h.crop),L=Math.min(O.w,O.h),B=(p.color??"#ffd56a").toLowerCase();h.mask=cr({mw:T,mh:C},[Cn({kind:"circle",cx:.5,cy:.5,w:+(L/O.w).toFixed(5),h:+(L/O.h).toFixed(5),rot:0},O.w,O.h)]),h.edge=p.booleanValue===!1?{color:B,width:.03,glow:1.6}:{color:B,width:.03,glow:1.6,cover:.7,sweep:200,comet:!0},h.shadow={...hn,opacity:.5,blur:20,distance:8};const H=Math.max(.1,Math.min(1,at(p.numberValue)??.32)),q=Math.max(-.5,Math.min(.5,at(p.posX)??0)),et=Math.max(-.5,Math.min(.5,at(p.posY)??0)),st=h.duration,Y=(ct,gt)=>{Object.assign(h,Qn(h,ct,gt.filter(Z=>Z.time<=st+1e-6)))};Y("x",[{time:0,value:q}]),Y("y",[{time:0,value:et}]),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}]),d.push(`avatarBadge ${V}: round badge${p.booleanValue===!1?"":" with a running ring light"}`);break}case"beatRamp":{const h=[...new Set([...Array.isArray(p.clipIds)?p.clipIds:[],...p.clipId?[p.clipId]:[]])];if(!h.length||h.length>60)throw Error("beatRamp needs 1–60 video clips (clipIds)");const w=h.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=at(p.every)??at(p.numberValue)??1;if(!Vf.includes(T))throw Error(`beatRamp every must be one of ${Vf.join(", ")} beats`);const C=p.preset??"peak-burst",O=H4(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=U4(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)),q=L.at(-1).start+L.at(-1).duration,et=s.find(Y=>Y.track===B&&!H.has(Y.id)&&Y.start<q-1e-6&&Y.start+Y.duration>L[0].start+1e-6);if(et)throw Error(`beatRamp would cover "${et.label||et.id}" on the same row (${L[0].start}–${+q.toFixed(2)} s) — move it or pick the shots on a free row`);const st=at(p.peak)??void 0;L.forEach((Y,ct)=>{const gt=w[ct],Z={...gt,start:Y.start,track:B},nt=Tf(Z,C,Y.duration,{peak:st}),dt=s.findIndex(vt=>vt.id===gt.id);s[dt]=nt}),d.push(`beatRamp ${C}: ${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 h=[...new Set([...Array.isArray(p.clipIds)?p.clipIds:[],...p.clipId?[p.clipId]:[]])];if(!h.length)throw Error("setAnchor needs clipId or clipIds");if(!Wf.includes(p.preset))throw Error(`setAnchor preset must be one of ${Wf.join(", ")}`);const w=n.W||1280,T=n.H||720,C={tl:"top-left",t:"top",tr:"top-right",l:"left",c:"center",r:"right",bl:"bottom-left",b:"bottom",br:"bottom-right"}[p.preset];for(const O of h){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,(at(p.at)??L.start)-L.start)),H=o.find(xt=>xt.id===L.nodeId),q=H?.width>0&&H?.height>0?H.width/H.height:w/T,et=w/T,st=L.fit==="cover"?1:Math.min(1,q/et),Y=L.fit==="cover"?1:Math.min(1,et/q),ct=Zt(L,"zoom",B),gt=.5+Zt(L,"x",B),Z=.5+Zt(L,"y",B),nt=st*ct/2,dt=Y*ct/2,vt=L.shape?.v===2?gg(L):[gt-nt,Z-dt,gt+nt,Z+dt];sr(s);const At=s.indexOf(L);s[At]=Ca(s,L,{anchor:C,at:B,W:w,H:T,box:vt})}d.push(`setAnchor ${p.preset} (${T1[p.preset].join(", ")}): ${h.length} layer(s)`);break}case"zoomMove":{const h=[...new Set([...Array.isArray(p.clipIds)?p.clipIds:[],...p.clipId?[p.clipId]:[]])];if(!h.length)throw Error("zoomMove needs clipId or clipIds");if(!xc.includes(p.preset))throw Error(`zoomMove preset must be one of ${xc.join(", ")}`);for(const w of h){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 C=p.preset.endsWith("start"),O=Zt(T,"zoom",C?T.duration:0),L=q4(p.preset,T.duration,O,at(p.numberValue)??void 0,at(p.duration)??void 0),B=L[0].time,H=L.at(-1).time,q=Ee(T,"zoom").filter(Y=>Y.time<B-1e-6||Y.time>H+1e-6).map(Y=>({time:Y.time,value:Y.value})),et=Qn(T,"zoom",[...q,...L].sort((Y,ct)=>Y.time-ct.time)),st=s.indexOf(T);s[st]=et}d.push(`zoomMove ${p.preset}: ${h.length} clip(s)`);break}case"stabilize":{const h=y(p.clipId);if(!h)throw Error("Clip not found");if(p.booleanValue===!1){if(!h.stabilized)throw Error("That clip is not stabilized");const{url:L,gcsUri:B,inPoint:H,sourceDuration:q}=h.stabilized,et=s.indexOf(h),st={...h,url:L,inPoint:H,sourceDuration:q};delete st.stabilized,B?st.gcsUri=B:delete st.gcsUri,s[et]=st,d.push(`stabilize off: ${V}`);break}const w=Array.isArray(p.processed)?p.processed.find(L=>L.clipId===h.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){d.push(`stabilize ${V} (dry run)`);break}const T=at(w.duration);if(typeof w.url!="string"||!T||T<=0)throw Error("stabilize: the stabilised video is missing");const C=h.stabilized??{url:h.url,...h.gcsUri?{gcsUri:h.gcsUri}:{},inPoint:h.inPoint??0,sourceDuration:h.sourceDuration},O=s.indexOf(h);s[O]={...h,url:w.url,...typeof w.gcsUri=="string"?{gcsUri:w.gcsUri}:{},inPoint:0,sourceDuration:+T.toFixed(3),stabilized:{...C,amount:w.amount}},d.push(`stabilize ${V} (${Math.round((w.amount??.5)*100)}%)`);break}case"logoLight":{const h=y(p.clipId);if(!h||!["image","video"].includes(h.kind)||h.motion||h.title||h.shape||h.card||h.geo)throw Error("logoLight needs the logo picture clip");const w=Math.max(0,Math.min(h.duration-.2,at(p.at)??0)),T=Math.max(.4,Math.min(4,at(p.duration)??1.2,h.duration-w)),C=(L,B,H)=>[{time:+w.toFixed(3),value:0,ease:Qt["ease-out"]},{time:+(w+T*L).toFixed(3),value:B,ease:Qt["ease-in-out"]},{time:+(w+T).toFixed(3),value:H}],O=[...(h.effects||[]).filter(L=>L.type!=="glow"&&L.type!=="exposure"),{type:"glow",amount:.35,keys:C(.45,.9,.35)},{type:"exposure",amount:0,keys:C(.4,.55,0)}];if(O.length>cn)throw Error(`At most ${cn} effects per clip`);h.effects=O,h.enter={type:"zoom-out",duration:+Math.min(T,.9).toFixed(3),amount:.12,fade:!0},d.push(`logo light ${h.label||h.id} @ ${w}s`);break}case"addSfx":{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const h=da(p.sfxId)??e5(p);if(!h)throw Error(`Unknown sound effect "${p.sfxId}"`);const w=at(p.at);if(w===null||w<0||w+h.duration>He)throw Error("addSfx needs at (timeline seconds) inside the timeline");const T=at(p.volume);if(T!==null&&(T<0||T>1))throw Error("SFX volume must be 0..1");const C=(h.music?r5:Bi)(s,r,h,w,{volume:T??void 0,track:at(p.track),id:Dt()});h.gcsUri&&(C.gcsUri=h.gcsUri),s.push(C),d.push(`sfx ${h.name} → ${C.start}s`);break}case"reframe":{if(!["16:9","9:16","1:1","4:5"].includes(p.aspectRatio))throw Error("Reframe needs aspectRatio");const h=h4(s,o,p.aspectRatio,{clipId:p.clipId},r);if(!h.reframed)throw Error(h.skipped.join("; ")||"Nothing to reframe");s=h.clips,N=p.aspectRatio,d.push(`reframe ${p.aspectRatio}: ${h.reframed} clip${h.skipped.length?` (skipped: ${h.skipped.join("; ")})`:""}`);break}case"rippleDelete":s=Of(s,p.clipId,null,r),d.push(`ripple delete: ${V}`);break;case"setTransition":{if(p.nearestCut===!0&&p.transitionId&&Number.isFinite(p.at)){const h=y(p.clipId);if(!h)throw Error("Clip not found");const T=s.filter(C=>C.nodeId===h.nodeId&&C.track===h.track&&C.kind===h.kind&&!C.mask&&s.some(O=>O.id!==C.id&&O.track===C.track&&O.kind!=="audio"&&Math.abs(O.start-(C.start+C.duration))<1/60)).sort((C,O)=>Math.abs(C.start+C.duration-p.at)-Math.abs(O.start+O.duration-p.at))[0];if(!T||Math.abs(T.start+T.duration-p.at)>1.5)throw Error("No cut near that time");p={...p,clipId:T.id}}try{if(p.transitionId){if(!p.spec||p.spec.id!==p.transitionId)throw Error(`Unknown transition "${p.transitionId}"`);const h=y(p.clipId),w=h&&s.find(T=>T.id!==h.id&&T.track===h.track&&T.kind!=="audio"&&Math.abs(T.start-(h.start+h.duration))<1/60);s=jd(s,p.clipId,p.spec.id==="match-walk"?mg(p.spec,h,w,o):p.spec,at(p.duration)??void 0),d.push(`transition ${p.spec.name}: ${V}`);break}y(p.clipId)?.transition&&(s=Xd(s,p.clipId)),y(p.clipId)?.join&&(s=s.map(h=>{if(h.id!==p.clipId)return h;const{join:w,...T}=h;return T})),s=y5(s,p.clipId,p.preset,p.duration??0,r),d.push(`transition: ${V}`);break}catch(h){const w=qA(s,p,c,r);if(!w)throw h;s=w.clips,d.push(`transition → ${w.note}: ${V}`);break}}case"addSubtitles":{const h=y(p.clipId),w=h&&o.find(O=>O.id===h.nodeId);if(!h||!w?.transcript?.length)throw Error("Analyze speech first");const T=sc(h,Yd(w.transcript)),C=Ud(T,h.duration);h.captionWords?.length&&(h.captionWords=rl(rk(h.captions,C,h.captionWords,h.duration),h.duration)),h.captions=C,d.push(`subtitles: ${V}`);break}case"addSocialCaptions":{const h=y(p.clipId),w=h&&o.find(L=>L.id===h.nodeId);if(!h||!["video","audio"].includes(h.kind))throw Error("Social captions need a video or audio clip");const T=p.captionStyle??"social";if(!["social","karaoke","classic","lesson"].includes(T))throw Error("Invalid caption preset");if(p.captionPosition!=null&&!["top","center","bottom"].includes(p.captionPosition))throw Error("Invalid caption position");if(p.emphasis!=null&&typeof p.emphasis!="boolean")throw Error("Invalid emphasis flag");if(p.perGroup!=null&&![1,2,3].includes(p.perGroup))throw Error("Words per group must be 1–3");if(p.look!=null&&!m1(p.look))throw Error(`Unknown caption look; use one of ${f1.map(L=>L.id).join(", ")}`);if(!h.captions?.length){if(!w?.transcript?.length)throw Error("Analyze speech first");h.captions=Ud(sc(h,Yd(w.transcript)),h.duration)}const C={...p.cueWords!=null?{cueWords:p.cueWords}:{},...p.lineWords!=null?{lineWords:p.lineWords}:{}};if(T==="classic"){h.captionStyle=yi({...p.look?zf({style:"classic"},p.look):{style:"classic"},...C}),d.push(`captions classic: ${V}`);break}if(h.captionWords=rl((w?.words?.length?Rh(h,rl(w.words,1/0,Cd)):np(h.captions)).slice(0,ek),h.duration),!h.captionWords.length)throw Error("No words to caption");if(h.captionStyle=yi({...ok,...T==="lesson"?o6:{style:T},...p.captionPosition?{position:p.captionPosition}:{},...p.emphasis!=null?{emphasis:p.emphasis}:{},...p.perGroup!=null?{perGroup:p.perGroup}:{},...typeof p.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(p.color)?{emphasisColor:p.color,emphasisColor2:p.color}:{}}),p.look&&(h.captionStyle=zf(h.captionStyle,p.look)),Object.keys(C).length&&(h.captionStyle=yi({...h.captionStyle,...C})),p.highlight!=null){if(!y1(p.highlight))throw Error(`Unknown highlight look; use one of ${g1.map(H=>H.id).join(", ")}`);const L=M5(p.highlight,h.captionStyle),B={...h.captionStyle,...L};for(const H of Object.keys(B))B[H]===void 0&&delete B[H];h.captionStyle=yi(B)}const O={...p.emphasisScale!=null?{emphasisScale:p.emphasisScale}:{},...p.anim!=null?{anim:p.anim}:{},...p.rowWords!=null?{rowWords:p.rowWords}:{},...p.lineGap!=null?{lineGap:p.lineGap}:{},...p.rowShift!=null?{rowShift:p.rowShift}:{}};Object.keys(O).length&&(h.captionStyle=yi({...h.captionStyle,...O})),d.push(`${T} captions: ${V}`);break}case"editCaptions":{d.push(...R4(s,p));break}case"rippleTrim":{const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=Si([h],[{...p,op:"trim"}],o,r);if(w.errors.length)throw Error(w.errors.join("; "));s=Of(s,h.id,w.clips[0],r),d.push(`ripple trim: ${V}`);break}case"speedRampTransition":{const h=(et,st)=>et&&st&&et.id!==st.id&&et.track===st.track&&et.kind!=="audio"&&st.kind!=="audio"&&Math.abs(st.start-(et.start+et.duration))<.016666666666666666;let w=p.clipId!=null?y(p.clipId):null,T=w?s.find(et=>h(et,w)):null;if(w&&!T){const et=s.find(st=>h(w,st));et&&(T=w,w=et)}if(!w&&Number.isFinite(p.at)){const st=s.flatMap(Y=>s.filter(ct=>h(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-p.at)-Math.abs(ct[1].start-p.at)||Y[0].track-ct[0].track)[0];st&&Math.abs(st[1].start-p.at)<=.25&&([T,w]=st)}if(!T||!w)throw Error(p.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(p.remove===!0||p.preset==="none"||p.booleanValue===!1){if(!T.transition?.ramp)throw Error("No speed ramp transition on that cut");s=Xd(s,T.id),d.push(`speed ramp off: ${T.label||T.id} → ${w.label||w.id}`);break}const C=p.rampFx&&typeof p.rampFx=="object"?p.rampFx:{},O=et=>p[et]!==void 0&&p[et]!==null&&!(et==="align"&&!["center","end","start"].includes(p[et]))?p[et]:C[et]??void 0,L=Object.fromEntries(["preset","duration","align","peak","zoomCenter","curve",...Z2].map(et=>[et,et==="curve"&&p.curve===null?null:O(et)]).filter(([,et])=>et!==void 0)),B=J2(T,w,L,T.transition?.ramp?T.transition:null);s=s.map(et=>et.id===T.id?{...et,transition:B,join:void 0,visualFadeOut:void 0,fadeOutColor:void 0}:et.id===w.id?{...et,visualFadeIn:void 0,fadeInColor:void 0}:et),Q2(s.find(et=>et.id===T.id),s);const H=tk(s).plans.get(T.id),q=[["A",H?.peakA],["B",H?.peakB]].filter(([,et])=>et!=null&&et<B.ramp.peak-.01);d.push(`speed ramp ${B.name} ${B.duration}s peak ${B.ramp.peak}×${B.align?` align ${B.align}`:""}: ${T.label||T.id} → ${w.label||w.id}${q.length?` (not enough spare footage: peak ${q.map(([et,st])=>`${et} ${st}×`).join(", ")})`:""}`);break}case"speedRamp":{const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=Array.isArray(p.keys)&&p.keys.length?p.keys:null;if(!w&&p.preset==null)throw Error("speedRamp needs a preset or keys");const T=!w&&at(p.at)!==null?at(p.at)-h.start:void 0;if(T!==void 0&&!(T>0&&T<h.duration))throw Error("speedRamp at must be a timeline time inside the clip");const C=at(p.peak)??void 0,L=(p.fit===!0||p.booleanValue===!0)&&!w&&p.preset!=null&&p.preset!=="normal"?Tf(h,p.preset,h.duration,{peak:C}):f5(h,{preset:p.preset??void 0,keys:w,hitAt:T,peak:C});s=s.map(B=>B.id===h.id?L:B),d.push(`speed ramp ${w?"keys":p.preset}${T!==void 0?" (hit placed)":""}: ${V}`);break}case"setTimeRemap":{const h=y(p.clipId);if(!h)throw Error("Clip not found");let w;if(p.booleanValue===!1)w=ls(h,{off:!0});else{const T=Array.isArray(p.keys)&&p.keys.length?p.keys:void 0,C=at(p.duration);w=ls(h,{preset:p.preset??void 0,keys:T,blend:p.blend??void 0,duration:C??void 0});const O=at(p.freezeAt);if(O!==null){const L=Nd(w,O,at(p.hold)??1);w=ls(w,{keys:L.keys,duration:L.duration})}}s=s.map(T=>T.id===h.id?w:T),d.push(`time remap ${p.booleanValue===!1?"off":p.preset??(p.keys?"keys":p.freezeAt!=null?"freeze":p.blend?`blend ${p.blend}`:"on")}: ${V}`);break}case"setClipProperty":case"setSpeed":case"setCrop":case"setKeyframes":{const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=B4(h,p);s=s.map(T=>T.id===h.id?w:T),d.push(`${p.op}: ${V}`);break}case"colorGrade":{const h=Array.isArray(p.clipIds)?p.clipIds:p.clipId!=null?[p.clipId]:[];if(!h.length||h.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:at(st.x)??0,y:at(st.y)??0,l:at(st.l)??0}:null,C=p.nodes??p.windows,O=Array.isArray(C)?{mode:"add",custom:C}:C,L={...Object.fromEntries([...ec,"temperature","tint","shadows","highlights","sharpness"].map(st=>[st,at(p[st])])),recipe:typeof p.recipe=="string"?p.recipe:null,wheels:p.wheels&&typeof p.wheels=="object"?Object.fromEntries(["lift","gamma","gain","offset"].map(st=>[st,T(p.wheels[st])])):null,curves:p.curves&&typeof p.curves=="object"?Object.fromEntries(["master","r","g","b"].map(st=>[st,p.curves[st]?w(p.curves[st]):null])):null,mixer:p.mixer&&typeof p.mixer=="object"?p.mixer:null,lut:p.lut&&typeof p.lut=="object"&&!Array.isArray(p.lut)?p.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&&!pg.has(L.recipe))throw Error(`recipe: ${[...pg].join(" | ")}`);const B=[],H=new Set,q=new Set;let et=null;if(p.copyFrom!=null&&(et=y(Mt(p.copyFrom)),!et))throw Error(`copyFrom clip not found: ${String(p.copyFrom).slice(0,60)}`);for(const st of h){const Y=y(Mt(st));if(!Y)throw Error(`Clip not found: ${String(st).slice(0,60)}`);const ct=Hd(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 gt=p.reset||et?Object.fromEntries(Object.entries(Y).filter(([St])=>St!=="grade"&&!ec.includes(St))):Y;if(et&&et.id!==Y.id){if(ct!==Hd(et))throw Error("copyFrom: copy between two footage clips or two adjustment layers");if(gt={...gt,...Object.fromEntries(ec.filter(St=>et[St]!=null).map(St=>[St,et[St]])),...et.grade?{grade:JSON.parse(JSON.stringify(et.grade))}:{}},ct&&gt.grade?.secondaries)throw Error("an adjustment layer takes no power windows")}const Z=[],nt=LS({...gt,hasFace:!!Y.face,hasPerson:!!Y.colorPerson,hasDepth:!!Y.depthMap},L,{notes:Z,queue:Y.kind==="video"&&!ct});for(const St of Z)St.startsWith("skipped:")&&H.add(St.slice(8));const dt=Z.filter(St=>St.startsWith("pending:")).map(St=>St.slice(8)),vt=s.findIndex(St=>St.id===Y.id),At={...gt,...nt};nt.grade||delete At.grade,(L.windows?.presets?.includes("depth-ai")||L.windows?.custom?.some(St=>St?.shape==="depth"))&&!Y.depthMap&&(Y.kind==="video"||Y.kind==="image")&&Object.assign(At,De(At,{kind:"depth-map",op:"colorGrade",params:{upgrade:"depth-ai"}}));let xt=At;for(const St of dt)xt=De(xt,{kind:St==="face"?"color-face":"color-person",op:"colorGrade"}),q.add(St);s[vt]=xt,B.push(Y.label||Y.id)}d.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(", ")}`:""}${q.size?` — pending: the ${[...q].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(p.track))throw Error("Missing track ID");const h=["gain","pan"].includes(p.property)?p.numberValue:p.booleanValue,w={...r,[p.track]:{...r[p.track],[p.property]:h}};q2(w),r=w,d.push(`track ${p.track}: ${p.property}`);break}case"updateText":{const h=y(p.clipId);if(!h?.title)throw Error("Clip is not an editable title");if(typeof p.templateId=="string"&&p.design==null)throw Error(`Unknown text template "${p.templateId.slice(0,64)}"`);const w=p.design!=null?{design:p.design,animation:p.animation??void 0,templateId:p.templateId,styleId:"classic"}:{},T=Wl({...h.title,...w,...Object.fromEntries(["text","fontSize","color","placement","fontFamily","align","accentColor"].filter(B=>p[B]!=null).map(B=>[B,p[B]]))}),C=at(p.posX),O=at(p.posY),L=C!==null||O!==null?{...en(h),...C!==null?{posX:Math.max(-1,Math.min(1,C))}:{},...O!==null?{posY:Math.max(-1,Math.min(1,O))}:{}}:{};L.motionV===2&&L.posX===void 0&&h.posX===void 0&&(L.posX=0),L.motionV===2&&L.posY===void 0&&h.posY===void 0&&(L.posY=0),Object.assign(h,{title:T,url:"",gcsUri:void 0,label:T.text.slice(0,40),...L}),d.push(`text: ${V}${O!==null&&Math.abs(h.posY)>.45?" (posY past ±0.45: the text may leave the frame)":""}`);break}case"addTextAnimator":case"removeTextAnimator":{const h=te(p),w=y(h.clipId);if(!w?.title)throw Error(`${p.op} needs a text layer (clipId)`);const T=[...w.title.animators||[]],C=at(h.index)??at(h.numberValue),O=()=>{if(C===null||!Number.isInteger(C)||C<0||C>=T.length)throw Error(T.length?`index: 0–${T.length-1}`:"the text has no animators");return C};if(p.op==="removeTextAnimator")h.all===!0?T.length=0:T.splice(O(),1);else{const B=typeof h.preset=="string"&&h.preset?tx(h.preset,w.duration):[ex({...typeof h.name=="string"?{name:h.name}:{},properties:h.properties,selectors:h.selectors})];if(C!==null?T.splice(O(),1,...B):T.push(...B),T.length>rf)throw Error(`at most ${rf} animators on a text layer`)}const L=Wl({...w.title,animators:T});Object.assign(w,{title:L,url:"",gcsUri:void 0}),d.push(`text animators (${T.length}): ${V}`);break}case"duplicateClip":{const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=bb(s,[h],p.at,{tracks:r,insert:p.booleanValue===!0});if(!Number.isFinite(p.at)||p.at<0||w.error)throw Error(w.error||"Invalid paste time");s=w.clips,d.push(`duplicate: ${V}`);break}case"move":{const h=y(p.clipId);if(!h)throw Error(`Không thấy clip ${p.clipId}`);const w=at(p.start);w!==null&&(h.start=ft(Math.max(0,Math.min(He-h.duration,w))));const T=at(p.track);if(T!==null){if(!Wd(h.kind,T))throw Error("Track không hợp lệ cho loại clip này");h.track=T}d.push(`move ${V} → ${h.start}s${p.track!==void 0?` (track ${Ri.includes(h.track)?"A"+(Ri.indexOf(h.track)+1):"V"+(Oa(h.track)+1)})`:""}`);break}case"trim":{const h=y(p.clipId);if(!h)throw Error(`Không thấy clip ${p.clipId}`);Object.assign(h,X2(h));const w={...h};if(Bn(h)){const et=at(p.inPoint),st=at(p.duration);if(et!==null){const Y=ft(Math.max(0,Math.min(h.duration-1/Me,et)));Object.assign(h,U2(h,Y)),h.start=ft(h.start+Y),h.duration=ft(h.duration-Y)}st!==null&&(h.duration=ft(Math.max(1/Me,Math.min(He-h.start,st)))),Object.assign(h,Bl(w,et!==null?ft(Math.max(0,Math.min(w.duration-1/Me,et))):0,h.duration)),d.push(`trim ${V} → ${h.duration}s (time remap)`);break}if(Zr(h)&&!h.reverse){const et=h.kind!=="image"?o.find(nt=>nt.id===h.nodeId)?.words:null,st=nt=>{const dt=Lp(et,nt);return Math.abs(dt-nt)<=_i.reach?dt:nt};let Y=at(p.inPoint),ct=0;if(Y!==null&&et?.length&&(Y=st(Y)),Y!==null){const nt=Math.max(0,Math.min(fg(h)-1/Me,Y));ct=Ba(h,nt-(h.inPoint||0)),Object.assign(h,Y2(h,ct)),h.inPoint=nt,Zr(h)||delete h.speedRamp}let gt=at(p.duration);gt!==null&&et?.length&&(gt=Ba(h,st((h.inPoint||0)+Ui(h,gt))-(h.inPoint||0)));const Z=Ba(h,fg(h)-(h.inPoint||0));h.duration=ft(Math.max(1/Me,Math.min(Z,gt??h.duration))),h.start+h.duration>He&&(h.duration=ft(He-h.start)),Object.assign(h,Bl(w,ct,h.duration)),d.push(`trim ${V} → ${h.duration}s (in ${+(h.inPoint||0).toFixed(3)}s)`);break}const T=h.playbackRate||1,C=h.sourceDuration??h.motion?.duration??He,O=h.kind!=="image"&&!h.reverse?o.find(et=>et.id===h.nodeId)?.words:null,L=et=>{const st=Lp(O,et);return Math.abs(st-et)<=_i.reach?st:et};let B=at(p.inPoint);B!==null&&O?.length&&(B=L(B)),B!==null&&(h.inPoint=ft(Math.max(0,Math.min(C-1/Me,B))));let H=at(p.duration);H!==null&&O?.length&&(H=(L((h.inPoint||0)+H*T)-(h.inPoint||0))/T),H!==null?h.duration=ft(Math.max(1/Me,Math.min((C-(h.inPoint||0))/T,H))):h.duration=ft(Math.max(1/Me,Math.min((C-(h.inPoint||0))/T,h.duration))),h.start+h.duration>He&&(h.duration=ft(He-h.start));const q=w.reverse?w.duration-h.duration-((h.inPoint||0)-(w.inPoint||0))/T:((h.inPoint||0)-(w.inPoint||0))/T;Object.assign(h,Bl(w,q,h.duration)),d.push(`trim ${V} → ${h.duration}s (in ${h.inPoint||0}s)`);break}case"split":{const h=y(p.clipId);if(!h)throw Error(`Không thấy clip ${p.clipId}`);if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);let w=at(p.at);if(w===null)throw Error("Thiếu thời điểm cắt");const T=h.kind!=="image"&&!h.reverse?o.find(O=>O.id===h.nodeId)?.words:null;if(T?.length){const O=(h.inPoint||0)+Ui(h,w-h.start),L=Lp(T,O),B=h.start+Ba(h,L-(h.inPoint||0));Math.abs(L-O)<=_i.reach&&B>h.start+1/Me&&B<h.start+h.duration-1/Me&&(w=B)}const C=Fe(h,w,Dt());if(C.length===1)throw Error("Điểm cắt phải nằm trong clip");s=s.flatMap(O=>O.id===h.id?C:[O]),d.push(`split ${V} tại ${ft(w)}s`);break}case"delete":{if(!y(p.clipId))throw Error(`Không thấy clip ${p.clipId}`);s=s.filter(h=>h.id!==p.clipId),d.push(`delete ${V}`);break}case"setVolume":{const h=y(p.clipId);if(!h)throw Error(`Không thấy clip ${p.clipId}`);const w=at(p.volume);if(w===null)throw Error("Thiếu volume");h.volume=Math.max(0,Math.min(1,w)),d.push(`volume ${V} → ${Math.round(h.volume*100)}%`);break}case"addClip":{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const h=o.find(B=>B.id===p.materialId);if(!h||!h.url)throw Error(`Không thấy material ${p.materialId}`);if(h.kind==="lottie"){const B=V2(h.lottie),H=at(p.start)??0,q=ft(Math.max(1/Me,at(p.duration)??Math.min(120,W2(B))));if(H<0||H+q>He)throw Error("Vượt giới hạn 20 phút");const{track:et}=qt(s,r,ft(H),ft(H)+q,at(p.track)),st=Dt();X.push(st),s.push({id:st,nodeId:h.id,track:et,start:ft(H),duration:q,inPoint:0,volume:0,url:h.url,...h.gcsUri?{gcsUri:h.gcsUri}:{},kind:"image",label:h.label||"Lottie",lottie:{w:B.w,h:B.h,fr:B.fr,ip:B.ip,op:B.op,loop:!0},motionKeys:[]}),d.push(`add Lottie ${h.label||""} → ${ft(H)}s`);break}const w=at(p.track)??(h.kind==="audio"?H2:0);if(!Wd(h.kind,w))throw Error("Track không hợp lệ cho loại material này");const T=h.kind==="image"?null:at(h.duration);let C=at(p.duration)??(h.kind==="image"?HA:T);if(C===null)throw Error("Material chưa có thời lượng — hãy nêu duration cụ thể");T!==null&&(C=Math.min(C,T)),C=ft(Math.max(1/Me,C));const O=at(p.start)??s.filter(B=>B.track===w).reduce((B,H)=>Math.max(B,H.start+H.duration),0);if(O<0||O+C>He)throw Error("Vượt giới hạn 20 phút");if(r[w]?.locked)throw Error("Track đã khóa");const L=Dt();X.push(L),s.push({id:L,nodeId:h.id,track:w,start:ft(O),duration:C,inPoint:0,volume:1,url:h.url,...h.gcsUri?{gcsUri:h.gcsUri}:{},kind:h.kind,label:h.label||h.kind,...T!==null?{sourceDuration:T}:{}}),d.push(`add ${h.label||h.kind} → ${ft(O)}s`);break}case"addVfxPreset":{if(p._error)throw Error(p._error);const h=p._footage;if(!h)throw Error("addVfxPreset needs presetId (search_vfx_presets)");if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const w=ft(Math.max(0,at(p.start)??0)),T=ft(Number(h.duration));if(w+T>He)throw Error("Vượt giới hạn 20 phút");const C=Array.isArray(p.point)&&p.point.length===2&&p.point.every(B=>Number.isFinite(B))?p.point.map(B=>Math.max(0,Math.min(1,B))):null,{track:O}=qt(s,r,w,w+T,at(p.track)),L=Dt();X.push(L),s.push({...Rf({id:L,track:O,start:w,duration:T,footage:h,frame:{W:l.W||1280,H:l.H||720},at:C,scale:at(p.scale)??1}),vfxPreset:{...p._preset}}),d.push(`addVfxPreset: ${String(h.name).slice(0,40)}${p._preset?.rendered?"":" (preview — render it with Cycles: clipoox render --vfx)"} → ${w}s`);break}case"addVfxFootage":{const h=p.footage;if(!h||typeof h!="object"||typeof h.url!="string"||!(Number(h.duration)>0))throw Error("addVfxFootage needs a footage clip from the library (footageId — search_vfx_footage)");if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const w=ft(Math.max(0,at(p.start)??0)),T=ft(Math.max(1/Me,Math.min(at(p.duration)??Number(h.duration),Number(h.duration))));if(w+T>He)throw Error("Vượt giới hạn 20 phút");const C=Array.isArray(p.point)&&p.point.length===2&&p.point.every(B=>Number.isFinite(B))?p.point.map(B=>Math.max(0,Math.min(1,B))):null,{track:O}=qt(s,r,w,w+T,at(p.track)),L=Dt();X.push(L),s.push(Rf({id:L,track:O,start:w,duration:T,footage:h,frame:{W:l.W||1280,H:l.H||720},at:C,scale:at(p.scale)??1,sound:p.booleanValue===!0})),d.push(`addVfxFootage: ${String(h.name||"VFX").slice(0,40)} → ${w}s`);break}case"vfxFootageFollow":{const h=y(p.clipId);if(!h||!h.vfxFootage)throw Error("vfxFootageFollow needs clipId = a Footage VFX layer (addVfxFootage)");if(p.booleanValue===!1){const O=Math.max(0,Math.min(h.duration,at(p.time)??0));for(const[L,B]of Object.entries(WM(h,O)))B===void 0?delete h[L]:h[L]=B;d.push(`vfxFootageFollow ${V}: stopped`);break}const w=p.sourceClipId?y(p.sourceClipId):s.filter(O=>O.kind==="video"&&!O.vfxFootage&&!O.vfx&&O.id!==h.id&&O.start<h.start+h.duration&&O.start+O.duration>h.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 p.point=="string"?p.point:typeof p.handPoint=="string"?p.handPoint:"palm",C=VM(h,w,{source:p.source,hand:p.hand==="left"?"left":"right",point:T,...p.object!=null?{object:p.object}:{},scale:p.scale===!0||p.followScale===!0,offset:Array.isArray(p.offset)&&p.offset.length>=2?p.offset:null,W:n.W||1280,H:n.H||720});for(const[O,L]of Object.entries(C.patch))L===void 0?delete h[O]:h[O]=L;d.push(`vfxFootageFollow ${V}: follows the ${p.source}${p.source==="hand"?` (${p.hand==="left"?"left":"right"} ${T})`:""} of ${w.label||w.id} — ${C.keys} keys ${C.from}–${C.to}s`);break}case"addVfxLayer":{let h=y(p.clipId);if(!h||h.kind!=="video"||h.vfx)throw Error("VFX needs the filmed video clip");if(h.person){const H=h,q=s.find(et=>et.id!==H.id&&et.kind==="video"&&!et.person&&!et.vfx&&et.url===H.url&&et.start===H.start&&et.duration===H.duration);q&&(h=q)}if(!Vd.includes(p.layer))throw Error(`VFX layer must be ${Vd.join(" / ")}`);const w=o.find(H=>H.id===p.materialId);if(!w||!w.url||w.kind!=="video")throw Error(`Không thấy video ${p.materialId}`);const T=at(w.duration),C=ft(Math.max(1/Me,Math.min(h.duration,T??h.duration))),O=B2(s,h.id,p.layer);if(O){_2(O,w,{duration:C,blend:p.blend}),X.push(O.id),d.push(`addVfxLayer: ${p.layer} pass of ${V} replaced`);break}if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const L=G2(s,r,h,p.layer,h.start,h.start+C),B=Dt();X.push(B),s.push(K2({id:B,material:w,src:h,layer:p.layer,track:L,start:h.start,duration:C,blend:p.blend})),d.push(`addVfxLayer: ${p.layer} pass over ${V}`),p.layer==="behind"&&it.splice(D+1,0,{op:"placeBehindPerson",clipId:B,sourceClipId:h.id});break}case"finishVfx":{const h=R2(s,y(p.clipId));if(!h||h.kind!=="video"||h.vfx)throw Error("VFX needs the filmed video clip");const w=D2(s,h,{strength:at(p.numberValue)??1,off:p.booleanValue===!1,newId:Dt,tracks:r,maxClips:Gt});s=w.clips,X.push(...w.added),d.push(`finishVfx ${V}: ${w.notes.join(", ")}`);break}case"set3DLayer":case"setLayerOrder":case"setPropertyKeys":case"setEase":case"setAnimation":case"setReveal":case"setShapeStyle":{const h=s.findIndex(C=>C.id===p.clipId);if(h<0)throw Error("Clip not found");const w=s[h],T=[];s[h]=p.op==="set3DLayer"?z2(w,p.booleanValue!==!1,p.numberValue):p.op==="setLayerOrder"?P2(w,p.numberValue):p.op==="setPropertyKeys"?Qn(w,p.property,Array.isArray(p.propertyKeys)?L2(w,p.propertyKeys,T):p.propertyKeys):p.op==="setEase"?N2(w,p.property,p.ease,p.times):p.op==="setReveal"?_d(w,p.preset,{start:at(p.at),duration:at(p.duration),ease:p.ease}):p.op==="setShapeStyle"?F2(w,{color:p.color,fill:p.fill,strokeWidth:at(p.numberValue)}):fc(w,p.property,p.preset,{duration:p.duration??(p.property==="exit"?c.out:c.in),amount:p.numberValue,fade:p.booleanValue,ease:p.ease??(n.motion?c.ease:void 0)}),d.push(`${p.op}${p.property?` ${p.property}`:""}: ${V}${T.length?` (${T.join("; ")})`:""}`);break}case"addPins":{const h=XA(o,s,p.materialId);if(!h)throw Error("Pins need the A-roll material");const w=Array.isArray(h.words)?h.words.length:As(h)||1/0,T=(Array.isArray(p.pins)?p.pins:[]).slice(0,60).map((L,B)=>({id:`ai${Date.now().toString(36)}${B}`,mediaId:h.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 C=F??n?.pins??[],O=C.filter(L=>!T.some(B=>B.mediaId===L.mediaId&&B.from<=L.to&&B.to>=L.from));F=gv([...O,...T]),d.push(`pins: +${T.length}`);break}case"setTrackMatte":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error("Clip not found");if(!p.sourceClipId){delete h.matte,d.push(`setTrackMatte off: ${V}`);break}const w=y(p.sourceClipId);if(!w)throw Error("Matte source not found");const T=Number.isFinite(p.numberValue)?ix(p.numberValue):h.matte?.feather,C=sx.includes(p.matteMode)?p.matteMode:"alpha";h.matte={source:w.id,mode:C,...T?{feather:T}:{},...C==="depth"?{depth:h.matte?.depth??.5}:{}},af(s),d.push(`setTrackMatte: ${V}`);break}case"modelMove":{const h=s.findIndex(T=>T.id===p.clipId);if(h<0)throw Error("Clip not found");const w=s[h];if(!["model","image","video"].includes(w.kind))throw Error("3D moves need a 3D model, image or video");if(!rm.includes(p.preset))throw Error(`Unknown 3D move (${rm.join(", ")})`);s[h]=sv(w.kind==="model"||w.is3D?w:{...w,is3D:!0},p.preset,{at:at(p.at)??0,duration:at(p.duration),amount:at(p.numberValue)??1}),d.push(`modelMove ${p.preset}: ${V}`);break}case"setModelAnimation":{const h=y(p.clipId);if(!h||h.kind!=="model")throw Error("GLB animations need a 3D model clip");const w=typeof p.text=="string"?p.text.trim():"";if(!w||w==="none"){delete h.modelAnim,d.push(`model animation off: ${V}`);break}const T={clip:w,...at(p.numberValue)!==null?{speed:at(p.numberValue)}:{},...typeof p.booleanValue=="boolean"?{loop:p.booleanValue}:{},...at(p.at)!==null?{offset:Math.max(0,at(p.at))}:{}};O2(T),h.modelAnim=T,d.push(`model animation ${w}: ${V}`);break}case"modelBuild":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="model")throw Error("modelBuild needs a 3D model clip (a GLB layer)");if(p.booleanValue===!1||p.style==="none"){delete h.modelBuild,d.push(`model build off: ${V}`);break}const w=Math.max(0,Math.min(h.duration,(at(p.at)??h.start)-h.start));h.modelBuild=T2({style:p.style,order:p.order,at:w,duration:at(p.duration)??void 0,stagger:at(p.stagger)??void 0,dust:p.dust,dustColor:p.dustColor??p.color,seed:Number.isInteger(p.seed)?p.seed:void 0}),d.push(`model build ${h.modelBuild.style} (${h.modelBuild.order}) at ${(h.start+w).toFixed(2)} s for ${h.modelBuild.duration} s: ${V}`);break}case"modelLook":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="model")throw Error("modelLook needs a 3D model clip (a GLB layer)");const w=j2(h.modelLook,p);if(!w){delete h.modelLook,d.push(`model look off: ${V}`);break}h.modelLook=w,d.push(`model look ${w.preset??"custom"}${w.shadow!==void 0?` shadow ${w.shadow}`:""}: ${V}`);break}case"modelLaunch":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="model")throw Error("modelLaunch needs a 3D model clip (a GLB layer)");const w=A2(h,p);if(!w){delete h.modelLaunch,d.push(`model launch off: ${V}`);break}h.modelLaunch=w,d.push(`model launch ${w.land} at ${(h.start+w.at).toFixed(2)} s, lands at ${(h.start+C2(w)).toFixed(2)} s on [${w.to.map(T=>T.toFixed(2)).join(", ")}] (height ${w.height}): ${V}`);break}case"modelPlace":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="model")throw Error("modelPlace needs a 3D model clip (a GLB layer)");const w={x:at(p.x)??void 0,y:at(p.y)??void 0,lift:at(p.lift)??void 0,scale:at(p.scale)??void 0,yaw:at(p.yaw)??void 0,tilt:at(p.tilt)??void 0,roll:at(p.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(h.duration,(at(p.at)??h.start)-h.start)),C=pv(h,w,T,p.key===!0);Object.assign(h,C),d.push(`model placed${p.key===!0||C.motionKeys?` (key at ${(h.start+T).toFixed(2)} s)`:""}: ${V}`);break}case"trackCamera3D":{p=te(p);const h=y(p.clipId),w=Yk(p,h);Object.assign(h,De(h,{kind:"camera-track",op:"trackCamera3D",params:w})),d.push(`trackCamera3D ${V}: the camera is solved in the open editor${w.lens?` (lens ${w.lens} mm)`:""}`);break}case"placeOnTrack":{p=te(p);const h=y(p.clipId),w=Uk(p,h,y(p.sourceClipId));Object.assign(h,De(h,{kind:"camera-place",op:"placeOnTrack",params:w})),h.kind==="model"&&!h.modelLook&&(h.modelLook={preset:"overcast"}),d.push(`placeOnTrack ${V}: placed on the 3D camera track of ${y(p.sourceClipId).label||p.sourceClipId} in the open editor${h.kind==="model"?" (modelLook overcast: shadow on the ground)":""}`);break}case"trackObject3D":{p=te(p);const h=y(p.clipId),w=NM(p,h);Object.assign(h,De(h,{kind:"object-track",op:"trackObject3D",params:w})),d.push(`trackObject3D ${V}: the object is tracked in 3D in the open editor`);break}case"placeOnObject":{p=te(p);const h=y(p.clipId),w=FM(p,h,y(p.sourceClipId));Object.assign(h,De(h,{kind:"object-place",op:"placeOnObject",params:w})),d.push(`placeOnObject ${V}: glued to the tracked object of ${y(p.sourceClipId).label||p.sourceClipId} in the open editor`);break}case"segmentPerson":{const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("segmentPerson needs a video clip");if(p.quality!==void 0&&p.quality!=="free"&&p.quality!=="hq")throw Error("segmentPerson quality: free | hq");if(p.quality==="hq"){if(typeof p.job!="string"||!/^[A-Za-z0-9-]{8,64}$/.test(p.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(h.person?.hq&&!h.personPending){d.push(`segmentPerson: ${V} already has an HQ person matte`);break}A(h,null),h.personPending={behind:h.personPending.behind,job:p.job},d.push(`segmentPerson: ${V} (HQ person matte, made on the server)`);break}if(h.person&&h.person.src!=="object"){d.push(`segmentPerson: ${V} already has an AI person matte`);break}if(n.noPendingMatte)throw Error(`"${V}" has no AI person matte yet — open Roto → Tách người bằng AI on it`);A(h,null),d.push(`segmentPerson: ${V} (AI person matte computed in the editor)`);break}case"samCutout":{const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("samCutout needs a video clip");if(typeof p.job!="string"||!/^[A-Za-z0-9-]{8,64}$/.test(p.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=I2(p.prompts);if(h.samPending&&h.samPending.job!==p.job)throw Error(`"${V}" is already being cut out by AI Pro — wait for it (get_pending_jobs)`);h.samPending={job:p.job,prompts:w.map(T=>({id:T.id,name:Gd(T.name)}))},d.push(`samCutout: ${V} (${w.length} AI Pro cut-out${w.length>1?"s":""}, made on the server)`);break}case"placeBehindPerson":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error("Clip not found");let w=y(p.sourceClipId);if(!w||w.kind!=="video")throw Error("Person video not found");if(w.id===h.id)throw Error("A layer cannot go behind its own person");if(!w.person){const Z=w,nt=s.find(dt=>dt.id!==Z.id&&dt.kind==="video"&&dt.person&&dt.person.src!=="object"&&dt.url===Z.url);nt&&(w={...Z,person:nt.person})}if(Xn(h,w)<0){d.push(`placeBehindPerson: ${V} already behind`);break}if(!w.person){if(n.noPendingMatte||!t.some(Z=>Z.id===w.id))throw Error(`"${w.label||w.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);A(w,h.id),X.push(`${w.id}-person-pending`),d.push(`placeBehindPerson: ${V} (waits for the AI person matte of ${w.label||w.id})`);break}const C=nl(h,w,{index:Oa,at:fn,isFree:Z=>!r[Z]?.locked&&!s.some(nt=>nt.track===Z&&nt.start<w.start+w.duration&&nt.start+nt.duration>w.start)});if(C===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=Bd(s,w,{id:O,track:C,label:`${w.label||"Video"} · ${w.person.src==="object"?"vật thể":"người"}`,target:h}),H=!w.motionKeys?.length&&!w.speedRamp&&!w.timeRemap&&!w.reverse&&!(w.playbackRate&&w.playbackRate!==1);let q=Math.max(w.start,h.start),et=Math.min(w.start+w.duration,h.start+h.duration);const st=B.clips.find(Z=>Z.id===O),Y=w.start+w.duration,ct=q,gt=et;for(const Z of B.clips)Z.id!==O&&Z.id!==w.id&&Z.kind!=="audio"&&!Z.person&&Z.start<gt&&Z.start+Z.duration>ct&&Xn(Z,st)<0&&Xn(Z,w)>0&&(q=Math.min(q,Math.max(w.start,Z.start)),et=Math.max(et,Math.min(Y,Z.start+Z.duration)));if(H&&et-q>1/30&&(q>w.start+1e-6||et<w.start+w.duration-1e-6)){const Z=B.clips.find(nt=>nt.id===O);Z.inPoint=+((w.inPoint||0)+(q-w.start)).toFixed(4),Z.start=+q.toFixed(4),Z.duration=+(et-q).toFixed(4)}al(B.clips),s=B.clips,X.push(O),d.push(`placeBehindPerson: ${V}`);break}case"placeBehindObject":case"cutOutObject":{const h=p.op==="placeBehindObject",w=h?y(p.clipId):null,T=p.op;if(h&&(!w||w.kind==="audio"))throw Error("Clip not found");let C=y(h?p.sourceClipId:p.clipId);if(!C||C.kind!=="video")throw Error("Object video not found");if(w&&C.id===w.id)throw Error("A layer cannot go behind its own video");const O=WA(p.points),L=Gd(p.objectName??p.name);let B=typeof p.objectId=="string"?p.objectId.trim().slice(0,120):"";if(h&&C.person?.src==="object"&&!C.person.obj&&!L&&!B){if(Xn(w,C)<0){d.push(`placeBehindObject: ${V} already behind`);break}it.splice(D+1,0,{op:"placeBehindPerson",clipId:w.id,sourceClipId:C.id}),d.push(`placeBehindObject: ${V}`);break}Mp(C)&&!B&&!L&&(B=vp(C).id);const H=O?hg(C,at(p.at)??(w??C).start):void 0,q=M2(s,C,{id:B||void 0,name:L||void 0,...O&&!L&&!B?{pts:O,at:H}:{}});if(B&&!q)throw Error(`No object "${B}" on ${C.label||C.id}`);let et;if(q?.layer){const Y=q.layer,ct=vp(Y);if(h){if(Xn(w,Y)<0){d.push(`placeBehindObject: ${V} already behind "${ct.name}"`);break}P(Y,w,C),d.push(`placeBehindObject: ${V} behind "${ct.name}"`);break}if(!O||Kd(O,v2(Y).obj?.pts)){X.push(Y.id),d.push(`cutOutObject: "${ct.name}" is already its own layer`);break}et={...ct,pts:O,at:H,layer:Y.id}}else if(q?.pending)et=q.pending,C=q.clip,!h&&O&&!Kd(O,et.pts)&&(et={...et,pts:O,at:H});else{if(!O){if(!h)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:C.id,name:L,at:hg(C,at(p.at)??w.start)}),d.push(`placeBehindObject: ${V} (finds "${L}" after Accept)`);break}if(Mp(C)){const Y=s.find(ct=>ct.id!==C.id&&ct.kind==="video"&&ct.url===C.url&&!ct.person&&!ct.mask);Y&&(C=Y)}et={id:S2(s,C),name:L||$2(E2(s,C)+1),pts:O,at:H}}const st=j(C,et,w);if(st){et.layer||X.push(st.id),h&&Xn(w,st)>=0&&P(st,w,C),d.push(h?`placeBehindObject: ${V} behind "${et.name}"`:et.layer?`cutOutObject: "${et.name}" re-picked`:`cutOutObject: "${et.name}" of ${C.label||C.id}`);break}if(n.noPendingMatte||!t.some(Y=>Y.id===C.id))throw Error(`"${C.label||C.id}" has no AI matte for the object "${et.name}" yet — open Roto → Tách vật thể bằng AI on it`);z(C,et,w?.id??null),X.push(`${C.id}-${et.id}-pending`),d.push(h?`placeBehindObject: ${V} (waits for the AI matte of "${et.name}" in ${C.label||C.id})`:`${T}: "${et.name}" of ${C.label||C.id} (AI object matte computed in the editor)`);break}case"placeBehindDepth":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error("Clip not found");let w=y(p.sourceClipId);if(!w||w.kind==="audio")throw Error("Depth map or footage not found");if(p.materialId){const O=o.find(q=>q.id===p.materialId);if(!O||!O.url||!["video","image"].includes(O.kind))throw Error(`Không thấy bản đồ độ sâu ${p.materialId}`);const L=w,B=h.matte?.source&&y(h.matte.source),H=B&&B.nodeId===O.id&&B.start===L.start?B:null;if(H)w=H;else{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const q=qt(s,r,L.start,L.start+L.duration,null).track,et=Dt();X.push(et);const st=["inPoint","playbackRate","speedRamp","posX","posY","scale","scaleX","scaleY","rotation","flipX","flipY","crop","motionKeys","reverse","fit"];w={id:et,nodeId:O.id,track:q,start:L.start,duration:L.duration,url:O.url,...O.gcsUri?{gcsUri:O.gcsUri}:{},kind:O.kind,label:`${L.label||"Video"} · độ sâu`,volume:0,...Object.fromEntries(st.filter(Y=>L[Y]!==void 0).map(Y=>[Y,structuredClone(L[Y])])),...at(O.duration)!=null?{sourceDuration:at(O.duration)}:{}},s.push(w)}}if(w.id===h.id)throw Error("A layer cannot be its own depth map");const T=Math.max(0,Math.min(1,at(p.numberValue)??h.matte?.depth??.5)),C=h.matte?.source===w.id?h.matte.feather:void 0;h.matte={source:w.id,mode:"depth",depth:+T.toFixed(3),...C?{feather:C}:{}},af(s),d.push(`placeBehindDepth: ${V} at depth ${Math.round(T*100)}%`);break}case"collageStyle":{const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("Collage style needs a visual clip");if(p.back&&(h.zIndex=-100),p.sticker!=null)if(p.sticker==="none")delete h.sticker;else{const w=U$[p.sticker];if(!w)throw Error("Unknown sticker edge");h.sticker=structuredClone(w)}if(p.torn!=null){const w=p.torn==="all"?Dc:[p.torn];if(!w.every(L=>Dc.includes(L)))throw Error("Unknown torn side");const T=o.find(L=>L.id===h.nodeId),C=Number.isInteger(T?.width)&&T.width>1?T.width:1600,O=Number.isInteger(T?.height)&&T.height>1?T.height:1e3;h.mask=pE(h.mask,{mw:C,mh:O,crop:h.crop,sides:w,seed:Number.isInteger(p.seed)?p.seed:1})}if(p.watercolor){const w=_d(h,"watercolor",{start:0,duration:Math.min(1.2,h.duration/2)});Object.assign(h,w)}if(p.cutout!=null){if(!["person","object"].includes(p.cutout)||h.kind!=="image"||!h.url)throw Error("Background removal needs a photo and person / object");$.push({clipId:h.id,mode:p.cutout})}d.push(`collage ${V}`);break}case"rotoMask":{const h=y(p.clipId);if(!h)throw Error("rotoMask needs clipId (a video / image clip)");const{mask:w,follow:T}=DA(h,p,{size:RA(h,o.find(B=>B.id===h.nodeId))});w?h.mask=w:delete h.mask;const C=new Set(yg(w)),L=[...((h.clientJobs??[]).find(B=>B?.kind==="mask-track"&&(B.state==="pending"||B.state==="running"))?.params?.masks??[]).filter(B=>C.has(B.id)&&!T.some(H=>H.id===B.id)),...T];L.length?Object.assign(h,De(h,{kind:"mask-track",op:"rotoMask",params:{masks:L}})):h.clientJobs?.some(B=>B?.kind==="mask-track"&&B.state==="pending")&&(h.clientJobs=h.clientJobs.filter(B=>!(B?.kind==="mask-track"&&B.state==="pending"))),d.push(`rotoMask ${V}: ${yg(w).length} mask(s)${T.length?`, ${T.length} to track in the editor`:""}`);break}case"runAnalyzer":{const h=y(p.clipId);if(!h)throw Error("Clip not found");if(h.kind!=="video")throw Error("runAnalyzer needs a video clip");const w=p.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=p.values&&typeof p.values=="object"&&!Array.isArray(p.values)?p.values:{};if(JSON.stringify(T).length>4096)throw Error("runAnalyzer: values too large");Object.assign(h,De(h,{kind:"plugin-analyze",op:"runAnalyzer",params:{plugin:{id:w.id,...w.item?{item:w.item}:{},v:w.v},values:T}})),d.push(`runAnalyzer ${w.id}${w.item?`/${w.item}`:""}: ${V} (in the open editor)`);break}case"bakeMap":{const h=y(p.clipId);if(!h)throw Error("Clip not found");if(!h.geo)throw Error("bakeMap needs an animated map layer (addMap)");Object.assign(h,De(h,{kind:"map-bake",op:"bakeMap"})),d.push(`bakeMap: ${V} → video (in the open editor)`);break}case"portalDive":{const h=y(p.clipId);if(!h)throw Error("Clip not found");const w=h.pendingPin&&!h.pin;if(!w&&!h.pin)throw Error("portalDive needs a pinned layer: pinToSurface (mode plane) or a corner pin first");if(h.pin?.scene||w&&h.pendingPin.mode!=="plane")throw Error("portalDive works on a flat pin (pinToSurface mode plane, corner / face / map pin)");if((w?h.pendingPin:h.pin).dive){const H=u5(s,h.id);s.splice(0,s.length,...H)}const C=y(p.clipId),O=w?C.pendingPin:C.pin;if(p.booleanValue===!1){d.push(`portalDive off: ${V}`);break}const L=x2(C,y(O.clip??O.source),{at:at(p.at)??null,dur:at(p.duration)??1.2}),B=p5(L);if(w?C.pendingPin={...C.pendingPin,dive:B}:C.pin={...C.pin,dive:B},!w&&n.W&&n.H){const H=d1(s,C.id,n.W,n.H);s.splice(0,s.length,...H)}d.push(`portalDive: the camera pushes into ${V} from ${L.at.toFixed(2)}s, the screen fills the frame at ${(L.at+L.dur).toFixed(2)}s`);break}case"pinToSurface":{const h=y(p.clipId),w=y(p.sourceClipId),T=ol(h,w,p);delete h.pin,Object.assign(h,T),S.push({clipId:h.id,...T.pendingPin});let C="";if(w.person&&p.booleanValue!==!1&&Xn(h,w)>=0){const L=nl(h,w,{index:Oa,at:fn,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 q=Bd(s,w,{id:B,track:L,label:`${w.label||"Video"} · người`,target:h});al(q.clips),s=q.clips,X.push(B),C=", person in front"}}d.push(`pinToSurface ${V} → ${w.label||w.id} (${T.pendingPin.mode}${C})`);break}case"addFlash":{const h=Array.isArray(p.times)&&p.times.length?p.times.map(at):[at(p.at)];if(!h.length||h.length>um||h.some(L=>L===null||L<0||L>He))throw Error(`addFlash: at (timeline s) or times [≤${um} instants]`);const w=p.flashStyle??p.style??"white";if(!Object.hasOwn(Tn,w))throw Error(`addFlash style: ${Object.keys(Tn).join("|")}`);const T=dm(w,at(p.strength)??at(p.numberValue)??1),C=ft(hm(w)),O=Tn[w][n.locale==="en"?"en":"vi"];for(const L of h){if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const B=ft(L),{track:H}=qt(s,r,B,B+C,at(p.track)),q=Dt();X.push(q),s.push({...xp({id:q,track:H,start:B,duration:C,label:`${n.locale==="en"?"Flash":"Chớp"} · ${O}`}),motionKeys:[],effects:T.map(et=>({...et,keys:et.keys.map(st=>({...st}))}))})}d.push(`flash ${w} ×${h.length} (${h.map(L=>ft(L)).join(", ")}s)`);break}case"setEffect":{const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("Effects need a 2D visual clip");if(!Object.hasOwn(pc,p.property))throw Error("Unknown effect");const w=at(p.numberValue);if(w===null||w<0||w>1)throw Error("Effect amount must be 0..1");let T=null;if(p.property==="glow-pro"){const B=p.glow??(typeof p.prompt=="string"&&p.prompt.trim().startsWith("{")?(()=>{try{return JSON.parse(p.prompt)}catch{throw Error("Glow Pro settings (prompt) must be JSON")}})():void 0),H=(h.effects||[]).find(q=>q.type==="glow-pro")?.params;B!==void 0?T=k2({...H||{},...B}):H&&(T=H)}const C={type:p.property,amount:w,...T?{params:T}:{}},O=(h.effects||[]).filter(B=>B.type!==p.property),L=(h.effects||[]).findIndex(B=>B.type===p.property);if(w>0&&(L>=0?O.splice(L,0,C):O.push(C)),O.length>cn)throw Error(`At most ${cn} effects per clip`);O.length?h.effects=O:delete h.effects,d.push(`effect ${p.property} ${w?Math.round(w*100)+"%":"off"}: ${V}`);break}case"personEcho":case"clonePerson":{p=te(p);let h=y(p.clipId);if(!h||h.kind!=="video")throw Error(`${p.op} needs the filmed video clip of the person`);if(!h.person){const L=h,B=s.find(H=>H.id!==L.id&&H.kind==="video"&&H.person&&H.person.src!=="object"&&H.url===L.url);B&&(h={...L,person:B.person})}if(!h.person){if(n.noPendingMatte||!t.some(H=>H.id===h.id))throw Error(`"${h.label||h.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);const{clipId:L,...B}=p;A(h,null,{...B,clipId:h.id}),d.push(`${p.op} ${h.label||h.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=[],T=()=>{let L=Dt();for(;y(L);)L=Dt();return w.push(L),L},C=p.op==="personEcho"?{layers:HM(h,{copies:$t(p.copies)??$t(p.numberValue),gap:$t(p.gap),fade:$t(p.fade),opacity:$t(p.opacity),spread:$t(p.spread),look:typeof p.look=="string"&&p.look?p.look:null,start:$t(p.start),duration:$t(p.duration)},T),poofs:[]}:UM(h,{count:$t(p.count)??$t(p.numberValue),layout:p.layout,spread:$t(p.spread),depth:$t(p.depth),delay:$t(p.delay),mirror:p.mirror!==!1,feet:Array.isArray(p.feet)?p.feet:void 0,horizon:$t(p.horizon),start:$t(p.start),duration:$t(p.duration),smoke:p.smoke!==!1},T);if(s.length+C.layers.length+C.poofs.length>Gt)throw Error(`Tối đa ${Gt} clip`);for(const L of[...C.layers,...C.poofs]){const{track:B}=qt(s,r,L.start,L.start+L.duration);s.push({...L,track:B}),X.push(L.id)}s.some(L=>L.id!==h.id&&L.kind==="video"&&L.url===h.url&&!L.person&&!L.mask&&L.start===h.start&&L.duration===h.duration&&(L.inPoint||0)===(h.inPoint||0))||(s=s.map(L=>{if(L.id!==h.id)return L;const B={...L};return delete B.person,delete B.mask,B})),d.push(p.op==="personEcho"?`personEcho ${h.label||h.id}: ${C.layers.length-1} copies + the person on top`:`clonePerson ${h.label||h.id}: ${C.layers.length-1} clones${C.poofs.length?` (${C.poofs.length} smoke poofs)`:""} + the person in front`);break}case"addShock":{p=te(p);const h=y(p.clipId);if(!h||h.kind==="audio")throw Error("addShock needs a visual clip");if(p.booleanValue===!1){delete h.shocks,d.push(`addShock ${V}: rings removed`);break}const w=$t(p.at)??h.start,T=Array.isArray(p.point)?p.point:[$t(p.u)??.5,$t(p.v)??.8];if(w<h.start-1e-6||w>h.start+h.duration+1e-6)throw Error("addShock at must be a timeline time inside the clip");if((h.shocks?.length??0)>=Dd.max)throw Error(`A clip holds up to ${Dd.max} shockwaves`);const C=b2({t:w-h.start,u:$t(T[0])??.5,v:$t(T[1])??.8,radius:$t(p.radius),strength:$t(p.strength),duration:$t(p.duration),squash:$t(p.squash),light:$t(p.light)});if(h.shocks=w2([...h.shocks??[],C].sort((O,L)=>O.t-L.t),h.duration),p.cracks===!0){let O=Dt();for(;y(O);)O=Dt();const L=n.W||1280,B=n.H||720,H=h.scale??1,q=.5+(h.posX??0)+(C.u-.5)*H,et=.5+(h.posY??0)+(C.v-.5)*H,st=rv({id:O,at:w,duration:Math.min(Math.max(1.2,C.duration*1.8),h.start+h.duration-w+.5),u:q,v:et,size:C.radius*.65*H,squash:C.squash,seed:Math.round(w*1e3)%9973+1,W:L,H:B}),{track:Y}=qt(s,r,st.start,st.start+st.duration);s.push({...st,track:Y}),X.push(O)}d.push(`addShock ${V}: ring at ${(+w).toFixed(2)} s${p.cracks===!0?" + ground cracks":""}`);break}case"smoothSlowMo":{const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("smoothSlowMo needs a video clip");if(p.booleanValue===!1){delete h.smoothSlow,d.push(`smoothSlowMo ${V}: off`);break}h.smoothSlow=!0,d.push(`smoothSlowMo ${V}: on${W1(h)?"":" (slow it below 1× with setSpeed / speedRamp to see it)"}`);break}case"objectTrail":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("objectTrail needs a video clip");const w=Array.isArray(p.path)&&p.path.length>=2&&p.path.every(q=>Array.isArray(q)&&(q.length===3||q.length===4)&&q.every(Number.isFinite)&&q[1]>=-.2&&q[1]<=1.2&&q[2]>=-.2&&q[2]<=1.2)?[...p.path].sort((q,et)=>q[0]-et[0]):null;if(p.path!==void 0&&p.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(p.point)?p.point:null;if(!T||!T.every(q=>Number.isFinite(q)&&q>=0&&q<=1))throw Error("objectTrail point [u, v] (0..1 of the picture)");const C=$t(p.at)??(w?w[0][0]:h.start),O=Math.min($t(p.duration)??(w?w.at(-1)[0]-C+($t(p.length)??.45):h.start+h.duration-C),h.start+h.duration-C);if(!(O>=.2)||C<h.start-1e-6)throw Error("objectTrail must lie inside the footage");let L=Dt();for(;y(L);)L=Dt();const B=Hk({id:L,at:C,duration:O,color:p.color,width:$t(p.width),length:$t(p.length),source:h.id,point:T,style:p.style==="energy"||p.style==="ribbon"||p.style==="wheel"?p.style:void 0,aspect:$t(p.ringAspect),rot:$t(p.ringRot),wind:Array.isArray(p.wind)?p.wind:void 0,stretch:$t(p.stretch),taper:$t(p.taper),vanish:Array.isArray(p.vanish)?p.vanish:void 0,flow:$t(p.flow),ring:$t(p.ring),spread:$t(p.spread)}),{track:H}=qt(s,r,B.start,B.start+B.duration);if(w){const q=n.W||1280,et=n.H||720,st=(nt,dt,vt,At,xt)=>.5*(2*dt+(vt-nt)*xt+(2*nt-5*dt+4*vt-At)*xt*xt+(3*dt-nt-3*vt+At)*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)*q,st(Y(dt-1)[2],Y(dt)[2],Y(dt+1)[2],Y(dt+2)[2],vt)*et,...w.every(At=>At.length===4)?[(Y(dt)[3]+(Y(dt+1)[3]-Y(dt)[3])*vt)*et]:[]])}const{pendingPin:gt,...Z}=B;if(s.push({...Z,track:H,...Xk({...Z,track:H},ct,q,et),pendingPin:void 0}),X.push(L),p.split===!0&&p.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=Dt();for(;y(dt);)dt=Dt();const vt=qt(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"}}}),X.push(dt)}d.push(`objectTrail on ${h.label||h.id}: drawn along the given path (${w.length} points)`);break}s.push({...B,track:H}),X.push(L),S.push({clipId:L,...B.pendingPin}),d.push(`objectTrail on ${h.label||h.id}: tracked in the editor, then drawn`);break}case"addImpact":{p=te(p);const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("addImpact needs a visual clip");if(p.booleanValue===!1){delete h.impacts,d.push(`addImpact ${V}: hits removed`);break}const w=$t(p.at)??h.start,T=Array.isArray(p.point)?p.point:[$t(p.u)??.5,$t(p.v)??.5];if(w<h.start-1e-6||w>h.start+h.duration+1e-6)throw Error("addImpact at must be a timeline time inside the clip");if((h.impacts?.length??0)>=Kl.max)throw Error(`A clip holds up to ${Kl.max} impact hits`);const C=Fd({t:w-h.start,u:$t(T[0])??.5,v:$t(T[1])??.5,strength:$t(p.strength),duration:$t(p.duration),blur:$t(p.blur),rgb:$t(p.rgb),flash:$t(p.flash)});h.impacts=Rd([...h.impacts??[],C].sort((nt,dt)=>nt.t-dt.t),h.duration);const O=ju(h,"rot")||Math.abs(h.rotation??0)>1e-6,L=n.W||1280,B=n.H||720,H=O?cc(h,C.u,C.v,w-h.start,L,B,L,B):null,q=h.scale??1,et=H?H.px/L:.5+(h.posX??0)+(C.u-.5)*q,st=H?H.py/B:.5+(h.posY??0)+(C.v-.5)*q,Y=[];let ct=()=>{let nt=Dt();for(;y(nt)||Y.some(dt=>dt.id===nt);)nt=Dt();return nt};p.debris!==!1&&Y.push(qM({id:ct(),at:w,u:et,v:st,size:.6+.6*($t(p.strength)??.8),seed:Math.round(w*1e3)%9973+1})),p.pillars===!0&&Y.push(_v({id:ct(),at:w,u:et,v:st,size:.7+.5*($t(p.strength)??.8),color:/^#[0-9a-fA-F]{6}$/.test(p.color??"")?p.color:void 0}));const gt=h.person&&h.person.src!=="object"?h.person:s.find(nt=>nt.id!==h.id&&nt.kind==="video"&&nt.person&&nt.person.src!=="object"&&nt.url===h.url)?.person;let Z=null;if(p.keepPerson!==!1&&gt&&h.kind==="video"){const nt=Math.min(h.start+h.duration,w+C.duration+.05);Z=Gn({...h,person:gt},ct(),{start:ao(w),duration:ao(nt-w),inPoint:ao((h.inPoint||0)+(w-h.start)*(h.playbackRate||1)),label:`${h.label||"Video"} · người nét`}),delete Z.impacts,delete Z.motionKeys,H&&Object.assign(Z,Q1(h,w,nt-w)),Y.push(Z)}if(p.shake!==!1){const nt=Math.max(.15,Math.min(1,.35+.5*($t(p.strength)??.8))),dt=w-h.start,vt=Math.min(h.duration,dt+.35),At=Math.round(w*1e3)+h.id.length;Object.assign(h,ti(h,{amount:nt,freq:14,from:dt,to:vt,seed:At,props:["x","y"]})),Z&&Object.assign(Z,ti(Z,{amount:nt,freq:14,from:0,to:vt-dt,seed:At,props:["x","y"]}))}if(s.length+Y.length>Gt)throw Error(`Tối đa ${Gt} clip`);if(H){const nt=Math.round(Zt(h,"rot",w-h.start)*100)/100;for(const dt of Y)dt.motion&&(dt.rotation=nt)}for(const nt of Y){const{track:dt}=qt(s,r,nt.start,nt.start+nt.duration);s.push({...nt,track:dt}),X.push(nt.id)}d.push(`addImpact ${V}: hit at ${(+w).toFixed(2)} s${p.debris!==!1?" + debris":""}${p.pillars===!0?" + a pillar of light":""}${Z?" + the person sharp on top":""}`);break}case"speedBolt":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("speedBolt needs a video clip");const w=Array.isArray(p.point)?p.point:null;if(w&&!w.every(q=>Number.isFinite(q)&&q>=0&&q<=1))throw Error("speedBolt point [u, v] (0..1 of the picture)");const T=$t(p.at)??h.start,C=Math.min($t(p.duration)??h.start+h.duration-T,h.start+h.duration-T);if(!(C>=.2)||T<h.start-1e-6)throw Error("speedBolt must lie inside the footage");if(!w&&h.personPending&&!(h.person&&h.person.src!=="object")&&!n.noPendingMatte&&t.some(q=>q.id===h.id)&&!s.some(q=>q.id!==h.id&&q.kind==="video"&&q.person&&q.person.src!=="object"&&q.url===h.url)){const{clipId:q,...et}=p;A(h,null,{...et,clipId:h.id}),d.push(`speedBolt ${h.label||h.id}: waits for the AI person matte (made in the editor), then runs`);break}const O=!w&&!(h.person||h.personPending)?s.find(q=>q.id!==h.id&&q.kind==="video"&&q.person&&q.person.src!=="object"&&q.url===h.url)??h:h;let L=Dt();for(;y(L);)L=Dt();const B=Wk({id:L,at:T,duration:C,color:p.color,width:$t(p.width),length:$t(p.length),jag:$t(p.jag),source:O.id,point:w??void 0}),{track:H}=qt(s,r,B.start,B.start+B.duration);s.push({...B,track:H}),X.push(L),S.push({clipId:L,...B.pendingPin}),d.push(`speedBolt on ${h.label||h.id}: tracked in the editor, then drawn`);break}case"addCombatHit":{p=te(p);let h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("addCombatHit needs a visual clip");const w=p.style??"slash";if(!Object.hasOwn(Fu,w))throw Error(`addCombatHit style: ${Wx.join("|")}`);const T=Fu[w],C=$t(p.at)??h.start,O=Array.isArray(p.point)?p.point:[$t(p.u)??.5,$t(p.v)??.5];if(C<h.start-1e-6||C>h.start+h.duration+1e-6)throw Error("addCombatHit at must be a timeline time inside the clip");const L=Math.max(.1,Math.min(1,$t(p.strength)??.85)),B=$t(p.size)??.85+.35*L,H=ju(h,"rot")||Math.abs(h.rotation??0)>1e-6,q=n.W||1280,et=n.H||720,st=H?cc(h,$t(O[0])??.5,$t(O[1])??.5,C-h.start,q,et,q,et):null,Y=h.scale??1,ct=st?st.px/q:.5+(h.posX??0)+(($t(O[0])??.5)-.5)*Y,gt=st?st.py/et:.5+(h.posY??0)+(($t(O[1])??.5)-.5)*Y,Z=[],nt=[];let dt=()=>{let St=Dt();for(;y(St)||Z.some(jt=>jt.id===St);)St=Dt();return St};const vt=Math.round(C*1e3)%9973+1;Z.push(gf({id:dt(),presetId:T.preset,label:T.label,at:C,u:ct,v:gt,color:p.color??T.color,core:p.core??T.core,angle:$t(p.angle),arc:$t(p.arc),flip:p.flip,spread:$t(p.spread),width:$t(p.width),size:B,sparks:p.sparks,seed:vt,duration:$t(p.duration)??T.duration})),T.extraPreset&&Z.push(gf({id:dt(),presetId:T.extraPreset,label:"Tia lửa va chạm",at:C,u:ct,v:gt,color:p.color??T.color,core:p.core??T.core,size:B*.95,seed:vt+11}));let At=0;const xt=p.hitstop===!1||p.hitstop===0?0:$t(p.hitstop)??T.hitstop;if(xt>0&&h.kind==="video"&&!h.freeze&&!h.speedCurve){const St=Math.max(.04,Math.min(.5,xt));try{const jt=h.timeRemap?h:ls(h,{}),Kt=Nd(jt,Math.max(0,C-h.start),St);h=ls(jt,{keys:Kt.keys,duration:Kt.duration}),s=s.map(ee=>ee.id===h.id?h:ee),At=St,nt.push(`hitstop ${St.toFixed(2)}s`)}catch{}}if(p.impactFrame!==!1){const St=typeof p.impactFrame=="string"?p.impactFrame:T.impactFrame;if(!Object.hasOwn(Tn,St))throw Error(`addCombatHit impactFrame: ${Object.keys(Tn).join("|")} | false`);const jt=dm(St,L),Kt=ft(hm(St)),ee=Tn[St][n.locale==="en"?"en":"vi"];Z.push({...xp({id:dt(),track:0,start:ft(C),duration:Kt,label:`Impact · ${ee}`}),motionKeys:[],effects:jt.map(le=>({...le,keys:le.keys.map(xe=>({...xe}))}))}),nt.push(`flash ${St}`)}if(p.impact!==!1&&(h.impacts?.length??0)<Kl.max){const St=Fd({t:C-h.start,u:$t(O[0])??.5,v:$t(O[1])??.5,strength:L,duration:Math.max(.22,Math.min(.75,$t(p.duration)??.38))});h.impacts=Rd([...h.impacts??[],St].sort((jt,Kt)=>jt.t-Kt.t),h.duration),nt.push("impact blur")}if(p.shake!==!1){const St=Math.max(.2,Math.min(1,.35+.55*L)),jt=C-h.start,Kt=Math.min(h.duration,jt+.32);Object.assign(h,ti(h,{amount:St,freq:16,from:jt,to:Kt,seed:vt+h.id.length,props:["x","y"]})),nt.push("shake")}if(s.length+Z.length>Gt)throw Error(`Tối đa ${Gt} clip`);if(st){const St=Math.round(Zt(h,"rot",C-h.start)*100)/100;for(const jt of Z)jt.motion&&(jt.rotation=St)}for(const St of Z){const{track:jt}=qt(s,r,St.start,St.start+St.duration);s.push({...St,track:jt}),X.push(St.id)}if(p.sfx!==!1){let St=0;for(const jt of T.sfx){const Kt=da(jt.id);if(!Kt)continue;const ee=Math.max(0,C+jt.offset);try{const le=Bi(s,r,Kt,ee,{id:dt(),volume:.85});s.push(le),X.push(le.id),St++}catch{}}St&&nt.push(`sfx ×${St}`)}d.push(`addCombatHit (${w}) on ${V} at ${(+C).toFixed(2)}s${nt.length?` [${nt.join(", ")}]`:""}`);break}case"weaponTrail":{p=te(p);const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("weaponTrail needs a visual clip");const w=Array.isArray(p.path)&&p.path.length>=2,T=Array.isArray(p.point)?p.point:null;if(T&&!T.every(et=>Number.isFinite(et)&&et>=0&&et<=1))throw Error("weaponTrail point [u, v] (0..1 of the picture)");const C=$t(p.at)??h.start,O=Math.min($t(p.duration)??(w?.75:h.start+h.duration-C),h.start+h.duration-C);if(!(O>=.15)||C<h.start-1e-6)throw Error("weaponTrail must lie inside the clip");if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);let L=Dt();for(;y(L);)L=Dt();const B=!w&&!T&&!(h.person||h.personPending)?s.find(et=>et.id!==h.id&&et.kind==="video"&&et.person&&et.person.src!=="object"&&et.url===h.url)??h:h,H=Xx({id:L,at:C,duration:O,color:p.color,core:p.core,width:$t(p.width),length:$t(p.length),sparks:p.sparks,source:B.id,point:T??void 0,path:w?p.path:void 0}),{track:q}=qt(s,r,H.start,H.start+H.duration);s.push({...H,track:q}),X.push(L),H.pendingPin&&S.push({clipId:L,...H.pendingPin}),d.push(`weaponTrail on ${h.label||h.id}: ${w?`scripted path (${p.path.length} pts)`:"tracked energy ribbon"}`);break}case"personElectric":{p=te(p);let h=y(p.clipId);if(!h||h.kind!=="video")throw Error("personElectric needs the filmed video of the person");if(!h.person){const et=h,st=s.find(Y=>Y.id!==et.id&&Y.kind==="video"&&Y.person&&Y.person.src!=="object"&&Y.url===et.url);st&&(h={...et,person:st.person})}if(!h.person){if(n.noPendingMatte||!t.some(Y=>Y.id===h.id))throw Error(`"${h.label||h.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);const{clipId:et,...st}=p;A(h,null,{...st,clipId:h.id}),d.push(`personElectric ${h.label||h.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=Math.max(h.start,$t(p.start)??h.start),T=Math.min(h.start+h.duration,$t(p.duration)!=null?w+$t(p.duration):h.start+h.duration);if(!(T-w>.1))throw Error("personElectric must lie inside the person clip");let C=Dt();for(;y(C);)C=Dt();const O=/^#[0-9a-fA-F]{6}$/.test(p.color??"")?p.color:"#ffc23d",L=Math.max(.1,Math.min(1,$t(p.crackle)??.75)),B=Gn(h,C,{start:ao(w),duration:ao(T-w),inPoint:ao((h.inPoint||0)+(w-h.start)*(h.playbackRate||1)),label:`${h.label||"Video"} · điện`,edge:Su({color:O,width:.009,glow:1.6,crackle:L,amount:1})});delete B.impacts;const{track:H}=qt(s,r,B.start,B.start+B.duration);s.push({...B,track:H}),X.push(C),s.some(et=>et.id!==h.id&&et.kind==="video"&&et.url===h.url&&!et.person&&!et.mask&&et.start===h.start&&et.duration===h.duration&&(et.inPoint||0)===(h.inPoint||0))||(s=s.map(et=>{if(et.id!==h.id)return et;const st={...et};return delete st.person,delete st.mask,st})),d.push(`personElectric ${h.label||h.id}: electricity on the person`);break}case"worldFlip":{p=te(p);const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("worldFlip needs a 2D visual clip");const w=$t(p.at)??h.start,T=w-h.start,C=$t(p.duration)??.6;if(T<-1e-6||T>h.duration)throw Error("worldFlip at must be a timeline time inside the clip");Object.assign(h,Rv(h,{from:Math.max(0,T),to:T+C,turn:$t(p.turn)??$t(p.numberValue)??180,back:p.back===!0,W:n.W||1280,H:n.H||720})),d.push(`worldFlip ${V}: turns ${$t(p.turn)??$t(p.numberValue)??180}° at ${(+w).toFixed(2)} s`);break}case"lightBurst":{p=te(p);const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("lightBurst needs a 2D visual clip");const w=(Array.isArray(p.hits)?p.hits:[$t(p.at)??h.start]).filter(Number.isFinite).slice(0,Js.maxHits),T=Kv(h,w);if(!T.length)throw Error("lightBurst hits must be timeline times inside the clip");const C=[...h.effects||[]].filter(O=>O.type!=="light-burst");if(C.length>=cn)throw Error(`At most ${cn} effects per clip`);h.effects=y2([...C,{type:"light-burst",amount:0,keys:T}]),d.push(`lightBurst ${V}: ${w.length} burst(s) of light`);break}case"breathMist":{p=te(p);const h=y(p.clipId),w=$t(p.at)??h?.start??0,T=Array.isArray(p.point)?p.point:[$t(p.u)??.5,$t(p.v)??.35];if(h&&(w<h.start-1e-6||w>h.start+h.duration+1e-6))throw Error("breathMist at must be a timeline time inside the clip");let C=Dt();for(;y(C);)C=Dt();const O=Bv({id:C,at:w,u:$t(T[0])??.5,v:$t(T[1])??.35,angle:$t(p.angle)??200,length:$t(p.length)??1,size:$t(p.size)??1,duration:$t(p.duration)??1.6,color:/^#[0-9a-fA-F]{6}$/.test(p.color??"")?p.color:void 0}),{track:L}=qt(s,r,O.start,O.start+O.duration);s.push({...O,track:L}),X.push(C),d.push(`breathMist at ${(+w).toFixed(2)} s`);break}case"documentary":{if(p._error)throw Error(p._error);const h=p._plan;if(!h||!Array.isArray(h.S)||!Array.isArray(h.K))throw Error("documentary needs stations");const w=Math.max(0,at(p.start)??0),T=Math.ceil(h.total/er.layerSeconds-1e-6),C=[];for(let B=0;B<T;B++){let H=Dt();for(;y(H)||C.includes(H);)H=Dt();C.push(H)}const O=d8({ids:C,at:w,plan:h,label:p.label||void 0}),{track:L}=qt(s,r,w,w+h.total);for(const B of O)s.push({...B,track:L}),X.push(B.id);d.push(`documentary: ${h.S.length} station(s) in one camera move, ${h.total.toFixed(1)} s (${h.style})`);break}case"energyAura":{p=te(p);const h=y(p.clipId);if(!h||h.kind!=="video")throw Error("energyAura needs a video clip (the footage of the person / thing)");const w=Array.isArray(p.path)&&p.path.length>=2&&p.path.every(et=>Array.isArray(et)&&et.length===4&&et.every(Number.isFinite))?[...p.path].sort((et,st)=>et[0]-st[0]):null;if(p.path!==void 0&&p.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(h.start,$t(p.start)??(w?w[0][0]:h.start)),C=Math.min(h.start+h.duration,T+($t(p.duration)??(w?w.at(-1)[0]-T:h.start+h.duration-T)));if(!(C-T>=.2))throw Error("energyAura must lie inside the footage");const O={look:p.look,color:p.color,hot:p.hot,size:$t(p.size),intensity:$t(p.intensity),wind:Array.isArray(p.wind)?p.wind:void 0,speed:$t(p.speed),stretch:$t(p.stretch),taper:$t(p.taper)};let L=typeof p._auraId=="string"&&!y(p._auraId)?p._auraId:Dt();for(;!p._auraId&&y(L);)L=Dt();const B=w?w.map(et=>[+(et[0]-T).toFixed(4),et[1],et[2],et[3]]):[];let H=ev({id:L,at:T,duration:C-T,settings:O,body:B,kind:w?"thing":"person"});w||(H=De(H,{kind:"aura-pose",op:"energyAura",params:{source:h.id,from:+(T-h.start).toFixed(4),duration:+(C-T).toFixed(4),person:Number.isInteger(p.person)?p.person:1}}));const{track:q}=qt(s,r,H.start,H.start+H.duration);s.push({...H,track:q}),X.push(L),d.push(`energyAura ${Uh(O).look} on ${h.label||h.id}${w?" (along the given path)":": the body tracked in the editor"}`);break}case"personAura":{p=te(p);let h=y(p.clipId);if(!h||h.kind!=="video")throw Error("personAura needs the filmed video of the person");if(!h.person){const O=h,L=s.find(B=>B.id!==O.id&&B.kind==="video"&&B.person&&B.person.src!=="object"&&B.url===O.url);L&&(h={...O,person:L.person})}if(!h.person){if(n.noPendingMatte||!t.some(B=>B.id===h.id))throw Error(`"${h.label||h.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);const{clipId:O,...L}=p;A(h,null,{...L,clipId:h.id}),d.push(`personAura ${h.label||h.id}: waits for the AI person matte (made in the editor), then runs`);break}const T=Dv(h,()=>{let O=Dt();for(;y(O)||s.some(L=>L.id===O);)O=Dt();return O},{start:$t(p.start),duration:$t(p.duration),color:/^#[0-9a-fA-F]{6}$/.test(p.color??"")?p.color:void 0,silhouette:p.silhouette===!0,style:p.style==="fresnel"?"fresnel":"rainbow"});if(s.length+T.length>Gt)throw Error(`Tối đa ${Gt} clip`);for(const O of T){const{track:L}=qt(s,r,O.start,O.start+O.duration);s.push({...O,track:L}),X.push(O.id)}s.some(O=>O.id!==h.id&&O.kind==="video"&&O.url===h.url&&!O.person&&!O.mask&&O.start===h.start&&O.duration===h.duration&&(O.inPoint||0)===(h.inPoint||0))||(s=s.map(O=>{if(O.id!==h.id)return O;const L={...O};return delete L.person,delete L.mask,L})),d.push(`personAura ${h.label||h.id}: aura${p.silhouette===!0?" + coloured figure":""}`);break}case"hudWall":{p=te(p);const h=p.sourceClipId!=null?y(p.sourceClipId):null;if(p.sourceClipId!=null&&(!h||h.kind!=="video"))throw Error("hudWall sourceClipId must be the footage (a video clip)");const w=$t(p.start)??h?.start??0,T=Math.min(gn.maxSeconds,$t(p.duration)??(h?h.start+h.duration-w:6)),{cards:C,assets:O}=fE(p,o,n.locale),L=p.region!=null&&typeof p.region=="object"?p.region:null,B=n.W||1280,H=n.H||720,q=mE({cards:C,cols:$t(p.cols),rows:$t(p.rows),curve:$t(p.curve),color:p.color,look:p.look,toolbar:p.toolbar,...L&&Number(L.w)>0&&Number(L.h)>0&&(p.mode??"plane")==="plane"?{W:B*L.w,H:H*L.h,fill:!0}:{W:B,H}});let et=Dt();for(;y(et);)et=Dt();const st=wE({id:et,at:w,duration:T,cfg:q,assets:O});if(p.region!=null){if(!h)throw Error("hudWall region needs sourceClipId (the footage to stick the wall to)");Object.assign(st,ol(st,h,{region:p.region,mode:p.mode??"plane",at:p.at}))}const{track:Y}=qt(s,r,st.start,st.start+st.duration);s.push({...st,track:Y}),X.push(et),st.pendingPin&&S.push({clipId:et,...st.pendingPin}),d.push(`hudWall: ${C.length} card(s), ${q.cols}×${q.rows}${st.pendingPin?`, stuck to ${h.label||h.id} (${st.pendingPin.mode}, tracked in the editor)`:""}`);break}case"hudPanel":{p=te(p);const h=p.sourceClipId!=null?y(p.sourceClipId):null;if(p.sourceClipId!=null&&(!h||h.kind!=="video"))throw Error("hudPanel sourceClipId must be the footage (a video clip)");if(p.region!=null&&!h)throw Error("hudPanel region needs sourceClipId (the footage to stick the panel to)");const w=ft(($t(p.start)??h?.start??0)+Math.max(0,$t(p.delay)??0)),T=Math.min(ar.maxSeconds,$t(p.duration)??(p.kind==="prompt"||p.kind==="keyboard"?Math.max(4,hb(String(p.text??""),$t(p.typeAt)??.5,$t(p.cps)??14).at(-1)+1.6||4):4));if(!(T>=.5))throw Error("hudPanel: duration ≥ 0.5 s");const C=p.kind==="prompt"&&p.keyboard===!0?["prompt","keyboard"]:[p.kind],O=[],L=[];for(const B of C){const H=xA(B,B==="keyboard"&&p.kind==="prompt"?{...p,posX:void 0,posY:p.keyboardY,width:void 0,tiltX:void 0,tiltY:void 0}:p,{materials:o,locale:n.locale,fill:p.region!=null&&B!=="keyboard"});if(p.region==null){const Y=n.W||1280,ct=n.H||720,gt=h??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],Z=gt?Oc(gt,o.find(dt=>dt.id===gt.nodeId),w+T/2,{W:Y,H:ct})??{...ct>Y*1.1?Ie.face.portrait:Ie.face.landscape,assumed:!0}:null,nt=vA(H.S,Z,Y,ct);nt&&L.push(`${B} ${nt}`)}let q=Dt();for(;y(q);)q=Dt();const et={id:q,nodeId:"",kind:"image",url:"",volume:0,start:w,duration:ft(T),label:H.label,motionV:2,posX:0,posY:0,scale:1,motion:kA(H.S,H.TT,H.assets)};p.region!=null&&B!=="keyboard"&&Object.assign(et,ol(et,h,{region:p.region,mode:p.mode??"plane",at:p.at}));const{track:st}=qt(s,r,et.start,et.start+et.duration);s.push({...et,track:st}),X.push(q),O.push(B),et.pendingPin&&S.push({clipId:q,...et.pendingPin})}d.push(`hudPanel: ${O.join(" + ")} (${ub(p.look,p.color).id}) ${w.toFixed(2)}–${(w+T).toFixed(2)}s${L.length?` — ${L.join(", ")}`:""}${p.region!=null?`, stuck to ${h.label||h.id} (tracked in the editor)`:""}`);break}case"hudInteract":{p=te(p);const h=y(Mt(p.wallClipId??p.clipId));if(!my(h))throw Error("hudInteract needs wallClipId = a HUD wall layer (hudWall)");const w=y(p.sourceClipId);if(!w||w.kind!=="video")throw Error("hudInteract needs sourceClipId = the footage with the hands");const T=Math.max(h.start,w.start),C=Math.min(h.start+h.duration,w.start+w.duration);if(!(C-T>=.3))throw Error("The HUD wall and the footage do not play at the same time");const O=Qu.includes(p.hand)?p.hand:"any",L=p.grab===!1?!1:Number.isInteger(p.grab)?p.grab:"auto",B=$t(p.fly),H=Array.isArray(p.events)?p.events.slice(0,64).map(Ut=>({t:at(Ut?.t),type:Ut?.type,...Array.isArray(Ut?.point)?{point:Ut.point.map(Number)}:{}})):null,q=p.matteClipId!=null?y(p.matteClipId):null;if(p.matteClipId!=null&&!q?.person)throw Error("hudInteract matteClipId must be a clip with an AI person / object cut-out of the hands");s=s.filter(Ut=>Ut.hud?.wall!==h.id);const et=()=>{let Ut=Dt();for(;y(Ut);)Ut=Dt();return Ut},{HUD:st}=od(h.motion),Y=h.motion.params?.color??st.color,ct=h.motion.params?.look??st.look,gt=n.W||1280,Z=n.H||720,nt=w.hands?.mw??gt,dt=w.hands?.mh??Z,vt=ME(h,w,s,{cam:u,W:gt,H:Z}),At=et();let xt=null;if(p.shadow===!0){const Ut={...w,id:At,volume:0,hud:{wall:h.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 Ut[Nt];xt=vE(Ut,{id:At,wallMask:vt,mw:nt,mh:dt}),xt.track=qt(s,r,xt.start,xt.start+xt.duration).track,s.push(xt),X.push(At)}const St=et(),jt={id:St,nodeId:"",kind:"image",url:"",volume:0,start:ao(T),duration:ao(C-T),label:"HUD · thẻ kéo ra",motionV:2,posX:0,posY:0,scale:1,motion:gh({color:Y,look:ct}),hud:{wall:h.id,role:"grab"}};jt.track=qt(s,r,jt.start,jt.start+jt.duration).track,s.push(jt),X.push(St);const Kt=et(),ee={...w,id:Kt,label:`${w.label||"Video"} · tay`,volume:0,hud:{wall:h.id,role:"hands",src:w.id},mask:wh(w.hands?.mw,w.hands?.mh)};for(const Ut of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","shocks","impacts","trail","pendingPin","pin"])delete ee[Ut];const le=q?.person??(w.person&&w.person.src!=="object"?w.person:s.find(Ut=>Ut.id!==w.id&&Ut.kind==="video"&&Ut.url===w.url&&Ut.person&&Ut.person.src!=="object")?.person);le?ee.person=le:delete ee.person,ee.track=qt(s,r,w.start,w.start+w.duration).track,s.push(ee),X.push(Kt);const xe={source:w.id,mode:"hud",wall:h.id,cutout:Kt,...xt?{shadow:At}:{},side:O,grab:L,...q?{matte:q.id}:{},...B!=null?{fly:B}:{},...H?{events:H}:{},from:ao(T-w.start),duration:ao(C-T)};if(Dp(w,T-w.start,C-T)||H?.every(Ut=>Array.isArray(Ut.point))){const Ut=xE({wall:h,layer:jt,src:w,clips:s,cam:u,W:n.W||1280,H:n.H||720,events:H,grab:L,side:O,fly:B});if(h.motion=Ut.wall,jt.motion=Ut.grab,w.hands){const Nt=r0(w,{until:Ut.cutoutUntil});Nt&&(ee.mask=Nt,xt&&(xt.mask={...Nt,masks:[...Nt.masks,{...vt,mode:"intersect"}]}))}d.push(`hudInteract ${h.label||h.id}: ${Ut.report.taps} tap(s), ${Ut.report.pinches} pinch(es)${Ut.report.grabbed!=null?`, card ${Ut.report.grabbed+1} pulled out`:""}, hands in front${w.hands?" (the open editor then cuts them out pixel by pixel)":""}`),w.hands&&Object.assign(jt,De(jt,{kind:"hand-track",op:"hudInteract",params:xe}));break}Object.assign(jt,De(jt,{kind:"hand-track",op:"hudInteract",params:xe})),d.push(`hudInteract ${h.label||h.id}: the hands are tracked in the editor, then the HUD reacts`);break}case"handAttach":{p=te(p);const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("handAttach needs a visual layer (clipId)");const w=y(p.sourceClipId);if(!w||w.kind!=="video")throw Error("handAttach needs sourceClipId = the footage with the hands");if(w.id===h.id)throw Error("A layer cannot follow its own hands");if(h.pin||h.pendingPin||h.parentId)throw Error("handAttach: unpin / unparent the layer first");const{point:T,side:C}=n0(p),O=p.scale===!0,L=Array.isArray(p.offset)&&p.offset.length===2&&p.offset.every(Number.isFinite)?p.offset:null,B=Math.max(h.start,w.start),H=Math.min(h.start+h.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(Dp(w,B-w.start,H-B)){for(const[q,et]of Object.entries(kE(h,w,{point:T,side:C,scale:O,offset:L,W:n.W||1280,H:n.H||720})))et===void 0?delete h[q]:h[q]=et;d.push(`handAttach ${V}: follows the ${C==="any"?"":C+" "}hand's ${T}`);break}Object.assign(h,De(h,{kind:"hand-track",op:"handAttach",params:{source:w.id,mode:"attach",point:T,side:C,scale:O,...L?{offset:L}:{},from:ao(B-w.start),duration:ao(H-B)}})),d.push(`handAttach ${V}: the hands are tracked in the editor, then it follows the ${T}`);break}case"fixMatte":{p=te(p);const h=y(p.clipId);if(!h?.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=h.clientJobs?.find(H=>H?.kind==="matte-fix"&&H.state==="pending"),T=w?.params?.strokes??[];if(p.clear===!0){Object.assign(h,De(h,{kind:"matte-fix",op:"fixMatte",params:{clear:!0,strokes:[]}})),d.push(`fixMatte ${V}: back to the AI cut-out (in the editor)`);break}if(p.roto===!0){Object.assign(h,De(h,{kind:"matte-fix",op:"fixMatte",params:{...w?.params??{},roto:!0}})),d.push(`fixMatte ${V}: traced into Roto splines (in the editor)`);break}const C=at(p.at),O=p.mode??"add";if(C===null||C<h.start-1e-6||C>h.start+h.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(p.points)?p.points:null;if(!L||!L.length||L.length>120||!L.every(H=>Array.isArray(H)&&H.length===2&&H.every(q=>Number.isFinite(q)&&q>=-.2&&q<=1.2)))throw Error("fixMatte points: [[x, y] …] 0..1 of the frame (≤ 120)");const B={local:ao(C-h.start),mode:O,points:L.map(H=>H.map(ao)),size:Math.max(.002,Math.min(.3,at(p.size)??.015)),spread:Math.round(Math.max(0,Math.min(60,at(p.spread)??8)))};Object.assign(h,De(h,{kind:"matte-fix",op:"fixMatte",params:{...w?.params?.clear?{clear:!0}:{},...w?.params?.roto?{roto:!0}:{},strokes:[...T,B].slice(-50)}})),d.push(`fixMatte ${V}: ${O} stroke at ${(+C).toFixed(2)}s, followed ±${B.spread} frames (in the editor)`);break}case"cameraShake":{const h=y(p.clipId);if(!h||h.kind==="audio"||h.kind==="model")throw Error("Camera shake needs a 2D visual clip");const w=at(p.at)??0,T=at(p.duration)??Math.min(1.5,h.duration-w),C=Math.max(.1,Math.min(1,at(p.numberValue)??.5)),O=Math.round(w*1e3)+h.id.length;if(p.preset!=null&&!Ju.includes(p.preset))throw Error(`cameraShake preset (axis) must be one of ${Ju.join(", ")}`);const L=p.preset!=null?Y4(p.preset,C,{amountX:at(p.amountX)??void 0,amountY:at(p.amountY)??void 0,amountRot:at(p.amountRot)??void 0,freq:at(p.freq)??void 0}):null;Object.assign(h,ti(h,L?{props:L.props,amp:L.amp,freq:L.freq,from:w,to:w+T,seed:O}:{amount:C,freq:12,from:w,to:w+T,seed:O})),d.push(`camera shake${p.preset?` ${p.preset}`:""} ${V}: ${w}s +${T}s`);break}case"writeMotion":{const h=typeof p.prompt=="string"?p.prompt.trim():"";if(h.length<6||h.length>6e3)throw Error("Motion brief must be 6–6000 characters");if(g.length>=Rl)throw Error(`At most ${Rl} Claude motion jobs per request`);if(p.clipId){const L=y(p.clipId);if(!L?.motion)throw Error("writeMotion clipId must be a Motion Code layer");g.push({clipId:L.id,prompt:h}),d.push(`Claude motion (sửa) ${V}`);break}const w=p.fromClipId?y(p.fromClipId):null;if(p.fromClipId&&!w?.motion)throw Error("writeMotion fromClipId must be a Motion Code layer");const T=at(p.start)??(w?w.start+w.duration:null),C=at(p.duration)??6;if(T===null||T<0||C<1||C>Dl+1e-6||T+C>He)throw Error(`Motion layer timing: start ≥ 0, 1–${Dl}s`);const O=g.filter(L=>!L.clipId&&L.join==null).reduce((L,B)=>L+(B.duration||0),0);if(O+C>Dl+1e-6)throw Error(`Claude motion: at most ${Dl}s of new layers per request (this plan asks for ${ft(O+C)}s) — split it into several requests`);g.push({prompt:h,start:ft(T),duration:ft(C),...w?{fromClipId:w.id}:{},...p.preset==="motion3d"?{kind:"three"}:{}}),d.push(`Claude motion (${w?`nối tiếp ${w.label}`:"mới"}) → ${ft(T)}s / ${ft(C)}s`);break}case"setMotionCode":{const h=y(p.clipId);if(!h?.motion)throw Error("setMotionCode clipId must be a Motion Code layer");if(typeof p.code!="string"||!/\brender\b/.test(p.code))throw Error("Motion code must define function render(ctx, t, env)");const w=p.motionKind==="three"?"three":p.motionKind==="2d"?void 0:h.motion.kind,T=ko({code:p.code,params:p.params??{},...h.motion.prompt?{prompt:h.motion.prompt}:{},...w?{kind:w}:{},...h.motion.assets?{assets:h.motion.assets}:{}});h.motion=h.motion.duration?{...T,duration:h.motion.duration}:T,p.space===null||p.space===""?delete h.space:p.space!==void 0&&Object.assign(h,dg(p)),d.push(`motion code ${V}`);break}case"setMotion":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error("Motion requires a visual clip");const w=Vl(p.preset,h.duration);h.motionKeys=Eu(h,w),delete h.posX,delete h.posY,delete h.scale,h.motionV=2,d.push(`motion ${V}: ${p.preset}`);break}case"generateBroll":{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);if(s.filter(O=>O.gen?.status==="pending"&&!t.some(L=>L.id===O.id)).length>=il)throw Error(`At most ${il} generated B-roll per request`);const h=p.layout??"cutaway";if(!$g.includes(h))throw Error("Unsupported B-roll layout");const w=Dt(),{clip:T,trackNote:C}=V5({clips:s,tracks:r,materials:o,generator:p.generator,prompt:p.prompt,start:at(p.start),duration:at(p.duration),layout:h,preset:p.preset,track:at(p.track),trackFallback:!0,newId:()=>w,refs:p.refs??void 0});X.push(w),s.push(T),d.push(`generateBroll → ${T.start}s / ${T.duration}s${C?` (${C})`:""}`);break}case"redrawVideo":{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const h=y(p.clipId);if(!h||h.kind!=="video"||h.gen||h.title||h.shape||h.motion)throw Error("needs a video clip");if(!wi(h.gcsUri))throw Error("this video has no stored copy — add it to the project first (upload / Media)");if(h.duration<rn.minSeconds-1e-6)throw Error(`the clip must be at least ${rn.minSeconds}s`);if(p.style!==void 0&&!Ld.includes(p.style))throw Error(`style: one of ${Ld.join(", ")}`);if(p.mode!==void 0&&!h2.includes(p.mode))throw Error("mode: keyframes or fast");if(p.resolution!==void 0&&!d2.includes(p.resolution))throw Error("resolution: 720p or 1080p");if(p.keyframes!==void 0&&(!Number.isInteger(p.keyframes)||p.keyframes<rn.minKeyframes||p.keyframes>rn.maxKeyframes))throw Error(`keyframes: ${rn.minKeyframes}–${rn.maxKeyframes}`);const w=typeof p.character=="string"?p.character.trim():"";if(w.length>rn.maxCharacterText)throw Error(`character: at most ${rn.maxCharacterText} characters`);const T=Array.isArray(p.characterIds)?p.characterIds:[],C=[...new Set([...T.map(Y=>{const ct=o.find(gt=>gt.id===Y)||s.find(gt=>gt.id===Y&&gt.kind==="image");if(!ct||ct.kind!=="image"||!wi(ct.gcsUri))throw Error(`character picture ${String(Y).slice(0,40)} is not a stored image`);return ct.gcsUri}),...Array.isArray(p.refs)?p.refs:[]])];if(C.length>rn.maxCharacterRefs||!C.every(wi))throw Error(`at most ${rn.maxCharacterRefs} stored character pictures`);if(!w&&!C.length)throw Error("needs a character (description and / or picture)");const O=f2(h.duration),L=m2(p.style),B=ft(Math.min(h.duration,O)),{moved:H,...q}=Ku(s,r,h.start,h.start+B,at(p.track),{fallback:!0}),et=Dt(),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",...q,id:et,start:h.start,duration:B,gen:{status:"pending",generator:g2,prompt:w,duration:O,finish:{colorMatch:!1},...C.length?{refs:C}:{},redraw:{src:h.gcsUri,inPoint:ft(h.inPoint??0),seconds:O,style:L.id,mode:p.mode??"keyframes",...p.keyframes!==void 0?{keyframes:p.keyframes}:{},resolution:p.resolution??"720p"}}}),X.push(et),d.push(`redrawVideo ${st} → ${h.start}s / ${B}s (${p.mode??"keyframes"})${H?` (track ${q.track})`:""}`);break}case"regionEdit":{const h=y(p.clipId);if(!h||h.kind!=="video"||h.gen||h.title||h.shape||h.motion||h.freeze)throw Error("regionEdit needs a video clip");if(!wi(h.gcsUri))throw Error("this video has no stored copy — add it to the project first (upload / Media)");if((h.playbackRate??1)!==1||Zr(h)||Bn(h)||h.reverse)throw Error("regionEdit needs the clip at normal speed (not reversed, sped up or ramped)");if(p.aspectRatio!=null&&!Od.includes(p.aspectRatio))throw Error(`aspectRatio: one of ${Od.join(", ")}`);const w=Array.isArray(p.regions)?p.regions.map(L=>L&&typeof L=="object"?{...L,start:Number.isFinite(L.start)?ft(L.start):L.start,end:Number.isFinite(L.end)?ft(L.end):L.end}:L):p.regions;if(i2(w,h.duration),s.length+w.length>Gt)throw Error(`Tối đa ${Gt} clip`);const T=Object.fromEntries(KA.filter(L=>h[L]!==void 0).map(L=>[L,structuredClone(h[L])])),C=n.locale==="en",O=new Set;for(const[L,B]of[...w].sort((H,q)=>H.start-q.start).entries()){const H=typeof B.prompt=="string"?B.prompt.trim():"",q=B.action??(H?"custom":null),et=B.model??s2;if(!q)throw Error(`region ${L+1}: action (scene, camera, character, relight, dof) or prompt (custom)`);if(q==="custom"&&!H)throw Error(`region ${L+1}: custom needs prompt (what to change)`);let st=null;if(B.imageMaterialId!=null){const jt=o.find(Kt=>Kt.id===B.imageMaterialId)||s.find(Kt=>Kt.id===B.imageMaterialId&&Kt.kind==="image");if(!jt||jt.kind!=="image"||!wi(jt.gcsUri))throw Error(`region ${L+1}: imageMaterialId ${String(B.imageMaterialId).slice(0,40)} is not a stored image in Media`);st=jt.gcsUri}if(zd(q).image==="required"&&!st)throw Error(`region ${L+1}: ${q} needs imageMaterialId (one front view of the new character from Media)`);let Y;try{Y=l2({inPoint:h.inPoint??0,length:h.duration,start:B.start,end:B.end,model:et})}catch(jt){throw Error(`region ${L+1}: ${jt.message}`)}const ct=B.exact===!0&&H?H.slice(0,Pd.maxPrompt):c2(q,H,{hasImage:!!st}),gt=ft(h.start+B.start),Z=ft(B.end-B.start),nt=Math.max(.05,Math.min(Pd.fade,Z/4)),{moved:dt,...vt}=Ku(s,r,gt,gt+Z,at(p.track),{fallback:!0}),At=Dt(),xt=zd(q),St=p2[et];s.push({nodeId:"",kind:"video",url:"",label:`${C?xt.en:xt.vi} · ${St.label}`,...T,inPoint:Y.offset,sourceDuration:Y.seconds,volume:0,...vt,id:At,start:gt,duration:Z,enter:{type:"fade",duration:nt},exit:{type:"fade",duration:nt},gen:{status:"pending",generator:u2,prompt:ct,duration:Y.seconds,finish:{colorMatch:!1},...st?{refs:[st]}:{},region:{src:h.gcsUri,action:q,model:et,winStart:Y.winStart,seconds:Y.seconds,offset:Y.offset,...p.aspectRatio!=null?{aspect:p.aspectRatio}:{}}}}),X.push(At),O.add(vt.track)}d.push(`regionEdit ${V} → ${w.length} region(s) on track ${[...O].join(", ")}`);break}case"addBroll":case"addText":case"addShape":case"addSolid":case"addAdjustmentLayer":case"addElement":case"addMotion":case"addMap":case"addCard":case"generateElement":{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);const h=at(p.start),w=at(p.duration);if(h===null||w===null||h<0||w<1/Me||h+w>He)throw Error("Invalid creative clip timing");const T=ft(h),C=ft(w),O=at(p.track),{track:L,moved:B}=qt(s,r,T,T+C,O);let H;if(p.op==="addAdjustmentLayer"){const{id:gt,track:Z,start:nt,duration:dt,...vt}=xp({id:"x",track:0,start:0,duration:1,label:Jw(s)}),At=at(p.numberValue);H={...vt,...At!==null&&At>=0&&At<1?{opacity:At}:{}}}else if(p.op==="addSolid"){const gt=["linear","radial"].includes(p.preset)?p.preset:"color",Z=p.color??"#d93a3a",{id:nt,track:dt,start:vt,duration:At,...xt}=Vh({id:"x",track:0,start:0,duration:1,aspect:n.W&&n.H?n.W/n.H:void 0,label:Qw(s),fill:gt==="color"?{type:gt,color:Z}:{type:gt,from:Z,to:p.fill??"#0d0f12",angle:at(p.angle)??90}}),St=at(p.numberValue);H={...xt,...St!==null&&St>=0&&St<1?{opacity:St}:{}}}else if(p.op==="addBroll"){const gt=o.find(nt=>nt.id===p.materialId);if(!gt?.url||!["image","video"].includes(gt.kind))throw Error("B-roll requires an existing image or video material");const Z=at(p.inPoint)??0;if(Z<0||gt.kind==="image"&&Z!==0||gt.kind==="video"&&(!Number.isFinite(gt.duration)||Z+C>gt.duration+1e-6))throw Error("B-roll range exceeds known source duration");H={nodeId:gt.id,kind:gt.kind,url:gt.url,label:gt.label||"B-roll",inPoint:Z,sourceDuration:gt.kind==="video"?gt.duration:void 0,volume:0,fit:"cover"}}else if(p.op==="generateElement"){const gt=p.generator??Kk;if(!Vk[gt])throw Error("Unsupported element generator");const nt=typeof p.prompt=="string"?p.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>=il)throw Error(`At most ${il} generated items per request`);H={nodeId:"",kind:"image",url:"",label:`AI element · ${nt.slice(0,40)}`,volume:0,gen:{status:"pending",generator:gt,prompt:nt,duration:C},...ot(p,.45)},p.anim!=null&&(H.element={},H.pendingAnim=p.anim)}else if(p.op==="addElement"){if(p.elementId!=null){const gt=kg(p.elementId);if(!gt)throw Error("Unknown element");const Z={id:gt.id,...p.primary?{primary:p.primary}:{},...p.secondary?{secondary:p.secondary}:{}};H={nodeId:"",kind:"image",url:"",label:`Element · ${gt.name}`,volume:0,shape:t2(gt.id,Z),element:Z,...ot(p,.25)}}else{const gt=o.find(Z=>Z.id===p.materialId);if(!gt?.url||gt.kind!=="image")throw Error("Element requires a library id or an image material");H={nodeId:gt.id,kind:"image",url:gt.url,...gt.gcsUri?{gcsUri:gt.gcsUri}:{},label:gt.label||"Element",volume:0,element:{},...ot(p,.25)}}H.pendingAnim=p.anim??{}}else if(p.op==="addMotion"){if(C>to.maxDuration+1e-6)throw Error(`Motion Code layers: at most ${to.maxDuration}s`);const gt=!p.code&&p.motionPreset?Fi(p.motionPreset,p):null,Z=ko(gt?{code:gt.code,params:{...gt.params,...p.params??{}},preset:gt.preset,kind:gt.kind}:{code:p.code,params:p.params??{},preset:p.motionPreset??void 0,prompt:p.prompt??void 0,kind:p.motionKind??void 0,assets:p.motionAssets??void 0});H={nodeId:"",kind:"image",url:"",label:typeof p.label=="string"&&p.label.trim()?p.label.trim().slice(0,60):gt?`Motion · ${String(p.text||gt.name).slice(0,40)}`:"Motion code",volume:0,motion:Z,...dg(p)}}else if(p.op==="addMap"){const gt=lg(p.models,o,p.geo?.stops??[]),Z=cg(p.images,o,p.geo?.stops??[]),nt=Ad({...p.geo,...gt?{models:gt}:{},...Z?{images:Z}:{},...p.buildings!==void 0&&p.buildings!==null?{buildings:p.buildings}:{}},C),dt=typeof p.label=="string"&&p.label.trim()?p.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(p.op==="addCard"){const gt=e2({html:p.html,width:at(p.width)??Td.width,height:at(p.height)??Td.height,...p.fill?{bg:p.fill}:{}}),Z=720/Math.min(n.W||1280,n.H||720),nt=(n.W||1280)*Z,dt=(n.H||720)*Z;H={nodeId:"",kind:"image",url:"",label:`Card · ${n2(gt.html).slice(0,40)||"HTML"}`,volume:0,card:gt,posX:Math.max(-1,Math.min(1,at(p.posX)??0)),posY:Math.max(-1,Math.min(1,at(p.posY)??r2(gt,p.placement,nt,dt))),scale:Math.max(.05,Math.min(4,at(p.scale)??o2(gt,nt,dt))),enter:{type:"fade",duration:Math.min(.4,C/4)},exit:{type:"fade",duration:Math.min(.3,C/4)}}}else if(p.op==="addShape"){const gt=p.shape&&Object.hasOwn(qh,p.shape),Z=gt?Tv(p.shape,{color:p.color??"#c6f432",accent:p.fill??"#2bd4c9",duration:C}):a2({preset:p.shape??void 0,d:p.path??void 0,stroke:p.color??"#c6f432",fill:p.fill??null,strokeWidth:at(p.numberValue)??18});H={nodeId:"",kind:"image",url:"",label:`Shape · ${p.shape??"custom"}`,volume:0,shape:Z,...ot(p,gt?1:.6)}}else{const gt=Wl(p);H={nodeId:"",kind:"image",url:"",label:gt.text.slice(0,40),title:gt,volume:0,...at(p.posX)!==null||at(p.posY)!==null?ot(p,1):{},...p.decor===!0?{decor:!0}:{}}}const q=p.op==="addSolid"||p.op==="addAdjustmentLayer"||p.op==="addMap"?[]:Vl(p.preset??"none",C),et=Dt();X.push(et);const{pendingAnim:st,...Y}=H,ct={...Y,id:et,start:T,duration:C,track:L,motionKeys:q,...H.posX!==void 0?{motionV:2}:{}};s.push(st?C5(ct,st):lt?fc(ct,"exit","fade",{duration:Math.min(.3,C/4)}):ct),d.push(`${lt?"lockup":p.op} → ${T}s / ${C}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 h=sd(p,{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 h.patches){const C=s.findIndex(O=>O.id===T.id);s[C]={...s[C],shape:T.shape,...T.duration?{duration:T.duration}:{}}}const w=(T,C,O,L,B={})=>{if(s.length>=Gt)throw Error(`Tối đa ${Gt} clip`);if(O===null||L===null||O<0||L<1/Me||O+L>He)throw Error("Invalid creative clip timing");const H=ft(O),q=ft(L),{track:et}=qt(s,r,H,H+q,B.zIndex===-1?null:at(p.track)),st=Dt();return X.push(st),s.push({id:st,nodeId:"",kind:"image",url:"",label:C,volume:0,shape:T,posX:0,posY:0,scale:1,motionV:2,start:H,duration:q,track:et,motionKeys:[],...B}),st};if(h.layer&&w(h.layer.shape,h.layer.label,at(p.start),h.layer.duration??at(p.duration)),h.frameLayers){const T=h.startAbs?0:at(p.start)??0;for(const C of h.layers){const O=w(C.shape,C.label,T+C.start,C.duration,p.track!=null?{}:{});if(C.clientJob){const L=s.findIndex(B=>B.id===O);s[L]=De(s[L],C.clientJob)}}if(h.shakeAt!=null){const C=h.shakeAt,O=L=>!X.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-C)<.05,q=Math.abs(B.start-C)<.05;if(!H&&!q)continue;const et=H?Math.max(0,B.duration-.25):0,st=H?B.duration:Math.min(B.duration,.4);if(st-et>=.2)try{s[L]={...B,...ti(B,{amount:H?.3:.45,freq:16,from:et,to:st,seed:Math.round(C*1e3)+L})}}catch{}}}}else if(h.layers){const T=n.W||1280,C=n.H||720,O=h.layers.map(H=>w(H.shape,H.label,at(p.start),at(p.duration),H.place??{})),L=H=>s.findIndex(q=>q.id===O[H]);h.layers.forEach((H,q)=>{H.anchor!=null&&(sr(s),s[L(q)]=Ca(s,s[L(q)],{anchor:H.anchor,box:H.box,W:T,H:C}))});const B=Cl(s,O,T,C);if(h.layers.forEach((H,q)=>{H.parent!=null&&H.parent!==q&&(sr(s),s[L(q)]=Ca(s,s[L(q)],{parentClipId:O[H.parent],W:T,H:C}))}),h.camera){const H=ft(at(p.start)??0),q=ft(at(p.duration)??1),{track:et}=qt(s,r,H,H+q,null),st=Dt();s.push(xr({id:st,track:et,start:H,duration:q,label:"Camera 2D"})),X.push(st);const Y=s.length-1;s[Y]=jl(s[Y],h.camera.preset,{W:T,H:C,amount:h.camera.amount??1}),O.forEach((ct,gt)=>{h.layers[gt].parent==null&&(sr(s),s[L(gt)]=Ca(s,s[L(gt)],{parentClipId:st,W:T,H:C}))})}sr(s),h.layers.forEach((H,q)=>{if(H.motion){const{preset:et,...st}=H.motion;s[L(q)]=jl(s[L(q)],et,{...st,W:T,H:C})}}),s=xs(s,B,T,C)}if(h.paper){const T=s.find(C=>cb(C)&&C.start<=h.paper.start+1e-6&&C.start+C.duration>=h.paper.start+h.paper.duration-1e-6&&!r[C.track]?.locked);T?Object.assign(T,{shape:h.paper.shape,label:h.paper.label}):w(h.paper.shape,h.paper.label,h.paper.start,h.paper.duration,{zIndex:-1})}d.push(h.note);break}case"animateLayer":case"rigLayer":{const h=rb(p),w=n.W||1280,T=n.H||720;if(p.op==="rigLayer"){const q=y(h.clipId);if(!q||q.kind==="audio")throw Error("Clip not found");if(r[q.track]?.locked)throw Error("That layer is locked");const et=Object.hasOwn(p,"parentClipId")?p.parentClipId:h.parentClipId,st=et===void 0?void 0:et===null||et===""?null:et;if(st===void 0&&h.anchor==null)throw Error("rigLayer needs parentClipId (null = unlink) and / or anchor");sr(s);const Y=Math.max(0,Math.min(q.duration,(at(h.at)??q.start)-q.start)),ct=q.shape?.v===2?gg(q):null,gt=Cl(s,su(s,[q.id]),w,T),Z=s.indexOf(q);s[Z]=Ca(s,q,{parentClipId:st,anchor:h.anchor,at:Y,W:w,H:T,box:ct}),s=xs(s,gt,w,T),d.push(`rigLayer: ${q.label}${st!==void 0?` → ${st?y(st)?.label:"no parent"}`:""}`);break}const C=Array.isArray(h.clipIds)&&h.clipIds.length?h.clipIds:h.clipId?[h.clipId]:null;if(!C)throw Error("animateLayer needs clipId (or clipIds)");if(!Dn[h.preset])throw Error(`animateLayer preset: ${Object.keys(Dn).join(" | ")}`);const O=at(h.stagger)??0,L=at(h.period),B=at(h.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");sr(s);const H=Cl(s,su(s,C.map(q=>y(q)?.id).filter(Boolean)),w,T);if(h.camera===!0){if(!Uc.includes(h.preset))throw Error(`animateLayer camera: true takes a camera preset (${Uc.join(" | ")})`);const q=C.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}),et=Math.min(...q.map(dt=>dt.start)),st=Math.max(...q.map(dt=>dt.start+dt.duration)),{track:Y}=qt(s,r,ft(et),ft(st),null),ct=Dt();s.push(xr({id:ct,track:Y,start:ft(et),duration:ft(st-et),label:"Camera 2D"})),X.push(ct);const gt=s.length-1,Z=Math.max(0,(at(h.at)??et)-et),nt=at(h.duration);s[gt]=jl(s[gt],h.preset,{W:w,H:T,amount:B??1,a:Z,b:nt!==null?Math.min(st-et,Z+nt):st-et});for(const dt of q)if(!dt.parentId){sr(s);const vt=s.findIndex(At=>At.id===dt.id);s[vt]=Ca(s,s[vt],{parentClipId:ct,W:w,H:T})}sr(s),s=xs(s,H,w,T),d.push(`animateLayer ${h.preset}: Camera 2D over ${q.length} layer(s)`);break}C.forEach((q,et)=>{const st=y(q);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/Me,(at(h.at)??st.start)-st.start)),ct=at(h.duration),gt=L??Dn[h.preset].period,Z=s.indexOf(st);s[Z]=jl(st,h.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?et*O/gt%1:0})}),s=xs(s,H,w,T),d.push(`animateLayer ${h.preset}: ${C.length} layer(s)`);break}case"setEasing":case"loopKeys":case"addBounce":{const h=y(p.clipId);if(!h||h.kind==="audio")throw Error("Clip not found");const w=p.property?[p.property]:void 0,T=hv(n.motion),C=(q,et)=>q==null?et:Math.max(0,Math.min(1,at(q)??et)),O=Math.max(.05,Math.min(1,at(p.numberValue)??.5)),L=p.op==="setEasing"&&Array.isArray(p.times)&&p.times.length?p.times:null,B=p.easeIn!=null||p.easeOut!=null,H=L?zk(h,{in:p.easeIn!=null||!B?C(p.easeIn,T.in):null,out:p.easeOut!=null||!B?C(p.easeOut,T.out):null},L,w):p.op==="setEasing"?Pk(h,{in:C(p.easeIn,T.in),out:C(p.easeOut,T.out)},w?Ee(h,w[0]).map(q=>({prop:w[0],time:q.time})):void 0):p.op==="loopKeys"?Lk(h,["cycle","pingpong","offset"].includes(p.loopMode)?p.loopMode:"cycle",{props:w}):Nk(h,(p.settle??c.settle)==="bounce"?"bounce":"elastic",{amount:O,...w?{props:w}:{}});if(!w&&!L&&p.op==="setEasing")for(const q of["enter","exit"])h[q]&&(H[q]={...h[q],ease:Tu([C(p.easeOut,T.out),0,1-C(p.easeIn,T.in),1])});if(!w&&p.op==="addBounce"&&!Object.keys(H).length&&h.enter&&(H.enter={...h.enter,ease:Tu([.34,1+O*1.2,.64,1])}),!Object.keys(H).length)throw Error(L?"No key at those times (clip-local seconds)":p.op==="addBounce"?"Needs a property with at least 2 keys and room after the last key, or an enter animation":p.op==="setEasing"?"Layer has no keys or enter / exit animation":"Layer has no keys");Object.assign(h,H),d.push(`${p.op}: ${V}`);break}case"matchReference":{const h=o.find(Nt=>Nt.id===p.materialId);if(!h||h.role!=="reference")throw Error("materialId phải là một Video mẫu (Media → vai trò Video mẫu)");if(!h.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(p.picks)?p.picks:Array.isArray(p.items)?p.items:[]).slice(0,sS).map(wS);for(const Nt of w){const Bt=o.find(_t=>_t.id===Nt.materialId);if(!Bt)throw Error(`Không thấy material ${Nt.materialId}`);if(Bt.role==="reference"||Bt.id===h.id)throw Error("Không dùng cảnh của video mẫu — chọn khoảnh khắc từ footage của bạn");if(!["video","image"].includes(Bt.kind))throw Error(`${Bt.label||Bt.id}: chỉ dùng video / ảnh`)}const T=ft(Math.max(0,at(p.start)??0));let C=p.fromClipId?y(Mt(p.fromClipId)):null,O=null;if(p.fromClipId&&(!C||C.kind!=="audio"))throw Error("fromClipId phải là clip nhạc (audio)");if(C)O=o.find(Nt=>Nt.id===C.nodeId)??null;else{const Nt=o.filter(Bt=>Bt.kind==="audio"&&Bt.role==="music");O=Nt.length===1?Nt[0]:null}let L=null;try{L=O?.beats?V4(O.beats):null}catch{L=null}const B=Nt=>{const Bt=o.find(_t=>_t.id===Nt);return Bt?.kind==="image"?1/0:at(Bt?.duration)??1/0},H=C?C.start-(C.inPoint||0)-T:0,q=Nt=>!C||Nt>=(C.inPoint||0)&&Nt<(C.inPoint||0)+C.duration,et=L?{...L,beats:L.beats.filter(q).map(Nt=>Nt+H).filter(Nt=>Nt>=0),drops:L.drops.filter(q).map(Nt=>Nt+H).filter(Nt=>Nt>=0)}:null,st=(Nt,Bt,_t)=>{const de=o.find(ye=>ye.id===Nt),re=ye=>Number.isFinite(ye?.start)&&Number.isFinite(ye?.end)&&ye.end>Bt&&ye.start<_t;return Array.isArray(de?.words)&&de.words.length?de.words.filter(re).map(ye=>ye.word).join(" "):(Array.isArray(de?.transcript)?de.transcript:[]).filter(re).map(ye=>ye.text).join(" ")},Y=kS({recipe:h.refRecipe,picks:w,beats:et,duration:at(p.duration),start:T,sourceDuration:B,copy:p.copy,spoken:st}),ct=T+Y.duration;if(s.length+Y.segments.length+1>Gt)throw Error(`Tối đa ${Gt} clip`);if(ct>He)throw Error("Vượt giới hạn 20 phút");const Z=!(Nt=>s.some(Bt=>Bt.kind!=="audio"&&Bt.track===Nt&&Bt.start<ct-1e-6&&Bt.start+Bt.duration>T+1e-6))(0)&&!r[0]?.locked?0:qt(s,r,T,ct,null).track,nt=Math.max(0,Math.min(2,at(p.volume)??(O?0:1))),dt=[];for(const Nt of Y.segments){const Bt=o.find(re=>re.id===Nt.materialId),_t=Dt();X.push(_t),dt.push(_t);const de=Bt.kind==="image"?null:at(Bt.duration);s.push({id:_t,nodeId:Bt.id,track:Z,start:ft(Nt.start),duration:ft(Nt.duration),inPoint:Bt.kind==="image"?0:Nt.inPoint,volume:Bt.kind==="image"?0:nt,url:Bt.url,...Bt.gcsUri?{gcsUri:Bt.gcsUri}:{},kind:Bt.kind,label:`${Bt.label||Bt.kind} · ${Nt.role}`,...de!==null?{sourceDuration:de}:{}})}if(O&&!C){const Nt=Ri.find(_t=>!r[_t]?.locked&&!s.some(de=>de.track===_t&&de.start<ct-1e-6&&de.start+de.duration>T+1e-6));if(Nt===void 0)throw Error("Không còn hàng audio trống cho nhạc");const Bt=Dt();X.push(Bt),s.push({id:Bt,nodeId:O.id,track:Nt,start:T,duration:ft(Math.min(Y.duration,at(O.duration)??Y.duration)),inPoint:0,volume:1,url:O.url,...O.gcsUri?{gcsUri:O.gcsUri}:{},kind:"audio",label:O.label||"Music",...at(O.duration)!=null?{sourceDuration:at(O.duration)}:{}})}const vt={punch:0,move:0,shake:0,look:0,text:0},At=[];Y.segments.forEach((Nt,Bt)=>{const _t=y(dt[Bt]),de=o.find(ye=>ye.id===Nt.materialId),re=(ye,or)=>{try{or(),vt[ye]++}catch{At.push(ye)}};Nt.move&&re("move",()=>{_t.motionKeys=Eu(_t,Vl(Nt.move,_t.duration)),delete _t.posX,delete _t.posY,delete _t.scale,_t.motionV=2}),Nt.punch&&re("punch",()=>Object.assign(_t,Pm(_t,{at:0,duration:Math.min(Yo.maxDuration,_t.duration),amount:Nt.punch.amount,style:Nt.punch.style,anchor:jc(_t,de)}))),Nt.shake&&re("shake",()=>Object.assign(_t,ti(_t,{amount:Nt.shake,freq:12,from:0,to:_t.duration,seed:Bt+1}))),Y.look&&re("look",()=>{const ye=[...(_t.effects||[]).filter(or=>or.type!==Y.look.effect),{type:Y.look.effect,amount:Y.look.amount}];if(ye.length>cn)throw Error("effects");_t.effects=ye})});const xt=p.specs&&typeof p.specs=="object"?p.specs:{},St=[];Y.segments.forEach((Nt,Bt)=>{if(!Bt||!Nt.transition)return;let _t=xt[Nt.transition];if(!_t){St.push(Nt.transition);return}const de=y(dt[Bt-1]),re=y(dt[Bt]);try{_t.id==="match-walk"&&(_t=mg(_t,de,re,o)),s=jd(s,dt[Bt-1],_t,Math.min(_t.duration,.45*Math.min(de.duration,re.duration)))}catch{St.push(Nt.transition)}});const{W:jt=1280,H:Kt=720}=n,ee=Kt>jt*1.1,le=ee?Ie.bands.portrait:Ie.bands.landscape,xe=[];if(Y.segments.forEach((Nt,Bt)=>{if(!Nt.text)return;const _t=y(dt[Bt]),de=Oc(_t,o.find(ye=>ye.id===Nt.materialId),_t.start+_t.duration/2,{W:jt,H:Kt});let re=Nt.text.placement;de&&!(de.assumed&&re!=="center")&&Bm(le[re],de,ee)&&(re=["top","lower","center"].find(ye=>!Bm(le[ye],de,ee))??re),xe.push({op:"addText",text:Nt.text.text,start:_t.start,duration:Math.max(.5,_t.duration),placement:re,fontFamily:"Anton",fontSize:ee?72:64,color:"#ffffff",styleId:"classic",preset:Nt.energy>=4?"pop-in":"none"})}),xe.length){const Nt=new Set(s.map(_t=>_t.id)),Bt=Si(s,xe,o,r,u,{...n,maxOps:xe.length});s=Bt.clips,vt.text=xe.length-Bt.errors.length;for(let _t=0;_t<Bt.errors.length;_t++)At.push("text");for(const _t of s)Nt.has(_t.id)||X.push(_t.id)}const Ut=Object.entries(vt).filter(([,Nt])=>Nt).map(([Nt,Bt])=>`${Bt} ${Nt}`).join(", ");d.push(`matchReference: ${Y.segments.length} cảnh, ${Y.duration}s${Y.snapped?", cắt theo beat":""}${Y.drop!=null?`, payoff @${Y.drop}s`:""}${Ut?`; style: ${Ut}${Y.look?` (${Y.look.effect})`:""}`:""}${St.length?` (${St.length} chuyển cảnh thành cắt thẳng)`:""}${At.length?` (${At.length} style bỏ qua)`:""}`);break}case"multicam":{const h=e8(s,p,o,r,{newId:Dt});s=h.clips,X.push(...h.created),d.push(h.note);break}case"kineticEdit":{const h=p.fromClipId?y(Mt(p.fromClipId)):null,w=h&&o.find(xt=>xt.id===h.nodeId);let T=[];if(h&&(T=lc(h,w?.words?.length?rl(w.words,1/0,Cd):null).map(St=>({word:St.word,start:h.start+St.start,end:h.start+St.end}))),!T.length&&typeof(p.text??p.prompt)=="string"&&(T=m3(p.text??p.prompt,at(p.start)??h?.start??0)),!T.length)throw Error(h?"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 C=at(p.start),O=C!=null&&at(p.duration)!=null?C+at(p.duration):null;C!=null&&(T=T.filter(xt=>xt.start>=C-1e-6&&(O==null||xt.start<O)));const L=n.H>n.W*1.1,B=n.brand?.colors??[],H=p.color&&/^#[0-9a-f]{6}$/i.test(p.color)?p.color:B[0]??"#e8141c",q=T.map(xt=>xt.word).join(" "),et=typeof p.preset=="string"&&p.preset.startsWith("poox-")?p.preset.slice(5):"auto",st=[...new Set([...Yg(q).industries,...o1(q),...n.brand?.industry&&n.brand.industry!=="general"?[n.brand.industry]:[]])];let Y=Wa[et]?et:x3(q,{industries:st,tone:n.brand?.tone??null,seed:T.length});et==="auto"&&Wa[Y].kind==="scenes"&&!ug(Wa[Y].caption)&&(Y="punch");const ct=B3(T,{palette:{accent:H,dark:"#0b0b0d",light:"#f4f4f1"},io:Math.max(.08,Math.min(.4,at(p.numberValue)??.16)),portrait:L,orb:!1,seed:1,industry:n.brand?.industry??null,genre:Y,known:xt=>!!ug(xt)});if(s.length+ct.beats.length+ct.els.length+ct.carriers.length+ct.orbs.length+ct.texture.length+ct.sfx.length>Gt)throw Error(`Kinetic Edit: ${ct.beats.length} nhịp vượt giới hạn ${Gt} clip — chọn đoạn ngắn hơn (start / duration)`);const gt=ct.beats[0].start,Z=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:St}=qt(dt,r,gt,Z,null);nt.push(St),dt=[...dt,{id:`probe${xt}`,kind:"image",track:St,start:gt,duration:Z-gt}]}const vt=(xt,St,jt,Kt,ee,le)=>{const xe=Fi(xt,{}),Ut=Dt();X.push(Ut),s.push({id:Ut,nodeId:"",kind:"image",url:"",label:ee,volume:0,track:le,start:jt,duration:Kt,motionKeys:[],motion:ko({code:Zw+xt,params:{...xe.params,...St},preset:xt})})};ct.beats.forEach((xt,St)=>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[St%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 At=0;for(const xt of ct.sfx){const St=da(xt.id);if(St)try{s.push(Bi(s,r,St,xt.at,{id:Dt()})),At++}catch{}}d.push(`Poox 1.1 (${ct.genre}): ${ct.lines} lines, ${ct.beats.length} beats, ${At} whooshes (${gt.toFixed(1)}–${Z.toFixed(1)} s)`);break}case"parallax":{const h=(p.clipIds||[]).filter(T=>y(T));if(h.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");const w=NE(s,h,{strength:at(p.numberValue)??1});for(const[T,C]of Object.entries(w))Object.assign(y(T),C);d.push(`parallax ${Object.keys(w).length} layers`);break}case"stations":{const h=(p.clipIds||[]).filter(T=>y(T));if(h.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");const w=LE(s,h,u,{style:p.preset??"fly-truck",travel:at(p.duration)??1,spacing:at(p.numberValue)??1.2,swing:p.booleanValue!==!1});for(const[T,C]of Object.entries(w.patches))Object.assign(y(T),C);u=w.camera,d.push(`stations ${p.preset??"fly-truck"}: camera flies through ${w.stations} stations`);break}case"arrange3D":{const h=(p.clipIds||[]).filter(T=>y(T));if(h.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");const w=ky(s,h,p.preset??"wall",{W:n.W||1280,H:n.H||720,spread:at(p.numberValue)??1});for(const[T,C]of Object.entries(w))Object.assign(y(T),C);d.push(`arrange3D ${p.preset??"wall"}: ${Object.keys(w).length} layers`);break}case"cameraTour":{const h=(p.clipIds||[]).filter(C=>y(C)),w=at(p.at)??Math.min(...h.map(C=>y(C).start)),T=xh(s,h,u,{at:Number.isFinite(w)?w:0,flight:at(p.duration)??1,hold:at(p.numberValue)??1.5,W:n.W||1280,H:n.H||720});u=T.camera,d.push(`cameraTour: ${h.length} layer(s) ${(Number.isFinite(w)?w:0).toFixed(1)}–${T.end.toFixed(1)} s`);break}case"addDevice":{const h=y(p.clipId);if(!h)throw Error(`Không tìm thấy clip ${p.clipId}`);if(r[h.track]?.locked)throw Error("Track đã khóa");const w=typeof p.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(p.color)?p.color:void 0,T=Ng(s,r,h,p.preset??"phone",{id:Dt(),color:w,pose:{scale:.8,modelRotation:{x:-6,y:-18,z:0}}});s.push(T.clip),X.push(T.clip.id),Object.assign(h,T.sourcePatch),d.push(`addDevice ${T.clip.device.type}: ${h.label||h.id} on screen (${T.clip.id})`);break}case"scene3D":{const h=(p.clipIds||[]).filter(T=>y(T));if(h.some(T=>r[y(T).track]?.locked))throw Error("Track đã khóa");if(ZE.includes(p.preset)){const T=QE(s,r,h,u,p.preset,{at:at(p.at)??void 0,newId:Dt,W:n.W||1280,H:n.H||720,duration:at(p.duration)??void 0,angle:at(p.numberValue)??void 0,angleTo:at(p.angleTo)??void 0,angleKeys:Array.isArray(p.angleKeys)?p.angleKeys:void 0,axis:p.axis==="y"?"y":p.axis==="x"?"x":void 0,anchor:["center","start","end"].includes(p.anchor)?p.anchor:void 0,media:o});for(const C of T.remove??[]){const O=s.findIndex(L=>L.id===C);O>=0&&s.splice(O,1)}for(const[C,O]of Object.entries(T.patches))Object.assign(y(C),O);for(const C of T.add)s.push(C),X.push(C.id);u=T.camera,d.push(`scene3D ${p.preset}: ${T.add.length} rig layer(s), to ${T.end.toFixed(1)} s`);break}if($y.includes(p.preset)){const T=typeof p.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(p.color)?p.color:void 0,C=eS(s,r,h,u,p.preset,{at:at(p.at)??void 0,newId:Dt,W:n.W||1280,H:n.H||720,duration:at(p.duration)??void 0,color:T,media:o});for(const[O,L]of Object.entries(C.patches))Object.assign(y(O),L);for(const O of C.add)s.push(O),X.push(O.id);u=C.camera,d.push(`scene3D ${p.preset}: ${C.add.length} rig layer(s), to ${C.end.toFixed(1)} s`);break}if(Yw.includes(p.preset)){const T=typeof p.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(p.color)?p.color:void 0,C=qw(s,r,h,u,p.preset,{at:at(p.at)??void 0,newId:Dt,color:T});for(const[O,L]of Object.entries(C.patches))Object.assign(y(O),L);for(const O of C.add)s.push(O),X.push(O.id);u=C.camera,d.push(`scene3D ${p.preset}: ${C.add.length} device(s), camera to ${C.end.toFixed(1)} s`);break}const w=GE(s,h,u,p.preset??"photo-wall-tour",{at:at(p.at)??void 0,W:n.W||1280,H:n.H||720});for(const[T,C]of Object.entries(w.patches))Object.assign(y(T),C);u=w.camera,d.push(`scene3D ${p.preset??"photo-wall-tour"}: ${Object.keys(w.patches).length} layers, camera to ${w.end.toFixed(1)} s`);break}case"anchorMontage":{s=a8(s,r,{clipIds:p.clipIds,at:at(p.at)??void 0,frames:at(p.numberValue)??void 0,polarity:p.booleanValue===!0,style:p.preset==="strobe"?"strobe":"anchor",newId:Dt}),d.push(`montage of ${p.clipIds.length} shots`);break}case"stagger":{const h=(p.clipIds||[]).filter(O=>y(O));if(h.length<2)throw Error("stagger needs at least 2 clipIds");if(h.some(O=>r[y(O).track]?.locked))throw Error("Track đã khóa");const w=Math.max(0,Math.min(10,at(p.numberValue)??.1)),T=["forward","reverse","center","random"].includes(p.order)?p.order:"forward",C=Ok(s,h,w,T,7);for(const O of C){const L=y(O.id);L&&L.start!==O.start&&(L.start=O.start)}d.push(`stagger ${h.length} layers by ${w}s (${T})`);break}case"alignLayers":{if(!Ck.includes(p.gridPoint))throw Error("Unknown grid point");const h=p.clipIds?.length?p.clipIds:p.clipId?[p.clipId]:[],w=n.W??1280,T=n.H??720;if(!h.length)throw Error("alignLayers needs clipIds");for(const C of h){const O=y(C);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,p.at!=null?at(p.at)-O.start:0));Object.assign(O,jk(O,n.rectOf?.(O)??Tk(O,L,w,T),p.gridPoint,ft(L),w,T))}d.push(`align ${h.length} layer(s) → ${p.gridPoint}`);break}case"physicsDrop":{const h=p.clipIds?.length?p.clipIds:p.clipId?[p.clipId]:[];if(!h.length)throw Error("physicsDrop needs clipIds");for(const O of h){const L=y(O);if(!L)throw Error("Clip not found");if(r[L.track]?.locked)throw Error("Track đã khóa")}const w=at(p.at)??Math.min(...h.map(O=>y(O).start)),T=at(p.numberValue),C=Ak(s,h,{at:w,W:n.W??1280,H:n.H??720,rectOf:n.rectOf,mode:p.mode==="above"?"above":"here",bounciness:T!=null?Math.max(0,Math.min(.95,T)):"normal",duration:at(p.duration)??3,walls:p.booleanValue===!0});s=s.map(O=>h.includes(O.id)?C.clips.find(L=>L.id===O.id)??O:O),d.push(`physics drop: ${h.length} layer(s) from ${ft(w)}s`);break}case"applyPalette":{const h=p.clipIds?.length?p.clipIds:p.clipId?[p.clipId]:[];if(!h.length)throw Error("applyPalette needs clipIds");for(const w of h){const T=y(w);if(!T)throw Error("Clip not found");if(r[T.track]?.locked)throw Error("Track đã khóa");Object.assign(T,Ik(T,p.colors))}d.push(`palette (${(p.colors||[]).length} colours) → ${h.length} layer(s)`);break}case"makeSeamless":{if(p.booleanValue===!1){d.push("seamless: off");break}const h=at(p.numberValue),w=Zh(s,r,u,{overlap:h!==null&&h>0&&h<=.6?h:void 0,accent:typeof p.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(p.color)?p.color:void 0,newId:Dt,...l});s=w.clips,u=w.camera,d.push(`seamless: ${w.notes.join("; ")}`);break}case"setJoin":{const h=z$(s,r,u,{join:at(p.numberValue),style:p.preset,duration:at(p.duration),ease:p.ease,newId:Dt,...l});if(s=h.clips,u=h.camera,d.push(`join ${at(p.numberValue)}: ${h.style}${typeof p.text=="string"&&p.text.trim()?` — ${p.text.trim().slice(0,200)}`:""}${h.notes.length>1?` (${h.notes.slice(1).join("; ")})`:""}`),p.booleanValue===!0&&typeof p.prompt=="string"&&p.prompt.trim().length>=6){if(g.length>=Rl)throw Error(`At most ${Rl} Claude motion jobs per request`);g.push({join:at(p.numberValue),prompt:p.prompt.trim().slice(0,1200)})}break}case"joinCut":{s=Uw(s,p.clipId,p.preset,{duration:at(p.duration)??void 0,color:typeof p.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(p.color)?p.color:void 0}),d.push(p.preset==="none"?`join removed: ${V}`:`join ${p.preset}: ${V}`);break}case"silhouetteReveal":{const h=Xw(s,r,p.clipId,{duration:at(p.duration)??void 0,newId:Dt});s=h.clips,$.push({clipId:h.copyId,mode:p.preset==="object"?"object":"person"}),d.push(`silhouette reveal: ${V}`);break}case"setJoinMotion":{const h=L$(s,r,u,{join:at(p.numberValue),code:p.code,params:p.params??{},prompt:p.prompt??"",duration:at(p.duration),newId:Dt,...l});s=h.clips,u=h.camera,d.push(`join ${at(p.numberValue)}: Claude Motion layer`);break}case"separateText":{const h=hh(s,{tracks:r});s=h.clips,d.push(`text guard: ${h.notes.length?h.notes.join("; "):"no overlapping text"}`);break}case"precompose":{const h=te(p),w=Array.isArray(h.clipIds)?h.clipIds:typeof h.clipId=="string"?[h.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=Dt();for(;y(T);)T=Dt();const C=rx(s,w,{id:T,label:typeof h.label=="string"&&h.label.trim()?h.label.trim().slice(0,80):nx(s),tracks:r,W:n.W||1280,H:n.H||720});s=C.clips,X.push(C.id),d.push(`precompose ${w.length} layer(s) → comp ${y(C.id).label} (${C.id}) on track ${C.track}`);break}case"uncompose":{const h=y(p.clipId);if(!nf(h))throw Error("uncompose needs a comp layer (clipId)");const w=ox(s,h.id,{tracks:r,W:n.W||1280,H:n.H||720,newId:Dt});s=w.clips,d.push(`uncompose ${h.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 h=(at(p.track)!==null?[at(p.track)]:[...new Set(s.map(w=>w.track))]).filter(w=>!r[w]?.locked);for(const w of h){let T=0;for(const C of s.filter(O=>O.track===w).sort((O,L)=>O.start-L.start))C.start=ft(T),T=ft(T+C.duration)}d.push(`compact ${at(p.track)!==null?"track "+p.track:"tất cả track"}`);break}case"courseEdit":throw Error(p.error||"courseEdit could not be built");case"framedEdit":throw Error(p.error||"framedEdit could not be built");case"updateMap":{const h=y(p.clipId);if(!h?.geo)throw Error("updateMap needs an animated map clip (addMap)");if(Array.isArray(p.places)&&!p.placesResolved)throw Error("updateMap places must be resolved first");const w=h.geo,T=w.plan??{},C=Array.isArray(p.places)?p.places:Sd(w),O=(st,Y)=>st??Y,L=Vg({places:C,duration:h.duration,style:O(p.mapStyle,w.style),route:O(p.route,T.route??!!w.route),routeLook:O(p.routeLook,T.routeLook??w.route?.look??"saber"),color:O(p.color,T.color??w.route?.color??"#ff3b30"),pins:O(p.pins,T.pins??w.pins.length>0),drawnRoute:p.routePoints!==void 0?p.routePoints:T.drawnRoute,drawnAreas:p.areas!==void 0?p.areas:T.drawnAreas,icons:Array.isArray(p.icons)?p.icons:w.icons??null}),B=p.models!==void 0?lg(p.models,o,C)??[]:w.models,H=p.images!==void 0?cg(p.images,o,C)??[]:w.images??[],q=p.buildings===void 0||p.buildings===null?w.buildings:p.buildings,et=s.indexOf(h);s[et]={...h,geo:Ad({...L,models:B,images:H,...w.hd?{hd:w.hd}:{},...q?{buildings:q}:{}},h.duration)},d.push(`map ${h.id}: ${L.stops.length} stop(s)${s[et].geo.buildings?", 3D buildings":""}${L.route?`, ${L.route.look} route`:""}${L.areas.length?`, ${L.areas.length} area(s)`:""}${B.length?`, ${B.length} model(s)`:""}${H.length?`, ${H.length} picture(s)`:""}${L.icons?.length?`, ${L.icons.length} icon(s)`:""}`);break}case"annotateMap":case"flyTo":case"setMapBounds":{const h=te(p),w=y(h.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(h.size)&&h.size.length===2&&h.size.every(B=>Number.isInteger(B)&&B>1&&B<=2e4)&&!w.mapSize&&(w.mapSize=[h.size[0],h.size[1]]),h.bounds!=null&&(w.mapBounds=Bk(h.bounds)),p.op==="setMapBounds"){if(h.bounds==null)throw Error("setMapBounds needs bounds [west, south, east, north]");d.push(`map bounds ${JSON.stringify(w.mapBounds)}`);break}const C=n.W||1280,O=n.H||720;if(p.op==="flyTo"){const B=_k(w,h,{W:C,H:O,cam:u});B.camera?u=B.camera:Object.assign(w,B.patch),d.push(B.applied);break}const L=Gk(h,{base:w,W:C,H:O,cam:u,materials:o});if(s.length+L.layers.length>Gt)throw Error(`Tối đa ${Gt} clip`);for(const B of L.layers){const{track:H}=qt(s,r,B.start,B.start+B.duration),q=Dt();if(X.push(q),h.kind==="icon"&&w.kind==="video"){const[et,st]=B.mapAnno.follow,Y=.07,ct={x:Math.max(0,Math.min(1-2*Y,et-Y)),y:Math.max(0,Math.min(1-2*Y,st-Y)),w:2*Y,h:2*Y},gt={...B,id:q,track:H},Z=ol(gt,w,{region:ct,mode:h.follow==="point"?"point":"scene",at:B.start});s.push({...gt,...Z}),S.push({clipId:q,...Z.pendingPin})}else s.push({...B,id:q,track:H})}d.push(`${L.applied} (${L.layers.length} layer${L.layers.length>1?"s":""}${h.kind==="icon"&&w.kind==="video"?", tracked on the footage once the editor opens":""})`);break}case"reglueMap":{s=of(s,u,n.W||1280,n.H||720),d.push("map items re-glued to the camera");break}case"meshWarp":case"puppet":case"liquify":case"displace":case"clearDistort":{const h=te(p),w=y(h.clipId);if(!w)throw Error(`Không tìm thấy layer ${h.clipId}`);if(!Kw(w))throw Error("Distort needs a video / picture / text / shape layer");const T={...w.distort||{}};if(p.op==="meshWarp"){const O=Math.round(at(h.rows)??3),L=Math.round(at(h.cols)??3),B=O*L,H=(Array.isArray(h.keys)?h.keys:[]).map(q=>{const et=q?.offsets??q?.d;if(et!=null&&(!Array.isArray(et)||et.length!==B))throw Error(`meshWarp offsets: ${B} [dx, dy] pairs (rows × cols, row by row)`);return{t:at(q?.t)??0,d:et==null?new Array(B*2).fill(0):et.flatMap(st=>Array.isArray(st)?[Number(st[0]),Number(st[1])]:[Number(st),NaN])}});T.mesh={rows:O,cols:L,keys:H.sort((q,et)=>q.t-et.t)},d.push(`mesh warp ${V}: ${O}×${L}, ${H.length} key${H.length===1?"":"s"}`)}else if(p.op==="puppet"){if(!Array.isArray(h.pins))throw Error("puppet needs pins [{u, v, dx?, dy?, keys?}]");T.puppet={pins:h.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)}:{}})),...at(h.stiff)!=null?{stiff:at(h.stiff)}:{}},d.push(`puppet ${V}: ${h.pins.length} pin${h.pins.length===1?"":"s"}`)}else if(p.op==="liquify"){if(!Array.isArray(h.strokes)||!h.strokes.length||h.strokes.length>200)throw Error("liquify needs strokes [{tool, points [[u,v]…], size?, pressure?}] (1–200)");for(const O of h.strokes)if(!Id.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 ${Id.join(" | ")}, points [[u,v]…] (0..1 of the picture)`);T.liquify=Vw(h.reset?null:T.liquify,h.strokes,{aspect:at(h.aspect)??1}),d.push(`liquify ${V}: ${h.strokes.length} stroke${h.strokes.length===1?"":"s"}`)}else if(p.op==="displace")if(h.mapClipId==null)delete T.displace,d.push(`displacement map off ${V}`);else{const O=y(h.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:at(h.x)??0,y:at(h.y)??0,...h.channel==="rg"?{channel:"rg"}:{},...Array.isArray(h.keys)?{keys:[...h.keys].map(L=>({t:L?.t,x:L?.x??0,y:L?.y??0})).sort((L,B)=>L.t-B.t)}:{}},d.push(`displacement map ${V} ← ${O.label||O.id} (${T.displace.x}, ${T.displace.y} px)`)}else{const O=h.tool??h.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];d.push(`distort off ${V}${O?` (${O})`:""}`)}const C=Ww(Hw(T));C?w.distort=C:delete w.distort,kn(w);break}default:throw Error(`Op không hỗ trợ: ${p?.op}`)}for(const h of[p?.clipId,...Array.isArray(p?.clipIds)?p.clipIds:[]]){const w=typeof h=="string"?y(h):null;if(nf(w)){const T=fk(w);if(T.length)throw Error(`not supported on a comp layer (${T.join(", ")}) — apply it to the layers inside the comp`)}}for(let h=ht;h<X.length;h++)x.push(D)}catch(V){X.length=ht,v.push(D),f.push(`${p?.op||"?"}: ${V.message}`)}}if(s=px(s),s.some(D=>D.mapAnno?.follow)&&(JSON.stringify(u)!==JSON.stringify(a)||it.some(D=>D?.op==="flyTo"||D?.op==="move"||D?.op==="setPropertyKeys"))&&(s=of(s,u,n.W||1280,n.H||720)),X.length){const D=new Set(X.filter(ht=>!s.find(yt=>yt.id===ht)?.mapAnno)),U=hh(s,{tracks:r,movable:D});U.notes.length&&(s=U.clips,d.push(`text guard: ${U.notes.join("; ")}`))}return N&&!m.length&&m.push({op:"setExportFormat",aspectRatio:N}),{clips:s,tracks:r,actions:m,motionJobs:g,applied:d,errors:f,failed:v,createdBy:x,camera:u,...F?{pins:F}:{},..._?{markers:_}:{},...K!==void 0?{exportRange:K}:{},...$.length?{cutouts:$}:{},...E.length?{mattes:E}:{},...k.length?{lookups:k}:{},...S.length?{surfacePins:S}:{}}}function qA(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,l=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(),c=/slide|push|wipe|whip|trượt|đẩy/.test(u)?"slide":/zoom|phóng/.test(u)?"zoom":"fade",s=at(e.duration)??at(e.spec?.duration)??((o.in??.5)+(o.out??.5))/2,d=Math.max(.1,Math.min(1,s/2)),f=c==="slide"?"slide-left":c==="zoom"?"zoom-in":"fade",m=c==="slide"?"slide-left":c==="zoom"?"zoom-out":"fade";return{clips:t.map(v=>v.id===a.id?fc(v,"exit",f,{duration:d}):l&&v.id===l.id?fc(v,"enter",m,{duration:d}):v),note:`${f} out${l?` / ${m} in on ${l.label||l.id}`:""} (no footage cut to transition)`}}const ZA=new Set(["addClip","placeBehindPerson","cutOutObject","annotateMap",...yb]);function Kj(t,e,o=[],r={},a=null,n={}){const i=Math.min(ac,n?.maxOps??nc);let l=(Array.isArray(e)?e:[]).slice(0,i).map((c,s)=>({op:c,index:s}));const u=[];for(let c=0;c<=i+1;c++){const s=Si(t,l.map(k=>k.op),o,r,a,n);if(!s.errors.length){if(u.length&&l.some(k=>Os.includes(k.op?.op))){for(const k of l.filter(y=>Os.includes(y.op?.op)))u.push({index:k.index,op:k.op?.op,error:"skipped: part of the plan could not be applied"});l=l.filter(k=>!Os.includes(k.op?.op));continue}return u.sort((k,y)=>k.index-y.index),{ops:l.map(k=>k.op),skipped:u,result:s}}const d=new Set(s.failed),f=new Map(s.failed.map((k,y)=>[k,s.errors[y]])),m=new Set(s.createdBy),g=l.map((k,y)=>y).filter(k=>m.has(k)||d.has(k)&&ZA.has(l[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;;){$=new Set([...d].filter(I=>!k.has(I))),S=new Set;for(let I=!0;I;)I=!1,l.forEach((z,j)=>{!$.has(j)&&v(z.op).some(P=>x(P)!==void 0&&$.has(x(P)))&&($.add(j),S.add(j),I=!0)});const y=g.filter(I=>!$.has(I));E=I=>{if(typeof I!="string"||!/^new:\d+$/.test(I))return I;const z=x(I);return z===void 0?I:`new:${y.indexOf(z)+1}`};const A=[...$].filter(I=>d.has(I)&&!S.has(I)&&!k.has(I)&&v(l[I].op).some(z=>E(z)!==z));if(!A.length)break;A.forEach(I=>k.add(I))}for(const k of[...$].sort((y,A)=>y-A))u.push({index:l[k].index,op:l[k].op?.op??"?",error:S.has(k)?`${l[k].op?.op??"?"}: targets a layer that could not be created`:f.get(k)});if(l=l.flatMap((k,y)=>$.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:E(k.op.clipId)}:{},...Array.isArray(k.op.clipIds)?{clipIds:k.op.clipIds.map(E)}:{}}:k.op}]),!l.length)break}return u.sort((c,s)=>c.index-s.index),{ops:[],skipped:u,result:null}}function bb(t,e,o,{insert:r=!1,makeId:a=Dt,tracks:n={}}={}){if(!Array.isArray(e)||!e.length)return{clips:t,pasted:[]};if(t.length+e.length>Gt)return{clips:t,pasted:[],error:`Tối đa ${Gt} 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)),l=Math.max(0,Number(o)||0),u=e.map(s=>({...s,id:a(),start:ft(l+(s.start-i))}));let c=t.map(s=>({...s}));if(r){const s={};for(const d of u)s[d.track]=Math.max(s[d.track]||0,ft(d.start+d.duration-l));for(const d of c)s[d.track]&&d.start>=l-1/(2*Me)&&(d.start=ft(d.start+s[d.track]))}return c=[...c,...u],c.some(s=>s.start+s.duration>He)?{clips:t,pasted:[],error:"Vượt giới hạn 20 phút"}:{clips:c,pasted:u.map(s=>s.id)}}let JA=0;function Dt(){try{return crypto.randomUUID()}catch{return`op-${Date.now()}-${JA++}`}}export{y0 as $,rM as A,Lx as B,pC as C,er as D,eM as E,CC as F,Z4 as G,g1 as H,AC as I,bv as J,QC as K,b5 as L,Ux as M,ej as N,JC as O,Wa as P,dv as Q,xv as R,Du as S,Zg as T,Ev as U,H5 as V,Sv as W,rj as X,e6 as Y,co as Z,n8 as _,Cx as a,GI as a$,b0 as a0,a8 as a1,Tr as a2,YS as a3,VS as a4,m0 as a5,z1 as a6,cj as a7,pj as a8,uj as a9,xj as aA,kj as aB,HC as aC,XC as aD,UC as aE,pv as aF,Wy as aG,Dn as aH,du as aI,Ih as aJ,Wi as aK,Aj as aL,nj as aM,qh as aN,Tv as aO,Yh as aP,hv as aQ,YC as aR,qC as aS,t0 as aT,lj as aU,sj as aV,pE as aW,tb as aX,LI as aY,yu as aZ,jj as a_,u5 as aa,p5 as ab,BC as ac,Do as ad,CM as ae,RC as af,_C as ag,DC as ah,LM as ai,zC as aj,Xh as ak,_1 as al,PC as am,LC as an,AM as ao,FC as ap,NC as aq,us as ar,Bu as as,Af as at,s5 as au,h1 as av,$c as aw,VC as ax,wC as ay,Mj as az,lC as b,Bi as b$,Cv as b0,Tn as b1,hm as b2,dm as b3,Z1 as b4,VE as b5,xy as b6,vy as b7,tS as b8,dj as b9,tM as bA,rm as bB,sv as bC,fC as bD,Qg as bE,tj as bF,kC as bG,Kj as bH,xC as bI,hC as bJ,dC as bK,j5 as bL,C4 as bM,E4 as bN,M1 as bO,o$ as bP,ym as bQ,r$ as bR,a$ as bS,l4 as bT,p4 as bU,Yo as bV,ry as bW,p1 as bX,yC as bY,aj as bZ,gC as b_,wy as ba,QE as bb,GE as bc,eS as bd,ky as be,xh as bf,fj as bg,nS as bh,zE as bi,hj as bj,by as bk,NE as bl,LE as bm,f3 as bn,_a as bo,mC as bp,vS as bq,gj as br,Py as bs,Ws as bt,jy as bu,xS as bv,mj as bw,_5 as bx,MC as by,P$ as bz,cC as c,Ej as c$,o5 as c0,X4 as c1,Vf as c2,Ju as c3,SC as c4,Wf as c5,IC as c6,EC as c7,Rc as c8,Jm as c9,zj as cA,Dj as cB,BA as cC,Lj as cD,Nj as cE,Fj as cF,Rj as cG,Tj as cH,Oj as cI,Pa as cJ,WC as cK,QM as cL,kE as cM,LA as cN,r0 as cO,xE as cP,Dp as cQ,Le as cR,Zs as cS,Ec as cT,OC as cU,jC as cV,lM as cW,TC as cX,H8 as cY,$j as cZ,Sj as c_,ZC as ca,ac as cb,a5 as cc,da as cd,Z3 as ce,bC as cf,H4 as cg,pm as ch,Iv as ci,oj as cj,h4 as ck,ij as cl,g5 as cm,C1 as cn,Of as co,wj as cp,Cj as cq,Gu as cr,Pj as cs,Gj as ct,mb as cu,$v as cv,bb as cw,eb as cx,_j as cy,Bj as cz,f1 as d,gp as d0,Ij as d1,vj as d2,KC as d3,Sc as d4,BM as d5,yj as d6,bj as d7,I5 as e,K5 as f,C5 as g,M5 as h,uC as i,z4 as j,e4 as k,k5 as l,vC as m,o4 as n,$C as o,Ox as p,r4 as q,W1 as r,f5 as s,Si as t,my as u,w0 as v,zf as w,M0 as x,GC as y,Ff as z};