UNPKG

space-router

Version:
18 lines 12.1 kB
!function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([/*!*************************!*\ !*** ./src/js/index.js ***! \*************************/ function(e,t,n){var o,r,l;(function(i){!function(n,i){r=[],o=i(n),l="function"==typeof o?o.apply(t,r):o,!(void 0!==l&&(e.exports=l))}("undefined"!=typeof i?i:this.window||this.global,function(e){"use strict";function t(){for(var e={},t=0;t<arguments.length;t++){var n=arguments[t];for(var o in n)h.call(n,o)&&(e[o]=n[o])}return e}function o(e,t,n){t||(t=250);var o,r;return function(){var l=n||this,i=+new Date,s=arguments;o&&i<o+t?(clearTimeout(r),r=setTimeout(function(){o=i,e.apply(l,s)},t)):(o=i,e.apply(l,s))}}var r,l,i,s=n(/*! smooth-scroll */1),c=n(/*! ./default-options.js */2),a={},u={},d=n(/*! ./build-html.js */3),f=n(/*! ./parse-content.js */4),m=(e.document,document.body,!!e.document.querySelector&&!!e.addEventListener),h=Object.prototype.hasOwnProperty;return u.destroy=function(){try{document.querySelector(a.tocSelector).innerHTML=""}catch(e){console.warn("Element not found: "+a.tocSelector)}document.removeEventListener("scroll",this._scrollListener,!1),document.removeEventListener("resize",this._scrollListener,!1),r&&document.removeEventListener("click",this._clickListener,!1),s&&s.destroy()},u.init=function(e){if(m&&(a=t(c,e||{}),this.options=a,this.state={},r=d(a),l=f(a),this._buildHtml=r,this._parseContent=l,u.destroy(),i=l.selectHeadings(a.contentSelector,a.headingSelector),null!==i)){var n=l.nestHeadingsArray(i),h=n.nest;return r.render(a.tocSelector,h),this._scrollListener=o(function(){r.updateToc(i)},a.throttleTimeout),this._scrollListener(),document.addEventListener("scroll",this._scrollListener,!1),document.addEventListener("resize",this._scrollListener,!1),this._clickListener=o(function(e){r.disableTocAnimation(e),r.updateToc(i)},a.throttleTimeout),document.addEventListener("click",this._clickListener,!1),s&&(this.smoothScroll=s.init(t(a.smoothScrollOptions,{callback:r.enableTocAnimation}))),this}},u.refresh=function(e){u.destroy(),u.init(e||this.options)},e.tocbot=u,u})}).call(t,function(){return this}())},/*!******************************************************!*\ !*** ./~/smooth-scroll/dist/js/smooth-scroll.min.js ***! \******************************************************/ function(e,t,n){var o,r,l;(function(n){/*! smooth-scroll v10.2.1 | (c) 2016 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */ !function(n,i){r=[],o=i(n),l="function"==typeof o?o.apply(t,r):o,!(void 0!==l&&(e.exports=l))}("undefined"!=typeof n?n:this.window||this.global,function(e){"use strict";var t,n,o,r,l,i,s,c={},a="querySelector"in document&&"addEventListener"in e,u={selector:"[data-scroll]",selectorHeader:null,speed:500,easing:"easeInOutCubic",offset:0,callback:function(){}},d=function(){var e={},t=!1,n=0,o=arguments.length;"[object Boolean]"===Object.prototype.toString.call(arguments[0])&&(t=arguments[0],n++);for(var r=function(n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t&&"[object Object]"===Object.prototype.toString.call(n[o])?e[o]=d(!0,e[o],n[o]):e[o]=n[o])};n<o;n++){var l=arguments[n];r(l)}return e},f=function(e){return Math.max(e.scrollHeight,e.offsetHeight,e.clientHeight)},m=function(e,t){for(Element.prototype.matches||(Element.prototype.matches=Element.prototype.matchesSelector||Element.prototype.mozMatchesSelector||Element.prototype.msMatchesSelector||Element.prototype.oMatchesSelector||Element.prototype.webkitMatchesSelector||function(e){for(var t=(this.document||this.ownerDocument).querySelectorAll(e),n=t.length;--n>=0&&t.item(n)!==this;);return n>-1});e&&e!==document;e=e.parentNode)if(e.matches(t))return e;return null},h=function(e){"#"===e.charAt(0)&&(e=e.substr(1));for(var t,n=String(e),o=n.length,r=-1,l="",i=n.charCodeAt(0);++r<o;){if(t=n.charCodeAt(r),0===t)throw new InvalidCharacterError("Invalid character: the input contains U+0000.");l+=t>=1&&t<=31||127==t||0===r&&t>=48&&t<=57||1===r&&t>=48&&t<=57&&45===i?"\\"+t.toString(16)+" ":t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(r):"\\"+n.charAt(r)}return"#"+l},p=function(e,t){var n;return"easeInQuad"===e&&(n=t*t),"easeOutQuad"===e&&(n=t*(2-t)),"easeInOutQuad"===e&&(n=t<.5?2*t*t:-1+(4-2*t)*t),"easeInCubic"===e&&(n=t*t*t),"easeOutCubic"===e&&(n=--t*t*t+1),"easeInOutCubic"===e&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e&&(n=t*t*t*t),"easeOutQuart"===e&&(n=1- --t*t*t*t),"easeInOutQuart"===e&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e&&(n=t*t*t*t*t),"easeOutQuint"===e&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),n||t},v=function(e,t,n){var o=0;if(e.offsetParent)do o+=e.offsetTop,e=e.offsetParent;while(e);return o=Math.max(o-t-n,0),Math.min(o,C()-y())},y=function(){return Math.max(document.documentElement.clientHeight,e.innerHeight||0)},C=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},S=function(e){return e&&"object"==typeof JSON&&"function"==typeof JSON.parse?JSON.parse(e):{}},g=function(e){return e?f(e)+e.offsetTop:0},b=function(t,n,o){o||(t.focus(),document.activeElement.id!==t.id&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))};c.animateScroll=function(n,o,i){var c=S(o?o.getAttribute("data-options"):null),a=d(t||u,i||{},c),f="[object Number]"===Object.prototype.toString.call(n),m=f||!n.tagName?null:n;if(f||m){var h=e.pageYOffset;a.selectorHeader&&!r&&(r=document.querySelector(a.selectorHeader)),l||(l=g(r));var y,x,E=f?n:v(m,l,parseInt(a.offset,10)),N=E-h,O=C(),L=0,H=function(t,r,l){var i=e.pageYOffset;(t==r||i==r||e.innerHeight+i>=O)&&(clearInterval(l),b(n,r,f),a.callback(n,o))},A=function(){L+=16,y=L/parseInt(a.speed,10),y=y>1?1:y,x=h+N*p(a.easing,y),e.scrollTo(0,Math.floor(x)),H(x,E,s)},T=function(){clearInterval(s),s=setInterval(A,16)};0===e.pageYOffset&&e.scrollTo(0,0),T()}};var x=function(t){var r;try{r=h(decodeURIComponent(e.location.hash))}catch(t){r=h(e.location.hash)}n&&(n.id=n.getAttribute("data-scroll-id"),c.animateScroll(n,o),n=null,o=null)},E=function(r){if(0===r.button&&!r.metaKey&&!r.ctrlKey&&(o=m(r.target,t.selector),o&&"a"===o.tagName.toLowerCase()&&o.hostname===e.location.hostname&&o.pathname===e.location.pathname&&/#/.test(o.href))){var l;try{l=h(decodeURIComponent(o.hash))}catch(e){l=h(o.hash)}if("#"===l){r.preventDefault(),n=document.body;var i=n.id?n.id:"smooth-scroll-top";return n.setAttribute("data-scroll-id",i),n.id="",void(e.location.hash.substring(1)===i?x():e.location.hash=i)}n=document.querySelector(l),n&&(n.setAttribute("data-scroll-id",n.id),n.id="",o.hash===e.location.hash&&(r.preventDefault(),x()))}},N=function(e){i||(i=setTimeout(function(){i=null,l=g(r)},66))};return c.destroy=function(){t&&(document.removeEventListener("click",E,!1),e.removeEventListener("resize",N,!1),t=null,n=null,o=null,r=null,l=null,i=null,s=null)},c.init=function(n){a&&(c.destroy(),t=d(u,n||{}),r=t.selectorHeader?document.querySelector(t.selectorHeader):null,l=g(r),document.addEventListener("click",E,!1),e.addEventListener("hashchange",x,!1),r&&e.addEventListener("resize",N,!1))},c})}).call(t,function(){return this}())},/*!***********************************!*\ !*** ./src/js/default-options.js ***! \***********************************/ function(e,t){e.exports={tocSelector:".js-toc",contentSelector:".js-toc-content",headingSelector:"h1, h2, h3",ignoreSelector:".js-toc-ignore",linkClass:"toc-link",extraLinkClasses:"",activeLinkClass:"is-active-link",listClass:"toc-list",extraListClasses:"",isCollapsedClass:"is-collapsed",collapsibleClass:"is-collapsible",listItemClass:"toc-list-item",collapseDepth:0,smoothScrollOptions:{easing:"easeInOutCubic",offset:0,speed:300},headingsOffset:0,throttleTimeout:50,positionFixedSelector:null,positionFixedClass:"is-position-fixed",fixedSidebarOffset:"auto",includeHtml:!1}},/*!******************************!*\ !*** ./src/js/build-html.js ***! \******************************/ function(e,t){e.exports=function(e){function t(e,n){var l=n.appendChild(o(e));if(e.children.length){var i=r(e.isCollapsed);e.children.forEach(function(e){t(e,i)}),l.appendChild(i)}}function n(e,n){var o=!1,l=r(o);n.forEach(function(e){t(e,l)});var i=document.querySelector(e);if(null!==i)return i.firstChild&&i.removeChild(i.firstChild),i.appendChild(l)}function o(t){var n=document.createElement("li"),o=document.createElement("a");return e.listItemClass&&n.setAttribute("class",e.listItemClass),e.includeHtml&&t.childNodes.length?u.call(t.childNodes,function(e){o.appendChild(e.cloneNode(!0))}):o.textContent=t.textContent,o.setAttribute("data-scroll",""),o.setAttribute("href","#"+t.id),o.setAttribute("class",e.linkClass+h+"node-name--"+t.nodeName+h+e.extraLinkClasses),n.appendChild(o),n}function r(t){var n=document.createElement("ul"),o=e.listClass+h+e.extraListClasses;return t&&(o+=h+e.collapsibleClass,o+=h+e.isCollapsedClass),n.setAttribute("class",o),n}function l(){var t=document.documentElement.scrollTop||f.scrollTop,n=document.querySelector(e.positionFixedSelector);"auto"===e.fixedSidebarOffset&&(e.fixedSidebarOffset=document.querySelector(e.tocSelector).offsetTop),t>e.fixedSidebarOffset?n.className.indexOf(e.positionFixedClass)===-1&&(n.className+=h+e.positionFixedClass):n.className=n.className.split(h+e.positionFixedClass).join("")}function i(t){var n=document.documentElement.scrollTop||f.scrollTop;e.positionFixedSelector&&l();var o,r=t;if(m&&null!==document.querySelector(e.tocSelector)&&r.length>0){d.call(r,function(t,l){if(t.offsetTop>n+e.headingsOffset+1){var i=0===l?l:l-1;return o=r[i],!0}if(l===r.length-1)return o=r[r.length-1],!0});var i=document.querySelector(e.tocSelector).querySelectorAll("."+e.linkClass);u.call(i,function(t){t.className=t.className.split(h+e.activeLinkClass).join("")});var c=document.querySelector(e.tocSelector).querySelector("."+e.linkClass+".node-name--"+o.nodeName+'[href="#'+o.id+'"]');c.className+=h+e.activeLinkClass;var a=document.querySelector(e.tocSelector).querySelectorAll("."+e.listClass+"."+e.collapsibleClass);u.call(a,function(t){var n=h+e.isCollapsedClass;t.className.indexOf(n)===-1&&(t.className+=h+e.isCollapsedClass)}),c.nextSibling&&(c.nextSibling.className=c.nextSibling.className.split(h+e.isCollapsedClass).join("")),s(c.parentNode.parentNode)}}function s(t){return t.className.indexOf(e.collapsibleClass)!==-1?(t.className=t.className.split(h+e.isCollapsedClass).join(""),s(t.parentNode.parentNode)):t}function c(t){var n=t.target||t.srcElement;"string"==typeof n.className&&n.className.indexOf(e.linkClass)!==-1&&(m=!1)}function a(){m=!0}var u=[].forEach,d=[].some,f=document.body,m=!0,h=" ";return{enableTocAnimation:a,disableTocAnimation:c,render:n,updateToc:i}}},/*!*********************************!*\ !*** ./src/js/parse-content.js ***! \*********************************/ function(e,t){e.exports=function(e){function t(e){return e[e.length-1]}function n(e){return+e.nodeName.split("H").join("")}function o(t){var o={id:t.id,children:[],nodeName:t.nodeName,headingLevel:n(t),textContent:t.textContent.trim()};return e.includeHtml&&(o.childNodes=t.childNodes),o}function r(r,l){for(var i=o(r),s=n(r),c=l,a=t(c),u=a?a.headingLevel:0,d=s-u;d>0;)a=t(c),a&&void 0!==a.children&&(c=a.children),d--;return s>=e.collapseDepth&&(i.isCollapsed=!0),c.push(i),c}function l(t,n){var o=n;e.ignoreSelector&&(o=n.split(",").map(function(t){return t.trim()+":not("+e.ignoreSelector+")"}));try{return document.querySelector(t).querySelectorAll(o)}catch(e){return console.warn("Element not found: "+t),null}}function i(e){return s.call(e,function(e,t){var n=o(t);return r(n,e.nest),e},{nest:[]})}var s=[].reduce;return{nestHeadingsArray:i,selectHeadings:l}}}]); //# sourceMappingURL=tocbot.min.js.map