/*! @darowasahito/gekko v1.1.0 | MIT | 2026-04-09T03:13:23.725Z */
(function(n,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(n=typeof globalThis<"u"?globalThis:n||self,n.Gekko=o())})(this,function(){"use strict";var b=Object.defineProperty;var q=(n,o,r)=>o in n?b(n,o,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[o]=r;var u=(n,o,r)=>(q(n,typeof o!="symbol"?o+"":o,r),r);const n=Math.pow,o=Math.sqrt,r=Math.sin,y=Math.cos,a=Math.PI,d=1.70158,f=d*1.525,E=d+1,v=2*a/3,k=2*a/4.5;function m(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375}const M={inQuad:function(t){return t*t},outQuad:function(t){return 1-(1-t)*(1-t)},inOutQuad:function(t){return t<.5?2*t*t:1-n(-2*t+2,2)/2},inCubic:function(t){return t*t*t},outCubic:function(t){return 1-n(1-t,3)},inOutCubic:function(t){return t<.5?4*t*t*t:1-n(-2*t+2,3)/2},inQuart:function(t){return t*t*t*t},outQuart:function(t){return 1-n(1-t,4)},inOutQuart:function(t){return t<.5?8*t*t*t*t:1-n(-2*t+2,4)/2},inQuint:function(t){return t*t*t*t*t},outQuint:function(t){return 1-n(1-t,5)},inOutQuint:function(t){return t<.5?16*t*t*t*t*t:1-n(-2*t+2,5)/2},inSine:function(t){return 1-y(t*a/2)},outSine:function(t){return r(t*a/2)},inOutSine:function(t){return-(y(a*t)-1)/2},inExpo:function(t){return t===0?0:n(2,10*t-10)},outExpo:function(t){return t===1?1:1-n(2,-10*t)},inOutExpo:function(t){return t===0?0:t===1?1:t<.5?n(2,20*t-10)/2:(2-n(2,-20*t+10))/2},inCirc:function(t){return 1-o(1-n(t,2))},outCirc:function(t){return o(1-n(t-1,2))},inOutCirc:function(t){return t<.5?(1-o(1-n(2*t,2)))/2:(o(1-n(-2*t+2,2))+1)/2},inElastic:function(t){return t===0?0:t===1?1:-n(2,10*t-10)*r((t*10-10.75)*v)},outElastic:function(t){return t===0?0:t===1?1:n(2,-10*t)*r((t*10-.75)*v)+1},inOutElastic:function(t){return t===0?0:t===1?1:t<.5?-(n(2,20*t-10)*r((20*t-11.125)*k))/2:n(2,-20*t+10)*r((20*t-11.125)*k)/2+1},inBack:function(t){return E*t*t*t-d*t*t},outBack:function(t){return 1+E*n(t-1,3)+d*n(t-1,2)},inOutBack:function(t){return t<.5?n(2*t,2)*((f+1)*2*t-f)/2:(n(2*t-2,2)*((f+1)*(t*2-2)+f)+2)/2},inBounce:function(t){return 1-m(1-t)},outBounce:m,inOutBounce:function(t){return t<.5?(1-m(1-2*t))/2:(1+m(2*t-1))/2},linear:function(t){return t}};class Q{constructor(e){u(this,"params");u(this,"isStop",!1);u(this,"isScrolling",!1);u(this,"delayTimeoutId",null);u(this,"currentAnchor",null);u(this,"currentTrigger",null);u(this,"optionsDefault",{speed:1e3,isSpeedAsDuration:!1,delay:0,easing:"outQuad",offset:0});u(this,"clickHandler",e=>{this.onClick(e)});u(this,"error",(...e)=>{console.error("Gekko",...e)});this.params={...this.optionsDefault,...e},document.querySelectorAll("a").forEach(s=>{s.target||s.addEventListener("click",this.clickHandler)}),window.location.hash&&(window.scrollTo(0,0),this.scroll(window.location.hash));const i="onwheel"in document?"wheel":"onmousewheel"in document?"mousewheel":"DOMMouseScroll";document.addEventListener(i,()=>{this.onScroll()}),document.addEventListener("touchstart",()=>{this.onScroll()})}scroll(e,i=!0){const s=document.getElementById(e.replace("#",""));if(s){this.isStop=!1,this.delayTimeoutId!==null&&(clearTimeout(this.delayTimeoutId),this.delayTimeoutId=null),document.dispatchEvent(new CustomEvent("beforeScroll",{detail:{anchor:e}})),this.currentAnchor=e;const c=()=>{var A;const l=window.scrollY||document.documentElement.scrollTop,g=s.getBoundingClientRect().top+l;let h;typeof this.params.offset=="number"?h=this.params.offset:typeof this.params.offset=="string"?h=((A=document.querySelector(this.params.offset))==null?void 0:A.getBoundingClientRect().height)||0:typeof this.params.offset=="function"?h=this.params.offset(this.currentTrigger):h=0;const S=Math.max(0,g-h),w=S-l;if(w===0){this.currentAnchor=null,this.currentTrigger=null;return}if(history.pushState({},"",e),i){this.isScrolling=!0;const B=this.params.isSpeedAsDuration?this.params.speed:Math.abs(w/this.params.speed)*1e3;let T=null;const C=O=>{T===null&&(T=O);const I=(O-T)/B;I<1&&!this.isStop?(window.scrollTo(0,l+w*M[this.params.easing](I)),window.requestAnimationFrame(C)):this.isStop?(this.isScrolling=!1,this.currentAnchor=null,this.currentTrigger=null,document.dispatchEvent(new CustomEvent("stopScroll",{detail:{anchor:e}}))):(window.scrollTo(0,S),this.isScrolling=!1,this.currentAnchor=null,this.currentTrigger=null,document.dispatchEvent(new CustomEvent("afterScroll",{detail:{anchor:e}})))};window.requestAnimationFrame(C)}else window.scrollTo(0,S),this.currentAnchor=null,this.currentTrigger=null},p=typeof this.params.delay=="function"?this.params.delay(this.currentTrigger):this.params.delay;p>0?this.delayTimeoutId=setTimeout(()=>{this.delayTimeoutId=null,this.isStop||c()},p):c()}else this.error(`${e} is not found.`)}stop(){if(this.isStop=!0,this.delayTimeoutId!==null&&(clearTimeout(this.delayTimeoutId),this.delayTimeoutId=null,this.currentAnchor!==null)){const e=this.currentAnchor;this.currentAnchor=null,this.currentTrigger=null,document.dispatchEvent(new CustomEvent("stopScroll",{detail:{anchor:e}}))}}on(e,i){const s=c=>{i(c.detail.anchor)};document.addEventListener(e,s)}options(e){this.params={...this.params,...e}}destroy(){this.stop(),document.querySelectorAll("a").forEach(i=>{i.removeEventListener("click",this.clickHandler)});const e="onwheel"in document?"wheel":"onmousewheel"in document?"mousewheel":"DOMMouseScroll";document.removeEventListener(e,this.onScroll),document.removeEventListener("touchstart",this.onScroll)}onClick(e){const i=e.currentTarget;if(!i){this.error("Unexpected error occurred. Target does not exist.");return}this.currentTrigger=i;const s=g=>g.replace(/\/$/,""),c=s(`${i.protocol}//${i.host}${i.pathname}`),p=s(`${location.origin}${location.pathname}`),l=c===p?i.hash:"";l&&i.dataset.gekko!=="no-smooth"&&(e.preventDefault(),e.stopPropagation(),this.scroll(l))}onScroll(){this.isScrolling&&this.stop()}}return Q});
