PageSourceSearch

https://doreens.pizza/wp-content/plugins/woocommerce/assets/client…/cart.js?ver=77881d4d5064fcdb6321

js doreens.pizza collected 2026-10-10 00:31:06 UTC 10,328 bytes, 1 lines download raw bytes

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