1import{f as yt}from"./ctMediaConvertDownload-n0-64pPl.js";import{w as gt,c as wt}from"./ctPendingDownload-Dt1VJrS4.js";import{i as vt}from"./mediaInputFromFilename-AaKRjYpC.js";import{g as xt}from"./ffmpegVideoCompress-C_zYTcnz.js";import{r as Q}from"./mediaMetadataDisplay-rUX1VKD5.js";import{c as at,s as ct}from"./fileDropzone-CA_uaFcV.js";import{s as Mt}from"./ctToast-CcYHdnwm.js";import{w as Et}from"./wireMediaToolPageOnce-DYtotjbx.js";import{c as Ct,w as Bt,V as It}from"./videoToolRuntime-DN3EFO8-.js";import"./ctMediaProgressUi-wz6CtyvX.js";import"./ctFullscreenAd-wL9Ec5Hb.js";import"./app-Dsk0FNLH.js";import"./videoEncodeHints-B5HbAqTP.js";import"./transientNotice-Ds_di7lD.js";import"./ffmpegProbeDuration-CZSGPlSL.js";import"./videoToolFilePick-DVHx6tsU.js";import"./ffmpegWasmProbe-Dr2SB0y0.js";import"./videoToolFfmpegSession-vgvYnhrp.js";import"./ctMediaSourceOutputName-BkKiostT.js";function L(u){const a=document.getElementById("ctCropVidToastBody"),l=document.getElementById("ctCropVidToast");!a||!l||Mt(l,{bodyEl:a,message:u,delay:12e3})}function j(u){const a=Math.max(2,Math.round(u));return a%2===0?a:a-1}function tt(u){const a=u.videoWidth,l=u.videoHeight,y=u.clientWidth,g=u.clientHeight;if(!a||!l||!y||!g)return null;const i=Math.min(y/a,g/l),b=a*i,V=l*i,x=(y-b)/2,F=(g-V)/2;return{ox:x,oy:F,cw:b,ch:V,scale:i,rw:y,rh:g}}function st(u){let a=Math.min(1,Math.max(0,u.nw)),l=Math.min(1,Math.max(0,u.nh)),y=Math.min(Math.max(0,u.nx),1-a),g=Math.min(Math.max(0,u.ny),1-l);return{nx:y,ny:g,nw:a,nh:l}}function q(u){const a=u.value.trim();if(a==="")return null;const l=parseFloat(a);return Number.isFinite(l)?Math.min(100,Math.max(0,l)):null}function kt(){const u=document.getElementById("ct-crop-video-online-root");if(!Et(u,"ctCropVidWired"))return;const a=(u.dataset.ctFormat||"mp4").toLowerCase(),l=document.getElementById("ctCropVidFile"),y=document.getElementById("ctCropVidDrop"),g=document.getElementById("ctCropVidDropCaption"),i=document.getElementById("ctCropVidPreview"),b=(i==null?void 0:i.closest(".ct-media-preview-slot--video"))??null,V=document.getElementById("ctCropVidHud"),x=document.getElementById("ctCropVidBox"),F=document.getElementById("ctCropVidMeta"),H=document.getElementById("ctCropVidName"),X=document.getElementById("ctCropVidBtn"),Y=document.getElementById("ctCropVidDownload"),R=wt();gt(Y,R);const z=document.getElementById("ctCropVidClr"),dt=document.getElementById("ctCropVidWasmStatus"),M=document.getElementById("ctCropVidW"),E=document.getElementById("ctCropVidH"),C=document.getElementById("ctCropVidX"),B=document.getElementById("ctCropVidY"),A=document.getElementById("ctCropVidResetZero");if(!l||!i||!b||!V||!x||!H||!X||!z||!M||!E||!C||!B||!A)return;let s={nx:.1,ny:.1,nw:.8,nh:.8},P=!1;const G=new WeakMap;function _(t,e,n){if(n!==null)return n/100;if(t.value.trim()===""&&document.activeElement===t){const r=G.get(t);if(r)return r[e]}return s[e]}function et(t=!1){P=!0;const e=s,n=String(Math.round(e.nw*1e3)/10),r=String(Math.round(e.nh*1e3)/10),o=String(Math.round(e.nx*1e3)/10),h=String(Math.round(e.ny*1e3)/10),c=(d,p)=>{!t&&document.activeElement===d&&d.value.trim()===""||(d.value=p)};c(M,n),c(E,r),c(C,o),c(B,h),P=!1}function D(){const t=q(M),e=q(E),n=q(C),r=q(B);s=st({nx:_(C,"nx",n),ny:_(B,"ny",r),nw:_(M,"nw",t),nh:_(E,"nh",e)}),et(!1)}function lt(){[M,E,C,B].forEach(t=>{if(t.value.trim()!=="")return;P=!0;const e=s;t===M?t.value=String(Math.round(e.nw*1e3)/10):t===E?t.value=String(Math.round(e.nh*1e3)/10):t===C?t.value=String(Math.round(e.nx*1e3)/10):t===B&&(t.value=String(Math.round(e.ny*1e3)/10)),P=!1}),D()}const m=Ct({statusEl:dt,progressIds:{barId:"ctCropVidProgBar",labelId:"ctCropVidProgLabel",percentId:"ctCropVidProgPct"},routeFormat:a,probeReadyLabel:"Ready to crop"}),{setProg:ut}=m,k=document.getElementById("ctCropVidReadyLabel"),U=()=>{X.disabled=!m.currentFile||m.encodeInFlight},mt=()=>{V.classList.remove("d-none"),V.setAttribute("aria-hidden","false"),A.disabled=!1,k&&(k.textContent="Ready to crop")},pt=()=>{V.classList.add("d-none"),V.setAttribute("aria-hidden","true"),A.disabled=!0};let f=null;function nt(t,e,n,r,o){s=st({nx:(t-o.ox)/o.cw,ny:(e-o.oy)/o.ch,nw:n/o.cw,nh:r/o.ch}),et(!0)}function W(){const t=tt(i);if(!t)return;const{ox:e,oy:n,cw:r,ch:o}=t,h=e+s.nx*r,c=n+s.ny*o,d=Math.max(s.nw*r,2),p=Math.max(s.nh*o,2);x.style.left=`${h}px`,x.style.top=`${c}px`,x.style.width=`${d}px`,x.style.height=`${p}px`}function $(){i.src&&W()}typeof ResizeObserver<"u"&&b&&new ResizeObserver(()=>$()).observe(b);function ot(t){if(!f||!i)return;const e=b.getBoundingClientRect(),n=t.clientX-e.left,r=t.clientY-e.top,o=tt(i);if(!o)return;const{ox:h,oy:c,cw:d,ch:p}=o,v=16;
1if(f.mode==="move"){let J=f.rect.x+(n-f.startX),K=f.rect.y+(r-f.startY);J=Math.min(Math.max(J,h),h+d-f.rect.w),K=Math.min(Math.max(K,c),c+p-f.rect.h),nt(J,K,f.rect.w,f.rect.h,o),W();return}const S=f.anchor.x,I=f.anchor.y;let w=Math.min(S,n),T=Math.min(I,r),N=Math.max(S,n),O=Math.max(I,r);w=Math.min(Math.max(w,h),h+d-v),T=Math.min(Math.max(T,c),c+p-v),N=Math.min(Math.max(N,w+v),h+d),O=Math.min(Math.max(O,T+v),c+p);const ft=N-w,ht=O-T;nt(w,T,ft,ht,o),W()}[M,E,C,B].forEach(t=>{t.addEventListener("focus",()=>{G.set(t,{...s})}),t.addEventListener("input",()=>{P||(D(),W())}),t.addEventListener("blur",()=>{if(!P){if(t.value.trim()===""){P=!0;const e=s;t===M?t.value=String(Math.round(e.nw*1e3)/10):t===E?t.value=String(Math.round(e.nh*1e3)/10):t===C?t.value=String(Math.round(e.nx*1e3)/10):t===B&&(t.value=String(Math.round(e.ny*1e3)/10)),P=!1}G.delete(t),D(),W()}})}),A.addEventListener("click",()=>{if(m.currentFile){if(!i.videoWidth||!i.videoHeight){L("Wait for the video to load, then try again.");return}M.value="100",E.value="100",C.value="0",B.value="
10",D(),$()}});function Z(){f=null,window.removeEventListener("pointermove",ot),window.removeEventListener("pointerup",Z),window.removeEventListener("pointercancel",Z)}function rt(t,e){if(!i.videoWidth)return;t.preventDefault(),t.stopPropagation();const n=tt(i);if(!n)return;const r=b.getBoundingClientRect(),o=t.clientX-r.left,h=t.clientY-r.top,c=n.ox+s.nx*n.cw,d=n.oy+s.ny*n.ch,p=s.nw*n.cw,v=s.nh*n.ch;if(e==="move")f={mode:"move",startX:o,startY:h,rect:{x:c,y:d,w:p,h:v}};else{const S={nw:{x:c+p,y:d+v},ne:{x:c,y:d+v},sw:{x:c+p,y:d},se:{x:c,y:d}};f={mode:e,startX:o,startY:h,rect:{x:c,y:d,w:p,h:v},anchor:S[e]}}if(typeof x.setPointerCapture=="function")try{x.setPointerCapture(t.pointerId)}catch{}window.addEventListener("pointermove",ot),window.addEventListener("pointerup",Z),window.addEventListener("pointercancel",Z)}x.addEventListener("pointerdown",t=>{const e=t.target;if(e instanceof HTMLElement&&e.dataset.ctHandle){const n=e.dataset.ctHandle;if(n==="nw"||n==="ne"||n==="sw"||n==="se"){rt(t,n);return}}rt(t,"move")}),i.addEventListener("loadedmetadata",()=>{D();const t=m.currentFile;t&&Q(F,m.metadata,t,i),$()}),i.addEventListener("durationchange",()=>{const t=m.currentFile;t&&Q(F,m.metadata,t,i)});function it(){M.value="80",E.value="80",C.value="10",B.value="10",s={nx:.1,ny:.1,nw:.8,nh:.8},pt(),k&&(k.textContent="Ready to crop")}Bt({fileEl:l,dropEl:y,dropCaptionEl:g,runtime:m,clearBtn:z,nameInput:H,preview:i,metaEl:F,onEmpty:()=>{it(),ct(l,y,g),U()},onTooLarge:()=>{L("File size exceeds the 500MB limit."),at(l,{drop:y,captionEl:g})},onProbeFailed:()=>{L("Failed to read video metadata.")},onReady:({file:t})=>{mt(),Q(F,m.metadata,t,i),D(),$(),U()}}),window.addEventListener("resize",$),z.addEventListener("click",()=>{R.clear(),R.syncDownloadButton(Y),at(l,{notify:!1,drop:y,captionEl:g??void 0}),z.disabled=!0,H&&(H.value="cropped_video"),it(),m.clearPickState({preview:i,metaEl:F}),ct(l,y,g),U()}),X.addEventListener("click",async()=>{var S;const t=m.currentFile;if(!t){L("Please choose a video.");return}if(t.size>It){L("File size exceeds the 500MB limit.");return}const e=i.videoWidth,n=i.videoHeight;if(!e||!n){L("Wait for the video metadata to load, then try again.");return}lt();let r=j(s.nw*e),o=j(s.nh*n),h=Math.min(Math.round(s.nx*e),e-r),c=Math.min(Math.round(s.ny*n),n-o);if(r=Math.min(r,e-h),o=Math.min(o,n-c),r=j(r),o=j(o),r<2||o<2){L("Crop region is too small.");return}const d=m.inputNameFor(t),p=`output.${a}`,v=xt(a,m.metadata);R.clear(),R.syncDownloadButton(Y),X.disabled=!0;try{const I=await m.runEncode({inName:d,args:["-y","-loglevel","warning","-stats","-i",d,"-vf",`crop=${r}:${o}:${h}:${c}`,...v,p],encodingLabel:"Croppingâ¦"}),w=await I.readFile(p),T=w.buffer?w.buffer.slice(w.byteOffset,w.byteOffset+w.byteLength):w,N=new Blob([T],{type:`video/${a}`}),O=(H.value||"cropped_video").replace(/[^\w\-]+/g,"_");await yt(R,Y,{blob:N,filename:`${O}.${a}`,progressUi:(S=m.setProg)==null?void 0:S.ui});try{await I.deleteFile(d),await I.deleteFile(p)}catch{}}catch(I){vt(I)||(L(I instanceof Error?I.message:"Crop failed."),ut.ui.hardReset("Ready to crop"))}finally{U()}})}export{kt as initCropVideoOnlinePage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.