1import{buildSectionSelector,normalizeSectionId}from"@theme/section-renderer";const sectionDocumentPromises=new Map;class LazyContentSection extends HTMLElement{#observer;#contentLoadPromise=null;load(){this.#observer?.disconnect(),this.#observer=void 0;const stylesheetUrl=this.dataset.stylesheet;return stylesheetUrl&&this.#ensureStylesheetsDeferred(stylesheetUrl),this.dataset.script&&this.#ensureScriptDeferred(this.dataset.script),this.hasAttribute("data-loaded")?Promise.resolve():this.dataset.sectionId?this.#loadFromSectionApi():(this.#syncLoadedUi(),Promise.resolve())}#pendingStylesheetUrl;#pendingContentFetch=!1;connectedCallback(){const stylesheetUrl=this.dataset.stylesheet,needsContentFetch=!!this.dataset.sectionId&&!this.hasAttribute("data-loaded");if(this.#pendingStylesheetUrl=stylesheetUrl,this.#pendingContentFetch=needsContentFetch,this.dataset.loadImmediately==="true"){stylesheetUrl&&this.#ensureStylesheetsDeferred(stylesheetUrl),this.dataset.script&&this.#ensureScriptDeferred(this.dataset.script),this.#syncLoadedUi();return}if(!stylesheetUrl&&!needsContentFetch){this.#syncLoadedUi();return}this.#observeNearViewport(stylesheetUrl,needsContentFetch)}disconnectedCallback(){this.#observer?.disconnect(),this.#observer=void 0}loadNow(){return this.#observer?.disconnect(),this.#observer=void 0,this.#pendingStylesheetUrl&&this.#ensureStylesheetsDeferred(this.#pendingStylesheetUrl),this.dataset.script&&this.#ensureScriptDeferred(this.dataset.script),this.#pendingContentFetch?this.#loadFromSectionApi():Promise.resolve()}#observeNearViewport(stylesheetUrl,fetchContent){const rootMargin=this.dataset.rootMargin||"200px 0px";this.#observer=new IntersectionObserver(entries=>{for(const entry of entries)if(entry.isIntersecting){this.#observer?.disconnect(),stylesheetUrl&&this.#ensureStylesheetsDeferred(stylesheetUrl),this.dataset.script&&this.#ensureScriptDeferred(this.dataset.script),fetchContent&&this.load();break}},{root:null,rootMargin,threshold:0}),this.#observer.observe(this)}#syncLoadedUi(){this.setAttribute("aria-busy","false"),this.dispatchEvent(new CustomEvent("lazy-content-section:loaded",{bubbles:!0}))}#ensureStylesheetsDeferred(value){value.split(",").map(url=>url.trim()).filter(Boolean).forEach(url=>this.#ensureStylesheetDeferred(url))}#ensureStylesheetDeferred(url){if(!url)return;const selector=`link[data-lazy-content-stylesheet][href="${CSS.escape(url)}"]`;if(document.head.querySelector(selector)||document.querySelector(`link[rel="stylesheet"][href="${CSS.escape(url)}"]`))return;const link=document.createElement("link");link.rel="stylesheet",link.href=url,link.media="print",link.dataset.lazyContentStylesheet="",link.onload=()=>{link.media="all"},document.head.appendChild(link)}#ensureScriptDeferred(src){if(!src||document.querySelector(`script[src="${CSS.escape(src)}"]`))return;const script=document.createElement("script");script.src=src,script.defer=!0,script.dataset.lazyContentScript="",document.head.appendChild(script)}async#ensureStylesheets(value){const urls=value.split(",").map(url=>url.trim()).filter(Boolean);await Promise.all(urls.map(url=>this.#ensureStylesheet(url)))}#ensureStylesheet(url){return!url||document.querySelector(`link[rel="stylesheet"][href="${CSS.escape(url)}"]`)||document.querySelector(`link[data-lazy-content-stylesheet][href="${CSS.escape(url)}"]`)?Promise.resolve():new Promise((resolve,reject)=>{const link=document.createElement("link");link.rel="stylesheet",link.href=url,link.dataset.lazyContentStylesheet="",link.onload=()=>resolve(),link.onerror=()=>reject(new Error(`Failed to load stylesheet: ${url}`)),document.head.appendChild(link)})}#ensureScript(src){return!src||document.querySelector(`script[src="${CSS.escape(src)}"]`)?Promise.resolve():new Promise((resolve,reject)=>{const script=document.createElement("script");script.src=src,script.defer=!0,script.dataset.lazyContentScript="",script.onload=()=>resolve(),script.onerror=()=>reject(new Error(`Failed to load script: ${src}`)),document.head.appendChild(script)})}#loadFromSectionApi(){return this.#contentLoadPromise||(this.#contentLoadPromise=this.#fetchAndMountSection()),this.#contentLoadPromise}async#fetchAndMountSection(){const rawId=this.dataset.sectionId??"",sectionId=normalizeSectionId(rawId),blockId=this.dataset.blockId??"";if(!sectionId){this.#fail(new Error("lazy-content-section: missing data-section-id"));return}this.dataset.stylesheet&&await this.#ensureStylesheets(this.dataset.stylesheet),this.dataset.script&&await this.#ensureScript(this.dataset.script);try{const wrapper=(await this.#getSectionDocument(sectionId)).getElementById(buildSectionSelector(sectionId)),inner=this.#findLazyInner(wrapper,blockId);if(!inner){this.#fail(new Error(blockId?`lazy-content-section: no .lazy-content-section__inner for block ${blockId}`:"lazy-content-section: no .lazy-content-section__inner in section response"));return}const cloned=inner.cloneNode(!0);this.replaceChildren(...cloned.childNodes),this.#activateScripts(this),this.setAttribute("data-loaded",""),this.setAttribute("aria-busy","false"),this.dispatchEvent(new CustomEvent("lazy-content-section:loaded",{bubbles:!0}))}catch(error){const err=error instanceof Error?error:new Error(String(error));this.#fail(err)}}#getSectionDocument(sectionId){let promise=sectionDocumentPromises.get(sectionId);return promise||(promise=this.#fetchSectionHtml(sectionId).then(html=>new DOMParser().parseFromString(html,"text/html")),sectionDocumentPromises.set(sectionId,promise)),promise}#findLazyInner(sectionRoot,blockId){return sectionRoot?blockId?sectionRoot.querySelector(`lazy-content-section[data-block-id="${CSS.escape(blockId)}"]`)?.querySelector(".lazy-content-section__inner")??null:(sectionRoot.querySelector("lazy-content-section[data-section-id]:not([data-block-id])")||sectionRoot.querySelector("lazy-content-section"))?.querySelector(".lazy-content-section__inner")??null:null}async#fetchSectionHtml(sectionId){const url=new URL(window.location.href);
1url.searchParams.set("section_id",sectionId),url.searchParams.sort();const response=await fetch(url.toString(),{headers:{Accept:"text/html","X-Requested-With":"XMLHttpRequest"}});if(!response.ok)throw new Error(`Section HTTP ${response.status}`);return response.text()}#activateScripts(root){root.querySelectorAll("script").forEach(script=>{const clone=document.createElement("script");for(const{name,value}of script.attributes)clone.setAttribute(name,value);clone.textContent=script.textContent,script.replaceWith(clone)})}#fail(error){this.#contentLoadPromise=null,this.setAttribute("aria-busy","false"),this.dataset.error=error.message,this.dispatchEvent(new CustomEvent("lazy-content-section:error",{bubbles:!0,detail:{error}}))}}customElements.get("lazy-content-section")||customElements.define("lazy-content-section",LazyContentSection); 2//# sourceMappingURL=/cdn/shop/t/2/assets/lazy-content-section.js.map?v=113755099889763321391783326697
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.