1import{morph,MORPH_OPTIONS}from"@theme/morph";class SectionRenderer{#cache=new Map;#abortControllersBySectionId=new Map;#pendingRendersBySectionId=new Map;#pendingPromises=new Map;constructor(){window.addEventListener("load",this.#cachePageSections.bind(this))}async renderSection(sectionId,options){const{cache=!Shopify.designMode,mode="full",injectStylesheet=!1}=options??{},{url}=options??{};this.#abortPendingMorph(sectionId);const abortController=new AbortController;this.#abortControllersBySectionId.set(sectionId,abortController);const renderPromise=this.#renderSection(sectionId,{cache,mode,injectStylesheet,url},abortController);return this.#pendingRendersBySectionId.set(sectionId,{abortController,promise:renderPromise}),renderPromise}async#renderSection(sectionId,{cache,mode,injectStylesheet,url},abortController){let sectionHTML="";try{sectionHTML=await this.getSectionHTML(sectionId,cache,url,abortController.signal)}catch(error){if(abortController.signal.aborted){const pendingRender=this.#pendingRendersBySectionId.get(sectionId);return pendingRender&&pendingRender.abortController!==abortController?pendingRender.promise:sectionHTML}throw error}finally{this.#abortControllersBySectionId.get(sectionId)===abortController&&this.#abortControllersBySectionId.delete(sectionId),this.#pendingRendersBySectionId.get(sectionId)?.abortController===abortController&&this.#pendingRendersBySectionId.delete(sectionId)}return abortController.signal.aborted||morphSection(sectionId,sectionHTML,{mode,injectStylesheet}),sectionHTML}#abortPendingMorph(sectionId){const existingAbortController=this.#abortControllersBySectionId.get(sectionId);existingAbortController&&(existingAbortController.abort(),this.#abortControllersBySectionId.delete(sectionId))}async getSectionHTML(sectionId,useCache=!0,url=new URL(window.location.href),signal){const sectionUrl=buildSectionRenderingURL(sectionId,url),shouldSharePendingPromise=!signal;let pendingPromise=this.#pendingPromises.get(sectionUrl);if(pendingPromise)return pendingPromise;if(useCache){const cachedHTML=this.#cache.get(sectionUrl);if(cachedHTML)return cachedHTML}pendingPromise=fetch(sectionUrl,{signal}).then(response=>response.text()),shouldSharePendingPromise&&(pendingPromise=pendingPromise.finally(()=>{this.#pendingPromises.delete(sectionUrl)}),this.#pendingPromises.set(sectionUrl,pendingPromise));const sectionHTML=await pendingPromise;return this.#cache.set(sectionUrl,sectionHTML),sectionHTML}#cachePageSections(){for(const section of document.querySelectorAll(".shopify-section")){const url=buildSectionRenderingURL(section.id);if(this.#cache.get(url)||containsShadowRoot(section))return;this.#cache.set(url,section.outerHTML)}}}const SECTION_ID_PREFIX="shopify-section-";function buildSectionRenderingURL(sectionId,url=new URL(window.location.href)){return url.searchParams.set("section_id",normalizeSectionId(sectionId)),url.searchParams.sort(),url.toString()}export function buildSectionSelector(sectionId){return`${SECTION_ID_PREFIX}${sectionId}`}export function normalizeSectionId(sectionId){return sectionId.replace(new RegExp(`^${SECTION_ID_PREFIX}`),"")}function containsShadowRoot(element){return!!element.shadowRoot||Array.from(element.children).some(containsShadowRoot)}export async function morphSection(sectionId,html,options={}){const{mode="full",injectStylesheet=!1}=options,fragment=new DOMParser().parseFromString(html,"text/html"),existingElement=document.getElementById(buildSectionSelector(sectionId)),newElement=fragment.getElementById(buildSectionSelector(sectionId));if(!existingElement)throw new Error(`Section ${sectionId} not found`);if(!newElement)throw new Error(`Section ${sectionId} not found in the section rendering response`);morph(existingElement,newElement,{...MORPH_OPTIONS,hydrationMode:mode==="hydration"}),injectStylesheet&&injectSectionStylesheet(fragment,existingElement)}function injectSectionStylesheet(fragment,sectionElement){const newStylesheet=fragment.querySelector("style[data-section-stylesheet]");if(!newStylesheet)return;const existingStylesheet=sectionElement.querySelector("style[data-section-stylesheet]");existingStylesheet?existingStylesheet.textContent=newStylesheet.textContent:sectionElement.prepe
1nd(newStylesheet)}export const sectionRenderer=new SectionRenderer; 2//# sourceMappingURL=/cdn/shop/t/3/assets/section-renderer.js.map?v=44511745960026958271782122108
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.