// @bun
var{defineProperty:k,getOwnPropertyNames:b,getOwnPropertyDescriptor:y}=Object,S=Object.prototype.hasOwnProperty;function w(J){return this[J]}var e=(J)=>{var K=(M??=new WeakMap).get(J),X;if(K)return K;if(K=k({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function"){for(var Z of b(J))if(!S.call(K,Z))k(K,Z,{get:w.bind(J,Z),enumerable:!(X=y(J,Z))||X.enumerable})}return M.set(J,K),K},M;var P=(J)=>J;function v(J,K){this[J]=P.bind(null,K)}var r=(J,K)=>{for(var X in K)k(J,X,{get:K[X],enumerable:!0,configurable:!0,set:v.bind(K,X)})};var x=(J,K)=>()=>(J&&(K=J(J=0)),K);var g=import.meta.require;import{createHash as G}from"crypto";import{readFile as d,stat as F}from"fs/promises";async function H(J){try{let K=await d(J);return G("sha256").update(K).digest("hex").slice(0,16)}catch{return""}}function KJ(J){return G("sha256").update(J).digest("hex").slice(0,16)}function T(J){return G("sha256").update(J).digest("hex").slice(0,16)}function XJ(J,K){let X=JSON.stringify(K,Object.keys(K).sort());return`${T(J)}-${T(X)}`}async function YJ(J){try{return(await F(J)).mtimeMs}catch{return 0}}async function V(J){try{return await F(J),!0}catch{return!1}}var E=()=>{};import{resolve as m,basename as u,extname as p,join as f}from"path";import{mkdir as l}from"fs/promises";async function n(){try{return await import("ts-images")}catch{return null}}async function c(J,K,X){let Z=await n();if(!Z)return console.warn("[stx-media] ts-images not installed, skipping responsive generation"),null;let $=m(J);if(!await V($))return console.warn(`[stx-media] Source file not found: ${J}`),null;try{let z=K.responsiveWidths||X.breakpoints||h,O=K.formats||X.defaultFormats||["avif","webp","jpeg"],A=X.outputDir||"dist/images",U=X.baseUrl||"/images";await l(A,{recursive:!0});let D=await H($),R=u(J,p(J)),I=X.formatQuality||{jpeg:{quality:82},png:{quality:80},webp:{quality:82},avif:{quality:75}},j={src:J,byFormat:{},srcsets:{}};for(let Y of O){j.byFormat[Y]=[];let Q=[];for(let q of z){let _=`${R}-${q}w-${D}.${Y}`,L=f(A,_),N=`${U}/${_}`;try{let W=I[Y]?.quality||80;if(await V(L)){j.byFormat[Y].push({path:L,url:N,width:q,height:0,format:Y,size:0}),Q.push(`${N} ${q}w`);continue}let B=await Z.processImage({input:$,output:L,format:Y,quality:W,resize:{width:q}});if(B)j.byFormat[Y].push({path:L,url:N,width:q,height:B.height||Math.round(q*(B.height||1)/(B.width||1)),format:Y,size:B.outputSize||0}),Q.push(`${N} ${q}w`)}catch(W){console.warn(`[stx-media] Failed to generate ${Y} at ${q}w: ${W}`)}}j.srcsets[Y]=Q.join(", ")}let C=K.placeholder||X.placeholderStrategy||"thumbhash";if(C!=="none")try{if(C==="thumbhash"){let Y=await Z.generateThumbHash($);j.placeholder={dataURL:Y.dataUrl,width:Y.width||32,height:Y.height||32,strategy:"thumbhash"}}else{let Y=await Z.generatePlaceholder($,{strategy:C,width:20});j.placeholder={dataURL:Y.dataURL,width:Y.width,height:Y.height,strategy:C}}}catch(Y){console.warn(`[stx-media] Failed to generate placeholder: ${Y}`)}return j.sizes=K.sizes||i(z),j}catch(z){return console.error(`[stx-media] Responsive generation failed: ${z}`),null}}function i(J){let K=[...J].sort((Z,$)=>Z-$),X=[];for(let Z=0;Z<K.length-1;Z++){let $=K[Z];X.push(`(max-width: ${$}px) ${$}px`)}return X.push(`${K[K.length-1]}px`),X.join(", ")}function zJ(J,K="width"){if(!J||J.length===0)return"";if(K==="dpr")return J.filter((X)=>X.dpr).map((X)=>`${X.url} ${X.dpr}x`).join(", ");return J.map((X)=>`${X.url} ${X.width}w`).join(", ")}async function AJ(J,K,X){let Z=[];for(let $ of K){let z=await c($.src,{responsiveWidths:$.widths},X);if(z){for(let[O,A]of Object.entries(z.srcsets))if(A)Z.push({media:$.media,srcset:A,type:o(O)})}}return Z}function o(J){switch(J){case"avif":return"image/avif";case"webp":return"image/webp";case"jpeg":return"image/jpeg";case"png":return"image/png";case"gif":return"image/gif";default:return"image/jpeg"}}var h;var a=x(()=>{E();h=[320,480,640,768,1024,1280,1536,1920]});a();export{zJ as generateSrcset,c as generateResponsiveVariants,AJ as generateArtDirectionSources,h as DEFAULT_RESPONSIVE_WIDTHS};
