// @bun
var{defineProperty:Z,getOwnPropertyNames:g,getOwnPropertyDescriptor:v}=Object,u=Object.prototype.hasOwnProperty;function x(q){return this[q]}var qj=(q)=>{var j=(E??=new WeakMap).get(q),w;if(j)return j;if(j=Z({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var z of g(q))if(!u.call(j,z))Z(j,z,{get:x.bind(q,z),enumerable:!(w=v(q,z))||w.enumerable})}return E.set(q,j),j},E;var y=(q)=>q;function m(q,j){this[q]=y.bind(null,j)}var I=(q,j)=>{for(var w in j)Z(q,w,{get:j[w],enumerable:!0,configurable:!0,set:m.bind(j,w)})};var c=(q,j)=>()=>(q&&(j=q(q=0)),j);var wj=import.meta.require;function V(){return`<script data-stx-hydration-runtime>
(function() {
  'use strict';

  var stxIslands = window.__stxIslands = window.__stxIslands || {
    _registry: {},
    _hydrated: new Set(),

    register: function(name, loader) {
      this._registry[name] = loader;
    },

    hydrateIsland: function(el) {
      var id = el.getAttribute('data-island');
      if (!id || this._hydrated.has(id)) return Promise.resolve();
      this._hydrated.add(id);

      var componentName = el.getAttribute('data-component');
      var propsScript = el.querySelector('script[data-island-props="' + id + '"]');
      var props = {};
      if (propsScript) {
        try { props = JSON.parse(propsScript.textContent || '{}'); }
catch (e) {}
      }

      var loader = componentName ? this._registry[componentName] : null;

      if (loader) {
        return Promise.resolve(typeof loader === 'function' ? loader() : loader)
          .then(function(mod) {
            var comp = mod && mod.default ? mod.default : mod;
            if (comp && comp.hydrate) {
              return comp.hydrate(el, props);
            }
else if (comp && comp.mount) {
              return comp.mount(el, props);
            }
          })
          .then(function() {
            el.classList.add('hydrated');
            el.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
          })
          .catch(function(err) {
            console.error('[stx] Hydration failed for island:', id, err);
            el.classList.add('hydrated');
            el.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
          });
      }

      // No loader registered \u2014 just mark as hydrated (CSS-only island)
      el.classList.add('hydrated');
      el.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
      return Promise.resolve();
    },

    _setupStrategy: function(el) {
      var self = this;
      var strategy = el.getAttribute('data-strategy') || 'load';

      switch (strategy) {
        case 'load':
          self.hydrateIsland(el);
          break;

        case 'idle':
          if ('requestIdleCallback' in window) {
            requestIdleCallback(function() { self.hydrateIsland(el); }, { timeout: 2000 });
          }
else {
            setTimeout(function() { self.hydrateIsland(el); }, 200);
          }
          break;

        case 'visible':
          if ('IntersectionObserver' in window) {
            var rootMargin = el.getAttribute('data-root-margin') || '0px';
            var threshold = parseFloat(el.getAttribute('data-threshold') || '0') || 0;
            var obs = new IntersectionObserver(function(entries) {
              entries.forEach(function(entry) {
                if (entry.isIntersecting) {
                  obs.disconnect();
                  self.hydrateIsland(el);
                }
              });
            }, { rootMargin: rootMargin, threshold: threshold });
            obs.observe(el);
          }
else {
            self.hydrateIsland(el);
          }
          break;

        case 'media':
          var mediaQuery = el.getAttribute('data-media') || '(min-width: 768px)';
          var mq = window.matchMedia(mediaQuery);
          if (mq.matches) {
            self.hydrateIsland(el);
          }
else {
            var handler = function(e) {
              if (e.matches) {
                mq.removeEventListener('change', handler);
                self.hydrateIsland(el);
              }
            };
            mq.addEventListener('change', handler);
          }
          break;

        case 'hover':
          var events = ['mouseenter', 'focusin', 'touchstart'];
          var hoverHandler = function() {
            events.forEach(function(e) { el.removeEventListener(e, hoverHandler); });
            self.hydrateIsland(el);
          };
          events.forEach(function(e) {
            el.addEventListener(e, hoverHandler, { once: true, passive: true });
          });
          break;

        case 'event':
          var eventName = el.getAttribute('data-event') || 'stx:activate';
          window.addEventListener(eventName, function evtHandler(e) {
            if (!e.detail || e.detail.id === el.getAttribute('data-island') || e.detail.id === '*') {
              window.removeEventListener(eventName, evtHandler);
              self.hydrateIsland(el);
            }
          });
          break;

        case 'only':
          var tmpl = el.querySelector('template[data-client-content]');
          if (tmpl) {
            el.innerHTML = tmpl.innerHTML;
          }
          el.classList.add('hydrated');
          break;

        default:
          self.hydrateIsland(el);
      }
    },

    initIslands: function() {
      var self = this;
      var islands = document.querySelectorAll('.stx-island:not(.hydrated)');
      islands.forEach(function(el) {
        self._setupStrategy(el);
      });
    }
  };

  // Auto-init on DOMContentLoaded
  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', function() { stxIslands.initIslands(); });
  }
else {
    stxIslands.initIslands();
  }
})();
</script>`}function Fj(q){if(q.size===0)return"";return`<script data-stx-island-manifest>
(function() {
  if (!window.__stxIslands) return;
${Array.from(q.entries()).map(([w,z])=>`  window.__stxIslands.register('${w}', function() { return import('${z}'); });`).join(`
`)}
})();
</script>`}function _(q){let j=q.match(/<([A-Z][a-zA-Z0-9]+)[\s/>]/);if(j)return j[1];let w=q.match(/<([a-z][a-z0-9]*-[a-z0-9-]+)[\s/>]/);if(w)return w[1];return null}function R(q,j){let w={},z=/:([a-zA-Z_][\w-]*)\s*=\s*"([^"]+)"/g,G;while((G=z.exec(q))!==null){let K=G[1],Q=G[2];if(Q in j)w[K]=j[Q];else w[K]=Q}return w}var n={};I(n,{processStaticDirectives:()=>C,processPartialHydrationDirectives:()=>k,onHydrated:()=>b,isHydrated:()=>P,hydrateIsland:()=>M,hydrateByStrategy:()=>N,hydrateAll:()=>D,generatePartialHydrationCSS:()=>A,generateIslandManifest:()=>H,default:()=>s,createIslandRegistry:()=>f});function f(){let q=new Map;return{islands:q,register(j){q.set(j.id,j)},get(j){return q.get(j)},async hydrate(j){let w=q.get(j);if(!w||w.hydrated)return;if(w.hydrated=!0,typeof window<"u"&&typeof window.dispatchEvent==="function")window.dispatchEvent(new CustomEvent("stx:hydrate",{detail:{id:j,component:w.component}}))},async hydrateAll(){let j=Array.from(q.values()).filter((w)=>!w.hydrated).map((w)=>this.hydrate(w.id));await Promise.all(j)}}}function r(q){return`
    <script data-hydrate="${q}">
      (function() {
        const island = document.querySelector('[data-island="${q}"]');
        if (!island) return;

        // Immediately hydrate
        island.classList.add('hydrated');
        island.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
      })();
    </script>
  `}function l(q,j){let w=j.timeout||2000,z=j.priority||"low";return`
    <script data-hydrate="${q}">
      (function() {
        const island = document.querySelector('[data-island="${q}"]');
        if (!island) return;

        function hydrate() {
          if (island.classList.contains('hydrated')) return;
          island.classList.add('hydrated');
          island.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
        }

        if ('requestIdleCallback' in window) {
          const idleOptions = { timeout: ${w} };
          ${z==="high"?"requestIdleCallback(hydrate, idleOptions);":`
          // Low priority: wait for multiple idle periods
          let idleCount = 0;
          function waitForIdle() {
            requestIdleCallback((deadline) => {
              if (deadline.didTimeout || ++idleCount >= 2) {
                hydrate();
              }
else {
                waitForIdle();
              }
            }, idleOptions);
          }
          waitForIdle();
          `}
        }
else {
          // Fallback for browsers without requestIdleCallback
          setTimeout(hydrate, ${w});
        }
      })();
    </script>
  `}function o(q,j){let w=j.rootMargin||"0px",z=j.threshold||0;return`
    <script data-hydrate="${q}">
      (function() {
        const island = document.querySelector('[data-island="${q}"]');
        if (!island) return;

        function hydrate() {
          if (island.classList.contains('hydrated')) return;
          island.classList.add('hydrated');
          island.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
        }

        if ('IntersectionObserver' in window) {
          const observer = new IntersectionObserver((entries) => {
            entries.forEach((entry) => {
              if (entry.isIntersecting) {
                observer.disconnect();
                hydrate();
              }
            });
          }, {
            rootMargin: '${w}',
            threshold: ${JSON.stringify(z)}
          });

          observer.observe(island);
        }
else {
          // Fallback: hydrate on load
          hydrate();
        }
      })();
    </script>
  `}function d(q,j){let w=j.media||"(min-width: 768px)";return`
    <script data-hydrate="${q}">
      (function() {
        const island = document.querySelector('[data-island="${q}"]');
        if (!island) return;

        function hydrate() {
          if (island.classList.contains('hydrated')) return;
          island.classList.add('hydrated');
          island.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
        }

        const mediaQuery = window.matchMedia('${w}');

        function handleMediaChange(e) {
          if (e.matches) {
            mediaQuery.removeEventListener('change', handleMediaChange);
            hydrate();
          }
        }

        if (mediaQuery.matches) {
          hydrate();
        }
else {
          mediaQuery.addEventListener('change', handleMediaChange);
        }
      })();
    </script>
  `}function i(q){return`
    <script data-hydrate="${q}">
      (function() {
        const island = document.querySelector('[data-island="${q}"]');
        if (!island) return;

        function hydrate() {
          if (island.classList.contains('hydrated')) return;
          island.classList.add('hydrated');
          island.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
        }

        // Hydrate on first interaction
        const events = ['mouseenter', 'focusin', 'touchstart'];
        const handler = () => {
          events.forEach(e => island.removeEventListener(e, handler));
          hydrate();
        };

        events.forEach(e => island.addEventListener(e, handler, { once: true, passive: true }));
      })();
    </script>
  `}function a(q,j){let w=j.event||"stx:activate";return`
    <script data-hydrate="${q}">
      (function() {
        const island = document.querySelector('[data-island="${q}"]');
        if (!island) return;

        function hydrate() {
          if (island.classList.contains('hydrated')) return;
          island.classList.add('hydrated');
          island.dispatchEvent(new CustomEvent('stx:hydrated', { bubbles: true }));
        }

        // Listen for custom event
        window.addEventListener('${w}', function handler(e) {
          if (!e.detail || e.detail.id === '${q}' || e.detail.id === '*') {
            window.removeEventListener('${w}', handler);
            hydrate();
          }
        });
      })();
    </script>
  `}function k(q,j={},w){let z=q,G=!1,K=/@client:(load|idle|visible|media|only|hover|event)/i.test(q);if(z=W(z,"load",j),z=W(z,"idle",j),z=W(z,"visible",j),z=W(z,"media",j),z=e(z),z=W(z,"hover",j),z=W(z,"event",j),G=K&&z!==q,G)z+=`
