1import{SBF_SKU,SBF_THRESHOLD}from"small-batch-fee-constants";var SBF_SECTION_ID="sbf-variant-data",CART_MUTATION_RE=/\/cart\/(add|change|update|clear)(\.js)?(\?|$)/;function cartRoute(){return window.Shopify&&window.Shopify.routes&&window.Shopify.routes.root?window.Shopify.routes.root:"/"}function notifyCartUpdated(){var settings=window.themeVariables&&window.themeVariables.settings;if(settings&&settings.pageType==="cart"){window.location.reload();return}document.dispatchEvent(new CustomEvent("cart:refresh",{bubbles:!0}))}function cartFetch(url,body){return fetch(url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(body)}).then(function(res){return res.ok?res.json():res.text().then(function(t){throw new Error("Cart request failed: "+res.status+" "+t)})})}function shimMultiplier(map,variantId){return!map||variantId==null?NaN:parseFloat(map[String(variantId)])}export function computeQualifyingCount(items,multiplierMap){for(var count=0,i=0;i<items.length;i++){var item=items[i];if(item.sku!==SBF_SKU){var qty=item.quantity,serverMult=shimMultiplier(multiplierMap,item.variant_id);if(serverMult>0&&qty*serverMult<SBF_THRESHOLD){count++;continue}var properties=item.properties;if(properties){var propMult=parseFloat(properties._sbf_sqft_per_unit);propMult>0&&qty*propMult<SBF_THRESHOLD&&count++}}}return count}export function syncSmallBatchFee(cart,feeVariantId,multiplierMap){for(var items=cart&&cart.items||[],qualifyingCount=computeQualifyingCount(items,multiplierMap),feeLine=null,i=0;i<items.length;i++)if(items[i].sku===SBF_SKU){feeLine=items[i];break}var currentFeeQty=feeLine?feeLine.quantity:0,route=cartRoute();return qualifyingCount===currentFeeQty?Promise.resolve():qualifyingCount===0?cartFetch(route+"cart/change.js",{id:feeLine.key,quantity:0}).then(notifyCartUpdated):feeLine?cartFetch(route+"cart/change.js",{id:feeLine.key,quantity:qualifyingCount}).then(notifyCartUpdated):cartFetch(route+"cart/add.js",{items:[{id:feeVariantId,quantity:qualifyingCount}]}).then(notifyCartUpdated).catch(function(err){console.error("[small-batch-fee-sync] fee product unavailable:",err)})}export function parseVariantDataHtml(html){try{var doc=new DOMParser().parseFromString(html,"text/html"),el=doc.querySelector("script[data-sbf-variant-data]");if(!el)return{};var parsed=JSON.parse((el.textContent||"{}").trim()||"{}");return parsed&&typeof parsed=="object"?parsed:{}}catch(err){return console.error("[small-batch-fee-sync] failed to parse variant-data section:",err),{}}}export function isCartMutationRequest(input,init){var url=typeof input=="string"?input:input&&input.url||"",method=init&&init.method||input&&typeof input!="string"&&input.method||"GET";return String(method).toUpperCase()==="POST"&&CART_MUTATION_RE.test(String(url))}export function createSyncScheduler(runFn){var inFlight=!1,pending=!1,idleWaiters=[];function flushIdleWaiters(){var waiters=idleWaiters;idleWaiters=[];for(var i=0;i<waiters.length;i++)waiters[i]()}function start(){inFlight=!0;var result;try{result=runFn()}catch(err){result=Promise.reject(err)}Promise.resolve(result).catch(function(){}).then(function(){inFlight=!1,pending?(pending=!1,start()):flushIdleWaiters()})}function request(){if(inFlight){pending=!0;return}start()}function isBusy(){return inFlight||pending}function drain(){return isBusy()?new Promise(function(resolve){idleWaiters.push(resolve)}):Promise.resolve()}return{request:request,isBusy:isBusy,drain:drain}}export function installCheckoutSettleGuard(opts){var scheduler=opts.scheduler,capMs=opts.capMs!=null?opts.capMs:2500,target=opts.target||document,bypassing=!1;function onSubmit(event){if(bypassing)return;var submitter=event.submitter;if(!submitter||submitter.name!=="checkout"||!scheduler.isBusy()||event.defaultPrevented)return;var form=event.target;if(!form||typeof form.requestSubmit!="function")return;event.preventDefault();var done=!1;function proceed(){if(!done){done=!0,clearTimeout(timer),bypassing=!0;try{form.requestSubmit(submitter)}finally{bypassing=!1}}}var timer=setTimeout(proceed,capMs);scheduler.drain().then(proceed,proceed)}return target.addEventListener("submit",onSubmit,!0),function(){target.removeEventListener("submit",onSubmit,!0)}}export function installCartMutationInterceptors(opts){var onMutation=opts.onMutation,isInternal=opts.isInternal||function(){return!1},target=opts.target||window,originalFetch=target.fetch;if(typeof originalFetch=="function"){var realFetch=originalFetch;target.fetch=function(input,init){var internal=isInternal(),promise=realFetch.apply(this,arguments);return!internal&&isCartMutationRequest(input,init)&&Promise.resolve(promise).then(function(res){res&&res.ok&&onMutation()}).catch(function(){}),promise}}var XHR=target.XMLHttpRequest,origOpen,origSend;return XHR&&XHR.prototype&&(origOpen=XHR.prototype.open,origSend=XHR.prototype.send,XHR.prototype.open=function(method,url){return this.__sbfMethod=String(method||"").toUpperCase(),this.__sbfUrl=String(url||""),origOpen.apply(this,arguments)},XHR.prototype.send=function(){return!isInternal()&&this.__sbfMethod==="POST"&&CART_MUTATION_RE.test(this.__sbfUrl)&&this.addEventListener("loadend",function(){this.status>=200&&this.status<300&&onMutation()}),origSend.apply(this,arguments)}),function(){typeof originalFetch=="function"&&(target.fetch=originalFetch),XHR&&XHR.prototype&&(XHR.prototype.open=origOpen,XHR.prototype.send=origSend)}}(function(){var el=document.querySelector('meta[name="sbf-variant-id"]'),rawValue=el?el.getAttribute("content"):null,feeVariantId=parseInt(rawValue,10);if(!el||!Number.isFinite(feeVariantId)||feeVariantId<=0){var reason=el?"invalid fee_variant_id value: "+JSON.stringify(rawValue):'meta[name="sbf-variant-id"] tag not found in <head>',errorMsg="[small-batch-fee-sync] Initialization failed: "+reason+". Expected a positive integer variant ID for SKU "+SBF_SKU+'. Verify that the "small-batch-fee" product exists and has a variant with SKU '+SBF_SKU+', and that theme.liquid renders <meta name="sbf-variant-id">.';throw console.error(errorMsg),new Error(errorMsg)}var internalCartMutation=!1,shimMultipliers=Object.create(null),fetchedHandles=Object.create(null);function fetchVariantMultipliers(handle){var url=cartRoute()+"products/"+encodeURIComponent(handle)+"?section_id="+SBF_SECTION_ID;return fetch(url,{credentials:"same-origin"}).then(function(res){if(!res.ok)throw new Error("Section fetch failed: "+res.status);return res.text()}).then(parseVariantDataHtml)}function ensureMultipliers(items){var handles={};
1(items||[]).forEach(function(item){if(item.sku!==SBF_SKU){var handle=item.handle;handle&&!fetchedHandles[handle]&&(handles[handle]=!0)}});var list=Object.keys(handles);return list.length?Promise.all(list.map(function(handle){return fetchVariantMultipliers(handle).then(function(map){fetchedHandles[handle]=!0,Object.keys(map).forEach(function(vid){shimMultipliers[vid]=map[vid]})}).catch(function(err){console.error("[small-batch-fee-sync] variant-data fetch failed for "+handle+":",err)})})).then(function(){return shimMultipliers}):Promise.resolve(shimMultipliers)}function runSync(){return fetch(cartRoute()+"cart.js").then(function(r){return r.ok?r.json():r.text().then(function(t){throw new Error("Cart fetch failed: "+r.status+" "+t)})}).then(function(cart){return ensureMultipliers(cart.items).then(function(map){internalCartMutation=!0;var done;try{done=syncSmallBatchFee(cart,feeVariantId,map)}finally{internalCartMutation=!1}return done})}).catch(function(err){console.error("[small-batch-fee-sync] sync error:",err)})}var scheduler=createSyncScheduler(runSync);installCartMutationInterceptors({onMutation:scheduler.request,isInternal:function(){return internalCartMutation}}),document.addEventListener("cart:change",scheduler.request),installCheckoutSettleGuard({scheduler:scheduler}),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",scheduler.request):scheduler.request()})(); 2//# sourceMappingURL=/cdn/shop/t/18/assets/small-batch-fee-sync.js.map?v=147242345186371232071788879395
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.