// @bun
var{defineProperty:V,getOwnPropertyNames:h,getOwnPropertyDescriptor:g}=Object,l=Object.prototype.hasOwnProperty;function f(q){return this[q]}var Eq=(q)=>{var J=(j??=new WeakMap).get(q),H;if(J)return J;if(J=V({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var Q of h(q))if(!l.call(J,Q))V(J,Q,{get:f.bind(q,Q),enumerable:!(H=g(q,Q))||H.enumerable})}return j.set(q,J),J},j;var m=(q)=>q;function s(q,J){this[q]=m.bind(null,J)}var zq=(q,J)=>{for(var H in J)V(q,H,{get:J[H],enumerable:!0,configurable:!0,set:s.bind(J,H)})};var Aq=(q,J)=>()=>(q&&(J=q(q=0)),J);var E=import.meta.require;var Fq=`
<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 b(q={}){let{debug:J=!1,timeout:H=30000}=q;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: ${J},`).replace("timeout: 30000",`timeout: ${H}`)}function c(){return!1}function i(q,J={}){let H=/@craft(?:\(([\s\S]*?)\))?/g;return q.replace(H,(Q,U)=>{let K={};if(U)try{K=JSON.parse(U.replace(/'/g,'"'))}catch{try{K=Function(`return ${U}`)()}catch{console.warn(`[stx] Invalid @craft config: ${U}`)}}return b(K)})}function C(q,J={}){if(q.includes("__craftBridgeInitialized"))return q;let H=b(J);if(q.includes("</head>"))return q.replace("</head>",`${H}
</head>`);if(q.includes("<body"))return q.replace(/(<body[^>]*>)/,`$1
${H}`);return H+q}var n={CRAFT_BRIDGE_SCRIPT:`
<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>
`,generateCraftBridgeScript:b,processCraftDirective:i,injectCraftBridge:C,isCraftEnvironment:c},Oq=n;var k={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:(q,J)=>{let H=q.checked?"checked":"",Q=q.disabled?"disabled":"";return`<label class="craft-checkbox-wrapper">
        <input type="checkbox" class="craft-checkbox" ${H} ${Q}>
        <span class="craft-checkbox-label">${J||q.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:(q,J)=>{let H=q.min??0,Q=q.max??100,U=q.step??1,K=q.value??50,$=q.disabled?"disabled":"";return`<input type="range" class="craft-slider" min="${H}" max="${Q}" step="${U}" value="${K}" ${$}>`}},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:(q,J)=>{let H=q.size||40,Q=q.src,U=String(q.alt||""),K=q.fallback||(U?U.charAt(0).toUpperCase():"?");if(Q)return`<img class="craft-avatar" src="${Q}" alt="${U}" style="width:${H}px;height:${H}px;border-radius:50%">`;return`<div class="craft-avatar craft-avatar-fallback" style="width:${H}px;height:${H}px;border-radius:50%;display:flex;align-items:center;justify-content:center">${K}</div>`}},progress:{nativeType:"craft-progress",fallbackTag:"div",fallbackClasses:"craft-progress",nativeProps:["value","max","variant"],render:(q,J)=>{let H=Number(q.value)||0,Q=Number(q.max)||100;return`<div class="craft-progress"><div class="craft-progress-bar" style="width:${Math.min(100,Math.max(0,H/Q*100))}%"></div></div>`}},spinner:{nativeType:"craft-spinner",fallbackTag:"div",fallbackClasses:"craft-spinner",nativeProps:["size"],render:(q,J)=>{let H=q.size||24;return`<div class="craft-spinner" style="width:${H}px;height:${H}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:(q,J)=>{let H=q.open?"open":"",Q=q.title||"";return`<dialog class="craft-modal" ${H}>
        <div class="craft-modal-content">
          ${Q?`<div class="craft-modal-header"><h2>${Q}</h2></div>`:""}
          <div class="craft-modal-body">${J}</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:(q,J)=>{let H=q.open?"open":"",Q=q.title||"Details";return`<details class="craft-accordion" ${H}>
        <summary class="craft-accordion-header">${Q}</summary>
        <div class="craft-accordion-content">${J}</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:(q,J)=>{let H=q.variant||"info",Q=q.title||"";return`<div class="craft-alert craft-alert-${H}" role="alert">
        ${Q?`<div class="craft-alert-title">${Q}</div>`:""}
        <div class="craft-alert-content">${J}</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:(q,J)=>{let H=q.content||"",Q=q.position||"top";return`<span class="craft-tooltip" data-tooltip="${H}" data-position="${Q}">${J}</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:(q,J)=>{return`<input type="color" class="craft-color-picker" value="${q.value||"#000000"}">`}},"date-picker":{nativeType:"craft-date-picker",fallbackTag:"input",fallbackClasses:"craft-date-picker",nativeProps:["value","min","max","format"],render:(q,J)=>{let H=q.value||"",Q=q.min||"",U=q.max||"";return`<input type="date" class="craft-date-picker" value="${H}" min="${Q}" max="${U}">`}},"time-picker":{nativeType:"craft-time-picker",fallbackTag:"input",fallbackClasses:"craft-time-picker",nativeProps:["value","min","max","step"],render:(q,J)=>{return`<input type="time" class="craft-time-picker" value="${q.value||""}">`}}},P=`
<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 y(q,J={}){let{classPrefix:H="craft"}=J;if(!q.includes("craft-component-styles"))if(q.includes("</head>"))q=q.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(q.includes("<style>"))q=q.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 q=`
<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>
`+q;return q=q.replace(/<@craft-(\w+[-\w]*)\s*([^>]*?)\/>/g,(Q,U,K)=>{return S(U,K,"",J,H)}),q=q.replace(/<@craft-(\w+[-\w]*)\s*([^>]*)>([\s\S]*?)<\/@craft-\1>/g,(Q,U,K,$)=>{return S(U,K,$.trim(),J,H)}),q}function S(q,J,H,Q,U){let K=Q.components?.[q]||k[q];if(!K)return console.warn(`[stx] Unknown Craft component: @craft-${q}`),`<div class="${U}-unknown" data-component="${q}">${H}</div>`;let $=r(J),Y=[K.fallbackClasses||`${U}-${q}`];if($.class)Y.push($.class),delete $.class;if(K.render)return K.render($,H);let Z=t($,K,Y);if(["input","hr","br","img"].includes(K.fallbackTag))return`<${K.fallbackTag} ${Z}>`;return`<${K.fallbackTag} ${Z}>${H}</${K.fallbackTag}>`}function r(q){let J={},H=/(?::|@)?(\w+[-\w]*)(?:="([^"]*)")?/g,Q;while((Q=H.exec(q))!==null){let[U,K,$]=Q;if(U.startsWith(":"))J[K]=$;else if(U.startsWith("@"))J[`on${K.charAt(0).toUpperCase()}${K.slice(1)}`]=$;else if($===void 0)J[K]=!0;else J[K]=$}return J}function t(q,J,H){let Q=[];Q.push(`class="${H.join(" ")}"`),Q.push(`data-craft="${J.nativeType}"`);for(let[U,K]of Object.entries(q))if(K===!0)Q.push(U);else if(K!==!1&&K!==void 0&&K!==null){let $=String(K).replace(/"/g,"&quot;");Q.push(`${U}="${$}"`)}return Q.join(" ")}function a(q,J){k[q]=J}function o(){return{...k}}var e={CRAFT_COMPONENTS:k,CRAFT_COMPONENT_STYLES:`
<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>
`,processCraftComponents:y,registerCraftComponent:a,getCraftComponents:o},kq=e;import{existsSync as N,mkdirSync as M,copyFileSync as R,chmodSync as A}from"fs";import{join as X,basename as p}from"path";import{spawn as B,execSync as qq}from"child_process";import{tmpdir as d,homedir as D,platform as Hq}from"os";async function Jq(q){let J=Date.now();try{if(!await Bun.file(q.input).exists())return{success:!1,target:q.target||F(),format:q.format||"app",error:`Input file not found: ${q.input}`};let H=q.target||F(),Q=q.format||Zq(H),U=q.output||X(process.cwd(),"dist","native");if(!N(U))M(U,{recursive:!0});let K=await Bun.file(q.input).text();if(K=C(K,{debug:q.verbose}),K=y(K),!K.includes("craft-component-styles")){if(K.includes("</head>"))K=K.replace("</head>",`${P}
</head>`)}let $=q.name||p(q.input,".stx"),Y=q.version||"1.0.0",Z=q.craftPath||await Yq();if(!Z)return{success:!1,target:H,format:Q,error:"Craft binary not found. Please install Craft or specify craftPath."};if(q.verbose)console.log(`\uD83D\uDCE6 Building native app for ${H}...`),console.log(`   Input: ${q.input}`),console.log(`   Output: ${U}`),console.log(`   Craft: ${Z}`);let L;switch(H){case"macos":L=await Kq(K,$,Y,U,Q,q,Z);break;case"windows":L=await Qq(K,$,Y,U,Q,q,Z);break;case"linux":L=await Uq(K,$,Y,U,Q,q,Z);break;case"ios":L=await Xq(K,$,Y,U,q,Z);break;case"android":L=await $q(K,$,Y,U,q,Z);break;default:L={success:!1,target:H,format:Q,error:`Unsupported target: ${H}`}}return L.duration=Date.now()-J,L}catch(H){return{success:!1,target:q.target||F(),format:q.format||"app",error:H.message,duration:Date.now()-J}}}async function Kq(q,J,H,Q,U,K,$){let Y=K.bundleId||`com.stx.${J.toLowerCase().replace(/[^a-z0-9]/g,"")}`,Z=X(Q,`${J}.app`),L=X(Z,"Contents"),W=X(L,"MacOS"),G=X(L,"Resources");M(W,{recursive:!0}),M(G,{recursive:!0});let _=X(G,"index.html");await Bun.write(_,q);let w="";if(K.sidebar?.enabled&&K.sidebar?.config)w=X(G,"sidebar-config.json"),await Bun.write(w,JSON.stringify(K.sidebar.config));let x=K.sidebar?.enabled?`--native-sidebar --sidebar-width ${K.sidebar?.width||240} --sidebar-config "$(cat "$RESOURCES/sidebar-config.json")"`:"",I=`#!/bin/bash
DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
RESOURCES="$DIR/../Resources"
"${$}" --html "$(cat "$RESOURCES/index.html")" \\
  --title "${K.window?.title||J}" \\
  --width ${K.window?.width||1200} \\
  --height ${K.window?.height||800} \\
  ${K.systemTray?"--system-tray":""} \\
  ${K.devTools?"--dev-tools":""} \\
  ${K.window?.frameless?"--frameless":""} \\
  ${K.window?.alwaysOnTop?"--always-on-top":""} \\
  ${x}
`,z=X(W,J);await Bun.write(z,I),A(z,493);let O=X(W,"craft");try{R($,O),A(O,493)}catch{let T=`#!/bin/bash
exec "${$}" "$@"`;await Bun.write(O,T),A(O,493)}let u=`<?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>${J}</string>
    <key>CFBundleIdentifier</key>
    <string>${Y}</string>
    <key>CFBundleName</key>
    <string>${J}</string>
    <key>CFBundleDisplayName</key>
    <string>${J}</string>
    <key>CFBundleShortVersionString</key>
    <string>${H}</string>
    <key>CFBundleVersion</key>
    <string>${H}</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>
    <${K.systemTray?"true":"false"}/>
</dict>
</plist>`;if(await Bun.write(X(L,"Info.plist"),u),K.icon&&await Bun.file(K.icon).exists())R(K.icon,X(G,"AppIcon.icns"));if(U==="dmg"){let T=X(Q,`${J}-${H}.dmg`),v=await Lq(Z,T,J);if(!v.success)return{success:!1,target:"macos",format:"dmg",error:v.error};return{success:!0,target:"macos",format:"dmg",outputPath:T}}return{success:!0,target:"macos",format:"app",outputPath:Z}}async function Qq(q,J,H,Q,U,K,$){let Y=X(Q,J);M(Y,{recursive:!0});let Z=X(Y,"index.html");await Bun.write(Z,q);let L=`@echo off
set DIR=%~dp0
"${$}" --html-file "%DIR%index.html" ^
  --title "${K.window?.title||J}" ^
  --width ${K.window?.width||1200} ^
  --height ${K.window?.height||800} ^
  ${K.systemTray?"--system-tray":""} ^
  ${K.devTools?"--dev-tools":""}
`;if(await Bun.write(X(Y,`${J}.bat`),L),U==="zip"){let W=X(Q,`${J}-${H}-windows.zip`),G=await Wq(Y,W);if(!G.success)return{success:!1,target:"windows",format:"zip",error:G.error};return{success:!0,target:"windows",format:"zip",outputPath:W}}return{success:!0,target:"windows",format:"app",outputPath:Y}}async function Uq(q,J,H,Q,U,K,$){let Y=X(Q,J);M(Y,{recursive:!0});let Z=X(Y,"index.html");await Bun.write(Z,q);let L=`#!/bin/bash
DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
"${$}" --html-file "$DIR/index.html" \\
  --title "${K.window?.title||J}" \\
  --width ${K.window?.width||1200} \\
  --height ${K.window?.height||800} \\
  ${K.systemTray?"--system-tray":""} \\
  ${K.devTools?"--dev-tools":""}
`,W=X(Y,J.toLowerCase());await Bun.write(W,L),A(W,493);let G=`[Desktop Entry]
Type=Application
Name=${J}
Exec=${W}
Terminal=false
Categories=Utility;
`;if(await Bun.write(X(Y,`${J.toLowerCase()}.desktop`),G),U==="deb"){let _=X(Q,`${J.toLowerCase()}_${H}_amd64.deb`),w=await Gq(Y,_,J,H,K);if(!w.success)return{success:!1,target:"linux",format:"deb",error:w.error};return{success:!0,target:"linux",format:"deb",outputPath:_}}if(U==="appimage"){let _=X(Q,`${J}-${H}-x86_64.AppImage`),w=await wq(Y,_,J,K);if(!w.success)return{success:!1,target:"linux",format:"appimage",error:w.error};return{success:!0,target:"linux",format:"appimage",outputPath:_}}return{success:!0,target:"linux",format:"app",outputPath:Y}}async function Xq(q,J,H,Q,U,K){return{success:!1,target:"ios",format:"ipa",error:`iOS build requires Xcode and additional setup. Use 'stx init:ios ${J}' to create an iOS project.`}}async function $q(q,J,H,Q,U,K){return{success:!1,target:"android",format:"apk",error:`Android build requires Android SDK and additional setup. Use 'stx init:android ${J}' to create an Android project.`}}async function Yq(){let q=[X(process.cwd(),"../../craft/packages/zig/zig-out/bin/craft-minimal"),X(process.cwd(),"../craft/packages/zig/zig-out/bin/craft-minimal"),X(D(),"Code/craft/packages/zig/zig-out/bin/craft-minimal"),"/usr/local/bin/craft","/usr/bin/craft",X(D(),".local/bin/craft"),X(process.env.LOCALAPPDATA||"","craft","craft.exe"),X(process.env.PROGRAMFILES||"","craft","craft.exe")];for(let J of q)if(await Bun.file(J).exists())return J;try{let H=qq("which craft 2>/dev/null || where craft 2>nul",{encoding:"utf-8"}).trim().split(`
`)[0];if(H&&await Bun.file(H).exists())return H}catch{}return null}function F(){switch(Hq()){case"darwin":return"macos";case"win32":return"windows";default:return"linux"}}function Zq(q){switch(q){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 Lq(q,J,H){return new Promise((Q)=>{let U=B("hdiutil",["create","-volname",H,"-srcfolder",q,"-ov","-format","UDZO",J]);U.on("close",(K)=>{if(K===0)Q({success:!0});else Q({success:!1,error:`hdiutil exited with code ${K}`})}),U.on("error",(K)=>{Q({success:!1,error:K.message})})})}async function Wq(q,J){return new Promise((H)=>{let Q=B("zip",["-r",J,"."],{cwd:q});Q.on("close",(U)=>{if(U===0)H({success:!0});else H({success:!1,error:`zip exited with code ${U}`})}),Q.on("error",(U)=>{H({success:!1,error:U.message})})})}async function Gq(q,J,H,Q,U){return new Promise((K)=>{try{let $=X(d(),`stx-deb-${Date.now()}`),Y=X($,"DEBIAN"),Z=X($,"usr","bin"),L=X($,"usr","share","applications"),W=X($,"usr","share",H.toLowerCase());M(Y,{recursive:!0}),M(Z,{recursive:!0}),M(L,{recursive:!0}),M(W,{recursive:!0});let G=E("fs").readdirSync(q);for(let I of G)R(X(q,I),X(W,I));let _=`#!/bin/bash
exec /usr/share/${H.toLowerCase()}/${H.toLowerCase()} "$@"`;E("fs").writeFileSync(X(Z,H.toLowerCase()),_),A(X(Z,H.toLowerCase()),493);let w=`Package: ${H.toLowerCase()}
Version: ${Q}
Section: utils
Priority: optional
Architecture: amd64
Depends: libgtk-3-0, libwebkit2gtk-4.0-37
Maintainer: ${U.author||"Unknown"}
Description: ${U.description||H}
`;E("fs").writeFileSync(X(Y,"control"),w);let x=B("dpkg-deb",["--build",$,J]);x.on("close",(I)=>{if(E("fs").rmSync($,{recursive:!0,force:!0}),I===0)K({success:!0});else K({success:!1,error:`dpkg-deb exited with code ${I}`})}),x.on("error",(I)=>{E("fs").rmSync($,{recursive:!0,force:!0}),K({success:!1,error:I.message})})}catch($){K({success:!1,error:$.message})}})}async function wq(q,J,H,Q){return new Promise((U)=>{try{let K=X(d(),`stx-appimage-${Date.now()}`),$=X(K,`${H}.AppDir`),Y=X($,"usr"),Z=X(Y,"bin"),L=X(Y,"share");M(Z,{recursive:!0}),M(L,{recursive:!0});let W=X(L,H.toLowerCase());M(W,{recursive:!0});let G=E("fs").readdirSync(q);for(let z of G)R(X(q,z),X(W,z));let _=`#!/bin/bash
SELF=$(readlink -f "$0")
HERE=\${SELF%/*}
export PATH="\${HERE}/usr/bin:\${PATH}"
exec "\${HERE}/usr/share/${H.toLowerCase()}/${H.toLowerCase()}" "$@"
`;E("fs").writeFileSync(X($,"AppRun"),_),A(X($,"AppRun"),493);let w=`[Desktop Entry]
Type=Application
Name=${H}
Exec=${H.toLowerCase()}
Terminal=false
Categories=Utility;
Icon=${H.toLowerCase()}
`;E("fs").writeFileSync(X($,`${H.toLowerCase()}.desktop`),w);let x=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(X($,`${H.toLowerCase()}.png`),x),Q.icon&&N(Q.icon))R(Q.icon,X($,`${H.toLowerCase()}.png`));let I=B("appimagetool",[$,J],{env:{...process.env,ARCH:"x86_64"}});I.on("close",(z)=>{if(E("fs").rmSync(K,{recursive:!0,force:!0}),z===0)A(J,493),U({success:!0});else U({success:!1,error:`appimagetool exited with code ${z}. Install from https://appimage.github.io/appimagetool/`})}),I.on("error",(z)=>{E("fs").rmSync(K,{recursive:!0,force:!0}),U({success:!1,error:`appimagetool not found: ${z.message}`})})}catch(K){U({success:!1,error:K.message})}})}function Iq(){return[F()]}function Mq(q){switch(q){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"]}}var _q={buildNative:Jq,getAvailableTargets:Iq,getAvailableFormats:Mq,detectPlatform:F},Dq=_q;export{Iq as getAvailableTargets,Mq as getAvailableFormats,Dq as default,Jq as buildNative};
