mirror of
https://github.com/hugo-fixit/FixIt.git
synced 2026-08-24 15:28:57 +00:00
3 lines
41 KiB
JavaScript
3 lines
41 KiB
JavaScript
"use strict";function _objectDestructuringEmpty(obj){if(obj==null)throw new TypeError("Cannot destructure undefined")}function _createForOfIteratorHelper(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e){throw _e},f:F}}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 normalCompletion=true,didErr=false,err;return{s:function s(){it=it.call(o)},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e2){didErr=true;err=_e2},f:function f(){try{if(!normalCompletion&&it.return!=null)it.return()}finally{if(didErr)throw err}}}}function _defineProperty(obj,key,value){if(key in obj){Object.defineProperty(obj,key,{value:value,enumerable:true,configurable:true,writable:true})}else{obj[key]=value}return obj}function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_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(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _iterableToArray(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter)}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++){arr2[i]=arr[i]}return arr2}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);Object.defineProperty(Constructor,"prototype",{writable:false});return Constructor}var Util=function(){function Util(){_classCallCheck(this,Util)}_createClass(Util,[{key:"forEach",value:function forEach(elements,handler){elements=elements||[];for(var i=0;i<elements.length;i++){handler(elements[i])}}},{key:"getScrollTop",value:function getScrollTop(){var _document$documentEle;return((_document$documentEle=document.documentElement)!==null&&_document$documentEle!==void 0?_document$documentEle: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(element,animation,reserved,callback){var _element$classList;!Array.isArray(animation)&&(animation=[animation]);(_element$classList=element.classList).add.apply(_element$classList,["animate__animated"].concat(_toConsumableArray(animation)));element.addEventListener("animationend",function(){var _element$classList2;!reserved&&(_element$classList2=element.classList).remove.apply(_element$classList2,["animate__animated"].concat(_toConsumableArray(animation)));typeof callback==="function"&&callback()},{once:true})}},{key:"isValidDate",value:function isValidDate(date){return date instanceof Date&&!isNaN(date.getTime())}},{key:"scrollIntoView",value:function scrollIntoView(selector){var element=selector.startsWith("#")?document.getElementById(selector.slice(1)):document.querySelector(selector);element===null||element===void 0?void 0:element.scrollIntoView({behavior:"smooth"})}}]);return Util}();var FixIt=function(){function FixIt(){var _this2=this;_classCallCheck(this,FixIt);_defineProperty(this,"getSiteTime",function(){var now=new Date;var run=new Date(_this2.config.siteTime);var $runTimes=document.querySelector(".run-times");if(!_this2.util.isValidDate(run)||!$runTimes){clearInterval(_this2.siteTime);$runTimes&&$runTimes.parentNode.remove();return}var runTime=(now-run)/1000,days=Math.floor(runTime/60/60/24),hours=Math.floor(runTime/60/60-24*days),minutes=Math.floor(runTime/60-24*60*days-60*hours),seconds=Math.floor((now-run)/1000-24*60*60*days-60*60*hours-60*minutes);$runTimes.innerHTML="".concat(days,", ").concat(String(hours).padStart(2,0),":").concat(String(minutes).padStart(2,0),":").concat(String(seconds).padStart(2,0))});this.config=window.config;this.data=this.config.data;this.isDark=document.body.dataset.theme==="dark";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=false;window.objectFitImages&&objectFitImages()}_createClass(FixIt,[{key:"initThemeColor",value:function initThemeColor(){var _this3=this;var $meta=document.querySelector("[name=\"theme-color\"]");if(!$meta){return}this._themeColorOnSwitchTheme=this._themeColorOnSwitchTheme||function(){$meta.content=_this3.isDark?$meta.dataset.dark:$meta.dataset.light};this.switchThemeEventSet.add(this._themeColorOnSwitchTheme);this._themeColorOnSwitchTheme()}},{key:"initSVGIcon",value:function initSVGIcon(){this.util.forEach(document.querySelectorAll("[data-svg-src]"),function($icon){fetch($icon.getAttribute("data-svg-src")).then(function(response){return response.text()}).then(function(svg){var $temp=document.createElement("div");$temp.insertAdjacentHTML("afterbegin",svg);var $svg=$temp.firstChild;$svg.setAttribute("data-svg-src",$icon.getAttribute("data-svg-src"));$svg.classList.add("icon");var $titleElements=$svg.getElementsByTagName("title");$titleElements.length&&$svg.removeChild($titleElements[0]);$icon.parentElement.replaceChild($svg,$icon)}).catch(function(err){console.error(err)})})}},{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($item){$item.addEventListener("mouseover",function(){this.querySelector(".sub-menu").style.left="".concat(this.getBoundingClientRect().left,"px")});$item.querySelector(".sub-menu").style.minWidth="".concat($item.offsetWidth-8,"px")})}},{key:"initMenuMobile",value:function initMenuMobile(){var _this4=this;var $menuToggleMobile=document.getElementById("menu-toggle-mobile");var $menuMobile=document.getElementById("menu-mobile");$menuToggleMobile.addEventListener("click",function(event){document.body.classList.toggle("blur");$menuToggleMobile.classList.toggle("active");$menuMobile.classList.toggle("active");_this4.disableScrollEvent=document.body.classList.contains("blur")},false);this._menuMobileOnClickMask=this._menuMobileOnClickMask||function(){$menuToggleMobile.classList.remove("active");$menuMobile.classList.remove("active")};this.clickMaskEventSet.add(this._menuMobileOnClickMask);this.util.forEach(document.querySelectorAll(".menu-item>.nested-item"),function($nestedItem){$nestedItem.addEventListener("click",function(){this.parentNode.querySelector(".sub-menu").classList.toggle("open");this.querySelector(".dropdown-icon").classList.toggle("open")})})}},{key:"initSwitchTheme",value:function initSwitchTheme(){var _this5=this;this.util.forEach(document.getElementsByClassName("theme-switch"),function($themeSwitch){$themeSwitch.addEventListener("click",function(){var _window$localStorage;document.body.dataset.theme=document.body.dataset.theme==="dark"?"light":"dark";_this5.isDark=!_this5.isDark;(_window$localStorage=window.localStorage)===null||_window$localStorage===void 0?void 0:_window$localStorage.setItem("theme",_this5.isDark?"dark":"light");var _iterator=_createForOfIteratorHelper(_this5.switchThemeEventSet),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var event=_step.value;event()}}catch(err){_iterator.e(err)}finally{_iterator.f()}},false)})}},{key:"initSearch",value:function initSearch(){var _this6=this;var searchConfig=this.config.search;var isMobile=this.util.isMobile();if(!searchConfig||isMobile&&this._searchMobileOnce||!isMobile&&this._searchDesktopOnce){return}var maxResultLength=searchConfig.maxResultLength||10;var snippetLength=searchConfig.snippetLength||50;var highlightTag=searchConfig.highlightTag||"em";var suffix=isMobile?"mobile":"desktop";var $header=document.getElementById("header-".concat(suffix));var $searchInput=document.getElementById("search-input-".concat(suffix));var $searchToggle=document.getElementById("search-toggle-".concat(suffix));var $searchLoading=document.getElementById("search-loading-".concat(suffix));var $searchClear=document.getElementById("search-clear-".concat(suffix));if(isMobile){this._searchMobileOnce=true;$searchInput.addEventListener("focus",function(){_this6.disableScrollEvent=true;document.body.classList.add("blur");$header.classList.add("open")},false);document.getElementById("search-cancel-mobile").addEventListener("click",function(){_this6.disableScrollEvent=false;$header.classList.remove("open");document.body.classList.remove("blur");document.getElementById("menu-toggle-mobile").classList.remove("active");document.getElementById("menu-mobile").classList.remove("active");$searchLoading.style.display="none";$searchClear.style.display="none";_this6._searchMobile&&_this6._searchMobile.autocomplete.setVal("")},false);$searchClear.addEventListener("click",function(){$searchClear.style.display="none";_this6._searchMobile&&_this6._searchMobile.autocomplete.setVal("")},false);this._searchMobileOnClickMask=this._searchMobileOnClickMask||function(){$header.classList.remove("open");$searchLoading.style.display="none";$searchClear.style.display="none";_this6._searchMobile&&_this6._searchMobile.autocomplete.setVal("")};this.clickMaskEventSet.add(this._searchMobileOnClickMask)}else{this._searchDesktopOnce=true;$searchToggle.addEventListener("click",function(){document.body.classList.add("blur");$header.classList.add("open");$searchInput.focus()},false);$searchClear.addEventListener("click",function(){$searchClear.style.display="none";_this6._searchDesktop&&_this6._searchDesktop.autocomplete.setVal("")},false);this._searchDesktopOnClickMask=this._searchDesktopOnClickMask||function(){$header.classList.remove("open");$searchLoading.style.display="none";$searchClear.style.display="none";_this6._searchDesktop&&_this6._searchDesktop.autocomplete.setVal("")};this.clickMaskEventSet.add(this._searchDesktopOnClickMask)}$searchInput.addEventListener("input",function(){if($searchInput.value==="")$searchClear.style.display="none";else $searchClear.style.display="inline"},false);var initAutosearch=function initAutosearch(){var autosearch=autocomplete("#search-input-".concat(suffix),{hint:false,autoselect:true,dropdownMenuContainer:"#search-dropdown-".concat(suffix),clearOnSelected:true,cssClasses:{noPrefix:true},debug:true},{name:"search",source:function source(query,callback){$searchLoading.style.display="inline";$searchClear.style.display="none";var finish=function finish(results){$searchLoading.style.display="none";$searchClear.style.display="inline";callback(results)};if(searchConfig.type==="lunr"){var search=function search(){if(lunr.queryHandler){query=lunr.queryHandler(query)}var results={};_this6._index.search(query).forEach(function(_ref){var ref=_ref.ref,metadata=_ref.matchData.metadata;var matchData=_this6._indexData[ref];var uri=matchData.uri,title=matchData.title,context=matchData.content;if(results[uri]){return}var position=0;Object.values(metadata).forEach(function(_ref2){var content=_ref2.content;if(content){var matchPosition=content.position[0][0];if(matchPosition<position||position===0){position=matchPosition}}});position-=snippetLength/5;if(position>0){position+=context.substr(position,20).lastIndexOf(" ")+1;context="..."+context.substr(position,snippetLength)}else{context=context.substr(0,snippetLength)}Object.keys(metadata).forEach(function(key){title=title.replace(new RegExp("(".concat(key,")"),"gi"),"<".concat(highlightTag,">$1</").concat(highlightTag,">"));context=context.replace(new RegExp("(".concat(key,")"),"gi"),"<".concat(highlightTag,">$1</").concat(highlightTag,">"))});results[uri]={uri:uri,title:title,date:matchData.date,context:context}});return Object.values(results).slice(0,maxResultLength)};if(!_this6._index){fetch(searchConfig.lunrIndexURL).then(function(response){return response.json()}).then(function(data){var indexData={};_this6._index=lunr(function(){var _this7=this;if(searchConfig.lunrLanguageCode)this.use(lunr[searchConfig.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"];data.forEach(function(record){indexData[record.objectID]=record;_this7.add(record)})});_this6._indexData=indexData;finish(search())}).catch(function(err){console.error(err);finish([])})}else finish(search())}else if(searchConfig.type==="algolia"){_this6._algoliaIndex=_this6._algoliaIndex||algoliasearch(searchConfig.algoliaAppID,searchConfig.algoliaSearchKey).initIndex(searchConfig.algoliaIndex);_this6._algoliaIndex.search(query,{offset:0,length:maxResultLength*8,attributesToHighlight:["title"],attributesToSnippet:["content:".concat(snippetLength)],highlightPreTag:"<".concat(highlightTag,">"),highlightPostTag:"</".concat(highlightTag,">")}).then(function(_ref3){var hits=_ref3.hits;var results={};hits.forEach(function(_ref4){var uri=_ref4.uri,date=_ref4.date,title=_ref4._highlightResult.title,content=_ref4._snippetResult.content;if(results[uri]&&results[uri].context.length>content.value){return}results[uri]={uri:uri,title:title.value,date:date,context:content.value}});finish(Object.values(results).slice(0,maxResultLength))}).catch(function(err){console.error(err);finish([])})}},templates:{suggestion:function suggestion(_ref5){var title=_ref5.title,date=_ref5.date,context=_ref5.context;return"<div><span class=\"suggestion-title\">".concat(title,"</span><span class=\"suggestion-date\">").concat(date,"</span></div><div class=\"suggestion-context\">").concat(context,"</div>")},empty:function empty(_ref6){var query=_ref6.query;return"<div class=\"search-empty\">".concat(searchConfig.noResultsFound,": <span class=\"search-query\">\"").concat(query,"\"</span></div>")},footer:function footer(_ref7){_objectDestructuringEmpty(_ref7);var _ref8=searchConfig.type==="algolia"?{searchType:"algolia",icon:"<i class=\"fa-brands fa-algolia fa-fw\" aria-hidden=\"true\"></i>",href:"https://www.algolia.com/"}:{searchType:"Lunr.js",icon:"",href:"https://lunrjs.com/"},searchType=_ref8.searchType,icon=_ref8.icon,href=_ref8.href;return"<div class=\"search-footer\">Search by <a href=\"".concat(href,"\" rel=\"noopener noreferrer\" target=\"_blank\">").concat(icon," ").concat(searchType,"</a></div>")}}});autosearch.on("autocomplete:selected",function(_event,suggestion,_dataset,_context){window.location.assign(suggestion.uri)});if(isMobile){_this6._searchMobile=autosearch}else{_this6._searchDesktop=autosearch}};if(searchConfig.lunrSegmentitURL&&!document.getElementById("lunr-segmentit")){var script=document.createElement("script");script.id="lunr-segmentit";script.src=searchConfig.lunrSegmentitURL;script.async=true;if(script.readyState){script.onreadystatechange=function(){if(script.readyState=="loaded"||script.readyState=="complete"){script.onreadystatechange=null;initAutosearch()}}}else{script.onload=function(){initAutosearch()}}document.body.appendChild(script)}else{initAutosearch()}}},{key:"initDetails",value:function initDetails(){this.util.forEach(document.getElementsByClassName("details"),function($details){var $summary=$details.querySelector(".details-summary");$summary.addEventListener("click",function(){$details.classList.toggle("open")},false)})}},{key:"initLightGallery",value:function initLightGallery(){if(this.config.lightgallery){lightGallery(document.getElementById("content"),{plugins:[lgThumbnail,lgZoom],selector:".lightgallery",speed:400,hideBarsDelay:2000,allowMediaOverlap:true,exThumbImage:"data-thumbnail",toggleThumb:true,thumbWidth:80,thumbHeight:"60px",actualSize:false,showZoomInOutIcons:true,licenseKey:"none"})}}},{key:"initHighlight",value:function initHighlight(){var _this8=this;this.util.forEach(document.querySelectorAll(".highlight > pre.chroma"),function($preChroma){var $chroma=document.createElement("div");$chroma.className=$preChroma.className;var $table=document.createElement("table");$chroma.appendChild($table);var $tbody=document.createElement("tbody");$table.appendChild($tbody);var $tr=document.createElement("tr");$tbody.appendChild($tr);var $td=document.createElement("td");$tr.appendChild($td);$preChroma.parentElement.replaceChild($chroma,$preChroma);$td.appendChild($preChroma)});this.util.forEach(document.querySelectorAll(".highlight > .chroma"),function($chroma){var $codeElements=$chroma.querySelectorAll("pre.chroma > code");if($codeElements.length){var $code=$codeElements[$codeElements.length-1];var $header=document.createElement("div");$header.className="code-header "+$code.className.toLowerCase();var $title=document.createElement("span");$title.classList.add("code-title");$title.insertAdjacentHTML("afterbegin","<i class=\"arrow fa-solid fa-chevron-right fa-fw\" aria-hidden=\"true\"></i>");$title.addEventListener("click",function(){$chroma.classList.toggle("open")},false);$header.appendChild($title);var $ellipses=document.createElement("span");$ellipses.insertAdjacentHTML("afterbegin","<i class=\"fa-solid fa-ellipsis-h fa-fw\" aria-hidden=\"true\"></i>");$ellipses.classList.add("ellipses");$ellipses.addEventListener("click",function(){$chroma.classList.add("open")},false);$header.appendChild($ellipses);if(_this8.config.code.editable){var $edit=document.createElement("span");$edit.classList.add("edit");$edit.insertAdjacentHTML("afterbegin","<i class=\"fa-solid fa-key fa-fw\" title=\"".concat(_this8.config.code.editUnLockTitle,"\" aria-hidden=\"true\"></i>"));$edit.addEventListener("click",function(){var $iconKey=$edit.querySelector(".fa-key");var $iconLock=$edit.querySelector(".fa-lock");var $preChromas=$edit.parentElement.parentElement.querySelectorAll("pre.chroma");var $preChroma=$preChromas.length===2?$preChromas[1]:$preChromas[0];if($iconKey){$iconKey.classList.add("fa-lock");$iconKey.classList.remove("fa-key");$iconKey.title=_this8.config.code.editLockTitle;$preChroma.setAttribute("contenteditable",true);$preChroma.focus()}else{$iconLock.classList.add("fa-key");$iconLock.classList.remove("fa-lock");$iconLock.title=_this8.config.code.editUnLockTitle;$preChroma.setAttribute("contenteditable",false);$preChroma.blur()}},false);$header.appendChild($edit)}if(_this8.config.code.copyTitle){var $copy=document.createElement("span");$copy.insertAdjacentHTML("afterbegin","<i class=\"fa-regular fa-copy fa-fw\" aria-hidden=\"true\"></i>");$copy.classList.add("copy");var code=$code.innerText;if(_this8.config.code.maxShownLines<0||code.split("\n").length<_this8.config.code.maxShownLines+2){$chroma.classList.add("open")}$copy.title=_this8.config.code.copyTitle;$copy.addEventListener("click",function(){navigator.clipboard.writeText(code).then(function(){_this8.util.animateCSS($code,"animate__flash")},function(){console.error("Clipboard write failed!","Your browser does not support clipboard API!")})},false);$header.appendChild($copy)}$chroma.insertBefore($header,$chroma.firstChild)}})}},{key:"initTable",value:function initTable(){this.util.forEach(document.querySelectorAll(".content table"),function($table){var $wrapper=document.createElement("div");$wrapper.className="table-wrapper";$table.parentElement.replaceChild($wrapper,$table);$wrapper.appendChild($table)})}},{key:"initHeaderLink",value:function initHeaderLink(){for(var num=1;num<=6;num++){this.util.forEach(document.querySelectorAll(".single .content > h"+num),function($header){$header.classList.add("header-link");$header.insertAdjacentHTML("afterbegin","<a href=\"#".concat($header.id,"\" class=\"header-mark\"></a>"))})}}},{key:"initToc",value:function initToc(){var _this9=this;var $tocCore=document.getElementById("TableOfContents");if($tocCore===null){return}if(document.getElementById("toc-static").getAttribute("date-kept")==="true"||this.util.isTocStatic()){var $tocContentStatic=document.getElementById("toc-content-static");if($tocCore.parentElement!==$tocContentStatic){$tocCore.parentElement.removeChild($tocCore);$tocContentStatic.appendChild($tocCore)}this._tocOnScroll&&this.scrollEventSet.delete(this._tocOnScroll)}else{var $tocContentAuto=document.getElementById("toc-content-auto");if($tocCore.parentElement!==$tocContentAuto){$tocCore.parentElement.removeChild($tocCore);$tocContentAuto.appendChild($tocCore)}var $toc=document.getElementById("toc-auto");$toc.style.visibility="visible";this.util.animateCSS($toc,["animate__fadeIn","animate__faster"],true);$toc.style.marginTop=document.querySelector(".single-title").clientHeight+document.querySelector(".post-meta").clientHeight+"px";$toc.style.marginBottom=document.getElementById("post-footer").clientHeight+"px";var $tocLinkElements=$tocCore.querySelectorAll("a:first-child");var $tocLiElements=$tocCore.getElementsByTagName("li");var $headerLinkElements=document.getElementsByClassName("header-link");var headerIsFixed=document.body.getAttribute("data-header-desktop")!=="normal";var headerHeight=document.getElementById("header-desktop").offsetHeight;this._tocOnScroll=this._tocOnScroll||function(){var $comments=document.getElementById("comments");if($comments){$toc.style.marginBottom=document.getElementById("post-footer").clientHeight+$comments.clientHeight+"px"}_this9.util.forEach($tocLinkElements,function($tocLink){$tocLink.classList.remove("active")});_this9.util.forEach($tocLiElements,function($tocLi){$tocLi.classList.remove("has-active")});var INDEX_SPACING=20+(headerIsFixed?headerHeight:0);var activeTocIndex=$headerLinkElements.length-1;for(var i=0;i<$headerLinkElements.length-1;i++){var thisTop=$headerLinkElements[i].getBoundingClientRect().top;var nextTop=$headerLinkElements[i+1].getBoundingClientRect().top;if(i==0&&thisTop>INDEX_SPACING||thisTop<=INDEX_SPACING&&nextTop>INDEX_SPACING){activeTocIndex=i;break}}if(activeTocIndex!==-1){$tocLinkElements[activeTocIndex].classList.add("active");var $parent=$tocLinkElements[activeTocIndex].parentElement;while($parent!==$tocCore){$parent.classList.add("has-active");$parent=$parent.parentElement.parentElement}}};this._tocOnScroll();this.scrollEventSet.add(this._tocOnScroll)}}},{key:"initTocListener",value:function initTocListener(){var _document$querySelect,_this10=this;var $toc=document.getElementById("toc-auto");var $tocContentAuto=document.getElementById("toc-content-auto");(_document$querySelect=document.querySelector("#toc-auto>.toc-title"))===null||_document$querySelect===void 0?void 0:_document$querySelect.addEventListener("click",function(){var animation=["animate__faster"];var tocHidden=$toc.classList.contains("toc-hidden");animation.push(tocHidden?"animate__fadeIn":"animate__fadeOut");$tocContentAuto.classList.remove(tocHidden?"animate__fadeOut":"animate__fadeIn");_this10.util.animateCSS($tocContentAuto,animation,true);$toc.classList.toggle("toc-hidden")},false)}},{key:"initMath",value:function initMath(){if(this.config.math){renderMathInElement(document.body,this.config.math)}}},{key:"initMermaid",value:function initMermaid(){var _this11=this;this._mermaidOnSwitchTheme=this._mermaidOnSwitchTheme||function(){var $mermaidElements=document.getElementsByClassName("mermaid");if($mermaidElements.length){var _this11$config$mermai;var themes=(_this11$config$mermai=_this11.config.mermaid.themes)!==null&&_this11$config$mermai!==void 0?_this11$config$mermai:["neutral","dark"];mermaid.initialize({startOnLoad:false,theme:_this11.isDark?themes[1]:themes[0],securityLevel:"loose"});_this11.util.forEach($mermaidElements,function($mermaid){mermaid.render("svg-"+$mermaid.id,_this11.data[$mermaid.id],function(svgCode){$mermaid.innerHTML=svgCode},$mermaid)})}};this.switchThemeEventSet.add(this._mermaidOnSwitchTheme);this._mermaidOnSwitchTheme()}},{key:"initEcharts",value:function initEcharts(){var _this12=this;if(!this.config.echarts){return}echarts.registerTheme("light",this.config.echarts.lightTheme);echarts.registerTheme("dark",this.config.echarts.darkTheme);this._echartsOnSwitchTheme=this._echartsOnSwitchTheme||function(){_this12._echartsArr=_this12._echartsArr||[];for(var i=0;i<_this12._echartsArr.length;i++){_this12._echartsArr[i].dispose()}_this12._echartsArr=[];_this12.util.forEach(document.getElementsByClassName("echarts"),function($echarts){var chart=echarts.init($echarts,_this12.isDark?"dark":"light",{renderer:"svg"});chart.setOption(JSON.parse(_this12.data[$echarts.id]));_this12._echartsArr.push(chart)})};this.switchThemeEventSet.add(this._echartsOnSwitchTheme);this._echartsOnSwitchTheme();this._echartsOnResize=this._echartsOnResize||function(){for(var i=0;i<_this12._echartsArr.length;i++){_this12._echartsArr[i].resize()}};this.resizeEventSet.add(this._echartsOnResize)}},{key:"initMapbox",value:function initMapbox(){var _this13=this;if(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($mapbox){var _this13$data$$mapbox$=_this13.data[$mapbox.id],lng=_this13$data$$mapbox$.lng,lat=_this13$data$$mapbox$.lat,zoom=_this13$data$$mapbox$.zoom,lightStyle=_this13$data$$mapbox$.lightStyle,darkStyle=_this13$data$$mapbox$.darkStyle,marked=_this13$data$$mapbox$.marked,navigation=_this13$data$$mapbox$.navigation,geolocate=_this13$data$$mapbox$.geolocate,scale=_this13$data$$mapbox$.scale,fullscreen=_this13$data$$mapbox$.fullscreen;var mapbox=new mapboxgl.Map({container:$mapbox,center:[lng,lat],zoom:zoom,minZoom:0.2,style:_this13.isDark?darkStyle:lightStyle,attributionControl:false});if(marked){new mapboxgl.Marker().setLngLat([lng,lat]).addTo(mapbox)}if(navigation){mapbox.addControl(new mapboxgl.NavigationControl,"bottom-right")}if(geolocate){mapbox.addControl(new mapboxgl.GeolocateControl({positionOptions:{enableHighAccuracy:true},showUserLocation:true,trackUserLocation:true}),"bottom-right")}if(scale){mapbox.addControl(new mapboxgl.ScaleControl)}if(fullscreen){mapbox.addControl(new mapboxgl.FullscreenControl)}mapbox.addControl(new MapboxLanguage);_this13._mapboxArr.push(mapbox)});this._mapboxOnSwitchTheme=this._mapboxOnSwitchTheme||function(){_this13.util.forEach(_this13._mapboxArr,function(mapbox){var $mapbox=mapbox.getContainer();var _this13$data$$mapbox$2=_this13.data[$mapbox.id],lightStyle=_this13$data$$mapbox$2.lightStyle,darkStyle=_this13$data$$mapbox$2.darkStyle;mapbox.setStyle(_this13.isDark?darkStyle:lightStyle);mapbox.addControl(new MapboxLanguage)})};this.switchThemeEventSet.add(this._mapboxOnSwitchTheme)}}},{key:"initTypeit",value:function initTypeit(){var _this14=this;if(this.config.typeit){var typeitConfig=this.config.typeit;var speed=typeitConfig.speed||100;var cursorSpeed=typeitConfig.cursorSpeed||1000;var cursorChar=typeitConfig.cursorChar||"|";Object.values(typeitConfig.data).forEach(function(group){var typeone=function typeone(i){var id=group[i];var instance=new TypeIt("#".concat(id),{strings:_this14.data[id],speed:speed,lifeLike:true,cursorSpeed:cursorSpeed,cursorChar:cursorChar,waitUntilVisible:true,afterComplete:function afterComplete(){if(i===group.length-1){if(typeitConfig.duration>=0){window.setTimeout(function(){instance.destroy()},typeitConfig.duration)}return}instance.destroy();typeone(i+1)}}).go()};typeone(0)})}}},{key:"initCommentLightGallery",value:function initCommentLightGallery(comments,images){if(!this.config.lightGallery){return}document.querySelectorAll(comments).forEach(function($content){var $imgs=$content.querySelectorAll(images+":not([lightgallery-loaded])");$imgs.forEach(function($img){$img.setAttribute("lightgallery-loaded","");var $link=document.createElement("a");$link.setAttribute("class","comment-lightgallery");$link.setAttribute("href",$img.src);$link.append($img.cloneNode());$img.replaceWith($link)});if($imgs.length){lightGallery($content,{selector:".comment-lightgallery",actualSize:false,hideBarsDelay:2000,speed:400})}})}},{key:"initComment",value:function initComment(){var _this$config$comment,_this15=this;if(!((_this$config$comment=this.config.comment)!==null&&_this$config$comment!==void 0&&_this$config$comment.enable)){return}if(document.querySelector("#comments")){var $viewCommentsBtn=document.querySelector(".view-comments");$viewCommentsBtn.classList.remove("d-none");$viewCommentsBtn.addEventListener("click",function(){_this15.util.scrollIntoView("#comments")},false)}if(this.config.comment.artalk){var artalk=new Artalk(this.config.comment.artalk);artalk.setDarkMode(this.isDark);this.switchThemeEventSet.add(function(){artalk.setDarkMode(_this15.isDark)});artalk.on("comments-loaded",function(){_this15.config.comment.artalk.lightgallery&&_this15.initCommentLightGallery(".atk-comment .atk-content","img:not([atk-emoticon])")});return artalk}if(this.config.comment.gitalk){this.config.comment.gitalk.body=decodeURI(window.location.href);var gitalk=new Gitalk(this.config.comment.gitalk);gitalk.render("gitalk");return gitalk}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 utterancesConfig=this.config.comment.utterances;var script=document.createElement("script");script.src="https://utteranc.es/client.js";script.setAttribute("repo",utterancesConfig.repo);script.setAttribute("issue-term",utterancesConfig.issueTerm);if(utterancesConfig.label)script.setAttribute("label",utterancesConfig.label);script.setAttribute("theme",this.isDark?utterancesConfig.darkTheme:utterancesConfig.lightTheme);script.crossOrigin="anonymous";script.async=true;document.getElementById("utterances").appendChild(script);this._utterancesOnSwitchTheme=this._utterancesOnSwitchTheme||function(){var _document$querySelect2;var message={type:"set-theme",theme:_this15.isDark?utterancesConfig.darkTheme:utterancesConfig.lightTheme};(_document$querySelect2=document.querySelector(".utterances-frame"))===null||_document$querySelect2===void 0?void 0:_document$querySelect2.contentWindow.postMessage(message,"https://utteranc.es")};this.switchThemeEventSet.add(this._utterancesOnSwitchTheme);return}if(this.config.comment.twikoo){var twikooConfig=this.config.comment.twikoo;if(twikooConfig.lightgallery){twikooConfig.onCommentLoaded=function(){_this15.initCommentLightGallery(".tk-comments .tk-content","img:not(.tk-owo-emotion)")}}twikoo.init(twikooConfig);if(twikooConfig.commentCount){twikoo.getCommentsCount({envId:twikooConfig.envId,region:twikooConfig.region,urls:[window.location.pathname],includeReply:false}).then(function(response){var twikooCommentCount=document.getElementById("twikoo-comment-count");if(twikooCommentCount)twikooCommentCount.innerHTML=response[0].count})}return}if(this.config.comment.giscus){var giscusConfig=this.config.comment.giscus;this._giscusOnSwitchTheme=this._giscusOnSwitchTheme||function(){var _document$querySelect3;var message={setConfig:{theme:_this15.isDark?giscusConfig.darkTheme:giscusConfig.lightTheme}};(_document$querySelect3=document.querySelector(".giscus-frame"))===null||_document$querySelect3===void 0?void 0:_document$querySelect3.contentWindow.postMessage({giscus:message},"https://giscus.app")};this.switchThemeEventSet.add(this._giscusOnSwitchTheme);var _this=this;_this.giscus2parentMsg=window.addEventListener("message",function(event){var $script=document.querySelector("#giscus>script");if($script){_this._giscusOnSwitchTheme();$script.parentElement.removeChild($script)}window.removeEventListener("message",_this.giscus2parentMsg)});return}}},{key:"initCookieconsent",value:function initCookieconsent(){this.config.cookieconsent&&cookieconsent.initialise(this.config.cookieconsent)}},{key:"initSiteTime",value:function initSiteTime(){var _this16=this;if(this.config.siteTime){this.siteTime=setInterval(this.getSiteTime,500);document.addEventListener("visibilitychange",function(){if(document.hidden){return clearInterval(_this16.siteTime)}_this16.siteTime=setInterval(_this16.getSiteTime,500)},false)}}},{key:"initServiceWorker",value:function initServiceWorker(){if(this.config.enablePWA&&"serviceWorker"in navigator){navigator.serviceWorker.register("/service-worker.min.js",{scope:"/"}).then(function(registration){}).catch(function(error){console.error("error: ",error)});navigator.serviceWorker.ready.then(function(registration){})}}},{key:"initWatermark",value:function initWatermark(){var _this$config$watermar,_document$querySelect4,_document$querySelect5;((_this$config$watermar=this.config.watermark)===null||_this$config$watermar===void 0?void 0:_this$config$watermar.enable)&&new Watermark({content:this.config.watermark.content||"".concat((_document$querySelect4=(_document$querySelect5=document.querySelector("footer .fixit-icon"))===null||_document$querySelect5===void 0?void 0:_document$querySelect5.outerHTML)!==null&&_document$querySelect4!==void 0?_document$querySelect4:""," 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 _this17=this,_this$config$encrypti,_this$config$encrypti2;var $tocNodes=document.querySelectorAll("#toc-auto>.d-none, #toc-static.d-none");this.decryptor=new FixItDecryptor({decrypted:function decrypted(){_this17.initTwemoji();_this17.initDetails();_this17.initLightGallery();_this17.initHighlight();_this17.initTable();_this17.initHeaderLink();_this17.initMath();_this17.initMermaid();_this17.initEcharts();_this17.initTypeit();_this17.initMapbox();_this17.util.forEach($tocNodes,function($element){$element.classList.remove("d-none")});_this17.initToc();_this17.initTocListener();_this17.initPangu()},reset:function reset(){_this17.util.forEach($tocNodes,function($element){$element.classList.add("d-none")})}});if((_this$config$encrypti=this.config.encryption)!==null&&_this$config$encrypti!==void 0&&_this$config$encrypti.shortcode){this.decryptor.addEventListener("decrypted",function(){_this17.decryptor.initShortcodes()});this.decryptor.initShortcodes()}((_this$config$encrypti2=this.config.encryption)===null||_this$config$encrypti2===void 0?void 0:_this$config$encrypti2.all)&&this.decryptor.init()}},{key:"initMDevtools",value:function initMDevtools(){var _this$config,_this18=this;var type=(_this$config=this.config)===null||_this$config===void 0?void 0:_this$config.mDevtools;if(typeof window.orientation==="undefined"){return}if(type==="vConsole"){var vConsole=new VConsole({target:".widgets",theme:this.isDark?"dark":"light"});this._vConsoleOnSwitchTheme=this._vConsoleOnSwitchTheme||function(){vConsole.setOption("theme",_this18.isDark?"dark":"light")};this.switchThemeEventSet.add(this._vConsoleOnSwitchTheme)}if(type==="eruda"){eruda.init({defaults:{theme:this.isDark?"Dark":"Light"}});this._erudaOnSwitchTheme=this._erudaOnSwitchTheme||function(){eruda.util.evalCss.setTheme(_this18.isDark?"Dark":"Light")};this.switchThemeEventSet.add(this._erudaOnSwitchTheme)}}},{key:"initAutoMark",value:function initAutoMark(){var _this19=this,_window$localStorage3;if(!this.config.autoBookmark){return}window.addEventListener("beforeunload",function(){var _window$localStorage2;(_window$localStorage2=window.localStorage)===null||_window$localStorage2===void 0?void 0:_window$localStorage2.setItem("fixit-bookmark/#".concat(location.pathname),_this19.util.getScrollTop())});var scrollTop=Number((_window$localStorage3=window.localStorage)===null||_window$localStorage3===void 0?void 0:_window$localStorage3.getItem("fixit-bookmark/#".concat(location.pathname)));if(scrollTop&&location.hash===""){window.scrollTo({top:scrollTop,behavior:"smooth"})}}},{key:"onScroll",value:function onScroll(){var _this20=this;var $headers=[];var ACCURACY=20;var $fixedButtons=document.querySelector(".fixed-buttons");var $backToTop=document.querySelector(".back-to-top");var $readingProgressBar=document.querySelector(".reading-progress-bar");if(document.body.dataset.headerDesktop==="auto"){$headers.push(document.getElementById("header-desktop"))}if(document.body.dataset.headerMobile==="auto"){$headers.push(document.getElementById("header-mobile"))}$backToTop===null||$backToTop===void 0?void 0:$backToTop.addEventListener("click",function(){_this20.util.scrollIntoView("body")});window.addEventListener("scroll",function(event){if(_this20.disableScrollEvent){event.preventDefault();return}var $mask=document.getElementById("mask");_this20.newScrollTop=_this20.util.getScrollTop();var scroll=_this20.newScrollTop-_this20.oldScrollTop;_this20.util.forEach($headers,function($header){if(scroll>ACCURACY){$header.classList.remove("animate__fadeInDown");_this20.util.animateCSS($header,["animate__fadeOutUp"],true);$mask.click()}else if(scroll<-ACCURACY){$header.classList.remove("animate__fadeOutUp");_this20.util.animateCSS($header,["animate__fadeInDown"],true);$mask.click()}});var contentHeight=document.body.scrollHeight-window.innerHeight;var scrollPercent=Math.max(Math.min(100*Math.max(_this20.newScrollTop,0)/contentHeight,100),0);if($readingProgressBar){$readingProgressBar.style.setProperty("--progress","".concat(scrollPercent.toFixed(2),"%"))}if($fixedButtons){if(scrollPercent>1){$fixedButtons.classList.remove("d-none","animate__fadeOut");_this20.util.animateCSS($fixedButtons,["animate__fadeIn"],true)}else{$fixedButtons.classList.remove("animate__fadeIn");_this20.util.animateCSS($fixedButtons,["animate__fadeOut"],true,function(){$fixedButtons.classList.contains("animate__fadeOut")&&$fixedButtons.classList.add("d-none")})}if($backToTop){$backToTop.querySelector("span").innerText="".concat(Math.round(scrollPercent),"%")}}var _iterator2=_createForOfIteratorHelper(_this20.scrollEventSet),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var _event2=_step2.value;_event2()}}catch(err){_iterator2.e(err)}finally{_iterator2.f()}_this20.oldScrollTop=_this20.newScrollTop},false)}},{key:"onResize",value:function onResize(){var _this21=this;var resizeBefore=this.util.isMobile();window.addEventListener("resize",function(){if(!_this21._resizeTimeout){_this21._resizeTimeout=window.setTimeout(function(){_this21._resizeTimeout=null;var _iterator3=_createForOfIteratorHelper(_this21.resizeEventSet),_step3;try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var event=_step3.value;event()}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}_this21.initToc();_this21.initMermaid();_this21.initSearch();var isMobile=_this21.util.isMobile();if(isMobile!==resizeBefore){document.getElementById("mask").click();resizeBefore=isMobile}},100)}},false)}},{key:"onClickMask",value:function onClickMask(){var _this22=this;document.getElementById("mask").addEventListener("click",function(){if(!document.body.classList.contains("blur")){return}var _iterator4=_createForOfIteratorHelper(_this22.clickMaskEventSet),_step4;try{for(_iterator4.s();!(_step4=_iterator4.n()).done;){var event=_step4.value;event()}}catch(err){_iterator4.e(err)}finally{_iterator4.f()}_this22.disableScrollEvent=false;document.body.classList.remove("blur")},false)}},{key:"init",value:function init(){var _this23=this;try{var _this$config$encrypti3;if(this.config.encryption){this.initFixItDecryptor()}else if(!((_this$config$encrypti3=this.config.encryption)!==null&&_this$config$encrypti3!==void 0&&_this$config$encrypti3.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.initThemeColor();this.initSVGIcon();this.initMenu();this.initSwitchTheme();this.initSearch();this.initCookieconsent();this.initSiteTime();this.initServiceWorker();this.initWatermark();this.initMDevtools();this.initAutoMark();window.setTimeout(function(){var _this23$config$encryp;_this23.initComment();if(!((_this23$config$encryp=_this23.config.encryption)!==null&&_this23$config$encryp!==void 0&&_this23$config$encryp.all)){_this23.initToc();_this23.initTocListener()}_this23.onScroll();_this23.onResize();_this23.onClickMask()},100)}catch(err){console.error(err)}}}]);return FixIt}();var themeInit=function themeInit(){window.fixit=new FixIt;window.fixit.init()};if(document.readyState!=="loading"){themeInit()}else{document.addEventListener("DOMContentLoaded",themeInit,false)}
|
|
|
|
//# sourceMappingURL=theme.min.js.map
|