import './async-D55cHugf.js';
import { d as bind_props, f as attr_class, a as attr, g as attr_style, i as stringify, e as ensure_array_like } from './index-u8mz_F03.js';
import { o as onDestroy } from './index-server-CQz6EZl_.js';
import { k } from './BlockLabel-bKYWnOzQ.js';
import { u as u$1 } from './DownloadLink-nj1p0krE.js';
import { w as w$1 } from './IconButton-BRnu7KaR.js';
import { p as p$1 } from './Empty-DGRbZO0a.js';
import { y as y$1 } from './ShareButton-7VTs9dOO.js';
import { l } from './Download-DcU5dONL.js';
import { r as r$1 } from './Video-FfbWmOVG.js';
import { y } from './IconButtonWrapper-CjFRPb3y.js';
import { b as bs } from './2-BLdXJizP.js';
import { w, b } from './utils.svelte-B2py64Fz.js';
import { i } from './Maximize-CuHbK64j.js';
import { p, c, u } from './VolumeLevels-DlU2d99x.js';
import { n } from './Play-B_z3rKL1.js';
import { r } from './Undo-Ce01x-M5.js';
import { c as ch } from './Video2-BN5I0jvO.js';
import { v } from './ModifyUpload-CWSi2EyW.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import './context-CBkBucIx.js';
import './index5-BoOEKc6P.js';
import './dev-fallback-Bc5Ork7Y.js';
import './index-Cg-Pg6j3.js';
import './clone-Yk88IHKV.js';
import './Clear-D7Yjckqz.js';
import './Edit-DWZSi_T0.js';

