import{c as e,d as t,l as n,n as r,o as i,r as a,t as o}from"./parse1688ContextSku-BGzahmc5.js";function s(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function c(e){if(!s(e))return!1;let t=e.mainImage,n=e.offerImgList;return Array.isArray(t)||Array.isArray(n)}function l(){let e=window,t=[e.gallery,s(e.__INIT_DATA)?e.__INIT_DATA.gallery:null,s(e.__GLOBAL_DATA__)?e.__GLOBAL_DATA__.gallery:null];for(let e of t)if(c(e))return e;return null}function u(){let e=window.context;return!s(e)||!a(e)?null:e}function d(){let e=window.offer_details;if(!s(e))return null;let t=e.content;return typeof t!=`string`||!t.trim()?null:{content:t}}function f(e){try{window.postMessage({source:t,type:n,payload:e},`*`)}catch{}}function p(){let e=d();return e?(f(e),!0):!1}function m(n){try{window.postMessage({source:t,type:e,payload:n},`*`)}catch{}}function h(e){let n=r(e);console.log(`[xyxp-1688-sku] context bridge post`,{href:location.href,pieceWeightScaleRowCount:n.length,previewFirst2:n.slice(0,2),note:`previewFirst2 仅预览；完整 SKU 见后续 SKU parsed 日志与 console.table`});try{window.postMessage({source:t,type:i,payload:e},`*`)}catch{}n.length>0&&o(e,`1688-main-world:bridge`)}function g(){let e=u();return e?(h(e),!0):!1}function _(){let e=0,t=window.setInterval(()=>{e+=1;let n=l();if(n){m(n),clearInterval(t);return}e>=16&&clearInterval(t)},500),n=()=>{let e=l();e&&m(e)};n(),window.addEventListener(`DOMContentLoaded`,n,{once:!0}),window.addEventListener(`load`,n,{once:!0})}function v(){let e=!1,t=0;window.addEventListener(`message`,t=>{if(t.source!==window)return;let n=t.data;if(!(!n||n.source!==`xyxp-1688`)){if(n.type===`1688_CONTEXT_ACK`){e=!0;return}n.type===`1688_CONTEXT_REQUEST`&&g()}});let n=()=>e?!0:g(),r=window.setInterval(()=>{if(t+=1,n()&&e){clearInterval(r);return}t>=40&&clearInterval(r)},500);n(),window.addEventListener(`DOMContentLoaded`,n,{once:!0}),window.addEventListener(`load`,n,{once:!0})}_(),v();function y(){let e=!1,t=0;window.addEventListener(`message`,e=>{if(e.source!==window)return;let t=e.data;!t||t.source!==`xyxp-1688`||t.type===`1688_OFFER_DETAILS_REQUEST`&&p()});let n=()=>e?!0:p()?(e=!0,!0):!1,r=window.setInterval(()=>{if(t+=1,n()){clearInterval(r);return}t>=24&&clearInterval(r)},500);n(),window.addEventListener(`DOMContentLoaded`,n,{once:!0}),window.addEventListener(`load`,n,{once:!0})}y(),console.log(`[xyxp-1688] MAIN world bridge booted`,location.href);