1import{Component}from"@theme/component";import{debounce,isClickedOutside,onAnimationEnd}from"@theme/utilities";export class DialogComponent extends Component{requiredRefs=["dialog"];connectedCallback(){super.connectedCallback(),(this.minWidth||this.maxWidth)&&window.addEventListener("resize",this.#handleResize)}disconnectedCallback(){super.disconnectedCallback(),(this.minWidth||this.maxWidth)&&window.removeEventListener("resize",this.#handleResize)}#handleResize=debounce(()=>{const{minWidth,maxWidth}=this;if(!minWidth&&!maxWidth)return;const windowWidth=window.innerWidth;(windowWidth<minWidth||windowWidth>maxWidth)&&this.closeDialog()},50);#previousScrollY=0;#ownsScrollLock=!1;adoptScrollLock(scrollY){this.#ownsScrollLock=!0,this.#previousScrollY=scrollY,document.body.style.width="100%",document.body.style.position="fixed",document.body.style.top=`-${scrollY}px`}#unlockBodyScroll(){document.body.style.width="",document.body.style.position="",document.body.style.top="",window.scrollTo({top:this.#previousScrollY,behavior:"instant"})}#releaseScrollLockAfterClose(){if(!this.#ownsScrollLock)return;const stillOpen=this.#findOpenModalDialog();if(!stillOpen)this.#unlockBodyScroll();else{const nextHost=stillOpen.parentElement instanceof DialogComponent?stillOpen.parentElement:stillOpen.closest("cart-drawer-component, quick-add-dialog, dialog-component");nextHost instanceof DialogComponent&&nextHost!==this?nextHost.adoptScrollLock(this.#previousScrollY):this.#unlockBodyScroll()}this.#ownsScrollLock=!1}static#supportsModalPseudo=null;#dialogIsTopLayerModal(dialog){if(DialogComponent.#supportsModalPseudo===null)try{document.createElement("dialog").matches(":modal"),DialogComponent.#supportsModalPseudo=!0}catch{DialogComponent.#supportsModalPseudo=!1}if(DialogComponent.#supportsModalPseudo)return dialog.matches(":modal");if(dialog.closest("[data-qa-drawer-ported]")||dialog.hasAttribute("data-qa-non-modal")||dialog.closest("[data-quick-add-variant-drawer]"))return!1;let parent=dialog.parentElement;for(;parent;){if(parent instanceof HTMLDialogElement&&parent.open)return!1;parent=parent.parentElement}return!0}#findOpenModalDialog(){for(const dialog of document.querySelectorAll("dialog[open]"))if(dialog instanceof HTMLDialogElement&&this.#dialogIsTopLayerModal(dialog))return dialog;return null}#resetDialogScroll(dialog){dialog.scrollTop&&(dialog.scrollTop=0);for(const el of dialog.querySelectorAll("*"))el instanceof HTMLElement&&el.scrollTop&&(el.scrollTop=0)}#onDialogCloseEvent=()=>{this.removeEventListener("click",this.#handleClick),this.removeEventListener("keydown",this.#handleKeyDown),this.refs.dialog.classList.remove("dialog-closing"),this.#releaseScrollLockAfterClose(),this.dispatchEvent(new DialogCloseEvent)};showDialog(){const{dialog}=this.refs;if(dialog.open)return;dialog.classList.remove("dialog-visible","dialog-enter-hold","dialog-closing");const bodyAlreadyLocked=document.body.style.position==="fixed";if(this.#ownsScrollLock=!bodyAlreadyLocked,bodyAlreadyLocked){const lockedTop=Math.abs(parseInt(document.body.style.top||"0",10));this.#previousScrollY=Number.isFinite(lockedTop)?lockedTop:window.scrollY}else this.#previousScrollY=window.scrollY;requestAnimationFrame(()=>{this.#ownsScrollLock&&(document.body.style.width="100%",document.body.style.position="fixed",document.body.style.top=`-${this.#previousScrollY}px`),dialog.classList.add("dialog-enter-hold"),dialog.showModal(),this.#resetDialogScroll(dialog),dialog.addEventListener("close",this.#onDialogCloseEvent,{once:!0}),this.dispatchEvent(new DialogOpenEvent),requestAnimationFrame(()=>{setTimeout(()=>{dialog.classList.remove("dialog-enter-hold"),dialog.open&&dialog.hasAttribute("data-slide-right")&&dialog.classList.add("dialog-visible")})}),this.addEventListener("click",this.#handleClick),this.addEventListener("keydown",this.#handleKeyDown)})}closeDialog=async()=>{const{dialog}=this.refs;if(dialog.open){if(dialog.classList.contains("dialog-closing")){await onAnimationEnd(dialog,void 0,{subtree:!1});return}this.removeEventListener("click",this.#handleClick),this.removeEventListener("keydown",this.#handleKeyDown),dialog.hasAttribute("data-sli
1de-right")&&dialog.classList.remove("dialog-visible"),dialog.classList.add("dialog-closing"),dialog.style.animation="none",dialog.offsetWidth,dialog.style.animation="",await new Promise(resolve=>{requestAnimationFrame(()=>{setTimeout(resolve)})}),await onAnimationEnd(dialog,void 0,{subtree:!1}),dialog.close()}};toggleDialog=()=>{this.refs.dialog.open?this.closeDialog():this.showDialog()};#handleClick(event){const{dialog}=this.refs;isClickedOutside(event,dialog)&&this.closeDialog()}#handleKeyDown(event){event.key==="Escape"&&(event.preventDefault(),this.closeDialog())}get minWidth(){return Number(this.getAttribute("dialog-active-min-width"))}get maxWidth(){return Number(this.getAttribute("dialog-active-max-width"))}}customElements.get("dialog-component")||customElements.define("dialog-component",DialogComponent);export class DialogOpenEvent extends CustomEvent{constructor(){super(DialogOpenEvent.eventName)}static eventName="dialog:open"}export class DialogCloseEvent extends CustomEvent{constructor(){super(DialogCloseEvent.eventName)}static eventName="dialog:close"}document.addEventListener("toggle",event=>{if(event.target instanceof HTMLDetailsElement&&event.target.hasAttribute("scroll-lock")){const{open}=event.target;open?document.documentElement.setAttribute("scroll-lock",""):document.documentElement.removeAttribute("scroll-lock")}},{capture:!0}); 2//# sourceMappingURL=/cdn/shop/t/332/assets/dialog.js.map?v=13539440050104110391788435048
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.