!function(e,t){"function"==typeof define&&define.amd?define([],function(){return t(e)}):"object"==typeof exports?module.exports=t(e):e.Gumshoe=t(e)}("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,function(u){"use strict";function d(e,t,n){n.settings.events&&(n=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n}),t.dispatchEvent(n))}function n(e){var t=0;if(e.offsetParent)for(;e;)t+=e.offsetTop,e=e.offsetParent;return 0<=t?t:0}function f(e){e&&e.sort(function(e,t){return n(e.content)<n(t.content)?-1:1})}function r(e,t,n){return e=e.getBoundingClientRect(),t="function"==typeof(t=t).offset?parseFloat(t.offset()):parseFloat(t.offset),n?parseInt(e.bottom,10)<(u.innerHeight||document.documentElement.clientHeight):parseInt(e.top,10)<=t}function s(){return Math.ceil(u.innerHeight+u.pageYOffset)>=Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)}function m(e,t){var n,o,c=e[e.length-1];if(n=c,o=t,!(!s()||!r(n.content,o,!0)))return c;for(var l=e.length-1;0<=l;l--)if(r(e[l].content,t))return e[l]}function v(e,t){var n;!e||(n=e.nav.closest("li"))&&(n.classList.remove(t.navClass),e.content.classList.remove(t.contentClass),o(n,t),d("gumshoeDeactivate",n,{link:e.nav,content:e.content,settings:t}))}var p={navClass:"active",contentClass:"active",nested:!1,nestedClass:"active",offset:0,reflow:!1,events:!0},o=function(e,t){t.nested&&e.parentNode&&((e=e.parentNode.closest("li"))&&(e.classList.remove(t.nestedClass),o(e,t)))},h=function(e,t){!t.nested||(e=e.parentNode.closest("li"))&&(e.classList.add(t.nestedClass),h(e,t))};return function(e,t){var n,c,l,o,r,s={setup:function(){n=document.querySelectorAll(e),c=[],Array.prototype.forEach.call(n,function(e){var t=document.getElementById(decodeURIComponent(e.hash.substr(1)));t&&c.push({nav:e,content:t})}),f(c)}};s.detect=function(){var e,t,n,o=m(c,r);o?l&&o.content===l.content||(v(l,r),t=r,!(e=o)||(n=e.nav.closest("li"))&&(n.classList.add(t.navClass),e.content.classList.add(t.contentClass),h(n,t),d("gumshoeActivate",n,{link:e.nav,content:e.content,settings:t})),l=o):l&&(v(l,r),l=null)};function i(e){o&&u.cancelAnimationFrame(o),o=u.requestAnimationFrame(s.detect)}function a(e){o&&u.cancelAnimationFrame(o),o=u.requestAnimationFrame(function(){f(c),s.detect()})}s.destroy=function(){l&&v(l,r),u.removeEventListener("scroll",i,!1),r.reflow&&u.removeEventListener("resize",a,!1),r=o=l=n=c=null};return r=function(){var n={};return Array.prototype.forEach.call(arguments,function(e){for(var t in e){if(!e.hasOwnProperty(t))return;n[t]=e[t]}}),n}(p,t||{}),s.setup(),s.detect(),u.addEventListener("scroll",i,!1),r.reflow&&u.addEventListener("resize",a,!1),s}});var tocScroll=null,header=null;function scrollHandlerForHeader(){0==header.getBoundingClientRect().top?header.classList.add("scrolled"):header.classList.remove("scrolled")}function scrollHandlerForTOC(t){if(null!==tocScroll)if(0==t)tocScroll.scrollTo(0,0);else if(Math.ceil(t)==Math.ceil(document.documentElement.scrollHeight-window.innerHeight))tocScroll.scrollTo(0,tocScroll.scrollHeight);else{const e=document.querySelector(".scroll-current");null!=e&&((t=e.getBoundingClientRect()).top<0?e.scrollIntoView(!0):t.bottom>window.innerHeight&&e.scrollIntoView(!1))}}function scrollHandler(e){scrollHandlerForHeader(),scrollHandlerForTOC(e)}function setupScrollHandler(){var t,n=!1;window.addEventListener("scroll",function(e){t=window.scrollY,n||(window.requestAnimationFrame(function(){scrollHandler(t),n=!1}),n=!0)}),window.scroll()}function setupScrollSpy(){null!==tocScroll&&new Gumshoe(".toc-tree a",{reflow:!0,recursive:!0,navClass:"scroll-current"})}function setup(){setupScrollHandler(),setupScrollSpy()}function main(){document.body.parentNode.classList.remove("no-js"),header=document.querySelector("header"),tocScroll=document.querySelector(".toc-scroll"),setup()}document.addEventListener("DOMContentLoaded",main);
//# sourceMappingURL=main.js.map
