3 lines
4.0 KiB
JavaScript
3 lines
4.0 KiB
JavaScript
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='<div class="photo-swipe-loading"><svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" preserveAspectRatio="xMidYMid" viewBox="25 25 50 50"><animateTransform attributeName="transform" type="rotate" dur="2s" keyTimes="0;1" repeatCount="indefinite" values="0;360"></animateTransform><circle cx="50" cy="50" r="20" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round"><animate attributeName="stroke-dasharray" dur="1.5s" keyTimes="0;0.5;1" repeatCount="indefinite" values="1,200;90,200;1,200"></animate><animate attributeName="stroke-dashoffset" dur="1.5s" keyTimes="0;0.5;1" repeatCount="indefinite" values="0;-35px;-125px"></animate></circle></svg></div>',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.getNumItems();d++){const i=document.createElement("div");i.className="photo-swipe-bullet",i.onclick=c=>{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:'<svg class="pswp__icn" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><path d="M249.5 270.833H437v-75H212a37.5 37.5 0 0 0-37.5 37.5v225h75v-187.5zm-37.5 600h225v-75H249.5v-187.5h-75v225a37.5 37.5 0 0 0 37.5 37.5zm637.5-37.5v-225h-75v187.5H587v75h225a37.5 37.5 0 0 0 37.5-37.5zM587 270.833h187.5v187.5h75v-225a37.5 37.5 0 0 0-37.5-37.5H587v75z"/></svg>',onClick:()=>{r()}})}o&&e.ui.registerElement({name:"download",order:8,isButton:!0,tagName:"a",html:{isCustomSVG:!0,inner:'<path d="M20.5 14.3 17.1 18V10h-2.2v7.9l-3.4-3.6L10 16l6 6.1 6-6.1-1.5-1.6ZM23 23H9v2h14" id="pswp__icn-download"/>',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
|