var e=`[xyxp-taobao-sku]`,t=``;function n(n,r){if(!n.length)return;let i=`${n.length}:${n[0]?.skuId}:${n[n.length-1]?.skuId}`;i!==t&&(t=i,console.log(e,`SKU parsed (${r})`,{count:n.length,withPrice:n.filter(e=>e.price!=null).length,withImage:n.filter(e=>e.imageUrl).length}),console.table(n.map(e=>({skuId:e.skuId,price:e.priceText??``,qty:e.quantity??``,image:e.imageUrl?`yes`:``,spec:e.properties.map(e=>`${e.name}:${e.value}`).join(` / `)}))))}function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function i(e){return e==null?``:String(e).trim()}function a(e){let t=e.trim();return t?t.startsWith(`//`)?`https:${t}`:t:``}function o(e){if(!r(e))return null;if(r(e.skuBase)||r(e.item))return e;let t=e.res;if(r(t))return t;let n=e.loaderData;if(r(n)){let e=n.home;if(r(e)){let t=e.data;if(r(t)){let e=t.res;if(r(e))return e}}}return null}function s(e){let t=o(e);if(!t)return!1;let n=t.skuBase;if(!r(n))return!1;let i=n.skus;return Array.isArray(i)&&i.some(r)}function c(e){let t=new Map;if(!Array.isArray(e))return t;for(let n of e){if(!r(n))continue;let e=i(n.pid),o=i(n.name)||`规格`,s=n.values;if(Array.isArray(s))for(let n of s){if(!r(n))continue;let s=i(n.vid);if(!e||!s)continue;let c=a(i(n.image));t.set(`${e}:${s}`,{propName:o,valueName:i(n.name)||s,image:c||void 0})}}return t}function l(e){return e.split(`;`).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf(`:`);return t<=0?null:{pid:e.slice(0,t),vid:e.slice(t+1)}}).filter(e=>!!(e?.pid&&e?.vid))}function u(e){let t=e.subPrice;if(r(t)){let e=i(t.priceText).replace(/起$/,``),n=Number(i(t.priceMoney));if(Number.isFinite(n)&&n>0){let t=n/100;return{priceText:e||String(t),price:t}}if(e){let t=Number(e.replace(/[^\d.]/g,``));return{priceText:e,price:Number.isFinite(t)?t:void 0}}}let n=e.price;if(r(n)){let e=i(n.priceText).replace(/起$/,``),t=Number(i(n.priceMoney));if(Number.isFinite(t)&&t>0){let n=t/100;return{priceText:e||String(n),price:n}}if(e){let t=Number(e.replace(/[^\d.]/g,``));return{priceText:e,price:Number.isFinite(t)?t:void 0}}}return{priceText:``}}function d(e,t){let n=[];for(let{pid:r,vid:i}of l(e)){let e=t.get(`${r}:${i}`);n.push({name:e?.propName??`规格`,value:e?.valueName??i})}return n}function f(e,t){for(let{pid:n,vid:r}of l(e)){let e=t.get(`${n}:${r}`);if(e?.image)return e.image}}function p(e,t=`buildSkusFromTaobaoIce`){let a=o(e);if(!a)return[];let s=a.skuBase,l=a.skuCore;if(!r(s)||!Array.isArray(s.skus))return[];let p=c(s.props),m=r(l)?l:null,h=r(m?.sku2info)?m.sku2info:{},g=[];for(let e of s.skus){if(!r(e))continue;let t=i(e.skuId),n=i(e.propPath);if(!t||t===`0`||!n)continue;let a=d(n,p),o=h[t],s=r(o)?u(o):{priceText:``},c=r(o)?o.quantity:void 0,l=typeof c==`number`&&Number.isFinite(c)?c:Number.isFinite(Number(c))?Number(c):void 0;g.push({skuId:t,priceText:s.priceText,price:s.price,quantity:l,imageUrl:f(n,p),properties:a.length?a:[{name:`规格`,value:t}]})}return n(g,t),g}function m(e){let t=o(e);if(!t)return null;let n=t.item;return r(n)?n:null}var h=`xyxp-taobao`,g=`TAOBAO_ICE_DATA`,_=`TAOBAO_ICE_DATA_REQUEST`,v=`TAOBAO_ICE_DATA_ACK`,y=`xyxp-taobao-ice-data`;function b(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function x(e){let t=o(e);if(!t||!s({res:t}))return null;try{return JSON.parse(JSON.stringify({res:t}))}catch{return null}}function S(e){let t=!1;try{window.postMessage({source:h,type:g,payload:e},`*`),t=!0}catch(e){console.warn(`[xyxp-taobao-sku] postMessage bridge failed`,e)}try{document.dispatchEvent(new CustomEvent(y,{detail:e})),t=!0}catch(e){console.warn(`[xyxp-taobao-sku] CustomEvent bridge failed`,e)}return t}function C(){try{window.postMessage({source:h,type:v},`*`)}catch{}}function w(e){return b(e)&&e.source===`xyxp-taobao`}export{v as a,_ as c,s as d,m as f,C as i,h as l,S as n,y as o,w as r,g as s,x as t,p as u};