// @bun
var E=import.meta.require;var WX=`
<script>
(function() {
  'use strict';

  // Skip if already initialized or not in Craft environment
  if (window.__craftBridgeInitialized) return;
  window.__craftBridgeInitialized = true;

  // Message ID counter
  let messageId = 0;
  const generateId = () => 'msg_' + Date.now() + '_' + (++messageId);

  // Pending requests
  const pending = new Map();

  // Event listeners
  const eventListeners = new Map();

  // Configuration
  const config = {
    debug: false,
    timeout: 30000
  };

  // Send message to native
  function send(message) {
    const json = JSON.stringify(message);

    if (config.debug) {
      console.log('[Craft Bridge] Sending:', message.method, message.params);
    }

    // iOS WKWebView
    if (window.webkit?.messageHandlers?.craft) {
      window.webkit.messageHandlers.craft.postMessage(message);
      return true;
    }

    // Android WebView
    if (window.CraftBridge) {
      window.CraftBridge.postMessage(json);
      return true;
    }

    // Electron IPC
    if (window.craftIPC) {
      window.craftIPC.send('bridge-message', message);
      return true;
    }

    return false;
  }

  // Make a request and wait for response
  function request(method, params) {
    return new Promise((resolve, reject) => {
      const id = generateId();
      const timeout = setTimeout(() => {
        pending.delete(id);
        reject(new Error('Request timeout: ' + method));
      }, config.timeout);

      pending.set(id, { resolve, reject, timeout });

      const sent = send({
        id,
        type: 'request',
        method,
        params
      });

      if (!sent) {
        clearTimeout(timeout);
        pending.delete(id);
        // Return gracefully if not in Craft environment
        resolve(undefined);
      }
    });
  }

  // Handle incoming messages
  function handleMessage(event) {
    let data;
    try {
      data = event.detail || (typeof event.data === 'string' ? JSON.parse(event.data) : event.data);
    }
catch (e) {
      return;
    }

    if (!data || !data.id) return;

    if (config.debug) {
      console.log('[Craft Bridge] Received:', data);
    }

    if (data.type === 'response') {
      const req = pending.get(data.id);
      if (req) {
        clearTimeout(req.timeout);
        pending.delete(data.id);
        if (data.error) {
          req.reject(new Error(data.error.message));
        }
else {
          req.resolve(data.result);
        }
      }
    }
else if (data.type === 'event' && data.method) {
      const listeners = eventListeners.get(data.method) || [];
      listeners.forEach(fn => fn(data.params));
    }
  }

  // Listen for messages
  window.addEventListener('message', handleMessage);
  window.addEventListener('craft-bridge-message', handleMessage);

  // Check if running in Craft
  function isCraft() {
    return !!(
      window.webkit?.messageHandlers?.craft ||
      window.CraftBridge ||
      window.craftIPC
    );
  }

  // Subscribe to events
  function on(event, callback) {
    if (!eventListeners.has(event)) {
      eventListeners.set(event, []);
    }
    eventListeners.get(event).push(callback);
    return () => {
      const listeners = eventListeners.get(event);
      const idx = listeners.indexOf(callback);
      if (idx > -1) listeners.splice(idx, 1);
    };
  }

  // Build the craft API object
  window.craft = {
    // Meta
    isCraft,
    on,
    config,

    // Window API
    window: {
      show: () => request('window.show'),
      hide: () => request('window.hide'),
      close: () => request('window.close'),
      minimize: () => request('window.minimize'),
      maximize: () => request('window.maximize'),
      restore: () => request('window.restore'),
      focus: () => request('window.focus'),
      blur: () => request('window.blur'),
      setTitle: (title) => request('window.setTitle', { title }),
      setSize: (width, height) => request('window.setSize', { width, height }),
      setPosition: (x, y) => request('window.setPosition', { x, y }),
      setFullscreen: (fullscreen) => request('window.setFullscreen', { fullscreen }),
      setAlwaysOnTop: (alwaysOnTop) => request('window.setAlwaysOnTop', { alwaysOnTop }),
      getSize: () => request('window.getSize'),
      getPosition: () => request('window.getPosition'),
      isFullscreen: () => request('window.isFullscreen'),
      isMaximized: () => request('window.isMaximized'),
      isMinimized: () => request('window.isMinimized'),
      isVisible: () => request('window.isVisible'),
      center: () => request('window.center'),
      toggleFullscreen: () => request('window.toggleFullscreen'),
      startDrag: () => request('window.startDrag'),
    },

    // System Tray/Menubar API
    tray: {
      setTitle: (title) => request('tray.setTitle', { title }),
      setTooltip: (tooltip) => request('tray.setTooltip', { tooltip }),
      setIcon: (icon) => request('tray.setIcon', { icon }),
      setMenu: (menu) => request('tray.setMenu', { menu }),
      show: () => request('tray.show'),
      hide: () => request('tray.hide'),
      onClick: (callback) => on('tray.click', callback),
      onDoubleClick: (callback) => on('tray.doubleClick', callback),
      onRightClick: (callback) => on('tray.rightClick', callback),
    },

    // App API
    app: {
      quit: () => request('app.quit'),
      hide: () => request('app.hide'),
      show: () => request('app.show'),
      focus: () => request('app.focus'),
      getInfo: () => request('app.getInfo'),
      getVersion: () => request('app.getVersion'),
      getName: () => request('app.getName'),
      getPath: (name) => request('app.getPath', { name }),
      isDarkMode: () => request('app.isDarkMode'),
      getLocale: () => request('app.getLocale'),
      setBadge: (badge) => request('app.setBadge', { badge }),
      hideDockIcon: () => request('app.hideDockIcon'),
      showDockIcon: () => request('app.showDockIcon'),
      notify: (options) => request('app.notify', options),
      registerShortcut: (accelerator, callback) => {
        const id = generateId();
        on('shortcut.' + id, callback);
        return request('app.registerShortcut', { accelerator, id });
      },
      unregisterShortcut: (accelerator) => request('app.unregisterShortcut', { accelerator }),
    },

    // Dialog API
    dialog: {
      openFile: (options) => request('dialog.openFile', options),
      openFolder: (options) => request('dialog.openFolder', options),
      saveFile: (options) => request('dialog.saveFile', options),
      showAlert: (options) => request('dialog.showAlert', options),
      showConfirm: (options) => request('dialog.showConfirm', options),
      showPrompt: (options) => request('dialog.showPrompt', options),
      showColorPicker: (options) => request('dialog.showColorPicker', options),
    },

    // Clipboard API
    clipboard: {
      writeText: (text) => request('clipboard.writeText', { text }),
      readText: () => request('clipboard.readText'),
      writeHTML: (html) => request('clipboard.writeHTML', { html }),
      readHTML: () => request('clipboard.readHTML'),
      clear: () => request('clipboard.clear'),
    },

    // File System API (limited for security)
    fs: {
      readFile: (path, encoding) => request('fs.readFile', { path, encoding }),
      writeFile: (path, content, encoding) => request('fs.writeFile', { path, content, encoding }),
      exists: (path) => request('fs.exists', { path }),
      stat: (path) => request('fs.stat', { path }),
      readDir: (path) => request('fs.readDir', { path }),
      createDir: (path, recursive) => request('fs.createDir', { path, recursive }),
      remove: (path, recursive) => request('fs.remove', { path, recursive }),
    },

    // Process/Shell API (limited for security)
    process: {
      exec: (command, options) => request('process.exec', { command, ...options }),
      spawn: (command, args, options) => request('process.spawn', { command, args, ...options }),
      env: () => request('process.env'),
      cwd: () => request('process.cwd'),
      platform: () => request('process.platform'),
    },

    // Native component helpers
    components: {
      createSidebar: (config) => request('component.createSidebar', config),
      createFileBrowser: (config) => request('component.createFileBrowser', config),
      createSplitView: (config) => request('component.createSplitView', config),
      updateComponent: (id, props) => request('component.update', { componentId: id, props }),
      destroyComponent: (id) => request('component.destroy', { componentId: id }),
    }
  };

  // Dispatch ready event
  window.dispatchEvent(new CustomEvent('craft:ready', { detail: { isCraft: isCraft() } }));

  if (config.debug) {
    console.log('[Craft Bridge] Initialized, isCraft:', isCraft());
  }
})();
</script>
`;function N(U={}){let{debug:X=!1,timeout:$=30000}=U;return`
<script>
(function() {
  'use strict';

  // Skip if already initialized or not in Craft environment
  if (window.__craftBridgeInitialized) return;
  window.__craftBridgeInitialized = true;

  // Message ID counter
  let messageId = 0;
  const generateId = () => 'msg_' + Date.now() + '_' + (++messageId);

  // Pending requests
  const pending = new Map();

  // Event listeners
  const eventListeners = new Map();

  // Configuration
  const config = {
    debug: false,
    timeout: 30000
  };

  // Send message to native
  function send(message) {
    const json = JSON.stringify(message);

    if (config.debug) {
      console.log('[Craft Bridge] Sending:', message.method, message.params);
    }

    // iOS WKWebView
    if (window.webkit?.messageHandlers?.craft) {
      window.webkit.messageHandlers.craft.postMessage(message);
      return true;
    }

    // Android WebView
    if (window.CraftBridge) {
      window.CraftBridge.postMessage(json);
      return true;
    }

    // Electron IPC
    if (window.craftIPC) {
      window.craftIPC.send('bridge-message', message);
      return true;
    }

    return false;
  }

  // Make a request and wait for response
  function request(method, params) {
    return new Promise((resolve, reject) => {
      const id = generateId();
      const timeout = setTimeout(() => {
        pending.delete(id);
        reject(new Error('Request timeout: ' + method));
      }, config.timeout);

      pending.set(id, { resolve, reject, timeout });

      const sent = send({
        id,
        type: 'request',
        method,
        params
      });

      if (!sent) {
        clearTimeout(timeout);
        pending.delete(id);
        // Return gracefully if not in Craft environment
        resolve(undefined);
      }
    });
  }

  // Handle incoming messages
  function handleMessage(event) {
    let data;
    try {
      data = event.detail || (typeof event.data === 'string' ? JSON.parse(event.data) : event.data);
    }
catch (e) {
      return;
    }

    if (!data || !data.id) return;

    if (config.debug) {
      console.log('[Craft Bridge] Received:', data);
    }

    if (data.type === 'response') {
      const req = pending.get(data.id);
      if (req) {
        clearTimeout(req.timeout);
        pending.delete(data.id);
        if (data.error) {
          req.reject(new Error(data.error.message));
        }
else {
          req.resolve(data.result);
        }
      }
    }
else if (data.type === 'event' && data.method) {
      const listeners = eventListeners.get(data.method) || [];
      listeners.forEach(fn => fn(data.params));
    }
  }

  // Listen for messages
  window.addEventListener('message', handleMessage);
  window.addEventListener('craft-bridge-message', handleMessage);

  // Check if running in Craft
  function isCraft() {
    return !!(
      window.webkit?.messageHandlers?.craft ||
      window.CraftBridge ||
      window.craftIPC
    );
  }

  // Subscribe to events
  function on(event, callback) {
    if (!eventListeners.has(event)) {
      eventListeners.set(event, []);
    }
    eventListeners.get(event).push(callback);
    return () => {
      const listeners = eventListeners.get(event);
      const idx = listeners.indexOf(callback);
      if (idx > -1) listeners.splice(idx, 1);
    };
  }

  // Build the craft API object
  window.craft = {
    // Meta
    isCraft,
    on,
    config,

    // Window API
    window: {
      show: () => request('window.show'),
      hide: () => request('window.hide'),
      close: () => request('window.close'),
      minimize: () => request('window.minimize'),
      maximize: () => request('window.maximize'),
      restore: () => request('window.restore'),
      focus: () => request('window.focus'),
      blur: () => request('window.blur'),
      setTitle: (title) => request('window.setTitle', { title }),
      setSize: (width, height) => request('window.setSize', { width, height }),
      setPosition: (x, y) => request('window.setPosition', { x, y }),
      setFullscreen: (fullscreen) => request('window.setFullscreen', { fullscreen }),
      setAlwaysOnTop: (alwaysOnTop) => request('window.setAlwaysOnTop', { alwaysOnTop }),
      getSize: () => request('window.getSize'),
      getPosition: () => request('window.getPosition'),
      isFullscreen: () => request('window.isFullscreen'),
      isMaximized: () => request('window.isMaximized'),
      isMinimized: () => request('window.isMinimized'),
      isVisible: () => request('window.isVisible'),
      center: () => request('window.center'),
      toggleFullscreen: () => request('window.toggleFullscreen'),
      startDrag: () => request('window.startDrag'),
    },

    // System Tray/Menubar API
    tray: {
      setTitle: (title) => request('tray.setTitle', { title }),
      setTooltip: (tooltip) => request('tray.setTooltip', { tooltip }),
      setIcon: (icon) => request('tray.setIcon', { icon }),
      setMenu: (menu) => request('tray.setMenu', { menu }),
      show: () => request('tray.show'),
      hide: () => request('tray.hide'),
      onClick: (callback) => on('tray.click', callback),
      onDoubleClick: (callback) => on('tray.doubleClick', callback),
      onRightClick: (callback) => on('tray.rightClick', callback),
    },

    // App API
    app: {
      quit: () => request('app.quit'),
      hide: () => request('app.hide'),
      show: () => request('app.show'),
      focus: () => request('app.focus'),
      getInfo: () => request('app.getInfo'),
      getVersion: () => request('app.getVersion'),
      getName: () => request('app.getName'),
      getPath: (name) => request('app.getPath', { name }),
      isDarkMode: () => request('app.isDarkMode'),
      getLocale: () => request('app.getLocale'),
      setBadge: (badge) => request('app.setBadge', { badge }),
      hideDockIcon: () => request('app.hideDockIcon'),
      showDockIcon: () => request('app.showDockIcon'),
      notify: (options) => request('app.notify', options),
      registerShortcut: (accelerator, callback) => {
        const id = generateId();
        on('shortcut.' + id, callback);
        return request('app.registerShortcut', { accelerator, id });
      },
      unregisterShortcut: (accelerator) => request('app.unregisterShortcut', { accelerator }),
    },

    // Dialog API
    dialog: {
      openFile: (options) => request('dialog.openFile', options),
      openFolder: (options) => request('dialog.openFolder', options),
      saveFile: (options) => request('dialog.saveFile', options),
      showAlert: (options) => request('dialog.showAlert', options),
      showConfirm: (options) => request('dialog.showConfirm', options),
      showPrompt: (options) => request('dialog.showPrompt', options),
      showColorPicker: (options) => request('dialog.showColorPicker', options),
    },

    // Clipboard API
    clipboard: {
      writeText: (text) => request('clipboard.writeText', { text }),
      readText: () => request('clipboard.readText'),
      writeHTML: (html) => request('clipboard.writeHTML', { html }),
      readHTML: () => request('clipboard.readHTML'),
      clear: () => request('clipboard.clear'),
    },

    // File System API (limited for security)
    fs: {
      readFile: (path, encoding) => request('fs.readFile', { path, encoding }),
      writeFile: (path, content, encoding) => request('fs.writeFile', { path, content, encoding }),
      exists: (path) => request('fs.exists', { path }),
      stat: (path) => request('fs.stat', { path }),
      readDir: (path) => request('fs.readDir', { path }),
      createDir: (path, recursive) => request('fs.createDir', { path, recursive }),
      remove: (path, recursive) => request('fs.remove', { path, recursive }),
    },

    // Process/Shell API (limited for security)
    process: {
      exec: (command, options) => request('process.exec', { command, ...options }),
      spawn: (command, args, options) => request('process.spawn', { command, args, ...options }),
      env: () => request('process.env'),
      cwd: () => request('process.cwd'),
      platform: () => request('process.platform'),
    },

    // Native component helpers
    components: {
      createSidebar: (config) => request('component.createSidebar', config),
      createFileBrowser: (config) => request('component.createFileBrowser', config),
      createSplitView: (config) => request('component.createSplitView', config),
      updateComponent: (id, props) => request('component.update', { componentId: id, props }),
      destroyComponent: (id) => request('component.destroy', { componentId: id }),
    }
  };

  // Dispatch ready event
  window.dispatchEvent(new CustomEvent('craft:ready', { detail: { isCraft: isCraft() } }));

  if (config.debug) {
    console.log('[Craft Bridge] Initialized, isCraft:', isCraft());
  }
})();
</script>
`.replace("debug: false,",`debug: ${X},`).replace("timeout: 30000",`timeout: ${$}`)}function ZX(){return!1}function _X(U,X={}){let $=/@craft(?:\(([\s\S]*?)\))?/g;return U.replace($,(q,Y)=>{let J={};if(Y)try{J=JSON.parse(Y.replace(/'/g,'"'))}catch{try{J=Function(`return ${Y}`)()}catch{console.warn(`[stx] Invalid @craft config: ${Y}`)}}return N(J)})}function v(U,X={}){if(U.includes("__craftBridgeInitialized"))return U;let $=N(X);if(U.includes("</head>"))return U.replace("</head>",`${$}
</head>`);if(U.includes("<body"))return U.replace(/(<body[^>]*>)/,`$1
${$}`);return $+U}var YU=new Map([["craft-button",{name:"Button",zigType:"craft.Button",props:[{name:"variant",type:"string",required:!1,default:"primary"},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onclick",type:"callback",required:!1}],children:"single"}],["craft-text-input",{name:"TextInput",zigType:"craft.TextInput",props:[{name:"value",type:"string",required:!1,default:""},{name:"placeholder",type:"string",required:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-textarea",{name:"TextArea",zigType:"craft.TextArea",props:[{name:"value",type:"string",required:!1,default:""},{name:"placeholder",type:"string",required:!1},{name:"rows",type:"number",required:!1,default:3},{name:"disabled",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-checkbox",{name:"Checkbox",zigType:"craft.Checkbox",props:[{name:"checked",type:"boolean",required:!1,default:!1},{name:"label",type:"string",required:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-select",{name:"Select",zigType:"craft.Select",props:[{name:"value",type:"string",required:!1},{name:"options",type:"array",required:!0},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-slider",{name:"Slider",zigType:"craft.Slider",props:[{name:"value",type:"number",required:!1,default:0},{name:"min",type:"number",required:!1,default:0},{name:"max",type:"number",required:!1,default:100},{name:"step",type:"number",required:!1,default:1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-toggle",{name:"Toggle",zigType:"craft.Toggle",props:[{name:"checked",type:"boolean",required:!1,default:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-modal",{name:"Modal",zigType:"craft.Modal",props:[{name:"open",type:"boolean",required:!1,default:!1},{name:"title",type:"string",required:!1},{name:"closable",type:"boolean",required:!1,default:!0},{name:"onclose",type:"callback",required:!1}],children:"multiple"}],["craft-alert",{name:"Alert",zigType:"craft.Alert",props:[{name:"variant",type:"string",required:!1,default:"info"},{name:"title",type:"string",required:!1},{name:"dismissible",type:"boolean",required:!1,default:!1}],children:"single"}],["craft-progress",{name:"ProgressBar",zigType:"craft.ProgressBar",props:[{name:"value",type:"number",required:!1,default:0},{name:"max",type:"number",required:!1,default:100},{name:"indeterminate",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-spinner",{name:"Spinner",zigType:"craft.Spinner",props:[{name:"size",type:"number",required:!1,default:24}],children:"none"}],["craft-avatar",{name:"Avatar",zigType:"craft.Avatar",props:[{name:"src",type:"string",required:!1},{name:"alt",type:"string",required:!1},{name:"size",type:"number",required:!1,default:40}],children:"none"}],["craft-badge",{name:"Badge",zigType:"craft.Badge",props:[{name:"variant",type:"string",required:!1,default:"default"}],children:"single"}],["craft-card",{name:"Card",zigType:"craft.Card",props:[{name:"padding",type:"number",required:!1,default:16}],children:"multiple"}],["craft-accordion",{name:"Accordion",zigType:"craft.Accordion",props:[{name:"title",type:"string",required:!0},{name:"open",type:"boolean",required:!1,default:!1}],children:"multiple"}],["craft-tabs",{name:"TabView",zigType:"craft.TabView",props:[{name:"activeTab",type:"number",required:!1,default:0},{name:"ontabchange",type:"callback",required:!1}],children:"multiple"}],["craft-tooltip",{name:"Tooltip",zigType:"craft.Tooltip",props:[{name:"content",type:"string",required:!0},{name:"position",type:"string",required:!1,default:"top"}],children:"single"}],["craft-date-picker",{name:"DatePicker",zigType:"craft.DatePicker",props:[{name:"value",type:"string",required:!1},{name:"min",type:"string",required:!1},{name:"max",type:"string",required:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-time-picker",{name:"TimePicker",zigType:"craft.TimePicker",props:[{name:"value",type:"string",required:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-color-picker",{name:"ColorPicker",zigType:"craft.ColorPicker",props:[{name:"value",type:"color",required:!1,default:"#000000"},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-data-table",{name:"DataTable",zigType:"craft.DataTable",props:[{name:"data",type:"array",required:!0},{name:"columns",type:"array",required:!0},{name:"sortable",type:"boolean",required:!1,default:!1},{name:"paginated",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-virtual-list",{name:"VirtualList",zigType:"craft.VirtualList",props:[{name:"items",type:"array",required:!0},{name:"itemHeight",type:"number",required:!1,default:48},{name:"renderItem",type:"callback",required:!0}],children:"none"}],["craft-tree-view",{name:"TreeView",zigType:"craft.TreeView",props:[{name:"data",type:"object",required:!0},{name:"expandable",type:"boolean",required:!1,default:!0}],children:"none"}]]);async function wX(U,X={}){let $=performance.now(),q={target:X.target||"universal",format:X.format||"zig",optimize:X.optimize??!0,treeShake:X.treeShake??!0,hotReload:X.hotReload??!1,debug:X.debug??!1,sourceMaps:X.sourceMaps??!1,bundle:X.bundle??!0,minify:X.minify??!1,components:X.components||YU},Y=typeof U==="string"?QU(U):U,J=KU(Y.tree,q),G=AU(J),Q=q.treeShake?OU(J,G):J,K=new Map;if(q.target==="universal"){let L=["macos","windows","linux","ios","android"];for(let B of L){let A=P(Q,{...q,target:B});K.set(B,A)}}else{let L=P(Q,q);K.set(q.target,L)}let W=VU(Q,q,K),_=IU(Y,Q,q),F={compilationTime:performance.now()-$,totalComponents:S(Y.tree),nativeComponents:C(Q),webComponents:S(Y.tree)-C(Q),bundleSize:W.length,treeShakenSize:q.treeShake?EU(J,Q):W.length,warnings:[],errors:[]},w;if(q.sourceMaps)w=MU(Y,Q);return{code:W,platformCode:K,dependencies:G,manifest:_,sourceMaps:w,stats:F}}function QU(U){let X={type:"fragment",children:[]},$=U.match(/<body[^>]*>([\s\S]*?)<\/body>/i),q=$?$[1]:U;return h(q,X),{id:s(),hash:l(U),tree:X,scripts:bU(U),styles:jU(U),staticParts:new Map,dynamicParts:new Map,dependencies:[],metadata:{hasSlots:!1,hasDynamicContent:U.includes("{{"),hasEventHandlers:U.includes("onclick")||U.includes("onchange"),hasAsyncContent:!1,componentCount:0,maxDepth:0,estimatedSize:U.length}}}function h(U,X){let $=/<(@?[\w-]+)([^>]*)(?:\/>|>([\s\S]*?)<\/\1>)/g,q;while((q=$.exec(U))!==null){let[,Y,J,G]=q,Q=Y.startsWith("@craft-"),K={type:Q?"component":"element",tag:Q?Y.slice(1):Y,props:GU(J),children:[],componentName:Q?Y.slice(1):void 0};if(G){let W=G.replace(/<[^>]+>/g,"").trim();if(W)K.children=K.children??[],K.children.push({type:"text",text:W});h(G,K)}X.children=X.children??[],X.children.push(K)}}function GU(U){let X={},$=/([\w-:@]+)(?:=["']([^"']*)["'])?/g,q;while((q=$.exec(U))!==null){let[,Y,J]=q;X[Y]=J??!0}return X}function KU(U,X){return g(U,X)}function g(U,X){let $=U.componentName?X.components?.get(U.componentName):void 0,q="craft.View";if($)q=$.zigType;else if(U.type==="text")q="craft.Text";else if(U.tag)q=WU(U.tag);let Y={};if(U.props)for(let[K,W]of Object.entries(U.props))Y[K]=ZU(W);let J=[];if(U.children)for(let K of U.children)J.push(g(K,X));let G=new Map;if(U.props){for(let[K,W]of Object.entries(U.props))if(K.startsWith("on")&&typeof W==="string")G.set(K.slice(2).toLowerCase(),W)}let Q=FU(U);return{type:_U(U,$),zigType:q,props:Y,children:J,events:G,styles:Q,id:U.hydrationKey,key:U.props?.key}}function WU(U){return{div:"craft.View",span:"craft.Text",p:"craft.Text",h1:"craft.Text",h2:"craft.Text",h3:"craft.Text",h4:"craft.Text",h5:"craft.Text",h6:"craft.Text",button:"craft.Button",input:"craft.TextInput",textarea:"craft.TextArea",select:"craft.Select",img:"craft.Image",a:"craft.Link",ul:"craft.List",ol:"craft.List",li:"craft.ListItem",form:"craft.Form",label:"craft.Label",nav:"craft.View",header:"craft.View",footer:"craft.View",main:"craft.View",section:"craft.View",article:"craft.View",aside:"craft.View"}[U.toLowerCase()]||"craft.View"}function ZU(U){if(typeof U==="string"){if(U.startsWith("{{")&&U.endsWith("}}"))return{type:"binding",path:U.slice(2,-2).trim()};if(U.includes("(")&&U.includes(")"))return{type:"callback",handler:U};return{type:"literal",value:U}}if(typeof U==="number"||typeof U==="boolean")return{type:"literal",value:U};return{type:"literal",value:String(U)}}function _U(U,X){if(X){let q=X.name.toLowerCase();if(q.includes("button"))return"button";if(q.includes("input")||q.includes("text"))return"input";if(q.includes("image")||q.includes("avatar"))return"image";if(q.includes("list")||q.includes("table"))return"list";if(q.includes("scroll"))return"scroll";return"custom"}if(U.type==="text")return"text";let $=U.tag?.toLowerCase();if($==="button")return"button";if($==="input"||$==="textarea")return"input";if($==="img")return"image";if($==="ul"||$==="ol")return"list";return"view"}function FU(U){let X=U.props?.style,$={},q={};if(X){let Y=X.split(";").filter(Boolean);for(let J of Y){let[G,Q]=J.split(":").map((K)=>K.trim());if(!G||!Q)continue;switch(G){case"display":$.display=Q;break;case"flex-direction":$.flexDirection=Q;break;case"justify-content":$.justifyContent=wU(Q);break;case"align-items":$.alignItems=LU(Q);break;case"gap":$.gap=Number.parseInt(Q,10);break;case"padding":$.padding=Number.parseInt(Q,10);break;case"margin":$.margin=Number.parseInt(Q,10);break;case"width":$.width=Q==="auto"?"auto":Number.parseInt(Q,10);break;case"height":$.height=Q==="auto"?"auto":Number.parseInt(Q,10);break;case"background-color":case"background":q.backgroundColor=Q;break;case"border-color":q.borderColor=Q;break;case"border-width":q.borderWidth=Number.parseInt(Q,10);break;case"border-radius":q.borderRadius=Number.parseInt(Q,10);break;case"opacity":q.opacity=Number.parseFloat(Q);break}}}return{layout:$,appearance:q}}function wU(U){return{"flex-start":"start","flex-end":"end",center:"center","space-between":"between","space-around":"around"}[U]||"start"}function LU(U){return{"flex-start":"start","flex-end":"end",center:"center",stretch:"stretch"}[U]||"start"}function AU(U){let X=[],$=new Set;function q(Y,J){let G=Y.id||s();if($.has(G))return;$.add(G);let Q={id:G,type:"component",path:Y.zigType,dependencies:J?[J]:[],size:f(Y),isStatic:BU(Y)};X.push(Q);for(let K of Y.children)q(K,G)}return q(U),X}function f(U){let X=100;return X+=Object.keys(U.props).length*20,X+=U.events.size*50,X}function BU(U){for(let X of Object.values(U.props))if(X.type!=="literal")return!1;return U.events.size===0}function OU(U,X){return U}function EU(U,X){let $=0;function q(Y){$+=f(Y);for(let J of Y.children)q(J)}return q(X),$}function P(U,X){switch(X.format){case"zig":return u(U,X);case"typescript":return HU(U,X);case"json":return JSON.stringify(U,null,X.minify?0:2);default:return u(U,X)}}function u(U,X){let $=[];return $.push("// Auto-generated by stx compiler"),$.push("// Target: "+X.target),$.push(""),$.push('const std = @import("std");'),$.push('const craft = @import("craft");'),$.push(""),$.push("pub fn render(allocator: std.mem.Allocator) !craft.Element {"),$.push("    return try build(allocator);"),$.push("}"),$.push(""),m(U,$,0),$.join(`
`)}function m(U,X,$){let q="    ".repeat($);if($===0)X.push("fn build(allocator: std.mem.Allocator) !craft.Element {");let Y=`node_${$}`;X.push(`${q}    var ${Y} = try ${U.zigType}.init(allocator);`);for(let[J,G]of Object.entries(U.props))if(G.type==="literal"){let Q=typeof G.value==="string"?`"${G.value}"`:String(G.value);X.push(`${q}    ${Y}.set${zU(J)}(${Q});`)}for(let J=0;J<U.children.length;J++){let G=U.children[J];if(G.type==="text"){let Q=G.props.text?.type==="literal"?String(G.props.text.value):"";X.push(`${q}    try ${Y}.addChild(try craft.Text.init(allocator, "${Q}"));`)}else m(G,X,$+1),X.push(`${q}    try ${Y}.addChild(node_${$+1});`)}if($===0)X.push(`    return ${Y}.element();`),X.push("}")}function HU(U,X){let $=[];return $.push("// Auto-generated by stx compiler"),$.push("// Target: "+X.target),$.push(""),$.push('import { Craft } from "@stacksjs/craft";'),$.push(""),$.push("export function render(): Craft.Element {"),$.push("  return "+d(U,1)+";"),$.push("}"),$.join(`
`)}function d(U,X){let $="  ".repeat(X),q=[];for(let[Q,K]of Object.entries(U.props))if(K.type==="literal"){let W=typeof K.value==="string"?`"${K.value}"`:String(K.value);q.push(`${Q}: ${W}`)}let Y=q.length>0?`{ ${q.join(", ")} }`:"{}",J=U.children.map((Q)=>Q.type==="text"?`"${Q.props.text?.type==="literal"?Q.props.text.value:""}"`:d(Q,X+1)),G=J.length>0?`,
${$}  [${J.join(`,
${$}    `)}]`:"";return`Craft.create("${U.zigType}", ${Y}${G})`}function VU(U,X,$){if(X.target==="universal"){let q=[];q.push("// Universal entry point"),q.push("");for(let[Y,J]of $)q.push(`// --- ${Y.toUpperCase()} ---`),q.push(`#if ${Y.toUpperCase()}`),q.push(J),q.push("#endif"),q.push("");return q.join(`
`)}return $.get(X.target)||P(U,X)}function IU(U,X,$){let q=[];function Y(J){q.push({name:J.zigType,hash:l(JSON.stringify(J.props)),props:Object.keys(J.props),events:Array.from(J.events.keys()),slots:[],isNative:J.zigType.startsWith("craft.")});for(let G of J.children)Y(G)}return Y(X),{version:"1.0.0",components:q,entry:U.id,assets:[],styles:U.styles}}function MU(U,X){return JSON.stringify({version:3,file:"output.zig",sources:["input.stx"],mappings:""})}var RU=0;function s(){return`id_${++RU}`}function l(U){let X=0;for(let $=0;$<U.length;$++){let q=U.charCodeAt($);X=(X<<5)-X+q,X=X&X}return Math.abs(X).toString(36)}function zU(U){return U.charAt(0).toUpperCase()+U.slice(1)}function bU(U){let X=[],$=/<script[^>]*>([\s\S]*?)<\/script>/gi,q;while((q=$.exec(U))!==null)X.push(q[1]);return X}function jU(U){let X=[],$=/<style[^>]*>([\s\S]*?)<\/style>/gi,q;while((q=$.exec(U))!==null)X.push(q[1]);return X}function S(U){let X=U.type==="component"?1:0;if(U.children)for(let $ of U.children)X+=S($);return X}function C(U){let X=U.zigType.startsWith("craft.")?1:0;for(let $ of U.children)X+=C($);return X}function LX(U){return{start:async()=>{console.log("[craft-compiler] Hot reload server started")},stop:async()=>{console.log("[craft-compiler] Hot reload server stopped")},notifyChange:(X)=>{console.log(`[craft-compiler] File changed: ${X}`)}}}var y={button:{nativeType:"craft-button",fallbackTag:"button",fallbackClasses:"craft-button",nativeProps:["variant","size","disabled","loading"]},"text-input":{nativeType:"craft-text-input",fallbackTag:"input",fallbackClasses:"craft-text-input",nativeProps:["placeholder","value","type","disabled","readonly"]},textarea:{nativeType:"craft-textarea",fallbackTag:"textarea",fallbackClasses:"craft-textarea",nativeProps:["placeholder","value","rows","disabled","readonly"]},checkbox:{nativeType:"craft-checkbox",fallbackTag:"input",fallbackClasses:"craft-checkbox",nativeProps:["checked","disabled","label"],render:(U,X)=>{let $=U.checked?"checked":"",q=U.disabled?"disabled":"";return`<label class="craft-checkbox-wrapper">
        <input type="checkbox" class="craft-checkbox" ${$} ${q}>
        <span class="craft-checkbox-label">${X||U.label||""}</span>
      </label>`}},radio:{nativeType:"craft-radio",fallbackTag:"input",fallbackClasses:"craft-radio",nativeProps:["checked","disabled","name","value","label"]},select:{nativeType:"craft-select",fallbackTag:"select",fallbackClasses:"craft-select",nativeProps:["value","disabled","options","placeholder"]},slider:{nativeType:"craft-slider",fallbackTag:"input",fallbackClasses:"craft-slider",nativeProps:["value","min","max","step","disabled"],render:(U,X)=>{let $=U.min??0,q=U.max??100,Y=U.step??1,J=U.value??50,G=U.disabled?"disabled":"";return`<input type="range" class="craft-slider" min="${$}" max="${q}" step="${Y}" value="${J}" ${G}>`}},label:{nativeType:"craft-label",fallbackTag:"span",fallbackClasses:"craft-label",nativeProps:["text","for"]},badge:{nativeType:"craft-badge",fallbackTag:"span",fallbackClasses:"craft-badge",nativeProps:["variant","size"]},avatar:{nativeType:"craft-avatar",fallbackTag:"div",fallbackClasses:"craft-avatar",nativeProps:["src","alt","size","fallback"],render:(U,X)=>{let $=U.size||40,q=U.src,Y=String(U.alt||""),J=U.fallback||(Y?Y.charAt(0).toUpperCase():"?");if(q)return`<img class="craft-avatar" src="${q}" alt="${Y}" style="width:${$}px;height:${$}px;border-radius:50%">`;return`<div class="craft-avatar craft-avatar-fallback" style="width:${$}px;height:${$}px;border-radius:50%;display:flex;align-items:center;justify-content:center">${J}</div>`}},progress:{nativeType:"craft-progress",fallbackTag:"div",fallbackClasses:"craft-progress",nativeProps:["value","max","variant"],render:(U,X)=>{let $=Number(U.value)||0,q=Number(U.max)||100;return`<div class="craft-progress"><div class="craft-progress-bar" style="width:${Math.min(100,Math.max(0,$/q*100))}%"></div></div>`}},spinner:{nativeType:"craft-spinner",fallbackTag:"div",fallbackClasses:"craft-spinner",nativeProps:["size"],render:(U,X)=>{let $=U.size||24;return`<div class="craft-spinner" style="width:${$}px;height:${$}px"></div>`}},card:{nativeType:"craft-card",fallbackTag:"div",fallbackClasses:"craft-card",nativeProps:["title","subtitle","variant"]},modal:{nativeType:"craft-modal",fallbackTag:"dialog",fallbackClasses:"craft-modal",nativeProps:["open","title","closable","size"],render:(U,X)=>{let $=U.open?"open":"",q=U.title||"";return`<dialog class="craft-modal" ${$}>
        <div class="craft-modal-content">
          ${q?`<div class="craft-modal-header"><h2>${q}</h2></div>`:""}
          <div class="craft-modal-body">${X}</div>
        </div>
      </dialog>`}},tabs:{nativeType:"craft-tabs",fallbackTag:"div",fallbackClasses:"craft-tabs",nativeProps:["activeTab","tabs"]},accordion:{nativeType:"craft-accordion",fallbackTag:"details",fallbackClasses:"craft-accordion",nativeProps:["open","title"],render:(U,X)=>{let $=U.open?"open":"",q=U.title||"Details";return`<details class="craft-accordion" ${$}>
        <summary class="craft-accordion-header">${q}</summary>
        <div class="craft-accordion-content">${X}</div>
      </details>`}},divider:{nativeType:"craft-divider",fallbackTag:"hr",fallbackClasses:"craft-divider",nativeProps:["orientation","variant"]},table:{nativeType:"craft-table",fallbackTag:"table",fallbackClasses:"craft-table",nativeProps:["columns","rows","sortable","selectable"]},list:{nativeType:"craft-list",fallbackTag:"ul",fallbackClasses:"craft-list",nativeProps:["items","selectable"]},tree:{nativeType:"craft-tree",fallbackTag:"div",fallbackClasses:"craft-tree",nativeProps:["nodes","expandable","selectable"]},alert:{nativeType:"craft-alert",fallbackTag:"div",fallbackClasses:"craft-alert",nativeProps:["variant","title","dismissible"],render:(U,X)=>{let $=U.variant||"info",q=U.title||"";return`<div class="craft-alert craft-alert-${$}" role="alert">
        ${q?`<div class="craft-alert-title">${q}</div>`:""}
        <div class="craft-alert-content">${X}</div>
      </div>`}},toast:{nativeType:"craft-toast",fallbackTag:"div",fallbackClasses:"craft-toast",nativeProps:["variant","duration","position"]},tooltip:{nativeType:"craft-tooltip",fallbackTag:"span",fallbackClasses:"craft-tooltip",nativeProps:["content","position"],render:(U,X)=>{let $=U.content||"",q=U.position||"top";return`<span class="craft-tooltip" data-tooltip="${$}" data-position="${q}">${X}</span>`}},menu:{nativeType:"craft-menu",fallbackTag:"nav",fallbackClasses:"craft-menu",nativeProps:["items","orientation"]},breadcrumb:{nativeType:"craft-breadcrumb",fallbackTag:"nav",fallbackClasses:"craft-breadcrumb",nativeProps:["items","separator"]},pagination:{nativeType:"craft-pagination",fallbackTag:"nav",fallbackClasses:"craft-pagination",nativeProps:["total","page","pageSize"]},"code-editor":{nativeType:"craft-code-editor",fallbackTag:"textarea",fallbackClasses:"craft-code-editor",nativeProps:["value","language","theme","readonly","lineNumbers"]},"file-browser":{nativeType:"craft-file-browser",fallbackTag:"div",fallbackClasses:"craft-file-browser",nativeProps:["path","showHidden","selectable"]},"color-picker":{nativeType:"craft-color-picker",fallbackTag:"input",fallbackClasses:"craft-color-picker",nativeProps:["value","format"],render:(U,X)=>{return`<input type="color" class="craft-color-picker" value="${U.value||"#000000"}">`}},"date-picker":{nativeType:"craft-date-picker",fallbackTag:"input",fallbackClasses:"craft-date-picker",nativeProps:["value","min","max","format"],render:(U,X)=>{let $=U.value||"",q=U.min||"",Y=U.max||"";return`<input type="date" class="craft-date-picker" value="${$}" min="${q}" max="${Y}">`}},"time-picker":{nativeType:"craft-time-picker",fallbackTag:"input",fallbackClasses:"craft-time-picker",nativeProps:["value","min","max","step"],render:(U,X)=>{return`<input type="time" class="craft-time-picker" value="${U.value||""}">`}}},r=`
<style id="craft-component-styles">
/* Craft Component Base Styles */
.craft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--craft-primary, #3b82f6);
  color: white;
}
.craft-button:hover { opacity: 0.9; }
.craft-button:disabled { opacity: 0.5; cursor: not-allowed; }
.craft-button-secondary { background: var(--craft-secondary, #6b7280); }
.craft-button-outline { background: transparent; border: 1px solid currentColor; color: var(--craft-primary, #3b82f6); }

.craft-text-input, .craft-textarea, .craft-select {
  padding: 8px 12px;
  border: 1px solid var(--craft-border, #d1d5db);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: var(--craft-bg, #fff);
  color: var(--craft-text, #1f2937);
  transition: border-color 0.2s ease;
}
.craft-text-input:focus, .craft-textarea:focus, .craft-select:focus {
  outline: none;
  border-color: var(--craft-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.craft-checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.craft-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.craft-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  cursor: pointer;
}

.craft-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--craft-primary, #3b82f6);
  color: white;
}

.craft-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--craft-secondary, #6b7280);
  color: white;
  font-weight: 600;
  overflow: hidden;
}
.craft-avatar img { width: 100%; height: 100%; object-fit: cover; }

.craft-progress {
  width: 100%;
  height: 8px;
  background: var(--craft-border, #e5e7eb);
  border-radius: 4px;
  overflow: hidden;
}
.craft-progress-bar {
  height: 100%;
  background: var(--craft-primary, #3b82f6);
  transition: width 0.3s ease;
}

.craft-spinner {
  border: 2px solid var(--craft-border, #e5e7eb);
  border-top-color: var(--craft-primary, #3b82f6);
  border-radius: 50%;
  animation: craft-spin 0.8s linear infinite;
}
@keyframes craft-spin { to { transform: rotate(360deg); } }

.craft-card {
  background: var(--craft-bg, #fff);
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.craft-modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.craft-modal::backdrop { background: rgba(0,0,0,0.5); }
.craft-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-modal-header h2 { margin: 0; font-size: 18px; }
.craft-modal-body { padding: 20px; }

.craft-accordion {
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 6px;
  overflow: hidden;
}
.craft-accordion-header {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 500;
  background: var(--craft-bg-secondary, #f9fafb);
}
.craft-accordion-content { padding: 16px; }

.craft-divider {
  border: none;
  border-top: 1px solid var(--craft-border, #e5e7eb);
  margin: 16px 0;
}

.craft-alert {
  padding: 12px 16px;
  border-radius: 6px;
  border-left: 4px solid;
}
.craft-alert-info { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }
.craft-alert-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.craft-alert-warning { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.craft-alert-error { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.craft-alert-title { font-weight: 600; margin-bottom: 4px; }

.craft-tooltip {
  position: relative;
  cursor: help;
}
.craft-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #1f2937;
  color: white;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.craft-tooltip:hover::after { opacity: 1; }

.craft-table {
  width: 100%;
  border-collapse: collapse;
}
.craft-table th, .craft-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-table th { font-weight: 600; background: var(--craft-bg-secondary, #f9fafb); }

.craft-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.craft-list li {
  padding: 12px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-list li:last-child { border-bottom: none; }

.craft-code-editor {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 6px;
  resize: vertical;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .craft-text-input, .craft-textarea, .craft-select, .craft-card {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
  }
  .craft-modal {
    background: #1f2937;
    color: #f3f4f6;
  }
  .craft-accordion-header { background: #374151; }
  .craft-table th { background: #374151; }
}
</style>
`;function i(U,X={}){let{classPrefix:$="craft"}=X;if(!U.includes("craft-component-styles"))if(U.includes("</head>"))U=U.replace("</head>",`
<style id="craft-component-styles">
/* Craft Component Base Styles */
.craft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--craft-primary, #3b82f6);
  color: white;
}
.craft-button:hover { opacity: 0.9; }
.craft-button:disabled { opacity: 0.5; cursor: not-allowed; }
.craft-button-secondary { background: var(--craft-secondary, #6b7280); }
.craft-button-outline { background: transparent; border: 1px solid currentColor; color: var(--craft-primary, #3b82f6); }

.craft-text-input, .craft-textarea, .craft-select {
  padding: 8px 12px;
  border: 1px solid var(--craft-border, #d1d5db);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: var(--craft-bg, #fff);
  color: var(--craft-text, #1f2937);
  transition: border-color 0.2s ease;
}
.craft-text-input:focus, .craft-textarea:focus, .craft-select:focus {
  outline: none;
  border-color: var(--craft-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.craft-checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.craft-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.craft-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  cursor: pointer;
}

.craft-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--craft-primary, #3b82f6);
  color: white;
}

.craft-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--craft-secondary, #6b7280);
  color: white;
  font-weight: 600;
  overflow: hidden;
}
.craft-avatar img { width: 100%; height: 100%; object-fit: cover; }

.craft-progress {
  width: 100%;
  height: 8px;
  background: var(--craft-border, #e5e7eb);
  border-radius: 4px;
  overflow: hidden;
}
.craft-progress-bar {
  height: 100%;
  background: var(--craft-primary, #3b82f6);
  transition: width 0.3s ease;
}

.craft-spinner {
  border: 2px solid var(--craft-border, #e5e7eb);
  border-top-color: var(--craft-primary, #3b82f6);
  border-radius: 50%;
  animation: craft-spin 0.8s linear infinite;
}
@keyframes craft-spin { to { transform: rotate(360deg); } }

.craft-card {
  background: var(--craft-bg, #fff);
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.craft-modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.craft-modal::backdrop { background: rgba(0,0,0,0.5); }
.craft-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-modal-header h2 { margin: 0; font-size: 18px; }
.craft-modal-body { padding: 20px; }

.craft-accordion {
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 6px;
  overflow: hidden;
}
.craft-accordion-header {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 500;
  background: var(--craft-bg-secondary, #f9fafb);
}
.craft-accordion-content { padding: 16px; }

.craft-divider {
  border: none;
  border-top: 1px solid var(--craft-border, #e5e7eb);
  margin: 16px 0;
}

.craft-alert {
  padding: 12px 16px;
  border-radius: 6px;
  border-left: 4px solid;
}
.craft-alert-info { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }
.craft-alert-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.craft-alert-warning { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.craft-alert-error { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.craft-alert-title { font-weight: 600; margin-bottom: 4px; }

.craft-tooltip {
  position: relative;
  cursor: help;
}
.craft-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #1f2937;
  color: white;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.craft-tooltip:hover::after { opacity: 1; }

.craft-table {
  width: 100%;
  border-collapse: collapse;
}
.craft-table th, .craft-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-table th { font-weight: 600; background: var(--craft-bg-secondary, #f9fafb); }

.craft-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.craft-list li {
  padding: 12px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-list li:last-child { border-bottom: none; }

.craft-code-editor {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 6px;
  resize: vertical;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .craft-text-input, .craft-textarea, .craft-select, .craft-card {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
  }
  .craft-modal {
    background: #1f2937;
    color: #f3f4f6;
  }
  .craft-accordion-header { background: #374151; }
  .craft-table th { background: #374151; }
}
</style>

</head>`);else if(U.includes("<style>"))U=U.replace("<style>",`
<style id="craft-component-styles">
/* Craft Component Base Styles */
.craft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--craft-primary, #3b82f6);
  color: white;
}
.craft-button:hover { opacity: 0.9; }
.craft-button:disabled { opacity: 0.5; cursor: not-allowed; }
.craft-button-secondary { background: var(--craft-secondary, #6b7280); }
.craft-button-outline { background: transparent; border: 1px solid currentColor; color: var(--craft-primary, #3b82f6); }

.craft-text-input, .craft-textarea, .craft-select {
  padding: 8px 12px;
  border: 1px solid var(--craft-border, #d1d5db);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: var(--craft-bg, #fff);
  color: var(--craft-text, #1f2937);
  transition: border-color 0.2s ease;
}
.craft-text-input:focus, .craft-textarea:focus, .craft-select:focus {
  outline: none;
  border-color: var(--craft-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.craft-checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.craft-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.craft-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  cursor: pointer;
}

.craft-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--craft-primary, #3b82f6);
  color: white;
}

.craft-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--craft-secondary, #6b7280);
  color: white;
  font-weight: 600;
  overflow: hidden;
}
.craft-avatar img { width: 100%; height: 100%; object-fit: cover; }

.craft-progress {
  width: 100%;
  height: 8px;
  background: var(--craft-border, #e5e7eb);
  border-radius: 4px;
  overflow: hidden;
}
.craft-progress-bar {
  height: 100%;
  background: var(--craft-primary, #3b82f6);
  transition: width 0.3s ease;
}

.craft-spinner {
  border: 2px solid var(--craft-border, #e5e7eb);
  border-top-color: var(--craft-primary, #3b82f6);
  border-radius: 50%;
  animation: craft-spin 0.8s linear infinite;
}
@keyframes craft-spin { to { transform: rotate(360deg); } }

.craft-card {
  background: var(--craft-bg, #fff);
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.craft-modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.craft-modal::backdrop { background: rgba(0,0,0,0.5); }
.craft-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-modal-header h2 { margin: 0; font-size: 18px; }
.craft-modal-body { padding: 20px; }

.craft-accordion {
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 6px;
  overflow: hidden;
}
.craft-accordion-header {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 500;
  background: var(--craft-bg-secondary, #f9fafb);
}
.craft-accordion-content { padding: 16px; }

.craft-divider {
  border: none;
  border-top: 1px solid var(--craft-border, #e5e7eb);
  margin: 16px 0;
}

.craft-alert {
  padding: 12px 16px;
  border-radius: 6px;
  border-left: 4px solid;
}
.craft-alert-info { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }
.craft-alert-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.craft-alert-warning { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.craft-alert-error { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.craft-alert-title { font-weight: 600; margin-bottom: 4px; }

.craft-tooltip {
  position: relative;
  cursor: help;
}
.craft-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #1f2937;
  color: white;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.craft-tooltip:hover::after { opacity: 1; }

.craft-table {
  width: 100%;
  border-collapse: collapse;
}
.craft-table th, .craft-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-table th { font-weight: 600; background: var(--craft-bg-secondary, #f9fafb); }

.craft-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.craft-list li {
  padding: 12px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-list li:last-child { border-bottom: none; }

.craft-code-editor {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 6px;
  resize: vertical;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .craft-text-input, .craft-textarea, .craft-select, .craft-card {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
  }
  .craft-modal {
    background: #1f2937;
    color: #f3f4f6;
  }
  .craft-accordion-header { background: #374151; }
  .craft-table th { background: #374151; }
}
</style>

<style>`);else U=`
<style id="craft-component-styles">
/* Craft Component Base Styles */
.craft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--craft-primary, #3b82f6);
  color: white;
}
.craft-button:hover { opacity: 0.9; }
.craft-button:disabled { opacity: 0.5; cursor: not-allowed; }
.craft-button-secondary { background: var(--craft-secondary, #6b7280); }
.craft-button-outline { background: transparent; border: 1px solid currentColor; color: var(--craft-primary, #3b82f6); }

.craft-text-input, .craft-textarea, .craft-select {
  padding: 8px 12px;
  border: 1px solid var(--craft-border, #d1d5db);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  background: var(--craft-bg, #fff);
  color: var(--craft-text, #1f2937);
  transition: border-color 0.2s ease;
}
.craft-text-input:focus, .craft-textarea:focus, .craft-select:focus {
  outline: none;
  border-color: var(--craft-primary, #3b82f6);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.craft-checkbox-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.craft-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.craft-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  cursor: pointer;
}

.craft-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--craft-primary, #3b82f6);
  color: white;
}

.craft-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--craft-secondary, #6b7280);
  color: white;
  font-weight: 600;
  overflow: hidden;
}
.craft-avatar img { width: 100%; height: 100%; object-fit: cover; }

.craft-progress {
  width: 100%;
  height: 8px;
  background: var(--craft-border, #e5e7eb);
  border-radius: 4px;
  overflow: hidden;
}
.craft-progress-bar {
  height: 100%;
  background: var(--craft-primary, #3b82f6);
  transition: width 0.3s ease;
}

.craft-spinner {
  border: 2px solid var(--craft-border, #e5e7eb);
  border-top-color: var(--craft-primary, #3b82f6);
  border-radius: 50%;
  animation: craft-spin 0.8s linear infinite;
}
@keyframes craft-spin { to { transform: rotate(360deg); } }

.craft-card {
  background: var(--craft-bg, #fff);
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.craft-modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.craft-modal::backdrop { background: rgba(0,0,0,0.5); }
.craft-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-modal-header h2 { margin: 0; font-size: 18px; }
.craft-modal-body { padding: 20px; }

.craft-accordion {
  border: 1px solid var(--craft-border, #e5e7eb);
  border-radius: 6px;
  overflow: hidden;
}
.craft-accordion-header {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 500;
  background: var(--craft-bg-secondary, #f9fafb);
}
.craft-accordion-content { padding: 16px; }

.craft-divider {
  border: none;
  border-top: 1px solid var(--craft-border, #e5e7eb);
  margin: 16px 0;
}

.craft-alert {
  padding: 12px 16px;
  border-radius: 6px;
  border-left: 4px solid;
}
.craft-alert-info { background: #eff6ff; border-color: #3b82f6; color: #1e40af; }
.craft-alert-success { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.craft-alert-warning { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.craft-alert-error { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.craft-alert-title { font-weight: 600; margin-bottom: 4px; }

.craft-tooltip {
  position: relative;
  cursor: help;
}
.craft-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: #1f2937;
  color: white;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.craft-tooltip:hover::after { opacity: 1; }

.craft-table {
  width: 100%;
  border-collapse: collapse;
}
.craft-table th, .craft-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-table th { font-weight: 600; background: var(--craft-bg-secondary, #f9fafb); }

.craft-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.craft-list li {
  padding: 12px;
  border-bottom: 1px solid var(--craft-border, #e5e7eb);
}
.craft-list li:last-child { border-bottom: none; }

.craft-code-editor {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 12px;
  background: #1e1e1e;
  color: #d4d4d4;
  border-radius: 6px;
  resize: vertical;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .craft-text-input, .craft-textarea, .craft-select, .craft-card {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
  }
  .craft-modal {
    background: #1f2937;
    color: #f3f4f6;
  }
  .craft-accordion-header { background: #374151; }
  .craft-table th { background: #374151; }
}
</style>
`+U;return U=U.replace(/<@craft-(\w+[-\w]*)\s*([^>]*?)\/>/g,(q,Y,J)=>{return c(Y,J,"",X,$)}),U=U.replace(/<@craft-(\w+[-\w]*)\s*([^>]*)>([\s\S]*?)<\/@craft-\1>/g,(q,Y,J,G)=>{return c(Y,J,G.trim(),X,$)}),U}function c(U,X,$,q,Y){let J=q.components?.[U]||y[U];if(!J)return console.warn(`[stx] Unknown Craft component: @craft-${U}`),`<div class="${Y}-unknown" data-component="${U}">${$}</div>`;let G=kU(X),Q=[J.fallbackClasses||`${Y}-${U}`];if(G.class)Q.push(G.class),delete G.class;if(J.render)return J.render(G,$);let K=TU(G,J,Q);if(["input","hr","br","img"].includes(J.fallbackTag))return`<${J.fallbackTag} ${K}>`;return`<${J.fallbackTag} ${K}>${$}</${J.fallbackTag}>`}function kU(U){let X={},$=/(?::|@)?(\w+[-\w]*)(?:="([^"]*)")?/g,q;while((q=$.exec(U))!==null){let[Y,J,G]=q;if(Y.startsWith(":"))X[J]=G;else if(Y.startsWith("@"))X[`on${J.charAt(0).toUpperCase()}${J.slice(1)}`]=G;else if(G===void 0)X[J]=!0;else X[J]=G}return X}function TU(U,X,$){let q=[];q.push(`class="${$.join(" ")}"`),q.push(`data-craft="${X.nativeType}"`);for(let[Y,J]of Object.entries(U))if(J===!0)q.push(Y);else if(J!==!1&&J!==void 0&&J!==null){let G=String(J).replace(/"/g,"&quot;");q.push(`${Y}="${G}"`)}return q.join(" ")}function BX(U,X){y[U]=X}function OX(){return{...y}}var I=new Map,M=new Map;function xU(U,X){let $=X?.id||mU(U),q=dU(U),Y=I.get($);if(Y&&Y.hash===q)return Y;let J=PU(U),G=uU(U),Q=hU(U),K=NU(J),{staticParts:W,dynamicParts:_}=vU(J),F=gU(U),w={id:$,hash:q,tree:J,scripts:G,styles:Q,staticParts:W,dynamicParts:_,dependencies:F,metadata:K};return I.set($,w),w}async function HX(U,X={},$={}){let q=performance.now();if($.cache){let Q=`${U.id}:${JSON.stringify(X)}`,K=M.get(Q);if(K&&Date.now()-K.timestamp<($.cacheTTL||60000))return{html:K.html,styles:U.styles.join(`
`),scripts:U.scripts.join(`
`),metadata:{renderTime:0,cacheHit:!0,totalSize:K.html.length,componentCount:U.metadata.componentCount}}}let Y;if($.streaming)Y=await CU(U.tree,X);else Y=R(U.tree,X);let J;if($.hydrate){let Q=DU(Y,U,X);Y=Q.html,J=Q.data}if($.minify)Y=fU(Y);if($.cache){let Q=`${U.id}:${JSON.stringify(X)}`;M.set(Q,{html:Y,timestamp:Date.now()})}let G=performance.now()-q;return{html:Y,styles:U.styles.join(`
`),scripts:U.scripts.join(`
`),hydrationData:J,metadata:{renderTime:G,cacheHit:!1,totalSize:Y.length,componentCount:U.metadata.componentCount}}}function VX(U,X){let $=[],q=[],Y=[],J=new Map,G=[];return z(U.tree,(Q,K)=>{if(Q.type==="component"&&Q.componentName){if(UU(Q.componentName))$.push(Q.componentName)}if(Q.type==="element"&&Q.tag){let W=cU(Q);if(W)G.push(W);if(Q.props){for(let[_,F]of Object.entries(Q.props))if(_.startsWith("on")&&typeof F==="string"){let w=`handler_${J.size}`;J.set(w,F)}}}if(Q.isStatic&&Q.type==="element")q.push(o(Q));else if(!Q.isStatic&&Q.type!=="text")Y.push(Q.tag||Q.componentName||"unknown")}),{nativeComponents:$,staticHTML:q,dynamicParts:Y,eventHandlers:J,nativeWidgets:G}}function IX(U,X={}){let $=xU(U),q=yU($,X),Y=new Map,J=[];return z($.tree,(G)=>{if(G.type==="component"&&G.componentName){if(UU(G.componentName)){J.push(G.componentName);let Q=`<!--craft:${G.componentName}:${G.hydrationKey||"default"}-->`;Y.set(G.hydrationKey||G.componentName,Q)}}}),{staticHTML:q,dynamicPlaceholders:Y,craftComponents:J}}function PU(U){let X={type:"fragment",children:[]},$=X,q=[X],Y=U,J=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);while(Y.length>0){let G=Y.match(/^<(@?[\w-]+)([^>]*)>/);if(G){let[W,_,F]=G,w=SU(F),L=_.startsWith("@craft-"),B=L?_:_.toLowerCase(),A={type:L?"component":"element",tag:B,props:w,children:[],componentName:L?B.slice(1):void 0,isStatic:!p(F),hydrationKey:lU()};if($.children=$.children||[],$.children.push(A),!J.has(B)&&!F.endsWith("/"))q.push(A),$=A;Y=Y.slice(W.length);continue}let Q=Y.match(/^<\/(@?[\w-]+)>/);if(Q){let[W,_]=Q,w=_.startsWith("@craft-")?_:_.toLowerCase();while(q.length>1){let L=q.pop();if($=q[q.length-1],L.tag===w)break}Y=Y.slice(W.length);continue}let K=Y.match(/^[^<]+/);if(K){let W=K[0];if(W.trim()){let _={type:"text",text:W,isStatic:!p(W)};$.children=$.children||[],$.children.push(_)}Y=Y.slice(W.length);continue}Y=Y.slice(1)}return X}function SU(U){let X={},$=/([\w-:@]+)(?:=(?:"([^"]*)"|'([^']*)'|(\S+)))?/g,q;while((q=$.exec(U))!==null){let[,Y,J,G,Q]=q,K=J??G??Q??!0;X[Y]=K}return X}function z(U,X,$=[]){if(X(U,$),U.children)U.children.forEach((q,Y)=>{z(q,X,[...$,`${Y}`])})}function R(U,X){switch(U.type){case"text":return t(U.text||"",X);case"element":case"component":{let $=U.tag||"div",q=n(U.props||{},X),Y=(U.children||[]).map((J)=>R(J,X)).join("");if(!U.children||U.children.length===0){if(["input","br","hr","img","meta","link"].includes($))return`<${$}${q} />`}return`<${$}${q}>${Y}</${$}>`}case"fragment":return(U.children||[]).map(($)=>R($,X)).join("");case"slot":return`<!--slot:${U.slotName||"default"}-->`;default:return""}}function o(U){if(U.type==="text")return U.text||"";let X=U.tag||"div",$=n(U.props||{},{});return`<${X}${$}></${X}>`}function n(U,X){let $=[];for(let[q,Y]of Object.entries(U))if(Y===!0)$.push(` ${q}`);else if(Y!==!1&&Y!==null&&Y!==void 0){let J=t(String(Y),X);$.push(` ${q}="${e(J)}"`)}return $.join("")}async function CU(U,X){return R(U,X)}function yU(U,X){let $=[];return z(U.tree,(q)=>{if(q.isStatic)$.push(R(q,X))}),$.join("")}function DU(U,X,$){let q={templateId:X.id,context:$,dynamicParts:Array.from(X.dynamicParts.entries())},Y=`
<script data-craft-hydration>
  window.__CRAFT_HYDRATION__ = ${JSON.stringify(q)};
</script>`;return{html:U+Y,data:q}}function NU(U){let X=!1,$=!1,q=!1,Y=!1,J=0,G=0;function Q(K,W){if(G=Math.max(G,W),K.type==="slot")X=!0;if(K.type==="component")J++;if(!K.isStatic)$=!0;if(K.props)for(let _ of Object.keys(K.props)){if(_.startsWith("on"))q=!0;if(_==="@async"||_==="data-async")Y=!0}if(K.children)K.children.forEach((_)=>Q(_,W+1))}return Q(U,0),{hasSlots:X,hasDynamicContent:$,hasEventHandlers:q,hasAsyncContent:Y,componentCount:J,maxDepth:G,estimatedSize:JSON.stringify(U).length}}function vU(U){let X=new Map,$=new Map;return z(U,(q,Y)=>{let J=Y.join(".");if(q.isStatic)X.set(J,o(q));else $.set(J,q.tag||q.componentName||"dynamic")}),{staticParts:X,dynamicParts:$}}function uU(U){let X=[],$=/<script[^>]*>([\s\S]*?)<\/script>/gi,q;while((q=$.exec(U))!==null)X.push(q[1]);return X}function hU(U){let X=[],$=/<style[^>]*>([\s\S]*?)<\/style>/gi,q;while((q=$.exec(U))!==null)X.push(q[1]);return X}function gU(U){let X=[],$=/@include\s*\(\s*['"]([^'"]+)['"]/g,q;while((q=$.exec(U))!==null)X.push(q[1]);let Y=/@component\s*\(\s*['"]([^'"]+)['"]/g;while((q=Y.exec(U))!==null)X.push(q[1]);let J=/<@craft-[\w-]+/g;while((q=J.exec(U))!==null)X.push(q[0].slice(2));return[...new Set(X)]}function p(U){return/\{\{.*?\}\}|\{\!\!.*?\!\!\}/.test(U)}function t(U,X){let $=U.replace(/\{\{\s*(.+?)\s*\}\}/g,(q,Y)=>{try{let J=a(Y.trim(),X);return e(String(J??""))}catch{return""}});return $=$.replace(/\{!!\s*(.+?)\s*!!\}/g,(q,Y)=>{try{let J=a(Y.trim(),X);return String(J??"")}catch{return""}}),$}function a(U,X){if(/^[\w.]+$/.test(U)){let $=U.split("."),q=X;for(let Y of $)if(q&&typeof q==="object"&&Y in q)q=q[Y];else return;return q}try{return Function(...Object.keys(X),`return ${U}`)(...Object.values(X))}catch{return}}function e(U){return U.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function fU(U){return U.replace(/\s+/g," ").replace(/>\s+</g,"><").replace(/\s+>/g,">").replace(/<\s+/g,"<").trim()}function mU(U){let X=0;for(let $=0;$<U.length;$++){let q=U.charCodeAt($);X=(X<<5)-X+q,X=X&X}return`tpl_${Math.abs(X).toString(36)}`}function dU(U){let X=0;for(let $=0;$<U.length;$++){let q=U.charCodeAt($);X=(X<<5)-X+q,X=X&X}return Math.abs(X).toString(36)}var sU=0;function lU(){return`h_${++sU}`}function UU(U){return["craft-button","craft-text-input","craft-textarea","craft-checkbox","craft-radio","craft-select","craft-slider","craft-toggle","craft-date-picker","craft-time-picker","craft-color-picker","craft-file-input","craft-modal","craft-alert","craft-toast","craft-progress","craft-spinner","craft-avatar","craft-badge","craft-card","craft-accordion","craft-tabs","craft-tooltip","craft-popover","craft-dropdown","craft-context-menu","craft-data-table","craft-virtual-list","craft-tree-view","craft-map","craft-chart","craft-video","craft-audio","craft-webview","craft-canvas","craft-image-viewer","craft-pdf-viewer","craft-code-editor","craft-rich-editor"].includes(U)}function cU(U){let X=U.tag?.toLowerCase(),$=U.props?.type,q={button:{component:"craft-button",confidence:0.95,reason:"Native button provides better touch feedback"},"input:text":{component:"craft-text-input",confidence:0.9,reason:"Native text input has better keyboard handling"},"input:checkbox":{component:"craft-checkbox",confidence:0.95,reason:"Native checkbox follows platform conventions"},"input:range":{component:"craft-slider",confidence:0.9,reason:"Native slider provides smooth interaction"},"input:date":{component:"craft-date-picker",confidence:0.95,reason:"Native date picker provides platform-specific UI"},"input:time":{component:"craft-time-picker",confidence:0.95,reason:"Native time picker provides platform-specific UI"},"input:color":{component:"craft-color-picker",confidence:0.9,reason:"Native color picker provides platform-specific UI"},textarea:{component:"craft-textarea",confidence:0.85,reason:"Native textarea handles multiline input better"},select:{component:"craft-select",confidence:0.9,reason:"Native select provides platform dropdown UI"},progress:{component:"craft-progress",confidence:0.95,reason:"Native progress bar matches platform style"},video:{component:"craft-video",confidence:0.95,reason:"Native video provides hardware acceleration"},audio:{component:"craft-audio",confidence:0.95,reason:"Native audio provides system integration"},dialog:{component:"craft-modal",confidence:0.9,reason:"Native modal provides proper layering and focus"}},Y=$?`${X}:${$}`:X,J=q[Y||""]||q[X||""];if(J)return{htmlSelector:Y||X||"",nativeComponent:J.component,confidence:J.confidence,reason:J.reason};return null}function rU(){I.clear()}function iU(){M.clear()}function MX(){rU(),iU()}function RX(){return{templateCacheSize:I.size,renderCacheSize:M.size,totalEntries:I.size+M.size}}import{existsSync as $U,mkdirSync as O,copyFileSync as b,chmodSync as V}from"fs";import{join as Z,basename as pU}from"path";import{spawn as x,execSync as aU}from"child_process";import{tmpdir as qU,homedir as XU,platform as oU}from"os";async function yX(U){let X=Date.now();try{if(!await Bun.file(U.input).exists())return{success:!1,target:U.target||T(),format:U.format||"app",error:`Input file not found: ${U.input}`};let $=U.target||T(),q=U.format||qX($),Y=U.output||Z(process.cwd(),"dist","native");if(!$U(Y))O(Y,{recursive:!0});let J=await Bun.file(U.input).text();if(J=v(J,{debug:U.verbose}),J=i(J),!J.includes("craft-component-styles")){if(J.includes("</head>"))J=J.replace("</head>",`${r}
</head>`)}let G=U.name||pU(U.input,".stx"),Q=U.version||"1.0.0",K=U.craftPath||await $X();if(!K)return{success:!1,target:$,format:q,error:"Craft binary not found. Please install Craft or specify craftPath."};if(U.verbose)console.log(`\uD83D\uDCE6 Building native app for ${$}...`),console.log(`   Input: ${U.input}`),console.log(`   Output: ${Y}`),console.log(`   Craft: ${K}`);let W;switch($){case"macos":W=await nU(J,G,Q,Y,q,U,K);break;case"windows":W=await tU(J,G,Q,Y,q,U,K);break;case"linux":W=await eU(J,G,Q,Y,q,U,K);break;case"ios":W=await UX(J,G,Q,Y,U,K);break;case"android":W=await XX(J,G,Q,Y,U,K);break;default:W={success:!1,target:$,format:q,error:`Unsupported target: ${$}`}}return W.duration=Date.now()-X,W}catch($){return{success:!1,target:U.target||T(),format:U.format||"app",error:$.message,duration:Date.now()-X}}}async function nU(U,X,$,q,Y,J,G){let Q=J.bundleId||`com.stx.${X.toLowerCase().replace(/[^a-z0-9]/g,"")}`,K=Z(q,`${X}.app`),W=Z(K,"Contents"),_=Z(W,"MacOS"),F=Z(W,"Resources");O(_,{recursive:!0}),O(F,{recursive:!0});let w=Z(F,"index.html");await Bun.write(w,U);let L="";if(J.sidebar?.enabled&&J.sidebar?.config)L=Z(F,"sidebar-config.json"),await Bun.write(L,JSON.stringify(J.sidebar.config));let B=J.sidebar?.enabled?`--native-sidebar --sidebar-width ${J.sidebar?.width||240} --sidebar-config "$(cat "$RESOURCES/sidebar-config.json")"`:"",A=`#!/bin/bash
DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
RESOURCES="$DIR/../Resources"
"${G}" --html "$(cat "$RESOURCES/index.html")" \\
  --title "${J.window?.title||X}" \\
  --width ${J.window?.width||1200} \\
  --height ${J.window?.height||800} \\
  ${J.systemTray?"--system-tray":""} \\
  ${J.devTools?"--dev-tools":""} \\
  ${J.window?.frameless?"--frameless":""} \\
  ${J.window?.alwaysOnTop?"--always-on-top":""} \\
  ${B}
`,H=Z(_,X);await Bun.write(H,A),V(H,493);let j=Z(_,"craft");try{b(G,j),V(j,493)}catch{let k=`#!/bin/bash
exec "${G}" "$@"`;await Bun.write(j,k),V(j,493)}let JU=`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleExecutable</key>
    <string>${X}</string>
    <key>CFBundleIdentifier</key>
    <string>${Q}</string>
    <key>CFBundleName</key>
    <string>${X}</string>
    <key>CFBundleDisplayName</key>
    <string>${X}</string>
    <key>CFBundleShortVersionString</key>
    <string>${$}</string>
    <key>CFBundleVersion</key>
    <string>${$}</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>LSMinimumSystemVersion</key>
    <string>10.15</string>
    <key>NSHighResolutionCapable</key>
    <true/>
    <key>NSSupportsAutomaticGraphicsSwitching</key>
    <true/>
    <key>LSUIElement</key>
    <${J.systemTray?"true":"false"}/>
</dict>
</plist>`;if(await Bun.write(Z(W,"Info.plist"),JU),J.icon&&await Bun.file(J.icon).exists())b(J.icon,Z(F,"AppIcon.icns"));if(Y==="dmg"){let k=Z(q,`${X}-${$}.dmg`),D=await JX(K,k,X);if(!D.success)return{success:!1,target:"macos",format:"dmg",error:D.error};return{success:!0,target:"macos",format:"dmg",outputPath:k}}return{success:!0,target:"macos",format:"app",outputPath:K}}async function tU(U,X,$,q,Y,J,G){let Q=Z(q,X);O(Q,{recursive:!0});let K=Z(Q,"index.html");await Bun.write(K,U);let W=`@echo off
set DIR=%~dp0
"${G}" --html-file "%DIR%index.html" ^
  --title "${J.window?.title||X}" ^
  --width ${J.window?.width||1200} ^
  --height ${J.window?.height||800} ^
  ${J.systemTray?"--system-tray":""} ^
  ${J.devTools?"--dev-tools":""}
`;if(await Bun.write(Z(Q,`${X}.bat`),W),Y==="zip"){let _=Z(q,`${X}-${$}-windows.zip`),F=await YX(Q,_);if(!F.success)return{success:!1,target:"windows",format:"zip",error:F.error};return{success:!0,target:"windows",format:"zip",outputPath:_}}return{success:!0,target:"windows",format:"app",outputPath:Q}}async function eU(U,X,$,q,Y,J,G){let Q=Z(q,X);O(Q,{recursive:!0});let K=Z(Q,"index.html");await Bun.write(K,U);let W=`#!/bin/bash
DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
"${G}" --html-file "$DIR/index.html" \\
  --title "${J.window?.title||X}" \\
  --width ${J.window?.width||1200} \\
  --height ${J.window?.height||800} \\
  ${J.systemTray?"--system-tray":""} \\
  ${J.devTools?"--dev-tools":""}
`,_=Z(Q,X.toLowerCase());await Bun.write(_,W),V(_,493);let F=`[Desktop Entry]
Type=Application
Name=${X}
Exec=${_}
Terminal=false
Categories=Utility;
`;if(await Bun.write(Z(Q,`${X.toLowerCase()}.desktop`),F),Y==="deb"){let w=Z(q,`${X.toLowerCase()}_${$}_amd64.deb`),L=await QX(Q,w,X,$,J);if(!L.success)return{success:!1,target:"linux",format:"deb",error:L.error};return{success:!0,target:"linux",format:"deb",outputPath:w}}if(Y==="appimage"){let w=Z(q,`${X}-${$}-x86_64.AppImage`),L=await GX(Q,w,X,J);if(!L.success)return{success:!1,target:"linux",format:"appimage",error:L.error};return{success:!0,target:"linux",format:"appimage",outputPath:w}}return{success:!0,target:"linux",format:"app",outputPath:Q}}async function UX(U,X,$,q,Y,J){return{success:!1,target:"ios",format:"ipa",error:`iOS build requires Xcode and additional setup. Use 'stx init:ios ${X}' to create an iOS project.`}}async function XX(U,X,$,q,Y,J){return{success:!1,target:"android",format:"apk",error:`Android build requires Android SDK and additional setup. Use 'stx init:android ${X}' to create an Android project.`}}async function $X(){let U=[Z(process.cwd(),"../../craft/packages/zig/zig-out/bin/craft-minimal"),Z(process.cwd(),"../craft/packages/zig/zig-out/bin/craft-minimal"),Z(XU(),"Code/craft/packages/zig/zig-out/bin/craft-minimal"),"/usr/local/bin/craft","/usr/bin/craft",Z(XU(),".local/bin/craft"),Z(process.env.LOCALAPPDATA||"","craft","craft.exe"),Z(process.env.PROGRAMFILES||"","craft","craft.exe")];for(let X of U)if(await Bun.file(X).exists())return X;try{let $=aU("which craft 2>/dev/null || where craft 2>nul",{encoding:"utf-8"}).trim().split(`
`)[0];if($&&await Bun.file($).exists())return $}catch{}return null}function T(){switch(oU()){case"darwin":return"macos";case"win32":return"windows";default:return"linux"}}function qX(U){switch(U){case"macos":return"app";case"windows":return"zip";case"linux":return"appimage";case"ios":return"ipa";case"android":return"apk";default:return"app"}}async function JX(U,X,$){return new Promise((q)=>{let Y=x("hdiutil",["create","-volname",$,"-srcfolder",U,"-ov","-format","UDZO",X]);Y.on("close",(J)=>{if(J===0)q({success:!0});else q({success:!1,error:`hdiutil exited with code ${J}`})}),Y.on("error",(J)=>{q({success:!1,error:J.message})})})}async function YX(U,X){return new Promise(($)=>{let q=x("zip",["-r",X,"."],{cwd:U});q.on("close",(Y)=>{if(Y===0)$({success:!0});else $({success:!1,error:`zip exited with code ${Y}`})}),q.on("error",(Y)=>{$({success:!1,error:Y.message})})})}async function QX(U,X,$,q,Y){return new Promise((J)=>{try{let G=Z(qU(),`stx-deb-${Date.now()}`),Q=Z(G,"DEBIAN"),K=Z(G,"usr","bin"),W=Z(G,"usr","share","applications"),_=Z(G,"usr","share",$.toLowerCase());O(Q,{recursive:!0}),O(K,{recursive:!0}),O(W,{recursive:!0}),O(_,{recursive:!0});let F=E("fs").readdirSync(U);for(let A of F)b(Z(U,A),Z(_,A));let w=`#!/bin/bash
exec /usr/share/${$.toLowerCase()}/${$.toLowerCase()} "$@"`;E("fs").writeFileSync(Z(K,$.toLowerCase()),w),V(Z(K,$.toLowerCase()),493);let L=`Package: ${$.toLowerCase()}
Version: ${q}
Section: utils
Priority: optional
Architecture: amd64
Depends: libgtk-3-0, libwebkit2gtk-4.0-37
Maintainer: ${Y.author||"Unknown"}
Description: ${Y.description||$}
`;E("fs").writeFileSync(Z(Q,"control"),L);let B=x("dpkg-deb",["--build",G,X]);B.on("close",(A)=>{if(E("fs").rmSync(G,{recursive:!0,force:!0}),A===0)J({success:!0});else J({success:!1,error:`dpkg-deb exited with code ${A}`})}),B.on("error",(A)=>{E("fs").rmSync(G,{recursive:!0,force:!0}),J({success:!1,error:A.message})})}catch(G){J({success:!1,error:G.message})}})}async function GX(U,X,$,q){return new Promise((Y)=>{try{let J=Z(qU(),`stx-appimage-${Date.now()}`),G=Z(J,`${$}.AppDir`),Q=Z(G,"usr"),K=Z(Q,"bin"),W=Z(Q,"share");O(K,{recursive:!0}),O(W,{recursive:!0});let _=Z(W,$.toLowerCase());O(_,{recursive:!0});let F=E("fs").readdirSync(U);for(let H of F)b(Z(U,H),Z(_,H));let w=`#!/bin/bash
SELF=$(readlink -f "$0")
HERE=\${SELF%/*}
export PATH="\${HERE}/usr/bin:\${PATH}"
exec "\${HERE}/usr/share/${$.toLowerCase()}/${$.toLowerCase()}" "$@"
`;E("fs").writeFileSync(Z(G,"AppRun"),w),V(Z(G,"AppRun"),493);let L=`[Desktop Entry]
Type=Application
Name=${$}
Exec=${$.toLowerCase()}
Terminal=false
Categories=Utility;
Icon=${$.toLowerCase()}
`;E("fs").writeFileSync(Z(G,`${$.toLowerCase()}.desktop`),L);let B=Buffer.from([137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,8,2,0,0,0,144,119,83,222,0,0,0,12,73,68,65,84,8,215,99,248,255,255,63,0,5,254,2,254,220,204,89,231,0,0,0,0,73,69,78,68,174,66,96,130]);if(E("fs").writeFileSync(Z(G,`${$.toLowerCase()}.png`),B),q.icon&&$U(q.icon))b(q.icon,Z(G,`${$.toLowerCase()}.png`));let A=x("appimagetool",[G,X],{env:{...process.env,ARCH:"x86_64"}});A.on("close",(H)=>{if(E("fs").rmSync(J,{recursive:!0,force:!0}),H===0)V(X,493),Y({success:!0});else Y({success:!1,error:`appimagetool exited with code ${H}. Install from https://appimage.github.io/appimagetool/`})}),A.on("error",(H)=>{E("fs").rmSync(J,{recursive:!0,force:!0}),Y({success:!1,error:`appimagetool not found: ${H.message}`})})}catch(J){Y({success:!1,error:J.message})}})}function DX(){return[T()]}function NX(U){switch(U){case"macos":return["app","dmg","pkg"];case"windows":return["app","zip","msi"];case"linux":return["app","deb","rpm","appimage"];case"ios":return["ipa"];case"android":return["apk"];default:return["app"]}}export{HX as renderSSR,BX as registerCraftComponent,_X as processCraftDirective,i as processCraftComponents,IX as prerenderForCraft,ZX as isCraftEnvironment,v as injectCraftBridge,RX as getSSRCacheStats,OX as getCraftComponents,DX as getAvailableTargets,NX as getAvailableFormats,VX as generateCraftOptimizations,N as generateCraftBridgeScript,LX as createHotReloadServer,wX as compileToNative,xU as compileTemplate,rU as clearTemplateCache,iU as clearRenderCache,MX as clearAllCaches,yX as buildNative,YU as NATIVE_COMPONENTS,r as CRAFT_COMPONENT_STYLES,y as CRAFT_COMPONENTS,WX as CRAFT_BRIDGE_SCRIPT};
