// @bun
var{defineProperty:A,getOwnPropertyNames:D,getOwnPropertyDescriptor:F}=Object,G=Object.prototype.hasOwnProperty;function I(j){return this[j]}var W=(j)=>{var q=(B??=new WeakMap).get(j),w;if(q)return q;if(q=A({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var x of D(j))if(!G.call(q,x))A(q,x,{get:I.bind(j,x),enumerable:!(w=F(j,x))||w.enumerable})}return B.set(j,q),q},B;var J=(j)=>j;function K(j,q){this[j]=J.bind(null,q)}var X=(j,q)=>{for(var w in q)A(j,w,{get:q[w],enumerable:!0,configurable:!0,set:K.bind(q,w)})};var Y=(j,q)=>()=>(j&&(q=j(j=0)),q);var Z=import.meta.require;import Q from"fs";function C(j,q,w="source"){return`
    <div class="stx-code-panel">
      <div class="stx-code-tabs">
        <button class="${w==="source"?"active":""}" onclick="window.__stxStory.setCodeTab('source')">Source</button>
        <button class="${w==="story"?"active":""}" onclick="window.__stxStory.setCodeTab('story')">Story</button>
        <button class="${w==="compiled"?"active":""}" onclick="window.__stxStory.setCodeTab('compiled')">Compiled</button>
        <button class="${w==="props"?"active":""}" onclick="window.__stxStory.setCodeTab('props')">Props</button>
      </div>
      <div class="stx-code-toolbar">
        <button onclick="window.__stxStory.copyCode()" title="Copy code">\uD83D\uDCCB Copy</button>
        <button onclick="window.__stxStory.openInVSCode()" title="Open in VS Code">\uD83D\uDCDD VS Code</button>
      </div>
      <div class="stx-code-content" id="code-content">
        <!-- Content loaded dynamically -->
      </div>
    </div>
  `}async function E(j){try{return await Q.promises.readFile(j,"utf-8")}catch{return"// Unable to read source file"}}function L(j,q){let w=Object.entries(q).map(([x,z])=>{if(typeof z==="string")return`${x}="${z}"`;if(typeof z==="boolean")return z?x:`:${x}="false"`;if(typeof z==="number")return`:${x}="${z}"`;return`:${x}="${JSON.stringify(z).replace(/"/g,"'")}"`}).join(`
  `);return`<${j}
  ${w}
/>`}function M(j){return JSON.stringify(j,null,2)}function O(j,q){let w=U(j);if(q==="html"||q==="stx")w=w.replace(/(&lt;\/?)([\w-]+)/g,'$1<span class="hl-tag">$2</span>').replace(/([\w-]+)(=)/g,'<span class="hl-attr">$1</span>$2').replace(/(&quot;[^&]*&quot;)/g,'<span class="hl-string">$1</span>').replace(/(&lt;!--[\s\S]*?--&gt;)/g,'<span class="hl-comment">$1</span>').replace(/(@\w+)/g,'<span class="hl-directive">$1</span>').replace(/(\{\{[^}]*\}\})/g,'<span class="hl-interpolation">$1</span>');else if(q==="json")w=w.replace(/(&quot;\w+&quot;)(:)/g,'<span class="hl-key">$1</span>$2').replace(/(: )(&quot;[^&]*&quot;)/g,'$1<span class="hl-string">$2</span>').replace(/(: )(\d+)/g,'$1<span class="hl-number">$2</span>').replace(/(true|false|null)/g,'<span class="hl-boolean">$1</span>');else if(q==="typescript"||q==="javascript")w=w.replace(/\b(const|let|var|function|return|if|else|for|while|class|interface|type|export|import|from|async|await)\b/g,'<span class="hl-keyword">$1</span>').replace(/(&apos;[^&]*&apos;|&quot;[^&]*&quot;|`[^`]*`)/g,'<span class="hl-string">$1</span>').replace(/\b(\d+)\b/g,'<span class="hl-number">$1</span>').replace(/(\/\/.*$)/gm,'<span class="hl-comment">$1</span>').replace(/(\/\*[\s\S]*?\*\/)/g,'<span class="hl-comment">$1</span>');return`<pre class="hl-code"><code>${w}</code></pre>`}function R(){return`
    .hl-code {
      margin: 0;
      padding: 16px;
      overflow: auto;
      font-family: 'SF Mono', Monaco, Consolas, monospace;
      font-size: 13px;
      line-height: 1.5;
      background: var(--bg-secondary);
      border-radius: 4px;
    }
    .hl-code code {
      font-family: inherit;
    }
    .hl-tag { color: #22863a; }
    .hl-attr { color: #6f42c1; }
    .hl-string { color: #032f62; }
    .hl-comment { color: #6a737d; font-style: italic; }
    .hl-directive { color: #d73a49; font-weight: 500; }
    .hl-interpolation { color: #e36209; }
    .hl-key { color: #005cc5; }
    .hl-number { color: #005cc5; }
    .hl-boolean { color: #d73a49; }
    .hl-keyword { color: #d73a49; }

    .dark .hl-tag { color: #85e89d; }
    .dark .hl-attr { color: #b392f0; }
    .dark .hl-string { color: #9ecbff; }
    .dark .hl-comment { color: #6a737d; }
    .dark .hl-directive { color: #f97583; }
    .dark .hl-interpolation { color: #ffab70; }
    .dark .hl-key { color: #79b8ff; }
    .dark .hl-number { color: #79b8ff; }
    .dark .hl-boolean { color: #f97583; }
    .dark .hl-keyword { color: #f97583; }
  `}function V(){return`
    .stx-code-panel {
      display: flex;
      flex-direction: column;
      height: 100%;
      border-left: 1px solid var(--border);
    }
    .stx-code-tabs {
      display: flex;
      border-bottom: 1px solid var(--border);
      background: var(--bg-secondary);
    }
    .stx-code-tabs button {
      padding: 8px 16px;
      border: none;
      background: none;
      color: var(--text-secondary);
      cursor: pointer;
      font-size: 12px;
      border-bottom: 2px solid transparent;
    }
    .stx-code-tabs button:hover {
      color: var(--text);
    }
    .stx-code-tabs button.active {
      color: var(--primary);
      border-bottom-color: var(--primary);
    }
    .stx-code-toolbar {
      display: flex;
      gap: 8px;
      padding: 8px;
      border-bottom: 1px solid var(--border);
    }
    .stx-code-toolbar button {
      padding: 4px 8px;
      border: 1px solid var(--border);
      border-radius: 4px;
      background: var(--bg);
      color: var(--text);
      font-size: 12px;
      cursor: pointer;
    }
    .stx-code-toolbar button:hover {
      background: var(--bg-secondary);
    }
    .stx-code-content {
      flex: 1;
      overflow: auto;
      padding: 0;
    }
    ${R()}
  `}function N(){return`
    window.__stxStory.copyCode = function() {
      const codeEl = document.querySelector('.hl-code code');
      if (codeEl) {
        navigator.clipboard.writeText(codeEl.textContent || '');
        // Show toast
        const toast = document.createElement('div');
        toast.className = 'stx-toast';
        toast.textContent = 'Copied to clipboard!';
        document.body.appendChild(toast);
        setTimeout(() => toast.remove(), 2000);
      }
    };
  `}function H(j){return`
    window.__stxStory.openInVSCode = function() {
      // Use VS Code URL scheme
      window.open('vscode://file/${j}', '_blank');
    };
  `}function U(j){return j.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}export{O as highlightCode,L as getStoryCode,M as getPropsJson,H as getOpenInVSCodeScript,R as getHighlightStyles,N as getCopyCodeScript,E as getComponentSource,V as getCodePanelStyles,C as generateCodePanel};
