-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsourcey.js
More file actions
1 lines (1 loc) · 17.5 KB
/
Copy pathsourcey.js
File metadata and controls
1 lines (1 loc) · 17.5 KB
1
(function(){(function(){function e(e){try{return window.sessionStorage.getItem(e)}catch{return null}}function t(e,t){try{window.sessionStorage.setItem(e,t)}catch{}}function n(e){try{window.sessionStorage.removeItem(e)}catch{}}function r(e){var t=(e||`/`).replace(/\/+$/,``)||`/`;return t=t.replace(/\/index(?:\.html)?$/,``)||`/`,t=t.replace(/\.html$/,``),t||`/`}function i(e){if(!e.length)return null;for(var t=e.map(function(e){return r(e).split(`/`).filter(Boolean)}),n=[],i=0;i<t[0].length;i++){var a=t[0][i];if(!t.every(function(e){return e[i]===a}))break;n.push(a)}return`/`+n.join(`/`)}function a(e){var t=[];return e.querySelectorAll(`a.nav-link[href]`).forEach(function(e){var n=e.getAttribute(`href`);if(!(!n||n.startsWith(`#`)))try{var r=new URL(n,window.location.href);r.origin===window.location.origin&&t.push(r.pathname)}catch{}}),i(t)}function o(){var e=document.querySelector(`meta[name="sourcey-search"]`),t=e&&e.getAttribute(`content`);if(!t)return null;try{var n=new URL(t,window.location.href);if(n.origin===window.location.origin)return r(n.pathname.replace(/\/search-index\.json$/,``))}catch{}return null}function s(e,t){var n=e.getAttribute(`data-sourcey-sidebar-tab`)||`default`,i=a(t)||o()||r(window.location.pathname);return`sourcey:sidebar-scroll:v1:`+window.location.origin+i+`:`+n}function c(e,t){var n=Math.max(0,e.scrollHeight-e.clientHeight);return Math.max(0,Math.min(t,n))}function l(e,n){t(n,String(Math.round(e.scrollTop||0)))}function u(t,r){var i=e(r);if(i===null)return!1;n(r);var a=Number(i);if(!Number.isFinite(a)||a<=0)return!1;function o(){t.scrollTop=c(t,a)}return o(),requestAnimationFrame(o),!0}function d(e){var t=e.querySelector(`.nav-link.active`);t&&requestAnimationFrame(function(){t.scrollIntoView({block:`nearest`,behavior:`auto`})})}function f(e,t){if(!t||e.defaultPrevented||e.button!==void 0&&e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||t.hasAttribute(`download`))return!1;var n=t.getAttribute(`target`);if(n&&n.toLowerCase()!==`_self`)return!1;var r=t.getAttribute(`href`);if(!r||r.startsWith(`#`))return!1;try{var i=new URL(r,window.location.href);return i.origin!==window.location.origin||i.pathname===window.location.pathname&&i.search===window.location.search&&i.hash?!1:i.protocol===`http:`||i.protocol===`https:`}catch{return!1}}function p(){var e=document.querySelector(`[data-sourcey-sidebar-scroll]`),t=document.getElementById(`nav`);if(!(!e||!t)){var n=s(e,t);u(e,n)||d(t),t.addEventListener(`click`,function(t){f(t,t.target.closest(`a[href]`))&&l(e,n)})}}function m(){p();var e=document.getElementById(`mobile-nav`),t=document.querySelectorAll(`[data-drawer-slide]`);if(!e)return;function n(){var t=document.querySelector(`#nav .nav-link.active`);if(t){var n=t.getAttribute(`href`);n&&e.querySelectorAll(`.nav-link`).forEach(function(e){e.classList.toggle(`active`,e.getAttribute(`href`)===n)})}}t.forEach(function(t){t.addEventListener(`click`,function(){n(),e.showModal()})}),e.addEventListener(`click`,function(t){t.target===e&&e.close()}),e.addEventListener(`click`,function(t){(t.target.closest(`a`)||t.target.closest(`[data-close-drawer]`))&&e.close()});var r=document.getElementById(`drawer-group-toggle`),i=document.getElementById(`drawer-group-list`);if(!r||!i)return;function a(){i.style.display=`none`,r.setAttribute(`aria-expanded`,`false`)}r.addEventListener(`click`,function(){i.style.display===`none`?(i.style.display=``,r.setAttribute(`aria-expanded`,`true`)):a()}),e.addEventListener(`click`,function(e){i.style.display!==`none`&&!e.target.closest(`.drawer-dropdown`)&&a()})}`requestIdleCallback`in window?window.requestIdleCallback(m,{timeout:250}):window.addEventListener(`load`,m,{once:!0})})(),(function(){function e(){var e=document.getElementById(`navbar`),t=document.querySelectorAll(`#nav .nav-link, #nav .nav-group-link`),n=document.querySelectorAll(`[data-traverse-target]`),r=[];if(document.querySelectorAll(`#toc .toc-item`).forEach(function(e){var t=e.getAttribute(`href`);if(t&&t.indexOf(`#`)!==-1){var n=document.getElementById(t.split(`#`)[1]);n&&r.push(n)}}),!n.length&&!r.length||!t.length&&!r.length)return;var i=null,a=null,o=null,s={};if(t.forEach(function(e){var t=e.getAttribute(`href`);t&&t.indexOf(`#`)!==-1&&(s[t.split(`#`)[1]]=e)}),!Object.keys(s).length&&!r.length)return;var c=document.querySelectorAll(`#toc .toc-item`),l={};c.forEach(function(e){var t=e.getAttribute(`href`);t&&t.indexOf(`#`)!==-1&&(l[t.split(`#`)[1]]=e)});var u=Object.values(s);function d(e,t){if(!(e===i&&!t)){i=e,u.forEach(function(e){e.classList.remove(`active`)}),c.forEach(function(e){e.classList.remove(`active`)});var n=s[e];n&&(n.classList.add(`active`),n.scrollIntoView({block:`nearest`,behavior:`auto`}));var r=l[e];r&&r.classList.add(`active`)}}function f(t,r){var i=document.getElementById(t);if(i){if(t===(n.length?n[0].getAttribute(`data-traverse-target`):null)){window.scrollTo({top:0,behavior:r});return}var a=(e?e.offsetHeight:0)-1;window.scrollTo({top:i.getBoundingClientRect().top+window.scrollY-a,behavior:r})}}function p(e,t){var n=e.target.closest(t);if(n){var r=n.getAttribute(`href`);if(!(!r||r.indexOf(`#`)===-1)){var i=r.split(`#`)[1];i&&(e.preventDefault(),a=i,d(i,!0),f(i,`smooth`),history.replaceState(null,``,`#`+i),clearTimeout(o),o=setTimeout(function(){a=null},800))}}}var m=document.getElementById(`toc`);m&&m.addEventListener(`click`,function(e){p(e,`.toc-item`)});var h=document.getElementById(`nav`);h&&h.addEventListener(`click`,function(e){p(e,`.nav-link, .nav-group-link`)});function g(){if(!a){for(var t=(e?e.offsetHeight:0)+20,i=null,o=0;o<n.length&&n[o].getBoundingClientRect().top<=t;o++)i=n[o].getAttribute(`data-traverse-target`);for(var s=0;s<r.length&&r[s].getBoundingClientRect().top<=t;s++)i=r[s].id;var c=n.length?n:r;if(!i&&c.length&&(i=n.length?c[0].getAttribute(`data-traverse-target`):c[0].id),window.innerHeight+window.scrollY>=document.body.scrollHeight-10){var l=c[c.length-1];i=n.length?l.getAttribute(`data-traverse-target`):l.id}i&&d(i)}}var _=!1;window.addEventListener(`scroll`,function(){_||(_=!0,requestAnimationFrame(function(){g(),_=!1}))},{passive:!0});var v=window.location.hash.slice(1)||new URLSearchParams(window.location.search).get(`target`);v&&document.getElementById(v)?(d(v),requestAnimationFrame(function(){f(v,`instant`)})):g(),window.addEventListener(`hashchange`,function(){var e=window.location.hash.slice(1);e&&(d(e,!0),f(e,`smooth`))})}window.location.hash.slice(1)||new URLSearchParams(window.location.search).get(`target`)?requestAnimationFrame(e):`requestIdleCallback`in window?window.requestIdleCallback(e,{timeout:250}):window.addEventListener(`load`,e,{once:!0})})(),(function(){function e(){var e=null;document.addEventListener(`click`,function(e){var r=e.target.closest(`.code-lang-trigger`);if(document.querySelectorAll(`.code-lang-menu`).forEach(function(e){if(!r||!e.parentElement.contains(r)){t(e);var n=e.parentElement.querySelector(`.code-lang-trigger`);n&&n.setAttribute(`aria-expanded`,`false`)}}),r){e.stopPropagation();var i=r.nextElementSibling;if(i){var a=!i.classList.contains(`hidden`);a?t(i):(i.classList.remove(`hidden`),n(r,i)),r.setAttribute(`aria-expanded`,a?`false`:`true`)}}}),document.addEventListener(`click`,function(n){var r=n.target.closest(`.code-lang-option`);if(r){var a=r.closest(`.code-lang-dropdown`),o=!!(a&&a.hasAttribute(`data-lang-sync`)),s=r.textContent.trim(),c=r.closest(`.code-lang-menu`);if(c){t(c);var l=c.parentElement.querySelector(`.code-lang-trigger`);l&&l.setAttribute(`aria-expanded`,`false`)}var u=window.scrollY;if(i(r),o&&s!==e){e=s;var d=r.closest(`.code-group`);document.querySelectorAll(`.code-group`).forEach(function(e){e===d||!e.querySelector(`.code-lang-dropdown[data-lang-sync]`)||e.querySelectorAll(`.code-lang-option`).forEach(function(e){e.textContent.trim()===s&&i(e)})})}window.scrollTo(0,u)}});function t(e){e.classList.add(`hidden`),e.style.position=``,e.style.top=``,e.style.right=``,e.style.bottom=``,e.style.maxHeight=``}function n(e,t){var n=e.getBoundingClientRect(),r=4,i=8,a=window.innerHeight-n.bottom-i,o=n.top-i,s=a<160&&o>a;t.style.position=`fixed`,t.style.right=Math.max(i,window.innerWidth-n.right)+`px`,t.style.maxHeight=Math.max(96,Math.floor((s?o:a)-r))+`px`,s?(t.style.top=``,t.style.bottom=Math.max(i,window.innerHeight-n.top+r)+`px`):(t.style.bottom=``,t.style.top=Math.min(window.innerHeight-i,n.bottom+r)+`px`)}function r(e){var t=e.closest(`[data-response-dropdown]`);if(t){var n=t.getAttribute(`data-response-dropdown`),r=t.closest(`.code-group`),i=r&&r.querySelector(`.response-panel[data-response-panel="`+n+`"]`);if(i)return i}return e.closest(`.code-lang-scope`)||e.closest(`.code-group`)}function i(e){var t=e.closest(`.code-lang-dropdown`),n=r(e),i=e.getAttribute(`data-lang-index`);if(t){var a=t.querySelector(`.code-lang-label`);t.querySelectorAll(`.code-lang-option`).forEach(function(e){var n=e.getAttribute(`data-lang-index`)===i;if(e.setAttribute(`aria-selected`,n?`true`:`false`),e.className=e.className.replace(/(dark:)?text-\[rgb\([^\]]+\)\]/g,``).trim(),n){e.classList.add(`text-[rgb(var(--color-primary))]`,`dark:text-[rgb(var(--color-primary-light))]`),a&&(a.textContent=e.textContent.trim());var r=t.querySelector(`.code-lang-trigger .code-lang-icon`),o=e.querySelector(`.lang-icon`);r&&o&&(r.innerHTML=o.outerHTML)}else e.classList.add(`text-[rgb(var(--color-stone-600))]`,`dark:text-[rgb(var(--color-stone-400))]`)})}n&&n.querySelectorAll(`.code-lang-panel`).forEach(function(e){e.classList.toggle(`active`,e.getAttribute(`data-lang-panel`)===i)})}document.addEventListener(`click`,function(e){var t=e.target.closest(`.response-tab`);if(t){var n=t.closest(`.response-tabs`),r=t.getAttribute(`data-response-index`),i=window.scrollY;n.querySelectorAll(`.response-tab`).forEach(function(e){var t=e.getAttribute(`data-response-index`)===r;e.classList.toggle(`active`,t),e.setAttribute(`aria-selected`,t?`true`:`false`)}),n.querySelectorAll(`.response-panel`).forEach(function(e){e.classList.toggle(`active`,e.getAttribute(`data-response-panel`)===r)}),n.querySelectorAll(`[data-response-dropdown]`).forEach(function(e){e.classList.toggle(`hidden`,e.getAttribute(`data-response-dropdown`)!==r)}),window.scrollTo(0,i)}}),document.addEventListener(`click`,function(e){var t=e.target.closest(`.copy-btn`);if(t){var n=t.closest(`.code-group`)||t.closest(`.prose-code-block`);if(n){var r=n.querySelectorAll(`.code-lang-panel.active, .response-panel.active`),i=r.length?r[r.length-1]:null,a=i?i.querySelector(`code, .code-block, .font-mono`):n.querySelector(`code, .code-block, .font-mono`);if(a){var o=a.textContent||``;navigator.clipboard.writeText(o).then(function(){t.classList.add(`copied`);var e=t.nextElementSibling;e&&e.classList.contains(`copy-tooltip`)&&(e.textContent=`Copied!`),setTimeout(function(){t.classList.remove(`copied`),e&&e.classList.contains(`copy-tooltip`)&&(e.textContent=`Copy`)},2e3)})}}}}),document.addEventListener(`click`,function(e){var t=e.target.closest(`.rust-doctest-toggle-hidden`);if(t){var n=t.getAttribute(`data-target`),r=t.getAttribute(`data-display`),i=n?document.getElementById(n.replace(/^#/,``)):null,a=r?document.getElementById(r.replace(/^#/,``)):null;!i||!a||(i.hasAttribute(`hidden`)?(i.removeAttribute(`hidden`),a.setAttribute(`hidden`,``),t.textContent=`Hide hidden lines`):(i.setAttribute(`hidden`,``),a.removeAttribute(`hidden`),t.textContent=`Show hidden lines`))}}),document.addEventListener(`keydown`,function(e){e.key===`Escape`&&document.querySelectorAll(`.code-lang-menu`).forEach(function(e){e.classList.add(`hidden`);var t=e.parentElement.querySelector(`.code-lang-trigger`);t&&t.setAttribute(`aria-expanded`,`false`)})}),document.addEventListener(`click`,function(e){var t=e.target.closest(`.directive-tab`);if(t){var n=t.getAttribute(`data-tab-group`),r=t.getAttribute(`data-tab-index`),i=window.scrollY;document.querySelectorAll(`.directive-tab[data-tab-group="`+n+`"]`).forEach(function(e){e.classList.toggle(`active`,e.getAttribute(`data-tab-index`)===r)}),document.querySelectorAll(`.directive-tab-panel[data-tab-group="`+n+`"]`).forEach(function(e){e.classList.toggle(`active`,e.getAttribute(`data-tab-index`)===r)}),window.scrollTo(0,i)}})}`requestIdleCallback`in window?window.requestIdleCallback(e,{timeout:250}):window.addEventListener(`load`,e,{once:!0})})(),(function(){var e=`sourcey-theme`,t=document.getElementById(`theme-toggle`),n=document.documentElement;function r(){var t=localStorage.getItem(e);return t===`dark`||t===`light`?t:`light`}function i(e){e===`dark`?n.classList.add(`dark`):n.classList.remove(`dark`),n.style.colorScheme=e,t&&(t.setAttribute(`aria-label`,e===`dark`?`Switch to light mode`:`Switch to dark mode`),t.setAttribute(`title`,e===`dark`?`Light mode`:`Dark mode`))}i(r()),t&&t.addEventListener(`click`,function(){var t=n.classList.contains(`dark`)?`light`:`dark`;localStorage.setItem(e,t),i(t)})})(),(function(){function e(){var e=document.getElementById(`search-dialog`),t=document.getElementById(`search-input`),n=document.getElementById(`search-results`),r=document.getElementById(`search-open`);if(!e||!t||!n)return;var i=[],a=-1,o=[],s=!1,c=document.querySelector(`meta[name="sourcey-search"]`);function l(e){if(s){e();return}if(!c){s=!0,e();return}var t=c.getAttribute(`content`);fetch(t).then(function(e){return e.json()}).then(function(t){i=t.map(function(e){var t=e.title||``,n=e.qualifiedName||``,r=e.owner||``,i=e.tab||``;return{url:e.url,method:e.method||``,path:e.path||``,title:t,summary:n||t,tag:r||i,content:e.content||``,category:e.category||``,featured:!!e.featured,symbolKind:e.symbolKind||``,owner:r,ownerKind:e.ownerKind||``,namespace:e.namespace||``,qualifiedName:n,titleLower:t.toLowerCase(),pathLower:(e.path||``).toLowerCase(),qualifiedLower:n.toLowerCase(),ownerLower:r.toLowerCase(),searchText:[e.method||``,e.path||``,t,n,r,e.ownerKind||``,e.namespace||``,e.symbolKind||``,e.content||``,i].join(` `).toLowerCase()}}),s=!0,e()}).catch(function(){s=!0,e()})}var u=e.querySelector(`.search-dialog-inner`);function d(){if(!(!r||!u)){var e=r.getBoundingClientRect();u.style.position=`absolute`,u.style.top=e.top-4+`px`;var t=Math.min(e.width*.5,200);u.style.left=e.left-t/2+`px`,u.style.width=e.width+t+`px`,u.style.maxWidth=`none`,u.style.transform=`none`,u.style.margin=`0`}}function f(){d(),e.classList.add(`open`),t.value=``,t.focus(),s?m(``):(n.innerHTML=`<div class="search-loading">Loading…</div>`,l(function(){m(``)})),document.addEventListener(`keydown`,b)}function p(){e.classList.remove(`open`),document.removeEventListener(`keydown`,b)}function m(e){var t=e.toLowerCase().trim();if(t){var n=t.split(/\s+/);o=i.map(function(e){return{entry:e,score:h(e,t,n)}}).filter(function(e){return e.score>0});var r={Pages:0,Endpoints:1,Models:2,Functions:3,Types:4,Enums:5,"Enum Values":6,Variables:7,Friends:8,Properties:9,Members:10,Sections:20};o.sort(function(e,t){return t.score===e.score?(r[e.entry.category]||19)-(r[t.entry.category]||19):t.score-e.score}),o=o.map(function(e){return e.entry}).slice(0,50)}else{var s=i.filter(function(e){return e.featured}),c=i.filter(function(e){return!e.featured&&e.category!==`Sections`});o=s.concat(c).slice(0,30)}a=o.length?0:-1,g()}function h(e,t,n){if(!n.every(function(t){return e.searchText.indexOf(t)!==-1}))return 0;var r=t.replace(/\s+/g,``),i=e.qualifiedLower||``,a=e.titleLower||``,o=e.pathLower||``,s=e.ownerLower||``,c=1;return i&&i===r&&(c+=1200),a&&a===t&&(c+=900),o&&o===t&&(c+=850),i&&i.endsWith(`::`+r)&&(c+=780),s&&r===s+`::`+a&&(c+=760),i&&r.indexOf(`::`)!==-1&&i.indexOf(r)!==-1&&(c+=700),a&&a.indexOf(t)===0&&(c+=500),i&&i.indexOf(r)!==-1&&(c+=420),s&&s.indexOf(r)!==-1&&(c+=240),o&&o.indexOf(t)!==-1&&(c+=180),e.content.toLowerCase().indexOf(t)!==-1&&(c+=80),e.category===`Sections`&&(c-=70),e.symbolKind&&(c+=35),e.featured&&(c+=20),c}function g(){for(var e=``,t=``,r=0;r<o.length;r++){var i=o[r],s=i.category||`Results`;s!==t&&(e+=`<div class="search-category">`+_(s)+`</div>`,t=s);var c=`search-result`+(r===a?` active`:``),l=i.method?`<span class="search-result-method method-`+i.method.toLowerCase()+`">`+i.method+`</span> <span class="search-result-path">`+_(i.path)+`</span>`:`<span class="search-result-path">`+_(i.summary)+`</span>`,u=i.tag?`<span class="search-result-tag">`+_(i.tag)+`</span>`:``,d=i.method&&i.summary?`<span class="search-result-summary">`+_(i.summary)+`</span>`:``;e+=`<a href="`+v(i.url)+`" class="`+c+`" data-index="`+r+`"><div class="search-result-main">`+l+d+`</div>`+u+`</a>`}n.innerHTML=e;var f=n.querySelector(`.search-result.active`);f&&f.scrollIntoView({block:`nearest`})}function _(e){var t=document.createElement(`span`);return t.textContent=e,t.innerHTML}function v(e){return _(e).replace(/"/g,`"`).replace(/'/g,`'`)}function y(e){if(!(e<0||e>=o.length)){var t=o[e];p(),window.location.href=t.url}}function b(e){if(e.key===`Escape`){p(),e.preventDefault();return}if(e.key===`ArrowDown`){e.preventDefault(),a=Math.min(a+1,o.length-1),g();return}if(e.key===`ArrowUp`){e.preventDefault(),a=Math.max(a-1,0),g();return}if(e.key===`Enter`){e.preventDefault(),a>=0&&y(a);return}}t.addEventListener(`input`,function(){m(t.value)}),n.addEventListener(`click`,function(e){var t=e.target.closest(`.search-result`);t&&(e.preventDefault(),y(parseInt(t.getAttribute(`data-index`),10)))}),r&&r.addEventListener(`click`,f);var x=document.getElementById(`search-open-mobile`);x&&x.addEventListener(`click`,f),document.addEventListener(`keydown`,function(e){(e.ctrlKey||e.metaKey)&&e.key===`k`&&(e.preventDefault(),f()),e.key===`/`&&!S(e.target)&&(e.preventDefault(),f())}),e.addEventListener(`click`,function(t){t.target===e&&p()});function S(e){var t=e.tagName;return t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable}}`requestIdleCallback`in window?window.requestIdleCallback(e,{timeout:250}):window.addEventListener(`load`,e,{once:!0})})()})();