(function () {
  'use strict';

  // Generated by @auroraview/sdk

  // src/inject/plugins/utils.ts
  async function invokePlugin(plugin, command, args) {
    if (!window.auroraview || !window.auroraview.invoke) {
      throw new Error("AuroraView bridge not available");
    }
    const result = await window.auroraview.invoke(
      `plugin:${plugin}|${command}`,
      args || {}
    );
    if (result && result.success === false) {
      const error = new Error(result.error || "Unknown error");
      error.code = result.code || "UNKNOWN";
      throw error;
    }
    return result;
  }
  function attachPlugin(name, api) {
    if (window.auroraview) {
      window.auroraview[name] = api;
      console.log(`[AuroraView] ${name.charAt(0).toUpperCase() + name.slice(1)} plugin initialized`);
    }
  }
  function initPlugin(name, api) {
    if (window.auroraview) {
      attachPlugin(name, api);
    } else {
      const observer = setInterval(function() {
        if (window.auroraview) {
          clearInterval(observer);
          attachPlugin(name, api);
        }
      }, 10);
      setTimeout(function() {
        clearInterval(observer);
      }, 5e3);
    }
  }

  // src/inject/plugins/fs.ts
  (function() {
    const fs = {
      /**
       * Read a file as text
       */
      async readFile(path, encoding) {
        return invokePlugin("fs", "read_file", { path, encoding });
      },
      /**
       * Read a file as binary (base64 encoded)
       */
      async readFileBinary(path) {
        return invokePlugin("fs", "read_file_binary", { path });
      },
      /**
       * Read a file as ArrayBuffer
       */
      async readFileBuffer(path) {
        const base64 = await this.readFileBinary(path);
        const binary = atob(base64);
        const bytes = new Uint8Array(binary.length);
        for (let i = 0; i < binary.length; i++) {
          bytes[i] = binary.charCodeAt(i);
        }
        return bytes.buffer;
      },
      /**
       * Write text to a file
       */
      async writeFile(path, contents, append) {
        return invokePlugin("fs", "write_file", {
          path,
          contents,
          append: append || false
        });
      },
      /**
       * Write binary data to a file
       */
      async writeFileBinary(path, contents, append) {
        let bytes;
        if (contents instanceof ArrayBuffer) {
          bytes = Array.from(new Uint8Array(contents));
        } else if (contents instanceof Uint8Array) {
          bytes = Array.from(contents);
        } else {
          throw new Error("contents must be ArrayBuffer or Uint8Array");
        }
        return invokePlugin("fs", "write_file_binary", {
          path,
          contents: bytes,
          append: append || false
        });
      },
      /**
       * Read directory contents
       */
      async readDir(path, recursive) {
        return invokePlugin("fs", "read_dir", {
          path,
          recursive: recursive || false
        });
      },
      /**
       * Create a directory
       */
      async createDir(path, recursive) {
        return invokePlugin("fs", "create_dir", {
          path,
          recursive: recursive !== false
        });
      },
      /**
       * Remove a file or directory
       */
      async remove(path, recursive) {
        return invokePlugin("fs", "remove", {
          path,
          recursive: recursive || false
        });
      },
      /**
       * Copy a file or directory
       */
      async copy(from, to) {
        return invokePlugin("fs", "copy", { from, to });
      },
      /**
       * Rename/move a file or directory
       */
      async rename(from, to) {
        return invokePlugin("fs", "rename", { from, to });
      },
      /**
       * Check if a path exists
       */
      async exists(path) {
        const result = await invokePlugin("fs", "exists", { path });
        return result && result.exists;
      },
      /**
       * Get file or directory statistics
       */
      async stat(path) {
        return invokePlugin("fs", "stat", { path });
      }
    };
    initPlugin("fs", fs);
  })();

})();
