1var $=Object.defineProperty;var U=n=>{throw TypeError(n)};var z=(n,c,e)=>c in n?$(n,c,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[c]=e;var w=(n,c,e)=>z(n,typeof c!="symbol"?c+"":c,e),A=(n,c,e)=>c.has(n)||U("Cannot "+e);var i=(n,c,e)=>(A(n,c,"read from private field"),e?e.call(n):c.get(n)),l=(n,c,e)=>c.has(n)?U("Cannot add the same private member more than once"):c instanceof WeakSet?c.add(n):c.set(n,e),h=(n,c,e,t)=>(A(n,c,"write to private field"),t?t.call(n,e):c.set(n,e),e),d=(n,c,e)=>(A(n,c,"access private method"),e);import{C as j}from"./component.js";import{l as G,p as J,o as Q,e as O}from"./utilities.js";import{s as _}from"./section-renderer.js";import{m as F}from"./morph.js";import{T as X}from"./events.js";import{RecentlyViewed as V}from"./recently-viewed-products.js";import{D as Y}from"./dialog.js";var S,v,I,k,L,M,r,p,f,R,g,K,q,N,D,P,W,H,E,y,T;class Z extends j{constructor(){super(...arguments);l(this,r);w(this,"requiredRefs",["searchInput","predictiveSearchResults","resetButton"]);l(this,S,new AbortController);l(this,v,null);l(this,I,new ResizeObserver(e=>{for(const t of e)this.style.setProperty("--predictive-search-results-height",`${t.contentRect.height}px`)}));l(this,k,e=>{const t=e.target;!(t instanceof HTMLButtonElement||t instanceof HTMLAnchorElement||t instanceof HTMLInputElement||t.closest("button")||t.closest("a")||t.closest("input"))&&this.refs.searchInput&&this.refs.searchInput.focus()});l(this,L,e=>{var t;e.metaKey&&e.key==="k"&&((t=this.dialog)==null||t.toggleDialog())});l(this,M,()=>{i(this,y).call(this)});w(this,"expandSearch",()=>{this.classList.add("predictive-search--expanded"),this.dataset.activeColorScheme&&(this.dialog??this).classList.add(`color-${this.dataset.activeColorScheme}`)});l(this,f,!1);w(this,"onSearchKeyDown",e=>{var o,a,u;if(e.key==="Escape"){i(this,y).call(this);return}if(!((o=i(this,r,p))!=null&&o.length)||e.key==="ArrowLeft"||e.key==="ArrowRight")return;const t=i(this,r,R),s=i(this,r,p).length;switch(e.key){case"ArrowDown":h(this,f,!0),e.preventDefault(),h(this,r,t<s-1?t+1:0,g);break;case"Tab":e.shiftKey?(h(this,f,!0),e.preventDefault(),h(this,r,t>0?t-1:s-1,g)):(h(this,f,!0),e.preventDefault(),h(this,r,t<s-1?t+1:0,g));break;case"ArrowUp":h(this,f,!0),e.preventDefault(),h(this,r,t>0?t-1:s-1,g);break;case"Enter":const m=this.refs.predictiveSearchResults.querySelector("[data-single-result-url]");if(m instanceof HTMLElement&&m.dataset.singleResultUrl){e.preventDefault(),window.location.href=m.dataset.singleResultUrl;return}if(i(this,r,R)>=0)e.preventDefault(),(u=(a=i(this,r,K))==null?void 0:a.querySelector("a"))==null||u.click();else{const b=new URL(Theme.routes.search_url,location.origin);b.searchParams.set("q",this.refs.searchInput.value),window.location.href=b.toString()}break}});w(this,"resetSearch",O((e=!0)=>{e&&this.refs.searchInput.focus(),i(this,y).call(this)},100));w(this,"search",O(e=>{if(!e.inputType)return;const t=this.refs.searchInput.value.trim();if(h(this,r,-1,g),!t.length){i(this,y).call(this);return}d(this,r,H).call(this),d(this,r,N).call(this,t)},200));l(this,P,async()=>{const{predictiveSearchResults:e}=this.refs,t=d(this,r,E).call(this);try{const s=await d(this,r,D).call(this);if(!s)return;const a=new DOMParser().parseFromString(s,"text/html").getElementById("predictive-search-products");if(!a)return;for(const m of a.children)m instanceof HTMLElement&&m.setAttribute("ref","recentlyViewedWrapper");const u=e.querySelector("#predictive-search-products");if(!u||(this.refs.recentlyViewedWrapper&&this.refs.recentlyViewedWrapper.remove(),t.signal.aborted))return;u.prepend(...a.children)}catch(s){throw s}});l(this,y,async()=>{const{predictiveSearchResults:e,searchInput:t}=this.refs,s="predictive-search-empty";h(this,r,-1,g),t.value="",d(this,r,W).call(this);const o=d(this,r,E).call(this),a=await _.getSectionHTML(s,!1),u=new DOMParser().parseFromString(a,"text/html").querySelector(".predictive-search-empty-section");if(!u)throw new Error("No empty section markup found");if(V.getProducts().length>0){const b=await d(this,r,D).call(this);if(!b)return;const C=new DOMParser().parseFromString(b,"text/html").getElementById("predictive-search-products");if(!C)return;for(const B of C.children)B instanceof HTMLElement&&B.setAttribute("ref","recentlyViewedWrapper");const x=u.querySelector("#predictive-search-products");if(!x)return;x.prepend(...C.children)}o.signal.aborted||(F(e,u),d(this,r,q).call(this))});l(this,T,()=>{this.refs.searchInput.blur()})}get dialog(){return this.closest("dialog-component")}connectedCallback(){super.connectedCallback();const{dialog:e}=this,{signal:t}=i(this,S);this.refs.searchInput.value.length>0&&d(this,r,H).call(this),e?(document.addEventListener("keydown",i(this,L),{signal:t}),e.addEventListener(Y.eventName,i(this,M),{signal:t}),this.addEventListener("click",i(this,k),{signal:t})):document.addEventListener(X.megaMenuHover,i(this,T),{signal:t}),G(i(this,P));const s=this.refs.predictiveSearchResults.firstElementChild;s&&i(this,I).observe(s)}disconnectedCallback(){super.disconnectedCallback(),i(this,S).abort(),i(this,I).disconnect()}clearRecentlyViewedProducts(e){e.stopPropagation(),V.clearProducts();const{recentlyViewedItems:t,recentlyViewedTitle:s,recentlyViewedWrapper:o}=this.refs;[...t||[],...s||[]].length!==0&&o&&(o.classList.add("removing"),Q(o,()=>{o.remove()}))}}S=new WeakMap,v=new WeakMap,I=new WeakMap,k=new WeakMap,L=new WeakMap,M=new WeakMap,r=new WeakSet,p=function(){return Array.from(this.querySelectorAll(".predictive-search-results__wrapper-queries, .predictive-search-results__wrapper-products, .predictive-search-results__list")).flatMap(s=>s.classList.contains("predictive-search-results__wrapper-products")?Array.from(s.querySelectorAll(".predictive-search-results__card")):Array.from(s.querySelectorAll('[ref="resultsItems[]"], .predictive-search-results__card'))).filter(s=>s instanceof HTMLElement)},f=new WeakMap,R=function(){var e;return((e=i(this,r,p))==null?void 0:e.findIndex(t=>t.getAttribute("aria-selected")==="true"))??-1},g=function(e){var t;
1if((t=i(this,r,p))!=null&&t.length){i(this,r,p).forEach(s=>{s.classList.remove("keyboard-focus")});for(const[s,o]of i(this,r,p).entries())s===e?(o.setAttribute("aria-selected","true"),i(this,f)&&o.classList.add("keyboard-focus"),o.scrollIntoView({behavior:J()?"instant":"smooth",block:"nearest"})):o.removeAttribute("aria-selected");this.refs.searchInput.focus()}},K=function(){var e;return(e=i(this,r,p))==null?void 0:e[i(this,r,R)]},q=function(){requestAnimationFrame(()=>{const e=this.refs.predictiveSearchResults.querySelector(".predictive-search-results__inner");e instanceof HTMLElement&&(e.scrollTop=0);const t=this.querySelector(".predictive-search-form__content");t instanceof HTMLElement&&(t.scrollTop=0)})},N=async function(e){if(!this.dataset.sectionId)return;const t=new URL(Theme.routes.predictive_search_url,location.origin);t.searchParams.set("q",e),t.searchParams.set("resources[limit_scope]","each");const{predictiveSearchResults:s}=this.refs,o=d(this,r,E).call(this);_.getSectionHTML(this.dataset.sectionId,!1,t).then(a=>{a&&(o.signal.aborted||(F(s,a),d(this,r,q).call(this)))}).catch(a=>{if(!o.signal.aborted)throw a})},D=async function(){if(!this.dataset.sectionId)return null;const e=V.getProducts();if(e.length===0)return null;const t=new URL(Theme.routes.search_url,location.origin);return t.searchParams.set("q",e.map(s=>`id:${s}`).join(" OR ")),t.searchParams.set("resources[type]","product"),_.getSectionHTML(this.dataset.sectionId,!1,t)},P=new WeakMap,W=function(){const{resetButton:e}=this.refs;e.hidden=!0},H=function(){const{resetButton:e}=this.refs;e.hidden=!1},E=function(){const e=new AbortController;return i(this,v)&&i(this,v).abort(),h(this,v,e),e},y=new WeakMap,T=new WeakMap;customElements.get("predictive-search-component")||customElements.define("predictive-search-component",Z);
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.