hugo-theme-relearn/js/theme.min.js

41 lines
38 KiB
JavaScript
Raw Normal View History

window.relearn=window.relearn||{};var touchsupport,formelements,psc,psm,pst,elc,scrollbarSize,theme=!0,isPrint=document.querySelector("body").classList.contains("print"),isPrintPreview=!1,isRtl=document.querySelector("html").getAttribute("dir")=="rtl",lang=document.querySelector("html").getAttribute("lang"),dir_padding_start="padding-left",dir_padding_end="padding-right",dir_key_start=37,dir_key_end=39,dir_scroll=1;isRtl&&(dir_padding_start="padding-right",dir_padding_end="padding-left",dir_key_start=39,dir_key_end=37,dir_scroll=-1),touchsupport="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,formelements="button, datalist, fieldset, input, label, legend, meter, optgroup, option, output, progress, select, textarea",pst=new Map,elc=document.querySelector("#R-body-inner");function regexEscape(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}function documentFocus(){elc.focus(),psc&&psc.scrollbarY.focus()}function scrollbarWidth(){var t,e=document.createElement("div");return e.className="scrollbar-measure",document.body.appendChild(e),t=e.offsetWidth-e.clientWidth,document.body.removeChild(e),t}scrollbarSize=scrollbarWidth();function adjustContentWidth(){var e=parseFloat(getComputedStyle(elc).getPropertyValue(dir_padding_start)),t=e;elc.scrollHeight>elc.clientHeight&&(t=Math.max(0,e-scrollbarSize)),elc.style[dir_padding_end]=""+t+"px"}let debounceTimeout;function debounce(e,t){return function(...n){clearTimeout(debounceTimeout),debounceTimeout=setTimeout(()=>e.apply(this,n),t)}}function fixCodeTabs(){var e=Array.from(document.querySelectorAll(".tab-content.tab-panel-style")).filter(function(e){return e.querySelector("*:scope > .tab-content-text > div.highlight:only-child, *:scope > .tab-content-text > pre:not(.mermaid).pre-code:only-child")});e.forEach(function(e){var n=e.dataset.tabItem,s=e.parentNode.parentNode,t=s.querySelector('.tab-nav-button.tab-panel-style[data-tab-item="'+n+'"]');e.classList.contains("initial")&&(t.classList.remove("initial"),t.classList.add("code"),e.classList.remove("initial"),e.classList.add("code")),e.classList.add("codify")})}function switchTab(e,t){var s,o,c,l,n=Array.from(document.querySelectorAll('.tab-panel[data-tab-group="'+e+'"]')).filter(function(e){return!!e.querySelector('[data-tab-item="'+t+'"]')}),i=n&&n.reduce(function(e,t){return e.concat(Array.from(t.querySelectorAll("[data-tab-item]")).filter(function(e){return e.parentNode.parentNode==t}))},[]),a=n&&n.reduce(function(e,n){return e.concat(Array.from(n.querySelectorAll('[data-tab-item="'+t+'"]')).filter(function(e){return e.parentNode.parentNode==n}))},[]),r=event&&event.target&&event.target.getBoundingClientRect;r&&(c=event.target.getBoundingClientRect().top),i&&i.forEach(function(e){e.classList.remove("active"),e.removeAttribute("tabindex")}),a&&a.forEach(function(e){e.classList.add("active"),e.setAttribute("tabindex","-1")}),r&&(initMermaid(!0),l=event.target.getBoundingClientRect().top-c,window.scrollTo(window.scrollX,window.scrollY+l),window.localStorage&&(o=window.localStorage.getItem(window.relearn.absBaseUri+"/tab-selections"),o?(s=JSON.parse(o)):(s={}),s[e]=t,window.localStorage.setItem(window.relearn.absBaseUri+"/tab-selections",JSON.stringify(s))))}function restoreTabSelections(){if(window.localStorage){var e,t=window.localStorage.getItem(window.relearn.absBaseUri+"/tab-selections");t?(e=JSON.parse(t)):(e={}),Object.keys(e).forEach(function(t){var n=e[t];switchTab(t,n)})}}function initMermaid(e,t){var n,c,l=!0,d=isRtl,o=function(e){var t=document.createElement("textarea");return t.innerHTML=e,t.value},i=function(e){var t=document.createElement("textarea");return t.textContent=e,t.innerHTML},a=function(e){var c,i=1,a=2,r=3,l=/^(?:\s*[\n\r])*(?:-{3}(\s*[\n\r](?:.*?)[\n\r])-{3}(?:\s*[\n\r]+)+)?(?:\s*(?:%%\s*\{\s*\w+\s*:([^%]*?)%%\s*[\n\r]?))?(.*)$/s,t=l.exec(e),n={},s={},o=e;return t&&t.length==4&&(n=t[i]?jsyaml.load(t[i]):n,s=t[a]?JSON.parse('{ "init": '+t[a]).init:s,o=t[r]?t[r]:o),c={yaml:n,dir:s,content:o.trim()},c},r=function(e){var t,n="";return Object.keys(e.yaml).length&&(n=`
`+jsyaml.dump(e.yaml)+`---
`),t="",Object.keys(e.dir).length&&(t="%%{init: "+JSON.stringify(e.dir)+`}%%
`),n+t+e.content},u=function(e){var t=!1,n=e.theme;return document.querySelectorAll(".mermaid").forEach(function(e){var c,l,s=a(o(e.innerHTML));s.yaml.theme&&(s.yaml.relearn_user_theme=!0),s.dir.theme&&(s.dir.relearn_user_theme=!0),!s.yaml.relearn_user_theme&&!s.dir.relearn_user_theme&&(s.yaml.theme=n),t=!0,l=i(r(s)),c=document.createElement("div"),Array.from(e.attributes).forEach(function(t){c.setAttribute(t.name,t.value),e.removeAttribute(t.name)}),c.classList.add("mermaid-container"),c.classList.remove("mermaid"),e.classList.add("mermaid"),e.innerHTML=l,e.offsetParent!==null&&e.classList.add("mermaid-render"),c.innerHTML='<div class="mermaid-code">'+l+"</div>"+e.outerHTML,e.parentNode.replaceChild(c,e)}),t},h=function(e){var n=!1,t=e.theme;return document.querySelectorAll(".mermaid-container").forEach(function(e){var l,s=e.querySelector(".mermaid"),d=e.querySelector(".mermaid-code"),c=a(o(d.innerHTML));if(s.classList.contains("mermaid-render")){if(c.yaml.relearn_user_theme||c.dir.relearn_user_theme)return;if(c.yaml.theme==t||c.dir.theme==t)return}if(s.offsetParent!==null)s.classList.add("mermaid-render");else{s.classList.remove("mermaid-render");return}n=!0,c.yaml.theme=t,l=i(r(c)),s.removeAttribute("data-processed"),s.innerHTML=l,d.innerHTML=l}),n},s=this;if(e&&!s.is_initialized)return;if(typeof mermaid=="undefined"||typeof mermaid.mermaidAPI=="undefined")return;s.is_initialized||(s.is_initialized=!0,window.addEventListener("beforeprint",function(){isPrintPreview=!0,initMermaid(!0,{theme:getColorValue("PRINT-MERMAID-theme")})}.bind(this)),window.addEventListener("afterprint",function(){isPrintPreview=!1,initMermaid(!0)}.bind(this))),t=t||{theme:getColorValue("MERMAID-theme")},e&&(n=sessionStorage.getItem(window.relearn.absBaseUri+"/search-value"),unmark()),c=e?h(t):u(t),c&&(mermaid.initialize(Object.assign({securityLevel:"antiscript",startOnLoad:!1},window.relearn.mermaidConfig,{theme:t.theme})),mermaid.run({postRenderCallback:function(e){var t=d3.selectAll("body:not(.print) .mermaid-container.zoomable > .mermaid > #"+e);t.each(function(){var e,n,s,o,t=this.parentElement;t.style.maxWidth=this.style.maxWidth||this.getAttribute("width"),t.style.maxWidth=t.style.maxWidth||"calc( "+this.getAttribute("width")+"px + 1rem )",e=d3.select(this),e.html("<g>"+e.html()+"</g>"),o=e.select("*:scope > g"),t.insertAdjacentHTML("beforeend",'<button class="svg-reset-button" title="'+window.T_Reset_view+'"><i class="fas fa-undo-alt"></i></button>'),n=t.querySelector(".svg-reset-button"),s=d3.zoom().on("zoom",function(e){o.attr("transform",e.transform),e.transform.k==1&&e.transform.x==0&&e.transform.y==0?n.classList.remove("zoomed"):n.classList.add("zoomed")}),n.addEventListener("click",function(){e.transition().duration(350).call(s.transform,d3.zoomIdentity),this.setAttribute("aria-label",window.T_View_reset),this.classList.add("tooltipped","tooltipped-"+(l?"":"s")+(d?"e":"w"))}),n.addEventListener("mouseleave",function(){this.classList.contains("tooltipped")&&(this.classList.remove("tooltipped","tooltipped-w","tooltipped-se","tooltipped-sw"),this.removeAttribute("aria-label"))}),e.call(s)})},querySelector:".mermaid.mermaid-render",suppressErrors:!0})),e&&n&&n.length&&(sessionStorage.setItem(window.relearn.absBaseUri+"/search-value",n),mark())}function initOpenapi(e,t){var s=this;if(e&&!s.is_initialized)return;s.is_initialized||(s.is_initialized=!0,window.addEventListener("beforeprint",function(){isPrintPreview=!0,initOpenapi(!0)}.bind(this)),window.addEventListener("afterprint",function(){isPrintPreview=!1,initOpenapi(!0)}.bind(this))),t=t||{};function i(){}function a(){}function r(e){var r=window.relearn.relBasePath,o=window.relearn.themeUseOpenapi.assetsBuster,i=isPrint||isPrintPreview?"PRINT-":"",l=i?`print`:`html`,c=window.relearn.min,v=`${r}/css/format-${l}${c}.css${o}`,g=document.documentElement.dataset.rThemeVariant,f=getColorValue(i+"OPENAPI-theme"),p=getColorValue(i+"OPENAPI-CODE-theme");const s="relearn-swagger-ui",d=s+"-iframe",u=document.getElementById(d);u&&u.remove();const h=s+"-error",m=document.getElementById(h);m&&m.
<html lang="${lang}" dir="${isRtl?"rtl":"ltr"}" data-r-output-format="${l}" data-r-theme-variant="${g}">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="${window.relearn.themeUseOpenapi.css}">
<link rel="stylesheet" href="${r}/css/swagger${c}.css${o}">
<link rel="stylesheet" href="${r}/css/swagger-${f}${c}.css${o}">
<link rel="stylesheet" href="${v}">
<script>
function relearn_expand_all() {
document.querySelectorAll(".expand-operation[aria-expanded=false]").forEach(btn => btn.click());
document.querySelectorAll(".models-control[aria-expanded=false]").forEach(btn => btn.click());
document.querySelectorAll(".opblock-summary-control[aria-expanded=false]").forEach(btn => btn.click());
document.querySelectorAll(".model-container > .model-box > button[aria-expanded=false]").forEach(btn => btn.click());
return false;
}
function relearn_collapse_all() {
document.querySelectorAll(".expand-operation[aria-expanded=true]").forEach(btn => btn.click());
document.querySelectorAll(".models-control[aria-expanded=true]").forEach(btn => btn.click());
document.querySelectorAll(".opblock-summary-control[aria-expanded=true]").forEach(btn => btn.click());
document.querySelectorAll(".model-container > .model-box > .model-box > .model > span > button[aria-expanded=true]").forEach(btn => btn.click());
return false;
}
<\/script>
</head>
<body>
<a class="relearn-expander" href="" onclick="return relearn_collapse_all()">Collapse all</a>
<a class="relearn-expander" href="" onclick="return relearn_expand_all()">Expand all</a>
<div id="relearn-swagger-ui"></div>
</body>
</html>`,t.height="100%",t.width="100%",t.onload=function(){const o=a(e,"sc-openapi-wrapper"),i=new Promise(function(e){e()});i.then(function(){var o={defaultModelsExpandDepth:2,defaultModelExpandDepth:2,docExpansion:isPrint||isPrintPreview?"full":"list",domNode:t.contentWindow.document.getElementById(s),filter:!isPrint&&!isPrintPreview,layout:"BaseLayout",onComplete:function(){(isPrint||isPrintPreview)&&(t.contentWindow.document.querySelectorAll(".model-container > .model-box > button[aria-expanded=false]").forEach(function(e){e.click()}),n(t))},plugins:[SwaggerUIBundle.plugins.DownloadUrl],presets:[SwaggerUIBundle.presets.apis,SwaggerUIStandalonePreset],syntaxHighlight:{activated:!0,theme:p},validatorUrl:"none"};if(e.dataset.openapiSpec)try{Object.assign(o,{spec:JSON.parse(e.dataset.openapiSpec)})}catch{try{Object.assign(o,{spec:jsyaml.load(e.dataset.openapiSpec)})}catch{console.error('OpenAPI: file "'+e.dataset.openapiUrl+'" could not be parsed as JSON or YAML')}}else Object.assign(o,{url:e.dataset.openapiUrl});SwaggerUIBundle(o)}).then(function(){let e=function(){n(t)},s=new MutationObserver(e);s.observe(t.contentWindow.document.documentElement,{childList:!0,subtree:!0})}).then(function(){o&&o.classList.toggle("is-loading",!1),n(t)}).catch(function(t){const n=document.createElement("div");for(n.classList.add("sc-alert","sc-alert-error"),n.innerHTML=t,n.id=h;e.lastChild;)e.removeChild(e.lastChild);o&&(o.classList.toggle("is-loading",!1),o.insertAdjacentElement("afterbegin",n))})},e.appendChild(t)}function n(e){e.style.height=e.contentWindow.document.documentElement.getBoundingClientRect().height+(isPrintPreview?200:0)+"px"}function c(){let e=document.getElementsByClassName("sc-openapi-iframe");for(let t=0;t<e.length;t++)n(e[t])}let o=document.getElementsByClassName("sc-openapi-container");for(let e=0;e<o.length;e++)r(o[e]);o.length&&i(c)}function initAnchorClipboard(){if(window.relearn.disableAnchorCopy&&window.relearn.disableAnchorScrolling)return;document.querySelectorAll(":has(h1) :is(h2[id], h3[id], h4[id] , h5[id], h6[id])").forEach(function(e){var n=encodeURI((document.location.origin=="null"?document.location.protocol+"//"+document.location.host:document.location.origin)+document.location.pathname),s=n+"#"+e.id,t=document.createElement("button");t.classList.add("anchor"),window.relearn.disableAnchorCopy||t.setAttribute("title",window.T_Copy_link_to_clipboard),t.setAttribute("data-clipboard-text",s),t.innerHTML='<i class="fas fa-link fa-lg"></i>',e.appendChild(t)});var e,n,t=document.querySelectorAll(".anchor");if(window.relearn.disableAnchorCopy){if(!window.relearn.disableAnchorScrolling)for(e=0;e<t.length;e++)t[e].addEventListener("click",function(e){e.target.parentElement.parentElement.scrollIntoView({behavior:"smooth"});var t=window.history.state||{},t=Object.assign({},typeof t=="object"?t:{});history.replaceState({},"",e.text)})}else{for(e=0;e<t.length;e++)t[e].addEventListener("mouseleave",function(){this.removeAttribute("aria-label"),this.classList.remove("tooltipped","tooltipped-se","tooltipped-sw")});n=new ClipboardJS(".anchor"),n.on("success",function(e){if(e.clearSelection(),e.trigger.setAttribute("aria-label",window.T_Link_copied_to_clipboard),e.trigger.classList.add("tooltipped","tooltipped-s"+(isRtl?"e":"w")),!window.relearn.disableAnchorScrolling){e.trigger.parentElement.scrollIntoView({behavior:"smooth"});var t=window.history.state||{},t=Object.assign({},typeof t=="object"?t:{});history.replaceState({},"",e.text)}})}}function initCodeClipboard(){function j(e){var t,n=e.cloneNode(!0);return Array.from(n.querySelectorAll("*:scope > span > span:first-child:not(:last-child)")).forEach(function(e){e.remove()}),t=n.textContent,t=t.replace(/\n$/,""),t}function b(e){var t="",n=e==="cut"?"X":"C";return/iPhone|iPad/i.test(navigator.userAgent)?t="No support :(":/Mac/i.test(navigator.userAgent)?t="Press -"+n+" to "+e:t="Press Ctrl-"+n+" to "+e,t}document.addEventListener("copy",function(e){var s,n=document.getSelection(),t=n.anchorNode;function o(e){for(var n,s,t=0;t<e.rangeCount;t++)if(s=e.getRangeAt(t)
.article-subheading,
:not(.article-subheading) + h1:not(.a11y-only),
h1:not(.a11y-only):first-child,
h2, h3, h4, h5, h6
),
main .include.hide-first-heading > :where( h1, h2, h3, h4, h5, h6 ) ~ :where( h1, h2, h3, h4, h5, h6 )
`));!t.shiftKey&&!t.ctrlKey&&t.altKey&&!t.metaKey&&(t.which==38?(s=isPrint?document.querySelector("#R-body"):document.querySelector(".flex-block-wrapper"),n.some(function(t){var o=t.getBoundingClientRect().top,i=o-e;if(i>-1)return s.scrollIntoView(),!0;s=t})):t.which==40&&n.some(function(t,s){var o,a=t.getBoundingClientRect().top,i=a-e;if(i>-1&&i<1)return s+1<n.length&&(o=n[s+1],o.scrollIntoView()),!0;if(i>=1)return o=t,o.scrollIntoView(),!0}))})}function initArrowHorizontalNav(){if(isPrint)return;var e,t,n,s,o=document.querySelector(".topbar-button-prev a");o&&o.addEventListener("click",navPrev),n=document.querySelector(".topbar-button-next a"),n&&n.addEventListener("click",navNext),s=document.querySelector("#R-body-inner"),e=0,t=0,document.addEventListener("keydown",function(i){if(!i.shiftKey&&!i.ctrlKey&&!i.altKey&&!i.metaKey){var a=i.target.matches(formelements);if(a)return;i.which==dir_key_start&&(!e&&+s.scrollLeft.toFixed()*dir_scroll<=0?o&&o.click():e!=-1&&clearTimeout(e),e=-1),i.which==dir_key_end&&(!t&&+s.scrollLeft.toFixed()*dir_scroll+ +s.clientWidth.toFixed()>=+s.scrollWidth.toFixed()?n&&n.click():t!=-1&&clearTimeout(t),t=-1)}}),document.addEventListener("keyup",function(n){if(!n.shiftKey&&!n.ctrlKey&&!n.altKey&&!n.metaKey){var s=n.target.matches(formelements);if(s)return;n.which==dir_key_start&&e==-1&&(e=setTimeout(function(){e=0},300)),n.which==dir_key_end&&t==-1&&(t=setTimeout(function(){t=0},300))}})}function initMenuScrollbar(){if(isPrint)return;var e=document.querySelector("#R-content-wrapper"),n=document.querySelector(".topbar-button.topbar-flyout .topbar-content-wrapper"),t=!0;document.addEventListener("keydown",function(s){if(t=!1,s.shiftKey||s.altKey||s.ctrlKey||s.metaKey||s.which<32||s.which>40)return;var o,i,a,r=elc&&elc.matches(":hover"),c=e&&e.matches(":hover"),l=n&&n.matches(":hover"),d=s.target.matches(formelements);!r&&!c&&!l&&!d&&(i=document.querySelector("body").matches(".topbar-flyout"),a=document.querySelector("body").matches(".sidebar-flyout"),i?(o=pst.get(document.querySelector(".topbar-button.topbar-flyout")),o&&o.scrollbarY.focus()):a?psm&&psm.scrollbarY.focus():(document.querySelector("#R-body-inner").focus(),psc&&psc.scrollbarY.focus()))}),psm=e&&new PerfectScrollbar("#R-content-wrapper",{scrollingThreshold:2e3,swipeEasing:!1,wheelPropagation:!1}),document.querySelectorAll(".topbar-button .topbar-content-wrapper").forEach(function(e){var t=getTopbarButtonParent(e);if(!t)return;pst.set(t,new PerfectScrollbar(e,{scrollingThreshold:2e3,swipeEasing:!1,wheelPropagation:!1})),e.addEventListener("click",toggleTopbarFlyoutEvent)}),document.addEventListener("keydown",function(){t&&(psc&&psc.scrollbarY.blur(),psm&&psm.scrollbarY.blur(),pst.forEach(function(e){e.scrollbarY.blur()}),t=!1)}),window.addEventListener("resize",function(){pst.forEach(function(e){setTimeout(function(){e.update()},10)}),psm&&setTimeout(function(){psm.update()},10),psc&&setTimeout(function(){psc.update()},10)}),document.querySelectorAll("#R-sidebar .collapsible-menu input").forEach(function(e){e.addEventListener("change",function(){psm&&setTimeout(function(){psm.update()},10)})}),pst.forEach(function(e){setTimeout(function(){e.update()},10)}),psm&&setTimeout(function(){psm.update()},10),psc&&setTimeout(function(){psc.update()},10),window.addEventListener("resize",adjustContentWidth),adjustContentWidth()}function imageEscapeHandler(e){if(e.key=="Escape"){var t=e.target;t.click()}}function navShortcutHandler(e){!e.shiftKey&&e.altKey&&e.ctrlKey&&!e.metaKey&&e.which==78&&toggleNav()}function searchShortcutHandler(e){!e.shiftKey&&e.altKey&&e.ctrlKey&&!e.metaKey&&e.which==70&&showSearch()}function tocShortcutHandler(e){!e.shiftKey&&e.altKey&&e.ctrlKey&&!e.metaKey&&e.which==84&&toggleToc()}function editShortcutHandler(e){!e.shiftKey&&e.altKey&&e.ctrlKey&&!e.metaKey&&e.which==87&&showEdit()}function printShortcutHandler(e){!e.shiftKey&&e.altKey&&e.ctrlKey&&!e.metaKey&&e.which==80&&showPrint()}function showSearch(){var t,e=document.querySelector("#R-search-by");if(!e)return;t=document.querySelector("body"),e==document.