// @bun
var{defineProperty:A,getOwnPropertyNames:t,getOwnPropertyDescriptor:r}=Object,i=Object.prototype.hasOwnProperty;function o(J){return this[J]}var IJ=(J)=>{var K=(u??=new WeakMap).get(J),W;if(K)return K;if(K=A({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function"){for(var Q of t(J))if(!i.call(K,Q))A(K,Q,{get:o.bind(J,Q),enumerable:!(W=r(J,Q))||W.enumerable})}return u.set(J,K),K},u;var e=(J)=>J;function JJ(J,K){this[J]=e.bind(null,K)}var kJ=(J,K)=>{for(var W in K)A(J,W,{get:K[W],enumerable:!0,configurable:!0,set:JJ.bind(K,W)})};var _=(J,K)=>()=>(J&&(K=J(J=0)),K);var PJ=import.meta.require;function g(){return"loading"in HTMLImageElement.prototype}function f(){return"IntersectionObserver"in window}function KJ(J={}){let K={...v,...J},W=document.querySelectorAll(K.selector);if(W.length===0)return()=>{};if(K.useNative&&g())return W.forEach((X)=>{if(X.tagName==="IMG"||X.tagName==="IFRAME")B(X,K)}),()=>{};if(!f())return W.forEach((X)=>B(X,K)),()=>{};let Q=new IntersectionObserver((X)=>{X.forEach((M)=>{if(M.isIntersecting){let Z=M.target;B(Z,K),Q.unobserve(Z)}})},{root:K.root,rootMargin:K.rootMargin,threshold:K.threshold});return W.forEach((X)=>Q.observe(X)),()=>{Q.disconnect()}}function B(J,K={}){let{onLoad:W,onLoaded:Q,onError:X}=K;if(W)W(J);let M=J.tagName==="IMG",Z=J.tagName==="VIDEO",$=J.tagName==="IFRAME";if(M)c(J,Q,X);else if(Z)h(J,Q,X);else if($)QJ(J,Q,X);else{let H=J.querySelector("img[data-src], img[data-srcset]"),Y=J.querySelector("video[data-src]");if(H)c(H,()=>{if(Q)Q(J)},(q)=>{if(X)X(J,q)});else if(Y)h(Y,()=>{if(Q)Q(J)},(q)=>{if(X)X(J,q)});J.querySelectorAll("source[data-srcset]").forEach((q)=>{let V=q;if(V.dataset.srcset)V.srcset=V.dataset.srcset,delete V.dataset.srcset;if(V.dataset.sizes)V.sizes=V.dataset.sizes,delete V.dataset.sizes})}}function c(J,K,W){let Q=()=>{J.classList.add("stx-img-loaded"),J.style.opacity="1";let M=J.closest(".stx-img-placeholder");if(M)M.classList.add("stx-img-loaded");if(K)K(J)},X=()=>{if(J.classList.add("stx-img-error"),W)W(J,Error(`Failed to load image: ${J.src}`))};if(J.addEventListener("load",Q,{once:!0}),J.addEventListener("error",X,{once:!0}),J.dataset.srcset)J.srcset=J.dataset.srcset,delete J.dataset.srcset;if(J.dataset.src)J.src=J.dataset.src,delete J.dataset.src;if(J.dataset.sizes)J.sizes=J.dataset.sizes,delete J.dataset.sizes}function h(J,K,W){let Q=()=>{if(J.classList.add("stx-video-loaded"),K)K(J)},X=()=>{if(J.classList.add("stx-video-error"),W)W(J,Error(`Failed to load video: ${J.src}`))};if(J.addEventListener("loadeddata",Q,{once:!0}),J.addEventListener("error",X,{once:!0}),J.querySelectorAll("source[data-src]").forEach((Z)=>{let $=Z;if($.dataset.src)$.src=$.dataset.src,delete $.dataset.src}),J.dataset.src)J.src=J.dataset.src,delete J.dataset.src;if(J.dataset.poster)J.poster=J.dataset.poster,delete J.dataset.poster;J.load()}function QJ(J,K,W){let Q=()=>{if(J.classList.add("stx-iframe-loaded"),K)K(J)},X=()=>{if(J.classList.add("stx-iframe-error"),W)W(J,Error(`Failed to load iframe: ${J.src}`))};if(J.addEventListener("load",Q,{once:!0}),J.addEventListener("error",X,{once:!0}),J.dataset.src)J.src=J.dataset.src,delete J.dataset.src}function WJ(J){B(J,{})}function XJ(J="[data-stx-lazy]"){document.querySelectorAll(J).forEach((W)=>B(W,{}))}function YJ(J={}){let K={...v,...J};return new IntersectionObserver((W,Q)=>{W.forEach((X)=>{if(X.isIntersecting)B(X.target,K),Q.unobserve(X.target)})},{root:K.root,rootMargin:K.rootMargin,threshold:K.threshold})}function ZJ(J,K){J.observe(K)}function $J(J){J.disconnect()}function C(){return`
(function() {
  'use strict';

  if (typeof window === 'undefined') return;

  var defaultOptions = {
    root: null,
    rootMargin: '50px 0px',
    threshold: 0
  };

  function isNativeLazySupported() {
    return 'loading' in HTMLImageElement.prototype;
  }

  function loadElement(el) {
    var img = el.tagName === 'IMG' ? el : el.querySelector('img[data-src], img[data-srcset]');
    var video = el.tagName === 'VIDEO' ? el : el.querySelector('video[data-src]');

    // Load sources in picture elements
    var sources = el.querySelectorAll('source[data-srcset]');
    sources.forEach(function(source) {
      if (source.dataset.srcset) {
        source.srcset = source.dataset.srcset;
        delete source.dataset.srcset;
      }
      if (source.dataset.sizes) {
        source.sizes = source.dataset.sizes;
        delete source.dataset.sizes;
      }
    });

    if (img) {
      img.onload = function() {
        img.style.opacity = '1';
        img.classList.add('stx-img-loaded');
        var wrapper = img.closest('.stx-img-placeholder');
        if (wrapper) wrapper.classList.add('stx-img-loaded');
      };
      if (img.dataset.srcset) { img.srcset = img.dataset.srcset; delete img.dataset.srcset; }
      if (img.dataset.src) { img.src = img.dataset.src; delete img.dataset.src; }
      if (img.dataset.sizes) { img.sizes = img.dataset.sizes; delete img.dataset.sizes; }
    }

    if (video) {
      var videoSources = video.querySelectorAll('source[data-src]');
      videoSources.forEach(function(source) {
        if (source.dataset.src) { source.src = source.dataset.src; delete source.dataset.src; }
      });
      if (video.dataset.src) { video.src = video.dataset.src; delete video.dataset.src; }
      if (video.dataset.poster) { video.poster = video.dataset.poster; delete video.dataset.poster; }
      video.load();
    }
  }

  function init() {
    var elements = document.querySelectorAll('[data-stx-lazy]');
    if (!elements.length) return;

    if (!('IntersectionObserver' in window)) {
      elements.forEach(loadElement);
      return;
    }

    var observer = new IntersectionObserver(function(entries) {
      entries.forEach(function(entry) {
        if (entry.isIntersecting) {
          loadElement(entry.target);
          observer.unobserve(entry.target);
        }
      });
    }, defaultOptions);

    elements.forEach(function(el) { observer.observe(el); });
  }

  // Initialize when DOM is ready
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  }
else {
    init();
  }

  // Expose for manual use
  window.STX = window.STX || {};
  window.STX.lazyLoad = loadElement;
  window.STX.initLazyLoading = init;
})();
`.trim()}var v;var T=_(()=>{v={root:null,rootMargin:"50px 0px",threshold:0,useNative:!0,selector:"[data-stx-lazy]"}});function d(J,K={}){let W={...MJ,...K},Q=J.closest(".stx-img-placeholder");if(!Q){HJ(J,W);return}if(Q.style.setProperty("--stx-img-transition-duration",`${W.duration}ms`),Q.style.setProperty("--stx-img-transition-easing",W.easing),W.loadingClass)Q.classList.add(W.loadingClass);if(J.complete&&J.naturalWidth>0)p(J,Q,W);else J.addEventListener("load",()=>p(J,Q,W),{once:!0}),J.addEventListener("error",()=>qJ(J,Q,W),{once:!0})}function HJ(J,K){let W=()=>{J.style.transition=`opacity ${K.duration}ms ${K.easing}`,J.style.opacity="1",J.classList.remove(K.loadingClass),J.classList.add(K.loadedClass)};if(J.complete&&J.naturalWidth>0)W();else J.style.opacity="0",J.classList.add(K.loadingClass),J.addEventListener("load",W,{once:!0})}function p(J,K,W){if(W.loadingClass)K.classList.remove(W.loadingClass);if(W.loadedClass)K.classList.add(W.loadedClass);if(J.style.opacity="1",W.removePlaceholder)setTimeout(()=>{K.style.backgroundImage="none"},W.duration)}function qJ(J,K,W){if(W.loadingClass)K.classList.remove(W.loadingClass);K.classList.add("stx-img-error"),J.classList.add("stx-img-error")}function VJ(J,K){let W=j(J),Q=K.getContext("2d");if(!Q)return;K.width=W.w,K.height=W.h;let X=Q.createImageData(W.w,W.h);X.data.set(W.rgba),Q.putImageData(X,0,0)}function j(J){let K=J[0]|J[1]<<8|J[2]<<16,W=(K&63)/63,Q=(K>>6&63)/31.5-1,X=(K>>12&63)/31.5-1,M=(K>>18&31)/31,Z=K>>23!==0,$=J[3]|J[4]<<8,H=($>>3&63)/63,Y=($>>9&63)/63,G=$>>15!==0,q=Math.max(3,G?Z?5:7:Z?5:5),V=Math.max(3,G?Z?5:5:Z?5:7),N=32,w=32,F=new Uint8ClampedArray(4096);for(let R=0;R<32;R++)for(let U=0;U<32;U++){let O=(R*32+U)*4,S=U/31,y=R/31,L=W+(S-0.5)*M*0.5+(y-0.5)*M*0.5,n=Q*(1-S*0.3),x=X*(1-y*0.3),E=L-0.6666666666666666*n,b=(3*L-E+x)/2,a=b-x;F[O]=Math.max(0,Math.min(255,Math.round(b*255))),F[O+1]=Math.max(0,Math.min(255,Math.round(a*255))),F[O+2]=Math.max(0,Math.min(255,Math.round(E*255))),F[O+3]=255}return{w:32,h:32,rgba:F}}function GJ(J){let K=j(J),W=document.createElement("canvas");W.width=K.w,W.height=K.h;let Q=W.getContext("2d");if(!Q)return"";let X=Q.createImageData(K.w,K.h);return X.data.set(K.rgba),Q.putImageData(X,0,0),W.toDataURL("image/png")}function NJ(J){let K=atob(J),W=new Uint8Array(K.length);for(let Q=0;Q<K.length;Q++)W[Q]=K.charCodeAt(Q);return W}function FJ(J,K,W=300){return new Promise((Q)=>{J.style.transition=`opacity ${W}ms ease-out`,K.style.transition=`opacity ${W}ms ease-out`,K.style.opacity="0",K.offsetWidth,J.style.opacity="0",K.style.opacity="1",setTimeout(Q,W)})}function BJ(J={}){document.querySelectorAll("[data-stx-blur-up], .stx-img-placeholder img").forEach((W)=>{d(W,J)})}function I(){return`
(function() {
  'use strict';

  if (typeof window === 'undefined') return;

  var defaultOptions = {
    duration: 300,
    easing: 'ease-out',
    loadedClass: 'stx-img-loaded'
  };

  function initBlurUp(img, options) {
    options = Object.assign({}, defaultOptions, options);
    var wrapper = img.closest('.stx-img-placeholder');

    if (!wrapper) {
      if (img.complete && img.naturalWidth > 0) {
        img.style.opacity = '1';
      }
else {
        img.style.opacity = '0';
        img.style.transition = 'opacity ' + options.duration + 'ms ' + options.easing;
        img.onload = function() { img.style.opacity = '1'; };
      }
      return;
    }

    wrapper.style.setProperty('--stx-img-transition-duration', options.duration + 'ms');
    wrapper.style.setProperty('--stx-img-transition-easing', options.easing);

    var onLoaded = function() {
      wrapper.classList.add(options.loadedClass);
      img.style.opacity = '1';
    };

    if (img.complete && img.naturalWidth > 0) {
      onLoaded();
    }
else {
      img.addEventListener('load', onLoaded, { once: true });
    }
  }

  function init() {
    var elements = document.querySelectorAll('.stx-img-placeholder img, [data-stx-blur-up]');
    elements.forEach(function(img) { initBlurUp(img); });
  }

  // Initialize when DOM is ready
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  }
else {
    init();
  }

  // Expose for manual use
  window.STX = window.STX || {};
  window.STX.initBlurUp = initBlurUp;
  window.STX.initAllBlurUp = init;
})();
`.trim()}function k(){return`
.stx-img-placeholder {
  position: relative;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.stx-img-placeholder img {
  display: block;
  width: 100%;
  height: auto;
  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,
.stx-img-blur.stx-img-loaded {
  filter: blur(0);
  transform: scale(1);
}

.stx-img-error {
  opacity: 0.5;
}
`.trim()}var MJ;var P=_(()=>{MJ={duration:300,easing:"ease-out",removePlaceholder:!1,loadedClass:"stx-img-loaded",loadingClass:"stx-img-loading"}});function l(J,K={}){if(K.maxSize&&J.size>K.maxSize)return{valid:!1,error:`File size (${m(J.size)}) exceeds maximum (${m(K.maxSize)})`,code:"FILE_TOO_LARGE"};if(K.accept&&K.accept.length>0){if(!K.accept.some((Q)=>{if(Q.endsWith("/*")){let X=Q.slice(0,-1);return J.type.startsWith(X)}return J.type===Q}))return{valid:!1,error:`File type "${J.type}" is not allowed`,code:"INVALID_TYPE"}}return{valid:!0}}function m(J){if(J<1024)return`${J} B`;if(J<1048576)return`${(J/1024).toFixed(1)} KB`;return`${(J/1048576).toFixed(2)} MB`}async function s(J,K,W){let Q={...RJ,...K},X=l(J,Q);if(!X.valid)return{success:!1,error:X.error,name:J.name,size:J.size,type:J.type};if(Q.chunkSize&&J.size>Q.chunkSize)return OJ(J,Q,W);return UJ(J,Q,W)}async function UJ(J,K,W){return new Promise((Q)=>{let X=new XMLHttpRequest,M=Date.now(),Z=0,$=M;X.upload.addEventListener("progress",(Y)=>{if(Y.lengthComputable&&W){let G=Date.now(),q=(G-$)/1000,V=Y.loaded-Z,N=q>0?V/q:0,w=Y.total-Y.loaded,F=N>0?w/N*1000:void 0;Z=Y.loaded,$=G,W({file:J,loaded:Y.loaded,total:Y.total,percent:Math.round(Y.loaded/Y.total*100),speed:N,timeRemaining:F})}}),X.addEventListener("load",()=>{if(X.status>=200&&X.status<300)try{let Y=JSON.parse(X.responseText);Q({success:!0,url:Y.url,id:Y.id,name:J.name,size:J.size,type:J.type,data:Y})}catch{Q({success:!0,name:J.name,size:J.size,type:J.type})}else Q({success:!1,error:`Upload failed with status ${X.status}`,name:J.name,size:J.size,type:J.type})}),X.addEventListener("error",()=>{Q({success:!1,error:"Network error during upload",name:J.name,size:J.size,type:J.type})}),X.addEventListener("timeout",()=>{Q({success:!1,error:"Upload timed out",name:J.name,size:J.size,type:J.type})});let H=new FormData;if(H.append(K.fieldName||"file",J),K.formData)for(let[Y,G]of Object.entries(K.formData))H.append(Y,G);if(X.open(K.method||"POST",K.endpoint),X.timeout=K.timeout||60000,X.withCredentials=K.withCredentials||!1,K.headers)for(let[Y,G]of Object.entries(K.headers))X.setRequestHeader(Y,G);X.send(H)})}async function OJ(J,K,W){let Q=K.chunkSize,X=Math.ceil(J.size/Q),M=0,Z;for(let $=0;$<X;$++){let H=$*Q,Y=Math.min(H+Q,J.size),G=J.slice(H,Y),q=new FormData;if(q.append(K.fieldName||"file",G,J.name),q.append("chunk",String($)),q.append("totalChunks",String(X)),q.append("fileName",J.name),q.append("fileSize",String(J.size)),q.append("fileType",J.type),Z)q.append("uploadId",Z);if(K.formData)for(let[V,N]of Object.entries(K.formData))q.append(V,N);try{let V=await fetch(K.endpoint,{method:K.method||"POST",headers:K.headers,credentials:K.withCredentials?"include":"same-origin",body:q});if(!V.ok)return{success:!1,error:`Chunk ${$+1}/${X} failed with status ${V.status}`,name:J.name,size:J.size,type:J.type};let N=await V.json();if(!Z&&N.uploadId)Z=N.uploadId;if(M=Y,W)W({file:J,loaded:M,total:J.size,percent:Math.round(M/J.size*100),chunk:$+1,totalChunks:X});if($===X-1)return{success:!0,url:N.url,id:N.id||Z,name:J.name,size:J.size,type:J.type,data:N}}catch(V){return{success:!1,error:`Chunk upload failed: ${V}`,name:J.name,size:J.size,type:J.type}}}return{success:!1,error:"Unknown error during chunked upload",name:J.name,size:J.size,type:J.type}}async function _J(J,K,W,Q){let X=[];for(let M of J){let Z=await s(M,K,($)=>{if(W)W(M,$)});if(X.push(Z),Q)Q(M,Z)}return X}function AJ(J,K=200){return new Promise((W,Q)=>{if(!J.type.startsWith("image/")){Q(Error("File is not an image"));return}let X=new FileReader;X.onload=(M)=>{let Z=new Image;Z.onload=()=>{let $=document.createElement("canvas"),H=Z.width,Y=Z.height;if(H>K||Y>K)if(H>Y)Y=Math.round(Y*K/H),H=K;else H=Math.round(H*K/Y),Y=K;$.width=H,$.height=Y;let G=$.getContext("2d");if(G)G.drawImage(Z,0,0,H,Y),W($.toDataURL("image/jpeg",0.7));else Q(Error("Could not get canvas context"))},Z.onerror=()=>Q(Error("Could not load image")),Z.src=M.target?.result},X.onerror=()=>Q(Error("Could not read file")),X.readAsDataURL(J)})}function CJ(J){return new Promise((K,W)=>{if(!J.type.startsWith("video/")){W(Error("File is not a video"));return}let Q=document.createElement("video"),X=document.createElement("canvas");Q.preload="metadata",Q.muted=!0,Q.playsInline=!0,Q.onloadeddata=()=>{Q.currentTime=0.1},Q.onseeked=()=>{X.width=Q.videoWidth,X.height=Q.videoHeight;let M=X.getContext("2d");if(M)M.drawImage(Q,0,0),K(X.toDataURL("image/jpeg",0.7));else W(Error("Could not get canvas context"));URL.revokeObjectURL(Q.src)},Q.onerror=()=>{URL.revokeObjectURL(Q.src),W(Error("Could not load video"))},Q.src=URL.createObjectURL(J)})}function D(){return`
(function() {
  'use strict';

  if (typeof window === 'undefined') return;

  window.STX = window.STX || {};

  window.STX.uploadFile = function(file, options, onProgress) {
    return new Promise(function(resolve) {
      var xhr = new XMLHttpRequest();

      xhr.upload.addEventListener('progress', function(e) {
        if (e.lengthComputable && onProgress) {
          onProgress({
            file: file,
            loaded: e.loaded,
            total: e.total,
            percent: Math.round((e.loaded / e.total) * 100)
          });
        }
      });

      xhr.addEventListener('load', function() {
        if (xhr.status >= 200 && xhr.status < 300) {
          try {
            var data = JSON.parse(xhr.responseText);
            resolve({ success: true, url: data.url, id: data.id, data: data });
          }
catch (e) {
            resolve({ success: true });
          }
        }
else {
          resolve({ success: false, error: 'Upload failed: ' + xhr.status });
        }
      });

      xhr.addEventListener('error', function() {
        resolve({ success: false, error: 'Network error' });
      });

      var formData = new FormData();
      formData.append(options.fieldName || 'file', file);

      xhr.open(options.method || 'POST', options.endpoint);
      if (options.headers) {
        for (var key in options.headers) {
          xhr.setRequestHeader(key, options.headers[key]);
        }
      }
      xhr.send(formData);
    });
  };

  window.STX.validateFile = function(file, options) {
    if (options.maxSize && file.size > options.maxSize) {
      return { valid: false, error: 'File too large' };
    }
    if (options.accept && options.accept.length) {
      var valid = options.accept.some(function(type) {
        return type.endsWith('/*') ? file.type.startsWith(type.slice(0, -1)) : file.type === type;
      });
      if (!valid) return { valid: false, error: 'Invalid file type' };
    }
    return { valid: true };
  };
})();
`.trim()}var RJ;var z=_(()=>{RJ={method:"POST",fieldName:"file",timeout:60000,withCredentials:!1}});function TJ(){return{script:[C(),I(),D()].join(`

`),css:k()}}function EJ(){let{script:J,css:K}=TJ(),W=J.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"").replace(/\s+/g," ").replace(/\s*([{};,:])\s*/g,"$1").trim(),Q=K.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").replace(/\s*([{};,:])\s*/g,"$1").trim();return{script:W,css:Q}}var jJ=_(()=>{T();P();z();T();P();z()});jJ();export{l as validateFile,_J as uploadFiles,s as uploadFile,j as thumbHashToRGBA,GJ as thumbHashToDataURL,VJ as renderThumbhashToCanvas,NJ as parseThumbhashString,ZJ as observeElement,B as loadElement,XJ as lazyLoadAll,WJ as lazyLoad,g as isNativeLazySupported,f as isIntersectionObserverSupported,KJ as initLazyLoading,d as initBlurUp,BJ as initAllBlurUp,CJ as generateVideoPreview,D as generateUploadRuntime,EJ as generateMinifiedMediaRuntime,TJ as generateMediaRuntime,C as generateLazyLoadRuntime,AJ as generateImagePreview,I as generateBlurUpRuntime,k as generateBlurUpCSS,$J as disconnectObserver,FJ as crossfadeTransition,YJ as createLazyObserver};
