import{isFunction as H,useLocale as L,isString as M,isArray as D}from"@vuepress/helper/client";import{watchImmediate as C,useFullscreen as O,useEventListener as k}from"@vueuse/core";import{inject as R,ref as V,isRef as z,computed as w,onMounted as F,onUnmounted as B}from"vue";import{useFrontmatter as j}from"vuepress/client";import"photoswipe/dist/photoswipe.css";import"./styles/photo-swipe.css";const p=V({}),b=Symbol(__VUEPRESS_DEV__?"photoswipe":""),q=e=>{z(e)?C(()=>e.value,o=>{p.value=o}):H(e)?C(w(e),o=>{p.value=o}):p.value=e},x=()=>R(b),U=e=>{e.provide(b,p)},f=e=>new Promise((o,s)=>{e.complete?o({type:"image",element:e,src:e.src,width:e.naturalWidth,height:e.naturalHeight,alt:e.alt,msrc:e.src}):(e.onload=()=>{o(f(e))},e.onerror=()=>{s()})}),G=e=>new Promise((o,s)=>{const t=new Image;t.src=e,t.onload=()=>{o(f(t))},t.onerror=()=>{s()}}),T='
',E=(e,{download:o=!0,fullscreen:s=!0}={})=>{e.on("uiRegister",()=>{if(e.ui.registerElement({name:"bulletsIndicator",className:"photo-swipe-bullets-indicator",appendTo:"wrapper",onInit:t=>{const r=[];let u=-1;for(let d=0;d{e.goTo(r.indexOf(c.target))},r.push(i),t.appendChild(i)}e.on("change",()=>{u>=0&&r[u].classList.remove("active"),r[e.currIndex].classList.add("active"),u=e.currIndex})}}),s){const{isSupported:t,toggle:r}=O();t.value&&e.ui.registerElement({name:"fullscreen",order:7,isButton:!0,html:'',onClick:()=>{r()}})}o&&e.ui.registerElement({name:"download",order:8,isButton:!0,tagName:"a",html:{isCustomSVG:!0,inner:'',outlineID:"pswp__icn-download"},onInit:t=>{t.setAttribute("download",""),t.setAttribute("target","_blank"),t.setAttribute("rel","noopener"),e.on("change",()=>{t.setAttribute("href",e.currSlide.data.src)})}})})},Z=({selector:e,locales:o,download:s=!0,fullscreen:t=!0,scrollToClose:r=!0})=>{const u=x(),d=L(o),i=j(),c=w(()=>{const{photoSwipe:a}=i.value;return a===!1?null:M(a)?a:D(e)?e.join(", "):e}),g=w(()=>({...u.value,...d.value,download:s,fullscreen:t,scrollToClose:r}));let h=null,m=0,n=null;k("click",async a=>{const I=a.target;if(!c.value||!h||!I.matches(c.value))return;m!==0&&n.destroy();const S=Date.now(),A=await h,v=Array.from(document.querySelectorAll(c.value)),y=v.map(l=>({html:T,element:l,msrc:l.src})),N=v.findIndex(l=>l===I);n=new A({preloaderDelay:0,showHideAnimationType:"zoom",...g.value,dataSource:y,index:N,...r?{closeOnVerticalDrag:!0,wheelToZoom:!1}:{}}),m=S,E(n,{download:s,fullscreen:t}),n.init(),n.on("destroy",()=>{n=null,m=0}),v.map((l,_)=>f(l).then(P=>{m===S&&(y.splice(_,1,P),n?.refreshSlideContent(_))}))},{passive:!0}),k("wheel",()=>{g.value.scrollToClose&&n?.close()}),F(()=>{__VUEPRESS_SSR__||("requestIdleCallback"in window?window.requestIdleCallback:setTimeout)(()=>{h=import("photoswipe").then(({default:a})=>a)})}),B(()=>{n?.destroy()})};export{T as L,x as a,q as d,U as i,G as r,E as s,Z as u};
//# sourceMappingURL=usePhotoSwipe-w7wkUXvx.js.map