blob: e169123fff82adbaf3f9d982b02996093ee0b39c [file] [log] [blame]
(()=>{var T=document.querySelector(".JumpDialog"),u=T?.querySelector(".JumpDialog-body"),o=T?.querySelector(".JumpDialog-list"),h=T?.querySelector(".JumpDialog-input"),A=document.querySelector(".js-documentation"),p;function q(){let s=[];if(!!A){for(let e of A.querySelectorAll("[data-kind]"))s.push(P(e));for(let e of s)e.link.addEventListener("click",function(){T?.close()});return s.sort(function(e,t){return e.lower.localeCompare(t.lower)}),s}}function P(s){let e=document.createElement("a"),t=s.getAttribute("id");e.setAttribute("href","#"+t),e.setAttribute("tabindex","-1"),e.setAttribute("data-gtmc","jump to link");let i=s.getAttribute("data-kind");return{link:e,name:t??"",kind:i??"",lower:t?.toLowerCase()??""}}var k,f=-1;function g(s){for(k=s,p||(p=q()),b(-1);o?.firstChild;)o.firstChild.remove();if(s){let e=s.toLowerCase(),t=[],i=[],r=[],n=(l,a,d)=>l.name.substring(0,a)+"<b>"+l.name.substring(a,d)+"</b>"+l.name.substring(d);for(let l of p??[]){let a=l.name.toLowerCase();if(a===e)l.link.innerHTML=n(l,0,l.name.length),t.push(l);else if(a.startsWith(e))l.link.innerHTML=n(l,0,s.length),i.push(l);else{let d=a.indexOf(e);d>-1&&(l.link.innerHTML=n(l,d,d+s.length),r.push(l))}}for(let l of t.concat(i).concat(r))o?.appendChild(l.link)}else{if(!p||p.length===0){let e=document.createElement("i");e.innerHTML="There are no symbols on this page.",o?.appendChild(e)}for(let e of p??[])e.link.innerHTML=e.name+" <i>"+e.kind+"</i>",o?.appendChild(e.link)}u&&(u.scrollTop=0),p?.length&&o&&o.children.length>0&&b(0)}function b(s){let e=o?.children;if(!(!e||!u)){if(f>=0&&e[f].classList.remove("JumpDialog-active"),s>=e.length&&(s=e.length-1),s>=0){e[s].classList.add("JumpDialog-active");let t=e[s].offsetTop-e[0].offsetTop,i=t+e[s].clientHeight;t<u.scrollTop?u.scrollTop=t:i>u.scrollTop+u.clientHeight&&(u.scrollTop=i-u.clientHeight)}f=s}}function C(s){if(f<0)return;let e=f+s;e<0&&(e=0),b(e)}h?.addEventListener("keyup",function(){h.value.toUpperCase()!=k.toUpperCase()&&g(h.value)});h?.addEventListener("keydown",function(s){let e=38,t=40,i=13;switch(s.which){case e:C(-1),s.preventDefault();break;case t:C(1),s.preventDefault();break;case i:f>=0&&o&&(o.children[f].click(),s.preventDefault());break}});var I=document.querySelector(".ShortcutsDialog");document.addEventListener("keypress",function(s){if(T?.open||I?.open)return;let e=s.target,t=e?.tagName;if(t=="INPUT"||t=="SELECT"||t=="TEXTAREA"||e?.contentEditable=="true"||s.metaKey||s.ctrlKey)return;switch(String.fromCharCode(s.which)){case"f":case"F":s.preventDefault(),h&&(h.value=""),T?.showModal(),h?.focus(),g("");break;case"?":I?.showModal();break}});var w=document.querySelector(".js-jumpToInput");w&&w.addEventListener("click",()=>{h&&(h.value=""),g("")});var m={PLAY_HREF:".js-exampleHref",PLAY_CONTAINER:".js-exampleContainer",EXAMPLE_INPUT:".Documentation-exampleCode",EXAMPLE_OUTPUT:".Documentation-exampleOutput",EXAMPLE_ERROR:".Documentation-exampleError",PLAY_BUTTON:".Documentation-examplePlayButton",SHARE_BUTTON:".Documentation-exampleShareButton",FORMAT_BUTTON:".Documentation-exampleFormatButton",RUN_BUTTON:".Documentation-exampleRunButton"},S=class{constructor(e){this.exampleEl=e;this.exampleEl=e,this.anchorEl=e.querySelector("a"),this.errorEl=e.querySelector(m.EXAMPLE_ERROR),this.playButtonEl=e.querySelector(m.PLAY_BUTTON),this.shareButtonEl=e.querySelector(m.SHARE_BUTTON),this.formatButtonEl=e.querySelector(m.FORMAT_BUTTON),this.runButtonEl=e.querySelector(m.RUN_BUTTON),this.inputEl=this.makeTextArea(e.querySelector(m.EXAMPLE_INPUT)),this.outputEl=e.querySelector(m.EXAMPLE_OUTPUT),this.playButtonEl?.addEventListener("click",()=>this.handleShareButtonClick()),this.shareButtonEl?.addEventListener("click",()=>this.handleShareButtonClick()),this.formatButtonEl?.addEventListener("click",()=>this.handleFormatButtonClick()),this.runButtonEl?.addEventListener("click",()=>this.handleRunButtonClick()),!!this.inputEl&&(this.resize(),this.inputEl.addEventListener("keyup",()=>this.resize()),this.inputEl.addEventListener("keydown",t=>this.onKeydown(t)))}makeTextArea(e){let t=document.createElement("textarea");return t.classList.add("Documentation-exampleCode","code"),t.spellcheck=!1,t.value=e?.textContent??"",e?.parentElement?.replaceChild(t,e),t}getAnchorHash(){return this.anchorEl?.hash}expand(){this.exampleEl.open=!0}resize(){if(this.inputEl?.value){let e=(this.inputEl.value.match(/\n/g)||[]).length;this.inputEl.style.height=`${(20+e*20+12+2)/16}rem`}}onKeydown(e){e.key==="Tab"&&(document.execCommand("insertText",!1," "),e.preventDefault())}setInputText(e){this.inputEl&&(this.inputEl.value=e)}setOutputText(e){this.outputEl&&(this.outputEl.textContent=e)}setErrorText(e){this.errorEl&&(this.errorEl.textContent=e),this.setOutputText("An error has occurred\u2026")}handleShareButtonClick(){let e="https://play.golang.org/p/";this.setOutputText("Waiting for remote server\u2026"),fetch("/play/share",{method:"POST",body:this.inputEl?.value}).then(t=>t.text()).then(t=>{let i=e+t;this.setOutputText(`<a href="${i}">${i}</a>`),window.open(i)}).catch(t=>{this.setErrorText(t)})}handleFormatButtonClick(){this.setOutputText("Waiting for remote server\u2026");let e=new FormData;e.append("body",this.inputEl?.value??""),fetch("/play/fmt",{method:"POST",body:e}).then(t=>t.json()).then(({Body:t,Error:i})=>{this.setOutputText(i||"Done."),t&&(this.setInputText(t),this.resize())}).catch(t=>{this.setErrorText(t)})}handleRunButtonClick(){this.setOutputText("Waiting for remote server\u2026"),fetch("/play/compile",{method:"POST",body:JSON.stringify({body:this.inputEl?.value,version:2})}).then(e=>e.json()).then(async({Events:e,Errors:t})=>{this.setOutputText(t||"");for(let i of e||[])this.setOutputText(i.Message),await new Promise(r=>setTimeout(r,i.Delay/1e6))}).catch(e=>{this.setErrorText(e)})}},M=location.hash.match(/^#(example-.*)$/);if(M){let s=document.getElementById(M[1]);s&&(s.open=!0)}var j=[...document.querySelectorAll(m.PLAY_HREF)],U=s=>j.find(e=>e.hash===s.getAnchorHash());for(let s of document.querySelectorAll(m.PLAY_CONTAINER)){let e=new S(s),t=U(e);t?t.addEventListener("click",()=>{e.expand()}):console.warn("example href not found")}var v=class{constructor(e){this.el=e;this.el.addEventListener("change",t=>{let i=t.target,r=i.value;i.value.startsWith("/")||(r="/"+r),window.location.href=r})}};function H(s){let e=document.createElement("label");e.classList.add("go-Label"),e.setAttribute("aria-label","Menu");let t=document.createElement("select");t.classList.add("go-Select","js-selectNav"),e.appendChild(t);let i=document.createElement("optgroup");i.label="Outline",t.appendChild(i);let r={},n;for(let l of s.treeitems){if(Number(l.depth)>4)continue;l.groupTreeitem?(n=r[l.groupTreeitem.label],n||(n=r[l.groupTreeitem.label]=document.createElement("optgroup"),n.label=l.groupTreeitem.label,t.appendChild(n))):n=i;let a=document.createElement("option");a.label=l.label,a.textContent=l.label,a.value=l.el.href.replace(window.location.origin,"").replace("/",""),n.appendChild(a)}return s.addObserver(l=>{let a=l.el.hash,d=t.querySelector(`[value$="${a}"]`)?.value;d&&(t.value=d)},50),e}var x=class{constructor(e){this.el=e;this.handleResize=()=>{this.el.style.setProperty("--js-tree-height","100vh"),this.el.style.setProperty("--js-tree-height",this.el.clientHeight+"px")};this.treeitems=[],this.firstChars=[],this.firstTreeitem=null,this.lastTreeitem=null,this.observerCallbacks=[],this.init()}init(){this.handleResize(),window.addEventListener("resize",this.handleResize),this.findTreeItems(),this.updateVisibleTreeitems(),this.observeTargets(),this.firstTreeitem&&(this.firstTreeitem.el.tabIndex=0)}observeTargets(){this.addObserver(i=>{this.expandTreeitem(i),this.setSelected(i)});let e=new Map,t=new IntersectionObserver(i=>{for(let r of i)e.set(r.target.id,r.isIntersecting||r.intersectionRatio===1);for(let[r,n]of e)if(n){let l=this.treeitems.find(a=>a.el?.href.endsWith(`#${r}`));if(l)for(let a of this.observerCallbacks)a(l);break}},{threshold:1,rootMargin:"-60px 0px 0px 0px"});for(let i of this.treeitems.map(r=>r.el.getAttribute("href")))if(i){let r=i.replace(window.location.origin,"").replace("/","").replace("#",""),n=document.getElementById(r);n&&t.observe(n)}}addObserver(e,t=200){this.observerCallbacks.push(_(e,t))}setFocusToNextItem(e){let t=null;for(let i=e.index+1;i<this.treeitems.length;i++){let r=this.treeitems[i];if(r.isVisible){t=r;break}}t&&this.setFocusToItem(t)}setFocusToPreviousItem(e){let t=null;for(let i=e.index-1;i>-1;i--){let r=this.treeitems[i];if(r.isVisible){t=r;break}}t&&this.setFocusToItem(t)}setFocusToParentItem(e){e.groupTreeitem&&this.setFocusToItem(e.groupTreeitem)}setFocusToFirstItem(){this.firstTreeitem&&this.setFocusToItem(this.firstTreeitem)}setFocusToLastItem(){this.lastTreeitem&&this.setFocusToItem(this.lastTreeitem)}setSelected(e){for(let t of this.el.querySelectorAll('[aria-expanded="true"]'))t!==e.el&&(t.nextElementSibling?.contains(e.el)||t.setAttribute("aria-expanded","false"));for(let t of this.el.querySelectorAll("[aria-selected]"))t!==e.el&&t.setAttribute("aria-selected","false");e.el.setAttribute("aria-selected","true"),this.updateVisibleTreeitems(),this.setFocusToItem(e,!1)}expandTreeitem(e){let t=e;for(;t;)t.isExpandable&&t.el.setAttribute("aria-expanded","true"),t=t.groupTreeitem;this.updateVisibleTreeitems()}expandAllSiblingItems(e){for(let t of this.treeitems)t.groupTreeitem===e.groupTreeitem&&t.isExpandable&&this.expandTreeitem(t)}collapseTreeitem(e){let t=null;e.isExpanded()?t=e:t=e.groupTreeitem,t&&(t.el.setAttribute("aria-expanded","false"),this.updateVisibleTreeitems(),this.setFocusToItem(t))}setFocusByFirstCharacter(e,t){let i,r;t=t.toLowerCase(),i=e.index+1,i===this.treeitems.length&&(i=0),r=this.getIndexFirstChars(i,t),r===-1&&(r=this.getIndexFirstChars(0,t)),r>-1&&this.setFocusToItem(this.treeitems[r])}findTreeItems(){let e=(t,i)=>{let r=i,n=t.firstElementChild;for(;n;)(n.tagName==="A"||n.tagName==="SPAN")&&(r=new O(n,this,i),this.treeitems.push(r),this.firstChars.push(r.label.substring(0,1).toLowerCase())),n.firstElementChild&&e(n,r),n=n.nextElementSibling};e(this.el,null),this.treeitems.map((t,i)=>t.index=i)}updateVisibleTreeitems(){this.firstTreeitem=this.treeitems[0];for(let e of this.treeitems){let t=e.groupTreeitem;for(e.isVisible=!0;t&&t.el!==this.el;)t.isExpanded()||(e.isVisible=!1),t=t.groupTreeitem;e.isVisible&&(this.lastTreeitem=e)}}setFocusToItem(e,t=!0){e.el.tabIndex=0,t&&e.el.focus();for(let i of this.treeitems)i!==e&&(i.el.tabIndex=-1)}getIndexFirstChars(e,t){for(let i=e;i<this.firstChars.length;i++)if(this.treeitems[i].isVisible&&t===this.firstChars[i])return i;return-1}},O=class{constructor(e,t,i){e.tabIndex=-1,this.el=e,this.groupTreeitem=i,this.label=e.textContent?.trim()??"",this.tree=t,this.depth=(i?.depth||0)+1,this.index=0;let r=e.parentElement;r?.tagName.toLowerCase()==="li"&&r?.setAttribute("role","none"),e.setAttribute("aria-level",this.depth+""),e.getAttribute("aria-label")&&(this.label=e?.getAttribute("aria-label")?.trim()??""),this.isExpandable=!1,this.isVisible=!1,this.isInGroup=!!i;let n=e.nextElementSibling;for(;n;){if(n.tagName.toLowerCase()=="ul"){let l=`${i?.label??""} nav group ${this.label}`.replace(/[\W_]+/g,"_");e.setAttribute("aria-owns",l),e.setAttribute("aria-expanded","false"),n.setAttribute("role","group"),n.setAttribute("id",l),this.isExpandable=!0;break}n=n.nextElementSibling}this.init()}init(){this.el.tabIndex=-1,this.el.getAttribute("role")||this.el.setAttribute("role","treeitem"),this.el.addEventListener("keydown",this.handleKeydown.bind(this)),this.el.addEventListener("click",this.handleClick.bind(this)),this.el.addEventListener("focus",this.handleFocus.bind(this)),this.el.addEventListener("blur",this.handleBlur.bind(this))}isExpanded(){return this.isExpandable?this.el.getAttribute("aria-expanded")==="true":!1}isSelected(){return this.el.getAttribute("aria-selected")==="true"}handleClick(e){e.target!==this.el&&e.target!==this.el.firstElementChild||(this.isExpandable&&(this.isExpanded()&&this.isSelected()?this.tree.collapseTreeitem(this):this.tree.expandTreeitem(this),e.stopPropagation()),this.tree.setSelected(this))}handleFocus(){let e=this.el;this.isExpandable&&(e=e.firstElementChild??e),e.classList.add("focus")}handleBlur(){let e=this.el;this.isExpandable&&(e=e.firstElementChild??e),e.classList.remove("focus")}handleKeydown(e){if(e.altKey||e.ctrlKey||e.metaKey)return;let t=!1;switch(e.key){case" ":case"Enter":this.isExpandable?(this.isExpanded()&&this.isSelected()?this.tree.collapseTreeitem(this):this.tree.expandTreeitem(this),t=!0):e.stopPropagation(),this.tree.setSelected(this);break;case"ArrowUp":this.tree.setFocusToPreviousItem(this),t=!0;break;case"ArrowDown":this.tree.setFocusToNextItem(this),t=!0;break;case"ArrowRight":this.isExpandable&&(this.isExpanded()?this.tree.setFocusToNextItem(this):this.tree.expandTreeitem(this)),t=!0;break;case"ArrowLeft":this.isExpandable&&this.isExpanded()?(this.tree.collapseTreeitem(this),t=!0):this.isInGroup&&(this.tree.setFocusToParentItem(this),t=!0);break;case"Home":this.tree.setFocusToFirstItem(),t=!0;break;case"End":this.tree.setFocusToLastItem(),t=!0;break;default:e.key.length===1&&e.key.match(/\S/)&&(e.key=="*"?this.tree.expandAllSiblingItems(this):this.tree.setFocusByFirstCharacter(this,e.key),t=!0);break}t&&(e.stopPropagation(),e.preventDefault())}};function _(s,e){let t;return(...i)=>{let r=()=>{t=null,s(...i)};t&&clearTimeout(t),t=setTimeout(r,e)}}var L=class{constructor(e,t){this.table=e;this.toggleAll=t;this.expandAllItems=()=>{this.toggles.map(e=>e.setAttribute("aria-expanded","true")),this.update()};this.collapseAllItems=()=>{this.toggles.map(e=>e.setAttribute("aria-expanded","false")),this.update()};this.update=()=>{this.updateVisibleItems(),setTimeout(()=>this.updateGlobalToggle())};this.rows=Array.from(e.querySelectorAll("[data-aria-controls]")),this.toggles=Array.from(this.table.querySelectorAll("[aria-expanded]")),this.setAttributes(),this.attachEventListeners(),this.update()}setAttributes(){for(let e of["data-aria-controls","data-aria-labelledby","data-id"])this.table.querySelectorAll(`[${e}]`).forEach(t=>{t.setAttribute(e.replace("data-",""),t.getAttribute(e)??""),t.removeAttribute(e)})}attachEventListeners(){this.rows.forEach(e=>{e.addEventListener("click",t=>{this.handleToggleClick(t)})}),this.toggleAll?.addEventListener("click",()=>{this.expandAllItems()}),document.addEventListener("keydown",e=>{(e.ctrlKey||e.metaKey)&&e.key==="f"&&this.expandAllItems()})}handleToggleClick(e){let t=e.currentTarget;t?.hasAttribute("aria-expanded")||(t=this.table.querySelector(`button[aria-controls="${t?.getAttribute("aria-controls")}"]`));let i=t?.getAttribute("aria-expanded")==="true";t?.setAttribute("aria-expanded",i?"false":"true"),e.stopPropagation(),this.update()}updateVisibleItems(){this.rows.map(e=>{let t=e?.getAttribute("aria-expanded")==="true";e?.getAttribute("aria-controls")?.trimEnd().split(" ")?.map(r=>{let n=document.getElementById(`${r}`);t?(n?.classList.add("visible"),n?.classList.remove("hidden")):(n?.classList.add("hidden"),n?.classList.remove("visible"))})})}updateGlobalToggle(){if(!this.toggleAll)return;this.rows.some(t=>t.hasAttribute("aria-expanded"))&&(this.toggleAll.style.display="block"),this.toggles.some(t=>t.getAttribute("aria-expanded")==="false")?(this.toggleAll.innerText="Expand all",this.toggleAll.onclick=this.expandAllItems):(this.toggleAll.innerText="Collapse all",this.toggleAll.onclick=this.collapseAllItems)}};var B=document.querySelector(".js-expandableTable");if(B){let s=new L(B,document.querySelector(".js-expandAllDirectories"));window.location.search.includes("expand-directories")&&s.expandAllItems()}var N=document.querySelector(".js-tree");if(N){let s=new x(N),e=H(s),t=document.querySelector(".js-mainNavMobile");t&&t.firstElementChild&&t?.replaceChild(e,t.firstElementChild),e.firstElementChild&&new v(e.firstElementChild)}var c=document.querySelector(".js-readme"),y=document.querySelector(".js-readmeContent"),D=document.querySelector(".js-readmeOutline"),E=document.querySelectorAll(".js-readmeExpand"),F=document.querySelector(".js-readmeCollapse"),V=document.querySelector(".DocNavMobile-select");c&&y&&D&&E.length&&F&&(window.location.hash.includes("readme")&&c.classList.add("UnitReadme--expanded"),V?.addEventListener("change",s=>{s.target.value.startsWith("readme-")&&c.classList.add("UnitReadme--expanded")}),E.forEach(s=>s.addEventListener("click",e=>{e.preventDefault(),c.classList.add("UnitReadme--expanded"),c.scrollIntoView()})),F.addEventListener("click",s=>{s.preventDefault(),c.classList.remove("UnitReadme--expanded"),E[1]&&E[1].scrollIntoView({block:"center"})}),y.addEventListener("keyup",()=>{c.classList.add("UnitReadme--expanded")}),y.addEventListener("click",()=>{c.classList.add("UnitReadme--expanded")}),D.addEventListener("click",()=>{c.classList.add("UnitReadme--expanded")}),document.addEventListener("keydown",s=>{(s.ctrlKey||s.metaKey)&&s.key==="f"&&c.classList.add("UnitReadme--expanded")}));function R(){if(!location.hash)return;let e=document.querySelector(location.hash)?.parentElement?.parentElement;e?.nodeName==="DETAILS"&&(e.open=!0)}R();window.addEventListener("hashchange",()=>R());document.querySelectorAll(".js-buildContextSelect").forEach(s=>{s.addEventListener("change",e=>{window.location.search=`?GOOS=${e.target.value}`})});})();
/*!
* @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 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.
*/
//# sourceMappingURL=main.js.map