1import{Controller}from"@hotwired/stimulus";import{Turbo}from"@hotwired/turbo-rails";const PENDING_CLASS="product-page:pending";export default class extends Controller{static get targets(){return["page"]}connect(){if(this.initialPageIndex=this.pageTargets.findIndex(t=>this._isLoaded(t)),-1===this.initialPageIndex)return this.initialPageIndex=0,void this._makeLazyLoadable(0);this._makeLazyLoadable(this.initialPageIndex-1),this._makeLazyLoadable(this.initialPageIndex+1),this._scrollPageIntoView(this.initialPageIndex)}makeAdjacentPageLazyLoadable(t){const e=this.pageTargets.indexOf(t.currentTarget);this._makeLazyLoadable(e>this.initialPageIndex?e+1:e-1)}preserveScrollPosition(t){const e=t.currentTarget,i=t.detail.render;t.detail.render=(t,r)=>{const a=this._firstChild(),n=a?a.getBoundingClientRect().top:null;if(i(t,r),e.classList.remove(PENDING_CLASS),!a)return;const s=a.getBoundingClientRect().top;s!==n&&this._withAutoScrollBehavior(()=>window.scrollBy(0,s-n))}}updatePageParameter(){this.pageParameterUpdateInProgress||(this.pageParameterUpdateInProgress=!0,window.requestAnimationFrame(()=>{try{this._replaceHistory(this._currentPageUrl())}finally{this.pageParameterUpdateInProgress=!1}}))}_scrollPageIntoView(t){if(t<=0)return;const e=this._contentChildren(this.pageTargets[t])[0];e&&this._withAutoScrollBehavior(()=>e.scrollIntoView())}_withAutoScrollBehavior(t){const e=document.documentElement,i=e.style.scrollBehavior;e.style.scrollBehavior="auto",t(),e.style.scrollBehavior=i}_firstChild(){for(const t of this.pageTargets){const e=this._contentChildren(t);if(e.length>0)return e[0]}return null}_contentChildren(t){return this._isLoaded(t)?t.children:[]}_isLoaded(t){return!t.classList.contains(PENDING_CLASS)}_makeLazyLoadable(t){const e=this.pageTargets[t];!e||e.hasAttribute("src")||this._isLoaded(e)||(e.setAttribute("loading","lazy"),e.setAttribute("src",e.dataset.paginatedGridSrc))}_currentPageUrl(){let t=null,e=null;for(const i of this.pageTargets)for(const r of this._contentChildren(i)){const a=r.getBoundingClientRect();if(!(a.bottom<=0)){if(null!==t&&a.top!==t)return e.dataset.paginatedGridSrc;t=a.top,e=i}}return e?e.dataset.paginatedGridSrc:null}_replaceHistory(t){if(!t)return;const e=new URL(t,document.baseURI);e.href!==window.location.href&&Turbo.session.history.replace(e,Turbo.session.history.restorationIdentifier)}}
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.