import './async-DWBXLqlH.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-D1re1cuM.js';
import { o as onDestroy } from './index-server-D4bj_1UO.js';
import './MarkdownCode.svelte_svelte_type_style_lang-CSnoIIp_.js';
import { k } from './BlockLabel-B2_AkSr2.js';
import { u as u$1 } from './DownloadLink-YXQWXYPr.js';
import { w } from './IconButton-C2_XRZp7.js';
import { p as p$1 } from './Empty-Cuu1wIXQ.js';
import { y as y$1 } from './ShareButton-CBu2I3ry.js';
import { l } from './Download-DQCZIsve.js';
import { r as r$1 } from './Video-BJvaeIU2.js';
import { y } from './IconButtonWrapper-BI5v6wo4.js';
import { p as ps } from './2-BbOIMXxe.js';
import { R, O } from './utils.svelte-BHoyPsmo.js';
import { i } from './Maximize-DWTTqpgt.js';
import { p, c, u } from './VolumeLevels-DVpBNR5e.js';
import { n } from './Play-Cq5X6dSn.js';
import { r } from './Undo-BWigpY9w.js';
import { c as ch } from './Video2-BN0RGMYm.js';
import { z } from './ModifyUpload-CHrOyHY7.js';
import { e as escape_html } from './escaping-CBnpiEl5.js';
import './context-BZS6UlnY.js';
import './uneval-ZBzcyJ66.js';
import './clone-CubQhOZi.js';
import './prism-python-B3XC7jWw.js';
import './index5-BoOEKc6P.js';
import './dev-fallback-Bc5Ork7Y.js';
import './Clear-CTfKb9Id.js';
import './Edit-DnE7yQ6U.js';

const te=a=>{let e=["B","KB","MB","GB","PB"],t=0;for(;a>1024;)a/=1024,t++;let s=e[t];return a.toFixed(1)+" "+s},ee=()=>true;function se(a,{autoplay:e}){async function t(){e&&await a.play();}return a.addEventListener("loadeddata",t),{destroy(){a.removeEventListener("loadeddata",t);}}}function It(a,e){a.component(t=>{let{videoElement:s$1,trimmedDuration:o=null,dragStart:w=0,dragEnd:p=0,loadingTimeline:_=false}=e,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$1.currentTime=g,w=g;}else if(D==="right"){v=Math.max(n,f);const g=v/100*m;s$1.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);}),t.push('<div class="container svelte-mctcyk">'),M)t.push("<!--[-->"),t.push('<div class="load-wrap svelte-mctcyk"><span aria-label="loading timeline" class="loader svelte-mctcyk"></span></div>');else {t.push("<!--[!-->"),t.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];t.push(`<img${attr("src",b)}${attr("alt",`frame-${d}`)} draggable="false" class="svelte-mctcyk"/>`);}t.push(`<!--]--> <button aria-label="end drag handle for trimming video" class="handle right svelte-mctcyk"${attr_style(`left: ${stringify(v)}%;`)}></button></div>`);}t.push("<!--]--></div>"),bind_props(e,{trimmedDuration:o,dragStart:w,dragEnd:p,loadingTimeline:_});});}function Ot(a,e){a.component(t=>{let{videoElement:s$1=void 0,showRedo:o=false,interactive:w$1=true,mode:p="",handle_reset_value:_,handle_trim_video:k,processingVideo:L=false,i18n:m,value:f=null,show_download_button:v=false,handle_clear:D=()=>{},has_change_history:M=false}=e;let x=null,I=0,F=0,O=false;const r$1=()=>{p==="edit"?(p="",s$1&&(x=s$1.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$1?(n.push("<!--[-->"),n.push('<div class="timeline-wrapper svelte-1orxdv">'),It(n,{videoElement:s$1,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(R(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> "),z(n,{i18n:m,onclear:()=>D(),download:v?f?.url:null,children:c$1=>{o&&p===""?(c$1.push("<!--[-->"),w(c$1,{Icon:r,label:"Reset video to initial value",disabled:L||!M,onclick:()=>{_(),p="";}})):c$1.push("<!--[!-->"),c$1.push("<!--]--> "),w$1&&p===""?(c$1.push("<!--[-->"),w(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=t.copy(),b(y);while(!d);t.subsume(y),bind_props(e,{mode:p,processingVideo:L});});}function Mt(a,e){a.component(t=>{let{root:s$1="",src:o,subtitle:w=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}=e,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 at=await ps([R]);let ot=(await D(at,s$1))?.filter(Boolean)[0];f(ot);};let G=1;const tt=.001;function et(){h&&Math.abs(h.volume-G)>tt&&(X=h.volume,G=h.volume);}onDestroy(()=>{h&&h.removeEventListener("volumechange",et);});let P=true,j;function st(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)} 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(R(A))} / ${escape_html(R(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("<!--[-->"),Ot(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=t.copy(),st(j);while(!P);t.subsume(j),bind_props(e,{playback_position:d});});}function Ft(a,e){a.component(t=>{let{value:s$1=null,subtitle:o=null,label:w$1=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$1,onload:r,onchange:d,onerror:y$2,onshare:b}=e,n=true,c;function U(g){k(g,{show_label:p,Icon:r$1,label:w$1||"Video"}),g.push("<!----> "),!s$1||s$1.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("<!---->"),Mt(g,{src:s$1.url,subtitle:o?.url,is_stream:s$1.is_stream,autoplay:_,onplay:()=>x?.(),onpause:()=>I?.(),onstop:()=>O$1?.(),onend:()=>F?.(),onloadedmetadata:()=>{r?.();},mirror:false,label:w$1,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$1.is_stream?s$1.url?.replace("playlist.m3u8","playlist-file"):s$1.url,download:s$1.orig_name||s$1.path,children:E=>{w(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?.(E),value:s$1,formatter:async E=>E?await O(E.data):""})):T.push("<!--[!-->"),T.push("<!--]-->");}}),g.push("<!----></div>")),g.push("<!--]-->");}do n=true,c=t.copy(),U(c);while(!n);t.subsume(c),bind_props(e,{value:s$1,playback_position:M});});}const ae=Object.freeze(Object.defineProperty({__proto__:null,default:Ft},Symbol.toStringTag,{value:"Module"}));

export { Mt as P, Ft as V, ee as a, ae as b, se as l, te as p };
//# sourceMappingURL=VideoPreview-GsGpXz96.js.map
