PageSourceSearch

https://spelldesigns.com/cdn/shop/t/358/assets/product-form.wqj8Ezzu.min.js?v=114808741622003562361788394336

js spelldesigns.com collected 2026-10-02 04:18:40 UTC 9,680 bytes, 1 lines download raw bytes

1import{a as h,c as n,P}from"./product-form.C9ZOviNZ.min.js";import{P as _}from"./product-quantity-selector.BrzAruxU.min.js";import{G as A}from"./global-events.DvHBnT1g.min.js";import{C as E}from"./cart.DicMdpyq.min.js";import{c as m,b as v}from"./validation.-D5ifRou.min.js";import"./fetch.Zi-fbXYd.min.js";import"./global-notice.DFqU4wMs.min.js";import"./gwp-renderer.D2rZTGxh.min.js";import"./cookies.CBBv29AF.min.js";function B(u){var e;const i=u.getAttribute(h.PRODUCT_OPTION_POSITION)||((e=u.dataset)==null?void 0:e.productOptionPosition)||u.getAttribute("data-product-option-position");let t=Number(i);if(!t&&u instanceof HTMLFieldSetElement){const s=u.querySelector('input[type="radio"]');t=Number((s==null?void 0:s.getAttribute(h.PRODUCT_OPTION_POSITION))||0)}return t}function C(u){var i;if(!u)return"$";try{return((i=new Intl.NumberFormat(void 0,{style:"currency",currency:u,currencyDisplay:"narrowSymbol"}).formatToParts(0).find(e=>e.type==="currency"))==null?void 0:i.value)||"$"}catch{return"$"}}function g(u,i){var a,o;const t=((o=(a=window.Shopify)==null?void 0:a.currency)==null?void 0:o.active)||"",e=C(t),s=(u/100).toFixed(2);let r=`<span class="price text-faint">${e}${s} ${t}</span>`;if(i&&i>u){const d=((i||0)/100).toFixed(2);r+=` <s class="compare-at-price">${e}${d} ${t}</s>`}return r}class I extends HTMLElement{constructor(){var i;if(super(),this.getSelectedOptions=()=>{const t=[];
1return this.querySelectorAll(n.OPTION_VALUES).forEach(s=>{s.checked&&t.push(s.getAttribute(h.PRODUCT_OPTION_VALUE_NAME))}),t},this.updatedSelectedOption=t=>{const e=t.target,s=e.getAttribute(h.PRODUCT_OPTION_NAME),r=e.getAttribute(h.PRODUCT_OPTION_VALUE_NAME),a=e.getAttribute(h.PRODUCT_OPTION_VALUE_ID),o=this.querySelector(`output[for=${s}]`),d=e.closest("fieldset");if(!d)return;if(d.querySelectorAll(n.RADIO_INPUT).forEach(c=>{c instanceof HTMLInputElement&&(c.checked=!1,c.removeAttribute("checked"))}),e.checked=!0,e.setAttribute("checked",""),o&&(o.textContent=r),this.selectedOptions=this.getSelectedOptions(),this.isPdp){const c=this.getSelectedVariantId();c&&this.updateUrl(c),this.updateProductState()}this.dispatchEvent(new CustomEvent(P.PRODUCT_OPTION_CHANGED,{detail:{optionName:s,optionValue:r,optionId:a}}))},this.updateUrl=t=>{const e=new URL(window.location.href);e.searchParams.set("variant",t.toString()),window.history.replaceState({},"",e.toString())},this.getSelectedVariant=()=>{if(this.selectedOptions=this.getSelectedOptions(),!this.productData||!this.selectedOptions)throw new Error("Product data not found");let t=null;if(t=this.productData.variants.find(e=>this.selectedOptions.every(s=>e.options.includes(s))),!t)throw new Error("Variant not found");return t},this.getSelectedVariantId=()=>this.getSelectedVariant().id,this.getProperties=()=>{const t={};return this.querySelectorAll(`${n.TEXT_INPUT}, ${n.TEXTAREA}`).forEach(s=>{const r=s.getAttribute("name");if(r!=null&&r.startsWith("properties[")){const a=r.replace("properties[","").replace("]","");t[a]=s.value}}),t},this.addToCart=()=>{var a;(a=this.addToCartButton)==null||a.classList.add("button-loading");let t;try{t=this.getSelectedVariantId()}catch(o){console.error(o);return}let e=1;if(this.addToCartQuantity){const o=this.addToCartQuantity.getAttribute(_.QUANTITY_VALUE);e=o?parseInt(o,10):1}let s={};s=this.getProperties();const r={id:t,quantity:e,properties:s};this.productOptionsEl&&this.productOptionsEl.classList.remove("product-options-active"),window.cartService.addToCart(r).finally(()=>{var o;(o=this.addToCartButton)==null||o.classList.remove("button-loading")})},this.updateProductCardState=t=>{var a,o;const e=(a=t.detail)==null?void 0:a.items,s=(o=this.productData)==null?void 0:o.variants;let r=0;!e||!s||(s.forEach((d,l)=>{var T,f,O;const c=d.id,p=((T=e.find(y=>y.id===c))==null?void 0:T.quantity)||0,S=d.inventory_quantity-p;r+=S,S<=0&&d.inventory_policy==="deny"?(f=this.optionValuesEls[l])==null||f.classList.add("disabled"):(O=this.optionValuesEls[l])==null||O.classList.remove("disabled")}),this.currentSwatch&&(r===0?this.currentSwatch.classList.add("sold-out"):this.currentSwatch.classList.remove("sold-out")))},this.eventCartUpdated=()=>{document.addEventListener(A.cart.update,t=>{this.isPdp?this.updateProductState():this.updateProductCardState(t)})},this.initProductStockLevel=()=>{var d,l,c,p;const t=this.getSelectedVariant(),e=this.querySelector(n.PRODUCT_LOW_STOCK);if(!e)return;let s=0;const r=(l=(d=t.title)==null?void 0:d.toLowerCase())==null?void 0:l.trim();(((c=CHROMA.stock_level)==null?void 0:c.thresholds)||[]).forEach(S=>{var f,O;const T=(O=(f=S.option_value)==null?void 0:f.toLowerCase())==null?void 0:O.split(",").map(y=>y.trim());(T&&T.includes(r)||T.includes("default")&&!s)&&(s=parseInt(S.low_stock_threshold))}),!m(t,((p=this.cartService.cart)==null?void 0:p.items)||[])&&t.inventory_quantity<=s?e==null||e.classList.remove("hidden"):e==null||e.classList.add("hidden")},this.isPdp=this.getAttribute(h.IS_PDP)==="true",this.addToCartButton=this.querySelector(n.ADD_TO_CART_BUTTON),this.addToCartQuantity=this.querySelector(n.ADD_TO_CART_QUANTITY),this.optionValuesEls=this.querySelectorAll(n.OPTION_VALUES),this.selectedOptions=this.getSelectedOptions(),this.productOptionsEl=this.querySelector(".product-options"),this.productData=this.querySelector(n.PRODUCT_DATA),this.domParser=new DOMParser,this.productSectionEl=document.querySelector(n.PRODUCT_SECTION),this.currentSwatch=this.querySelector(n.PRODUCT_CURRENT_SWATCH),this.cartService=E.getInstance(),this.buttonAddToCart=this.querySelector(n.PRODUCT_ATC),this.isComingSoon=((i=this.buttonAddToCart)==null?void 0:i.getAttribute(h.BUTTON_STATUS))==="coming-soon",this.productData)try{this.productData=JSON.parse(this.productData.innerHTML)}catch{this.productData=null}}connectedCallback(){if(this.isPdp){const i=this.getSelectedVariantId();i&&this.updateUrl(i),this.initProductStockLevel()}this.eventCartUpdated(),this.initElementEvents(),this.listenToParentFormChanges()}disconnectedCallback(){this.addToCartButton&&this.addToCartButton.removeEventListener("click",this.addToCart),this.optionValuesEls.forEac
1h(i=>{i.removeEventListener("click",this.updatedSelectedOption)})}initElementEvents(){this.addToCartButton&&this.addToCartButton.addEventListener("click",this.addToCart),this.optionValuesEls.forEach(i=>{i.addEventListener("click",this.updatedSelectedOption)})}listenToParentFormChanges(){if(this.isPdp)return;const i=document.querySelector('product-form[data-is-pdp="true"]'),t=this.getAttribute("data-is-child-product-form")==="true";if(i&&t){const e=i.getSelectedVariant();e&&this.updateProductOptionSelectors(e)}}async updateCartCurrencyToCookie(){var e,s;const i=(e=Shopify==null?void 0:Shopify.currency)==null?void 0:e.active,t=((s=Shopify==null?void 0:Shopify.routes)==null?void 0:s.root)||"/";if(i)try{const r=await fetch(t+"localization",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({currency:i})});r.ok||console.warn("Currency update failed:",r.status)}catch(r){console.error("Error updating currency:",r)}}async updateProductState(){const i=this.getSelectedVariant();i&&(this.updatePrice(i),this.updateBnplText(i),this.isComingSoon||(this.updateCurrentSwatch(),this.updateProductOptionSelectors(i),this.updateProductStockandSizeTagline(i),this.updateButtonAddToCart(i),this.updateWishlistButton(i)),await this.updateCartCurrencyToCookie())}updatePrice(i){const t=this.productSectionEl.querySelector(n.PRICE);t&&(t.innerHTML=g(i.price,i.compare_at_price))}updateBnplText(i){var c,p;const t=this.productSectionEl.querySelector(n.BNPL_TEXT),e=t==null?void 0:t.getAttribute("data-title");if(!t||!e)return;const s=4,r=i.price||0,a=((p=(c=window.Shopify)==null?void 0:c.currency)==null?void 0:p.active)||"",o=C(a),l=(Math.round(r/s)/100).toFixed(2);t.innerText=e.replace("_amount",`${o}${l}`)}updateProductOptionSelectors(i){const t=this.querySelectorAll(n.OPTION_VALUES),e=this.productData.variants;t.forEach(s=>{var l;const r=s==null?void 0:s.getAttribute(h.PRODUCT_VARIANT_ID),a=e.find(c=>c.id==r),o=s==null?void 0:s.nextElementSibling;if(!a||!o)return;s.checked=!1,a.id===i.id&&(s.checked=!0),m(a,((l=this.cartService.cart)==null?void 0:l.items)||[])?o.classList.add("disabled"):o.classList.remove("disabled")})}updateProductStockandSizeTagline(i){var o;const t=this.querySelector(n.PRODUCT_SIZE_TAGLINE);t&&(t.textContent=i.metafields.size_tagline||"");const e=this.querySelector("[data-stock-sold-out]"),s=this.querySelector("[data-stock-low-stock]"),r=this.querySelector("[data-stock-promo]");m(i,((o=this.cartService.cart)==null?void 0:o.items)||[])?(s==null||s.classList.add("hidden"),r==null||r.classList.add("hidden"),e==null||e.classList.remove("hidden")):(e==null||e.classList.add("hidden"),r==null||r.classList.remove("hidden"),this.initProductStockLevel())}updateButtonAddToCart(i){var e,s;const t=m(i,((e=this.cartService.cart)==null?void 0:e.items)||[]);(s=this.buttonAddToCart)==null||s.setAttribute(h.BUTTON_STATUS,t?"sold-out":"in-stock")}updateCurrentSwatch(){var t;if(!this.currentSwatch)return;v(this.productData,((t=this.cartService.cart)==null?void 0:t.items)||[])?this.currentSwatch.classList.add("sold-out"):this.currentSwatch.classList.remove("sold-out")}updateWishlistButton(i){const t=this.productSectionEl.querySelector(n.PRODUCT_WISHLIST_BUTTON);if(!t)return;const e=i.id;t.setAttribute("data-current-variant-id",e.toString()),t.setAttribute("data-variant-ids",e.toString());const s=t.querySelector("[data-wishlist-variant-option] label");s&&(s.textContent=i.title)}}customElements.get("product-form")||customElements.define("product-form",I);export{I as P,C as a,g as f,B as g};

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.