// @bun
var{defineProperty:M,getOwnPropertyNames:j,getOwnPropertyDescriptor:O}=Object,D=Object.prototype.hasOwnProperty;function H(q){return this[q]}var f=(q)=>{var k=(U??=new WeakMap).get(q),z;if(k)return k;if(k=M({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var B of j(q))if(!D.call(k,B))M(k,B,{get:H.bind(q,B),enumerable:!(z=O(q,B))||z.enumerable})}return U.set(q,k),k},U;var P=(q)=>q;function w(q,k){this[q]=P.bind(null,k)}var T=(q,k)=>{for(var z in k)M(q,z,{get:k[z],enumerable:!0,configurable:!0,set:w.bind(k,z)})};var S=(q,k)=>()=>(q&&(k=q(q=0)),k);var c=import.meta.require;var A={enabled:!1,components:new Map,stores:new Map,events:[],performance:[],selectedComponent:null,selectedStore:null,maxEvents:1000,maxPerformance:500};function v(q={}){if(typeof window>"u")return;A.enabled=!0,A.maxEvents=q.maxEvents||1000,A.maxPerformance=q.maxPerformance||500,window.__STX_DEVTOOLS__={getState:()=>A,getComponents:()=>Array.from(A.components.values()),getComponent:(k)=>A.components.get(k),getStores:()=>Array.from(A.stores.values()),getStore:(k)=>A.stores.get(k),getEvents:()=>A.events,getPerformance:()=>A.performance,selectComponent:(k)=>N(k),selectStore:(k)=>V(k),inspectElement:(k)=>x(k),highlightComponent:(k)=>Z(k),clearHighlight:()=>_(),logComponentTree:()=>b(),logStoreState:(k)=>C(k),timeTravel:(k,z)=>y(k,z)},h(),g(),console.log("%c[STX DevTools] Enabled","color: #10b981; font-weight: bold;")}function l(){A.enabled=!1,delete window.__STX_DEVTOOLS__;let q=document.getElementById("stx-devtools-panel");if(q)q.remove();console.log("%c[STX DevTools] Disabled","color: #ef4444;")}var E=0;function s(q,k,z={},B={},F){if(!A.enabled)return"";let G=`stx-${++E}`;k.setAttribute("data-stx-component-id",G);let J,L=k.parentElement;while(L){let Q=L.getAttribute("data-stx-component-id");if(Q){J=Q;let R=A.components.get(J);if(R)R.children.push(G);break}L=L.parentElement}let $={id:G,name:q,file:F,parentId:J,children:[],props:z,state:B,exposed:[],element:k,renderCount:1,lastRenderTime:0,createdAt:Date.now()};return A.components.set(G,$),K({timestamp:Date.now(),type:"component:mounted",componentId:G,payload:{name:q,props:z}}),G}function a(q,k){if(!A.enabled)return;let z=A.components.get(q);if(z)z.state={...z.state,...k},z.renderCount++,K({timestamp:Date.now(),type:"component:updated",componentId:q,payload:{state:k}})}function r(q,k){if(!A.enabled)return;let z=A.components.get(q);if(z){let B={...z.props};z.props={...z.props,...k},K({timestamp:Date.now(),type:"component:props-changed",componentId:q,payload:{oldProps:B,newProps:k}})}}function W(q){if(!A.enabled)return;let k=A.components.get(q);if(k){if(k.parentId){let z=A.components.get(k.parentId);if(z)z.children=z.children.filter((B)=>B!==q)}A.components.delete(q),K({timestamp:Date.now(),type:"component:unmounted",componentId:q,payload:{name:k.name}})}}function i(q,k,z={},B=[]){if(!A.enabled)return;let F={id:q,state:k,getters:z,actions:B,history:[{timestamp:Date.now(),type:"state",name:"__init__",newValue:k}]};A.stores.set(q,F),K({timestamp:Date.now(),type:"store:registered",payload:{id:q,state:k}})}function d(q,k,z,B,F="state"){if(!A.enabled)return;let G=A.stores.get(q);if(G){let J={timestamp:Date.now(),type:F,name:k,oldValue:z,newValue:B,stack:Error().stack};if(G.history.push(J),G.history.length>100)G.history=G.history.slice(-100);if(F==="state")G.state={...G.state,[k]:B};K({timestamp:Date.now(),type:`store:${F}`,payload:{storeId:q,name:k,oldValue:z,newValue:B}})}}function n(q,k){if(!A.enabled)return;let z=A.stores.get(q);if(z)z.getters=k}function K(q){if(!A.enabled)return;if(A.events.push(q),A.events.length>A.maxEvents)A.events=A.events.slice(-A.maxEvents);if(typeof window<"u")window.dispatchEvent(new CustomEvent("stx:devtools:event",{detail:q}))}function Y(q){if(!A.enabled)return;if(A.performance.push(q),A.performance.length>A.maxPerformance)A.performance=A.performance.slice(-A.maxPerformance)}function o(q,k,z){if(!A.enabled)return k();let B=performance.now(),F=k(),G=performance.now()-B;return Y({name:q,duration:G,timestamp:Date.now(),componentId:z}),F}async function t(q,k,z){if(!A.enabled)return k();let B=performance.now(),F=await k(),G=performance.now()-B;return Y({name:q,duration:G,timestamp:Date.now(),componentId:z}),F}function N(q){A.selectedComponent=q;let k=A.components.get(q);if(k)Z(q),console.log("%c[STX DevTools] Selected component:","color: #3b82f6;",k);return k}function V(q){A.selectedStore=q;let k=A.stores.get(q);if(k)console.log("%c[STX DevTools] Selected store:","color: #8b5cf6;",k);return k}function x(q){let k=q;while(k){let z=k.getAttribute("data-stx-component-id");if(z)return N(z);k=k.parentElement}console.log("%c[STX DevTools] No component found for element","color: #f59e0b;");return}function Z(q){_();let k=A.components.get(q);if(k?.element){let z=document.createElement("div");z.id="stx-devtools-highlight",z.style.cssText=`
      position: absolute;
      background: rgba(59, 130, 246, 0.2);
      border: 2px solid #3b82f6;
      pointer-events: none;
      z-index: 999999;
      transition: all 0.15s ease;
    `;let B=k.element.getBoundingClientRect();z.style.top=`${B.top+window.scrollY}px`,z.style.left=`${B.left+window.scrollX}px`,z.style.width=`${B.width}px`,z.style.height=`${B.height}px`;let F=document.createElement("div");F.style.cssText=`
      position: absolute;
      top: -24px;
      left: 0;
      background: #3b82f6;
      color: white;
      padding: 2px 8px;
      font-size: 12px;
      font-family: monospace;
      border-radius: 4px;
      white-space: nowrap;
    `,F.textContent=`<${k.name}>`,z.appendChild(F),document.body.appendChild(z)}}function _(){let q=document.getElementById("stx-devtools-highlight");if(q)q.remove()}function b(){console.group("%c[STX DevTools] Component Tree","color: #10b981; font-weight: bold;");let q=Array.from(A.components.values()).filter((z)=>!z.parentId);function k(z,B){let F="  ".repeat(B);if(console.log(`${F}%c<${z.name}>%c id=${z.id} renders=${z.renderCount}`,"color: #3b82f6;","color: #6b7280;"),Object.keys(z.props).length>0)console.log(`${F}  props:`,z.props);if(Object.keys(z.state).length>0)console.log(`${F}  state:`,z.state);for(let G of z.children){let J=A.components.get(G);if(J)k(J,B+1)}}for(let z of q)k(z,0);console.groupEnd()}function C(q){console.group("%c[STX DevTools] Store State","color: #8b5cf6; font-weight: bold;");let k=q?[A.stores.get(q)].filter(Boolean):Array.from(A.stores.values());for(let z of k)if(z)console.group(`Store: ${z.id}`),console.log("State:",z.state),console.log("Getters:",z.getters),console.log("Actions:",z.actions),console.log("History:",z.history),console.groupEnd();console.groupEnd()}function y(q,k){let z=A.stores.get(k);if(!z)return;if(q<0||q>=z.history.length){console.warn("[STX DevTools] Invalid history index");return}let B={};for(let F=0;F<=q;F++){let G=z.history[F];if(G.type==="state"&&G.name!=="__init__")B[G.name]=G.newValue;else if(G.name==="__init__")Object.assign(B,G.newValue)}if(console.log(`%c[STX DevTools] Time traveled to index ${q}`,"color: #f59e0b;",B),typeof window<"u"&&window.__STX_STORES__){let G=window.__STX_STORES__[k];if(G&&typeof G.$patch==="function")G.$patch(B)}}function g(){if(typeof MutationObserver>"u")return;new MutationObserver((k)=>{for(let z of k)z.removedNodes.forEach((B)=>{if(B instanceof HTMLElement){let F=B.getAttribute("data-stx-component-id");if(F)W(F);B.querySelectorAll("[data-stx-component-id]").forEach((G)=>{let J=G.getAttribute("data-stx-component-id");if(J)W(J)})}})}).observe(document.body,{childList:!0,subtree:!0})}function h(){if(typeof document>"u")return;if(document.getElementById("stx-devtools-panel"))return;let q=document.createElement("div");q.id="stx-devtools-panel",q.innerHTML=`
    <style>
      #stx-devtools-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        width: 400px;
        height: 300px;
        background: #1f2937;
        color: #e5e7eb;
        font-family: ui-monospace, monospace;
        font-size: 12px;
        border-top-left-radius: 8px;
        box-shadow: -4px -4px 20px rgba(0,0,0,0.3);
        z-index: 999998;
        display: flex;
        flex-direction: column;
        transform: translateY(calc(100% - 32px));
        transition: transform 0.2s ease;
      }
      #stx-devtools-panel.open {
        transform: translateY(0);
      }
      #stx-devtools-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 12px;
        background: #374151;
        border-top-left-radius: 8px;
        cursor: pointer;
        user-select: none;
      }
      #stx-devtools-header:hover {
        background: #4b5563;
      }
      #stx-devtools-title {
        font-weight: bold;
        color: #10b981;
      }
      #stx-devtools-tabs {
        display: flex;
        border-bottom: 1px solid #374151;
      }
      .stx-devtools-tab {
        padding: 6px 12px;
        cursor: pointer;
        border-bottom: 2px solid transparent;
      }
      .stx-devtools-tab:hover {
        background: #374151;
      }
      .stx-devtools-tab.active {
        border-bottom-color: #3b82f6;
        color: #3b82f6;
      }
      #stx-devtools-content {
        flex: 1;
        overflow: auto;
        padding: 8px;
      }
      .stx-devtools-component {
        padding: 4px 8px;
        cursor: pointer;
        border-radius: 4px;
      }
      .stx-devtools-component:hover {
        background: #374151;
      }
      .stx-devtools-component.selected {
        background: #3b82f6;
      }
      .stx-devtools-component-name {
        color: #60a5fa;
      }
      .stx-devtools-component-id {
        color: #6b7280;
        font-size: 10px;
        margin-left: 8px;
      }
      .stx-devtools-section {
        margin-bottom: 8px;
      }
      .stx-devtools-section-title {
        color: #9ca3af;
        font-size: 10px;
        text-transform: uppercase;
        margin-bottom: 4px;
      }
      .stx-devtools-json {
        background: #111827;
        padding: 4px 8px;
        border-radius: 4px;
        white-space: pre-wrap;
        word-break: break-all;
      }
    </style>
    <div id="stx-devtools-header">
      <span id="stx-devtools-title">STX DevTools</span>
      <span id="stx-devtools-toggle">\u25B2</span>
    </div>
    <div id="stx-devtools-tabs">
      <div class="stx-devtools-tab active" data-tab="components">Components</div>
      <div class="stx-devtools-tab" data-tab="stores">Stores</div>
      <div class="stx-devtools-tab" data-tab="events">Events</div>
    </div>
    <div id="stx-devtools-content">
      <div id="stx-devtools-components-tab"></div>
    </div>
  `,document.body.appendChild(q);let k=q.querySelector("#stx-devtools-header"),z=q.querySelector("#stx-devtools-toggle");k?.addEventListener("click",()=>{if(q.classList.toggle("open"),z)z.textContent=q.classList.contains("open")?"\u25BC":"\u25B2"});let B=q.querySelectorAll(".stx-devtools-tab");B.forEach((F)=>{F.addEventListener("click",()=>{B.forEach((G)=>G.classList.remove("active")),F.classList.add("active"),X(F.getAttribute("data-tab")||"components")})}),setInterval(()=>{let F=q.querySelector(".stx-devtools-tab.active");if(F&&q.classList.contains("open"))X(F.getAttribute("data-tab")||"components")},1000)}function X(q){let k=document.getElementById("stx-devtools-content");if(!k)return;switch(q){case"components":k.innerHTML=u();break;case"stores":k.innerHTML=I();break;case"events":k.innerHTML=m();break}k.querySelectorAll(".stx-devtools-component").forEach((z)=>{z.addEventListener("click",()=>{let B=z.getAttribute("data-id");if(B)N(B)})})}function u(){let k=Array.from(A.components.values()).filter((B)=>!B.parentId);function z(B,F){let G=B.children.map((J)=>A.components.get(J)).filter(Boolean).map((J)=>z(J,F+1)).join("");return`
      <div class="stx-devtools-component ${A.selectedComponent===B.id?"selected":""}"
           data-id="${B.id}"
           style="padding-left: ${F*16+8}px">
        <span class="stx-devtools-component-name">&lt;${B.name}&gt;</span>
        <span class="stx-devtools-component-id">${B.id}</span>
      </div>
      ${G}
    `}if(k.length===0)return'<div style="color: #6b7280; padding: 8px;">No components registered</div>';return k.map((B)=>z(B,0)).join("")}function I(){let q=Array.from(A.stores.values());if(q.length===0)return'<div style="color: #6b7280; padding: 8px;">No stores registered</div>';return q.map((k)=>`
    <div class="stx-devtools-section">
      <div class="stx-devtools-section-title">${k.id}</div>
      <div class="stx-devtools-json">${JSON.stringify(k.state,null,2)}</div>
    </div>
  `).join("")}function m(){let q=A.events.slice(-20).reverse();if(q.length===0)return'<div style="color: #6b7280; padding: 8px;">No events recorded</div>';return q.map((k)=>`
    <div style="padding: 4px 0; border-bottom: 1px solid #374151;">
      <span style="color: #60a5fa;">${k.type}</span>
      <span style="color: #6b7280; font-size: 10px; margin-left: 8px;">
        ${new Date(k.timestamp).toLocaleTimeString()}
      </span>
    </div>
  `).join("")}export{n as updateStoreGetters,a as updateComponentState,r as updateComponentProps,W as unregisterComponent,y as timeTravel,V as selectStore,N as selectComponent,i as registerStore,s as registerComponent,d as recordStoreMutation,Y as recordPerformance,K as recordEvent,t as measurePerformanceAsync,o as measurePerformance,C as logStoreState,b as logComponentTree,x as inspectElement,Z as highlightComponent,v as enableDevTools,l as disableDevTools,A as devToolsState,_ as clearHighlight};