`+V();return z}function W(q,j,w){let z=new RegExp(`@client:${j}(?:\\s*\\(([^)]*)\\))?\\s*([\\s\\S]*?)@endclient`,"gi");return q.replace(z,(G,K,Q)=>{let F={strategy:j};if(K)try{let h=K.split(",").map((X)=>X.trim());for(let X of h){let[O,B]=X.split(":").map((Y)=>Y.trim());if(O&&B){let Y=B.replace(/^['"]|['"]$/g,"");F[O]=Y}}}catch{}let J=`island-${Math.random().toString(36).substring(2,9)}`,$=_(Q.trim()),L=R(Q.trim(),w),U=[];if(F.rootMargin)U.push(`data-root-margin="${F.rootMargin}"`);if(F.threshold!==void 0)U.push(`data-threshold="${F.threshold}"`);if(F.media)U.push(`data-media="${F.media}"`);if(F.event)U.push(`data-event="${F.event}"`);if($)U.push(`data-component="${$}"`);let S=Object.keys(L).length>0?`
  <script type="application/json" data-island-props="${J}">${JSON.stringify(L)}</script>`:"",T="";switch(j){case"load":T=r(J);break;case"idle":T=l(J,F);break;case"visible":T=o(J,F);break;case"media":T=d(J,F);break;case"hover":T=i(J);break;case"event":T=a(J,F);break}return`
      <div data-island="${J}"
           data-strategy="${j}"
           ${U.join(`
           `)}
           class="stx-island"
           style="contents;">
        ${Q.trim()}${S}
      </div>
      ${T}
    `})}function e(q){let j=/@client:only\s*([\s\S]*?)@endclient/gi;return q.replace(j,(w,z)=>{let G=`island-only-${Math.random().toString(36).substring(2,9)}`;return`
      <div data-island="${G}"
           data-strategy="only"
           class="stx-island stx-client-only">
        <!-- Client-only content will be rendered here -->
        <template data-client-content>${z.trim()}</template>
      </div>
      <script data-hydrate="${G}">
        (function() {
          const island = document.querySelector('[data-island="${G}"]');
          if (!island) return;

          const template = island.querySelector('template[data-client-content]');
          if (template) {
            island.innerHTML = template.innerHTML;
            island.classList.add('hydrated');
          }
        })();
      </script>
    `})}function A(){return`
    /* Island base styles */
    .stx-island {
      display: contents;
    }

    /* Pre-hydration state */
    .stx-island:not(.hydrated) {
      /* Optional: add loading indicator */
    }

    /* Hydrated state */
    .stx-island.hydrated {
      /* Island is now interactive */
    }

    /* Client-only placeholder */
    .stx-client-only:not(.hydrated) {
      min-height: 50px;
      background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
      background-size: 200% 100%;
      animation: island-shimmer 1.5s infinite;
    }

    @keyframes island-shimmer {
      0% { background-position: 200% 0; }
      100% { background-position: -200% 0; }
    }

    /* Hydration transition */
    .stx-island {
      transition: opacity 0.2s ease-out;
    }

    .stx-island:not(.hydrated) {
      opacity: 0.7;
    }

    .stx-island.hydrated {
      opacity: 1;
    }
  `}function M(q){if(typeof window>"u")return;let j=document.querySelector(`[data-island="${q}"]`);if(!j||j.classList.contains("hydrated"))return;j.classList.add("hydrated"),j.dispatchEvent(new CustomEvent("stx:hydrated",{bubbles:!0}))}function N(q){if(typeof window>"u")return;document.querySelectorAll(`[data-strategy="${q}"]:not(.hydrated)`).forEach((w)=>{w.classList.add("hydrated"),w.dispatchEvent(new CustomEvent("stx:hydrated",{bubbles:!0}))})}function D(){if(typeof window>"u")return;document.querySelectorAll(".stx-island:not(.hydrated)").forEach((j)=>{j.classList.add("hydrated"),j.dispatchEvent(new CustomEvent("stx:hydrated",{bubbles:!0}))})}function P(q){if(typeof window>"u")return!1;return document.querySelector(`[data-island="${q}"]`)?.classList.contains("hydrated")??!1}function b(q){return new Promise((j)=>{if(typeof window>"u"){j();return}let w=document.querySelector(`[data-island="${q}"]`);if(!w){j();return}if(w.classList.contains("hydrated")){j();return}w.addEventListener("stx:hydrated",()=>j(),{once:!0})})}function C(q){return q.replace(/@static\s*([\s\S]*?)@endstatic/gi,(j,w)=>{return`<div class="stx-static">${w.trim()}</div>`})}function H(q){let j=q.map((w)=>({id:w.id,component:w.component,strategy:w.options.strategy,props:w.props}));return`
    <script type="application/json" id="stx-island-manifest">
      ${JSON.stringify(j)}
    </script>
  `}var s;var t=c(()=>{s={processPartialHydrationDirectives:k,processStaticDirectives:C,generatePartialHydrationCSS:A,generateIslandManifest:H,createIslandRegistry:f,hydrateIsland:M,hydrateByStrategy:N,hydrateAll:D,isHydrated:P,onHydrated:b}});t();export{C as processStaticDirectives,k as processPartialHydrationDirectives,b as onHydrated,P as isHydrated,M as hydrateIsland,N as hydrateByStrategy,D as hydrateAll,A as generatePartialHydrationCSS,H as generateIslandManifest,s as default,f as createIslandRegistry};
