@slidy/element
Version:
Simple, configurable & reusable carousel CustomElement
2 lines (1 loc) • 22.6 kB
JavaScript
;var Slidy=(()=>{var st=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var Oe=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var n in e)st(t,n,{get:e[n],enumerable:!0})},Fe=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of $e(e))!Oe.call(t,s)&&s!==n&&st(t,s,{get:()=>e[s],enumerable:!(o=Ie(e,s))||o.enumerable});return t};var Ce=t=>Fe(st({},"__esModule",{value:!0}),t);var Ze={};J(Ze,{animation:()=>pt,easing:()=>dt,element:()=>Q,media:()=>ht,plugin:()=>bt});var{assign:it,entries:St}=Object,{abs:z,exp:Mt,floor:It,min:ze,max:rt,round:tt,sign:V}=Math;function O(t,e,n){return ze(n,rt(t,e))}function at(t,e=50,n=!0){let o=0;return n?s=>{let i=performance.now();i-o>=e&&(t(s),o=i)}:s=>t(s)}function F(t,e){for(let n=0;n<t.length;n++)e(t[n],n,t);return t}var ut=(t,e)=>z(t.deltaX)>=z(t.deltaY)&&e.axis!=="y";function $t(t,e=0){return new Promise((n,o)=>{let s=setInterval(()=>{e++,e>=69?(clearInterval(s),o("few slides")):t.childElementCount&&(clearInterval(s),n(Ne(t)))},16)})}function Ne(t){return F(t.children,(e,n)=>e.index=n)}function et(t,e,n){let o=t.children.length;return e.loop?(n+o)%o:O(0,n,o-1)}function j(t,e){if(t.type==="wheel")return ut(t,e)?t.deltaX:t.shiftKey||e.axis==="y"?t.deltaY:0;{let n=t.touches&&t.touches[0]||t;return e.axis==="y"?n.pageY:n.pageX}}function C(t,e,n){t.dispatchEvent(new CustomEvent(e,{detail:n}))}function N(t,e,n=!0){let o=n?"addEventListener":"removeEventListener";F(e,s=>t[o](...s))}function Ot(t,e){let n=[...t.children],o=n.length,s=o-1,i=It(o/2),u=o>1?n[1].offsetTop-n[0].offsetTop>=n[0].offsetHeight:!1,c=u?"offsetTop":"offsetLeft",p=u?"offsetHeight":"offsetWidth",l=V(n[s][c]),f=o>1?n[s][c]*l-n[s-1][c]*l-n[s-rt(l,0)][p]:0,h=n.reduce((r,d)=>r+=d[p]+f,0)>t.offsetWidth,L=e.snap==="deck";it(e,{reverse:l,scrollable:h,vertical:u,edged:I()});function I(r){let d=b(l<0?s:0,"start"),y=b(l<0?0:s,"end"),E=b(r),S=e.direction,w=tt(e.position),T=M=>S<=0&&M<=d||S>=0&&M>=y;return e.loop?!1:T(r>=0?E:w)}function b(r,d=e.snap){let y=k=>n.find(x=>x.index===k)||n[0],E=k=>t[p]-y(k)[p],S=M(l<0?s:0,"start"),w=M(l<0?0:s,"end"),T=M(r,d);return e.loop||d==="deck"?T:O(S,T,w);function M(k,x){x=L?"deck":x;let D=y(k)[p]+f*2<t[p]?e.indent??1:E(k)/2/f,Y=x==="start"?0:x==="end"?1:.5,$=x==="start"?-D:x==="end"?D:0;return y(k)[c]-E(k)*Y+f*$}}return{edges:I,distance:b,index(r){let d=({index:y})=>z(b(y)-r);return n.reduce((y,E)=>d(E)<d(y)?E:y).index},position(r){let d=e.index;if(r){let y=n.slice(d-i).concat(n.slice(0,d-i));t.replaceChildren(...y)}return b(d)},swap(r){let d=o%r?V(-r):r,y=d>0?0:s;return h&&(y?t.prepend(n[y]):t.append(n[y])),(n[y][p]+f)*(d*l)},sense(r,d,y){return r.shiftKey||e.axis==="y"&&r.type!=="touchmove"||z(d)>=y},animate(){F(n,(r,d)=>{r.i=d,r.active=e.loop?i:e.index,r.size=r[p]+f,r.dist=b(r.index),r.track=e.position-r.dist,r.turn=O(-1,r.track/r.size,1),r.exp=O(0,(r.size-z(r.track))/r.size,1);let y=L?r.dist:e.position,E=u?`translateY(${-y}px)`:`translateX(${-y}px)`,S={node:t,child:r,options:e,translate:E},w=e.animation?.(S)||{transform:E};it(r.style,h?w:{transform:""})})}}}function ct(t,e){let n={...e},o,s=0,i=0,u=0,c=0,p=0,l,f,g=s=n.index??=0,h=n.position??=0,L=n.direction??=0,I=(n.duration??=450)/2,b=n.sensity??=2.5,r=n.gravity??=1.2,d=n.clamp??=0,y=[["touchmove",Et,{passive:!1}],["mousemove",Et],["touchend",At],["mouseup",At],["scroll",()=>{$(g),r=2}]],E=[["wheel",Te,{passive:!1,capture:!0}]],S=[["touchstart",xt,{passive:!1}],["mousedown",xt],["keydown",ke],["contextmenu",()=>$(g)],["dragstart",a=>a.preventDefault()]],w=new ResizeObserver(a=>{h=n.position=o().position(),$(g),C(t,"resize",{ROE:a,options:n})}),T=new MutationObserver(a=>{F(a,m=>{[...m.addedNodes,...m.removedNodes].every(A=>"index"in A)||Tt().then(q)}),C(t,"mutate",{ML:a,options:n})}),M=requestAnimationFrame,k="outline:0;overflow:hidden;user-select:none;-webkit-user-select:none;",x={init:q,update:Pe,destroy:Tt,to:$};q(),F(n.plugins||[],(a,m,v)=>{v[m]=a({node:t,options:n,instance:x})});function q(){$t(t).then(()=>{o=()=>Ot(t,n),t.style.cssText+=k,t.onwheel=at(wt,I,d),h=n.position=o().position(n.loop),w.observe(t),T.observe(t,{childList:!0}),N(t,S),N(window,E),C(t,"mount",{options:n})})}function D(a,m){L=n.direction=V(a),h=n.position+=v(a),g=n.index=o().index(h),r=o().edges()?1.8:n.gravity,b=0,o().animate(),C(t,"move",{index:g,position:h});function v(A){return g-s&&(A-=n.loop?o().swap(g-s):0,s=g,C(t,"index",{index:m})),A}}function Y(a,m){let A=n.snap||o().edges(a)?o().distance(a):h+m,H=I*O(1,a-s,2),K=A-h;u=M(kt);let G=0,Z=0,W=0;function kt(Pt){G||=Pt,Z=W;let Le=G-Pt,Lt=Mt(Le/H),Se=n.easing?.(Lt)||Lt;W=K*Se;let Me=Z%W?(Z-W)%K:0;D(Me,a),tt(W)?u=M(kt):(b=n.sensity,B())}}function $(a=0,m=0){a=et(t,n,a),B(),Y(a,m||o().distance(a)-h)}function xt(a){B(),b=n.sensity,i=j(a,n),c=a.timeStamp,p=0,N(window,y),!o().edges()&&a.stopPropagation()}function Et(a){let m=(i-j(a,n))*(2-r),v=a.timeStamp-c,A=1e3*m/(r+v);c=a.timeStamp,i=j(a,n),p=(2-r)*A+(r-1)*p,o().sense(a,m,b)&&(D(m,g),a.preventDefault())}function At(){B();let a=p*(2-r),m=o().index(h+a);Y(v(m,n),a);function v(A,H){return A=d&&A-s?g+d*L:A,et(t,H,A)}}function wt(a){B();let m=j(a,n)*(2-r),v=g+V(m)*(d||1),A=n.snap||l||o().edges(),H=o().sense(a,m,b),K=o().edges()?m/5:m,G=l?v:g,Z=l?0:I/2;!l&&H&&D(K,g),f=A&&H?setTimeout($,Z,G):void 0,!o().edges()&&a.stopPropagation()}function Te(a){if(a.composedPath().includes(t)){let m=n.axis==="y"&&!o().edges();(ut(a,n)||m||a.shiftKey)&&a.preventDefault();let v=d||n.axis==="y"&&!n.vertical||a.shiftKey;l!==v&&(t.onwheel=at(wt,I,v),l=v)}}function ke(a){let m=["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"],v=(m.indexOf(a.key)%2-1||1)*(d||1);m.indexOf(a.key)>=0&&($(g+v),a.preventDefault()),C(t,"keys",a.key)}function B(){clearTimeout(f),cancelAnimationFrame(u),N(window,y,!1)}function Pe(a){F(St(a),([m,v])=>{if(v!==n[m]){switch(m){case"index":$(g=n[m]=et(t,n,v));break;case"position":$(g,v);break;case"gravity":r=n[m]=O(0,v,2);break;case"duration":n[m]=v,I=v/2;break;case"sensity":b=n[m]=v;break;case"clamp":d=n[m]=v;break;default:n[m]=v;break}C(t,"update",a)}})}async function Tt(){B(),w.disconnect(),T.disconnect(),N(t,S,!1),N(window,E,!1),C(t,"destroy",t)}return x}function lt(t,e){return["animation","easing"].includes(t)?De(e):qe(e)}function qe(t){return!isNaN(t)||["true","false"].includes(t)?JSON.parse(t):t}function De(t){return Function(`const fn = ${t}; return fn`)()}var Q=class t extends HTMLElement{_slidy;_options;static observedAttributes=["index","clamp","indent","sensity","gravity","duration","animation","plugins","easing","snap","axis","loop"];constructor(){super();let e=document.createElement("style"),n=":host{display:flex;flex-flow:var(--flow);gap:var(--gap,1rem);width:100%;height:var(--height,20rem)}::slotted(*){flex:0 0 var(--width,auto);width:var(--width,auto);height:100%}",o=document.createElement("slot");e.append(n),this.attachShadow({mode:"closed"}).append(e,o),this.setUpAccessors(t.observedAttributes),this._options=this.setUpOptions(t.observedAttributes)}set options(e){this._options=e}get options(){return this._options}setUpAccessors(e){e.forEach(n=>{Object.defineProperty(this,n,{set:o=>this.setAttribute(n,o),get:()=>this.getAttribute(n)})})}setUpOptions(e){return{...e.reduce((o,s)=>{let i=this[s];return i&&(o[s]=lt(s,i)),o},{}),...this.options}}connectedCallback(){this.isConnected&&this.init(this._options)}attributeChangedCallback(e,n,o){let s=lt(e,o),i={[e]:s};this.update(i)}init(e={}){this._slidy=ct(this,e)}to(e){this._slidy?.to(e)}update(e){this._slidy?.update(e)}destroy(){this._slidy?.destroy()}};typeof window=="object"&&"customElements"in window&&customElements.define("slidy-element",Q);var pt={};J(pt,{blur:()=>zt,deck:()=>_t,fade:()=>Ft,flip:()=>Rt,matrix:()=>Vt,perspective:()=>Dt,rotate:()=>qt,scale:()=>Nt,shade:()=>Ct,shuffle:()=>Bt,stairs:()=>Qt,translate:()=>Ht});var Ft=({child:t,translate:e})=>({opacity:t.exp,transform:e}),Ct=({child:t,translate:e})=>{let n=t.i===t.active,o=Math.abs(t.track)<=t.size,s=n?0:1,i=`${t.track/.5}px, 0`;return t.index===4&&console.log(t.index,o),{transform:n?`${e} translate(${i})`:`${e}`,zIndex:`${s}`}},zt=({child:t,translate:e})=>{let o=t.i===t.active?t.active:t.i>t.active?t.active-t.i:t.i-t.active;return{opacity:String(t.exp),filter:`blur(${1-t.exp}ex`,transform:e,zIndex:String(o)}},Nt=({child:t,translate:e})=>({transform:`${e} scale(${t.exp})`}),qt=({child:t,options:e,translate:n})=>{let s=t.index===e.index?0:-1;return{transform:`${n} rotate(${t.turn}turn)`,zIndex:String(s)}},Dt=({child:t,translate:e})=>({transform:`${e} perspective(${-t.turn}px)`}),Bt=({node:t,child:e,options:n,translate:o})=>{let s=Math.sign(e.track),i=Math.abs(e.track)<e.size&&e.i===e.active,c=Math.abs(e.track)<e.size/2?-e.track:Math.abs(e.track)-e.size,p=n.vertical?`0, ${-e.track}px`:`${c}px, ${s}px`,l=e.i===e.active?e.active:e.i>e.active?e.active-e.i:-(e.i-e.active+t.children.length);return{transform:i?`${o} translate(${p})`:`${o}`,zIndex:String(l)}},Ht=({translate:t})=>({transform:t}),Vt=({node:t,child:e,options:n})=>{let o=e.index===n.index,s=e.exp,i=-e.turn,u=-e.turn,c=e.exp,p=-n.position,l=-e.turn,f=o?t.children.length-e.index:e.index<n.index?e.index-t.children.length:t.children.length-e.index-1;return{transform:`matrix(${s}, ${i}, ${u}, ${c}, ${p}, ${l})`,zIndex:String(f)}},Qt=({node:t,child:e,options:n,translate:o})=>{t.style.perspective=`${t.offsetWidth}px`;let s=n.snap==="deck",u=e.i===e.active?e.active:e.i>e.active?e.active-e.i:e.i-t.children.length+1,c=s?`scale(${e.exp})`:`translateZ(${-Math.abs(e.track)}px)`;return{transform:o+c,zIndex:String(u)}},Rt=({node:t,child:e,options:n,translate:o})=>{t.style.perspective=`${t.offsetWidth}px`;let s=n.snap==="deck",i=e.turn/(s?-2:-4),u=n.vertical?`rotateX(${i}turn)`:`rotateY(${-i}turn)`,c=Math.abs(i)<.25;return{transform:o+u,zIndex:String(c?0:-1),opacity:String(c||!s?1:0)}},_t=({node:t,child:e,options:n,translate:o})=>{t.style.perspective=`${t.offsetWidth}px`;let s=e.index===n.index,i=e.size/10,u=Math.abs(e.track*2)>=e.size/2,c=s?u?e.size+e.track:-e.track*2:-e.track/i,p=n.vertical?0:c,l=n.vertical?c:0,f=-Math.abs(e.track)/(i/2),g=s?-e.track/i:-e.track/(i*2),h=s?(e.size-Math.abs(e.track/2))/e.size:1,L=s?e.active:e.i>e.active?e.active-e.i:1-t.children.length-e.i;return{transform:o+`translate3d(${p}px, ${l}px, ${f}px) rotateZ(${g}deg) scale(${h})`,zIndex:String(L)}};var dt={};J(dt,{back:()=>te,bounce:()=>ee,circ:()=>Jt,cubic:()=>jt,elastic:()=>ne,expo:()=>Gt,linear:()=>Zt,quad:()=>Wt,quart:()=>Xt,quint:()=>Yt,sine:()=>Kt});var{cos:Be,sin:He,pow:mt,sqrt:Ve,PI:Ut}=Math,Zt=t=>t,Wt=t=>t*t,jt=t=>t*t*t,Xt=t=>t*t*t*t,Yt=t=>t*t*t*t*t,Kt=t=>1-Be(t*Ut/2),Gt=t=>t===0?0:mt(2,10*t-10),Jt=t=>1-Ve(1-mt(t,2)),te=t=>2.70158*t*t*t-1.70158*t*t,ee=t=>1-(n=>n<.36363636363636365?7.5625*n*n:n<.7272727272727273?7.5625*(n-=.5454545454545454)*n+.75:n<.9090909090909091?7.5625*(n-=.8181818181818182)*n+.9375:7.5625*(n-=.9545454545454546)*n+.984375)(1-t),ne=t=>{let e=2*Ut/3;return t%1?-mt(2,10*t-10)*He((t*10-10.75)*e):t};var bt={};J(bt,{audio:()=>he,autoplay:()=>ve,fool:()=>re,log:()=>oe,marquee:()=>ie,play:()=>se,share:()=>we});function oe(t){return console.log("log",t),({node:e,options:n,instance:o})=>(console.log("log",{node:e,options:n,instance:o}),e.addEventListener("destroy",function s(){e.removeEventListener("destroy",s)}),null)}function R(t,e,n){let o=n?new CustomEvent(e,n):new Event(e,{bubbles:!0});return t.dispatchEvent(o)}function nt(t,e,n=0){let o,s=0,i=0,u=e;function c(){s===1&&(s=2,clearInterval(o),u=n||e-Math.abs(performance.now()-i))}function p(){s===2&&(s=3,setTimeout(g,u))}function l(){s=0,clearInterval(o)}function f(){s=1,i=performance.now(),o=setInterval(()=>{t(),i=performance.now()},e)}function g(){s===3&&(t(),f())}return{play:f,pause:c,resume:p,stop:l}}function se(t,e,n=0){(!t||!Object.keys(t).length)&&(t={duration:1500,delay:0});let{duration:o,delay:s}=t;return({node:i,options:u,instance:c})=>{e||=()=>{!u.loop&&u.index&&u.edged?(R(i,"stop"),p.stop(),n=0):(n=1,c.to(u.index+1))};let p=nt(e,o,s);return i.addEventListener("mount",l),i.addEventListener("destroy",p.stop),p;function l(){document.onvisibilitychange=()=>{if(document.visibilityState==="hidden"){if(n!==1)return;R(i,"pause"),p.pause(),n=2}else{if(n!==2)return;R(i,"resume"),p.resume()}},i.onpointerenter=()=>{n===1&&(R(i,"pause"),p.pause(),n=2)},i.onpointerleave=()=>{n===2&&(R(i,"resume"),p.resume())}}}}function ie(t={duration:700,delay:1}){let{duration:e,delay:n}=t;return({node:o,options:s,instance:i})=>{let u=nt(()=>{i.to(s.index,e/16.667)},Math.abs(e/16.667),n);return o.addEventListener("mount",c),o.addEventListener("destroy",u.stop),u;function c(){s.loop=!0,s.snap=void 0,s.duration=Math.abs(e),u.play(),document.onvisibilitychange=()=>{document.visibilityState==="hidden"?u.pause():u.resume()},o.onpointerenter=()=>u.pause(),o.onpointerleave=()=>u.resume()}}}function re(){return({node:t,instance:e})=>{t.addEventListener("destroy",function o(){t.removeEventListener("destroy",o),t.removeEventListener("index",n)}),t.addEventListener("index",n);function n({detail:{index:o}}){setTimeout(function(){e.update({axis:o%2?"x":"y"})})}}}var ae={viewBox:"0 0 24 24",path:"M5.75,3A1.75,1.75,0,0,0,4,4.75v14.5A1.75,1.75,0,0,0,5.75,21h3.5A1.75,1.75,0,0,0,11,19.25V4.75A1.75,1.75,0,0,0,9.25,3ZM5.5,4.75a.25.25,0,0,1,.25-.25h3.5a.25.25,0,0,1,.25.25v14.5a.25.25,0,0,1-.25.25H5.75a.25.25,0,0,1-.25-.25ZM14.75,3A1.75,1.75,0,0,0,13,4.75v14.5A1.75,1.75,0,0,0,14.75,21h3.5A1.75,1.75,0,0,0,20,19.25V4.75A1.75,1.75,0,0,0,18.25,3ZM14.5,4.75a.25.25,0,0,1,.25-.25h3.5a.25.25,0,0,1,.25.25v14.5a.25.25,0,0,1-.25.25h-3.5a.25.25,0,0,1-.25-.25Z"},ue={viewBox:"0 0 24 24",path:"M7.61,4.61a.75.75,0,0,0-1.11.66V18.73a.75.75,0,0,0,1.11.65L20,12.66a.75.75,0,0,0,0-1.32ZM5,5.27a2.25,2.25,0,0,1,3.33-2L20.69,10a2.26,2.26,0,0,1,0,4L8.33,20.7a2.25,2.25,0,0,1-3.33-2Z"},ce={viewBox:"0 0 24 24",path:"M5.75,3h12.5A2.75,2.75,0,0,1,21,5.75v12.5A2.75,2.75,0,0,1,18.25,21H5.75A2.75,2.75,0,0,1,3,18.25V5.75A2.75,2.75,0,0,1,5.75,3Zm0,1.5A1.25,1.25,0,0,0,4.5,5.75v12.5A1.25,1.25,0,0,0,5.75,19.5h12.5a1.25,1.25,0,0,0,1.25-1.25V5.75A1.25,1.25,0,0,0,18.25,4.5Z"};var P=15,X=2,de={play:ue.path,pause:ae.path,stop:ce.path},Qe=`0 0 ${2*P+X} ${2*P+X}`,le=`${X}px`,pe=`M ${P+X/2}, ${P+X/2} m -${P}, 0 a ${P},${P} 0 1,0 ${2*P},0 a ${P},${P} 0 1,0 ${-2*P},0`,ft=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).innerHTML=`<style>:host{grid-area:slides;--slidy-autoplay-stroke-length: ${2*Math.PI*P};width:var(--slidy-autoplay-control-size,2.25em);height:var(--slidy-autoplay-control-size,2.25em);grid-template:1fr/1fr;place-content:center;place-items:center;display:grid;position:absolute;bottom:1em;right:1em}:host>svg{width:var(--slidy-autoplay-control-size,2.25em);height:var(--slidy-autoplay-control-size,2.25em)}:host>*{grid-area:1/1}:host>button{pointer-events:all;fill:var(--slidy-arrow-icon-color,currentColor);background-color:var(--slidy-counter-bg,#4e4e4ebf);cursor:pointer;border:none;border-radius:1em;outline:none;justify-content:center;align-items:center;padding:.25em;font-family:inherit;display:flex}:host>button,:host>button svg{width:calc(.9*var(--slidy-autoplay-control-size,2.25em));height:calc(.9*var(--slidy-autoplay-control-size,2.25em))}:host>button:disabled{opacity:.75;cursor:not-allowed}:host>button:focus-visible{outline:2px dashed var(--slidy-focus-ring-color,#c9c9c9e6);outline-offset:calc(.25*var(--slidy-autoplay-control-size,2.25em));border-radius:50%}.slidy-autoplay-indicator{stroke-dasharray:var(--slidy-autoplay-stroke-length);stroke-dashoffset:var(--slidy-autoplay-stroke-length);animation:slidy-autoplay-indicator var(--slidy-autoplay-interval)linear forwards infinite}.slidy-autoplay-indicator.stop{animation:unset}.slidy-autoplay-indicator.pause{animation-play-state:paused}@keyframes slidy-autoplay-indicator{to{stroke-dashoffset:0}}</style><svg viewBox="${Qe}"><path stroke="var(--slidy-counter-bg, #4e4e4ebf)" stroke-width="${le}" fill="none" d="${pe}"></path><path class="slidy-autoplay-indicator stop" stroke="var(--slidy-autoplay-indicator-accent, lightpink)" stroke-width="${le}" fill="none" d="${pe}"></path></svg><button type="button"><svg viewBox="0 0 24 24"><path d=""></path></svg></button>`}setDuration(e){this.style.setProperty("--slidy-autoplay-interval",e+"ms")}get path0(){return this.shadowRoot.firstElementChild.nextElementSibling.firstElementChild.nextElementSibling}get button(){return this.shadowRoot.firstElementChild.nextElementSibling.nextElementSibling}get path1(){return this.button.firstElementChild.firstElementChild}get animation(){let e=this.path0.classList;return{pause(){e.add("pause")},cancel(){e.add("stop")},play(){e.remove("stop","pause")}}}},me=!1;function fe(t){me||(customElements.define("autoplay-button",ft),me=!0);let e=document.createElement("autoplay-button"),n=e.button;return n.onclick=t,[e,n,e.path1]}var yt=(t,e)=>{let n=Object.entries(e),o=()=>{for(let[i,u]of n)t.addEventListener(i,u)},s=()=>{for(let[i,u]of n)t.removeEventListener(i,u)};return o(),s},vt=(t,...e)=>e.includes(t);var _=performance.now.bind(performance),ot=class{queue;timeoutId;index;off;time=_();constructor(e){this.queue=e,this.index=0,this.off=0}start(){this.time=_(),this.runNextTask()}pause(){clearTimeout(this.timeoutId),this.off+=_()-this.time}stop(){clearTimeout(this.timeoutId),this.off=0,this.index=0}runNextTask(){this.index===this.queue.length&&this.stop();let e=this.queue[this.index];if(typeof e=="function"){let n=_();e(),this.index++,this.off+=_()-n,this.runNextTask()}else this.timeoutId=setTimeout(()=>{this.index++,this.time=_(),this.off=0,this.runNextTask()},e.await-this.off)}};function ye(t,e,n=0){let o=new ot([()=>{e.animation.play()},{await:e.interval},()=>{t(),e.animation.cancel(),n=3},{await:e.delay},()=>{n=1,e.animation.cancel()}]);return{play(){n!==3&&e.animation.play(),n=1,e.state=0,o.start()},pause(){n!==3&&(n=2),e.state=2,e.animation.pause(),o.pause()},stop(){n=0,e.state=1,e.animation.cancel(),o.stop()}}}var Re={play:"Start autoplay",stop:"Stop autoplay"};var _e={0:"pause",1:"play",2:"stop"},ve=({i18n:t=Re,duration:e=2500,delay:n=0,autoplay:o=!1,target:s}={})=>{let i=1,u={0:t.stop,1:t.play,2:t.stop};return({node:c,options:p,instance:l})=>{let f=()=>c.childElementCount,g=()=>{let x=p.index+1;p.loop||x<f()?(i=0,r(),l.to(x)):b.stop()},[h,L,I]=fe(()=>{vt(i,2,0)?b.stop():b.play(),r()}),b=ye(g,{set state(x){i=x,r()},delay:n,interval:e,animation:h.animation});s?typeof s=="string"?document.querySelector(s).appendChild(h):s.appendChild(h):c.insertAdjacentElement("afterend",h),h.setDuration(e);let r=()=>{r.current!==i&&(L.setAttribute("title",u[i]),I.setAttribute("d",de[_e[i]]),r.current=i)};r();let d=x=>{let q=x.detail.index+1;p.loop||q<f()?L.removeAttribute("disabled"):(L.setAttribute("disabled","disabled"),b.stop()),r()},y=()=>{i===0&&b.pause()},E=()=>{i===2&&b.play()},S=()=>{vt(T,0,1)||E()},w=2,T=2;c.onpointerenter=()=>{T=1,w!==0&&y()},h.onpointerenter=()=>{T=0,y()},h.onpointerleave=()=>{w!==1&&E(),w=0},c.onpointerleave=()=>{w=1,T=2,queueMicrotask(S)};let M=yt(document,{visibilitychange:()=>{document.visibilityState==="hidden"&&i===0?b.pause():i===2&&b.play()}}),k=yt(c,{index:d,mount:()=>{o&&b.play()},destroy:()=>{b.stop(),M(),k()}})}};var U={C4:261.63,E4:329.63,G4:392,Bell:1567.98,Beep:493.88},ge={index:[{freq:U.C4,dur:.5},{freq:U.E4,dur:.5},{freq:U.G4,dur:.5},{freq:U.C4,dur:1}],keys:[{freq:U.Beep,dur:1},{freq:U.Bell,dur:.5}]};var be=(t,e,n)=>{let o=t.createOscillator();o.type="square";let s=t.createGain();o.connect(s),s.connect(t.destination),o.frequency.value=e,s.gain.setValueAtTime(1,t.currentTime),s.gain.exponentialRampToValueAtTime(.001,t.currentTime+n),o.start(t.currentTime),o.stop(t.currentTime+n)};var he=(t=ge)=>{let e,n=!1,o=Object.entries(t).reduce((s,[i,u])=>(s[i]=()=>{if(!e)try{e=new AudioContext}catch{return}n||u.forEach((c,p,l)=>{let f=p>0?l[p-1].dur*1e3:0;setTimeout(()=>{be(e,c.freq,c.dur),p===0&&(n=!0),p===l.length-1&&setTimeout(()=>{n=!1},c.dur)},f)})},s),{});return({node:s})=>{function i(){for(let[u,c]of Object.entries(o))s.removeEventListener(u,c);s.removeEventListener("destroy",i)}s.addEventListener("destroy",i);for(let[u,c]of Object.entries(o))s.addEventListener(u,c)}};var Ue="Share",xe="slidy-share-button",gt=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}).innerHTML=`<style>:host{width:var(--slidy-share-control-size,2.25em);height:var(--slidy-share-control-size,2.25em);grid-area:slides;place-content:center;place-items:center;display:grid;position:absolute;bottom:1em;left:1em}:host>button{pointer-events:all;fill:var(--slidy-arrow-icon-color,currentColor);background-color:var(--slidy-counter-bg,#4e4e4ebf);cursor:pointer;width:var(--slidy-share-control-size,2.25em);height:var(--slidy-share-control-size,2.25em);border:none;border-radius:50%;outline:none;justify-content:center;align-items:center;padding:.25em;font-family:inherit;display:flex}:host>button svg{width:calc(.9*var(--slidy-share-control-size,2.25em));height:calc(.9*var(--slidy-share-control-size,2.25em))}</style><button type="button" aria-label="${Ue}"><svg viewBox="1 0 15 15" fill="none"><path fill="currentColor" fill-rule="evenodd" d="M5 7.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Zm.713 1.164a2.5 2.5 0 1 1 0-2.328l3.391-2.12A2.5 2.5 0 1 1 14 3.5a2.5 2.5 0 0 1-4.484 1.52l-3.53 2.207a2.526 2.526 0 0 1 0 .546l3.53 2.206a2.5 2.5 0 1 1-.411.804l-3.392-2.12ZM11.5 5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm1.5 6.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z" clip-rule="evenodd"/></svg></button>`}},Ee=!1,Ae=t=>{Ee||(customElements.define(xe,gt),Ee=!0);let e=document.createElement(xe);return e.onclick=t,e};var we=({target:t,type:e}={target:void 0,type:"url"})=>({node:n,options:o})=>{let s=Ae(()=>{let u=o.index;if(!u)return;let c=n.childNodes[u];if(!c)return;let p=c.querySelector("[src]")?.src||c.style.backgroundImage||void 0,l=c.querySelector("img")?.alt||void 0;if(p)try{e==="url"&&navigator.share({url:p,title:l})}finally{}});function i(){s.remove(),n.removeEventListener("destroy",i)}n.addEventListener("destroy",i),t?typeof t=="string"?document.querySelector(t).appendChild(s):t.appendChild(s):n.insertAdjacentElement("afterend",s)};function ht({queries:t,getter:e,cookie:n}){let o=new Set,s={};if(typeof window=="object")for(let l in t){let f=window.matchMedia(t[l]);i(f,l),f.onchange=g=>i(g,l)}function i(l,f){s[f]=l.matches,u(s),e&&e(s),n&&(document.cookie=`media=${JSON.stringify(s)}`)}function u(l){o.forEach(f=>f(l))}function c(l){return l(s),o.add(l),()=>p(l)}let p=l=>o.delete(l);return{matches:s,subscribe:c}}return Ce(Ze);})();