// @bun
var{defineProperty:X,getOwnPropertyNames:O,getOwnPropertyDescriptor:T}=Object,w=Object.prototype.hasOwnProperty;function C(b){return this[b]}var c=(b)=>{var j=(R??=new WeakMap).get(b),z;if(j)return j;if(j=X({},"__esModule",{value:!0}),b&&typeof b==="object"||typeof b==="function"){for(var D of O(b))if(!w.call(j,D))X(j,D,{get:C.bind(b,D),enumerable:!(z=T(b,D))||z.enumerable})}return R.set(b,j),j},R;var P=(b)=>b;function E(b,j){this[b]=P.bind(null,j)}var d=(b,j)=>{for(var z in j)X(b,z,{get:j[z],enumerable:!0,configurable:!0,set:E.bind(j,z)})};var h=(b,j)=>()=>(b&&(j=b(b=0)),j);var l=import.meta.require;function k(b){if(!W)return null;let j=document.getElementById("stx-loading-indicator");if(j)j.remove();let z=document.createElement("div");z.id="stx-loading-indicator";let D=b.initialColor?`linear-gradient(to right, ${b.initialColor}, ${b.color})`:b.color;z.style.cssText=`
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: ${b.height};
    background: ${D};
    z-index: ${b.zIndex};
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.1s ease-out, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
  `;let Y=document.createElement("div");if(Y.style.cssText=`
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(255,255,255,0.4) 50%,
      transparent 100%
    );
    animation: stx-shimmer 1.5s infinite;
  `,z.appendChild(Y),!document.getElementById("stx-loading-styles")){let Q=document.createElement("style");Q.id="stx-loading-styles",Q.textContent=`
      @keyframes stx-shimmer {
        0% { transform: translateX(-100%); }
        100% { transform: translateX(100%); }
      }
    `,document.head.appendChild(Q)}return document.body.appendChild(z),z}function H(b,j){if(!W||!G)return;if(J=Math.min(Math.max(b,0),100),A)cancelAnimationFrame(A);A=requestAnimationFrame(()=>{if(!G)return;G.style.opacity=J>0?"1":"0",G.style.transform=`scaleX(${J/100})`})}function I(b){if(!W)return;if(_=!0,J=0,!G)G=k(b);if(V)clearTimeout(V);if(K)clearInterval(K);H(10,b),K=setInterval(()=>{if(!_)return;let j=90-J,z=Math.max(0.5,j*0.1);if(J<90)H(J+z,b)},b.throttle)}function f(b){if(!W)return;if(_=!1,K)clearInterval(K),K=null;H(100,b),V=setTimeout(()=>{if(G)G.style.opacity="0";setTimeout(()=>{if(J=0,G)G.style.transform="scaleX(0)"},300)},200)}function L(){if(!W)return;if(_=!1,J=0,K)clearInterval(K),K=null;if(V)clearTimeout(V),V=null;if(G)G.style.opacity="0",G.style.transform="scaleX(0)"}function B(b){let j={...x,...b};return{start:()=>I(j),set:(z)=>H(z,j),finish:()=>f(j),clear:()=>L(),get state(){return{isLoading:_,progress:J,error:!1}}}}function v(b){if(!W)return;if(N)N(),N=null;let j={...x,...b},z=B(j);G=k(j);let D=!1,Y=(U)=>{let M=U.target.closest("a");if(!M)return;let Z=M.getAttribute("href");if(!Z)return;if(Z.startsWith("http")||Z.startsWith("#")||Z.startsWith("mailto:")||Z.startsWith("tel:")||M.target==="_blank"||M.hasAttribute("download"))return;D=!0,z.start()},Q=()=>{if(!D)z.start(),D=!0},y=()=>{if(D||j.autoFinish)z.finish(),D=!1};document.addEventListener("click",Y),window.addEventListener("popstate",Q),window.addEventListener("load",y);let q=window.fetch,$=0,F=async function(...U){let S=typeof U[0]==="string"?U[0]:U[0].url,M=S.includes("/api/")||S.startsWith("/api");if(M){if($++,$===1&&!D)z.start()}try{return await q.apply(this,U)}finally{if(M){if($--,$===0&&!D)z.finish()}}};window.fetch=F,N=()=>{if(document.removeEventListener("click",Y),window.removeEventListener("popstate",Q),window.removeEventListener("load",y),window.fetch===F)window.fetch=q}}function g(){if(N)N(),N=null}function m(b){let j={...x,...b},z=j.initialColor?`linear-gradient(to right, ${j.initialColor}, ${j.color})`:j.color;return`
<div id="stx-loading-indicator" style="
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: ${j.height};
  background: ${z};
  z-index: ${j.zIndex};
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.1s ease-out, opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
">
  <div style="
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.4) 50%, transparent 100%);
    animation: stx-shimmer 1.5s infinite;
  "></div>
</div>
<style>
  @keyframes stx-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
  }
</style>
<script>
(function() {
  var opts = ${JSON.stringify(j)};
  var el = document.getElementById('stx-loading-indicator');
  var progress = 0;
  var loading = false;
  var interval = null;

  function update(p) {
    progress = Math.min(Math.max(p, 0), 100);
    if (el) {
      el.style.opacity = progress > 0 ? '1' : '0';
      el.style.transform = 'scaleX(' + (progress / 100) + ')';
    }
  }

  window.stxLoading = {
    start: function() {
      loading = true;
      progress = 0;
      update(10);
      if (interval) clearInterval(interval);
      interval = setInterval(function() {
        if (!loading) return;
        var remaining = 90 - progress;
        var inc = Math.max(0.5, remaining * 0.1);
        if (progress < 90) update(progress + inc);
      }, opts.throttle);
    },
    finish: function() {
      loading = false;
      if (interval) { clearInterval(interval); interval = null; }
      update(100);
      setTimeout(function() {
        if (el) el.style.opacity = '0';
        setTimeout(function() {
          progress = 0;
          if (el) el.style.transform = 'scaleX(0)';
        }, 300);
      }, 200);
    },
    set: function(v) { update(v); },
    clear: function() {
      loading = false;
      progress = 0;
      if (interval) { clearInterval(interval); interval = null; }
      if (el) { el.style.opacity = '0'; el.style.transform = 'scaleX(0)'; }
    }
  };

  // Auto-hook navigation
  document.addEventListener('click', function(e) {
    var link = e.target.closest && e.target.closest('a');
    if (!link) return;
    var href = link.getAttribute('href');
    if (!href || href.startsWith('http') || href.startsWith('#') || href.startsWith('mailto:') || href.startsWith('tel:') || link.target === '_blank') return;
    window.stxLoading.start();
  });

  window.addEventListener('popstate', function() { window.stxLoading.start(); });
  window.addEventListener('load', function() { window.stxLoading.finish(); });
})();
</script>
`}var W,x,G=null,J=0,_=!1,A=null,V=null,K=null,N=null,a;var u=h(()=>{W=typeof window<"u"&&typeof document<"u",x={color:"#6366f1",initialColor:"",height:"3px",duration:2000,throttle:200,autoFinish:!0,zIndex:999999};a={useLoadingIndicator:B,initLoadingIndicator:v,generateLoadingIndicatorHtml:m}});u();export{B as useLoadingIndicator,v as initLoadingIndicator,m as generateLoadingIndicatorHtml,a as default,g as cleanupLoadingIndicator};
