PageSourceSearch

https://www.aliceandolivia.com/cdn/shop/t/314/assets/predictive-search.CjLh3YBI.min.js

js aliceandolivia.com collected 2026-10-01 10:35:53 UTC 17,764 bytes, 1 lines download raw bytes

1var e,t=Object.defineProperty,i=e=>{throw TypeError(e)},s=(e,i,s)=>((e,i,s)=>i in e?t(e,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[i]=s)(e,"symbol"!=typeof i?i+"":i,s),r=(e,t,s)=>t.has(e)||i("Cannot "+s),n=(e,t,i)=>(r(e,t,"read from private field"),i?i.call(e):t.get(e)),o=(e,t,i,s)=>(r(e,t,"write to private field"),s?s.call(e,i):t.set(e,i),i);import{getNostoSearchClientSettings as l,NOSTO_SEARCH_PRODUCT_FIELDS as a,unwrapNostoSearchResponse as c,normalizeNostoProductHits as d,resolveNostoProductTotal as h,escapeHtml as u,buildDynamicProductCardMarkup as p}from"./nosto-storefront-search.Cv8LUWN1.min.js";import{B as v}from"./BaseElement.DADCq26n.min.js";import{L as m}from"./LiveRegionUtility.Hp9s8h0e.min.js";import"./vendor-lit.Dzz78LSH.min.js";import"./aria-live-region-context.DDahWXfJ.min.js";function g(e){var t;return((null==(t=null==e?void 0:e.keywords)?void 0:t.hits)??[]).map(e=>"string"==typeof e?{keyword:e}:{keyword:(null==e?void 0:e.keyword)??(null==e?void 0:e.text)??(null==e?void 0:e.name)??""}).filter(e=>e.keyword)}function f(e){var t;return((null==(t=null==e?void 0:e.popularSearches)?void 0:t.hits)??[]).map(e=>({keyword:(null==e?void 0:e.query)??(null==e?void 0:e.keyword)??(null==e?void 0:e.text)??""})).filter(e=>e.keyword)}const y=class t extends v{constructor(){var t,r;super(...arguments),s(this,"$liveRegionUtility",new m(this)),s(this,"searchTerm",""),s(this,"input"),s(this,"predictiveSearchResults"),s(this,"cachedResults",{}),s(this,"abortController",new AbortController),s(this,"allPredictiveSearchInstances",[]),s(this,"nostoAutocompleteRequestId",0),s(this,"_focusOutTimeout",null),s(this,"_unifiedSearchRestoreParent",null),s(this,"_unifiedSearchRestoreNext",null),s(this,"_promotedToViewport",!1),t=this,(r=e).has(t)?i("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(t):r.set(t,null)}connectedCallback(){if(super.connectedCallback(),this.input=this.querySelector('summary input[type="search"][form]')||this.querySelector('summary input[type="search"]')||this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.allPredictiveSearchInstances=document.querySelectorAll("predictive-search"),this.setupEventListeners(),this.syncUnifiedFieldOverlayVisibility(),this.isPersistentSuggestions()){const e=this.closest("[data-nosto-search-empty]");(null==e?void 0:e.hasAttribute("hidden"))?this.observeEmptySectionReveal(e):this.activatePersistentSuggestions()}}isPersistentSuggestions(){return this.hasAttribute("data-persistent-suggestions")}disconnectedCallback(){var t;null==(t=n(this,e))||t.disconnect(),o(this,e,null),super.disconnectedCallback()}observeEmptySectionReveal(t){const i=()=>{var i;t.hasAttribute("hidden")||(null==(i=n(this,e))||i.disconnect(),o(this,e,null),this.activatePersistentSuggestions())};t.hasAttribute("hidden")?(o(this,e,new MutationObserver(i)),n(this,e).observe(t,{attributes:!0,attributeFilter:["hidden"]})):i()}activatePersistentSuggestions(){if(!this.isPersistentSuggestions()||!this.input)return;const e=()=>{this.open();const e=this.cacheKeyForTerm("");this.cachedResults[e]?this.renderSearchResults(this.cachedResults[e]):this.getSearchResults("")},t=(i=0)=>{this.prefersNostoPredictiveSearch()||i>=8?e():window.setTimeout(()=>t(i+1),200*(i+1))};t()}isUnifiedField(){return Boolean(this.closest("details[data-search-unified-field]"))}isInsideMenuDrawer(){return Boolean(this.closest("#mobile-menu-drawer")||this._promotedToViewport)}shouldPromoteUnifiedSearchToViewport(){return this.isUnifiedField()&&this.isInsideMenuDrawer()}closeMenuDrawer(){var e;const t=document.getElementById("mobile-menu-drawer");null==(e=null==t?void 0:t.hide)||e.call(t)}promoteUnifiedSearchToViewport(){if(this._promotedToViewport||!this.shouldPromoteUnifiedSearchToViewport())return;const e=this.parentElement;e&&(this._unifiedSearchRestoreParent=e,this._unifiedSearchRestoreNext=this.nextSibling,document.body.appendChild(this),this.classList.add(...t.VIEWPORT_PROMOTION_CLASSES),this._promotedToViewport=!0)}restoreUnifiedSearchFromViewport(){this._promotedToViewport&&this._unifiedSearchRestoreParent&&(this._unifiedSearchRestoreParent.insertBefore(this,this._unifiedSearchRestoreNext),this.classList.remove(...t.VIEWPORT_PROMOTION_CLASSES),this._promotedToViewport=!1,this._unifiedSearchRestoreParent=null,this._unifiedSearchRestoreNext=null)}syncUnifiedFieldOverlayVisibility(){if(!this.isUnifiedField())return;const e=this.closest("details[data-search]"),t=this.querySelector("[data-predictive-search-panel]");if(!e||!t)return;const i=e.open;t.classList.toggle("hidden",!i),t.classList.toggle("flex",i)}ensureDetailsOverlayOpen(){const e=this.closest("details[data-search]");if(!(null==e?void 0:e.hasAttribute("data-search-unified-field")))return;this.shouldPromoteUnifiedSearchToViewport()&&this.promoteUnifiedSearchToViewport();const t=!e.open;t&&e.setAttribute("open","");const i=()=>{var e;document.activeElement!==this.input&&(null==(e=this.input)||e.focus({preventScroll:!0}))};t&&this._promotedToViewport?(this.closeMenuDrawer(),requestAnimationFrame(()=>{requestAnimationFrame(i)})):t&&this.input&&requestAnimationFrame(i),this.syncUnifiedFieldOverlayVisibility()}onUnifiedFieldActivate(){this.ensureDetailsOverlayOpen(),this.syncUnifiedFieldOverlayVisibility()}onUnifiedFieldPointerDown(e){"mouse"===e.pointerType&&0!==e.button||this.onUnifiedFieldActivate()}get searchForTextElement(){return this.querySelector("[data-predictive-search-search-for-text]")}setupEventListeners(){var e;(null==(e=this.input)?void 0:e.form)&&(this.input.form.addEventListener("submit",this.onFormSubmit.bind(this)),this.input.addEventListener("focus",this.onFocus.bind(this)),this.input.addEventListener("input",this.onChange.bind(this)),this.isUnifiedField()&&(this.input.addEventListener("pointerdown",this.onUnifiedFieldPointerDown.bind(this)),this.input.addEventListener("click",this.onUnifiedFieldActivate.bind(this))),this.addEventListener("focusout",this.onFocusOut.bind(this)),this.addEventListener("keyup",this.onKeyup.bind(this)),this.addEventListener("keydown",this.onKeydown.bind(this)),this.addEventListener("click",this.onNostoProductHitClick.bind(this)))}onNostoProductHitClick(e){var t,i,s,r,n,o,l;if(!(null==(i=null==(t=window.__VENDORS__)?void 0:t.nosto)?void 0:i.predictiveSearch))return;const a=null==(r=(s=e.target).closest)?void 0:r.call(s,"[data-nosto-hit][data-product-id]");if(!a)return;const c=a.getAttribute("data-product-id"),d=(null==(o=(n=e.target).closest)?void 0:o.call(n,"a[data-product-url], a[data-nosto-hit]"))??a.querySelector("a[data-product-url], a[data-nosto-hit]");c&&"function"==typeof window.nostojs&&(null==(l=window.nostojs)||l.call(window,e=>{var t;return null==(t=e.recordSearchClick)?void 0:t.call(e,"autocomplete",{productId:c,url:(null==d?void 0:d.href)??""})}))}get query(){return this.input.value.trim()}prefersNostoPredictiveSearch(){var e,t;return!0===(null==(t=null==(e=window.__VENDORS__)?void 0:e.nosto)?void 0:t.predictiveSearch)&&"function"==typeof window.nostojs&&"object"==typeof window.__NOSTO_PREDICTIVE_I18N__&&null!==window.__NOSTO_PREDICTIVE_I18N__}cacheKeyForTerm(e){const t=e.replace(/ /g,"-").toLowerCase();return`${this.prefersNostoPredictiveSearch()?"n":"s"}:24:${t}`}onChange(){var e,t;this.ensureDetailsOverlayOpen();const i=this.query;if(this.searchTerm&&i.startsWith(this.searchTerm)||null==(e=this.querySelector("#predictive-search-results-groups-wrapper"))||e.remove(),this.updateSearchForTerm(this.searchTerm,i),this.searchTerm=i,!this.searchTerm.length)return this.prefersNostoPredictiveSearch()?(null==(t=this.querySelector("#predictive-search-results-groups-wrapper"))||t.remove(),void this.get
1SearchResults("")):void this.close(!0);this.getSearchResults(this.searchTerm)}onFormSubmit(e){var t;const i=null==(t=window.__VENDORS__)?void 0:t.nosto,s=this.querySelector('[aria-selected="true"] a'),r=!this.query.length||Boolean(s);(null==i?void 0:i.predictiveSearch)&&"function"==typeof window.nostojs&&!r&&this.query.length>0&&window.nostojs(e=>{var t;return null==(t=e.recordSearchSubmit)?void 0:t.call(e,this.query)}),r&&e.preventDefault()}onFocus(){this.ensureDetailsOverlayOpen();const e=this.query;if(e.length)this.searchTerm!==e?this.onChange():"true"===this.getAttribute("results")?this.open():this.getSearchResults(this.searchTerm);else if(this.prefersNostoPredictiveSearch()){const e=()=>{document.activeElement===this.input&&("true"===this.getAttribute("results")&&this.querySelector("#predictive-search-results-groups-wrapper")?this.open():this.getSearchResults(""))};this.isUnifiedField()?requestAnimationFrame(e):e()}}onFocusOut(e){if(this.isPersistentSuggestions())return;const t=e.relatedTarget;t&&this.contains(t)||(this._focusOutTimeout&&clearTimeout(this._focusOutTimeout),this._focusOutTimeout=setTimeout(()=>{this._focusOutTimeout=null,this.contains(document.activeElement)||this.close()},this.isUnifiedField()?120:0))}onKeyup(e){switch(this.isPersistentSuggestions()||this.query.length||this.prefersNostoPredictiveSearch()||this.close(!0),e.code){case"ArrowUp":e.preventDefault(),this.switchOption("up");break;case"ArrowDown":e.preventDefault(),this.switchOption("down");break;case"Enter":e.preventDefault(),this.selectOption()}}onKeydown(e){"ArrowUp"!==e.code&&"ArrowDown"!==e.code||e.preventDefault()}updateSearchForTerm(e,t){var i;const s=null==(i=this.searchForTextElement)?void 0:i.innerText;if(!s||!e.length)return;if((s.match(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"))||[]).length>1)return;const r=s.replace(e,t);this.searchForTextElement.innerText=r}switchOption(e){if(!this.getAttribute("open"))return;const t="up"===e;this.selectedElement=this.querySelector('[aria-selected="true"]');const i=Array.from(this.querySelectorAll("li, [data-predictive-search-item]")).filter(e=>null!==e.offsetParent);let s=0;if(t&&!this.selectedElement)return;let r=-1,n=0;for(;-1===r&&n<i.length;)i[n]===this.selectedElement&&(r=n),n++;if(!t&&this.selectedElement?s=r===i.length-1?0:r+1:t&&(s=0===r?i.length-1:r-1),s===r)return;const o=i[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()}commitCachedResultsMarkdown(e,t){this.allPredictiveSearchInstances.forEach(i=>{i.cachedResults[e]=t}),this.renderSearchResults(t)}fetchShopifyPredictiveSearch(e){const t=this.cacheKeyForTerm(e);fetch(`${window.routes.predictive_search_url}?q=${encodeURIComponent(e)}&section_id=predictive-search`,{signal:this.abortController.signal}).then(e=>{if(!e.ok)throw new Error(String(e.status));return e.text()}).then(e=>{const i=(new DOMParser).parseFromString(e,"text/html").querySelector("#shopify-section-predictive-search"),s=(null==i?void 0:i.innerHTML)??"";this.commitCachedResultsMarkdown(t,s)}).catch(e=>{if(20!==(null==e?void 0:e.code))throw this.close(),e})}fetchNostoPredictiveSearch(e){var t;const i=this.cacheKeyForTerm(e),s=++this.nostoAutocompleteRequestId;null==(t=window.nostojs)||t.call(window,t=>{if("function"!=typeof t.search)return void this.fetchShopifyPredictiveSearch(e);const r=l(t);t.search(function(e){const t=0===e.length,i=t?{emptyQueryMatchesAll:!0}:{},s={query:e,products:{fields:[...a],size:4,...i}};return t&&(s.keywords={fields:["keyword"],size:4,...i},s.categories={size:4,...i},s.popularSearches={size:4,...i}),s}(e),{track:"autocomplete",redirect:!1}).then(t=>{if(s!==this.nostoAutocompleteRequestId)return;const{markup:n}=function(e,t,i){const s=c(t),r=window.__NOSTO_PREDICTIVE_I18N__,n=e.length>0,o=n?[]:[...g(s),...f(s)],l=n?[]:function(e){var t;return((null==(t=null==e?void 0:e.categories)?void 0:t.hits)??[]).map(e=>({name:(null==e?void 0:e.name)??(null==e?void 0:e.fullName)??"",url:(null==e?void 0:e.url)??(null==e?void 0:e.urlPath)??""})).filter(e=>e.url&&e.name)}(s),a=d(s,i).slice(0,4),v=o.length+l.length+a.length,m=n?h(s,a.length):v,y=function(e,t,i){if(!e.length||t<=0)return"";const s=u((null==i?void 0:i.resultsHeading)??"Results"),r=u((null==i?void 0:i.viewAllResults)??"View all results");return`<header class="mx-pagegutter flex items-baseline justify-between gap-sm pb-xs md:pb-sm" id="predictive-search-results-header">\n  <h4 class="h4">${s}<sup class="ml-3xs caption text-foreground-secondary">(${t})</sup></h4>\n  <a href="${window.routes.search_url}?q=${encodeURIComponent(e)}&type=product&options%5Bprefix%5D=last" class="shrink-0 text-heading-6-cap font-normal tracking-[0.6px] text-foreground uppercase underline underline-offset-4">${r}</a>\n</header>`}(e,m,r),S=e.length?e:(null==r?void 0:r.suggestions)??"Suggestions",w=0===v?((null==r?void 0:r.noResultsTpl)??"No results").replace(/__NOSTO_Q__/g,S):1===v?((null==r?void 0:r.liveRegionOneTpl)??"1 result").replace(/__NOSTO_Q__/g,S):((null==r?void 0:r.liveRegionOtherTpl)??"").replace(/__NOSTO_Q__/g,S).replace(/__NOSTO_C__/g,String(v));let b="",_="";if(o.length||l.length){const e=[...o.map(e=>({type:"keyword",entry:e})),...l.map(e=>({type:"category",entry:e}))].slice(0,4).map(({type:e,entry:t},i)=>"keyword"===e?`<li class="shrink-0 aria-selected:bg-background md:px-pagegutter" id="predictive-search-option-nosto-kw-${i+1}" role="option" aria-selected="false"><a class="block w-fit border-0 border-b border-b-border-01 text-heading-6-cap font-normal tracking-[0.6px] text-foreground uppercase" href="${window.routes.search_url}?q=${encodeURIComponent(t.keyword)}&type=product&options%5Bprefix%5D=last" tabindex="-1">${u(t.keyword)}</a></li>`:`<li class="shrink-0 aria-selected:bg-background md:px-pagegutter" id="predictive-search-option-nosto-category-${i+1}" role="option" aria-selected="false"><a class="block border-0 text-heading-6-cap font-normal tracking-[0.6px] text-foreground uppercase" href="${u(t.url)}" tabindex="-1">${u(t.name)}</a></li>`).join("");b=`<div class="grid gap-xs md:gap-md">\n  <h2 class="mx-pagegutter text-heading-5 text-foreground-secondary uppercase" id="predictive-search-queries">${u((null==r?void 0:r.suggestions)??"Suggestions")}</h2>\n  <ul class="flex flex-row text-heading-6-cap flex-wrap gap-[35px] px-pagegutter pb-lg md:pb-0 md:grid md:gap-xs md:px-0" id="predictive-search-results-queries-list" role="group" aria-labelledby="predictive-search-queries">${e}</ul>\n</div>`}if(a.length){const e=a.map((e,t)=>{const i=p(e,{template:"product-card-predictive-modal",forceEagerImage:!0,productId:e.productId?String(e.productId):void 0});return i?`<li class="min-w-0 aria-selected:bg-background" id="predictive-search-option-nosto-product-${t+1}" role="option" aria-selected="false">${i}</li>`:""}
1).filter(Boolean).join("");_=`<div class="grid gap-sm has-[ul:empty]:hidden">\n  <ul class="grid grid-cols-2 gap-x-xs gap-y-sm px-pagegutter md:grid-cols-4 md:gap-x-sm" id="predictive-search-results-products-list" role="group" aria-label="${u((null==r?void 0:r.products)??"Products")}">${e}</ul>\n</div>`}const x=_?n?_:`<div class="md:flex-1">${_}</div>`:"";let R="";return n&&(a.length||m>0)?R=`<div class="grid gap-sm pt-md lg:pt-lg" id="predictive-search-results-groups-wrapper">\n  ${y}\n  ${x}\n</div>`:!n&&v>0&&(R=`<div class="grid gap-sm pt-md lg:pt-lg" id="predictive-search-results-groups-wrapper">\n  <div class="md:flex md:gap-sm md:pt-lg">\n  <div class="flex flex-col gap-md empty:hidden md:basis-50">${b}</div>${x}\n  </div>\n</div>`),{markup:`<div id="predictive-search-results" role="listbox" section-id="predictive-search">${R}\n</div>\n<span class="hidden" data-predictive-search-live-region-count-value>${u(w)}</span>`}}(e,t,r);this.commitCachedResultsMarkdown(i,n)}).catch(()=>{s===this.nostoAutocompleteRequestId&&this.fetchShopifyPredictiveSearch(e)})})}getSearchResults(e){const t=this.cacheKeyForTerm(e);this.setLiveRegionLoadingState(),this.cachedResults[t]?this.renderSearchResults(this.cachedResults[t]):this.prefersNostoPredictiveSearch()?this.fetchNostoPredictiveSearch(e):this.fetchShopifyPredictiveSearch(e)}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(){var e;this.removeAttribute("loading");const t=this.querySelector("[data-predictive-search-live-region-count-value]"),i=(null==(e=null==t?void 0:t.textContent)?void 0:e.trim())||this.loadingText||"";this.$liveRegionUtility.announce({message:i})}open(){this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0),this.syncUnifiedFieldOverlayVisibility()}close(e=!1){this.closeResults(e)}closeResults(e=!1){var t,i,s;if(this.isPersistentSuggestions()&&!e)return;e&&(this.searchTerm="",this.input&&(this.input.value=""),this.removeAttribute("results"),null==(t=this.predictiveSearchResults)||t.replaceChildren());const r=this.querySelector('[aria-selected="true"]');r&&r.setAttribute("aria-selected",!1),this.input&&(this.input.setAttribute("aria-activedescendant",""),this.input.setAttribute("aria-expanded",!1)),this.removeAttribute("loading"),this.removeAttribute("open"),null==(i=this.predictiveSearchResults)||i.removeAttribute("style"),this.isUnifiedField()&&(null==(s=this.closest("details[data-search]"))||s.removeAttribute("open"),this.syncUnifiedFieldOverlayVisibility(),this.restoreUnifiedSearchFromViewport())}};e=new WeakMap,s(y,"VIEWPORT_PROMOTION_CLASSES",["fixed","inset-0","z-[45]","pointer-events-none","flex","flex-col"]);let S=y;window.customElements.define("predictive-search",S);export{S as PredictiveSearch};

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.