blob: 4fb7a8847bf5273d6c3b9715c8ec5997229a935c [file] [log] [blame]
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"},I=class{constructor(e){this.exampleEl=e;var t,i,s,l;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),(t=this.playButtonEl)==null||t.addEventListener("click",()=>this.handleShareButtonClick()),(i=this.shareButtonEl)==null||i.addEventListener("click",()=>this.handleShareButtonClick()),(s=this.formatButtonEl)==null||s.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",r=>this.onKeydown(r)))}makeTextArea(e){var i,s;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:"",(s=e==null?void 0:e.parentElement)==null||s.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 s=e+i;this.setOutputText(`<a href="${s}">${s}</a>`),window.open(s)}).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(s=>s.json()).then(({Body:s,Error:l})=>{this.setOutputText(l||"Done."),s&&(this.setInputText(s),this.resize())}).catch(s=>{this.setErrorText(s)})}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 s of t||[])this.setOutputText(s.Message),await new Promise(l=>setTimeout(l,s.Delay/1e6))}).catch(t=>{this.setErrorText(t)})}};function S(){let n=location.hash.match(/^#(example-.*)$/);if(n){let i=document.getElementById(n[1]);i&&(i.open=!0)}let e=[...document.querySelectorAll(m.PLAY_HREF)],t=i=>e.find(s=>s.hash===i.getAnchorHash());for(let i of document.querySelectorAll(m.PLAY_CONTAINER)){let s=new I(i),l=t(s);l?l.addEventListener("click",()=>{s.expand()}):console.warn("example href not found")}}function H(n,e,t,i){var s;(s=window.dataLayer)!=null||(window.dataLayer=[]),typeof n=="string"?window.dataLayer.push({event:n,event_category:e,event_action:t,event_label:i}):window.dataLayer.push(n)}var O=class{constructor(){this.handlers={},document.addEventListener("keydown",e=>this.handleKeyPress(e))}on(e,t,i,s){var l,r;return(r=(l=this.handlers)[e])!=null||(l[e]=new Set),this.handlers[e].add({description:t,callback:i,...s}),this}handleKeyPress(e){var t;for(let i of(t=this.handlers[e.key.toLowerCase()])!=null?t:new Set){if(i.target&&i.target!==e.target)return;let s=e.target;if(!i.target&&((s==null?void 0:s.tagName)==="INPUT"||(s==null?void 0:s.tagName)==="SELECT"||(s==null?void 0:s.tagName)==="TEXTAREA")||(s==null?void 0:s.isContentEditable)||i.withMeta&&!(e.ctrlKey||e.metaKey)||!i.withMeta&&(e.ctrlKey||e.metaKey))return;H("keypress","hotkeys",`${e.key} pressed`,i.description),i.callback(e)}}},B=new O;var a=document.querySelector(".JumpDialog"),p=a==null?void 0:a.querySelector(".JumpDialog-body"),c=a==null?void 0:a.querySelector(".JumpDialog-list"),u=a==null?void 0:a.querySelector(".JumpDialog-input"),N=document.querySelector(".js-documentation"),h;function $(){let n=[];if(!!N){for(let e of N.querySelectorAll("[data-kind]"))n.push(G(e));for(let e of n)e.link.addEventListener("click",function(){a==null||a.close()});return n.sort(function(e,t){return e.lower.localeCompare(t.lower)}),n}}function G(n){var s;let e=document.createElement("a"),t=n.getAttribute("id");e.setAttribute("href","#"+t),e.setAttribute("tabindex","-1"),e.setAttribute("data-gtmc","jump to link");let i=n.getAttribute("data-kind");return{link:e,name:t!=null?t:"",kind:i!=null?i:"",lower:(s=t==null?void 0:t.toLowerCase())!=null?s:""}}var P,f=-1;function g(n){for(P=n,h||(h=$()),x(-1);c==null?void 0:c.firstChild;)c.firstChild.remove();if(n){let e=n.toLowerCase(),t=[],i=[],s=[],l=(r,o,d)=>r.name.substring(0,o)+"<b>"+r.name.substring(o,d)+"</b>"+r.name.substring(d);for(let r of h!=null?h:[]){let o=r.name.toLowerCase();if(o===e)r.link.innerHTML=l(r,0,r.name.length),t.push(r);else if(o.startsWith(e))r.link.innerHTML=l(r,0,n.length),i.push(r);else{let d=o.indexOf(e);d>-1&&(r.link.innerHTML=l(r,d,d+n.length),s.push(r))}}for(let r of t.concat(i).concat(s))c==null||c.appendChild(r.link)}else{if(!h||h.length===0){let e=document.createElement("i");e.innerHTML="There are no symbols on this page.",c==null||c.appendChild(e)}for(let e of h!=null?h:[])e.link.innerHTML=e.name+" <i>"+e.kind+"</i>",c==null||c.appendChild(e.link)}p&&(p.scrollTop=0),(h==null?void 0:h.length)&&c&&c.children.length>0&&x(0)}function x(n){let e=c==null?void 0:c.children;if(!(!e||!p)){if(f>=0&&e[f].classList.remove("JumpDialog-active"),n>=e.length&&(n=e.length-1),n>=0){e[n].classList.add("JumpDialog-active");let t=e[n].offsetTop-e[0].offsetTop,i=t+e[n].clientHeight;t<p.scrollTop?p.scrollTop=t:i>p.scrollTop+p.clientHeight&&(p.scrollTop=i-p.clientHeight)}f=n}}function R(n){if(f<0)return;let e=f+n;e<0&&(e=0),x(e)}function q(){var t;u==null||u.addEventListener("keyup",function(){u.value.toUpperCase()!=P.toUpperCase()&&g(u.value)}),u==null||u.addEventListener("keydown",function(i){let s=38,l=40,r=13;switch(i.which){case s:R(-1),i.preventDefault();break;case l:R(1),i.preventDefault();break;case r:f>=0&&c&&(c.children[f].click(),i.preventDefault());break}});let n=document.querySelector(".ShortcutsDialog");B.on("f","open jump to modal",i=>{(a==null?void 0:a.open)||(n==null?void 0:n.open)||(i.preventDefault(),u&&(u.value=""),a==null||a.showModal(),u==null||u.focus(),g(""))}).on("?","open shortcuts modal",()=>{(a==null?void 0:a.open)||(n==null?void 0:n.open)||n==null||n.showModal()});let e=document.querySelector(".js-jumpToInput");e&&e.addEventListener("click",()=>{u&&(u.value=""),g("")}),(t=document.querySelector(".js-openShortcuts"))==null||t.addEventListener("click",()=>{n==null||n.showModal()})}var y=class{constructor(e){this.el=e;this.el.addEventListener("change",t=>{let i=t.target,s=i.value;i.value.startsWith("/")||(s="/"+s),window.location.href=s})}};function F(n){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 s={},l;for(let r of n.treeitems){if(Number(r.depth)>4)continue;r.groupTreeitem?(l=s[r.groupTreeitem.label],l||(l=s[r.groupTreeitem.label]=document.createElement("optgroup"),l.label=r.groupTreeitem.label,t.appendChild(l))):l=i;let o=document.createElement("option");o.label=r.label,o.textContent=r.label,o.value=r.el.href.replace(window.location.origin,"").replace("/",""),l.appendChild(o)}return n.addObserver(r=>{var b;let o=r.el.hash,d=(b=t.querySelector(`[value$="${o}"]`))==null?void 0:b.value;d&&(t.value=d)},50),e}var L=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 s of i)e.set(s.target.id,s.isIntersecting||s.intersectionRatio===1);for(let[s,l]of e)if(l){let r=this.treeitems.find(o=>{var d;return(d=o.el)==null?void 0:d.href.endsWith(`#${s}`)});if(r)for(let o of this.observerCallbacks)o(r);break}},{threshold:1,rootMargin:"-60px 0px 0px 0px"});for(let i of this.treeitems.map(s=>s.el.getAttribute("href")))if(i){let s=i.replace(window.location.origin,"").replace("/","").replace("#",""),l=document.getElementById(s);l&&t.observe(l)}}addObserver(e,t=200){this.observerCallbacks.push(W(e,t))}setFocusToNextItem(e){let t=null;for(let i=e.index+1;i<this.treeitems.length;i++){let s=this.treeitems[i];if(s.isVisible){t=s;break}}t&&this.setFocusToItem(t)}setFocusToPreviousItem(e){let t=null;for(let i=e.index-1;i>-1;i--){let s=this.treeitems[i];if(s.isVisible){t=s;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,s;t=t.toLowerCase(),i=e.index+1,i===this.treeitems.length&&(i=0),s=this.getIndexFirstChars(i,t),s===-1&&(s=this.getIndexFirstChars(0,t)),s>-1&&this.setFocusToItem(this.treeitems[s])}findTreeItems(){let e=(t,i)=>{let s=i,l=t.firstElementChild;for(;l;)(l.tagName==="A"||l.tagName==="SPAN")&&(s=new _(l,this,i),this.treeitems.push(s),this.firstChars.push(s.label.substring(0,1).toLowerCase())),l.firstElementChild&&e(l,s),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}},_=class{constructor(e,t,i){var r,o,d,b,C;e.tabIndex=-1,this.el=e,this.groupTreeitem=i,this.label=(o=(r=e.textContent)==null?void 0:r.trim())!=null?o:"",this.tree=t,this.depth=((i==null?void 0:i.depth)||0)+1,this.index=0;let s=e.parentElement;(s==null?void 0:s.tagName.toLowerCase())==="li"&&(s==null||s.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 M=`${(C=i==null?void 0:i.label)!=null?C:""} nav group ${this.label}`.replace(/[\W_]+/g,"_");e.setAttribute("aria-owns",M),e.setAttribute("aria-expanded","false"),l.setAttribute("role","group"),l.setAttribute("id",M),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 W(n,e){let t;return(...i)=>{let s=()=>{t=null,n(...i)};t&&clearTimeout(t),t=setTimeout(s,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 s;let t=(e==null?void 0:e.getAttribute("aria-expanded"))==="true",i=(s=e==null?void 0:e.getAttribute("aria-controls"))==null?void 0:s.trimEnd().split(" ");i==null||i.map(l=>{let r=document.getElementById(`${l}`);t?(r==null||r.classList.add("visible"),r==null||r.classList.remove("hidden")):(r==null||r.classList.add("hidden"),r==null||r.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)}};q();S();var K=document.querySelector(".js-expandableTable");if(K){let n=new A(K,document.querySelector(".js-expandAllDirectories"));window.location.search.includes("expand-directories")&&n.expandAllItems()}var U=document.querySelector(".js-tree");if(U){let n=new L(U),e=F(n),t=document.querySelector(".js-mainNavMobile");t&&t.firstElementChild&&(t==null||t.replaceChild(e,t.firstElementChild)),e.firstElementChild&&new y(e.firstElementChild)}var E=document.querySelector(".js-readme"),w=document.querySelector(".js-readmeContent"),D=document.querySelector(".js-readmeOutline"),v=document.querySelectorAll(".js-readmeExpand"),V=document.querySelector(".js-readmeCollapse"),k=document.querySelector(".DocNavMobile-select");E&&w&&D&&v.length&&V&&(window.location.hash.includes("readme")&&T(),k==null||k.addEventListener("change",n=>{n.target.value.startsWith("readme-")&&T()}),v.forEach(n=>n.addEventListener("click",e=>{e.preventDefault(),T(),E.scrollIntoView()})),V.addEventListener("click",n=>{n.preventDefault(),E.classList.remove("UnitReadme--expanded"),v[1]&&v[1].scrollIntoView({block:"center"})}),w.addEventListener("keyup",()=>{T()}),w.addEventListener("click",()=>{T()}),D.addEventListener("click",()=>{T()}),document.addEventListener("keydown",n=>{(n.ctrlKey||n.metaKey)&&n.key==="f"&&T()}));function T(){history.replaceState(null,"",`${location.pathname}#section-readme`),E==null||E.classList.add("UnitReadme--expanded")}function J(){var t;if(!location.hash)return;let n=document.getElementById(location.hash.slice(1)),e=(t=n==null?void 0:n.parentElement)==null?void 0:t.parentElement;(e==null?void 0:e.nodeName)==="DETAILS"&&(e.open=!0)}J();window.addEventListener("hashchange",()=>J());document.querySelectorAll(".js-buildContextSelect").forEach(n=>{n.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