var I=Object.defineProperty;var P=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var z=(e,t,a)=>t in e?I(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,E=(e,t)=>{for(var a in t||(t={}))O.call(t,a)&&z(e,a,t[a]);if(P)for(var a of P(t))_.call(t,a)&&z(e,a,t[a]);return e};const R={title:20,description:15,url:15,firstParagraph:15,headings:15,density:15,imageAlt:5},$=(e="")=>{if(typeof document=="undefined")return e;const t=document.createElement("textarea");return t.innerHTML=e,t.value},u=(e="")=>$(String(e).replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ")),f=(e="")=>u(e).toLowerCase().replace(/[^a-z0-9]+/g," ").replace(/\s+/g," ").trim(),F=(e="")=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),K=(e="")=>f(e).split(" ").filter(Boolean),g=(e,t,a)=>{const r=f(e);return!r||!t?!1:r.includes(t)||a.every(c=>r.includes(c))},L=(e="")=>{const t=String(e).match(/<p\b[^>]*>([\s\S]*?)<\/p>/i);if(t!=null&&t[1])return u(t[1]);const a=u(e),[r=""]=a.split(/\n\s*\n/);return r||a.slice(0,320)},M=(e="")=>(String(e).match(/<h[1-6]\b[^>]*>[\s\S]*?<\/h[1-6]>/gi)||[]).map(a=>u(a)).filter(Boolean),j=(e="")=>{const t=[],a=/<img\b[^>]*\balt=(["'])(.*?)\1/gi;let r=a.exec(String(e));for(;r;)t.push($(r[2]||"")),r=a.exec(String(e));return t.filter(Boolean)},U=(e="")=>{if(!e)return"";try{const t=new URL(e,typeof window!="undefined"?window.location.origin:"https://example.com");return`${t.pathname} ${t.search}`.replace(/[-_/=?&]+/g," ")}catch(t){return String(e).replace(/[-_/=?&]+/g," ")}},W=(e="",t="")=>{var c;if(!t)return 0;const a=f(e);if(!a)return 0;const r=new RegExp(`\\b${F(t).replace(/\s+/g,"\\s+")}\\b`,"g");return((c=a.match(r))==null?void 0:c.length)||0},N=(e,t)=>{if(!Array.isArray(e)||e.length===0)return{aggregate:0,primary:null,secondary:[],perKeyword:[]};const a=e.map(s=>v(E({keyword:s.keyword},t))),r=e.findIndex(s=>s.primary),c=r>=0?a[r]:a[0],l=a.filter((s,d)=>d!==(r>=0?r:0));let o;if(l.length===0)o=c.score;else{const s=l.reduce((d,p)=>d+p.score,0)/l.length;o=Math.round(c.score*.7+s*.3)}return{aggregate:o,primary:c,secondary:l,perKeyword:a}},v=({keyword:e="",title:t="",seoTitle:a="",description:r="",url:c="",content:l=""})=>{const o=f(e),s=K(e),d=u(l),p=K(d).length,b=a||t,x=L(l),S=M(l),w=j(l),h=W(d,o),m=p>0&&s.length>0?Number((h*s.length/p*100).toFixed(2)):0,n=!!o,C=h>0&&m>=.5&&m<=2.5,B={title:{passed:n&&g(b,o,s),applicable:!!(n&&b),detail:b},description:{passed:n&&g(r,o,s),applicable:!!(n&&r),detail:r},url:{passed:n&&g(U(c),o,s),applicable:!!(n&&c),detail:c},firstParagraph:{passed:n&&g(x,o,s),applicable:!!(n&&x),detail:x},headings:{passed:n&&S.some(i=>g(i,o,s)),applicable:!!(n&&S.length>0),detail:S},density:{passed:n&&C,applicable:!!(n&&p>0),detail:{density:m,occurrenceCount:h,totalWords:p}},imageAlt:{passed:n&&w.some(i=>g(i,o,s)),applicable:!!(n&&w.length>0),detail:w}},A=n?Object.entries(B).reduce((i,[T,y])=>y.applicable?i+R[T]:i,0):0,H=n?Object.entries(B).reduce((i,[T,y])=>y.applicable&&y.passed?i+R[T]:i,0):0;return{keyword:e,normalizedKeyword:o,totalWords:p,occurrenceCount:h,density:m,score:A>0?Math.round(H/A*100):0,checks:B}};export{N as a,v as b};
