// @bun
var{defineProperty:X,getOwnPropertyNames:G,getOwnPropertyDescriptor:H}=Object,S=Object.prototype.hasOwnProperty;function v(j){return this[j]}var u=(j)=>{var f=($??=new WeakMap).get(j),x;if(f)return f;if(f=X({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var z of G(j))if(!S.call(f,z))X(f,z,{get:v.bind(j,z),enumerable:!(x=H(j,z))||x.enumerable})}return $.set(j,f),f},$;var E=(j)=>j;function F(j,f){this[j]=E.bind(null,f)}var w=(j,f)=>{for(var x in f)X(j,x,{get:f[x],enumerable:!0,configurable:!0,set:F.bind(f,x)})};var K=(j,f)=>()=>(j&&(f=j(j=0)),f);var O=import.meta.require;async function Y(){try{return await import("ts-images")}catch{return null}}async function N(j,f={}){let x={...b,...f},z=await Y();if(z)try{return await L(j,x,z)}catch(J){console.warn(`[stx-media] ts-images placeholder generation failed, using fallback: ${J}`)}return R(j,x)}async function L(j,f,x){let{generatePlaceholder:z,generateThumbHash:J}=x,M={blur:"blur",thumbhash:"thumbhash",blurhash:"thumbhash",pixelate:"pixelate","dominant-color":"dominant-color",none:"blur"}[f.strategy]||"blur";if(f.strategy==="thumbhash")return{dataURL:(await J(j)).dataUrl,width:32,height:32,aspectRatio:1,originalWidth:0,originalHeight:0,strategy:"thumbhash"};let B=await z(j,{width:f.width,height:f.height,quality:f.quality,blurLevel:f.blurLevel,strategy:M,base64Encode:!0});return{dataURL:B.dataURL,width:B.width,height:B.height,aspectRatio:B.aspectRatio,originalWidth:B.originalWidth,originalHeight:B.originalHeight,strategy:f.strategy,dominantColor:B.dominantColor,css:B.css}}function R(j,f){let x=f.width||20,z=f.height||x,J="#e5e7eb",V=`<svg xmlns="http://www.w3.org/2000/svg" width="${x}" height="${z}" viewBox="0 0 ${x} ${z}"><rect fill="#e5e7eb" width="${x}" height="${z}"/></svg>`;return{dataURL:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(V)}`,width:x,height:z,aspectRatio:x/z,originalWidth:0,originalHeight:0,strategy:f.strategy,dominantColor:"#e5e7eb"}}async function g(j){let f=await Y();if(f)try{return(await f.generateThumbHash(j)).dataUrl}catch{}return(await R(j,{strategy:"thumbhash",width:32,height:32})).dataURL}function n(j){let f=j[0]|j[1]<<8|j[2]<<16,x=(f&63)/63,z=(f>>6&63)/31.5-1,J=(f>>12&63)/31.5-1,V=(f>>18&31)/31,M=f>>23!==0,B=j[3]|j[4]<<8,U=(B>>3&63)/63,A=(B>>9&63)/63,Z=B>>15!==0,P=Math.max(3,Z?M?5:7:M?5:7),T=Math.max(3,Z?M?5:7:M?5:7),_=32,C=32,W=Math.max(0,Math.min(255,Math.round((x+z)*255))),k=Math.max(0,Math.min(255,Math.round(x*255))),q=Math.max(0,Math.min(255,Math.round((x-z)*255))),D=`<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32">
    <rect fill="rgb(${W},${k},${q})" width="32" height="32"/>
  </svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(D)}`}async function d(j,f=20,x=50){return N(j,{strategy:"blur",width:f,quality:x,blurLevel:40})}async function p(j){let f=await Y();if(f)try{return(await f.generatePlaceholder(j,{strategy:"dominant-color"})).dominantColor||"#e5e7eb"}catch{}return"#e5e7eb"}function l(j,f=1,x=1){let z=`<svg xmlns="http://www.w3.org/2000/svg" width="${f}" height="${x}"><rect fill="${j}" width="${f}" height="${x}"/></svg>`;return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(z)}`}function c(j,f,x={}){let z=x.transitionDuration||300,J=x.easing||"ease-out";return`
#${j} {
  --stx-img-transition-duration: ${z}ms;
  --stx-img-transition-easing: ${J};
  background-image: url('${f.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 i(j){return`background-image: url('${j.dataURL}'); background-size: cover; background-position: center;`}async function r(j,f={}){let x=`${j}:${JSON.stringify(f)}`;if(Q.has(x))return Q.get(x);let z=await N(j,f);return Q.set(x,z),z}function o(){Q.clear()}function a(){return{size:Q.size,keys:Array.from(Q.keys())}}var b,m,Q;var y=K(()=>{b={strategy:"thumbhash",width:20,quality:50,blurLevel:40,transitionDuration:300,easing:"ease-out"},m=`
.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();Q=new Map});y();export{a as getPlaceholderCacheStats,r as getCachedPlaceholder,g as generateThumbhashPlaceholder,i as generatePlaceholderStyle,c as generatePlaceholderCSS,N as generatePlaceholder,d as generateLQIP,l as generateColorPlaceholder,p as extractDominantColor,n as decodeThumbhash,o as clearPlaceholderCache,b as DEFAULT_PLACEHOLDER_OPTIONS,m as BLUR_UP_CSS};
