import { f as fallback } from './async-Djx13DAD.js';
import { c as bind_props, d as attr_class, a as attr, g as attr_style, j as stringify, e as ensure_array_like } from './index-B7gr0Dsc.js';
import { o as onDestroy } from './index-server-lqjMX237.js';
import './MarkdownCode.svelte_svelte_type_style_lang-DJRtJayx.js';
import { k } from './BlockLabel-DYKzuObf.js';
import { u as u$1 } from './DownloadLink-BLkRTIUs.js';
import { w } from './IconButton-7VBZdgpA.js';
import { p as p$1 } from './Empty-uaeWNu3s.js';
import { y as y$2 } from './ShareButton-B1Vd_e6T.js';
import { l } from './Download-rAXPPveZ.js';
import { r as r$1 } from './Video-Cl-Q8BCK.js';
import { y as y$1 } from './IconButtonWrapper-DlgTGGi-.js';
import { S as Ss } from './2-CeYbpaU1.js';
import { y, w as w$1 } from './utils.svelte-D8Xdzglu.js';
import { i } from './Maximize-DxOGYNPn.js';
import { p, c, u } from './VolumeLevels-ChNcuVO2.js';
import { n } from './Play-BVmRHWoH.js';
import { r } from './Undo-DlTKhhuO.js';
import { Q as Qu } from './Video2-pxW-QOKm.js';
import { z } from './ModifyUpload-Dqp1u9XX.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import './context-BZS6UlnY.js';
import './uneval-DjLoL4oF.js';
import './clone-BLo8hHdj.js';
import './prism-python-BaDPvmdn.js';
import './index5-BoOEKc6P.js';
import './dev-fallback-Bc5Ork7Y.js';
import './Clear-CiR-WD8W.js';
import './Edit-DVsun1ou.js';

