https://mbnovels.com/wp-content/plugins/woocommerce/assets/client/…/cart.js?ver=b6c4f13305af68a3b567
1import*as e from"@woocommerce/stores/store-notices";import*as t from"@wordpress/interactivity";import*as r from"@woocommerce/stores/woocommerce/products";var n={4317:e=>{e.exports=import("@wordpress/a11y")},1167:t=>{t.exports=e}},o={};function a(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,a),r.exports}a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);const i=(s={getConfig:()=>t.getConfig,store:()=>t.store},c={},a.d(c,s),c);var s,c;a.d({},{});const d=e=>e.replace(/^attribute_(pa_)?/,"").replace(/-/g," ").toLowerCase(),l=(e,t)=>d(e)===d(t),{state:u}=(0,i.store)("woocommerce/products",{},{lock:"I acknowledge that using a private store means my plugin will inevitably break on the next store release."}),m=(e,t)=>{if(!Array.isArray(e.variation)||!Array.isArray(t))return!1;if(e.variation.length!==t.length)return!1;const r=u.productVariations[e.id]?.parent,n=u.products[r]?.attributes??[];return e.variation.every(({attribute:e,value:r})=>t.some(t=>{const o=n.find(t=>l(e,t.name))?.terms,a=o?.find(e=>e.name===r)?.slug||r;return l(t.attribute,e)&&t.value.toLowerCase()===a?.toLowerCase()}))};function y(e){return"name"in e}const p=e=>({notice:e.message,type:"error",dismissible:!0}),f=e=>({notice:e,type:"notice",dismissible:!0});function h(e,t,r){return"variation"===e.type?!(t!==e.id||!e.variation||!r||e.variation.length!==r.length)&&m(e,r):t===e.id}function g(e,t){const r=new Set;for(const n of e)if(t.items.filter(e=>h(e,n.id,n.variation)).reduce((e,t)=>e+t.quantity,0)===n.preAddTotal+n.deltaTotal)for(const e of n.preExistingKeys)r.add(e);return r}function v(e){const t=new Set,r=new Set,n=new Set;for(const o of e)o.productsPendingAdd?.forEach(e=>t.add(e)),o.cartItemsPendingQuantity?.forEach(e=>r.add(e)),o.cartItemsPendingDelete?.forEach(e=>n.add(e));const o={};return t.size>0&&(o.productsPendingAdd=[...t]),r.size>0&&(o.cartItemsPendingQuantity=[...r]),n.size>0&&(o.cartItemsPendingDelete=[...n]),o}const w=(e,t,r=new Set)=>{const n=e.items,o=t.items,a=n.filter(y).filter(e=>!o.some(t=>e.key===t.key)),i=o.filter(e=>{if(!y(e))return!1;if(r.has(e.key))return!1;const t=n.find(t=>t.key===e.key);return t&&e.quantity!==t.quantity});return[...a.map(e=>f('"%s" was removed from your cart.'.replace("%s",e.name))),...i.map(e=>f('The quantity of "%1$s" was changed to %2$d.'.replace("%1$s",e.name).replace("%2$d",e.quantity.toString())))]};let b=!1,k=3e3,q=null;const C=new Promise(e=>{q=e});let S=null,E=null;function I(){E||(E=Promise.resolve().then(a.bind(a,4317)),E.then(({speak:e})=>{S=e}).catch(()=>{}))}let P=null;async function N(e,t){return await C,P||(P=function(e){const{endpoint:t,getHeaders:r,takeSnapshot:n,rollback:o,commit:a,fetchHandler:i=fetch}=e;let s=null;const c=new Map;let d=[],l=null,u=null;const m=new Map;let y=!1,p=!1,f=[],h=0;function g(){l=null,d.length>0?w():function(){null!==u?a(u):null!==s&&o(s);const t=[];c.forEach(e=>{t.push({success:!m.get(e.id),...void 0!==e.request.meta&&{meta:e.request.meta}})});try{e.onCycleSettled?.(t)}catch(e){console.error(e)}p=!1;const r=f;f=[],r.forEach(e=>e()),c.forEach(e=>{const t=m.get(e.id);t?e.reject(t):e.resolve({success:!0,...null!==u&&{data:u}})}),s=null,u=null,m.clear(),c.clear()}()}function v(e,t){for(const r of e)m.set(r,t);g()}async function w(){if(y=!1,0===d.length||null!==l)return;l=[...d],d=[];const e=l,n=r();try{const r=e.map(e=>{const t=c.get(e);return t?{path:t.request.path,method:t.request.method,headers:{...n,"Content-Type":"application/json"},body:t.request.body}:null}).filter(Boolean),o=JSON.stringify({requests:r}),a=await i(t,{method:"POST",keepalive:(new TextEncoder).encode(o).byteLength<65536,headers:{"Content-Type":"application/json",...n},body:o});a.ok?function(e,t){t.forEach((t,r)=>{const n=e[r];if(n)if(t.status>=200&&t.status<300)u=t.body;else{const e=t.body;m.set(n,Object.assign(new Error(e?.message||"Request failed"),{code:e?.code||"unknown_error"}))}}),g()}(e,(await a.json()).responses||[]):v(e,new Error(`Request failed: ${a.status}`))}catch(t){v(e,t instanceof Error?t:new Error(String(t)))}}return{submit:function(e){return new Promise((t,r)=>{const o=String(h++);p||(s=n(),p=!0);const a=e.body?JSON.parse(JSON.stringify(e.body)):void 0;e.applyOptimistic&&e.applyOptimistic(),c.set(o,{id:o,request:{...e,body:a},resolve:t,reject:r}),d.push(o),y||null!==l||(y=!0,queueMicrotask(()=>w()))})},getStatus:function(){return{isProcessing:p,pendingCount:d.length}},waitForIdle:function(){return p?new Promise(e=>{f.push(e)}):Promise.resolve()}}}({endpoint:`${e.restUrl}wc/store/v1/batch`,getHeaders:()=>({Nonce:e.nonce}),takeSnapshot:()=>JSON.parse(JSON.stringify(e.cart)),rollback:t=>{e.cart=t},commit:t=>{e.cart=t},fetchHandler:async(...t)=>{const r=await fetch(...t);return e.nonce=r.headers.get("Nonce")||e.nonce,r},onCycleSettled:e=>{const t=e.filter(e=>e.success&&void 0!==e.meta);if(0===t.length)return;const r=t.some(e=>"add"===e.meta.origin);if(r&&(({preserveCartData:e=!1})=>
1{((e,{bubbles:t=!1,cancelable:r=!1,element:n,detail:o={}})=>{if(!CustomEvent)return;n||(n=document.body);const a=new CustomEvent(e,{bubbles:t,cancelable:r,detail:o});n.dispatchEvent(a)})("wc-blocks_added_to_cart",{bubbles:!0,cancelable:!0,detail:{preserveCartData:e}})})({preserveCartData:!0}),function({quantityChanges:e}){window.dispatchEvent(new CustomEvent("wc-blocks_store_sync_required",{detail:{type:"from_iAPI",quantityChanges:e}}))}({quantityChanges:v(t.map(e=>e.meta.quantityChanges))}),r){const{messages:e}=(0,i.getConfig)("woocommerce"),t=e?.addedToCartText;t&&(S?S(t,"polite"):E&&E.then(()=>{S?.(t,"polite")}).catch(()=>{}))}}})),P.submit(t)}const O="I acknowledge that using a private store means my plugin will inevitably break on the next store release.",{state:T}=(0,i.store)("woocommerce",{},{lock:O}),{actions:A}=(0,i.store)("woocommerce",{state:{findItemInCart:({id:e,key:t,variation:r})=>T.cart.items.find(n=>t?t===n.key:"variation"===n.type?!(e!==n.id||!n.variation||!r||n.variation.length!==r.length)&&m(n,r):e===n.id)},actions:{*removeCartItem(e){let t=null;try{const r=(yield N(T,{path:"/wc/store/v1/cart/remove-item",method:"POST",body:{key:e},applyOptimistic:()=>{T.cart.items=T.cart.items.filter(t=>t.key!==e),t=JSON.parse(JSON.stringify(T.cart))},meta:{quantityChanges:{cartItemsPendingDelete:[e]},origin:"remove"}})).data;if(r&&t){const e=w(t,r),n=r.errors.map(p);yield A.updateNotices([...e,...n],!0)}}catch(e){A.showNoticeError(e)}},*addCartItem({id:e,key:t,quantity:r,quantityToAdd:n,variation:o},{showCartUpdatesNotices:a=!0}={}){if(void 0!==r&&void 0!==n)throw new Error("addCartItem: pass either quantity or quantityToAdd, not both.");if(void 0===t&&void 0!==r&&void 0===n)throw new Error("addCartItem: a keyless add must pass quantityToAdd (a delta), not an absolute quantity.");I();const i=T.findItemInCart({id:e,key:t,variation:o});let s;s="number"==typeof n?(i?.quantity??0)+n:"number"==typeof r?r:1;const c=!!t,d=c?"update-item":"add-item",l=c?{cartItemsPendingQuantity:i?.key?[i.key]:[]}:{productsPendingAdd:[e]};let u;if(c&&i)u={...i,quantity:s};else{const t=i?s-i.quantity:s;u={id:e,quantity:t,...o&&{variation:o}}}let m=null;const f=[];if(!c){const t=[];let r=0;for(const n of T.cart.items)h(n,e,o)&&(r+=n.quantity,n.key&&t.push(n.key));f.push({id:e,variation:o,preAddTotal:r,deltaTotal:u.quantity,preExistingKeys:t})}let v;try{const e=yield N(T,{path:`/wc/store/v1/cart/${d}`,method:"POST",body:u,applyOptimistic:()=>{i?y(i)&&i.sold_individually||(i.quantity=s):T.cart.items.push(u),m=JSON.parse(JSON.stringify(T.cart))},meta:{quantityChanges:l,origin:"add"}});v={success:!0};const t=e.data;if(a&&t&&m){const e=g(f,t),r=w(m,t,e),n=t.errors.map(p);yield A.updateNotices([...r,...n],!0)}}catch(e){A.showNoticeError(e),v??={success:!1,error:{...e?.code&&{co
1de:e.code},message:e instanceof Error&&e.message||String(e)||"Request failed"}}}return v},*batchAddCartItems(e,{showCartUpdatesNotices:t=!0}={}){I();try{const r=new Map,n=e.map(e=>{const t=T.findItemInCart({id:e.id,key:e.key,variation:e.variation});let n;n="number"==typeof e.quantityToAdd?(t?.quantity??0)+e.quantityToAdd:e.quantity??1;const o=!!e.key,a=o?"update-item":"add-item";let i,s;if(o&&t)i={key:t.key,id:t.id,quantity:n},s={quantityChanges:{cartItemsPendingQuantity:[t.key]},origin:"add"};else{const o=t?n-t.quantity:n;i={id:e.id,quantity:o,...e.variation&&{variation:e.variation}},s={quantityChanges:{productsPendingAdd:[e.id]},origin:"add"};const a=(c=e.id,(d=e.variation)&&0!==d.length?`${c}|${[...d].sort((e,t)=>e.attribute.localeCompare(t.attribute)).map(e=>`${e.attribute}=${e.value}`).join("&")}`:String(c));if(r.has(a)){const e=r.get(a);e&&(e.deltaTotal+=o)}else{const t=[];let n=0;for(const r of T.cart.items)h(r,e.id,e.variation)&&(n+=r.quantity,r.key&&t.push(r.key));r.set(a,{id:e.id,variation:e.variation,preAddTotal:n,deltaTotal:o,preExistingKeys:t})}}var c,d;return N(T,{path:`/wc/store/v1/cart/${a}`,method:"POST",body:i,applyOptimistic:()=>{t?t.quantity=n:T.cart.items.push(i)},meta:s})}),o=JSON.parse(JSON.stringify(T.cart)),a=yield Promise.allSettled(n),i=[...a].reverse().find(e=>"fulfilled"===e.status&&e.value.success);if(i){const e=i.value.data;if(t){const t=g([...r.values()],e),n=w(o,e,t),a=e.errors.map(p);yield A.updateNotices([...n,...a],!0)}}const s=a.filter(e=>"rejected"===e.status).map(e=>p(e.reason));s.length>0&&(yield A.updateNotices(s))}catch(e){A.showNoticeError(e)}},*refreshCartItems(){if(!P?.getStatus().isProcessing&&!b){b=!0;try{const t=yield fetch(`${T.restUrl}wc/store/v1/cart`,{method:"GET",cache:"no-store",headers:{"Content-Type":"application/json"}});T.nonce=t.headers.get("Nonce")||T.nonce,q&&(q(),q=null);const r=yield t.json();if(function(e){return!e.ok}(t))throw e=r,Object.assign(new Error(e.message||"Unknown error."),{code:e.code||"unknown_error"});if(P?.getStatus().isProcessing)return;T.cart=r,k=3e3}catch(e){setTimeout(A.refreshCartItems,k),k*=2}finally{b=!1}var e}},*waitForIdle(){P&&(yield P.waitForIdle())},*showNoticeError(e){yield Promise.resolve().then(a.bind(a,1167));const{actions:t}=(0,i.store)("woocommerce/store-notices",{},{lock:"I acknowledge that using a private store means my plugin will inevitably break on the next store release."}),{code:r,message:n}=e,o=T.errorMessages?.[r]||n;t.addNotice({notice:o,type:"error",dismissible:!0}),console.error(e)},*updateNotices(e=[],t=!1){yield Promise.resolve().then(a.bind(a,1167));const{state:r,actions:n}=(0,i.store)("woocommerce/store-notices",{},{lock:"I acknowledge that using a private store means my plugin will inevitably break on the next store release."}),o=e.map(e=>n.addNotice(e)),{notices:s}=r;t&&s.map(({id:e})=>e).filter(e=>!o.includes(e)).forEach(e=>n.removeNotice(e))}}},{lock:O});A.refreshCartItems(),window.addEventListener("wc-blocks_store_sync_required",async e=>{"from_@wordpress/data"===e.detail.type&&A.refreshCartItems()});
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.