function e(e,t){for(let n of t){let t=e.querySelector(n)?.textContent?.trim();if(t)return t}return``}function t(e){return e.trim()?(e.split(`,`)[0]?.trim()??``).split(/\s+/)[0]?.trim()??``:``}var n=[`src`,`lazySrc`,`lazy`,`original`,`url`,`img`,`imgUrl`,`realUrl`,`ksLazyload`,`lazyload`];function r(e){let t=[],r=e.dataset;for(let e of n){let n=r[e];n&&i(n)&&t.push(n)}for(let[e,n]of Object.entries(r))n&&/src|url|img|pic|image|lazy|load/i.test(e)&&i(n)&&t.push(n);return t}function i(e){let t=e.trim();return!t||t.startsWith(`data:`)?!1:/^https?:\/\//i.test(t)||t.startsWith(`//`)||/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i.test(t)}var a=[`data-src`,`data-lazy-src`,`data-lazy`,`data-original`,`data-url`,`data-img-url`,`data-image`,`data-img`,`data-pic`,`data-preview`,`data-ks-lazyload`,`data-ks-lazyload-custom`];function o(e){let n=[];for(let t of a){let r=e.getAttribute(t);r&&n.push(r)}e.currentSrc&&n.push(e.currentSrc),e.src&&!e.src.startsWith(`data:`)&&n.push(e.src);let i=e.getAttribute(`srcset`);if(i){let e=t(i);e&&n.push(e)}n.push(...r(e));for(let e of n){let t=d(e);if(t&&!s(t))return t}return``}function s(e){let t=e.toLowerCase();return!e||e.startsWith(`data:image/svg`)||/\/1x1[./_-]/i.test(t)||/[?&]1x1/i.test(t)||/spacer|blank|pixel|tracking|beacon|\.gif\?/i.test(t)||t.includes(`gw.alicdn.com`)?!0:(/sx\d+\s*sy\d+/i.test(t)&&/_\d+x\d+/.test(t),!1)}function c(e,t,n=20){let r=[];for(let n of t)e.querySelectorAll(n).forEach(e=>{let t=o(e);t&&r.push(t)});return f(r).slice(0,n)}function l(e){let t=e.getAttribute(`style`)??``,n=t.match(/background-image\s*:\s*url\(\s*['"]?([^'")\s]+)['"]?\s*\)/i);if(n?.[1]||(n=t.match(/url\(\s*['"]?([^'")\s]+)['"]?\s*\)/i),n?.[1]&&i(n[1])))return d(n[1]);if(e instanceof HTMLElement){let t=e.dataset;for(let e of[`backgroundImage`,`bgUrl`,`imgUrl`,`pic`,`thumb`]){let n=t[e];if(n&&i(n))return d(n)}}return``}function u(e,t,n=24){let r=[];for(let n of t)e.querySelectorAll(n).forEach(e=>{let t=l(e);t&&!s(t)&&r.push(t)});return f(r).slice(0,n)}function d(e){if(!e)return``;let t=e.trim();return t.startsWith(`//`)?`https:${t}`:(t.startsWith(`http://`)||t.startsWith(`https://`),t)}function f(e){return Array.from(new Set(e.filter(Boolean)))}function p(e,t,n){let r=new Set(e),i=t.filter(e=>e&&!r.has(e)),a=new Set(i),o=n.filter(e=>e&&!r.has(e)&&!a.has(e));return{main:f(e),detail:f(i),sku:f(o)}}function m(e){return new DOMParser().parseFromString(e,`text/html`)}var h=24e3,g=`
<!-- …[详情 HTML 已截断] -->`,_=`script, style, noscript, template, svg, iframe, object, embed`;function v(e){if(e instanceof Element)for(let t of Array.from(e.attributes)){let n=t.name.toLowerCase();(n.startsWith(`on`)||n===`href`&&/^javascript:/i.test(t.value))&&e.removeAttribute(t.name)}e.childNodes.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&v(e)})}function y(e){let t=document.createElement(`template`);return t.innerHTML=e,t.content.querySelectorAll(_).forEach(e=>e.remove()),v(t.content),t.innerHTML.trim()}function b(e,t){let n=new Set,r=[],i=e=>{!(e instanceof HTMLElement)||n.has(e)||(n.add(e),r.push(e))};for(let n of t)e.querySelectorAll(n).forEach(e=>i(e));return e.querySelectorAll(`*`).forEach(e=>{let n=e.shadowRoot;if(n)for(let e of t)n.querySelectorAll(e).forEach(e=>i(e))}),r}function x(e,t){let n=b(e,t);if(n.length)return y(n.map(e=>{let t=e.cloneNode(!0);return t.querySelectorAll(_).forEach(e=>e.remove()),v(t),t.outerHTML}).join(`
`))||void 0}function S(e,t=h){if(e==null)return;let n=e.trim();if(n)return n.length<=t?n:`${n.slice(0,Math.max(0,t-24))}${g}`}export{c as a,o as c,d,m as f,u as i,e as l,f as m,x as n,p as o,s as p,S as r,l as s,h as t,i as u};