mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
3 lines
29 KiB
JavaScript
3 lines
29 KiB
JavaScript
"use strict";function _readOnlyError(a){throw new TypeError("\""+a+"\" is read-only")}function _objectDestructuringEmpty(a){if(null==a)throw new TypeError("Cannot destructure undefined")}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}var Util=function(){function a(){_classCallCheck(this,a)}return _createClass(a,[{key:"forEach",value:function forEach(a,b){a=a||[];for(var c=0;c<a.length;c++)b(a[c])}},{key:"getScrollTop",value:function getScrollTop(){return document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop}},{key:"isMobile",value:function isMobile(){return window.matchMedia("only screen and (max-width: 680px)").matches}},{key:"isTocStatic",value:function isTocStatic(){return window.matchMedia("only screen and (max-width: 960px)").matches}},{key:"animateCSS",value:function animateCSS(a,b,c,d){var e;Array.isArray(b)||(b=[b]),(e=a.classList).add.apply(e,["animate__animated"].concat(_toConsumableArray(b)));var f=function(){var c;(c=a.classList).remove.apply(c,["animate__animated"].concat(_toConsumableArray(b))),a.removeEventListener("animationend",f),"function"==typeof d&&d()};c||a.addEventListener("animationend",f,!1)}},{key:"isValidDate",value:function isValidDate(a){return a instanceof Date&&!isNaN(a.getTime())}}]),a}(),FixIt=function(){function a(){var b=this;_classCallCheck(this,a),_defineProperty(this,"getSiteTime",function(){var a=Math.floor,c=new Date,d=new Date(b.config.siteTime),e=document.querySelector(".run-times");if(!b.util.isValidDate(d)||!e)return clearInterval(b.siteTime),void(e&&e.parentNode.remove());var f=(c-d)/1e3,g=a(f/60/60/24),h=a(f/60/60-24*g),i=a(f/60-1440*g-60*h),j=a((c-d)/1e3-86400*g-3600*h-60*i);e.innerHTML="".concat(g,", ").concat((h+"").padStart(2,0),":").concat((i+"").padStart(2,0),":").concat((j+"").padStart(2,0))}),this.config=window.config,this.data=this.config.data,this.isDark="dark"===document.body.getAttribute("theme"),this.util=new Util,this.newScrollTop=this.util.getScrollTop(),this.oldScrollTop=this.newScrollTop,this.scrollEventSet=new Set,this.resizeEventSet=new Set,this.switchThemeEventSet=new Set,this.clickMaskEventSet=new Set,this.disableScrollEvent=!1,window.objectFitImages&&objectFitImages()}return _createClass(a,[{key:"initSVGIcon",value:function initSVGIcon(){this.util.forEach(document.querySelectorAll("[data-svg-src]"),function(a){fetch(a.getAttribute("data-svg-src")).then(function(a){return a.text()}).then(function(b){var c=document.createElement("div");c.insertAdjacentHTML("afterbegin",b);var d=c.firstChild;d.setAttribute("data-svg-src",a.getAttribute("data-svg-src")),d.classList.add("icon");var e=d.getElementsByTagName("title");e.length&&d.removeChild(e[0]),a.parentElement.replaceChild(d,a)}).catch(function(a){console.error(a)})})}},{key:"initTwemoji",value:function initTwemoji(){this.config.twemoji&&twemoji.parse(document.body)}},{key:"initMenu",value:function initMenu(){this.initMenuDesktop(),this.initMenuMobile()}},{key:"initMenuDesktop",value:function initMenuDesktop(){this.util.forEach(document.querySelectorAll("[has-children], #header-desktop .language"),function(a){a.addEventListener("mouseover",function(){this.querySelector(".sub-menu").style.left="".concat(this.getBoundingClientRect().left,"px")}),a.querySelector(".sub-menu").style.minWidth="".concat(a.offsetWidth-8,"px")})}},{key:"initMenuMobile",value:function initMenuMobile(){var a=this,b=document.getElementById("menu-toggle-mobile"),c=document.getElementById("menu-mobile");b.addEventListener("click",function(){document.body.classList.toggle("blur"),b.classList.toggle("active"),c.classList.toggle("active"),a.disableScrollEvent=document.body.classList.contains("blur")},!1),this._menuMobileOnClickMask=this._menuMobileOnClickMask||function(){b.classList.remove("active"),c.classList.remove("active")},this.clickMaskEventSet.add(this._menuMobileOnClickMask),this.util.forEach(document.querySelectorAll(".menu-item>.nested-item"),function(a){a.addEventListener("click",function(){this.parentNode.querySelector(".sub-menu").classList.toggle("open"),this.querySelector(".dropdown-icon").classList.toggle("open")})})}},{key:"initSwitchTheme",value:function initSwitchTheme(){var a=this;this.util.forEach(document.getElementsByClassName("theme-switch"),function(b){b.addEventListener("click",function(){document.body.setAttribute("theme","dark"===document.body.getAttribute("theme")?"light":"dark"),a.isDark=!a.isDark,window.localStorage&&localStorage.setItem("theme",a.isDark?"dark":"light");var b,c=_createForOfIteratorHelper(a.switchThemeEventSet);try{for(c.s();!(b=c.n()).done;){var d=b.value;d()}}catch(a){c.e(a)}finally{c.f()}},!1)})}},{key:"initSearch",value:function initSearch(){var a=this,b=this.config.search,c=this.util.isMobile();if(!(!b||c&&this._searchMobileOnce||!c&&this._searchDesktopOnce)){var d=b.maxResultLength||10,e=b.snippetLength||50,f=b.highlightTag||"em",g=c?"mobile":"desktop",h=document.getElementById("header-".concat(g)),i=document.getElementById("search-input-".concat(g)),j=document.getElementById("search-toggle-".concat(g)),k=document.getElementById("search-loading-".concat(g)),l=document.getElementById("search-clear-".concat(g));c?(this._searchMobileOnce=!0,i.addEventListener("focus",function(){a.disableScrollEvent=!0,document.body.classList.add("blur"),h.classList.add("open")},!1),document.getElementById("search-cancel-mobile").addEventListener("click",function(){a.disableScrollEvent=!1,h.classList.remove("open"),document.body.classList.remove("blur"),document.getElementById("menu-toggle-mobile").classList.remove("active"),document.getElementById("menu-mobile").classList.remove("active"),k.style.display="none",l.style.display="none",a._searchMobile&&a._searchMobile.autocomplete.setVal("")},!1),l.addEventListener("click",function(){l.style.display="none",a._searchMobile&&a._searchMobile.autocomplete.setVal("")},!1),this._searchMobileOnClickMask=this._searchMobileOnClickMask||function(){h.classList.remove("open"),k.style.display="none",l.style.display="none",a._searchMobile&&a._searchMobile.autocomplete.setVal("")},this.clickMaskEventSet.add(this._searchMobileOnClickMask)):(this._searchDesktopOnce=!0,j.addEventListener("click",function(){document.body.classList.add("blur"),h.classList.add("open"),i.focus()},!1),l.addEventListener("click",function(){l.style.display="none",a._searchDesktop&&a._searchDesktop.autocomplete.setVal("")},!1),this._searchDesktopOnClickMask=this._searchDesktopOnClickMask||function(){h.classList.remove("open"),k.style.display="none",l.style.display="none",a._searchDesktop&&a._searchDesktop.autocomplete.setVal("")},this.clickMaskEventSet.add(this._searchDesktopOnClickMask)),i.addEventListener("input",function(){l.style.display=""===i.value?"none":"inline"},!1);var m=function(){var h=autocomplete("#search-input-".concat(g),{hint:!1,autoselect:!0,dropdownMenuContainer:"#search-dropdown-".concat(g),clearOnSelected:!0,cssClasses:{noPrefix:!0},debug:!0},{name:"search",source:function source(c,g){k.style.display="inline",l.style.display="none";var h=function(a){k.style.display="none",l.style.display="inline",g(a)};if("lunr"===b.type){var i=function(){lunr.queryHandler&&(c=lunr.queryHandler(c));var b={};return a._index.search(c).forEach(function(c){var d=c.ref,g=c.matchData.metadata,h=a._indexData[d],i=h.uri,j=h.title,k=h.content;if(!b[i]){var l=0;Object.values(g).forEach(function(a){var b=a.content;if(b){var c=b.position[0][0];(c<l||0===l)&&(l=c)}}),l-=e/5,0<l?(l+=k.substr(l,20).lastIndexOf(" ")+1,k="..."+k.substr(l,e)):k=k.substr(0,e),Object.keys(g).forEach(function(a){j=j.replace(new RegExp("(".concat(a,")"),"gi"),"<".concat(f,">$1</").concat(f,">")),k=k.replace(new RegExp("(".concat(a,")"),"gi"),"<".concat(f,">$1</").concat(f,">"))}),b[i]={uri:i,title:j,date:h.date,context:k}}}),Object.values(b).slice(0,d)};a._index?h(i()):fetch(b.lunrIndexURL).then(function(a){return a.json()}).then(function(c){var d={};a._index=lunr(function(){var a=this;b.lunrLanguageCode&&this.use(lunr[b.lunrLanguageCode]),this.ref("objectID"),this.field("title",{boost:50}),this.field("tags",{boost:20}),this.field("categories",{boost:20}),this.field("content",{boost:10}),this.metadataWhitelist=["position"],c.forEach(function(b){d[b.objectID]=b,a.add(b)})}),a._indexData=d,h(i())}).catch(function(a){console.error(a),h([])})}else"algolia"===b.type&&(a._algoliaIndex=a._algoliaIndex||algoliasearch(b.algoliaAppID,b.algoliaSearchKey).initIndex(b.algoliaIndex),a._algoliaIndex.search(c,{offset:0,length:8*d,attributesToHighlight:["title"],attributesToSnippet:["content:".concat(e)],highlightPreTag:"<".concat(f,">"),highlightPostTag:"</".concat(f,">")}).then(function(a){var b=a.hits,c={};b.forEach(function(a){var b=a.uri,d=a.date,e=a._highlightResult.title,f=a._snippetResult.content;c[b]&&c[b].context.length>f.value||(c[b]={uri:b,title:e.value,date:d,context:f.value})}),h(Object.values(c).slice(0,d))}).catch(function(a){console.error(a),h([])}))},templates:{suggestion:function suggestion(a){var b=a.title,c=a.date,d=a.context;return"<div><span class=\"suggestion-title\">".concat(b,"</span><span class=\"suggestion-date\">").concat(c,"</span></div><div class=\"suggestion-context\">").concat(d,"</div>")},empty:function empty(a){var c=a.query;return"<div class=\"search-empty\">".concat(b.noResultsFound,": <span class=\"search-query\">\"").concat(c,"\"</span></div>")},footer:function footer(a){_objectDestructuringEmpty(a);var c="algolia"===b.type?{searchType:"algolia",icon:"<i class=\"fa-brands fa-algolia fa-fw\"></i>",href:"https://www.algolia.com/"}:{searchType:"Lunr.js",icon:"",href:"https://lunrjs.com/"},d=c.searchType,e=c.icon,f=c.href;return"<div class=\"search-footer\">Search by <a href=\"".concat(f,"\" rel=\"noopener noreffer\" target=\"_blank\">").concat(e," ").concat(d,"</a></div>")}}});h.on("autocomplete:selected",function(a,b){window.location.assign(b.uri)}),c?a._searchMobile=h:a._searchDesktop=h};if(b.lunrSegmentitURL&&!document.getElementById("lunr-segmentit")){var n=document.createElement("script");n.id="lunr-segmentit",n.type="text/javascript",n.src=b.lunrSegmentitURL,n.async=!0,n.readyState?n.onreadystatechange=function(){("loaded"==n.readyState||"complete"==n.readyState)&&(n.onreadystatechange=null,m())}:n.onload=function(){m()},document.body.appendChild(n)}else m()}}},{key:"initDetails",value:function initDetails(){this.util.forEach(document.getElementsByClassName("details"),function(a){var b=a.querySelector(".details-summary");b.addEventListener("click",function(){a.classList.toggle("open")},!1)})}},{key:"initLightGallery",value:function initLightGallery(){this.config.lightGallery&&lightGallery(document.getElementById("content"),this.config.lightGallery)}},{key:"initHighlight",value:function initHighlight(){var a=this;this.util.forEach(document.querySelectorAll(".highlight > pre.chroma"),function(a){var b=document.createElement("div");b.className=a.className;var c=document.createElement("table");b.appendChild(c);var d=document.createElement("tbody");c.appendChild(d);var e=document.createElement("tr");d.appendChild(e);var f=document.createElement("td");e.appendChild(f),a.parentElement.replaceChild(b,a),f.appendChild(a)}),this.util.forEach(document.querySelectorAll(".highlight > .chroma"),function(b){var c=b.querySelectorAll("pre.chroma > code");if(c.length){var d=c[c.length-1],e=document.createElement("div");e.className="code-header "+d.className.toLowerCase();var f=document.createElement("span");f.classList.add("code-title"),f.insertAdjacentHTML("afterbegin","<i class=\"arrow fa-solid fa-chevron-right fa-fw\"></i>"),f.addEventListener("click",function(){b.classList.toggle("open")},!1),e.appendChild(f);var g=document.createElement("span");if(g.insertAdjacentHTML("afterbegin","<i class=\"fa-solid fa-ellipsis-h fa-fw\"></i>"),g.classList.add("ellipses"),g.addEventListener("click",function(){b.classList.add("open")},!1),e.appendChild(g),a.config.code.editable){var h=document.createElement("span");h.classList.add("edit"),h.insertAdjacentHTML("afterbegin","<i class=\"fa-solid fa-key fa-fw\" title=\"".concat(a.config.code.editUnLockTitle,"\"></i>")),h.addEventListener("click",function(){var b=h.querySelector(".fa-key"),c=h.querySelector(".fa-lock"),d=h.parentElement.parentElement.querySelectorAll("pre.chroma"),e=2===d.length?d[1]:d[0];b?(b.classList.add("fa-lock"),b.classList.remove("fa-key"),b.title=a.config.code.editLockTitle,e.setAttribute("contenteditable",!0),e.focus()):(c.classList.add("fa-key"),c.classList.remove("fa-lock"),c.title=a.config.code.editUnLockTitle,e.setAttribute("contenteditable",!1),e.blur())},!1),e.appendChild(h)}if(a.config.code.copyTitle){var i=document.createElement("span");i.insertAdjacentHTML("afterbegin","<i class=\"fa-regular fa-copy fa-fw\"></i>"),i.classList.add("copy");var j=d.innerText;(0>a.config.code.maxShownLines||j.split("\n").length<a.config.code.maxShownLines+2)&&b.classList.add("open"),i.title=a.config.code.copyTitle,i.addEventListener("click",function(){navigator.clipboard.writeText(j).then(function(){a.util.animateCSS(d,"animate__flash")},function(){console.error("Clipboard write failed!","Your browser does not support clipboard API!")})},!1),e.appendChild(i)}b.insertBefore(e,b.firstChild)}})}},{key:"initTable",value:function initTable(){this.util.forEach(document.querySelectorAll(".content table"),function(a){var b=document.createElement("div");b.className="table-wrapper",a.parentElement.replaceChild(b,a),b.appendChild(a)})}},{key:"initHeaderLink",value:function initHeaderLink(){for(var a=1;6>=a;a++)this.util.forEach(document.querySelectorAll(".single .content > h"+a),function(a){a.classList.add("header-link"),a.insertAdjacentHTML("afterbegin","<a href=\"#".concat(a.id,"\" class=\"header-mark\"></a>"))})}},{key:"initToc",value:function initToc(){var a=this,b=document.getElementById("TableOfContents");if(null!==b)if("true"===document.getElementById("toc-static").getAttribute("kept")||this.util.isTocStatic()){var h=document.getElementById("toc-content-static");b.parentElement!==h&&(b.parentElement.removeChild(b),h.appendChild(b)),this._tocOnScroll&&this.scrollEventSet.delete(this._tocOnScroll)}else{var i=document.getElementById("toc-content-auto");b.parentElement!==i&&(b.parentElement.removeChild(b),i.appendChild(b));var j=document.getElementById("toc-auto");j.style.visibility="visible",this.util.animateCSS(j,["animate__fadeIn","animate__faster"],!0),j.style.marginTop=document.querySelector(".single-title").clientHeight+document.querySelector(".post-meta").clientHeight+"px",j.style.marginBottom=document.getElementById("post-footer").clientHeight+"px";var c=b.querySelectorAll("a:first-child"),d=b.getElementsByTagName("li"),e=document.getElementsByClassName("header-link"),f="normal"!==document.body.getAttribute("header-desktop"),g=document.getElementById("header-desktop").offsetHeight;this._tocOnScroll=this._tocOnScroll||function(){var h=document.getElementById("comments");h&&(j.style.marginBottom=document.getElementById("post-footer").clientHeight+h.clientHeight+"px"),a.util.forEach(c,function(a){a.classList.remove("active")}),a.util.forEach(d,function(a){a.classList.remove("has-active")});for(var k=20+(f?g:0),l=e.length-1,m=0;m<e.length-1;m++){var n=e[m].getBoundingClientRect().top,o=e[m+1].getBoundingClientRect().top;if(0==m&&n>k||n<=k&&o>k){l=m;break}}if(-1!==l){c[l].classList.add("active");for(var p=c[l].parentElement;p!==b;)p.classList.add("has-active"),p=p.parentElement.parentElement}},this._tocOnScroll(),this.scrollEventSet.add(this._tocOnScroll)}}},{key:"initTocListener",value:function initTocListener(){var a,b=this,c=document.getElementById("toc-auto"),d=document.getElementById("toc-content-auto");null===(a=document.querySelector("#toc-auto>.toc-title"))||void 0===a?void 0:a.addEventListener("click",function(){var a=["animate__faster"],e=c.classList.contains("toc-hidden");a.push(e?"animate__fadeIn":"animate__fadeOut"),d.classList.remove(e?"animate__fadeOut":"animate__fadeIn"),b.util.animateCSS(d,a,!0),c.classList.toggle("toc-hidden")},!1)}},{key:"initMath",value:function initMath(){this.config.math&&renderMathInElement(document.body,this.config.math)}},{key:"initMermaid",value:function initMermaid(){var a=this,b=document.getElementsByClassName("mermaid");b.length&&(mermaid.initialize({startOnLoad:!1,theme:"default"}),this.util.forEach(b,function(b){mermaid.mermaidAPI.render("svg-"+b.id,a.data[b.id],function(a){b.insertAdjacentHTML("afterbegin",a)},b)}))}},{key:"initEcharts",value:function initEcharts(){var a=this;this._echartsOnSwitchTheme=this._echartsOnSwitchTheme||function(){a._echartsArr=a._echartsArr||[];for(var b=0;b<a._echartsArr.length;b++)a._echartsArr[b].dispose();a._echartsArr=[],a.util.forEach(document.getElementsByClassName("echarts"),function(b){var c=echarts.init(b,a.isDark?"dark":"macarons",{renderer:"svg"});c.setOption(JSON.parse(a.data[b.id])),a._echartsArr.push(c)})},this.switchThemeEventSet.add(this._echartsOnSwitchTheme),this._echartsOnSwitchTheme(),this._echartsOnResize=this._echartsOnResize||function(){for(var b=0;b<a._echartsArr.length;b++)a._echartsArr[b].resize()},this.resizeEventSet.add(this._echartsOnResize)}},{key:"initMapbox",value:function initMapbox(){var a=this;this.config.mapbox&&(mapboxgl.accessToken=this.config.mapbox.accessToken,mapboxgl.setRTLTextPlugin(this.config.mapbox.RTLTextPlugin),this._mapboxArr=this._mapboxArr||[],this.util.forEach(document.getElementsByClassName("mapbox"),function(b){var c=a.data[b.id],d=c.lng,e=c.lat,f=c.zoom,g=c.lightStyle,h=c.darkStyle,i=c.marked,j=c.navigation,k=c.geolocate,l=c.scale,m=c.fullscreen,n=new mapboxgl.Map({container:b,center:[d,e],zoom:f,minZoom:.2,style:a.isDark?h:g,attributionControl:!1});i&&new mapboxgl.Marker().setLngLat([d,e]).addTo(n),j&&n.addControl(new mapboxgl.NavigationControl,"bottom-right"),k&&n.addControl(new mapboxgl.GeolocateControl({positionOptions:{enableHighAccuracy:!0},showUserLocation:!0,trackUserLocation:!0}),"bottom-right"),l&&n.addControl(new mapboxgl.ScaleControl),m&&n.addControl(new mapboxgl.FullscreenControl),n.addControl(new MapboxLanguage),a._mapboxArr.push(n)}),this._mapboxOnSwitchTheme=this._mapboxOnSwitchTheme||function(){a.util.forEach(a._mapboxArr,function(b){var c=b.getContainer(),d=a.data[c.id],e=d.lightStyle,f=d.darkStyle;b.setStyle(a.isDark?f:e),b.addControl(new MapboxLanguage)})},this.switchThemeEventSet.add(this._mapboxOnSwitchTheme))}},{key:"initTypeit",value:function initTypeit(){var a=this;if(this.config.typeit){var b=this.config.typeit,c=b.speed||100,d=b.cursorSpeed||1e3,e=b.cursorChar||"|";Object.values(b.data).forEach(function(f){var g=function(h){var i=f[h],j=new TypeIt("#".concat(i),{strings:a.data[i],speed:c,lifeLike:!0,cursorSpeed:d,cursorChar:e,waitUntilVisible:!0,afterComplete:function afterComplete(){return h===f.length-1&&0<=b.duration?void window.setTimeout(function(){j.destroy()},b.duration):void(j.destroy(),g(h+1))}}).go()};g(0)})}}},{key:"initCommentLightGallery",value:function initCommentLightGallery(a,b){this.config.lightGallery&&document.querySelectorAll(a).forEach(function(a){var c=a.querySelectorAll(b+":not([lightgallery-loaded])");c.forEach(function(a){a.setAttribute("lightgallery-loaded","");var b=document.createElement("a");b.setAttribute("class","comment-lightgallery"),b.setAttribute("href",a.src),b.append(a.cloneNode()),a.replaceWith(b)}),c.length&&lightGallery(a,{selector:".comment-lightgallery",actualSize:!1,hideBarsDelay:2e3,speed:400})})}},{key:"initComment",value:function initComment(){var a=this;if(this.config.comment){if(this.config.comment.artalk){var d=new Artalk(this.config.comment.artalk);return d.setDarkMode(this.isDark),this.switchThemeEventSet.add(function(){d.setDarkMode(a.isDark)}),d.on("comments-loaded",function(){a.config.comment.artalk.lightgallery&&a.initCommentLightGallery(".atk-comment .atk-content","img:not([atk-emoticon])")}),d}if(this.config.comment.gitalk){this.config.comment.gitalk.body=decodeURI(window.location.href);var e=new Gitalk(this.config.comment.gitalk);return e.render("gitalk"),e}if(this.config.comment.valine)return new Valine(this.config.comment.valine);if(this.config.comment.waline)return Waline.init(this.config.comment.waline);if(this.config.comment.utterances){var b=this.config.comment.utterances,c=document.createElement("script");return c.src="https://utteranc.es/client.js",c.type="text/javascript",c.setAttribute("repo",b.repo),c.setAttribute("issue-term",b.issueTerm),b.label&&c.setAttribute("label",b.label),c.setAttribute("theme",this.isDark?b.darkTheme:b.lightTheme),c.crossOrigin="anonymous",c.async=!0,document.getElementById("utterances").appendChild(c),this._utterancesOnSwitchTheme=this._utterancesOnSwitchTheme||function(){var c,d={type:"set-theme",theme:a.isDark?b.darkTheme:b.lightTheme};null===(c=document.querySelector(".utterances-frame"))||void 0===c?void 0:c.contentWindow.postMessage(d,"https://utteranc.es")},void this.switchThemeEventSet.add(this._utterancesOnSwitchTheme)}if(this.config.comment.twikoo){var f=this.config.comment.twikoo;return f.lightgallery&&(f.onCommentLoaded=function(){a.initCommentLightGallery(".tk-comments .tk-content","img:not(.tk-owo-emotion)")}),twikoo.init(f),void(f.commentCount&&twikoo.getCommentsCount({envId:f.envId,region:f.region,urls:[window.location.pathname],includeReply:!1}).then(function(a){var b=document.getElementById("twikoo-comment-count");b&&(b.innerHTML=a[0].count)}))}if(this.config.comment.giscus){var g=this.config.comment.giscus;this._giscusOnSwitchTheme=this._giscusOnSwitchTheme||function(){var b,c={setConfig:{theme:a.isDark?g.darkTheme:g.lightTheme}};null===(b=document.querySelector(".giscus-frame"))||void 0===b?void 0:b.contentWindow.postMessage({giscus:c},"https://giscus.app")},this.switchThemeEventSet.add(this._giscusOnSwitchTheme);var h=this;return void(h.giscus2parentMsg=window.addEventListener("message",function(){var a=document.querySelector("#giscus>script");a&&(h._giscusOnSwitchTheme(),a.parentElement.removeChild(a)),window.removeEventListener("message",h.giscus2parentMsg)}))}}}},{key:"initCookieconsent",value:function initCookieconsent(){this.config.cookieconsent&&cookieconsent.initialise(this.config.cookieconsent)}},{key:"initSiteTime",value:function initSiteTime(){var a=this;this.config.siteTime&&(this.siteTime=setInterval(this.getSiteTime,500),document.addEventListener("visibilitychange",function(){return document.hidden?clearInterval(a.siteTime):void(a.siteTime=setInterval(a.getSiteTime,500))},!1))}},{key:"initServiceWorker",value:function initServiceWorker(){this.config.enablePWA&&"serviceWorker"in navigator&&(navigator.serviceWorker.register("/service-worker.min.js",{scope:"/"}).then(function(){}).catch(function(a){console.error("error: ",a)}),navigator.serviceWorker.ready.then(function(){}))}},{key:"initWatermark",value:function initWatermark(){var a;(null===(a=this.config.watermark)||void 0===a?void 0:a.enable)&&new Watermark({content:this.config.watermark.content||"<img class=\"fixit-icon\" src=\"/images/fixit.svg\" alt=\"FixIt logo\" /> FixIt Theme",appendTo:this.config.watermark.appendto||".wrapper>main",opacity:this.config.watermark.opacity,width:this.config.watermark.width,height:this.config.watermark.height,rowSpacing:this.config.watermark.rowspacing,colSpacing:this.config.watermark.colspacing,rotate:this.config.watermark.rotate,fontSize:this.config.watermark.fontsize,fontFamily:this.config.watermark.fontfamily})}},{key:"initPangu",value:function initPangu(){this.config.enablePangu&&pangu.autoSpacingPage()}},{key:"initFixItDecryptor",value:function initFixItDecryptor(){var a,b,c=this,d=document.querySelectorAll("#toc-auto>.d-none, #toc-static.d-none");this.decryptor=new FixItDecryptor({decrypted:function decrypted(){c.initTwemoji(),c.initDetails(),c.initLightGallery(),c.initHighlight(),c.initTable(),c.initHeaderLink(),c.initMath(),c.initMermaid(),c.initEcharts(),c.initTypeit(),c.initMapbox(),c.util.forEach(d,function(a){a.classList.remove("d-none")}),c.initToc(),c.initTocListener(),c.initPangu()},reset:function reset(){c.util.forEach(d,function(a){a.classList.add("d-none")})}}),null!==(a=this.config.encryption)&&void 0!==a&&a.shortcode&&(this.decryptor.addEventListener("decrypted",function(){c.decryptor.initShortcodes()}),this.decryptor.initShortcodes()),(null===(b=this.config.encryption)||void 0===b?void 0:b.all)&&this.decryptor.init()}},{key:"onScroll",value:function onScroll(){var a=this,b=[];if("auto"===document.body.getAttribute("header-desktop")&&b.push(document.getElementById("header-desktop")),"auto"===document.body.getAttribute("header-mobile")&&b.push(document.getElementById("header-mobile")),document.getElementById("comments")){var e=document.getElementById("view-comments");e.href="#comments",e.style.display="block"}var c=document.getElementById("fixed-buttons"),d=20;window.addEventListener("scroll",function(e){if(a.disableScrollEvent)return void e.preventDefault();var f=document.getElementById("mask");a.newScrollTop=a.util.getScrollTop();var g=a.newScrollTop-a.oldScrollTop,h=a.util.isMobile();a.util.forEach(b,function(b){g>d?(b.classList.remove("animate__fadeInDown"),a.util.animateCSS(b,["animate__fadeOutUp","animate__faster"],!0),f.click()):g<-d&&(b.classList.remove("animate__fadeOutUp"),a.util.animateCSS(b,["animate__fadeInDown","animate__faster"],!0),f.click())}),a.newScrollTop>100?h&&g>d?(c.classList.remove("animate__fadeIn"),a.util.animateCSS(c,["animate__fadeOut","animate__faster"],!0)):(!h||g<-d)&&(c.style.display="block",c.classList.remove("animate__fadeOut"),a.util.animateCSS(c,["animate__fadeIn","animate__faster"],!0)):(!h&&(c.classList.remove("animate__fadeIn"),a.util.animateCSS(c,["animate__fadeOut","animate__faster"],!0)),c.style.display="none");var i,j=_createForOfIteratorHelper(a.scrollEventSet);try{for(j.s();!(i=j.n()).done;){var k=i.value;k()}}catch(a){j.e(a)}finally{j.f()}a.oldScrollTop=a.newScrollTop},!1)}},{key:"onResize",value:function onResize(){var a=this,b=this.util.isMobile();window.addEventListener("resize",function(){a._resizeTimeout||(a._resizeTimeout=window.setTimeout(function(){a._resizeTimeout=null;var c,d=_createForOfIteratorHelper(a.resizeEventSet);try{for(d.s();!(c=d.n()).done;){var f=c.value;f()}}catch(a){d.e(a)}finally{d.f()}a.initToc(),a.initMermaid(),a.initSearch();var e=a.util.isMobile();e!==b&&(document.getElementById("mask").click(),e,_readOnlyError("resizeBefore"))},100))},!1)}},{key:"onClickMask",value:function onClickMask(){var a=this;document.getElementById("mask").addEventListener("click",function(){if(document.body.classList.contains("blur")){var b,c=_createForOfIteratorHelper(a.clickMaskEventSet);try{for(c.s();!(b=c.n()).done;){var d=b.value;d()}}catch(a){c.e(a)}finally{c.f()}a.disableScrollEvent=!1,document.body.classList.remove("blur")}},!1)}},{key:"init",value:function init(){var a=this;try{var b;this.config.encryption?this.initFixItDecryptor():!(null!==(b=this.config.encryption)&&void 0!==b&&b.all)&&(this.initTwemoji(),this.initDetails(),this.initLightGallery(),this.initHighlight(),this.initTable(),this.initHeaderLink(),this.initMath(),this.initMermaid(),this.initEcharts(),this.initTypeit(),this.initMapbox(),this.initPangu()),this.initSVGIcon(),this.initMenu(),this.initSwitchTheme(),this.initSearch(),this.initCookieconsent(),this.initSiteTime(),this.initServiceWorker(),this.initWatermark(),window.setTimeout(function(){var b;a.initComment(),null!==(b=a.config.encryption)&&void 0!==b&&b.all||(a.initToc(),a.initTocListener()),a.onScroll(),a.onResize(),a.onClickMask()},100)}catch(a){console.error(a)}}}]),a}(),themeInit=function(){window.fixit=new FixIt,window.fixit.init()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",themeInit,!1):themeInit();
|
|
|
|
//# sourceMappingURL=theme.min.js.map
|