clipoox-render 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/package.json +1 -1
  2. package/scripts/render-local.mjs +1322 -1320
  3. package/web/assets/{FxEmbed-CGqGi2Lw.js → FxEmbed-BCmj9Q5C.js} +1 -1
  4. package/web/assets/{MotionEmbed-C3CZ3_y_.js → MotionEmbed-CEmbcq8Z.js} +1 -1
  5. package/web/assets/PluginStore-C5hyahvG.js +3 -0
  6. package/web/assets/{ShotComposer-DFfaYLoV.js → ShotComposer-0DUtMTVI.js} +4 -4
  7. package/web/assets/{TemplateEmbed-C8pXcPsc.js → TemplateEmbed-ANxSs7H5.js} +1 -1
  8. package/web/assets/{TimelinePlugins-DnkV3i4G.js → TimelinePlugins-BYZ9y4m3.js} +4 -4
  9. package/web/assets/{TimelinePlugins-DYarX9RK.css → TimelinePlugins-D841ngau.css} +1 -1
  10. package/web/assets/{TimelineShotFx-foiuuogg.js → TimelineShotFx-q5PQwq-V.js} +2 -2
  11. package/web/assets/{TransitionEmbed-BueDilY0.js → TransitionEmbed-O6LInGWq.js} +1 -1
  12. package/web/assets/{Whiteboard-zBsNHh5h.js → Whiteboard-BP_DvIAV.js} +1 -1
  13. package/web/assets/{aerial-z34Nww_T.js → aerial-CGLDKKtP.js} +2 -2
  14. package/web/assets/{agentTools-ALxghYpf.js → agentTools-2Ghb80VH.js} +2 -2
  15. package/web/assets/{analyzerRun-DNwryAlU.js → analyzerRun-DRgxrcJA.js} +1 -1
  16. package/web/assets/{analyzerSandbox-A1oFsCrO.js → analyzerSandbox-DuIVFnsk.js} +1 -1
  17. package/web/assets/{api-DUp403BK.js → api-CJ8PdbfZ.js} +5 -5
  18. package/web/assets/{auraTrack-BKVZCwNt.js → auraTrack-DQw9sVU6.js} +1 -1
  19. package/web/assets/{breakthrough-Cwt8gEwK.js → breakthrough-BNj_iTDr.js} +2 -2
  20. package/web/assets/{cameraPresets-DSOPj4oy.js → cameraPresets-CYw0OdM3.js} +1 -1
  21. package/web/assets/{captionLayout-EuB59pN_.js → captionLayout-DvDPTwO9.js} +1 -1
  22. package/web/assets/{clientExport-BL1XMTF0.js → clientExport-xhoXY6Dh.js} +1 -1
  23. package/web/assets/conversion-4rhF3xRJ.js +17 -0
  24. package/web/assets/{depthEstimate-DOvsY8mn.js → depthEstimate-DEpeCojm.js} +1 -1
  25. package/web/assets/{directorTools-BkbNYbSq.js → directorTools-C5CpTmci.js} +1 -1
  26. package/web/assets/{distortFrames-Drch0LhT.js → distortFrames-Dia8O1NM.js} +2 -2
  27. package/web/assets/{distortGL-BlmBZKRU.js → distortGL-QalhICvi.js} +1 -1
  28. package/web/assets/{editTools-BcGinqHC.js → editTools-CY_JrQfw.js} +1 -1
  29. package/web/assets/engine-BedcnK45.js +1 -0
  30. package/web/assets/{exportEncode-MUwVTI52.js → exportEncode-QYsT9JBO.js} +1 -1
  31. package/web/assets/{exportGlb-SIXFRRJM.js → exportGlb-TSj09XoV.js} +1 -1
  32. package/web/assets/{faceTracker-DCbZbLMc.js → faceTracker-CnCWOwnJ.js} +1 -1
  33. package/web/assets/{fightDirector-hlF1JS_z.js → fightDirector-DCI_FWTh.js} +1 -1
  34. package/web/assets/{fightDrama-fHN5EXk3.js → fightDrama-Bg7uP_2Q.js} +2 -2
  35. package/web/assets/{frameSink-BvOXjLuw.js → frameSink-DeM8xC8_.js} +3 -3
  36. package/web/assets/{gpuCompose-CNkLwpbZ.js → gpuCompose-CA3UmOl4.js} +1 -1
  37. package/web/assets/{gpuExport-DQB6x4eh.js → gpuExport-D31azOQA.js} +13 -9
  38. package/web/assets/{handMatte-BD7OE3Zc.js → handMatte-Dl-xVXFR.js} +1 -1
  39. package/web/assets/{handTracker-BumGtRCW.js → handTracker-CplBsAFg.js} +2 -2
  40. package/web/assets/{id3-BCR9Bqgo.js → id3-arvEpAg7.js} +1 -1
  41. package/web/assets/{index-CuaB7Y0L.js → index-D5oyVCRl.js} +1 -1
  42. package/web/assets/index-_tSTJnL9.js +8 -0
  43. package/web/assets/layer-worker-DFuo32bk.js +5 -0
  44. package/web/assets/library-BufgA-Pl.js +1 -0
  45. package/web/assets/{lottieLayer-1ET89OUr.js → lottieLayer-DzbA3bHV.js} +4 -4
  46. package/web/assets/{lottie_light_canvas-DD9pkFL8.js → lottie_light_canvas-B-d7-ATe.js} +1 -1
  47. package/web/assets/main-VVYiW8XD.js +309 -0
  48. package/web/assets/{mapBake-DLoBt_k5.js → mapBake-BKOcEd0w.js} +1 -1
  49. package/web/assets/maskTrack-CHGXtBRy.js +1 -0
  50. package/web/assets/{matteFixRun-BdHKC3m5.js → matteFixRun-vgYrINet.js} +1 -1
  51. package/web/assets/{objectLocate-bZtc5AJo.js → objectLocate-BJltm8Ob.js} +1 -1
  52. package/web/assets/{output-BwZzMbp-.js → output-p-Q7qous.js} +1 -1
  53. package/web/assets/{pendingMatte-mlyLLZCT.js → pendingMatte-BPyzzx4y.js} +2 -2
  54. package/web/assets/{personAi-CUNQeseG.js → personAi-gJu03SjU.js} +2 -2
  55. package/web/assets/{plateCamera-_jP1xXnj.js → plateCamera-B2JvhjJw.js} +1 -1
  56. package/web/assets/{plateCameraMatch-rr0oUwQ2.js → plateCameraMatch-ByB9nVQT.js} +2 -2
  57. package/web/assets/{plateFollow-BjvtcT8q.js → plateFollow-C9S-l7RH.js} +2 -2
  58. package/web/assets/{plateMatte-BqyL8cQZ.js → plateMatte-J4qlNHnY.js} +2 -2
  59. package/web/assets/{pluginAutomation-Dp188qm7.js → pluginAutomation-CkP3tA9r.js} +1 -1
  60. package/web/assets/{poseTracker-DDGDhhMF.js → poseTracker-DGLbouqt.js} +1 -1
  61. package/web/assets/{productTools-CRgI88-O.js → productTools-CkaWF1bM.js} +2 -2
  62. package/web/assets/remote-C7J0Tqhb.js +1433 -0
  63. package/web/assets/{rigTrack-UYZU4P-e.js → rigTrack-urT3nDK0.js} +1 -1
  64. package/web/assets/{rotoMaskStore-BxyxB2bD.js → rotoMaskStore-DPziPKAN.js} +1 -1
  65. package/web/assets/{rotoMatte-BdYa8FSB.js → rotoMatte-C-2o3vv0.js} +1 -1
  66. package/web/assets/{rotoscope-DDixNQCt.js → rotoscope-GvPFRUBg.js} +1 -1
  67. package/web/assets/{shot-worker-D9sZS6bn.js → shot-worker-6dYkHPoL.js} +1 -1
  68. package/web/assets/{shotFxAgent-7RQNtEe4.js → shotFxAgent-BFLkqs8v.js} +1 -1
  69. package/web/assets/{skin-CVwmK130.js → skin-DY4QLaBI.js} +1 -1
  70. package/web/assets/{spark.module-B34aiScb.js → spark.module-DzziUgOj.js} +1 -1
  71. package/web/assets/{spellDuel-BkweL6pI.js → spellDuel-BD3m2ebA.js} +2 -2
  72. package/web/assets/store-Cug4GGcP.js +1 -0
  73. package/web/assets/{store-75tQUvPT.js → store-DW4E9xnW.js} +1 -1
  74. package/web/assets/{surfaceLight-DhU-zgNL.js → surfaceLight-aDSYU8Jg.js} +1 -1
  75. package/web/assets/surfacePin-m83hCgGP.js +2 -0
  76. package/web/assets/{textAnimators-nVSz_sZo.js → textAnimators-DUZjhVGO.js} +1 -1
  77. package/web/assets/{thumb-r6dlZprA.js → thumb-CS0ZuiGS.js} +1 -1
  78. package/web/assets/{timeline3d-246tBEJl.js → timeline3d-DOw-CpZI.js} +2 -2
  79. package/web/assets/{timeline3dExport-T57qnWi9.js → timeline3dExport-BtYLU1pw.js} +1 -1
  80. package/web/assets/{timelineComp-BcewYGR2.js → timelineComp-B4GtoH2f.js} +1 -1
  81. package/web/assets/{timelineProps-CJzzAWWO.js → timelineProps-D7MVutxu.js} +1 -1
  82. package/web/assets/{timelineText-BzUhNWPB.js → timelineText-BH09jfSM.js} +1 -1
  83. package/web/assets/{titleArt-B8DVR58F.js → titleArt-Drsrtfiv.js} +3 -3
  84. package/web/assets/{titleFrameBudget-BYRZAQPs.js → titleFrameBudget-CLZWaFHO.js} +1 -1
  85. package/web/assets/{titleFrames-BVgm601q.js → titleFrames-BI1DnLBn.js} +1 -1
  86. package/web/assets/{tool-CAGU3dUa.js → tool-DktQYmS6.js} +1 -1
  87. package/web/assets/{tools-DVaOkokV.js → tools-Co9aRDiT.js} +1 -1
  88. package/web/assets/{toonTools-CfGTR_H1.js → toonTools-CD9clJvN.js} +2 -2
  89. package/web/assets/{trackAnchor-DzUt1r5Q.js → trackAnchor-sOjTtd3I.js} +1 -1
  90. package/web/assets/{userFonts-DzY0A4bD.js → userFonts-CwlKh9NR.js} +1 -1
  91. package/web/assets/{vfxAlpha-DQJOaZ9v.js → vfxAlpha-71tSN86T.js} +2 -2
  92. package/web/assets/{vfxBackground-DiktQFOD.js → vfxBackground-Bq7lJvmZ.js} +2 -2
  93. package/web/assets/{videoExport-Ce0ElSQR.js → videoExport-D4KbireJ.js} +1 -1
  94. package/web/assets/{views-V3si1lOz.js → views-ozVF4ABO.js} +1 -1
  95. package/web/assets/{weaponDuel-D6sLVGmG.js → weaponDuel-ZhX-tjGZ.js} +1 -1
  96. package/web/assets/{windowFrames-D_2QJCJJ.js → windowFrames-CpqX3kOM.js} +1 -1
  97. package/web/layer-worker.html +3 -3
  98. package/web/assets/PluginStore-DKXZ-jBj.js +0 -3
  99. package/web/assets/index-DYa7fEK0.js +0 -24
  100. package/web/assets/layer-worker-DxPMMKIZ.js +0 -5
  101. package/web/assets/library-CyjJ8nGG.js +0 -1
  102. package/web/assets/main-BKjBWQik.js +0 -309
  103. package/web/assets/maskTrack-C2SJbDGO.js +0 -1
  104. package/web/assets/remote-Dva2qg58.js +0 -1241
  105. package/web/assets/surfacePin-ObK6QgDm.js +0 -2
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-DUp403BK.js","assets/titleFrameBudget-BYRZAQPs.js"])))=>i.map(i=>d[i]);
2
- import{PMREMGenerator as he,SRGBColorSpace as ke,Texture as de,CanvasTexture as le,Group as k,MeshStandardMaterial as B,Color as ue,BoxGeometry as q,Mesh as p,PlaneGeometry as N,CircleGeometry as pe,MeshBasicMaterial as Z,CylinderGeometry as Oe,ExtrudeGeometry as Ee,ShapeGeometry as Fe,Shape as Te,Vector3 as l,Euler as $,Quaternion as A,Matrix4 as H,PerspectiveCamera as me,Raycaster as fe,Vector2 as we,Plane as _,Scene as Le,WebGLRenderer as Ie,HemisphereLight as qe,DirectionalLight as De,NoToneMapping as Re,PCFShadowMap as je,ShadowMaterial as Ve,ACESFilmicToneMapping as _e,Box3 as P,AnimationMixer as Ge,Matrix3 as Be,BufferGeometry as ne,BufferAttribute as X,ShaderMaterial as We,Points as Ue,GridHelper as Ye,LoopRepeat as Xe,Line as Ke,LineBasicMaterial as Ne}from"./three.module-Bx43vjkH.js";import{G as se}from"./GLTFLoader-BHWu1lKg.js";import{az as Qe}from"./api-DUp403BK.js";import{lW as R,_ as Je,ee as K,lX as Ze,lY as $e,f9 as He,fb as et,cd as tt,fr as ye,fA as oe,fB as nt,lZ as st,l_ as ot,l$ as it,m0 as at,m1 as rt,m2 as ct,lV as ht}from"./titleFrameBudget-BYRZAQPs.js";import{R as ge}from"./RoomEnvironment-Dmv_G5ka.js";const dt=new Map;async function lt(a){try{const e=await(await Je(async()=>{const{signOutput:t}=await import("./api-DUp403BK.js").then(n=>n.c2);return{signOutput:t}},__vite__mapDeps([0,1]))).signOutput({gcsUri:a});return typeof e=="string"&&e?e:null}catch{return null}}function xe(a,e,t){const n=new Te,s=-a/2,o=-e/2;return t=Math.min(t,a/2,e/2),n.moveTo(s+t,o),n.lineTo(s+a-t,o),n.quadraticCurveTo(s+a,o,s+a,o+t),n.lineTo(s+a,o+e-t),n.quadraticCurveTo(s+a,o+e,s+a-t,o+e),n.lineTo(s+t,o+e),n.quadraticCurveTo(s,o+e,s,o+e-t),n.lineTo(s,o+t),n.quadraticCurveTo(s,o,s+t,o),n}function C(a,e,t){const n=new Fe(xe(a,e,t),12),s=n.attributes.uv,o=n.attributes.position;for(let i=0;i<s.count;i++)s.setXY(i,o.getX(i)/a+.5,o.getY(i)/e+.5);return n}function T(a,e,t,n,s=.012){const o=new Ee(xe(a-s*2,e-s*2,Math.max(.001,n-s)),{depth:t-s*2,bevelEnabled:!0,bevelThickness:s,bevelSize:s,bevelSegments:4,curveSegments:14});return o.translate(0,0,-(t-s*2)/2),o}const S=(a,e=.32)=>new B({color:a,metalness:.85,roughness:e}),G=()=>new B({color:"#050506",metalness:.2,roughness:.08}),ie=a=>new B({color:a,metalness:.1,roughness:.75}),W=()=>new Z({color:"#ffffff",toneMapped:!1});function ae(a,{w:e,h:t,d:n,r:s,bezel:o,island:i,lenses:r}){const c=new k;c.add(new p(T(e,t,n,s),S(a)));const h=new p(C(e-.012,t-.012,s-.006),G());h.position.z=n/2+.0015,c.add(h);const m=e-o*2,d=t-o*2,f=new p(C(m,d,Math.max(.01,s-o)),W());if(f.position.z=n/2+.003,c.add(f),i){const u=new p(C(m*.3,d*.032,d*.016),new Z({color:"#000"}));u.position.set(0,d/2-d*.035,n/2+.004),c.add(u)}if(r){const u=new p(T(e*.42,e*.42,.02,e*.1,.006),G());u.position.set(-e/2+e*.27,t/2-e*.27,-n/2-.008),c.add(u);for(let g=0;g<r;g++){const M=g*2*Math.PI/Math.max(1,r)+.6,x=new p(new Oe(e*.075,e*.08,.018,28),S("#2a2a2c",.2));x.rotation.x=Math.PI/2,x.position.set(u.position.x+Math.cos(M)*e*.09,u.position.y+Math.sin(M)*e*.09,-n/2-.022),c.add(x);const w=new p(new pe(e*.05,24),G());w.rotation.y=Math.PI,w.position.set(x.position.x,x.position.y,-n/2-.0315),c.add(w)}}for(const[u,g]of[[t*.22,t*.08],[t*.09,t*.08]]){const M=new p(new q(.008,g,n*.35),S(a));M.position.set(-e/2-.002,u,0),c.add(M)}const v=new p(new q(.008,t*.12,n*.35),S(a));return v.position.set(e/2+.002,t*.14,0),c.add(v),{object:c,screen:f,screenAspect:m/d}}function ut(a,e){const t=new k,n=1.8,s=1.22,o=.045,i=new p(T(n,s,o,.06),S(a));i.rotation.x=-Math.PI/2,t.add(i);const r=new p(C(n*.86,s*.42,.02),ie("#111214"));r.rotation.x=-Math.PI/2,r.position.set(0,o/2+.001,-s*.15),t.add(r);const c=new q(n*.86/15*.82,.006,s*.42/6*.78),h=ie("#1b1c1f");for(let O=0;O<6;O++)for(let E=0;E<15;E++){const F=new p(c,h);F.position.set(-n*.43+(E+.5)*n*.86/15,o/2+.004,-s*.15-s*.21+(O+.5)*s*.42/6),t.add(F)}const m=new p(C(n*.36,s*.26,.025),S(a,.5));m.rotation.x=-Math.PI/2,m.position.set(0,o/2+.0012,s*.27),t.add(m);const d=new k;d.position.set(0,o/2,-s/2),t.add(d);const f=1.16,v=.022,u=new k;u.position.set(0,f/2,0),d.add(u),u.add(new p(T(n,f,v,.05),S(a)));const g=new p(C(n-.01,f-.01,.045),G());g.position.z=v/2+.0015,u.add(g);const M=n-.09,x=f-.1,w=new p(C(M,x,.012),W());w.position.set(0,.01,v/2+.003),u.add(w);const y=new p(new pe(.07,40),S("#e9e9ea",.15));y.rotation.y=Math.PI,y.position.z=-v/2-.002,u.add(y);const z=Math.max(0,Math.min(1,e));return d.rotation.x=(1-z)*Math.PI/2-z*.26,{object:t,screen:w,screenAspect:M/x}}function pt(a){const e=new k,t=1.8,n=1.04,s=.035;e.add(new p(T(t,n,s,.02,.006),S(a,.45)));const o=t-.04,i=n-.04,r=new p(C(o,i,.006),W());r.position.z=s/2+.002,e.add(r);const c=new p(new q(.12,.32,.04),S(a,.4));c.position.set(0,-n/2-.14,-.05),e.add(c);const h=new p(T(.62,.26,.025,.08,.006),S(a,.4));return h.rotation.x=-Math.PI/2,h.position.set(0,-n/2-.3,-.02),e.add(h),{object:e,screen:r,screenAspect:o/i}}function mt(a){const e=new k,t=1.2,n=1.6,s=.42,o=new B({color:new ue(a).multiplyScalar(.62),metalness:0,roughness:.85}),i=new q(t,n,s);e.add(new p(i,o));const r=new p(new N(t*.98,n*.98),W());return r.position.z=s/2+.002,e.add(r),{object:e,screen:r,screenAspect:t/n}}function ft(a){const e=a.color??(a.type==="box"?R.white:a.type==="tv"?R.black:a.type==="laptop"?R.silver:R.titanium);switch(a.type){case"phone":return ae(e,{w:.83,h:1.8,d:.075,r:.13,bezel:.032,island:!0,lenses:3});case"tablet":return ae(e,{w:1.35,h:1.8,d:.06,r:.09,bezel:.05,island:!1,lenses:1});case"laptop":return ut(e,a.open??1);case"tv":return pt(e);default:return mt(e)}}const re=new WeakMap;function wt(a){let e=re.get(a);if(!e){const t=new he(a);e=t.fromScene(new ge,0,.1,100,{size:64}).texture,t.dispose(),re.set(a,e)}return e}class yt{constructor(e,t,n){this.mesh=e,this.aspect=t,this.media=n;const s=o=>n.kind==="video"?this.loadVideo(o):this.loadImage(o);this.ready=n?.url?s(n.url).catch(async o=>{const i=n.gcsUri?await lt(n.gcsUri):null;if(!i||i===n.url)throw o;return s(i)}):Promise.resolve(),n?.url||e.material.color.set("#0d0f12")}texture=null;video=null;ready;whenReady(){return this.ready}fit(e,t){const n=this.texture,s=e/t;s>this.aspect?(n.repeat.set(this.aspect/s,1),n.offset.set((1-this.aspect/s)/2,0)):(n.repeat.set(1,s/this.aspect),n.offset.set(0,(1-s/this.aspect)/2))}apply(e,t,n){e.colorSpace=ke,e.anisotropy=4,this.texture=e,this.fit(t,n);const s=this.mesh.material;s.map=e,s.needsUpdate=!0}loadImage(e){return new Promise((t,n)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>{this.apply(new de(s),s.naturalWidth,s.naturalHeight),this.texture.needsUpdate=!0,t()},s.onerror=()=>n(Error("Không tải được ảnh màn hình thiết bị")),s.src=e})}canvas=null;draw(){const e=this.video,t=this.canvas;!e||!t||e.readyState<2||(t.getContext("2d").drawImage(e,0,0,t.width,t.height),this.texture&&(this.texture.needsUpdate=!0))}loadVideo(e){const t=document.createElement("video");return t.crossOrigin="anonymous",t.muted=!0,t.playsInline=!0,t.preload="auto",this.video=t,new Promise((n,s)=>{t.onloadeddata=()=>{const o=Math.min(1,1280/Math.max(t.videoWidth,t.videoHeight)),i=document.createElement("canvas");i.width=Math.max(2,Math.round(t.videoWidth*o)),i.height=Math.max(2,Math.round(t.videoHeight*o)),this.canvas=i,this.apply(new le(i),t.videoWidth,t.videoHeight),this.draw(),n()},t.onerror=()=>s(Error("Không tải được video màn hình thiết bị")),t.src=e})}async sync(e,t=!1){const n=this.video,s=this.media;if(!n||!s||!this.texture)return;const o=Number.isFinite(n.duration)&&n.duration>0?n.duration:0;let i=(s.inPoint||0)+Math.max(0,e)*(s.speed||1);if(o&&(i=Math.min(i,o-.04)),Math.abs(n.currentTime-i)>(t?.004:.12)){const r=new Promise(c=>{const h=()=>{n.removeEventListener("seeked",h),c()};n.addEventListener("seeked",h),setTimeout(h,t?4e3:600)});if(n.currentTime=i,t)await r;else{r.then(()=>this.draw());return}}this.draw()}dispose(){this.texture?.dispose(),this.video&&(this.video.removeAttribute("src"),this.video.load(),this.video=null)}}const gt=1.8,b=Math.PI/180;function I(a,e,t,n,s){if(He(t)&&a.is3D!==!1){const o=ye(n,s),i=et(t,a.start+Math.max(0,e),n,s),r=c=>new l(i.R[0][c],-i.R[1][c],-i.R[2][c]);return{pos:new l(i.pos[0]/o,-i.pos[1]/o,-i.pos[2]/o),quat:new A().setFromRotationMatrix(new H().makeBasis(r(0),r(1).negate(),r(2).negate())),fov:2*Math.atan(s/2/i.f)/b,on:!0}}return{pos:new l(0,0,5),quat:new A,fov:40,on:!1}}function Q(a,e,t,n,s){const o=tt(a,Math.max(0,e),n,s);if(t.on){const r=ye(n,s);return{pos:new l(o.x*n/r,-o.y*s/r,o.depth),zoom:o.zoom}}const i=2*(5-o.depth)*Math.tan(t.fov*b/2);return{pos:new l(o.x*i*(n/s),-o.y*i,o.depth),zoom:o.zoom}}function ve(a){const e=a.modelRotation||{x:0,y:0,z:0};return new l(0,1,0).applyEuler(new $(e.x*b,e.y*b,e.z*b)).normalize()}function Me(a,e,t,n,s){const o=Math.min(48,Math.max(2,Math.ceil(a.duration/.1)));let i=1/0;for(let r=0;r<=o;r++){const c=a.duration*r/o;i=Math.min(i,Q(a,c,I(a,c,t,n,s),n,s).pos.dot(e))}return i}function xt(a,e,t,n,s,o){const i=new me(a.fov,s/o,.01,100);i.position.copy(a.pos),i.quaternion.copy(a.quat),i.updateMatrixWorld(!0),i.updateProjectionMatrix();const r=new fe;return r.setFromCamera(new we(e[0]*2-1,1-e[1]*2),i),r.ray.intersectPlane(new _(t.clone(),-n),new l)}function vt(a,e,t,n,s,o,i){const r=I(a,e,t,n,s),{pos:c,zoom:h}=Q(a,e,r,n,s),m={x:K(a,"rx",e),y:K(a,"ry",e),z:K(a,"rz",e)},d=a.modelSpin||{x:0,y:0,z:0},f=(a.inPoint||0)+e,v=new $((m.x+d.x*f)*b,(m.y+d.y*f)*b,(m.z+d.z*f)*b),u=ve(a),g=gt*h,x=!!a.modelLaunch||!!a.modelLook?i??Me(a,u,t,n,s):null,w=a.modelLaunch,y=w?Ze(w,e):null;if(w&&y){const E=Q(a,w.at,I(a,w.at,t,n,s),n,s).pos,F=E.clone().addScaledVector(u,x-E.dot(u)),ee=xt(I(a,w.at+w.duration,t,n,s),w.to,u,x,n,s)??F.clone(),ze=F.clone().lerp(ee,y.g),L=ee.clone().sub(F);L.addScaledVector(u,-L.dot(u));const Ae=$e(y,L.length()/g);let D;if(w.face!==!1&&L.lengthSq()>1e-8){const Y=L.normalize(),te=new l().crossVectors(u,Y).normalize(),Ce=new l().crossVectors(Y,te);D=new A().setFromRotationMatrix(new H().makeBasis(te,Ce,Y))}else D=new A().setFromEuler(v);D.multiply(new A().setFromAxisAngle(new l(1,0,0),-Ae*b)).multiply(new A().setFromAxisAngle(new l(0,0,1),y.roll*b));const U=y.jolt*.035*g,Pe=new l(Math.sin(e*91)*U,Math.sin(e*67+1)*U*.6,Math.sin(e*53+2)*U);return{cam:r,pos:ze.addScaledVector(u,o*h+y.h*g).add(Pe),quat:D,zoom:h,N:u,d:x,len:g}}const z=new A().setFromEuler(v),O=c.clone();return a.modelGround&&O.add(new l(0,1,0).applyQuaternion(z).multiplyScalar(o*h)),{cam:r,pos:O,quat:z,zoom:h,N:u,d:x,len:g}}function Mt(a,e,t){const n=new l(1,0,0).applyQuaternion(t.quat),o=e.clone().cross(n).normalize().clone().negate(),i=new l().crossVectors(e,o).normalize(),r=a.azimuth*b,c=a.elevation*b;return o.multiplyScalar(Math.cos(c)*Math.cos(r)).addScaledVector(i,Math.cos(c)*Math.sin(r)).addScaledVector(e,Math.sin(c)).normalize()}const be=new Map,J=new Set,bt=a=>a?be.get(a):void 0;function St(a){return J.add(a),()=>{J.delete(a)}}const ce=(a,e)=>a.name||`Animation ${e+1}`,Se=new Map,zt=a=>a?Se.get(a):void 0,j=600,At="attribute float aAlpha;attribute float aSize;varying float vA;uniform float uScale;void main(){vA=aAlpha;vec4 mv=modelViewMatrix*vec4(position,1.);gl_PointSize=aSize*uScale/max(.05,-mv.z);gl_Position=projectionMatrix*mv;}",Pt="uniform vec3 uColor;varying float vA;void main(){vec2 d=gl_PointCoord-.5;float r=length(d);if(r>.5)discard;gl_FragColor=vec4(uColor,vA*smoothstep(.5,.05,r));}";let V=null;function Ct(){if(V)return V;const a=document.createElement("canvas");a.width=a.height=128;const e=a.getContext("2d"),t=e.createRadialGradient(64,64,0,64,64,64);return t.addColorStop(0,"rgba(0,0,0,1)"),t.addColorStop(.35,"rgba(0,0,0,.75)"),t.addColorStop(.7,"rgba(0,0,0,.22)"),t.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=t,e.fillRect(0,0,128,128),V=new le(a),V}class kt{canvas;renderer;scene=new Le;camera=new me(40,1,.01,100);halfY=0;group=new k;disposed=!1;mixer=null;clips=[];action=null;rest=[];width;height;screen=null;pieces=[];dust=null;cut=[new _,new _];guides=null;buildOn=!1;constructor(e,t){this.width=e,this.height=t,this.renderer=new Ie({alpha:!0,antialias:!0,preserveDrawingBuffer:!0}),this.renderer.setPixelRatio(1),this.renderer.setSize(e,t,!1),this.renderer.setClearColor(0,0),this.canvas=this.renderer.domElement,this.camera.aspect=e/t,this.camera.position.set(0,0,5),this.camera.lookAt(0,0,0),this.camera.updateProjectionMatrix(),this.scene.add(this.group,this.hemi,this.key,this.key.target),this.key.position.set(3,5,5)}hemi=new qe(16777215,7829367,3);key=new De(16777215,3);catcher=null;contact=null;lookEnv=null;lookOn=!1;groundCache=null;applyLook(e){const t=this.renderer;if(!e){if(!this.lookOn)return;this.lookOn=!1,t.shadowMap.enabled=!1,t.toneMapping=Re,t.toneMappingExposure=1,this.hemi.color.set(16777215),this.hemi.groundColor.set(7829367),this.hemi.intensity=3,this.key.color.set(16777215),this.key.intensity=3,this.key.castShadow=!1,this.key.position.set(3,5,5),this.key.target.position.set(0,0,0),this.scene.environment===this.lookEnv&&(this.scene.environment=null),this.catcher&&(this.catcher.visible=!1),this.contact&&(this.contact.visible=!1);return}if(!this.lookOn&&(this.lookOn=!0,t.shadowMap.enabled=!0,t.shadowMap.type=je,this.key.castShadow=!0,this.key.shadow.mapSize.set(2048,2048),this.key.shadow.bias=-4e-4,this.key.shadow.normalBias=.02,this.group.traverse(n=>{const s=n;s.isMesh&&(s.castShadow=!0,s.receiveShadow=!0)}),this.catcher||(this.catcher=new p(new N(1,1),new Ve({opacity:.4,depthWrite:!1})),this.catcher.receiveShadow=!0,this.catcher.renderOrder=-2,this.scene.add(this.catcher)),this.contact||(this.contact=new p(new N(1,1),new Z({map:Ct(),transparent:!0,depthWrite:!1,color:0})),this.contact.renderOrder=-1,this.scene.add(this.contact)),!this.lookEnv&&!this.screen)){const n=new he(t);this.lookEnv=n.fromScene(new ge,.04,.1,100,{size:128}).texture,n.dispose()}t.toneMapping=_e,t.toneMappingExposure=e.exposure,!this.screen&&this.lookEnv&&(this.scene.environment=this.lookEnv),this.scene.environmentIntensity=e.env,this.hemi.color.set(e.ambient),this.hemi.groundColor.set(e.ambient).multiplyScalar(.45),this.hemi.intensity=e.ambientIntensity,this.key.color.set(e.color),this.key.intensity=e.intensity,this.key.shadow.radius=1+e.softness*9,this.key.shadow.blurSamples=8+Math.round(e.softness*16),this.catcher.material.opacity=e.shadow,this.catcher.visible=e.shadow>0}groundFor(e,t){const n=JSON.stringify([e.id,e.start,e.duration,e.posX,e.posY,e.spatialDepth,e.modelDepth,e.scale,e.motionKeys,e.modelRotation,e.parentId,t?JSON.stringify(t):""]);if(this.groundCache?.key===n)return this.groundCache.d;const s=Me(e,ve(e),t,this.width,this.height);return this.groundCache={key:n,d:s},s}async load(e){const t=await Qe(e);this.add(await new se().loadAsync(t),e)}async loadBuffer(e,t){this.add(await new se().parseAsync(e,""),t)}async loadDevice(e){if(!e.device)throw Error("Không phải thiết bị 3D");const t=ft(e.device);this.scene.environment=wt(this.renderer),this.addObject(t.object),!this.disposed&&(this.screen=new yt(t.screen,t.screenAspect,e.deviceScreen),await this.screen.whenReady())}async prepare(e){await this.screen?.sync(e,!0)}addObject(e){if(this.disposed){this.disposeObject(e);return}const t=new P().setFromObject(e),n=t.getSize(new l),s=Math.max(n.x,n.y,n.z);e.scale.setScalar(1.8/s),e.updateMatrixWorld(!0),this.halfY=n.y*1.8/s/2,e.position.sub(new P().setFromObject(e).getCenter(new l)),e.updateMatrixWorld(!0),this.group.add(e)}add(e,t){if(this.disposed){this.disposeObject(e.scene);return}const s=new P().setFromObject(e.scene).getSize(new l),o=Math.max(s.x,s.y,s.z);if(!Number.isFinite(o)||o<=0)throw Error("GLB không có hình học hợp lệ");e.scene.scale.setScalar(1.8/o),e.scene.updateMatrixWorld(!0);const i=new P().setFromObject(e.scene).getCenter(new l);e.scene.position.sub(i),e.scene.updateMatrixWorld(!0),this.halfY=s.y*1.8/o/2,this.group.add(e.scene),this.clips=e.animations||[],this.clips.length&&(this.mixer=new Ge(e.scene),e.scene.traverse(r=>{r!==e.scene&&this.rest.push({o:r,p:r.position.clone(),q:r.quaternion.clone(),s:r.scale.clone()})})),this.collectPieces(e.scene),Se.set(t,this.pieces.length),be.set(t,this.clips.map((r,c)=>({name:ce(r,c),duration:r.duration}))),J.forEach(r=>r())}collectPieces(e){this.group.updateMatrixWorld(!0);const t=[];e.traverse(c=>{c.isMesh&&t.push(c)});const n=new P().setFromObject(e),s=c=>{const h=c.getSize(new l);return h.x*h.y*h.z},o=s(n)*.02,i=n.getSize(new l),r=i.x*i.z;for(const c of t.slice(0,oe.maxPieces)){const h=new P().setFromObject(c),m=h.getCenter(new l),d=h.getSize(new l),f=new H().copy(c.parent.matrixWorld).invert();this.pieces.push({o:c,p:c.position.clone(),q:c.quaternion.clone(),s:c.scale.clone(),toParent:new Be().setFromMatrix4(f),box:{bottom:h.min.y,cx:m.x,cz:m.z,h:d.y,r:Math.max(d.x,d.z)/2,big:s(h)>o,base:d.x*d.z>=r*.25&&h.min.y<=n.min.y+i.y*.03}})}}build(e,t){let n=null;try{n=e.modelBuild?nt(e.modelBuild):null}catch{n=null}const s=new Set;this.group.traverse(i=>{const r=i.material;if(r)for(const c of Array.isArray(r)?r:[r])s.add(c)});const o=[];if(n){const i=st(this.pieces.map(h=>h.box),n);this.pieces.forEach((h,m)=>{const d=ot(n.style,h.box,i[m],t,m,n.seed);h.o.position.copy(h.p),h.o.quaternion.copy(h.q),h.o.scale.copy(h.s),h.o.visible=d.visible,(d.dx||d.dy||d.dz)&&h.o.position.add(new l(d.dx,d.dy,d.dz).applyMatrix3(h.toParent)),(d.rx||d.ry||d.rz)&&h.o.quaternion.multiply(new A().setFromEuler(new $(d.rx,d.ry,d.rz)))}),this.group.updateMatrixWorld(!0);const r=new l(0,1,0).applyQuaternion(this.group.getWorldQuaternion(new A)).normalize();it(n,t)&&o.push(this.cut[0].setFromNormalAndCoplanarPoint(r,this.group.localToWorld(new l(0,-this.halfY,0))));const c=at(n,t,this.halfY);c!==null&&o.push(this.cut[1].setFromNormalAndCoplanarPoint(r.clone().negate(),this.group.localToWorld(new l(0,c,0)))),this.dustAt(rt(this.pieces.map(h=>h.box),i,n,t,j),n.dustColor),this.buildOn=!0}else{for(const i of this.pieces)i.o.position.copy(i.p),i.o.quaternion.copy(i.q),i.o.scale.copy(i.s),i.o.visible=!0;this.dustAt([],oe.dustColor),this.buildOn=!1}this.renderer.localClippingEnabled=o.length>0;for(const i of s){const r=o.length?o:null;i.clippingPlanes!==r&&(i.clippingPlanes?.length||r)&&(i.clippingPlanes=r,i.needsUpdate=!0)}}dustAt(e,t){if(!e.length&&!this.dust)return;if(!this.dust){const r=new ne;r.setAttribute("position",new X(new Float32Array(j*3),3)),r.setAttribute("aAlpha",new X(new Float32Array(j),1)),r.setAttribute("aSize",new X(new Float32Array(j),1));const c=new We({uniforms:{uColor:{value:new ue(t)},uScale:{value:this.height*1.2}},vertexShader:At,fragmentShader:Pt,transparent:!0,depthWrite:!1});this.dust=new Ue(r,c),this.dust.frustumCulled=!1,this.group.add(this.dust)}const n=this.dust.geometry,s=n.getAttribute("position"),o=n.getAttribute("aAlpha"),i=n.getAttribute("aSize");e.forEach((r,c)=>{s.setXYZ(c,r[0],r[1],r[2]),o.setX(c,r[3]),i.setX(c,r[4])}),n.setDrawRange(0,e.length),s.needsUpdate=o.needsUpdate=i.needsUpdate=!0,this.dust.material.uniforms.uColor.value.set(t)}setGuides(e,t=4){if(!e){this.guides&&(this.scene.remove(this.guides),this.disposeObject(this.guides),this.guides=null);return}if(this.guides)return;const n=new k,s=new Ye(t,16,6742271,2781056);s.rotation.x=Math.PI/2;for(const i of Array.isArray(s.material)?s.material:[s.material])i.transparent=!0,i.opacity=.85,i.depthWrite=!1;const o=(i,r)=>new Ke(new ne().setFromPoints([new l,i]),new Ne({color:r}));n.add(s,o(new l(.5,0,0),16731469),o(new l(0,.5,0),5111674),o(new l(0,0,.5),5086207)),this.guides=n,this.scene.add(n)}surfaceAt(e,t){const n=new fe;n.setFromCamera(new we(e/this.width*2-1,1-t/this.height*2),this.camera);const s=n.ray.intersectPlane(new _(new l(0,0,1),0),new l);return s?{x:s.x,y:s.y}:null}pose(e,t){if(!this.mixer)return;const n=e.modelAnim,s=n?this.clips.find((i,r)=>ce(i,r)===n.clip):void 0;if(!n||!s){if(this.action){this.mixer.stopAllAction(),this.action=null;for(const i of this.rest)i.o.position.copy(i.p),i.o.quaternion.copy(i.q),i.o.scale.copy(i.s)}return}const o=this.mixer.clipAction(s);this.action!==o&&(this.mixer.stopAllAction(),o.setLoop(Xe,1/0),o.play(),this.action=o),o.time=ct(n,s.duration,t,e.inPoint||0),this.mixer.update(0)}render(e,t,n=!1,s){const o=e.modelLook?ht(e.modelLook):null;this.applyLook(o);const i=this.width,r=this.height,c=e.modelLook||e.modelLaunch?this.groundFor(e,s):void 0,h=vt(e,t,s,i,r,this.halfY,c);this.camera.position.copy(h.cam.pos),this.camera.quaternion.copy(h.cam.quat),this.camera.fov=h.cam.fov,this.camera.updateProjectionMatrix(),this.camera.updateMatrixWorld(!0),this.group.scale.setScalar(h.zoom),this.group.quaternion.copy(h.quat),this.group.position.copy(h.pos),this.pose(e,t),(e.modelBuild||this.buildOn)&&this.build(e,t),o&&this.placeShadows(e,o,h.N,h.d??0,h.len,s),n&&this.screen?.sync(t),this.renderer.render(this.scene,this.camera),n&&this.publish(e.id)}placeShadows(e,t,n,s,o,i){const r=this.group.getWorldPosition(new l),c=r.dot(n)-s,h=r.clone().addScaledVector(n,-c),m=new A().setFromUnitVectors(new l(0,0,1),n),d=Math.max(0,c-this.halfY*this.group.scale.x),f=Math.max(6*o,d*4+3*o);this.catcher.position.copy(h).addScaledVector(n,.001*o),this.catcher.quaternion.copy(m),this.catcher.scale.set(f,f,1);const v=new P().setFromObject(this.group),u=v.getSize(new l),g=Math.max(.2*o,Math.hypot(u.x,u.y,u.z)-Math.abs(u.clone().dot(n)))*.62,M=Math.max(0,1-d/(.8*o));this.contact.visible=t.contact>0&&M>0,this.contact.position.copy(h).addScaledVector(n,.002*o),this.contact.quaternion.copy(m),this.contact.scale.set(g*(1+d/o),g*.75*(1+d/o),1),this.contact.material.opacity=t.contact*.85*M;const x=Mt(t,n,I(e,0,i,this.width,this.height)),w=12*o;this.key.target.position.copy(h),this.key.position.copy(h).addScaledVector(x,w),this.key.target.updateMatrixWorld();const y=this.key.shadow.camera,z=f*.6;y.left=-z,y.right=z,y.top=z,y.bottom=-z,y.near=Math.max(.01,w-4*o-d),y.far=w+4*o+d,y.updateProjectionMatrix()}publish(e){const t=new P().setFromObject(this.group);if(t.isEmpty())return;let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const r of[t.min.x,t.max.x])for(const c of[t.min.y,t.max.y])for(const h of[t.min.z,t.max.z]){const m=new l(r,c,h).project(this.camera),d=(m.x+1)/2*this.width,f=(1-m.y)/2*this.height;n=Math.min(n,d),o=Math.max(o,d),s=Math.min(s,f),i=Math.max(i,f)}dt.set(e,{cx:(n+o)/2,cy:(s+i)/2,w:o-n,h:i-s,angle:0,W:this.width,H:this.height})}async frame(e){const t=await new Promise(o=>(e??this.canvas).toBlob(o,"image/webp",.8));if(!t)throw Error("Không xuất được frame 3D");const n=new Uint8Array(await t.arrayBuffer());let s="";for(let o=0;o<n.length;o+=16384)s+=String.fromCharCode(...n.subarray(o,o+16384));return btoa(s)}disposeObject(e){e.traverse(t=>{const n=t;n.geometry?.dispose();for(const s of n.material?Array.isArray(n.material)?n.material:[n.material]:[]){for(const o of Object.values(s))o instanceof de&&o.dispose();s.dispose()}})}dispose(){this.disposed=!0,this.screen?.dispose(),this.screen=null,this.mixer?.stopAllAction(),this.disposeObject(this.group),this.renderer.dispose(),this.canvas.remove()}}const It=Object.freeze(Object.defineProperty({__proto__:null,Timeline3DScene:kt,modelAnimations:bt,modelPieces:zt,onModelAnimations:St},Symbol.toStringTag,{value:"Module"}));export{kt as T,zt as a,dt as l,bt as m,St as o,It as t};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-CJ8PdbfZ.js","assets/titleFrameBudget-CLZWaFHO.js"])))=>i.map(i=>d[i]);
2
+ import{PMREMGenerator as he,SRGBColorSpace as ke,Texture as de,CanvasTexture as le,Group as k,MeshStandardMaterial as B,Color as ue,BoxGeometry as q,Mesh as p,PlaneGeometry as N,CircleGeometry as pe,MeshBasicMaterial as Z,CylinderGeometry as Oe,ExtrudeGeometry as Ee,ShapeGeometry as Fe,Shape as Te,Vector3 as l,Euler as $,Quaternion as A,Matrix4 as H,PerspectiveCamera as me,Raycaster as fe,Vector2 as we,Plane as _,Scene as Le,WebGLRenderer as Ie,HemisphereLight as qe,DirectionalLight as De,NoToneMapping as Re,PCFShadowMap as je,ShadowMaterial as Ve,ACESFilmicToneMapping as _e,Box3 as P,AnimationMixer as Ge,Matrix3 as Be,BufferGeometry as ne,BufferAttribute as X,ShaderMaterial as We,Points as Ue,GridHelper as Ye,LoopRepeat as Xe,Line as Ke,LineBasicMaterial as Ne}from"./three.module-Bx43vjkH.js";import{G as se}from"./GLTFLoader-BHWu1lKg.js";import{az as Qe}from"./api-CJ8PdbfZ.js";import{lW as R,_ as Je,ee as K,lX as Ze,lY as $e,f9 as He,fb as et,cd as tt,fr as ye,fA as oe,fB as nt,lZ as st,l_ as ot,l$ as it,m0 as at,m1 as rt,m2 as ct,lV as ht}from"./titleFrameBudget-CLZWaFHO.js";import{R as ge}from"./RoomEnvironment-Dmv_G5ka.js";const dt=new Map;async function lt(a){try{const e=await(await Je(async()=>{const{signOutput:t}=await import("./api-CJ8PdbfZ.js").then(n=>n.c2);return{signOutput:t}},__vite__mapDeps([0,1]))).signOutput({gcsUri:a});return typeof e=="string"&&e?e:null}catch{return null}}function xe(a,e,t){const n=new Te,s=-a/2,o=-e/2;return t=Math.min(t,a/2,e/2),n.moveTo(s+t,o),n.lineTo(s+a-t,o),n.quadraticCurveTo(s+a,o,s+a,o+t),n.lineTo(s+a,o+e-t),n.quadraticCurveTo(s+a,o+e,s+a-t,o+e),n.lineTo(s+t,o+e),n.quadraticCurveTo(s,o+e,s,o+e-t),n.lineTo(s,o+t),n.quadraticCurveTo(s,o,s+t,o),n}function C(a,e,t){const n=new Fe(xe(a,e,t),12),s=n.attributes.uv,o=n.attributes.position;for(let i=0;i<s.count;i++)s.setXY(i,o.getX(i)/a+.5,o.getY(i)/e+.5);return n}function T(a,e,t,n,s=.012){const o=new Ee(xe(a-s*2,e-s*2,Math.max(.001,n-s)),{depth:t-s*2,bevelEnabled:!0,bevelThickness:s,bevelSize:s,bevelSegments:4,curveSegments:14});return o.translate(0,0,-(t-s*2)/2),o}const S=(a,e=.32)=>new B({color:a,metalness:.85,roughness:e}),G=()=>new B({color:"#050506",metalness:.2,roughness:.08}),ie=a=>new B({color:a,metalness:.1,roughness:.75}),W=()=>new Z({color:"#ffffff",toneMapped:!1});function ae(a,{w:e,h:t,d:n,r:s,bezel:o,island:i,lenses:r}){const c=new k;c.add(new p(T(e,t,n,s),S(a)));const h=new p(C(e-.012,t-.012,s-.006),G());h.position.z=n/2+.0015,c.add(h);const m=e-o*2,d=t-o*2,f=new p(C(m,d,Math.max(.01,s-o)),W());if(f.position.z=n/2+.003,c.add(f),i){const u=new p(C(m*.3,d*.032,d*.016),new Z({color:"#000"}));u.position.set(0,d/2-d*.035,n/2+.004),c.add(u)}if(r){const u=new p(T(e*.42,e*.42,.02,e*.1,.006),G());u.position.set(-e/2+e*.27,t/2-e*.27,-n/2-.008),c.add(u);for(let g=0;g<r;g++){const M=g*2*Math.PI/Math.max(1,r)+.6,x=new p(new Oe(e*.075,e*.08,.018,28),S("#2a2a2c",.2));x.rotation.x=Math.PI/2,x.position.set(u.position.x+Math.cos(M)*e*.09,u.position.y+Math.sin(M)*e*.09,-n/2-.022),c.add(x);const w=new p(new pe(e*.05,24),G());w.rotation.y=Math.PI,w.position.set(x.position.x,x.position.y,-n/2-.0315),c.add(w)}}for(const[u,g]of[[t*.22,t*.08],[t*.09,t*.08]]){const M=new p(new q(.008,g,n*.35),S(a));M.position.set(-e/2-.002,u,0),c.add(M)}const v=new p(new q(.008,t*.12,n*.35),S(a));return v.position.set(e/2+.002,t*.14,0),c.add(v),{object:c,screen:f,screenAspect:m/d}}function ut(a,e){const t=new k,n=1.8,s=1.22,o=.045,i=new p(T(n,s,o,.06),S(a));i.rotation.x=-Math.PI/2,t.add(i);const r=new p(C(n*.86,s*.42,.02),ie("#111214"));r.rotation.x=-Math.PI/2,r.position.set(0,o/2+.001,-s*.15),t.add(r);const c=new q(n*.86/15*.82,.006,s*.42/6*.78),h=ie("#1b1c1f");for(let O=0;O<6;O++)for(let E=0;E<15;E++){const F=new p(c,h);F.position.set(-n*.43+(E+.5)*n*.86/15,o/2+.004,-s*.15-s*.21+(O+.5)*s*.42/6),t.add(F)}const m=new p(C(n*.36,s*.26,.025),S(a,.5));m.rotation.x=-Math.PI/2,m.position.set(0,o/2+.0012,s*.27),t.add(m);const d=new k;d.position.set(0,o/2,-s/2),t.add(d);const f=1.16,v=.022,u=new k;u.position.set(0,f/2,0),d.add(u),u.add(new p(T(n,f,v,.05),S(a)));const g=new p(C(n-.01,f-.01,.045),G());g.position.z=v/2+.0015,u.add(g);const M=n-.09,x=f-.1,w=new p(C(M,x,.012),W());w.position.set(0,.01,v/2+.003),u.add(w);const y=new p(new pe(.07,40),S("#e9e9ea",.15));y.rotation.y=Math.PI,y.position.z=-v/2-.002,u.add(y);const z=Math.max(0,Math.min(1,e));return d.rotation.x=(1-z)*Math.PI/2-z*.26,{object:t,screen:w,screenAspect:M/x}}function pt(a){const e=new k,t=1.8,n=1.04,s=.035;e.add(new p(T(t,n,s,.02,.006),S(a,.45)));const o=t-.04,i=n-.04,r=new p(C(o,i,.006),W());r.position.z=s/2+.002,e.add(r);const c=new p(new q(.12,.32,.04),S(a,.4));c.position.set(0,-n/2-.14,-.05),e.add(c);const h=new p(T(.62,.26,.025,.08,.006),S(a,.4));return h.rotation.x=-Math.PI/2,h.position.set(0,-n/2-.3,-.02),e.add(h),{object:e,screen:r,screenAspect:o/i}}function mt(a){const e=new k,t=1.2,n=1.6,s=.42,o=new B({color:new ue(a).multiplyScalar(.62),metalness:0,roughness:.85}),i=new q(t,n,s);e.add(new p(i,o));const r=new p(new N(t*.98,n*.98),W());return r.position.z=s/2+.002,e.add(r),{object:e,screen:r,screenAspect:t/n}}function ft(a){const e=a.color??(a.type==="box"?R.white:a.type==="tv"?R.black:a.type==="laptop"?R.silver:R.titanium);switch(a.type){case"phone":return ae(e,{w:.83,h:1.8,d:.075,r:.13,bezel:.032,island:!0,lenses:3});case"tablet":return ae(e,{w:1.35,h:1.8,d:.06,r:.09,bezel:.05,island:!1,lenses:1});case"laptop":return ut(e,a.open??1);case"tv":return pt(e);default:return mt(e)}}const re=new WeakMap;function wt(a){let e=re.get(a);if(!e){const t=new he(a);e=t.fromScene(new ge,0,.1,100,{size:64}).texture,t.dispose(),re.set(a,e)}return e}class yt{constructor(e,t,n){this.mesh=e,this.aspect=t,this.media=n;const s=o=>n.kind==="video"?this.loadVideo(o):this.loadImage(o);this.ready=n?.url?s(n.url).catch(async o=>{const i=n.gcsUri?await lt(n.gcsUri):null;if(!i||i===n.url)throw o;return s(i)}):Promise.resolve(),n?.url||e.material.color.set("#0d0f12")}texture=null;video=null;ready;whenReady(){return this.ready}fit(e,t){const n=this.texture,s=e/t;s>this.aspect?(n.repeat.set(this.aspect/s,1),n.offset.set((1-this.aspect/s)/2,0)):(n.repeat.set(1,s/this.aspect),n.offset.set(0,(1-s/this.aspect)/2))}apply(e,t,n){e.colorSpace=ke,e.anisotropy=4,this.texture=e,this.fit(t,n);const s=this.mesh.material;s.map=e,s.needsUpdate=!0}loadImage(e){return new Promise((t,n)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>{this.apply(new de(s),s.naturalWidth,s.naturalHeight),this.texture.needsUpdate=!0,t()},s.onerror=()=>n(Error("Không tải được ảnh màn hình thiết bị")),s.src=e})}canvas=null;draw(){const e=this.video,t=this.canvas;!e||!t||e.readyState<2||(t.getContext("2d").drawImage(e,0,0,t.width,t.height),this.texture&&(this.texture.needsUpdate=!0))}loadVideo(e){const t=document.createElement("video");return t.crossOrigin="anonymous",t.muted=!0,t.playsInline=!0,t.preload="auto",this.video=t,new Promise((n,s)=>{t.onloadeddata=()=>{const o=Math.min(1,1280/Math.max(t.videoWidth,t.videoHeight)),i=document.createElement("canvas");i.width=Math.max(2,Math.round(t.videoWidth*o)),i.height=Math.max(2,Math.round(t.videoHeight*o)),this.canvas=i,this.apply(new le(i),t.videoWidth,t.videoHeight),this.draw(),n()},t.onerror=()=>s(Error("Không tải được video màn hình thiết bị")),t.src=e})}async sync(e,t=!1){const n=this.video,s=this.media;if(!n||!s||!this.texture)return;const o=Number.isFinite(n.duration)&&n.duration>0?n.duration:0;let i=(s.inPoint||0)+Math.max(0,e)*(s.speed||1);if(o&&(i=Math.min(i,o-.04)),Math.abs(n.currentTime-i)>(t?.004:.12)){const r=new Promise(c=>{const h=()=>{n.removeEventListener("seeked",h),c()};n.addEventListener("seeked",h),setTimeout(h,t?4e3:600)});if(n.currentTime=i,t)await r;else{r.then(()=>this.draw());return}}this.draw()}dispose(){this.texture?.dispose(),this.video&&(this.video.removeAttribute("src"),this.video.load(),this.video=null)}}const gt=1.8,b=Math.PI/180;function I(a,e,t,n,s){if(He(t)&&a.is3D!==!1){const o=ye(n,s),i=et(t,a.start+Math.max(0,e),n,s),r=c=>new l(i.R[0][c],-i.R[1][c],-i.R[2][c]);return{pos:new l(i.pos[0]/o,-i.pos[1]/o,-i.pos[2]/o),quat:new A().setFromRotationMatrix(new H().makeBasis(r(0),r(1).negate(),r(2).negate())),fov:2*Math.atan(s/2/i.f)/b,on:!0}}return{pos:new l(0,0,5),quat:new A,fov:40,on:!1}}function Q(a,e,t,n,s){const o=tt(a,Math.max(0,e),n,s);if(t.on){const r=ye(n,s);return{pos:new l(o.x*n/r,-o.y*s/r,o.depth),zoom:o.zoom}}const i=2*(5-o.depth)*Math.tan(t.fov*b/2);return{pos:new l(o.x*i*(n/s),-o.y*i,o.depth),zoom:o.zoom}}function ve(a){const e=a.modelRotation||{x:0,y:0,z:0};return new l(0,1,0).applyEuler(new $(e.x*b,e.y*b,e.z*b)).normalize()}function Me(a,e,t,n,s){const o=Math.min(48,Math.max(2,Math.ceil(a.duration/.1)));let i=1/0;for(let r=0;r<=o;r++){const c=a.duration*r/o;i=Math.min(i,Q(a,c,I(a,c,t,n,s),n,s).pos.dot(e))}return i}function xt(a,e,t,n,s,o){const i=new me(a.fov,s/o,.01,100);i.position.copy(a.pos),i.quaternion.copy(a.quat),i.updateMatrixWorld(!0),i.updateProjectionMatrix();const r=new fe;return r.setFromCamera(new we(e[0]*2-1,1-e[1]*2),i),r.ray.intersectPlane(new _(t.clone(),-n),new l)}function vt(a,e,t,n,s,o,i){const r=I(a,e,t,n,s),{pos:c,zoom:h}=Q(a,e,r,n,s),m={x:K(a,"rx",e),y:K(a,"ry",e),z:K(a,"rz",e)},d=a.modelSpin||{x:0,y:0,z:0},f=(a.inPoint||0)+e,v=new $((m.x+d.x*f)*b,(m.y+d.y*f)*b,(m.z+d.z*f)*b),u=ve(a),g=gt*h,x=!!a.modelLaunch||!!a.modelLook?i??Me(a,u,t,n,s):null,w=a.modelLaunch,y=w?Ze(w,e):null;if(w&&y){const E=Q(a,w.at,I(a,w.at,t,n,s),n,s).pos,F=E.clone().addScaledVector(u,x-E.dot(u)),ee=xt(I(a,w.at+w.duration,t,n,s),w.to,u,x,n,s)??F.clone(),ze=F.clone().lerp(ee,y.g),L=ee.clone().sub(F);L.addScaledVector(u,-L.dot(u));const Ae=$e(y,L.length()/g);let D;if(w.face!==!1&&L.lengthSq()>1e-8){const Y=L.normalize(),te=new l().crossVectors(u,Y).normalize(),Ce=new l().crossVectors(Y,te);D=new A().setFromRotationMatrix(new H().makeBasis(te,Ce,Y))}else D=new A().setFromEuler(v);D.multiply(new A().setFromAxisAngle(new l(1,0,0),-Ae*b)).multiply(new A().setFromAxisAngle(new l(0,0,1),y.roll*b));const U=y.jolt*.035*g,Pe=new l(Math.sin(e*91)*U,Math.sin(e*67+1)*U*.6,Math.sin(e*53+2)*U);return{cam:r,pos:ze.addScaledVector(u,o*h+y.h*g).add(Pe),quat:D,zoom:h,N:u,d:x,len:g}}const z=new A().setFromEuler(v),O=c.clone();return a.modelGround&&O.add(new l(0,1,0).applyQuaternion(z).multiplyScalar(o*h)),{cam:r,pos:O,quat:z,zoom:h,N:u,d:x,len:g}}function Mt(a,e,t){const n=new l(1,0,0).applyQuaternion(t.quat),o=e.clone().cross(n).normalize().clone().negate(),i=new l().crossVectors(e,o).normalize(),r=a.azimuth*b,c=a.elevation*b;return o.multiplyScalar(Math.cos(c)*Math.cos(r)).addScaledVector(i,Math.cos(c)*Math.sin(r)).addScaledVector(e,Math.sin(c)).normalize()}const be=new Map,J=new Set,bt=a=>a?be.get(a):void 0;function St(a){return J.add(a),()=>{J.delete(a)}}const ce=(a,e)=>a.name||`Animation ${e+1}`,Se=new Map,zt=a=>a?Se.get(a):void 0,j=600,At="attribute float aAlpha;attribute float aSize;varying float vA;uniform float uScale;void main(){vA=aAlpha;vec4 mv=modelViewMatrix*vec4(position,1.);gl_PointSize=aSize*uScale/max(.05,-mv.z);gl_Position=projectionMatrix*mv;}",Pt="uniform vec3 uColor;varying float vA;void main(){vec2 d=gl_PointCoord-.5;float r=length(d);if(r>.5)discard;gl_FragColor=vec4(uColor,vA*smoothstep(.5,.05,r));}";let V=null;function Ct(){if(V)return V;const a=document.createElement("canvas");a.width=a.height=128;const e=a.getContext("2d"),t=e.createRadialGradient(64,64,0,64,64,64);return t.addColorStop(0,"rgba(0,0,0,1)"),t.addColorStop(.35,"rgba(0,0,0,.75)"),t.addColorStop(.7,"rgba(0,0,0,.22)"),t.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=t,e.fillRect(0,0,128,128),V=new le(a),V}class kt{canvas;renderer;scene=new Le;camera=new me(40,1,.01,100);halfY=0;group=new k;disposed=!1;mixer=null;clips=[];action=null;rest=[];width;height;screen=null;pieces=[];dust=null;cut=[new _,new _];guides=null;buildOn=!1;constructor(e,t){this.width=e,this.height=t,this.renderer=new Ie({alpha:!0,antialias:!0,preserveDrawingBuffer:!0}),this.renderer.setPixelRatio(1),this.renderer.setSize(e,t,!1),this.renderer.setClearColor(0,0),this.canvas=this.renderer.domElement,this.camera.aspect=e/t,this.camera.position.set(0,0,5),this.camera.lookAt(0,0,0),this.camera.updateProjectionMatrix(),this.scene.add(this.group,this.hemi,this.key,this.key.target),this.key.position.set(3,5,5)}hemi=new qe(16777215,7829367,3);key=new De(16777215,3);catcher=null;contact=null;lookEnv=null;lookOn=!1;groundCache=null;applyLook(e){const t=this.renderer;if(!e){if(!this.lookOn)return;this.lookOn=!1,t.shadowMap.enabled=!1,t.toneMapping=Re,t.toneMappingExposure=1,this.hemi.color.set(16777215),this.hemi.groundColor.set(7829367),this.hemi.intensity=3,this.key.color.set(16777215),this.key.intensity=3,this.key.castShadow=!1,this.key.position.set(3,5,5),this.key.target.position.set(0,0,0),this.scene.environment===this.lookEnv&&(this.scene.environment=null),this.catcher&&(this.catcher.visible=!1),this.contact&&(this.contact.visible=!1);return}if(!this.lookOn&&(this.lookOn=!0,t.shadowMap.enabled=!0,t.shadowMap.type=je,this.key.castShadow=!0,this.key.shadow.mapSize.set(2048,2048),this.key.shadow.bias=-4e-4,this.key.shadow.normalBias=.02,this.group.traverse(n=>{const s=n;s.isMesh&&(s.castShadow=!0,s.receiveShadow=!0)}),this.catcher||(this.catcher=new p(new N(1,1),new Ve({opacity:.4,depthWrite:!1})),this.catcher.receiveShadow=!0,this.catcher.renderOrder=-2,this.scene.add(this.catcher)),this.contact||(this.contact=new p(new N(1,1),new Z({map:Ct(),transparent:!0,depthWrite:!1,color:0})),this.contact.renderOrder=-1,this.scene.add(this.contact)),!this.lookEnv&&!this.screen)){const n=new he(t);this.lookEnv=n.fromScene(new ge,.04,.1,100,{size:128}).texture,n.dispose()}t.toneMapping=_e,t.toneMappingExposure=e.exposure,!this.screen&&this.lookEnv&&(this.scene.environment=this.lookEnv),this.scene.environmentIntensity=e.env,this.hemi.color.set(e.ambient),this.hemi.groundColor.set(e.ambient).multiplyScalar(.45),this.hemi.intensity=e.ambientIntensity,this.key.color.set(e.color),this.key.intensity=e.intensity,this.key.shadow.radius=1+e.softness*9,this.key.shadow.blurSamples=8+Math.round(e.softness*16),this.catcher.material.opacity=e.shadow,this.catcher.visible=e.shadow>0}groundFor(e,t){const n=JSON.stringify([e.id,e.start,e.duration,e.posX,e.posY,e.spatialDepth,e.modelDepth,e.scale,e.motionKeys,e.modelRotation,e.parentId,t?JSON.stringify(t):""]);if(this.groundCache?.key===n)return this.groundCache.d;const s=Me(e,ve(e),t,this.width,this.height);return this.groundCache={key:n,d:s},s}async load(e){const t=await Qe(e);this.add(await new se().loadAsync(t),e)}async loadBuffer(e,t){this.add(await new se().parseAsync(e,""),t)}async loadDevice(e){if(!e.device)throw Error("Không phải thiết bị 3D");const t=ft(e.device);this.scene.environment=wt(this.renderer),this.addObject(t.object),!this.disposed&&(this.screen=new yt(t.screen,t.screenAspect,e.deviceScreen),await this.screen.whenReady())}async prepare(e){await this.screen?.sync(e,!0)}addObject(e){if(this.disposed){this.disposeObject(e);return}const t=new P().setFromObject(e),n=t.getSize(new l),s=Math.max(n.x,n.y,n.z);e.scale.setScalar(1.8/s),e.updateMatrixWorld(!0),this.halfY=n.y*1.8/s/2,e.position.sub(new P().setFromObject(e).getCenter(new l)),e.updateMatrixWorld(!0),this.group.add(e)}add(e,t){if(this.disposed){this.disposeObject(e.scene);return}const s=new P().setFromObject(e.scene).getSize(new l),o=Math.max(s.x,s.y,s.z);if(!Number.isFinite(o)||o<=0)throw Error("GLB không có hình học hợp lệ");e.scene.scale.setScalar(1.8/o),e.scene.updateMatrixWorld(!0);const i=new P().setFromObject(e.scene).getCenter(new l);e.scene.position.sub(i),e.scene.updateMatrixWorld(!0),this.halfY=s.y*1.8/o/2,this.group.add(e.scene),this.clips=e.animations||[],this.clips.length&&(this.mixer=new Ge(e.scene),e.scene.traverse(r=>{r!==e.scene&&this.rest.push({o:r,p:r.position.clone(),q:r.quaternion.clone(),s:r.scale.clone()})})),this.collectPieces(e.scene),Se.set(t,this.pieces.length),be.set(t,this.clips.map((r,c)=>({name:ce(r,c),duration:r.duration}))),J.forEach(r=>r())}collectPieces(e){this.group.updateMatrixWorld(!0);const t=[];e.traverse(c=>{c.isMesh&&t.push(c)});const n=new P().setFromObject(e),s=c=>{const h=c.getSize(new l);return h.x*h.y*h.z},o=s(n)*.02,i=n.getSize(new l),r=i.x*i.z;for(const c of t.slice(0,oe.maxPieces)){const h=new P().setFromObject(c),m=h.getCenter(new l),d=h.getSize(new l),f=new H().copy(c.parent.matrixWorld).invert();this.pieces.push({o:c,p:c.position.clone(),q:c.quaternion.clone(),s:c.scale.clone(),toParent:new Be().setFromMatrix4(f),box:{bottom:h.min.y,cx:m.x,cz:m.z,h:d.y,r:Math.max(d.x,d.z)/2,big:s(h)>o,base:d.x*d.z>=r*.25&&h.min.y<=n.min.y+i.y*.03}})}}build(e,t){let n=null;try{n=e.modelBuild?nt(e.modelBuild):null}catch{n=null}const s=new Set;this.group.traverse(i=>{const r=i.material;if(r)for(const c of Array.isArray(r)?r:[r])s.add(c)});const o=[];if(n){const i=st(this.pieces.map(h=>h.box),n);this.pieces.forEach((h,m)=>{const d=ot(n.style,h.box,i[m],t,m,n.seed);h.o.position.copy(h.p),h.o.quaternion.copy(h.q),h.o.scale.copy(h.s),h.o.visible=d.visible,(d.dx||d.dy||d.dz)&&h.o.position.add(new l(d.dx,d.dy,d.dz).applyMatrix3(h.toParent)),(d.rx||d.ry||d.rz)&&h.o.quaternion.multiply(new A().setFromEuler(new $(d.rx,d.ry,d.rz)))}),this.group.updateMatrixWorld(!0);const r=new l(0,1,0).applyQuaternion(this.group.getWorldQuaternion(new A)).normalize();it(n,t)&&o.push(this.cut[0].setFromNormalAndCoplanarPoint(r,this.group.localToWorld(new l(0,-this.halfY,0))));const c=at(n,t,this.halfY);c!==null&&o.push(this.cut[1].setFromNormalAndCoplanarPoint(r.clone().negate(),this.group.localToWorld(new l(0,c,0)))),this.dustAt(rt(this.pieces.map(h=>h.box),i,n,t,j),n.dustColor),this.buildOn=!0}else{for(const i of this.pieces)i.o.position.copy(i.p),i.o.quaternion.copy(i.q),i.o.scale.copy(i.s),i.o.visible=!0;this.dustAt([],oe.dustColor),this.buildOn=!1}this.renderer.localClippingEnabled=o.length>0;for(const i of s){const r=o.length?o:null;i.clippingPlanes!==r&&(i.clippingPlanes?.length||r)&&(i.clippingPlanes=r,i.needsUpdate=!0)}}dustAt(e,t){if(!e.length&&!this.dust)return;if(!this.dust){const r=new ne;r.setAttribute("position",new X(new Float32Array(j*3),3)),r.setAttribute("aAlpha",new X(new Float32Array(j),1)),r.setAttribute("aSize",new X(new Float32Array(j),1));const c=new We({uniforms:{uColor:{value:new ue(t)},uScale:{value:this.height*1.2}},vertexShader:At,fragmentShader:Pt,transparent:!0,depthWrite:!1});this.dust=new Ue(r,c),this.dust.frustumCulled=!1,this.group.add(this.dust)}const n=this.dust.geometry,s=n.getAttribute("position"),o=n.getAttribute("aAlpha"),i=n.getAttribute("aSize");e.forEach((r,c)=>{s.setXYZ(c,r[0],r[1],r[2]),o.setX(c,r[3]),i.setX(c,r[4])}),n.setDrawRange(0,e.length),s.needsUpdate=o.needsUpdate=i.needsUpdate=!0,this.dust.material.uniforms.uColor.value.set(t)}setGuides(e,t=4){if(!e){this.guides&&(this.scene.remove(this.guides),this.disposeObject(this.guides),this.guides=null);return}if(this.guides)return;const n=new k,s=new Ye(t,16,6742271,2781056);s.rotation.x=Math.PI/2;for(const i of Array.isArray(s.material)?s.material:[s.material])i.transparent=!0,i.opacity=.85,i.depthWrite=!1;const o=(i,r)=>new Ke(new ne().setFromPoints([new l,i]),new Ne({color:r}));n.add(s,o(new l(.5,0,0),16731469),o(new l(0,.5,0),5111674),o(new l(0,0,.5),5086207)),this.guides=n,this.scene.add(n)}surfaceAt(e,t){const n=new fe;n.setFromCamera(new we(e/this.width*2-1,1-t/this.height*2),this.camera);const s=n.ray.intersectPlane(new _(new l(0,0,1),0),new l);return s?{x:s.x,y:s.y}:null}pose(e,t){if(!this.mixer)return;const n=e.modelAnim,s=n?this.clips.find((i,r)=>ce(i,r)===n.clip):void 0;if(!n||!s){if(this.action){this.mixer.stopAllAction(),this.action=null;for(const i of this.rest)i.o.position.copy(i.p),i.o.quaternion.copy(i.q),i.o.scale.copy(i.s)}return}const o=this.mixer.clipAction(s);this.action!==o&&(this.mixer.stopAllAction(),o.setLoop(Xe,1/0),o.play(),this.action=o),o.time=ct(n,s.duration,t,e.inPoint||0),this.mixer.update(0)}render(e,t,n=!1,s){const o=e.modelLook?ht(e.modelLook):null;this.applyLook(o);const i=this.width,r=this.height,c=e.modelLook||e.modelLaunch?this.groundFor(e,s):void 0,h=vt(e,t,s,i,r,this.halfY,c);this.camera.position.copy(h.cam.pos),this.camera.quaternion.copy(h.cam.quat),this.camera.fov=h.cam.fov,this.camera.updateProjectionMatrix(),this.camera.updateMatrixWorld(!0),this.group.scale.setScalar(h.zoom),this.group.quaternion.copy(h.quat),this.group.position.copy(h.pos),this.pose(e,t),(e.modelBuild||this.buildOn)&&this.build(e,t),o&&this.placeShadows(e,o,h.N,h.d??0,h.len,s),n&&this.screen?.sync(t),this.renderer.render(this.scene,this.camera),n&&this.publish(e.id)}placeShadows(e,t,n,s,o,i){const r=this.group.getWorldPosition(new l),c=r.dot(n)-s,h=r.clone().addScaledVector(n,-c),m=new A().setFromUnitVectors(new l(0,0,1),n),d=Math.max(0,c-this.halfY*this.group.scale.x),f=Math.max(6*o,d*4+3*o);this.catcher.position.copy(h).addScaledVector(n,.001*o),this.catcher.quaternion.copy(m),this.catcher.scale.set(f,f,1);const v=new P().setFromObject(this.group),u=v.getSize(new l),g=Math.max(.2*o,Math.hypot(u.x,u.y,u.z)-Math.abs(u.clone().dot(n)))*.62,M=Math.max(0,1-d/(.8*o));this.contact.visible=t.contact>0&&M>0,this.contact.position.copy(h).addScaledVector(n,.002*o),this.contact.quaternion.copy(m),this.contact.scale.set(g*(1+d/o),g*.75*(1+d/o),1),this.contact.material.opacity=t.contact*.85*M;const x=Mt(t,n,I(e,0,i,this.width,this.height)),w=12*o;this.key.target.position.copy(h),this.key.position.copy(h).addScaledVector(x,w),this.key.target.updateMatrixWorld();const y=this.key.shadow.camera,z=f*.6;y.left=-z,y.right=z,y.top=z,y.bottom=-z,y.near=Math.max(.01,w-4*o-d),y.far=w+4*o+d,y.updateProjectionMatrix()}publish(e){const t=new P().setFromObject(this.group);if(t.isEmpty())return;let n=1/0,s=1/0,o=-1/0,i=-1/0;for(const r of[t.min.x,t.max.x])for(const c of[t.min.y,t.max.y])for(const h of[t.min.z,t.max.z]){const m=new l(r,c,h).project(this.camera),d=(m.x+1)/2*this.width,f=(1-m.y)/2*this.height;n=Math.min(n,d),o=Math.max(o,d),s=Math.min(s,f),i=Math.max(i,f)}dt.set(e,{cx:(n+o)/2,cy:(s+i)/2,w:o-n,h:i-s,angle:0,W:this.width,H:this.height})}async frame(e){const t=await new Promise(o=>(e??this.canvas).toBlob(o,"image/webp",.8));if(!t)throw Error("Không xuất được frame 3D");const n=new Uint8Array(await t.arrayBuffer());let s="";for(let o=0;o<n.length;o+=16384)s+=String.fromCharCode(...n.subarray(o,o+16384));return btoa(s)}disposeObject(e){e.traverse(t=>{const n=t;n.geometry?.dispose();for(const s of n.material?Array.isArray(n.material)?n.material:[n.material]:[]){for(const o of Object.values(s))o instanceof de&&o.dispose();s.dispose()}})}dispose(){this.disposed=!0,this.screen?.dispose(),this.screen=null,this.mixer?.stopAllAction(),this.disposeObject(this.group),this.renderer.dispose(),this.canvas.remove()}}const It=Object.freeze(Object.defineProperty({__proto__:null,Timeline3DScene:kt,modelAnimations:bt,modelPieces:zt,onModelAnimations:St},Symbol.toStringTag,{value:"Module"}));export{kt as T,zt as a,dt as l,bt as m,St as o,It as t};
@@ -1 +1 @@
1
- import{c1 as E,eQ as M,eR as D,lV as F,eS as v}from"./titleFrameBudget-BYRZAQPs.js";import{T as C}from"./timeline3d-246tBEJl.js";import{wantsFrame as u,SKIPPED_FRAME as L}from"./frameSink-BvOXjLuw.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./api-DUp403BK.js";import"./RoomEnvironment-Dmv_G5ka.js";const d=6;async function T(p,w,a,g,f){const{width:s,height:c,fps:r}=E(w),b=M(D(p));for(const e of p.filter(l=>l.kind==="model")){if(!u(a,"modelFrames",e.id))continue;if(!e.gcsUri&&!e.device)throw Error("Clip 3D chưa có GLB");const l=Math.ceil(e.duration*r);if(l>3600)throw Error("Mỗi clip 3D tối đa 2 phút khi xuất MP4. Hãy chia clip dài thành nhiều đoạn.");const o=new C(s,c),h=e.modelLook?F(e.modelLook).blur:e.motionBlur?.5:0,m=h>0?Object.assign(document.createElement("canvas"),{width:s,height:c}):null,t=m?.getContext("2d");try{e.device?await o.loadDevice(e):await o.load(e.gcsUri);for(let i=0;i<l;i++){if(g?.aborted)throw new DOMException("Export cancelled","AbortError");if(!u(a,"modelFrames",e.id,i)){await a.push("modelFrames",e.id,L);continue}if(v(b),await o.prepare(i/r),m&&t){t.globalCompositeOperation="copy",t.clearRect(0,0,s,c),t.globalCompositeOperation="lighter",t.globalAlpha=1/d;for(let n=0;n<d;n++){const x=Math.max(0,Math.min(e.duration,i/r+(n/(d-1)-.5)*h/r));o.render(e,x,!1,f),t.drawImage(o.canvas,0,0)}t.globalAlpha=1,t.globalCompositeOperation="source-over",await a.push("modelFrames",e.id,await o.frame(m))}else o.render(e,i/r,!1,f),await a.push("modelFrames",e.id,await o.frame());i%8===0&&await new Promise(n=>setTimeout(n,0))}}finally{o.dispose()}}}export{T as render3DFrames};
1
+ import{c1 as E,eQ as M,eR as D,lV as F,eS as v}from"./titleFrameBudget-CLZWaFHO.js";import{T as C}from"./timeline3d-DOw-CpZI.js";import{wantsFrame as u,SKIPPED_FRAME as L}from"./frameSink-DeM8xC8_.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./api-CJ8PdbfZ.js";import"./RoomEnvironment-Dmv_G5ka.js";const d=6;async function T(p,w,a,g,f){const{width:s,height:c,fps:r}=E(w),b=M(D(p));for(const e of p.filter(l=>l.kind==="model")){if(!u(a,"modelFrames",e.id))continue;if(!e.gcsUri&&!e.device)throw Error("Clip 3D chưa có GLB");const l=Math.ceil(e.duration*r);if(l>3600)throw Error("Mỗi clip 3D tối đa 2 phút khi xuất MP4. Hãy chia clip dài thành nhiều đoạn.");const o=new C(s,c),h=e.modelLook?F(e.modelLook).blur:e.motionBlur?.5:0,m=h>0?Object.assign(document.createElement("canvas"),{width:s,height:c}):null,t=m?.getContext("2d");try{e.device?await o.loadDevice(e):await o.load(e.gcsUri);for(let i=0;i<l;i++){if(g?.aborted)throw new DOMException("Export cancelled","AbortError");if(!u(a,"modelFrames",e.id,i)){await a.push("modelFrames",e.id,L);continue}if(v(b),await o.prepare(i/r),m&&t){t.globalCompositeOperation="copy",t.clearRect(0,0,s,c),t.globalCompositeOperation="lighter",t.globalAlpha=1/d;for(let n=0;n<d;n++){const x=Math.max(0,Math.min(e.duration,i/r+(n/(d-1)-.5)*h/r));o.render(e,x,!1,f),t.drawImage(o.canvas,0,0)}t.globalAlpha=1,t.globalCompositeOperation="source-over",await a.push("modelFrames",e.id,await o.frame(m))}else o.render(e,i/r,!1,f),await a.push("modelFrames",e.id,await o.frame());i%8===0&&await new Promise(n=>setTimeout(n,0))}}finally{o.dispose()}}}export{T as render3DFrames};
@@ -1 +1 @@
1
- import{f as R,au as b,io as C,eQ as nt,eR as ot,eS as Mt,jh as bt,ia as T,F as vt,fp as _t,gV as it,ee as L,h1 as at,h5 as St,gW as Pt,gY as Ot,fu as tt,jl as rt,m as E,l as A,gU as st,fe as Q,lQ as ut,lR as z,it as et,ec as G,d7 as dt,lS as lt,h as U,s as pt,i2 as $t,i3 as Et}from"./titleFrameBudget-BYRZAQPs.js";const O=1/vt,w=1e-6,X=t=>typeof t=="number"&&Number.isFinite(t);function jt(t){if(t===null)return null;if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).some(i=>i!=="in"&&i!=="out")||!X(t.in)||!X(t.out))throw Error("Invalid export range");const n=b(t.in),e=b(t.out);if(n<0||e>R||e-n<O-w)throw Error("Invalid export range");return{in:n,out:e}}function Y(t,n){if(t==null&&n==null)return null;const e=jt({in:t??0,out:n??R});return e.in<=w&&e.out>=R-w?null:e}function Jt(t,n,e){const i=Math.max(0,Math.min(R,b(e))),o=t?.in??0,s=t?.out??R;try{return n==="in"?i>=R-O+w?void 0:Y(i,i>=s-w?null:s):i<O-w?void 0:Y(i<=o+w?null:o,i)}catch{return}}function qt(t,n,e,i){if(!(i>=O))return t??null;const o=t?.in??0,s=t?.out??R;try{if(n==="in")return Y(Math.max(0,Math.min(b(e),b(Math.min(s,i)-O))),s>=R-w?null:s);const f=Math.max(b(o+O),Math.min(b(e),i));return Y(o,f>=i-w?null:f)}catch{return t??null}}function Zt(t,n){if(!t||!X(t.in)||!X(t.out)||!(n>0))return null;const e=Math.max(0,Math.min(n,t.in)),i=Math.max(0,Math.min(n,t.out));return i-e<O-w||e<=w&&i>=n-w?null:{in:e,out:i}}function Rt(t,n,e){if(!t||!Array.isArray(t.motionKeys)||!t.motionKeys.length)return t;let i={...t,motionKeys:[]};for(const o of St){const s=Pt(t,o);if(!s.length)continue;const f=s.some(a=>a.time<n-w),l=s.some(a=>a.time>e+w),p=[...s].reverse().find(a=>a.time<=n+w);i=Ot(i,o,[...f?[{time:0,value:tt(t,o,n),...p?.ease!==void 0?{ease:p.ease}:{}}]:[],...s.filter(a=>(f?a.time>n+w:a.time>=n-w)&&(l?a.time<e-w:a.time<=e+w)).map(a=>({...a,time:Math.max(0,b(a.time-n))})),...l?[{time:b(e-n),value:tt(t,o,e)}]:[]])}return i}const At=t=>[...t.parentId?[t.parentId]:[],...Array.isArray(t.shape?.items)?t.shape.items.flatMap(n=>n?.pins&&typeof n.pins=="object"?Object.values(n.pins):[]):[]];function Ft(t,n,e,i,o,s){const f=n.find(I=>I.id===t.id)??t,l=t.start+t.duration<=e+w?t.duration:0,p=_t(f,l,o,s),a=p.sx??1,r=p.sy??1,v=it("image",t.track)?t.track:0;return{...at({id:t.id,track:v,start:0,duration:i,label:String(t.label||"Null").slice(0,160)}),posX:p.x,posY:p.y,scale:p.zoom,rotation:p.rot,anchorX:L(t,"ax",l),anchorY:L(t,"ay",l),...a!==1||r!==1?{motionKeys:[{time:0,sx:a,sy:r}]}:{}}}function J({clips:t,camera:n=null},e,{W:i=1280,H:o=720}={}){if(!e||!Array.isArray(t))return{clips:t,camera:n};const s=e.in,f=e.out,l=b(f-s),p=[];for(const m of t){if(m.start+m.duration<=s+w||m.start>=f-w)continue;let k=m;if(k.start<s-w){const g=b(s-k.start);if(k.duration-g<O-w)continue;if(g>=O-w){const _=C(k,s,`${m.id}~in`);_.length===2&&(k={..._[1],id:m.id})}}if(k.start+k.duration>f+w){const g=b(f-k.start);if(g<O-w)continue;k.duration-g>=O-w&&(k=C(k,f,`${m.id}~out`)[0])}p.push({...k,start:Math.max(0,b(k.start-s))})}const a=new Set(p.map(m=>m.id)),r=new Map(t.map(m=>[m.id,m])),v=[...new Set(p.flatMap(At))].filter(m=>!a.has(m)&&r.get(m)&&!r.get(m).disabled&&r.get(m).kind!=="audio");let I=[];if(v.length){const m=nt(ot(t.filter(k=>!k.disabled)));Mt(m),I=v.map(k=>Ft(r.get(k),m,s,l,i,o))}const y=new Set([...a,...I.map(m=>m.id)]);return{clips:[...p.map(m=>{const k=r.get(m.id),g=[];let _=m;if(m.parentId&&!y.has(m.parentId)&&g.push("parentId"),m.matte&&!a.has(m.matte.source)&&(g.push("matte"),m.matte.mode?.endsWith("-inverted")||(_={...m,opacity:0,motionKeys:bt(m,"opacity",[])})),m.transition&&k&&T(t,k)&&!T(p,m)&&g.push("transition"),m.join&&k&&T(t,k)&&!T(p,m)&&g.push("join"),!g.length)return _;_={..._};for(const F of g)delete _[F];return _}),...I],camera:Rt(n,s,f)}}const j=t=>!!t&&!!t.comp&&Array.isArray(t.comp.clips),D=">",q=t=>j(t)?1+Math.max(0,...t.comp.clips.map(q)):0,mt=t=>j(t)?t.comp.clips.reduce((n,e)=>n+1+mt(e),0):0,Tt=t=>j(t)?Math.max(0,...t.comp.clips.map(n=>n.start+n.duration)):0,ft=t=>{let n=1;for(;t.some(e=>e.label===`Comp ${n}`);)n++;return`Comp ${n}`},K=t=>String(t).padStart(3,"0"),V=["x","y","zoom","rot","ax","ay"],zt={x:0,y:0,zoom:1,rot:0,ax:0,ay:0};function Z(t){return t.parentId||V.some(n=>G(t,n).length||Math.abs(L(t,n,0)-zt[n])>1e-9)?!0:["enter","exit"].some(n=>t[n]&&t[n].type!=="fade")}const ct=t=>G(t,"opacity").length>0||["enter","exit"].some(n=>t[n]&&(t[n].type==="fade"||t[n].fade!==!1));function ht(t,n){const e=[];for(const o of t.motionKeys||[]){const s={time:o.time};for(const l of V)Number.isFinite(o[l])&&(s[l]=o[l]);if(Object.keys(s).length===1)continue;const f=o.ease&&Object.fromEntries(Object.entries(o.ease).filter(([l])=>V.includes(l)));f&&Object.keys(f).length&&(s.ease=f),e.push(s)}const i=Object.fromEntries(["posX","posY","scale","rotation","anchorX","anchorY","parentId","zIndex","enter","exit"].filter(o=>t[o]!==void 0).map(o=>[o,t[o]]));return{...at({id:n,track:t.track,start:t.start,duration:t.duration,label:t.label}),...i,motionKeys:e,_comp:t.id}}function Kt(t,n){if(Math.abs(n-1)<1e-9)return t;const e=G(t,"opacity"),i={...t,opacity:(t.opacity??1)*n};return e.length?{...i,...dt(i,"opacity",e.map(o=>({...o,value:o.value*n})))}:i}function Nt(t,n){const e=Math.max(1,Math.ceil(t.duration*60-1e-6)),i=[];for(let o=0;o<=e;o++){const s=Math.min(t.duration,o/60);i.push({time:+s.toFixed(6),value:Math.max(0,Math.min(1,L(t,"opacity",s)*n(s)))})}return{...t,...dt(t,"opacity",i)}}function W(t,n){const e={...t},i=o=>n(o);if(e.parentId!==void 0){const o=i(e.parentId);o?e.parentId=o:delete e.parentId}if(e.matte?.source!==void 0){const o=i(e.matte.source);o?e.matte={...e.matte,source:o}:delete e.matte}e._virtual!==void 0&&(e._virtual=i(e._virtual)??e._virtual),typeof e.space=="string"&&(e.space=i(e.space)??e.space);for(const o of["bend","vfx"])typeof e[o]?.source=="string"&&(e[o]={...e[o],source:i(e[o].source)??e[o].source});return Array.isArray(e.shape?.items)&&e.shape.items.some(o=>o?.pins)&&(e.shape={...e.shape,items:e.shape.items.map(o=>o?.pins&&typeof o.pins=="object"?{...o,pins:Object.fromEntries(Object.entries(o.pins).map(([s,f])=>[s,i(f)??f]))}:o)}),e}const Dt=t=>{if(t.transition===void 0&&t.join===void 0)return t;const{transition:n,join:e,...i}=t;return i};function H(t){const n=t.comp.tracks||{};return t.comp.clips.filter(e=>!e.disabled&&!(e.kind!=="audio"&&n[e.track]?.hidden)).map(e=>n[e.track]?.muted?{...e,volume:0}:e)}function kt(t,n,e,i){const o=t.inPoint||0,s=t.start-o;return J({clips:n},{in:o,out:o+t.duration},{W:e,H:i}).clips.map(l=>{const p={...l,start:b(t.start+l.start)};for(const a of["_txIn","_txOut"])p[a]&&(p[a]={...p[a],t0:p[a].t0+s});return p})}function Lt(t,n){const e=t.inPoint||0;if(U(t)&&!t.reverse)return e+pt(t,Math.max(0,Math.min(t.duration,n)));const i=t.playbackRate||1,o=Math.max(0,Math.min(t.duration,n));return e+(t.reverse?Math.max(0,t.duration-o-1/30):o)*i}function yt(t){const n=t.inPoint||0,e=U(t)&&!t.reverse?pt(t,t.duration):t.duration*(t.playbackRate||1);return{from:n,to:n+e}}function wt(t){const n=H(t),e=new Set(n.map(o=>o.id)),i=`${t.id}${D}`;return n.map(o=>({...W(o,s=>e.has(s)?i+s:null),id:i+o.id}))}function It(t,{W:n=1280,H:e=720}={}){const{from:i,to:o}=yt(t);return J({clips:wt(t)},{in:i,out:o},{W:n,H:e}).clips.map(s=>({...s,volume:0}))}function Ut(t,{W:n=1280,H:e=720}={}){const i=[],o=(s,f)=>{for(const l of s)if(l?._group&&j(l)&&f<z){const p=N(It(l,{W:n,H:e}),{W:n,H:e});i.push(p),o(p,f+1)}};return o(N(t||[],{W:n,H:e}),0),i}function Xt(t,n,e,i){if(t.reverse||U(t))return[];const o=t.playbackRate||1,s=t.inPoint||0,f=`${t.id}${D}`,l=N(H(t),{W:e,H:i,depth:n+1}).filter(a=>a.url&&(a.volume??1)>0&&(a.kind==="audio"||a.kind==="video"&&!a.freeze&&!a.reverse));return J({clips:l},{in:s,out:s+t.duration*o},{W:e,H:i}).clips.flatMap(a=>{const r=(a.playbackRate||1)*o;return r>8||U(a)&&o!==1?[]:[{...Object.fromEntries(["nodeId","url","gcsUri","label","inPoint","sourceDuration","audioFx","duck","muffle"].filter(I=>a[I]!==void 0).map(I=>[I,a[I]])),id:`${f}${a.id}~a`,kind:"audio",track:a.kind==="audio"?a.track:st[0],start:b(t.start+a.start/o),duration:Math.max(1/30,b(a.duration/o)),volume:(a.volume??1)*(t.volume??1),...r!==1?{playbackRate:r}:{},...a.speedRamp&&o===1?{speedRamp:a.speedRamp}:{},...a.audioFadeIn?{audioFadeIn:a.audioFadeIn/o}:{},...a.audioFadeOut?{audioFadeOut:a.audioFadeOut/o}:{},_comp:t.id,_slot:`§a${f}${a.id}`}]})}function xt(t,n,e){let i=n;return n.kind!=="audio"&&!n.nullLayer&&(i=e!==null?Kt(i,e):Nt(i,o=>Q(t,i.start-t.start+o).opacity)),t.volume!==void 0&&t.volume!==1&&(n.kind==="video"||n.kind==="audio")&&(i={...i,volume:(i.volume??1)*t.volume}),t.lookBypass&&(i={...i,lookBypass:!0}),i}function Yt(t,n,e,i,o){if(n>=z)return[];t={...t,...rt(t)};let s=nt(ot(H(t))).map(Dt);s=N(s,{W:e,H:i,depth:n+1});const f=kt(t,s,e,i),l=new Set(f.map(y=>y.id)),p=`${t.id}${D}`,a=o?`${p}~comp`:null,r=ct(t)?null:Q(t,0).opacity,v=[...new Set(f.filter(y=>y.kind!=="audio").map(y=>`${K((y.zIndex??0)+200)}:${K(E(y.track)+1)}`))].sort(),I=f.map(y=>{let x=W(y,m=>l.has(m)?p+m:null);return x={...xt(t,x,r),id:p+y.id,_comp:t.id,...x.parentId===void 0&&a&&y.kind!=="audio"?{parentId:a}:{}},y.kind!=="audio"?(x.track=t.track,x._slot=`§${K(v.indexOf(`${K((y.zIndex??0)+200)}:${K(E(y.track)+1)}`))}${y._slot??""}`,t.zIndex!==void 0?x.zIndex=t.zIndex:delete x.zIndex):x._slot=`§${y._slot??""}${y.id}`,x});return I.sort((y,x)=>y._slot<x._slot?-1:y._slot>x._slot?1:0),a?[ht(t,a),...I]:I}function N(t,{W:n=1280,H:e=720,depth:i=0}={}){if(!Array.isArray(t)||!t.some(r=>j(r)&&!r._group))return t;const o=new Set(t.filter(r=>r.transition).map(r=>T(t,r)?.id).filter(Boolean)),s=r=>lt(r)||o.has(r.id),f=new Set(t.filter(r=>r.parentId).map(r=>r.parentId)),l=new Set(t.filter(r=>j(r)&&!s(r)).map(r=>r.id)),p=new Map,a=[];for(const r of t){if(!j(r)||r._group){a.push(r);continue}if(r.disabled)continue;if(s(r)){i<z&&a.push({...r,_group:!0},...Xt(r,i,n,e));continue}const v=Z(r)||f.has(r.id);v&&p.set(r.id,`${r.id}${D}~comp`),a.push(...Yt(r,i,n,e,v))}return a.map(r=>{if(r.parentId&&p.has(r.parentId))return{...r,parentId:p.get(r.parentId)};if(r.matte&&l.has(r.matte.source)){const{matte:v,...I}=r;return I}return r})}function Bt(t,n,{id:e,label:i,tracks:o={},W:s=1280,H:f=720}={}){const l=new Set(n||[]),p=t.filter(u=>l.has(u.id));if(!p.length)throw Error("Precompose: select at least one layer");if(!p.some(u=>u.kind!=="audio"))throw Error("Precompose needs at least one picture layer");if(p.some(u=>o[u.track]?.locked))throw Error("Track đã khóa");if(1+Math.max(0,...p.map(q))>z)throw Error(`Comps nest at most ${z} deep`);const a=t.filter(u=>!l.has(u.id)),r=[...p.filter(u=>u.matte&&!l.has(u.matte.source)),...a.filter(u=>u.matte&&l.has(u.matte.source))];if(r.length)throw Error(`Precompose: the track matte of "${r[0].label||r[0].id}" crosses the comp's edge — take the matte layer in too, or remove the matte`);const v=b(Math.min(...p.map(u=>u.start))),I=b(Math.max(...p.map(u=>u.start+u.duration))),y=Math.max(1/30,b(I-v)),x=u=>a.some(c=>c.track===u&&c.kind!=="audio"&&c.start<I-1e-6&&c.start+c.duration>v+1e-6)||o[u]?.locked,m=[...new Set(p.filter(u=>u.kind!=="audio").map(u=>u.track))].sort((u,c)=>E(c)-E(u));let k=m.find(u=>!x(u));for(let u=E(m[0])+1;k===void 0;u++)x(A(u))||(k=A(u));const g=u=>T(t,u),_=p.map(u=>{let c={...u};return c.parentId&&!l.has(c.parentId)&&(c={...c,...et(t,u,null,0,s,f)}),c.transition&&!l.has(g(u)?.id)&&delete c.transition,c.join&&!l.has(g(u)?.id)&&delete c.join,c.parentId===void 0&&delete c.parentId,{...c,start:b(u.start-v)}}),F=a.map(u=>{let c=u;return u.parentId&&l.has(u.parentId)&&(c={...c,...et(t,u,null,0,s,f)},c.parentId===void 0&&(c={...c},delete c.parentId)),(c.transition||c.join)&&l.has(g(u)?.id)&&(c={...c},delete c.transition,delete c.join),c}),$=[...new Set(p.map(u=>u.track))].filter(u=>o[u]?.hidden||o[u]?.muted),B=Object.fromEntries($.map(u=>[u,{...o[u].hidden?{hidden:!0}:{},...o[u].muted?{muted:!0}:{}}])),P={id:e||`comp-${Date.now().toString(36)}`,nodeId:"",kind:"image",url:"",label:i||ft(t),track:k,start:v,duration:y,inPoint:0,sourceDuration:y,motionV:2,comp:{clips:_,...$.length?{tracks:B}:{}}};return{clips:[...F,P],id:P.id,track:k}}function Vt(t,n,{tracks:e={},W:i=1280,H:o=720,newId:s=()=>`null-${Math.random().toString(36).slice(2,9)}`}={}){const f=t.find(d=>d.id===n);if(!j(f))throw Error("Uncompose needs a comp layer");if(e[f.track]?.locked)throw Error("Track đã khóa");const l={...f,...rt(f)},p=t.filter(d=>d.id!==n),a=new Set(p.map(d=>d.id)),r=l.comp.tracks||{},v=l.comp.clips.map(d=>({...d,...r[d.track]?.hidden&&d.kind!=="audio"?{disabled:!0}:{},...r[d.track]?.muted?{volume:0}:{}})),I=kt(l,v,i,o),y=new Map;for(const d of I){let h=d.id,M=2;for(;a.has(h)||[...y.values()].includes(h);)h=`${d.id}-${M++}`;y.set(d.id,h)}const x=[...p],m=(d,h)=>!e[d]?.locked&&!x.some(M=>M.track===d&&h.some(S=>M.start<S.start+S.duration-1e-6&&M.start+M.duration>S.start+1e-6)),k=new Map,g=[...new Set(I.filter(d=>d.kind!=="audio").map(d=>d.track))].sort((d,h)=>E(d)-E(h)),_=d=>I.filter(h=>h.kind!=="audio"&&h.track===d),F=g.every(d=>m(d,_(d)));let $=F?E(g.at(-1)??l.track)+1:E(l.track);for(const d of g){const h=_(d);if(F){k.set(d,d),x.push(...h);continue}for(;!m(A($),h);)$++;k.set(d,A($)),x.push(...h.map(M=>({...M,track:A($)}))),$++}for(const d of[...new Set(I.filter(h=>h.kind==="audio").map(h=>h.track))]){const h=I.filter(S=>S.kind==="audio"&&S.track===d),M=[d,...st.filter(S=>S!==d)].find(S=>m(S,h));if(M===void 0)throw Error("Uncompose: no free audio row for the comp's sounds");k.set(d,M),x.push(...h.map(S=>({...S,track:M})))}const B=Z(l)||p.some(d=>d.parentId===n);let P=null;if(B){let d=$;const h=[{start:l.start,duration:l.duration}];for(;!m(A(d),h);)d++;let M=s();for(;a.has(M);)M=s();const{_comp:S,...gt}=ht(l,M);P={...gt,track:A(d),label:l.label||"Null"}}const u=ct(l)?null:Q(l,0).opacity,c=I.map(d=>{let h=W(d,M=>y.get(M)??null);if(h={...xt(l,h,u),id:y.get(d.id),track:k.get(d.track)??d.track},h.parentId===void 0&&P&&d.kind!=="audio"&&(h.parentId=P.id),!it(h.kind,h.track))throw Error("Uncompose: no free row");return h});return{clips:[...p.map(d=>d.parentId===n?P?{...d,parentId:P.id}:(({parentId:h,...M})=>M)(d):d),...P?[P]:[],...c],ids:c.map(d=>d.id),nullId:P?.id??null,dropped:ut(f)}}const Wt=Object.freeze(Object.defineProperty({__proto__:null,COMP_DEPTH:z,COMP_SEP:D,compBlockers:$t,compClipCount:mt,compContentEnd:Tt,compDepth:q,compGrouped:lt,compInner:wt,compLabel:ft,compMoves:Z,compPictureFields:ut,compRange:yt,compRenderLevel:It,compTime:Lt,expandComps:N,groupedLevels:Ut,isComp:j,precompose:Bt,stripComp:Et,uncompose:Vt},Symbol.toStringTag,{value:"Module"}));export{wt as a,Lt as b,Tt as c,Zt as d,N as e,ft as f,mt as g,qt as h,j as i,Jt as j,Y as m,Bt as p,J as s,Wt as t,Vt as u};
1
+ import{f as R,au as b,io as C,eQ as nt,eR as ot,eS as Mt,jh as bt,ia as T,F as vt,fp as _t,gV as it,ee as L,h1 as at,h5 as St,gW as Pt,gY as Ot,fu as tt,jl as rt,m as E,l as A,gU as st,fe as Q,lQ as ut,lR as z,it as et,ec as G,d7 as dt,lS as lt,h as U,s as pt,i2 as $t,i3 as Et}from"./titleFrameBudget-CLZWaFHO.js";const O=1/vt,w=1e-6,X=t=>typeof t=="number"&&Number.isFinite(t);function jt(t){if(t===null)return null;if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).some(i=>i!=="in"&&i!=="out")||!X(t.in)||!X(t.out))throw Error("Invalid export range");const n=b(t.in),e=b(t.out);if(n<0||e>R||e-n<O-w)throw Error("Invalid export range");return{in:n,out:e}}function Y(t,n){if(t==null&&n==null)return null;const e=jt({in:t??0,out:n??R});return e.in<=w&&e.out>=R-w?null:e}function Jt(t,n,e){const i=Math.max(0,Math.min(R,b(e))),o=t?.in??0,s=t?.out??R;try{return n==="in"?i>=R-O+w?void 0:Y(i,i>=s-w?null:s):i<O-w?void 0:Y(i<=o+w?null:o,i)}catch{return}}function qt(t,n,e,i){if(!(i>=O))return t??null;const o=t?.in??0,s=t?.out??R;try{if(n==="in")return Y(Math.max(0,Math.min(b(e),b(Math.min(s,i)-O))),s>=R-w?null:s);const f=Math.max(b(o+O),Math.min(b(e),i));return Y(o,f>=i-w?null:f)}catch{return t??null}}function Zt(t,n){if(!t||!X(t.in)||!X(t.out)||!(n>0))return null;const e=Math.max(0,Math.min(n,t.in)),i=Math.max(0,Math.min(n,t.out));return i-e<O-w||e<=w&&i>=n-w?null:{in:e,out:i}}function Rt(t,n,e){if(!t||!Array.isArray(t.motionKeys)||!t.motionKeys.length)return t;let i={...t,motionKeys:[]};for(const o of St){const s=Pt(t,o);if(!s.length)continue;const f=s.some(a=>a.time<n-w),l=s.some(a=>a.time>e+w),p=[...s].reverse().find(a=>a.time<=n+w);i=Ot(i,o,[...f?[{time:0,value:tt(t,o,n),...p?.ease!==void 0?{ease:p.ease}:{}}]:[],...s.filter(a=>(f?a.time>n+w:a.time>=n-w)&&(l?a.time<e-w:a.time<=e+w)).map(a=>({...a,time:Math.max(0,b(a.time-n))})),...l?[{time:b(e-n),value:tt(t,o,e)}]:[]])}return i}const At=t=>[...t.parentId?[t.parentId]:[],...Array.isArray(t.shape?.items)?t.shape.items.flatMap(n=>n?.pins&&typeof n.pins=="object"?Object.values(n.pins):[]):[]];function Ft(t,n,e,i,o,s){const f=n.find(I=>I.id===t.id)??t,l=t.start+t.duration<=e+w?t.duration:0,p=_t(f,l,o,s),a=p.sx??1,r=p.sy??1,v=it("image",t.track)?t.track:0;return{...at({id:t.id,track:v,start:0,duration:i,label:String(t.label||"Null").slice(0,160)}),posX:p.x,posY:p.y,scale:p.zoom,rotation:p.rot,anchorX:L(t,"ax",l),anchorY:L(t,"ay",l),...a!==1||r!==1?{motionKeys:[{time:0,sx:a,sy:r}]}:{}}}function J({clips:t,camera:n=null},e,{W:i=1280,H:o=720}={}){if(!e||!Array.isArray(t))return{clips:t,camera:n};const s=e.in,f=e.out,l=b(f-s),p=[];for(const m of t){if(m.start+m.duration<=s+w||m.start>=f-w)continue;let k=m;if(k.start<s-w){const g=b(s-k.start);if(k.duration-g<O-w)continue;if(g>=O-w){const _=C(k,s,`${m.id}~in`);_.length===2&&(k={..._[1],id:m.id})}}if(k.start+k.duration>f+w){const g=b(f-k.start);if(g<O-w)continue;k.duration-g>=O-w&&(k=C(k,f,`${m.id}~out`)[0])}p.push({...k,start:Math.max(0,b(k.start-s))})}const a=new Set(p.map(m=>m.id)),r=new Map(t.map(m=>[m.id,m])),v=[...new Set(p.flatMap(At))].filter(m=>!a.has(m)&&r.get(m)&&!r.get(m).disabled&&r.get(m).kind!=="audio");let I=[];if(v.length){const m=nt(ot(t.filter(k=>!k.disabled)));Mt(m),I=v.map(k=>Ft(r.get(k),m,s,l,i,o))}const y=new Set([...a,...I.map(m=>m.id)]);return{clips:[...p.map(m=>{const k=r.get(m.id),g=[];let _=m;if(m.parentId&&!y.has(m.parentId)&&g.push("parentId"),m.matte&&!a.has(m.matte.source)&&(g.push("matte"),m.matte.mode?.endsWith("-inverted")||(_={...m,opacity:0,motionKeys:bt(m,"opacity",[])})),m.transition&&k&&T(t,k)&&!T(p,m)&&g.push("transition"),m.join&&k&&T(t,k)&&!T(p,m)&&g.push("join"),!g.length)return _;_={..._};for(const F of g)delete _[F];return _}),...I],camera:Rt(n,s,f)}}const j=t=>!!t&&!!t.comp&&Array.isArray(t.comp.clips),D=">",q=t=>j(t)?1+Math.max(0,...t.comp.clips.map(q)):0,mt=t=>j(t)?t.comp.clips.reduce((n,e)=>n+1+mt(e),0):0,Tt=t=>j(t)?Math.max(0,...t.comp.clips.map(n=>n.start+n.duration)):0,ft=t=>{let n=1;for(;t.some(e=>e.label===`Comp ${n}`);)n++;return`Comp ${n}`},K=t=>String(t).padStart(3,"0"),V=["x","y","zoom","rot","ax","ay"],zt={x:0,y:0,zoom:1,rot:0,ax:0,ay:0};function Z(t){return t.parentId||V.some(n=>G(t,n).length||Math.abs(L(t,n,0)-zt[n])>1e-9)?!0:["enter","exit"].some(n=>t[n]&&t[n].type!=="fade")}const ct=t=>G(t,"opacity").length>0||["enter","exit"].some(n=>t[n]&&(t[n].type==="fade"||t[n].fade!==!1));function ht(t,n){const e=[];for(const o of t.motionKeys||[]){const s={time:o.time};for(const l of V)Number.isFinite(o[l])&&(s[l]=o[l]);if(Object.keys(s).length===1)continue;const f=o.ease&&Object.fromEntries(Object.entries(o.ease).filter(([l])=>V.includes(l)));f&&Object.keys(f).length&&(s.ease=f),e.push(s)}const i=Object.fromEntries(["posX","posY","scale","rotation","anchorX","anchorY","parentId","zIndex","enter","exit"].filter(o=>t[o]!==void 0).map(o=>[o,t[o]]));return{...at({id:n,track:t.track,start:t.start,duration:t.duration,label:t.label}),...i,motionKeys:e,_comp:t.id}}function Kt(t,n){if(Math.abs(n-1)<1e-9)return t;const e=G(t,"opacity"),i={...t,opacity:(t.opacity??1)*n};return e.length?{...i,...dt(i,"opacity",e.map(o=>({...o,value:o.value*n})))}:i}function Nt(t,n){const e=Math.max(1,Math.ceil(t.duration*60-1e-6)),i=[];for(let o=0;o<=e;o++){const s=Math.min(t.duration,o/60);i.push({time:+s.toFixed(6),value:Math.max(0,Math.min(1,L(t,"opacity",s)*n(s)))})}return{...t,...dt(t,"opacity",i)}}function W(t,n){const e={...t},i=o=>n(o);if(e.parentId!==void 0){const o=i(e.parentId);o?e.parentId=o:delete e.parentId}if(e.matte?.source!==void 0){const o=i(e.matte.source);o?e.matte={...e.matte,source:o}:delete e.matte}e._virtual!==void 0&&(e._virtual=i(e._virtual)??e._virtual),typeof e.space=="string"&&(e.space=i(e.space)??e.space);for(const o of["bend","vfx"])typeof e[o]?.source=="string"&&(e[o]={...e[o],source:i(e[o].source)??e[o].source});return Array.isArray(e.shape?.items)&&e.shape.items.some(o=>o?.pins)&&(e.shape={...e.shape,items:e.shape.items.map(o=>o?.pins&&typeof o.pins=="object"?{...o,pins:Object.fromEntries(Object.entries(o.pins).map(([s,f])=>[s,i(f)??f]))}:o)}),e}const Dt=t=>{if(t.transition===void 0&&t.join===void 0)return t;const{transition:n,join:e,...i}=t;return i};function H(t){const n=t.comp.tracks||{};return t.comp.clips.filter(e=>!e.disabled&&!(e.kind!=="audio"&&n[e.track]?.hidden)).map(e=>n[e.track]?.muted?{...e,volume:0}:e)}function kt(t,n,e,i){const o=t.inPoint||0,s=t.start-o;return J({clips:n},{in:o,out:o+t.duration},{W:e,H:i}).clips.map(l=>{const p={...l,start:b(t.start+l.start)};for(const a of["_txIn","_txOut"])p[a]&&(p[a]={...p[a],t0:p[a].t0+s});return p})}function Lt(t,n){const e=t.inPoint||0;if(U(t)&&!t.reverse)return e+pt(t,Math.max(0,Math.min(t.duration,n)));const i=t.playbackRate||1,o=Math.max(0,Math.min(t.duration,n));return e+(t.reverse?Math.max(0,t.duration-o-1/30):o)*i}function yt(t){const n=t.inPoint||0,e=U(t)&&!t.reverse?pt(t,t.duration):t.duration*(t.playbackRate||1);return{from:n,to:n+e}}function wt(t){const n=H(t),e=new Set(n.map(o=>o.id)),i=`${t.id}${D}`;return n.map(o=>({...W(o,s=>e.has(s)?i+s:null),id:i+o.id}))}function It(t,{W:n=1280,H:e=720}={}){const{from:i,to:o}=yt(t);return J({clips:wt(t)},{in:i,out:o},{W:n,H:e}).clips.map(s=>({...s,volume:0}))}function Ut(t,{W:n=1280,H:e=720}={}){const i=[],o=(s,f)=>{for(const l of s)if(l?._group&&j(l)&&f<z){const p=N(It(l,{W:n,H:e}),{W:n,H:e});i.push(p),o(p,f+1)}};return o(N(t||[],{W:n,H:e}),0),i}function Xt(t,n,e,i){if(t.reverse||U(t))return[];const o=t.playbackRate||1,s=t.inPoint||0,f=`${t.id}${D}`,l=N(H(t),{W:e,H:i,depth:n+1}).filter(a=>a.url&&(a.volume??1)>0&&(a.kind==="audio"||a.kind==="video"&&!a.freeze&&!a.reverse));return J({clips:l},{in:s,out:s+t.duration*o},{W:e,H:i}).clips.flatMap(a=>{const r=(a.playbackRate||1)*o;return r>8||U(a)&&o!==1?[]:[{...Object.fromEntries(["nodeId","url","gcsUri","label","inPoint","sourceDuration","audioFx","duck","muffle"].filter(I=>a[I]!==void 0).map(I=>[I,a[I]])),id:`${f}${a.id}~a`,kind:"audio",track:a.kind==="audio"?a.track:st[0],start:b(t.start+a.start/o),duration:Math.max(1/30,b(a.duration/o)),volume:(a.volume??1)*(t.volume??1),...r!==1?{playbackRate:r}:{},...a.speedRamp&&o===1?{speedRamp:a.speedRamp}:{},...a.audioFadeIn?{audioFadeIn:a.audioFadeIn/o}:{},...a.audioFadeOut?{audioFadeOut:a.audioFadeOut/o}:{},_comp:t.id,_slot:`§a${f}${a.id}`}]})}function xt(t,n,e){let i=n;return n.kind!=="audio"&&!n.nullLayer&&(i=e!==null?Kt(i,e):Nt(i,o=>Q(t,i.start-t.start+o).opacity)),t.volume!==void 0&&t.volume!==1&&(n.kind==="video"||n.kind==="audio")&&(i={...i,volume:(i.volume??1)*t.volume}),t.lookBypass&&(i={...i,lookBypass:!0}),i}function Yt(t,n,e,i,o){if(n>=z)return[];t={...t,...rt(t)};let s=nt(ot(H(t))).map(Dt);s=N(s,{W:e,H:i,depth:n+1});const f=kt(t,s,e,i),l=new Set(f.map(y=>y.id)),p=`${t.id}${D}`,a=o?`${p}~comp`:null,r=ct(t)?null:Q(t,0).opacity,v=[...new Set(f.filter(y=>y.kind!=="audio").map(y=>`${K((y.zIndex??0)+200)}:${K(E(y.track)+1)}`))].sort(),I=f.map(y=>{let x=W(y,m=>l.has(m)?p+m:null);return x={...xt(t,x,r),id:p+y.id,_comp:t.id,...x.parentId===void 0&&a&&y.kind!=="audio"?{parentId:a}:{}},y.kind!=="audio"?(x.track=t.track,x._slot=`§${K(v.indexOf(`${K((y.zIndex??0)+200)}:${K(E(y.track)+1)}`))}${y._slot??""}`,t.zIndex!==void 0?x.zIndex=t.zIndex:delete x.zIndex):x._slot=`§${y._slot??""}${y.id}`,x});return I.sort((y,x)=>y._slot<x._slot?-1:y._slot>x._slot?1:0),a?[ht(t,a),...I]:I}function N(t,{W:n=1280,H:e=720,depth:i=0}={}){if(!Array.isArray(t)||!t.some(r=>j(r)&&!r._group))return t;const o=new Set(t.filter(r=>r.transition).map(r=>T(t,r)?.id).filter(Boolean)),s=r=>lt(r)||o.has(r.id),f=new Set(t.filter(r=>r.parentId).map(r=>r.parentId)),l=new Set(t.filter(r=>j(r)&&!s(r)).map(r=>r.id)),p=new Map,a=[];for(const r of t){if(!j(r)||r._group){a.push(r);continue}if(r.disabled)continue;if(s(r)){i<z&&a.push({...r,_group:!0},...Xt(r,i,n,e));continue}const v=Z(r)||f.has(r.id);v&&p.set(r.id,`${r.id}${D}~comp`),a.push(...Yt(r,i,n,e,v))}return a.map(r=>{if(r.parentId&&p.has(r.parentId))return{...r,parentId:p.get(r.parentId)};if(r.matte&&l.has(r.matte.source)){const{matte:v,...I}=r;return I}return r})}function Bt(t,n,{id:e,label:i,tracks:o={},W:s=1280,H:f=720}={}){const l=new Set(n||[]),p=t.filter(u=>l.has(u.id));if(!p.length)throw Error("Precompose: select at least one layer");if(!p.some(u=>u.kind!=="audio"))throw Error("Precompose needs at least one picture layer");if(p.some(u=>o[u.track]?.locked))throw Error("Track đã khóa");if(1+Math.max(0,...p.map(q))>z)throw Error(`Comps nest at most ${z} deep`);const a=t.filter(u=>!l.has(u.id)),r=[...p.filter(u=>u.matte&&!l.has(u.matte.source)),...a.filter(u=>u.matte&&l.has(u.matte.source))];if(r.length)throw Error(`Precompose: the track matte of "${r[0].label||r[0].id}" crosses the comp's edge — take the matte layer in too, or remove the matte`);const v=b(Math.min(...p.map(u=>u.start))),I=b(Math.max(...p.map(u=>u.start+u.duration))),y=Math.max(1/30,b(I-v)),x=u=>a.some(c=>c.track===u&&c.kind!=="audio"&&c.start<I-1e-6&&c.start+c.duration>v+1e-6)||o[u]?.locked,m=[...new Set(p.filter(u=>u.kind!=="audio").map(u=>u.track))].sort((u,c)=>E(c)-E(u));let k=m.find(u=>!x(u));for(let u=E(m[0])+1;k===void 0;u++)x(A(u))||(k=A(u));const g=u=>T(t,u),_=p.map(u=>{let c={...u};return c.parentId&&!l.has(c.parentId)&&(c={...c,...et(t,u,null,0,s,f)}),c.transition&&!l.has(g(u)?.id)&&delete c.transition,c.join&&!l.has(g(u)?.id)&&delete c.join,c.parentId===void 0&&delete c.parentId,{...c,start:b(u.start-v)}}),F=a.map(u=>{let c=u;return u.parentId&&l.has(u.parentId)&&(c={...c,...et(t,u,null,0,s,f)},c.parentId===void 0&&(c={...c},delete c.parentId)),(c.transition||c.join)&&l.has(g(u)?.id)&&(c={...c},delete c.transition,delete c.join),c}),$=[...new Set(p.map(u=>u.track))].filter(u=>o[u]?.hidden||o[u]?.muted),B=Object.fromEntries($.map(u=>[u,{...o[u].hidden?{hidden:!0}:{},...o[u].muted?{muted:!0}:{}}])),P={id:e||`comp-${Date.now().toString(36)}`,nodeId:"",kind:"image",url:"",label:i||ft(t),track:k,start:v,duration:y,inPoint:0,sourceDuration:y,motionV:2,comp:{clips:_,...$.length?{tracks:B}:{}}};return{clips:[...F,P],id:P.id,track:k}}function Vt(t,n,{tracks:e={},W:i=1280,H:o=720,newId:s=()=>`null-${Math.random().toString(36).slice(2,9)}`}={}){const f=t.find(d=>d.id===n);if(!j(f))throw Error("Uncompose needs a comp layer");if(e[f.track]?.locked)throw Error("Track đã khóa");const l={...f,...rt(f)},p=t.filter(d=>d.id!==n),a=new Set(p.map(d=>d.id)),r=l.comp.tracks||{},v=l.comp.clips.map(d=>({...d,...r[d.track]?.hidden&&d.kind!=="audio"?{disabled:!0}:{},...r[d.track]?.muted?{volume:0}:{}})),I=kt(l,v,i,o),y=new Map;for(const d of I){let h=d.id,M=2;for(;a.has(h)||[...y.values()].includes(h);)h=`${d.id}-${M++}`;y.set(d.id,h)}const x=[...p],m=(d,h)=>!e[d]?.locked&&!x.some(M=>M.track===d&&h.some(S=>M.start<S.start+S.duration-1e-6&&M.start+M.duration>S.start+1e-6)),k=new Map,g=[...new Set(I.filter(d=>d.kind!=="audio").map(d=>d.track))].sort((d,h)=>E(d)-E(h)),_=d=>I.filter(h=>h.kind!=="audio"&&h.track===d),F=g.every(d=>m(d,_(d)));let $=F?E(g.at(-1)??l.track)+1:E(l.track);for(const d of g){const h=_(d);if(F){k.set(d,d),x.push(...h);continue}for(;!m(A($),h);)$++;k.set(d,A($)),x.push(...h.map(M=>({...M,track:A($)}))),$++}for(const d of[...new Set(I.filter(h=>h.kind==="audio").map(h=>h.track))]){const h=I.filter(S=>S.kind==="audio"&&S.track===d),M=[d,...st.filter(S=>S!==d)].find(S=>m(S,h));if(M===void 0)throw Error("Uncompose: no free audio row for the comp's sounds");k.set(d,M),x.push(...h.map(S=>({...S,track:M})))}const B=Z(l)||p.some(d=>d.parentId===n);let P=null;if(B){let d=$;const h=[{start:l.start,duration:l.duration}];for(;!m(A(d),h);)d++;let M=s();for(;a.has(M);)M=s();const{_comp:S,...gt}=ht(l,M);P={...gt,track:A(d),label:l.label||"Null"}}const u=ct(l)?null:Q(l,0).opacity,c=I.map(d=>{let h=W(d,M=>y.get(M)??null);if(h={...xt(l,h,u),id:y.get(d.id),track:k.get(d.track)??d.track},h.parentId===void 0&&P&&d.kind!=="audio"&&(h.parentId=P.id),!it(h.kind,h.track))throw Error("Uncompose: no free row");return h});return{clips:[...p.map(d=>d.parentId===n?P?{...d,parentId:P.id}:(({parentId:h,...M})=>M)(d):d),...P?[P]:[],...c],ids:c.map(d=>d.id),nullId:P?.id??null,dropped:ut(f)}}const Wt=Object.freeze(Object.defineProperty({__proto__:null,COMP_DEPTH:z,COMP_SEP:D,compBlockers:$t,compClipCount:mt,compContentEnd:Tt,compDepth:q,compGrouped:lt,compInner:wt,compLabel:ft,compMoves:Z,compPictureFields:ut,compRange:yt,compRenderLevel:It,compTime:Lt,expandComps:N,groupedLevels:Ut,isComp:j,precompose:Bt,stripComp:Et,uncompose:Vt},Symbol.toStringTag,{value:"Module"}));export{wt as a,Lt as b,Tt as c,Zt as d,N as e,ft as f,mt as g,qt as h,j as i,Jt as j,Y as m,Bt as p,J as s,Wt as t,Vt as u};
@@ -1 +1 @@
1
- import{dG as P,eI as O,dH as M,id as R,fK as E,fM as j}from"./remote-Dva2qg58.js";import"./api-DUp403BK.js";import"./titleFrameBudget-BYRZAQPs.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./rigTrack-UYZU4P-e.js";const K=(t,e,i=.1)=>["X","Y","Z"].map((o,s)=>({id:t+s,label:`${e} ${o}`,step:i})),A=[...K("p","Vị trí"),...K("t","Nhìn tới"),{id:"lens",label:"Tiêu cự (mm)",step:1,min:14,max:200},{id:"roll",label:"Nghiêng (°)",step:1}],U=[...K("p","Vị trí"),...K("r","Xoay",1),{id:"s",label:"Kích thước",step:.05,min:.05}],_=K("o","Lệch"),X=[...K("p","Vị trí"),{id:"s",label:"Kích thước",step:.05,min:.05}],p=t=>t.shots.find(e=>e.id===t.activeShot)||t.shots[0];function H(t,e){if(e==="camera")return A;const i=t.items.find(o=>o.id===e);return i?i.kind==="fx"?i.fx?.attach?_:X:U:[]}function I(t,e){return e==="camera"?t.motion==="path"&&!!t.cameraKeys?.length:(t.objectKeys?.[e]?.length??0)>0}const y=t=>+t.slice(1);function J(t,e,i,o){const s=p(t);if(e==="camera"){const c=P(s,o);return i==="lens"?c.lens:i==="roll"?c.roll:(i[0]==="p"?c.position:c.target)[y(i)]}const r=t.items.find(c=>c.id===e);if(!r)return 0;if(i[0]==="o")return O(r,s,o).position[y(i)];const n=M(r,s,o);return i==="s"?n.scale[0]:(i[0]==="p"?n.position:n.rotation)[y(i)]}const C=t=>+t.toFixed(3);function q(t,e,i,o,s,r=()=>crypto.randomUUID()){const n=p(t);if(!n||!Number.isFinite(s))return t;const c=f=>({...t,shots:t.shots.map(l=>l.id===n.id?{...l,...f}:l)});if(e==="camera"){const f=P(n,o),l={position:[...f.position],target:[...f.target],roll:f.roll};return i==="roll"?l.roll=s:i!=="lens"&&((i[0]==="p"?l.position:l.target)[y(i)]=s),c(R(n,o,l,r,i==="lens"?s:void 0))}const a=t.items.find(f=>f.id===e);if(!a||a.locked)return t;if(i[0]==="o"){const f=O(a,n,o).position.slice();if(f[y(i)]=s,E(a,n))return j(t,e,o,{position:f});const l={...a.fx.attach,offset:f};return{...t,items:t.items.map(u=>u.id===e?{...u,fx:{...u.fx,attach:l}}:u)}}const d=M(a,n,o),m={position:[...d.position],rotation:[...d.rotation],scale:[...d.scale]};i==="s"?m.scale=d.scale[0]>1e-6?d.scale.map(f=>C(f*s/d.scale[0])):[s,s,s]:(i[0]==="p"?m.position:m.rotation)[y(i)]=s;const h=n.objectKeys?.[e]||[];if(h.length){const f=h.find(u=>Math.abs(u.time-o)<1e-6),l={...f,id:f?.id??r(),time:o,...m};return c({objectKeys:{...n.objectKeys,[e]:[...h.filter(u=>u.id!==l.id),l].sort((u,F)=>u.time-F.time)}})}return{...t,items:t.items.map(f=>f.id===e?{...f,...m}:f)}}const b=1e-6,S=(t,e)=>e==="camera"?t.motion==="path"?t.cameraKeys||[]:[]:t.objectKeys?.[e]||[];function x(t,e,i){const o=p(t),s=[...i].sort((r,n)=>r.time-n.time);if(e==="camera"){const r=s,n=r[0],c=r[r.length-1],a={cameraKeys:r,motion:r.length?"path":"static",...n&&c?{position:n.position,target:n.target,lens:n.lens,roll:n.roll,endPosition:c.position,endTarget:c.target,endLens:c.lens}:{}};return{...t,shots:t.shots.map(d=>d.id===o.id?{...d,...a}:d)}}return{...t,shots:t.shots.map(r=>r.id===o.id?{...r,objectKeys:{...r.objectKeys,[e]:s}}:r)}}const k=(t,e)=>e!=="camera"&&!!t.items.find(i=>i.id===e)?.locked;function T(t,e,i,o=()=>crypto.randomUUID()){const s=p(t);if(!s||k(t,e))return t;const r=S(s,e);if(r.some(a=>Math.abs(a.time-i)<b))return t;if(e==="camera"){const a=P(s,i);return x(t,e,[...r,{id:o(),time:i,position:a.position,target:a.target,lens:a.lens,roll:a.roll}])}const n=t.items.find(a=>a.id===e);if(!n)return t;if(n.kind==="fx"&&n.fx?.attach)return j(t,e,i,{id:o()});const c=M(n,s,i);return x(t,e,[...r,{id:o(),time:i,position:c.position,rotation:c.rotation,scale:c.scale}])}function z(t,e,i){return["camera",...t.items.filter(o=>!o.hidden).map(o=>o.id)].reduce((o,s)=>T(o,s,e,i),t)}function Q(t,e){const i=p(t);return e.flatMap(o=>{const s=S(i,o.row).find(r=>r.id===o.id);return s?[{row:o.row,key:structuredClone(s)}]:[]})}function W(t,e,i,o=()=>crypto.randomUUID()){if(!e.length)return{stage:t,pasted:[]};const s=Math.min(...e.map(c=>c.key.time)),r=[];let n=t;for(const c of new Set(e.map(a=>a.row))){if(k(n,c)||c!=="camera"&&!n.items.some(d=>d.id===c))continue;let a=[...S(p(n),c)];for(const d of e.filter(m=>m.row===c)){const m=Math.min(1,Math.max(0,d.key.time-s+i)),h={...structuredClone(d.key),id:o(),time:m};a=[...a.filter(f=>Math.abs(f.time-m)>=b),h],r.push({row:c,id:h.id})}n=x(n,c,a)}return{stage:n,pasted:r}}function v(t,e,i){let o=t;for(const s of new Set(e.map(r=>r.row))){if(k(o,s))continue;const r=new Set(e.filter(n=>n.row===s).map(n=>n.id));o=x(o,s,S(p(o),s).map(n=>r.has(n.id)?{...n,ease:i}:n))}return o}function g(t,e,i){let o=t,s=!1;for(const r of new Set(e.map(n=>n.row))){if(k(o,r))continue;const n=new Set(e.filter(m=>m.row===r).map(m=>m.id)),a=S(p(o),r).map(m=>n.has(m.id)?{...m,time:m.time+i}:m);a.every(m=>m.time>=-b&&m.time<=1+b)&&a.every((m,h)=>a.every((f,l)=>h>=l||Math.abs(m.time-f.time)>b))&&(s=!0,o=x(o,r,a.map(m=>({...m,time:Math.min(1,Math.max(0,m.time))}))))}return{stage:o,moved:s}}export{A as CAMERA_PROPS,X as FX_FREE_PROPS,_ as FX_OFFSET_PROPS,U as OBJECT_PROPS,T as addKeyAt,Q as copyKeys,v as easeKeys,z as keyAllAt,g as nudgeKeys,W as pasteKeys,J as readProp,I as rowKeyed,H as rowProps,q as writeProp};
1
+ import{dG as P,eI as O,dH as M,ia as R,fK as E,fM as j}from"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const K=(t,e,i=.1)=>["X","Y","Z"].map((o,s)=>({id:t+s,label:`${e} ${o}`,step:i})),A=[...K("p","Vị trí"),...K("t","Nhìn tới"),{id:"lens",label:"Tiêu cự (mm)",step:1,min:14,max:200},{id:"roll",label:"Nghiêng (°)",step:1}],U=[...K("p","Vị trí"),...K("r","Xoay",1),{id:"s",label:"Kích thước",step:.05,min:.05}],_=K("o","Lệch"),X=[...K("p","Vị trí"),{id:"s",label:"Kích thước",step:.05,min:.05}],p=t=>t.shots.find(e=>e.id===t.activeShot)||t.shots[0];function H(t,e){if(e==="camera")return A;const i=t.items.find(o=>o.id===e);return i?i.kind==="fx"?i.fx?.attach?_:X:U:[]}function I(t,e){return e==="camera"?t.motion==="path"&&!!t.cameraKeys?.length:(t.objectKeys?.[e]?.length??0)>0}const y=t=>+t.slice(1);function J(t,e,i,o){const s=p(t);if(e==="camera"){const c=P(s,o);return i==="lens"?c.lens:i==="roll"?c.roll:(i[0]==="p"?c.position:c.target)[y(i)]}const r=t.items.find(c=>c.id===e);if(!r)return 0;if(i[0]==="o")return O(r,s,o).position[y(i)];const n=M(r,s,o);return i==="s"?n.scale[0]:(i[0]==="p"?n.position:n.rotation)[y(i)]}const C=t=>+t.toFixed(3);function q(t,e,i,o,s,r=()=>crypto.randomUUID()){const n=p(t);if(!n||!Number.isFinite(s))return t;const c=f=>({...t,shots:t.shots.map(l=>l.id===n.id?{...l,...f}:l)});if(e==="camera"){const f=P(n,o),l={position:[...f.position],target:[...f.target],roll:f.roll};return i==="roll"?l.roll=s:i!=="lens"&&((i[0]==="p"?l.position:l.target)[y(i)]=s),c(R(n,o,l,r,i==="lens"?s:void 0))}const a=t.items.find(f=>f.id===e);if(!a||a.locked)return t;if(i[0]==="o"){const f=O(a,n,o).position.slice();if(f[y(i)]=s,E(a,n))return j(t,e,o,{position:f});const l={...a.fx.attach,offset:f};return{...t,items:t.items.map(u=>u.id===e?{...u,fx:{...u.fx,attach:l}}:u)}}const d=M(a,n,o),m={position:[...d.position],rotation:[...d.rotation],scale:[...d.scale]};i==="s"?m.scale=d.scale[0]>1e-6?d.scale.map(f=>C(f*s/d.scale[0])):[s,s,s]:(i[0]==="p"?m.position:m.rotation)[y(i)]=s;const h=n.objectKeys?.[e]||[];if(h.length){const f=h.find(u=>Math.abs(u.time-o)<1e-6),l={...f,id:f?.id??r(),time:o,...m};return c({objectKeys:{...n.objectKeys,[e]:[...h.filter(u=>u.id!==l.id),l].sort((u,F)=>u.time-F.time)}})}return{...t,items:t.items.map(f=>f.id===e?{...f,...m}:f)}}const b=1e-6,S=(t,e)=>e==="camera"?t.motion==="path"?t.cameraKeys||[]:[]:t.objectKeys?.[e]||[];function x(t,e,i){const o=p(t),s=[...i].sort((r,n)=>r.time-n.time);if(e==="camera"){const r=s,n=r[0],c=r[r.length-1],a={cameraKeys:r,motion:r.length?"path":"static",...n&&c?{position:n.position,target:n.target,lens:n.lens,roll:n.roll,endPosition:c.position,endTarget:c.target,endLens:c.lens}:{}};return{...t,shots:t.shots.map(d=>d.id===o.id?{...d,...a}:d)}}return{...t,shots:t.shots.map(r=>r.id===o.id?{...r,objectKeys:{...r.objectKeys,[e]:s}}:r)}}const k=(t,e)=>e!=="camera"&&!!t.items.find(i=>i.id===e)?.locked;function T(t,e,i,o=()=>crypto.randomUUID()){const s=p(t);if(!s||k(t,e))return t;const r=S(s,e);if(r.some(a=>Math.abs(a.time-i)<b))return t;if(e==="camera"){const a=P(s,i);return x(t,e,[...r,{id:o(),time:i,position:a.position,target:a.target,lens:a.lens,roll:a.roll}])}const n=t.items.find(a=>a.id===e);if(!n)return t;if(n.kind==="fx"&&n.fx?.attach)return j(t,e,i,{id:o()});const c=M(n,s,i);return x(t,e,[...r,{id:o(),time:i,position:c.position,rotation:c.rotation,scale:c.scale}])}function z(t,e,i){return["camera",...t.items.filter(o=>!o.hidden).map(o=>o.id)].reduce((o,s)=>T(o,s,e,i),t)}function Q(t,e){const i=p(t);return e.flatMap(o=>{const s=S(i,o.row).find(r=>r.id===o.id);return s?[{row:o.row,key:structuredClone(s)}]:[]})}function W(t,e,i,o=()=>crypto.randomUUID()){if(!e.length)return{stage:t,pasted:[]};const s=Math.min(...e.map(c=>c.key.time)),r=[];let n=t;for(const c of new Set(e.map(a=>a.row))){if(k(n,c)||c!=="camera"&&!n.items.some(d=>d.id===c))continue;let a=[...S(p(n),c)];for(const d of e.filter(m=>m.row===c)){const m=Math.min(1,Math.max(0,d.key.time-s+i)),h={...structuredClone(d.key),id:o(),time:m};a=[...a.filter(f=>Math.abs(f.time-m)>=b),h],r.push({row:c,id:h.id})}n=x(n,c,a)}return{stage:n,pasted:r}}function v(t,e,i){let o=t;for(const s of new Set(e.map(r=>r.row))){if(k(o,s))continue;const r=new Set(e.filter(n=>n.row===s).map(n=>n.id));o=x(o,s,S(p(o),s).map(n=>r.has(n.id)?{...n,ease:i}:n))}return o}function g(t,e,i){let o=t,s=!1;for(const r of new Set(e.map(n=>n.row))){if(k(o,r))continue;const n=new Set(e.filter(m=>m.row===r).map(m=>m.id)),a=S(p(o),r).map(m=>n.has(m.id)?{...m,time:m.time+i}:m);a.every(m=>m.time>=-b&&m.time<=1+b)&&a.every((m,h)=>a.every((f,l)=>h>=l||Math.abs(m.time-f.time)>b))&&(s=!0,o=x(o,r,a.map(m=>({...m,time:Math.min(1,Math.max(0,m.time))}))))}return{stage:o,moved:s}}export{A as CAMERA_PROPS,X as FX_FREE_PROPS,_ as FX_OFFSET_PROPS,U as OBJECT_PROPS,T as addKeyAt,Q as copyKeys,v as easeKeys,z as keyAllAt,g as nudgeKeys,W as pasteKeys,J as readProp,I as rowKeyed,H as rowProps,q as writeProp};
@@ -1 +1 @@
1
- import{u as o}from"./store-75tQUvPT.js";import{t as l,c as w}from"./api-DUp403BK.js";import{l as v,d as C}from"./titleArt-B8DVR58F.js";import{i as h}from"./textAnimators-nVSz_sZo.js";import"./titleFrameBudget-BYRZAQPs.js";async function y(g){const e=[],m=o.getState().canvasId;for(const t of g){if(!t.title||t.url){e.push(t);continue}const n=document.createElement("canvas");n.width=1280,n.height=720;const a=n.getContext("2d");if(!a)throw Error("Canvas unavailable");const r=await v(t.title),f=r.filter(h),c=r.filter(i=>!h(i));c.length&&o.getState().toast(l("Font {0} chưa tải được (mạng chập chờn) — chữ tạm dùng font thay thế. Chọn lại font để thử lại.",[c.join(", ")]),"info"),f.length&&o.getState().toast(l("Font riêng của chữ này không còn trong tài khoản của bạn — chữ dùng font mặc định. Tải font lên lại (Chữ → Font) hoặc chọn font khác."),"info"),C(a,t.title);const p=await new Promise((i,d)=>n.toBlob(s=>s?i(s):d(Error("Cannot create title")),"image/png")),u=await w(new File([p],"timeline-title.png",{type:"image/png"}));if(o.getState().canvasId!==m)throw Error("Canvas changed while creating text");e.push({...t,...u})}return e}export{y as materializeTitles};
1
+ import{u as o}from"./store-DW4E9xnW.js";import{t as l,c as w}from"./api-CJ8PdbfZ.js";import{l as v,d as C}from"./titleArt-Drsrtfiv.js";import{i as h}from"./textAnimators-DUZjhVGO.js";import"./titleFrameBudget-CLZWaFHO.js";async function y(g){const e=[],m=o.getState().canvasId;for(const t of g){if(!t.title||t.url){e.push(t);continue}const n=document.createElement("canvas");n.width=1280,n.height=720;const a=n.getContext("2d");if(!a)throw Error("Canvas unavailable");const r=await v(t.title),f=r.filter(h),c=r.filter(i=>!h(i));c.length&&o.getState().toast(l("Font {0} chưa tải được (mạng chập chờn) — chữ tạm dùng font thay thế. Chọn lại font để thử lại.",[c.join(", ")]),"info"),f.length&&o.getState().toast(l("Font riêng của chữ này không còn trong tài khoản của bạn — chữ dùng font mặc định. Tải font lên lại (Chữ → Font) hoặc chọn font khác."),"info"),C(a,t.title);const p=await new Promise((i,d)=>n.toBlob(s=>s?i(s):d(Error("Cannot create title")),"image/png")),u=await w(new File([p],"timeline-title.png",{type:"image/png"}));if(o.getState().canvasId!==m)throw Error("Canvas changed while creating text");e.push({...t,...u})}return e}export{y as materializeTitles};
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/userFonts-DzY0A4bD.js","assets/api-DUp403BK.js","assets/titleFrameBudget-BYRZAQPs.js","assets/store-75tQUvPT.js","assets/textAnimators-nVSz_sZo.js"])))=>i.map(i=>d[i]);
2
- import{_ as rt,mP as it}from"./titleFrameBudget-BYRZAQPs.js";import{u as lt,v as ht,o as ft,R as dt,w as Ne,x as Ue,y as Ee,z as pt,l as qe,A as ut,C as gt,a as ct}from"./textAnimators-nVSz_sZo.js";const Ye=(e,t)=>typeof document<"u"?Object.assign(document.createElement("canvas"),{width:e,height:t}):new OffscreenCanvas(e,t),re=1280,ie=720,ue=new Map,wt=8,He=()=>Ye(re,ie);function Xe(e,t,s){const r=s*Math.PI/180,a=Math.cos(r),h=Math.sin(r),u=(Math.abs(a)*re+Math.abs(h)*ie)/2;return Math.min(1,Math.max(0,((e-re/2)*a+(t-ie/2)*h+u)/(2*u)))}function mt(e){return()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function yt(e,t){const s=He(),r=s.getContext("2d"),{scale:a,size:h,fade:u,fadeAngle:g}=e;if(r.fillStyle=t,e.pattern==="grain"){const w=Math.max(1,Math.round(a/4)),m=Math.ceil(re/w),v=Math.ceil(ie/w),T=mt(1729);for(let c=0;c<v;c++)for(let A=0;A<m;A++){const p=A*w,S=c*w,z=h*(1-u*Xe(p,S,g));T()<z&&r.fillRect(p,S,w,w)}return s}const l=e.angle*Math.PI/180,f=Math.cos(l),i=Math.sin(l),d=Math.hypot(re,ie)/2+a;r.beginPath();for(let w=-d;w<=d;w+=a){if(e.pattern==="lines"){for(let m=-d;m<d;m+=a*2){const v=re/2+(m+a)*f-w*i,T=ie/2+(m+a)*i+w*f,c=a*h*(1-u*Xe(v,T,g))/2;if(c<.15)continue;const A=[[m,w-c],[m+a*2,w-c],[m+a*2,w+c],[m,w+c]].map(([p,S])=>[re/2+p*f-S*i,ie/2+p*i+S*f]);r.moveTo(A[0][0],A[0][1]);for(const[p,S]of A.slice(1))r.lineTo(p,S);r.closePath()}continue}for(let m=-d;m<=d;m+=a){const v=re/2+m*f-w*i,T=ie/2+m*i+w*f;if(v<-a||T<-a||v>re+a||T>ie+a)continue;const c=a*.6*h*(1-u*Xe(v,T,g));c<.3||(r.moveTo(v+c,T),r.arc(v,T,c,0,Math.PI*2))}}return r.fill(),s}function bt(e,t,s){const r=JSON.stringify([e.pattern,e.scale,e.size,e.angle,e.fade,e.fadeAngle,t,s]);let a=ue.get(r);if(a)return ue.delete(r),ue.set(r,a),a;if(a=yt(e,s?"#000000":t),s){const h=He(),u=h.getContext("2d");u.fillStyle="#000000",u.fillRect(0,0,re,ie),u.globalCompositeOperation="destination-out",u.drawImage(a,0,0),a=h}return ue.set(r,a),ue.size>wt&&ue.delete(ue.keys().next().value),a}function Mt(e,t,s){e.save(),e.setTransform(1,0,0,1,0,0),e.filter="none",e.shadowBlur=0,e.globalAlpha=t.opacity,e.globalCompositeOperation=t.mode==="atop"?"source-atop":"destination-out",e.drawImage(bt(t,s,t.mode==="keep"),0,0),e.restore()}const ee={width:1280,height:720};let kt=null;const St=()=>kt??=Ye(ee.width,ee.height);function Tt(e,t){const s=[];for(const r of t.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/userFonts-CwlKh9NR.js","assets/api-CJ8PdbfZ.js","assets/titleFrameBudget-CLZWaFHO.js","assets/store-DW4E9xnW.js","assets/textAnimators-DUZjhVGO.js"])))=>i.map(i=>d[i]);
2
+ import{_ as rt,mP as it}from"./titleFrameBudget-CLZWaFHO.js";import{u as lt,v as ht,o as ft,R as dt,w as Ne,x as Ue,y as Ee,z as pt,l as qe,A as ut,C as gt,a as ct}from"./textAnimators-DUZjhVGO.js";const Ye=(e,t)=>typeof document<"u"?Object.assign(document.createElement("canvas"),{width:e,height:t}):new OffscreenCanvas(e,t),re=1280,ie=720,ue=new Map,wt=8,He=()=>Ye(re,ie);function Xe(e,t,s){const r=s*Math.PI/180,a=Math.cos(r),h=Math.sin(r),u=(Math.abs(a)*re+Math.abs(h)*ie)/2;return Math.min(1,Math.max(0,((e-re/2)*a+(t-ie/2)*h+u)/(2*u)))}function mt(e){return()=>{e|=0,e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function yt(e,t){const s=He(),r=s.getContext("2d"),{scale:a,size:h,fade:u,fadeAngle:g}=e;if(r.fillStyle=t,e.pattern==="grain"){const w=Math.max(1,Math.round(a/4)),m=Math.ceil(re/w),v=Math.ceil(ie/w),T=mt(1729);for(let c=0;c<v;c++)for(let A=0;A<m;A++){const p=A*w,S=c*w,z=h*(1-u*Xe(p,S,g));T()<z&&r.fillRect(p,S,w,w)}return s}const l=e.angle*Math.PI/180,f=Math.cos(l),i=Math.sin(l),d=Math.hypot(re,ie)/2+a;r.beginPath();for(let w=-d;w<=d;w+=a){if(e.pattern==="lines"){for(let m=-d;m<d;m+=a*2){const v=re/2+(m+a)*f-w*i,T=ie/2+(m+a)*i+w*f,c=a*h*(1-u*Xe(v,T,g))/2;if(c<.15)continue;const A=[[m,w-c],[m+a*2,w-c],[m+a*2,w+c],[m,w+c]].map(([p,S])=>[re/2+p*f-S*i,ie/2+p*i+S*f]);r.moveTo(A[0][0],A[0][1]);for(const[p,S]of A.slice(1))r.lineTo(p,S);r.closePath()}continue}for(let m=-d;m<=d;m+=a){const v=re/2+m*f-w*i,T=ie/2+m*i+w*f;if(v<-a||T<-a||v>re+a||T>ie+a)continue;const c=a*.6*h*(1-u*Xe(v,T,g));c<.3||(r.moveTo(v+c,T),r.arc(v,T,c,0,Math.PI*2))}}return r.fill(),s}function bt(e,t,s){const r=JSON.stringify([e.pattern,e.scale,e.size,e.angle,e.fade,e.fadeAngle,t,s]);let a=ue.get(r);if(a)return ue.delete(r),ue.set(r,a),a;if(a=yt(e,s?"#000000":t),s){const h=He(),u=h.getContext("2d");u.fillStyle="#000000",u.fillRect(0,0,re,ie),u.globalCompositeOperation="destination-out",u.drawImage(a,0,0),a=h}return ue.set(r,a),ue.size>wt&&ue.delete(ue.keys().next().value),a}function Mt(e,t,s){e.save(),e.setTransform(1,0,0,1,0,0),e.filter="none",e.shadowBlur=0,e.globalAlpha=t.opacity,e.globalCompositeOperation=t.mode==="atop"?"source-atop":"destination-out",e.drawImage(bt(t,s,t.mode==="keep"),0,0),e.restore()}const ee={width:1280,height:720};let kt=null;const St=()=>kt??=Ye(ee.width,ee.height);function Tt(e,t){const s=[];for(const r of t.split(`
3
3
  `)){let a="";for(const h of Array.from(r))a&&e.measureText(a+h).width>1050&&(s.push(a),a=""),a+=h;s.push(a)}return s}function Rt(e,t,s){if(t.design){if(!t.design.layers.some(S=>S.type==="texture"))return Je(e,t,t.design,s);const A=St(),p=A.getContext("2d");p.setTransform(1,0,0,1,0,0),p.globalAlpha=1,p.globalCompositeOperation="source-over",p.clearRect(0,0,ee.width,ee.height),Je(p,t,t.design,s),e.drawImage(A,0,0);return}const{text:r,fontSize:a,color:h,placement:u,fontFamily:g="Arial",align:l="center",styleId:f="classic",accentColor:i="#32d8cd"}=t,d=f!=="classic",w=d?800:600;e.font=`${w} ${a}px "${g}", sans-serif`,e.textAlign=l,e.textBaseline="middle";const m=Tt(e,r),v=a*(d?1.12:1.3);if(m.length*v>560)throw Error("Text is too long for the frame; reduce copy or font size");const T=m.length*v,c=u==="top"?80+T/2:u==="lower"?640-T/2:360;m.forEach((A,p)=>{const S=l==="left"?90:l==="right"?1190:640,z=c+(p-(m.length-1)/2)*v,Y=e.measureText(A).width;if(e.save(),f==="accent-bar"){const I=l==="left"?S-18:l==="right"?S-Y-18:S-Y/2-18;e.fillStyle=i,e.beginPath(),e.roundRect(I,z-a*.56,Y+36,a*1.12,10),e.fill()}if(f==="tape-label"){const I=a*.45,_=Y+I*2,F=a*1.32,W=l==="left"?S+Y/2:l==="right"?S-Y/2:S,G=(p%2?1:-1)*.028,V=6;e.save(),e.translate(W,z),e.rotate(G),e.beginPath(),e.moveTo(-_/2,-F/2),e.lineTo(_/2,-F/2);for(let E=1;E<=V;E++)e.lineTo(_/2+(E%2?a*.07:0),-F/2+F*E/V);e.lineTo(-_/2,F/2);for(let E=V-1;E>=0;E--)e.lineTo(-_/2-(E%2?a*.07:0),-F/2+F*E/V);e.closePath(),e.shadowColor="rgba(0,0,0,0.22)",e.shadowBlur=a*.12,e.shadowOffsetY=a*.04,e.globalAlpha=.94,e.fillStyle=i,e.fill(),e.shadowColor="transparent",e.globalAlpha=.07,e.strokeStyle="#5a4a30",e.lineWidth=1;for(let E=1;E<5;E++){const ae=-F/2+F*E/5;e.beginPath(),e.moveTo(-_/2,ae),e.lineTo(_/2,ae+(E%2?1.5:-1.5)),e.stroke()}e.restore(),e.save(),e.translate(W,z),e.rotate(G),e.translate(-W,-z)}if(f==="echo-stack"&&(e.fillStyle=i,e.globalAlpha=.82,e.fillText(A,S+13,z+13),e.globalAlpha=1),f==="outline-punch"&&(e.lineWidth=Math.max(4,a*.11),e.lineJoin="round",e.strokeStyle=i,e.strokeText(A,S,z)),f==="neon-edge"&&(e.shadowColor=i,e.shadowBlur=25,e.strokeStyle=i,e.lineWidth=Math.max(3,a*.07),e.lineJoin="round",e.strokeText(A,S,z),e.shadowBlur=12),f==="classic"&&(e.shadowColor="#000000",e.shadowBlur=8),e.fillStyle=f==="duotone-stack"&&p%2?i:h,e.fillText(A,S,z),f==="tape-label"&&e.restore(),f==="duotone-stack"&&p===m.length-1){const I=l==="left"?S:l==="right"?S-Y:S-Y/2;e.fillStyle=i,e.fillRect(I,z+a*.55,Math.min(Y,760),Math.max(4,a*.07))}e.restore()})}const _e=typeof Intl<"u"&&"Segmenter"in Intl?new Intl.Segmenter("vi",{granularity:"grapheme"}):null,he=e=>_e?Array.from(_e.segment(e),t=>t.segment):Array.from(e);function be(e,t){if(t>=.999||!/^#[0-9a-f]{6}$/i.test(e))return e;const s=parseInt(e.slice(1),16),r=Math.max(0,t);return`rgb(${Math.round((s>>16&255)*r)},${Math.round((s>>8&255)*r)},${Math.round((s&255)*r)})`}function Re(e,t,s){if(!/^#[0-9a-f]{6}$/i.test(e))return e;const r=parseInt(e.slice(1),16);return"#"+[r>>16&255,r>>8&255,r&255].map(a=>Math.round(a+(t-a)*s).toString(16).padStart(2,"0")).join("")}const Le=e=>{if(!/^#[0-9a-f]{6}$/i.test(e))return[e,e];const t=ct(e.toLowerCase()).gradient;return[t[0],t.at(-1)]};function Ke(e,t,s,r,a,h,u){const g=s+a/2,l=r+h/2;let f;if(t.type==="radial")f=e.createRadialGradient(g,l,0,g,l,Math.max(a,h)/2);else{const i=(t.angle??90)*Math.PI/180,d=Math.cos(i)*a/2,w=Math.sin(i)*h/2;f=e.createLinearGradient(g-d,l-w,g+d,l+w)}return t.gradient.forEach((i,d)=>f.addColorStop(t.stops?.[d]??d/(t.gradient.length-1),u(i))),f}const Pt=e=>typeof e=="string"?e:e.type==="radial"?e.gradient[0]:e.gradient.at(-1),Te=(e,t)=>{if(!/^#[0-9a-f]{6}$/i.test(e))return`rgba(255,255,255,${t})`;const s=parseInt(e.slice(1),16);return`rgba(${s>>16&255},${s>>8&255},${s&255},${t})`};function Qe(e,t,s,r){const a=r?.stretch??e.stretch;return`${r?.italic?"italic ":""}${r?.weight??e.weight} ${a&&a!=="normal"?a+" ":""}${t}px "${r?.font??s}", sans-serif`}function Pe(e,t,s,r,a){e.font=Qe(t,s,r,a),"letterSpacing"in e&&(e.letterSpacing=`${((a?.tracking??t.tracking??0)*s).toFixed(2)}px`)}const Me=e=>{const t=Math.sin(e*127.1+311.7)*43758.5453;return t-Math.floor(t)},At="#ff2a1f";function Ct(e,t,s,r,a,h,u){const g=Math.max(a*.3,e.measureText(t).width),l=Math.floor(u*14),f=Math.round(2+h*8),i=e.globalAlpha;e.save(),e.shadowColor="transparent",e.filter="none";for(let d=0;d<f;d++){const w=c=>Me(d*13.71+c*3.17+s*.0137+l*.731),m=Math.round(a*(.07+.2*w(1))),v=s-a*.25+(g+a*.5)*w(2)-m/2,T=r-a*1.05+a*1.25*w(3)-m/2;e.globalAlpha=i*Math.min(1,h*1.6)*(.65+.35*w(4)),e.fillStyle=d%3===2?"#ffffff":At,e.fillRect(Math.round(v),Math.round(T),m,m)}e.restore()}function Ze(e,t,s,r){const{fontSize:a,placement:h,fontFamily:u="Arial",align:g="center"}=t,l=s.stack==="ink";e.textBaseline=l?"alphabetic":"middle",e.textAlign="left";const f=!!s.lines,i=s.maxWidth?s.maxWidth*ee.width:1050,d=!!s.lines?.some(T=>T.side||T.x||T.y||T.align),w=T=>{const c=[],A=r.split(`
4
4
  `);A.forEach((y,N)=>{const H=qe(s,N,A.length);let te=a*(H?.scale??1)*T;if(Pe(e,s,te,u,H),f){const k=d?i*T:i,M=e.measureText(y||" ").width;M>k&&(te*=k/M,Pe(e,s,te,u,H))}const o=[];let b="";if(f)o.push(y);else if(s.wrap==="word"){for(const k of y.split(/(\s+)/))if(b&&b.trim()&&e.measureText(b+k).width>i&&k.trim()&&(o.push(b.trimEnd()),b=""),!(!b&&!k.trim()))if(e.measureText(k).width>i)for(const M of he(k))b&&e.measureText(b+M).width>i&&(o.push(b),b=""),b+=M;else b+=k;o.push(b.trimEnd())}else{for(const k of he(y))b&&e.measureText(b+k).width>i&&(o.push(b),b=""),b+=k;o.push(b)}for(const k of o){const M=e.measureText(k||" ");c.push({text:k,paragraph:N,size:te,fill:H?.fill,style:H,width:M.width,left:0,center:0,ascent:l?M.actualBoundingBoxAscent:te*.56,descent:l?M.actualBoundingBoxDescent:te*.56})}});const p=c.map(y=>l?y.ascent+y.descent:y.size*s.lineHeight),S=c.map(y=>l?(s.gap??.08)*y.size:0),z=y=>!!y.style?.side,Y=c.map((y,N)=>N).filter(y=>!z(c[y]));let I=0;Y.forEach((y,N)=>{I+=p[y]+(N?S[y]:0)});const _=(h==="top"?80:h==="lower"?640-I:ee.height/2-I/2)+(s.shiftY??0)*ee.height,F=(g==="left"?90:g==="right"?1190:ee.width/2)+(s.shiftX??0)*ee.width,W=Math.max(0,...Y.map(y=>c[y].width)),G=g==="left"?F:g==="right"?F-W:F-W/2;let V=_;if(Y.forEach((y,N)=>{const H=c[y];N&&(V+=S[y]),H.center=V+p[y]/2,V+=p[y];const te=H.style?.align??g;H.left=te==="left"?G:te==="right"?G+W-H.width:G+(W-H.width)/2}),!d)return{rows:c,heights:p,gaps:S,total:I,box:{x:G,y:_,w:W,h:I},extras:d,ink:l};const E=a*T;for(const y of c)z(y)&&(y.center=_+I/2,y.left=y.style.side==="left"?G-.12*E-y.width:G+W+.12*E),y.left+=(y.style?.x??0)*E,y.center+=(y.style?.y??0)*E;const ae=Math.min(...c.map(y=>y.left)),ge=Math.max(...c.map(y=>y.left+y.width)),se=Math.min(...c.map((y,N)=>y.center-p[N]/2)),ke=Math.max(...c.map((y,N)=>y.center+p[N]/2)),Ae=g==="left"?F-ae:g==="right"?F-ge:F-(ae+ge)/2,ce=(h==="top"?80:h==="lower"?640-(ke-se):ee.height/2-(ke-se)/2)+(s.shiftY??0)*ee.height-se;for(const y of c)y.left+=Ae,y.center+=ce;return{rows:c,heights:p,gaps:S,total:I,box:{x:ae+Ae,y:se+ce,w:ge-ae,h:ke-se},extras:d,ink:l}};let m=w(1),v=1;for(let T=0;T<4;T++){const c=m.extras?m.box.h:m.total,A=Math.max(c/560,m.extras?m.box.w/i:0);if(A<=1)break;v*=.98/A,m=w(v)}if((m.extras?m.box.h:m.total)>560)throw Error("Text is too long for the frame; reduce copy or font size");return m}const xe=(e,t)=>(t.uppercase?e.text.toLocaleUpperCase("vi"):e.text).normalize("NFC");function Et(e){const t=Ye(1,1).getContext("2d");if(!t)return[];if(!e.design){const s=e.text.split(`
5
- `).length,r=Math.min(560,s*e.fontSize*1.3);return[{paragraph:-1,x:115,y:e.placement==="top"?80:e.placement==="lower"?640-r:360-r/2,w:1050,h:r,rotate:0}]}try{const s=Ze(t,e,e.design,xe(e,e.design));return s.rows.map((r,a)=>({paragraph:r.paragraph,x:r.left,y:r.center-s.heights[a]/2,w:r.width,h:s.heights[a],rotate:r.style?.rotate??0}))}catch{return[]}}function vt(e,t,s,r,a,h){const u=[[t,s+h*.1],[t+r*.55,s+h*.2],[t+r,s-h*.26]],g=28,l=[],f=[];for(let i=0;i<=g;i++){const d=i/g,w=(1-d)*(1-d),m=2*(1-d)*d,v=d*d,T=w*u[0][0]+m*u[1][0]+v*u[2][0],c=w*u[0][1]+m*u[1][1]+v*u[2][1],A=2*(1-d)*(u[1][0]-u[0][0])+2*d*(u[2][0]-u[1][0]),p=2*(1-d)*(u[1][1]-u[0][1])+2*d*(u[2][1]-u[1][1]),S=Math.hypot(A,p)||1,z=a*Math.pow(Math.sin(Math.PI*d),.55)*(1.25-.55*d)/2;l.push([T-p/S*z,c+A/S*z]),f.push([T+p/S*z,c-A/S*z])}e.beginPath(),e.moveTo(l[0][0],l[0][1]);for(const i of l.slice(1))e.lineTo(i[0],i[1]);for(const i of f.reverse())e.lineTo(i[0],i[1]);e.closePath()}function Ge(e,t,s,r,a){if(e.globalAlpha*=Math.min(1,Math.max(0,t.opacity)),e.globalAlpha<.002)return!1;const h=a*.3;if(t.wipeX<1){const l=(s.w+2*h)*Math.max(0,t.wipeX);e.beginPath(),e.rect(r==="right"?s.x+s.w+h-l:s.x-h,s.y-a*2,l,s.h+a*4),e.clip()}if(t.wipeY<1){const l=(s.h+2*h)*Math.max(0,t.wipeY);e.beginPath(),e.rect(s.x-a*2,r==="bottom"?s.y+s.h+h-l:s.y-h,s.w+a*4,l),e.clip()}const u=r==="left"?s.x:r==="right"?s.x+s.w:s.x+s.w/2,g=r==="top"?s.y:r==="bottom"?s.y+s.h:s.y+s.h/2;return e.translate(u+t.x*a,g+t.y*a),e.rotate(t.rotate*Math.PI/180),e.scale(t.scale*t.scaleX,t.scale*t.scaleY),e.translate(-u,-g),!0}const je=[];function De(e,t,s){let r=je[e];return(!r||r.width!==t||r.height!==s)&&(r=typeof document<"u"?Object.assign(document.createElement("canvas"),{width:t,height:s}):new OffscreenCanvas(t,s),je[e]=r),r.getContext("2d")}function zt(e,t,s,r){const a=e.canvas.width,h=e.canvas.height,u=e.getTransform(),g=De(0,a,h),l=De(1,a,h),f=i=>{i.font=e.font,i.textAlign=e.textAlign,i.textBaseline=e.textBaseline;const d=i,w=e;for(const m of["letterSpacing","fontStretch","fontKerning"])m in w&&(d[m]=w[m])};g.setTransform(1,0,0,1,0,0),g.globalCompositeOperation="source-over",g.clearRect(0,0,a,h),g.fillStyle=s,g.fillRect(0,0,a,h),g.setTransform(u),f(g),g.globalCompositeOperation="destination-out",g.fillStyle="#000",t(g),l.setTransform(1,0,0,1,0,0),l.globalCompositeOperation="source-over",l.clearRect(0,0,a,h),l.filter=`blur(${Math.max(.5,r).toFixed(1)}px)`,l.drawImage(g.canvas,0,0),l.filter="none",l.setTransform(u),f(l),l.globalCompositeOperation="destination-in",l.fillStyle="#000",t(l),e.save(),e.setTransform(1,0,0,1,0,0),e.shadowColor="transparent",e.filter="none",e.drawImage(l.canvas,0,0),e.restore()}function It(e,t,s,r,a,h){const{fontSize:u,fontFamily:g="Arial"}=t,l=qe(s,0,1),f=u*(l?.scale??1);Pe(e,s,f,g,l);const i=he(r.replace(/\s*\n\s*/g," ")),d=i.map(p=>e.measureText(p).width),w=h?h.time:0,m=it(s.path,d,w,ee),v=i.length,T=h&&t.animation?Math.min(.8,Math.max(.1,h.duration*.4)):0,c=p=>{if(typeof p=="string")return a(p);const S=f*.5,z=(p.angle??90)*Math.PI/180,Y=Math.cos(z)*S,I=Math.sin(z)*S,_=p.type==="radial"?e.createRadialGradient(0,0,0,0,0,f*.6):e.createLinearGradient(-Y,-I,Y,I);return p.gradient.forEach((F,W)=>_.addColorStop(p.stops?.[W]??W/Math.max(1,p.gradient.length-1),a(F))),_};e.textAlign="center",e.textBaseline="middle";const A=h&&t.animators?.length?Ue(t.animators,Ne([i.join("")]),h.time):null;for(const p of s.layers){if(p.type!=="text")continue;e.save(),e.globalAlpha=p.opacity,p.shadow&&(e.shadowColor=a(p.shadow.color),e.shadowBlur=p.shadow.blur*f,e.shadowOffsetX=p.shadow.x*f,e.shadowOffsetY=p.shadow.y*f);const S=(p.offset?.x||0)*f,z=(p.offset?.y||0)*f;i.forEach((Y,I)=>{const _=m[I];if(!_.visible||!Y.trim())return;const F=T?Math.min(1,Math.max(0,(w-I/Math.max(1,v)*T)/.15)):1;if(F<=0)return;const W=A?.[I];if(W&&(W.opacity<=.002||W.scale<=1e-4))return;e.save(),e.globalAlpha*=F,e.translate(_.x+S,_.y+z),e.rotate(_.angle);const G=()=>{p.stroke&&(e.strokeStyle=a(p.stroke.color),e.lineWidth=Math.max(1.5,p.stroke.width*f),e.strokeText(Y,0,0)),e.fillStyle=c(p.fill),e.fillText(Y,0,0)};W?et(e,W,0,0,G,V=>V==="fill"?e.fillText(Y,0,0):e.strokeText(Y,0,0)):G(),e.restore()}),e.restore()}}const ve=new Map;function $t(e,t,s){const r=e.font+"|"+(e.letterSpacing??"")+"|"+t;let a=ve.get(r);if(!a){let h="";a=[0];for(const u of s)h+=u,a.push(e.measureText(h).width);ve.size>400&&ve.clear(),ve.set(r,a)}return a}function et(e,t,s,r,a,h){e.globalAlpha*=t.opacity,e.translate(s+t.x,r+t.y),t.rotate&&e.rotate(t.rotate*Math.PI/180),t.skew&&e.transform(1,0,Math.tan(-t.skew*Math.PI/180),1,0,0),t.scale!==1&&e.scale(t.scale,t.scale),e.translate(-s,-r),t.blur>.05&&(e.filter=`blur(${t.blur.toFixed(1)}px)`),t.stroke>.05&&t.strokeColor&&(e.save(),e.lineWidth=t.stroke*2,e.lineJoin="round",e.strokeStyle=t.strokeColor,h("stroke"),e.restore()),a(),t.fill&&t.fillAmount>.002&&(e.save(),e.shadowColor="transparent",e.globalAlpha*=t.fillAmount,e.fillStyle=t.fill,h("fill"),e.restore())}function Je(e,t,s,r){const{fontSize:a,color:h,fontFamily:u="Arial",align:g="center",accentColor:l="#dfff00"}=t,f=xe(t,s),i=o=>o==="{color}"?h:o==="{accent}"?l:o==="{accent-hi}"?Re(l,255,.5):o==="{accent-lo}"?Re(l,0,.45):o==="{accent-bright}"?Le(l)[0]:o==="{accent-deep}"?Le(l)[1]:o==="{color-lo}"?Re(h,0,.45):o==="transparent"?"rgba(0,0,0,0)":o;if(e.lineJoin="round",s.path){It(e,t,s,f,i,r);return}const{rows:d,heights:w,total:m,box:v,extras:T,ink:c}=Ze(e,t,s,f),A=o=>c?o.center+(o.ascent-o.descent)/2:o.center,p=o=>c?w[o]:d[o].size*1.12,S=Math.max(...d.map(o=>o.paragraph))+1,z=r&&t.animation?t.animation:void 0,Y=z?Array.from({length:S},(o,b)=>{const k=d.filter(M=>M.paragraph===b).map(M=>M.text).join(" ");return{word:Math.max(1,k.split(/\s+/).filter(Boolean).length),char:Math.max(1,he(k.replace(/\s/g,"")).length)}}):[],I=z&&r?ht(z,Y,r.time,r.duration,ft(s,d.length)):r?r.time:1e6,_={...dt,masked:!1},F=(o,b,k,M)=>z?gt(z,o,b,k,M,I):_,W=(o,b,k,M,n,oe)=>typeof o=="string"?be(i(o),oe):Ke(e,o,b,k,M,n,Q=>be(i(Q),oe));let G=0,V=0;const E=(o,b,k,M,n,oe=b-4e3,Q=8e3)=>{if(e.globalAlpha*=Math.min(1,Math.max(0,o.opacity)),o.flicker>0&&Me(Math.floor(I*24)+b*.01)<o.flicker&&(e.globalAlpha=0),o.reveal<1||o.masked){const $=Math.max(0,M*o.reveal);e.beginPath(),e.rect(-4e3,k-$,8e3,$*2),e.clip()}o.wipeX<1&&(e.beginPath(),e.rect(oe-n*.1,k-M*1.6,(Q+n*.2)*Math.max(0,o.wipeX),M*3.2),e.clip()),o.wipeY<1&&(e.beginPath(),e.rect(-4e3,k-M*1.2,8e3,M*2.4*Math.max(0,o.wipeY)),e.clip());const j=o.glitch>0?o.glitch*n*.35*(Me(Math.floor(I*18)+k*.01)*2-1):0;G=Math.max(G,o.glitch),V=Math.max(V,o.pixels);const O=o.scatter>0?o.scatter*n*(Me(b*.0173+k*.0071+1.3)*2-1):0,K=o.scatter>0?o.scatter*n*.7*(Me(b*.0119+k*.0153+7.9)*2-1):0;return e.translate(b+o.x*n+j+O,k+o.y*n+K),e.rotate(o.rotate*Math.PI/180),e.scale(o.scale*o.scaleX,o.scale*o.scaleY),e.translate(-b,-k),o.blur>0&&(e.filter=`blur(${(o.blur*n).toFixed(1)}px)`),o.brightness},ae=o=>{Pe(e,s,o.size,u,o.style);const b=d.filter(O=>O.paragraph===o.paragraph&&d.indexOf(O)<d.indexOf(o));let k=he(b.map(O=>O.text).join("").replace(/\s/g,"")).length,M=b.map(O=>O.text).join(" ").split(/\s+/).filter(Boolean).length;const n=[];let oe=M-1,Q=!0,j="";for(const O of he(o.text)){const K=e.measureText(j).width;if(j+=O,/\s/.test(O)){Q=!0;continue}Q&&(oe++,Q=!1),n.push({text:O,x:o.left+K,w:e.measureText(j).width-K,char:k++,word:oe})}return n},ge=(o,b)=>!!z?.in.some(k=>k.unit===b&&(!k.lines||k.lines.includes(o))),se=o=>Y[o]||{word:1,char:1},ke=Array.from({length:S},(o,b)=>d.filter(k=>k.paragraph===b).map(k=>k.text).join(" ").split(/\s+/).filter(Boolean).length),Ae=o=>ke.slice(0,o).reduce((b,k)=>b+k,0),ce=o=>o.style?.align??g,y=r&&t.animators?.length?t.animators:null,N=y?Ne(d.map(o=>o.text)):null,H=y&&N?Ue(y,N,r.time):null,te=[];if(N){let o=0;for(let b=0;b<d.length;b++)te.push(o),o+=he(d[b].text).length}for(const o of s.layers){if(o.type==="texture"){Mt(e,o,i(o.color));continue}if(o.type==="shape"||o.type==="icon"){e.save(),Ft(e,o,I,i),e.restore();continue}if(e.save(),e.globalAlpha=o.opacity,o.type==="box"&&o.per==="block"){const M=d[0],n=F("line",M.paragraph,M.paragraph,S),oe=o.padX*a,Q=o.padY*a,j=(T?v.x:Math.min(...d.map(L=>L.left)))-oe,O=(T?v.y:d[0].center-p(0)/2)-Q,K=(T?v.w:Math.max(...d.map(L=>L.width)))+oe*2,$=(T?v.h:m-(w[0]-p(0))/2-(w.at(-1)-p(d.length-1))/2)+Q*2,U=E(n,j+K/2,O+$/2,$/2,a);(!o.motion||Ge(e,Ee(o.motion,I),{x:j,y:O,w:K,h:$},o.motion.origin,a))&&(o.skewX&&(e.translate(j+K/2,O+$/2),e.transform(1,0,Math.tan(-o.skewX*Math.PI/180),1,0,0),e.translate(-j-K/2,-O-$/2)),o.shadow&&(e.shadowColor=i(o.shadow.color),e.shadowBlur=o.shadow.blur*a,e.shadowOffsetX=o.shadow.x*a,e.shadowOffsetY=o.shadow.y*a),e.fillStyle=W(o.fill,j,O,K,$,U),e.beginPath(),e.roundRect(j,O,K,$,o.radius*a),e.fill(),o.stroke&&(e.strokeStyle=be(i(o.stroke.color),U),e.lineWidth=Math.max(1.5,o.stroke.width*a),e.stroke())),e.restore();continue}const b=d.map((M,n)=>o.lines?o.lines.includes(M.paragraph):o.type==="underline"?o.line==="all"||n===d.length-1:!0);let k=0;for(const[M,n]of d.entries()){if(!b[M])continue;const oe=k++;e.save();const Q=n.left+n.width/2;n.style?.rotate&&(e.translate(Q,n.center),e.rotate(n.style.rotate*Math.PI/180),e.translate(-Q,-n.center));const j=F("line",n.paragraph,n.paragraph,S);G=0,V=0;const O=E(j,Q,n.center,w[M]/2+n.size*.1,n.size,n.left,n.width),K=$=>!o.motion||Ge(e,Ee(o.motion,I-(o.motion.stagger??0)*oe),$,o.motion.origin,n.size);if(o.type==="box"){const $=o.padX*n.size,U=o.padY*n.size,L=n.left-$,B=n.center-p(M)/2-U,D=n.width+$*2,fe=p(M)+U*2;K({x:L,y:B,w:D,h:fe})&&(o.skewX&&(e.translate(L+D/2,B+fe/2),e.transform(1,0,Math.tan(-o.skewX*Math.PI/180),1,0,0),e.translate(-L-D/2,-B-fe/2)),o.shadow&&(e.shadowColor=i(o.shadow.color),e.shadowBlur=o.shadow.blur*n.size,e.shadowOffsetX=o.shadow.x*n.size,e.shadowOffsetY=o.shadow.y*n.size),e.fillStyle=W(o.fill,L,B,D,fe,O),e.beginPath(),e.roundRect(L,B,D,fe,o.radius*n.size),e.fill(),o.stroke&&(e.strokeStyle=be(i(o.stroke.color),O),e.lineWidth=Math.max(1.5,o.stroke.width*n.size),e.stroke()))}if(o.type==="underline"){const $=n.width*o.width,U=ce(n),L=U==="left"?n.left:U==="right"?n.left+n.width-$:n.left+(n.width-$)/2,B=n.center+o.offsetY*n.size,D=Math.max(3,o.height*n.size);K({x:L,y:B-(o.style==="swash"?n.size*.3:0),w:$,h:D+(o.style==="swash"?n.size*.5:0)})&&(e.fillStyle=W(o.fill,L,B,$,D,O),o.style==="swash"?(vt(e,L,B,$,D,n.size),e.fill()):e.fillRect(L,B,$,D))}if(o.type==="text"){Pe(e,s,n.size,u,n.style);const $=j.count!==1?pt(n.text,j.count):n.text;let U=n.left,L=n.width;if($!==n.text){L=e.measureText($).width;const P=ce(n);U=P==="left"?n.left:P==="right"?n.left+n.width-L:n.left+(n.width-L)/2}const B=(o.offset?.x||0)*n.size,D=(o.offset?.y||0)*n.size;if(r&&o.flicker&&Me(Math.floor(I*12)*1.37+5)<o.flicker&&(e.globalAlpha*=.18),!K({x:U+B-n.size*.05,y:n.center-p(M)/2+D-n.size*.12,w:L+n.size*.1,h:p(M)+n.size*.24})){e.restore();continue}o.shadow&&(e.shadowColor=i(o.shadow.color),e.shadowBlur=o.shadow.blur*n.size,e.shadowOffsetX=o.shadow.x*n.size,e.shadowOffsetY=o.shadow.y*n.size);const fe=o.lineFills?o.lineFills[M%o.lineFills.length]:void 0;let we=null;if(r&&o.shine){const P=o.shine;let X=I-P.start;X>=0&&P.every>0&&(X%=P.every);const q=X/P.duration;if(X>=0&&q<1){const C=P.width*n.size,R=U-C+(L+C*2)*q,Z=P.angle*Math.PI/180,x=i(P.color);we=e.createLinearGradient(R-C*Math.cos(Z),n.center-C*Math.sin(Z),R+C*Math.cos(Z),n.center+C*Math.sin(Z)),we.addColorStop(0,Te(x,0)),we.addColorStop(.5,Te(x,1)),we.addColorStop(1,Te(x,0))}}const tt=fe??(n.fill&&o.fill==="{color}"?n.fill:o.fill),ot=n.center-p(M)/2+D,at=(P,X)=>W(P,U+B,ot,L,p(M),X),nt=o.reflection?A(n)+D+e.measureText($).actualBoundingBoxDescent:0,Se=(P,X,q,C)=>{const R=A(n)+D,Z=C??tt;if(V>.02&&Ct(e,P,X+B,R,n.size,V,I),G>.02){const x=e.globalAlpha,ne=G*n.size*.08;e.globalAlpha=x*.85,e.fillStyle="#fd436a",e.fillText(P,X+B+ne,R),e.fillStyle="#37eaff",e.fillText(P,X+B-ne,R),e.globalAlpha=x}if(o.stroke&&(e.strokeStyle=be(i(o.stroke.color),q),e.lineWidth=Math.max(2,o.stroke.width*n.size),e.strokeText(P,X+B,R)),e.fillStyle=at(Z,q),e.fillText(P,X+B,R),o.innerGlow){const x=e.getTransform();zt(e,ne=>ne.fillText(P,X+B,R),be(i(o.innerGlow.color),q),o.innerGlow.blur*n.size*Math.hypot(x.a,x.b))}if(we&&(e.save(),e.shadowColor="transparent",e.fillStyle=we,e.fillText(P,X+B,R),e.restore()),o.reflection){const x=o.reflection,ne=nt+x.gap*n.size,Oe=p(M)*x.fade,J=i(Pt(Z)),de=!/^#[0-9a-f]{6}$/i.test(J),pe=de&&o.stroke?i(o.stroke.color):J;e.save(),e.shadowColor="transparent",e.filter="none",e.translate(0,2*ne),e.scale(1,-1);const ye=e.createLinearGradient(0,ne,0,ne-Oe);ye.addColorStop(0,Te(pe,x.opacity)),ye.addColorStop(1,Te(pe,0)),de&&o.stroke?(e.strokeStyle=ye,e.lineWidth=Math.max(2,o.stroke.width*n.size),e.strokeText(P,X+B,R)):(e.fillStyle=ye,e.fillText(P,X+B,R)),e.restore()}},me=new Map;for(const P of o.highlights??[])for(const X of P.words)me.set(X,P.fill);const ze=Ae(n.paragraph),Ie=ge(n.paragraph,"word"),$e=ge(n.paragraph,"char"),Fe=j.spread;if(H){const P=he(n.text),X=$t(e,n.text,P),q=te[M],C=ae(n);let R=0;for(let J=0;J<P.length;J++)R+=H[q+J].tracking;const Z=ce(n);let ne=Z==="left"?0:Z==="right"?-R:-R/2,Oe=0;for(let J=0;J<P.length;J++){const de=H[q+J],pe=n.left+X[J],ye=X[J+1]-X[J],We=!/\S/u.test(P[J]),le=We?null:C[Oe++],Ce=ne;if(ne+=de.tracking,We||!le||de.opacity<=.002||de.scale<=1e-4)continue;e.save();let Be=O;Ie&&(Be*=E(F("word",n.paragraph,le.word,se(n.paragraph).word),le.x+le.w/2,n.center,w[M]/2+n.size*.1,n.size)),$e&&(Be*=E(F("char",n.paragraph,le.char,se(n.paragraph).char),le.x+le.w/2,n.center,w[M]/2+n.size*.1,n.size)),e.globalAlpha>.002&&et(e,de,pe+Ce+B+ye/2,n.center,()=>Se(P[J],pe+Ce,Be,me.get(ze+le.word)),st=>st==="fill"?e.fillText(P[J],pe+Ce+B,A(n)+D):e.strokeText(P[J],pe+Ce+B,A(n)+D)),e.restore()}}else if(!Ie&&!$e&&!Fe)if(!me.size||$!==n.text)Se($,U,O);else{const P=new Map;for(const C of ae(n)){const R=ze+C.word,Z=P.get(R);P.set(R,Z?{x0:Math.min(Z.x0,C.x),x1:Math.max(Z.x1,C.x+C.w)}:{x0:C.x,x1:C.x+C.w})}const X=[...P].filter(([C])=>me.has(C)),q=n.size*.04;e.save(),e.beginPath(),e.rect(-1e5,-1e5,2e5,2e5);for(const[,C]of X)e.rect(C.x0+B-q,-1e5,C.x1-C.x0+q*2,2e5);e.clip("evenodd"),Se($,U,O),e.restore();for(const[C,R]of X)e.save(),e.beginPath(),e.rect(R.x0+B-q,-1e5,R.x1-R.x0+q*2,2e5),e.clip(),Se($,U,O,me.get(C)),e.restore()}else{const P=ae(n),X=(P.length-1)/2;for(const[q,C]of P.entries()){e.save(),Fe&&e.translate((q-X)*Fe*n.size,0);let R=O;Ie&&(R*=E(F("word",n.paragraph,C.word,se(n.paragraph).word),C.x+C.w/2,n.center,w[M]/2+n.size*.1,n.size)),$e&&(R*=E(F("char",n.paragraph,C.char,se(n.paragraph).char),C.x+C.w/2,n.center,w[M]/2+n.size*.1,n.size)),e.globalAlpha>.002&&Se(C.text,C.x,R,me.get(ze+C.word)),e.restore()}}}e.restore()}e.restore()}}function Ft(e,t,s,r){const a=ee.width,h=ee.height,u=Ee(t.motion,s);if(e.globalAlpha=t.opacity*Math.min(1,Math.max(0,u.opacity)),e.globalAlpha<.002)return;let g,l,f,i;t.type==="shape"?(g=(t.box[0]+t.box[2]/2)*a,l=(t.box[1]+t.box[3]/2)*h,f=t.box[2]*a,i=t.box[3]*h):(f=i=t.size*h,g=t.center[0]*a,l=t.center[1]*h);const d=t.motion?.origin??"center",w=d==="left"?g-f/2:d==="right"?g+f/2:g,m=d==="top"?l-i/2:d==="bottom"?l+i/2:l;if(u.wipeX<1&&(e.beginPath(),e.rect(g-f/2-8,l-i/2-8,(f+16)*Math.max(0,u.wipeX),i+16),e.clip()),u.wipeY<1&&(e.beginPath(),e.rect(g-f/2-8,l-i/2-8,f+16,(i+16)*Math.max(0,u.wipeY)),e.clip()),e.translate(w+u.x*a,m+u.y*h),e.scale(u.scale*u.scaleX,u.scale*u.scaleY),e.translate(g-w,l-m),e.rotate(((t.rotate||0)+u.rotate)*Math.PI/180),t.type==="shape"){if(t.skewX&&e.transform(1,0,Math.tan(t.skewX*Math.PI/180),1,0,0),t.blur&&(e.filter=`blur(${(t.blur*h).toFixed(1)}px)`),t.shape==="glow"){const c=typeof t.fill=="string"?r(t.fill):r(t.stroke?.color??"{accent}"),A=Math.max(f,i)/2;e.scale(f/2/A,i/2/A);const p=e.createRadialGradient(0,0,0,0,0,A);p.addColorStop(0,c),p.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=p,e.beginPath(),e.arc(0,0,A,0,Math.PI*2),e.fill();return}e.beginPath(),t.shape==="rect"?e.roundRect(-f/2,-i/2,f,i,Math.min(f,i)/2*Math.min(1,t.radius*2)):e.ellipse(0,0,f/2,i/2,0,0,Math.PI*2),t.fill&&(typeof t.fill=="string"?e.fillStyle=r(t.fill):e.fillStyle=Ke(e,t.fill,-f/2,-i/2,f,i,r),e.fill()),t.stroke&&(e.strokeStyle=r(t.stroke.color),e.lineWidth=t.stroke.width,e.setLineDash(t.stroke.dash??[]),e.stroke());return}if(t.glow&&(e.shadowColor=r(t.color),e.shadowBlur=t.glow*f*.5),t.badge!=="none"){e.save(),t.badge==="diamond"&&e.rotate(Math.PI/4);const c=t.badge==="diamond"?f*.72:f;e.beginPath(),t.badge==="circle"?e.arc(0,0,f/2,0,Math.PI*2):e.roundRect(-c/2,-c/2,c,c,t.badge==="square"?0:c*.22),t.badgeFill&&(e.fillStyle=r(t.badgeFill),e.fill()),t.badgeStroke&&(e.strokeStyle=r(t.badgeStroke),e.lineWidth=2,e.stroke()),e.restore()}e.shadowBlur=0;const v=f*.6,T=v/24;e.translate(-v/2,-v/2),e.scale(T,T),e.strokeStyle=r(t.color),e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round";for(const c of ut[t.name]??[])e.stroke(new Path2D(c))}function Ot(e){const t=[];for(const s of Array.from(document.styleSheets)){let r;try{r=s.cssRules}catch{continue}for(const a of Array.from(r))if(a instanceof CSSFontFaceRule&&a.style.getPropertyValue("font-family").replace(/['"]/g,"").trim()===e){const h=a.style.getPropertyValue("src");if(!h)continue;t.push(new FontFace(e,h,{weight:a.style.getPropertyValue("font-weight")||"normal",stretch:a.style.getPropertyValue("font-stretch")||"normal",style:a.style.getPropertyValue("font-style")||"normal"}))}}return t}const Ve=async(e,t)=>{try{return await document.fonts.load(e,t),!0}catch{}await new Promise(r=>setTimeout(r,400));const s=e.match(/"([^"]+)"/)?.[1]??"";try{const r=Ot(s);return r.length?(await Promise.all(r.map(a=>a.load().then(()=>document.fonts.add(a)))),!0):!1}catch{return!1}};async function Yt(e){const t=lt(e),s=[];if(t.length){const l=await rt(()=>import("./userFonts-DzY0A4bD.js"),__vite__mapDeps([0,1,2,3,4]));await l.userFontsReady();for(const f of t)l.isMissingCustomFont(f)&&s.push(f)}const r=e.design?.weight??(e.styleId&&e.styleId!=="classic"?800:600),a=e.design?.stretch&&e.design.stretch!=="normal"?e.design.stretch+" ":"",h=e.fontFamily||"Arial",u=[];await Ve(`${r} ${a}${e.fontSize}px "${h}"`,e.text)||u.push(h);const g=e.design;if(g?.lines?.some(l=>l.font||l.weight||l.italic||l.stretch)){const l=[...new Set(g.lines.map(i=>Qe(g,e.fontSize,h,i).replace(/ sans-serif$/,"").replace(/,$/,"")))],f=await Promise.all(l.map(i=>Ve(i,e.text)));l.forEach((i,d)=>{f[d]||u.push(i.replace(/^.*?"([^"]+)".*$/,"$1"))})}return[...new Set([...u.filter(l=>!s.includes(l)),...s])]}export{Rt as d,Yt as l,Et as t};
5
+ `).length,r=Math.min(560,s*e.fontSize*1.3);return[{paragraph:-1,x:115,y:e.placement==="top"?80:e.placement==="lower"?640-r:360-r/2,w:1050,h:r,rotate:0}]}try{const s=Ze(t,e,e.design,xe(e,e.design));return s.rows.map((r,a)=>({paragraph:r.paragraph,x:r.left,y:r.center-s.heights[a]/2,w:r.width,h:s.heights[a],rotate:r.style?.rotate??0}))}catch{return[]}}function vt(e,t,s,r,a,h){const u=[[t,s+h*.1],[t+r*.55,s+h*.2],[t+r,s-h*.26]],g=28,l=[],f=[];for(let i=0;i<=g;i++){const d=i/g,w=(1-d)*(1-d),m=2*(1-d)*d,v=d*d,T=w*u[0][0]+m*u[1][0]+v*u[2][0],c=w*u[0][1]+m*u[1][1]+v*u[2][1],A=2*(1-d)*(u[1][0]-u[0][0])+2*d*(u[2][0]-u[1][0]),p=2*(1-d)*(u[1][1]-u[0][1])+2*d*(u[2][1]-u[1][1]),S=Math.hypot(A,p)||1,z=a*Math.pow(Math.sin(Math.PI*d),.55)*(1.25-.55*d)/2;l.push([T-p/S*z,c+A/S*z]),f.push([T+p/S*z,c-A/S*z])}e.beginPath(),e.moveTo(l[0][0],l[0][1]);for(const i of l.slice(1))e.lineTo(i[0],i[1]);for(const i of f.reverse())e.lineTo(i[0],i[1]);e.closePath()}function Ge(e,t,s,r,a){if(e.globalAlpha*=Math.min(1,Math.max(0,t.opacity)),e.globalAlpha<.002)return!1;const h=a*.3;if(t.wipeX<1){const l=(s.w+2*h)*Math.max(0,t.wipeX);e.beginPath(),e.rect(r==="right"?s.x+s.w+h-l:s.x-h,s.y-a*2,l,s.h+a*4),e.clip()}if(t.wipeY<1){const l=(s.h+2*h)*Math.max(0,t.wipeY);e.beginPath(),e.rect(s.x-a*2,r==="bottom"?s.y+s.h+h-l:s.y-h,s.w+a*4,l),e.clip()}const u=r==="left"?s.x:r==="right"?s.x+s.w:s.x+s.w/2,g=r==="top"?s.y:r==="bottom"?s.y+s.h:s.y+s.h/2;return e.translate(u+t.x*a,g+t.y*a),e.rotate(t.rotate*Math.PI/180),e.scale(t.scale*t.scaleX,t.scale*t.scaleY),e.translate(-u,-g),!0}const je=[];function De(e,t,s){let r=je[e];return(!r||r.width!==t||r.height!==s)&&(r=typeof document<"u"?Object.assign(document.createElement("canvas"),{width:t,height:s}):new OffscreenCanvas(t,s),je[e]=r),r.getContext("2d")}function zt(e,t,s,r){const a=e.canvas.width,h=e.canvas.height,u=e.getTransform(),g=De(0,a,h),l=De(1,a,h),f=i=>{i.font=e.font,i.textAlign=e.textAlign,i.textBaseline=e.textBaseline;const d=i,w=e;for(const m of["letterSpacing","fontStretch","fontKerning"])m in w&&(d[m]=w[m])};g.setTransform(1,0,0,1,0,0),g.globalCompositeOperation="source-over",g.clearRect(0,0,a,h),g.fillStyle=s,g.fillRect(0,0,a,h),g.setTransform(u),f(g),g.globalCompositeOperation="destination-out",g.fillStyle="#000",t(g),l.setTransform(1,0,0,1,0,0),l.globalCompositeOperation="source-over",l.clearRect(0,0,a,h),l.filter=`blur(${Math.max(.5,r).toFixed(1)}px)`,l.drawImage(g.canvas,0,0),l.filter="none",l.setTransform(u),f(l),l.globalCompositeOperation="destination-in",l.fillStyle="#000",t(l),e.save(),e.setTransform(1,0,0,1,0,0),e.shadowColor="transparent",e.filter="none",e.drawImage(l.canvas,0,0),e.restore()}function It(e,t,s,r,a,h){const{fontSize:u,fontFamily:g="Arial"}=t,l=qe(s,0,1),f=u*(l?.scale??1);Pe(e,s,f,g,l);const i=he(r.replace(/\s*\n\s*/g," ")),d=i.map(p=>e.measureText(p).width),w=h?h.time:0,m=it(s.path,d,w,ee),v=i.length,T=h&&t.animation?Math.min(.8,Math.max(.1,h.duration*.4)):0,c=p=>{if(typeof p=="string")return a(p);const S=f*.5,z=(p.angle??90)*Math.PI/180,Y=Math.cos(z)*S,I=Math.sin(z)*S,_=p.type==="radial"?e.createRadialGradient(0,0,0,0,0,f*.6):e.createLinearGradient(-Y,-I,Y,I);return p.gradient.forEach((F,W)=>_.addColorStop(p.stops?.[W]??W/Math.max(1,p.gradient.length-1),a(F))),_};e.textAlign="center",e.textBaseline="middle";const A=h&&t.animators?.length?Ue(t.animators,Ne([i.join("")]),h.time):null;for(const p of s.layers){if(p.type!=="text")continue;e.save(),e.globalAlpha=p.opacity,p.shadow&&(e.shadowColor=a(p.shadow.color),e.shadowBlur=p.shadow.blur*f,e.shadowOffsetX=p.shadow.x*f,e.shadowOffsetY=p.shadow.y*f);const S=(p.offset?.x||0)*f,z=(p.offset?.y||0)*f;i.forEach((Y,I)=>{const _=m[I];if(!_.visible||!Y.trim())return;const F=T?Math.min(1,Math.max(0,(w-I/Math.max(1,v)*T)/.15)):1;if(F<=0)return;const W=A?.[I];if(W&&(W.opacity<=.002||W.scale<=1e-4))return;e.save(),e.globalAlpha*=F,e.translate(_.x+S,_.y+z),e.rotate(_.angle);const G=()=>{p.stroke&&(e.strokeStyle=a(p.stroke.color),e.lineWidth=Math.max(1.5,p.stroke.width*f),e.strokeText(Y,0,0)),e.fillStyle=c(p.fill),e.fillText(Y,0,0)};W?et(e,W,0,0,G,V=>V==="fill"?e.fillText(Y,0,0):e.strokeText(Y,0,0)):G(),e.restore()}),e.restore()}}const ve=new Map;function $t(e,t,s){const r=e.font+"|"+(e.letterSpacing??"")+"|"+t;let a=ve.get(r);if(!a){let h="";a=[0];for(const u of s)h+=u,a.push(e.measureText(h).width);ve.size>400&&ve.clear(),ve.set(r,a)}return a}function et(e,t,s,r,a,h){e.globalAlpha*=t.opacity,e.translate(s+t.x,r+t.y),t.rotate&&e.rotate(t.rotate*Math.PI/180),t.skew&&e.transform(1,0,Math.tan(-t.skew*Math.PI/180),1,0,0),t.scale!==1&&e.scale(t.scale,t.scale),e.translate(-s,-r),t.blur>.05&&(e.filter=`blur(${t.blur.toFixed(1)}px)`),t.stroke>.05&&t.strokeColor&&(e.save(),e.lineWidth=t.stroke*2,e.lineJoin="round",e.strokeStyle=t.strokeColor,h("stroke"),e.restore()),a(),t.fill&&t.fillAmount>.002&&(e.save(),e.shadowColor="transparent",e.globalAlpha*=t.fillAmount,e.fillStyle=t.fill,h("fill"),e.restore())}function Je(e,t,s,r){const{fontSize:a,color:h,fontFamily:u="Arial",align:g="center",accentColor:l="#dfff00"}=t,f=xe(t,s),i=o=>o==="{color}"?h:o==="{accent}"?l:o==="{accent-hi}"?Re(l,255,.5):o==="{accent-lo}"?Re(l,0,.45):o==="{accent-bright}"?Le(l)[0]:o==="{accent-deep}"?Le(l)[1]:o==="{color-lo}"?Re(h,0,.45):o==="transparent"?"rgba(0,0,0,0)":o;if(e.lineJoin="round",s.path){It(e,t,s,f,i,r);return}const{rows:d,heights:w,total:m,box:v,extras:T,ink:c}=Ze(e,t,s,f),A=o=>c?o.center+(o.ascent-o.descent)/2:o.center,p=o=>c?w[o]:d[o].size*1.12,S=Math.max(...d.map(o=>o.paragraph))+1,z=r&&t.animation?t.animation:void 0,Y=z?Array.from({length:S},(o,b)=>{const k=d.filter(M=>M.paragraph===b).map(M=>M.text).join(" ");return{word:Math.max(1,k.split(/\s+/).filter(Boolean).length),char:Math.max(1,he(k.replace(/\s/g,"")).length)}}):[],I=z&&r?ht(z,Y,r.time,r.duration,ft(s,d.length)):r?r.time:1e6,_={...dt,masked:!1},F=(o,b,k,M)=>z?gt(z,o,b,k,M,I):_,W=(o,b,k,M,n,oe)=>typeof o=="string"?be(i(o),oe):Ke(e,o,b,k,M,n,Q=>be(i(Q),oe));let G=0,V=0;const E=(o,b,k,M,n,oe=b-4e3,Q=8e3)=>{if(e.globalAlpha*=Math.min(1,Math.max(0,o.opacity)),o.flicker>0&&Me(Math.floor(I*24)+b*.01)<o.flicker&&(e.globalAlpha=0),o.reveal<1||o.masked){const $=Math.max(0,M*o.reveal);e.beginPath(),e.rect(-4e3,k-$,8e3,$*2),e.clip()}o.wipeX<1&&(e.beginPath(),e.rect(oe-n*.1,k-M*1.6,(Q+n*.2)*Math.max(0,o.wipeX),M*3.2),e.clip()),o.wipeY<1&&(e.beginPath(),e.rect(-4e3,k-M*1.2,8e3,M*2.4*Math.max(0,o.wipeY)),e.clip());const j=o.glitch>0?o.glitch*n*.35*(Me(Math.floor(I*18)+k*.01)*2-1):0;G=Math.max(G,o.glitch),V=Math.max(V,o.pixels);const O=o.scatter>0?o.scatter*n*(Me(b*.0173+k*.0071+1.3)*2-1):0,K=o.scatter>0?o.scatter*n*.7*(Me(b*.0119+k*.0153+7.9)*2-1):0;return e.translate(b+o.x*n+j+O,k+o.y*n+K),e.rotate(o.rotate*Math.PI/180),e.scale(o.scale*o.scaleX,o.scale*o.scaleY),e.translate(-b,-k),o.blur>0&&(e.filter=`blur(${(o.blur*n).toFixed(1)}px)`),o.brightness},ae=o=>{Pe(e,s,o.size,u,o.style);const b=d.filter(O=>O.paragraph===o.paragraph&&d.indexOf(O)<d.indexOf(o));let k=he(b.map(O=>O.text).join("").replace(/\s/g,"")).length,M=b.map(O=>O.text).join(" ").split(/\s+/).filter(Boolean).length;const n=[];let oe=M-1,Q=!0,j="";for(const O of he(o.text)){const K=e.measureText(j).width;if(j+=O,/\s/.test(O)){Q=!0;continue}Q&&(oe++,Q=!1),n.push({text:O,x:o.left+K,w:e.measureText(j).width-K,char:k++,word:oe})}return n},ge=(o,b)=>!!z?.in.some(k=>k.unit===b&&(!k.lines||k.lines.includes(o))),se=o=>Y[o]||{word:1,char:1},ke=Array.from({length:S},(o,b)=>d.filter(k=>k.paragraph===b).map(k=>k.text).join(" ").split(/\s+/).filter(Boolean).length),Ae=o=>ke.slice(0,o).reduce((b,k)=>b+k,0),ce=o=>o.style?.align??g,y=r&&t.animators?.length?t.animators:null,N=y?Ne(d.map(o=>o.text)):null,H=y&&N?Ue(y,N,r.time):null,te=[];if(N){let o=0;for(let b=0;b<d.length;b++)te.push(o),o+=he(d[b].text).length}for(const o of s.layers){if(o.type==="texture"){Mt(e,o,i(o.color));continue}if(o.type==="shape"||o.type==="icon"){e.save(),Ft(e,o,I,i),e.restore();continue}if(e.save(),e.globalAlpha=o.opacity,o.type==="box"&&o.per==="block"){const M=d[0],n=F("line",M.paragraph,M.paragraph,S),oe=o.padX*a,Q=o.padY*a,j=(T?v.x:Math.min(...d.map(L=>L.left)))-oe,O=(T?v.y:d[0].center-p(0)/2)-Q,K=(T?v.w:Math.max(...d.map(L=>L.width)))+oe*2,$=(T?v.h:m-(w[0]-p(0))/2-(w.at(-1)-p(d.length-1))/2)+Q*2,U=E(n,j+K/2,O+$/2,$/2,a);(!o.motion||Ge(e,Ee(o.motion,I),{x:j,y:O,w:K,h:$},o.motion.origin,a))&&(o.skewX&&(e.translate(j+K/2,O+$/2),e.transform(1,0,Math.tan(-o.skewX*Math.PI/180),1,0,0),e.translate(-j-K/2,-O-$/2)),o.shadow&&(e.shadowColor=i(o.shadow.color),e.shadowBlur=o.shadow.blur*a,e.shadowOffsetX=o.shadow.x*a,e.shadowOffsetY=o.shadow.y*a),e.fillStyle=W(o.fill,j,O,K,$,U),e.beginPath(),e.roundRect(j,O,K,$,o.radius*a),e.fill(),o.stroke&&(e.strokeStyle=be(i(o.stroke.color),U),e.lineWidth=Math.max(1.5,o.stroke.width*a),e.stroke())),e.restore();continue}const b=d.map((M,n)=>o.lines?o.lines.includes(M.paragraph):o.type==="underline"?o.line==="all"||n===d.length-1:!0);let k=0;for(const[M,n]of d.entries()){if(!b[M])continue;const oe=k++;e.save();const Q=n.left+n.width/2;n.style?.rotate&&(e.translate(Q,n.center),e.rotate(n.style.rotate*Math.PI/180),e.translate(-Q,-n.center));const j=F("line",n.paragraph,n.paragraph,S);G=0,V=0;const O=E(j,Q,n.center,w[M]/2+n.size*.1,n.size,n.left,n.width),K=$=>!o.motion||Ge(e,Ee(o.motion,I-(o.motion.stagger??0)*oe),$,o.motion.origin,n.size);if(o.type==="box"){const $=o.padX*n.size,U=o.padY*n.size,L=n.left-$,B=n.center-p(M)/2-U,D=n.width+$*2,fe=p(M)+U*2;K({x:L,y:B,w:D,h:fe})&&(o.skewX&&(e.translate(L+D/2,B+fe/2),e.transform(1,0,Math.tan(-o.skewX*Math.PI/180),1,0,0),e.translate(-L-D/2,-B-fe/2)),o.shadow&&(e.shadowColor=i(o.shadow.color),e.shadowBlur=o.shadow.blur*n.size,e.shadowOffsetX=o.shadow.x*n.size,e.shadowOffsetY=o.shadow.y*n.size),e.fillStyle=W(o.fill,L,B,D,fe,O),e.beginPath(),e.roundRect(L,B,D,fe,o.radius*n.size),e.fill(),o.stroke&&(e.strokeStyle=be(i(o.stroke.color),O),e.lineWidth=Math.max(1.5,o.stroke.width*n.size),e.stroke()))}if(o.type==="underline"){const $=n.width*o.width,U=ce(n),L=U==="left"?n.left:U==="right"?n.left+n.width-$:n.left+(n.width-$)/2,B=n.center+o.offsetY*n.size,D=Math.max(3,o.height*n.size);K({x:L,y:B-(o.style==="swash"?n.size*.3:0),w:$,h:D+(o.style==="swash"?n.size*.5:0)})&&(e.fillStyle=W(o.fill,L,B,$,D,O),o.style==="swash"?(vt(e,L,B,$,D,n.size),e.fill()):e.fillRect(L,B,$,D))}if(o.type==="text"){Pe(e,s,n.size,u,n.style);const $=j.count!==1?pt(n.text,j.count):n.text;let U=n.left,L=n.width;if($!==n.text){L=e.measureText($).width;const P=ce(n);U=P==="left"?n.left:P==="right"?n.left+n.width-L:n.left+(n.width-L)/2}const B=(o.offset?.x||0)*n.size,D=(o.offset?.y||0)*n.size;if(r&&o.flicker&&Me(Math.floor(I*12)*1.37+5)<o.flicker&&(e.globalAlpha*=.18),!K({x:U+B-n.size*.05,y:n.center-p(M)/2+D-n.size*.12,w:L+n.size*.1,h:p(M)+n.size*.24})){e.restore();continue}o.shadow&&(e.shadowColor=i(o.shadow.color),e.shadowBlur=o.shadow.blur*n.size,e.shadowOffsetX=o.shadow.x*n.size,e.shadowOffsetY=o.shadow.y*n.size);const fe=o.lineFills?o.lineFills[M%o.lineFills.length]:void 0;let we=null;if(r&&o.shine){const P=o.shine;let X=I-P.start;X>=0&&P.every>0&&(X%=P.every);const q=X/P.duration;if(X>=0&&q<1){const C=P.width*n.size,R=U-C+(L+C*2)*q,Z=P.angle*Math.PI/180,x=i(P.color);we=e.createLinearGradient(R-C*Math.cos(Z),n.center-C*Math.sin(Z),R+C*Math.cos(Z),n.center+C*Math.sin(Z)),we.addColorStop(0,Te(x,0)),we.addColorStop(.5,Te(x,1)),we.addColorStop(1,Te(x,0))}}const tt=fe??(n.fill&&o.fill==="{color}"?n.fill:o.fill),ot=n.center-p(M)/2+D,at=(P,X)=>W(P,U+B,ot,L,p(M),X),nt=o.reflection?A(n)+D+e.measureText($).actualBoundingBoxDescent:0,Se=(P,X,q,C)=>{const R=A(n)+D,Z=C??tt;if(V>.02&&Ct(e,P,X+B,R,n.size,V,I),G>.02){const x=e.globalAlpha,ne=G*n.size*.08;e.globalAlpha=x*.85,e.fillStyle="#fd436a",e.fillText(P,X+B+ne,R),e.fillStyle="#37eaff",e.fillText(P,X+B-ne,R),e.globalAlpha=x}if(o.stroke&&(e.strokeStyle=be(i(o.stroke.color),q),e.lineWidth=Math.max(2,o.stroke.width*n.size),e.strokeText(P,X+B,R)),e.fillStyle=at(Z,q),e.fillText(P,X+B,R),o.innerGlow){const x=e.getTransform();zt(e,ne=>ne.fillText(P,X+B,R),be(i(o.innerGlow.color),q),o.innerGlow.blur*n.size*Math.hypot(x.a,x.b))}if(we&&(e.save(),e.shadowColor="transparent",e.fillStyle=we,e.fillText(P,X+B,R),e.restore()),o.reflection){const x=o.reflection,ne=nt+x.gap*n.size,Oe=p(M)*x.fade,J=i(Pt(Z)),de=!/^#[0-9a-f]{6}$/i.test(J),pe=de&&o.stroke?i(o.stroke.color):J;e.save(),e.shadowColor="transparent",e.filter="none",e.translate(0,2*ne),e.scale(1,-1);const ye=e.createLinearGradient(0,ne,0,ne-Oe);ye.addColorStop(0,Te(pe,x.opacity)),ye.addColorStop(1,Te(pe,0)),de&&o.stroke?(e.strokeStyle=ye,e.lineWidth=Math.max(2,o.stroke.width*n.size),e.strokeText(P,X+B,R)):(e.fillStyle=ye,e.fillText(P,X+B,R)),e.restore()}},me=new Map;for(const P of o.highlights??[])for(const X of P.words)me.set(X,P.fill);const ze=Ae(n.paragraph),Ie=ge(n.paragraph,"word"),$e=ge(n.paragraph,"char"),Fe=j.spread;if(H){const P=he(n.text),X=$t(e,n.text,P),q=te[M],C=ae(n);let R=0;for(let J=0;J<P.length;J++)R+=H[q+J].tracking;const Z=ce(n);let ne=Z==="left"?0:Z==="right"?-R:-R/2,Oe=0;for(let J=0;J<P.length;J++){const de=H[q+J],pe=n.left+X[J],ye=X[J+1]-X[J],We=!/\S/u.test(P[J]),le=We?null:C[Oe++],Ce=ne;if(ne+=de.tracking,We||!le||de.opacity<=.002||de.scale<=1e-4)continue;e.save();let Be=O;Ie&&(Be*=E(F("word",n.paragraph,le.word,se(n.paragraph).word),le.x+le.w/2,n.center,w[M]/2+n.size*.1,n.size)),$e&&(Be*=E(F("char",n.paragraph,le.char,se(n.paragraph).char),le.x+le.w/2,n.center,w[M]/2+n.size*.1,n.size)),e.globalAlpha>.002&&et(e,de,pe+Ce+B+ye/2,n.center,()=>Se(P[J],pe+Ce,Be,me.get(ze+le.word)),st=>st==="fill"?e.fillText(P[J],pe+Ce+B,A(n)+D):e.strokeText(P[J],pe+Ce+B,A(n)+D)),e.restore()}}else if(!Ie&&!$e&&!Fe)if(!me.size||$!==n.text)Se($,U,O);else{const P=new Map;for(const C of ae(n)){const R=ze+C.word,Z=P.get(R);P.set(R,Z?{x0:Math.min(Z.x0,C.x),x1:Math.max(Z.x1,C.x+C.w)}:{x0:C.x,x1:C.x+C.w})}const X=[...P].filter(([C])=>me.has(C)),q=n.size*.04;e.save(),e.beginPath(),e.rect(-1e5,-1e5,2e5,2e5);for(const[,C]of X)e.rect(C.x0+B-q,-1e5,C.x1-C.x0+q*2,2e5);e.clip("evenodd"),Se($,U,O),e.restore();for(const[C,R]of X)e.save(),e.beginPath(),e.rect(R.x0+B-q,-1e5,R.x1-R.x0+q*2,2e5),e.clip(),Se($,U,O,me.get(C)),e.restore()}else{const P=ae(n),X=(P.length-1)/2;for(const[q,C]of P.entries()){e.save(),Fe&&e.translate((q-X)*Fe*n.size,0);let R=O;Ie&&(R*=E(F("word",n.paragraph,C.word,se(n.paragraph).word),C.x+C.w/2,n.center,w[M]/2+n.size*.1,n.size)),$e&&(R*=E(F("char",n.paragraph,C.char,se(n.paragraph).char),C.x+C.w/2,n.center,w[M]/2+n.size*.1,n.size)),e.globalAlpha>.002&&Se(C.text,C.x,R,me.get(ze+C.word)),e.restore()}}}e.restore()}e.restore()}}function Ft(e,t,s,r){const a=ee.width,h=ee.height,u=Ee(t.motion,s);if(e.globalAlpha=t.opacity*Math.min(1,Math.max(0,u.opacity)),e.globalAlpha<.002)return;let g,l,f,i;t.type==="shape"?(g=(t.box[0]+t.box[2]/2)*a,l=(t.box[1]+t.box[3]/2)*h,f=t.box[2]*a,i=t.box[3]*h):(f=i=t.size*h,g=t.center[0]*a,l=t.center[1]*h);const d=t.motion?.origin??"center",w=d==="left"?g-f/2:d==="right"?g+f/2:g,m=d==="top"?l-i/2:d==="bottom"?l+i/2:l;if(u.wipeX<1&&(e.beginPath(),e.rect(g-f/2-8,l-i/2-8,(f+16)*Math.max(0,u.wipeX),i+16),e.clip()),u.wipeY<1&&(e.beginPath(),e.rect(g-f/2-8,l-i/2-8,f+16,(i+16)*Math.max(0,u.wipeY)),e.clip()),e.translate(w+u.x*a,m+u.y*h),e.scale(u.scale*u.scaleX,u.scale*u.scaleY),e.translate(g-w,l-m),e.rotate(((t.rotate||0)+u.rotate)*Math.PI/180),t.type==="shape"){if(t.skewX&&e.transform(1,0,Math.tan(t.skewX*Math.PI/180),1,0,0),t.blur&&(e.filter=`blur(${(t.blur*h).toFixed(1)}px)`),t.shape==="glow"){const c=typeof t.fill=="string"?r(t.fill):r(t.stroke?.color??"{accent}"),A=Math.max(f,i)/2;e.scale(f/2/A,i/2/A);const p=e.createRadialGradient(0,0,0,0,0,A);p.addColorStop(0,c),p.addColorStop(1,"rgba(0,0,0,0)"),e.fillStyle=p,e.beginPath(),e.arc(0,0,A,0,Math.PI*2),e.fill();return}e.beginPath(),t.shape==="rect"?e.roundRect(-f/2,-i/2,f,i,Math.min(f,i)/2*Math.min(1,t.radius*2)):e.ellipse(0,0,f/2,i/2,0,0,Math.PI*2),t.fill&&(typeof t.fill=="string"?e.fillStyle=r(t.fill):e.fillStyle=Ke(e,t.fill,-f/2,-i/2,f,i,r),e.fill()),t.stroke&&(e.strokeStyle=r(t.stroke.color),e.lineWidth=t.stroke.width,e.setLineDash(t.stroke.dash??[]),e.stroke());return}if(t.glow&&(e.shadowColor=r(t.color),e.shadowBlur=t.glow*f*.5),t.badge!=="none"){e.save(),t.badge==="diamond"&&e.rotate(Math.PI/4);const c=t.badge==="diamond"?f*.72:f;e.beginPath(),t.badge==="circle"?e.arc(0,0,f/2,0,Math.PI*2):e.roundRect(-c/2,-c/2,c,c,t.badge==="square"?0:c*.22),t.badgeFill&&(e.fillStyle=r(t.badgeFill),e.fill()),t.badgeStroke&&(e.strokeStyle=r(t.badgeStroke),e.lineWidth=2,e.stroke()),e.restore()}e.shadowBlur=0;const v=f*.6,T=v/24;e.translate(-v/2,-v/2),e.scale(T,T),e.strokeStyle=r(t.color),e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round";for(const c of ut[t.name]??[])e.stroke(new Path2D(c))}function Ot(e){const t=[];for(const s of Array.from(document.styleSheets)){let r;try{r=s.cssRules}catch{continue}for(const a of Array.from(r))if(a instanceof CSSFontFaceRule&&a.style.getPropertyValue("font-family").replace(/['"]/g,"").trim()===e){const h=a.style.getPropertyValue("src");if(!h)continue;t.push(new FontFace(e,h,{weight:a.style.getPropertyValue("font-weight")||"normal",stretch:a.style.getPropertyValue("font-stretch")||"normal",style:a.style.getPropertyValue("font-style")||"normal"}))}}return t}const Ve=async(e,t)=>{try{return await document.fonts.load(e,t),!0}catch{}await new Promise(r=>setTimeout(r,400));const s=e.match(/"([^"]+)"/)?.[1]??"";try{const r=Ot(s);return r.length?(await Promise.all(r.map(a=>a.load().then(()=>document.fonts.add(a)))),!0):!1}catch{return!1}};async function Yt(e){const t=lt(e),s=[];if(t.length){const l=await rt(()=>import("./userFonts-CwlKh9NR.js"),__vite__mapDeps([0,1,2,3,4]));await l.userFontsReady();for(const f of t)l.isMissingCustomFont(f)&&s.push(f)}const r=e.design?.weight??(e.styleId&&e.styleId!=="classic"?800:600),a=e.design?.stretch&&e.design.stretch!=="normal"?e.design.stretch+" ":"",h=e.fontFamily||"Arial",u=[];await Ve(`${r} ${a}${e.fontSize}px "${h}"`,e.text)||u.push(h);const g=e.design;if(g?.lines?.some(l=>l.font||l.weight||l.italic||l.stretch)){const l=[...new Set(g.lines.map(i=>Qe(g,e.fontSize,h,i).replace(/ sans-serif$/,"").replace(/,$/,"")))],f=await Promise.all(l.map(i=>Ve(i,e.text)));l.forEach((i,d)=>{f[d]||u.push(i.replace(/^.*?"([^"]+)".*$/,"$1"))})}return[...new Set([...u.filter(l=>!s.includes(l)),...s])]}export{Rt as d,Yt as l,Et as t};
@@ -14576,4 +14576,4 @@ ${e}
14576
14576
  ctx.save()
14577
14577
  for(const [lag,al] of [[0,1],[.18,.55]]){const z=M.ease.inExpo(M.clamp(k-lag+.08)),s=M.lerp(.22,3.2,z),w=W*.5*s,hh=H*.5*s;if(s>3.1)continue;ctx.globalAlpha=al*Math.min(1,Math.sin(Math.PI*M.clamp(k-lag+.08))*1.6);ctx.strokeStyle=A;ctx.lineWidth=Math.max(1.5,u*.006*s);ctx.strokeRect(W/2-w/2,H/2-hh/2,w,hh);ctx.fillStyle=INK;const q=u*.012*s;[[-1,-1],[1,-1],[-1,1],[1,1]].forEach(c=>ctx.fillRect(W/2+c[0]*w/2-q/2,H/2+c[1]*hh/2-q/2,q,q));if(lag===0){CHV(W/2-w/2-u*.06*s,H/2,u*.05*s,0,2,A);CHV(W/2+w/2+u*.06*s,H/2,u*.05*s,Math.PI,2,A)}}
14578
14578
  if(full){ctx.globalAlpha=.3;ctx.fillStyle=M.mix(A,'#ffffff',.7);ctx.fillRect(-m,-m,W+2*m,H+2*m)}
14579
- ctx.restore()`,{k:1.2,min:.5})}),YP=t=>Object.hasOwn(ug,t)?ug[t]:null,gg=Object.freeze({accent:"#ff1f8e",lime:"#c6f432",paper:"#fbf7fa",ink:"#141418"}),Im="#c6f432",Hs=Object.freeze(["ur-photocopy-scribble","ur-magenta-flash","ur-neon-edge","ur-torn-paper","ur-cutout-blocks","ur-sticker-slap","ed-box-wipe","ed-arc-swoosh","ed-star-flythrough","ed-window-morph","ed-window-morph-v","ed-flicker-cut","ed-color-flash","ed-negative-blink","ed-silhouette-lead","ed-flash-invert","ed-invert-cut","tl-duotone-flash","tl-pixel-dissolve","tl-card-cascade","tl-chevron-push","tl-scramble","tl-blur-whip","tl-frame-zoom"]),QP=Object.freeze(Ul.filter(t=>Hs.includes(t.id))),n0=.2,o0=1.2,ZP=/^#[0-9a-fA-F]{6}$/,Lo=t=>Ao(t)&&!t.motion&&!t.lottie&&!t.geo&&!t.element&&!t.solid&&!t.adjust&&!t.nullLayer&&!t.freeze,Kl=t=>{const e=Ls(t?.style),c=Number.isFinite(t?.duration)?t.duration:e?.dur??.5;return 2*V(Math.max(n0,Math.min(o0,c))/2)},af=(t,e)=>t.kind==="sequence"?e+1/15:1.5*e+1/15;function Om(t,e,c,{duration:a,color:n}={}){const o=t.find(d=>d.id===e);if(!o)throw Error("Clip not found");if(c==="none"){if(!o.join)throw Error("No join style on this cut");return t.map(d=>{if(d.id!==e)return d;const{join:p,...b}=d;return b})}const i=Io(t,o);if(!Lo(o)||!Lo(i))throw Error("Join styles need two touching filmed clips (video / photo) on the same track");const s=Ls(c??o.join?.style);if(!s||!Hs.includes(s.id))throw Error(`Unknown footage join style "${c}" — use ${Hs.join(", ")}`);const r={style:s.id},l=Number.isFinite(a)?a:o.join?.style===s.id?o.join.duration:void 0;if(l!==void 0){if(!(l>=n0&&l<=o0))throw Error("Join duration must be 0.2–1.2 s");r.duration=V(l)}const x=n??o.join?.color;if(x!==void 0){if(!ZP.test(x))throw Error("Join colour must be #RRGGBB");r.color=x}const h=Kl(r),f=af(s,h);if(o.duration<f-1e-6||i.duration<f-1e-6)throw Error(`Clips too short for this join (each needs ≥ ${f.toFixed(2)} s)`);return t.map(d=>{if(d.id===o.id){const{transition:p,visualFadeOut:b,fadeOutColor:g,...m}=d;return{...m,join:r}}if(d.id===i.id&&(d.visualFadeIn||d.fadeInColor)){const{visualFadeIn:p,fadeInColor:b,...g}=d;return g}return d})}function JP(t,e,c,{duration:a,newId:n=()=>`sil-${Math.random().toString(36).slice(2,9)}`}={}){const o=t.find(T=>T.id===c),i=o&&Io(t,o);if(!o||!i||!Lo(o)||!Lo(i))throw Error("Silhouette reveal needs two touching filmed clips on one track");if(i.kind!=="image"||!i.url)throw Error("Silhouette reveal needs a photo after the cut (its subject is cut out in the browser)");const s=Om(t,c,"ed-silhouette-lead",{duration:a}),r=Kl(s.find(T=>T.id===c).join),l=V(i.start-r/2),x=V(i.start+r/2),{track:h}=bl(s,e,l,x),{transition:f,join:d,visualFadeIn:p,visualFadeOut:b,fadeInColor:g,fadeOutColor:m,enter:y,exit:k,captions:w,captionWords:A,mask:u,...M}=i,v=kn({...M,id:n(),track:h,start:l,duration:V(x-l),volume:0,label:`${i.label??"Shot"} · silhouette`,silhouetteOf:i.id},"enter","slide-left",{duration:V(r/2),amount:1,fade:!1,ease:"expo-out"});return{clips:[...s,v],copyId:v.id}}function i0(t){return t.filter(e=>e.join&&!e.disabled).flatMap(e=>{const c=Io(t,e),a=Ls(e.join.style);if(!a||!Hs.includes(a.id)||e.transition||!Lo(e)||!Lo(c))return[];const n=Kl(e.join);return e.duration<af(a,n)-1e-6||c.duration<af(a,n)-1e-6?[]:[{a:e,b:c,style:a,w:n,cut:c.start}]})}const Xx=t=>{const e=tc[t.ease],c=e==="hold"?[-1,0,0,0]:Array.isArray(e)?e:[0,0,1,1];return{e0:c[0],e1:c[1],e2:c[2],e3:c[3]}};function s0({a:t,b:e,style:c,w:a,cut:n}){const o=c.pack==="urban",i=c.pack==="techlaunch",s=c.sticker?null:i?YP(c.deco):o?qP(c.deco):XP(c.deco);if(!s)return null;const r=t.join.color??(i?gg.accent:Im),l=V(Math.min(2*n,Ja.maxDuration,Math.max(s.min,a*s.k+s.add))),x=Ry({code:s.code,params:i?{...gg,accent:r,...Xx(c)}:o?{accent:r,...NP,...Xx(c)}:{accent:r,..._P,...Xx(c),w:a,flash:t.join.color??"#ffffff"},preset:c.id});return{id:`${t.id}~jfx`,nodeId:"",kind:"image",url:"",label:`${i?"Tech Launch":o?"Urban":"Editorial"} · ${t.label} → ${e.label}`,volume:0,start:V(n-l/2),duration:l,track:t.track,motion:{...x,duration:l},motionKeys:[],_slot:"k",_virtual:t.id,...t.zIndex!==void 0||e.zIndex!==void 0?{zIndex:Math.max(t.zIndex??0,e.zIndex??0)}:{},...s.cam&&t.is3D&&e.is3D?{is3D:!0}:{}}}function t7(t){const e=new Set(t.map(c=>c.id));return i0(t).map(s0).filter(c=>c&&!e.has(c.id))}const e7=.1,bg=(t,e)=>{const{captions:c,captionWords:a,audioFadeIn:n,audioFadeOut:o,visualFadeIn:i,visualFadeOut:s,enter:r,exit:l,transition:x,join:h,...f}=t;return{...f,volume:0,_slot:"j",_virtual:e}},yg=t=>{if(!t.revealType)return t;const{revealType:e,reveal:c,...a}=t;return{...a,...It(a,"reveal").length?{motionKeys:Ba(a,"reveal",[])}:{}}};function qm(t){if(!t.some(o=>o.join))return t;let e=t.slice();const c=[],a=[],n=o=>{e=e.map(i=>i.id===o.id?o:i)};for(const o of i0(t).sort((i,s)=>i.cut-s.cut)){const i=e.find(b=>b.id===o.a.id),s=e.find(b=>b.id===o.b.id),{style:r,w:l,cut:x}=o,h=l/2,f=V(x-h),d=V(x+h);if(r.kind==="sequence"){const b=xg(r,{out:[i],inn:[{...s,start:f,duration:V(s.duration+h)}],b0:f,b1:d});for(const g of[i,s]){const m=b.get(g.id);if(!m)continue;let{seam:y,...k}=m;r.sticker&&(k={...k,motionKeys:Ba(k,"rot",It(g,"rot"))}),n({...k,start:g.start,duration:g.duration,inPoint:g.inPoint,...g.seam?{seam:g.seam}:{}})}}else{const b=i.playbackRate||1,g=s.playbackRate||1,{tail:m,head:y}=u2(i,s),k=xg(r,{out:[i],inn:[{...s,inPoint:(s.inPoint||0)-h*g}],b0:f,b1:d}),w=k.get(i.id),A=k.get(s.id);if(!w||!A)continue;const u=({seam:P,...z})=>z,[M,v]=eg(u(w),x,`${i.id}~jna`),[T,S]=eg(u(A),x,s.id);if(!v||!S)continue;n({...yg(M),...i.seam?{seam:i.seam}:{}}),n({...yg({...S,inPoint:s.inPoint||0}),...s.seam?{seam:s.seam}:{}}),(m<h||y<h)&&c.push({clipId:i.id,tail:Math.min(m,h),head:Math.min(y,h),need:h});const C=i.kind==="video"&&m<h,R=s.kind==="video"&&y<h;a.push({...bg(v,i.id),...C?{_still:!0,inPoint:Math.max(0,(i.inPoint||0)+i.duration*b-e7)}:{}}),a.push({...bg({...T,id:`${s.id}~jnb`},s.id),...R?{_still:!0,inPoint:s.inPoint||0}:{inPoint:(s.inPoint||0)-h*g}})}const p=s0({...o,a:{...o.a}});p&&!t.some(b=>b.id===p.id)&&a.push(p)}return Object.assign([...e,...a],{short:c})}const oD=Object.freeze(Object.defineProperty({__proto__:null,FOOTAGE_JOIN_ACCENT:Im,FOOTAGE_JOIN_IDS:Hs,FOOTAGE_JOIN_MAX:o0,FOOTAGE_JOIN_MIN:n0,FOOTAGE_JOIN_STYLES:QP,cutJoins:i0,expandJoins:qm,joinDeco:s0,joinDecoLayers:t7,joinWindow:Kl,joinable:Lo,setCutJoin:Om,silhouetteReveal:JP},Symbol.toStringTag,{value:"Module"})),mg=21600,Nm=t=>t.kind==="image"&&(im(t.title)||!!t.shape||!!t.motion||!!t.lottie||!!t.card||!!t.geo||t.warped===!0),iD=t=>rk(qm((t||[]).filter(e=>e&&!e.disabled))).filter(e=>e._virtual&&Nm(e)),sD=(t,e)=>(t||[]).filter(c=>!c?.disabled&&Nm(c)).reduce((c,a)=>c+(uR(a)?1:Math.ceil(a.duration*e)),0),rD=(t,e=!0)=>e?`Video có quá nhiều lớp chữ động / Motion chồng nhau (${t} khung, tối đa ${mg}). Hãy xuất từng đoạn ngắn hơn hoặc xoá bớt các lớp chữ trùng nhau.`:`Too many overlapping animated text / Motion layers (${t} frames, max ${mg}). Export a shorter part at a time or remove duplicate text layers.`;export{i4 as $,KH as A,gl as B,dk as C,T5 as D,OH as E,Ye as F,ya as G,Hs as H,hW as I,Ul as J,u6 as K,iW as L,J1 as M,$8 as N,YE as O,oy as P,_8 as Q,Xa as R,bM as S,Ay as T,Xb as U,LE as V,Zb as W,Ib as X,ME as Y,fE as Z,c7 as _,sf as a,Vg as a$,TE as a0,Jr as a1,T4 as a2,PE as a3,G4 as a4,P4 as a5,Ih as a6,uE as a7,BE as a8,zE as a9,ez as aA,tc as aB,az as aC,nz as aD,Pn as aE,Ds as aF,me as aG,ws as aH,iM as aI,nn as aJ,lz as aK,Vn as aL,xz as aM,oz as aN,hz as aO,iw as aP,Tz as aQ,vi as aR,aw as aS,jM as aT,R0 as aU,Ql as aV,vM as aW,AM as aX,XM as aY,lw as aZ,sw as a_,EE as aa,WE as ab,lb as ac,$b as ad,jd as ae,Bf as af,l4 as ag,Kd as ah,Tf as ai,Oh as aj,Ub as ak,zl as al,L4 as am,$4 as an,I4 as ao,Az as ap,LM as aq,ar,yz as as,bz as at,V as au,U5 as av,Mr as aw,hs as ax,M0 as ay,cz as az,Qx as b,Ps as b$,vz as b0,Pz as b1,Rz as b2,ah as b3,pz as b4,gz as b5,Ss as b6,C0 as b7,GM as b8,Zl as b9,gH as bA,HR as bB,cH as bC,aH as bD,eH as bE,Jh as bF,pH as bG,dB as bH,o7 as bI,r7 as bJ,t5 as bK,dh as bL,MB as bM,vB as bN,pB as bO,AB as bP,TB as bQ,mB as bR,uB as bS,gB as bT,s7 as bU,x7 as bV,bB as bW,yB as bX,wB as bY,kB as bZ,Hb as b_,DM as ba,JM as bb,z0 as bc,P0 as bd,B0 as be,wz as bf,X4 as bg,q3 as bh,C7 as bi,XE as bj,If as bk,t6 as bl,FE as bm,_E as bn,VE as bo,Cm as bp,ef as bq,V1 as br,_1 as bs,zs as bt,w8 as bu,M8 as bv,R8 as bw,sW as bx,p1 as by,ve as bz,z7 as c,Ml as c$,Ns as c0,n7 as c1,FB as c2,pR as c3,fR as c4,zL as c5,sm as c6,oR as c7,DL as c8,eo as c9,C9 as cA,K2 as cB,r9 as cC,M9 as cD,_a as cE,f9 as cF,pS as cG,l9 as cH,wS as cI,X2 as cJ,nS as cK,c9 as cL,RR as cM,e9 as cN,hc as cO,dS as cP,zS as cQ,i9 as cR,n9 as cS,o9 as cT,PS as cU,h9 as cV,t9 as cW,QB as cX,Te as cY,hS as cZ,id as c_,iR as ca,sR as cb,HL as cc,Yn as cd,gR as ce,sn as cf,BL as cg,LL as ch,Co as ci,hB as cj,xB as ck,fB as cl,RB as cm,Sk as cn,Z0 as co,Do as cp,XL as cq,X7 as cr,$f as cs,Bs as ct,Ny as cu,Gy as cv,PA as cw,Zk as cx,KB as cy,U2 as cz,R7 as d,vC as d$,Mf as d0,JB as d1,ZB as d2,xS as d3,oS as d4,bE as d5,Xv as d6,co as d7,zd as d8,sE as d9,Hv as dA,RW as dB,PW as dC,AA as dD,Uh as dE,qy as dF,wW as dG,Xf as dH,Xh as dI,kA as dJ,FW as dK,mo as dL,kW as dM,XW as dN,vW as dO,TW as dP,SW as dQ,CW as dR,Oy as dS,QW as dT,AW as dU,YW as dV,_W as dW,VW as dX,Ox as dY,UW as dZ,Xy as d_,$v as da,Cv as db,Fv as dc,Ed as dd,rE as de,Wb as df,Cb as dg,Wd as dh,HC as di,ML as dj,SL as dk,kL as dl,bl as dm,Vh as dn,js as dp,Ro as dq,dE as dr,Db as ds,vl as dt,V3 as du,$s as dv,gb as dw,eE as dx,yb as dy,Dv as dz,A5 as e,RE as e$,hL as e0,Cs as e1,XB as e2,Rl as e3,SE as e4,qb as e5,vr as e6,kE as e7,Rk as e8,GB as e9,$w as eA,eB,Zz as eC,Jz as eD,tB as eE,Kz as eF,Qz as eG,Xz as eH,p9 as eI,HS as eJ,u9 as eK,qS as eL,g9 as eM,d9 as eN,y9 as eO,fL as eP,rk as eQ,qm as eR,rx as eS,Bk as eT,im as eU,DH as eV,IH as eW,UH as eX,JW as eY,zW as eZ,PP as e_,PC as ea,jL as eb,It as ec,Pr as ed,et as ee,Mo as ef,Zt as eg,_4 as eh,DE as ei,V4 as ej,Qb as ek,ps as el,FL as em,aB as en,g2 as eo,p2 as ep,Yz as eq,Oz as er,Nz as es,To as et,bo as eu,qz as ev,Uz as ew,_z as ex,Vz as ey,Fz as ez,Rm as f,T7 as f$,mw as f0,qW as f1,NB as f2,p4 as f3,QC as f4,IL as f5,b9 as f6,Iz as f7,EL as f8,Ll as f9,tr as fA,L5 as fB,OE as fC,xC as fD,DW as fE,jB as fF,NL as fG,qL as fH,qB as fI,L9 as fJ,of as fK,Tg as fL,b7 as fM,p0 as fN,m7 as fO,nb as fP,h7 as fQ,f7 as fR,n5 as fS,d7 as fT,M7 as fU,Pa as fV,M5 as fW,w5 as fX,Vx as fY,v7 as fZ,A7 as f_,ye as fa,Vs as fb,Ys as fc,Hl as fd,bm as fe,K7 as ff,vL as fg,rz as fh,J7 as fi,DB as fj,F7 as fk,dL as fl,pL as fm,il as fn,EB as fo,mf as fp,Xk as fq,to as fr,jy as fs,v2 as ft,Mi as fu,NW as fv,uc as fw,_f as fx,Dl as fy,Js as fz,qM as g,MH as g$,Sl as g0,q9 as g1,M3 as g2,si as g3,Lm as g4,O9 as g5,d3 as g6,cb as g7,KS as g8,kl as g9,S9 as gA,p7 as gB,$9 as gC,B9 as gD,w9 as gE,Ww as gF,Sw as gG,vo as gH,D0 as gI,Gz as gJ,fl as gK,pf as gL,i2 as gM,Kr as gN,So as gO,vw as gP,h2 as gQ,$z as gR,N0 as gS,di as gT,Ck as gU,As as gV,Il as gW,$e as gX,Vf as gY,WW as gZ,wm as g_,R9 as ga,P9 as gb,fd as gc,yd as gd,j9 as ge,ob as gf,G9 as gg,QL as gh,Wz as gi,Ez as gj,Hz as gk,ZH as gl,Lz as gm,RH as gn,zH as go,PH as gp,Md as gq,K9 as gr,U9 as gs,C3 as gt,k9 as gu,T3 as gv,A9 as gw,g7 as gx,v9 as gy,T9 as gz,Ho as h,zk as h$,sl as h0,ZL as h1,SH as h2,_R as h3,uz as h4,LA as h5,UC as h6,AL as h7,c0 as h8,ol as h9,E5 as hA,xE as hB,EP as hC,Kl as hD,QP as hE,o0 as hF,n0 as hG,iE as hH,X9 as hI,F9 as hJ,vf as hK,cr as hL,pm as hM,um as hN,gm as hO,cy as hP,JH as hQ,tD as hR,ni as hS,v0 as hT,Nm as hU,zB as hV,OW as hW,gh as hX,PB as hY,OB as hZ,LW as h_,TL as ha,FC as hb,Vr as hc,HH as hd,tl as he,F4 as hf,o4 as hg,AE as hh,Zr as hi,Hf as hj,ey as hk,Lh as hl,Zv as hm,Ob as hn,bi as ho,yi as hp,Vb as hq,CE as hr,d4 as hs,Qd as ht,Yb as hu,Kb as hv,vE as hw,Ls as hx,Ry as hy,Ja as hz,TM as i,xi as i$,kz as i0,LB as i1,tP as i2,TH as i3,_L as i4,BB as i5,KW as i6,GA as i7,HW as i8,pE as i9,Qn as iA,oE as iB,mb as iC,aE as iD,tv as iE,Mb as iF,WB as iG,X5 as iH,oB as iI,Ao as iJ,yL as iK,a9 as iL,UB as iM,rD as iN,dl as iO,Os as iP,iD as iQ,J8 as iR,Qf as iS,us as iT,V7 as iU,Q7 as iV,Z7 as iW,Y7 as iX,_5 as iY,_7 as iZ,mz as i_,Io as ia,u2 as ib,rh as ic,rB as id,sB as ie,Lo as ig,FH as ih,Bo as ii,zo as ij,AH as ik,EH as il,Xm as im,eg as io,bR as ip,sD as iq,mg as ir,Kk as is,$B as it,CH as iu,BH as iv,LH as iw,WH as ix,ab as iy,yE as iz,hf as j,x5 as j$,Mz as j0,KE as j1,e6 as j2,c6 as j3,a6 as j4,Bn as j5,YC as j6,a7 as j7,VL as j8,TR as j9,nD as jA,cD as jB,eD as jC,aD as jD,xg as jE,YP as jF,qP as jG,XP as jH,gg as jI,NP as jJ,_P as jK,fW as jL,JE as jM,tW as jN,AT as jO,RT as jP,PT as jQ,mR as jR,Ky as jS,T2 as jT,vh as jU,fb as jV,rb as jW,Y4 as jX,IW as jY,S7 as jZ,u7 as j_,gr as ja,Qt as jb,GL as jc,Hg as jd,K5 as je,m1 as jf,uW as jg,Ba as jh,Hx as ji,xA as jj,w1 as jk,Pi as jl,ki as jm,eC as jn,k8 as jo,D8 as jp,rC as jq,lC as jr,$y as js,H8 as jt,FM as ju,LS as jv,_r as jw,Cc as jx,xW as jy,be as jz,Um as k,pP as k$,l5 as k0,ys as k1,H9 as k2,p5 as k3,l0 as k4,i5 as k5,kf as k6,eb as k7,w7 as k8,y7 as k9,Cg as kA,Rg as kB,m5 as kC,Rc as kD,l7 as kE,Zm as kF,Qe as kG,i7 as kH,_m as kI,Tk as kJ,lE as kK,cE as kL,J3 as kM,wL as kN,G7 as kO,U7 as kP,N7 as kQ,_H as kR,VH as kS,YH as kT,QH as kU,mL as kV,zC as kW,EC as kX,bL as kY,uL as kZ,gL as k_,JS as ka,k7 as kb,d5 as kc,D9 as kd,I9 as ke,o5 as kf,Sg as kg,ao as kh,gS as ki,MS as kj,Fh as kk,uH as kl,dR as km,eL as kn,a0 as ko,JP as kp,Om as kq,kH as kr,mi as ks,RP as kt,$H as ku,jH as kv,UE as kw,kn as kx,B7 as ky,y5 as kz,gf as l,O7 as l$,Pm as l0,$r as l1,Hr as l2,Pk as l3,ih as l4,jz as l5,cB as l6,dz as l7,WM as l8,XC as l9,tz as lA,Q9 as lB,d2 as lC,EW as lD,sz as lE,iz as lF,mE as lG,j4 as lH,KL as lI,m9 as lJ,BS as lK,pw as lL,uw as lM,Y9 as lN,_9 as lO,V9 as lP,eP as lQ,U1 as lR,vH as lS,WL as lT,aR as lU,q7 as lV,wH as lW,j7 as lX,$7 as lY,L7 as lZ,H7 as l_,_C as la,GW as lb,IB as lc,B2 as ld,OL as le,iB as lf,tE as lg,Iv as lh,F3 as li,Ov as lj,nE as lk,Pl as ll,Dz as lm,IE as ln,$L as lo,XH as lp,ko as lq,nB as lr,cC as ls,zz as lt,Bz as lu,Cz as lv,lB as lw,CB as lx,qg as ly,UL as lz,ti as m,sL as m$,D7 as m0,I7 as m1,W7 as m2,uR as m3,N9 as m4,lW as m5,BW as m6,ZE as m7,oW as m8,nW as m9,iH as mA,dH as mB,nH as mC,hH as mD,fH as mE,rH as mF,sH as mG,rW as mH,tH as mI,lH as mJ,xH as mK,bH as mL,od as mM,fP as mN,a5 as mO,PL as mP,RL as mQ,wE as mR,Xs as mS,uC as mT,pA as mU,pW as mV,yW as mW,MA as mX,yA as mY,TA as mZ,Ol as m_,cW as ma,g6 as mb,QE as mc,aW as md,eW as me,gi as mf,Ag as mg,W9 as mh,kg as mi,E9 as mj,z9 as mk,Q4 as ml,qE as mm,GE as mn,jE as mo,NE as mp,Tc as mq,$E as mr,GH as ms,NH as mt,qH as mu,W8 as mv,yH as mw,oH as mx,mH as my,JL as mz,P7 as n,tL as n0,aL as n1,nL as n2,lL as n3,xL as n4,ZW as n5,rL as n6,cL as n7,oL as n8,iL as n9,gW as nA,dW as nB,HE as nC,oD as nD,Y3 as na,CL as nb,SB as nc,ph as nd,fz as ne,hk as nf,zP as ng,YL as nh,HB as ni,Sz as nj,s9 as nk,x9 as nl,YB as nm,gE as nn,hE as no,VB as np,_B as nq,jW as nr,$W as ns,Z9 as nt,Sr as nu,J9 as nv,t4 as nw,bW as nx,mW as ny,MW as nz,Yx as o,Br as p,P5 as q,E7 as r,za as s,J as t,rp as u,UM as v,ip as w,sp as x,l6 as y,Xr as z};
14579
+ ctx.restore()`,{k:1.2,min:.5})}),YP=t=>Object.hasOwn(ug,t)?ug[t]:null,gg=Object.freeze({accent:"#ff1f8e",lime:"#c6f432",paper:"#fbf7fa",ink:"#141418"}),Im="#c6f432",Hs=Object.freeze(["ur-photocopy-scribble","ur-magenta-flash","ur-neon-edge","ur-torn-paper","ur-cutout-blocks","ur-sticker-slap","ed-box-wipe","ed-arc-swoosh","ed-star-flythrough","ed-window-morph","ed-window-morph-v","ed-flicker-cut","ed-color-flash","ed-negative-blink","ed-silhouette-lead","ed-flash-invert","ed-invert-cut","tl-duotone-flash","tl-pixel-dissolve","tl-card-cascade","tl-chevron-push","tl-scramble","tl-blur-whip","tl-frame-zoom"]),QP=Object.freeze(Ul.filter(t=>Hs.includes(t.id))),n0=.2,o0=1.2,ZP=/^#[0-9a-fA-F]{6}$/,Lo=t=>Ao(t)&&!t.motion&&!t.lottie&&!t.geo&&!t.element&&!t.solid&&!t.adjust&&!t.nullLayer&&!t.freeze,Kl=t=>{const e=Ls(t?.style),c=Number.isFinite(t?.duration)?t.duration:e?.dur??.5;return 2*V(Math.max(n0,Math.min(o0,c))/2)},af=(t,e)=>t.kind==="sequence"?e+1/15:1.5*e+1/15;function Om(t,e,c,{duration:a,color:n}={}){const o=t.find(d=>d.id===e);if(!o)throw Error("Clip not found");if(c==="none"){if(!o.join)throw Error("No join style on this cut");return t.map(d=>{if(d.id!==e)return d;const{join:p,...b}=d;return b})}const i=Io(t,o);if(!Lo(o)||!Lo(i))throw Error("Join styles need two touching filmed clips (video / photo) on the same track");const s=Ls(c??o.join?.style);if(!s||!Hs.includes(s.id))throw Error(`Unknown footage join style "${c}" — use ${Hs.join(", ")}`);const r={style:s.id},l=Number.isFinite(a)?a:o.join?.style===s.id?o.join.duration:void 0;if(l!==void 0){if(!(l>=n0&&l<=o0))throw Error("Join duration must be 0.2–1.2 s");r.duration=V(l)}const x=n??o.join?.color;if(x!==void 0){if(!ZP.test(x))throw Error("Join colour must be #RRGGBB");r.color=x}const h=Kl(r),f=af(s,h);if(o.duration<f-1e-6||i.duration<f-1e-6)throw Error(`Clips too short for this join (each needs ≥ ${f.toFixed(2)} s)`);return t.map(d=>{if(d.id===o.id){const{transition:p,visualFadeOut:b,fadeOutColor:g,...m}=d;return{...m,join:r}}if(d.id===i.id&&(d.visualFadeIn||d.fadeInColor)){const{visualFadeIn:p,fadeInColor:b,...g}=d;return g}return d})}function JP(t,e,c,{duration:a,newId:n=()=>`sil-${Math.random().toString(36).slice(2,9)}`}={}){const o=t.find(T=>T.id===c),i=o&&Io(t,o);if(!o||!i||!Lo(o)||!Lo(i))throw Error("Silhouette reveal needs two touching filmed clips on one track");if(i.kind!=="image"||!i.url)throw Error("Silhouette reveal needs a photo after the cut (its subject is cut out in the browser)");const s=Om(t,c,"ed-silhouette-lead",{duration:a}),r=Kl(s.find(T=>T.id===c).join),l=V(i.start-r/2),x=V(i.start+r/2),{track:h}=bl(s,e,l,x),{transition:f,join:d,visualFadeIn:p,visualFadeOut:b,fadeInColor:g,fadeOutColor:m,enter:y,exit:k,captions:w,captionWords:A,mask:u,...M}=i,v=kn({...M,id:n(),track:h,start:l,duration:V(x-l),volume:0,label:`${i.label??"Shot"} · silhouette`,silhouetteOf:i.id},"enter","slide-left",{duration:V(r/2),amount:1,fade:!1,ease:"expo-out"});return{clips:[...s,v],copyId:v.id}}function i0(t){return t.filter(e=>e.join&&!e.disabled).flatMap(e=>{const c=Io(t,e),a=Ls(e.join.style);if(!a||!Hs.includes(a.id)||e.transition||!Lo(e)||!Lo(c))return[];const n=Kl(e.join);return e.duration<af(a,n)-1e-6||c.duration<af(a,n)-1e-6?[]:[{a:e,b:c,style:a,w:n,cut:c.start}]})}const Xx=t=>{const e=tc[t.ease],c=e==="hold"?[-1,0,0,0]:Array.isArray(e)?e:[0,0,1,1];return{e0:c[0],e1:c[1],e2:c[2],e3:c[3]}};function s0({a:t,b:e,style:c,w:a,cut:n}){const o=c.pack==="urban",i=c.pack==="techlaunch",s=c.sticker?null:i?YP(c.deco):o?qP(c.deco):XP(c.deco);if(!s)return null;const r=t.join.color??(i?gg.accent:Im),l=V(Math.min(2*n,Ja.maxDuration,Math.max(s.min,a*s.k+s.add))),x=Ry({code:s.code,params:i?{...gg,accent:r,...Xx(c)}:o?{accent:r,...NP,...Xx(c)}:{accent:r,..._P,...Xx(c),w:a,flash:t.join.color??"#ffffff"},preset:c.id});return{id:`${t.id}~jfx`,nodeId:"",kind:"image",url:"",label:`${i?"Tech Launch":o?"Urban":"Editorial"} · ${t.label} → ${e.label}`,volume:0,start:V(n-l/2),duration:l,track:t.track,motion:{...x,duration:l},motionKeys:[],_slot:"k",_virtual:t.id,...t.zIndex!==void 0||e.zIndex!==void 0?{zIndex:Math.max(t.zIndex??0,e.zIndex??0)}:{},...s.cam&&t.is3D&&e.is3D?{is3D:!0}:{}}}function t7(t){const e=new Set(t.map(c=>c.id));return i0(t).map(s0).filter(c=>c&&!e.has(c.id))}const e7=.1,bg=(t,e)=>{const{captions:c,captionWords:a,audioFadeIn:n,audioFadeOut:o,visualFadeIn:i,visualFadeOut:s,enter:r,exit:l,transition:x,join:h,...f}=t;return{...f,volume:0,_slot:"j",_virtual:e}},yg=t=>{if(!t.revealType)return t;const{revealType:e,reveal:c,...a}=t;return{...a,...It(a,"reveal").length?{motionKeys:Ba(a,"reveal",[])}:{}}};function qm(t){if(!t.some(o=>o.join))return t;let e=t.slice();const c=[],a=[],n=o=>{e=e.map(i=>i.id===o.id?o:i)};for(const o of i0(t).sort((i,s)=>i.cut-s.cut)){const i=e.find(b=>b.id===o.a.id),s=e.find(b=>b.id===o.b.id),{style:r,w:l,cut:x}=o,h=l/2,f=V(x-h),d=V(x+h);if(r.kind==="sequence"){const b=xg(r,{out:[i],inn:[{...s,start:f,duration:V(s.duration+h)}],b0:f,b1:d});for(const g of[i,s]){const m=b.get(g.id);if(!m)continue;let{seam:y,...k}=m;r.sticker&&(k={...k,motionKeys:Ba(k,"rot",It(g,"rot"))}),n({...k,start:g.start,duration:g.duration,inPoint:g.inPoint,...g.seam?{seam:g.seam}:{}})}}else{const b=i.playbackRate||1,g=s.playbackRate||1,{tail:m,head:y}=u2(i,s),k=xg(r,{out:[i],inn:[{...s,inPoint:(s.inPoint||0)-h*g}],b0:f,b1:d}),w=k.get(i.id),A=k.get(s.id);if(!w||!A)continue;const u=({seam:P,...z})=>z,[M,v]=eg(u(w),x,`${i.id}~jna`),[T,S]=eg(u(A),x,s.id);if(!v||!S)continue;n({...yg(M),...i.seam?{seam:i.seam}:{}}),n({...yg({...S,inPoint:s.inPoint||0}),...s.seam?{seam:s.seam}:{}}),(m<h||y<h)&&c.push({clipId:i.id,tail:Math.min(m,h),head:Math.min(y,h),need:h});const C=i.kind==="video"&&m<h,R=s.kind==="video"&&y<h;a.push({...bg(v,i.id),...C?{_still:!0,inPoint:Math.max(0,(i.inPoint||0)+i.duration*b-e7)}:{}}),a.push({...bg({...T,id:`${s.id}~jnb`},s.id),...R?{_still:!0,inPoint:s.inPoint||0}:{inPoint:(s.inPoint||0)-h*g}})}const p=s0({...o,a:{...o.a}});p&&!t.some(b=>b.id===p.id)&&a.push(p)}return Object.assign([...e,...a],{short:c})}const oD=Object.freeze(Object.defineProperty({__proto__:null,FOOTAGE_JOIN_ACCENT:Im,FOOTAGE_JOIN_IDS:Hs,FOOTAGE_JOIN_MAX:o0,FOOTAGE_JOIN_MIN:n0,FOOTAGE_JOIN_STYLES:QP,cutJoins:i0,expandJoins:qm,joinDeco:s0,joinDecoLayers:t7,joinWindow:Kl,joinable:Lo,setCutJoin:Om,silhouetteReveal:JP},Symbol.toStringTag,{value:"Module"})),mg=21600,Nm=t=>t.kind==="image"&&(im(t.title)||!!t.shape||!!t.motion||!!t.lottie||!!t.card||!!t.geo||t.warped===!0),iD=t=>rk(qm((t||[]).filter(e=>e&&!e.disabled))).filter(e=>e._virtual&&Nm(e)),sD=(t,e)=>(t||[]).filter(c=>!c?.disabled&&Nm(c)).reduce((c,a)=>c+(uR(a)?1:Math.ceil(a.duration*e)),0),rD=(t,e=!0)=>e?`Video có quá nhiều lớp chữ động / Motion chồng nhau (${t} khung, tối đa ${mg}). Hãy xuất từng đoạn ngắn hơn hoặc xoá bớt các lớp chữ trùng nhau.`:`Too many overlapping animated text / Motion layers (${t} frames, max ${mg}). Export a shorter part at a time or remove duplicate text layers.`;export{i4 as $,KH as A,gl as B,dk as C,T5 as D,OH as E,Ye as F,ya as G,Hs as H,hW as I,Ul as J,u6 as K,iW as L,J1 as M,$8 as N,YE as O,oy as P,_8 as Q,Xa as R,bM as S,Ay as T,Xb as U,LE as V,Zb as W,Ib as X,ME as Y,fE as Z,c7 as _,sf as a,Vg as a$,TE as a0,Jr as a1,T4 as a2,PE as a3,G4 as a4,P4 as a5,Ih as a6,uE as a7,BE as a8,zE as a9,ez as aA,tc as aB,az as aC,nz as aD,Pn as aE,Ds as aF,me as aG,ws as aH,iM as aI,nn as aJ,lz as aK,Vn as aL,xz as aM,oz as aN,hz as aO,iw as aP,Tz as aQ,vi as aR,aw as aS,jM as aT,R0 as aU,Ql as aV,vM as aW,AM as aX,XM as aY,lw as aZ,sw as a_,EE as aa,WE as ab,lb as ac,$b as ad,jd as ae,Bf as af,l4 as ag,Kd as ah,Tf as ai,Oh as aj,Ub as ak,zl as al,L4 as am,$4 as an,I4 as ao,Az as ap,LM as aq,ar,yz as as,bz as at,V as au,U5 as av,Mr as aw,hs as ax,M0 as ay,cz as az,Qx as b,Ps as b$,vz as b0,Pz as b1,Rz as b2,ah as b3,pz as b4,gz as b5,Ss as b6,C0 as b7,GM as b8,Zl as b9,gH as bA,HR as bB,cH as bC,aH as bD,eH as bE,Jh as bF,pH as bG,dB as bH,o7 as bI,r7 as bJ,t5 as bK,dh as bL,MB as bM,vB as bN,pB as bO,AB as bP,TB as bQ,mB as bR,uB as bS,gB as bT,s7 as bU,x7 as bV,bB as bW,yB as bX,wB as bY,kB as bZ,Hb as b_,DM as ba,JM as bb,z0 as bc,P0 as bd,B0 as be,wz as bf,X4 as bg,q3 as bh,C7 as bi,XE as bj,If as bk,t6 as bl,FE as bm,_E as bn,VE as bo,Cm as bp,ef as bq,V1 as br,_1 as bs,zs as bt,w8 as bu,M8 as bv,R8 as bw,sW as bx,p1 as by,ve as bz,z7 as c,Ml as c$,Ns as c0,n7 as c1,FB as c2,pR as c3,fR as c4,zL as c5,sm as c6,oR as c7,DL as c8,eo as c9,C9 as cA,K2 as cB,r9 as cC,M9 as cD,_a as cE,f9 as cF,pS as cG,l9 as cH,wS as cI,X2 as cJ,nS as cK,c9 as cL,RR as cM,e9 as cN,hc as cO,dS as cP,zS as cQ,i9 as cR,n9 as cS,o9 as cT,PS as cU,h9 as cV,t9 as cW,QB as cX,Te as cY,hS as cZ,id as c_,iR as ca,sR as cb,HL as cc,Yn as cd,gR as ce,sn as cf,BL as cg,LL as ch,Co as ci,hB as cj,xB as ck,fB as cl,RB as cm,Sk as cn,Z0 as co,Do as cp,XL as cq,X7 as cr,$f as cs,Bs as ct,Ny as cu,Gy as cv,PA as cw,Zk as cx,KB as cy,U2 as cz,R7 as d,vC as d$,Mf as d0,JB as d1,ZB as d2,xS as d3,oS as d4,bE as d5,Xv as d6,co as d7,zd as d8,sE as d9,Hv as dA,RW as dB,PW as dC,AA as dD,Uh as dE,qy as dF,wW as dG,Xf as dH,Xh as dI,kA as dJ,FW as dK,mo as dL,kW as dM,XW as dN,vW as dO,TW as dP,SW as dQ,CW as dR,Oy as dS,QW as dT,AW as dU,YW as dV,_W as dW,VW as dX,Ox as dY,UW as dZ,Xy as d_,$v as da,Cv as db,Fv as dc,Ed as dd,rE as de,Wb as df,Cb as dg,Wd as dh,HC as di,ML as dj,SL as dk,kL as dl,bl as dm,Vh as dn,js as dp,Ro as dq,dE as dr,Db as ds,vl as dt,V3 as du,$s as dv,gb as dw,eE as dx,yb as dy,Dv as dz,A5 as e,RE as e$,hL as e0,Cs as e1,XB as e2,Rl as e3,SE as e4,qb as e5,vr as e6,kE as e7,Rk as e8,GB as e9,$w as eA,eB,Zz as eC,Jz as eD,tB as eE,Kz as eF,Qz as eG,Xz as eH,p9 as eI,HS as eJ,u9 as eK,qS as eL,g9 as eM,d9 as eN,y9 as eO,fL as eP,rk as eQ,qm as eR,rx as eS,Bk as eT,im as eU,DH as eV,IH as eW,UH as eX,JW as eY,zW as eZ,PP as e_,PC as ea,jL as eb,It as ec,Pr as ed,et as ee,Mo as ef,Zt as eg,_4 as eh,DE as ei,V4 as ej,Qb as ek,ps as el,FL as em,aB as en,g2 as eo,p2 as ep,Yz as eq,Oz as er,Nz as es,To as et,bo as eu,qz as ev,Uz as ew,_z as ex,Vz as ey,Fz as ez,Rm as f,T7 as f$,mw as f0,qW as f1,NB as f2,p4 as f3,QC as f4,IL as f5,b9 as f6,Iz as f7,EL as f8,Ll as f9,tr as fA,L5 as fB,OE as fC,xC as fD,DW as fE,jB as fF,NL as fG,qL as fH,qB as fI,L9 as fJ,of as fK,Tg as fL,b7 as fM,p0 as fN,m7 as fO,nb as fP,h7 as fQ,f7 as fR,n5 as fS,d7 as fT,M7 as fU,Pa as fV,M5 as fW,w5 as fX,Vx as fY,v7 as fZ,A7 as f_,ye as fa,Vs as fb,Ys as fc,Hl as fd,bm as fe,K7 as ff,vL as fg,rz as fh,J7 as fi,DB as fj,F7 as fk,dL as fl,pL as fm,il as fn,EB as fo,mf as fp,Xk as fq,to as fr,jy as fs,v2 as ft,Mi as fu,NW as fv,uc as fw,_f as fx,Dl as fy,Js as fz,qM as g,MH as g$,Sl as g0,q9 as g1,M3 as g2,si as g3,Lm as g4,O9 as g5,d3 as g6,cb as g7,KS as g8,kl as g9,S9 as gA,p7 as gB,$9 as gC,B9 as gD,w9 as gE,Ww as gF,Sw as gG,vo as gH,D0 as gI,Gz as gJ,fl as gK,pf as gL,i2 as gM,Kr as gN,So as gO,vw as gP,h2 as gQ,$z as gR,N0 as gS,di as gT,Ck as gU,As as gV,Il as gW,$e as gX,Vf as gY,WW as gZ,wm as g_,R9 as ga,P9 as gb,fd as gc,yd as gd,j9 as ge,ob as gf,G9 as gg,QL as gh,Wz as gi,Ez as gj,Hz as gk,ZH as gl,Lz as gm,RH as gn,zH as go,PH as gp,Md as gq,K9 as gr,U9 as gs,C3 as gt,k9 as gu,T3 as gv,A9 as gw,g7 as gx,v9 as gy,T9 as gz,Ho as h,zk as h$,sl as h0,ZL as h1,SH as h2,_R as h3,uz as h4,LA as h5,UC as h6,AL as h7,c0 as h8,ol as h9,E5 as hA,xE as hB,EP as hC,Kl as hD,QP as hE,o0 as hF,n0 as hG,iE as hH,X9 as hI,F9 as hJ,vf as hK,cr as hL,pm as hM,um as hN,gm as hO,cy as hP,JH as hQ,tD as hR,ni as hS,v0 as hT,Nm as hU,zB as hV,OW as hW,gh as hX,PB as hY,OB as hZ,LW as h_,TL as ha,FC as hb,Vr as hc,HH as hd,tl as he,F4 as hf,o4 as hg,AE as hh,Zr as hi,Hf as hj,ey as hk,Lh as hl,Zv as hm,Ob as hn,bi as ho,yi as hp,Vb as hq,CE as hr,d4 as hs,Qd as ht,Yb as hu,Kb as hv,vE as hw,Ls as hx,Ry as hy,Ja as hz,TM as i,xi as i$,kz as i0,LB as i1,tP as i2,TH as i3,_L as i4,BB as i5,KW as i6,GA as i7,HW as i8,pE as i9,Qn as iA,oE as iB,mb as iC,aE as iD,tv as iE,Mb as iF,WB as iG,X5 as iH,oB as iI,Ao as iJ,yL as iK,a9 as iL,UB as iM,rD as iN,dl as iO,Os as iP,iD as iQ,J8 as iR,Qf as iS,us as iT,V7 as iU,Q7 as iV,Z7 as iW,Y7 as iX,_5 as iY,_7 as iZ,mz as i_,Io as ia,u2 as ib,rh as ic,rB as id,sB as ie,Lo as ig,FH as ih,Bo as ii,zo as ij,AH as ik,EH as il,Xm as im,eg as io,bR as ip,sD as iq,mg as ir,Kk as is,$B as it,CH as iu,BH as iv,LH as iw,WH as ix,ab as iy,yE as iz,hf as j,x5 as j$,Mz as j0,KE as j1,e6 as j2,c6 as j3,a6 as j4,Bn as j5,YC as j6,a7 as j7,VL as j8,TR as j9,nD as jA,cD as jB,eD as jC,aD as jD,xg as jE,YP as jF,qP as jG,XP as jH,gg as jI,NP as jJ,_P as jK,fW as jL,JE as jM,tW as jN,AT as jO,RT as jP,PT as jQ,mR as jR,Ky as jS,T2 as jT,vh as jU,fb as jV,rb as jW,Y4 as jX,IW as jY,S7 as jZ,u7 as j_,gr as ja,Qt as jb,GL as jc,Hg as jd,K5 as je,m1 as jf,uW as jg,Ba as jh,Hx as ji,xA as jj,w1 as jk,Pi as jl,ki as jm,eC as jn,k8 as jo,D8 as jp,rC as jq,lC as jr,$y as js,H8 as jt,FM as ju,LS as jv,_r as jw,Cc as jx,xW as jy,be as jz,Um as k,pP as k$,l5 as k0,ys as k1,H9 as k2,p5 as k3,l0 as k4,i5 as k5,kf as k6,eb as k7,w7 as k8,y7 as k9,Cg as kA,Rg as kB,m5 as kC,Rc as kD,l7 as kE,Zm as kF,Qe as kG,i7 as kH,_m as kI,Tk as kJ,lE as kK,cE as kL,J3 as kM,wL as kN,G7 as kO,U7 as kP,N7 as kQ,_H as kR,VH as kS,YH as kT,QH as kU,mL as kV,zC as kW,EC as kX,bL as kY,uL as kZ,gL as k_,JS as ka,k7 as kb,d5 as kc,D9 as kd,I9 as ke,o5 as kf,Sg as kg,ao as kh,gS as ki,MS as kj,Fh as kk,uH as kl,dR as km,eL as kn,a0 as ko,JP as kp,Om as kq,kH as kr,mi as ks,RP as kt,$H as ku,jH as kv,UE as kw,kn as kx,B7 as ky,y5 as kz,gf as l,O7 as l$,Pm as l0,$r as l1,Hr as l2,Pk as l3,ih as l4,jz as l5,cB as l6,dz as l7,WM as l8,XC as l9,tz as lA,Q9 as lB,d2 as lC,EW as lD,sz as lE,iz as lF,mE as lG,j4 as lH,KL as lI,m9 as lJ,BS as lK,pw as lL,uw as lM,Y9 as lN,_9 as lO,V9 as lP,eP as lQ,U1 as lR,vH as lS,WL as lT,aR as lU,q7 as lV,wH as lW,j7 as lX,$7 as lY,L7 as lZ,H7 as l_,_C as la,GW as lb,IB as lc,B2 as ld,OL as le,iB as lf,tE as lg,Iv as lh,F3 as li,Ov as lj,nE as lk,Pl as ll,Dz as lm,IE as ln,$L as lo,XH as lp,ko as lq,nB as lr,cC as ls,zz as lt,Bz as lu,Cz as lv,lB as lw,CB as lx,qg as ly,UL as lz,ti as m,sL as m$,D7 as m0,I7 as m1,W7 as m2,uR as m3,N9 as m4,lW as m5,BW as m6,ZE as m7,oW as m8,nW as m9,iH as mA,dH as mB,nH as mC,hH as mD,fH as mE,rH as mF,sH as mG,rW as mH,tH as mI,lH as mJ,xH as mK,bH as mL,od as mM,fP as mN,a5 as mO,PL as mP,RL as mQ,wE as mR,Xs as mS,uC as mT,pA as mU,pW as mV,yW as mW,MA as mX,yA as mY,TA as mZ,Ol as m_,cW as ma,g6 as mb,QE as mc,aW as md,eW as me,gi as mf,Ag as mg,W9 as mh,kg as mi,E9 as mj,z9 as mk,Q4 as ml,qE as mm,GE as mn,jE as mo,NE as mp,Tc as mq,$E as mr,GH as ms,NH as mt,qH as mu,W8 as mv,yH as mw,oH as mx,mH as my,JL as mz,P7 as n,tL as n0,aL as n1,nL as n2,lL as n3,xL as n4,ZW as n5,rL as n6,cL as n7,oL as n8,iL as n9,gW as nA,dW as nB,HE as nC,oD as nD,Y3 as na,fz as nb,hk as nc,zP as nd,YL as ne,HB as nf,Sz as ng,s9 as nh,x9 as ni,YB as nj,gE as nk,hE as nl,VB as nm,_B as nn,CL as no,SB as np,ph as nq,jW as nr,$W as ns,Z9 as nt,Sr as nu,J9 as nv,t4 as nw,bW as nx,mW as ny,MW as nz,Yx as o,Br as p,P5 as q,E7 as r,za as s,J as t,rp as u,UM as v,ip as w,sp as x,l6 as y,Xr as z};
@@ -1 +1 @@
1
- import{c1 as T,eQ as ot,eR as rt,m3 as nt,eV as B,m4 as it,ec as st,eW as lt,eS as O,ee as V,eU as Q,eZ as X,eY as Z,e_ as q,eX as z}from"./titleFrameBudget-BYRZAQPs.js";import{l as ht,d as dt}from"./titleArt-B8DVR58F.js";import{i as R,j as mt,s as k,d as P,l as ct,k as j,f as ft,e as G,a as ut,p as pt,t as wt,m as tt}from"./lottieLayer-1ET89OUr.js";import{wantsFrame as J,SKIPPED_FRAME as gt}from"./frameSink-BvOXjLuw.js";import{t as N}from"./api-DUp403BK.js";import"./textAnimators-nVSz_sZo.js";import"./rigTrack-UYZU4P-e.js";const xt=e=>Q(e.title)||!!e.shape||!!e.motion||!!e.lottie||!!e.card||!!e.geo,U=e=>e.kind==="image"&&!!e.title?.text&&!e.url&&!Q(e.title),H=4,Y=192*1024*1024,g=new Map;let A=0;function Et(e,s){if(e.geo||e.shape&&R(e.shape)||e.pin?.scene||e.space)return null;const{start:i,track:h,...n}=e;return JSON.stringify([s,n])}function Mt(e,s){const i=s.reduce((h,n)=>h+n.length,0);if(!(i>Y/4)){g.delete(e),g.set(e,{frames:s,bytes:i}),A+=i;for(const[h,n]of g){if(A<=Y)break;g.delete(h),A-=n.bytes}}}function Tt(){g.clear(),A=0}const bt=e=>new Promise((s,i)=>e.toBlob(h=>{if(!h)return i(Error("Cannot encode title frame"));const n=new FileReader;n.onload=()=>s(String(n.result).slice(String(n.result).indexOf(",")+1)),n.onerror=()=>i(n.error),n.readAsDataURL(h)},"image/webp",.9));async function Pt(e,s,i,h,n){const{fps:o,width:f,height:S}=T(s),u=T({...s,resolution:"720p"}),y=e.some(t=>t.shape&&R(t.shape))?ot(rt(e)):null,$=!!i.wants;for(const t of e.filter(d=>(xt(d)||U(d))&&!d.warped)){if(!J(i,"titleFrames",t.id))continue;const d=a=>J(i,"titleFrames",t.id,a),m=Et(t,s),r=m?g.get(m):void 0;if(r){g.delete(m),g.set(m,r);for(const a of r.frames){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");await i.push("titleFrames",t.id,a)}continue}const x=[],E=t.title,M=nt(t)||U(t)?1:Math.ceil(t.duration*o);if(M>1&&Math.ceil(t.duration*o)>3600)throw Error("Mỗi tiêu đề động / Motion tối đa 2 phút khi xuất MP4.");E&&!t.shape&&!t.motion&&!t.lottie&&!t.card&&!t.geo&&await ht(E);const b=t.card?await mt(t.card).catch(a=>{throw Error(N("Thẻ HTML “{0}”: {1}",[t.label,a.message]))}):null,[p,w]=b?[b.width,b.height]:t.geo?[u.width,u.height]:t.lottie?[B(t.lottie).W,B(t.lottie).H]:t.motion?[u.width,u.height]:t.shape?[k(t.shape).W,k(t.shape).H]:[1280,720],C=Object.assign(document.createElement("canvas"),{width:p,height:w}),F=C.getContext("2d");if(!F)throw Error("Canvas unavailable");let _="",D=null;const I=(a,l)=>tt({layer:`export:${a.id}`,motion:a.motion,t:z(a,l/o),width:p,height:w,duration:q(a),fps:o,surface:a.pin?.scene?Z(a,e,a.start+l/o,p,w):null,space:a.space?(O(e),X(a,e,a.start+l/o,p,w,n)):null}),c=[],L="\0same",W="\0skip",K=t.shape&&!t.motion&&!t.card&&!t.lottie&&!t.geo&&!R(t.shape)?it(t.shape):null,et=K==null?1/0:Math.max(K,...["trimStart","trimEnd"].flatMap(a=>st(t,a).map(l=>l.time))),v=async()=>{const a=await c.shift();if(a===W){await i.push("titleFrames",t.id,gt);return}if(a===L||a===_){x.push("="),await i.push("titleFrames",t.id,"=");return}_=a,x.push(a),await i.push("titleFrames",t.id,a)};try{for(let a=0;a<M;a++){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");if(!d(a)){c.push(Promise.resolve(W)),c.length>=H&&await v();continue}if(!$&&a>0&&(a-1)/o>et+1e-6){c.push(Promise.resolve(L)),c.length>=H&&await v();continue}if(F.clearRect(0,0,p,w),t.motion){let l;try{l=await(D??I(t,a)),D=a+1<M&&d(a+1)?I(t,a+1):null}catch(at){throw D?.catch(()=>{}),P(`export:${t.id}`),Error(`Motion “${t.label}”: ${at.message}`)}F.drawImage(l,0,0),l.close()}else if(t.lottie)try{await ct(`export:${t.id}`,t.url,{W:p,H:w},lt(t,a/o),C)}catch(l){throw j(`export:${t.id}`),Error(`Lottie “${t.label}”: ${l.message}`)}else if(t.geo)try{await ft(`export:${t.id}`,t.geo,{W:p,H:w},a/o,C,{wait:2e4,duration:t.duration})}catch(l){throw G(`export:${t.id}`),Error(N("Bản đồ “{0}”: {1}",[t.label,l.message]))}else b?F.drawImage(b,0,0):t.shape?(y&&O(y),ut(F,pt(t,e,a/o,f,S),{start:V(t,"trimStart",a/o),end:V(t,"trimEnd",a/o),offset:wt(t.shape)},p,w,a/o)):dt(F,E,{time:a/o,duration:t.duration});c.push(bt(C)),c.length>=H&&await v()}for(;c.length;)await v();m&&!$&&Mt(m,x)}finally{for(const a of c)a.catch(()=>{})}t.motion&&P(`export:${t.id}`),t.lottie&&j(`export:${t.id}`),t.geo&&G(`export:${t.id}`)}}function Dt(e,s,i,h){const{fps:n}=T(i),{width:o,height:f}=T({...i,resolution:"720p"}),S=Math.ceil(e.duration*n)-1,u=Object.assign(document.createElement("canvas"),{width:o,height:f}),y=u.getContext("2d");if(!y)throw Error("Canvas unavailable");const $=r=>tt({layer:`export:${e.id}`,motion:e.motion,t:z(e,r/n),width:o,height:f,duration:q(e),fps:n,surface:e.pin?.scene?Z(e,s,e.start+r/n,o,f):null,space:e.space?(O(s),X(e,s,e.start+r/n,o,f,h)):null});let t=null,d=-1;const m=r=>{r?.p.then(x=>x.close(),()=>{})};return{W:o,H:f,async frame(r){if(r=Math.max(0,Math.min(S,r)),r===d)return u;for(;t&&t.i<r;){const M=t;t=null,await M.p.then(b=>b.close(),()=>{})}const x=t&&t.i===r?t.p:$(r);t&&t.i!==r&&m(t),t=null;let E;try{E=await x}catch(M){throw P(`export:${e.id}`),Error(`Motion “${e.label}”: ${M.message}`)}return t=r<S?{i:r+1,p:$(r+1)}:null,y.clearRect(0,0,o,f),y.drawImage(E,0,0),E.close(),d=r,u},close(){m(t),t=null,P(`export:${e.id}`)}}}export{Tt as clearFrameCache,Et as frameCacheKey,Dt as liveMotion,Pt as renderTitleFrames};
1
+ import{c1 as T,eQ as ot,eR as rt,m3 as nt,eV as B,m4 as it,ec as st,eW as lt,eS as O,ee as V,eU as Q,eZ as X,eY as Z,e_ as q,eX as z}from"./titleFrameBudget-CLZWaFHO.js";import{l as ht,d as dt}from"./titleArt-Drsrtfiv.js";import{i as R,j as mt,s as k,d as P,l as ct,k as j,f as ft,e as G,a as ut,p as pt,t as wt,m as tt}from"./lottieLayer-DzbA3bHV.js";import{wantsFrame as J,SKIPPED_FRAME as gt}from"./frameSink-DeM8xC8_.js";import{t as N}from"./api-CJ8PdbfZ.js";import"./textAnimators-DUZjhVGO.js";import"./rigTrack-urT3nDK0.js";const xt=e=>Q(e.title)||!!e.shape||!!e.motion||!!e.lottie||!!e.card||!!e.geo,U=e=>e.kind==="image"&&!!e.title?.text&&!e.url&&!Q(e.title),H=4,Y=192*1024*1024,g=new Map;let A=0;function Et(e,s){if(e.geo||e.shape&&R(e.shape)||e.pin?.scene||e.space)return null;const{start:i,track:h,...n}=e;return JSON.stringify([s,n])}function Mt(e,s){const i=s.reduce((h,n)=>h+n.length,0);if(!(i>Y/4)){g.delete(e),g.set(e,{frames:s,bytes:i}),A+=i;for(const[h,n]of g){if(A<=Y)break;g.delete(h),A-=n.bytes}}}function Tt(){g.clear(),A=0}const bt=e=>new Promise((s,i)=>e.toBlob(h=>{if(!h)return i(Error("Cannot encode title frame"));const n=new FileReader;n.onload=()=>s(String(n.result).slice(String(n.result).indexOf(",")+1)),n.onerror=()=>i(n.error),n.readAsDataURL(h)},"image/webp",.9));async function Pt(e,s,i,h,n){const{fps:o,width:f,height:S}=T(s),u=T({...s,resolution:"720p"}),y=e.some(t=>t.shape&&R(t.shape))?ot(rt(e)):null,$=!!i.wants;for(const t of e.filter(d=>(xt(d)||U(d))&&!d.warped)){if(!J(i,"titleFrames",t.id))continue;const d=a=>J(i,"titleFrames",t.id,a),m=Et(t,s),r=m?g.get(m):void 0;if(r){g.delete(m),g.set(m,r);for(const a of r.frames){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");await i.push("titleFrames",t.id,a)}continue}const x=[],E=t.title,M=nt(t)||U(t)?1:Math.ceil(t.duration*o);if(M>1&&Math.ceil(t.duration*o)>3600)throw Error("Mỗi tiêu đề động / Motion tối đa 2 phút khi xuất MP4.");E&&!t.shape&&!t.motion&&!t.lottie&&!t.card&&!t.geo&&await ht(E);const b=t.card?await mt(t.card).catch(a=>{throw Error(N("Thẻ HTML “{0}”: {1}",[t.label,a.message]))}):null,[p,w]=b?[b.width,b.height]:t.geo?[u.width,u.height]:t.lottie?[B(t.lottie).W,B(t.lottie).H]:t.motion?[u.width,u.height]:t.shape?[k(t.shape).W,k(t.shape).H]:[1280,720],C=Object.assign(document.createElement("canvas"),{width:p,height:w}),F=C.getContext("2d");if(!F)throw Error("Canvas unavailable");let _="",D=null;const I=(a,l)=>tt({layer:`export:${a.id}`,motion:a.motion,t:z(a,l/o),width:p,height:w,duration:q(a),fps:o,surface:a.pin?.scene?Z(a,e,a.start+l/o,p,w):null,space:a.space?(O(e),X(a,e,a.start+l/o,p,w,n)):null}),c=[],L="\0same",W="\0skip",K=t.shape&&!t.motion&&!t.card&&!t.lottie&&!t.geo&&!R(t.shape)?it(t.shape):null,et=K==null?1/0:Math.max(K,...["trimStart","trimEnd"].flatMap(a=>st(t,a).map(l=>l.time))),v=async()=>{const a=await c.shift();if(a===W){await i.push("titleFrames",t.id,gt);return}if(a===L||a===_){x.push("="),await i.push("titleFrames",t.id,"=");return}_=a,x.push(a),await i.push("titleFrames",t.id,a)};try{for(let a=0;a<M;a++){if(h?.aborted)throw new DOMException("Export cancelled","AbortError");if(!d(a)){c.push(Promise.resolve(W)),c.length>=H&&await v();continue}if(!$&&a>0&&(a-1)/o>et+1e-6){c.push(Promise.resolve(L)),c.length>=H&&await v();continue}if(F.clearRect(0,0,p,w),t.motion){let l;try{l=await(D??I(t,a)),D=a+1<M&&d(a+1)?I(t,a+1):null}catch(at){throw D?.catch(()=>{}),P(`export:${t.id}`),Error(`Motion “${t.label}”: ${at.message}`)}F.drawImage(l,0,0),l.close()}else if(t.lottie)try{await ct(`export:${t.id}`,t.url,{W:p,H:w},lt(t,a/o),C)}catch(l){throw j(`export:${t.id}`),Error(`Lottie “${t.label}”: ${l.message}`)}else if(t.geo)try{await ft(`export:${t.id}`,t.geo,{W:p,H:w},a/o,C,{wait:2e4,duration:t.duration})}catch(l){throw G(`export:${t.id}`),Error(N("Bản đồ “{0}”: {1}",[t.label,l.message]))}else b?F.drawImage(b,0,0):t.shape?(y&&O(y),ut(F,pt(t,e,a/o,f,S),{start:V(t,"trimStart",a/o),end:V(t,"trimEnd",a/o),offset:wt(t.shape)},p,w,a/o)):dt(F,E,{time:a/o,duration:t.duration});c.push(bt(C)),c.length>=H&&await v()}for(;c.length;)await v();m&&!$&&Mt(m,x)}finally{for(const a of c)a.catch(()=>{})}t.motion&&P(`export:${t.id}`),t.lottie&&j(`export:${t.id}`),t.geo&&G(`export:${t.id}`)}}function Dt(e,s,i,h){const{fps:n}=T(i),{width:o,height:f}=T({...i,resolution:"720p"}),S=Math.ceil(e.duration*n)-1,u=Object.assign(document.createElement("canvas"),{width:o,height:f}),y=u.getContext("2d");if(!y)throw Error("Canvas unavailable");const $=r=>tt({layer:`export:${e.id}`,motion:e.motion,t:z(e,r/n),width:o,height:f,duration:q(e),fps:n,surface:e.pin?.scene?Z(e,s,e.start+r/n,o,f):null,space:e.space?(O(s),X(e,s,e.start+r/n,o,f,h)):null});let t=null,d=-1;const m=r=>{r?.p.then(x=>x.close(),()=>{})};return{W:o,H:f,async frame(r){if(r=Math.max(0,Math.min(S,r)),r===d)return u;for(;t&&t.i<r;){const M=t;t=null,await M.p.then(b=>b.close(),()=>{})}const x=t&&t.i===r?t.p:$(r);t&&t.i!==r&&m(t),t=null;let E;try{E=await x}catch(M){throw P(`export:${e.id}`),Error(`Motion “${e.label}”: ${M.message}`)}return t=r<S?{i:r+1,p:$(r+1)}:null,y.clearRect(0,0,o,f),y.drawImage(E,0,0),E.close(),d=r,u},close(){m(t),t=null,P(`export:${e.id}`)}}}export{Tt as clearFrameCache,Et as frameCacheKey,Dt as liveMotion,Pt as renderTitleFrames};
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GLTFExporter-BuGYM-Ik.js","assets/three.module-Bx43vjkH.js"])))=>i.map(i=>d[i]);
2
- import{dU as P}from"./remote-Dva2qg58.js";import{_ as R}from"./titleFrameBudget-BYRZAQPs.js";import{Vector3 as S,WebGLRenderer as O,NeutralToneMapping as D,SRGBColorSpace as B,Scene as F,Color as k,HemisphereLight as G,DirectionalLight as C,PerspectiveCamera as $,Mesh as q,Group as _,BufferGeometry as U,BufferAttribute as x,InstancedMesh as W,Matrix4 as Z,MeshPhysicalMaterial as V,DoubleSide as Y,FrontSide as X}from"./three.module-Bx43vjkH.js";const f=Object.freeze({code:24e3,triangles:3e5,instanceTriangles:3e6,meshes:64,instances:2e4,params:12,timeoutMs:8e3,size:500}),J=String.raw`
2
+ import{dU as P}from"./remote-C7J0Tqhb.js";import{_ as R}from"./titleFrameBudget-CLZWaFHO.js";import{Vector3 as S,WebGLRenderer as O,NeutralToneMapping as D,SRGBColorSpace as B,Scene as F,Color as k,HemisphereLight as G,DirectionalLight as C,PerspectiveCamera as $,Mesh as q,Group as _,BufferGeometry as U,BufferAttribute as x,InstancedMesh as W,Matrix4 as Z,MeshPhysicalMaterial as V,DoubleSide as Y,FrontSide as X}from"./three.module-Bx43vjkH.js";const f=Object.freeze({code:24e3,triangles:3e5,instanceTriangles:3e6,meshes:64,instances:2e4,params:12,timeoutMs:8e3,size:500}),J=String.raw`
3
3
  const __codeModel = (() => {
4
4
  const LIM = ${JSON.stringify(f)}
5
5
  let seed = 1, noiseSeed = 1
@@ -1 +1 @@
1
- import{b as N,c as E,a as _,d as D}from"./shotFxAgent-7RQNtEe4.js";import{jj as P,jk as B,gM as h,eL as L,eq as A,dJ as U,dH as X}from"./remote-Dva2qg58.js";import"./api-DUp403BK.js";import"./titleFrameBudget-BYRZAQPs.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./rigTrack-UYZU4P-e.js";const j=(s,n)=>{const o=h(s);return{anchor:n?(c,d,x)=>n.partPointAt(o,x,c.id,d):void 0,items:s.items,shot:o,at:(c,d)=>{const x=s.items.find(b=>b.id===c.id),k=X(x,o,o.duration?Math.max(0,Math.min(1,d/o.duration)):0);return{position:k.position,rotation:k.rotation}},uid:()=>crypto.randomUUID(),restPose:{...U.Đứng}}},w=(s,n,o)=>({...s,shots:s.shots.map(c=>c.id===s.activeShot?{...c,fxTiming:{...c.fxTiming,[n]:o}}:c)}),v=(s,n)=>{const o=A(s,h(n));return{name:s.name,id:s.id,effect:s.fx.cat??s.fx.preset,preset:s.fx.preset,start_s:o.start,end_s:+(o.start+o.duration).toFixed(2),...s.fx.attach?{attach:s.fx.attach}:{},...s.fx.path?{path:s.fx.path}:{}}};function Y(s,n,o){const c=o.engine();c&&c.sync(o.getStage(),null);const d=o.getStage();if(s==="add_effect"){const t=N(n,j(d,c));if(!t.ok)return{ok:!1,error:t.error};const e=t.item;if(e.fx&&e.fx.preset in P&&o.userText!=null&&!B(o.userText))return{ok:!1,error:"blood effects are only used when the user asks for blood (máu / blood) in their message — leave it out"};o.setStage(i=>w({...i,items:[...i.items,e]},e.id,t.timing));const f=h(o.getStage());return{ok:!0,...v(e,o.getStage()),...t.timing.start+t.timing.duration>f.duration+.01?{note:"the effect runs past the end of the shot; shorten it or extend the shot with set_duration"}:{},hint:"render_preview / preview_motion at the effect time to check it is readable"}}if(s==="add_destruction"){const t=E(n,j(d,c));if(!t.ok)return{ok:!1,error:t.error};const e=t.item;o.setStage(i=>{const a=w({...i,items:[...i.items,e]},e.id,t.timing);return{...a,shots:a.shots.map(p=>p.id===a.activeShot?{...p,objectKeys:{...p.objectKeys,[e.id]:t.keys}}:p)}});const f=d.items.filter(i=>i.fx?.preset===e.fx.preset&&i.fx?.target?.to===e.fx?.target?.to&&i.id!==e.id).map(i=>i.name);return{ok:!0,...v(e,o.getStage()),target:d.items.find(i=>i.id===e.fx?.target?.to)?.name,recipe:e.fx.params.recipe,...t.keys.length?{sphere_path:t.keys.map(i=>({at_s:+(i.time*h(d).duration).toFixed(2),position:i.position}))}:{mode:e.fx.params.mode},...f.length?{combines_with:f}:{},hint:"render_preview after the sweep / collapse time to see the destruction; remove_effect removes it"}}if(s==="edit_destruction"){const t=_(d.items.filter(m=>m.kind==="fx"&&m.fx?.preset===L),String(n.name));if(!t?.fx)return{ok:!1,error:`no Mix FX named '${String(n.name)}' (add_destruction makes one; scene_summary lists effects)`};const e=h(d),f=e.duration||1,i=[];let a=d;const p=m=>m.map((r,u)=>({id:`${t.id}-k${u}-${Math.round(r.time*1e6)}`,time:r.time,position:r.position,rotation:[...t.rotation],scale:[...t.scale]})),T=m=>{a={...a,shots:a.shots.map(r=>r.id===a.activeShot?{...r,objectKeys:{...r.objectKeys,[t.id]:m}}:r)}};if(n.target!=null){const m=d.items.find(r=>r.name.toLowerCase()===String(n.target).toLowerCase()&&r.kind!=="fx");if(!m)return{ok:!1,error:`no object '${String(n.target)}' to break`};a={...a,items:a.items.map(r=>r.id===t.id?{...r,fx:{...r.fx,target:{to:m.id,part:"center"}}}:r)},i.push(`target ${m.name}`)}if(Array.isArray(n.points)){if(n.points.length<2||n.points.length>24)return{ok:!1,error:"points: 2 to 24 path points"};const m=[];for(const r of n.points){const u=Number(r.time_s),l=r.position;if(!Number.isFinite(u)||u<0||u>f+1e-6)return{ok:!1,error:`time_s ${String(r.time_s)} is outside the shot (0–${f} s)`};if(!Array.isArray(l)||l.length!==3||!l.every(y=>Number.isFinite(Number(y))))return{ok:!1,error:"each point needs position [x, y, z]"};m.push({time:Math.min(1,u/f),position:l.map(Number)})}T(p(m.sort((r,u)=>r.time-u.time))),i.push(`path of ${m.length} points`)}else if(n.sweep===!0){const m=a.items.find(F=>F.id===t.id).fx,r=m.target?.to?c?.objectBounds()[m.target.to]:null;if(!r)return{ok:!1,error:"sweep measures the target: it needs the 3D view (a scene open in the composer or the render machine) and a target"};const u=m.params,l=Number(u.radius)*t.scale[0]+Number(u.falloff)+.3,y=(r.min[1]+r.max[1])/2,K=(r.min[2]+r.max[2])/2,S=A(t,e),M=Math.min(1,S.start/f),O=Math.min(1,(S.start+S.duration)/f);T(p([{time:M,position:[r.min[0]-l,y,K]},{time:O,position:[r.max[0]+l,y,K]}])),i.push("sweep through the target")}if(!i.length)return{ok:!1,error:"give points, sweep or target"};const $=a;return o.setStage(()=>$),{ok:!0,name:t.name,changed:i,path_s:(h($).objectKeys?.[t.id]||[]).map(m=>+(m.time*f).toFixed(3))}}if(s==="update_effect"){const t=_(d.items.filter(a=>a.kind==="fx"),String(n.name));if(!t?.fx)return{ok:!1,error:`no effect named '${String(n.name)}'; use remove_effect / update_effect with the name returned by add_effect (see scene_summary effects)`};const e=h(d),f=A(t,e),i=D(t,n,{...j(d,c),timing:f});return i.ok?(o.setStage(a=>w({...a,items:a.items.map(p=>p.id===t.id?{...p,...i.itemPatch,fx:i.fx}:p)},t.id,{start:i.timing.start,duration:i.timing.duration,...i.timing.loop?{loop:!0}:{}})),{ok:!0,...v(o.getStage().items.find(a=>a.id===t.id),o.getStage())}):{ok:!1,error:i.error}}const x=Array.isArray(n.names)?n.names.map(String):n.name!=null?[String(n.name)]:[],k=[],b=[],g=new Set;for(const t of x){const e=_(d.items.filter(f=>f.kind==="fx"),t);e?(g.add(e.id),k.push(e.name)):b.push(t)}for(const t of d.items)t.trackAnchor&&g.has(t.trackAnchor.effect)&&g.add(t.id);return o.setStage(t=>({...t,items:t.items.filter(e=>!g.has(e.id)),shots:t.shots.map(e=>({...e,...e.fxTiming?{fxTiming:Object.fromEntries(Object.entries(e.fxTiming).filter(([f])=>!g.has(f)))}:{},...e.objectKeys?{objectKeys:Object.fromEntries(Object.entries(e.objectKeys).filter(([f])=>!g.has(f)))}:{}}))})),{ok:!b.length,removed:k,missing:b}}export{Y as runFxTool};
1
+ import{b as N,c as E,a as _,d as D}from"./shotFxAgent-BFLkqs8v.js";import{jj as P,jk as B,gM as h,eL as L,eq as A,dJ as U,dH as X}from"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const j=(s,n)=>{const o=h(s);return{anchor:n?(c,d,x)=>n.partPointAt(o,x,c.id,d):void 0,items:s.items,shot:o,at:(c,d)=>{const x=s.items.find(b=>b.id===c.id),k=X(x,o,o.duration?Math.max(0,Math.min(1,d/o.duration)):0);return{position:k.position,rotation:k.rotation}},uid:()=>crypto.randomUUID(),restPose:{...U.Đứng}}},w=(s,n,o)=>({...s,shots:s.shots.map(c=>c.id===s.activeShot?{...c,fxTiming:{...c.fxTiming,[n]:o}}:c)}),v=(s,n)=>{const o=A(s,h(n));return{name:s.name,id:s.id,effect:s.fx.cat??s.fx.preset,preset:s.fx.preset,start_s:o.start,end_s:+(o.start+o.duration).toFixed(2),...s.fx.attach?{attach:s.fx.attach}:{},...s.fx.path?{path:s.fx.path}:{}}};function Y(s,n,o){const c=o.engine();c&&c.sync(o.getStage(),null);const d=o.getStage();if(s==="add_effect"){const t=N(n,j(d,c));if(!t.ok)return{ok:!1,error:t.error};const e=t.item;if(e.fx&&e.fx.preset in P&&o.userText!=null&&!B(o.userText))return{ok:!1,error:"blood effects are only used when the user asks for blood (máu / blood) in their message — leave it out"};o.setStage(i=>w({...i,items:[...i.items,e]},e.id,t.timing));const f=h(o.getStage());return{ok:!0,...v(e,o.getStage()),...t.timing.start+t.timing.duration>f.duration+.01?{note:"the effect runs past the end of the shot; shorten it or extend the shot with set_duration"}:{},hint:"render_preview / preview_motion at the effect time to check it is readable"}}if(s==="add_destruction"){const t=E(n,j(d,c));if(!t.ok)return{ok:!1,error:t.error};const e=t.item;o.setStage(i=>{const a=w({...i,items:[...i.items,e]},e.id,t.timing);return{...a,shots:a.shots.map(p=>p.id===a.activeShot?{...p,objectKeys:{...p.objectKeys,[e.id]:t.keys}}:p)}});const f=d.items.filter(i=>i.fx?.preset===e.fx.preset&&i.fx?.target?.to===e.fx?.target?.to&&i.id!==e.id).map(i=>i.name);return{ok:!0,...v(e,o.getStage()),target:d.items.find(i=>i.id===e.fx?.target?.to)?.name,recipe:e.fx.params.recipe,...t.keys.length?{sphere_path:t.keys.map(i=>({at_s:+(i.time*h(d).duration).toFixed(2),position:i.position}))}:{mode:e.fx.params.mode},...f.length?{combines_with:f}:{},hint:"render_preview after the sweep / collapse time to see the destruction; remove_effect removes it"}}if(s==="edit_destruction"){const t=_(d.items.filter(m=>m.kind==="fx"&&m.fx?.preset===L),String(n.name));if(!t?.fx)return{ok:!1,error:`no Mix FX named '${String(n.name)}' (add_destruction makes one; scene_summary lists effects)`};const e=h(d),f=e.duration||1,i=[];let a=d;const p=m=>m.map((r,u)=>({id:`${t.id}-k${u}-${Math.round(r.time*1e6)}`,time:r.time,position:r.position,rotation:[...t.rotation],scale:[...t.scale]})),T=m=>{a={...a,shots:a.shots.map(r=>r.id===a.activeShot?{...r,objectKeys:{...r.objectKeys,[t.id]:m}}:r)}};if(n.target!=null){const m=d.items.find(r=>r.name.toLowerCase()===String(n.target).toLowerCase()&&r.kind!=="fx");if(!m)return{ok:!1,error:`no object '${String(n.target)}' to break`};a={...a,items:a.items.map(r=>r.id===t.id?{...r,fx:{...r.fx,target:{to:m.id,part:"center"}}}:r)},i.push(`target ${m.name}`)}if(Array.isArray(n.points)){if(n.points.length<2||n.points.length>24)return{ok:!1,error:"points: 2 to 24 path points"};const m=[];for(const r of n.points){const u=Number(r.time_s),l=r.position;if(!Number.isFinite(u)||u<0||u>f+1e-6)return{ok:!1,error:`time_s ${String(r.time_s)} is outside the shot (0–${f} s)`};if(!Array.isArray(l)||l.length!==3||!l.every(y=>Number.isFinite(Number(y))))return{ok:!1,error:"each point needs position [x, y, z]"};m.push({time:Math.min(1,u/f),position:l.map(Number)})}T(p(m.sort((r,u)=>r.time-u.time))),i.push(`path of ${m.length} points`)}else if(n.sweep===!0){const m=a.items.find(F=>F.id===t.id).fx,r=m.target?.to?c?.objectBounds()[m.target.to]:null;if(!r)return{ok:!1,error:"sweep measures the target: it needs the 3D view (a scene open in the composer or the render machine) and a target"};const u=m.params,l=Number(u.radius)*t.scale[0]+Number(u.falloff)+.3,y=(r.min[1]+r.max[1])/2,K=(r.min[2]+r.max[2])/2,S=A(t,e),M=Math.min(1,S.start/f),O=Math.min(1,(S.start+S.duration)/f);T(p([{time:M,position:[r.min[0]-l,y,K]},{time:O,position:[r.max[0]+l,y,K]}])),i.push("sweep through the target")}if(!i.length)return{ok:!1,error:"give points, sweep or target"};const $=a;return o.setStage(()=>$),{ok:!0,name:t.name,changed:i,path_s:(h($).objectKeys?.[t.id]||[]).map(m=>+(m.time*f).toFixed(3))}}if(s==="update_effect"){const t=_(d.items.filter(a=>a.kind==="fx"),String(n.name));if(!t?.fx)return{ok:!1,error:`no effect named '${String(n.name)}'; use remove_effect / update_effect with the name returned by add_effect (see scene_summary effects)`};const e=h(d),f=A(t,e),i=D(t,n,{...j(d,c),timing:f});return i.ok?(o.setStage(a=>w({...a,items:a.items.map(p=>p.id===t.id?{...p,...i.itemPatch,fx:i.fx}:p)},t.id,{start:i.timing.start,duration:i.timing.duration,...i.timing.loop?{loop:!0}:{}})),{ok:!0,...v(o.getStage().items.find(a=>a.id===t.id),o.getStage())}):{ok:!1,error:i.error}}const x=Array.isArray(n.names)?n.names.map(String):n.name!=null?[String(n.name)]:[],k=[],b=[],g=new Set;for(const t of x){const e=_(d.items.filter(f=>f.kind==="fx"),t);e?(g.add(e.id),k.push(e.name)):b.push(t)}for(const t of d.items)t.trackAnchor&&g.has(t.trackAnchor.effect)&&g.add(t.id);return o.setStage(t=>({...t,items:t.items.filter(e=>!g.has(e.id)),shots:t.shots.map(e=>({...e,...e.fxTiming?{fxTiming:Object.fromEntries(Object.entries(e.fxTiming).filter(([f])=>!g.has(f)))}:{},...e.objectKeys?{objectKeys:Object.fromEntries(Object.entries(e.objectKeys).filter(([f])=>!g.has(f)))}:{}}))})),{ok:!b.length,removed:k,missing:b}}export{Y as runFxTool};