const k = globalThis.showDirectoryPicker;
async function I(a = {}) {
  if (k && !a._preferPolyfill) return k(a);
  const e = document.createElement("input");
  e.type = "file", e.webkitdirectory = !0, e.multiple = !0, e.style.position = "fixed", e.style.top = "-100000px", e.style.left = "-100000px", document.body.appendChild(e);
  const t = Promise.resolve().then(() => M);
  return await new Promise((i) => {
    e.addEventListener("change", i), e.click();
  }), t.then((i) => i.getDirHandlesFromInput(e));
}
const A = {
  accepts: []
}, x = globalThis.showOpenFilePicker;
async function N(a = {}) {
  const e = {
    ...A,
    ...a
  };
  if (x && !a._preferPolyfill) return x(e);
  const t = document.createElement("input");
  t.type = "file", t.multiple = e.multiple, t.accept = (e.accepts || []).map((n) => [...(n.extensions || []).map((s) => "." + s), ...n.mimeTypes || []]).flat().join(","), Object.assign(t.style, {
    position: "fixed",
    top: "-100000px",
    left: "-100000px"
  }), document.body.appendChild(t);
  const i = Promise.resolve().then(() => M);
  return await new Promise((n) => {
    t.addEventListener("change", n, {
      once: !0
    }), t.click();
  }), t.remove(), i.then((n) => n.getFileHandlesFromInput(t));
}
const _ = globalThis.showSaveFilePicker;
async function W(a = {}) {
  if (_ && !a._preferPolyfill) return _(a);
  a._name && (console.warn("deprecated _name, spec now have `suggestedName`"), a.suggestedName = a._name);
  const {
    FileSystemFileHandle: e
  } = await Promise.resolve().then(() => h), {
    FileHandle: t
  } = await import("./downloader-DcCTL3Wz-DLn-B9X4.js");
  return new e(new t(a.suggestedName));
}
globalThis.DataTransferItem && !DataTransferItem.prototype.getAsFileSystemHandle && (DataTransferItem.prototype.getAsFileSystemHandle = async function() {
  const a = this.webkitGetAsEntry(), [{
    FileHandle: e,
    FolderHandle: t
  }, {
    FileSystemDirectoryHandle: i
  }, {
    FileSystemFileHandle: n
  }] = await Promise.all([import("./sandbox-ChAzL-i--CWB3CeSw.js"), Promise.resolve().then(() => E), Promise.resolve().then(() => h)]);
  return a.isFile ? new n(new e(a, !1)) : new i(new t(a, !1));
});
async function L(a, e = {}) {
  if (!a) return globalThis.navigator?.storage?.getDirectory() || globalThis.getOriginPrivateDirectory();
  const {
    FileSystemDirectoryHandle: t
  } = await Promise.resolve().then(() => E), i = await a, n = await (i.default ? i.default(e) : i(e));
  return new t(n);
}
const q = {
  WritableStream: globalThis.WritableStream,
  TransformStream: globalThis.TransformStream,
  DOMException: globalThis.DOMException,
  Blob: globalThis.Blob,
  File: globalThis.File
}, {
  WritableStream: z
} = q;
class u extends z {
  #e;
  constructor(e) {
    super(e), this.#e = e, Object.setPrototypeOf(this, u.prototype), this._closed = !1;
  }
  async close() {
    this._closed = !0;
    const e = this.getWriter(), t = e.close();
    return e.releaseLock(), t;
  }
  /** @param {number} position */
  seek(e) {
    return this.write({
      type: "seek",
      position: e
    });
  }
  /** @param {number} size */
  truncate(e) {
    return this.write({
      type: "truncate",
      size: e
    });
  }
  // The write(data) method steps are:
  write(e) {
    if (this._closed) return Promise.reject(new TypeError("Cannot write to a CLOSED writable stream"));
    const t = this.getWriter(), i = t.write(e);
    return t.releaseLock(), i;
  }
}
Object.defineProperty(u.prototype, Symbol.toStringTag, {
  value: "FileSystemWritableFileStream",
  writable: !1,
  enumerable: !1,
  configurable: !0
});
Object.defineProperties(u.prototype, {
  close: {
    enumerable: !0
  },
  seek: {
    enumerable: !0
  },
  truncate: {
    enumerable: !0
  },
  write: {
    enumerable: !0
  }
});
globalThis.FileSystemFileHandle && !globalThis.FileSystemFileHandle.prototype.createWritable && !globalThis.FileSystemWritableFileStream && (globalThis.FileSystemWritableFileStream = u);
const d = Symbol("adapter");
class T {
  /** @type {FileSystemHandle} */
  [d];
  /** @type {string} */
  name;
  /** @type {('file'|'directory')} */
  kind;
  /** @param {FileSystemHandle & {writable}} adapter */
  constructor(e) {
    this.kind = e.kind, this.name = e.name, this[d] = e;
  }
  /** @param {FileSystemHandlePermissionDescriptor} descriptor */
  async queryPermission(e = {}) {
    const {
      mode: t = "read"
    } = e, i = this[d];
    if (i.queryPermission) return i.queryPermission({
      mode: t
    });
    if (t === "read") return "granted";
    if (t === "readwrite") return i.writable ? "granted" : "denied";
    throw new TypeError(`Mode ${t} must be 'read' or 'readwrite'`);
  }
  async requestPermission({
    mode: e = "read"
  } = {}) {
    const t = this[d];
    if (t.requestPermission) return t.requestPermission({
      mode: e
    });
    if (e === "read") return "granted";
    if (e === "readwrite") return t.writable ? "granted" : "denied";
    throw new TypeError(`Mode ${e} must be 'read' or 'readwrite'`);
  }
  /**
   * Attempts to remove the entry represented by handle from the underlying file system.
   *
   * @param {object} options
   * @param {boolean} [options.recursive=false]
   */
  async remove(e = {}) {
    await this[d].remove(e);
  }
  /**
   * @param {FileSystemHandle} other
   */
  async isSameEntry(e) {
    return this === e ? !0 : !e || typeof e != "object" || this.kind !== e.kind || !e[d] ? !1 : this[d].isSameEntry(e[d]);
  }
}
Object.defineProperty(T.prototype, Symbol.toStringTag, {
  value: "FileSystemHandle",
  writable: !1,
  enumerable: !1,
  configurable: !0
});
globalThis.FileSystemHandle && (globalThis.FileSystemHandle.prototype.queryPermission ??= function(a) {
  return "granted";
});
const O = {
  INVALID: ["seeking position failed.", "InvalidStateError"],
  GONE: ["A requested file or directory could not be found at the time an operation was processed.", "NotFoundError"],
  MISMATCH: ["The path supplied exists, but was not an entry of requested type.", "TypeMismatchError"],
  MOD_ERR: ["The object can not be modified in this way.", "InvalidModificationError"],
  SYNTAX: (a) => [`Failed to execute 'write' on 'UnderlyingSinkBase': Invalid params passed. ${a}`, "SyntaxError"],
  SECURITY: ["It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.", "SecurityError"],
  DISALLOWED: ["The request is not allowed by the user agent or the platform in the current context.", "NotAllowedError"]
}, R = {
  writable: globalThis.WritableStream
};
async function U(a) {
  console.warn("deprecated fromDataTransfer - use `dt.items[0].getAsFileSystemHandle()` instead");
  const [e, t, i] = await Promise.all([import("./memory-B3L1Fctl-BjKBzeSl.js"), import("./sandbox-ChAzL-i--CWB3CeSw.js"), Promise.resolve().then(() => E)]), n = new e.FolderHandle("", !1);
  return n._entries = a.map((s) => s.isFile ? new t.FileHandle(s, !1) : new t.FolderHandle(s, !1)), new i.FileSystemDirectoryHandle(n);
}
async function B(a) {
  const {
    FolderHandle: e,
    FileHandle: t
  } = await import("./memory-B3L1Fctl-BjKBzeSl.js"), {
    FileSystemDirectoryHandle: i
  } = await Promise.resolve().then(() => E), n = Array.from(a.files), s = n[0].webkitRelativePath.split("/", 1)[0], l = new e(s, !1);
  return n.forEach((y) => {
    const o = y.webkitRelativePath.split("/");
    o.shift();
    const c = o.pop(), p = o.reduce((f, w) => (f._entries[w] || (f._entries[w] = new e(w, !1)), f._entries[w]), l);
    p._entries[c] = new t(y.name, y, !1);
  }), new i(l);
}
async function C(a) {
  const {
    FileHandle: e
  } = await import("./memory-B3L1Fctl-BjKBzeSl.js"), {
    FileSystemFileHandle: t
  } = await Promise.resolve().then(() => h);
  return Array.from(a.files).map((i) => new t(new e(i.name, i, !1)));
}
const M = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  config: R,
  errors: O,
  fromDataTransfer: U,
  getDirHandlesFromInput: B,
  getFileHandlesFromInput: C
}, Symbol.toStringTag, {
  value: "Module"
})), {
  GONE: G,
  MOD_ERR: $
} = O, m = Symbol("adapter");
let F = class H extends T {
  /** @type {FileSystemDirectoryHandle} */
  [m];
  constructor(e) {
    super(e), this[m] = e;
  }
  /**
   * @param {string} name Name of the directory
   * @param {object} [options]
   * @param {boolean} [options.create] create the directory if don't exist
   * @returns {Promise<FileSystemDirectoryHandle>}
   */
  async getDirectoryHandle(e, t = {}) {
    if (e === "") throw new TypeError("Name can't be an empty string.");
    if (e === "." || e === ".." || e.includes("/")) throw new TypeError("Name contains invalid characters.");
    t.create = !!t.create;
    const i = await this[m].getDirectoryHandle(e, t);
    return new H(i);
  }
  /** @returns {AsyncGenerator<[string, FileSystemHandle | FileSystemDirectoryHandle]>} */
  async *entries() {
    const {
      FileSystemFileHandle: e
    } = await Promise.resolve().then(() => h);
    for await (const [t, i] of this[m].entries()) yield [i.name, i.kind === "file" ? new e(i) : new H(i)];
  }
  /** @deprecated use .entries() instead */
  async *getEntries() {
    const {
      FileSystemFileHandle: e
    } = await Promise.resolve().then(() => h);
    console.warn("deprecated, use .entries() instead");
    for await (let t of this[m].entries()) yield t.kind === "file" ? new e(t) : new H(t);
  }
  /**
   * @param {string} name Name of the file
   * @param {object} [options]
   * @param {boolean} [options.create] create the file if don't exist
   */
  async getFileHandle(e, t = {}) {
    const {
      FileSystemFileHandle: i
    } = await Promise.resolve().then(() => h);
    if (e === "") throw new TypeError("Name can't be an empty string.");
    if (e === "." || e === ".." || e.includes("/")) throw new TypeError("Name contains invalid characters.");
    t.create = !!t.create;
    const n = await this[m].getFileHandle(e, t);
    return new i(n);
  }
  /**
   * @param {string} name
   * @param {object} [options]
   * @param {boolean} [options.recursive]
   */
  async removeEntry(e, t = {}) {
    if (e === "") throw new TypeError("Name can't be an empty string.");
    if (e === "." || e === ".." || e.includes("/")) throw new TypeError("Name contains invalid characters.");
    return t.recursive = !!t.recursive, this[m].removeEntry(e, t);
  }
  async resolve(e) {
    if (await e.isSameEntry(this)) return [];
    const t = [{
      handle: this,
      path: []
    }];
    for (; t.length; ) {
      let {
        handle: i,
        path: n
      } = t.pop();
      for await (const s of i.values()) {
        if (await s.isSameEntry(e)) return [...n, s.name];
        s.kind === "directory" && t.push({
          handle: s,
          path: [...n, s.name]
        });
      }
    }
    return null;
  }
  async *keys() {
    for await (const [e] of this[m].entries()) yield e;
  }
  async *values() {
    for await (const [e, t] of this) yield t;
  }
  [Symbol.asyncIterator]() {
    return this.entries();
  }
};
Object.defineProperty(F.prototype, Symbol.toStringTag, {
  value: "FileSystemDirectoryHandle",
  writable: !1,
  enumerable: !1,
  configurable: !0
});
Object.defineProperties(F.prototype, {
  getDirectoryHandle: {
    enumerable: !0
  },
  entries: {
    enumerable: !0
  },
  getFileHandle: {
    enumerable: !0
  },
  removeEntry: {
    enumerable: !0
  }
});
if (globalThis.FileSystemDirectoryHandle) {
  const a = globalThis.FileSystemDirectoryHandle.prototype;
  a.resolve = async function(n) {
    if (await n.isSameEntry(this)) return [];
    const s = [{
      handle: this,
      path: []
    }];
    for (; s.length; ) {
      let {
        handle: l,
        path: y
      } = s.pop();
      for await (const o of l.values()) {
        if (await o.isSameEntry(n)) return [...y, o.name];
        o.kind === "directory" && s.push({
          handle: o,
          path: [...y, o.name]
        });
      }
    }
    return null;
  };
  async function e(n) {
    if (await (await navigator.storage.getDirectory()).resolve(n) === null) throw new DOMException(...G);
  }
  const t = a.entries;
  a.entries = async function* () {
    await e(this), yield* t.call(this);
  }, a[Symbol.asyncIterator] = async function* () {
    yield* this.entries();
  };
  const i = a.removeEntry;
  a.removeEntry = async function(n, s = {}) {
    return i.call(this, n, s).catch(async (l) => {
      throw l instanceof DOMException && l.name === "UnknownError" && !s.recursive && !(await t.call(this).next()).done ? new DOMException(...$) : l;
    });
  };
}
const E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  FileSystemDirectoryHandle: F,
  default: F
}, Symbol.toStringTag, {
  value: "Module"
})), {
  INVALID: V,
  SYNTAX: D,
  GONE: Y
} = O, v = Symbol("adapter");
class S extends T {
  /** @type {FileSystemFileHandle} */
  [v];
  constructor(e) {
    super(e), this[v] = e;
  }
  /**
   * @param  {Object} [options={}]
   * @param  {boolean} [options.keepExistingData]
   * @returns {Promise<FileSystemWritableFileStream>}
   */
  async createWritable(e = {}) {
    return new u(await this[v].createWritable(e));
  }
  /**
   * @returns {Promise<File>}
   */
  async getFile() {
    return this[v].getFile();
  }
}
Object.defineProperty(S.prototype, Symbol.toStringTag, {
  value: "FileSystemFileHandle",
  writable: !1,
  enumerable: !1,
  configurable: !0
});
Object.defineProperties(S.prototype, {
  createWritable: {
    enumerable: !0
  },
  getFile: {
    enumerable: !0
  }
});
if (globalThis.FileSystemFileHandle && !globalThis.FileSystemFileHandle.prototype.createWritable) {
  const a = /* @__PURE__ */ new WeakMap();
  let e;
  const t = () => {
    let n, s;
    onmessage = async (l) => {
      const y = l.ports[0], o = l.data;
      switch (o.type) {
        case "open":
          const c = o.name;
          let p = await navigator.storage.getDirectory();
          for (const f of o.path) p = await p.getDirectoryHandle(f);
          n = await p.getFileHandle(c), s = await n.createSyncAccessHandle();
          break;
        case "write":
          s.write(o.data, {
            at: o.position
          }), s.flush();
          break;
        case "truncate":
          s.truncate(o.size);
          break;
        case "abort":
        case "close":
          s.close();
          break;
      }
      y.postMessage(0);
    };
  };
  globalThis.FileSystemFileHandle.prototype.createWritable = async function(n) {
    if (!e) {
      const r = `(${t.toString()})()`, b = new Blob([r], {
        type: "text/javascript"
      });
      e = URL.createObjectURL(b);
    }
    const s = new Worker(e, {
      type: "module"
    });
    let l = 0;
    const y = new TextEncoder();
    let o = await this.getFile().then((r) => r.size);
    const c = (r) => new Promise((b, j) => {
      const g = new MessageChannel();
      g.port1.onmessage = (P) => {
        P.data instanceof Error ? j(P.data) : b(P.data), g.port1.close(), g.port2.close(), g.port1.onmessage = null;
      }, s.postMessage(r, [g.port2]);
    }), p = await navigator.storage.getDirectory(), f = await a.get(this), w = await p.resolve(f);
    if (w === null) throw new DOMException(...Y);
    return await c({
      type: "open",
      path: w,
      name: this.name
    }), n?.keepExistingData === !1 && (await c({
      type: "truncate",
      size: 0
    }), o = 0), new u({
      start: (r) => {
      },
      async write(r) {
        if (r?.constructor === Object ? r = {
          ...r
        } : r = {
          type: "write",
          data: r,
          position: l
        }, r.type === "write") {
          if (!("data" in r)) throw await c({
            type: "close"
          }), new DOMException(...D("write requires a data argument"));
          if (r.position ??= l, typeof r.data == "string") r.data = y.encode(r.data);
          else if (r.data instanceof ArrayBuffer) r.data = new Uint8Array(r.data);
          else if (!(r.data instanceof Uint8Array) && ArrayBuffer.isView(r.data)) r.data = new Uint8Array(r.data.buffer, r.data.byteOffset, r.data.byteLength);
          else if (!(r.data instanceof Uint8Array)) {
            const b = await new Response(r.data).arrayBuffer();
            r.data = new Uint8Array(b);
          }
          Number.isInteger(r.position) && r.position >= 0 && (l = r.position), l += r.data.byteLength, o += r.data.byteLength;
        } else if (r.type === "seek")
          if (Number.isInteger(r.position) && r.position >= 0) {
            if (o < r.position) throw new DOMException(...V);
            console.log("seeking", r), l = r.position;
            return;
          } else throw await c({
            type: "close"
          }), new DOMException(...D("seek requires a position argument"));
        else if (r.type === "truncate") if (Number.isInteger(r.size) && r.size >= 0) o = r.size, l > o && (l = o);
        else throw await c({
          type: "close"
        }), new DOMException(...D("truncate requires a size argument"));
        await c(r);
      },
      async close() {
        await c({
          type: "close"
        }), s.terminate();
      },
      async abort(r) {
        await c({
          type: "abort",
          reason: r
        }), s.terminate();
      }
    });
  };
  const i = FileSystemDirectoryHandle.prototype.getFileHandle;
  FileSystemDirectoryHandle.prototype.getFileHandle = async function(...n) {
    const s = await i.call(this, ...n);
    return a.set(s, this), s;
  };
}
const h = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  FileSystemFileHandle: S,
  default: S
}, Symbol.toStringTag, {
  value: "Module"
})), X = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  FileSystemDirectoryHandle: F,
  FileSystemFileHandle: S,
  FileSystemHandle: T,
  FileSystemWritableFileStream: u,
  getOriginPrivateDirectory: L,
  showDirectoryPicker: I,
  showOpenFilePicker: N,
  showSaveFilePicker: W
}, Symbol.toStringTag, {
  value: "Module"
}));
export {
  X as a,
  q as c,
  O as e
};
//# sourceMappingURL=es6--XPcqeHG-D1VmO9CH.js.map
