PageSourceSearch

https://www.shoplc.com/cdn/shop/t/82/assets/unbxd-autosuggest.js?v=184389818124456281531789986639

js shoplc.com collected 2026-10-03 19:27:09 UTC 15,139 bytes, 2 lines download raw bytes

1import{Component}from"@theme/component";import{ThemeEvents}from"@theme/events";const getConfig=()=>typeof window<"u"&&window.UNBXD_CONFIG||{},DEFAULT_BIND_SELECTOR="#header-main",RESULTS_ID="unbxd-autosuggest-results",BOX_CLASS="unbxd-as-box",UNBXD_PLACEHOLDER_IMG="https://cdn.shopify.com/s/files/1/0533/2089/files/placeholder-images-image_large.png",UNBXD_AS_PRODUCT_FIELDS=["title","uniqueId","imageUrl","price","productUrl","autosuggest","handle","variants","variantId","v_sku","v_title","v_meta_name","v_imageUrl","v_productUrl"],DEFAULT_ENDPOINT="https://search.unbxd.io",INITIAL_QUERY="*",LOADING_HTML='<div class="unx-loading" role="status" aria-live="polite">Loading\u2026</div>',toArray=value=>Array.isArray(value)?value:[],escapeHtml=value=>String(value??"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),escapeAttr=value=>String(value??"").replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),pickImage=source=>Array.isArray(source)?source[0]||"":typeof source=="string"?source:"",firstImage=product=>pickImage(product?.imageUrl??product?.images),matchedVariant=product=>{const list=product?.variants;return Array.isArray(list)&&list.length?list[0]:null},productItemHtml=product=>{const variant=matchedVariant(product),title=variant&&variant.v_meta_name||product?.title||product?.autosuggest||"",url=variant&&variant.v_productUrl||product?.productUrl||(product?.handle?`/products/${product.handle}`:"");if(!url)return"";const image=variant&&pickImage(variant.v_imageUrl)||firstImage(product)||UNBXD_PLACEHOLDER_IMG;return`<a class="unx-item unx-popular-product" href="${escapeAttr(url)}"><img src="${escapeAttr(image)}" alt="${escapeAttr(title)}" loading="lazy" width="72" height="72" onerror="this.onerror=null;this.src=&#39;${UNBXD_PLACEHOLDER_IMG}&#39;;"><div>${escapeHtml(title)}</div></a>`},suggestionItemHtml=(item,doctype)=>{const value=item?.autosuggest||item?.value||"";return value?`<div class="${`unx-item unx-${doctype.replace(/_/g,"-")}`}" data-doctype="${doctype}" data-action="search" data-value="${escapeAttr(value)}" role="option" tabindex="-1">${escapeHtml(value)}</div>`:""},productRowsHtml=products=>products.map(productItemHtml).filter(Boolean).join(""),productsColumnHtml=products=>{const rows=productRowsHtml(products);return rows?`<div class="unx-popular-products">${rows}</div>`:""},SUGGESTION_DOCTYPES={KEYWORD_SUGGESTION:"keyword_suggestion",KEYWORD_SUGGESTIONS:"keyword_suggestion",IN_FIELD:"infield_suggestion",IN_FIELDS:"infield_suggestion",PROMOTED_SUGGESTION:"promoted_suggestion",PROMOTED_SUGGESTIONS:"promoted_suggestion",TOP_QUERIES:"top_search_query",TOP_SEARCHES:"top_search_query",TOP_SEARCH_QUERIES:"top_search_query",TRENDING_QUERIES:"trending_search",TRENDING_SEARCH:"trending_search",TRENDING_SEARCHES:"trending_search"},SUGGESTION_ORDER=["keyword_suggestion","infield_suggestion","promoted_suggestion","top_search_query","trending_search"],isProductEntry=entry=>!entry?.doctype||!SUGGESTION_DOCTYPES[entry.doctype];function composeColumns(products,suggestions){const suggestionsMarkup=suggestions.filter(Boolean).join(""),productsColumn=productsColumnHtml(products),suggestionsColumn=suggestionsMarkup?`<div class="unx-suggestions">${suggestionsMarkup}</div>`:"";return`${productsColumn}${suggestionsColumn}`}function buildBoxHtml(products){const list=toArray(products),popularProducts=list.filter(isProductEntry),grouped={};for(const entry of list){const group=SUGGESTION_DOCTYPES[entry?.doctype];group&&(grouped[group]??=[]).push(suggestionItemHtml(entry,group))}const suggestions=SUGGESTION_ORDER.flatMap(group=>grouped[group]??[]);return composeColumns(popularProducts,suggestions)}class UnbxdAutosuggest extends Component{static booted=!1;#controller=new AbortController;#config={};#box=null;#activeInput=null;#debounceTimer;#currentQuery="";#initialHtml="";#initialFetched=!1;#activeIndex=-1;#hoverTimer;#lastHoverValue="";#hoverCache=new Map;connectedCallback(){if(super.connectedCallback(),UnbxdAutosuggest.booted)return;const config=getConfig().autosuggest||{};if(!config.enabled)return;const{siteKey,apiKey}=getConfig();if(!siteKey||!apiKey){this.#log("error","Missing Unbxd siteKey/apiKey \u2014 autosuggest disabled");return}UnbxdAutosuggest.booted=!0,this.#config=config,document.body.classList.add("unbxd-as-active"),this.#bindEvents(),document.querySelectorAll(this.#inputSelector()).forEac
1h(el=>{el instanceof HTMLInputElement&&this.#setupForm(el)}),this.#prefetchInitial(),this.#adoptPreBootInput(),this.#log("info","Unbxd autosuggest (direct REST) initialized")}disconnectedCallback(){super.disconnectedCallback(),this.#controller.abort(),window.clearTimeout(this.#debounceTimer),window.clearTimeout(this.#hoverTimer),document.body.classList.remove("unbxd-as-active")}#adoptPreBootInput(){const selector=this.#inputSelector(),active=document.activeElement;let input=null;if(active instanceof HTMLInputElement&&active.closest(selector))input=active;else for(const el of document.querySelectorAll(selector))if(el instanceof HTMLInputElement&&(el.value||"").trim()){input=el;break}if(!input)return;const query=(input.value||"").trim();if(document.activeElement!==input){this.#syncSubmitEnabled(input);return}this.#activeInput=input,this.#mountBox(input),this.#syncSubmitEnabled(input),query.length>=this.#minChars()?this.#runQuery(query):this.#showInitial()}#minChars(){const value=Number(this.#config?.minChars);return value>0?value:1}#debounceDelay(){const value=Number(this.#config?.debounceDelay);return value>=0?value:300}#inputSelector(){return[".search-input","#cmdk-input",this.#config?.inputSelector,this.#config?.bindSelector,DEFAULT_BIND_SELECTOR].filter(Boolean).join(", ")}#buildUrl(query){const{apiKey,siteKey,endpoint}=getConfig(),base=String(endpoint||DEFAULT_ENDPOINT).replace(/\/+$/,""),cfg=this.#config,params=new URLSearchParams;return params.set("q",query),params.set("version","V2"),params.set("popularProducts.count",String(cfg.productCount??5)),params.set("keywordSuggestions.count",String(cfg.keywordCount??5)),params.set("topQueries.count",String(cfg.topQueriesCount??5)),params.set("inFields.count",String(cfg.infieldCount??5)),params.set("promotedSuggestion.count",String(cfg.promotedCount??5)),params.set("trendingQueries.count",String(cfg.trendingCount??5)),params.set("popularProducts.fields",UNBXD_AS_PRODUCT_FIELDS.join(",")),params.set("variants","true"),params.set("variants.count","1"),params.set("popularProducts.filter","availability:true"),params.set("promotion","true"),`${base}/${apiKey}/${siteKey}/autosuggest?${params.toString()}`}async#fetch(query){const response=await fetch(this.#buildUrl(query),{signal:this.#controller.signal});if(!response.ok)throw new Error(`Unbxd autosuggest API error: ${response.status}`);return response.json()}#prefetchInitial(){this.#initialFetched||(this.#initialFetched=!0,this.#fetch(INITIAL_QUERY).then(data=>{const html=buildBoxHtml(data?.response?.products);html&&(this.#initialHtml=html),this.#activeInput&&document.activeElement===this.#activeInput&&(this.#activeInput.value||"").trim().length<this.#minChars()&&this.#render(this.#initialHtml||'<div class="unx-no-results" role="status">No results found</div>')}).catch(error=>{this.#initialFetched=!1,error?.name!=="AbortError"&&this.#log("error",error)}))}#bindEvents(){const selector=this.#inputSelector(),signal=this.#controller.signal;document.addEventListener("focusin",event=>{const input=event.target?.closest?.(selector);input&&this.#onFocus(input)},{capture:!0,signal}),document.addEventListener("input",event=>{const input=event.target?.closest?.(selector);input&&this.#onInput(input)},{capture:!0,signal}),document.addEventListener("keydown",event=>{const input=event.target?.closest?.(selector);input&&input===this.#activeInput&&this.#onKeydown(event)},{capture:!0,signal}),document.addEventListener("click",event=>{if(!this.#box||!this.#box.isConnected)return;const target=event.target;target&&(this.#box.contains(target)||this.#activeInput&&this.#activeInput.contains(target)||target.closest?.(selector)||this.#hide())},{signal}),document.addEventListener(ThemeEvents.sectionMorphed,()=>this.#onSectionMorphed(),{signal})}#onSectionMorphed(){let input=this.#activeInput;if(input&&!input.isConnected&&input.id){const replacement=document.getElementById(input.id);replacement instanceof HTMLInputElement&&(input=replacement)}!input||!input.isConnected||(this.#activeInput=input,this.#setupForm(input),this.#syncSubmitEnabled(input),document.activeElement===input&&this.#box&&!this.#box.isConnected&&this.#box.innerHTML!==""&&this.#mountBox(input))}#onFocus(input){this.#activeInput=input,this.#mountBox(input),this.#syncSubmitEnabled(input);
1const value=(input.value||"").trim();value.length>=this.#minChars()?this.#runQuery(value):this.#showInitial()}#onInput(input){this.#activeInput=input,this.#syncSubmitEnabled(input);const query=(input.value||"").trim();if(query.length<this.#minChars()){window.clearTimeout(this.#debounceTimer),this.#currentQuery="",this.#showInitial();return}query!==this.#currentQuery&&(window.clearTimeout(this.#debounceTimer),this.#debounceTimer=window.setTimeout(()=>this.#runQuery(query),this.#debounceDelay()))}#runQuery(query){this.#currentQuery=query,this.#fetch(query).then(data=>{if(!this.#activeInput||(this.#activeInput.value||"").trim()!==query)return;const html=buildBoxHtml(data?.response?.products)||`<div class="unx-no-results" role="status">No results found for "${escapeHtml(query)}"</div>`;this.#render(html)}).catch(error=>{error?.name!=="AbortError"&&this.#log("error",error)})}#showInitial(){if(this.#initialHtml){this.#render(this.#initialHtml);return}this.#render(LOADING_HTML),this.#prefetchInitial()}#mountBox(input){if(!this.#box){const box=document.createElement("div");box.id=RESULTS_ID,box.className=BOX_CLASS,box.setAttribute("role","listbox"),box.addEventListener("mousedown",event=>event.preventDefault()),box.addEventListener("click",event=>this.#onBoxClick(event)),box.addEventListener("mouseover",event=>this.#onBoxHover(event)),this.#box=box}input.nextElementSibling!==this.#box&&input.insertAdjacentElement("afterend",this.#box),input.setAttribute("aria-controls",RESULTS_ID),input.setAttribute("aria-owns",RESULTS_ID),input.setAttribute("aria-expanded","true"),this.#setupForm(input)}#setupForm(input){const form=input.closest("form");if(!form||form.__unbxdAsBound)return;form.__unbxdAsBound=!0;const submit=event=>{const query=(input.value||"").trim();event.preventDefault(),query&&this.#navigate(query)};form.addEventListener("submit",submit,{signal:this.#controller.signal});const submitButton=form.querySelector('button[type="submit"], [type="submit"]');submitButton&&submitButton.addEventListener("click",submit,{signal:this.#controller.signal}),this.#syncSubmitEnabled(input)}#syncSubmitEnabled(input){const form=input.closest("form");if(!form)return;const submitButton=form.querySelector('button[type="submit"], [type="submit"]');if(!submitButton)return;const hasQuery=(input.value||"").trim().length>0;submitButton.disabled=!hasQuery,submitButton.setAttribute("aria-disabled",hasQuery?"false":"true")}#render(html){this.#box&&(this.#activeInput&&!this.#box.isConnected&&this.#activeInput.insertAdjacentElement("afterend",this.#box),this.#box.innerHTML=html,this.#box.classList.add(BOX_CLASS),this.#activeIndex=-1,window.clearTimeout(this.#hoverTimer),this.#lastHoverValue="",this.#activeInput&&this.#activeInput.setAttribute("aria-expanded","true"))}#onBoxHover(event){const item=event.target?.closest?.('.unx-suggestions [data-action="search"]');if(!item)return;const value=item.getAttribute("data-value")||"";!value||value===this.#lastHoverValue||(this.#lastHoverValue=value,window.clearTimeout(this.#hoverTimer),this.#hoverTimer=window.setTimeout(()=>this.#loadHoverProducts(value),120))}#loadHoverProducts(value){const cached=this.#hoverCache.get(value);if(cached!==void 0){this.#lastHoverValue===value&&this.#updateProductsColumn(cached);return}this.#fetch(value).then(data=>{const rows=productRowsHtml(toArray(data?.response?.products).filter(isProductEntry));this.#hoverCache.set(value,rows),this.#lastHoverValue===value&&this.#updateProductsColumn(rows)}).catch(error=>{error?.name!=="AbortError"&&this.#log("error",error)})}#updateProductsColumn(rows){if(!this.#box)return;const column=this.#box.querySelector(".unx-popular-products");column?column.innerHTML=rows:rows&&this.#box.insertAdjacentHTML("afterbegin",`<div class="unx-popular-products">${rows}</div>`)}#hide(){this.#box&&this.#box.parentNode&&this.#box.parentNode.removeChild(this.#box),this.#activeIndex=-1,this.#activeInput&&this.#activeInput.setAttribute("aria-expanded","false")}#onBoxClick(event){const item=event.target?.closest?.("[data-action]");if(!item)return;const action=item.getAttribute("data-action"),value=item.getAttribute("data-value")||"";action==="search"&&(event.preventDefault(),this.#navigate(value))}#onKeydown(event){if(!this.#box||!this.#box.isConnected)return;const items=Array.from(this.#box.querySelectorAll(".unx-item"));if(event.key==="Escape"){this.#hide();return}if(event.key==="Enter"){const item=this.#activeIndex>=0?items[this.#activeIndex]:null;if(item){if(event.preventDefault(),item.getAttribute("data-action")==="search")this.#navigate(item.getAttribute("data-value")||"");else{const href=item.getAttribute("href");href&&(window.location.href=href)}return}const query=(this.#activeInput?.value||"").trim();event.preventDefault(),query&&this.#navigate(query);return}if(event.key!=="ArrowDown"&&event.key!=="ArrowUp"||!items.length)return;event.preventDefault(),event.key==="ArrowDown"?this.#activeIndex=Math.min(this.#activeIndex+1,items.length-1):this.#activeIndex=Math.max(this.#activeIndex-1,-1),items.forEac
1h((item,index)=>this.#setItemActive(item,index===this.#activeIndex));const active=items[this.#activeIndex];if(active){active.scrollIntoView({block:"nearest"});const value=active.getAttribute("data-value");value&&this.#activeInput&&(this.#activeInput.value=value)}}#setItemActive(item,active){item.setAttribute("aria-selected",active?"true":"false"),active?(item.style.background="#f5f4ff",item.style.color="#5a3fd4"):(item.style.background="",item.style.color="")}#navigate(query){const trimmed=(query||"").trim();if(!trimmed)return;this.#activeInput&&(this.#activeInput.value=trimmed);const searchPath=typeof Theme<"u"&&Theme.routes?.search_url?Theme.routes.search_url:"/search";window.location.href=`${searchPath}?q=${encodeURIComponent(trimmed)}`}#log(level,...args){level==="error"?console.error("[Unbxd:autosuggest]",...args):getConfig().debug&&console.log("[Unbxd:autosuggest]",...args)}}customElements.get("unbxd-autosuggest")||customElements.define("unbxd-autosuggest",UnbxdAutosuggest);function ensureHost(){document.querySelector("unbxd-autosuggest")||getConfig().autosuggest?.enabled&&document.body.appendChild(document.createElement("unbxd-autosuggest"))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",ensureHost,{once:!0}):ensureHost();
2//# sourceMappingURL=/cdn/shop/t/82/assets/unbxd-autosuggest.js.map?v=184389818124456281531789986639

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.