const y="Jingrow",L="/logo.svg";function c(e,r,t="name"){if(!r||typeof document>"u")return;const o=`meta[${t}="${e}"]`;let i=document.querySelector(o);i||(i=document.createElement("meta"),i.setAttribute(t,e),document.head.appendChild(i)),i.setAttribute("content",r)}function W(e,r){if(!r||typeof document>"u")return;const t=`link[rel="${e}"]`;let o=document.querySelector(t);o||(o=document.createElement("link"),o.setAttribute("rel",e),document.head.appendChild(o)),o.setAttribute("href",r)}function E(e){if(typeof document>"u")return;const r=document.querySelector('script[type="application/ld+json"]');r&&r.remove();const t=document.createElement("script");t.type="application/ld+json",t.textContent=JSON.stringify(e,null,2),document.head.appendChild(t)}function U(e){if(typeof window>"u"||typeof document>"u")return;const r=window.location.pathname,t=e.url||r,o=e.image||L,i=e.title?`${e.title} - ${y}`:y;if(e.title&&(document.title=i),e.description&&c("description",e.description),e.keywords&&c("keywords",e.keywords),e.robots?c("robots",e.robots):c("robots","index,follow"),e.title&&c("og:title",e.title,"property"),e.description&&c("og:description",e.description,"property"),c("og:image",o,"property"),c("og:url",t,"property"),c("og:type","website","property"),c("og:site_name",y,"property"),c("og:locale","zh_CN","property"),c("twitter:card","summary_large_image"),e.title&&c("twitter:title",e.title),e.description&&c("twitter:description",e.description),c("twitter:image",o),W("canonical",t),e.title&&e.description){const l={"@context":"https://schema.org","@type":"WebPage",name:e.title,description:e.description,url:t,publisher:{"@type":"Organization",name:y,logo:{"@type":"ImageObject",url:o}}};E(l)}}const M={maxWidth:1024,maxHeight:1024,quality:.92,outputFormat:"image/jpeg",mode:"contain"};async function H(e,r={}){const t={...M,...r};return new Promise((o,i)=>{const l=new Image,g=document.createElement("canvas"),f=g.getContext("2d");if(!f){i(new Error("Canvas context not available"));return}const p=URL.createObjectURL(e);l.onload=()=>{try{let{width:s,height:a}=l;if(s<=t.maxWidth&&a<=t.maxHeight){URL.revokeObjectURL(p),e.arrayBuffer().then(n=>{o(new Blob([n],{type:e.type}))}).catch(i);return}let m=s,u=a,x=0,w=0,d=s,h=a;if(t.mode==="contain"){const n=Math.min(t.maxWidth/s,t.maxHeight/a,1);m=Math.round(s*n),u=Math.round(a*n)}else if(t.mode==="cover"){const n=Math.max(t.maxWidth/s,t.maxHeight/a);m=t.maxWidth,u=t.maxHeight,d=Math.round(t.maxWidth/n),h=Math.round(t.maxHeight/n),x=Math.round((s-d)/2),w=Math.round((a-h)/2)}else if(t.mode==="crop"){const n=Math.max(t.maxWidth/s,t.maxHeight/a),b=s*n,F=a*n;m=t.maxWidth,u=t.maxHeight,d=s,h=a,b>t.maxWidth&&(x=Math.round((b-t.maxWidth)/2/n),d=Math.round(t.maxWidth/n)),F>t.maxHeight&&(w=Math.round((F-t.maxHeight)/2/n),h=Math.round(t.maxHeight/n))}g.width=m,g.height=u,t.outputFormat==="image/jpeg"&&(f.fillStyle="#FFFFFF",f.fillRect(0,0,m,u)),f.drawImage(l,x,w,d,h,0,0,m,u),g.toBlob(n=>{URL.revokeObjectURL(p),n?o(n):i(new Error("Failed to create blob"))},t.outputFormat,t.quality)}catch(s){URL.revokeObjectURL(p),i(s)}},l.onerror=()=>{URL.revokeObjectURL(p),i(new Error("Failed to load image"))},l.src=p})}async function O(e,r={}){const t=await H(e,r),o={...M,...r};let i="jpg";o.outputFormat==="image/png"?i="png":o.outputFormat==="image/webp"&&(i="webp");const l=e.name.replace(/\.[^.]+$/,"")+"."+i;return new File([t],l,{type:o.outputFormat,lastModified:Date.now()})}export{O as c,U as u};
