clipoox-render 0.4.6 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/package.json +2 -2
  2. package/scripts/render-local.mjs +2656 -1672
  3. package/shared/photocraft/LICENSE.txt +206 -0
  4. package/shared/photocraft/clipoox_photo.js +396 -0
  5. package/shared/photocraft/clipoox_photo_bg.wasm +0 -0
  6. package/web/assets/{FxEmbed-ROS6C_HI.js → FxEmbed-adbxHEBi.js} +1 -1
  7. package/web/assets/ImageStudio-CMxiT1jp.js +3 -0
  8. package/web/assets/ImageStudio-De_DCTrz.css +1 -0
  9. package/web/assets/{MotionEmbed-E2hCysi-.js → MotionEmbed-CDUIyjk0.js} +1 -1
  10. package/web/assets/{PluginStore-CwUSpwPp.js → PluginStore-By_pdOOg.js} +2 -2
  11. package/web/assets/ShotComposer-DcwWZ-eP.css +1 -0
  12. package/web/assets/ShotComposer-XIbJ4nNm.js +287 -0
  13. package/web/assets/{TemplateEmbed-qG1AXdtf.js → TemplateEmbed-a01nKECT.js} +1 -1
  14. package/web/assets/{TimelinePlugins-CB1b6-Cb.js → TimelinePlugins-CqLMVjuh.js} +4 -4
  15. package/web/assets/TimelineShotFx-QmkyCg31.js +2 -0
  16. package/web/assets/{TransitionEmbed-Dym9P7--.js → TransitionEmbed-Cbwlxfl2.js} +1 -1
  17. package/web/assets/{Whiteboard-BdGjJZXW.js → Whiteboard-ChYqIr3v.js} +1 -1
  18. package/web/assets/{aerial-yLD_gDzw.js → aerial-CZeCeacv.js} +2 -2
  19. package/web/assets/{agentTools-B7g6tXTR.js → agentTools-DW2ETnxE.js} +2 -2
  20. package/web/assets/{aiInbetween-6eKDYbYS.js → aiInbetween-De98iM4m.js} +2 -2
  21. package/web/assets/analyzerRun-D5-g-Vxe.js +1 -0
  22. package/web/assets/{analyzerSandbox-N92T6amg.js → analyzerSandbox-E3CdovIk.js} +1 -1
  23. package/web/assets/{api-Dnl2uaKO.js → api-CZoVJ9Fy.js} +87 -87
  24. package/web/assets/auraTrack-ClhHuqlf.js +1 -0
  25. package/web/assets/{breakthrough-DSiuVwEX.js → breakthrough-DTpiUIZd.js} +2 -2
  26. package/web/assets/{cameraPresets-Cfn7qhXK.js → cameraPresets-DD0WmxiI.js} +1 -1
  27. package/web/assets/{cameraTracker-DHdF8Zqx.js → cameraTracker-Df9jWmz6.js} +2 -2
  28. package/web/assets/{captionLayout-cckQ7p-t.js → captionLayout-eiu9QPJu.js} +1 -1
  29. package/web/assets/{clientExport-pkLbOmEF.js → clientExport-BXegTdNc.js} +1 -1
  30. package/web/assets/{clientJobs-CcsLDqFM.js → clientJobs-eB-lNyin.js} +2 -2
  31. package/web/assets/clipoox_photo_bg-BQ0aVNY0.wasm +0 -0
  32. package/web/assets/depthEstimate-CfwX-tXP.js +1 -0
  33. package/web/assets/{directorTools-DMsatulF.js → directorTools-ABbI8m0e.js} +1 -1
  34. package/web/assets/distortFrames-DMnZ8OYh.js +2 -0
  35. package/web/assets/distortGL-DQu0Df2c.js +18 -0
  36. package/web/assets/{domino-DBrinEUu.js → domino-trmDBvfH.js} +1 -1
  37. package/web/assets/{editTools-BNnAvCw-.js → editTools-DEFo9Ahv.js} +1 -1
  38. package/web/assets/{engine-Co-ivzlQ.js → engine-Y-GotDIy.js} +1 -1
  39. package/web/assets/exportGlb-BeLpJKJT.js +2 -0
  40. package/web/assets/{faceTracker-ClR-lS6Y.js → faceTracker-BeSFnLM8.js} +1 -1
  41. package/web/assets/{fightDirector-BlpVAURl.js → fightDirector-Dfz3vu5-.js} +1 -1
  42. package/web/assets/{fightDrama-BK0QidpM.js → fightDrama-CNVn69s0.js} +2 -2
  43. package/web/assets/{focusTool-sVOb2GGS.js → focusTool-Dd2UDkiO.js} +1 -1
  44. package/web/assets/{frameSink-CSRqCnwI.js → frameSink-Rj02YES5.js} +3 -3
  45. package/web/assets/{glTransitionSources.generated-q0H-ZbnZ.js → glTransitionSources.generated-Cs8lVRqs.js} +438 -2
  46. package/web/assets/{gpuCompose-B5bgbHdQ.js → gpuCompose-DkkKH1Ab.js} +1 -1
  47. package/web/assets/gpuExport-DwrXpVGF.js +199 -0
  48. package/web/assets/{handMatte-Dj2taFoC.js → handMatte-B5sUeqKi.js} +1 -1
  49. package/web/assets/{handTracker-c6_rvuwA.js → handTracker-CQV-D7va.js} +2 -2
  50. package/web/assets/i18n-ClNt3LKg.js +3 -0
  51. package/web/assets/{index-Ds_8isyf.js → index-D2u6mD-8.js} +1 -1
  52. package/web/assets/layer-worker-DP0N05Ua.js +5 -0
  53. package/web/assets/library-cb43ZEmy.js +1 -0
  54. package/web/assets/{lottieLayer-Cv8ub9f6.js → lottieLayer-DEw0c3to.js} +4 -4
  55. package/web/assets/main-C_XcvNyC.js +311 -0
  56. package/web/assets/{main-B_MAOvi6.css → main-DlzdW5C4.css} +1 -1
  57. package/web/assets/{mapBake-DtQboFIX.js → mapBake-BUWz0cSx.js} +1 -1
  58. package/web/assets/maskTrack-GYpJyKFw.js +1 -0
  59. package/web/assets/matteFixRun-BCVsuSxf.js +1 -0
  60. package/web/assets/{objectLocate-XuAcemlO.js → objectLocate-CjIlo_u0.js} +1 -1
  61. package/web/assets/{objectSegmenter-D66spD7o.js → objectSegmenter-C4T9qgUL.js} +1 -1
  62. package/web/assets/{objectTrack.worker-BZS6WZ6l.js → objectTrack.worker-BVvsDmR0.js} +1450 -908
  63. package/web/assets/{pathTracer-DykgPkkh.js → pathTracer-DgL1_83l.js} +2 -2
  64. package/web/assets/{pendingMatte-BWBIWajI.js → pendingMatte-DPTe6xoZ.js} +2 -2
  65. package/web/assets/peopleMatte-C1hruEM6.js +1 -0
  66. package/web/assets/{personAi-EhBknW6X.js → personAi-Cjg9KKeH.js} +2 -2
  67. package/web/assets/{personHq-Ca351o06.js → personHq-CBP8v_cw.js} +2 -2
  68. package/web/assets/photo.worker-DK_ulTzR.js +1 -0
  69. package/web/assets/photoRun-lZ2BdSEk.js +2 -0
  70. package/web/assets/photoTools-DmUh69Qk.js +1 -0
  71. package/web/assets/plateCamera-DLqlXhMp.js +1 -0
  72. package/web/assets/{plateCameraMatch-GPZl1fQQ.js → plateCameraMatch-4VUlUMi-.js} +2 -2
  73. package/web/assets/{plateFollow-CJUilsNV.js → plateFollow-D2rjnmZA.js} +2 -2
  74. package/web/assets/plateMatte-0tTG7oeO.js +2 -0
  75. package/web/assets/{pluginAutomation-DAPHWZPN.js → pluginAutomation-ClFdpcCR.js} +1 -1
  76. package/web/assets/popTools-B38V4wub.js +1 -0
  77. package/web/assets/{poseTracker-CzEKvJph.js → poseTracker-qtuytI-L.js} +1 -1
  78. package/web/assets/{productTools-ce-zyZO0.js → productTools-DlC5vWjx.js} +2 -2
  79. package/web/assets/remote-CpkPQOQH.js +989 -0
  80. package/web/assets/{rigTrack-DMyqb0pb.js → rigTrack-BbKqZGs7.js} +1 -1
  81. package/web/assets/{rotoMaskStore-pE1AIt3I.js → rotoMaskStore-BZBJLcCp.js} +1 -1
  82. package/web/assets/{rotoMatte-7b7Ow64f.js → rotoMatte-BI-vjjrv.js} +1 -1
  83. package/web/assets/rotoscope-DuNcCxQy.js +1 -0
  84. package/web/assets/{sceneTrack-DlAH5s74.js → sceneTrack-CO4fTjft.js} +1 -1
  85. package/web/assets/{sceneTrack-CA21MCOP.js → sceneTrack-_n6WKKQv.js} +1 -1
  86. package/web/assets/{sceneTrack.worker-COlhlHRe.js → sceneTrack.worker-f2d-WOzw.js} +1496 -954
  87. package/web/assets/{shot-worker-DL1ZoIym.js → shot-worker-BSmfIXHO.js} +1 -1
  88. package/web/assets/{shotFxAgent-DqngnGFb.js → shotFxAgent-L2GG88W3.js} +1 -1
  89. package/web/assets/{skin-xFScwS3T.js → skin-CirUiqcr.js} +1 -1
  90. package/web/assets/{spark.module-DjaIF6J1.js → spark.module-3Q8DniuL.js} +1 -1
  91. package/web/assets/{spellDuel-BYNtnE8f.js → spellDuel-2CDLbiLQ.js} +2 -2
  92. package/web/assets/{store-CpqHUcA2.js → store-D3Y663py.js} +1 -1
  93. package/web/assets/{surfaceLight-C7YI9SV8.js → surfaceLight--HQj7xhO.js} +1 -1
  94. package/web/assets/{surfacePin-CzpUj1Cw.js → surfacePin-BCmgw-40.js} +2 -2
  95. package/web/assets/{textAnimators-B9vO_hbP.js → textAnimators-C4eMnVRD.js} +1 -1
  96. package/web/assets/{thumb-BTFsBS1u.js → thumb-M9B_goj-.js} +1 -1
  97. package/web/assets/{timeline3d-DrFaMPPB.js → timeline3d-BcW68fQr.js} +2 -2
  98. package/web/assets/{timeline3dExport-Uo0S0CR0.js → timeline3dExport-DgnorHLm.js} +1 -1
  99. package/web/assets/timelineComp-Ciu9JCWJ.js +1 -0
  100. package/web/assets/timelineOps-f1WsVbgS.js +526 -0
  101. package/web/assets/{timelineProps-0v-s69pw.js → timelineProps-CE1R11Hx.js} +1 -1
  102. package/web/assets/{timelineText-DurRhyuh.js → timelineText-Cppd4KB7.js} +1 -1
  103. package/web/assets/{titleArt-CnC0A7x7.js → titleArt-D0YI5xT2.js} +3 -3
  104. package/web/assets/{titleFrameBudget-DsM0V482.js → titleFrameBudget-h4nOQ5u9.js} +1717 -1175
  105. package/web/assets/titleFrames-DnCzi_AI.js +1 -0
  106. package/web/assets/{tool-D1FpErrX.js → tool-tp6gat1J.js} +1 -1
  107. package/web/assets/{tools-DIvrRu-5.js → tools-C07G9KUM.js} +1 -1
  108. package/web/assets/{toonTools-D9MNdRty.js → toonTools-Cazx2CL7.js} +2 -2
  109. package/web/assets/{trackAnchor-XvUuvkWP.js → trackAnchor-DoqFDcJB.js} +1 -1
  110. package/web/assets/{userFonts-Djka6RJX.js → userFonts-BlVEJfDk.js} +1 -1
  111. package/web/assets/{vfxAlpha-B-JzzRI1.js → vfxAlpha-Bp6VgIGN.js} +1 -1
  112. package/web/assets/vfxBackground-BFq44Srn.js +2 -0
  113. package/web/assets/{videoExport-NN-QijHd.js → videoExport-Cz02XKtX.js} +1 -1
  114. package/web/assets/{views-RQBs4zva.js → views-CNF3Afse.js} +1 -1
  115. package/web/assets/{weaponDuel-DKAEYJjO.js → weaponDuel-ChqBQo_b.js} +1 -1
  116. package/web/assets/{windowFrames-DhhJLIs-.js → windowFrames-dBMXwGek.js} +1 -1
  117. package/web/layer-worker.html +3 -3
  118. package/web/shot-worker.html +24 -24
  119. package/web/assets/ShotComposer-DLxWpdYH.js +0 -287
  120. package/web/assets/ShotComposer-deLi4grZ.css +0 -1
  121. package/web/assets/TimelineShotFx-CyHTgJHj.js +0 -2
  122. package/web/assets/analyzerRun-Cr-_79RH.js +0 -1
  123. package/web/assets/auraTrack-C8eAEIWQ.js +0 -1
  124. package/web/assets/depthEstimate-Cav4MmQ1.js +0 -1
  125. package/web/assets/distortFrames-D_v-aSVO.js +0 -2
  126. package/web/assets/distortGL-vhnBRB59.js +0 -12
  127. package/web/assets/exportGlb-D3PrWUvi.js +0 -2
  128. package/web/assets/gpuExport-oA2mUsdm.js +0 -198
  129. package/web/assets/i18n-C9zFX25m.js +0 -3
  130. package/web/assets/layer-worker-ClVZG6ZW.js +0 -5
  131. package/web/assets/library-BK0QVG4O.js +0 -1
  132. package/web/assets/main-CwrkBJ63.js +0 -309
  133. package/web/assets/maskTrack-D4QZfMWc.js +0 -1
  134. package/web/assets/matteFixRun-CytaeRzS.js +0 -1
  135. package/web/assets/plateCamera-BcdXD1uI.js +0 -1
  136. package/web/assets/plateMatte-CoEoVjxZ.js +0 -2
  137. package/web/assets/remote-8XzEAnAJ.js +0 -974
  138. package/web/assets/rotoscope-BUqNTKLd.js +0 -1
  139. package/web/assets/timelineComp-i-zdaoB2.js +0 -1
  140. package/web/assets/timelineOps-DSSaDsU2.js +0 -525
  141. package/web/assets/titleFrames-C8kvflgT.js +0 -1
  142. package/web/assets/vfxBackground-b053ziDK.js +0 -2
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Ds_8isyf.js","assets/three.module-Bx43vjkH.js","assets/remote-8XzEAnAJ.js","assets/index-CKtv7gGE.js","assets/i18n-C9zFX25m.js","assets/api-Dnl2uaKO.js","assets/titleFrameBudget-DsM0V482.js","assets/gltfLoader-U0Eebg7v.js","assets/store-CpqHUcA2.js","assets/rotoMaskStore-pE1AIt3I.js","assets/sceneTrack-DlAH5s74.js","assets/timelineOps-DSSaDsU2.js","assets/cameraTracker-DHdF8Zqx.js","assets/textAnimators-B9vO_hbP.js","assets/timelineComp-i-zdaoB2.js","assets/rigTrack-DMyqb0pb.js","assets/clientJobs-CuuUyhEy.js"])))=>i.map(i=>d[i]);
2
- import{_ as L}from"./titleFrameBudget-DsM0V482.js";import{WebGLRenderer as q,ACESFilmicToneMapping as A,SRGBColorSpace as D,Color as c,Vector3 as P,EquirectangularReflectionMapping as I}from"./three.module-Bx43vjkH.js";class O{constructor(e){this.canvas=e,this.renderer=new q({canvas:e,antialias:!0,preserveDrawingBuffer:!0,powerPreference:"high-performance"}),this.renderer.toneMapping=A,this.renderer.outputColorSpace=D}renderer;tracer=null;envTex=null;raf=0;running=!1;disposed=!1;targetSamples=64;async start(e,a={}){if(this.stop(),this.disposed)return;const u=Math.max(8,Math.min(256,a.targetSamples??64)),T=Math.max(2,Math.min(8,a.bounces??4));this.targetSamples=u;const f=this.canvas.parentElement?.getBoundingClientRect(),w=Math.max(320,Math.round(f?.width||this.canvas.clientWidth||960)),M=Math.max(180,Math.round(f?.height||this.canvas.clientHeight||540)),E=Math.min(window.devicePixelRatio||1,1.5);this.renderer.setPixelRatio(E),this.renderer.setSize(w,M,!1),this.renderer.toneMappingExposure=e.look.exposure;try{const{WebGLPathTracer:h,ProceduralEquirectTexture:R}=await L(async()=>{const{WebGLPathTracer:o,ProceduralEquirectTexture:b}=await import("./index-Ds_8isyf.js");return{WebGLPathTracer:o,ProceduralEquirectTexture:b}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]));if(this.disposed)return;this.tracer||(this.tracer=new h(this.renderer));const r=this.tracer;r.bounces=T,r.transmissiveBounces=4,r.filterGlossyFactor=.5,r.multipleImportanceSampling=!0,r.dynamicLowRes=!1,r.renderScale=1,r.tiles.set(2,2),this.envTex?.dispose();const s=new R(512,256),_=new c(e.look.sky.zenith),v=new c(e.look.sky.horizon),C=new c(e.look.sky.ground),i=new c(e.look.sky.glow),z=new P(...e.sunDir).normalize(),d=Math.max(.25,e.look.sky.gain*Math.max(.45,e.look.envIntensity)),x=e.look.sky.glowPower,k=e.look.sky.disk,t=new c,m=new P;s.generationCallback=(o,b,U,G)=>{m.setFromSpherical(o).normalize();const g=m.y;g>=0?t.copy(v).lerp(_,Math.pow(Math.min(1,g),.55)):t.copy(v).multiplyScalar(.78).lerp(C,Math.min(1,-g*4.5));const p=Math.max(0,m.dot(z));if(x>0){const n=(Math.pow(p,6)*.16+Math.pow(p,48)*.65)*x;t.r+=i.r*n,t.g+=i.g*n,t.b+=i.b*n}if(k>0&&p>.9985){const n=(p-.9985)/.0015*Math.min(k,8);t.r+=i.r*n,t.g+=i.g*n,t.b+=i.b*n}G.setRGB(t.r*d,t.g*d,t.b*d)},s.update(),s.mapping=I,this.envTex=s;const S=a.view==="viewport"?e.camera:e.shotCamera;S.updateMatrixWorld(!0);const l=S.clone();l.aspect=w/M,l.updateProjectionMatrix(),l.updateMatrixWorld(!0);const B=e.prepareForTrace(),F=e.scene.environment,W=e.scene.background;e.scene.environment=s,e.scene.background=s,e.scene.updateMatrixWorld(!0);try{r.setScene(e.scene,l)}finally{e.scene.environment=F,e.scene.background=W,B()}if(this.disposed)return;this.running=!0,a.onProgress?.(0,u);const y=()=>{if(!this.running||this.disposed||!this.tracer)return;this.tracer.renderSample();const o=Math.floor(this.tracer.samples);a.onProgress?.(Math.min(o,this.targetSamples),this.targetSamples),o<this.targetSamples?this.raf=requestAnimationFrame(y):this.running=!1};this.raf=requestAnimationFrame(y)}catch(h){this.running=!1,a.onError?.(h instanceof Error?h.message:String(h))}}captureDataUrl(){return this.canvas.toDataURL("image/png")}stop(){this.running=!1,this.raf&&(cancelAnimationFrame(this.raf),this.raf=0)}dispose(){this.stop(),this.disposed=!0,this.tracer?.dispose(),this.tracer=null,this.envTex?.dispose(),this.envTex=null,this.renderer.dispose()}}export{O as ShotPathTracer};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D2u6mD-8.js","assets/three.module-Bx43vjkH.js","assets/remote-CpkPQOQH.js","assets/index-CKtv7gGE.js","assets/i18n-ClNt3LKg.js","assets/api-CZoVJ9Fy.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/gltfLoader-U0Eebg7v.js","assets/store-D3Y663py.js","assets/rotoMaskStore-BZBJLcCp.js","assets/sceneTrack-CO4fTjft.js","assets/timelineOps-f1WsVbgS.js","assets/cameraTracker-Df9jWmz6.js","assets/textAnimators-C4eMnVRD.js","assets/timelineComp-Ciu9JCWJ.js","assets/rigTrack-BbKqZGs7.js","assets/clientJobs-CuuUyhEy.js"])))=>i.map(i=>d[i]);
2
+ import{_ as L}from"./titleFrameBudget-h4nOQ5u9.js";import{WebGLRenderer as q,ACESFilmicToneMapping as A,SRGBColorSpace as D,Color as c,Vector3 as P,EquirectangularReflectionMapping as I}from"./three.module-Bx43vjkH.js";class O{constructor(e){this.canvas=e,this.renderer=new q({canvas:e,antialias:!0,preserveDrawingBuffer:!0,powerPreference:"high-performance"}),this.renderer.toneMapping=A,this.renderer.outputColorSpace=D}renderer;tracer=null;envTex=null;raf=0;running=!1;disposed=!1;targetSamples=64;async start(e,a={}){if(this.stop(),this.disposed)return;const u=Math.max(8,Math.min(256,a.targetSamples??64)),T=Math.max(2,Math.min(8,a.bounces??4));this.targetSamples=u;const f=this.canvas.parentElement?.getBoundingClientRect(),w=Math.max(320,Math.round(f?.width||this.canvas.clientWidth||960)),M=Math.max(180,Math.round(f?.height||this.canvas.clientHeight||540)),E=Math.min(window.devicePixelRatio||1,1.5);this.renderer.setPixelRatio(E),this.renderer.setSize(w,M,!1),this.renderer.toneMappingExposure=e.look.exposure;try{const{WebGLPathTracer:h,ProceduralEquirectTexture:R}=await L(async()=>{const{WebGLPathTracer:o,ProceduralEquirectTexture:b}=await import("./index-D2u6mD-8.js");return{WebGLPathTracer:o,ProceduralEquirectTexture:b}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]));if(this.disposed)return;this.tracer||(this.tracer=new h(this.renderer));const r=this.tracer;r.bounces=T,r.transmissiveBounces=4,r.filterGlossyFactor=.5,r.multipleImportanceSampling=!0,r.dynamicLowRes=!1,r.renderScale=1,r.tiles.set(2,2),this.envTex?.dispose();const s=new R(512,256),_=new c(e.look.sky.zenith),v=new c(e.look.sky.horizon),C=new c(e.look.sky.ground),i=new c(e.look.sky.glow),z=new P(...e.sunDir).normalize(),d=Math.max(.25,e.look.sky.gain*Math.max(.45,e.look.envIntensity)),x=e.look.sky.glowPower,k=e.look.sky.disk,t=new c,m=new P;s.generationCallback=(o,b,U,G)=>{m.setFromSpherical(o).normalize();const g=m.y;g>=0?t.copy(v).lerp(_,Math.pow(Math.min(1,g),.55)):t.copy(v).multiplyScalar(.78).lerp(C,Math.min(1,-g*4.5));const p=Math.max(0,m.dot(z));if(x>0){const n=(Math.pow(p,6)*.16+Math.pow(p,48)*.65)*x;t.r+=i.r*n,t.g+=i.g*n,t.b+=i.b*n}if(k>0&&p>.9985){const n=(p-.9985)/.0015*Math.min(k,8);t.r+=i.r*n,t.g+=i.g*n,t.b+=i.b*n}G.setRGB(t.r*d,t.g*d,t.b*d)},s.update(),s.mapping=I,this.envTex=s;const S=a.view==="viewport"?e.camera:e.shotCamera;S.updateMatrixWorld(!0);const l=S.clone();l.aspect=w/M,l.updateProjectionMatrix(),l.updateMatrixWorld(!0);const B=e.prepareForTrace(),F=e.scene.environment,W=e.scene.background;e.scene.environment=s,e.scene.background=s,e.scene.updateMatrixWorld(!0);try{r.setScene(e.scene,l)}finally{e.scene.environment=F,e.scene.background=W,B()}if(this.disposed)return;this.running=!0,a.onProgress?.(0,u);const y=()=>{if(!this.running||this.disposed||!this.tracer)return;this.tracer.renderSample();const o=Math.floor(this.tracer.samples);a.onProgress?.(Math.min(o,this.targetSamples),this.targetSamples),o<this.targetSamples?this.raf=requestAnimationFrame(y):this.running=!1};this.raf=requestAnimationFrame(y)}catch(h){this.running=!1,a.onError?.(h instanceof Error?h.message:String(h))}}captureDataUrl(){return this.canvas.toDataURL("image/png")}stop(){this.running=!1,this.raf&&(cancelAnimationFrame(this.raf),this.raf=0)}dispose(){this.stop(),this.disposed=!0,this.tracer?.dispose(),this.tracer=null,this.envTex?.dispose(),this.envTex=null,this.renderer.dispose()}}export{O as ShotPathTracer};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/objectSegmenter-D66spD7o.js","assets/titleFrameBudget-DsM0V482.js","assets/personHq-Ca351o06.js","assets/matteQuality-9X-jgJrH.js","assets/api-Dnl2uaKO.js","assets/i18n-C9zFX25m.js","assets/index-CKtv7gGE.js","assets/cutoutClean-CLYYAuXg.js"])))=>i.map(i=>d[i]);
2
- import{di as O,dj as C,_ as B,de as v,kx as H,hl as D,b_ as M,ky as j}from"./titleFrameBudget-DsM0V482.js";import{t as T}from"./timelineOps-DSSaDsU2.js";import{s as R,d as W,w as z,p as F}from"./personHq-Ca351o06.js";import{u as g}from"./store-CpqHUcA2.js";import{t as m}from"./i18n-C9zFX25m.js";import{al as _}from"./api-Dnl2uaKO.js";import"./sceneTrack-DlAH5s74.js";import"./cameraTracker-DHdF8Zqx.js";import"./textAnimators-B9vO_hbP.js";import"./timelineComp-i-zdaoB2.js";import"./rigTrack-DMyqb0pb.js";import"./clientJobs-CuuUyhEy.js";import"./matteQuality-9X-jgJrH.js";import"./index-CKtv7gGE.js";const $=e=>document.querySelector(`video[data-clip-media="${e.id}"]`)?.currentSrc||e.url;function A(e,c=!1,t=!1){let d=null,s=-1;const l=(r,n="info")=>{const a=g.getState();d!==null&&a.dismissToast(d),a.toast(r,n),d=g.getState().toasts.at(-1)?.id??null};return l(c?m("Đang chạy Pro Cut cho “{0}” trên máy chủ… (khoảng 2 phút cho 1 phút video)",[e]):t?m("Đang tách vật thể AI cho “{0}”… (chạy trên máy, không tốn credit)",[e]):m("Đang tách người AI cho “{0}”… (chạy trên máy, không tốn credit)",[e])),{progress:r=>{const n=Math.floor(r.done/r.total*4)*25;n>s&&n<100&&n>0&&(s=n,l(c?m("Đang giữ lại người trong kết quả Pro Cut “{0}”… {1}%",[e,n]):t?m("Đang tách vật thể AI cho “{0}”… {1}%",[e,n]):m("Đang tách người AI cho “{0}”… {1}%",[e,n])))},done:(r,n="ok")=>l(r,n)}}const E=e=>{const c=document.querySelector(`video[data-clip-media="${e.id}"]`);return{duration:e.duration,sourceDuration:e.sourceDuration,width:c?.videoWidth||void 0,height:c?.videoHeight||void 0}};async function L(e,c,t){if(e.kind!=="video")throw Error(m("Chỉ tách người được trên clip video"));const d=await R({clip:e,url:$(e),signal:t,onProgress:c}),s=O(g.getState().clips.filter(l=>l.id!==e.id));if(d.data&&s+d.data.length>C)throw Error(m("Timeline đã chứa quá nhiều mặt nạ người AI (giới hạn lưu của dự án). Hãy xoá bớt mặt nạ ở clip khác hoặc cắt ngắn clip."));return d}async function N(e,c,t,d){const{segmentObject:s}=await B(async()=>{const{segmentObject:n}=await import("./objectSegmenter-D66spD7o.js");return{segmentObject:n}},__vite__mapDeps([0,1,2,3,4,5,6,7])),l=await s({clip:e,url:$(e),pts:c.pts.map(([n,a])=>({x:n,y:a})),at:c.at,signal:d,onProgress:t}),r=O(g.getState().clips.filter(n=>n.id!==e.id));if(l.data&&r+l.data.length>C)throw Error(m("Timeline đã chứa quá nhiều mặt nạ người AI (giới hạn lưu của dự án). Hãy xoá bớt mặt nạ ở clip khác hoặc cắt ngắn clip."));return l}const I=(e,c)=>e.map(t=>{if(t.id!==c||!t.personPending)return t;const d={...t};return delete d.personPending,d}),k=new Set,rt=e=>k.has(e);function at(e,c){for(const t of e)t.personPending&&t.kind==="video"&&!k.has(t.id)&&(k.add(t.id),q(t.id,c).finally(()=>k.delete(t.id)))}async function ct({ids:e,checkpoint:c=()=>{}}={}){const t=g.getState().clips.filter(s=>s.personPending&&s.kind==="video"&&(!e||e.includes(s.id))).map(s=>s.id),d=[];for(const s of t){if(k.has(s))continue;k.add(s);const l=new Set(g.getState().clips.filter(r=>r.person?.src==="object").map(r=>r.id));try{await q(s,c);const r=g.getState().clips.find(a=>a.id===s),n=!r?.personPending&&(!!r?.person||g.getState().clips.some(a=>a.person?.src==="object"&&!l.has(a.id)));d.push({clipId:s,ok:n,message:n?"matte completed":"matte dropped or failed"})}catch(r){d.push({clipId:s,ok:!1,message:String(r?.message||r)})}finally{k.delete(s)}}return d}async function q(e,c){let t=g.getState().clips.find(i=>i.id===e);if(!t?.personPending||g.getState().timelineTracks[t.track]?.locked||v(t.personPending).length&&(await V(t,c),t=g.getState().clips.find(i=>i.id===e),!t?.personPending||!H(t.personPending)))return;const s=t.personPending.job,l=A(t.label,!!s);let r;try{if(s){const i=await W(t,await z(s),{onProgress:l.progress}),o=t.person&&t.person.src!=="object"?t.person.pick:void 0;r=o?{...i,pick:o}:i}else r=t.person&&t.person.src!=="object"?t.person:await L(t,l.progress)}catch(i){_(s?"person-matte-hq":"person-matte",i.message,{op:"pending",...E(t)}),l.done(s?m("Chưa chạy Pro Cut được cho “{0}”: {1}",[t.label,i.message]):m("Chưa tách được người cho “{0}”: {1} — mở Roto → Tách người rồi “Đặt ra sau người”.",[t.label,i.message]),"error"),g.getState().clips.find(o=>o.id===e)?.personPending&&g.setState(o=>({clips:I(o.clips,e)}));return}const n=g.getState(),a=n.clips.find(i=>i.id===e);if(!a||!a.personPending&&!s)return;const f=D(n.clips,new Map([[e,r]])),u=[...(a.personPending?.behind??[]).filter(i=>f.some(o=>o.id===i)).map(i=>({op:"placeBehindPerson",clipId:i,sourceClipId:e})),...(a.personPending?.then??[]).map(i=>({...i,clipId:e}))],P=M({...n.timelineFormat,resolution:"720p"}),b=f.find(i=>i.id===e);for(let i=0;i<u.length;i++){const o=u[i];if(o.op!=="clonePerson"||o.feet!=null||!b)continue;const h=await F(b,Math.max(0,(o.start??b.start)-b.start),P.width,P.height).catch(()=>null);h&&(u[i]={...o,feet:h.feet,...o.horizon==null?{horizon:h.horizon}:{}})}const p=u.length?T(f,u,[],n.timelineTracks,n.timelineCamera,{noPendingMatte:!0,W:P.width,H:P.height}):null;g.setState({clips:I(n.clips,e)}),c(),g.setState({clips:p?p.clips:f,...p?{timelineTracks:p.tracks}:{}});const w=p?p.applied.filter(i=>i.startsWith("placeBehindPerson")).length:0,y=p?p.applied.filter(i=>/^(personEcho|clonePerson|personElectric|speedBolt)/.test(i)).length:0;l.done(p?.errors.length?m("Đã tách người cho “{0}”; {1} lớp chưa đặt ra sau người được: {2}",[a.label,p.errors.length,p.errors.join(" · ")]):y&&!w?m("Đã tách người cho “{0}” và tạo {1} hiệu ứng (vệt bóng / nhân bản).",[a.label,y]):u.length?m("Đã tách người cho “{0}” và đặt {1} lớp ra sau người.",[a.label,w]):s?m("Đã Pro Cut cho “{0}” ({1} khung).",[a.label,r.n]):m("Đã tách người cho “{0}” ({1} khung).",[a.label,r.n]),p?.errors.length?"error":"ok")}async function V(e,c){const t=e.id,d=v(e.personPending),s=A(e.label,!1,!0),l=new Map,r=[];for(const o of d)try{l.set(`${t}|${o.id}`,await N(e,{pts:o.pts,at:o.at},s.progress))}catch(h){r.push(`${o.name}: ${h.message}`),_("object-matte",h.message,{op:"pending",...E(e)})}const n=g.getState(),a=n.clips.find(o=>o.id===t);if(!a?.personPending)return;const f=v(a.personPending);let u=n.clips;for(const o of f)l.has(`${t}|${o.id}`)||(u=u.map(h=>h.id===t?j(h,o.id):h));const P=f.filter(o=>l.has(`${t}|${o.id}`)).flatMap(o=>{const h=o.behind.filter(S=>u.some(x=>x.id===S));return h.length?h.map(S=>({op:"placeBehindObject",clipId:S,sourceClipId:t,objectId:o.id})):[{op:"cutOutObject",clipId:t,objectId:o.id}]}),b=M({...n.timelineFormat,resolution:"720p"}),p=P.length?T(u,P,[],n.timelineTracks,n.timelineCamera,{noPendingMatte:!0,objectMattes:l,W:b.width,H:b.height}):null;let w=u;for(const o of f)w=w.map(h=>h.id===t?j(h,o.id):h);g.setState({clips:w}),p&&(c(),g.setState({clips:p.clips,timelineTracks:p.tracks}));const y=p?p.clips.filter(o=>!n.clips.some(h=>h.id===o.id)).length:0,i=[...r,...p?.errors??[]];s.done(i.length?m("Đã tách {0} vật thể của “{1}”; chưa tách được: {2}",[y,a.label,i.join(" · ")]):m("Đã tách {0} vật thể của “{1}”, mỗi vật thể một layer riêng.",[y,a.label]),i.length?"error":"ok")}export{E as clipDetail,rt as matteRunning,A as progressToast,at as resumePendingMattes,ct as runPendingMattes,L as segmentClipMatte,N as segmentClipObject};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/objectSegmenter-C4T9qgUL.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/personHq-CBP8v_cw.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/i18n-ClNt3LKg.js","assets/index-CKtv7gGE.js","assets/cutoutClean-CLYYAuXg.js"])))=>i.map(i=>d[i]);
2
+ import{dl as O,dm as C,_ as B,dh as y,kE as H,ho as D,b_ as M,kF as j}from"./titleFrameBudget-h4nOQ5u9.js";import{x as T}from"./timelineOps-f1WsVbgS.js";import{s as F,d as R,w as W,p as z}from"./personHq-CBP8v_cw.js";import{u as g}from"./store-D3Y663py.js";import{t as m}from"./i18n-ClNt3LKg.js";import{am as _}from"./api-CZoVJ9Fy.js";import"./sceneTrack-CO4fTjft.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./rigTrack-BbKqZGs7.js";import"./clientJobs-CuuUyhEy.js";import"./matteQuality-9X-jgJrH.js";import"./index-CKtv7gGE.js";const $=e=>document.querySelector(`video[data-clip-media="${e.id}"]`)?.currentSrc||e.url;function A(e,c=!1,t=!1){let d=null,s=-1;const l=(r,n="info")=>{const a=g.getState();d!==null&&a.dismissToast(d),a.toast(r,n),d=g.getState().toasts.at(-1)?.id??null};return l(c?m("Đang chạy Pro Cut cho “{0}” trên máy chủ… (khoảng 2 phút cho 1 phút video)",[e]):t?m("Đang tách vật thể AI cho “{0}”… (chạy trên máy, không tốn credit)",[e]):m("Đang tách người AI cho “{0}”… (chạy trên máy, không tốn credit)",[e])),{progress:r=>{const n=Math.floor(r.done/r.total*4)*25;n>s&&n<100&&n>0&&(s=n,l(c?m("Đang giữ lại người trong kết quả Pro Cut “{0}”… {1}%",[e,n]):t?m("Đang tách vật thể AI cho “{0}”… {1}%",[e,n]):m("Đang tách người AI cho “{0}”… {1}%",[e,n])))},done:(r,n="ok")=>l(r,n)}}const E=e=>{const c=document.querySelector(`video[data-clip-media="${e.id}"]`);return{duration:e.duration,sourceDuration:e.sourceDuration,width:c?.videoWidth||void 0,height:c?.videoHeight||void 0}};async function L(e,c,t){if(e.kind!=="video")throw Error(m("Chỉ tách người được trên clip video"));const d=await F({clip:e,url:$(e),signal:t,onProgress:c}),s=O(g.getState().clips.filter(l=>l.id!==e.id));if(d.data&&s+d.data.length>C)throw Error(m("Timeline đã chứa quá nhiều mặt nạ người AI (giới hạn lưu của dự án). Hãy xoá bớt mặt nạ ở clip khác hoặc cắt ngắn clip."));return d}async function N(e,c,t,d){const{segmentObject:s}=await B(async()=>{const{segmentObject:n}=await import("./objectSegmenter-C4T9qgUL.js");return{segmentObject:n}},__vite__mapDeps([0,1,2,3,4,5,6,7])),l=await s({clip:e,url:$(e),pts:c.pts.map(([n,a])=>({x:n,y:a})),at:c.at,signal:d,onProgress:t}),r=O(g.getState().clips.filter(n=>n.id!==e.id));if(l.data&&r+l.data.length>C)throw Error(m("Timeline đã chứa quá nhiều mặt nạ người AI (giới hạn lưu của dự án). Hãy xoá bớt mặt nạ ở clip khác hoặc cắt ngắn clip."));return l}const I=(e,c)=>e.map(t=>{if(t.id!==c||!t.personPending)return t;const d={...t};return delete d.personPending,d}),k=new Set,rt=e=>k.has(e);function at(e,c){for(const t of e)t.personPending&&t.kind==="video"&&!k.has(t.id)&&(k.add(t.id),q(t.id,c).finally(()=>k.delete(t.id)))}async function ct({ids:e,checkpoint:c=()=>{}}={}){const t=g.getState().clips.filter(s=>s.personPending&&s.kind==="video"&&(!e||e.includes(s.id))).map(s=>s.id),d=[];for(const s of t){if(k.has(s))continue;k.add(s);const l=new Set(g.getState().clips.filter(r=>r.person?.src==="object").map(r=>r.id));try{await q(s,c);const r=g.getState().clips.find(a=>a.id===s),n=!r?.personPending&&(!!r?.person||g.getState().clips.some(a=>a.person?.src==="object"&&!l.has(a.id)));d.push({clipId:s,ok:n,message:n?"matte completed":"matte dropped or failed"})}catch(r){d.push({clipId:s,ok:!1,message:String(r?.message||r)})}finally{k.delete(s)}}return d}async function q(e,c){let t=g.getState().clips.find(i=>i.id===e);if(!t?.personPending||g.getState().timelineTracks[t.track]?.locked||y(t.personPending).length&&(await V(t,c),t=g.getState().clips.find(i=>i.id===e),!t?.personPending||!H(t.personPending)))return;const s=t.personPending.job,l=A(t.label,!!s);let r;try{if(s){const i=await R(t,await W(s),{onProgress:l.progress}),o=t.person&&t.person.src!=="object"?t.person.pick:void 0;r=o?{...i,pick:o}:i}else r=t.person&&t.person.src!=="object"?t.person:await L(t,l.progress)}catch(i){_(s?"person-matte-hq":"person-matte",i.message,{op:"pending",...E(t)}),l.done(s?m("Chưa chạy Pro Cut được cho “{0}”: {1}",[t.label,i.message]):m("Chưa tách được người cho “{0}”: {1} — mở Roto → Tách người rồi “Đặt ra sau người”.",[t.label,i.message]),"error"),g.getState().clips.find(o=>o.id===e)?.personPending&&g.setState(o=>({clips:I(o.clips,e)}));return}const n=g.getState(),a=n.clips.find(i=>i.id===e);if(!a||!a.personPending&&!s)return;const f=D(n.clips,new Map([[e,r]])),u=[...(a.personPending?.behind??[]).filter(i=>f.some(o=>o.id===i)).map(i=>({op:"placeBehindPerson",clipId:i,sourceClipId:e})),...(a.personPending?.then??[]).map(i=>({...i,clipId:e}))],P=M({...n.timelineFormat,resolution:"720p"}),b=f.find(i=>i.id===e);for(let i=0;i<u.length;i++){const o=u[i];if(o.op!=="clonePerson"||o.feet!=null||!b)continue;const h=await z(b,Math.max(0,(o.start??b.start)-b.start),P.width,P.height).catch(()=>null);h&&(u[i]={...o,feet:h.feet,...o.horizon==null?{horizon:h.horizon}:{}})}const p=u.length?T(f,u,[],n.timelineTracks,n.timelineCamera,{noPendingMatte:!0,W:P.width,H:P.height}):null;g.setState({clips:I(n.clips,e)}),c(),g.setState({clips:p?p.clips:f,...p?{timelineTracks:p.tracks}:{}});const w=p?p.applied.filter(i=>i.startsWith("placeBehindPerson")).length:0,S=p?p.applied.filter(i=>/^(personEcho|clonePerson|personElectric|speedBolt)/.test(i)).length:0;l.done(p?.errors.length?m("Đã tách người cho “{0}”; {1} lớp chưa đặt ra sau người được: {2}",[a.label,p.errors.length,p.errors.join(" · ")]):S&&!w?m("Đã tách người cho “{0}” và tạo {1} hiệu ứng (vệt bóng / nhân bản).",[a.label,S]):u.length?m("Đã tách người cho “{0}” và đặt {1} lớp ra sau người.",[a.label,w]):s?m("Đã Pro Cut cho “{0}” ({1} khung).",[a.label,r.n]):m("Đã tách người cho “{0}” ({1} khung).",[a.label,r.n]),p?.errors.length?"error":"ok")}async function V(e,c){const t=e.id,d=y(e.personPending),s=A(e.label,!1,!0),l=new Map,r=[];for(const o of d)try{l.set(`${t}|${o.id}`,await N(e,{pts:o.pts,at:o.at},s.progress))}catch(h){r.push(`${o.name}: ${h.message}`),_("object-matte",h.message,{op:"pending",...E(e)})}const n=g.getState(),a=n.clips.find(o=>o.id===t);if(!a?.personPending)return;const f=y(a.personPending);let u=n.clips;for(const o of f)l.has(`${t}|${o.id}`)||(u=u.map(h=>h.id===t?j(h,o.id):h));const P=f.filter(o=>l.has(`${t}|${o.id}`)).flatMap(o=>{const h=o.behind.filter(v=>u.some(x=>x.id===v));return h.length?h.map(v=>({op:"placeBehindObject",clipId:v,sourceClipId:t,objectId:o.id})):[{op:"cutOutObject",clipId:t,objectId:o.id}]}),b=M({...n.timelineFormat,resolution:"720p"}),p=P.length?T(u,P,[],n.timelineTracks,n.timelineCamera,{noPendingMatte:!0,objectMattes:l,W:b.width,H:b.height}):null;let w=u;for(const o of f)w=w.map(h=>h.id===t?j(h,o.id):h);g.setState({clips:w}),p&&(c(),g.setState({clips:p.clips,timelineTracks:p.tracks}));const S=p?p.clips.filter(o=>!n.clips.some(h=>h.id===o.id)).length:0,i=[...r,...p?.errors??[]];s.done(i.length?m("Đã tách {0} vật thể của “{1}”; chưa tách được: {2}",[S,a.label,i.join(" · ")]):m("Đã tách {0} vật thể của “{1}”, mỗi vật thể một layer riêng.",[S,a.label]),i.length?"error":"ok")}export{E as clipDetail,rt as matteRunning,A as progressToast,at as resumePendingMattes,ct as runPendingMattes,L as segmentClipMatte,N as segmentClipObject};
@@ -0,0 +1 @@
1
+ import{_ as m}from"./titleFrameBudget-h4nOQ5u9.js";import{t as p}from"./i18n-ClNt3LKg.js";import"./index-CKtv7gGE.js";const l=Object.freeze({url:"https://huggingface.co/Xenova/modnet/resolve/fa2fa546052fba4c08921230a26cc69a333fca12/onnx/model.onnx",sha256:"07c308cf0fc7e6e8b2065a12ed7fc07e1de8febb7dc7839d7b7f15dd66584df9",bytes:25888640});function w(o,n,e=512){const t=e/Math.min(o,n),a=i=>Math.max(32,Math.round(i/32)*32);return{W:a(o*t),H:a(n*t)}}function g(o,n,e){const t=n*e,a=new Float32Array(3*t);for(let i=0;i<t;i++)for(let r=0;r<3;r++)a[r*t+i]=o[i*4+r]/127.5-1;return a}function b(o,n,e){const t=new Uint8Array(n*e);for(let a=0;a<t.length;a++)t[a]=Math.round(Math.max(0,Math.min(1,o[a]))*255);return t}const y="1.31.1",f=`https://cdn.jsdelivr.net/npm/onnxruntime-web@${y}/dist/`,_="clipoox-people-1";let u=null;const v=o=>[...new Uint8Array(o)].map(n=>n.toString(16).padStart(2,"0")).join("");async function O(o){const n=await caches.open(_).catch(()=>null),e=await n?.match(l.url);if(e){const s=new Uint8Array(await e.arrayBuffer());if(s.length===l.bytes)return s}const t=await fetch(l.url);if(!t.ok||!t.body)throw Error(p("Không tải được mô hình tách người (HTTP {0})",[t.status]));const a=t.body.getReader(),i=[];let r=0;for(;;){const{done:s,value:d}=await a.read();if(s)break;i.push(d),r+=d.length,o?.(Math.min(1,r/l.bytes))}const c=new Uint8Array(r);let h=0;for(const s of i)c.set(s,h),h+=s.length;if(v(await crypto.subtle.digest("SHA-256",c))!==l.sha256)throw Error(p("Mô hình tách người tải về bị lỗi (mã kiểm tra không khớp) — thử lại."));return await n?.put(l.url,new Response(c,{headers:{"content-type":"application/octet-stream"}})).catch(()=>{}),c}function M(o){return u||(u=(async()=>{const n=await m(()=>import(`${f}ort.wasm.min.mjs`),[]);n.env.wasm.wasmPaths=f,n.env.wasm.numThreads=globalThis.crossOriginIsolated?Math.min(4,navigator.hardwareConcurrency||1):1;const e=await n.InferenceSession.create(await O(o),{executionProviders:["wasm"],graphOptimizationLevel:"all"});return Object.assign(e,{ort:n})})(),u.catch(()=>{u=null})),u}async function A(o,n){const{W:e,H:t}=w(o.width,o.height);if(window.__peopleMatteStub)return{data:window.__peopleMatteStub(e,t),w:e,h:t};const a=await M(h=>n?.("download",h));n?.("run");const i=new OffscreenCanvas(e,t),r=i.getContext("2d",{willReadFrequently:!0});r.imageSmoothingQuality="high",r.drawImage(o,0,0,e,t);const c=await a.run({[a.inputNames[0]]:new a.ort.Tensor("float32",g(r.getImageData(0,0,e,t).data,e,t),[1,3,t,e])});return{data:b(c[a.outputNames[0]].data,e,t),w:e,h:t}}export{A as peopleOfPicture};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-CzEKvJph.js","assets/titleFrameBudget-DsM0V482.js","assets/store-CpqHUcA2.js","assets/index-CKtv7gGE.js","assets/i18n-C9zFX25m.js","assets/personHq-Ca351o06.js","assets/matteQuality-9X-jgJrH.js","assets/api-Dnl2uaKO.js","assets/rigTrack-DMyqb0pb.js","assets/objectSegmenter-D66spD7o.js","assets/cutoutClean-CLYYAuXg.js"])))=>i.map(i=>d[i]);
2
- import{_ as K}from"./titleFrameBudget-DsM0V482.js";import{S as yt}from"./personHq-Ca351o06.js";import{a as ht,s as nt,i as xt,d as gt,b as pt,g as Mt,o as _t,t as bt,c as Pt,r as Et}from"./cutoutClean-CLYYAuXg.js";import"./matteQuality-9X-jgJrH.js";import"./api-Dnl2uaKO.js";import"./i18n-C9zFX25m.js";import"./index-CKtv7gGE.js";const wt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${yt}/wasm`,Ot=[0,11,12,13,14,23,24,25,26],st=512,Y=512;async function Rt(){if(typeof window<"u"&&window.__personPoseStub)return{detect:window.__personPoseStub,close:()=>{}};const[{FilesetResolver:b,PoseLandmarker:P},{POSE_MODEL_URL:n}]=await Promise.all([K(()=>import("./vision_bundle-9zIsgJJP.js"),[]),K(()=>import("./poseTracker-CzEKvJph.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))]),s=await b.forVisionTasks(wt),R=await P.createFromOptions(s,{baseOptions:{modelAssetPath:n,delegate:"CPU"},runningMode:"VIDEO",numPoses:4,minPoseDetectionConfidence:.4,minPosePresenceConfidence:.4,minTrackingConfidence:.4});let w=0;return{detect:(u,y)=>(w=Math.max(w+1,Math.round(y)),(R.detectForVideo(u,w).landmarks??[]).map(M=>M.map(h=>[h.x,h.y,h.visibility??1]))),close:()=>R.close()}}async function kt(b,P,n,s){const[{detect:R,close:w},{objectProbability:u}]=await Promise.all([Rt(),K(()=>import("./objectSegmenter-D66spD7o.js"),__vite__mapDeps([9,1,5,6,7,4,3,10]))]),y=Object.assign(document.createElement("canvas"),{width:st,height:Math.max(2,Math.round(st*P/b))}),A=y.getContext("2d",{willReadFrequently:!0}),M=Object.assign(document.createElement("canvas"),{width:Y,height:Y}),h=M.getContext("2d",{willReadFrequently:!0}),at=Object.assign(document.createElement("canvas"),{width:n,height:s}),Q=at.getContext("2d",{willReadFrequently:!0}),B=n*s,v={frames:0,ai:0,rejected:0,tPose:0,tPrep:0,tRead:0,tMap:0,tClean:0};return{stats:v,close:()=>{window.__cutoutDebug&&console.log("# ai stats",JSON.stringify(v)),w()},async frame(G,k,rt){v.frames++;let Z=performance.now();const C=t=>{const r=performance.now();v[t]+=r-Z,Z=r};A.drawImage(G,0,0,y.width,y.height);const tt=R(y,rt).filter(t=>Array.isArray(t)&&t.length>=33);C("tPose");const{label:L,regions:it}=ht(k,n,s,128),T=it.filter(t=>t.area>=.002*B).sort((t,r)=>r.area-t.area);if(!T.length)return null;const J=nt(k,n,s,3,!0),$=t=>[Math.max(0,Math.min(n-1,Math.floor(t[0]*n))),Math.max(0,Math.min(s-1,Math.floor(t[1]*s)))],D=t=>t[2]>.6&&t[0]>=0&&t[0]<1&&t[1]>=0&&t[1]<1,ct=t=>{const r=new Map;for(const m of t)if(D(m)){const[l,O]=$(m),i=L[O*n+l]||(J[O*n+l]>=128?At(L,n,s,l,O,3):0);i&&r.set(i,(r.get(i)??0)+1)}let f=0,x=1;for(const[m,l]of r)l>x&&(x=l,f=m);return f},V=new Map;for(const t of tt){const r=ct(t);r&&V.set(r,[...V.get(r)??[],t])}const I=(tt.length?T.filter(t=>V.has(t.id)):T.filter(t=>t.area>=.25*T[0].area)).slice(0,4);if(!I.length)return null;const N=new Float32Array(B),et=new Uint8Array(B),lt=(t,r)=>{for(let f=-2;f<=2;f++)for(let x=-2;x<=2;x++){const m=t+x,l=r+f;m>=0&&l>=0&&m<n&&l<s&&(et[l*n+m]=1)}};C("tPrep");for(const t of I){const r=V.get(t.id)??[],f=[];for(const e of r){for(const o of Ot)if(D(e[o])){const[c,d]=$(e[o]);J[d*n+c]>=128&&f.push([e[o][0]*n,e[o][1]*s])}if(D(e[11])&&D(e[12])){const o=(e[11][0]+e[12][0])/2,c=(e[11][1]+e[12][1])/2,[d,g]=$([o,c]);J[g*n+d]>=128&&f.push([o*n,c*s])}}{const e=t.x1-t.x0+3,o=t.y1-t.y0+3,c=t.x0-1,d=t.y0-1,g=p=>{const F=p%e+c,H=(p/e|0)+d;return F>=0&&H>=0&&F<n&&H<s&&L[H*n+F]===t.id},X=new Int32Array(e*o);for(let p=0;p<X.length;p++)X[p]=g(p)?1:0;for(const p of xt(gt(F=>X[F]===1,e,o),X,1,e,o,6))f.push([p[0]+c+.5,p[1]+d+.5])}if(!f.length)continue;let x=t.x0,m=t.y0,l=t.x1+1,O=t.y1+1;for(const e of r)for(const o of e)D(o)&&(x=Math.min(x,o[0]*n),m=Math.min(m,o[1]*s),l=Math.max(l,o[0]*n),O=Math.max(O,o[1]*s));const i=b/n,a=Et(x*i,m*i,l*i,O*i,b,P);C("tPrep"),h.drawImage(G,a.sx,a.sy,a.sw,a.sh,0,0,Y,Y);const E=await u(M,f.map(([e,o])=>({x:(e*i-a.sx)/a.sw,y:(o*i-a.sy)/a.sh})).filter(e=>e.x>0&&e.x<1&&e.y>0&&e.y<1).slice(0,24));C("tRead");const j=Math.max(4,Math.round(.15*Math.max(t.x1-t.x0,t.y1-t.y0))),U=Math.max(0,t.x0-j,Math.floor(a.sx/i)),q=Math.max(0,t.y0-j,Math.floor(a.sy/i)),dt=Math.min(n-1,t.x1+j,Math.ceil((a.sx+a.sw)/i)),mt=Math.min(s-1,t.y1+j,Math.ceil((a.sy+a.sh)/i)),_=dt-U+1,S=mt-q+1,W=new Uint8Array(_*S);for(let e=0;e<S;e++)for(let o=0;o<_;o++)L[(e+q)*n+o+U]===t.id&&(W[e*_+o]=255);const ut=nt(W,_,S,j,!0),z=new Float32Array(_*S);for(let e=0;e<S;e++){const o=((e+q+.5)*i-a.sy)/a.sh*E.height-.5;if(!(o<-.5||o>E.height-.5))for(let c=0;c<_;c++){const d=e*_+c;if(!ut[d])continue;const g=((c+U+.5)*i-a.sx)/a.sw*E.width-.5;g<-.5||g>E.width-.5||(z[d]=pt(E.data,E.width,E.height,g,o))}}const ot=Mt(E.data,.8)||_t(z,W,.5,128).inB<.5;ot?v.rejected++:v.ai++;for(let e=0;e<S;e++)for(let o=0;o<_;o++){const c=e*_+o,d=(e+q)*n+o+U,g=ot?W[c]?k[d]/255:0:z[c];g>N[d]&&(N[d]=g)}for(const[e,o]of f)lt(Math.floor(e),Math.floor(o));C("tMap")}bt(N,k,n,s,Math.max(2,Math.round(.012*Math.max(I[0].x1-I[0].x0,I[0].y1-I[0].y0)))),Q.drawImage(G,0,0,n,s);const ft=Pt(N,Q.getImageData(0,0,n,s).data,n,s,{seeds:et});return C("tClean"),ft}}}function At(b,P,n,s,R,w){for(let u=1;u<=w;u++)for(let y=-u;y<=u;y++)for(let A=-u;A<=u;A++){const M=s+A,h=R+y;if(M>=0&&h>=0&&M<P&&h<n&&b[h*P+M])return b[h*P+M]}return 0}export{kt as personAiReader};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-qtuytI-L.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/store-D3Y663py.js","assets/index-CKtv7gGE.js","assets/i18n-ClNt3LKg.js","assets/personHq-CBP8v_cw.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/rigTrack-BbKqZGs7.js","assets/objectSegmenter-C4T9qgUL.js","assets/cutoutClean-CLYYAuXg.js"])))=>i.map(i=>d[i]);
2
+ import{_ as K}from"./titleFrameBudget-h4nOQ5u9.js";import{S as yt}from"./personHq-CBP8v_cw.js";import{a as ht,s as nt,i as xt,d as gt,b as pt,g as Mt,o as _t,t as bt,c as Pt,r as Et}from"./cutoutClean-CLYYAuXg.js";import"./matteQuality-9X-jgJrH.js";import"./api-CZoVJ9Fy.js";import"./i18n-ClNt3LKg.js";import"./index-CKtv7gGE.js";const wt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${yt}/wasm`,Ot=[0,11,12,13,14,23,24,25,26],st=512,Y=512;async function Rt(){if(typeof window<"u"&&window.__personPoseStub)return{detect:window.__personPoseStub,close:()=>{}};const[{FilesetResolver:b,PoseLandmarker:P},{POSE_MODEL_URL:n}]=await Promise.all([K(()=>import("./vision_bundle-9zIsgJJP.js"),[]),K(()=>import("./poseTracker-qtuytI-L.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))]),s=await b.forVisionTasks(wt),R=await P.createFromOptions(s,{baseOptions:{modelAssetPath:n,delegate:"CPU"},runningMode:"VIDEO",numPoses:4,minPoseDetectionConfidence:.4,minPosePresenceConfidence:.4,minTrackingConfidence:.4});let w=0;return{detect:(u,y)=>(w=Math.max(w+1,Math.round(y)),(R.detectForVideo(u,w).landmarks??[]).map(M=>M.map(h=>[h.x,h.y,h.visibility??1]))),close:()=>R.close()}}async function kt(b,P,n,s){const[{detect:R,close:w},{objectProbability:u}]=await Promise.all([Rt(),K(()=>import("./objectSegmenter-C4T9qgUL.js"),__vite__mapDeps([9,1,5,6,7,4,3,10]))]),y=Object.assign(document.createElement("canvas"),{width:st,height:Math.max(2,Math.round(st*P/b))}),A=y.getContext("2d",{willReadFrequently:!0}),M=Object.assign(document.createElement("canvas"),{width:Y,height:Y}),h=M.getContext("2d",{willReadFrequently:!0}),at=Object.assign(document.createElement("canvas"),{width:n,height:s}),Q=at.getContext("2d",{willReadFrequently:!0}),B=n*s,v={frames:0,ai:0,rejected:0,tPose:0,tPrep:0,tRead:0,tMap:0,tClean:0};return{stats:v,close:()=>{window.__cutoutDebug&&console.log("# ai stats",JSON.stringify(v)),w()},async frame(G,k,rt){v.frames++;let Z=performance.now();const C=t=>{const r=performance.now();v[t]+=r-Z,Z=r};A.drawImage(G,0,0,y.width,y.height);const tt=R(y,rt).filter(t=>Array.isArray(t)&&t.length>=33);C("tPose");const{label:L,regions:it}=ht(k,n,s,128),T=it.filter(t=>t.area>=.002*B).sort((t,r)=>r.area-t.area);if(!T.length)return null;const J=nt(k,n,s,3,!0),$=t=>[Math.max(0,Math.min(n-1,Math.floor(t[0]*n))),Math.max(0,Math.min(s-1,Math.floor(t[1]*s)))],D=t=>t[2]>.6&&t[0]>=0&&t[0]<1&&t[1]>=0&&t[1]<1,ct=t=>{const r=new Map;for(const m of t)if(D(m)){const[l,O]=$(m),i=L[O*n+l]||(J[O*n+l]>=128?At(L,n,s,l,O,3):0);i&&r.set(i,(r.get(i)??0)+1)}let f=0,x=1;for(const[m,l]of r)l>x&&(x=l,f=m);return f},V=new Map;for(const t of tt){const r=ct(t);r&&V.set(r,[...V.get(r)??[],t])}const I=(tt.length?T.filter(t=>V.has(t.id)):T.filter(t=>t.area>=.25*T[0].area)).slice(0,4);if(!I.length)return null;const N=new Float32Array(B),et=new Uint8Array(B),lt=(t,r)=>{for(let f=-2;f<=2;f++)for(let x=-2;x<=2;x++){const m=t+x,l=r+f;m>=0&&l>=0&&m<n&&l<s&&(et[l*n+m]=1)}};C("tPrep");for(const t of I){const r=V.get(t.id)??[],f=[];for(const e of r){for(const o of Ot)if(D(e[o])){const[c,d]=$(e[o]);J[d*n+c]>=128&&f.push([e[o][0]*n,e[o][1]*s])}if(D(e[11])&&D(e[12])){const o=(e[11][0]+e[12][0])/2,c=(e[11][1]+e[12][1])/2,[d,g]=$([o,c]);J[g*n+d]>=128&&f.push([o*n,c*s])}}{const e=t.x1-t.x0+3,o=t.y1-t.y0+3,c=t.x0-1,d=t.y0-1,g=p=>{const F=p%e+c,H=(p/e|0)+d;return F>=0&&H>=0&&F<n&&H<s&&L[H*n+F]===t.id},X=new Int32Array(e*o);for(let p=0;p<X.length;p++)X[p]=g(p)?1:0;for(const p of xt(gt(F=>X[F]===1,e,o),X,1,e,o,6))f.push([p[0]+c+.5,p[1]+d+.5])}if(!f.length)continue;let x=t.x0,m=t.y0,l=t.x1+1,O=t.y1+1;for(const e of r)for(const o of e)D(o)&&(x=Math.min(x,o[0]*n),m=Math.min(m,o[1]*s),l=Math.max(l,o[0]*n),O=Math.max(O,o[1]*s));const i=b/n,a=Et(x*i,m*i,l*i,O*i,b,P);C("tPrep"),h.drawImage(G,a.sx,a.sy,a.sw,a.sh,0,0,Y,Y);const E=await u(M,f.map(([e,o])=>({x:(e*i-a.sx)/a.sw,y:(o*i-a.sy)/a.sh})).filter(e=>e.x>0&&e.x<1&&e.y>0&&e.y<1).slice(0,24));C("tRead");const j=Math.max(4,Math.round(.15*Math.max(t.x1-t.x0,t.y1-t.y0))),U=Math.max(0,t.x0-j,Math.floor(a.sx/i)),q=Math.max(0,t.y0-j,Math.floor(a.sy/i)),dt=Math.min(n-1,t.x1+j,Math.ceil((a.sx+a.sw)/i)),mt=Math.min(s-1,t.y1+j,Math.ceil((a.sy+a.sh)/i)),_=dt-U+1,S=mt-q+1,W=new Uint8Array(_*S);for(let e=0;e<S;e++)for(let o=0;o<_;o++)L[(e+q)*n+o+U]===t.id&&(W[e*_+o]=255);const ut=nt(W,_,S,j,!0),z=new Float32Array(_*S);for(let e=0;e<S;e++){const o=((e+q+.5)*i-a.sy)/a.sh*E.height-.5;if(!(o<-.5||o>E.height-.5))for(let c=0;c<_;c++){const d=e*_+c;if(!ut[d])continue;const g=((c+U+.5)*i-a.sx)/a.sw*E.width-.5;g<-.5||g>E.width-.5||(z[d]=pt(E.data,E.width,E.height,g,o))}}const ot=Mt(E.data,.8)||_t(z,W,.5,128).inB<.5;ot?v.rejected++:v.ai++;for(let e=0;e<S;e++)for(let o=0;o<_;o++){const c=e*_+o,d=(e+q)*n+o+U,g=ot?W[c]?k[d]/255:0:z[c];g>N[d]&&(N[d]=g)}for(const[e,o]of f)lt(Math.floor(e),Math.floor(o));C("tMap")}bt(N,k,n,s,Math.max(2,Math.round(.012*Math.max(I[0].x1-I[0].x0,I[0].y1-I[0].y0)))),Q.drawImage(G,0,0,n,s);const ft=Pt(N,Q.getImageData(0,0,n,s).data,n,s,{seeds:et});return C("tClean"),ft}}}function At(b,P,n,s,R,w){for(let u=1;u<=w;u++)for(let y=-u;y<=u;y++)for(let A=-u;A<=u;A++){const M=s+A,h=R+y;if(M>=0&&h>=0&&M<P&&h<n&&b[h*P+M])return b[h*P+M]}return 0}export{kt as personAiReader};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-CzEKvJph.js","assets/titleFrameBudget-DsM0V482.js","assets/store-CpqHUcA2.js","assets/index-CKtv7gGE.js","assets/i18n-C9zFX25m.js","assets/rigTrack-DMyqb0pb.js","assets/matteQuality-9X-jgJrH.js","assets/api-Dnl2uaKO.js","assets/personAi-EhBknW6X.js","assets/cutoutClean-CLYYAuXg.js"])))=>i.map(i=>d[i]);
2
- import{a7 as at,da as _t,db as Pt,cw as kt,kz as z,kA as xt,kB as D,kC as St,kD as rt,kE as st,kF as At,kG as Ot,_ as L,kH as vt,d1 as bt}from"./titleFrameBudget-DsM0V482.js";import{p as G,m as Ct,g as Tt,l as Ft,r as Rt,t as It,f as Dt,c as et,a as Lt,b as Vt}from"./matteQuality-9X-jgJrH.js";import{bO as it,e as Ut,a as Nt,s as jt,r as Ht}from"./api-Dnl2uaKO.js";import{t as _}from"./i18n-C9zFX25m.js";async function ie(t,e,r,a){const n=t.person;if(!n)return null;const s=await at(n),i=_t(s,n,Pt(t,e)),o=G(i,n.w,n.h);if(!o)return null;const u=(c,f)=>{const g=kt(t,c,f,e,r,a,n.mw,n.mh);return[g.px/r,g.py/a]},h=u(o.x+o.w/2,o.y+o.h),m=u(o.x+o.w/2,o.y)[1],l=c=>Math.round(c*1e3)/1e3;return{feet:[l(h[0]),l(h[1])],horizon:l(Math.min(h[1]-.1,m+.07*(h[1]-m)))}}const ct="1.0.1",lt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${ct}/wasm`,ht="https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/1/selfie_multiclass_256x256.tflite",Wt={multiclass:{path:ht,person:t=>{const e=t[0],r=new Float32Array(e.length);for(let a=0;a<e.length;a++)r[a]=1-e[a];return r}},selfie:{path:"/models/selfie_segmenter.tflite",person:t=>t[0]}},zt=640,Gt=640*640,Xt=512,Kt=32,Bt=8,ut=120,W=new Map;async function dt(t="selfie"){if(typeof window<"u"&&window.__personSegmenterStub)return window.__personSegmenterStub;let e;for(const r of t==="selfie"?["selfie"]:[t,"selfie"])try{return await $t(r)}catch(a){e=a,console.warn(`person model ${r} failed to load`,a)}throw e}function $t(t){const e=t,r=W.get(e);if(r)return r;const a=(t==="pose"?Qt():(async()=>{const{FilesetResolver:n,ImageSegmenter:s}=await L(async()=>{const{FilesetResolver:m,ImageSegmenter:l}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:m,ImageSegmenter:l}},[]),i=await n.forVisionTasks(lt),o=Wt[t],u=await s.createFromOptions(i,{baseOptions:{modelAssetPath:o.path,delegate:"CPU"},runningMode:"VIDEO",outputConfidenceMasks:!0,outputCategoryMask:!1});let h=0;return(m,l)=>{h=Math.max(h+1,Math.round(l));const c=u.segmentForVideo(m,h);try{const f=c.confidenceMasks;if(!f?.length)throw Error("no mask");return{data:o.person(f.map(g=>g.getAsFloat32Array())),width:f[0].width,height:f[0].height}}finally{c.close()}}})()).catch(n=>{throw W.delete(e),n});return W.set(e,a),a}async function Qt(){const[{FilesetResolver:t,PoseLandmarker:e},{POSE_MODEL_URL:r}]=await Promise.all([L(()=>import("./vision_bundle-9zIsgJJP.js"),[]),L(()=>import("./poseTracker-CzEKvJph.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]))]),a=await t.forVisionTasks(lt),n=await e.createFromOptions(a,{baseOptions:{modelAssetPath:r,delegate:"CPU"},runningMode:"VIDEO",numPoses:4,outputSegmentationMasks:!0,minPoseDetectionConfidence:.4,minPosePresenceConfidence:.4,minTrackingConfidence:.4});let s=0;return(i,o)=>{s=Math.max(s+1,Math.round(o));const u=n.detectForVideo(i,s);try{const h=u.segmentationMasks??[];if(!h.length)return{data:new Float32Array(i.width*i.height),width:i.width,height:i.height};const m=h[0].width,l=h[0].height,c=new Float32Array(m*l);for(const f of h){const g=f.getAsFloat32Array();for(let w=0;w<c.length;w++)g[w]>c[w]&&(c[w]=g[w])}return{data:c,width:m,height:l}}finally{u.close()}}}async function Jt(t){return await(await dt())(t,performance.now())}function Yt(t,e,r){const a=new Uint8Array(e*r);for(let n=0;n<r;n++){const s=Math.floor(n*t.height/r),i=Math.max(s+1,Math.floor((n+1)*t.height/r));for(let o=0;o<e;o++){const u=Math.floor(o*t.width/e),h=Math.max(u+1,Math.floor((o+1)*t.width/e));let m=0,l=0;for(let c=s;c<i&&c<t.height;c++)for(let f=u;f<h&&f<t.width;f++)m+=t.data[c*t.width+f],l++;a[n*e+o]=Math.round(Math.max(0,Math.min(1,l?m/l:0))*255)}}return a}const K={r:.5,eps:.001,lo:.3,hi:.7};function X(t,e,r,a,n,s=!0,i=K){let o=t.data;if(s&&e&&e.length===t.width*t.height*4){const u=Math.max(2,Math.round(Math.max(t.width,t.height)/128));o=Ct(Tt(o,Ft(e,t.width,t.height),t.width,t.height,{r:Math.max(1,Math.round(u*i.r)),eps:i.eps}),i.lo,i.hi)}return Rt(o,t.width,t.height,r,a,n)}const nt=(t,e)=>Math.abs(t.currentTime-e)<=1e-4?Promise.resolve():new Promise((r,a)=>{const n=window.setTimeout(()=>a(Error(_("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(n),r()},t.currentTime=e});function mt(t,e=!0){const a=Object.assign(document.createElement("canvas"),{width:t.videoWidth,height:t.videoHeight}),n=a.getContext("2d"),s=()=>(n.drawImage(t,0,0,a.width,a.height),a);let i=null,o=!1,u=!e||typeof t.requestVideoFrameCallback!="function";return async h=>u||i===null?(await nt(t,h),i=h,s()):i>=h-.02||o||await new Promise(l=>{const c=window.setTimeout(()=>l(!1),4e3),f=(g,w)=>{i=w.mediaTime,w.mediaTime>=h-.02?(window.clearTimeout(c),s(),t.pause(),l(!0)):t.requestVideoFrameCallback(f)};t.onended=()=>{o=!0,window.clearTimeout(c),l(!0)},t.requestVideoFrameCallback(f),t.play().catch(()=>{window.clearTimeout(c),l(!1)})})?a:(u=!0,t.pause(),await nt(t,h),i=h,s())}async function ft({clip:t,url:e,fps:r,signal:a,onProgress:n,quality:s={}}){if(t.kind!=="video")throw Error(_("Chỉ tách người được trên clip video"));const i=await dt(s.model),o=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});o.src=e;const u=typeof window<"u"&&!!window.__personSegmenterStub,{crop:h=!u,refine:m=!0,smooth:l=!0,levels:c=Kt,edge:f=K}=s,g=s.ai??(!u&&s.model!=="pose"&&t.duration*(t.playbackRate||1)<=ut);try{await new Promise((d,y)=>{o.onloadeddata=()=>d(),o.onerror=()=>y(Error(_("Không đọc được video để tách người (CORS / định dạng)")))});const w=o.videoWidth,M=o.videoHeight,p=Math.min(s.inputW??zt,w,Math.round(Math.sqrt(Gt*w/M))),k=Math.max(2,Math.round(p*M/w)),x=t.inPoint||0,V=t.duration*(t.playbackRate||1),Q=s.plan??(r?{...st(w,M),fps:r}:At(w,M,V)),{w:S,h:A}=Q;let O=Q.fps;for(;Math.ceil(V*O)+1>Ot&&O>1;)O/=2;const J=Math.max(1,Math.ceil(V*O)+1),Y=Object.assign(document.createElement("canvas"),{width:p,height:k}),Z=Y.getContext("2d",{willReadFrequently:!0}),C=document.createElement("canvas"),q=C.getContext("2d",{willReadFrequently:!0}),pt={x:0,y:0,w:1,h:1},U=B({mw:w,mh:M,w:S,h:A,fps:O,s0:x},c),N=l?It(d=>U.push(d)):null,gt=mt(o,s.step!==!1);let v=null;if(g)try{v=await(await L(async()=>{const{personAiReader:d}=await import("./personAi-EhBknW6X.js");return{personAiReader:d}},__vite__mapDeps([8,1,9,6,7,4,3]))).personAiReader(w,M,S,A)}catch(d){console.warn("person AI cut-out",d)}let T=o,F=null,j=null,H=0;const tt=async()=>{Z.drawImage(T,0,0,p,k);const d=await i(Y,++H);return j=X(d,m?Z.getImageData(0,0,p,k).data:null,pt,S,A,m,f)},Mt=(d,y)=>!d||!y?d??y:{x:Math.min(d.x,y.x),y:Math.min(d.y,y.y),w:Math.max(d.x+d.w,y.x+y.w)-Math.min(d.x,y.x),h:Math.max(d.y+d.h,y.y+y.h)-Math.min(d.y,y.y)},yt=()=>Mt(G(F,S,A,{thr:64}),j&&G(j,S,A,{thr:64}));for(let d=0;d<J;d++){if(a?.aborted)throw new DOMException("Đã huỷ","AbortError");const y=Math.max(0,Math.min(o.duration-1/60,x+d/O));T=await gt(y);const E=h&&F&&d%Bt?Dt(yt(),w,M):null;let P;if(E){const b=Math.min(1,Xt/Math.max(E.sw,E.sh)),R=Math.max(2,Math.round(E.sw*b)),I=Math.max(2,Math.round(E.sh*b));(C.width!==R||C.height!==I)&&Object.assign(C,{width:R,height:I}),q.drawImage(T,E.sx,E.sy,E.sw,E.sh,0,0,R,I);const Et=await i(C,++H);P=X(Et,m?q.getImageData(0,0,R,I).data:null,{x:E.sx/w,y:E.sy/M,w:E.sw/w,h:E.sh/M},S,A,m,f),et(P)<.5*et(F)&&(P=await tt())}else P=await tt();if(F=P,v)try{P=await v.frame(T,P,++H)??P}catch(b){console.warn("person AI cut-out",b),v.close(),v=null}N?N.push(P):U.push(P),n?.({done:d+1,total:J}),d%4===3&&await new Promise(b=>setTimeout(b,0))}return N?.finish(),v?.close(),await U.finish({},{store:s.store!==!1})}finally{o.removeAttribute("src"),o.load()}}function B({mw:t,mh:e,w:r,h:a,fps:n,s0:s},i=32){const o=vt(r,a),u=z({w:r,h:a,lv:i,ck:o});return{push:h=>u.push(h),async finish(h={},{store:m=!0}={}){if(!u.n)throw Error(_("Không đọc được khung hình nào của video"));let l=u.finish(),c=u.n,f=n;for(;l.length>xt;){if(c<4)throw Error(_("Clip quá dài để lưu mặt nạ người — hãy cắt ngắn clip."));const p=await D({v:2,w:r,h:a,n:c,ck:o,lv:i,data:l}),k=z({w:r,h:a,lv:i,ck:o});for(let x=0;x<c;x+=2)k.push(p[x]);l=k.finish(),c=k.n,f/=2}const g={v:2,mw:t,mh:e,w:r,h:a,fps:f,s0:+s.toFixed(4),n:c,ck:o,lv:i,data:l,feather:.008,grow:-.1,...h};if(!m)return g;const w=await D(g);let M=g;try{const p=await it(l);M={...g,ref:p},delete M.data}catch(p){if(l.length>St)throw p}return rt(M,w),M}}}async function Zt(t,{mw:e,mh:r,w:a,h:n,fps:s,s0:i},o={},u={}){const{lv:h,...m}=o,l=B({mw:e,mh:r,w:a,h:n,fps:s,s0:i},h??16);for(const c of t)l.push(c);return l.finish(m,u)}const ce=Object.freeze(Object.defineProperty({__proto__:null,AI_MAX_SECONDS:ut,EDGE:K,MULTICLASS_URL:ht,SEGMENTER_VERSION:ct,downscaleMask:Yt,frameStepper:mt,matteWriter:B,packMatte:Zt,personProbability:Jt,refinedFrame:X,segmentPerson:ft},Symbol.toStringTag,{value:"Module"})),wt="clipoox:person-hq",$=t=>Math.round(t.duration*Math.abs(t.playbackRate||1)*1e3)/1e3,ot=600,le=async t=>(await Ut(wt,{span:$(t)})).credits;function qt(t){return t.kind!=="video"?_("Chỉ tách người được trên clip video"):t.gcsUri?$(t)>ot?_("Pro Cut tối đa {0} phút mỗi lần — hãy tách clip ngắn hơn",[ot/60]):null:_("Pro Cut cần video đã lưu trong Media (tải lên trước).")}async function he(t,{canvasId:e,mw:r,mh:a}={}){const n=qt(t);if(n)throw Error(n);const s=await jt({gcsUri:t.gcsUri}),i=r&&a?{mw:Math.round(r),mh:Math.round(a)}:{};return(await Ht(wt,{videoUrl:s,trimStart:t.inPoint||0,span:$(t),...i},e)).jobId}async function ue(t,{signal:e,every:r=4e3}={}){for(let a=0;;){if(e?.aborted)throw new DOMException("Đã huỷ","AbortError");let n=null;try{n=await Nt(t,!0),a=0}catch(s){const i=s.status;if(i===403||i===404||++a>5)throw s}if(n?.status==="succeeded"){const s=n.output?.matte;if(!s)throw Error(_("Pro Cut không trả về mặt nạ"));return bt(s)}if(n?.status==="failed")throw Error(n.error?_(n.error):_("Pro Cut thất bại — credit đã được hoàn lại"));await new Promise(s=>setTimeout(s,r))}}const te=160,ee=6,ne=t=>document.querySelector(`video[data-clip-media="${t.id}"]`)?.currentSrc||t.url;async function de(t,e,{signal:r,onProgress:a}={}){const n=await ft({clip:t,url:ne(t),signal:r,onProgress:a,quality:{model:"pose",plan:{...st(e.mw,e.mh,te),fps:ee},refine:!1,levels:16,store:!1}}),[s,i]=await Promise.all([at({...e,pick:void 0}),D(n)]),o=z({w:e.w,h:e.h,lv:e.lv??32,ck:e.ck}),u=Lt(e.w,e.h);for(let c=0;c<e.n;c++){if(r?.aborted)throw new DOMException("Đã huỷ","AbortError");const f=Math.max(0,Math.min(n.n-1,(e.s0+c/e.fps-n.s0)*n.fps)),g=i[Math.floor(f)],w=i[Math.min(n.n-1,Math.floor(f)+1)],M=new Uint8Array(g.length);for(let p=0;p<M.length;p++)M[p]=g[p]>w[p]?g[p]:w[p];o.push(u.keep(s[c],Vt(M,n.w,n.h,e.w,e.h))),c%24===23&&await new Promise(p=>setTimeout(p,0))}const h=o.finish(),m={...e,ref:void 0,data:h};delete m.ref;const l={...e,ref:await it(h)};return rt(l,await D(m)),l}export{ht as M,ct as S,qt as a,le as b,he as c,de as d,Yt as e,Zt as f,mt as g,$ as h,ce as i,B as m,ie as p,ft as s,ue as w};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-qtuytI-L.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/store-D3Y663py.js","assets/index-CKtv7gGE.js","assets/i18n-ClNt3LKg.js","assets/rigTrack-BbKqZGs7.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/personAi-Cjg9KKeH.js","assets/cutoutClean-CLYYAuXg.js"])))=>i.map(i=>d[i]);
2
+ import{a7 as at,dd as Et,de as Pt,cz as kt,kG as z,kH as xt,kI as D,kJ as St,kK as rt,kL as st,kM as At,kN as Ot,_ as L,kO as vt,d4 as bt}from"./titleFrameBudget-h4nOQ5u9.js";import{p as G,m as Tt,g as Ct,l as Rt,r as Ft,t as It,f as Dt,c as et,a as Lt,b as Vt}from"./matteQuality-9X-jgJrH.js";import{bS as it,e as Ut,b as Nt,a as jt,r as Ht}from"./api-CZoVJ9Fy.js";import{t as E}from"./i18n-ClNt3LKg.js";async function ie(t,e,r,a){const n=t.person;if(!n)return null;const s=await at(n),i=Et(s,n,Pt(t,e)),o=G(i,n.w,n.h);if(!o)return null;const u=(c,f)=>{const g=kt(t,c,f,e,r,a,n.mw,n.mh);return[g.px/r,g.py/a]},h=u(o.x+o.w/2,o.y+o.h),m=u(o.x+o.w/2,o.y)[1],l=c=>Math.round(c*1e3)/1e3;return{feet:[l(h[0]),l(h[1])],horizon:l(Math.min(h[1]-.1,m+.07*(h[1]-m)))}}const ct="1.0.1",lt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${ct}/wasm`,ht="https://storage.googleapis.com/mediapipe-models/image_segmenter/selfie_multiclass_256x256/float32/1/selfie_multiclass_256x256.tflite",Wt={multiclass:{path:ht,person:t=>{const e=t[0],r=new Float32Array(e.length);for(let a=0;a<e.length;a++)r[a]=1-e[a];return r}},selfie:{path:"/models/selfie_segmenter.tflite",person:t=>t[0]}},zt=640,Gt=640*640,Kt=512,Xt=32,$t=8,ut=120,W=new Map;async function dt(t="selfie"){if(typeof window<"u"&&window.__personSegmenterStub)return window.__personSegmenterStub;let e;for(const r of t==="selfie"?["selfie"]:[t,"selfie"])try{return await Bt(r)}catch(a){e=a,console.warn(`person model ${r} failed to load`,a)}throw e}function Bt(t){const e=t,r=W.get(e);if(r)return r;const a=(t==="pose"?Jt():(async()=>{const{FilesetResolver:n,ImageSegmenter:s}=await L(async()=>{const{FilesetResolver:m,ImageSegmenter:l}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:m,ImageSegmenter:l}},[]),i=await n.forVisionTasks(lt),o=Wt[t],u=await s.createFromOptions(i,{baseOptions:{modelAssetPath:o.path,delegate:"CPU"},runningMode:"VIDEO",outputConfidenceMasks:!0,outputCategoryMask:!1});let h=0;return(m,l)=>{h=Math.max(h+1,Math.round(l));const c=u.segmentForVideo(m,h);try{const f=c.confidenceMasks;if(!f?.length)throw Error("no mask");return{data:o.person(f.map(g=>g.getAsFloat32Array())),width:f[0].width,height:f[0].height}}finally{c.close()}}})()).catch(n=>{throw W.delete(e),n});return W.set(e,a),a}async function Jt(){const[{FilesetResolver:t,PoseLandmarker:e},{POSE_MODEL_URL:r}]=await Promise.all([L(()=>import("./vision_bundle-9zIsgJJP.js"),[]),L(()=>import("./poseTracker-qtuytI-L.js"),__vite__mapDeps([0,1,2,3,4,5,6,7]))]),a=await t.forVisionTasks(lt),n=await e.createFromOptions(a,{baseOptions:{modelAssetPath:r,delegate:"CPU"},runningMode:"VIDEO",numPoses:4,outputSegmentationMasks:!0,minPoseDetectionConfidence:.4,minPosePresenceConfidence:.4,minTrackingConfidence:.4});let s=0;return(i,o)=>{s=Math.max(s+1,Math.round(o));const u=n.detectForVideo(i,s);try{const h=u.segmentationMasks??[];if(!h.length)return{data:new Float32Array(i.width*i.height),width:i.width,height:i.height};const m=h[0].width,l=h[0].height,c=new Float32Array(m*l);for(const f of h){const g=f.getAsFloat32Array();for(let w=0;w<c.length;w++)g[w]>c[w]&&(c[w]=g[w])}return{data:c,width:m,height:l}}finally{u.close()}}}async function Qt(t){return await(await dt())(t,performance.now())}function Yt(t,e,r){const a=new Uint8Array(e*r);for(let n=0;n<r;n++){const s=Math.floor(n*t.height/r),i=Math.max(s+1,Math.floor((n+1)*t.height/r));for(let o=0;o<e;o++){const u=Math.floor(o*t.width/e),h=Math.max(u+1,Math.floor((o+1)*t.width/e));let m=0,l=0;for(let c=s;c<i&&c<t.height;c++)for(let f=u;f<h&&f<t.width;f++)m+=t.data[c*t.width+f],l++;a[n*e+o]=Math.round(Math.max(0,Math.min(1,l?m/l:0))*255)}}return a}const X={r:.5,eps:.001,lo:.3,hi:.7};function K(t,e,r,a,n,s=!0,i=X){let o=t.data;if(s&&e&&e.length===t.width*t.height*4){const u=Math.max(2,Math.round(Math.max(t.width,t.height)/128));o=Tt(Ct(o,Rt(e,t.width,t.height),t.width,t.height,{r:Math.max(1,Math.round(u*i.r)),eps:i.eps}),i.lo,i.hi)}return Ft(o,t.width,t.height,r,a,n)}const nt=(t,e)=>Math.abs(t.currentTime-e)<=1e-4?Promise.resolve():new Promise((r,a)=>{const n=window.setTimeout(()=>a(Error(E("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(n),r()},t.currentTime=e});function mt(t,e=!0){const a=Object.assign(document.createElement("canvas"),{width:t.videoWidth,height:t.videoHeight}),n=a.getContext("2d"),s=()=>(n.drawImage(t,0,0,a.width,a.height),a);let i=null,o=!1,u=!e||typeof t.requestVideoFrameCallback!="function";return async h=>u||i===null?(await nt(t,h),i=h,s()):i>=h-.02||o||await new Promise(l=>{const c=window.setTimeout(()=>l(!1),4e3),f=(g,w)=>{i=w.mediaTime,w.mediaTime>=h-.02?(window.clearTimeout(c),s(),t.pause(),l(!0)):t.requestVideoFrameCallback(f)};t.onended=()=>{o=!0,window.clearTimeout(c),l(!0)},t.requestVideoFrameCallback(f),t.play().catch(()=>{window.clearTimeout(c),l(!1)})})?a:(u=!0,t.pause(),await nt(t,h),i=h,s())}async function ft({clip:t,url:e,fps:r,signal:a,onProgress:n,quality:s={}}){if(t.kind!=="video")throw Error(E("Chỉ tách người được trên clip video"));const i=await dt(s.model),o=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});o.src=e;const u=typeof window<"u"&&!!window.__personSegmenterStub,{crop:h=!u,refine:m=!0,smooth:l=!0,levels:c=Xt,edge:f=X}=s,g=s.ai??(!u&&s.model!=="pose"&&t.duration*(t.playbackRate||1)<=ut);try{await new Promise((d,y)=>{o.onloadeddata=()=>d(),o.onerror=()=>y(Error(E("Không đọc được video để tách người (CORS / định dạng)")))});const w=o.videoWidth,M=o.videoHeight,p=Math.min(s.inputW??zt,w,Math.round(Math.sqrt(Gt*w/M))),k=Math.max(2,Math.round(p*M/w)),x=t.inPoint||0,V=t.duration*(t.playbackRate||1),J=s.plan??(r?{...st(w,M),fps:r}:At(w,M,V)),{w:S,h:A}=J;let O=J.fps;for(;Math.ceil(V*O)+1>Ot&&O>1;)O/=2;const Q=Math.max(1,Math.ceil(V*O)+1),Y=Object.assign(document.createElement("canvas"),{width:p,height:k}),Z=Y.getContext("2d",{willReadFrequently:!0}),T=document.createElement("canvas"),q=T.getContext("2d",{willReadFrequently:!0}),pt={x:0,y:0,w:1,h:1},U=$({mw:w,mh:M,w:S,h:A,fps:O,s0:x},c),N=l?It(d=>U.push(d)):null,gt=mt(o,s.step!==!1);let v=null;if(g)try{v=await(await L(async()=>{const{personAiReader:d}=await import("./personAi-Cjg9KKeH.js");return{personAiReader:d}},__vite__mapDeps([8,1,9,6,7,4,3]))).personAiReader(w,M,S,A)}catch(d){console.warn("person AI cut-out",d)}let C=o,R=null,j=null,H=0;const tt=async()=>{Z.drawImage(C,0,0,p,k);const d=await i(Y,++H);return j=K(d,m?Z.getImageData(0,0,p,k).data:null,pt,S,A,m,f)},Mt=(d,y)=>!d||!y?d??y:{x:Math.min(d.x,y.x),y:Math.min(d.y,y.y),w:Math.max(d.x+d.w,y.x+y.w)-Math.min(d.x,y.x),h:Math.max(d.y+d.h,y.y+y.h)-Math.min(d.y,y.y)},yt=()=>Mt(G(R,S,A,{thr:64}),j&&G(j,S,A,{thr:64}));for(let d=0;d<Q;d++){if(a?.aborted)throw new DOMException("Đã huỷ","AbortError");const y=Math.max(0,Math.min(o.duration-1/60,x+d/O));C=await gt(y);const _=h&&R&&d%$t?Dt(yt(),w,M):null;let P;if(_){const b=Math.min(1,Kt/Math.max(_.sw,_.sh)),F=Math.max(2,Math.round(_.sw*b)),I=Math.max(2,Math.round(_.sh*b));(T.width!==F||T.height!==I)&&Object.assign(T,{width:F,height:I}),q.drawImage(C,_.sx,_.sy,_.sw,_.sh,0,0,F,I);const _t=await i(T,++H);P=K(_t,m?q.getImageData(0,0,F,I).data:null,{x:_.sx/w,y:_.sy/M,w:_.sw/w,h:_.sh/M},S,A,m,f),et(P)<.5*et(R)&&(P=await tt())}else P=await tt();if(R=P,v)try{P=await v.frame(C,P,++H)??P}catch(b){console.warn("person AI cut-out",b),v.close(),v=null}N?N.push(P):U.push(P),n?.({done:d+1,total:Q}),d%4===3&&await new Promise(b=>setTimeout(b,0))}return N?.finish(),v?.close(),await U.finish({},{store:s.store!==!1})}finally{o.removeAttribute("src"),o.load()}}function $({mw:t,mh:e,w:r,h:a,fps:n,s0:s},i=32){const o=vt(r,a),u=z({w:r,h:a,lv:i,ck:o});return{push:h=>u.push(h),async finish(h={},{store:m=!0}={}){if(!u.n)throw Error(E("Không đọc được khung hình nào của video"));let l=u.finish(),c=u.n,f=n;for(;l.length>xt;){if(c<4)throw Error(E("Clip quá dài để lưu mặt nạ người — hãy cắt ngắn clip."));const p=await D({v:2,w:r,h:a,n:c,ck:o,lv:i,data:l}),k=z({w:r,h:a,lv:i,ck:o});for(let x=0;x<c;x+=2)k.push(p[x]);l=k.finish(),c=k.n,f/=2}const g={v:2,mw:t,mh:e,w:r,h:a,fps:f,s0:+s.toFixed(4),n:c,ck:o,lv:i,data:l,feather:.008,grow:-.1,...h};if(!m)return g;const w=await D(g);let M=g;try{const p=await it(l);M={...g,ref:p},delete M.data}catch(p){if(l.length>St)throw p}return rt(M,w),M}}}async function Zt(t,{mw:e,mh:r,w:a,h:n,fps:s,s0:i},o={},u={}){const{lv:h,...m}=o,l=$({mw:e,mh:r,w:a,h:n,fps:s,s0:i},h??16);for(const c of t)l.push(c);return l.finish(m,u)}const ce=Object.freeze(Object.defineProperty({__proto__:null,AI_MAX_SECONDS:ut,EDGE:X,MULTICLASS_URL:ht,SEGMENTER_VERSION:ct,downscaleMask:Yt,frameStepper:mt,matteWriter:$,packMatte:Zt,personProbability:Qt,refinedFrame:K,segmentPerson:ft},Symbol.toStringTag,{value:"Module"})),wt="clipoox:person-hq",B=t=>Math.round(t.duration*Math.abs(t.playbackRate||1)*1e3)/1e3,ot=600,le=async t=>(await Ut(wt,{span:B(t)})).credits;function qt(t){return t.kind!=="video"?E("Chỉ tách người được trên clip video"):t.gcsUri?B(t)>ot?E("Pro Cut tối đa {0} phút mỗi lần — hãy tách clip ngắn hơn",[ot/60]):null:E("Pro Cut cần video đã lưu trong Media (tải lên trước).")}async function he(t,{canvasId:e,mw:r,mh:a}={}){const n=qt(t);if(n)throw Error(n);const s=await jt({gcsUri:t.gcsUri}),i=r&&a?{mw:Math.round(r),mh:Math.round(a)}:{};return(await Ht(wt,{videoUrl:s,trimStart:t.inPoint||0,span:B(t),...i},e)).jobId}async function ue(t,{signal:e,every:r=4e3}={}){for(let a=0;;){if(e?.aborted)throw new DOMException("Đã huỷ","AbortError");let n=null;try{n=await Nt(t,!0),a=0}catch(s){const i=s.status;if(i===403||i===404||++a>5)throw s}if(n?.status==="succeeded"){const s=n.output?.matte;if(!s)throw Error(E("Pro Cut không trả về mặt nạ"));return bt(s)}if(n?.status==="failed")throw Error(n.error?E(n.error):E("Pro Cut thất bại — credit đã được hoàn lại"));await new Promise(s=>setTimeout(s,r))}}const te=160,ee=6,ne=t=>document.querySelector(`video[data-clip-media="${t.id}"]`)?.currentSrc||t.url;async function de(t,e,{signal:r,onProgress:a}={}){const n=await ft({clip:t,url:ne(t),signal:r,onProgress:a,quality:{model:"pose",plan:{...st(e.mw,e.mh,te),fps:ee},refine:!1,levels:16,store:!1}}),[s,i]=await Promise.all([at({...e,pick:void 0}),D(n)]),o=z({w:e.w,h:e.h,lv:e.lv??32,ck:e.ck}),u=Lt(e.w,e.h);for(let c=0;c<e.n;c++){if(r?.aborted)throw new DOMException("Đã huỷ","AbortError");const f=Math.max(0,Math.min(n.n-1,(e.s0+c/e.fps-n.s0)*n.fps)),g=i[Math.floor(f)],w=i[Math.min(n.n-1,Math.floor(f)+1)],M=new Uint8Array(g.length);for(let p=0;p<M.length;p++)M[p]=g[p]>w[p]?g[p]:w[p];o.push(u.keep(s[c],Vt(M,n.w,n.h,e.w,e.h))),c%24===23&&await new Promise(p=>setTimeout(p,0))}const h=o.finish(),m={...e,ref:void 0,data:h};delete m.ref;const l={...e,ref:await it(h)};return rt(l,await D(m)),l}export{ht as M,ct as S,qt as a,le as b,he as c,de as d,Yt as e,Zt as f,mt as g,B as h,ce as i,$ as m,ie as p,ft as s,ue as w};
@@ -0,0 +1 @@
1
+ (function(){"use strict";function At(t,e,a,o,r){const c=+e,l=+a,s=+r;let i,n,u,x;try{i=G(t,v.__wbindgen_malloc),n=E,u=G(o,v.__wbindgen_malloc),x=E}catch(m){throw u&&v.__wbindgen_free(u,x*1,1),i&&v.__wbindgen_free(i,n*1,1),m}const b=v.content_fill(i,n,c,l,u,x,s);if(b[3])throw V(b[2]);var h=J(b[0],b[1]).slice();return v.__wbindgen_free(b[0],b[1]*1,1),h}function kt(t,e,a,o,r){const c=+a,l=+o;let s,i,n,u,x,b;try{s=Bt(t,v.__wbindgen_malloc,v.__wbindgen_realloc),i=E,n=G(e,v.__wbindgen_malloc),u=E,x=Ut(r)?0:G(r,v.__wbindgen_malloc),b=E}catch(M){throw x&&v.__wbindgen_free(x,b*1,1),n&&v.__wbindgen_free(n,u*1,1),s&&v.__wbindgen_free(s,i*1,1),M}const h=v.filter(s,i,n,u,c,l,x,b);if(h[3])throw V(h[2]);var m=J(h[0],h[1]).slice();return v.__wbindgen_free(h[0],h[1]*1,1),m}function vt(t,e,a,o,r,c,l,s,i){const n=+e,u=+a,x=+r,b=+c,h=+l,m=+s,M=+i;let f,y,d,p;try{f=G(t,v.__wbindgen_malloc),y=E,d=G(o,v.__wbindgen_malloc),p=E}catch(_){throw d&&v.__wbindgen_free(d,p*1,1),f&&v.__wbindgen_free(f,y*1,1),_}const g=v.refine_mask(f,y,n,u,d,p,x,b,h,m,M);if(g[3])throw V(g[2]);var k=J(g[0],g[1]).slice();return v.__wbindgen_free(g[0],g[1]*1,1),k}function St(t,e,a,o,r,c){const l=+e,s=+a,i=+r,n=+c;let u,x,b,h;try{u=G(t,v.__wbindgen_malloc),x=E,b=G(o,v.__wbindgen_malloc),h=E}catch(f){throw b&&v.__wbindgen_free(b,h*1,1),u&&v.__wbindgen_free(u,x*1,1),f}const m=v.remove_area(u,x,l,s,b,h,i,n);if(m[3])throw V(m[2]);var M=J(m[0],m[1]).slice();return v.__wbindgen_free(m[0],m[1]*1,1),M}function Tt(t,e,a){const o=+e,r=+a,c=G(t,v.__wbindgen_malloc),l=E,s=v.select_subject(c,l,o,r);if(s[3])throw V(s[2]);var i=J(s[0],s[1]).slice();return v.__wbindgen_free(s[0],s[1]*1,1),i}function mt(){return{__proto__:null,"./clipoox_photo_bg.js":{__proto__:null,__wbg___wbindgen_throw_4c88d8bf264fd984:function(e,a){throw new Error(dt(e,a))},__wbindgen_generic_0000000000000001:function(e,a){return dt(e,a)},__wbindgen_init_externref_table:function(){const e=v.__wbindgen_externrefs;e.set(0,void 0),e.set(1024,void 0),e.set(1025,null),e.set(1026,!0),e.set(1027,!1)}}}}function J(t,e){return t=t>>>0,$().subarray(t/1,t/1+e)}function dt(t,e){return t=t>>>0,Ct($().subarray(t,t+e))}let Y=null;function $(){return(Y===null||Y.byteLength===0)&&(Y=new Uint8Array(v.memory.buffer)),Y}function Ut(t){return t==null}function G(t,e){const a=e(t.length*1,1)>>>0;return $().set(t,a/1),E=t.length,a}function Bt(t,e,a){if(a===void 0){const s=Q.encode(t),i=e(s.length,1)>>>0;return $().subarray(i,i+s.length).set(s),E=s.length,i}let o=t.length,r=e(o,1)>>>0;const c=$();let l=0;for(;l<o;l++){const s=t.charCodeAt(l);if(s>127)break;c[r+l]=s}if(l!==o){l!==0&&(t=t.slice(l)),r=a(r,o,o=l+t.length*3,1)>>>0;const s=$().subarray(r+l,r+o),i=Q.encodeInto(t,s);l+=i.written,r=a(r,o,l,1)>>>0}return E=l,r}function V(t){const e=v.__wbindgen_externrefs.get(t);return v.__externref_table_dealloc(t),e}let at=new TextDecoder("utf-8",{ignoreBOM:!0});at.decode();const Nt=2146435072;let it=0;function Ct(t){return it+=t.length,it>=Nt&&(at=new TextDecoder("utf-8",{ignoreBOM:!0}),at.decode(),it=t.length),at.decode(t)}const Q=new TextEncoder;"encodeInto"in Q||(Q.encodeInto=function(t,e){const a=Q.encode(t);return e.set(a),{read:t.length,written:a.length}});let E=0,v;function bt(t,e){return v=t.exports,Y=null,v.__wbindgen_start(),v}async function Ot(t,e){if(typeof Response=="function"&&t instanceof Response){if(!t.ok)throw new Error(`failed to fetch Wasm: ${t.status} ${t.statusText} fetching '${t.url}'`);if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(r){if(a(t.type)&&t.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r);else throw r}const o=await t.arrayBuffer();return await WebAssembly.instantiate(o,e)}else{const o=await WebAssembly.instantiate(t,e);return o instanceof WebAssembly.Instance?{instance:o,module:t}:o}function a(o){switch(o){case"basic":case"cors":case"default":return!0}return!1}}function jt(t){if(v!==void 0)return v;t!==void 0&&(Object.getPrototypeOf(t)===Object.prototype?{module:t}=t:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));const e=mt();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));const a=new WebAssembly.Instance(t,e);return bt(a)}let Z;async function Ft(t){return v!==void 0?v:(Z===void 0&&(Z=Rt(t),Z.catch(()=>{Z=void 0})),Z)}async function Rt(t){t!==void 0&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),t===void 0&&(t=new URL("/assets/clipoox_photo_bg-BQ0aVNY0.wasm",self.location.href));const e=mt();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));const{instance:a,module:o}=await Ot(await t,e);return bt(a)}var Et=Object.freeze({__proto__:null,content_fill:At,default:Ft,filter:kt,initSync:jt,refine_mask:vt,remove_area:St,select_subject:Tt});let st=null;function zt({wasm:t}={}){return st??=(async()=>{const e=Et,a=new URL("/assets/clipoox_photo_bg-BQ0aVNY0.wasm",self.location.href);return t?e.initSync({module:t}):typeof window>"u"&&typeof self>"u"&&typeof process<"u"&&process.versions?.node?e.initSync({module:await(await import("node:fs/promises")).readFile(a)}):await e.default({module_or_path:a}),e})().catch(e=>{throw st=null,e}),st}const Lt="clipoox:grab-text",lt=60,It={sans:"Be Vietnam Pro",serif:"Noto Serif",script:"Dancing Script",display:"Anton",mono:"Courier New"},Dt=t=>Math.max(0,Math.min(1,t)),rt=t=>Math.round(t*1e4)/1e4,Wt=t=>typeof t=="string"&&/^#[0-9a-f]{6}$/i.test(t.trim())?t.trim().toLowerCase():"#111111";function Gt(t){let e=t;if(typeof t=="string"){const r=t.replace(/^```(?:json)?\s*|\s*```$/g,"").trim();try{e=JSON.parse(r)}catch{e=null}}const a=Array.isArray(e)?e:Array.isArray(e?.lines)?e.lines:[],o=[];for(const r of a.slice(0,lt*2)){const c=typeof r?.text=="string"?r.text.replace(/\s+/g," ").trim().slice(0,300):"",l=Array.isArray(r?.box_2d)&&r.box_2d.length===4?r.box_2d.map(Number):null;if(!c||!l||l.some(x=>!Number.isFinite(x)))continue;const[s,i,n,u]=l.map(x=>Dt(x/1e3));u-i<.003||n-s<.003||o.push({text:c,box:{x:rt(i),y:rt(s),w:rt(u-i),h:rt(n-s)},color:Wt(r.color),bold:!!r.bold,italic:!!r.italic,font:It[r.font]?r.font:"sans",align:["left","center","right"].includes(r.align)?r.align:"left",block:Number.isFinite(Number(r.block))?Number(r.block):o.length})}return o.sort((r,c)=>r.box.y-c.box.y||r.box.x-c.box.x).slice(0,lt)}function Pt(t){return Array.isArray(t)?Gt({lines:t.slice(0,lt).map(e=>{const a=e?.box&&typeof e.box=="object"?e.box:null;return{...e,box_2d:a?[a.y,a.x,Number(a.y)+Number(a.h),Number(a.x)+Number(a.w)].map(o=>Number(o)*1e3):e?.box_2d}})}):[]}function Kt(t,e){const a=new Uint8Array(t.w*t.h),o=t.data;for(const r of e){const c=r.box.h*.18,l=Math.max(r.box.w*.02,c*t.h/t.w),s=Math.max(0,Math.floor((r.box.x-l)*t.w)),i=Math.min(t.w,Math.ceil((r.box.x+r.box.w+l)*t.w)),n=Math.max(0,Math.floor((r.box.y-c)*t.h)),u=Math.min(t.h,Math.ceil((r.box.y+r.box.h+c)*t.h));if(i-s<2||u-n<2)continue;const x=parseInt(r.color.slice(1,3),16),b=parseInt(r.color.slice(3,5),16),h=parseInt(r.color.slice(5,7),16),m=new Uint8Array((i-s)*(u-n));let M=0;for(let p=n;p<u;p++)for(let g=s;g<i;g++){const k=(p*t.w+g)*4,_=o[k]-x,A=o[k+1]-b,N=o[k+2]-h;_*_+A*A+N*N<5625&&(m[(p-n)*(i-s)+(g-s)]=1,M++)}const f=M/m.length,y=f<.02||f>.75,d=Math.max(1,Math.round(r.box.h*t.h/10));for(let p=n;p<u;p++)for(let g=s;g<i;g++){if(y){a[p*t.w+g]=255;continue}if(m[(p-n)*(i-s)+(g-s)])for(let k=Math.max(n,p-d);k<Math.min(u,p+d+1);k++)a.fill(255,k*t.w+Math.max(s,g-d),k*t.w+Math.min(i,g+d+1))}}return a}function Ht(t,e,a){const o={w:t.w,h:t.h,data:new Uint8ClampedArray(t.data)},r=new Uint8Array(a),c=o.data;for(const l of e){const s=l.box.h*.18,i=Math.max(l.box.w*.02,s*t.h/t.w),n=Math.max(0,Math.floor((l.box.x-i)*t.w)),u=Math.min(t.w,Math.ceil((l.box.x+l.box.w+i)*t.w)),x=Math.max(0,Math.floor((l.box.y-s)*t.h)),b=Math.min(t.h,Math.ceil((l.box.y+l.box.h+s)*t.h)),h=[0,0,0],m=[0,0,0];let M=0;for(let d=x;d<b;d++)for(let p=n;p<u;p++){const g=d*t.w+p;if(!a[g]){for(let k=0;k<3;k++){const _=t.data[g*4+k];h[k]+=_,m[k]+=_*_}M++}}if(M<40)continue;const f=h.map(d=>d/M);if(!(Math.max(...m.map((d,p)=>Math.sqrt(Math.max(0,d/M-f[p]**2))))>16))for(let d=x;d<b;d++)for(let p=n;p<u;p++){const g=d*t.w+p;r[g]&&(c[g*4]=f[0],c[g*4+1]=f[1],c[g*4+2]=f[2],r[g]=0)}}return{pic:o,rest:r}}const ot=4096,Xt=1400,w=(t,e)=>({vi:t,en:e}),gt="vertex:nano-banana-2.1",$t=Object.freeze([{id:"split_layers",group:"cut",label:w("Tách lớp","Split into layers"),free:!0,star:!0,about:w("Tách người / chủ thể thành lớp riêng, nền phía sau được lấp lại — kéo, đổi cỡ từng lớp.","People / the subject become their own layers and the background behind them is filled in — move and resize each one."),params:{mode:{type:"enum",values:["auto","people","subject","box"],default:"auto"},box:{type:"box"},fill:{type:"bool",default:!0}}},{id:"remove_bg",group:"cut",label:w("Xoá nền","Remove background"),free:!0,about:w("Giữ người / chủ thể, nền trong suốt.","Keeps people / the subject, the background becomes transparent."),params:{mode:{type:"enum",values:["auto","people","subject","box"],default:"auto"},box:{type:"box"},edge:{type:"number",min:0,max:20,default:3}}},{id:"erase",group:"cut",label:w("Tẩy vật thể","Erase object"),free:!0,about:w("Tô lên vật thừa (người qua đường, dây điện, chữ…) — chỗ đó được lấp lại từ xung quanh (Content-Aware như Photoshop).","Paint over what should go (passers-by, wires, text…) — it is rebuilt from its surroundings (Content-Aware, like Photoshop)."),params:{areas:{type:"areas"}}},{id:"expand",group:"photo",label:w("Mở rộng ảnh","Expand picture"),free:!0,about:w("Ảnh rộng ra mỗi phía, phần mới được lấp từ chính ảnh.","The picture grows on each side; the new area is filled from the picture itself."),params:{left:{type:"number",min:0,max:2,default:0},right:{type:"number",min:0,max:2,default:0},top:{type:"number",min:0,max:2,default:0},bottom:{type:"number",min:0,max:2,default:0}}},{id:"blur_bg",group:"photo",label:w("Làm mờ nền","Blur background"),free:!0,about:w("Nền mờ như máy ảnh xoá phông, người / chủ thể giữ nét.","A soft background like a portrait lens; people / the subject stay sharp."),params:{amount:{type:"number",min:0,max:1,default:.5},mode:{type:"enum",values:["auto","people","subject"],default:"auto"}}},{id:"auto_focus",group:"photo",label:w("Lấy nét tự động","Auto focus"),free:!0,about:w("Lens Blur theo chiều sâu ảnh: chủ thể nét, càng xa càng mờ, đốm sáng bokeh.","Lens Blur by the picture's depth: the subject sharp, farther things softer, bokeh highlights."),params:{amount:{type:"number",min:0,max:1,default:.5}}},{id:"relight",group:"photo",label:w("Đổi ánh sáng","Relight"),free:!0,about:w("Đặt lại hướng và màu ánh sáng của ảnh.","Sets a new direction and colour for the light."),params:{angle:{type:"number",min:-180,max:180,default:135},elevation:{type:"number",min:0,max:90,default:40},intensity:{type:"number",min:0,max:100,default:60},ambient:{type:"number",min:0,max:100,default:50},warmth:{type:"number",min:-100,max:100,default:15},softness:{type:"number",min:1,max:100,default:50}}},{id:"sharpen",group:"photo",label:w("Làm nét","Sharpen"),free:!0,about:w("Smart Sharpen: rõ chi tiết, không làm tăng nhiễu.","Smart Sharpen: crisper detail without more noise."),params:{amount:{type:"number",min:0,max:400,default:120},radius:{type:"number",min:.1,max:20,default:1.2}}},{id:"upscale",group:"photo",label:w("Upscale ×2 / ×4","Upscale ×2 / ×4"),free:!0,browser:!0,about:w("Phóng to ảnh bằng Real-ESRGAN trên máy bạn (Clipoox Upscale).","Enlarges the picture with Real-ESRGAN on your computer (Clipoox Upscale)."),params:{scale:{type:"enum",values:[2,4],default:2},model:{type:"enum",values:["photo","anime"],default:"photo"}}},{id:"denoise",group:"photo",label:w("Khử nhiễu","Reduce noise"),free:!0,about:w("Bớt hạt nhiễu ảnh chụp tối, giữ chi tiết.","Less grain in low-light photos, detail kept."),params:{strength:{type:"number",min:0,max:10,default:6},details:{type:"number",min:0,max:100,default:60}}},{id:"skin_retouch",group:"photo",label:w("Làm đẹp da","Skin retouch"),free:!0,about:w("Da mịn và sáng hơn, giữ mắt, tóc, viền.","Smoother, brighter skin; eyes, hair and edges kept."),params:{amount:{type:"number",min:0,max:1,default:.5}}},{id:"filter",group:"filters",label:w("Bộ lọc Photoshop","Photoshop filters"),free:!0,about:w("Gaussian, Motion, Tilt-Shift, Oil Paint, Mosaic… (PhotoCraft).","Gaussian, Motion, Tilt-Shift, Oil Paint, Mosaic… (PhotoCraft)."),params:{name:{type:"enum"}}},{id:"grab_text",group:"ai",label:w("Lấy chữ","Grab text"),paid:!0,generator:Lt,about:w("Chữ trong ảnh thành lớp chữ sửa được; chữ cũ được xoá khỏi ảnh.","Text in the picture becomes editable text layers; the old letters are taken out of the picture."),params:{lines:{type:"lines"}}},{id:"new_background",group:"ai",label:w("Tạo nền mới","New background"),paid:!0,generator:gt,about:w("Nền mới theo mô tả; người / chủ thể giữ nguyên từng điểm ảnh, thành lớp riêng.","A new background from your words; people / the subject keep every pixel, on their own layer."),params:{prompt:{type:"text"},mode:{type:"enum",values:["auto","people","subject","box"],default:"auto"},box:{type:"box"}}},{id:"ai_edit",group:"ai",label:w("Sửa vùng bằng AI","AI edit a region"),paid:!0,generator:gt,about:w("Tô một vùng, gõ điều muốn đổi — chỉ vùng đó thay đổi.","Paint a region, type what should change — only that region changes."),params:{prompt:{type:"text"},areas:{type:"areas"}}}]),qt=t=>$t.find(e=>e.id===t)||null,T=(t,e,a,o,r,c,l=1)=>({key:t,label:w(e,a),min:o,max:r,default:c,step:l}),pt=Object.freeze([{id:"gaussianBlur",group:"blur",label:w("Làm mờ Gaussian","Gaussian Blur"),params:[T("radius","Bán kính","Radius",.1,250,6,.1)]},{id:"motionBlur",group:"blur",label:w("Mờ chuyển động","Motion Blur"),params:[T("angle","Góc","Angle",-90,90,0),T("distance","Khoảng cách","Distance",1,999,40)]},{id:"radialBlur",group:"blur",label:w("Mờ phóng (zoom)","Radial Blur (zoom)"),params:[T("amount","Mức","Amount",1,100,20)],fixed:{method:"zoom",quality:"good",centerX:.5,centerY:.5}},{id:"tiltShift",group:"blur",label:w("Tilt-Shift (mô hình thu nhỏ)","Tilt-Shift"),params:[T("blur","Độ mờ","Blur",0,500,15),T("focus","Dải nét","Focus band",.02,1,.15,.01),T("transition","Chuyển","Transition",.02,1,.25,.01),T("angle","Góc","Angle",-90,90,0)],fixed:{centerX:.5,centerY:.5}},{id:"surfaceBlur",group:"blur",label:w("Mờ bề mặt","Surface Blur"),params:[T("radius","Bán kính","Radius",1,100,8),T("threshold","Ngưỡng","Threshold",2,255,20)]},{id:"unsharpMask",group:"sharpen",label:w("Unsharp Mask","Unsharp Mask"),params:[T("amount","Mức","Amount",1,500,100),T("radius","Bán kính","Radius",.1,250,1.5,.1),T("threshold","Ngưỡng","Threshold",0,255,0)]},{id:"highPass",group:"sharpen",label:w("High Pass","High Pass"),params:[T("radius","Bán kính","Radius",.1,250,4,.1)]},{id:"addNoise",group:"noise",label:w("Thêm hạt (film)","Add Noise (film grain)"),params:[T("amount","Mức","Amount",.1,400,8,.1)],fixed:{distribution:"gaussian",monochromatic:!0,seed:7}},{id:"median",group:"noise",label:w("Median","Median"),params:[T("radius","Bán kính","Radius",1,100,2)]},{id:"dustAndScratches",group:"noise",label:w("Bụi và vết xước","Dust & Scratches"),params:[T("radius","Bán kính","Radius",1,100,3),T("threshold","Ngưỡng","Threshold",0,255,10)]},{id:"oilPaint",group:"art",label:w("Sơn dầu","Oil Paint"),params:[T("stylization","Phong cách","Stylization",.1,10,4,.1),T("cleanliness","Độ sạch","Cleanliness",0,10,6,.1),T("scale","Tỉ lệ","Scale",.1,10,1,.1),T("bristleDetail","Chi tiết lông cọ","Bristle detail",0,10,3,.1)],fixed:{lighting:!0,angle:-60,shine:1}},{id:"mosaic",group:"art",label:w("Khảm (pixel)","Mosaic"),params:[T("cellSize","Ô","Cell size",2,200,16)]},{id:"crystallize",group:"art",label:w("Pha lê","Crystallize"),params:[T("cellSize","Ô","Cell size",3,300,20)],fixed:{seed:7}},{id:"pointillize",group:"art",label:w("Chấm điểm","Pointillize"),params:[T("cellSize","Ô","Cell size",3,300,8)],fixed:{seed:7,background:[1,1,1,1]}},{id:"colorHalftone",group:"art",label:w("Bán sắc màu","Color Halftone"),params:[T("maxRadius","Bán kính","Max radius",4,127,8)],fixed:{angles:[108,162,90,45]}},{id:"emboss",group:"art",label:w("Chạm nổi","Emboss"),params:[T("angle","Góc","Angle",-180,180,135),T("height","Độ cao","Height",1,100,3),T("amount","Mức","Amount",1,500,100)]},{id:"twirl",group:"distort",label:w("Xoắn","Twirl"),params:[T("angle","Góc","Angle",-999,999,50)]},{id:"pinch",group:"distort",label:w("Bóp / phồng","Pinch"),params:[T("amount","Mức","Amount",-100,100,50)]},{id:"diffuse",group:"art",label:w("Khuếch tán","Diffuse"),params:[],fixed:{mode:"normal",seed:7}},{id:"facet",group:"art",label:w("Mặt phẳng","Facet"),params:[]},{id:"findEdges",group:"art",label:w("Tìm cạnh","Find Edges"),params:[]},{id:"solarize",group:"art",label:w("Phơi sáng ngược","Solarize"),params:[]},{id:"desaturate",group:"art",label:w("Đen trắng","Desaturate"),params:[]},{id:"invert",group:"art",label:w("Âm bản","Invert"),params:[]}]),yt=t=>pt.find(e=>e.id===t)||null,q=(t,e,a,o)=>{const r=Number(t);return Number.isFinite(r)?Math.min(o,Math.max(a,r)):e},B=t=>{throw Object.assign(new Error(t),{status:400})};function Jt(t,e={}){const a=qt(t);a||B(`Không có công cụ "${String(t).slice(0,30)}"`),a.soon&&B(`"${a.label.vi}" sẽ có ở bản sau`);const o={};for(const[r,c]of Object.entries(a.params||{})){const l=e?.[r];c.type==="number"?o[r]=q(l,c.default,c.min,c.max):c.type==="bool"?o[r]=l===void 0?c.default:!!l:c.type==="enum"&&c.values?o[r]=c.values.includes(l)?l:c.default:c.type==="box"&&l&&typeof l=="object"?o[r]=xt(l):c.type==="text"?o[r]=typeof l=="string"?l.replace(/\s+/g," ").trim().slice(0,600):"":c.type==="lines"?o[r]=Pt(l):c.type==="areas"&&Array.isArray(l)&&(o[r]=l.slice(0,50).map(xt).filter(Boolean).map((s,i)=>({...s,shape:l[i]?.shape==="ellipse"?"ellipse":"rect"})))}if((t==="new_background"||t==="ai_edit")&&o.prompt.length<3&&B(t==="ai_edit"?"Gõ điều muốn đổi ở vùng đã tô":'Mô tả nền mới (vd. "bãi biển lúc hoàng hôn")'),t==="filter"){const r=yt(e?.name);r||B(`Bộ lọc: một trong ${pt.map(c=>c.id).join(", ")}`),o.name=r.id;for(const c of r.params)o[c.key]=q(e?.[c.key],c.default,c.min,c.max)}return o}function xt(t){if(!t||typeof t!="object")return null;const e=q(t.x,0,0,1),a=q(t.y,0,0,1),o=q(t.w,0,0,1-e),r=q(t.h,0,0,1-a);return o>0&&r>0?{x:e,y:a,w:o,h:r}:null}function Yt(t){const e=yt(t.name),a={filter:e.id,...e.fixed||{}};for(const o of e.params)a[o.key]=t[o.key]??o.default;return JSON.stringify(a)}const z=(t,e,a)=>({w:t,h:e,data:a||new Uint8ClampedArray(t*e*4)}),P=t=>t.data instanceof Uint8Array?t.data:new Uint8Array(t.data.buffer,t.data.byteOffset,t.data.byteLength),K=t=>{let e=0;for(let a=0;a<t.length;a++)t[a]>127&&e++;return e/Math.max(1,t.length)};function H(t,e,a){if(t.w===e&&t.h===a)return t;const o=z(e,a),r=t.data,c=o.data,l=t.w/e,s=t.h/a;for(let i=0;i<a;i++){const n=Math.max(0,(i+.5)*s-.5),u=Math.min(t.h-1,Math.floor(n)),x=Math.min(t.h-1,u+1),b=n-u;for(let h=0;h<e;h++){const m=Math.max(0,(h+.5)*l-.5),M=Math.min(t.w-1,Math.floor(m)),f=Math.min(t.w-1,M+1),y=m-M,d=(u*t.w+M)*4,p=(u*t.w+f)*4,g=(x*t.w+M)*4,k=(x*t.w+f)*4,_=(i*e+h)*4;for(let A=0;A<4;A++)c[_+A]=(r[d+A]*(1-y)+r[p+A]*y)*(1-b)+(r[g+A]*(1-y)+r[k+A]*y)*b}}return o}function tt(t,e,a,o,r){if(e===o&&a===r)return t;const c=new Uint8Array(o*r),l=e/o,s=a/r;for(let i=0;i<r;i++){const n=Math.max(0,(i+.5)*s-.5),u=Math.min(a-1,Math.floor(n)),x=Math.min(a-1,u+1),b=n-u;for(let h=0;h<o;h++){const m=Math.max(0,(h+.5)*l-.5),M=Math.min(e-1,Math.floor(m)),f=Math.min(e-1,M+1),y=m-M;c[i*o+h]=(t[u*e+M]*(1-y)+t[u*e+f]*y)*(1-b)+(t[x*e+M]*(1-y)+t[x*e+f]*y)*b}}return c}function Mt(t,e,a,o,r){if(o<1)return t;const c=new Float32Array(e*a),l=new Uint8Array(e*a);for(let s=0;s<a;s++)for(let i=0;i<e;i++){let n=0,u=0;for(let x=Math.max(0,i-o);x<=Math.min(e-1,i+o);x++){const b=t[s*e+x];r?b>n&&(n=b):(n+=b,u++)}c[s*e+i]=r?n:n/u}for(let s=0;s<a;s++)for(let i=0;i<e;i++){let n=0,u=0;for(let x=Math.max(0,s-o);x<=Math.min(a-1,s+o);x++){const b=c[x*e+i];r?b>n&&(n=b):(n+=b,u++)}l[s*e+i]=r?n:Math.round(n/u)}return l}const ct=(t,e,a,o)=>Mt(t,e,a,Math.round(o),!0),ht=(t,e,a,o)=>Mt(t,e,a,Math.round(o),!1);function ut(t,e,a){const o=new Int32Array(e*a),r=[],c=[];for(let l=0;l<t.length;l++){if(t[l]<=127||o[l])continue;const s=r.length+1;let i=0;for(c.push(l),o[l]=s;c.length;){const n=c.pop(),u=n%e,x=n/e|0;i++;for(const b of[u>0?n-1:-1,u<e-1?n+1:-1,x>0?n-e:-1,x<a-1?n+e:-1])b>=0&&!o[b]&&t[b]>127&&(o[b]=s,c.push(b))}r.push(i)}return{labels:o,sizes:r}}function Vt(t,e,a){const o=new Uint8Array(e*a);for(const r of t||[]){const c=Math.floor(r.x*e),l=Math.floor(r.y*a),s=Math.ceil((r.x+r.w)*e),i=Math.ceil((r.y+r.h)*a),n=(c+s)/2,u=(l+i)/2,x=Math.max(.5,(s-c)/2),b=Math.max(.5,(i-l)/2);for(let h=Math.max(0,l);h<Math.min(a,i);h++)for(let m=Math.max(0,c);m<Math.min(e,s);m++)r.shape==="ellipse"&&((m+.5-n)/x)**2+((h+.5-u)/b)**2>1||(o[h*e+m]=255)}return o}function ft(t,e,a,o){const r=new Float32Array(e*a),c=new Float32Array(e*a),l=2*o+1;for(let s=0;s<a;s++){const i=s*e;let n=0;for(let u=-o;u<=o;u++)n+=t[i+Math.min(e-1,Math.max(0,u))];for(let u=0;u<e;u++)r[i+u]=n/l,n+=t[i+Math.min(e-1,u+o+1)]-t[i+Math.max(0,u-o)]}for(let s=0;s<e;s++){let i=0;for(let n=-o;n<=o;n++)i+=r[Math.min(a-1,Math.max(0,n))*e+s];for(let n=0;n<a;n++)c[n*e+s]=i/l,i+=r[Math.min(a-1,n+o+1)*e+s]-r[Math.max(0,n-o)*e+s]}return c}function Qt(t,e){const a=Math.min(1,1024/Math.max(t.w,t.h)),o=Math.max(8,Math.round(t.w*a)),r=Math.max(8,Math.round(t.h*a)),c=o*r,l=H(t,o,r),s=tt(e,t.w,t.h,o,r),i=Float32Array.from(s,y=>y/255),n=[Math.max(4,Math.round(Math.max(o,r)/20)),Math.max(1,Math.round(Math.max(o,r)/300))],u=n.map(y=>ft(i,o,r,y)),x=[],b=[];for(let y=0;y<3;y++){const d=new Float32Array(c);for(let A=0;A<c;A++)d[A]=l.data[A*4+y]/255;let p=d,g=d,k=null,_=null;n.forEach((A,N)=>{const O=u[N],C=new Float32Array(c),F=new Float32Array(c);for(let S=0;S<c;S++)C[S]=p[S]*i[S],F[S]=g[S]*(1-i[S]);const U=ft(C,o,r,A),W=ft(F,o,r,A),L=new Float32Array(c);k=new Float32Array(c),_=new Float32Array(c);for(let S=0;S<c;S++)k[S]=U[S]/(O[S]+1e-5),_[S]=W[S]/(1-O[S]+1e-5),L[S]=Math.min(1,Math.max(0,k[S]+i[S]*(d[S]-i[S]*k[S]-(1-i[S])*_[S])));p=L,g=_}),x.push(k),b.push(_)}const h=z(t.w,t.h,new Uint8ClampedArray(t.data)),m=h.data,M=o/t.w,f=r/t.h;for(let y=0;y<t.h;y++){const d=Math.max(0,(y+.5)*f-.5),p=Math.min(r-1,Math.floor(d)),g=Math.min(r-1,p+1),k=d-p;for(let _=0;_<t.w;_++){const A=y*t.w+_,N=e[A];if(m[A*4+3]=Math.round(m[A*4+3]*N/255),N===0||N===255)continue;const O=Math.max(0,(_+.5)*M-.5),C=Math.min(o-1,Math.floor(O)),F=Math.min(o-1,C+1),U=O-C,W=p*o+C,L=p*o+F,S=g*o+C,D=g*o+F,I=N/255,R=j=>(j[W]*(1-U)+j[L]*U)*(1-k)+(j[S]*(1-U)+j[D]*U)*k;for(let j=0;j<3;j++){const X=R(x[j]),ne=R(b[j]);m[A*4+j]=Math.round(255*Math.min(1,Math.max(0,X+I*(t.data[A*4+j]/255-I*X-(1-I)*ne))))}}}return h}function Zt(t,e,a){const{labels:o,sizes:r}=ut(t,e,a);if(!r.length)return t;const c=Math.max(...r),l=new Uint8Array(r.length+1);r.forEach((f,y)=>{f>=Math.max(c*.05,e*a*8e-4)&&(l[y+1]=1)});const s=Math.min(1,512/Math.max(e,a)),i=Math.max(4,Math.round(e*s)),n=Math.max(4,Math.round(a*s)),u=Uint8Array.from(o,f=>l[f]?255:0),x=tt(ct(tt(u,e,a,i,n),i,n,Math.max(2,Math.round(Math.max(i,n)/64))),i,n,e,a),b=new Uint8Array(t);for(let f=0;f<b.length;f++)(o[f]&&!l[o[f]]||!o[f]&&x[f]<128)&&(b[f]=0);const h=Uint8Array.from(b,f=>f>127?0:255),m=ut(h,e,a),M=new Uint8Array(m.sizes.length+1);for(let f=0;f<e;f++)M[m.labels[f]]=1,M[m.labels[(a-1)*e+f]]=1;for(let f=0;f<a;f++)M[m.labels[f*e]]=1,M[m.labels[f*e+e-1]]=1;for(let f=0;f<b.length;f++){const y=m.labels[f];y&&!M[y]&&m.sizes[y-1]<c*.002&&(b[f]=255)}return b}const wt=()=>new Promise(t=>setTimeout(t,0));async function et(t,e,{mode:a="auto",box:o=null,person:r=null}={}){const c=P(e);if(a==="box"){o||B("Chọn một khung quanh vật thể trước");const l=Math.floor(o.x*e.w),s=Math.floor(o.y*e.h),i=Math.max(4,Math.round(o.w*e.w)),n=Math.max(4,Math.round(o.h*e.h)),u=new Uint8Array(i*n*4);for(let h=0;h<n;h++)u.set(c.subarray(((s+h)*e.w+l)*4,((s+h)*e.w+l+i)*4),h*i*4);const x=t.select_subject(u,i,n),b=new Uint8Array(e.w*e.h);for(let h=0;h<n;h++)b.set(x.subarray(h*i,(h+1)*i),(s+h)*e.w+l);return b}return r&&r.length===e.w*e.h&&(a==="people"||a==="auto"&&K(r)>.004)?r:(a==="people"&&B('Không tìm thấy người trong ảnh — thử "Chủ thể" hoặc khoanh vùng vật thể'),t.select_subject(c,e.w,e.h))}const _t=(t,e,a,o)=>t.refine_mask(P(e),e.w,e.h,a,Math.max(1,o),!0,.6,15,0);async function nt(t,e,a,{grow:o=0,contentAware:r=!1,seed:c=1}={}){const l=Math.min(1,Xt/Math.max(e.w,e.h)),s=Math.max(8,Math.round(e.w*l)),i=Math.max(8,Math.round(e.h*l)),n=H(e,s,i),u=tt(a,e.w,e.h,s,i);for(let d=0;d<u.length;d++)u[d]=u[d]>40?255:0;await wt();const x=r?t.content_fill(P(n),s,i,u,c):t.remove_area(P(n),s,i,u,Math.round(o*l),c);if(l===1)return z(e.w,e.h,new Uint8ClampedArray(x));const b=H(z(s,i,new Uint8ClampedArray(x)),e.w,e.h),h=Math.max(1,Math.round(2/l)),m=ht(ct(a,e.w,e.h,o+h),e.w,e.h,h),M=z(e.w,e.h,new Uint8ClampedArray(e.data)),f=M.data,y=b.data;for(let d=0;d<m.length;d++){const p=m[d]/255;if(!(p<=0)){for(let g=0;g<3;g++)f[d*4+g]=f[d*4+g]*(1-p)+y[d*4+g]*p;f[d*4+3]=Math.max(f[d*4+3],y[d*4+3]*p)}}return M}function te(t,e){const a=new Uint8Array(t.w*t.h),o=t.data;for(let r=0;r<a.length;r++){const c=o[r*4],l=o[r*4+1],s=o[r*4+2],i=128-.168736*c-.331264*l+.5*s,n=128+.5*c-.418688*l-.081312*s,u=Math.max(0,Math.abs(i-105)-18)+Math.max(0,Math.abs(n-152)-20);a[r]=u>25?0:Math.round(255*(1-u/25))*(e?e[r]/255:1)}return a}async function ee(t,e,a,o={},{person:r=null,depth:c=null,hole:l=null,onProgress:s=()=>{}}={}){const i=Jt(a,o);(!e||e.w<8||e.h<8)&&B("Ảnh quá nhỏ"),Math.max(e.w,e.h)>ot&&B(`Ảnh lớn hơn ${ot} px — thu nhỏ trước`);const n=e,u=Math.max(n.w,n.h);if(s(.05),a==="upscale"&&B("Upscale chạy trong trình duyệt (Image Studio) hoặc `npx clipoox upscale` trên máy bạn"),a==="split_layers"||a==="remove_bg"){let h=await et(t,n,{mode:i.mode,box:i.box,person:r});K(h)<.002&&B("Không tìm thấy người / chủ thể rõ ràng — thử khoanh vùng vật thể"),s(.3,"edge"),h=_t(t,n,h,a==="remove_bg"?Math.max(1,i.edge):Math.max(2,Math.round(u/400))),h=Zt(h,n.w,n.h),await wt(),s(.38,"edge");const m=Qt(n,h);if(a==="remove_bg")return s(1),{kind:"replace",pic:m,alpha:!0};const{labels:M,sizes:f}=ut(h,n.w,n.h),y=Math.max(...f),d=f.map((A,N)=>({id:N+1,s:A})).filter(A=>A.s>=Math.max(y*.08,n.w*n.h*.002)).sort((A,N)=>N.s-A.s).slice(0,8);d.length||B("Không tìm thấy người / chủ thể rõ ràng");const p=Math.max(3,Math.round(u/250)),g=ct(Uint8Array.from(M,A=>A?255:0),n.w,n.h,p),k=d.map((A,N)=>{let O=n.w,C=n.h,F=0,U=0;for(let D=0;D<M.length;D++)if(M[D]===A.id){const I=D%n.w,R=D/n.w|0;I<O&&(O=I),I>F&&(F=I),R<C&&(C=R),R>U&&(U=R)}O=Math.max(0,O-p),C=Math.max(0,C-p),F=Math.min(n.w-1,F+p),U=Math.min(n.h-1,U+p);const W=F-O+1,L=U-C+1,S=z(W,L);for(let D=0;D<L;D++)for(let I=0;I<W;I++){const R=(C+D)*n.w+O+I,j=M[R];if(j&&j!==A.id||!j&&!g[R])continue;const X=(D*W+I)*4;S.data[X]=m.data[R*4],S.data[X+1]=m.data[R*4+1],S.data[X+2]=m.data[R*4+2],S.data[X+3]=m.data[R*4+3]}return{pic:S,x:O,y:C,label:d.length>1?N+1:0}});s(.45,"fill");const _=i.fill===!1?n:await nt(t,n,Uint8Array.from(h,A=>A>40?255:0),{grow:p});return s(1),{kind:"split",background:_,cutouts:k}}if(a==="grab_text"){i.lines.length||B("Không thấy chữ trong ảnh");const h=Kt(n,i.lines);s(.2,"fill");const m=Ht(n,i.lines,h),M=K(m.rest)>0?await nt(t,m.pic,m.rest,{grow:Math.max(1,Math.round(u/800))}):m.pic;return s(1),{kind:"replace",pic:M,texts:i.lines}}if((a==="new_background"||a==="ai_edit")&&B("Công cụ AI chạy qua Image Studio hoặc MCP photo_tool (có báo giá trước)"),a==="erase"){const h=l&&l.length===n.w*n.h?l:i.areas?.length?Vt(i.areas,n.w,n.h):null;(!h||K(h)<=0)&&B("Tô lên vật cần tẩy trước"),s(.2,"fill");const m=await nt(t,n,h,{grow:Math.max(2,Math.round(u/500))});return s(1),{kind:"replace",pic:m}}if(a==="expand"){const h=Math.round(i.left*n.w),m=Math.round(i.right*n.w),M=Math.round(i.top*n.h),f=Math.round(i.bottom*n.h);h+m+M+f||B("Chọn phía cần mở rộng");const y=n.w+h+m,d=n.h+M+f;Math.max(y,d)>ot&&B(`Ảnh sau khi mở rộng lớn hơn ${ot} px`);const p=z(y,d),g=new Uint8Array(y*d).fill(255);for(let _=0;_<n.h;_++)p.data.set(n.data.subarray(_*n.w*4,(_+1)*n.w*4),((_+M)*y+h)*4),g.fill(0,(_+M)*y+h,(_+M)*y+h+n.w);s(.15,"fill");const k=await nt(t,p,g,{contentAware:!0});for(let _=0;_<n.h;_++)k.data.set(n.data.subarray(_*n.w*4,(_+1)*n.w*4),((_+M)*y+h)*4);for(let _=0;_<g.length;_++)g[_]&&(k.data[_*4+3]=255);return s(1),{kind:"replace",pic:k,offset:{left:h,top:M,right:m,bottom:f}}}if(a==="blur_bg"){let h=await et(t,n,{mode:i.mode,person:r});K(h)<.002&&B("Không tìm thấy người / chủ thể để giữ nét"),h=_t(t,n,h,Math.max(2,Math.round(u/400))),s(.3,"fill");const m=await nt(t,n,Uint8Array.from(h,k=>k>40?255:0),{grow:Math.max(3,Math.round(u/250))});s(.7,"blur");const M=Math.min(1,1600/u),f=Math.round(n.w*M),y=Math.round(n.h*M),d=Math.max(1,i.amount*.025*Math.max(f,y)),p=H(z(f,y,new Uint8ClampedArray(t.filter(JSON.stringify({filter:"gaussianBlur",radius:d}),P(H(m,f,y)),f,y,void 0))),n.w,n.h),g=z(n.w,n.h,new Uint8ClampedArray(n.data));for(let k=0;k<h.length;k++){const _=h[k]/255;for(let A=0;A<3;A++)g.data[k*4+A]=n.data[k*4+A]*_+p.data[k*4+A]*(1-_)}return s(1),{kind:"replace",pic:g}}if(a==="auto_focus"){let h=c&&c.length===n.w*n.h?c:null;if(!h){const U=await et(t,n,{person:r});h=ht(U,n.w,n.h,Math.max(2,Math.round(u/120)))}const m=await et(t,n,{person:r});let M=0,f=0;for(let U=0;U<m.length;U++)m[U]>127&&(M+=h[U],f++);const y=f?Math.round(M/f):255,d=Math.min(1,2048/u),p=Math.round(n.w*d),g=Math.round(n.h*d),k=H(n,p,g),_=tt(h,n.w,n.h,p,g),A=new Uint8Array(P(k));for(let U=0;U<_.length;U++)A[U*4+3]=_[U];s(.3,"blur");const N=Math.max(1,Math.min(100,i.amount*.03*Math.max(p,g))),O=t.filter(JSON.stringify({filter:"lensBlur",radius:N,blades:6,curvature:60,rotation:0,depth:"transparency",focalDistance:y,invertDepth:!1,brightness:15,threshold:230,noise:0,distribution:"uniform",monochromatic:!1,seed:1}),A,p,g,void 0),C=H(z(p,g,new Uint8ClampedArray(O)),n.w,n.h),F=z(n.w,n.h,new Uint8ClampedArray(n.data));for(let U=0;U<h.length;U++){const W=Math.min(1,Math.abs(h[U]-y)/40);for(let L=0;L<3;L++)F.data[U*4+L]=n.data[U*4+L]*(1-W)+C.data[U*4+L]*W}return s(1),{kind:"replace",pic:F}}if(a==="skin_retouch"){const h=await et(t,n,{person:r}),m=ht(te(n,K(h)>.002?h:null),n.w,n.h,Math.max(1,Math.round(u/500)));K(m)<.001&&B("Không thấy vùng da trong ảnh");const M=Uint8Array.from(m,d=>Math.round(d*i.amount));s(.3,"smooth");const f=t.filter(JSON.stringify({filter:"surfaceBlur",radius:Math.max(2,Math.round(u/180)),threshold:18+i.amount*14}),P(n),n.w,n.h,M),y=z(n.w,n.h,new Uint8ClampedArray(f));for(let d=0;d<M.length;d++){const p=M[d]/255*.12;if(p)for(let g=0;g<3;g++)y.data[d*4+g]+=(255-y.data[d*4+g])*p}return s(1),{kind:"replace",pic:y}}const x=a==="relight"?JSON.stringify({filter:"relight",...i}):a==="sharpen"?JSON.stringify({filter:"smartSharpen",amount:i.amount,radius:i.radius,reduceNoise:10}):a==="denoise"?JSON.stringify({filter:"reduceNoise",strength:i.strength,preserveDetails:i.details,reduceColorNoise:45,sharpenDetails:20,removeJpegArtifact:!0}):a==="filter"?Yt(i):null;x||B(`Công cụ "${a}" chưa chạy được ở đây`),s(.2);const b=t.filter(x,P(n),n.w,n.h,void 0);return s(1),{kind:"replace",pic:z(n.w,n.h,new Uint8ClampedArray(b))}}self.onmessage=async t=>{const{id:e,pic:a,tool:o,params:r,person:c,depth:l,hole:s}=t.data;try{const i=await zt(),n=await ee(i,a,o,r,{person:c,depth:l,hole:s,onProgress:(x,b)=>self.postMessage({id:e,progress:x,note:b})}),u=[];if(n.kind==="split"){u.push(n.background.data.buffer);for(const x of n.cutouts)u.push(x.pic.data.buffer)}else u.push(n.pic.data.buffer);self.postMessage({id:e,result:n},[...new Set(u)])}catch(i){self.postMessage({id:e,error:i?.message||String(i)})}}})();
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/peopleMatte-C1hruEM6.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/i18n-ClNt3LKg.js","assets/index-CKtv7gGE.js","assets/personHq-CBP8v_cw.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/depthEstimate-CfwX-tXP.js","assets/engine-Y-GotDIy.js","assets/store-Cug4GGcP.js","assets/id3-arvEpAg7.js","assets/output-p-Q7qous.js","assets/conversion-4rhF3xRJ.js"])))=>i.map(i=>d[i]);
2
+ import{_ as E}from"./titleFrameBudget-h4nOQ5u9.js";import{u as T,e as B,r as at,b as et}from"./api-CZoVJ9Fy.js";import{t as r}from"./i18n-ClNt3LKg.js";import{b as M,c as G,G as V,d as D,e as W,f as nt,g as rt,h as H,m as it,i as X,j as ot,k as ct,r as U,l as st}from"./photoTools-DmUh69Qk.js";import"./index-CKtv7gGE.js";let f=null,ut=0;const x=new Map;function lt(){return f||(f=new Worker(new URL("/assets/photo.worker-DK_ulTzR.js",import.meta.url),{type:"module"}),f.onmessage=t=>{const a=t.data,e=x.get(a.id);if(e){if(a.progress!==void 0)return e.progress?.(a.progress);x.delete(a.id),a.error?e.bad(Object.assign(new Error(a.error),{user:!0})):e.ok(a.result)}},f.onerror=t=>{for(const a of x.values())a.bad(new Error(t.message||"photo worker failed"));x.clear(),f=null},f)}function yt(){f?.terminate(),f=null;for(const t of x.values())t.bad(Object.assign(new Error(r("Đã dừng")),{cancelled:!0}));x.clear()}function N(t,a,e,n,i){const u=++ut,o=lt();return new Promise((c,s)=>{x.set(u,{ok:c,bad:s,progress:i}),o.postMessage({id:u,pic:t,tool:a,params:e,...n},[t.data.buffer])})}async function L(t){const a=await(await fetch(t)).blob(),e=await createImageBitmap(a),n=Math.min(1,W/Math.max(e.width,e.height)),i=Math.max(1,Math.round(e.width*n)),u=Math.max(1,Math.round(e.height*n)),o=new OffscreenCanvas(i,u),c=o.getContext("2d",{willReadFrequently:!0});return c.drawImage(e,0,0,i,u),e.close?.(),{w:i,h:u,data:new Uint8ClampedArray(c.getImageData(0,0,i,u).data)}}const j=(t,a=0)=>{const e=a?Math.min(1,a/Math.max(t.w,t.h)):1,n=Math.round(t.w*e),i=Math.round(t.h*e),u=new OffscreenCanvas(t.w,t.h);if(u.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(t.data),t.w,t.h),0,0),e===1)return u;const c=new OffscreenCanvas(n,i),s=c.getContext("2d");return s.imageSmoothingQuality="high",s.drawImage(u,0,0,n,i),c};async function q(t){let a=!1;for(let n=3;n<t.data.length;n+=4)if(t.data[n]<255){a=!0;break}const e=j(t);return a?{blob:await e.convertToBlob({type:"image/png"}),ext:"png"}:{blob:await e.convertToBlob({type:"image/jpeg",quality:.92}),ext:"jpg"}}async function ht(t,a){try{const{peopleOfPicture:e}=await E(async()=>{const{peopleOfPicture:i}=await import("./peopleMatte-C1hruEM6.js");return{peopleOfPicture:i}},__vite__mapDeps([0,1,2,3])),n=await e(j(t,1024),(i,u)=>{i==="download"&&a?.(.08+.12*(u||0),r("Đang tải model tách người (một lần, 26 MB)…"))});return U(n.data,n.w,n.h,t.w,t.h)}catch(e){console.warn("people model unavailable — MediaPipe",e)}try{const{personProbability:e}=await E(async()=>{const{personProbability:o}=await import("./personHq-CBP8v_cw.js").then(c=>c.i);return{personProbability:o}},__vite__mapDeps([4,1,5,6,2,3])),n=j(t,768),i=await e(n),u=new Uint8Array(i.width*i.height);for(let o=0;o<u.length;o++)u[o]=Math.round(Math.max(0,Math.min(1,i.data[o]))*255);return U(u,i.width,i.height,t.w,t.h)}catch(e){return console.warn("people mask unavailable",e),null}}function z(t,a,e){const n=nt(t,a,e);return{x:(t.x-n.x)/n.k,y:(t.y-n.y)/n.k,w:t.w/n.k,h:t.h/n.k}}function K(t,a,e,n){const i=z(t,e,n),u=new OffscreenCanvas(e,n),o=u.getContext("2d",{willReadFrequently:!0});o.drawImage(a,i.x,i.y,i.w,i.h);const c=o.getImageData(0,0,e,n).data,s=new Uint8Array(e*n);for(let l=0;l<s.length;l++)s[l]=c[l*4+3]>8?255:0;return s}async function J(t,a,e,{hole:n=null,onProgress:i}){const u=["split_layers","remove_bg","blur_bg","auto_focus","skin_retouch"].includes(a)&&e.mode!=="subject"&&e.mode!=="box";let o=null,c=null;if(u&&(i(.08,r("Đang tìm người trong ảnh…")),o=await ht(t,i)),a==="auto_focus")try{i(.12,r("Đang đọc chiều sâu ảnh…"));const{depthOfPicture:l}=await E(async()=>{const{depthOfPicture:p}=await import("./depthEstimate-CfwX-tXP.js");return{depthOfPicture:p}},__vite__mapDeps([7,1,2,3])),w=await l(j(t,1024),(p,g)=>i(.12+(p==="download"?.1*(g||0):.12),p==="download"?r("Đang tải model chiều sâu (một lần)…"):r("Đang đọc chiều sâu ảnh…")));c=U(w.data,w.w,w.h,t.w,t.h)}catch(l){console.warn("depth unavailable — focus by the subject",l)}const s={split_layers:r("Đang tách lớp…"),remove_bg:r("Đang xoá nền…"),erase:r("Đang tẩy và lấp lại…"),expand:r("Đang mở rộng ảnh…")}[a]||r("Đang xử lý ảnh…");return N(t,a,e,{person:o,depth:c,hole:n},l=>i(.25+.6*l,s))}async function _t({layer:t,tool:a,params:e,brush:n,box:i,layerIndex:u,onProgress:o}){if(!t.url)throw new Error(r("Lớp ảnh này chưa có ảnh"));o(.02,r("Đang đọc ảnh…"));const c=await L(t.url),s=c.w,l=c.h;let w;const p=a==="erase"&&n?K(t,n,s,l):null,g={...e};if(i&&g.mode==="box"){const m=z(t,s,l),b=Math.max(0,m.x+i.x*m.w),h=Math.max(0,m.y+i.y*m.h);g.box={x:b/s,y:h/l,w:Math.min(s-b,i.w*m.w)/s,h:Math.min(l-h,i.h*m.h)/l}}if(Q.has(a))return dt(t,c,a,g,{brush:n,layerIndex:u,onProgress:o});if(a==="upscale"){const m=await E(()=>import("./store-Cug4GGcP.js"),[]);await m.upscaleInstalled()||await m.installUpscalePack((y,O)=>o(.05+.25*y/O,r("Đang cài Clipoox Upscale Plugin…")));const h=await(await E(()=>import("./engine-Y-GotDIy.js"),__vite__mapDeps([8,1,9,10,11,12]))).upscaleImage(t.url,{scale:g.scale===4?4:2,model:g.model==="anime"?"anime":"photo",onProgress:y=>o(.3+.6*y.fraction,r("Đang upscale trên máy bạn…"))});o(.95,r("Đang lưu kết quả…"));const d=await T(new File([h.blob],`upscale-${h.width}x${h.height}.${h.blob.type==="image/png"?"png":"jpg"}`,{type:h.blob.type}),void 0,"image");return M(t,s,l,{kind:"replace",pic:{w:h.width,h:h.height,data:new Uint8ClampedArray(0)}},{main:d},a)}w=await J(c,a,g,{hole:p,onProgress:o}),w=G(w,t,s,l),o(.88,r("Đang lưu kết quả…"));const I=w.kind==="split"?w.background:w.pic,A=await q(I),$=(t.name||"photo").replace(/[^\p{L}\p{N} _-]+/gu,"").trim().slice(0,30)||"photo",v={index:u,main:await T(new File([A.blob],`${$} ${a}.${A.ext}`,{type:A.blob.type}),void 0,"image"),cutouts:[]};if(w.kind==="split")for(const[m,b]of w.cutouts.entries()){const h=await q(b.pic);v.cutouts.push(await T(new File([h.blob],`${$} layer ${m+1}.${h.ext}`,{type:h.blob.type}),void 0,"image"))}return o(1,r("Xong")),M(t,s,l,w,v,a,{names:{cutout:r("Chủ thể"),background:`${t.name||r("Ảnh")} · ${r("nền")}`}})}const Q=new Set(["grab_text","new_background","ai_edit"]);async function wt(t){const a=new Image;a.crossOrigin="anonymous",a.src=t,await a.decode();const e=Math.min(1,W/Math.max(a.naturalWidth,a.naturalHeight));return{w:Math.round(a.naturalWidth*e),h:Math.round(a.naturalHeight*e)}}const P=st;async function kt(t,a){if(!Q.has(t)||!a.url)return null;if(t==="grab_text")return(await B(V,{imageUrl:a.url})).credits;const{w:e,h:n}=await wt(a.url);return(await B(D,{prompt:"-",...P(e,n),count:1})).credits}async function k(t,a){const e=await q(t);return T(new File([e.blob],`${a}.${e.ext}`,{type:e.blob.type}),void 0,"image")}async function R(t,a,e,n,i,u){const o=await at(t,a),c=Date.now(),s=24e4;for(let l=0;;){await new Promise(p=>setTimeout(p,2500)),e(n+(i-n)*Math.min(.95,(Date.now()-c)/4e4),u);let w=null;try{w=await et(o.jobId,!0),l=0}catch(p){if(++l>5)throw p}if(w?.status==="succeeded")return w.output;if(w?.status==="failed")throw Object.assign(new Error(r(String(w.error||"AI không chạy được — đã hoàn credit"))),{user:!0});if(Date.now()-c>s)throw Object.assign(new Error(r("AI chạy quá lâu — thử lại sau (credit được hoàn nếu job lỗi)")),{user:!0})}}async function dt(t,a,e,n,{brush:i,layerIndex:u,onProgress:o}){if(!t.url||!/^https:/.test(t.url))throw Object.assign(new Error(r("Ảnh cần được lưu lên Clipoox trước (tải ảnh lên)")),{user:!0});const c=a.w,s=a.h,l=(t.name||"photo").replace(/[^\p{L}\p{N} _-]+/gu,"").trim().slice(0,30)||"photo",w={cutout:r("Chủ thể"),background:`${t.name||r("Ảnh")} · ${r("nền")}`};if(e==="grab_text"){const h=await R(V,{imageUrl:t.url},o,.05,.5,r("AI đang đọc chữ trong ảnh…")),d=Array.isArray(h?.lines)?h.lines:[];if(!d.length)throw Object.assign(new Error(r("Không thấy chữ nào trong ảnh")),{user:!0});const y=await N(a,"grab_text",{lines:d},{},C=>o(.5+.35*C,r("Đang xoá chữ cũ khỏi ảnh…")));o(.9,r("Đang lưu kết quả…"));const O=await k(y.pic,`${l} grab_text`);return o(1,r("Xong")),M(t,c,s,y,{index:u,main:O,cutouts:[]},e,{names:w})}const p=String(n.prompt||"");if(e==="ai_edit"){const h=i?K(t,i,c,s):Array.isArray(n.areas)&&n.areas.length?rt(n.areas,c,s):null;if(!h||!h.some(_=>_>127))throw Object.assign(new Error(r("Tô lên vùng cần sửa trước")),{user:!0});const d=H(a),y=P(c,s);o(.05,r("Đang chuẩn bị ảnh…"));const O=new Uint8Array(d.pic.w*d.pic.h);for(let _=0;_<s;_++)O.set(h.subarray(_*c,(_+1)*c),(_+d.y)*d.pic.w+d.x);const[C,Y]=[await k(d.pic,`${l} ai-edit`),await k(it(d.pic,O),`${l} ai-edit region`)],S=await R(D,{prompt:X("ai_edit",p),imageUrls:[C.url,Y.url],...y},o,.12,.8,r("AI đang sửa vùng đã tô…"));if(!S?.url)throw Object.assign(new Error(r("AI không trả về ảnh")),{user:!0});const Z=await L(S.url),F={kind:"replace",pic:ot(a,Z,d,h)};o(.9,r("Đang lưu kết quả…"));const tt=await k(F.pic,`${l} ai_edit`);return o(1,r("Xong")),M(t,c,s,F,{index:u,main:tt,cutouts:[]},e,{names:w})}const g=G(await J(a,"split_layers",{mode:n.mode,box:n.box},{onProgress:(h,d)=>o(h*.4,d)}),t,c,s);if(g.kind!=="split")throw new Error("split failed");const I=H(g.background),A=P(c,s),$=await k(I.pic,`${l} background ref`),v=await R(D,{prompt:X("new_background",p),imageUrls:[$.url],...A},o,.45,.85,r("AI đang vẽ nền mới…"));if(!v?.url)throw Object.assign(new Error(r("AI không trả về ảnh")),{user:!0});const m=ct(await L(v.url),I,c,s);o(.9,r("Đang lưu kết quả…"));const b={index:u,main:await k(m,`${l} new background`),cutouts:[]};for(const[h,d]of g.cutouts.entries())b.cutouts.push(await k(d.pic,`${l} layer ${h+1}`));return o(1,r("Xong")),M(t,c,s,{kind:"split",cutouts:g.cutouts},b,e,{names:w})}export{Q as PAID_TOOLS,yt as cancelPhoto,q as encodePicture,J as photoOnPicture,kt as photoToolPrice,L as readPicture,_t as runPhotoOnLayer};
@@ -0,0 +1 @@
1
+ const Y="clipoox:grab-text",G={sans:"Be Vietnam Pro",serif:"Noto Serif",script:"Dancing Script",display:"Anton",mono:"Courier New"};function V(t,e,n,a,{at:o,rect:r}){const h=r,d=[],u=t.x,m=t.y,s=t.x+t.w,l=t.y+t.h,c=(t.rotation||0)*Math.PI/180,p=t.x+t.w/2,f=t.y+t.h/2,b=(g,y)=>c?{x:p+(g-p)*Math.cos(c)-(y-f)*Math.sin(c),y:f+(g-p)*Math.sin(c)+(y-f)*Math.cos(c)}:{x:g,y};let M=0;for(const g of a){const y=h.x+g.box.x*e*h.k,z=h.y+g.box.y*n*h.k,A=g.box.w*e*h.k,B=g.box.h*n*h.k,S=y+A/2,k=z+B/2;if(S<u||S>s||k<m||k>l)continue;const C=Math.max(6,Math.round(B/1.2*10)/10),P=Math.round(A*1.12+C*.4),R=Math.round(C*1.25),$=g.align==="center"?S-P/2:g.align==="right"?y+A-P:y,q=k-R/2,U=b($+P/2,q+R/2);d.push({op:"add",index:o+M++,layer:{type:"text",name:g.text.slice(0,40),text:g.text,font:G[g.font]||G.sans,size:C,weight:g.font==="display"?400:g.bold?700:400,...g.italic?{italic:!0}:{},color:g.color,align:g.align,lineHeight:1.2,x:Math.round(U.x-P/2),y:Math.round(U.y-R/2),w:P,h:R,rotation:t.rotation||0}})}return d}const W=4096,i=(t,e)=>({vi:t,en:e}),O="vertex:nano-banana-2.1",J=Object.freeze([{id:"split_layers",group:"cut",label:i("Tách lớp","Split into layers"),free:!0,star:!0,about:i("Tách người / chủ thể thành lớp riêng, nền phía sau được lấp lại — kéo, đổi cỡ từng lớp.","People / the subject become their own layers and the background behind them is filled in — move and resize each one."),params:{mode:{type:"enum",values:["auto","people","subject","box"],default:"auto"},box:{type:"box"},fill:{type:"bool",default:!0}}},{id:"remove_bg",group:"cut",label:i("Xoá nền","Remove background"),free:!0,about:i("Giữ người / chủ thể, nền trong suốt.","Keeps people / the subject, the background becomes transparent."),params:{mode:{type:"enum",values:["auto","people","subject","box"],default:"auto"},box:{type:"box"},edge:{type:"number",min:0,max:20,default:3}}},{id:"erase",group:"cut",label:i("Tẩy vật thể","Erase object"),free:!0,about:i("Tô lên vật thừa (người qua đường, dây điện, chữ…) — chỗ đó được lấp lại từ xung quanh (Content-Aware như Photoshop).","Paint over what should go (passers-by, wires, text…) — it is rebuilt from its surroundings (Content-Aware, like Photoshop)."),params:{areas:{type:"areas"}}},{id:"expand",group:"photo",label:i("Mở rộng ảnh","Expand picture"),free:!0,about:i("Ảnh rộng ra mỗi phía, phần mới được lấp từ chính ảnh.","The picture grows on each side; the new area is filled from the picture itself."),params:{left:{type:"number",min:0,max:2,default:0},right:{type:"number",min:0,max:2,default:0},top:{type:"number",min:0,max:2,default:0},bottom:{type:"number",min:0,max:2,default:0}}},{id:"blur_bg",group:"photo",label:i("Làm mờ nền","Blur background"),free:!0,about:i("Nền mờ như máy ảnh xoá phông, người / chủ thể giữ nét.","A soft background like a portrait lens; people / the subject stay sharp."),params:{amount:{type:"number",min:0,max:1,default:.5},mode:{type:"enum",values:["auto","people","subject"],default:"auto"}}},{id:"auto_focus",group:"photo",label:i("Lấy nét tự động","Auto focus"),free:!0,about:i("Lens Blur theo chiều sâu ảnh: chủ thể nét, càng xa càng mờ, đốm sáng bokeh.","Lens Blur by the picture's depth: the subject sharp, farther things softer, bokeh highlights."),params:{amount:{type:"number",min:0,max:1,default:.5}}},{id:"relight",group:"photo",label:i("Đổi ánh sáng","Relight"),free:!0,about:i("Đặt lại hướng và màu ánh sáng của ảnh.","Sets a new direction and colour for the light."),params:{angle:{type:"number",min:-180,max:180,default:135},elevation:{type:"number",min:0,max:90,default:40},intensity:{type:"number",min:0,max:100,default:60},ambient:{type:"number",min:0,max:100,default:50},warmth:{type:"number",min:-100,max:100,default:15},softness:{type:"number",min:1,max:100,default:50}}},{id:"sharpen",group:"photo",label:i("Làm nét","Sharpen"),free:!0,about:i("Smart Sharpen: rõ chi tiết, không làm tăng nhiễu.","Smart Sharpen: crisper detail without more noise."),params:{amount:{type:"number",min:0,max:400,default:120},radius:{type:"number",min:.1,max:20,default:1.2}}},{id:"upscale",group:"photo",label:i("Upscale ×2 / ×4","Upscale ×2 / ×4"),free:!0,browser:!0,about:i("Phóng to ảnh bằng Real-ESRGAN trên máy bạn (Clipoox Upscale).","Enlarges the picture with Real-ESRGAN on your computer (Clipoox Upscale)."),params:{scale:{type:"enum",values:[2,4],default:2},model:{type:"enum",values:["photo","anime"],default:"photo"}}},{id:"denoise",group:"photo",label:i("Khử nhiễu","Reduce noise"),free:!0,about:i("Bớt hạt nhiễu ảnh chụp tối, giữ chi tiết.","Less grain in low-light photos, detail kept."),params:{strength:{type:"number",min:0,max:10,default:6},details:{type:"number",min:0,max:100,default:60}}},{id:"skin_retouch",group:"photo",label:i("Làm đẹp da","Skin retouch"),free:!0,about:i("Da mịn và sáng hơn, giữ mắt, tóc, viền.","Smoother, brighter skin; eyes, hair and edges kept."),params:{amount:{type:"number",min:0,max:1,default:.5}}},{id:"filter",group:"filters",label:i("Bộ lọc Photoshop","Photoshop filters"),free:!0,about:i("Gaussian, Motion, Tilt-Shift, Oil Paint, Mosaic… (PhotoCraft).","Gaussian, Motion, Tilt-Shift, Oil Paint, Mosaic… (PhotoCraft)."),params:{name:{type:"enum"}}},{id:"grab_text",group:"ai",label:i("Lấy chữ","Grab text"),paid:!0,generator:Y,about:i("Chữ trong ảnh thành lớp chữ sửa được; chữ cũ được xoá khỏi ảnh.","Text in the picture becomes editable text layers; the old letters are taken out of the picture."),params:{lines:{type:"lines"}}},{id:"new_background",group:"ai",label:i("Tạo nền mới","New background"),paid:!0,generator:O,about:i("Nền mới theo mô tả; người / chủ thể giữ nguyên từng điểm ảnh, thành lớp riêng.","A new background from your words; people / the subject keep every pixel, on their own layer."),params:{prompt:{type:"text"},mode:{type:"enum",values:["auto","people","subject","box"],default:"auto"},box:{type:"box"}}},{id:"ai_edit",group:"ai",label:i("Sửa vùng bằng AI","AI edit a region"),paid:!0,generator:O,about:i("Tô một vùng, gõ điều muốn đổi — chỉ vùng đó thay đổi.","Paint a region, type what should change — only that region changes."),params:{prompt:{type:"text"},areas:{type:"areas"}}}]),x=(t,e,n,a,o,r,h=1)=>({key:t,label:i(e,n),min:a,max:o,default:r,step:h}),H=Object.freeze([{id:"gaussianBlur",group:"blur",label:i("Làm mờ Gaussian","Gaussian Blur"),params:[x("radius","Bán kính","Radius",.1,250,6,.1)]},{id:"motionBlur",group:"blur",label:i("Mờ chuyển động","Motion Blur"),params:[x("angle","Góc","Angle",-90,90,0),x("distance","Khoảng cách","Distance",1,999,40)]},{id:"radialBlur",group:"blur",label:i("Mờ phóng (zoom)","Radial Blur (zoom)"),params:[x("amount","Mức","Amount",1,100,20)],fixed:{method:"zoom",quality:"good",centerX:.5,centerY:.5}},{id:"tiltShift",group:"blur",label:i("Tilt-Shift (mô hình thu nhỏ)","Tilt-Shift"),params:[x("blur","Độ mờ","Blur",0,500,15),x("focus","Dải nét","Focus band",.02,1,.15,.01),x("transition","Chuyển","Transition",.02,1,.25,.01),x("angle","Góc","Angle",-90,90,0)],fixed:{centerX:.5,centerY:.5}},{id:"surfaceBlur",group:"blur",label:i("Mờ bề mặt","Surface Blur"),params:[x("radius","Bán kính","Radius",1,100,8),x("threshold","Ngưỡng","Threshold",2,255,20)]},{id:"unsharpMask",group:"sharpen",label:i("Unsharp Mask","Unsharp Mask"),params:[x("amount","Mức","Amount",1,500,100),x("radius","Bán kính","Radius",.1,250,1.5,.1),x("threshold","Ngưỡng","Threshold",0,255,0)]},{id:"highPass",group:"sharpen",label:i("High Pass","High Pass"),params:[x("radius","Bán kính","Radius",.1,250,4,.1)]},{id:"addNoise",group:"noise",label:i("Thêm hạt (film)","Add Noise (film grain)"),params:[x("amount","Mức","Amount",.1,400,8,.1)],fixed:{distribution:"gaussian",monochromatic:!0,seed:7}},{id:"median",group:"noise",label:i("Median","Median"),params:[x("radius","Bán kính","Radius",1,100,2)]},{id:"dustAndScratches",group:"noise",label:i("Bụi và vết xước","Dust & Scratches"),params:[x("radius","Bán kính","Radius",1,100,3),x("threshold","Ngưỡng","Threshold",0,255,10)]},{id:"oilPaint",group:"art",label:i("Sơn dầu","Oil Paint"),params:[x("stylization","Phong cách","Stylization",.1,10,4,.1),x("cleanliness","Độ sạch","Cleanliness",0,10,6,.1),x("scale","Tỉ lệ","Scale",.1,10,1,.1),x("bristleDetail","Chi tiết lông cọ","Bristle detail",0,10,3,.1)],fixed:{lighting:!0,angle:-60,shine:1}},{id:"mosaic",group:"art",label:i("Khảm (pixel)","Mosaic"),params:[x("cellSize","Ô","Cell size",2,200,16)]},{id:"crystallize",group:"art",label:i("Pha lê","Crystallize"),params:[x("cellSize","Ô","Cell size",3,300,20)],fixed:{seed:7}},{id:"pointillize",group:"art",label:i("Chấm điểm","Pointillize"),params:[x("cellSize","Ô","Cell size",3,300,8)],fixed:{seed:7,background:[1,1,1,1]}},{id:"colorHalftone",group:"art",label:i("Bán sắc màu","Color Halftone"),params:[x("maxRadius","Bán kính","Max radius",4,127,8)],fixed:{angles:[108,162,90,45]}},{id:"emboss",group:"art",label:i("Chạm nổi","Emboss"),params:[x("angle","Góc","Angle",-180,180,135),x("height","Độ cao","Height",1,100,3),x("amount","Mức","Amount",1,500,100)]},{id:"twirl",group:"distort",label:i("Xoắn","Twirl"),params:[x("angle","Góc","Angle",-999,999,50)]},{id:"pinch",group:"distort",label:i("Bóp / phồng","Pinch"),params:[x("amount","Mức","Amount",-100,100,50)]},{id:"diffuse",group:"art",label:i("Khuếch tán","Diffuse"),params:[],fixed:{mode:"normal",seed:7}},{id:"facet",group:"art",label:i("Mặt phẳng","Facet"),params:[]},{id:"findEdges",group:"art",label:i("Tìm cạnh","Find Edges"),params:[]},{id:"solarize",group:"art",label:i("Phơi sáng ngược","Solarize"),params:[]},{id:"desaturate",group:"art",label:i("Đen trắng","Desaturate"),params:[]},{id:"invert",group:"art",label:i("Âm bản","Invert"),params:[]}]),Q=t=>H.find(e=>e.id===t)||null,v=(t,e,n)=>({w:t,h:e,data:n||new Uint8ClampedArray(t*e*4)});function _(t,e,n){if(t.w===e&&t.h===n)return t;const a=v(e,n),o=t.data,r=a.data,h=t.w/e,d=t.h/n;for(let u=0;u<n;u++){const m=Math.max(0,(u+.5)*d-.5),s=Math.min(t.h-1,Math.floor(m)),l=Math.min(t.h-1,s+1),c=m-s;for(let p=0;p<e;p++){const f=Math.max(0,(p+.5)*h-.5),b=Math.min(t.w-1,Math.floor(f)),M=Math.min(t.w-1,b+1),g=f-b,y=(s*t.w+b)*4,z=(s*t.w+M)*4,A=(l*t.w+b)*4,B=(l*t.w+M)*4,S=(u*e+p)*4;for(let k=0;k<4;k++)r[S+k]=(o[y+k]*(1-g)+o[z+k]*g)*(1-c)+(o[A+k]*(1-g)+o[B+k]*g)*c}}return a}function Z(t,e,n,a,o){if(e===a&&n===o)return t;const r=new Uint8Array(a*o),h=e/a,d=n/o;for(let u=0;u<o;u++){const m=Math.max(0,(u+.5)*d-.5),s=Math.min(n-1,Math.floor(m)),l=Math.min(n-1,s+1),c=m-s;for(let p=0;p<a;p++){const f=Math.max(0,(p+.5)*h-.5),b=Math.min(e-1,Math.floor(f)),M=Math.min(e-1,b+1),g=f-b;r[u*a+p]=(t[s*e+b]*(1-g)+t[s*e+M]*g)*(1-c)+(t[l*e+b]*(1-g)+t[l*e+M]*g)*c}}return r}function I(t,e,n,a,o){if(a<1)return t;const r=new Float32Array(e*n),h=new Uint8Array(e*n);for(let d=0;d<n;d++)for(let u=0;u<e;u++){let m=0,s=0;for(let l=Math.max(0,u-a);l<=Math.min(e-1,u+a);l++){const c=t[d*e+l];o?c>m&&(m=c):(m+=c,s++)}r[d*e+u]=o?m:m/s}for(let d=0;d<n;d++)for(let u=0;u<e;u++){let m=0,s=0;for(let l=Math.max(0,d-a);l<=Math.min(n-1,d+a);l++){const c=r[l*e+u];o?c>m&&(m=c):(m+=c,s++)}h[d*e+u]=o?m:Math.round(m/s)}return h}const N=(t,e,n,a)=>I(t,e,n,Math.round(a),!0),D=(t,e,n,a)=>I(t,e,n,Math.round(a),!1);function tt(t,e,n){const a=new Uint8Array(e*n);for(const o of t||[]){const r=Math.floor(o.x*e),h=Math.floor(o.y*n),d=Math.ceil((o.x+o.w)*e),u=Math.ceil((o.y+o.h)*n),m=(r+d)/2,s=(h+u)/2,l=Math.max(.5,(d-r)/2),c=Math.max(.5,(u-h)/2);for(let p=Math.max(0,h);p<Math.min(n,u);p++)for(let f=Math.max(0,r);f<Math.min(e,d);f++)o.shape==="ellipse"&&((f+.5-m)/l)**2+((p+.5-s)/c)**2>1||(a[p*e+f]=255)}return a}function T(t,e,n){const a=t.fit==="contain"?Math.min(t.w/e,t.h/n):Math.max(t.w/e,t.h/n),o=e*a,r=n*a;return{x:t.x+(t.w-o)/2,y:t.y+(t.h-r)/2,w:o,h:r,k:a}}function K(t,e,n){const a=T(t,e,n),o=Math.max(0,(t.x-a.x)/a.k),r=Math.max(0,(t.y-a.y)/a.k),h=Math.min(e,(t.x+t.w-a.x)/a.k),d=Math.min(n,(t.y+t.h-a.y)/a.k);return{x:o,y:r,w:Math.max(0,h-o),h:Math.max(0,d-r)}}function L(t,e,n){const a=(t.rotation||0)*Math.PI/180;if(!a)return{x:e,y:n};const o=t.x+t.w/2,r=t.y+t.h/2,h=e-o,d=n-r;return{x:o+h*Math.cos(a)-d*Math.sin(a),y:r+h*Math.sin(a)+d*Math.cos(a)}}const w=t=>Math.round(t*100)/100;function j(t,e,n){return{url:e.url,gcsUri:e.gcsUri,original:t.original||{url:t.url,gcsUri:t.gcsUri},edits:[...t.edits||[],n].slice(-20)}}function et(t,e,n,a,o,r,{names:h={}}={}){if(a.kind==="split"){const u=T(t,e,n),m=[{op:"update",id:t.id,set:{...j(t,o.main,r),name:h.background||`${t.name||"Ảnh"} · nền`}}],s=(o.index??0)+1;return a.cutouts.forEach((l,c)=>{const p=l.pic.w*u.k,f=l.pic.h*u.k,b=u.x+(l.x+l.pic.w/2)*u.k,M=u.y+(l.y+l.pic.h/2)*u.k,g=L(t,b,M);m.push({op:"add",index:s+c,layer:{type:"image",name:l.label?`${h.cutout||"Chủ thể"} ${l.label}`:h.cutout||"Chủ thể",url:o.cutouts[c].url,gcsUri:o.cutouts[c].gcsUri,fit:"cover",x:w(g.x-p/2),y:w(g.y-f/2),w:w(p),h:w(f),rotation:t.rotation||0,opacity:t.opacity??1,...t.adjust?{adjust:t.adjust}:{}}})}),m}const d=j(t,o.main,r);if(a.texts?.length)return[{op:"update",id:t.id,set:d},...V(t,e,n,a.texts,{at:(o.index??0)+1,rect:T(t,e,n)})];if(a.offset){const u=T(t,e,n),m=u.x-a.offset.left*u.k,s=u.y-a.offset.top*u.k,l=a.pic.w*u.k,c=a.pic.h*u.k,p=L(t,m+l/2,s+c/2);Object.assign(d,{x:w(p.x-l/2),y:w(p.y-c/2),w:w(l),h:w(c),fit:"cover"})}return[{op:"update",id:t.id,set:d}]}function at(t,e,n,a){if(t.kind!=="split")return t;const o=K(e,n,a),r=Math.floor(o.x),h=Math.floor(o.y),d=Math.ceil(o.x+o.w),u=Math.ceil(o.y+o.h),m=[];for(const s of t.cutouts){const l=Math.max(s.x,r),c=Math.max(s.y,h),p=Math.min(s.x+s.pic.w,d),f=Math.min(s.y+s.pic.h,u);if(p-l<4||f-c<4)continue;if(l===s.x&&c===s.y&&p===s.x+s.pic.w&&f===s.y+s.pic.h){m.push(s);continue}const b=p-l,M=f-c,g=v(b,M);for(let y=0;y<M;y++)g.data.set(s.pic.data.subarray(((c-s.y+y)*s.pic.w+(l-s.x))*4,((c-s.y+y)*s.pic.w+(l-s.x)+b)*4),y*b*4);m.push({...s,pic:g,x:l,y:c})}return{...t,cutouts:m}}const F=["1:1","3:2","2:3","3:4","4:3","4:5","5:4","9:16","16:9","21:9"];function E(t,e){const n=Math.log(t/e),a=o=>{const[r,h]=o.split(":").map(Number);return Math.abs(Math.log(r/h)-n)};return F.reduce((o,r)=>a(r)<a(o)?r:o,"1:1")}function nt(t,e){const n=E(t,e),[a,o]=n.split(":").map(Number);return{aspectRatio:n,resolution:X(Math.max(t,Math.round(e*a/o)),Math.max(e,Math.round(t*o/a)))}}const X=(t,e)=>Math.max(t,e)<=1100?"1K":"2K";function ot(t,e=E(t.w,t.h)){const[n,a]=e.split(":").map(Number);let o=t.w,r=Math.round(t.w*a/n);if(r<t.h&&(r=t.h,o=Math.round(t.h*n/a)),o===t.w&&r===t.h)return{pic:t,x:0,y:0,aspect:e};const h=Math.floor((o-t.w)/2),d=Math.floor((r-t.h)/2),u=v(o,r);for(let m=0;m<r;m++){const s=Math.min(t.h-1,Math.max(0,m-d));for(let l=0;l<o;l++){const c=Math.min(t.w-1,Math.max(0,l-h)),p=(m*o+l)*4,f=(s*t.w+c)*4;u.data[p]=t.data[f],u.data[p+1]=t.data[f+1],u.data[p+2]=t.data[f+2],u.data[p+3]=255}}return{pic:u,x:h,y:d,aspect:e}}function rt(t,e){const n=v(t.w,t.h,new Uint8ClampedArray(t.data)),a=n.data,o=N(e,t.w,t.h,Math.max(2,Math.round(Math.max(t.w,t.h)/300)));for(let r=0;r<e.length;r++)e[r]>127?(a[r*4]=a[r*4]*.45+255*.55,a[r*4+1]*=.45,a[r*4+2]*=.45):o[r]>127&&(a[r*4]=255,a[r*4+1]=0,a[r*4+2]=0),a[r*4+3]=255;return n}function it(t,e){const n=String(e||"").replace(/"/g,"'").slice(0,600);return t==="new_background"?`Image 1 is the background of a photo whose subject was removed. Make a new background for that photo: "${n}". Keep the same camera angle, horizon, perspective and light direction as image 1 so the subject can be placed back in front of it. Do not draw any people, animals or text unless asked. Photorealistic unless the request says otherwise. Same framing as image 1.`:`Image 1 is a photo. Image 2 is the same photo with a region tinted red. Change ONLY that red region of image 1: "${n}". Everything outside the region must stay exactly as in image 1 (same framing, size, colours, light). Return the whole edited photo, without any red tint or outline.`}function st(t,e,n,a){const o=_(e,n.pic.w,n.pic.h),r=v(t.w,t.h,new Uint8ClampedArray(t.data)),h=r.data,d=Math.max(2,Math.round(Math.max(t.w,t.h)/250)),u=D(N(a,t.w,t.h,d),t.w,t.h,d);for(let m=0;m<t.h;m++)for(let s=0;s<t.w;s++){const l=m*t.w+s,c=u[l]/255;if(c<=0)continue;const p=((m+n.y)*o.w+s+n.x)*4;for(let f=0;f<3;f++)h[l*4+f]=h[l*4+f]*(1-c)+o.data[p+f]*c}return r}function ut(t,e,n,a){const o=_(t,e.pic.w,e.pic.h),r=v(n,a);for(let h=0;h<a;h++)r.data.set(o.data.subarray(((h+e.y)*o.w+e.x)*4,((h+e.y)*o.w+e.x+n)*4),h*n*4);for(let h=3;h<r.data.length;h+=4)r.data[h]=255;return r}const ht=Object.freeze(Object.defineProperty({__proto__:null,PHOTO_AI_ASPECTS:F,PHOTO_AI_GENERATOR:O,PHOTO_FILTERS:H,PHOTO_MAX_SIDE:W,PHOTO_TOOLS:J,aiResolution:X,areasMask:tt,blendAiEdit:st,clipCutouts:at,cropAiBackground:ut,dilateMask:N,featherMask:D,markRegion:rt,nearestAspect:E,padToAspect:ot,photoAiPrompt:it,photoAiShape:nt,photoFilter:Q,photoResultOps:et,pictureRect:T,replacedSet:j,resizeMask:Z,resizePic:_,visibleRect:K},Symbol.toStringTag,{value:"Module"}));export{Y as G,H as P,J as a,et as b,at as c,O as d,W as e,T as f,tt as g,ot as h,it as i,st as j,ut as k,nt as l,rt as m,ht as n,Q as p,Z as r};
@@ -0,0 +1 @@
1
+ import{aO as R,du as O,fr as T,dk as q,bn as C,a7 as F,fs as k}from"./remote-CpkPQOQH.js";import{nN as W,nn as _,no as D,nO as j,nP as H,nQ as U,nR as B,lf as L}from"./titleFrameBudget-h4nOQ5u9.js";import{plateMatte as N,matteAt as Q}from"./plateMatte-0tTG7oeO.js";import{t as I}from"./i18n-ClNt3LKg.js";import"./index-CKtv7gGE.js";import"./api-CZoVJ9Fy.js";import"./three.module-Bx43vjkH.js";import"./gltfLoader-U0Eebg7v.js";import"./store-D3Y663py.js";import"./rotoMaskStore-BZBJLcCp.js";import"./sceneTrack-CO4fTjft.js";import"./timelineOps-f1WsVbgS.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./rigTrack-BbKqZGs7.js";import"./clientJobs-CuuUyhEy.js";import"./rotoMatte-BI-vjjrv.js";const X=15,Y=240,$=480;async function z(i,a,n,o,s,f){const e=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});e.src=i;try{await new Promise((h,g)=>{e.onloadeddata=()=>h(),e.onerror=()=>g(new Error(I("Không đọc được video nền (CORS / định dạng)")))});const M=e.videoWidth||1280,p=e.videoHeight||720,r=Math.min($,M),m=Math.max(2,Math.round(r*p/M)),c=Object.assign(document.createElement("canvas"),{width:r,height:m}),x=c.getContext("2d",{willReadFrequently:!0}),w=Math.max(2,Math.round(n*o)+1),v=[],u=[];for(let h=0;h<w;h++){if(s?.aborted)throw new DOMException("Đã huỷ","AbortError");const g=Math.min(n,h/o),b=Math.max(0,Math.min(e.duration-1/60,a+g));Math.abs(e.currentTime-b)>1e-4&&await new Promise((d,A)=>{const E=window.setTimeout(()=>A(new Error(I("Seek video quá lâu"))),8e3);e.onseeked=()=>{window.clearTimeout(E),d()},e.currentTime=b}),x.drawImage(e,0,0,r,m),v.push(B(x.getImageData(0,0,r,m).data,r,m)),u.push(g),f?.(h+1,w)}return{frames:v,times:u,W:r,H:m}}finally{e.removeAttribute("src"),e.load()}}function G(i){const a=F(i,0),n=k(a);return{position:[...a.position],q:n.quaternion.toArray(),distance:Math.max(.5,Math.hypot(...a.target.map((s,f)=>s-a.position[f]))),lens:a.lens}}async function Mt(i,a){const n=i.plate,o=i.shots.find(t=>t.id===i.activeShot);if(!n||!o)throw new Error("no-plate");const s=C.plateUrl?await C.plateUrl(n).catch(()=>n.url):n.url,f=a.fps??X,e=Math.min(o.duration,n.duration),{frames:M,times:p,W:r}=await z(s,n.inPoint,e,f,a.signal,a.progress),m=O(o.aspect),c=G(o),x=L(c.lens,r,m),w=await N(i,s,{signal:a.signal}),v=w?t=>{const l=Q(w,n.inPoint+p[t]);return l.box?(y,S)=>l.at(y,S)>.05||l.at(y+.02,S)>.05||l.at(y-.02,S)>.05:null}:null,u=_(M,x,{skip:v}),h=u.filter(t=>t.lost).length;if(h>u.length/2)throw new Error("camera-not-found");const g=D(M,x,{skip:v}),b=Math.ceil(u.length/Y);let d,A="turn",E=null,K=0;if(g?.mode==="free"){const t=j(g,c);d=H(t.cams,p,o.duration,{distance:c.distance,lens:c.lens,every:b,newId:a.newId}),A="travel",E=t.by;for(let l=1;l<t.cams.length;l++)K+=Math.hypot(...t.cams[l].position.map((y,S)=>y-t.cams[l-1].position[S]))}else d=U(u,p,o.duration,c,{W:r,aspect:m,every:b,newId:a.newId});const P=d.map(t=>Math.atan2(t.target[0]-t.position[0],-(t.target[2]-t.position[2]))*180/Math.PI);return{stage:{...i,shots:i.shots.map(t=>{if(t.id!==o.id)return t;const{handheld:l,...y}=t;return{...y,...q(d)}})},keys:d.length,frames:u.length,lost:h,mode:A,scale:E,travel:Math.round(K*100)/100,matte:w?w.made?"made":"timeline":"none",pan:Math.round((Math.max(...P)-Math.min(...P))*10)/10,lens:[Math.min(...d.map(t=>t.lens)),Math.max(...d.map(t=>t.lens))]}}function wt(i,a={}){const n=i.shots.find(r=>r.id===i.activeShot),o=R(n),s=O(n.aspect),f=s>=1?1920:Math.round(1920*s/2)*2,e=s>=1?Math.round(1920/s/2)*2:1920,M=Math.max(2,Math.round(n.duration*o)+1),p=[];for(let r=0;r<M;r++){const m=Math.min(n.duration,r/o),c=T(n,n.duration?m/n.duration:0);p.push({t:m,position:c.position.toArray(),q:c.quaternion.toArray(),lens:c.getFocalLength()})}return W(p,{fps:o,width:f,height:e,name:`${n.name} · Clipoox`,plate:a.plate??"",maxKeys:a.maxKeys})}export{X as TRACK_FPS,Y as TRACK_MAX_KEYS,wt as shotBlenderScript,Mt as trackPlateCamera};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/plateFollow-CJUilsNV.js","assets/titleFrameBudget-DsM0V482.js","assets/remote-8XzEAnAJ.js","assets/index-CKtv7gGE.js","assets/i18n-C9zFX25m.js","assets/api-Dnl2uaKO.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/store-CpqHUcA2.js","assets/rotoMaskStore-pE1AIt3I.js","assets/sceneTrack-DlAH5s74.js","assets/timelineOps-DSSaDsU2.js","assets/cameraTracker-DHdF8Zqx.js","assets/textAnimators-B9vO_hbP.js","assets/timelineComp-i-zdaoB2.js","assets/rigTrack-DMyqb0pb.js","assets/clientJobs-CuuUyhEy.js"])))=>i.map(i=>d[i]);
2
- import{_ as rt}from"./titleFrameBudget-DsM0V482.js";import{n as st,fs as at}from"./remote-8XzEAnAJ.js";import{mainBody as it,worldOf as ct,smooth as ht,depthOf as ut,lowestFoot as mt,rayOf as nt,FOOT_HEIGHT as ft,median as W}from"./plateFollow-CJUilsNV.js";import"./index-CKtv7gGE.js";import"./i18n-C9zFX25m.js";import"./api-Dnl2uaKO.js";import"./three.module-Bx43vjkH.js";import"./gltfLoader-U0Eebg7v.js";import"./store-CpqHUcA2.js";import"./rotoMaskStore-pE1AIt3I.js";import"./sceneTrack-DlAH5s74.js";import"./timelineOps-DSSaDsU2.js";import"./cameraTracker-DHdF8Zqx.js";import"./textAnimators-B9vO_hbP.js";import"./timelineComp-i-zdaoB2.js";import"./rigTrack-DMyqb0pb.js";import"./clientJobs-CuuUyhEy.js";const B=Math.PI/180,et=(t,n)=>[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]],pt=(t,n)=>t[0]*n[0]+t[1]*n[1]+t[2]*n[2],Q=t=>{const n=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/n,t[1]/n,t[2]/n]},z=Object.freeze({lean:25,lines:60,minShare:.06,agree:.7,maxTilt:40,minLines:6,minSupport:1});function dt(t,n,r,{lean:s=z.lean,minShare:M=z.minShare,max:i=z.lines}={}){const y=n*r,E=new Float32Array(y),A=new Float32Array(y),m=new Float32Array(y);let x=0,v=0;for(let c=1;c<r-1;c++)for(let h=1;h<n-1;h++){const a=c*n+h,d=t[a-n-1],H=t[a-n],_=t[a-n+1],b=t[a-1],w=t[a+1],q=t[a+n-1],R=t[a+n],S=t[a+n+1],V=_+2*w+S-d-2*b-q,I=q+2*R+S-d-2*H-_,G=Math.hypot(V,I);E[a]=V,A[a]=I,m[a]=G,x+=G,v+=G*G}const p=x/y,T=Math.max(48,p+1.2*Math.sqrt(Math.max(0,v/y-p*p))),P=.5,g=Math.round(2*s/P)+1,u=Math.ceil(Math.hypot(n,r)/2)+2,F=new Uint16Array(g*(2*u+1)),o=new Float32Array(g),l=new Float32Array(g);for(let c=0;c<g;c++){const h=(-s+c*P)*B;o[c]=Math.cos(h),l[c]=Math.sin(h)}const e=[];for(let c=1;c<r-1;c++)for(let h=1;h<n-1;h++){const a=c*n+h;if(m[a]<T||m[a]<m[a-1]||m[a]<=m[a+1])continue;let d=Math.atan2(A[a],E[a])/B;if(d>90?d-=180:d<-90&&(d+=180),Math.abs(d)>s)continue;const H=m[a-1]-2*m[a]+m[a+1],_=H<-1e-6?Math.max(-.5,Math.min(.5,.5*(m[a-1]-m[a+1])/H)):0;e.push(h+_-n/2,c-r/2,d);const b=Math.max(0,Math.round((d-3+s)/P)),w=Math.min(g-1,Math.round((d+3+s)/P));for(let q=b;q<=w;q++)F[q*(2*u+1)+Math.round(e[e.length-3]*o[q]+e[e.length-2]*l[q])+u]++}const O=[],C=Math.max(12,M*r*.6);for(let c=0;c<g;c++)for(let h=0;h<=2*u;h++){const a=F[c*(2*u+1)+h];a>=C&&O.push([a,c,h])}O.sort((c,h)=>h[0]-c[0]);const L=e.length/3,N=new Uint8Array(L),j=[],D=c=>{let h=0,a=0,d=0,H=0;for(const q of c){const R=e[q*3],S=e[q*3+1];h+=S,a+=R,d+=S*S,H+=R*S}const _=c.length,b=_*d-h*h;if(_<2||Math.abs(b)<1e-6)return null;const w=(_*H-a*h)/b;return{p:(a-w*h)/_,q:w}};let K=0;for(const[,c,h]of O){if(j.length>=i||K++>i*6)break;const a=o[c],d=l[c],H=h-u,_=-s+c*P;let b=[];for(let f=0;f<L;f++)!N[f]&&Math.abs(e[f*3]*a+e[f*3+1]*d-H)<=1.6&&Math.abs(e[f*3+2]-_)<=7&&b.push(f);if(b.length<C)continue;let w=D(b);if(!w)continue;const q=(f,J)=>{const lt=Math.hypot(1,f.q),tt=[];for(let U=0;U<L;U++)!N[U]&&Math.abs(e[U*3]-f.p-f.q*e[U*3+1])/lt<=J&&Math.abs(e[U*3+2]-_)<=10&&tt.push(U);return tt};b=q(w,1.2),w=D(b)??w,b.sort((f,J)=>e[f*3+1]-e[J*3+1]);let R=0,S=0,V=0;for(let f=1;f<=b.length;f++)(f===b.length||e[b[f]*3+1]-e[b[f-1]*3+1]>6)&&(e[b[f-1]*3+1]-e[b[V]*3+1]>e[b[S]*3+1]-e[b[R]*3+1]&&(R=V,S=f-1),V=f);const I=b.slice(R,S+1);if(I.length<C)continue;w=D(I)??w;const G=Math.hypot(1,w.q),X=e[I[0]*3+1],Y=e[I[I.length-1]*3+1],Z=(Y-X)*G;let $=0;for(const f of I)$+=((e[f*3]-w.p-w.q*e[f*3+1])/G)**2;if(!(Z<M*r||Math.sqrt($/I.length)>.8||Math.abs(Math.atan(-w.q)/B-_)>2.5)){for(const f of q(w,2))e[f*3+1]>=X-2&&e[f*3+1]<=Y+2&&(N[f]=1);j.push({x0:w.p+w.q*X+n/2,y0:X+r/2,x1:w.p+w.q*Y+n/2,y1:Y+r/2,length:Z})}}return j.sort((c,h)=>h.length-c.length).slice(0,i)}function Mt(t,n,r,s,{agree:M=z.agree,maxTilt:i=z.maxTilt}={}){const y=t.map(o=>({n:Q(et([o.x0-n/2,o.y0-r/2,s],[o.x1-n/2,o.y1-r/2,s])),length:o.length}));if(y.length<3)return null;const E=Math.sin(M*B),A=o=>{let l=0;const e=[];for(const O of y)Math.abs(pt(O.n,o))<E&&(l+=O.length,e.push(O));return{score:l,inl:e}},m=o=>o[1]>0?[-o[0],-o[1],-o[2]]:o;let x=null;const v=[[0,-1,0]];for(let o=0;o<y.length;o++)for(let l=o+1;l<y.length;l++){const e=et(y[o].n,y[l].n);Math.hypot(...e)>1e-4&&v.push(m(Q(e)))}for(const o of v){if(Math.acos(Math.min(1,-o[1]))>i*B)continue;const l=A(o);(!x||l.score>x.score)&&(x={...l,U:o})}if(!x||x.inl.length<3)return null;const p=[0,0,0,0,0,0,0,0,0];for(const o of x.inl)for(let l=0;l<3;l++)for(let e=0;e<3;e++)p[l*3+e]+=o.length*o.n[l]*o.n[e];const T=p[0]+p[4]+p[8];p[0]+=T*1e-6,p[4]+=T*1e-6,p[8]+=T*1e-6;const g=(o=>{const[l,e,O,C,L,N,j,D,K]=o,c=L*K-N*D,h=-(C*K-N*j),a=C*D-L*j,d=l*c+e*h+O*a;return Math.abs(d)<1e-18?null:[c/d,-(e*K-O*D)/d,(e*N-O*L)/d,h/d,(l*K-O*j)/d,-(l*N-O*C)/d,a/d,-(l*D-e*j)/d,(l*L-e*C)/d]})(p);let u=x.U;if(g)for(let o=0;o<12;o++)u=m(Q([g[0]*u[0]+g[1]*u[1]+g[2]*u[2],g[3]*u[0]+g[4]*u[1]+g[5]*u[2],g[6]*u[0]+g[7]*u[1]+g[8]*u[2]]));Math.acos(Math.min(1,-u[1]))>i*B&&(u=x.U);const F=x.inl.reduce((o,l)=>o+l.length,0)/r;return{tilt:Math.asin(Math.max(-1,Math.min(1,u[2])))/B,roll:Math.atan2(u[0],-u[1])/B,lines:x.inl.length,support:F,up:u}}function gt(t,n,r,s){const M=dt(t,n,r),i=Mt(M,n,r,s/36*n);return i&&i.lines>=z.minLines&&i.support>=z.minSupport?{...i,found:M.length}:null}const ot=28,yt=1.5,k=t=>Math.round(t*1e3)/1e3,bt=(t,n)=>{const r=t.filter(Number.isFinite).sort((s,M)=>s-M);return r.length?r[Math.min(r.length-1,Math.floor(r.length*n))]:NaN},wt=(t,n,r,s)=>{const M=n*Math.PI/180;return at({position:[0,0,0],target:[0,Math.sin(M),-Math.cos(M)],lens:t,roll:r,aspect:s})};function xt(t,n="16:9"){const r=t.lens??ot,s=t.tilt??t.seen?.tilt??0,M=t.roll??(t.tilt==null?t.seen?.roll:null)??0,i={lens:t.lens!=null?"given":"assumed",tilt:t.tilt!=null?"given":t.seen?"lines":"level",height:t.height!=null?"given":"default",place:"default"},y=wt(r,s,M,n),E=it(t.frames.filter(p=>p.lm&&p.lm.length>=33),t.aspect).filter(p=>p.lm);let A=t.height??yt,m=[0,-4];if(E.length>=2){const p=E.map(l=>l.wl&&l.wl.length>=33?l.wl:ct(l.lm,t.aspect)),T=ht(E.map((l,e)=>ut(y,l.lm,p[e]))),P=E.map((l,e)=>{const O=mt(l.lm);return-nt(y,l.lm[O][0],l.lm[O][1]).y*T[e]+ft[O]}),g=bt(P,.7);t.height==null&&g>.15&&g<30&&(A=g,i.height="feet");const u=E.map((l,e)=>nt(y,(l.lm[23][0]+l.lm[24][0])/2,(l.lm[23][1]+l.lm[24][1])/2).multiplyScalar(T[e])),F=u.filter((l,e)=>Math.abs(P[e]-A)<.2*A),o=F.length>=2?F:u;m=[W(o.map(l=>l.x)),W(o.map(l=>l.z))],i.place="person"}const x=s*Math.PI/180,v=[k(-m[0]),k(A),k(-m[1])];return{lens:k(r),height:k(A),tilt:k(s),roll:k(M),distance:k(Math.hypot(m[0],m[1])),position:v,target:[k(v[0]),k(v[1]+Math.sin(x)*4),k(v[2]-Math.cos(x)*4)],by:i,lines:t.tilt==null?t.seen?.lines??0:0}}function At(t,n){const r={...t.plate,match:{lens:n.lens,height:n.height,tilt:n.tilt,roll:n.roll}};return{...t,plate:r,shots:t.shots.map(s=>s.id!==t.activeShot?s:{...s,position:n.position,target:n.target,lens:n.lens,roll:n.roll,endPosition:n.position,endTarget:n.target,endLens:n.lens,motion:"static",cameraKeys:[]})}}const vt=t=>{const n=t.shots.find(r=>r.id===t.activeShot);return!!t.plate&&!!n&&!n.cameraKeys?.length};function Ut(t){const n=t.shots.find(M=>M.id===t.activeShot),r=st().shots[0],s=(M,i)=>M.every((y,E)=>Math.abs(y-i[E])<1e-6);return!!n&&s(n.position,r.position)&&s(n.target,r.target)&&Math.abs(n.lens-r.lens)<1e-6&&!n.roll}async function zt(t,n={},r={}){const s=t.plate,M=t.shots.find(v=>v.id===t.activeShot);if(!s||!M)throw new Error("no-plate");if(!vt(t))throw new Error("camera-keyed");const[i,y]=(M.aspect||"16:9").split(":").map(Number);let E=[],A=i/y||16/9,m=null;if(!(n.lens!=null&&n.height!=null&&n.tilt!=null)){const{readPlate:v}=await rt(async()=>{const{readPlate:T}=await import("./plateFollow-CJUilsNV.js");return{readPlate:T}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])),p=await v(t,r);E=p.tracked.frames,A=i/y||p.tracked.aspect,n.tilt==null&&(m=await Et(p.url,s.inPoint,p.span,n.lens??ot,r.signal).catch(T=>{if(T.name==="AbortError")throw T;return null}))}const x=xt({frames:E,aspect:A,lens:n.lens??null,tilt:n.tilt??null,roll:n.roll??null,height:n.height??null,seen:m},M.aspect);return{stage:At(t,x),match:x,found:E.filter(v=>v.lm).length}}async function Et(t,n,r,s,M){const i=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});i.src=t;try{await new Promise((T,P)=>{i.onloadeddata=()=>T(),i.onerror=()=>P(new Error("plate-unreadable"))});const y=i.videoWidth||1280,E=i.videoHeight||720,A=Math.min(960,y),m=Math.max(2,Math.round(A*E/y)),x=Object.assign(document.createElement("canvas"),{width:A,height:m}),v=x.getContext("2d",{willReadFrequently:!0}),p=[];for(const T of[.1,.3,.5,.7,.9]){if(M?.aborted)throw new DOMException("Đã huỷ","AbortError");const P=Math.max(0,Math.min(i.duration-1/60,n+r*T));Math.abs(i.currentTime-P)>1e-4&&await new Promise((o,l)=>{const e=window.setTimeout(()=>l(new Error("plate-seek")),8e3);i.onseeked=()=>{window.clearTimeout(e),o()},i.currentTime=P}),v.drawImage(i,0,0,A,m);const g=v.getImageData(0,0,A,m).data,u=new Uint8Array(A*m);for(let o=0;o<u.length;o++)u[o]=g[o*4]*77+g[o*4+1]*150+g[o*4+2]*29>>8;const F=gt(u,A,m,s);F&&p.push({tilt:F.tilt,roll:F.roll,lines:F.lines})}return Tt(p)}finally{i.removeAttribute("src"),i.load()}}function Tt(t){if(t.length<2)return null;const n=W(t.map(s=>s.tilt)),r=W(t.map(s=>s.roll));return t.filter(s=>Math.abs(s.tilt-n)<=5).length<Math.max(2,t.length*.6)?null:{tilt:k(n),roll:k(r),lines:Math.round(W(t.map(s=>s.lines)))}}export{yt as MATCH_HEIGHT,ot as MATCH_LENS,At as applyCameraMatch,xt as matchCamera,zt as matchPlateCamera,vt as matchable,Tt as tiltOfReads,Et as tiltOfStills,Ut as untouchedCamera};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/plateFollow-D2rjnmZA.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/remote-CpkPQOQH.js","assets/index-CKtv7gGE.js","assets/i18n-ClNt3LKg.js","assets/api-CZoVJ9Fy.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/store-D3Y663py.js","assets/rotoMaskStore-BZBJLcCp.js","assets/sceneTrack-CO4fTjft.js","assets/timelineOps-f1WsVbgS.js","assets/cameraTracker-Df9jWmz6.js","assets/textAnimators-C4eMnVRD.js","assets/timelineComp-Ciu9JCWJ.js","assets/rigTrack-BbKqZGs7.js","assets/clientJobs-CuuUyhEy.js"])))=>i.map(i=>d[i]);
2
+ import{_ as rt}from"./titleFrameBudget-h4nOQ5u9.js";import{n as st,fs as at}from"./remote-CpkPQOQH.js";import{mainBody as it,worldOf as ct,smooth as ht,depthOf as ut,lowestFoot as mt,rayOf as nt,FOOT_HEIGHT as ft,median as W}from"./plateFollow-D2rjnmZA.js";import"./index-CKtv7gGE.js";import"./i18n-ClNt3LKg.js";import"./api-CZoVJ9Fy.js";import"./three.module-Bx43vjkH.js";import"./gltfLoader-U0Eebg7v.js";import"./store-D3Y663py.js";import"./rotoMaskStore-BZBJLcCp.js";import"./sceneTrack-CO4fTjft.js";import"./timelineOps-f1WsVbgS.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./rigTrack-BbKqZGs7.js";import"./clientJobs-CuuUyhEy.js";const B=Math.PI/180,et=(t,n)=>[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]],pt=(t,n)=>t[0]*n[0]+t[1]*n[1]+t[2]*n[2],Q=t=>{const n=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/n,t[1]/n,t[2]/n]},z=Object.freeze({lean:25,lines:60,minShare:.06,agree:.7,maxTilt:40,minLines:6,minSupport:1});function dt(t,n,r,{lean:s=z.lean,minShare:M=z.minShare,max:i=z.lines}={}){const y=n*r,E=new Float32Array(y),A=new Float32Array(y),m=new Float32Array(y);let x=0,v=0;for(let c=1;c<r-1;c++)for(let h=1;h<n-1;h++){const a=c*n+h,d=t[a-n-1],H=t[a-n],_=t[a-n+1],b=t[a-1],w=t[a+1],q=t[a+n-1],R=t[a+n],S=t[a+n+1],V=_+2*w+S-d-2*b-q,I=q+2*R+S-d-2*H-_,G=Math.hypot(V,I);E[a]=V,A[a]=I,m[a]=G,x+=G,v+=G*G}const p=x/y,T=Math.max(48,p+1.2*Math.sqrt(Math.max(0,v/y-p*p))),P=.5,g=Math.round(2*s/P)+1,u=Math.ceil(Math.hypot(n,r)/2)+2,F=new Uint16Array(g*(2*u+1)),o=new Float32Array(g),l=new Float32Array(g);for(let c=0;c<g;c++){const h=(-s+c*P)*B;o[c]=Math.cos(h),l[c]=Math.sin(h)}const e=[];for(let c=1;c<r-1;c++)for(let h=1;h<n-1;h++){const a=c*n+h;if(m[a]<T||m[a]<m[a-1]||m[a]<=m[a+1])continue;let d=Math.atan2(A[a],E[a])/B;if(d>90?d-=180:d<-90&&(d+=180),Math.abs(d)>s)continue;const H=m[a-1]-2*m[a]+m[a+1],_=H<-1e-6?Math.max(-.5,Math.min(.5,.5*(m[a-1]-m[a+1])/H)):0;e.push(h+_-n/2,c-r/2,d);const b=Math.max(0,Math.round((d-3+s)/P)),w=Math.min(g-1,Math.round((d+3+s)/P));for(let q=b;q<=w;q++)F[q*(2*u+1)+Math.round(e[e.length-3]*o[q]+e[e.length-2]*l[q])+u]++}const O=[],C=Math.max(12,M*r*.6);for(let c=0;c<g;c++)for(let h=0;h<=2*u;h++){const a=F[c*(2*u+1)+h];a>=C&&O.push([a,c,h])}O.sort((c,h)=>h[0]-c[0]);const L=e.length/3,N=new Uint8Array(L),j=[],D=c=>{let h=0,a=0,d=0,H=0;for(const q of c){const R=e[q*3],S=e[q*3+1];h+=S,a+=R,d+=S*S,H+=R*S}const _=c.length,b=_*d-h*h;if(_<2||Math.abs(b)<1e-6)return null;const w=(_*H-a*h)/b;return{p:(a-w*h)/_,q:w}};let K=0;for(const[,c,h]of O){if(j.length>=i||K++>i*6)break;const a=o[c],d=l[c],H=h-u,_=-s+c*P;let b=[];for(let f=0;f<L;f++)!N[f]&&Math.abs(e[f*3]*a+e[f*3+1]*d-H)<=1.6&&Math.abs(e[f*3+2]-_)<=7&&b.push(f);if(b.length<C)continue;let w=D(b);if(!w)continue;const q=(f,J)=>{const lt=Math.hypot(1,f.q),tt=[];for(let U=0;U<L;U++)!N[U]&&Math.abs(e[U*3]-f.p-f.q*e[U*3+1])/lt<=J&&Math.abs(e[U*3+2]-_)<=10&&tt.push(U);return tt};b=q(w,1.2),w=D(b)??w,b.sort((f,J)=>e[f*3+1]-e[J*3+1]);let R=0,S=0,V=0;for(let f=1;f<=b.length;f++)(f===b.length||e[b[f]*3+1]-e[b[f-1]*3+1]>6)&&(e[b[f-1]*3+1]-e[b[V]*3+1]>e[b[S]*3+1]-e[b[R]*3+1]&&(R=V,S=f-1),V=f);const I=b.slice(R,S+1);if(I.length<C)continue;w=D(I)??w;const G=Math.hypot(1,w.q),X=e[I[0]*3+1],Y=e[I[I.length-1]*3+1],Z=(Y-X)*G;let $=0;for(const f of I)$+=((e[f*3]-w.p-w.q*e[f*3+1])/G)**2;if(!(Z<M*r||Math.sqrt($/I.length)>.8||Math.abs(Math.atan(-w.q)/B-_)>2.5)){for(const f of q(w,2))e[f*3+1]>=X-2&&e[f*3+1]<=Y+2&&(N[f]=1);j.push({x0:w.p+w.q*X+n/2,y0:X+r/2,x1:w.p+w.q*Y+n/2,y1:Y+r/2,length:Z})}}return j.sort((c,h)=>h.length-c.length).slice(0,i)}function Mt(t,n,r,s,{agree:M=z.agree,maxTilt:i=z.maxTilt}={}){const y=t.map(o=>({n:Q(et([o.x0-n/2,o.y0-r/2,s],[o.x1-n/2,o.y1-r/2,s])),length:o.length}));if(y.length<3)return null;const E=Math.sin(M*B),A=o=>{let l=0;const e=[];for(const O of y)Math.abs(pt(O.n,o))<E&&(l+=O.length,e.push(O));return{score:l,inl:e}},m=o=>o[1]>0?[-o[0],-o[1],-o[2]]:o;let x=null;const v=[[0,-1,0]];for(let o=0;o<y.length;o++)for(let l=o+1;l<y.length;l++){const e=et(y[o].n,y[l].n);Math.hypot(...e)>1e-4&&v.push(m(Q(e)))}for(const o of v){if(Math.acos(Math.min(1,-o[1]))>i*B)continue;const l=A(o);(!x||l.score>x.score)&&(x={...l,U:o})}if(!x||x.inl.length<3)return null;const p=[0,0,0,0,0,0,0,0,0];for(const o of x.inl)for(let l=0;l<3;l++)for(let e=0;e<3;e++)p[l*3+e]+=o.length*o.n[l]*o.n[e];const T=p[0]+p[4]+p[8];p[0]+=T*1e-6,p[4]+=T*1e-6,p[8]+=T*1e-6;const g=(o=>{const[l,e,O,C,L,N,j,D,K]=o,c=L*K-N*D,h=-(C*K-N*j),a=C*D-L*j,d=l*c+e*h+O*a;return Math.abs(d)<1e-18?null:[c/d,-(e*K-O*D)/d,(e*N-O*L)/d,h/d,(l*K-O*j)/d,-(l*N-O*C)/d,a/d,-(l*D-e*j)/d,(l*L-e*C)/d]})(p);let u=x.U;if(g)for(let o=0;o<12;o++)u=m(Q([g[0]*u[0]+g[1]*u[1]+g[2]*u[2],g[3]*u[0]+g[4]*u[1]+g[5]*u[2],g[6]*u[0]+g[7]*u[1]+g[8]*u[2]]));Math.acos(Math.min(1,-u[1]))>i*B&&(u=x.U);const F=x.inl.reduce((o,l)=>o+l.length,0)/r;return{tilt:Math.asin(Math.max(-1,Math.min(1,u[2])))/B,roll:Math.atan2(u[0],-u[1])/B,lines:x.inl.length,support:F,up:u}}function gt(t,n,r,s){const M=dt(t,n,r),i=Mt(M,n,r,s/36*n);return i&&i.lines>=z.minLines&&i.support>=z.minSupport?{...i,found:M.length}:null}const ot=28,yt=1.5,k=t=>Math.round(t*1e3)/1e3,bt=(t,n)=>{const r=t.filter(Number.isFinite).sort((s,M)=>s-M);return r.length?r[Math.min(r.length-1,Math.floor(r.length*n))]:NaN},wt=(t,n,r,s)=>{const M=n*Math.PI/180;return at({position:[0,0,0],target:[0,Math.sin(M),-Math.cos(M)],lens:t,roll:r,aspect:s})};function xt(t,n="16:9"){const r=t.lens??ot,s=t.tilt??t.seen?.tilt??0,M=t.roll??(t.tilt==null?t.seen?.roll:null)??0,i={lens:t.lens!=null?"given":"assumed",tilt:t.tilt!=null?"given":t.seen?"lines":"level",height:t.height!=null?"given":"default",place:"default"},y=wt(r,s,M,n),E=it(t.frames.filter(p=>p.lm&&p.lm.length>=33),t.aspect).filter(p=>p.lm);let A=t.height??yt,m=[0,-4];if(E.length>=2){const p=E.map(l=>l.wl&&l.wl.length>=33?l.wl:ct(l.lm,t.aspect)),T=ht(E.map((l,e)=>ut(y,l.lm,p[e]))),P=E.map((l,e)=>{const O=mt(l.lm);return-nt(y,l.lm[O][0],l.lm[O][1]).y*T[e]+ft[O]}),g=bt(P,.7);t.height==null&&g>.15&&g<30&&(A=g,i.height="feet");const u=E.map((l,e)=>nt(y,(l.lm[23][0]+l.lm[24][0])/2,(l.lm[23][1]+l.lm[24][1])/2).multiplyScalar(T[e])),F=u.filter((l,e)=>Math.abs(P[e]-A)<.2*A),o=F.length>=2?F:u;m=[W(o.map(l=>l.x)),W(o.map(l=>l.z))],i.place="person"}const x=s*Math.PI/180,v=[k(-m[0]),k(A),k(-m[1])];return{lens:k(r),height:k(A),tilt:k(s),roll:k(M),distance:k(Math.hypot(m[0],m[1])),position:v,target:[k(v[0]),k(v[1]+Math.sin(x)*4),k(v[2]-Math.cos(x)*4)],by:i,lines:t.tilt==null?t.seen?.lines??0:0}}function At(t,n){const r={...t.plate,match:{lens:n.lens,height:n.height,tilt:n.tilt,roll:n.roll}};return{...t,plate:r,shots:t.shots.map(s=>s.id!==t.activeShot?s:{...s,position:n.position,target:n.target,lens:n.lens,roll:n.roll,endPosition:n.position,endTarget:n.target,endLens:n.lens,motion:"static",cameraKeys:[]})}}const vt=t=>{const n=t.shots.find(r=>r.id===t.activeShot);return!!t.plate&&!!n&&!n.cameraKeys?.length};function Ut(t){const n=t.shots.find(M=>M.id===t.activeShot),r=st().shots[0],s=(M,i)=>M.every((y,E)=>Math.abs(y-i[E])<1e-6);return!!n&&s(n.position,r.position)&&s(n.target,r.target)&&Math.abs(n.lens-r.lens)<1e-6&&!n.roll}async function zt(t,n={},r={}){const s=t.plate,M=t.shots.find(v=>v.id===t.activeShot);if(!s||!M)throw new Error("no-plate");if(!vt(t))throw new Error("camera-keyed");const[i,y]=(M.aspect||"16:9").split(":").map(Number);let E=[],A=i/y||16/9,m=null;if(!(n.lens!=null&&n.height!=null&&n.tilt!=null)){const{readPlate:v}=await rt(async()=>{const{readPlate:T}=await import("./plateFollow-D2rjnmZA.js");return{readPlate:T}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16])),p=await v(t,r);E=p.tracked.frames,A=i/y||p.tracked.aspect,n.tilt==null&&(m=await Et(p.url,s.inPoint,p.span,n.lens??ot,r.signal).catch(T=>{if(T.name==="AbortError")throw T;return null}))}const x=xt({frames:E,aspect:A,lens:n.lens??null,tilt:n.tilt??null,roll:n.roll??null,height:n.height??null,seen:m},M.aspect);return{stage:At(t,x),match:x,found:E.filter(v=>v.lm).length}}async function Et(t,n,r,s,M){const i=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});i.src=t;try{await new Promise((T,P)=>{i.onloadeddata=()=>T(),i.onerror=()=>P(new Error("plate-unreadable"))});const y=i.videoWidth||1280,E=i.videoHeight||720,A=Math.min(960,y),m=Math.max(2,Math.round(A*E/y)),x=Object.assign(document.createElement("canvas"),{width:A,height:m}),v=x.getContext("2d",{willReadFrequently:!0}),p=[];for(const T of[.1,.3,.5,.7,.9]){if(M?.aborted)throw new DOMException("Đã huỷ","AbortError");const P=Math.max(0,Math.min(i.duration-1/60,n+r*T));Math.abs(i.currentTime-P)>1e-4&&await new Promise((o,l)=>{const e=window.setTimeout(()=>l(new Error("plate-seek")),8e3);i.onseeked=()=>{window.clearTimeout(e),o()},i.currentTime=P}),v.drawImage(i,0,0,A,m);const g=v.getImageData(0,0,A,m).data,u=new Uint8Array(A*m);for(let o=0;o<u.length;o++)u[o]=g[o*4]*77+g[o*4+1]*150+g[o*4+2]*29>>8;const F=gt(u,A,m,s);F&&p.push({tilt:F.tilt,roll:F.roll,lines:F.lines})}return Tt(p)}finally{i.removeAttribute("src"),i.load()}}function Tt(t){if(t.length<2)return null;const n=W(t.map(s=>s.tilt)),r=W(t.map(s=>s.roll));return t.filter(s=>Math.abs(s.tilt-n)<=5).length<Math.max(2,t.length*.6)?null:{tilt:k(n),roll:k(r),lines:Math.round(W(t.map(s=>s.lines)))}}export{yt as MATCH_HEIGHT,ot as MATCH_LENS,At as applyCameraMatch,xt as matchCamera,zt as matchPlateCamera,vt as matchable,Tt as tiltOfReads,Et as tiltOfStills,Ut as untouchedCamera};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-CzEKvJph.js","assets/titleFrameBudget-DsM0V482.js","assets/store-CpqHUcA2.js","assets/index-CKtv7gGE.js","assets/i18n-C9zFX25m.js","assets/personHq-Ca351o06.js","assets/matteQuality-9X-jgJrH.js","assets/api-Dnl2uaKO.js","assets/rigTrack-DMyqb0pb.js","assets/plateMatte-CoEoVjxZ.js","assets/rotoMatte-7b7Ow64f.js","assets/plateCameraMatch-GPZl1fQQ.js","assets/remote-8XzEAnAJ.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/rotoMaskStore-pE1AIt3I.js","assets/sceneTrack-DlAH5s74.js","assets/timelineOps-DSSaDsU2.js","assets/cameraTracker-DHdF8Zqx.js","assets/textAnimators-B9vO_hbP.js","assets/timelineComp-i-zdaoB2.js","assets/clientJobs-CuuUyhEy.js"])))=>i.map(i=>d[i]);
2
- import{_ as U}from"./titleFrameBudget-DsM0V482.js";import{fq as Z,ee as $,fr as tt,ef as nt,bn as G}from"./remote-8XzEAnAJ.js";import{m as et}from"./rigTrack-DMyqb0pb.js";import{Quaternion as ot,Vector3 as v}from"./three.module-Bx43vjkH.js";import"./index-CKtv7gGE.js";import"./i18n-C9zFX25m.js";import"./api-Dnl2uaKO.js";import"./gltfLoader-U0Eebg7v.js";import"./store-CpqHUcA2.js";import"./rotoMaskStore-pE1AIt3I.js";import"./sceneTrack-DlAH5s74.js";import"./timelineOps-DSSaDsU2.js";import"./cameraTracker-DHdF8Zqx.js";import"./textAnimators-B9vO_hbP.js";import"./timelineComp-i-zdaoB2.js";import"./clientJobs-CuuUyhEy.js";const n={eyeL:2,eyeR:5,earL:7,earR:8,shL:11,shR:12,elL:13,elR:14,wrL:15,wrR:16,hipL:23,hipR:24,knL:25,knR:26,anL:27,anR:28},at=[[n.shL,n.hipL],[n.shR,n.hipR],[n.hipL,n.knL],[n.hipR,n.knR],[n.shL,n.shR]],rt=15,O=(e,r)=>e.map((t,i)=>(t+r[i])/2),C=e=>{const r=e.filter(Number.isFinite).sort((t,i)=>t-i);return r.length?r[r.length>>1]:NaN};function D(e,r,t){return new v(r*2-1,1-t*2,.5).unproject(e).sub(e.position).normalize()}const q=(e,r)=>new v(e[0],-e[1],-e[2]).applyQuaternion(r);function it(e,r){const t=O(e[n.hipL],e[n.hipR]),i=O(e[n.shL],e[n.shR]),c=.5/Math.max(.001,Math.hypot((i[0]-t[0])*r,i[1]-t[1]));return e.map(u=>[(u[0]-t[0])*r*c,(u[1]-t[1])*c,u[2]*r*c])}function st(e,r,t){return C(at.map(([i,c])=>{if(Math.min(r[i][3]??1,r[c][3]??1)<.5)return NaN;const u=Math.hypot(t[i][0]-t[c][0],t[i][1]-t[c][1]);if(u<.12)return NaN;const w=D(e,r[i][0],r[i][1]).angleTo(D(e,r[c][0],r[c][1]));return w>1e-4?u/Math.tan(w):NaN}))}const lt=e=>{const r=e.filter(Number.isFinite);return r.length?r.reduce((t,i)=>t+i,0)/r.length:NaN};function W(e){const r=e.map((i,c)=>C(e.slice(Math.max(0,c-2),c+3))),t=r.map((i,c)=>lt(r.slice(Math.max(0,c-1),c+2)));return t.map((i,c)=>{if(Number.isFinite(i))return i;for(let u=1;u<t.length;u++)for(const w of[c-u,c+u])if(Number.isFinite(t[w]))return t[w];return 4})}const ct=[[1,4],[2,5],[3,6],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18],[19,20],[21,22],[23,24],[25,26],[27,28],[29,30],[31,32]],j=e=>{const r=[...e];for(const[t,i]of ct)r[t]=e[i],r[i]=e[t];return r},H=e=>(e%360+540)%360-180;function Q(e){const r=e[n.hipL][0]-e[n.hipR][0]+e[n.shL][0]-e[n.shR][0],t=e[n.hipL][2]-e[n.hipR][2]+e[n.shL][2]-e[n.shR][2];return{yaw:Math.atan2(t,r)*180/Math.PI,side:Math.abs(r)<.35*Math.hypot(r,t)}}function ht(e){const r=e.map(t=>{const{yaw:i,side:c}=Q(t.w),u=t.w[0][2]-(t.w[n.earL][2]+t.w[n.earR][2])/2,w=u<-.03?!0:u>.03?!1:null;return!c&&w!==null&&Math.abs(i)<90!==w?{lm:j(t.lm),w:j(t.w)}:t});for(let t=1;t<r.length;t++){const i=Q(r[t-1].w).yaw,c=Q(r[t].w).yaw;Math.abs(H(c-i))>110&&Math.abs(H(c+180-i))<Math.abs(H(c-i))&&(r[t]={lm:j(r[t].lm),w:j(r[t].w)})}return r}function mt(e,r=16/9){const t=[n.shL,n.shR,n.elL,n.elR,n.wrL,n.wrR,n.hipL,n.hipR,n.knL,n.knR,n.anL,n.anR],i=e.map((a,s)=>{if(!a.lm||a.lm.length<33)return null;const x=a.lm,y=O(x[n.hipL],x[n.hipR]),m=O(x[n.shL],x[n.shR]);return{i:s,t:a.t,x:y[0]*r,y:y[1],s:Math.max(.01,Math.hypot((m[0]-y[0])*r,m[1]-y[1])),vis:t.reduce((h,g)=>h+(x[g][3]??1),0)/t.length}}).filter(a=>!!a);if(i.length<4)return e;const c=i.map((a,s)=>s),u=a=>c[a]===a?a:c[a]=u(c[a]);for(let a=0;a<i.length;a++)for(let s=a+1;s<i.length;s++)Math.hypot(i[a].x-i[s].x,i[a].y-i[s].y)<=.7*Math.min(i[a].s,i[s].s)&&(c[u(a)]=u(s));const w=new Map;i.forEach((a,s)=>{const x=u(s);w.set(x,[...w.get(x)??[],a])});const M=[...w.values()].filter(a=>a.length>=3).map(a=>({g:a,t0:a[0].t,t1:a[a.length-1].t,score:a.length*C(a.map(s=>s.vis))**2}));if(!M.length||M.length===1&&M[0].g.length===i.length)return e;M.sort((a,s)=>s.score-a.score);const k=[M[0]],S=(a,s)=>Math.min(a.t1,s.t1)-Math.max(a.t0,s.t0)>.3*Math.max(.2,Math.min(a.t1-a.t0,s.t1-s.t0));for(let a=!0;a;){a=!1;for(const s of M){if(k.includes(s)||k.some(h=>S(h,s)))continue;const x=k.flatMap(h=>h.g);let y=1/0,m=!1;for(const h of[s.g[0],s.g[s.g.length-1]])for(const g of x){const R=Math.abs(g.t-h.t);R<y&&(y=R,m=Math.hypot(g.x-h.x,g.y-h.y)<=(.6+8*R)*Math.min(g.s,h.s))}m&&(k.push(s),a=!0)}}const E=new Set(k.flatMap(a=>a.g.map(s=>s.i)));return e.map((a,s)=>a.lm&&!E.has(s)?{...a,lm:null}:a)}const K=[27,28,29,30,31,32],pt={27:.09,28:.09,29:.035,30:.035,31:.03,32:.03},ft={27:"ankleR",28:"ankleL",29:"heelR",30:"heelL",31:"toeR",32:"toeL"},ut=e=>K.reduce((r,t)=>(e[t][3]??1)>=.3&&e[t][1]>e[r][1]?t:r,K[0]);function dt(e,r,t,i=16/9,c={}){const u=mt(e.filter(o=>o.lm&&o.lm.length>=33),i).filter(o=>o.lm),w=ht(u.map(o=>({lm:o.lm,w:o.wl&&o.wl.length>=33?o.wl:it(o.lm,i)}))),M=u.map((o,l)=>({...o,lm:w[l].lm})),k=w.map(o=>o.w),S=M.map(o=>r(o.t)),E=W(M.map((o,l)=>st(S[l],o.lm,k[l]))),a=(o,l,d)=>Math.hypot(o[l][0]-o[d][0],o[l][1]-o[d][1],o[l][2]-o[d][2]),s=C(k.map(o=>(a(o,n.hipL,n.knL)+a(o,n.knL,n.anL)+a(o,n.hipR,n.knR)+a(o,n.knR,n.anR))/2)),x=t/Math.max(.3,Number.isFinite(s)?s:.9),y=t/.93,m=M.map((o,l)=>{const d=k[l],f=S[l].getWorldQuaternion(new ot),b=O(d[n.hipL],d[n.hipR]),p=Y=>q(d[Y],f).multiplyScalar(x),N={hips:q(b,f).multiplyScalar(x),neck:q(O(d[n.shL],d[n.shR]),f).multiplyScalar(x),upL:p(n.shR),foreL:p(n.elR),handL:p(n.wrR),thighL:p(n.hipR),shinL:p(n.knR),footL:p(n.anR),upR:p(n.shL),foreR:p(n.elL),handR:p(n.wrL),thighR:p(n.hipL),shinR:p(n.knL),footR:p(n.anL)},{pose:F,yaw:A}=Z(N,{head:p(n.earL).add(p(n.earR)).multiplyScalar(.5),eyeA:p(n.eyeR),eyeB:p(n.eyeL)},{legTwist:!0}),z=et(F),_=O(z.hipL,z.hipR),T=Math.cos(A*Math.PI/180),I=Math.sin(A*Math.PI/180),V=new v((_[0]*T+_[2]*I)*y,_[1]*y,(-_[0]*I+_[2]*T)*y),X=D(S[l],...O(o.lm[n.hipL],o.lm[n.hipR]));return{pose:F,yaw:A,off:V,ray:X,cam:S[l],q:f,w:d,J:z}}),h=M.length,g=[...E],R=Array(h).fill(!1);if(c.floor&&h){const o=m.map((f,b)=>{const p=M[b].lm,N=ut(p),F=D(f.cam,p[N][0],p[N][1]);if(F.y>-.03)return NaN;const z=(Math.max(pt[N],f.J[ft[N]][1])*y-f.cam.position.y)/F.y;if(!(z>.3))return NaN;const _=O(f.w[n.hipL],f.w[n.hipR]),I=f.cam.position.clone().addScaledVector(F,z).add(q([_[0]-f.w[N][0],_[1]-f.w[N][1],_[2]-f.w[N][2]],f.q)).sub(f.cam.position).dot(f.ray);return I>.3?I:NaN}),l=o.map((f,b)=>f/E[b]),d=C(l.filter(f=>f>.6&&f<1.6));if(Number.isFinite(d)){const f=l.map(b=>Number.isFinite(b)&&Math.abs(b/d-1)<.12);if(f.filter(Boolean).length>=Math.max(3,h*.1)){const b=W(o.map((p,N)=>f[N]?p:NaN));for(let p=0;p<h;p++)R[p]=f[p],g[p]=f[p]?b[p]:E[p]*d}}}const B=(o,l)=>m[o].cam.position.clone().addScaledVector(m[o].ray,l).sub(m[o].off),L=m.map((o,l)=>B(l,g[l]));if(R.some(Boolean)){for(let o=0;o<h;o++)R[o]&&(L[o].y=0);for(let o=0;o<h;o++){if(R[o])continue;let l=o-1,d=o+1;for(;l>=0&&!R[l];)l--;for(;d<h&&!R[d];)d++;const f=l>=0?M[o].t-M[l].t:1/0,b=d<h?M[d].t-M[o].t:1/0;if(Math.min(f,b)>8)continue;const p=l>=0&&d<h?f/(f+b):l>=0?0:1,N=L[l>=0?l:d],F=L[d<h?d:l],A=N.x+(F.x-N.x)*p+m[o].off.x,z=N.z+(F.z-N.z)*p+m[o].off.z,{ray:_,cam:T}=m[o],I=_.x*_.x+_.z*_.z;if(I<.04)continue;const V=((A-T.position.x)*_.x+(z-T.position.z)*_.z)/I;V>.3&&(L[o]=B(o,V),g[o]=V,L[o].y<.02&&(L[o].y=0,R[o]=!0))}}const P=o=>Math.round(o*1e3)/1e3;return M.map((o,l)=>{const d=m[l].cam.position.clone().addScaledVector(m[l].ray,g[l]);return{time:o.t,pose:m[l].pose,position:[P(L[l].x),P(L[l].y),P(L[l].z)],yaw:m[l].yaw,hips:[P(d.x),P(d.y),P(d.z)],...c.floor&&R.some(Boolean)?R[l]?{grounded:!0}:{air:!0}:{}}})}let J=null;async function yt(e,r={}){const t=e.plate,i=e.shots.find(m=>m.id===e.activeShot);if(!t||!i)throw new Error("no-plate");const c=G.plateUrl?await G.plateUrl(t).catch(()=>t.url):t.url,u=r.fps??rt,w=Math.min(i.duration,t.duration),M=[t.gcsUri||t.url,t.inPoint,w,u].join("|");if(J?.key===M)return J;const[{trackPose:k},{matteAt:S,plateMatte:E}]=await Promise.all([U(()=>import("./poseTracker-CzEKvJph.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])),U(()=>import("./plateMatte-CoEoVjxZ.js"),__vite__mapDeps([9,1,10,7,4,3,2]))]),a=await E(e,c,{signal:r.signal,coarse:!0});let s;if(a){const m=g=>{const R=S(a,g).box;return R?{box:R}:null},h=Array.from({length:9},(g,R)=>S(a,t.inPoint+w*R/8).box?.h).filter(g=>g!=null).sort((g,R)=>g-R);s=Object.assign(m,{crop:h.length>3&&h[h.length>>1]<.4})}const x=m=>k({clip:{inPoint:t.inPoint,playbackRate:1},url:c,from:0,duration:w,fps:u,signal:r.signal,onProgress:r.progress,focus:m});let y=await x(s);if(s&&y.frames.filter(m=>m.lm).length<y.frames.length*.85){const m=await x();m.frames.filter(h=>h.lm).length>y.frames.filter(h=>h.lm).length&&(y=m,s=void 0)}return J={key:M,url:c,span:w,tracked:y,matte:a&&s?a.made?"made":"timeline":"none"},J}async function It(e,r,t){const i=e.plate,c=e.shots.find(L=>L.id===e.activeShot),u=e.items.find(L=>L.id===r);if(!i||!c)throw new Error("no-plate");if(!u||u.kind!=="person")throw new Error("no-person");const{url:w,span:M,tracked:k,matte:S}=await yt(e,t),E=k.frames.filter(L=>L.lm).length;if(E<2)throw new Error("no-person-in-plate");const[a,s]=(c.aspect||"16:9").split(":").map(Number),x=a/s||k.aspect;let y=e,m;const h=await U(()=>import("./plateCameraMatch-GPZl1fQQ.js"),__vite__mapDeps([11,1,12,3,4,7,13,14,2,15,16,17,18,19,20,8,21]));if(t.match!==!1&&h.matchable(e)&&(t.match===!0||t.lens!=null||!i.match&&h.untouchedCamera(e))){const L=typeof document>"u"?null:await h.tiltOfStills(w,i.inPoint,M,t.lens??i.match?.lens??h.MATCH_LENS,t.signal).catch(P=>{if(P.name==="AbortError")throw P;return null});m=h.matchCamera({frames:k.frames,aspect:x,lens:t.lens??null,seen:L},c.aspect),y=h.applyCameraMatch(e,m)}const g=y.shots.find(L=>L.id===y.activeShot),R=dt(k.frames,L=>tt(g,Math.min(1,L/g.duration)),.93*$(u)*(u.scale[1]||1),x,{floor:!!y.plate?.match}),B=nt(y,r,R,0,t.newId,{replace:"all"});return{stage:B.stage,keys:B.keys,found:E,frames:k.frames.length,hips:R.map(L=>({time:L.time/g.duration,at:L.hips})),matte:S,...m?{camera:m}:{}}}export{K as FEET,rt as FOLLOW_FPS,pt as FOOT_HEIGHT,n as LM,dt as bakeFollow,st as depthOf,ht as fixSides,It as followPlate,ut as lowestFoot,mt as mainBody,C as median,D as rayOf,yt as readPlate,W as smooth,it as worldOf};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-qtuytI-L.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/store-D3Y663py.js","assets/index-CKtv7gGE.js","assets/i18n-ClNt3LKg.js","assets/personHq-CBP8v_cw.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/rigTrack-BbKqZGs7.js","assets/plateMatte-0tTG7oeO.js","assets/rotoMatte-BI-vjjrv.js","assets/plateCameraMatch-4VUlUMi-.js","assets/remote-CpkPQOQH.js","assets/three.module-Bx43vjkH.js","assets/gltfLoader-U0Eebg7v.js","assets/rotoMaskStore-BZBJLcCp.js","assets/sceneTrack-CO4fTjft.js","assets/timelineOps-f1WsVbgS.js","assets/cameraTracker-Df9jWmz6.js","assets/textAnimators-C4eMnVRD.js","assets/timelineComp-Ciu9JCWJ.js","assets/clientJobs-CuuUyhEy.js"])))=>i.map(i=>d[i]);
2
+ import{_ as U}from"./titleFrameBudget-h4nOQ5u9.js";import{fq as Z,ee as $,fr as tt,ef as nt,bn as G}from"./remote-CpkPQOQH.js";import{m as et}from"./rigTrack-BbKqZGs7.js";import{Quaternion as ot,Vector3 as v}from"./three.module-Bx43vjkH.js";import"./index-CKtv7gGE.js";import"./i18n-ClNt3LKg.js";import"./api-CZoVJ9Fy.js";import"./gltfLoader-U0Eebg7v.js";import"./store-D3Y663py.js";import"./rotoMaskStore-BZBJLcCp.js";import"./sceneTrack-CO4fTjft.js";import"./timelineOps-f1WsVbgS.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./clientJobs-CuuUyhEy.js";const n={eyeL:2,eyeR:5,earL:7,earR:8,shL:11,shR:12,elL:13,elR:14,wrL:15,wrR:16,hipL:23,hipR:24,knL:25,knR:26,anL:27,anR:28},at=[[n.shL,n.hipL],[n.shR,n.hipR],[n.hipL,n.knL],[n.hipR,n.knR],[n.shL,n.shR]],rt=15,O=(e,r)=>e.map((t,i)=>(t+r[i])/2),C=e=>{const r=e.filter(Number.isFinite).sort((t,i)=>t-i);return r.length?r[r.length>>1]:NaN};function D(e,r,t){return new v(r*2-1,1-t*2,.5).unproject(e).sub(e.position).normalize()}const q=(e,r)=>new v(e[0],-e[1],-e[2]).applyQuaternion(r);function it(e,r){const t=O(e[n.hipL],e[n.hipR]),i=O(e[n.shL],e[n.shR]),c=.5/Math.max(.001,Math.hypot((i[0]-t[0])*r,i[1]-t[1]));return e.map(u=>[(u[0]-t[0])*r*c,(u[1]-t[1])*c,u[2]*r*c])}function st(e,r,t){return C(at.map(([i,c])=>{if(Math.min(r[i][3]??1,r[c][3]??1)<.5)return NaN;const u=Math.hypot(t[i][0]-t[c][0],t[i][1]-t[c][1]);if(u<.12)return NaN;const w=D(e,r[i][0],r[i][1]).angleTo(D(e,r[c][0],r[c][1]));return w>1e-4?u/Math.tan(w):NaN}))}const lt=e=>{const r=e.filter(Number.isFinite);return r.length?r.reduce((t,i)=>t+i,0)/r.length:NaN};function W(e){const r=e.map((i,c)=>C(e.slice(Math.max(0,c-2),c+3))),t=r.map((i,c)=>lt(r.slice(Math.max(0,c-1),c+2)));return t.map((i,c)=>{if(Number.isFinite(i))return i;for(let u=1;u<t.length;u++)for(const w of[c-u,c+u])if(Number.isFinite(t[w]))return t[w];return 4})}const ct=[[1,4],[2,5],[3,6],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18],[19,20],[21,22],[23,24],[25,26],[27,28],[29,30],[31,32]],j=e=>{const r=[...e];for(const[t,i]of ct)r[t]=e[i],r[i]=e[t];return r},H=e=>(e%360+540)%360-180;function Q(e){const r=e[n.hipL][0]-e[n.hipR][0]+e[n.shL][0]-e[n.shR][0],t=e[n.hipL][2]-e[n.hipR][2]+e[n.shL][2]-e[n.shR][2];return{yaw:Math.atan2(t,r)*180/Math.PI,side:Math.abs(r)<.35*Math.hypot(r,t)}}function ht(e){const r=e.map(t=>{const{yaw:i,side:c}=Q(t.w),u=t.w[0][2]-(t.w[n.earL][2]+t.w[n.earR][2])/2,w=u<-.03?!0:u>.03?!1:null;return!c&&w!==null&&Math.abs(i)<90!==w?{lm:j(t.lm),w:j(t.w)}:t});for(let t=1;t<r.length;t++){const i=Q(r[t-1].w).yaw,c=Q(r[t].w).yaw;Math.abs(H(c-i))>110&&Math.abs(H(c+180-i))<Math.abs(H(c-i))&&(r[t]={lm:j(r[t].lm),w:j(r[t].w)})}return r}function mt(e,r=16/9){const t=[n.shL,n.shR,n.elL,n.elR,n.wrL,n.wrR,n.hipL,n.hipR,n.knL,n.knR,n.anL,n.anR],i=e.map((a,s)=>{if(!a.lm||a.lm.length<33)return null;const x=a.lm,y=O(x[n.hipL],x[n.hipR]),m=O(x[n.shL],x[n.shR]);return{i:s,t:a.t,x:y[0]*r,y:y[1],s:Math.max(.01,Math.hypot((m[0]-y[0])*r,m[1]-y[1])),vis:t.reduce((h,g)=>h+(x[g][3]??1),0)/t.length}}).filter(a=>!!a);if(i.length<4)return e;const c=i.map((a,s)=>s),u=a=>c[a]===a?a:c[a]=u(c[a]);for(let a=0;a<i.length;a++)for(let s=a+1;s<i.length;s++)Math.hypot(i[a].x-i[s].x,i[a].y-i[s].y)<=.7*Math.min(i[a].s,i[s].s)&&(c[u(a)]=u(s));const w=new Map;i.forEach((a,s)=>{const x=u(s);w.set(x,[...w.get(x)??[],a])});const M=[...w.values()].filter(a=>a.length>=3).map(a=>({g:a,t0:a[0].t,t1:a[a.length-1].t,score:a.length*C(a.map(s=>s.vis))**2}));if(!M.length||M.length===1&&M[0].g.length===i.length)return e;M.sort((a,s)=>s.score-a.score);const k=[M[0]],S=(a,s)=>Math.min(a.t1,s.t1)-Math.max(a.t0,s.t0)>.3*Math.max(.2,Math.min(a.t1-a.t0,s.t1-s.t0));for(let a=!0;a;){a=!1;for(const s of M){if(k.includes(s)||k.some(h=>S(h,s)))continue;const x=k.flatMap(h=>h.g);let y=1/0,m=!1;for(const h of[s.g[0],s.g[s.g.length-1]])for(const g of x){const R=Math.abs(g.t-h.t);R<y&&(y=R,m=Math.hypot(g.x-h.x,g.y-h.y)<=(.6+8*R)*Math.min(g.s,h.s))}m&&(k.push(s),a=!0)}}const E=new Set(k.flatMap(a=>a.g.map(s=>s.i)));return e.map((a,s)=>a.lm&&!E.has(s)?{...a,lm:null}:a)}const K=[27,28,29,30,31,32],pt={27:.09,28:.09,29:.035,30:.035,31:.03,32:.03},ft={27:"ankleR",28:"ankleL",29:"heelR",30:"heelL",31:"toeR",32:"toeL"},ut=e=>K.reduce((r,t)=>(e[t][3]??1)>=.3&&e[t][1]>e[r][1]?t:r,K[0]);function dt(e,r,t,i=16/9,c={}){const u=mt(e.filter(o=>o.lm&&o.lm.length>=33),i).filter(o=>o.lm),w=ht(u.map(o=>({lm:o.lm,w:o.wl&&o.wl.length>=33?o.wl:it(o.lm,i)}))),M=u.map((o,l)=>({...o,lm:w[l].lm})),k=w.map(o=>o.w),S=M.map(o=>r(o.t)),E=W(M.map((o,l)=>st(S[l],o.lm,k[l]))),a=(o,l,d)=>Math.hypot(o[l][0]-o[d][0],o[l][1]-o[d][1],o[l][2]-o[d][2]),s=C(k.map(o=>(a(o,n.hipL,n.knL)+a(o,n.knL,n.anL)+a(o,n.hipR,n.knR)+a(o,n.knR,n.anR))/2)),x=t/Math.max(.3,Number.isFinite(s)?s:.9),y=t/.93,m=M.map((o,l)=>{const d=k[l],f=S[l].getWorldQuaternion(new ot),b=O(d[n.hipL],d[n.hipR]),p=Y=>q(d[Y],f).multiplyScalar(x),N={hips:q(b,f).multiplyScalar(x),neck:q(O(d[n.shL],d[n.shR]),f).multiplyScalar(x),upL:p(n.shR),foreL:p(n.elR),handL:p(n.wrR),thighL:p(n.hipR),shinL:p(n.knR),footL:p(n.anR),upR:p(n.shL),foreR:p(n.elL),handR:p(n.wrL),thighR:p(n.hipL),shinR:p(n.knL),footR:p(n.anL)},{pose:F,yaw:A}=Z(N,{head:p(n.earL).add(p(n.earR)).multiplyScalar(.5),eyeA:p(n.eyeR),eyeB:p(n.eyeL)},{legTwist:!0}),z=et(F),_=O(z.hipL,z.hipR),T=Math.cos(A*Math.PI/180),I=Math.sin(A*Math.PI/180),V=new v((_[0]*T+_[2]*I)*y,_[1]*y,(-_[0]*I+_[2]*T)*y),X=D(S[l],...O(o.lm[n.hipL],o.lm[n.hipR]));return{pose:F,yaw:A,off:V,ray:X,cam:S[l],q:f,w:d,J:z}}),h=M.length,g=[...E],R=Array(h).fill(!1);if(c.floor&&h){const o=m.map((f,b)=>{const p=M[b].lm,N=ut(p),F=D(f.cam,p[N][0],p[N][1]);if(F.y>-.03)return NaN;const z=(Math.max(pt[N],f.J[ft[N]][1])*y-f.cam.position.y)/F.y;if(!(z>.3))return NaN;const _=O(f.w[n.hipL],f.w[n.hipR]),I=f.cam.position.clone().addScaledVector(F,z).add(q([_[0]-f.w[N][0],_[1]-f.w[N][1],_[2]-f.w[N][2]],f.q)).sub(f.cam.position).dot(f.ray);return I>.3?I:NaN}),l=o.map((f,b)=>f/E[b]),d=C(l.filter(f=>f>.6&&f<1.6));if(Number.isFinite(d)){const f=l.map(b=>Number.isFinite(b)&&Math.abs(b/d-1)<.12);if(f.filter(Boolean).length>=Math.max(3,h*.1)){const b=W(o.map((p,N)=>f[N]?p:NaN));for(let p=0;p<h;p++)R[p]=f[p],g[p]=f[p]?b[p]:E[p]*d}}}const B=(o,l)=>m[o].cam.position.clone().addScaledVector(m[o].ray,l).sub(m[o].off),L=m.map((o,l)=>B(l,g[l]));if(R.some(Boolean)){for(let o=0;o<h;o++)R[o]&&(L[o].y=0);for(let o=0;o<h;o++){if(R[o])continue;let l=o-1,d=o+1;for(;l>=0&&!R[l];)l--;for(;d<h&&!R[d];)d++;const f=l>=0?M[o].t-M[l].t:1/0,b=d<h?M[d].t-M[o].t:1/0;if(Math.min(f,b)>8)continue;const p=l>=0&&d<h?f/(f+b):l>=0?0:1,N=L[l>=0?l:d],F=L[d<h?d:l],A=N.x+(F.x-N.x)*p+m[o].off.x,z=N.z+(F.z-N.z)*p+m[o].off.z,{ray:_,cam:T}=m[o],I=_.x*_.x+_.z*_.z;if(I<.04)continue;const V=((A-T.position.x)*_.x+(z-T.position.z)*_.z)/I;V>.3&&(L[o]=B(o,V),g[o]=V,L[o].y<.02&&(L[o].y=0,R[o]=!0))}}const P=o=>Math.round(o*1e3)/1e3;return M.map((o,l)=>{const d=m[l].cam.position.clone().addScaledVector(m[l].ray,g[l]);return{time:o.t,pose:m[l].pose,position:[P(L[l].x),P(L[l].y),P(L[l].z)],yaw:m[l].yaw,hips:[P(d.x),P(d.y),P(d.z)],...c.floor&&R.some(Boolean)?R[l]?{grounded:!0}:{air:!0}:{}}})}let J=null;async function yt(e,r={}){const t=e.plate,i=e.shots.find(m=>m.id===e.activeShot);if(!t||!i)throw new Error("no-plate");const c=G.plateUrl?await G.plateUrl(t).catch(()=>t.url):t.url,u=r.fps??rt,w=Math.min(i.duration,t.duration),M=[t.gcsUri||t.url,t.inPoint,w,u].join("|");if(J?.key===M)return J;const[{trackPose:k},{matteAt:S,plateMatte:E}]=await Promise.all([U(()=>import("./poseTracker-qtuytI-L.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8])),U(()=>import("./plateMatte-0tTG7oeO.js"),__vite__mapDeps([9,1,10,7,4,3,2]))]),a=await E(e,c,{signal:r.signal,coarse:!0});let s;if(a){const m=g=>{const R=S(a,g).box;return R?{box:R}:null},h=Array.from({length:9},(g,R)=>S(a,t.inPoint+w*R/8).box?.h).filter(g=>g!=null).sort((g,R)=>g-R);s=Object.assign(m,{crop:h.length>3&&h[h.length>>1]<.4})}const x=m=>k({clip:{inPoint:t.inPoint,playbackRate:1},url:c,from:0,duration:w,fps:u,signal:r.signal,onProgress:r.progress,focus:m});let y=await x(s);if(s&&y.frames.filter(m=>m.lm).length<y.frames.length*.85){const m=await x();m.frames.filter(h=>h.lm).length>y.frames.filter(h=>h.lm).length&&(y=m,s=void 0)}return J={key:M,url:c,span:w,tracked:y,matte:a&&s?a.made?"made":"timeline":"none"},J}async function It(e,r,t){const i=e.plate,c=e.shots.find(L=>L.id===e.activeShot),u=e.items.find(L=>L.id===r);if(!i||!c)throw new Error("no-plate");if(!u||u.kind!=="person")throw new Error("no-person");const{url:w,span:M,tracked:k,matte:S}=await yt(e,t),E=k.frames.filter(L=>L.lm).length;if(E<2)throw new Error("no-person-in-plate");const[a,s]=(c.aspect||"16:9").split(":").map(Number),x=a/s||k.aspect;let y=e,m;const h=await U(()=>import("./plateCameraMatch-4VUlUMi-.js"),__vite__mapDeps([11,1,12,3,4,7,13,14,2,15,16,17,18,19,20,8,21]));if(t.match!==!1&&h.matchable(e)&&(t.match===!0||t.lens!=null||!i.match&&h.untouchedCamera(e))){const L=typeof document>"u"?null:await h.tiltOfStills(w,i.inPoint,M,t.lens??i.match?.lens??h.MATCH_LENS,t.signal).catch(P=>{if(P.name==="AbortError")throw P;return null});m=h.matchCamera({frames:k.frames,aspect:x,lens:t.lens??null,seen:L},c.aspect),y=h.applyCameraMatch(e,m)}const g=y.shots.find(L=>L.id===y.activeShot),R=dt(k.frames,L=>tt(g,Math.min(1,L/g.duration)),.93*$(u)*(u.scale[1]||1),x,{floor:!!y.plate?.match}),B=nt(y,r,R,0,t.newId,{replace:"all"});return{stage:B.stage,keys:B.keys,found:E,frames:k.frames.length,hips:R.map(L=>({time:L.time/g.duration,at:L.hips})),matte:S,...m?{camera:m}:{}}}export{K as FEET,rt as FOLLOW_FPS,pt as FOOT_HEIGHT,n as LM,dt as bakeFollow,st as depthOf,ht as fixSides,It as followPlate,ut as lowestFoot,mt as mainBody,C as median,D as rayOf,yt as readPlate,W as smooth,it as worldOf};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/personHq-CBP8v_cw.js","assets/titleFrameBudget-h4nOQ5u9.js","assets/matteQuality-9X-jgJrH.js","assets/api-CZoVJ9Fy.js","assets/i18n-ClNt3LKg.js","assets/index-CKtv7gGE.js"])))=>i.map(i=>d[i]);
2
+ import{dd as c,a7 as m,_ as h}from"./titleFrameBudget-h4nOQ5u9.js";import"./rotoMatte-BI-vjjrv.js";import{u as w}from"./store-D3Y663py.js";import"./api-CZoVJ9Fy.js";import"./i18n-ClNt3LKg.js";import"./index-CKtv7gGE.js";function M(a){const l=a.plate,r=l?.timelineClipId;if(!l||!r)return null;const n=w.getState().clips,t=n.find(e=>e.id===r),o=e=>e?.person&&e.person.src!=="object"?e.person:null;return o(t)??o(n.find(e=>e.id!==r&&e.kind==="video"&&!!e.person&&(e.id===`${r}-person`||!!t&&e.url===t.url&&e.start===t.start)))}async function S(a,l,r={}){const n=M(a);try{if(n)return{p:n,frames:await m(n),made:!1};const t=a.plate,o=a.shots.find(d=>d.id===a.activeShot),{segmentPerson:e}=await h(async()=>{const{segmentPerson:d}=await import("./personHq-CBP8v_cw.js").then(u=>u.i);return{segmentPerson:d}},__vite__mapDeps([0,1,2,3,4,5])),f={id:"plate",nodeId:"",kind:"video",url:l,label:t.label,track:0,start:0,inPoint:t.inPoint,duration:Math.min(o.duration,t.duration),volume:0},p=await e({clip:f,url:l,signal:r.signal,...r.coarse?{fps:6}:{},quality:{store:!1,...r.coarse?{ai:!1}:{}}});return{p,frames:await m(p),made:!0}}catch(t){if(t.name==="AbortError")throw t;return null}}function k(a,l){const r=c(a.frames,a.p,l),{w:n,h:t}=a.p;let o=n,e=t,f=-1,p=-1,d=0;for(let i=0;i<t;i++)for(let s=0;s<n;s++)r[i*n+s]>127&&(d++,s<o&&(o=s),s>f&&(f=s),i<e&&(e=i),i>p&&(p=i));const u=f<0||d>n*t*.3?null:{x:o/n,y:e/t,w:(f-o+1)/n,h:(p-e+1)/t};return{a:r,w:n,h:t,box:u,at:(i,s)=>r[Math.min(t-1,Math.max(0,Math.floor(s*t)))*n+Math.min(n-1,Math.max(0,Math.floor(i*n)))]/255}}export{k as matteAt,S as plateMatte,M as plateMatteRef};
@@ -1 +1 @@
1
- import{w as c}from"./api-Dnl2uaKO.js";import{g as i}from"./i18n-C9zFX25m.js";async function e(o,t={}){const a=await c(),r=await fetch(o,{...t,headers:{"Content-Type":"application/json","Accept-Language":i(),...a?{"X-Firebase-Token":a}:{},...t.headers||{}}}),s=await r.json().catch(()=>({}));if(!r.ok){const n=new Error(s.error||`${r.status}`);throw n.status=r.status,n.code=s.code,n.args=s.args,n.data=s,n}return s}const p=o=>e("/api/ai-templates/run",{method:"POST",body:JSON.stringify({...o,dry_run:!0,locale:i()})}),m=(o,t)=>e("/api/ai-templates/run",{method:"POST",body:JSON.stringify({...o,max_credits:t,locale:i()})}).then(a=>a.doc),b=()=>e("/api/webhooks"),k=(o,t)=>e("/api/webhooks",{method:"POST",body:JSON.stringify({url:o,events:t})}).then(a=>a.endpoint),l=o=>e(`/api/webhooks/${encodeURIComponent(o)}`,{method:"PATCH",body:JSON.stringify({rotate:!0})}).then(t=>t.endpoint),y=o=>e(`/api/webhooks/${encodeURIComponent(o)}`,{method:"DELETE"}),g=o=>e(`/api/webhooks/${encodeURIComponent(o)}/test`,{method:"POST"}),u=(o,t)=>e("/api/webhooks/emit",{method:"POST",body:JSON.stringify({event:o,data:t})}).catch(()=>({sent:0}));export{k as a,y as b,m as c,u as e,b as l,p,l as r,g as t};
1
+ import{x as c}from"./api-CZoVJ9Fy.js";import{g as i}from"./i18n-ClNt3LKg.js";async function e(o,t={}){const a=await c(),r=await fetch(o,{...t,headers:{"Content-Type":"application/json","Accept-Language":i(),...a?{"X-Firebase-Token":a}:{},...t.headers||{}}}),s=await r.json().catch(()=>({}));if(!r.ok){const n=new Error(s.error||`${r.status}`);throw n.status=r.status,n.code=s.code,n.args=s.args,n.data=s,n}return s}const p=o=>e("/api/ai-templates/run",{method:"POST",body:JSON.stringify({...o,dry_run:!0,locale:i()})}),m=(o,t)=>e("/api/ai-templates/run",{method:"POST",body:JSON.stringify({...o,max_credits:t,locale:i()})}).then(a=>a.doc),b=()=>e("/api/webhooks"),k=(o,t)=>e("/api/webhooks",{method:"POST",body:JSON.stringify({url:o,events:t})}).then(a=>a.endpoint),l=o=>e(`/api/webhooks/${encodeURIComponent(o)}`,{method:"PATCH",body:JSON.stringify({rotate:!0})}).then(t=>t.endpoint),y=o=>e(`/api/webhooks/${encodeURIComponent(o)}`,{method:"DELETE"}),g=o=>e(`/api/webhooks/${encodeURIComponent(o)}/test`,{method:"POST"}),u=(o,t)=>e("/api/webhooks/emit",{method:"POST",body:JSON.stringify({event:o,data:t})}).catch(()=>({sent:0}));export{k as a,y as b,m as c,u as e,b as l,p,l as r,g as t};
@@ -0,0 +1 @@
1
+ import{de as z,cm as T,fr as et,fg as nt,dz as X,eA as mt}from"./remote-CpkPQOQH.js";import{Vector2 as C,Vector3 as ot,Euler as Z,Quaternion as ut}from"./three.module-Bx43vjkH.js";import"./index-CKtv7gGE.js";import"./i18n-ClNt3LKg.js";import"./api-CZoVJ9Fy.js";import"./titleFrameBudget-h4nOQ5u9.js";import"./gltfLoader-U0Eebg7v.js";import"./store-D3Y663py.js";import"./rotoMaskStore-BZBJLcCp.js";import"./sceneTrack-CO4fTjft.js";import"./timelineOps-f1WsVbgS.js";import"./cameraTracker-Df9jWmz6.js";import"./textAnimators-C4eMnVRD.js";import"./timelineComp-Ciu9JCWJ.js";import"./rigTrack-BbKqZGs7.js";import"./clientJobs-CuuUyhEy.js";const pt=["pop","drop","slide","flip","spin","grow"],dt=["as_given","left_right","right_left","top_bottom","bottom_top","center_out","random"],ft=["grid","scatter","collage","row","ring"],q=Object.freeze({objects:120,fps:24,minDur:.15,maxDur:3,defaultDur:.6,defaultEvery:.12,clones:120}),U=.001,L=(t,e,o)=>Math.max(e,Math.min(o,t)),G=(t,e,o)=>t+(e-t)*o,I=t=>Math.round(t*1e4)/1e4,R=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:e;function rt(t){let e=2166136261;for(const o of String(t??"pop"))e^=o.charCodeAt(0),e=Math.imul(e,16777619);return()=>{e+=1831565813;let o=e;return o=Math.imul(o^o>>>15,o|1),o^=o+Math.imul(o^o>>>7,o|61),((o^o>>>14)>>>0)/4294967296}}function Mt(t,e={}){const o=Math.max(1,Math.trunc(R(e.per_step,1))),a=Math.ceil(Math.max(0,t)/o);let s;const n=Array.isArray(e.times)?e.times.map(Number).filter(r=>Number.isFinite(r)&&r>=0).sort((r,u)=>r-u):[];if(n.length){const r=n.length>1?n[n.length-1]-n[n.length-2]:R(e.every,q.defaultEvery);s=Array.from({length:a},(u,b)=>b<n.length?n[b]:n[n.length-1]+(b-n.length+1)*r)}else if(R(e.bpm,0)>0){const r=60/L(e.bpm,20,300),u=Math.max(.25,R(e.beat_every,1));s=Array.from({length:a},(b,_)=>R(e.first_beat,R(e.start,0))+_*u*r)}else{const r=Math.max(0,R(e.every,q.defaultEvery));s=Array.from({length:a},(u,b)=>R(e.start,0)+b*r)}return Array.from({length:Math.max(0,t)},(r,u)=>I(s[Math.floor(u/o)]))}function yt(t,e="as_given",o="pop"){const a=t.map((n,r)=>r),s=n=>a.sort((r,u)=>n(r)-n(u)||r-u);switch(e){case"left_right":return s(n=>t[n][0]+t[n][1]*.001);case"right_left":return s(n=>-t[n][0]+t[n][1]*.001);case"top_bottom":return s(n=>t[n][1]+t[n][0]*.001);case"bottom_top":return s(n=>-t[n][1]+t[n][0]*.001);case"center_out":{const n=t.reduce((u,b)=>u+b[0],0)/Math.max(1,t.length),r=t.reduce((u,b)=>u+b[1],0)/Math.max(1,t.length);return s(u=>Math.hypot(t[u][0]-n,t[u][1]-r))}case"random":{const n=rt(o);for(let r=a.length-1;r>0;r--){const u=Math.floor(n()*(r+1));[a[r],a[u]]=[a[u],a[r]]}return a}default:return a}}const V=(t,e)=>{const o=G(9,3.6,e),a=Math.PI*2*G(1,1.6,e);return t>=1?1:1-Math.exp(-o*t)*Math.cos(a*t)},H=(t,e)=>{const o=G(9,3.6,e),a=Math.PI*2*G(1,1.6,e);return t>=1?0:Math.exp(-o*t)*Math.sin(a*t)},J=(t,e)=>{const o=1.2+2.2*e,a=t-1;return 1+(o+1)*a*a*a+o*a*a},W=t=>1-(1-t)**3;function gt(t,e){const{rest:o}=e,a=L(R(e.dur,q.defaultDur),q.minDur,q.maxDur),s=R(e.fps,q.fps),n=L(R(e.bounce,.6),0,1),r=Array.isArray(e.size)?e.size.map(j=>Math.max(.01,Math.abs(Number(j)||0))):[1,1,1],u=Math.max(r[0],r[1],r[2]),b=Math.max(2,Math.round(a*s)),_=o.position,i=o.rotation,l=o.scale,M=[];for(let j=0;j<=b;j++){const m=j/b,h=m*a;let f=[..._],S=[...i],d=[...l];const v=y=>l.map(c=>c*Math.max(U,y));switch(t){case"drop":{const y=R(e.height,Math.max(.6,u*1.5)),c=.55,x=L(m/.12,0,1);if(m<c){const A=m/c;f[1]=_[1]+y*(1-A*A)}else{const A=(m-c)/(1-c),k=y*.12*n;f[1]=_[1]+k*Math.max(0,Math.sin(Math.PI*L(A/.45,0,1)))}const p=m>=c?(m-c)/(1-c):-1,g=p>=0?.22*(.4+n)*Math.exp(-7*p)*Math.cos(Math.PI*3*p):m<c?-.06*(m/c):0;d=l.map((A,k)=>A*Math.max(U,x)*(k===1?1-g:1+g*.5));break}case"slide":{const y=Array.isArray(e.from)&&e.from.length>=2?e.from.map(Number):[-1,0],c=Math.hypot(y[0],y[y.length-1])||1,x=y[0]/c,p=y[y.length-1]/c,g=R(e.distance,Math.max(1.5,u*3)),A=J(m,n);f=[_[0]+x*g*(1-A),_[1],_[2]+p*g*(1-A)],S=[i[0],i[1]+(x>0?-1:1)*14*(1-A),i[2]],d=v(L(m/.08,0,1));break}case"flip":{const y=Math.max(.15,r[2]*.6)*Math.sin(Math.PI*L(m/.7,0,1));f[1]=_[1]+y,S=[i[0]-180*(1-J(L(m/.85,0,1),n*.6)),i[1],i[2]],d=v(W(L(m/.35,0,1)));break}case"spin":{const y=V(m,n);S=[i[0],i[1]-360*(1-W(m)),i[2]],d=v(y);break}case"grow":{const y=V(m,n);d=l.map((c,x)=>x===1?c*Math.max(U,y):c*Math.max(U,Math.min(1,m*6)));break}default:{const y=V(m,n);S=[i[0],i[1]+10*n*H(m,n),i[2]],f[1]=_[1]+u*.08*Math.max(0,H(m,n)),d=v(y)}}j===b&&(f=[..._],S=[...i],d=[...l]),M.push({t:I(h),position:f.map(I),rotation:S.map(I),scale:d.map(y=>I(Math.max(y,U*.999)))})}return M}function bt(t,e){const o=Math.max(0,R(e.at,0)),a=gt(t,e),s=a[a.length-1].t;return e.direction==="out"?a.map(n=>({...n,t:I(o+s-n.t)})).reverse():a.map(n=>({...n,t:I(o+n.t)}))}function wt(t,e,{duration:o,direction:a="in"}={}){const s=Math.max(1e-6,o||1),n=e[0].t/s,r=e[e.length-1].t/s,u=1e-6,b=(t||[]).filter(l=>a==="out"?l.time<n-u:l.time>r+u),_=e.map(l=>({time:Math.round(l.t/s*1e8)/1e8,position:l.position,rotation:l.rotation,scale:l.scale}));return{keys:(a==="out"?[...b,..._]:[..._,...b]).sort((l,M)=>l.time-M.time),replaced:(t||[]).length-b.length}}function xt({width:t,depth:e,sizes:o,mode:a="grid",gap:s=.08,seed:n="arrange",tilt:r=8,columns:u,fit:b=!0,jitter:_=.25,fill:i}){const l=Math.max(.1,t),M=Math.max(.1,e);if(!o.length)return{spots:[],scale:1,fits:!0,coverage:0};const m=o.reduce((S,[d,v])=>S+d*v,0);let h=typeof i=="number"&&i>0&&m>0?L(Math.sqrt(L(i,.05,.8)*l*M/m),.2,8):1;for(let S=0;S<40;S++){const d=o.map(([y,c])=>[y*h,c*h]),v=tt(a,d,l,M,s*Math.sqrt(h),n,r,u,_);if(v)return{spots:v,scale:I(h),fits:!0,coverage:I(m*h*h/(l*M))};if(!b||(h*=.92,h<.2))break}const f=o.map(([S,d])=>[S*h,d*h]);return{spots:tt("grid",f,l,M,0,n,0,u,0,!0)||f.map(()=>({u:0,v:0,yaw:0})),scale:I(h),fits:!1,coverage:I(m*h*h/(l*M))}}function tt(t,e,o,a,s,n,r,u,b,_=!1){const i=e.length,l=rt(n),M=Math.max(...e.map(d=>d[0])),j=Math.max(...e.map(d=>d[1])),m=()=>r?(l()*2-1)*r:0;if(t==="row"){const d=e.reduce((y,c)=>y+c[0],0)+s*(i-1);if(!_&&(d>o||j>a))return null;let v=-d/2;return e.map(([y])=>{const c={u:I(v+y/2),v:0,yaw:0};return v+=y+s,c})}if(t==="ring"){const d=Math.min(o-M,a-j)/2;if(i===1)return[{u:0,v:0,yaw:0}];const v=e.reduce((y,c)=>y+Math.hypot(c[0],c[1])*.8+s,0)/(2*Math.PI);return!_&&(d<=0||v>d)?null:e.map((y,c)=>{const x=c/i*Math.PI*2-Math.PI/2;return{u:I(Math.cos(x)*d),v:I(-Math.sin(x)*d),yaw:0}})}if(t==="grid"){const d=L(u?Math.trunc(u):Math.round(Math.sqrt(i*(o/(M+s))/(a/(j+s)))),1,i),v=Math.ceil(i/d),y=M+s,c=j+s;return!_&&(d*y-s>o+1e-9||v*c-s>a+1e-9)?null:e.map((x,p)=>{const g=Math.floor(p/d),A=g===v-1?i-g*d:d,k=p-g*d;return{u:I((k-(A-1)/2)*y),v:I(((v-1)/2-g)*c),yaw:0}})}if(t==="collage"){const d=e.reduce((w,N)=>w+N[0],0)/i,v=e.reduce((w,N)=>w+N[1],0)/i,y=L(Math.round(Math.sqrt(i*(o/(d+s))/(a/(v+s)))),1,i),c=Math.ceil(i/y),x=(e.reduce((w,N)=>w+N[0],0)+s*(i-c))/c,p=[];let g={items:[],w:0,d:0};e.forEach(([w,N],K)=>{const E=i-K,D=c-p.length;g.items.length&&(g.w+s+w>o||g.w+w/2>x&&E>=D&&D>1)&&(p.push(g),g={items:[],w:0,d:0}),g.items.push(K),g.w+=(g.items.length>1?s:0)+w,g.d=Math.max(g.d,N)}),p.push(g);const A=p.reduce((w,N)=>w+N.d,0)+s*(p.length-1);if(!_&&(A>a+1e-9||p.some(w=>w.w>o+1e-9)))return null;const k=new Array(i),F=Math.max(0,a-A)/(p.length+1);let P=a/2-F;for(const w of p){const N=w.items.length,K=Math.max(0,o-w.w)/(N+1);let E=-o/2+K;for(const D of w.items){const[Q,ct]=e[D],lt=(l()*2-1)*K*.4*b*2,ht=(l()*2-1)*(F*.4+(w.d-ct)/2)*b*2;k[D]={u:I(E+Q/2+lt),v:I(P-w.d/2+ht),yaw:I(m())},E+=Q+s+K}P-=w.d+s+F}return k}const h=e.map((d,v)=>v).sort((d,v)=>e[v][0]*e[v][1]-e[d][0]*e[d][1]||d-v),f=[],S=new Array(i);for(const d of h){const[v,y]=e[d],c=Math.hypot(v,y)/2;let x=null;for(let p=0;p<400&&!x;p++){const g=(l()-.5)*(o-v),A=(l()-.5)*(a-y);f.every(k=>Math.hypot(k.u-g,k.v-A)>=k.rad+c+s)&&(x={u:g,v:A})}if(!x)return null;f.push({...x,rad:c}),S[d]={u:I(x.u),v:I(x.v),yaw:I(m())}}return S}function _t(t,{count:e,spacing:o,smooth:a=!0,y:s=0,closed:n=!1}={}){const r=(t||[]).filter(h=>Array.isArray(h)&&(h.length===2||h.length===3)&&h.every(f=>Number.isFinite(Number(f)))).map(h=>h.length===2?[Number(h[0]),s,Number(h[1])]:h.map(Number));if(r.length<2)return{spots:[],length:0,error:"path needs at least 2 points"};const u=a&&r.length>2?vt(r,n):n?[...r,r[0]]:r,b=[],_=[0];for(let h=1;h<u.length;h++){const f=Math.hypot(u[h][0]-u[h-1][0],u[h][1]-u[h-1][1],u[h][2]-u[h-1][2]);b.push(f),_.push(_[h-1]+f)}const i=_[_.length-1];if(i<1e-6)return{spots:[],length:0,error:"the path has no length"};let l=Math.trunc(R(e,0));l>=1||(l=Math.max(2,Math.floor(i/Math.max(.01,R(o,.25)))+(n?0:1))),l=Math.min(l,q.clones);const M=n?i/l:l>1?i/(l-1):0,j=[];let m=1;for(let h=0;h<l;h++){const f=Math.min(i,h*M);for(;m<_.length-1&&_[m]<f;)m++;const S=u[m-1],d=u[m],v=b[m-1]>0?(f-_[m-1])/b[m-1]:0,y=[d[0]-S[0],d[1]-S[1],d[2]-S[2]],c=Math.hypot(...y)||1;j.push({position:[0,1,2].map(x=>I(G(S[x],d[x],v))),tangent:y.map(x=>I(x/c)),yaw:I(Math.atan2(-y[0],-y[2])*180/Math.PI)})}return{spots:j,length:I(i)}}function vt(t,e){const o=e?[t[t.length-1],...t,t[0],t[1]]:[t[0],...t,t[t.length-1]],a=[];for(let s=1;s<o.length-2;s++){const n=o[s-1],r=o[s],u=o[s+1],b=o[s+2],_=(h,f)=>Math.max(1e-4,Math.hypot(f[0]-h[0],f[1]-h[1],f[2]-h[2])**.5),i=0,l=i+_(n,r),M=l+_(r,u),j=M+_(u,b),m=12;for(let h=0;h<m;h++){const f=l+(M-l)*(h/m),S=B(n,r,(l-f)/(l-i),(f-i)/(l-i)),d=B(r,u,(M-f)/(M-l),(f-l)/(M-l)),v=B(u,b,(j-f)/(j-M),(f-M)/(j-M)),y=B(S,d,(M-f)/(M-i),(f-i)/(M-i)),c=B(d,v,(j-f)/(j-l),(f-l)/(j-l));a.push(B(y,c,(M-f)/(M-l),(f-l)/(M-l)))}}return a.push(e?t[0]:t[t.length-1]),a}const B=(t,e,o,a)=>[t[0]*o+e[0]*a,t[1]*o+e[1]*a,t[2]*o+e[2]*a],kt=t=>I(Math.atan2(-t[0],-t[1])*180/Math.PI),at=()=>crypto.randomUUID(),$=t=>Math.round(t*1e3)/1e3,O=(t,e)=>typeof t=="number"&&Number.isFinite(t)?t:typeof t=="string"&&t.trim()&&Number.isFinite(Number(t))?Number(t):e,Y=t=>Array.isArray(t)&&t.length>=2&&t.every(e=>Number.isFinite(Number(e)))?[Number(t[0]),Number(t[t.length-1])]:null;function st(t,e,o){let a;const s=Array.isArray(e.objects)?e.objects.map(String):Array.isArray(e.names)?e.names.map(String):[];if(s.length)try{a=s.map(r=>nt(t,r))}catch(r){return{error:r.message}}else if(typeof e.prefix=="string"&&e.prefix.trim()){const r=e.prefix.trim().toLowerCase();if(a=t.items.filter(u=>u.name.toLowerCase().startsWith(r)),!a.length)return{error:`no object's name starts with '${e.prefix}'`}}else return{error:`give objects (names) or prefix (every object whose name starts with it) to ${o}`};a=[...new Map(a.map(r=>[r.id,r])).values()];const n=a.map(r=>[r,r.kind==="fx"?"an effect has its own timing (update_effect)":X(r,"key")]).find(([,r])=>r);return n?{error:`${n[0].name}: ${n[1]}`}:a.length>q.objects?{error:`at most ${q.objects} objects per call`}:{items:a}}function it(t,e){if(e.kind==="set"&&e.set?.min&&e.set?.max){const a=e.scale,s=e.set.min,n=e.set.max;return{size:[0,1,2].map(r=>Math.abs((n[r]-s[r])*a[r])),centre:[0,1,2].map(r=>(n[r]+s[r])/2*a[r])}}const o=t.engine()?.objectBounds()?.[e.id];return o?{size:[0,1,2].map(a=>o.max[a]-o.min[a]),centre:[(o.min[0]+o.max[0])/2-e.position[0],0,(o.min[2]+o.max[2])/2-e.position[2]]}:{size:[...e.scale],centre:[0,0,0]}}function jt(t,e){const o=new ot(...e).project(t);return[(o.x+1)/2,(1-o.y)/2]}function At(t,e,o,a,s,n){const r=Math.max(1e-6,o.duration),u={},b=[];return a.forEach((i,l)=>{const M=s[l],j=n.direction==="out"?M:Math.min(r,M+n.dur),m=T(i,o,j/r),h=bt(n.style,{rest:{position:[...m.position],rotation:[...m.rotation],scale:[...m.scale]},at:M,dur:n.dur,bounce:n.bounce,size:it(t,i).size,height:n.height,from:n.from,distance:n.distance,direction:n.direction}),f=wt(o.objectKeys?.[i.id],h,{duration:r,direction:n.direction});u[i.id]=f.keys,b.push({name:i.name,at:$(M),until:$(h[h.length-1].t),replaced:f.replaced})}),{stage:{...e,shots:e.shots.map(i=>i.id!==o.id?i:{...i,objectKeys:{...i.objectKeys,...Object.fromEntries(Object.entries(u).map(([l,M])=>[l,M.map(j=>({...j,id:j.id??at()}))]))}})},report:b}}function Pt(t){return{style:pt.includes(t.style)?String(t.style):"pop",direction:t.direction==="out"?"out":"in",dur:Math.max(q.minDur,Math.min(q.maxDur,O(t.duration,q.defaultDur))),bounce:Math.max(0,Math.min(1,O(t.bounce,.6))),...t.height!=null?{height:O(t.height,1)}:{},...Y(t.from)?{from:Y(t.from)}:{},...t.distance!=null?{distance:O(t.distance,2)}:{}}}function St(t){return{start:O(t.start,.3),every:O(t.every,q.defaultEvery),per_step:O(t.per_step,1),...O(t.bpm,0)>0?{bpm:O(t.bpm,0),beat_every:O(t.beat_every,1),first_beat:O(t.first_beat,O(t.start,0))}:{},...Array.isArray(t.times)?{times:t.times.map(Number)}:{}}}function It(t,e){const o=e.getStage(),a=z(o),s=st(o,t,"pop");if("error"in s)return{ok:!1,error:s.error};const n=Pt(t),r=dt.includes(t.order)?String(t.order):"as_given",u=Mt(s.items.length,St(t)),b=et(a,Math.min(1,(u[0]??0)/Math.max(1e-6,a.duration))),_=s.items.map(m=>jt(b,T(m,a,Math.min(1,((u[0]??0)+n.dur)/Math.max(1e-6,a.duration))).position)),i=yt(_,r,t.seed??"pop"),l=i.map(m=>s.items[m]),M=Math.max(...u)+n.dur;if(M>a.duration+1e-6)return{ok:!1,error:`the last pop ends at ${$(M)} s but the shot is ${a.duration} s: set_duration ≥ ${Math.ceil(M*10)/10} s first, or a smaller every / duration`,needs_seconds:$(M)};if(a.lockUntil&&Math.min(...u)<a.lockUntil-1e-6)return{ok:!1,error:`the first pop at ${$(Math.min(...u))} s is inside the locked part (until ${$(a.lockUntil)} s)`};let j=[];return e.setStage(m=>{const h=At(e,m,z(m),l.map(f=>m.items.find(S=>S.id===f.id)??f),u,n);return j=h.report,h.stage}),{ok:!0,style:n.style,direction:n.direction,order:r,objects:j.map(({name:m,at:h,until:f})=>({name:m,at:h,until:f})),from:$(Math.min(...u)),until:$(M),...j.some(m=>m.replaced)?{replaced_keys:j.reduce((m,h)=>m+h.replaced,0)}:{},note:n.direction==="in"?"each piece is not there before its pop (keys before it were replaced); its keys after the pop are kept":"each piece is gone after its pop out (keys after it were replaced)"}}function Ot(t,e,o,a){const s=et(t,e),n=(P,w)=>{const N=new ot(P,w,.5).unproject(s),K=s.position.clone(),E=N.sub(K).normalize();if(E.y>-.001)return null;const D=(o-K.y)/E.y;return D>0?K.add(E.multiplyScalar(Math.min(D,80))):null},r=1-Math.max(0,Math.min(.45,a)),u=n(-r,r),b=n(r,r),_=n(-r,-r),i=n(r,-r);if(!u||!b||!_||!i)return{error:"the camera does not see the whole floor: aim it down at the floor (set_camera looking down, e.g. camera_preset top-down) or give area"};const l=s.matrixWorld.elements,M=new C(l[4],l[6]),j=new C(-l[8],-l[10]),m=(M.lengthSq()>.04?M:j).normalize();let h=new C(-m.y,m.x);h.x*l[0]+h.y*l[2]<0&&(h=h.multiplyScalar(-1));const f=[u,b,_,i],S=f.reduce((P,w)=>P.add(new C(w.x,w.z)),new C).multiplyScalar(.25),d=P=>{const w=new C(P.x,P.z).sub(S);return[w.dot(h),w.dot(m)]},[v,y,c,x]=f.map(d),p=Math.max(v[0],c[0]),g=Math.min(y[0],x[0]),A=Math.max(c[1],x[1]),k=Math.min(v[1],y[1]);if(g-p<.05||k-A<.05)return{error:"the floor the camera sees is too thin to arrange on: look down more steeply"};const F=S.clone().add(h.clone().multiplyScalar((p+g)/2)).add(m.clone().multiplyScalar((A+k)/2));return{centre:[F.x,F.y],right:[h.x,h.y],up:[m.x,m.y],width:g-p,depth:k-A}}function Qt(t,e){const o=e.getStage(),a=z(o),s=st(o,t,"arrange");if("error"in s)return{ok:!1,error:s.error};const n=s.items,r=ft.includes(t.mode)?String(t.mode):"collage",u=Math.max(0,Math.min(a.duration,O(t.time,0))),b=u/Math.max(1e-6,a.duration),_=O(t.floor_y,0);let i;const l=t.area;if(l&&typeof l=="object"&&Y(l.size)){const c=O(l.yaw_deg,0)*Math.PI/180,x=Y(l.center)??[0,0],p=Y(l.size);i={centre:x,right:[Math.cos(c),-Math.sin(c)],up:[-Math.sin(c),-Math.cos(c)],width:Math.abs(p[0]),depth:Math.abs(p[1])}}else{const c=Ot(a,b,_,O(t.margin,.12));if("error"in c)return{ok:!1,error:c.error};i=c}const M=t.face!=="keep",j=kt(i.up),m=n.map(c=>it(e,c)),h=m.map(({size:c},x)=>{if(M)return[c[0],c[2]];const p=(T(n[x],a,b).rotation[1]-j)*Math.PI/180,g=Math.abs(Math.cos(p)),A=Math.abs(Math.sin(p));return[c[0]*g+c[2]*A,c[0]*A+c[2]*g]}),f=xt({width:i.width,depth:i.depth,sizes:h,mode:r,gap:O(t.gap,.08),seed:t.seed??"arrange",tilt:M?O(t.tilt_deg,r==="collage"||r==="scatter"?8:0):0,columns:t.columns!=null?O(t.columns,0):void 0,fit:t.fit!==!1,...t.fill!=null?{fill:O(t.fill,0)}:{}}),S=i.right,d=i.up,v=f.scale,y=n.map((c,x)=>{const p=f.spots[x],g=T(c,a,b),A=M?j+p.yaw:g.rotation[1],k=A*Math.PI/180,F=m[x].centre[0]*v,P=m[x].centre[2]*v,w=F*Math.cos(k)+P*Math.sin(k),N=-F*Math.sin(k)+P*Math.cos(k),K=i.centre[0]+S[0]*p.u+d[0]*p.v-w,E=i.centre[1]+S[1]*p.u+d[1]*p.v-N;return{id:c.id,position:[$(K),$(_),$(E)],yaw:$(A),scale:c.scale.map(D=>$(D*v))}});return e.setStage(c=>{const x=new Map(y.map(k=>[k.id,k])),p=z(c),g=c.items.map(k=>{const F=x.get(k.id);return F?{...k,position:F.position,rotation:[k.rotation[0],F.yaw,k.rotation[2]],scale:F.scale}:k}),A={...p.objectKeys};for(const k of n){const F=x.get(k.id),P=A[k.id];if(!P?.length)continue;const w=T(k,p,b),N=[0,1,2].map(E=>F.position[E]-w.position[E]),K=F.yaw-w.rotation[1];A[k.id]=P.map(E=>({...E,position:E.position.map((D,Q)=>$(D+N[Q])),rotation:[E.rotation[0],$(E.rotation[1]+K),E.rotation[2]],scale:E.scale.map(D=>$(D*v))}))}return{...c,items:g,shots:c.shots.map(k=>k.id===p.id?{...k,objectKeys:A}:k)}}),{ok:!0,mode:r,objects:y.length,frame_m:[$(i.width),$(i.depth)],coverage:f.coverage,...v!==1?{scaled_by:v}:{},...f.coverage<.12&&t.fill==null?{hint:`the pieces cover only ${Math.round(f.coverage*100)} % of the frame: fill 0.3–0.45 scales them up together (the ident look), or bring the camera closer`}:{},...f.fits?{}:{warning:"the pieces do not fit even at 20 % size: fewer pieces, a wider shot (camera higher / shorter lens) or mode grid"},placed:y.map((c,x)=>({name:n[x].name,position:c.position,yaw_deg:c.yaw})),note:"laid out on the floor inside the camera frame (margin kept). Then pop_in to bring them in on the beat."}}function Vt(t,e){const o=e.getStage(),a=z(o);let s;try{s=nt(o,String(t.source??t.name??""))}catch(p){return{ok:!1,error:p.message}}const n=X(s,"duplicate")||X(s,"key");if(n)return{ok:!1,error:`${s.name}: ${n}`};if(s.kind==="person"||s.kind==="fx")return{ok:!1,error:"clone_along_path copies objects and models (a coin, a sticker, a kit piece), not people or effects"};const r=O(t.y,s.position[1]),u=Array.isArray(t.path)?t.path:[],b=_t(u,{count:t.count!=null?O(t.count,0):void 0,spacing:t.spacing!=null?O(t.spacing,.25):void 0,smooth:t.smooth!==!1,closed:t.closed===!0,y:r});if(b.error)return{ok:!1,error:b.error};const _=b.spots;if(_.length<2)return{ok:!1,error:"the path gives fewer than 2 spots: more count or a smaller spacing"};const i=(typeof t.group=="string"&&t.group.trim()?t.group.trim():`${s.name} path`).slice(0,40),l=p=>p.startsWith(`${i} `)&&/^\d+$/.test(p.slice(i.length+1)),M=new Set(o.items.filter(p=>l(p.name)&&!p.locked&&p.id!==s.id).map(p=>p.id)),j=t.align!=="keep",m=O(t.yaw_deg,0),h=O(t.tilt_deg,0),f=O(t.rise,0),S=p=>{const g=new Z(h*Math.PI/180,p*Math.PI/180,s.rotation[2]*Math.PI/180,"YXZ"),A=new ut().setFromEuler(g),k=new Z().setFromQuaternion(A,"XYZ");return[$(k.x*180/Math.PI),$(k.y*180/Math.PI),$(k.z*180/Math.PI)]},d=t.linked!==!1;let v=[];e.setStage(p=>{let g={...p,items:p.items.filter(P=>!M.has(P.id)),shots:p.shots.map(P=>({...P,objectKeys:Object.fromEntries(Object.entries(P.objectKeys||{}).filter(([w])=>!M.has(w)))}))};const A=[];for(let P=1;P<_.length;P++){const w=mt(g,[s.id],{linked:d,offset:[0,0,0],newId:at});g=w.stage,A.push(...w.ids)}v=A;const k=[s.id,...A],F=new Map(k.map((P,w)=>{const N=_[w],K=j?N.yaw+m:s.rotation[1]+m;return[P,{position:[N.position[0],$(N.position[1]+f*w),N.position[2]],rotation:j||h?S(K):s.rotation}]}));return g={...g,items:g.items.map(P=>{const w=F.get(P.id);if(!w)return P;const N=k.indexOf(P.id);return{...P,position:w.position,rotation:w.rotation,...N>0?{name:`${i} ${N}`}:{}}})},g={...g,shots:g.shots.map(P=>({...P,objectKeys:Object.fromEntries(Object.entries(P.objectKeys||{}).filter(([w])=>!A.includes(w)&&!(w===s.id&&P.id===a.id)))}))},g});const y=e.getStage(),c=[s.id,...v].map(p=>y.items.find(g=>g.id===p)).filter(Boolean);let x=null;if(t.grow&&typeof t.grow=="object"){const p=t.grow;if(x=It({...p,objects:c.map(g=>g.id),order:"as_given"},e),!x.ok)return{ok:!0,group:i,copies:c.length,path_length_m:b.length,grow_error:x.error,note:"the copies are placed; the grow did not apply (see grow_error) — fix it and call pop_in on them"}}return{ok:!0,source:s.name,group:i,copies:c.length,names:c.map(p=>p.name),path_length_m:b.length,linked:d,...M.size?{replaced:M.size}:{},...x?{grow:{from:x.from,until:x.until}}:{},note:'the source is the first piece on the path; copies are named "<group> 1…". Same group again = replaced. Its keys in this shot were cleared (pop_in / grow to animate).'}}export{Qt as arrange,Ot as cameraFloorFrame,Vt as cloneAlongPath,It as popIn};