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