// @bun
var{defineProperty:G,getOwnPropertyNames:Q,getOwnPropertyDescriptor:U}=Object,V=Object.prototype.hasOwnProperty;function W(j){return this[j]}var S=(j)=>{var k=(K??=new WeakMap).get(j),q;if(k)return k;if(k=G({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var v of Q(j))if(!V.call(k,v))G(k,v,{get:W.bind(j,v),enumerable:!(q=U(j,v))||q.enumerable})}return K.set(j,k),k},K;var X=(j)=>j;function Y(j,k){this[j]=X.bind(null,k)}var Z=(j,k)=>{for(var q in k)G(j,q,{get:k[q],enumerable:!0,configurable:!0,set:Y.bind(k,q)})};var M=(j,k)=>()=>(j&&(k=j(j=0)),k);var y=import.meta.require;var R={};Z(R,{processTeleportDirectives:()=>E,ensureTeleportTargets:()=>I});function $(){return`stx-teleport-${++L}`}function f(j){let k=j.split(",").map((w)=>w.trim()),q=k[0].replace(/['"]/g,""),v;for(let w=1;w<k.length;w++){let B=k[w].match(/disabled:\s*(.+)/);if(B)v=B[1].trim()}return{target:q,disabled:v}}function A(j,k){return`
    <script>
    (function() {
      const source = document.getElementById('${j}');
      if (!source) return;

      // Get the content template up-front so we can hold a reference for the
      // retry path. (template.content is moved out by cloneNode below.)
      const template = source.querySelector('template');
      if (!template) return;

      function mount(targetEl) {
        // Clone the template content and wrap it for tracking.
        const content = template.content.cloneNode(true);
        const wrapper = document.createElement('div');
        wrapper.setAttribute('data-teleport-from', '${j}');
        wrapper.appendChild(content);

        targetEl.appendChild(wrapper);

        // Remove the source placeholder
        source.remove();

        wrapper.dispatchEvent(new CustomEvent('teleport:mounted', {
          bubbles: true,
          detail: { sourceId: '${j}', target: '${k}' }
        }));
      }

      // The teleport script runs inline at the position it's emitted. If the
      // target is declared later in the same render pass (e.g. by a layout
      // shell whose onMount creates the portal root), the first lookup
      // misses. Pre-fix (stacksjs/stx#1728) the script bailed with a warning
      // and never tried again. Now retry once via requestAnimationFrame so
      // targets that land in the same paint cycle still work. A second
      // miss is still a warning \u2014 we don't loop forever.
      const firstEl = document.querySelector('${k}');
      if (firstEl) { mount(firstEl); return; }

      requestAnimationFrame(function() {
        const retryEl = document.querySelector('${k}');
        if (retryEl) { mount(retryEl); return; }
        console.warn('[stx] Teleport target not found: ${k}');
      });
    })();
    </script>
  `}function E(j,k,q){L=0;let v=/@teleport\s*\(([^)]+)\)\s*([\s\S]*?)@endteleport/g;return j.replace(v,(w,B,N)=>{let H=$(),{target:O,disabled:z}=f(B),J=N.trim();if(z)try{let F=!1;if(z==="true")F=!0;else if(z==="false")F=!1;else if(z in k)F=Boolean(k[z]);if(F)return`<div class="stx-teleport-inline" data-teleport-disabled>${J}</div>`}catch{}let P=A(H,O);return`
      <div id="${H}" class="stx-teleport-source" style="display: none;">
        <template>${J}</template>
      </div>
      ${P}
    `})}function I(){return`
    <script>
    (function() {
      // Common teleport targets
      const targets = ['#stx-modals', '#stx-tooltips', '#stx-notifications'];

      targets.forEach(selector => {
        const id = selector.slice(1); // Remove #
        if (!document.getElementById(id)) {
          const el = document.createElement('div');
          el.id = id;
          el.setAttribute('data-teleport-container', '');
          document.body.appendChild(el);
        }
      });
    })();
    </script>
  `}var L=0;export{E as processTeleportDirectives,I as ensureTeleportTargets};
