1(function(){"use strict";var STORAGE_KEY="pwPendingPersonalizationEdit",MAX_AGE_MS=36e5,RESTORE_ORIGINAL_QUANTITY=!0,DUPLICATE_PROPERTY="_pw-duplicated-at",CUSTOMIZATION_URL_PROPERTY="_customily-customization-url",chainedFetch=window.fetch,pristineFetch=window.pwNativeFetch||window.fetch,duplicating=!1;function getPending(){try{var pending=JSON.parse(sessionStorage.getItem(STORAGE_KEY)||"null");return!pending||!pending.key?null:Date.now()-(pending.ts||0)>MAX_AGE_MS?(clearPending(),null):pending}catch(error){return null}}function setPending(pending){try{return sessionStorage.setItem(STORAGE_KEY,JSON.stringify(pending)),!0}catch(error){return!1}}function clearPending(){try{sessionStorage.removeItem(STORAGE_KEY)}catch(error){}}document.addEventListener("click",function(event){var target=event.target;if(!(!target||!target.closest)){var editLink=target.closest("[data-customily-edit-link]");if(editLink){rememberEdit(event,editLink);return}var duplicateButton=target.closest("[data-customily-duplicate]");if(duplicateButton){event.preventDefault(),duplicateLine(duplicateButton);return}var detailsToggle=target.closest("[data-customily-details-toggle]");detailsToggle&&(event.preventDefault(),toggleDetails(detailsToggle))}});var CUSTOMILY_CDN="https://cdn.customily.com/";document.addEventListener("error",function(event){var img=event.target;if(!(!img||img.tagName!=="IMG")&&!img.getAttribute("data-pw-mirrored")){var src=img.getAttribute("src")||"";src.indexOf(CUSTOMILY_CDN)===0&&(img.setAttribute("data-pw-mirrored","1"),img.src="/apps/orders/asset/"+src.slice(CUSTOMILY_CDN.length))}},!0),document.addEventListener("click",function(event){var target=event.target;if(!(!target||!target.closest)){var media=target.closest(".cart-item__media");media&&handleThumbnailClick(event,media)&&event.stopPropagation()}},!0);function upscale(source){try{var url=new URL(source,window.location.origin);return url.searchParams.has("width")?(url.searchParams.set("width","1600"),url.searchParams.delete("height"),url.toString()):source}catch(error){return source}}function customilyPreviewControl(cartItem){for(var candidates=cartItem.querySelectorAll('a, button, span, div, p, [role="button"]'),i=0;i<candidates.length;i++){var element=candidates[i];if(!element.children.length&&!element.closest(".customily-cart-item-actions")&&(element.textContent||"").trim().toLowerCase()==="preview")return element}return null}function handleThumbnailClick(event,media){var cartItem=media.closest(".cart-item");if(!cartItem)return!1;var control=customilyPreviewControl(cartItem);if(control)return event.preventDefault(),control.click(),!0;var image=media.querySelector("img"),source=image&&(image.currentSrc||image.getAttribute("src"));return source?(event.preventDefault(),openPreview(upscale(source)),!0):!1}var previewOverlay=null;function previewElement(){return previewOverlay||(previewOverlay=document.createElement("div"),previewOverlay.className="customily-preview-overlay",previewOverlay.innerHTML='<button type="button" class="customily-preview-close" aria-label="Close preview"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"></path></svg></button><img alt="Product preview">',previewOverlay.addEventListener("click",function(event){if(event.target.closest(".customily-preview-close")){closePreview();return}event.stopPropagation()}),document.body.appendChild(previewOverlay),previewOverlay)}function openPreview(source){var overlay=previewElement();overlay.querySelector("img").setAttribute("src",source),overlay.classList.add("is-open"),overlay.querySelector(".customily-preview-close").focus()}function closePreview(){previewOverlay&&(previewOverlay.classList.remove("is-open"),previewOverlay.querySelector("img").removeAttribute("src"))}document.addEventListener("keydown",function(event){(event.key==="Escape"||event.key==="Esc")&&closePreview()});function toggleDetails(button){var wrapper=button.closest(".customily-cart-item-actions"),panel=wrapper&&wrapper.querySelector("[data-customily-details]");if(panel){var expanded=button.getAttribute("aria-expanded")==="true";
1button.setAttribute("aria-expanded",expanded?"false":"true"),panel.hidden=expanded,button.textContent=expanded?button.getAttribute("data-label-show")||"Show Details":button.getAttribute("data-label-hide")||"Hide Details"}}function rememberEdit(event,link){setPending({key:link.getAttribute("data-line-key"),productId:parseInt(link.getAttribute("data-product-id"),10)||null,quantity:parseInt(link.getAttribute("data-quantity"),10)||1,customizationUrl:link.getAttribute("href"),duplicateMarker:link.getAttribute("data-duplicate-marker")||"",ts:Date.now()})}function unique(values){return values.filter(function(value,index){return value&&values.indexOf(value)===index})}function readCart(){return window.fetch(window.routes.cart_url+".js",{headers:{Accept:"application/json"}}).then(function(response){return response.ok?response.json():null})}function findByKey(cart,key){return!cart||!cart.items||!key?null:cart.items.filter(function(item){return item.key===key})[0]||null}function propertyOf(line,name){var value=line&&line.properties&&line.properties[name];return value==null?"":String(value)}function describe(line){return{key:line.key,customizationUrl:propertyOf(line,CUSTOMIZATION_URL_PROPERTY),duplicateMarker:propertyOf(line,DUPLICATE_PROPERTY)}}function findLine(cart,descriptor,excludeKey){var byKey=findByKey(cart,descriptor.key);if(byKey)return byKey;if(!cart||!cart.items||!descriptor.customizationUrl)return null;var candidates=cart.items.filter(function(item){return excludeKey&&item.key===excludeKey||propertyOf(item,CUSTOMIZATION_URL_PROPERTY)!==descriptor.customizationUrl?!1:propertyOf(item,DUPLICATE_PROPERTY)===(descriptor.duplicateMarker||"")});return candidates.length===1?candidates[0]:null}function sectionInnerHTML(html,selector){if(!html)return null;var element=new DOMParser().parseFromString(html,"text/html").querySelector(selector);return element?element.innerHTML:null}function cartContext(element){var drawer=element.closest("cart-drawer");if(drawer&&typeof drawer.getSectionsToRender=="function")return{mode:"drawer",element:drawer,sections:unique(drawer.getSectionsToRender().map(function(section){return section.id}))};var items=document.querySelector("cart-items");if(items&&typeof items.getSectionsToRender=="function"){var toRender=items.getSectionsToRender();return{mode:"page",toRender:toRender,sections:unique(toRender.map(function(section){return section.section}))}}return null}function renderCart(context,state){return!context||!state||!state.sections?!1:context.mode==="drawer"?(context.element.renderContents(state),!0):(context.toRender.forEach(function(section){var container=document.getElementById(section.id);if(container){var elementToReplace=container.querySelector(section.selector)||container,newInner=sectionInnerHTML(state.sections[section.section],section.selector);newInner!==null&&(elementToReplace.innerHTML=newInner)}}),!0)}function changeCart(payload){return window.fetch(window.routes.cart_change_url,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(payload)}).then(function(response){return response.ok?response.json():null})}function setBusy(button,busy){busy?(button.setAttribute("aria-busy","true"),button.setAttribute("disabled","disabled")):(button.removeAttribute("aria-busy"),button.removeAttribute("disabled"))}function duplicateLine(button){if(!button.hasAttribute("aria-busy")){var key=button.getAttribute("data-line-key");if(key){setBusy(button,!0),clearPending();var context=cartContext(button),sections=context?context.sections.join(","):null,sectionsUrl=window.location.pathname,marker=String(Date.now()),expected=null;readCart().then(function(cart){if(!cart)throw new Error("could not read the cart");var line=findByKey(cart,key);if(!line)throw new Error("line "+key+" is no longer in the cart");var properties={};Object.keys(line.properties||{}).forEach(function(name){properties[name]=line.properties[name]}),properties[DUPLICATE_PROPERTY]=marker,expected=personalizationFingerprint(properties);var body={id:line.variant_id,quantity:1,properties:properties};sections&&(body.sections=sections,body.sections_url=sectionsUrl),duplicating=!0;var request=sendDuplicateAdd(body);return duplicating=!1,request}).then(function(response){return response.json().then(function(state){if(!response.ok||state.status)throw new Error(state.description||state.message||"add to cart failed");return state})}).then(function(state){return confirmCopy(expected,marker,sections,sectionsUrl).then(function(corrected){return corrected||state})}).then(function(state){renderCart(context,state)||window.location.reload()}).catch(function(error){console.warn("[customily-edit-cart] duplicate failed",error),setBusy(button,!1)})}}}function sendDuplicateAdd(body){return pristineFetch.call(window,window.routes.cart_add_url+".js",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify(body)})}function personalizationFingerprint(properties){var values=properties||{};return Object.keys(values).filter(function(name){return name.charAt(0)!=="_"}).sort().map(function(name){return name+"\0"+String(values[name])}).join("�")}function confirmCopy(expected,marker,sections,sectionsUrl){return expected?readCart().then(function(cart){if(!cart||!cart.items)return null;var copy=cart.items.filter(function(item){return String((item.properties||{})[DUPLICATE_PROPERTY])===marker})[0];return copy?personalizationFingerprint(copy.properties)===expected?(document.dispatchEvent(new CustomEvent("cart:updated",{detail:{cart:cart}})),null):(console.warn("[customily-edit-cart] the duplicate came back with a different personalization than the line it was copied from \u2014 removing it rather than leaving the customer a product they did not choose"),changeCart({id:copy.key,quantity:0,sections:sections,sections_url:sectionsUrl})):null}):Promise.resolve(null)}function readBodyField(body,field){if(!body)return null;try{if(typeof FormData!="undefined"&&body instanceof FormData||typeof URLSearchParams!="undefined"&&body instanceof URLSearchParams)return body.get(field);
1if(typeof body=="string"){var parsed=JSON.parse(body);return parsed?parsed[field]:null}}catch(error){}return null}function replaceOriginalLine(response,pending,sections,sectionsUrl){return response.clone().json().then(function(added){var addedItems=added&&added.items?added.items:[added],match=addedItems.filter(function(item){return item&&(!pending.productId||item.product_id===pending.productId)})[0];return match?(clearPending(),readCart().then(function(cart){var original=findLine(cart,pending,match.key);return!original||original.key===match.key?response:removeAndRestore(response,added,original,match,pending,sections,sectionsUrl)})):response})}function removeAndRestore(response,added,original,match,pending,sections,sectionsUrl){return changeCart({id:original.key,quantity:0,sections:sections,sections_url:sectionsUrl}).then(function(state){if(!state)return null;if(RESTORE_ORIGINAL_QUANTITY&&pending.quantity>1&&match.quantity===1){var replacement=findLine(state,describe(match),null);return replacement?changeCart({id:replacement.key,quantity:pending.quantity,sections:sections,sections_url:sectionsUrl}).then(function(restored){return restored||state}):state}return state}).then(function(state){return!state||!sections||!state.sections?response:(added.sections=state.sections,new Response(JSON.stringify(added),{status:response.status,statusText:response.statusText,headers:{"Content-Type":"application/json"}}))})}window.fetch=function(){var args=arguments,url=typeof args[0]=="string"?args[0]:args[0]&&args[0].url||"",isDuplicateAdd=duplicating,result=chainedFetch.apply(this,args);if(isDuplicateAdd||url.indexOf("/cart/add")===-1)return result;var pending=getPending();if(!pending)return result;var options=args[1]||{},sections=readBodyField(options.body,"sections"),sectionsUrl=readBodyField(options.body,"sections_url")||window.location.pathname;return result.then(function(response){return!response||!response.ok?response:replaceOriginalLine(response,pending,sections,sectionsUrl).catch(function(error){return console.warn("[customily-edit-cart] could not replace the original line",error),response})})}})(); 2//# sourceMappingURL=/cdn/shop/t/65/assets/customily-edit-cart.js.map?v=26950516947962014451788472548
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.