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