System.register(["./chunk-frameworks.js","./chunk-vendor.js"],function(){"use strict";var J,T,E,Q,Z,ee;return{setters:[function(y){J=y.s,T=y.a},function(y){E=y.t,Q=y.c,Z=y.e,ee=y.p}],execute:function(){var y=Object.defineProperty,fe=(e,i)=>y(e,"name",{value:i,configurable:!0});const{getItem:pe,setItem:te,removeItem:ie}=J("localStorage",{throwQuotaErrorsOnSet:!0});var k;(function(e){e.Branch="branch",e.Tag="tag"})(k||(k={}));const G=class{constructor(e,i,t,n,r){this.knownItems=[],this.currentSearchResult=[],this.exactMatchFound=!1,this.isLoading=!0,this.fetchInProgress=!1,this.fetchFailed=!1,this.refType=e,this.selector=i,this.refEndpoint=t,this.cacheKey=n,this.nameWithOwner=r}render(){this.selector.render()}async fetchData(){if(!(!this.isLoading||this.fetchInProgress)){if(!this.bootstrapFromLocalStorage()){this.fetchInProgress=!0,this.fetchFailed=!1;const e=await fetch(`${this.refEndpoint}?type=${this.refType}`,{headers:{Accept:"application/json"}});await this.processResponse(e)}this.isLoading=!1,this.fetchInProgress=!1,this.render()}}async processResponse(e){if(this.emitStats(e),!e.ok){this.fetchFailed=!0;return}const i=e.clone(),t=await e.json();this.knownItems=t.refs,this.cacheKey=t.cacheKey,this.flushToLocalStorage(await i.text())}emitStats(e){if(!e.ok){T({incrementKey:"REF_SELECTOR_BOOT_FAILED"},!0);return}switch(e.status){case 200:{T({incrementKey:"REF_SELECTOR_BOOTED_FROM_UNCACHED_HTTP"});break}case 304:{T({incrementKey:"REF_SELECTOR_BOOTED_FROM_HTTP_CACHE"});break}default:T({incrementKey:"REF_SELECTOR_UNEXPECTED_RESPONSE"})}}search(e){if(e===""){this.currentSearchResult=this.knownItems;return}const i=[],t=[];this.exactMatchFound=!1;let n;for(const r of this.knownItems)if(n=r.indexOf(e),!(n<0)){if(n===0){e===r?(t.unshift(r),this.exactMatchFound=!0):t.push(r);continue}i.push(r)}this.currentSearchResult=[...t,...i]}bootstrapFromLocalStorage(){const e=pe(this.localStorageKey);if(!e)return!1;const i=JSON.parse(e);return i.cacheKey!==this.cacheKey||!("refs"in i)?(ie(this.localStorageKey),!1):(this.knownItems=i.refs,this.isLoading=!1,T({incrementKey:"REF_SELECTOR_BOOTED_FROM_LOCALSTORAGE"}),!0)}async flushToLocalStorage(e){try{te(this.localStorageKey,e)}catch(i){if(i.message.toLowerCase().includes("quota")){this.clearSiblingLocalStorage(),T({incrementKey:"REF_SELECTOR_LOCALSTORAGE_OVERFLOWED"});try{te(this.localStorageKey,e)}catch(t){t.message.toLowerCase().includes("quota")&&T({incrementKey:"REF_SELECTOR_LOCALSTORAGE_GAVE_UP"})}}else throw i}}clearSiblingLocalStorage(){for(const e of Object.keys(localStorage))e.startsWith(G.LocalStoragePrefix)&&ie(e)}get localStorageKey(){return`${G.LocalStoragePrefix}:${this.nameWithOwner}:${this.refType}`}};let q=G;fe(q,"SearchIndex"),q.LocalStoragePrefix="ref-selector";function ve(e,i){var t=i.attributes,n,r,s,a,h,l;for(n=t.length-1;n>=0;--n)r=t[n],s=r.name,a=r.namespaceURI,h=r.value,a?(s=r.localName||s,l=e.getAttributeNS(a,s),l!==h&&e.setAttributeNS(a,s,h)):(l=e.getAttribute(s),l!==h&&e.setAttribute(s,h));for(t=e.attributes,n=t.length-1;n>=0;--n)r=t[n],r.specified!==!1&&(s=r.name,a=r.namespaceURI,a?(s=r.localName||s,i.hasAttributeNS(a,s)||e.removeAttributeNS(a,s)):i.hasAttribute(s)||e.removeAttribute(s))}var M,me="http://www.w3.org/1999/xhtml",C=typeof document=="undefined"?void 0:document;function ge(e){!M&&C.createRange&&(M=C.createRange(),M.selectNode(C.body));var i;return M&&M.createContextualFragment?i=M.createContextualFragment(e):(i=C.createElement("body"),i.innerHTML=e),i.childNodes[0]}function V(e,i){var t=e.nodeName,n=i.nodeName;return t===n?!0:i.actualize&&t.charCodeAt(0)<91&&n.charCodeAt(0)>90?t===n.toUpperCase():!1}function Se(e,i){return!i||i===me?C.createElement(e):C.createElementNS(i,e)}function Ie(e,i){for(var t=e.firstChild;t;){var n=t.nextSibling;i.appendChild(t),t=n}return i}function j(e,i,t){e[t]!==i[t]&&(e[t]=i[t],e[t]?e.setAttribute(t,""):e.removeAttribute(t))}var ne={OPTION:function(e,i){var t=e.parentNode;if(t){var n=t.nodeName.toUpperCase();n==="OPTGROUP"&&(t=t.parentNode,n=t&&t.nodeName.toUpperCase()),n==="SELECT"&&!t.hasAttribute("multiple")&&(e.hasAttribute("selected")&&!i.selected&&(e.setAttribute("selected","selected"),e.removeAttribute("selected")),t.selectedIndex=-1)}j(e,i,"selected")},INPUT:function(e,i){j(e,i,"checked"),j(e,i,"disabled"),e.value!==i.value&&(e.value=i.value),i.hasAttribute("value")||e.removeAttribute("value")},TEXTAREA:function(e,i){var t=i.value;e.value!==t&&(e.value=t);var n=e.firstChild;if(n){var r=n.nodeValue;if(r==t||!t&&r==e.placeholder)return;n.nodeValue=t}},SELECT:function(e,i){if(!i.hasAttribute("multiple")){for(var t=-1,n=0,r=e.firstChild,s,a;r;)if(a=r.nodeName&&r.nodeName.toUpperCase(),a==="OPTGROUP")s=r,r=s.firstChild;else{if(a==="OPTION"){if(r.hasAttribute("selected")){t=n;break}n++}r=r.nextSibling,!r&&s&&(r=s.nextSibling,s=null)}e.selectedIndex=t}}},F=1,xe=11,re=3,se=8;function z(){}function we(e){return e.id}function ye(e){return function(t,n,r){if(r||(r={}),typeof n=="string")if(t.nodeName==="#document"||t.nodeName==="HTML"){var s=n;n=C.createElement("html"),n.innerHTML=s}else n=ge(n);var a=r.getNodeKey||we,h=r.onBeforeNodeAdded||z,l=r.onNodeAdded||z,u=r.onBeforeElUpdated||z,p=r.onElUpdated||z,S=r.onBeforeNodeDiscarded||z,v=r.onNodeDiscarded||z,g=r.onBeforeElChildrenUpdated||z,w=r.childrenOnly===!0,I={},b;function R(d){b?b.push(d):b=[d]}function D(d,c){if(d.nodeType===F)for(var o=d.firstChild;o;){var f=void 0;c&&(f=a(o))?R(f):(v(o),o.firstChild&&D(o,c)),o=o.nextSibling}}function K(d,c,o){S(d)!==!1&&(c&&c.removeChild(d),v(d),D(d,o))}function de(d){if(d.nodeType===F||d.nodeType===xe)for(var c=d.firstChild;c;){var o=a(c);o&&(I[o]=c),de(c),c=c.nextSibling}}de(t);function ce(d){l(d);for(var c=d.firstChild;c;){var o=c.nextSibling,f=a(c);if(f){var x=I[f];x&&V(c,x)&&(c.parentNode.replaceChild(x,c),B(x,c))}ce(c),c=o}}function ke(d,c,o){for(;c;){var f=c.nextSibling;(o=a(c))?R(o):K(c,d,!0),c=f}}function B(d,c,o){var f=a(c);f&&delete I[f],!(n.isSameNode&&n.isSameNode(t))&&(!o&&(u(d,c)===!1||(e(d,c),p(d),g(d,c)===!1))||(d.nodeName!=="TEXTAREA"?Ve(d,c):ne.TEXTAREA(d,c)))}function Ve(d,c){var o=c.firstChild,f=d.firstChild,x,_,N,U,L;e:for(;o;){for(U=o.nextSibling,x=a(o);f;){if(N=f.nextSibling,o.isSameNode&&o.isSameNode(f)){o=U,f=N;continue e}_=a(f);var $=f.nodeType,O=void 0;if($===o.nodeType&&($===F?(x?x!==_&&((L=I[x])?N===L?O=!1:(d.insertBefore(L,f),_?R(_):K(f,d,!0),f=L):O=!1):_&&(O=!1),O=O!==!1&&V(f,o),O&&B(f,o)):($===re||$==se)&&(O=!0,f.nodeValue!==o.nodeValue&&(f.nodeValue=o.nodeValue))),O){o=U,f=N;continue e}_?R(_):K(f,d,!0),f=N}if(x&&(L=I[x])&&V(L,o))d.appendChild(L),B(L,o);else{var Y=h(o);Y!==!1&&(Y&&(o=Y),o.actualize&&(o=o.actualize(d.ownerDocument||C)),d.appendChild(o),ce(o))}o=U,f=N}ke(d,f,_);var ue=ne[d.nodeName];ue&&ue(d,c)}var m=t,H=m.nodeType,le=n.nodeType;if(!w){if(H===F)le===F?V(t,n)||(v(t),m=Ie(t,Se(n.nodeName,n.namespaceURI))):m=n;else if(H===re||H===se){if(le===H)return m.nodeValue!==n.nodeValue&&(m.nodeValue=n.nodeValue),m;m=n}}if(m===n)v(t);else if(B(m,n,w),b)for(var W=0,Ke=b.length;W=this._itemCount)throw Error("Requested index "+t+" is outside of range 0.."+this._itemCount);if(t>this._lastMeasuredIndex){for(var n=this.getSizeAndPositionOfLastMeasuredItem(),r=n.offset+n.size,s=this._lastMeasuredIndex+1;s<=t;s++){var a=this._itemSizeGetter({index:s});if(a==null||isNaN(a))throw Error("Invalid size returned for index "+s+" of value "+a);this._itemSizeAndPositionData[s]={offset:r,size:a},r+=a}this._lastMeasuredIndex=t}return this._itemSizeAndPositionData[t]},e.prototype.getSizeAndPositionOfLastMeasuredItem=function(){return this._lastMeasuredIndex>=0?this._itemSizeAndPositionData[this._lastMeasuredIndex]:{offset:0,size:0}},e.prototype.getTotalSize=function(){var t=this.getSizeAndPositionOfLastMeasuredItem();return t.offset+t.size+(this._itemCount-this._lastMeasuredIndex-1)*this._estimatedItemSize},e.prototype.getUpdatedOffsetForIndex=function(t){var n=t.align,r=n===void 0?Ae:n,s=t.containerSize,a=t.targetIndex;if(s<=0)return 0;var h=this.getSizeAndPositionForIndex(a),l=h.offset,u=l-s+h.size,p=void 0;switch(r){case Re:p=u;break;case be:p=l-(s-h.size)/2;break;default:p=l;break}var S=this.getTotalSize();return Math.max(0,Math.min(S-s,p))},e.prototype.getVisibleRange=function(t){var n=t.containerSize,r=t.offset,s=t.overscanCount,a=this.getTotalSize();if(a===0)return{};var h=r+n,l=this._findNearestItem(r),u=l,p=this.getSizeAndPositionForIndex(l);for(r=p.offset+p.size;rs&&(r=a-1)}if(n>0)return n-1},e.prototype._exponentialSearch=function(t){for(var n=t.index,r=t.offset,s=1;n=t?this._binarySearch({high:r,low:0,offset:t}):this._exponentialSearch({index:r,offset:t})},e}();function Le(e,i){if(!(e instanceof i))throw new TypeError("Cannot call a class as a function")}var Oe="position:relative; overflow:hidden; width:100%; min-height:100%; will-change: transform;",ze="position:absolute; top:0; left:0; height:100%; width:100%; overflow:visible;",ae=function(){function e(i,t){var n=this;Le(this,e),this.getRowHeight=function(r){var s=r.index,a=n.options.rowHeight;return typeof a=="function"?a(s):Array.isArray(a)?a[s]:a},this.container=i,this.options=t,this.state={},this._initializeSizeAndPositionManager(t.rowCount),this.render=this.render.bind(this),this.handleScroll=this.handleScroll.bind(this),this.componentDidMount()}return e.prototype.componentDidMount=function(){var t=this,n=this.options,r=n.onMount,s=n.initialScrollTop,a=n.initialIndex,h=n.height,l=s||a!=null&&this.getRowOffset(a)||0,u=this.inner=document.createElement("div"),p=this.content=document.createElement("div");u.setAttribute("style",Oe),p.setAttribute("style",ze),u.appendChild(p),this.container.appendChild(u),this.setState({offset:l,height:h},function(){l&&(t.container.scrollTop=l),t.container.addEventListener("scroll",t.handleScroll),typeof r=="function"&&r()})},e.prototype._initializeSizeAndPositionManager=function(t){this._sizeAndPositionManager=new _e({itemCount:t,itemSizeGetter:this.getRowHeight,estimatedItemSize:this.options.estimatedRowHeight||100})},e.prototype.setState=function(){var t=this,n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},r=arguments[1];this.state=Object.assign(this.state,n),requestAnimationFrame(function(){t.render(),typeof r=="function"&&r()})},e.prototype.resize=function(t,n){this.setState({height:t},n)},e.prototype.handleScroll=function(t){var n=this.options.onScroll,r=this.container.scrollTop;this.setState({offset:r}),typeof n=="function"&&n(r,t)},e.prototype.getRowOffset=function(t){var n=this._sizeAndPositionManager.getSizeAndPositionForIndex(t),r=n.offset;return r},e.prototype.scrollToIndex=function(t,n){var r=this.state.height,s=this._sizeAndPositionManager.getUpdatedOffsetForIndex({align:n,containerSize:r,targetIndex:t});this.container.scrollTop=s},e.prototype.setRowCount=function(t){this._initializeSizeAndPositionManager(t),this.render()},e.prototype.onRowsRendered=function(t){var n=this.options.onRowsRendered;typeof n=="function"&&n(t)},e.prototype.destroy=function(){this.container.removeEventListener("scroll",this.handleScroll),this.container.innerHTML=""},e.prototype.render=function(){for(var t=this.options,n=t.overscanCount,r=t.renderRow,s=this.state,a=s.height,h=s.offset,l=h===void 0?0:h,u=this._sizeAndPositionManager.getVisibleRange({containerSize:a,offset:l,overscanCount:n}),p=u.start,S=u.stop,v=document.createDocumentFragment(),g=p;g<=S;g++)v.appendChild(r(g));this.inner.style.height=this._sizeAndPositionManager.getTotalSize()+"px",this.content.style.top=this.getRowOffset(p)+"px",Ce(this.content,v,{childrenOnly:!0,getNodeKey:function(I){return I.nodeIndex}}),this.onRowsRendered({startIndex:p,stopIndex:S})},e}();function Ee(e,i){if(!(e instanceof i))throw new TypeError("Cannot call a class as a function")}function Me(e,i){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return i&&(typeof i=="object"||typeof i=="function")?i:e}function Pe(e,i){if(typeof i!="function"&&i!==null)throw new TypeError("Super expression must either be null or a function, not "+typeof i);e.prototype=Object.create(i&&i.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),i&&(Object.setPrototypeOf?Object.setPrototypeOf(e,i):e.__proto__=i)}(function(e){Pe(i,e);function i(){return Ee(this,i),Me(this,e.apply(this,arguments))}return i.prototype.onRowsRendered=function(n){var r=this,s=n.startIndex,a=n.stopIndex,h=this.options,l=h.isRowLoaded,u=h.loadMoreRows,p=h.minimumBatchSize,S=p===void 0?10:p,v=h.rowCount,g=v===void 0?0:v,w=h.threshold,I=w===void 0?15:w,b=Fe({isRowLoaded:l,minimumBatchSize:S,rowCount:g,startIndex:Math.max(0,s-I),stopIndex:Math.min(g-1,a+I)});b.forEach(function(R){var D=u(R);D&&D.then(function(){Ne({lastRenderedStartIndex:s,lastRenderedStopIndex:a,startIndex:R.startIndex,stopIndex:R.stopIndex})&&r.render()})})},i})(ae);function Ne(e){var i=e.lastRenderedStartIndex,t=e.lastRenderedStopIndex,n=e.startIndex,r=e.stopIndex;return!(n>t||r0;){var w=g.startIndex-1;if(!i({index:w}))g.startIndex=w;else break}return a}var oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,he=(e,i)=>oe(e,"name",{value:i,configurable:!0}),P=(e,i,t,n)=>{for(var r=n>1?void 0:n?De(i,t):i,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=(n?a(i,t,r):a(r))||r);return n&&r&&oe(i,t,r),r};let A=class extends HTMLElement{constructor(){super(...arguments);this.isCurrentVisible=!1,this.currentSelectionIndex=null}connectedCallback(){this.refType=this.getRequiredAttr("type")==="branch"?k.Branch:k.Tag;const e=this.getAttribute("current-committish");this.currentCommittish=e?atob(e):null,this.input=this.hasAttribute("initial-filter")&&this.currentCommittish||"",this.defaultBranch=atob(this.getRequiredAttr("default-branch")),this.nameWithOwner=atob(this.getRequiredAttr("name-with-owner")),this.canCreate=this.hasAttribute("can-create"),this.prefetchOnMouseover=this.hasAttribute("prefetch-on-mouseover");const i=this.getRequiredAttr("query-endpoint"),t=this.getRequiredAttr("cache-key");this.index=new q(this.refType,this,i,t,this.nameWithOwner),this.setupFetchListeners()}inputEntered(e){this.input=e.detail,this.render()}tabSelected(){this.index.fetchData()}renderTemplate(e,i){return new Z(e,i,ee)}renderRow(e){const i=this.index.currentSearchResult[e];if(!i&&e>=this.listLength)return document.createElement("span");if(this.index.fetchFailed)return this.renderTemplate(this.fetchFailedTemplate,{index:e,refName:this.input});if(!i){const a=this.input===this.currentCommittish;return this.isCurrentVisible||(this.isCurrentVisible=a),this.renderTemplate(this.noMatchTemplate,{index:e,isCurrent:a,refName:this.input})}const t=this.input.length>0,n=t?"is-filtering":"",r=i===this.currentCommittish;this.isCurrentVisible||(this.isCurrentVisible=r);const s=this.renderTemplate(this.itemTemplate,{refName:i,index:e,isFilteringClass:n,urlEncodedRefName:this.urlEncodeRef(i),isCurrent:r,isNotDefault:i!==this.defaultBranch});if(t){const a=s.querySelector("span");a.textContent="";const h=i.split(this.input),l=h.length-1;for(let u=0;u{i||(this.index.fetchData(),i=!0)},"fetch");if(!e||e.open){t();return}this.prefetchOnMouseover&&e.addEventListener("mouseover",t,{once:!0}),this.addEventListener("keydown",this.keydown),this.addEventListener("change",this.updateCurrent);const n=e.querySelector("input[data-ref-filter]");n&&(n.addEventListener("input",()=>{this.input=n.value,this.render()}),n.addEventListener("keydown",r=>{if(r.key==="ArrowDown"||r.key==="Tab")r.preventDefault(),r.stopPropagation(),this.focusFirstListMember();else if(r.key==="Enter"){let s=this.index.currentSearchResult.indexOf(this.input);if(s===-1)if(this.showCreateRow)s=this.listLength-1;else return;e.querySelector(`[data-index="${s}"]`).click(),r.preventDefault()}}))}focusFirstListMember(){!this.virtualizedList||(this.currentSelectionIndex=0,this.focusItemAtIndex(this.currentSelectionIndex))}updateCurrent(e){e.target instanceof HTMLInputElement&&e.target.checked&&e.target.value&&(this.currentCommittish=e.target.value)}keydown(e){if(this.currentSelectionIndex!==null){if(e.key==="Enter"){const i=document.activeElement;if(!i)return;i.click(),e.preventDefault();return}if(!(e.key==="Tab"&&e.shiftKey)&&e.key!=="Escape")switch(e.preventDefault(),e.stopPropagation(),e.key){case"ArrowUp":{this.currentSelectionIndex--,this.currentSelectionIndex<0&&(this.currentSelectionIndex=this.listLength-1),this.focusItemAtIndex(this.currentSelectionIndex);break}case"Home":{this.currentSelectionIndex=0,this.focusItemAtIndex(this.currentSelectionIndex);break}case"End":{this.currentSelectionIndex=this.listLength-1,this.focusItemAtIndex(this.currentSelectionIndex);break}case"Tab":case"ArrowDown":{this.currentSelectionIndex++,this.currentSelectionIndex>this.listLength-1&&(this.currentSelectionIndex=0),this.focusItemAtIndex(this.currentSelectionIndex);break}}}}focusItemAtIndex(e){this.virtualizedList.scrollToIndex(e,"center"),setTimeout(()=>{const i=this.listContainer.querySelector(`[data-index="${e}"]`);i&&i.focus()},20)}setupVirtualizedList(){this.listContainer.innerHTML="",this.virtualizedList=new ae(this.listContainer,{height:330,rowCount:this.listLength,renderRow:this.renderRow.bind(this),rowHeight:e=>this.showCreateRow&&e===this.listLength-1?51:33,onRowsRendered:()=>{var e;this.hiddenCurrentElement&&(this.listContainer.removeChild(this.hiddenCurrentElement),delete this.hiddenCurrentElement),this.isCurrentVisible?this.isCurrentVisible=!1:this.hiddenCurrentItemTemplate&&(this.hiddenCurrentElement=document.createElement("div"),(e=this.hiddenCurrentElement)==null||e.appendChild(this.renderTemplate(this.hiddenCurrentItemTemplate,{refName:this.currentCommittish})),this.listContainer.appendChild(this.hiddenCurrentElement))},initialIndex:0,overscanCount:6})}};he(A,"RefSelectorElement"),P([E],A.prototype,"listContainer",2),P([E],A.prototype,"itemTemplate",2),P([E],A.prototype,"noMatchTemplate",2),P([E],A.prototype,"fetchFailedTemplate",2),P([E],A.prototype,"hiddenCurrentItemTemplate",2),A=P([Q],A)}}}); //# sourceMappingURL=chunk-ref-selector-c0aa26ee.js.map