blob: 89c64166bb9f547cc1875e7c17b1d686f31ff37c [file] [log] [blame]
function P(){let n=document.querySelector(".js-header");document.querySelectorAll(".js-desktop-menu-hover").forEach(c=>{c.addEventListener("mouseenter",a=>{let u=a.target,s=document.querySelector(".forced-open");s&&s!==c&&(s.blur(),s.classList.remove("forced-open")),u.focus(),u.blur()});let r=a=>{var d,h;let u=a.target,s=u==null?void 0:u.classList.contains("forced-open"),t=a.currentTarget;s?(t.removeEventListener("blur",()=>t.classList.remove("forced-open")),t.classList.remove("forced-open"),t.classList.add("forced-closed"),t.blur(),(d=t==null?void 0:t.parentNode)==null||d.addEventListener("mouseout",()=>{t.classList.remove("forced-closed")})):(t.classList.remove("forced-closed"),t.classList.add("forced-open"),t.focus(),t.addEventListener("blur",()=>t.classList.remove("forced-open")),(h=t==null?void 0:t.parentNode)==null||h.removeEventListener("mouseout",()=>{t.classList.remove("forced-closed")}))};c.addEventListener("click",r)}),document.querySelectorAll(".Header-menuItem").forEach(c=>{c.addEventListener("keyup",r=>{var u;let a=r;a.key==="Escape"&&((u=a.target)==null||u.blur())})});let i=document.querySelectorAll(".js-headerMenuButton");i.forEach(c=>{c.addEventListener("click",r=>{r.preventDefault();let a=n==null?void 0:n.classList.contains("is-active");a?g(n):w(n),c.setAttribute("aria-expanded",a?"true":"false")})});let l=document.querySelector(".js-scrim");l==null||l.addEventListener("click",c=>{c.preventDefault(),document.querySelectorAll(".go-NavigationDrawer-submenuItem.is-active").forEach(a=>g(a)),g(n),i.forEach(a=>{a.setAttribute("aria-expanded",n!=null&&n.classList.contains("is-active")?"true":"false")})});let m=c=>{if(!c)return[];let r=Array.from(c.querySelectorAll(":scope > .go-NavigationDrawer-nav > .go-NavigationDrawer-list > .go-NavigationDrawer-listItem > a, :scope > .go-NavigationDrawer-nav > .go-NavigationDrawer-list > .go-NavigationDrawer-listItem > .go-Header-socialIcons > a")||[]),a=c.querySelector(".go-NavigationDrawer-header > a");return a&&r.unshift(a),r},p=c=>{if(!!c)return c.classList.contains("go-NavigationDrawer-submenuItem")},g=c=>{var u,s;if(!c)return;let r=m(c);c.classList.remove("is-active");let a=(u=c.closest(".go-NavigationDrawer-listItem"))==null?void 0:u.querySelector(":scope > a");a==null||a.focus(),r==null||r.forEach(t=>t==null?void 0:t.setAttribute("tabindex","-1")),r&&r[0]&&(r[0].removeEventListener("keydown",L(c)),r[r.length-1].removeEventListener("keydown",b(c))),c===n&&i&&((s=i[0])==null||s.focus())},w=c=>{let r=m(c);c.classList.add("is-active"),r.forEach(a=>a.setAttribute("tabindex","0")),r[0].focus(),r[0].addEventListener("keydown",L(c)),r[r.length-1].addEventListener("keydown",b(c))},L=c=>r=>{r.key==="Tab"&&r.shiftKey&&(r.preventDefault(),g(c))},b=c=>r=>{r.key==="Tab"&&!r.shiftKey&&(r.preventDefault(),g(c))},M=c=>{var u;let r=p(c),a=m(c);c.addEventListener("keyup",s=>{s.key==="Escape"&&g(c)}),a.forEach(s=>{let t=s.closest("li");if(t&&t.classList.contains("js-mobile-subnav-trigger")){let d=t.querySelector(".go-NavigationDrawer-submenuItem");s.addEventListener("click",()=>{w(d)})}}),r&&(g(c),(u=c==null?void 0:c.querySelector(".go-NavigationDrawer-header"))==null||u.addEventListener("click",s=>{s.preventDefault(),g(c)}))};document.querySelectorAll(".go-NavigationDrawer").forEach(c=>M(c)),g(n)}function U(){let n=document.querySelector(".js-searchForm"),e=document.querySelector(".js-expandSearch"),o=n==null?void 0:n.querySelector("input"),i=document.querySelector(".js-headerLogo"),l=document.querySelector(".js-headerMenuButton");e==null||e.addEventListener("click",()=>{n==null||n.classList.add("go-SearchForm--expanded"),i==null||i.classList.add("go-Header-logo--hidden"),l==null||l.classList.add("go-Header-navOpen--hidden"),o==null||o.focus()}),document==null||document.addEventListener("click",m=>{n!=null&&n.contains(m.target)||(n==null||n.classList.remove("go-SearchForm--expanded"),i==null||i.classList.remove("go-Header-logo--hidden"),l==null||l.classList.remove("go-Header-navOpen--hidden"))})}var k=class{constructor(e){this.el=e;this.setActive=e=>{this.activeIndex=(e+this.slides.length)%this.slides.length,this.el.setAttribute("data-slide-index",String(this.activeIndex));for(let o of this.dots)o.classList.remove("go-Carousel-dot--active");this.dots[this.activeIndex].classList.add("go-Carousel-dot--active");for(let o of this.slides)o.setAttribute("aria-hidden","true");this.slides[this.activeIndex].removeAttribute("aria-hidden"),this.liveRegion.textContent="Slide "+(this.activeIndex+1)+" of "+this.slides.length};var o;this.slides=Array.from(e.querySelectorAll(".go-Carousel-slide")),this.dots=[],this.liveRegion=document.createElement("div"),this.activeIndex=Number((o=e.getAttribute("data-slide-index"))!=null?o:0),this.initSlides(),this.initArrows(),this.initDots(),this.initLiveRegion()}initSlides(){for(let[e,o]of this.slides.entries())e!==this.activeIndex&&o.setAttribute("aria-hidden","true")}initArrows(){var o,i;let e=document.createElement("ul");e.classList.add("go-Carousel-arrows"),e.innerHTML=`
<li>
<button class="go-Carousel-prevSlide" aria-label="Go to previous slide">
<img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_left_gm_grey_24dp.svg" alt="">
</button>
</li>
<li>
<button class="go-Carousel-nextSlide" aria-label="Go to next slide">
<img class="go-Icon" height="24" width="24" src="/static/shared/icon/arrow_right_gm_grey_24dp.svg" alt="">
</button>
</li>
`,(o=e.querySelector(".go-Carousel-prevSlide"))==null||o.addEventListener("click",()=>this.setActive(this.activeIndex-1)),(i=e.querySelector(".go-Carousel-nextSlide"))==null||i.addEventListener("click",()=>this.setActive(this.activeIndex+1)),this.el.append(e)}initDots(){let e=document.createElement("ul");e.classList.add("go-Carousel-dots");for(let o=0;o<this.slides.length;o++){let i=document.createElement("li"),l=document.createElement("button");l.classList.add("go-Carousel-dot"),o===this.activeIndex&&l.classList.add("go-Carousel-dot--active"),l.innerHTML=`<span class="go-Carousel-obscured">Slide ${o+1}</span>`,l.addEventListener("click",()=>this.setActive(o)),i.append(l),e.append(i),this.dots.push(l)}this.el.append(e)}initLiveRegion(){this.liveRegion.setAttribute("aria-live","polite"),this.liveRegion.setAttribute("aria-atomic","true"),this.liveRegion.setAttribute("class","go-Carousel-obscured"),this.liveRegion.textContent=`Slide ${this.activeIndex+1} of ${this.slides.length}`,this.el.appendChild(this.liveRegion)}};var A=class{constructor(e){this.el=e;var o,i,l,m,p;this.data=(o=e.dataset.toCopy)!=null?o:e.innerText,!this.data&&((i=e.parentElement)==null?void 0:i.classList.contains("go-InputGroup"))&&(this.data=(p=this.data||((m=(l=e.parentElement)==null?void 0:l.querySelector("input"))==null?void 0:m.value))!=null?p:""),e.addEventListener("click",g=>this.handleCopyClick(g))}handleCopyClick(e){e.preventDefault();let o=1e3;if(!navigator.clipboard){this.showTooltipText("Unable to copy",o);return}navigator.clipboard.writeText(this.data).then(()=>{this.showTooltipText("Copied!",o)}).catch(()=>{this.showTooltipText("Unable to copy",o)})}showTooltipText(e,o){this.el.setAttribute("data-tooltip",e),setTimeout(()=>this.el.setAttribute("data-tooltip",""),o)}};var x=class{constructor(e){this.el=e;document.addEventListener("click",o=>{this.el.contains(o.target)||this.el.removeAttribute("open")})}};var q=class{constructor(e){this.el=e;this.el.addEventListener("change",o=>{let i=o.target,l=i.value;i.value.startsWith("/")||(l="/"+l),window.location.href=l})}};var C=class{constructor(e){this.el=e;window.dialogPolyfill&&window.dialogPolyfill.registerDialog(e),this.init()}init(){let e=document.querySelector(`[aria-controls="${this.el.id}"]`);e&&e.addEventListener("click",()=>{var o;this.el.showModal?this.el.showModal():this.el.setAttribute("opened","true"),(o=this.el.querySelector("input"))==null||o.focus()});for(let o of this.el.querySelectorAll("[data-modal-close]"))o.addEventListener("click",()=>{this.el.close?this.el.close():this.el.removeAttribute("opened")})}};function I(n,e,o,i){var l;(l=window.dataLayer)!=null||(window.dataLayer=[]),typeof n=="string"?window.dataLayer.push({event:n,event_category:e,event_action:o,event_label:i}):window.dataLayer.push(n)}function W(n){var e;(e=window.dataLayer)!=null||(window.dataLayer=[]),window.dataLayer.push(n)}var O=class{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,o,i,l){var m,p;return(p=(m=this.handlers)[e])!=null||(m[e]=new Set),this.handlers[e].add({description:o,callback:i,...l}),this}handleKeyPress(e){var o;for(let i of(o=this.handlers[e.key.toLowerCase()])!=null?o:new Set){if(i.target&&i.target!==e.target)return;let l=e.target;if(!i.target&&((l==null?void 0:l.tagName)==="INPUT"||(l==null?void 0:l.tagName)==="SELECT"||(l==null?void 0:l.tagName)==="TEXTAREA")||l!=null&&l.isContentEditable||i.withMeta&&!(e.ctrlKey||e.metaKey)||!i.withMeta&&(e.ctrlKey||e.metaKey))return;I("keypress","hotkeys",`${e.key} pressed`,i.description),i.callback(e)}}},H=new O;function $(){var u;let n=document.querySelector(".JumpDialog"),e=n==null?void 0:n.querySelector(".JumpDialog-body"),o=n==null?void 0:n.querySelector(".JumpDialog-list"),i=n==null?void 0:n.querySelector(".JumpDialog-input"),l=document.querySelector(".js-documentation"),m;function p(){let s=[];if(!!l){for(let t of l.querySelectorAll("[data-kind]"))s.push(g(t));for(let t of s)t.link.addEventListener("click",function(){n==null||n.close()});return s.sort(function(t,d){return t.lower.localeCompare(d.lower)}),s}}function g(s){var E;let t=document.createElement("a"),d=s.getAttribute("id");t.setAttribute("href","#"+d),t.setAttribute("tabindex","-1"),t.setAttribute("data-gtmc","jump to link");let h=s.getAttribute("data-kind");return{link:t,name:d!=null?d:"",kind:h!=null?h:"",lower:(E=d==null?void 0:d.toLowerCase())!=null?E:""}}let w,L=-1;function b(s){for(w=s,m||(m=p()),M(-1);o!=null&&o.firstChild;)o.firstChild.remove();if(s){let t=s.toLowerCase(),d=[],h=[],E=[],S=(v,y,T)=>v.name.substring(0,y)+"<b>"+v.name.substring(y,T)+"</b>"+v.name.substring(T);for(let v of m!=null?m:[]){let y=v.name.toLowerCase();if(y===t)v.link.innerHTML=S(v,0,v.name.length),d.push(v);else if(y.startsWith(t))v.link.innerHTML=S(v,0,s.length),h.push(v);else{let T=y.indexOf(t);T>-1&&(v.link.innerHTML=S(v,T,T+s.length),E.push(v))}}for(let v of d.concat(h).concat(E))o==null||o.appendChild(v.link)}else{if(!m||m.length===0){let t=document.createElement("i");t.innerHTML="There are no symbols on this page.",o==null||o.appendChild(t)}for(let t of m!=null?m:[])t.link.innerHTML=t.name+" <i>"+t.kind+"</i>",o==null||o.appendChild(t.link)}e&&(e.scrollTop=0),(m==null?void 0:m.length)&&o&&o.children.length>0&&M(0)}function M(s){let t=o==null?void 0:o.children;if(!(!t||!e)){if(L>=0&&t[L].classList.remove("JumpDialog-active"),s>=t.length&&(s=t.length-1),s>=0){t[s].classList.add("JumpDialog-active");let d=t[s].offsetTop-t[0].offsetTop,h=d+t[s].clientHeight;d<e.scrollTop?e.scrollTop=d:h>e.scrollTop+e.clientHeight&&(e.scrollTop=h-e.clientHeight)}L=s}}function c(s){if(L<0)return;let t=L+s;t<0&&(t=0),M(t)}i==null||i.addEventListener("keyup",function(){i.value.toUpperCase()!=w.toUpperCase()&&b(i.value)}),i==null||i.addEventListener("keydown",function(s){switch(s.which){case 38:c(-1),s.preventDefault();break;case 40:c(1),s.preventDefault();break;case 13:L>=0&&o&&(o.children[L].click(),s.preventDefault());break}});let r=document.querySelector(".ShortcutsDialog");H.on("f","open jump to modal",s=>{var t;(n==null?void 0:n.open)||(r==null?void 0:r.open)||(s.preventDefault(),i&&(i.value=""),(t=n==null?void 0:n.showModal)==null||t.call(n),i==null||i.focus(),b(""))}).on("?","open shortcuts modal",()=>{var s;(n==null?void 0:n.open)||(r==null?void 0:r.open)||(s=r==null?void 0:r.showModal)==null||s.call(r)});let a=document.querySelector(".js-jumpToInput");a&&a.addEventListener("click",()=>{var s;i&&(i.value=""),b(""),!((n==null?void 0:n.open)||(r==null?void 0:r.open))&&((s=n==null?void 0:n.showModal)==null||s.call(n),i==null||i.focus())}),(u=document.querySelector(".js-openShortcuts"))==null||u.addEventListener("click",()=>{var s;(s=r==null?void 0:r.showModal)==null||s.call(r)})}var G=async function(){if(!["/about"].includes(window.location.pathname))return;let e="h2, h3, h4",o=".LeftNav a",i=document.querySelector(".LeftNav"),l=document.querySelector(".go-Content"),m=!1;function p(a="",u={},...s){if(!a)throw new Error("Provide `type` to create document element.");let t=Object.assign(document.createElement(a),u);return s.forEach(d=>{typeof d=="string"?t.appendChild(document.createTextNode(d)):Array.isArray(d)?d.forEach(h=>t.appendChild(h)):d instanceof HTMLElement&&t.appendChild(d)}),t}function g(){return new Promise((a,u)=>{var d,h,E,S,v,y,T,J,R,_;let s=[],t=[];if(!l||!i)return u(".SiteContent not found.");if(i instanceof HTMLElement&&!((d=i==null?void 0:i.dataset)!=null&&d.hydrate))return a(!0);for(let f of l.querySelectorAll(e))if(f instanceof HTMLElement&&!((h=f==null?void 0:f.dataset)!=null&&h.ignore))switch(f.tagName){case"H2":s=[...s,{id:f.id,label:(E=f==null?void 0:f.dataset)!=null&&E.title?f.dataset.title:(S=f.textContent)!=null?S:""}];break;case"H3":case"H4":(v=s[s.length-1])!=null&&v.subnav?s[s.length-1].subnav&&((_=s[s.length-1].subnav)==null||_.push({id:f.id,label:(J=f==null?void 0:f.dataset)!=null&&J.title?f.dataset.title:(R=f.textContent)!=null?R:""})):s[s.length-1].subnav=[{id:f.id,label:(y=f==null?void 0:f.dataset)!=null&&y.title?f.dataset.title:(T=f.textContent)!=null?T:""}];break}for(let f of s){let V=p("a",{href:"#"+f.id},p("span",{},f.label));if(t=[...t,V],f!=null&&f.subnav){let N=[];for(let K of f.subnav){let z=p("li",{},p("a",{href:"#"+K.id},p("img",{src:"/static/frontend/about/dot.svg",width:"5",height:"5"}),p("span",{},K.label)));N=[...N,z]}let X=p("ul",{className:"LeftSubnav"},N);t=[...t,X]}}return t.forEach(f=>i.appendChild(f)),a(!0)})}function w(){return new Promise(a=>{if(!document.querySelectorAll(o))return a(!0);for(let u of document.querySelectorAll(o))if(u instanceof HTMLAnchorElement&&u.href===location.href){b(u);break}a(!0)})}function L(){return new Promise(a=>{if(!document.querySelectorAll(o))return a(!0);for(let u of document.querySelectorAll(o))u.classList.remove("active");a(!0)})}function b(a){a instanceof HTMLAnchorElement&&L().then(()=>{var s,t,d;a.classList.add("active");let u=(s=a==null?void 0:a.parentNode)==null?void 0:s.parentNode;u instanceof HTMLElement&&((t=u==null?void 0:u.classList)==null?void 0:t.contains("LeftSubnav"))&&((d=u.previousElementSibling)==null||d.classList.add("active"))})}function M(){c();let a=document.querySelector('[href="'+location.hash+'"]');a instanceof HTMLAnchorElement&&b(a)}function c(){m=!0,setTimeout(()=>{m=!1},200)}function r(){var a;if(window.addEventListener("hashchange",M),l!=null&&l.querySelectorAll(e)){let u=t=>{if(!m&&Array.isArray(t)&&t.length>0){for(let d of t)if(d.isIntersecting&&d.target instanceof HTMLElement){let{id:h}=d.target,E=document.querySelector('[href="#'+h+'"]');E instanceof HTMLAnchorElement&&b(E);break}}},s=new IntersectionObserver(u,{threshold:0,rootMargin:"0px 0px -50% 0px"});for(let t of l.querySelectorAll(e))t instanceof HTMLElement&&!((a=t==null?void 0:t.dataset)!=null&&a.ignore)&&s.observe(t)}}try{await g(),await w(),location.hash&&c(),r()}catch(a){a instanceof Error?console.error(a.message):console.error(a)}};window.addEventListener("load",()=>{var n;for(let e of document.querySelectorAll(".js-clipboard"))new A(e);for(let e of document.querySelectorAll(".js-modal"))new C(e);for(let e of document.querySelectorAll(".js-tooltip"))new x(e);for(let e of document.querySelectorAll(".js-selectNav"))new q(e);for(let e of document.querySelectorAll(".js-carousel"))new k(e);for(let e of document.querySelectorAll(".js-toggleTheme"))e.addEventListener("click",()=>{Y()});((n=document.querySelector(".js-gtmID"))==null?void 0:n.dataset.gtmid)&&window.dataLayer?W(function(){B()}):B(),P(),U(),$(),G()});H.on("/","focus search",n=>{let e=Array.from(document.querySelectorAll(".js-searchFocus")).pop();e&&!window.navigator.userAgent.includes("Firefox")&&(n.preventDefault(),e.focus())});H.on("y","set canonical url",()=>{var e;let n=(e=document.querySelector(".js-canonicalURLPath"))==null?void 0:e.dataset.canonicalUrlPath;if(n&&n!==""){let o=window.location.hash;o&&(n+=o),window.history.replaceState(null,"",n)}});(function(){I({"gtm.start":new Date().getTime(),event:"gtm.js"})})();function B(){let n=new URLSearchParams(window.location.search),e=n.get("utm_source");if(e!=="gopls"&&e!=="godoc"&&e!=="pkggodev")return;let o=new URL(window.location.href);n.delete("utm_source"),o.search=n.toString(),window.history.replaceState(null,"",o.toString())}function Y(){let n="dark",e=document.documentElement.getAttribute("data-theme");e==="dark"?n="light":e==="light"&&(n="auto");let o="";location.hostname.endsWith("go.dev")&&(o="domain=.go.dev;"),document.documentElement.setAttribute("data-theme",n),document.cookie=`prefers-color-scheme=${n};${o}path=/;max-age=31536000;`}
/*!
* @license
* Copyright 2019-2020 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
/**
* @license
* Copyright 2020 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
/**
* @license
* Copyright 2021 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
/**
* @license
* Copyright 2022 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
//# sourceMappingURL=frontend.js.map