1const requestIdleCallback=typeof window.requestIdleCallback=="function"?window.requestIdleCallback:setTimeout;function normalizeString(str){return str.normalize("NFD").replace(/\p{Diacritic}/gu,"").toLowerCase()}function onAnimationEnd(elements,callback,options={subtree:!0}){const animationPromises=(Array.isArray(elements)?elements.flatMap(element=>element.getAnimations(options)):elements.getAnimations(options)).reduce((acc,animation)=>(animation.timeline instanceof DocumentTimeline&&acc.push(animation.finished),acc),[]);return Promise.allSettled(animationPromises).then(callback)}function isPointWithinElement(x,y,element){const{left,right,top,bottom}=element.getBoundingClientRect();return x>=left&&x<=right&&y>=top&&y<=bottom}function isClickedOutside(event,element){return event.target instanceof HTMLDialogElement||!(event.target instanceof Element)?!isPointWithinElement(event.clientX,event.clientY,element):!element.contains(event.target)}class DeclarativeShadowElement extends HTMLElement{connectedCallback(){if(!this.shadowRoot){const template=this.querySelector(':scope > template[shadowrootmode="open"]');if(!(template instanceof HTMLTemplateElement))return;this.attachShadow({mode:"open"}).append(template.content.cloneNode(!0))}}}class Component extends DeclarativeShadowElement{refs={};requiredRefs;get roots(){return this.shadowRoot?[this,this.shadowRoot]:[this]}connectedCallback(){super.connectedCallback(),registerEventListeners(),this.#updateRefs(),requestIdleCallback(()=>{for(const root of this.roots)this.#mutationObserver.observe(root,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["ref"],attributeOldValue:!0})})}updatedCallback(){this.#mutationObserver.takeRecords(),this.#updateRefs()}disconnectedCallback(){this.#mutationObserver.disconnect()}#updateRefs(){const refs={},elements=this.roots.reduce((acc,root)=>{for(const element of root.querySelectorAll("[ref]"))this.#isDescendant(element)&&acc.add(element);return acc},new Set);for(const ref of elements){const refName=ref.getAttribute("ref")??"",isArray=refName.endsWith("[]"),path=isArray?refName.slice(0,-2):refName;if(isArray){const array=Array.isArray(refs[path])?refs[path]:[];array.push(ref),refs[path]=array}else refs[path]=ref}if(this.requiredRefs?.length){for(const ref of this.requiredRefs)if(!(ref in refs))throw new MissingRefError(ref,this)}this.refs=refs}#mutationObserver=new MutationObserver(mutations=>{mutations.some(m=>m.type==="attributes"&&this.#isDescendant(m.target)||m.type==="childList"&&[...m.addedNodes,...m.removedNodes].some(this.#isDescendant))&&this.#updateRefs()});#isDescendant=node=>getClosestComponent(getAncestor(node))===this}function getAncestor(node){if(node.parentNode)return node.parentNode;const root=node.getRootNode();return root instanceof ShadowRoot?root.host:null}function getClosestComponent(node){if(!node)return null;if(node instanceof Component||node instanceof HTMLElement&&node.tagName.toLowerCase().endsWith("-component"))return node;const ancestor=getAncestor(node);return ancestor?getClosestComponent(ancestor):null}let initialized=!1;function registerEventListeners(){if(initialized)return;initialized=!0;const events=["click","change","select","focus","blur","submit","input","keydown","keyup","toggle"],shouldBubble=["focus","blur"],expensiveEvents=["pointerenter","pointerleave"];for(const eventName of[...events,...expensiveEvents]){const attribute=`on:${eventName}`;document.addEventListener(eventName,event=>{const element=getElement(event);if(!element)return;const proxiedEvent=event.target!==element?new Proxy(event,{get(target,property){if(property==="target")return element;const value2=Reflect.get(target,property);return typeof value2=="function"?value2.bind(target):value2}}):event,value=element.getAttribute(attribute)??"";let[selector,method]=value.split("/");const matches=value.match(/([\/\?][^\/\?]+)([\/\?][^\/\?]+)$/),data=matches?matches[2]:null,instance=selector?selector.startsWith("#")?document.querySelector(selector):element.closest(selector):getClosestComponent(element);if(!(instance instanceof Component)||!method)return;method=method.replace(/\?.*/,"");const callback=instance[method];if(typeof callback=="function")try{const args=[proxiedEvent];data&&args.unshift(parseData(data)),callback.call(instance,...args)}catch(error){console.error(error)}},{capture:!0})}function getElement(event){const target=event.composedPath?.()[0]??event.target;if(target instanceof Element)return target.hasAttribute(`on:${event.type}`)?target:expensiveEvents.includes(event.type)?null:event.bubbles||shouldBubble.includes(event.type)?target.closest(`[on\\:${event.type}]`):null}}function parseData(str){const delimiter=str[0],data=str.slice(1);return delimiter==="?"?Object.fromEntries(Array.from(new URLSearchParams(data).entries()).map(([key,value])=>[key,parseValue(value)])):parseValue(data)}function parseValue(str){if(str==="true")return!0;
1if(str==="false")return!1;const maybeNumber=Number(str);return!isNaN(maybeNumber)&&str.trim()!==""?maybeNumber:str}class MissingRefError extends Error{constructor(ref,component){super(`Required ref "${ref}" not found in component ${component.tagName.toLowerCase()}`)}}class LocalizationFormComponent extends Component{#virtualListResizeObserver=null;#sharedVirtualRowHeight=48;#virtualSegments=null;connectedCallback(){super.connectedCallback(),this.refs.search&&this.refs.search.addEventListener("keydown",this.#onSearchKeyDown),this.refs.countryList&&this.refs.countryList.addEventListener("keydown",this.#onContainerKeyDown),this.refs.countryList&&this.refs.countryList.addEventListener("scroll",this.#onCountryListScroll),this.resizeLanguageInput(),requestAnimationFrame(()=>{this.#initCountryVirtualList(),requestAnimationFrame(()=>this.#syncVirtualSegments())})}updatedCallback(){super.updatedCallback(),this.#virtualListResizeObserver?.disconnect(),this.#virtualListResizeObserver=null,this.#virtualSegments=null,requestAnimationFrame(()=>{this.#initCountryVirtualList(),requestAnimationFrame(()=>this.#syncVirtualSegments())})}disconnectedCallback(){this.#virtualListResizeObserver?.disconnect(),this.#virtualListResizeObserver=null,this.#virtualSegments=null,this.refs.search&&this.refs.search.removeEventListener("keydown",this.#onSearchKeyDown),this.refs.countryList&&this.refs.countryList.removeEventListener("keydown",this.#onContainerKeyDown),this.refs.countryList&&this.refs.countryList.removeEventListener("scroll",this.#onCountryListScroll),super.disconnectedCallback()}#initCountryVirtualList(){if(this.dataset.countryVirtual!=="true"||this.#virtualSegments)return;const scripts=[...this.querySelectorAll('script[type="application/json"][data-country-virtual-json][data-virtual-segment]')];if(!scripts.length)return;const POOL_REFS={europe:"virtualEuropePool",international:"virtualInternationalPool"},segments=[];for(const script of scripts){const key=script.getAttribute("data-virtual-segment");if(!key||!Object.prototype.hasOwnProperty.call(POOL_REFS,key))continue;const track=this.querySelector(`[data-country-virtual-track][data-virtual-segment="${key}"]`);if(!(track instanceof HTMLElement))continue;const windowEl=track.querySelector(`[data-country-virtual-window][data-virtual-segment="${key}"]`);if(!(windowEl instanceof HTMLElement))continue;let data;try{const raw=script.textContent?.trim();data=raw?JSON.parse(raw):[]}catch{continue}const poolRefName=POOL_REFS[key],pool=this.refs[poolRefName];if(!Array.isArray(pool)||pool.length===0)continue;const hostLi=track.closest("li");segments.push({key,data:Array.isArray(data)?data:[],filtered:null,track,windowEl,hostLi,pool})}if(!segments.length)return;const sample=this.querySelector(".popular-countries .localization-form__list-item")||this.querySelector('.localization-form__list-item[role="option"][data-value]:not([data-virtual-pool])');this.#sharedVirtualRowHeight=sample instanceof HTMLElement&&sample.offsetHeight>0?Math.max(40,sample.offsetHeight):48;for(const seg of segments)if(seg.data.length===0){seg.track.style.height="0",seg.hostLi instanceof HTMLElement&&(seg.hostLi.hidden=!0);const label=this.querySelector(`[data-country-region-label="${seg.key}"]`);label instanceof HTMLElement&&(label.hidden=!0)}this.#virtualSegments=segments,typeof ResizeObserver<"u"&&this.refs.countryList&&(this.#virtualListResizeObserver?.disconnect(),this.#virtualListResizeObserver=new ResizeObserver(()=>{const s=this.querySelector(".popular-countries .localization-form__list-item")||this.querySelector('.localization-form__list-item[role="option"][data-value]:not([data-virtual-pool])');s instanceof HTMLElement&&s.offsetHeight>0&&(this.#sharedVirtualRowHeight=Math.max(40,s.offsetHeight),this.#syncVirtualSegments())}),this.#virtualListResizeObserver.observe(this.refs.countryList))}#offsetTopWithinScrollRoot(scrollRoot,el){let y=0,n=el;for(;n&&n!==scrollRoot;){y+=n.offsetTop;const next=n.offsetParent;n=next instanceof HTMLElement?next:null}if(n===scrollRoot)return y;for(y=0,n=el;n&&n!==scrollRoot;)y+=n.offsetTop,n=n.parentElement;return n===scrollRoot?y:0}#getCoreCountryItems(){return Array.isArray(this.refs.coreCountryItems)?this.refs.coreCountryItems:[]}#getStaticCountryItems(){return this.dataset.countryVirtual==="true"?[]:Array.isArray(this.refs.countryListItems)?this.refs.countryListItems:[]}#getFocusableCountryItems(){const core=this.#getCoreCountryItems(),staticRows=this.#getStaticCountryItems(),poolItems=[];if(this.#virtualSegments)for(const seg of this.#virtualSegments)for(const li of seg.pool)li.hidden||poolItems.push(li);return[...core,...staticRows,...poolItems].filter(li=>!li.hasAttribute("hidden"))}#extraRowMatchesSearch(searchValue,row){const el=document.createElement("div");el.dataset.value=row.iso,row.al&&(el.dataset.aliases=row.al),el.innerHTML=`<span class="country">${row.name}</span><span class="localization-form__currency">${row.cur}</span>`;const m=this.#findMatches(searchValue,el);return!!(m.label||m.alias||m.iso||m.currency)}#paintVirtualPoolRow(li,row,searchValue,selectedIso){li.dataset.value=row.iso,row.al?li.dataset.aliases=row.al:li.removeAttribute("data-aliases");const bid=this.dataset.blockId??"localization";li.id=`country-opt-${bid}-${row.iso}`,li.setAttribute("aria-label",row.name),row.iso===selectedIso?li.setAttribute("aria-current","true"):li.removeAttribute("aria-current");const leadTpl=this.querySelector(row.iso===selectedIso?'.popular-countries > li[aria-current="true"] > span:first-child':'.popular-countries > li:not([aria-current="true"]) > span:first-child'),lead=li.children[0];leadTpl&&lead&&lead.replaceWith(leadTpl.cloneNode(!0));const countrySpan=li.querySelector(".country"),curSpan=li.querySelector(".localization-form__currency");countrySpan&&(searchValue?countrySpan.innerHTML=this.#highlightMatches(row.name,searchValue):countrySpan.textContent=row.name),curSpan&&(curSpan.textContent=row.cur),li.hidden=!1}#syncVirtualSegments(){if(!this.#virtualSegments?.length||!this.refs.countryList)return;const countryList=this.refs.countryList,scrollTop=countryList.scrollTop,viewH=countryList.clientHeight,rowH=this.#sharedVirtualRowHeight;for(const seg of this.#virtualSegments){const active=seg.filtered!=null?seg.filtered:seg.data;if(active.length===0){seg.track.style.height="0";for(const li of seg.pool)li.hidden=!0;seg.windowEl.style.transform="translateY(0)";continue}const trackTop=this.#offsetTopWithinScrollRoot(countryList,seg.track),scrollPastTrack=scrollTop-trackTop,start=Math.min(active.length-1,Math.max(0,Math.floor(Math.max(0,scrollPastTrack)/rowH))),visibleCount=Math.min(seg.pool.length,Math.ceil(viewH/rowH)+4),end=Math.min(active.length,start+visibleCount);seg.track.style.height=`${active.length*rowH}px`,seg.windowEl.style.transform=`translateY(${start*rowH}
1px)`;const searchRaw=this.refs.search instanceof HTMLInputElement?normalizeString(this.refs.search.value):"",selectedIso=this.refs.countryInput?.value??"";let poolIx=0;for(let i=start;i<end;i++){const row=active[i],li=seg.pool[poolIx];if(!row||!li)break;this.#paintVirtualPoolRow(li,row,searchRaw,selectedIso),poolIx++}for(let j=poolIx;j<seg.pool.length;j++)seg.pool[j].hidden=!0}}#onContainerKeyDown=event=>{const{countryInput,form}=this.refs;switch(event.key){case"ArrowUp":event.preventDefault(),event.stopPropagation(),this.#changeCountryFocus("UP");break;case"ArrowDown":event.preventDefault(),event.stopPropagation(),this.#changeCountryFocus("DOWN");break;case"Enter":{event.preventDefault(),event.stopPropagation();const focusedItem=this.#getFocusableCountryItems().find(item=>item.getAttribute("aria-selected")==="true");focusedItem&&countryInput&&form&&(countryInput.value=focusedItem.dataset.value??"",form.submit());break}}this.refs.search&&setTimeout(()=>{const focusableItems=this.#getFocusableCountryItems(),focusedItemIndex=focusableItems.findIndex(item=>item===document.activeElement),focusedItem=focusableItems[focusedItemIndex];focusedItem?this.refs.search.setAttribute("aria-activedescendant",focusedItem.id):this.refs.search.setAttribute("aria-activedescendant","")})};selectCountry=(countryName,event)=>{event.preventDefault();const{countryInput,form}=this.refs;countryInput.value=countryName,form?.submit()};selectCountryFromVirtual(event){const li=event.target instanceof Element?event.target.closest("li[data-virtual-pool]"):null;if(!(li instanceof HTMLLIElement)||!this.contains(li))return;const code=li.dataset.value;code&&this.selectCountry(code,event)}changeLanguage(event){const{form,languageInput}=this.refs,value=event.target instanceof HTMLSelectElement?event.target.value:null;value&&(languageInput.value=value,this.resizeLanguageInput(),form.submit())}resizeLanguageInput(){const{languageInput}=this.refs;if(!languageInput)return;if(languageInput.closest(".nf-mobile-localization")){languageInput.style.removeProperty("width");return}for(const option of languageInput.options)option.selected||(option.dataset.optionLabel=option.textContent||"",option.innerText="");languageInput.style.width="fit-content";const measured=Math.ceil(languageInput.offsetWidth);for(const option of languageInput.options)option.dataset.optionLabel&&(option.textContent=option.dataset.optionLabel,delete option.dataset.optionLabel);measured>0?languageInput.style.width=`${measured+1}px`:languageInput.style.removeProperty("width")}#findMatches(searchValue,countryEl,options={matchLabel:!0,matchAlias:!0,matchIso:!0,matchCurrency:!0,labelMatchStart:!1,aliasExactMatch:!1}){let matchTypes={};const{aliases,value:iso}=countryEl.dataset;if(options.matchLabel){const countryName=normalizeString(countryEl.querySelector(".country")?.textContent??"");if(!countryName)return matchTypes;matchTypes.label=options.labelMatchStart?countryName.startsWith(searchValue):countryName.includes(searchValue)}if(options.matchCurrency){const currency=normalizeString(countryEl.querySelector(".localization-form__currency")?.textContent??"");matchTypes.currency=currency.includes(searchValue)}if(options.matchIso&&(matchTypes.iso=normalizeString(iso??"")==searchValue),options.matchAlias){const countryAliases=aliases?.split(",")?.map(alias=>normalizeString(alias));if(!countryAliases)return matchTypes;matchTypes.alias=countryAliases.length>0&&countryAliases.find(alias=>options.aliasExactMatch?alias===searchValue:alias.startsWith(searchValue))!==void 0}return matchTypes}#highlightMatches(text,searchValue){if(!text||!searchValue)return text??"";const normalizedText=normalizeString(text),normalizedSearch=normalizeString(searchValue),startIndex=normalizedText.indexOf(normalizedSearch);if(startIndex===-1)return text;const endIndex=startIndex+normalizedSearch.length,before=text.slice(0,startIndex),match=text.slice(startIndex,endIndex),after=text.slice(endIndex);let result="";return before&&(result+=`<mark>${before}</mark>`),result+=match,after&&(result+=`<mark>${after}</mark>`),result}filterCountries(){const{countryList,liveRegion,noResultsMessage,popularCountries,resetButton,search}=this.refs;if(!search||!countryList)return;const{labelResultsCount}=this.dataset,searchValue=normalizeString(search.value);let countVisibleCountries=0;resetButton?.toggleAttribute("hidden",!searchValue),popularCountries&&popularCountries.toggleAttribute("hidden",!!searchValue);const wrapper=this.querySelector(".country-selector-form__wrapper");wrapper&&wrapper.classList.toggle("is-searching",!!searchValue);const processRow=countryEl=>{if(searchValue===""){countryEl.removeAttribute("hidden");const countrySpan=countryEl.querySelector(".country");countrySpan&&(countrySpan.textContent=countrySpan.textContent),countVisibleCountries++}else{const matches=this.#findMatches(searchValue,countryEl);if(matches.label||matches.alias||matches.iso||matches.currency){countryEl.removeAttribute("hidden");const countrySpan=countryEl.querySelector(".country");countrySpan&&(countrySpan.innerHTML=this.#highlightMatches(countrySpan.textContent,searchValue)),countVisibleCountries++}else countryEl.setAttribute("hidden","")}};for(const countryEl of this.#getCoreCountryItems())processRow(countryEl);let virtualMatchCount=0;
1if(this.#virtualSegments){for(const seg of this.#virtualSegments){const label=this.querySelector(`[data-country-region-label="${seg.key}"]`);if(searchValue==="")seg.filtered=null,virtualMatchCount+=seg.data.length,seg.hostLi&&(seg.hostLi.hidden=seg.data.length===0),label instanceof HTMLElement&&(label.hidden=seg.data.length===0);else{seg.filtered=seg.data.filter(row=>this.#extraRowMatchesSearch(searchValue,row));const n=seg.filtered.length;virtualMatchCount+=n,seg.hostLi&&(seg.hostLi.hidden=n===0),label instanceof HTMLElement&&(label.hidden=n===0)}}countVisibleCountries+=virtualMatchCount}else for(const countryEl of this.#getStaticCountryItems())processRow(countryEl);liveRegion&&labelResultsCount&&(liveRegion.innerText=labelResultsCount.replace("[count]",`${countVisibleCountries}`)),noResultsMessage&&(noResultsMessage.hidden=countVisibleCountries>0),countryList.scrollTop=0,this.#syncVirtualSegments()}#changeCountryFocus(direction){const focusableItems=this.#getFocusableCountryItems(),focusedItemIndex=focusableItems.findIndex(item=>item===document.activeElement),focusedItem=focusableItems[focusedItemIndex];let itemToFocus;direction==="UP"?itemToFocus=focusedItemIndex>0?focusableItems[focusedItemIndex-1]:focusableItems[focusableItems.length-1]:itemToFocus=focusedItemIndex<focusableItems.length-1?focusableItems[focusedItemIndex+1]:focusableItems[0],focusedItem&&focusedItem.setAttribute("aria-selected","false"),itemToFocus?.setAttribute("aria-selected","true"),itemToFocus?.focus({preventScroll:!0})}resetCountriesFilter(event){const{search}=this.refs;event.stopPropagation(),search.value="",this.filterCountries(),search.setAttribute("aria-activedescendant",""),search.focus({preventScroll:!0})}#onSearchKeyDown=event=>{if(event.key==="Enter"){event.preventDefault(),event.stopPropagation();return}this.#onContainerKeyDown(event)};resetForm(){const{search}=this.refs;search&&search.value!=""&&(search.value="",this.filterCountries(),search.setAttribute("aria-activedescendant",""))}focusSearchInput=()=>{const{search}=this.refs;search?.focus({preventScroll:!0})};syncCountryVirtualList(){if(!this.#virtualSegments?.length)return;const s=this.querySelector(".popular-countries .localization-form__list-item")||this.querySelector('.localization-form__list-item[role="option"][data-value]:not([data-virtual-pool])');s instanceof HTMLElement&&s.offsetHeight>0&&(this.#sharedVirtualRowHeight=Math.max(40,s.offsetHeight)),this.#syncVirtualSegments()}#onCountryListScroll=event=>{const countryFilter=this.querySelector(".country-filter"),countryList=event.target instanceof HTMLElement?event.target:null;if(countryFilter&&countryList){const shouldShowBorder=countryList.scrollTop>0;countryFilter.classList.toggle("is-scrolled",shouldShowBorder)}this.#syncVirtualSegments()}}class DropdownLocalizationComponent extends Component{get isHidden(){return this.refs.panel.hasAttribute("hidden")}toggleSelector(){return this.isHidden?this.showPanel():this.hidePanel()}showPanel(){this.isHidden&&(this.addEventListener("keyup",this.#handleKeyUp),document.addEventListener("click",this.#handleClickOutside),this.refs.panel.removeAttribute("hidden"),this.refs.button.setAttribute("aria-expanded","true"),onAnimationEnd(this.refs.panel,()=>{this.#updateWidth(),this.refs.localizationForm?.resizeLanguageInput(),this.refs.localizationForm?.syncCountryVirtualList?.(),this.refs.localizationForm?.focusSearchInput()}))}hidePanel=()=>{this.isHidden||(this.removeEventListener("keyup",this.#handleKeyUp),document.removeEventListener("click",this.#handleClickOutside),this.refs.button?.setAttribute("aria-expanded","false"),this.refs.panel.setAttribute("hidden",""),this.refs.localizationForm?.resetForm())};#handleClickOutside=event=>{isClickedOutside(event,this)&&this.hidePanel()};#updateWidth(){const w=this.refs.localizationForm?.offsetWidth??0;this.style.setProperty("--width",`${Math.max(w,200)}px`)}#handleKeyUp=event=>{event.key==="Escape"&&(this.hidePanel(),event.stopPropagation(),this.refs.button?.focus({preventScroll:!0}))}}class DrawerLocalizationComponent extends Component{toggle(event){const{target}=event,{localizationForm}=this.refs;if(!localizationForm||!(target instanceof HTMLDetailsElement))return;const countryList=localizationForm.querySelector(".country-selector-form__wrapper");target.open?(countryList&&countryList.addEventListener("scroll",this.#onCountryListScroll),onAnimationEnd(target,localizationForm.focusSearchInput)):(countryList?.removeEventListener("scroll",this.#onCountryListScroll),localizationForm.resetForm())}#onCountryListScroll=event=>{const countryFilter=this.querySelector(".country-filter"),countryList=event.target instanceof HTMLElement?event.target:null;if(countryFilter&&countryList){const shouldShowBorder=countryList.scrollTop>0;countryFilter.classList.toggle("is-scrolled",shouldShowBorder)}}}customElements.get("localization-form-component")||customElements.define("localization-form-component",L
1ocalizationFormComponent),customElements.get("dropdown-localization-component")||customElements.define("dropdown-localization-component",DropdownLocalizationComponent),customElements.get("drawer-localization-component")||customElements.define("drawer-localization-component",DrawerLocalizationComponent); 2//# sourceMappingURL=/cdn/shop/t/2/assets/localization.js.map?v=165830939209485909551777995118
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.