const $e=a=>{let t=["B","KB","MB","GB","PB"],e=0;for(;a>1024;)a/=1024,e++;let s=t[e];return a.toFixed(1)+" "+s},et=()=>true;function tt(a,{autoplay:t}){async function e(){t&&await a.play();}return a.addEventListener("loadeddata",e),{destroy(){a.removeEventListener("loadeddata",e);}}}function Ie(a,t){a.component(e=>{let{videoElement:s,trimmedDuration:o=null,dragStart:w=0,dragEnd:p=0,loadingTimeline:_=false}=t,k=[],L=10,m,f=0,v=100,D=null,M=k.length!==L;const x=()=>{D=null;},I=(r,d)=>{if(D){const y=document.getElementById("timeline");if(!y)return;const b=y.getBoundingClientRect();let n=(r.clientX-b.left)/b.width*100;if(d?n=D==="left"?f+d:v+d:n=(r.clientX-b.left)/b.width*100,n=Math.max(0,Math.min(n,100)),D==="left"){f=Math.min(n,v);const g=f/100*m;s.currentTime=g,w=g;}else if(D==="right"){v=Math.max(n,f);const g=v/100*m;s.currentTime=g,p=g;}const c=f/100*m;o=v/100*m-c,f=f,v=v;}},F=r=>{if(D){const d=1/m*100;r.key==="ArrowLeft"?I({clientX:0},-d):r.key==="ArrowRight"&&I({clientX:0},d);}};if(onDestroy(()=>{window.removeEventListener("mousemove",I),window.removeEventListener("mouseup",x),window.removeEventListener("keydown",F);}),e.push('<div class="container svelte-mctcyk">'),M)e.push("<!--[-->"),e.push('<div class="load-wrap svelte-mctcyk"><span aria-label="loading timeline" class="loader svelte-mctcyk"></span></div>');else {e.push("<!--[!-->"),e.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(f)}%;`)}></button> <div class="opaque-layer svelte-mctcyk"${attr_style(`left: ${stringify(f)}%; right: ${stringify(100-v)}%`)}></div> <!--[-->`);const r=ensure_array_like(k);for(let d=0,y=r.length;d<y;d++){let b=r[d];e.push(`<img${attr("src",b)}${attr("alt",`frame-${d}`)} draggable="false" class="svelte-mctcyk"/>`);}e.push(`<!--]--> <button aria-label="end drag handle for trimming video" class="handle right svelte-mctcyk"${attr_style(`left: ${stringify(v)}%;`)}></button></div>`);}e.push("<!--]--></div>"),bind_props(t,{trimmedDuration:o,dragStart:w,dragEnd:p,loadingTimeline:_});});}function Oe(a,t){a.component(e=>{let{videoElement:s=void 0,showRedo:o=false,interactive:w$2=true,mode:p="",handle_reset_value:_,handle_trim_video:k,processingVideo:L=false,i18n:m,value:f=null,show_download_button:v$1=false,handle_clear:D=()=>{},has_change_history:M=false}=t;let x=null,I=0,F=0,O=false;const r$1=()=>{p==="edit"?(p="",s&&(x=s.duration)):p="edit";};let d=true,y;function b(n){n.push(`<div${attr_class("container svelte-1orxdv",void 0,{hidden:p!=="edit"})}>`),p==="edit"&&s?(n.push("<!--[-->"),n.push('<div class="timeline-wrapper svelte-1orxdv">'),Ie(n,{videoElement:s,get dragStart(){return I},set dragStart(c){I=c,d=false;},get dragEnd(){return F},set dragEnd(c){F=c,d=false;},get trimmedDuration(){return x},set trimmedDuration(c){x=c,d=false;},get loadingTimeline(){return O},set loadingTimeline(c){O=c,d=false;}}),n.push("<!----></div>")):n.push("<!--[!-->"),n.push('<!--]--> <div class="controls svelte-1orxdv" data-testid="waveform-controls">'),p==="edit"&&x!==null?(n.push("<!--[-->"),n.push(`<time aria-label="duration of selected region in seconds"${attr_class("svelte-1orxdv",void 0,{hidden:O})}>${escape_html(w(x))}</time> <div class="edit-buttons svelte-1orxdv"><button${attr_class("text-button svelte-1orxdv",void 0,{hidden:O})}>Trim</button> <button${attr_class("text-button svelte-1orxdv",void 0,{hidden:O})}>Cancel</button></div>`)):(n.push("<!--[!-->"),n.push('<div class="svelte-1orxdv"></div>')),n.push("<!--]--></div></div> "),v(n,{i18n:m,onclear:()=>D(),download:v$1?f?.url:null,children:c$1=>{o&&p===""?(c$1.push("<!--[-->"),w$1(c$1,{Icon:r,label:"Reset video to initial value",disabled:L||!M,onclick:()=>{_(),p="";}})):c$1.push("<!--[!-->"),c$1.push("<!--]--> "),w$2&&p===""?(c$1.push("<!--[-->"),w$1(c$1,{Icon:c,label:"Trim video to selection",disabled:L,onclick:r$1})):c$1.push("<!--[!-->"),c$1.push("<!--]-->");}}),n.push("<!---->");}do d=true,y=e.copy(),b(y);while(!d);e.subsume(y),bind_props(t,{mode:p,processingVideo:L});});}function Me(a,t){a.component(e=>{let{root:s="",src:o,subtitle:w$1=null,mirror:p$1,autoplay:_,loop:k,label:L="test",interactive:m=false,handle_change:f=()=>{},handle_reset_value:v=()=>{},upload:D,is_stream:M=void 0,i18n:x,show_download_button:I=false,value:F=null,handle_clear:O=()=>{},has_change_history:r$1=false,playback_position:d=void 0,onplay:y,onpause:b,onstop:n$1,onend:c,onerror:U,onloadstart:g,onloadeddata:T,onloadedmetadata:E}=t,A=0,B=0,S=true,h,C=false,X=1,N=false;async function Q(){h&&document.fullscreenElement!=h&&(h.currentTime>0&&!h.paused&&!h.ended&&h.readyState>h.HAVE_CURRENT_DATA?h.pause():await h.play());}function Z(){n$1?.(),c?.();}const $=async i=>{let R=new File([i],"video.mp4");const ae=await bs([R]);let oe=(await D(ae,s))?.filter(Boolean)[0];f(oe);};let G=1;const ee=.001;function te(){h&&Math.abs(h.volume-G)>ee&&(X=h.volume,G=h.volume);}onDestroy(()=>{h&&h.removeEventListener("volumechange",te);});let P=true,j;function se(i$1){i$1.push(`<div class="wrap svelte-1k28h7x"><div${attr_class("mirror-wrap svelte-1k28h7x",void 0,{mirror:p$1})}>`),ch(i$1,{src:o,preload:"auto",autoplay:_,loop:k,is_stream:M,controls:N,onclick:Q,onplay:()=>y?.(),onpause:()=>b?.(),onerror:R=>U?.(R),onended:Z,"data-testid":`${L}-player`,processingVideo:C,onloadstart:()=>g?.(),onloadeddata:()=>T?.(),onloadedmetadata:()=>E?.(),get currentTime(){return A},set currentTime(R){A=R,P=false;},get duration(){return B},set duration(R){B=R,P=false;},get paused(){return S},set paused(R){S=R,P=false;},get node(){return h},set node(R){h=R,P=false;},children:R=>{R.push(`<track kind="captions"${attr("src",w$1)} default/>`);},$$slots:{default:true}}),i$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">'),A===B?(i$1.push("<!--[-->"),r(i$1)):(i$1.push("<!--[!-->"),S?(i$1.push("<!--[-->"),n(i$1)):(i$1.push("<!--[!-->"),u(i$1)),i$1.push("<!--]-->")),i$1.push(`<!--]--></span> <span class="time svelte-1k28h7x">${escape_html(w(A))} / ${escape_html(w(B))}</span>  <progress${attr("value",A/B||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(i$1,{currentVolume:X}),i$1.push("<!----></button> "),i$1.push("<!--[!-->"),i$1.push("<!--]--></div> "),i$1.push("<!--[-->"),i$1.push('<div role="button" tabindex="0" class="icon svelte-1k28h7x" aria-label="full-screen">'),i(i$1),i$1.push("<!----></div>"),i$1.push("<!--]--></div></div></div> "),m?(i$1.push("<!--[-->"),Oe(i$1,{videoElement:h,showRedo:true,handle_trim_video:$,handle_reset_value:v,value:F,i18n:x,show_download_button:I,handle_clear:O,has_change_history:r$1,get processingVideo(){return C},set processingVideo(R){C=R,P=false;}})):i$1.push("<!--[!-->"),i$1.push("<!--]-->");}do P=true,j=e.copy(),se(j);while(!P);e.subsume(j),bind_props(t,{playback_position:d});});}function Fe(a,t){a.component(e=>{let{value:s=null,subtitle:o=null,label:w=void 0,show_label:p=true,autoplay:_,buttons:k$1=null,on_custom_button_click:L=null,loop:m,i18n:f,upload:v,display_icon_button_wrapper_top_corner:D=false,playback_position:M=void 0,onplay:x,onpause:I,onend:F,onstop:O,onload:r,onchange:d,onerror:y$2,onshare:b$1}=t,n=true,c;function U(g){k(g,{show_label:p,Icon:r$1,label:w||"Video"}),g.push("<!----> "),!s||s.url===void 0?(g.push("<!--[-->"),p$1(g,{unpadded_box:true,size:"large",children:T=>{r$1(T);},$$slots:{default:true}})):(g.push("<!--[!-->"),g.push("<!---->"),Me(g,{src:s.url,subtitle:o?.url,is_stream:s.is_stream,autoplay:_,onplay:()=>x?.(),onpause:()=>I?.(),onstop:()=>O?.(),onend:()=>F?.(),onloadedmetadata:()=>{r?.();},mirror:false,label:w,loop:m,interactive:false,upload:v,i18n:f,get playback_position(){return M},set playback_position(T){M=T,n=false;}}),g.push('<!----> <div data-testid="download-div">'),y(g,{display_top_corner:D,buttons:k$1??["download","share"],on_custom_button_click:L,children:T=>{k$1?.some(E=>typeof E=="string"&&E==="download")?(T.push("<!--[-->"),u$1(T,{href:s.is_stream?s.url?.replace("playlist.m3u8","playlist-file"):s.url,download:s.orig_name||s.path,children:E=>{w$1(E,{Icon:l,label:"Download"});},$$slots:{default:true}})):T.push("<!--[!-->"),T.push("<!--]--> "),k$1?.some(E=>typeof E=="string"&&E==="share")?(T.push("<!--[-->"),y$1(T,{i18n:f,onerror:E=>y$2?.(E),onshare:E=>b$1?.(E),value:s,formatter:async E=>E?await b(E.data):""})):T.push("<!--[!-->"),T.push("<!--]-->");}}),g.push("<!----></div>")),g.push("<!--]-->");}do n=true,c=e.copy(),U(c);while(!n);e.subsume(c),bind_props(t,{value:s,playback_position:M});});}const st=Object.freeze(Object.defineProperty({__proto__:null,default:Fe},Symbol.toStringTag,{value:"Module"}));

export { Me as P, Fe as V, et as a, st as b, tt as l, $e as p };
//# sourceMappingURL=VideoPreview-BCm0_09s.js.map
