1import{Component as p}from"@theme/component";import{sectionRenderer as m}from"@theme/section-renderer";import{requestIdleCallback as u,viewTransition as f}from"@theme/utilities";import{ThemeEvents as l}from"@theme/events";import{PaginatedListAspectRatioHelper as w}from"@theme/paginated-list-aspect-ratio";import{renderResults as v}from"@theme/results-update";const g="ResultsList";function h(n=window.location){const e=new URLSearchParams(n.search);return e.delete("page"),e.sort(),`${n.pathname}?${e}`}function c(n=window.location){return Number(new URLSearchParams(n.search).get("page")??1)}function P({base:n,page:e,renderedBase:t,renderedPage:r}){return n!==t?"rebaseline":e===r?"ignore":"render"}class b extends p{pages=new Map;infinityScrollObserver;#t=null;#r=null;#a;get paginationMode(){const e=this.getAttribute("pagination-mode");return e==="infinite"||e==="ajax"?e:"reload"}#i=h();#s=c();connectedCallback(){super.connectedCallback();const e=this.querySelector('[ref="cardGallery"]');e&&(this.#a=new w({templateCard:e})),this.#c(),this.#h(),document.addEventListener(l.FilterUpdate,this.#p),this.paginationMode==="ajax"&&(this.addEventListener("click",this.#d),window.addEventListener("popstate",this.#u),document.addEventListener(l.resultsRendered,this.#f))}disconnectedCallback(){super.disconnectedCallback(),this.infinityScrollObserver&&this.infinityScrollObserver.disconnect(),document.removeEventListener(l.FilterUpdate,this.#p),this.removeEventListener("click",this.#d),window.removeEventListener("popstate",this.#u),document.removeEventListener(l.resultsRendered,this.#f)}#c(){!(this.refs.viewMoreNext||this.refs.viewMorePrevious)&&this.paginationMode!=="ajax"||(this.#e("next"),this.#e("previous"))}#h(){const{viewMorePrevious:e,viewMoreNext:t}=this.refs;!e&&!t||(this.infinityScrollObserver||(this.infinityScrollObserver=new IntersectionObserver(async r=>{f.current&&await f.current;for(const i of r)if(i.isIntersecting){const{viewMorePrevious:s,viewMoreNext:o}=this.refs;i.target===s?this.#v():i.target===o&&this.#w()}},{rootMargin:"100px"})),e&&this.infinityScrollObserver.observe(e),t&&this.infinityScrollObserver.observe(t))}#n(e){if(!e)return!1;const{grid:t}=this.refs,r=t?.dataset.lastPage;return!(!r||e.page<1||e.page>Number(r))}async#e(e){const t=this.#l(e),r=()=>{e==="next"?(this.#t?.(),this.#t=null):(this.#r?.(),this.#r=null)};if(!t||!this.#n(t)){r();return}await this.#m(t.page,t.url),r()}async#m(e,t=void 0){const r={page:e,url:t};if(!t){const s=new URL(window.location.href);s.searchParams.set("page",e.toString()),s.hash="",r.url=s}if(!this.#n(r))return;const i=await m.getSectionHTML(this.sectionId,!0,r.url);this.pages.set(e,i)}async#w(){const{grid:e}=this.refs;if(!e)return;const t=this.#l("next");if(!t||!this.#n(t))return;let r=this.#o(t.page);if(!r){const i=new Promise(s=>{this.#t=s});if(this.#e("next"),await i,r=this.#o(t.page),!r)return}e.append(...r),this.#a.processNewElements(),history.pushState("","",t.url.toString()),u(()=>{this.#e("next")})}async#v(){const{grid:e}=this.refs;if(!e)return;const t=this.#l("previous");if(!t||!this.#n(t))return;let r=this.#o(t.page);if(!r){const a=new Promise(d=>{this.#r=d});if(this.#e("previous"),await a,r=this.#o(t.page),!r)return}const i=window.scrollY,s=e.firstElementChild,o=s?s.getBoundingClientRect().top+window.scrollY:0;if(e.prepend(...r),this.#a.processNewElements(),history.pushState("","",t.url.toString()),s){const d=s.getBoundingClientRect().top+window.scrollY-o;window.scrollTo({top:i+d,behavior:"instant"})}u(()=>{this.#e("previous")})}#l(e){const{cards:t}=this.refs,r=e==="previous";if(!Array.isArray(t))return;const i=t[r?0:t.length-1];if(!i)return;const s=Number(i.dataset.page),o=r?s-1:s+1,a=new URL(window.location.href);return a.searchParams.set("page",o.toString()),a.hash="",{page:o,url:a}}#o(e){const t=this.pages.get(e);if(!t)return;const i=new DOMParser().parseFromString(t,"text/html").querySelector('[ref="grid"]');if(i)return i.querySelectorAll(':scope > [ref="cards[]"]')}get sectionId(){const e=this.getAttribute("section-id");if(!e)throw new Error("The section-id attribute is required");return e}#d=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;const r=(e.target instanceof Element?e.target:null)?.closest("a.pagination__link, a.plp-load-more-btn");!(r instanceof HTMLAnchorElement)||r.origin!==window.location.origin||(e.preventDefault(),history.pushState({},"",r.href),this.#g({reveal:!0}))};#u=()=>{const e=h(),t=c(),r=P({base:e,page:t,renderedBase:this.#i,renderedPage:this.#s});r!=="ignore"&&(this.#i=e,this.#s=t,r==="render"&&this.#g({reveal:!1}))};async#g({reveal:e}){const t=new URL(window.location.href);t.searchParams.set("page",String(c())),t.hash="",this.#i=h(),this.#s=c(),document.getElementById(g)?.setAttribute("aria-busy","true");try{await v({sectionId:this.sectionId,reason:"page",url:t,scope:"results"}),e&&this.#P()}catch{}finally{document.getElementById(g)?.removeAttribute("aria-busy")}}#P(){const e=document.getElementById(g);e&&(e.getBoundingClientRect().top<0&&e.scrollIntoView({behavior:"instant",block:"start"}),e.focus({preventScroll:!0}))}#f=e=>{e.detail?.sectionId===this.sectionId&&(this.#i=h(),this.#s=c(),u(()=>this.#c()))};#p=()=>{this.pages.clear(),this.#t?.(),this.#r?.(),this.#t=null,this.#r=null;const e=this.refs.grid?.dataset.lastPage,t=new MutationObserver(()=>{if(this.refs.grid?.dataset.lastPage!==e){if(t.disconnect(),!this.isConnected)return;this.#h(),this.#c()}}),{grid:r}=this.refs;r&&(t.observe(r,{attributes:!0,attributeFilter:["data-last-page"],childList:!0}),setTimeout(()=>{t&&t.disconnect()},3e3))}}export{b as default,h as listUrlBase,P as pageChangeIntent,c as urlPage};
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.