1import { c as Component, h as html, r as repeat, I as isNumber, J as convertFractionsToDecimals, q as render, t as t$1, K as generateRdmString, M as ModalManager, H as HostAttr, a as autobind } from './bundled-app.js'; 2import { u as unsafeHTML } from './bundled-unsafe-html.js'; 3import { i as imgURL, u as updateImageSrc } from './bundled-ShopifyUtils.js'; 4 5function e(e,t,i,n){var r,s=arguments.length,l=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,n);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(l=(s<3?r(l):s>3?r(t,i,l):r(t,i))||l);return s>3&&l&&Object.defineProperty(t,i,l),l}function t(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class SizeGuide extends Component{onAppInit(){this.handle&&this.fetchGuide(),this.bindEvents();}render(){if(!this.state.html)return null;if(this.updateTitle(),this.updateImages(),this.updateContent(),this.updateFitting(),this.updateSizeConversions(),this.state.legacy)return html`${unsafeHTML(this.state.html)}`;{let e=SizeGuide.parseCSV(this.state.config,!0);return html` 6 ${e?e.map(e=>html` 7 ${e.title?html` 8 <h3 class="sizingTable__title">${e.title}</h3> 9 `:""} 10 11 <table class="sizingTable sizingTable__apparel table no-auto-invert"> 12 <thead> 13 <tr class="sizingTable__header"> 14 ${repeat(e.head,e=>e,(e,t)=>html` 15 <th class="sizingTable__header-item ${0===t?"bold":""}">${e.replace(/\(in\)|\(IN\)/g,"").trim()}</th> 16 `)} 17 </tr> 18 </thead> 19 20 <tbody class="sizingTable__body"> 21 ${repeat(e.body,e=>e,t=>html` 22 <tr class="sizingTable__row"> 23 ${repeat(t,e=>e,(t,i)=>html` 24 <td class="sizingTable__row-item sizingTable__label ${e.head[i]?.toLowerCase().includes("(in)")?"convert-unit":""}" unit="${t}"> 25 ${t} 26 </td> 27 `)} 28 </tr> 29 `)} 30 </tbody> 31 </table> 32 `):unsafeHTML(this.state.html)} 33 `}}onModalChange(e){"modal-sizeguide"===this.modalManager.getCurrentModalId()?this.ariaEnable():this.ariaDisable();}bindEvents(){this.hostObserver.observe(this.host,{attributes:!0,subtree:!1}),this.modalManager.stateChange$.subscribe({next:this.onModalChange}),this.unitSelector.forEach(e=>e.addEventListener("change",this.updateUnits));}onMutation(){this.handle&&""!==this.handle&&this.handle!==this.previousHandle&&(this.imageHolders.forEach(e=>{let t=e.querySelector("img");t?.classList.remove("lazyloaded"),t?.classList.add("no-animate");}),this.fetchGuide(),this.previousHandle=this.handle);}ariaEnable(){this.parent.setAttribute("aria-hidden","false"),this.parent.setAttribute("tabindex","0");}ariaDisable(){this.parent.setAttribute("aria-hidden","true"),this.parent.setAttribute("tabindex","-1");}async fetchGuide(){let{protocol:e,host:t}=window.location;this.loadingElement.classList.remove("sizeGuideModal__loading--hidden"),document.dispatchEvent(new CustomEvent("theme:loading:start"));try{let i=await fetch(`${e}//${t}${window.Shopify.routes.root}products/${this.handle}?view=_size-guide`);if(200===i.status){let e=await i.json();this.setState(e);}}catch(e){console.error(e);}this.loadingElement.classList.add("sizeGuideModal__loading--hidden"),document.dispatchEvent(new CustomEvent("theme:loading:end"));}updateTitle(){this.titleHolder.innerHTML=this.state.title;}updateUnits(){let e=this.parent.querySelector(".sizeGuideModal__btn input:checked")?.value,t=this.parent.querySelectorAll("table tbody td.convert-unit");"inches"===e?t.forEach(e=>e.innerHTML=e.getAttribute("unit")):"centimeters"===e&&t.forEach(e=>{let t=e.innerHTML.split(/-|Ã/g).map(e=>isNumber(e)?Math.round(2.54*convertFractionsToDecimals(e)):e),i="-";e.innerHTML.includes("Ã")&&(i=" Ã "),e.innerHTML=t.join(i);});}updateContent(){/\S/.test(this.state.contentHtml)?(render(html`${this.state.contentHtml&&unsafeHTML(this.state.contentHtml)}`,this.contentHolder),this.imageHolders=this.parent.querySelectorAll("[product-image]"),this.updateImages(),this.contentHolder.classList.remove("hidden")):this.contentHolder.classList.add("hidden");}updateSizeConversions(){let e=this.sizeConversion.querySelectorAll("input");
33e?.forEach(e=>e.checked=!1),e[0].checked=!0,this.state.hideSizeConversion&&this.sizeConversion.classList.add("hidden");}updateImages(){this.imageHolders.forEach(e=>{let t=e.querySelector("img");if(!t)return;let i=this.state.useShopifyImg?imgURL(this.state.image,"150x"):this.state.image;t?.classList.remove("no-animate"),updateImageSrc(t,i);});}updateFitting(){let{productFit:e,productFitCustomMessage:t}=this.state??{};if(t){this.fitMessage.textContent=t;return}if(e){let t=e.toLowerCase().replace(/\s+/g,"_");this.fitMessage.textContent=t$1(`product.fit.${t}`);return}this.fitMessage.textContent="";}static parseCSV(e,t=!1){let i=[],n=e.replaceAll("\r","\n").split(/\n/).map(e=>e.split(",").filter(e=>!!e.length)).filter(e=>!!e.length),r=null;for(let e=0;e<n.length;e++){let t=n[e],s=1===t.length&&n[e+1]?.length>1;if(!r){r=s?{id:generateRdmString(),title:t[0],head:null,body:[]}:{id:generateRdmString(),head:t,body:[]};continue}s||(r.head?s||r.body.push(t):r.head=t),r&&(!n[e+1]||n[e+1].length!==t.length)&&(i.push(r),r=null);}return t?SizeGuide.invertCSVTables(i):i}static invertCSVTables(e){let t=[];for(let i of e){let e={id:i.id,title:i.title,head:[SizeGuide.shortenColumnTitle(i.head[0])],body:[]};for(let t=0;t<i.body.length;t++)e.head.push(SizeGuide.shortenColumnTitle(i.body[t][0]));for(let t=1;t<i.head.length;t++)e.body.push([i.head[t],...i.body.map(e=>e[t])]);t.push(e);}return t}static invertHTMLTables(e){let t=document.createElement("div");return t.innerHTML=e,t.querySelectorAll("table:not(.no-auto-invert)").forEach(SizeGuide.invertHTMLTable),t.innerHTML}static invertHTMLTable(e){let t=e.querySelector("thead"),i=e.querySelector("tbody"),n=Array.from(t.querySelectorAll("tr")),r=Array.from(e.querySelectorAll("thead th")),s=Array.from(e.querySelectorAll("tbody tr")),l=Array.from(e.querySelectorAll("tbody tr")).map(e=>Array.from(e.querySelectorAll("td"))),o=r.map(e=>e.innerText.trim()),a=l.map(e=>e.map(e=>e.innerText.trim())),d=r[0].cloneNode(),h=s[0].cloneNode(),u=l[0][0].cloneNode(),c=[];for(let e=0;e<o.length;e++){let t=e%(o.length/n.length);c[t]||(c[t]=""),o[e].length&&(c[t]+=`<div>${o[e]}</div>`);}t.innerHTML="",i.innerHTML="";let p=d.cloneNode();p.innerHTML=SizeGuide.shortenColumnTitle(c[0]),t.appendChild(p);for(let e=0;e<a.length;e++){let i=d.cloneNode();i.innerHTML=SizeGuide.shortenColumnTitle(a[e][0]),t.appendChild(i);}for(let e=1;e<c.length;e++){let t=h.cloneNode(),n=u.cloneNode();for(let i of(n.innerHTML=c[e],t.appendChild(n),a)){let n=u.cloneNode();n.innerHTML=i[e],t.appendChild(n);}i.appendChild(t);}}static shortenColumnTitle(e){return e.replace(/^(\w+).*(\(.+\))$/,"$1 $2")}constructor(...e){super(...e),this.parent=this.host.closest("[size-guide-modal]"),this.loadingElement=this.parent.querySelector(".sizeGuideModal__loading"),this.contentHolder=this.parent.querySelector("[size-guide-content"),this.imageHolders=this.parent.querySelectorAll("[product-image]"),this.titleHolder=this.parent.querySelector("[product-title]"),this.fitMessage=this.parent.querySelector("[product-fit]"),this.sizeConversion=this.parent.querySelector("[size-guide-conversion]"),this.unitSelector=this.parent.querySelectorAll('input[name="unit-selector"]'),this.hostObserver=new MutationObserver(this.onMutation),this.modalManager=ModalManager.getInstance();}}SizeGuide.selector="size-guide",SizeGuide.noNullRendering=!0,e([HostAttr(),t("design:type",String)],SizeGuide.prototype,"handle",void 0),e([autobind,t("design:type",Function),t("design:paramtypes",["undefined"==typeof HTMLElement?Object:HTMLElement]),t("design:returntype",void 0)],SizeGuide.prototype,"onModalChange",null),e([autobind,t("design:type",Function),t("design:paramtypes",[]),t("design:returntype",void 0)],SizeGuide.prototype,"onMutation",null),e([autobind,t("design:type",Function),t("design:paramtypes",[]),t("design:returntype",void 0)],SizeGuide.prototype,"updateUnits",null),e([autobind,t("design:type",Function),t("design:paramtypes",[]),t("design:returntype",void 0)],SizeGuide.prototype,"updateContent",null); 34 35export { SizeGuide };
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.