| var c=document.querySelector(".JumpDialog"),p=c==null?void 0:c.querySelector(".JumpDialog-body"),o=c==null?void 0:c.querySelector(".JumpDialog-list"),u=c==null?void 0:c.querySelector(".JumpDialog-input"),M=document.querySelector(".js-documentation"),h;function V(){let s=[];if(!!M){for(let e of M.querySelectorAll("[data-kind]"))s.push(J(e));for(let e of s)e.link.addEventListener("click",function(){c==null||c.close()});return s.sort(function(e,t){return e.lower.localeCompare(t.lower)}),s}}function J(s){var r;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!=null?t:"",kind:i!=null?i:"",lower:(r=t==null?void 0:t.toLowerCase())!=null?r:""}}var S,T=-1;function x(s){for(S=s,h||(h=V()),g(-1);o==null?void 0:o.firstChild;)o.firstChild.remove();if(s){let e=s.toLowerCase(),t=[],i=[],r=[],l=(n,a,d)=>n.name.substring(0,a)+"<b>"+n.name.substring(a,d)+"</b>"+n.name.substring(d);for(let n of h!=null?h:[]){let a=n.name.toLowerCase();if(a===e)n.link.innerHTML=l(n,0,n.name.length),t.push(n);else if(a.startsWith(e))n.link.innerHTML=l(n,0,s.length),i.push(n);else{let d=a.indexOf(e);d>-1&&(n.link.innerHTML=l(n,d,d+s.length),r.push(n))}}for(let n of t.concat(i).concat(r))o==null||o.appendChild(n.link)}else{if(!h||h.length===0){let e=document.createElement("i");e.innerHTML="There are no symbols on this page.",o==null||o.appendChild(e)}for(let e of h!=null?h:[])e.link.innerHTML=e.name+" <i>"+e.kind+"</i>",o==null||o.appendChild(e.link)}p&&(p.scrollTop=0),(h==null?void 0:h.length)&&o&&o.children.length>0&&g(0)}function g(s){let e=o==null?void 0:o.children;if(!(!e||!p)){if(T>=0&&e[T].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<p.scrollTop?p.scrollTop=t:i>p.scrollTop+p.clientHeight&&(p.scrollTop=i-p.clientHeight)}T=s}}function H(s){if(T<0)return;let e=T+s;e<0&&(e=0),g(e)}u==null||u.addEventListener("keyup",function(){u.value.toUpperCase()!=S.toUpperCase()&&x(u.value)});u==null||u.addEventListener("keydown",function(s){let e=38,t=40,i=13;switch(s.which){case e:H(-1),s.preventDefault();break;case t:H(1),s.preventDefault();break;case i:T>=0&&o&&(o.children[T].click(),s.preventDefault());break}});var E=document.querySelector(".ShortcutsDialog");document.addEventListener("keypress",function(s){if((c==null?void 0:c.open)||(E==null?void 0:E.open))return;let e=s.target,t=e==null?void 0:e.tagName;if(t=="INPUT"||t=="SELECT"||t=="TEXTAREA"||(e==null?void 0:e.contentEditable)=="true"||s.metaKey||s.ctrlKey)return;switch(String.fromCharCode(s.which)){case"f":case"F":s.preventDefault(),u&&(u.value=""),c==null||c.showModal(),u==null||u.focus(),x("");break;case"?":E==null||E.showModal();break}});var O=document.querySelector(".js-jumpToInput");O&&O.addEventListener("click",()=>{u&&(u.value=""),x("")});var f={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"},B=class{constructor(e){this.exampleEl=e;var t,i,r,l;this.exampleEl=e,this.anchorEl=e.querySelector("a"),this.errorEl=e.querySelector(f.EXAMPLE_ERROR),this.playButtonEl=e.querySelector(f.PLAY_BUTTON),this.shareButtonEl=e.querySelector(f.SHARE_BUTTON),this.formatButtonEl=e.querySelector(f.FORMAT_BUTTON),this.runButtonEl=e.querySelector(f.RUN_BUTTON),this.inputEl=this.makeTextArea(e.querySelector(f.EXAMPLE_INPUT)),this.outputEl=e.querySelector(f.EXAMPLE_OUTPUT),(t=this.playButtonEl)==null||t.addEventListener("click",()=>this.handleShareButtonClick()),(i=this.shareButtonEl)==null||i.addEventListener("click",()=>this.handleShareButtonClick()),(r=this.formatButtonEl)==null||r.addEventListener("click",()=>this.handleFormatButtonClick()),(l=this.runButtonEl)==null||l.addEventListener("click",()=>this.handleRunButtonClick()),!!this.inputEl&&(this.resize(),this.inputEl.addEventListener("keyup",()=>this.resize()),this.inputEl.addEventListener("keydown",n=>this.onKeydown(n)))}makeTextArea(e){var i,r;let t=document.createElement("textarea");return t.classList.add("Documentation-exampleCode","code"),t.spellcheck=!1,t.value=(i=e==null?void 0:e.textContent)!=null?i:"",(r=e==null?void 0:e.parentElement)==null||r.replaceChild(t,e),t}getAnchorHash(){var e;return(e=this.anchorEl)==null?void 0:e.hash}expand(){this.exampleEl.open=!0}resize(){var e;if((e=this.inputEl)==null?void 0:e.value){let t=(this.inputEl.value.match(/\n/g)||[]).length;this.inputEl.style.height=`${(20+t*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(){var t;let e="https://play.golang.org/p/";this.setOutputText("Waiting for remote server\u2026"),fetch("/play/share",{method:"POST",body:(t=this.inputEl)==null?void 0:t.value}).then(i=>i.text()).then(i=>{let r=e+i;this.setOutputText(`<a href="${r}">${r}</a>`),window.open(r)}).catch(i=>{this.setErrorText(i)})}handleFormatButtonClick(){var t,i;this.setOutputText("Waiting for remote server\u2026");let e=new FormData;e.append("body",(i=(t=this.inputEl)==null?void 0:t.value)!=null?i:""),fetch("/play/fmt",{method:"POST",body:e}).then(r=>r.json()).then(({Body:r,Error:l})=>{this.setOutputText(l||"Done."),r&&(this.setInputText(r),this.resize())}).catch(r=>{this.setErrorText(r)})}handleRunButtonClick(){var e;this.setOutputText("Waiting for remote server\u2026"),fetch("/play/compile",{method:"POST",body:JSON.stringify({body:(e=this.inputEl)==null?void 0:e.value,version:2})}).then(t=>t.json()).then(async({Events:t,Errors:i})=>{this.setOutputText(i||"");for(let r of t||[])this.setOutputText(r.Message),await new Promise(l=>setTimeout(l,r.Delay/1e6))}).catch(t=>{this.setErrorText(t)})}},R=location.hash.match(/^#(example-.*)$/);if(R){let s=document.getElementById(R[1]);s&&(s.open=!0)}var K=[...document.querySelectorAll(f.PLAY_HREF)],$=s=>K.find(e=>e.hash===s.getAnchorHash());for(let s of document.querySelectorAll(f.PLAY_CONTAINER)){let e=new B(s),t=$(e);t?t.addEventListener("click",()=>{e.expand()}):console.warn("example href not found")}var L=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 N(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={},l;for(let n of s.treeitems){if(Number(n.depth)>4)continue;n.groupTreeitem?(l=r[n.groupTreeitem.label],l||(l=r[n.groupTreeitem.label]=document.createElement("optgroup"),l.label=n.groupTreeitem.label,t.appendChild(l))):l=i;let a=document.createElement("option");a.label=n.label,a.textContent=n.label,a.value=n.el.href.replace(window.location.origin,"").replace("/",""),l.appendChild(a)}return s.addObserver(n=>{var b;let a=n.el.hash,d=(b=t.querySelector(`[value$="${a}"]`))==null?void 0:b.value;d&&(t.value=d)},50),e}var y=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,l]of e)if(l){let n=this.treeitems.find(a=>{var d;return(d=a.el)==null?void 0:d.href.endsWith(`#${r}`)});if(n)for(let a of this.observerCallbacks)a(n);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("#",""),l=document.getElementById(r);l&&t.observe(l)}}addObserver(e,t=200){this.observerCallbacks.push(G(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){var t;for(let i of this.el.querySelectorAll('[aria-expanded="true"]'))i!==e.el&&(((t=i.nextElementSibling)==null?void 0:t.contains(e.el))||i.setAttribute("aria-expanded","false"));for(let i of this.el.querySelectorAll("[aria-selected]"))i!==e.el&&i.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,l=t.firstElementChild;for(;l;)(l.tagName==="A"||l.tagName==="SPAN")&&(r=new q(l,this,i),this.treeitems.push(r),this.firstChars.push(r.label.substring(0,1).toLowerCase())),l.firstElementChild&&e(l,r),l=l.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}},q=class{constructor(e,t,i){var n,a,d,b,w;e.tabIndex=-1,this.el=e,this.groupTreeitem=i,this.label=(a=(n=e.textContent)==null?void 0:n.trim())!=null?a:"",this.tree=t,this.depth=((i==null?void 0:i.depth)||0)+1,this.index=0;let r=e.parentElement;(r==null?void 0:r.tagName.toLowerCase())==="li"&&(r==null||r.setAttribute("role","none")),e.setAttribute("aria-level",this.depth+""),e.getAttribute("aria-label")&&(this.label=(b=(d=e==null?void 0:e.getAttribute("aria-label"))==null?void 0:d.trim())!=null?b:""),this.isExpandable=!1,this.isVisible=!1,this.isInGroup=!!i;let l=e.nextElementSibling;for(;l;){if(l.tagName.toLowerCase()=="ul"){let I=`${(w=i==null?void 0:i.label)!=null?w:""} nav group ${this.label}`.replace(/[\W_]+/g,"_");e.setAttribute("aria-owns",I),e.setAttribute("aria-expanded","false"),l.setAttribute("role","group"),l.setAttribute("id",I),this.isExpandable=!0;break}l=l.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(){var t;let e=this.el;this.isExpandable&&(e=(t=e.firstElementChild)!=null?t:e),e.classList.add("focus")}handleBlur(){var t;let e=this.el;this.isExpandable&&(e=(t=e.firstElementChild)!=null?t: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 G(s,e){let t;return(...i)=>{let r=()=>{t=null,s(...i)};t&&clearTimeout(t),t=setTimeout(r,e)}}var A=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=>{var i;t.setAttribute(e.replace("data-",""),(i=t.getAttribute(e))!=null?i:""),t.removeAttribute(e)})}attachEventListeners(){var e;this.rows.forEach(t=>{t.addEventListener("click",i=>{this.handleToggleClick(i)})}),(e=this.toggleAll)==null||e.addEventListener("click",()=>{this.expandAllItems()}),document.addEventListener("keydown",t=>{(t.ctrlKey||t.metaKey)&&t.key==="f"&&this.expandAllItems()})}handleToggleClick(e){let t=e.currentTarget;(t==null?void 0:t.hasAttribute("aria-expanded"))||(t=this.table.querySelector(`button[aria-controls="${t==null?void 0:t.getAttribute("aria-controls")}"]`));let i=(t==null?void 0:t.getAttribute("aria-expanded"))==="true";t==null||t.setAttribute("aria-expanded",i?"false":"true"),e.stopPropagation(),this.update()}updateVisibleItems(){this.rows.map(e=>{var r;let t=(e==null?void 0:e.getAttribute("aria-expanded"))==="true",i=(r=e==null?void 0:e.getAttribute("aria-controls"))==null?void 0:r.trimEnd().split(" ");i==null||i.map(l=>{let n=document.getElementById(`${l}`);t?(n==null||n.classList.add("visible"),n==null||n.classList.remove("hidden")):(n==null||n.classList.add("hidden"),n==null||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 F=document.querySelector(".js-expandableTable");if(F){let s=new A(F,document.querySelector(".js-expandAllDirectories"));window.location.search.includes("expand-directories")&&s.expandAllItems()}var P=document.querySelector(".js-tree");if(P){let s=new y(P),e=N(s),t=document.querySelector(".js-mainNavMobile");t&&t.firstElementChild&&(t==null||t.replaceChild(e,t.firstElementChild)),e.firstElementChild&&new L(e.firstElementChild)}var m=document.querySelector(".js-readme"),C=document.querySelector(".js-readmeContent"),U=document.querySelector(".js-readmeOutline"),v=document.querySelectorAll(".js-readmeExpand"),D=document.querySelector(".js-readmeCollapse"),k=document.querySelector(".DocNavMobile-select");m&&C&&U&&v.length&&D&&(window.location.hash.includes("readme")&&m.classList.add("UnitReadme--expanded"),k==null||k.addEventListener("change",s=>{s.target.value.startsWith("readme-")&&m.classList.add("UnitReadme--expanded")}),v.forEach(s=>s.addEventListener("click",e=>{e.preventDefault(),m.classList.add("UnitReadme--expanded"),m.scrollIntoView()})),D.addEventListener("click",s=>{s.preventDefault(),m.classList.remove("UnitReadme--expanded"),v[1]&&v[1].scrollIntoView({block:"center"})}),C.addEventListener("keyup",()=>{m.classList.add("UnitReadme--expanded")}),C.addEventListener("click",()=>{m.classList.add("UnitReadme--expanded")}),U.addEventListener("click",()=>{m.classList.add("UnitReadme--expanded")}),document.addEventListener("keydown",s=>{(s.ctrlKey||s.metaKey)&&s.key==="f"&&m.classList.add("UnitReadme--expanded")}));function _(){var t;if(!location.hash)return;let s=document.getElementById(location.hash.slice(1)),e=(t=s==null?void 0:s.parentElement)==null?void 0:t.parentElement;(e==null?void 0:e.nodeName)==="DETAILS"&&(e.open=!0)}_();window.addEventListener("hashchange",()=>_());document.querySelectorAll(".js-buildContextSelect").forEach(s=>{s.addEventListener("change",e=>{window.location.search=`?GOOS=${e.target.value}`})}); |