var e=`[xyxp-pdd-sku]`,t=``;function n(n,r,i){if(!n.length)return;let a=`${n.length}:${n[0]?.skuId}:${n[n.length-1]?.skuId}`;if(a===t)return;t=a;let o=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(` / `)}));console.log(e,`SKU parsed (${r})`,{count:n.length,withPrice:n.filter(e=>e.price!=null).length,withImage:n.filter(e=>e.imageUrl).length,skuIds:n.map(e=>e.skuId),...i}),console.table(o),globalThis.__xyxpPddParsedSkus=n}function r(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function i(e){return e==null?``:String(e).trim()}function a(e){if(!r(e))return null;let t=e.store;if(!r(t))return null;let n=t.initDataObj;if(!r(n))return null;let i=n.goods;return r(i)?i:null}function o(e){let t=a(e);if(!t)return[];let n=t.skus;return Array.isArray(n)?n.filter(r):[]}function s(e){let t=e.specs;if(!Array.isArray(t)){let t=i(e.spec);return t?[{name:`规格`,value:t}]:[]}let n=[],a=[...t].filter(r).sort((e,t)=>{let n=Number(e.spec_key_id),r=Number(t.spec_key_id);return Number.isFinite(n)&&Number.isFinite(r)&&n!==r?n-r:i(e.spec_key).localeCompare(i(t.spec_key),`zh-CN`)});for(let e of a){let t=i(e.spec_key)||`规格`,r=i(e.spec_value);r&&n.push({name:t,value:r})}if(n.length>0)return n;let o=i(e.spec);return o?[{name:`规格`,value:o}]:[]}function c(e){let t=e.groupPrice;return t==null?``:String(t).trim()}function l(e){let t=c(e);if(t){let e=Number(t);return{priceText:`¥${t}`,price:Number.isFinite(e)?e:void 0}}let n=Number(e.skuPrice);if(Number.isFinite(n)&&n>0){let e=(n/100).toFixed(2).replace(/\.00$/,``),t=Number(e);return{priceText:`¥${e}`,price:Number.isFinite(t)?t:void 0}}let r=i(e.normalPrice);if(r){let e=Number(r);return{priceText:`¥${r}`,price:Number.isFinite(e)?e:void 0}}return{}}function u(e,t){if(!e.length||!g(t))return e;let n=o(t);if(!n.length)return e;let r=new Map;for(let e of n){if(!c(e))continue;let t=s(e);if(!t.length)continue;let{priceText:n,price:i}=l(e);(n||i!=null)&&r.set(p(t),{priceText:n,price:i})}return r.size?e.map(e=>{let t=r.get(p(e.properties));return t?{...e,priceText:t.priceText??e.priceText,price:t.price??e.price}:e}):e}function d(e){let t=e.trim();return t?t.startsWith(`//`)?`https:${t}`:t:``}function f(e){let t=d(e).toLowerCase();return!t||t.includes(`avatar`)||t.includes(`commimg`)||t.includes(`promotion`)||t.includes(`funimg`)||t.includes(`/upload/ddpay/`)||t.includes(`/tag/`)||t.includes(`/coupon/`)?!1:t.includes(`/mms-goods-image/`)||t.includes(`mms-material-img`)}function p(e){return[...e].sort((e,t)=>{let n=e.name.localeCompare(t.name,`zh-CN`);return n===0?e.value.localeCompare(t.value,`zh-CN`):n}).map(e=>`${e.name}\0${e.value}`).join(`
`)}function m(e,t){if(!e.length||!g(t))return e;let n=h(t,`image-merge`);if(!n.length)return e;let r=new Map;for(let e of n){let t=e.imageUrl?.trim();t&&f(t)&&r.set(p(e.properties),t)}return r.size?e.map(e=>{let t=r.get(p(e.properties));if(t)return{...e,imageUrl:t};let n=e.imageUrl?.trim();return n&&f(n)?e:n?{...e,imageUrl:void 0}:e}):e}function h(e,t=`rawData`){let r=o(e);if(!r.length)return[];let a=[];for(let e of r){let t=i(e.skuId)||i(e.skuID);if(!t)continue;let n=Number(e.quantity),{priceText:r,price:o}=l(e),c=d(i(e.thumbUrl));a.push({skuId:t,priceText:r,price:o,quantity:Number.isFinite(n)?n:void 0,imageUrl:c||void 0,properties:s(e)})}return n(a,t,{rawRowCount:r.length}),a}function g(e){return o(e).length>0}var _=`xyxp-pdd`,v=`PDD_RAW_DATA`,y=`PDD_RAW_DATA_REQUEST`,b=`PDD_RAW_DATA_ACK`,x=`xyxp-pdd-raw-data`;function S(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function C(e){let t=a(e);if(!t)return null;try{return JSON.parse(JSON.stringify({store:{initDataObj:{goods:t}}}))}catch{return null}}function w(e){let t=!1;try{window.postMessage({source:_,type:v,payload:e},`*`),t=!0}catch(e){console.warn(`[xyxp-pdd-sku] postMessage bridge failed`,e)}try{document.dispatchEvent(new CustomEvent(x,{detail:e})),t=!0}catch(e){console.warn(`[xyxp-pdd-sku] CustomEvent bridge failed`,e)}return t}function T(){try{window.postMessage({source:_,type:b},`*`)}catch{}}function E(e){return S(e)&&e.source===`xyxp-pdd`}export{b as a,y as c,o as d,g as f,a as g,u as h,T as i,_ as l,m,w as n,x as o,f as p,E as r,v as s,C as t,h as u};