// @bun
var{defineProperty:YJ,getOwnPropertyNames:qZ,getOwnPropertyDescriptor:GZ}=Object,HZ=Object.prototype.hasOwnProperty;function MZ(J){return this[J]}var iZ=(J)=>{var Z=(kJ??=new WeakMap).get(J),X;if(Z)return Z;if(Z=YJ({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function"){for(var $ of qZ(J))if(!HZ.call(Z,$))YJ(Z,$,{get:MZ.bind(J,$),enumerable:!(X=GZ(J,$))||X.enumerable})}return kJ.set(J,Z),Z},kJ;var OZ=(J)=>J;function VZ(J,Z){this[J]=OZ.bind(null,Z)}var NZ=(J,Z)=>{for(var X in Z)YJ(J,X,{get:Z[X],enumerable:!0,configurable:!0,set:VZ.bind(Z,X)})};var A=(J,Z)=>()=>(J&&(Z=J(J=0)),Z);var KJ=import.meta.require;function p(J,Z=c,X={},$){return Z.sort((Y,K)=>Y-K).map((Y)=>{return`${v(J,{...X,w:Y,fm:$})} ${Y}w`}).join(", ")}function aZ(J,Z=320,X=2560,$=0.08,Y={},K){let B=jZ(Z,X,$);return p(J,B,Y,K)}function jZ(J,Z,X=0.08){let $=[],Y=J;while(Y<Z)$.push(Math.round(Y)),Y*=1+X*2;if($[$.length-1]!==Z)$.push(Z);return $}function BJ(J,Z,X=FJ,$={},Y){return X.sort((K,B)=>K-B).map((K)=>{let B=Math.round(Z*K);return`${v(J,{...$,w:B,dpr:K,fm:Y})} ${K}x`}).join(", ")}function rZ(J,Z,X=FJ,$=80,Y={},K){let B={1:$,1.5:Math.round($*0.9),2:Math.round($*0.8),3:Math.round($*0.7),4:Math.round($*0.6),5:Math.round($*0.5)};return X.sort((q,O)=>q-O).map((q)=>{let O=Math.round(Z*q),V=B[q]||Math.round($*Math.max(0.5,1-q*0.1));return`${v(J,{...Y,w:O,q:V,dpr:q,fm:K})} ${q}x`}).join(", ")}function qJ(J,Z="100vw"){if(!J||Object.keys(J).length===0)return Z;let $=Object.entries(J).map(([Y,K])=>{let B=/^\d+$/.test(Y)?`${Y}px`:Y;return{bp:B,size:K,numericBp:Number.parseInt(B)||0}}).sort((Y,K)=>Y.numericBp-K.numericBp).map(({bp:Y,size:K})=>`(max-width: ${Y}) ${K}`);return $.push(Z),$.join(", ")}function sZ(J,Z="100vw"){if(!J||J.length===0)return Z;let $=[...J].sort((Y,K)=>(Y.maxWidth||0)-(K.maxWidth||0)).filter((Y)=>Y.maxWidth).map((Y)=>`(max-width: ${Y.maxWidth}px) ${Y.imageWidth}`);return $.push(Z),$.join(", ")}function v(J,Z={}){let X=Object.entries(Z).filter(([,K])=>K!==void 0&&K!==null).map(([K,B])=>{if(Array.isArray(B))return[K,B.join(",")];return[K,String(B)]});if(X.length===0)return J;let $=X.map(([K,B])=>`${K}=${encodeURIComponent(B)}`).join("&"),Y=J.includes("?")?"&":"?";return`${J}${Y}${$}`}function eZ(J){let[Z,X]=J.split("?"),$={};if(X)new URLSearchParams(X).forEach((K,B)=>{if(/^\d+$/.test(K))$[B]=Number.parseInt(K,10);else if(/^\d+\.\d+$/.test(K))$[B]=Number.parseFloat(K);else if(K==="true")$[B]=!0;else if(K==="false")$[B]=!1;else $[B]=K});return{src:Z,params:$}}function J0(J){let{src:Z,widths:X,dprValues:$,fixedWidth:Y,formats:K=a,baseUrl:B="",params:q={}}=J,O=[];for(let V of K){let N,M;if(Y!==void 0&&$)N=BJ(Z,Y,$,q,V),M=$.map((G)=>({path:"",url:v(Z,{...q,w:Math.round(Y*G),fm:V}),width:Math.round(Y*G),height:0,format:V,size:0,dpr:G}));else{let G=X||c;N=p(Z,G,q,V),M=G.map((W)=>({path:"",url:v(Z,{...q,w:W,fm:V}),width:W,height:0,format:V,size:0}))}O.push({srcset:N,format:V,mimeType:xJ[V],variants:M})}return O}function Z0(J,Z="100vw"){return J.map(({srcset:X,mimeType:$})=>`<source type="${$}" srcset="${X}" sizes="${Z}" />`).join(`
`)}function $0(J,Z){if(J.length===0)return;let X=[...J].sort((Y,K)=>Y.width-K.width),$=X.find((Y)=>Y.width>=Z);if($)return $;return X[X.length-1]}function X0(J,Z){let X=Z?J.filter((Y)=>Y.format===Z):J;if(X.length===0){let Y=J.filter((B)=>B.format==="jpeg"),K=Y.length>0?Y:J;return K[Math.floor(K.length/2)]}let $=X.sort((Y,K)=>Y.width-K.width);return $[Math.floor($.length/2)]}function Y0(J){let Z=new Map;for(let X of J){let $=Z.get(X.format)||[];$.push(X),Z.set(X.format,$)}return Z}function GJ(J){return xJ[J]||"application/octet-stream"}function K0(J){return QZ[J]||J}function B0(J){switch(J.split(".").pop()?.toLowerCase()){case"jpg":case"jpeg":return"jpeg";case"png":return"png";case"webp":return"webp";case"avif":return"avif";case"gif":return"gif";default:return}}var c,FJ,a,xJ,QZ,tZ;var SJ=A(()=>{c=[320,480,640,768,1024,1280,1536,1920,2560],FJ=[1,1.5,2,3],a=["avif","webp","jpeg"],xJ={avif:"image/avif",webp:"image/webp",jpeg:"image/jpeg",png:"image/png",gif:"image/gif"},QZ={avif:"avif",webp:"webp",jpeg:"jpg",png:"png",gif:"gif"};tZ={fullWidth:"100vw",halfDesktop:"(max-width: 768px) 100vw, 50vw",thirdDesktop:"(max-width: 768px) 100vw, 33.33vw",quarterDesktop:"(max-width: 480px) 100vw, (max-width: 768px) 50vw, 25vw",contentWidth:"(max-width: 768px) 100vw, (max-width: 1200px) 80vw, 960px"}});async function MJ(){try{return await import("ts-images")}catch{return null}}async function CJ(J,Z={}){let X={..._Z,...Z},$=await MJ();if($)try{return await RZ(J,X,$)}catch(Y){console.warn(`[stx-media] ts-images placeholder generation failed, using fallback: ${Y}`)}return PJ(J,X)}async function RZ(J,Z,X){let{generatePlaceholder:$,generateThumbHash:Y}=X,B={blur:"blur",thumbhash:"thumbhash",blurhash:"thumbhash",pixelate:"pixelate","dominant-color":"dominant-color",none:"blur"}[Z.strategy]||"blur";if(Z.strategy==="thumbhash")return{dataURL:(await Y(J)).dataUrl,width:32,height:32,aspectRatio:1,originalWidth:0,originalHeight:0,strategy:"thumbhash"};let q=await $(J,{width:Z.width,height:Z.height,quality:Z.quality,blurLevel:Z.blurLevel,strategy:B,base64Encode:!0});return{dataURL:q.dataURL,width:q.width,height:q.height,aspectRatio:q.aspectRatio,originalWidth:q.originalWidth,originalHeight:q.originalHeight,strategy:Z.strategy,dominantColor:q.dominantColor,css:q.css}}function PJ(J,Z){let X=Z.width||20,$=Z.height||X,Y="#e5e7eb",K=`<svg xmlns="http://www.w3.org/2000/svg" width="${X}" height="${$}" viewBox="0 0 ${X} ${$}"><rect fill="#e5e7eb" width="${X}" height="${$}"/></svg>`;return{dataURL:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(K)}`,width:X,height:$,aspectRatio:X/$,originalWidth:0,originalHeight:0,strategy:Z.strategy,dominantColor:"#e5e7eb"}}async function G0(J){let Z=await MJ();if(Z)try{return(await Z.generateThumbHash(J)).dataUrl}catch{}return(await PJ(J,{strategy:"thumbhash",width:32,height:32})).dataURL}function H0(J){let Z=J[0]|J[1]<<8|J[2]<<16,X=(Z&63)/63,$=(Z>>6&63)/31.5-1,Y=(Z>>12&63)/31.5-1,K=(Z>>18&31)/31,B=Z>>23!==0,q=J[3]|J[4]<<8,O=(q>>3&63)/63,V=(q>>9&63)/63,N=q>>15!==0,M=Math.max(3,N?B?5:7:B?5:7),G=Math.max(3,N?B?5:7:B?5:7),W=32,H=32,z=Math.max(0,Math.min(255,Math.round((X+$)*255))),Q=Math.max(0,Math.min(255,Math.round(X*255))),U=Math.max(0,Math.min(255,Math.round((X-$)*255))),j=`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32">
    <rect fill="rgb(${z},${Q},${U})" width="32" height="32"/>
  </svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(j)}`}async function M0(J,Z=20,X=50){return CJ(J,{strategy:"blur",width:Z,quality:X,blurLevel:40})}async function O0(J){let Z=await MJ();if(Z)try{return(await Z.generatePlaceholder(J,{strategy:"dominant-color"})).dominantColor||"#e5e7eb"}catch{}return"#e5e7eb"}function V0(J,Z=1,X=1){let $=`<svg xmlns="http://www.w3.org/2000/svg" width="${Z}" height="${X}"><rect fill="${J}" width="${Z}" height="${X}"/></svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent($)}`}function DJ(J,Z,X={}){let $=X.transitionDuration||300,Y=X.easing||"ease-out";return`
#${J} {
  --stx-img-transition-duration: ${$}ms;
  --stx-img-transition-easing: ${Y};
  background-image: url('${Z.dataURL}');
  background-size: cover;
  background-position: center;
}

#${J} img {
  opacity: 0;
  transition: opacity var(--stx-img-transition-duration) var(--stx-img-transition-easing);
}

#${J}.stx-img-loaded img {
  opacity: 1;
}
`.trim()}function N0(J){return`background-image: url('${J.dataURL}'); background-size: cover; background-position: center;`}async function AJ(J,Z={}){let X=`${J}:${JSON.stringify(Z)}`;if(g.has(X))return g.get(X);let $=await CJ(J,Z);return g.set(X,$),$}function Q0(){g.clear()}function j0(){return{size:g.size,keys:Array.from(g.keys())}}var _Z,HJ,g;var IJ=A(()=>{_Z={strategy:"thumbhash",width:20,quality:50,blurLevel:40,transitionDuration:300,easing:"ease-out"},HJ=`
.stx-img-placeholder {
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.stx-img-placeholder img {
  opacity: 0;
  transition: opacity var(--stx-img-transition-duration, 300ms) var(--stx-img-transition-easing, ease-out);
}

.stx-img-placeholder.stx-img-loaded img {
  opacity: 1;
}

.stx-img-blur {
  filter: blur(20px);
  transform: scale(1.1);
  transition: filter var(--stx-img-transition-duration, 300ms) var(--stx-img-transition-easing, ease-out),
              transform var(--stx-img-transition-duration, 300ms) var(--stx-img-transition-easing, ease-out);
}

.stx-img-loaded .stx-img-blur {
  filter: blur(0);
  transform: scale(1);
}
`.trim();g=new Map});import{createHash as OJ}from"crypto";import{readFile as WZ,stat as vJ}from"fs/promises";async function m(J){try{let Z=await WZ(J);return OJ("sha256").update(Z).digest("hex").slice(0,16)}catch{return""}}function U0(J){return OJ("sha256").update(J).digest("hex").slice(0,16)}function bJ(J){return OJ("sha256").update(J).digest("hex").slice(0,16)}function r(J,Z){let X=JSON.stringify(Z,Object.keys(Z).sort());return`${bJ(J)}-${bJ(X)}`}async function VJ(J){try{return(await vJ(J)).mtimeMs}catch{return 0}}async function y(J){try{return await vJ(J),!0}catch{return!1}}var s=()=>{};import{mkdir as UZ,readFile as fJ,writeFile as zZ,readdir as uJ,rm as NJ,stat as EZ}from"fs/promises";import{join as h,dirname as LZ}from"path";async function wZ(J){try{await UZ(J,{recursive:!0})}catch{}}function gJ(J,Z,X){return h(J,X,`${Z}.json`)}async function yJ(J,Z,X){if((Date.now()-J.createdAt)/86400000>X)return!1;if(await VJ(Z)!==J.srcMtime)return!1;return!0}async function mJ(J,Z,X,$=d){if(!$.enabled)return null;let Y=r(J,Z),K=P.get(Y);if(K){if(await yJ(K,J,$.maxAge))return K.lastAccessedAt=Date.now(),K.data;P.delete(Y)}let B=gJ($.directory,Y,X);if(await y(B))try{let q=await fJ(B,"utf-8"),O=JSON.parse(q);if(await yJ(O,J,$.maxAge))return O.lastAccessedAt=Date.now(),P.set(Y,O),O.data}catch{}return null}async function hJ(J,Z,X,$,Y=d){if(!Y.enabled)return;let K=r(J,Z),B=await m(J),q=await VJ(J),O={key:K,src:J,srcHash:B,srcMtime:q,optionsHash:r("",Z),data:X,createdAt:Date.now(),lastAccessedAt:Date.now()};P.set(K,O);let V=gJ(Y.directory,K,$);try{await wZ(LZ(V)),await zZ(V,JSON.stringify(O,null,2))}catch(N){console.warn(`[stx-media] Failed to write cache: ${N}`)}}async function T0(J,Z,X=d){for(let[$,Y]of P.entries())if(Y.src===J)P.delete($)}async function dJ(J,Z=d){if(J==="all")P.clear();else P.clear();let X=J==="all"?["image","video"]:[J];for(let $ of X){let Y=h(Z.directory,$);try{await NJ(Y,{recursive:!0,force:!0})}catch{}}}async function k0(J=d){let Z={memoryEntries:P.size,diskEntries:{image:0,video:0},totalSizeMB:0};for(let X of["image","video"]){let $=h(J.directory,X);try{let Y=await uJ($);Z.diskEntries[X]=Y.length;for(let K of Y){let B=h($,K),q=await EZ(B);Z.totalSizeMB+=q.size/1048576}}catch{}}return Z}async function F0(J=d){let Z=0,X=J.maxAge*24*60*60*1000;for(let $ of["image","video"]){let Y=h(J.directory,$);try{let K=await uJ(Y);for(let B of K){let q=h(Y,B);try{let O=await fJ(q,"utf-8"),V=JSON.parse(O);if(Date.now()-V.createdAt>X)await NJ(q),P.delete(V.key),Z++}catch{await NJ(q).catch(()=>{}),Z++}}}catch{}}return Z}var P,d;var lJ=A(()=>{s();P=new Map,d={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:500}});class e{config;constructor(J={}){this.config={...TZ,...J}}async get(J,Z){return mJ(J,Z,"image",this.config)}async set(J,Z,X){return hJ(J,Z,X,"image",this.config)}async clear(){return dJ("image",this.config)}updateConfig(J){this.config={...this.config,...J}}}function QJ(J){if(!t)t=new e(J);else if(J)t.updateConfig(J);return t}async function JJ(J,Z,X){let $=X?{directory:`${X.outputDir}/../.cache`}:{};return QJ($).get(J,Z)}async function ZJ(J,Z,X,$){let Y=$?{directory:`${$.outputDir}/../.cache`}:{};return QJ(Y).set(J,Z,X)}async function nJ(){return QJ().clear()}var TZ,t=null;var jJ=A(()=>{lJ();TZ={enabled:!0,directory:".stx/media-cache",maxAge:30,maxSize:500,cacheVariants:!0,cachePlaceholders:!0}});import{resolve as kZ,basename as FZ,extname as xZ,join as SZ}from"path";import{mkdir as CZ}from"fs/promises";async function _J(){try{return await import("ts-images")}catch{return null}}function cJ(J){switch(J){case"quality":return{jpeg:{quality:90,mozjpeg:!0,progressive:!0},png:{compressionLevel:6,palette:!1},webp:{quality:90,effort:6,smartSubsample:!0},avif:{quality:85,effort:6}};case"performance":return{jpeg:{quality:70,mozjpeg:!0,progressive:!0},png:{compressionLevel:9,palette:!0},webp:{quality:70,effort:4,smartSubsample:!0},avif:{quality:60,effort:2}};case"web":default:return{jpeg:{quality:82,mozjpeg:!0,progressive:!0},png:{compressionLevel:8,palette:!1},webp:{quality:82,effort:5,smartSubsample:!0},avif:{quality:75,effort:4}}}}function PZ(J,Z){let X=Z?cJ(Z):cJ("web"),$=J.formatQuality||{};return{jpeg:{...X.jpeg,...$.jpeg},png:{...X.png,...$.png},webp:{...X.webp,...$.webp},avif:{...X.avif,...$.avif}}}async function pJ(J,Z,X){let $=await _J();if(!$)return console.warn("[stx-media] ts-images not installed, skipping optimization"),{src:J,processed:!1};let Y=await JJ(J,Z,X);if(Y)return Y;try{let K=kZ(J);if(!await y(K))return{src:J,processed:!1,errors:[`Source file not found: ${J}`]};let B=PZ(X,Z.preset),q=X.outputDir||"dist/images",O=X.baseUrl||"/images";await CZ(q,{recursive:!0});let V=await m(K),N=FZ(J,xZ(J)),M=Z.outputFormat?[Z.outputFormat]:X.defaultFormats||["avif","webp","jpeg"],G={src:J,processed:!0,variants:[],hash:V},W=null;if(Z.transformations&&Z.transformations.length>0)W=await RJ(K,Z.transformations,$);for(let H of M){let z=B[H]||{},Q=`${N}-${V}.${H}`,U=SZ(q,Q);try{let j=await $.optimizeImage({input:W||K,output:U,format:H,quality:z.quality,progressive:z.progressive});if(j){if(G.variants.push({path:U,url:`${O}/${Q}`,width:j.width||0,height:j.height||0,format:H,size:j.outputSize||0}),!G.originalWidth&&j.width)G.originalWidth=j.width,G.originalHeight=j.height}}catch(j){G.errors=G.errors||[],G.errors.push(`Failed to optimize ${H}: ${j}`)}}if(Z.embedThumbhash||Z.placeholder==="thumbhash")try{let H=await $.generateThumbHash(K);G.placeholder=H.dataUrl}catch(H){G.errors=G.errors||[],G.errors.push(`Failed to generate thumbhash: ${H}`)}if(Z.useDominantColor)try{let H=await $.generatePlaceholder(K,{strategy:"dominant-color"});G.dominantColor=H.dominantColor}catch(H){G.errors=G.errors||[],G.errors.push(`Failed to extract dominant color: ${H}`)}return await ZJ(J,Z,G,X),G}catch(K){return{src:J,processed:!1,errors:[`Processing failed: ${K}`]}}}async function iJ(J,Z,X,$){let Y=await _J();if(!Y)return{success:!1,error:"ts-images not installed"};try{return{success:!0,size:(await Y.optimizeImage({input:J,output:$,format:Z,quality:X}))?.outputSize}}catch(K){return{success:!1,error:String(K)}}}async function RJ(J,Z,X){let $=X||await _J();if(!$)return console.warn("[stx-media] ts-images not installed, skipping transformations"),null;try{let Y=await $.decode(J);for(let K of Z){let B=K.options||{};switch(K.type){case"resize":if(B.width||B.height)Y=await $.resize(Y,{width:B.width,height:B.height,fit:B.fit});break;case"blur":if(B.sigma!==void 0)Y=await $.blur(Y,B.sigma);break;case"sharpen":if(B.amount!==void 0)Y=await $.sharpen(Y,B.amount);break;case"grayscale":Y=await $.grayscale(Y);break;case"rotate":if(B.angle!==void 0)Y=await $.rotate(Y,B.angle);break;case"flip":Y=await $.flip(Y);break;case"flop":Y=await $.flop(Y);break;case"brightness":if(B.value!==void 0)Y=await $.brightness(Y,B.value);break;case"contrast":if(B.value!==void 0)Y=await $.contrast(Y,B.value);break;case"saturation":if(B.value!==void 0)Y=await $.saturation(Y,B.value);break}}return await $.encode(Y,"png")}catch(Y){return console.error(`[stx-media] Transformation failed: ${Y}`),null}}var oJ=A(()=>{s();jJ()});import{resolve as DZ,basename as AZ,extname as IZ,join as bZ}from"path";import{mkdir as vZ}from"fs/promises";async function yZ(){try{return await import("ts-images")}catch{return null}}async function WJ(J,Z,X){let $=await yZ();if(!$)return console.warn("[stx-media] ts-images not installed, skipping responsive generation"),null;let Y=DZ(J);if(!await y(Y))return console.warn(`[stx-media] Source file not found: ${J}`),null;try{let K=Z.responsiveWidths||X.breakpoints||fZ,B=Z.formats||X.defaultFormats||["avif","webp","jpeg"],q=X.outputDir||"dist/images",O=X.baseUrl||"/images";await vZ(q,{recursive:!0});let V=await m(Y),N=AZ(J,IZ(J)),M=X.formatQuality||{jpeg:{quality:82},png:{quality:80},webp:{quality:82},avif:{quality:75}},G={src:J,byFormat:{},srcsets:{}};for(let H of B){G.byFormat[H]=[];let z=[];for(let Q of K){let U=`${N}-${Q}w-${V}.${H}`,j=bZ(q,U),E=`${O}/${U}`;try{let T=M[H]?.quality||80;if(await y(j)){G.byFormat[H].push({path:j,url:E,width:Q,height:0,format:H,size:0}),z.push(`${E} ${Q}w`);continue}let L=await $.processImage({input:Y,output:j,format:H,quality:T,resize:{width:Q}});if(L)G.byFormat[H].push({path:j,url:E,width:Q,height:L.height||Math.round(Q*(L.height||1)/(L.width||1)),format:H,size:L.outputSize||0}),z.push(`${E} ${Q}w`)}catch(T){console.warn(`[stx-media] Failed to generate ${H} at ${Q}w: ${T}`)}}G.srcsets[H]=z.join(", ")}let W=Z.placeholder||X.placeholderStrategy||"thumbhash";if(W!=="none")try{if(W==="thumbhash"){let H=await $.generateThumbHash(Y);G.placeholder={dataURL:H.dataUrl,width:H.width||32,height:H.height||32,strategy:"thumbhash"}}else{let H=await $.generatePlaceholder(Y,{strategy:W,width:20});G.placeholder={dataURL:H.dataURL,width:H.width,height:H.height,strategy:W}}}catch(H){console.warn(`[stx-media] Failed to generate placeholder: ${H}`)}return G.sizes=Z.sizes||uZ(K),G}catch(K){return console.error(`[stx-media] Responsive generation failed: ${K}`),null}}function uZ(J){let Z=[...J].sort(($,Y)=>$-Y),X=[];for(let $=0;$<Z.length-1;$++){let Y=Z[$];X.push(`(max-width: ${Y}px) ${Y}px`)}return X.push(`${Z[Z.length-1]}px`),X.join(", ")}function aJ(J,Z="width"){if(!J||J.length===0)return"";if(Z==="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 m0(J,Z,X){let $=[];for(let Y of Z){let K=await WJ(Y.src,{responsiveWidths:Y.widths},X);if(K){for(let[B,q]of Object.entries(K.srcsets))if(q)$.push({media:Y.media,srcset:q,type:gZ(B)})}}return $}function gZ(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 fZ;var rJ=A(()=>{s();fZ=[320,480,640,768,1024,1280,1536,1920]});var sJ={};NZ(sJ,{setCachedImageResult:()=>ZJ,processImage:()=>pJ,optimizeImage:()=>iJ,getCachedImageResult:()=>JJ,generateSrcset:()=>aJ,generateResponsiveVariants:()=>WJ,clearImageCache:()=>nJ,applyTransformations:()=>RJ,ImageProcessorCache:()=>e});var tJ=A(()=>{oJ();rJ();jJ()});async function mZ(){try{return await Promise.resolve().then(() => (tJ(),sJ))}catch(J){if(!eJ)console.warn("[stx-media] Image processor not available, some features disabled:",J),eJ=!0;return null}}async function UJ(J,Z={}){let X=Z,$=J;if($.process&&!$.skipOptimization){if(X.tsImagesConfig?.enabled&&!X.isDev)return cZ($,X)}if(X.processedResult?.processed)return wJ(J,X.processedResult,Z);if(X.responsiveVariants)return XZ(J,X.responsiveVariants,Z);let{src:Y,alt:K,width:B,height:q,sizes:O,widths:V=c,dpr:N,formats:M=a,quality:G=zJ,params:W={},placeholder:H="none",placeholderOptions:z={},lazy:Q=!0,priority:U=!1,loading:j=U?"eager":XJ,decoding:E=$J,fetchpriority:T,objectFit:L,objectPosition:f,crossorigin:_,referrerpolicy:I}=J,D=J.class,w=J.style,k=J.id,b=J.data||{},{isDev:x=!1,baseUrl:l=""}=Z;if(x&&!Z.optimize)return lZ(J);let S,R,C=k||`stx-img-${Math.random().toString(36).slice(2,8)}`;if(H!=="none"&&!U)try{S=await AJ(Y,{strategy:H,...z}),R=DJ(C,S,z)}catch{}let i=N!==void 0&&B!==void 0,u;if(i)u=dZ(J,C,S,Z);else u=await hZ(J,C,S,Z);let n;if(U){let TJ=M.includes("webp")?"webp":M[0],KZ=p(Y,V,{...W,q:G},TJ),BZ=typeof O==="object"?qJ(O):O||"100vw";n=`<link rel="preload" as="image" imagesrcset="${KZ}" imagesizes="${BZ}" />`}let o=[];if(!JZ&&H!=="none")o.push(HJ),JZ=!0;if(R)o.push(R);let YZ=Q?$Z(C):void 0;return{html:u,preloadLink:n,css:o.length>0?o.join(`
`):void 0,script:YZ}}async function hZ(J,Z,X,$){let{src:Y,alt:K,width:B,height:q,sizes:O,widths:V=c,formats:N=a,quality:M=zJ,params:G={},lazy:W=!0,priority:H=!1,loading:z=H?"eager":XJ,decoding:Q=$J,fetchpriority:U,objectFit:j,objectPosition:E,crossorigin:T,referrerpolicy:L}=J,f=J.class,_=J.style,I=J.data||{},D=typeof O==="object"?qJ(O):O||"100vw",w=[];for(let x of N){let l=p(Y,V,{...G,q:M},x),S=GJ(x);if(W&&!H)w.push(`  <source type="${S}" data-srcset="${l}" data-sizes="${D}" />`);else w.push(`  <source type="${S}" srcset="${l}" sizes="${D}" />`)}let k=EJ({src:v(Y,{...G,q:M}),alt:K,width:B,height:q,loading:H?void 0:z,decoding:Q,fetchpriority:H?"high":U,objectFit:j,objectPosition:E,crossorigin:T,referrerpolicy:L,className:ZZ(f,X),style:LJ(_,j,E,X),lazy:W&&!H,data:I}),b;if(X){let x=`background-image: url('${X.dataURL}'); background-size: cover; background-position: center;`;b=`<div id="${Z}" class="stx-img-placeholder" style="${x}">
  <picture>
${w.join(`
`)}
    <img ${k} />
  </picture>
</div>`}else b=`<picture${Z?` id="${Z}"`:""}>
${w.join(`
`)}
  <img ${k} />
</picture>`;return b}function dZ(J,Z,X,$){let{src:Y,alt:K,width:B,height:q,dpr:O=[1,2,3],quality:V=zJ,params:N={},lazy:M=!0,priority:G=!1,loading:W=G?"eager":XJ,decoding:H=$J,fetchpriority:z,objectFit:Q,objectPosition:U,crossorigin:j,referrerpolicy:E}=J,T=J.class,L=J.style,f=J.data||{},_=typeof B==="number"?B:Number.parseInt(String(B),10),I=BJ(Y,_,O,{...N,q:V}),D=EJ({src:v(Y,{...N,w:_,q:V}),alt:K,width:B,height:q,loading:G?void 0:W,decoding:H,fetchpriority:G?"high":z,objectFit:Q,objectPosition:U,crossorigin:j,referrerpolicy:E,className:ZZ(T,X),style:LJ(L,Q,U,X),lazy:M&&!G,data:f}),w=M&&!G?`data-srcset="${I}"`:`srcset="${I}"`;if(X){let k=`background-image: url('${X.dataURL}'); background-size: cover; background-position: center;`;return`<div id="${Z}" class="stx-img-placeholder" style="${k}">
  <img ${D} ${w} />
</div>`}return`<img ${Z?`id="${Z}" `:""}${D} ${w} />`}function lZ(J){let{src:Z,alt:X,width:$,height:Y,loading:K=XJ,decoding:B=$J,fetchpriority:q,objectFit:O,objectPosition:V,crossorigin:N,referrerpolicy:M,priority:G=!1}=J,W=J.class,H=J.style,z=J.id,Q=J.data||{};return{html:`<img ${EJ({src:Z,alt:X,width:$,height:Y,loading:G?"eager":K,decoding:B,fetchpriority:G?"high":q,objectFit:O,objectPosition:V,crossorigin:N,referrerpolicy:M,className:W,style:LJ(H,O,V),id:z,data:Q})} />`}}function EJ(J){let Z=[];if(J.lazy)Z.push(`data-src="${F(J.src)}"`),Z.push('src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"');else Z.push(`src="${F(J.src)}"`);if(Z.push(`alt="${F(J.alt)}"`),J.width)Z.push(`width="${J.width}"`);if(J.height)Z.push(`height="${J.height}"`);if(J.loading)Z.push(`loading="${J.loading}"`);if(J.decoding)Z.push(`decoding="${J.decoding}"`);if(J.fetchpriority)Z.push(`fetchpriority="${J.fetchpriority}"`);if(J.crossorigin)Z.push(`crossorigin="${J.crossorigin}"`);if(J.referrerpolicy)Z.push(`referrerpolicy="${J.referrerpolicy}"`);if(J.className)Z.push(`class="${F(J.className)}"`);if(J.style)Z.push(`style="${F(J.style)}"`);if(J.id)Z.push(`id="${F(J.id)}"`);if(J.data)for(let[X,$]of Object.entries(J.data))Z.push(`data-${X}="${F($)}"`);if(J.lazy)Z.push("data-stx-lazy");return Z.join(" ")}function ZZ(J,Z){let X=[];if(J)X.push(J);if(Z)X.push("stx-img-blur");return X.join(" ")||""}function LJ(J,Z,X,$){let Y=[];if(Z)Y.push(`object-fit: ${Z}`);if(X)Y.push(`object-position: ${X}`);if($)Y.push("opacity: 0; transition: opacity 300ms ease-out");if(J)Y.push(J);return Y.join("; ")}function F(J){return J.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#039;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function $Z(J){return`
(function() {
  const container = document.getElementById('${J}');
  if (!container) return;

  const img = container.querySelector('img[data-stx-lazy]') || container;
  if (!img.dataset.src && !img.dataset.srcset) return;

  const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        // Load image
        if (img.dataset.src) img.src = img.dataset.src;
        if (img.dataset.srcset) img.srcset = img.dataset.srcset;

        // Load sources
        const sources = container.querySelectorAll('source[data-srcset]');
        sources.forEach(source => {
          if (source.dataset.srcset) source.srcset = source.dataset.srcset;
          if (source.dataset.sizes) source.sizes = source.dataset.sizes;
        });

        // Handle load completion
        img.onload = () => {
          img.style.opacity = '1';
          if (container.classList.contains('stx-img-placeholder')) {
            container.classList.add('stx-img-loaded');
          }
        };

        observer.disconnect();
      }
    });
  }, { rootMargin: '50px' });

  observer.observe(container);
})();
`.trim()}function nZ(J){let Z=J.match(/<Img\s+([^>]*?)\/?>/);if(!Z)return null;let X=Z[1],$={},Y=/(:?)(\w+)(?:=(?:"([^"]*)"|'([^']*)'|\{([^}]+)\}))?/g,K;while((K=Y.exec(X))!==null){let[,B,q,O,V,N]=K,M=O??V??N??!0;if(B===":"&&typeof M==="string")try{$[q]=JSON.parse(M)}catch{$[q]=M}else switch(q){case"src":$.src=String(M);break;case"alt":$.alt=String(M);break;case"width":$.width=Number(M)||M;break;case"height":$.height=Number(M)||M;break;case"sizes":$.sizes=String(M);break;case"quality":$.quality=Number(M);break;case"placeholder":$.placeholder=M;break;case"lazy":$.lazy=M===!0||M==="true";break;case"priority":$.priority=M===!0||M==="true";break;case"class":$.class=String(M);break;case"style":$.style=String(M);break;case"id":$.id=String(M);break;case"loading":$.loading=M;break;case"decoding":$.decoding=M;break;case"fetchpriority":$.fetchpriority=M;break;case"objectFit":$.objectFit=M;break;case"objectPosition":$.objectPosition=String(M);break;case"crossorigin":$.crossorigin=M;break}}if(!$.src||!$.alt)return null;return $}async function i0(J,Z={}){let X=/<Img\s+[^>]*?\/?>/g,$=[],Y=[],K=[],B=J,q=[],O;while((O=X.exec(J))!==null)q.push({match:O[0],index:O.index});for(let V=q.length-1;V>=0;V--){let{match:N}=q[V],M=nZ(N);if(M){let G=await UJ(M,Z);if(B=B.replace(N,G.html),G.preloadLink)$.push(G.preloadLink);if(G.css)Y.push(G.css);if(G.script)K.push(G.script)}}return{html:B,preloadLinks:$,styles:Y,scripts:K}}async function cZ(J,Z){let X=await mZ();if(!X)return UJ({...J,process:!1},Z);let $=Z.tsImagesConfig;if(J.responsiveWidths&&J.responsiveWidths.length>0||J.widths&&J.widths.length>0||!J.width&&!J.dpr){let K=await X.generateResponsiveVariants(J.src,J,$);if(K)return XZ(J,K,Z)}else{let K=await X.processImage(J.src,J,$);if(K.processed)return wJ(J,K,Z)}return UJ({...J,process:!1},Z)}async function wJ(J,Z,X){let{alt:$,width:Y,height:K,lazy:B=!0,priority:q=!1,objectFit:O,objectPosition:V,crossorigin:N,referrerpolicy:M}=J,G=J.class,W=J.style,H=J.id||`stx-img-${Math.random().toString(36).slice(2,8)}`,z=J.data||{},Q=Z.variants||[],U=Q.find((R)=>R.format==="jpeg")||Q.find((R)=>R.format==="webp")||Q[0],j=U?.url||J.src,E=Q.filter((R)=>R.format===(U?.format||"jpeg")).map((R)=>`${R.url} ${R.width}w`).join(", "),T=new Map;for(let R of Q){if(!T.has(R.format))T.set(R.format,[]);T.get(R.format).push(R)}let L=[],f=["avif","webp","jpeg","png"];for(let R of f){let C=T.get(R);if(C&&C.length>0){let i=C.map((n)=>`${n.url} ${n.width}w`).join(", "),u=GJ(R);if(B&&!q)L.push(`  <source type="${u}" data-srcset="${i}" />`);else L.push(`  <source type="${u}" srcset="${i}" />`)}}let _=[];if(B&&!q){if(_.push(`data-src="${F(j)}"`),_.push('src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"'),E)_.push(`data-srcset="${E}"`)}else if(_.push(`src="${F(j)}"`),E)_.push(`srcset="${E}"`);_.push(`alt="${F($)}"`);let I=Y||Z.originalWidth,D=K||Z.originalHeight;if(I)_.push(`width="${I}"`);if(D)_.push(`height="${D}"`);if(!q)_.push(`loading="${B?"lazy":"eager"}"`);if(_.push('decoding="async"'),q)_.push('fetchpriority="high"');if(N)_.push(`crossorigin="${N}"`);if(M)_.push(`referrerpolicy="${M}"`);let w=[];if(O)w.push(`object-fit: ${O}`);if(V)w.push(`object-position: ${V}`);if(Z.placeholder&&B)w.push("opacity: 0; transition: opacity 300ms ease-out");if(W)w.push(W);if(w.length>0)_.push(`style="${w.join("; ")}"`);let k=[];if(G)k.push(G);if(Z.placeholder)k.push("stx-img-blur");if(k.length>0)_.push(`class="${k.join(" ")}"`);if(B&&!q)_.push("data-stx-lazy");for(let[R,C]of Object.entries(z))_.push(`data-${R}="${F(C)}"`);let b;if(Z.placeholder||Z.dominantColor&&J.useDominantColor){let R=Z.placeholder?`background-image: url('${Z.placeholder}'); background-size: cover; background-position: center;`:`background-color: ${Z.dominantColor};`;b=`<div id="${H}" class="stx-img-placeholder" style="${R}">
  <picture>
${L.join(`
`)}
    <img ${_.join(" ")} />
  </picture>
</div>`}else b=`<picture${H?` id="${H}"`:""}>
${L.join(`
`)}
  <img ${_.join(" ")} />
</picture>`;let x=[];if(Z.placeholder)x.push(HJ);let l=B?$Z(H):void 0,S;if(q&&E)S=`<link rel="preload" as="image" imagesrcset="${E}" />`;return{html:b,preloadLink:S,css:x.length>0?x.join(`
`):void 0,script:l}}async function XZ(J,Z,X){let $={src:Z.src,processed:!0,variants:[],placeholder:Z.placeholder?.dataURL,originalWidth:Z.placeholder?.width,originalHeight:Z.placeholder?.height};for(let[Y,K]of Object.entries(Z.byFormat))if(K)$.variants.push(...K);return wJ(J,$,X)}var eJ=!1,zJ=80,$J="async",XJ="lazy",JZ=!1;var pZ=A(()=>{SJ();IJ()});pZ();export{UJ as renderImgComponent,i0 as processImgComponents,nZ as parseImgComponent};
