mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-14 10:09:31 -07:00
1 line
7.4 KiB
JavaScript
1 line
7.4 KiB
JavaScript
import{c as e,o as t,a as n,t as s,i,b as a,u as o,d as r,e as l,f as c,g as d,F as g,h as u,s as h,l as m,j as v,k as p,m as y,n as w,S as f}from"./main.js";var x=s("<div class=cursor><div class=cursorInner>");function I(s){let o;const[r,l]=e({x:0,y:0}),c=e=>{const{clientX:t,clientY:n}=e;l({x:t,y:n})};return t(()=>{o=new AbortController;const e=o.signal;window.addEventListener("mousemove",c,{passive:!0,signal:e})}),n(()=>{null==o||o.abort()}),g=(d=x()).firstChild,i(g,()=>s.cursorText()),a(e=>{var t=!!s.active(),n=`translate3d(${r().x}px, ${r().y}px, 0)`;return t!==e.e&&d.classList.toggle("active",e.e=t),n!==e.t&&(null!=(e.t=n)?d.style.setProperty("transform",n):d.style.removeProperty("transform")),e},{e:void 0,t:void 0}),d;var d,g}const A=document.getElementsByClassName("threshold")[0],E=Array.from(A.getElementsByClassName("num")),O=A.getElementsByClassName("dec").item(0),T=A.getElementsByClassName("inc").item(0),H=document.getElementsByClassName("index").item(0),L=Array.from(H.getElementsByClassName("num"));function b(){const[e,{incThreshold:t,decThreshold:n}]=o();return r(()=>{var t,n,s;t=l(e().index+1),n=l(e().length),L.forEach((e,s)=>{e.innerText=s<4?t[s]:n[s-4]}),s=l(e().threshold),E.forEach((e,t)=>{e.innerText=s[t]})}),O.onclick=n,T.onclick=t,null}var C=s("<div class=stage>"),k=s("<img>");function N(e){return e.map(e=>e.i)}function $(e,t){return function(e,t){return N(e).slice(-t.trailLength)}(e,t).slice(0,-1)}function U(e){return N(e).slice(-1)[0]}function V(e,t){return y(e.slice(-1)[0].i,t.length)}function j(e,t){return p(e.slice(-1)[0].i,t.length)}function W(e,t){return t.map(t=>e[t])}function B(e){e.forEach(e=>{e.src!==e.dataset.hiUrl&&(e.src=e.dataset.hiUrl,e.height=parseInt(e.dataset.hiImgH),e.width=parseInt(e.dataset.hiImgW))})}function M(e){e.forEach(e=>{e.src!==e.dataset.loUrl&&(e.src=e.dataset.loUrl,e.height=parseInt(e.dataset.loImgH),e.width=parseInt(e.dataset.loImgW))})}function F(e){let n;const s=Array(e.ijs.length);let l,v={x:0,y:0},p=!1;const[y,{incIndex:w}]=o(),f=y().length;let x=!1;const I=t=>{if(e.isOpen()||e.isAnimating()||!p||!x)return;const n={x:t.clientX,y:t.clientY};if(Math.hypot(n.x-v.x,n.y-v.y)>y().threshold){v=n,w();const t={i:y().index,...n};e.setCordHist(e=>[...e,t].slice(-f))}},A=()=>{!e.isAnimating()&&e.setIsOpen(!0)};function E(t){if(x&&p)if(t.complete)n.set(t,{opacity:1}).then(()=>{e.setIsLoading(!1)}).catch(e=>{console.log(e)});else{e.setIsLoading(!0);const s=new AbortController,i=s.signal;t.addEventListener("load",()=>{n.to(t,{opacity:1,ease:"power3.out",duration:.5}).then(()=>{e.setIsLoading(!1)}).catch(e=>{console.log(e)}).finally(()=>{s.abort()})},{once:!0,passive:!0,signal:i}),t.addEventListener("error",()=>{n.set(t,{opacity:1}).then(()=>{e.setIsLoading(!1)}).catch(e=>{console.log(e)}).finally(()=>{s.abort()})},{once:!0,passive:!0,signal:i})}}return t(()=>{s.forEach((t,n)=>{n<5&&(t.src=t.dataset.loUrl),function(e,t,n={attributes:!0}){new MutationObserver((e,n)=>{for(const s of e)if(t(s)){n.disconnect();break}}).observe(e,n)}(t,i=>!e.isOpen()&&!e.isAnimating()&&"style"===i.attributeName&&1===parseFloat(t.style.opacity)&&(n+5<s.length&&(s[n+5].src=s[n+5].dataset.loUrl),!0))}),window.addEventListener("mousemove",()=>{m().then(e=>{n=e,p=!0}).catch(e=>{console.log(e)})},{passive:!0,once:!0}),l=new AbortController;const t=l.signal;window.addEventListener("mousemove",I,{passive:!0,signal:t}),x=!0}),r(c(()=>e.cordHist(),()=>{(()=>{if(!x)return;if(0===s.length)return;const t=e.cordHist(),i=N(t);if(0===i.length)return;const a=W(s,i),o=e.isOpen(),r=y();if(n.set(a,{x:e=>t[e].x-window.innerWidth/2,y:e=>t[e].y-window.innerHeight/2,opacity:e=>Math.max((e+1+r.trailLength<=t.length?0:1)-(o?1:0),0),zIndex:e=>e,scale:.6}),o){const i=W(s,[U(t)])[0],a=[],o=[];switch(e.navVector()){case"prev":a.push(V(t,r)),o.push(j(t,r));break;case"next":a.push(j(t,r)),o.push(V(t,r))}B(W(s,a)),n.set(W(s,o),{opacity:0}),n.set(i,{x:0,y:0,scale:1}),E(i)}else M(a)})()},{defer:!0})),r(c(()=>e.isOpen(),async()=>{e.isAnimating()||(e.isOpen()?await(async()=>{if(!x||!p)throw new Error("not mounted or gsap not loaded");e.setIsAnimating(!0);const t=e.cordHist(),i=y(),a=U(t),o=s[a];B(W(s,[a,V(t,i),j(t,i)])),E(o);const r=n.timeline(),l=W(s,$(t,i));return r.to(l,{y:"+=20",ease:"power3.in",stagger:.075,duration:.3,delay:.1,opacity:0}),r.to(o,{x:0,y:0,ease:"power3.inOut",duration:.7,delay:.3}),r.to(o,{delay:.1,scale:1,ease:"power3.inOut"}),await r.then(()=>{e.setIsAnimating(!1)})})().catch(()=>{}).then(()=>{null==l||l.abort()}):await(async()=>{if(!x||!p)throw new Error("not mounted or gsap not loaded");e.setIsAnimating(!0),e.setNavVector("none");const t=e.cordHist(),i=y(),a=U(t),o=$(t,i);M(W(s,[...o,a]));const r=n.timeline(),l=W(s,[a])[0],c=W(s,o);return r.to(l,{scale:.6,duration:.6,ease:"power3.inOut"}),r.to(l,{delay:.3,duration:.7,ease:"power3.inOut",x:t.slice(-1)[0].x-window.innerWidth/2,y:t.slice(-1)[0].y-window.innerHeight/2}),r.to(c,{y:"-=20",ease:"power3.out",stagger:-.1,duration:.3,opacity:1}),await r.then(()=>{e.setIsAnimating(!1)})})().catch(()=>{}).then(()=>{l=new AbortController;const t=l.signal;window.addEventListener("mousemove",I,{passive:!0,signal:t}),e.setIsLoading(!1)}))},{defer:!0})),(O=C()).$$keydown=A,O.$$click=A,i(O,d(g,{get each(){return e.ijs},children:(e,t)=>{return n=k(),"function"==typeof(i=s[t()])?u(i,n):s[t()]=n,a(t=>{var s=e.loImgH,i=e.loImgW,a=e.hiUrl,o=e.hiImgH,r=e.hiImgW,l=e.loUrl,c=e.loImgH,d=e.loImgW,g=e.alt;return s!==t.e&&h(n,"height",t.e=s),i!==t.t&&h(n,"width",t.t=i),a!==t.a&&h(n,"data-hi-url",t.a=a),o!==t.o&&h(n,"data-hi-img-h",t.o=o),r!==t.i&&h(n,"data-hi-img-w",t.i=r),l!==t.n&&h(n,"data-lo-url",t.n=l),c!==t.s&&h(n,"data-lo-img-h",t.s=c),d!==t.h&&h(n,"data-lo-img-w",t.h=d),g!==t.r&&h(n,"alt",t.r=g),t},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0}),n;var n,i}})),O;var O}v(["click","keydown"]);var P=s("<div class=navOverlay>"),X=s("<div class=overlay tabindex=-1>");function Y(e){let t;const n=[e.prevText,e.closeText,e.nextText],[s,{incIndex:l,decIndex:c}]=o(),u=s().length,h=()=>{e.setNavVector("prev"),e.setCordHist(e=>e.map(e=>({...e,i:y(e.i,u)}))),c()},m=()=>{e.setIsOpen(!1)},v=()=>{e.setNavVector("next"),e.setCordHist(e=>e.map(e=>({...e,i:p(e.i,u)}))),l()},w=t=>{e.isOpen()&&!e.isAnimating()&&("ArrowLeft"===t.key?h():"Escape"===t.key?m():"ArrowRight"===t.key&&v())};return r(()=>{if(e.isOpen()){t=new AbortController;const e=t.signal;window.addEventListener("keydown",w,{passive:!0,signal:e})}else null==t||t.abort()}),f=P(),i(f,d(g,{each:n,children:t=>{return(s=X()).$$mouseover=()=>e.setHoverText(t),s.addEventListener("focus",()=>e.setHoverText(t)),s.$$click=()=>{(t=>{e.isOpen()&&!e.isAnimating()&&(t===n[0]?h():t===n[1]?m():v())})(t)},s;var s}})),a(()=>f.classList.toggle("active",!!e.active())),f;var f}function z(t){const[n,s]=e([]),[i,a]=e(!1),[o,r]=e(!1),[l,c]=e(!1),[g,u]=e(""),[h,m]=e("none"),v=w(()=>o()&&!l()),p=w(()=>i()?t.loadingText:g());return[d(b,{}),d(f,{get when(){return t.ijs.length>0},get children(){return[d(F,{get ijs(){return t.ijs},setIsLoading:a,isOpen:o,setIsOpen:r,isAnimating:l,setIsAnimating:c,cordHist:n,setCordHist:s,navVector:h,setNavVector:m}),d(f,{get when(){return o()},get children(){return[d(I,{cursorText:p,active:v,isOpen:o}),d(Y,{get prevText(){return t.prevText},get closeText(){return t.closeText},get nextText(){return t.nextText},get loadingText(){return t.loadingText},active:v,isAnimating:l,setCordHist:s,isOpen:o,setIsOpen:r,setHoverText:u,navVector:h,setNavVector:m})]}})]}})]}v(["click","mouseover"]);export{z as default}; |