const Kt=d=>{let t=["B","KB","MB","GB","PB"],a=0;for(;d>1024;)d/=1024,a++;let e=t[a];return d.toFixed(1)+" "+e},Yt=()=>true;function Jt(d,{autoplay:t}){async function a(){t&&await d.play();}return d.addEventListener("loadeddata",a),{destroy(){d.removeEventListener("loadeddata",a);}}}function kt(d,t){d.component(a=>{let e=t.videoElement,o=t.trimmedDuration,y=t.dragStart,f=t.dragEnd,v=t.loadingTimeline,E=[],k=10,p,g=0,_=100,R=null;const T=()=>{R=null;},w=(n,m)=>{if(R){const b=document.getElementById("timeline");if(!b)return;const s=b.getBoundingClientRect();let c=(n.clientX-s.left)/s.width*100;if(m?c=R==="left"?g+m:_+m:c=(n.clientX-s.left)/s.width*100,c=Math.max(0,Math.min(c,100)),R==="left"){g=Math.min(c,_);const I=g/100*p;e.currentTime=I,y=I;}else if(R==="right"){_=Math.max(c,g);const I=_/100*p;e.currentTime=I,f=I;}const u=g/100*p;o=_/100*p-u,g=g,_=_;}},D=n=>{if(R){const m=1/p*100;n.key==="ArrowLeft"?w({clientX:0},-m):n.key==="ArrowRight"&&w({clientX:0},m);}};if(onDestroy(()=>{window.removeEventListener("mousemove",w),window.removeEventListener("mouseup",T),window.removeEventListener("keydown",D);}),v=E.length!==k,a.push('<div class="container svelte-mctcyk">'),v)a.push("<!--[-->"),a.push('<div class="load-wrap svelte-mctcyk"><span aria-label="loading timeline" class="loader svelte-mctcyk"></span></div>');else {a.push("<!--[!-->"),a.push(`<div id="timeline" class="thumbnail-wrapper svelte-mctcyk"><button aria-label="start drag handle for trimming video" class="handle left svelte-mctcyk"${attr_style(`left: ${stringify(g)}%;`)}></button> <div class="opaque-layer svelte-mctcyk"${attr_style(`left: ${stringify(g)}%; right: ${stringify(100-_)}%`)}></div> <!--[-->`);const n=ensure_array_like(E);for(let m=0,b=n.length;m<b;m++){let s$1=n[m];a.push(`<img${attr("src",s$1)}${attr("alt",`frame-${m}`)} draggable="false" class="svelte-mctcyk"/>`);}a.push(`<!--]--> <button aria-label="end drag handle for trimming video" class="handle right svelte-mctcyk"${attr_style(`left: ${stringify(_)}%;`)}></button></div>`);}a.push("<!--]--></div>"),bind_props(t,{videoElement:e,trimmedDuration:o,dragStart:y,dragEnd:f,loadingTimeline:v});});}function Rt(d,t){d.component(a=>{let e=t.videoElement,o=fallback(t.showRedo,false),y$1=fallback(t.interactive,true),f=fallback(t.mode,""),v=t.handle_reset_value,E=t.handle_trim_video,k=fallback(t.processingVideo,false),p=t.i18n,g=fallback(t.value,null),_=fallback(t.show_download_button,false),R=fallback(t.handle_clear,()=>{}),T=fallback(t.has_change_history,false);let w$1=null,D=0,x=0,n=false;const m=()=>{f==="edit"?(f="",w$1=e.duration):f="edit";};f==="edit"&&w$1===null&&e&&(w$1=e.duration);let b=true,s$1;function c$1(u){u.push(`<div${attr_class("container svelte-1orxdv",void 0,{hidden:f!=="edit"})}>`),f==="edit"?(u.push("<!--[-->"),u.push('<div class="timeline-wrapper svelte-1orxdv">'),kt(u,{videoElement:e,get dragStart(){return D},set dragStart(i){D=i,b=false;},get dragEnd(){return x},set dragEnd(i){x=i,b=false;},get trimmedDuration(){return w$1},set trimmedDuration(i){w$1=i,b=false;},get loadingTimeline(){return n},set loadingTimeline(i){n=i,b=false;}}),u.push("<!----></div>")):u.push("<!--[!-->"),u.push('<!--]--> <div class="controls svelte-1orxdv" data-testid="waveform-controls">'),f==="edit"&&w$1!==null?(u.push("<!--[-->"),u.push(`<time aria-label="duration of selected region in seconds"${attr_class("svelte-1orxdv",void 0,{hidden:n})}>${escape_html(y(w$1))}</time> <div class="edit-buttons svelte-1orxdv"><button${attr_class("text-button svelte-1orxdv",void 0,{hidden:n})}>Trim</button> <button${attr_class("text-button svelte-1orxdv",void 0,{hidden:n})}>Cancel</button></div>`)):(u.push("<!--[!-->"),u.push('<div class="svelte-1orxdv"></div>')),u.push("<!--]--></div></div> "),z(u,{i18n:p,onclear:()=>R(),download:_?g?.url:null,children:i=>{o&&f===""?(i.push("<!--[-->"),w(i,{Icon:r,label:"Reset video to initial value",disabled:k||!T,onclick:()=>{v(),f="";}})):i.push("<!--[!-->"),i.push("<!--]--> "),y$1&&f===""?(i.push("<!--[-->"),w(i,{Icon:c,label:"Trim video to selection",disabled:k,onclick:m})):i.push("<!--[!-->"),i.push("<!--]-->");}}),u.push("<!---->");}do b=true,s$1=a.copy(),c$1(s$1);while(!b);a.subsume(s$1),bind_props(t,{videoElement:e,showRedo:o,interactive:y$1,mode:f,handle_reset_value:v,handle_trim_video:E,processingVideo:k,i18n:p,value:g,show_download_button:_,handle_clear:R,has_change_history:T});});}function Lt(d,t){d.component(a=>{let e=fallback(t.root,""),o=t.src,y$1=fallback(t.subtitle,null),f=t.mirror,v=t.autoplay,E=t.loop,k=fallback(t.label,"test"),p$1=fallback(t.interactive,false),g=fallback(t.handle_change,()=>{}),_=fallback(t.handle_reset_value,()=>{}),R=t.upload,T=t.is_stream,w=t.i18n,D=fallback(t.show_download_button,false),x=fallback(t.value,null),n$1=fallback(t.handle_clear,()=>{}),m=fallback(t.has_change_history,false),b=fallback(t.playback_position,0);let s$1=0,c,u$1=true,i$1,I=false,M=1,F=false;const q=async r=>{let L=new File([r],"video.mp4");const Y=await Ss([L]);let J=(await R(Y,e))?.filter(Boolean)[0];g(J);};let P=1,B;const j=.001;function V(){i$1&&Math.abs(i$1.volume-P)>j&&(M=i$1.volume,P=i$1.volume);}onDestroy(()=>{i$1&&i$1.removeEventListener("volumechange",V);}),i$1&&i$1!==B&&(B&&B.removeEventListener("volumechange",V),i$1.addEventListener("volumechange",V),B=i$1),s$1=s$1||0,c=c||0,b=s$1,b!==s$1&&i$1&&(i$1.currentTime=b),i$1&&!F&&(Math.abs(i$1.volume-M)>j&&(i$1.volume=M,P=M),i$1.controls=false),i$1&&F&&(P=i$1.volume);let O=true,A;function K(r$1){r$1.push(`<div class="wrap svelte-1k28h7x"><div${attr_class("mirror-wrap svelte-1k28h7x",void 0,{mirror:f})}>`),Qu(r$1,{src:o,preload:"auto",autoplay:v,loop:E,is_stream:T,controls:F,"data-testid":`${k}-player`,processingVideo:I,get currentTime(){return s$1},set currentTime(L){s$1=L,O=false;},get duration(){return c},set duration(L){c=L,O=false;},get paused(){return u$1},set paused(L){u$1=L,O=false;},get node(){return i$1},set node(L){i$1=L,O=false;},children:L=>{L.push(`<track kind="captions"${attr("src",y$1)} default/>`);},$$slots:{default:true}}),r$1.push('<!----></div> <div class="controls svelte-1k28h7x"><div class="inner svelte-1k28h7x"><span role="button" tabindex="0" class="icon svelte-1k28h7x" aria-label="play-pause-replay-button">'),s$1===c?(r$1.push("<!--[-->"),r(r$1)):(r$1.push("<!--[!-->"),u$1?(r$1.push("<!--[-->"),n(r$1)):(r$1.push("<!--[!-->"),u(r$1)),r$1.push("<!--]-->")),r$1.push(`<!--]--></span> <span class="time svelte-1k28h7x">${escape_html(y(s$1))} / ${escape_html(y(c))}</span>  <progress${attr("value",s$1/c||0)} class="svelte-1k28h7x"></progress> <div class="volume-control-wrapper svelte-1k28h7x"><button class="icon volume-button svelte-1k28h7x" aria-label="Adjust volume"${attr_style("",{color:"white"})}>`),p(r$1,{currentVolume:M}),r$1.push("<!----></button> "),r$1.push("<!--[!-->"),r$1.push("<!--]--></div> "),r$1.push("<!--[-->"),r$1.push('<div role="button" tabindex="0" class="icon svelte-1k28h7x" aria-label="full-screen">'),i(r$1),r$1.push("<!----></div>"),r$1.push("<!--]--></div></div></div> "),p$1?(r$1.push("<!--[-->"),Rt(r$1,{videoElement:i$1,showRedo:true,handle_trim_video:q,handle_reset_value:_,value:x,i18n:w,show_download_button:D,handle_clear:n$1,has_change_history:m,get processingVideo(){return I},set processingVideo(L){I=L,O=false;}})):r$1.push("<!--[!-->"),r$1.push("<!--]-->");}do O=true,A=a.copy(),K(A);while(!O);a.subsume(A),bind_props(t,{root:e,src:o,subtitle:y$1,mirror:f,autoplay:v,loop:E,label:k,interactive:p$1,handle_change:g,handle_reset_value:_,upload:R,is_stream:T,i18n:w,show_download_button:D,value:x,handle_clear:n$1,has_change_history:m,playback_position:b});});}function Tt(d,t){d.component(a=>{let e=fallback(t.value,null),o=fallback(t.subtitle,null),y=fallback(t.label,void 0),f=fallback(t.show_label,true),v=t.autoplay,E=fallback(t.buttons,null),k$1=fallback(t.on_custom_button_click,null),p=t.loop,g=t.i18n,_=t.upload,R=fallback(t.display_icon_button_wrapper_top_corner,false),T=fallback(t.playback_position,0);let n=true,m;function b(s){k(s,{show_label:f,Icon:r$1,label:y||"Video"}),s.push("<!----> "),!e||e.url===void 0?(s.push("<!--[-->"),p$1(s,{unpadded_box:true,size:"large",children:c=>{r$1(c);},$$slots:{default:true}})):(s.push("<!--[!-->"),s.push("<!---->"),Lt(s,{src:e.url,subtitle:o?.url,is_stream:e.is_stream,autoplay:v,mirror:false,label:y,loop:p,interactive:false,upload:_,i18n:g,get playback_position(){return T},set playback_position(c){T=c,n=false;}}),s.push('<!----> <div data-testid="download-div">'),y$1(s,{display_top_corner:R,buttons:E??["download","share"],on_custom_button_click:k$1,children:c=>{E?.some(u=>typeof u=="string"&&u==="download")?(c.push("<!--[-->"),u$1(c,{href:e.is_stream?e.url?.replace("playlist.m3u8","playlist-file"):e.url,download:e.orig_name||e.path,children:u=>{w(u,{Icon:l,label:"Download"});},$$slots:{default:true}})):c.push("<!--[!-->"),c.push("<!--]--> "),E?.some(u=>typeof u=="string"&&u==="share")?(c.push("<!--[-->"),y$2(c,{i18n:g,value:e,formatter:async u=>u?await w$1(u.data):""})):c.push("<!--[!-->"),c.push("<!--]-->");}}),s.push("<!----></div>")),s.push("<!--]-->");}do n=true,m=a.copy(),b(m);while(!n);a.subsume(m),bind_props(t,{value:e,subtitle:o,label:y,show_label:f,autoplay:v,buttons:E,on_custom_button_click:k$1,loop:p,i18n:g,upload:_,display_icon_button_wrapper_top_corner:R,playback_position:T});});}const Qt=Object.freeze(Object.defineProperty({__proto__:null,default:Tt},Symbol.toStringTag,{value:"Module"}));

export { Lt as P, Tt as V, Yt as a, Qt as b, Jt as l, Kt as p };
//# sourceMappingURL=VideoPreview-BPh6UXUU.js.map
