PageSourceSearch

https://www.peachandlily.com/cdn/shop/t/595/assets/predictive-search.mTc5lWYF.min.js

js peachandlily.com collected 2026-10-02 04:23:41 UTC 5,453 bytes, 1 lines download raw bytes

1var e=Object.defineProperty,t=(t,s,i)=>((t,s,i)=>s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[s]=i)(t,"symbol"!=typeof s?s+"":s,i);import{B as s}from"./BaseElement.DY9JFAhm.min.js";import{L as i}from"./LiveRegionUtility.H7cxURKH.min.js";import"./vendor-lit.DPhFYw_F.min.js";import"./aria-live-region-context.CV5M0wsv.min.js";window.customElements.define("predictive-search",class extends s{constructor(){super(...arguments),t(this,"$liveRegionUtility",new i(this)),t(this,"resultsMaxHeight"),t(this,"searchTerm",""),t(this,"input"),t(this,"clearButton"),t(this,"predictiveSearchResults"),t(this,"cachedResults",{}),t(this,"abortController",new AbortController),t(this,"allPredictiveSearchInstances",[])}connectedCallback(){super.connectedCallback(),this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.allPredictiveSearchInstances=document.querySelectorAll("predictive-search"),this.clearButton=this.querySelector("[data-search-clear]"),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.onChange.bind(this)),this.addEventListener("keyup",this.onKeyup.bind(this)),this.addEventListener("keydown",this.onKeydown.bind(this)),this.clearButton.addEventListener("click",e=>{this.onChange(e)})}get query(){return this.input.value.trim()}onChange(e){var t,s;e.target==this.clearButton&&(this.searchTerm="",null==(t=this.input)||t.removeAttribute("value"),this.classList.remove("has-terms"),this.close(!0));const i=this.query;this.searchTerm&&i.startsWith(this.searchTerm)||null==(s=this.querySelector("#predictive-search-results-groups-wrapper"))||s.remove(),this.updateSearchForTerm(this.searchTerm,i),this.searchTerm=i,this.searchTerm.length?this.getSearchResults(this.searchTerm):this.close(!0)}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():"true"===this.getAttribute("results")?this.open():this.getSearchResults(this.searchTerm))}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()}}onKeydown(e){"ArrowUp"!==e.code&&"ArrowDown"!==e.code||e.preventDefault()}updateSearchForTerm(e,t){var s;const i=null==(s=this.searchForTextElement)?void 0:s.innerText;if(i){if(i.match(new RegExp(e,"g")).length>1)return;const s=i.replace(e,t);this.searchForTextElement.innerText=s}}switchOption(e){if(!this.getAttribute("open"))return;const t="up"===e;this.selectedElement=this.querySelector('[aria-selected="true"]');const s=Array.from(this.querySelectorAll("li, [data-predictive-search-item]")).filter(e=>null!==e.offsetParent);let i=0;if(t&&!this.selectedElement)return;let r=-1,n=0;for(;-1===r&&n<=s.length;)s[n]===this.selectedElement&&(r=n),n++;if(!t&&this.selectedElement?i=r===s.length-1?0:r+1:t&&(i=0===r?s.length-1:r-1),i===r)return;const h=s[i];h.setAttribute("aria-selected",!0),this.selectedElement&&this.selectedElement.setAttribute("aria-selected",!1),this.input.setAttribute("aria-activedescendant",h.id)}selectOption(){const e=this.querySelector('[aria-selected="true"] a, button[aria-selected="true"]');e&&e.click()}getSearchResults(e){const t=e.replace(" ","-").toLowerCase();this.setLiveRegionLoadingState(),this.cachedResults[t]?this.renderSearchResults(this.cachedResults[t]):fetch(`${window.routes.predictive_search_url}?q=${encodeURIComponent(e)}&section_id=predictive-search`,{signal:this.abortController.signal}).then(e=>{if(!e.ok){var t=new Error(e.status);throw this.close(),t}return e.text()}).then(e=>{const s=(new DOMParser).parseFromString(e,"text/html").querySelector("#shopify-section-predictive-search").innerHTML;this.allPredictiveSearchInstances.forEach(e=>{e.cachedResults[t]=s}),this.renderSearchResults(s)}).catch(e=>{if(20!==(null==e?void 0:e.code))throw this.close(),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(){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 t=this.querySelector('[aria-selected="true"]');t&&t.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")}});

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.