// @bun
var{defineProperty:T,getOwnPropertyNames:A,getOwnPropertyDescriptor:N}=Object,K=Object.prototype.hasOwnProperty;function O(q){return this[q]}var j=(q)=>{var z=(M??=new WeakMap).get(q),B;if(z)return z;if(z=T({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var E of A(q))if(!K.call(z,E))T(z,E,{get:O.bind(q,E),enumerable:!(B=N(q,E))||B.enumerable})}return M.set(q,z),z},M;var W=(q)=>q;function w(q,z){this[q]=W.bind(null,z)}var y=(q,z)=>{for(var B in z)T(q,B,{get:z[B],enumerable:!0,configurable:!0,set:w.bind(z,B)})};var D=(q,z)=>()=>(q&&(z=q(q=0)),z);var I=import.meta.require;function v(){return`stx-${++x}-${Date.now().toString(36)}`}function f(q){let z={id:v(),element:q||null,mountHooks:[],destroyHooks:[],updateHooks:[],refs:new Map,watchers:[],isMounted:!1};return U.set(z.id,z),z}function R(q){H=q}function X(){return H}function Y(q){if(!H)return console.warn(`[stx] ${q} must be called within a component setup.`),null;return H}function g(q){let z=Y("onMount");if(z)z.mountHooks.push(q)}function S(q){let z=Y("onDestroy");if(z)z.destroyHooks.push(q)}function m(q){let z=Y("onUpdate");if(z)z.updateHooks.push(q)}function C(q=null){let z={value:q,get current(){return this.value}},B=X();if(B){let E=`ref-${B.refs.size}`;B.refs.set(E,z)}return z}function r(q,z=null){let B=C(z),E=X();if(E)E.refs.set(q,B);return B}function o(q,z,B={}){let E,G,_=!0,$=()=>{if(!_)return;let Q=q();if(E!==Q||B.immediate){if(G)G();G=z(Q,E),E=Q}};if(B.immediate)$();else E=q();let b=setInterval($,16),L=()=>{if(_=!1,clearInterval(b),G)G()},P=X();if(P)P.watchers.push({stop:L}),P.destroyHooks.push(L);return L}function s(q){let z,B=!0;return{get value(){if(B)z=q(),B=!1,queueMicrotask(()=>{B=!0});return z}}}function a(q,z){let B=f(q);R(B);try{z()}finally{R(null)}return B}function i(q){if(q.isMounted)return;q.isMounted=!0;for(let z of q.mountHooks)try{let B=z();if(typeof B==="function")q.destroyHooks.push(B)}catch(B){console.error("[stx] Error in onMount hook:",B)}}function c(q){if(!q.isMounted)return;for(let z of q.updateHooks)try{let B=z();if(typeof B==="function")q.destroyHooks.push(B)}catch(B){console.error("[stx] Error in onUpdate hook:",B)}}function t(q){if(!q.isMounted)return;for(let z of q.watchers)z.stop();for(let z of q.destroyHooks)try{z()}catch(B){console.error("[stx] Error in onDestroy hook:",B)}for(let z of q.refs.values())z.value=null;q.isMounted=!1,U.delete(q.id)}function e(){return`
// STX Lifecycle Runtime
(function() {
  if (typeof window === 'undefined') return;

  const instances = new Map();
  let currentInstance = null;
  let idCounter = 0;

  function generateId() {
    return 'stx-' + (++idCounter) + '-' + Date.now().toString(36);
  }

  function createInstance(element) {
    const instance = {
      id: generateId(),
      element: element,
      mountHooks: [],
      destroyHooks: [],
      updateHooks: [],
      refs: new Map(),
      watchers: [],
      isMounted: false
    };
    instances.set(instance.id, instance);
    return instance;
  }

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

  // Lifecycle hooks
  window.STX.onMount = function(hook) {
    if (currentInstance) currentInstance.mountHooks.push(hook);
  };

  window.STX.onDestroy = function(hook) {
    if (currentInstance) currentInstance.destroyHooks.push(hook);
  };

  window.STX.onUpdate = function(hook) {
    if (currentInstance) currentInstance.updateHooks.push(hook);
  };

  // Aliases
  window.STX.onMounted = window.STX.onMount;
  window.STX.onUnmounted = window.STX.onDestroy;
  window.STX.onUpdated = window.STX.onUpdate;

  // Refs
  window.STX.ref = function(initialValue) {
    const r = { value: initialValue || null };
    Object.defineProperty(r, 'current', {
      get: function() { return this.value; }
    });
    if (currentInstance) {
      currentInstance.refs.set('ref-' + currentInstance.refs.size, r);
    }
    return r;
  };

  // Watch
  window.STX.watch = function(source, callback, options) {
    options = options || {};
    let oldValue;
    let cleanup;
    let isActive = true;

    function run() {
      if (!isActive) return;
      const newValue = source();
      if (oldValue !== newValue || options.immediate) {
        if (cleanup) cleanup();
        cleanup = callback(newValue, oldValue);
        oldValue = newValue;
      }
    }

    if (options.immediate) {
      run();
    }
else {
      oldValue = source();
    }

    const intervalId = setInterval(run, 16);

    function stop() {
      isActive = false;
      clearInterval(intervalId);
      if (cleanup) cleanup();
    }

    if (currentInstance) {
      currentInstance.watchers.push({ stop: stop });
      currentInstance.destroyHooks.push(stop);
    }

    return stop;
  };

  // Computed
  window.STX.computed = function(getter) {
    let cached;
    let dirty = true;
    return {
      get value() {
        if (dirty) {
          cached = getter();
          dirty = false;
          queueMicrotask(function() { dirty = true; });
        }
        return cached;
      }
    };
  };

  // Component management
  window.STX.setupComponent = function(element, setup) {
    const instance = createInstance(element);
    currentInstance = instance;
    try {
      setup();
    }
finally {
      currentInstance = null;
    }
    return instance;
  };

  window.STX.mountComponent = function(instance) {
    if (instance.isMounted) return;
    instance.isMounted = true;
    instance.mountHooks.forEach(function(hook) {
      try {
        const cleanup = hook();
        if (typeof cleanup === 'function') {
          instance.destroyHooks.push(cleanup);
        }
      }
catch (e) {
        console.error('[stx] onMount error:', e);
      }
    });
  };

  window.STX.destroyComponent = function(instance) {
    if (!instance.isMounted) return;
    instance.watchers.forEach(function(w) { w.stop(); });
    instance.destroyHooks.forEach(function(hook) {
      try { hook(); }
catch (e) { console.error('[stx] onDestroy error:', e); }
    });
    instance.refs.forEach(function(ref) { ref.value = null; });
    instance.isMounted = false;
    instances.delete(instance.id);
  };

  // ==========================================================================
  // Vue-Style Refs System - No document.** required!
  // ==========================================================================

  // Internal: Query for ref elements without exposing document API
  function queryRef(name, root) {
    return (root || document).querySelector('[data-stx-ref="' + name + '"], [data-ref="' + name + '"]');
  }

  function queryAllRefs(root) {
    return (root || document).querySelectorAll('[data-stx-ref], [data-ref]');
  }

  // Auto-bind refs from ref attributes (Vue-style)
  window.STX.bindRefs = function(root, refs) {
    if (!root) return;
    queryAllRefs(root).forEach(function(el) {
      var refName = el.getAttribute('data-stx-ref') || el.getAttribute('data-ref');
      if (refs[refName]) {
        refs[refName].value = el;
      }
    });
  };

  // Vue-style useRefs() - returns object with all refs as direct elements
  // Usage: const { input, button, container } = STX.useRefs()
  window.STX.useRefs = function(root) {
    var refs = {};
    queryAllRefs(root).forEach(function(el) {
      var refName = el.getAttribute('data-stx-ref') || el.getAttribute('data-ref');
      if (refName) {
        refs[refName] = el;
      }
    });
    return refs;
  };

  // Get a single ref by name - Vue's useTemplateRef equivalent
  // Usage: const input = STX.useRef('input')
  window.STX.useRef = function(name, root) {
    return queryRef(name, root);
  };

  // Two-way binding helper for form elements
  // Usage: STX.model(inputEl, state, 'username')
  window.STX.model = function(el, state, key) {
    if (!el || !state) return;

    var isCheckbox = el.type === 'checkbox';
    var isRadio = el.type === 'radio';
    var isSelect = el.tagName === 'SELECT';

    // Set initial value
    if (isCheckbox) {
      el.checked = !!state[key];
    }
else if (isRadio) {
      el.checked = el.value === state[key];
    }
else {
      el.value = state[key] || '';
    }

    // Listen for changes
    var eventType = isCheckbox || isRadio ? 'change' : 'input';
    el.addEventListener(eventType, function() {
      if (isCheckbox) {
        state[key] = el.checked;
      }
else if (isRadio) {
        if (el.checked) state[key] = el.value;
      }
else {
        state[key] = el.value;
      }
    });

    // Return cleanup function
    return function() {
      el.removeEventListener(eventType, arguments.callee);
    };
  };

  // Batch event binding helper - cleaner than manual addEventListener
  // Usage: STX.on({ click: [btn1, btn2], input: [textField] }, handler)
  window.STX.on = function(el, event, handler) {
    if (!el) return function() {};
    el.addEventListener(event, handler);
    return function() { el.removeEventListener(event, handler); };
  };

  // Bind multiple events at once
  // Usage: STX.events(refs.btn, { click: handleClick, mouseenter: handleHover })
  window.STX.events = function(el, eventMap) {
    if (!el) return function() {};
    var cleanups = [];
    Object.keys(eventMap).forEach(function(event) {
      el.addEventListener(event, eventMap[event]);
      cleanups.push(function() { el.removeEventListener(event, eventMap[event]); });
    });
    return function() { cleanups.forEach(function(c) { c(); }); };
  };

  // ==========================================================================
  // DOM Helpers - Eliminate document.* usage
  // ==========================================================================

  // Global keyboard event listener
  // Usage: STX.onKey('Escape', () => closeModal())
  window.STX.onKey = function(key, handler, options) {
    var listener = function(e) {
      if (e.key === key) {
        handler(e);
      }
    };
    document.addEventListener('keydown', listener, options);
    return function() { document.removeEventListener('keydown', listener, options); };
  };

  // Create element helper
  // Usage: STX.el('div', { class: 'foo' }, 'text content')
  window.STX.el = function(tag, attrs, content) {
    var el = document.createElement(tag);
    if (attrs) {
      Object.keys(attrs).forEach(function(key) {
        if (key === 'class') {
          el.className = attrs[key];
        }
else if (key.startsWith('on')) {
          el.addEventListener(key.slice(2).toLowerCase(), attrs[key]);
        }
else {
          el.setAttribute(key, attrs[key]);
        }
      });
    }
    if (content) {
      if (typeof content === 'string') {
        el.textContent = content;
      }
else if (Array.isArray(content)) {
        content.forEach(function(child) { el.appendChild(child); });
      }
else {
        el.appendChild(content);
      }
    }
    return el;
  };

  // Get currently focused element
  // Usage: const focused = STX.activeElement()
  window.STX.activeElement = function() {
    return document.activeElement;
  };

  // Escape HTML helper
  // Usage: const safe = STX.escapeHtml(userInput)
  window.STX.escapeHtml = function(text) {
    var div = document.createElement('div');
    div.textContent = text;
    return div.innerHTML;
  };

  // MutationObserver for automatic lifecycle management
  const observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
      // Handle removed nodes
      mutation.removedNodes.forEach(function(node) {
        if (node.nodeType === 1 && node.__stx_instance__) {
          window.STX.destroyComponent(node.__stx_instance__);
        }
      });
    });
  });

  // Start observing when DOM is ready
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', function() {
      observer.observe(document.body, { childList: true, subtree: true });
    });
  }
else {
    observer.observe(document.body, { childList: true, subtree: true });
  }

  console.log('[stx] Lifecycle runtime initialized');
})();
`}function Z(q){return Symbol(q)}function n(q,z){(F.length>0?F[F.length-1]:J).set(q,z)}function qq(q,z){for(let B=F.length-1;B>=0;B--){let E=F[B];if(E.has(q))return E.get(q)}if(J.has(q))return J.get(q);if(arguments.length>1)return z;console.warn(`[stx] Injection "${String(q)}" not found.`);return}function d(){F.push(new Map)}function h(){F.pop()}async function zq(q){d();try{return await q()}finally{h()}}function Bq(){J.clear(),F.length=0}var H=null,U,x=0,p,l,u,J,F,Eq,Fq,Gq;var V=D(()=>{U=new Map;p=g,l=S,u=m;J=new Map,F=[];Eq=Z("theme"),Fq=Z("router"),Gq=Z("i18n")});V();export{zq as withInjectionScope,o as watch,c as updateComponent,a as setupComponent,R as setCurrentInstance,C as ref,d as pushInjectionScope,n as provide,h as popInjectionScope,u as onUpdated,m as onUpdate,l as onUnmounted,p as onMounted,g as onMount,S as onDestroy,r as namedRef,i as mountComponent,qq as inject,X as getCurrentInstance,e as generateLifecycleRuntime,t as destroyComponent,C as createRef,Z as createInjectionKey,f as createComponentInstance,s as computed,Bq as clearInjections,Eq as ThemeKey,Fq as RouterKey,Gq as I18nKey};
