1var u=Object.defineProperty;var d=(c,h,e)=>h in c?u(c,h,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[h]=e;var n=(c,h,e)=>d(c,typeof h!="symbol"?h+"":h,e);import{B as p}from"./chunk-BaseElement-CopzcQ-j.js";import{d as m}from"./chunk-debounce-D6ZMjh7U.js";import{L as g}from"./chunk-LiveRegionUtility-tvV1eypT.js";import"./chunk-lit-element-B04JoW0t.js";import"./chunk-aria-live-region-context-DAmBJh4s.js";import"./chunk-create-context-89xeped_.js";class v extends p{constructor(){super();n(this,"$liveRegionUtility",new g(this));n(this,"resultsMaxHeight");n(this,"searchTerm","");n(this,"input");n(this,"predictiveSearchResults");n(this,"cachedResults",{});n(this,"abortController",new AbortController);n(this,"allPredictiveSearchInstances",[]);this.debouncedOnChange=m(this.onChange.bind(this))}connectedCallback(){super.connectedCallback(),this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.allPredictiveSearchInstances=document.querySelectorAll("predictive-search"),this.setupEventListeners()}setupEventListeners(){this.input.form.addEventListener("submit",this.onFormSubmit.bind(this)),this.input.addEventListener("focus",this.onFocus.bind(this)),this.input.addEventListener("input",this.debouncedOnChange),this.input.addEventListener("blur",this.onBlur.bind(this)),this.addEventListener("focusout",this.onFocusOut.bind(this)),this.addEventListener("keyup",this.onKeyup.bind(this)),this.addEventListener("keydown",this.onKeydown.bind(this))}get query(){return this.input.value.trim()}onChange(){var i;const e=this.query;if((!this.searchTerm||!e.startsWith(this.searchTerm))&&((i=this.querySelector("#predictive-search-results-groups-wrapper"))==null||i.remove()),this.updateSearchForTerm(this.searchTerm,e),this.searchTerm=e,!this.searchTerm.length){this.close(!0);return}this.getSearchResults(this.searchTerm)}onFormSubmit(e){(!this.query.length||this.querySelector('[aria-selected="true"] a'))&&e.preventDefault()}onFocus(){const e=this.query;e.length&&(this.searchTerm!==e?this.onChange():this.getAttribute("results")==="true"?this.open():this.getSearchResults(this.searchTerm))}onFocusOut(){setTimeout(()=>{this.contains(document.activeElement)||this.close()})}onKeyup(e){switch(this.query.length||this.close(!0),e.preventDefault(),e.code){case"ArrowUp":this.switchOption("up");break;case"ArrowDown":this.switchOption("down");break;case"Enter":this.selectOption();break}}onKeydown(e){(e.code==="ArrowUp"||e.code==="ArrowDown")&&e.preventDefault()}updateSearchForTerm(e,i){var s;const t=(s=this.searchForTextElement)==null?void 0:s.innerText;if(t){if(t.match(new RegExp(e,"g")).length>1)return;const r=t.replace(e,i);this.searchForTextElement.innerText=r}}switchOption(e){if(!this.getAttribute("open"))return;const i=e==="up";this.selectedElement=this.querySelector('[aria-selected="true"]');const t=Array.from(this.querySelectorAll("li, [data-predictive-search-item]")).filter(l=>l.offsetParent!==null);let s=0;if(i&&!this.selectedElement)return;let r=-1,a=0;for(;r===-1&&a<=t.length;)t[a]===this.selectedElement&&(r=a),a++;if(!i&&this.selectedElement?s=r===t.length-1?0:r+1:i&&(s=r===0?t.length-1:r-1),s===r)return;const o=t[s];o.setAttribute("aria-selected",!0),this.selectedElement&&this.selectedElement.setAttribute("aria-selected",!1),this.input.setAttribute("aria-activedescendant",o.id)}selectOption(){const e=this.querySelector('[aria-selected="true"] a, button[aria-selected="true"]');e&&e.click()}getSearchResults(e){const i=e.replace(" ","-").toLowerCase();if(this.setLiveRegionLoadingState(),this.cachedResults[i]){this.renderSearchResults(this.cachedResults[i]);return}fetch(`${window.routes.predictive_search_url}?q=${encodeURIComponent(e)}&resources[limit]=4&resources[limit_scope]=each§ion_id=predictive-search`,{signal:this.abortController.signal}).then(t=>{if(!t.ok){var s=new Error(t.status);throw this.close(),s}return t.text()}).then(t=>{const s=new DOMParser().parseFromString(t,"text/html").querySelector("#shopify-section-predictive-search").innerHTML;
1this.allPredictiveSearchInstances.forEach(r=>{r.cachedResults[i]=s}),this.renderSearchResults(s)}).catch(t=>{if((t==null?void 0:t.code)!==20)throw this.close(),t})}setLiveRegionLoadingState(){this.loadingText=this.loadingText||this.getAttribute("data-loading-text"),this.$liveRegionUtility.announce({message:this.loadingText}),this.setAttribute("loading",!0)}renderSearchResults(e){this.predictiveSearchResults.innerHTML=e,this.setAttribute("results",!0),this.setLiveRegionResults(),this.open()}setLiveRegionResults(){this.removeAttribute("loading"),this.$liveRegionUtility.announce({message:this.querySelector("[data-predictive-search-live-region-count-value]").textContent})}getResultsMaxHeight(){return this.resultsMaxHeight=window.innerHeight-document.querySelector("#header-search").getBoundingClientRect().bottom,this.resultsMaxHeight}open(){this.predictiveSearchResults.style.maxHeight=this.resultsMaxHeight||`${this.getResultsMaxHeight()}px`,this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0)}close(e=!1){this.closeResults(e)}closeResults(e=!1){e&&(this.input.value="",this.removeAttribute("results"));const i=this.querySelector('[aria-selected="true"]');i&&i.setAttribute("aria-selected",!1),this.input.setAttribute("aria-activedescendant",""),this.removeAttribute("loading"),this.removeAttribute("open"),this.input.setAttribute("aria-expanded",!1),this.resultsMaxHeight=!1,this.predictiveSearchResults.removeAttribute("style")}onBlur(){this.query&&window.matchMedia("(max-width: 1023px)").matches&&this.predictiveSearchResults.focus()}}window.customElements.define("predictive-search",v);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.