opfs-worker 1.3.0 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { wrap as u } from "comlink";
2
- import { i as h, d as l, e as c } from "./helpers-BuGfPAg0.js";
3
- import { A as E, N as S, D as P, E as O, F, j as A, c as T, I as R, h as I, O as C, a as $, f as D, g as _, P as N, k as z, b as k, S as M, T as j, V as W, W as L, p as U, C as H, B, L as G, n as q, G as Y, z as V, l as X, M as Z, q as J, y as K, v as Q, o as nn, m as tn, u as en, t as rn, r as sn, H as an, x as on, K as cn, s as hn, J as ln, w as pn } from "./helpers-BuGfPAg0.js";
2
+ import { i as h, d as l, e as c } from "./helpers-Ca2c767K.js";
3
+ import { A as E, M as S, D as P, E as O, F, j as A, c as T, I as R, h as C, O as I, a as D, f as $, g as _, P as N, b as k, S as z, V as M, W as j, o as L, B as W, z as U, K as H, l as B, C as G, y as Y, k as q, L as V, p as Z, x as J, u as X, n as K, m as Q, t as nn, r as tn, q as en, G as rn, v as sn, J as an, s as on, H as cn, w as hn } from "./helpers-Ca2c767K.js";
4
4
  const f = `/**
5
5
  * @license
6
6
  * Copyright 2019 Google LLC
7
7
  * SPDX-License-Identifier: Apache-2.0
8
8
  */
9
- const bt = Symbol("Comlink.proxy"), Ht = Symbol("Comlink.endpoint"), Wt = Symbol("Comlink.releaseProxy"), J = Symbol("Comlink.finalizer"), U = Symbol("Comlink.thrown"), Ot = (s) => typeof s == "object" && s !== null || typeof s == "function", _t = {
9
+ const bt = Symbol("Comlink.proxy"), Ht = Symbol("Comlink.endpoint"), Wt = Symbol("Comlink.releaseProxy"), X = Symbol("Comlink.finalizer"), _ = Symbol("Comlink.thrown"), Ot = (s) => typeof s == "object" && s !== null || typeof s == "function", jt = {
10
10
  canHandle: (s) => Ot(s) && s[bt],
11
11
  serialize(s) {
12
12
  const { port1: t, port2: e } = new MessageChannel();
@@ -15,8 +15,8 @@ const bt = Symbol("Comlink.proxy"), Ht = Symbol("Comlink.endpoint"), Wt = Symbol
15
15
  deserialize(s) {
16
16
  return s.start(), Gt(s);
17
17
  }
18
- }, jt = {
19
- canHandle: (s) => Ot(s) && U in s,
18
+ }, _t = {
19
+ canHandle: (s) => Ot(s) && _ in s,
20
20
  serialize({ value: s }) {
21
21
  let t;
22
22
  return s instanceof Error ? t = {
@@ -32,8 +32,8 @@ const bt = Symbol("Comlink.proxy"), Ht = Symbol("Comlink.endpoint"), Wt = Symbol
32
32
  throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
33
33
  }
34
34
  }, Dt = /* @__PURE__ */ new Map([
35
- ["proxy", _t],
36
- ["throw", jt]
35
+ ["proxy", jt],
36
+ ["throw", _t]
37
37
  ]);
38
38
  function Ut(s, t) {
39
39
  for (const e of s)
@@ -72,7 +72,7 @@ function ot(s, t = globalThis, e = ["*"]) {
72
72
  case "ENDPOINT":
73
73
  {
74
74
  const { port1: u, port2: d } = new MessageChannel();
75
- ot(s, d), h = B(u, [u]);
75
+ ot(s, d), h = U(u, [u]);
76
76
  }
77
77
  break;
78
78
  case "RELEASE":
@@ -82,15 +82,15 @@ function ot(s, t = globalThis, e = ["*"]) {
82
82
  return;
83
83
  }
84
84
  } catch (c) {
85
- h = { value: c, [U]: 0 };
85
+ h = { value: c, [_]: 0 };
86
86
  }
87
- Promise.resolve(h).catch((c) => ({ value: c, [U]: 0 })).then((c) => {
88
- const [f, u] = Y(c);
89
- t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u), o === "RELEASE" && (t.removeEventListener("message", n), vt(t), J in s && typeof s[J] == "function" && s[J]());
87
+ Promise.resolve(h).catch((c) => ({ value: c, [_]: 0 })).then((c) => {
88
+ const [f, u] = V(c);
89
+ t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u), o === "RELEASE" && (t.removeEventListener("message", n), vt(t), X in s && typeof s[X] == "function" && s[X]());
90
90
  }).catch((c) => {
91
- const [f, u] = Y({
91
+ const [f, u] = V({
92
92
  value: new TypeError("Unserializable return value"),
93
- [U]: 0
93
+ [_]: 0
94
94
  });
95
95
  t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u);
96
96
  });
@@ -115,79 +115,79 @@ function Gt(s, t) {
115
115
  } finally {
116
116
  e.delete(i.id);
117
117
  }
118
- }), nt(s, e, [], t);
118
+ }), st(s, e, [], t);
119
119
  }
120
- function W(s) {
120
+ function H(s) {
121
121
  if (s)
122
122
  throw new Error("Proxy has been released and is not useable");
123
123
  }
124
124
  function At(s) {
125
- return $(s, /* @__PURE__ */ new Map(), {
125
+ return F(s, /* @__PURE__ */ new Map(), {
126
126
  type: "RELEASE"
127
127
  }).then(() => {
128
128
  vt(s);
129
129
  });
130
130
  }
131
- const q = /* @__PURE__ */ new WeakMap(), V = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
132
- const t = (q.get(s) || 0) - 1;
133
- q.set(s, t), t === 0 && At(s);
131
+ const G = /* @__PURE__ */ new WeakMap(), q = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
132
+ const t = (G.get(s) || 0) - 1;
133
+ G.set(s, t), t === 0 && At(s);
134
134
  });
135
135
  function qt(s, t) {
136
- const e = (q.get(t) || 0) + 1;
137
- q.set(t, e), V && V.register(s, t, s);
136
+ const e = (G.get(t) || 0) + 1;
137
+ G.set(t, e), q && q.register(s, t, s);
138
138
  }
139
139
  function Vt(s) {
140
- V && V.unregister(s);
140
+ q && q.unregister(s);
141
141
  }
142
- function nt(s, t, e = [], n = function() {
142
+ function st(s, t, e = [], n = function() {
143
143
  }) {
144
144
  let r = !1;
145
145
  const i = new Proxy(n, {
146
146
  get(o, a) {
147
- if (W(r), a === Wt)
147
+ if (H(r), a === Wt)
148
148
  return () => {
149
149
  Vt(i), At(s), t.clear(), r = !0;
150
150
  };
151
151
  if (a === "then") {
152
152
  if (e.length === 0)
153
153
  return { then: () => i };
154
- const l = $(s, t, {
154
+ const l = F(s, t, {
155
155
  type: "GET",
156
156
  path: e.map((h) => h.toString())
157
157
  }).then(C);
158
158
  return l.then.bind(l);
159
159
  }
160
- return nt(s, t, [...e, a]);
160
+ return st(s, t, [...e, a]);
161
161
  },
162
162
  set(o, a, l) {
163
- W(r);
164
- const [h, c] = Y(l);
165
- return $(s, t, {
163
+ H(r);
164
+ const [h, c] = V(l);
165
+ return F(s, t, {
166
166
  type: "SET",
167
167
  path: [...e, a].map((f) => f.toString()),
168
168
  value: h
169
169
  }, c).then(C);
170
170
  },
171
171
  apply(o, a, l) {
172
- W(r);
172
+ H(r);
173
173
  const h = e[e.length - 1];
174
174
  if (h === Ht)
175
- return $(s, t, {
175
+ return F(s, t, {
176
176
  type: "ENDPOINT"
177
177
  }).then(C);
178
178
  if (h === "bind")
179
- return nt(s, t, e.slice(0, -1));
179
+ return st(s, t, e.slice(0, -1));
180
180
  const [c, f] = ht(l);
181
- return $(s, t, {
181
+ return F(s, t, {
182
182
  type: "APPLY",
183
183
  path: e.map((u) => u.toString()),
184
184
  argumentList: c
185
185
  }, f).then(C);
186
186
  },
187
187
  construct(o, a) {
188
- W(r);
188
+ H(r);
189
189
  const [l, h] = ht(a);
190
- return $(s, t, {
190
+ return F(s, t, {
191
191
  type: "CONSTRUCT",
192
192
  path: e.map((c) => c.toString()),
193
193
  argumentList: l
@@ -200,17 +200,17 @@ function Yt(s) {
200
200
  return Array.prototype.concat.apply([], s);
201
201
  }
202
202
  function ht(s) {
203
- const t = s.map(Y);
203
+ const t = s.map(V);
204
204
  return [t.map((e) => e[0]), Yt(t.map((e) => e[1]))];
205
205
  }
206
206
  const Nt = /* @__PURE__ */ new WeakMap();
207
- function B(s, t) {
207
+ function U(s, t) {
208
208
  return Nt.set(s, t), s;
209
209
  }
210
210
  function Zt(s) {
211
211
  return Object.assign(s, { [bt]: !0 });
212
212
  }
213
- function Y(s) {
213
+ function V(s) {
214
214
  for (const [t, e] of Dt)
215
215
  if (e.canHandle(s)) {
216
216
  const [n, r] = e.serialize(s);
@@ -239,7 +239,7 @@ function C(s) {
239
239
  return s.value;
240
240
  }
241
241
  }
242
- function $(s, t, e, n) {
242
+ function F(s, t, e, n) {
243
243
  return new Promise((r) => {
244
244
  const i = Xt();
245
245
  t.set(i, r), s.start && s.start(), s.postMessage(Object.assign({ id: i }, e), n);
@@ -291,7 +291,7 @@ class w extends Error {
291
291
  }
292
292
  class Qt extends w {
293
293
  constructor(t) {
294
- super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, void 0, t);
294
+ super("OPFS is not supported in this browser", "ENOTSUP", void 0, void 0, t);
295
295
  }
296
296
  }
297
297
  class Kt extends w {
@@ -299,7 +299,7 @@ class Kt extends w {
299
299
  super(t, "INVALID_PATH", e, "access", n);
300
300
  }
301
301
  }
302
- class F extends w {
302
+ class R extends w {
303
303
  constructor(t, e, n) {
304
304
  const r = {
305
305
  file: \`File not found: \${e}\`,
@@ -311,7 +311,7 @@ class F extends w {
311
311
  }
312
312
  class te extends w {
313
313
  constructor(t, e, n) {
314
- super(\`Permission denied for \${e} on: \${t}\`, "PERMISSION_DENIED", t, e, n);
314
+ super(\`Permission denied for \${e} on: \${t}\`, "EACCES", t, e, n);
315
315
  }
316
316
  }
317
317
  class ee extends w {
@@ -324,10 +324,10 @@ class se extends w {
324
324
  super(\`File is busy: \${t}\`, "EBUSY", t, "open", e);
325
325
  }
326
326
  }
327
- class L extends w {
328
- constructor(t, e, n, r) {
329
- const i = e === "directory" ? \`Is a directory: \${n}\` : \`Not a directory: \${n}\`, o = e === "directory" ? "EISDIR" : "ENOTDIR";
330
- super(i, o, n, "access", r);
327
+ class nt extends w {
328
+ constructor(t, e, n) {
329
+ const r = t === "directory" ? \`Is a directory: \${e}\` : \`Not a directory: \${e}\`, i = t === "directory" ? "EISDIR" : "ENOTDIR";
330
+ super(r, i, e, "access", n);
331
331
  }
332
332
  }
333
333
  class N extends w {
@@ -359,15 +359,11 @@ class Ct extends w {
359
359
  class rt extends w {
360
360
  constructor(t, e, n) {
361
361
  const r = {
362
- remove: \`Failed to remove entry: \${e}\`,
363
- clear: \`Directory not empty: \${e}. Use recursive option to force removal.\`,
364
- root: "Cannot remove root directory"
365
- }, i = {
366
- remove: "RM_FAILED",
367
- clear: "ENOTEMPTY",
368
- root: "EROOT"
362
+ RM_FAILED: \`Failed to remove entry: \${e}\`,
363
+ ENOTEMPTY: \`Directory not empty: \${e}. Use recursive option to force removal.\`,
364
+ EROOT: "Cannot remove root directory"
369
365
  };
370
- super(r[t], i[t], e, "unlink", n);
366
+ super(r[t] || \`Directory operation failed: \${e}\`, t, e, "unlink", n);
371
367
  }
372
368
  }
373
369
  class re extends w {
@@ -375,36 +371,36 @@ class re extends w {
375
371
  super("Failed to initialize OPFS", "INIT_FAILED", t, "init", e);
376
372
  }
377
373
  }
378
- class Q extends w {
374
+ class J extends w {
379
375
  constructor(t, e, n) {
380
376
  super(\`Failed to \${t}: \${e}\`, \`\${t.toUpperCase()}_FAILED\`, e, t, n);
381
377
  }
382
378
  }
383
- class K extends w {
379
+ class Q extends w {
384
380
  constructor(t, e) {
385
381
  super(\`Destination already exists: \${t}\`, "EEXIST", t, "open", e);
386
382
  }
387
383
  }
388
- function _(s, t, e, n) {
384
+ function W(s, t, e, n) {
389
385
  const r = \`\${s.toUpperCase()}_FAILED\`;
390
386
  return new w(\`Failed to \${s} file descriptor: \${t}\`, r, e, s, n);
391
387
  }
392
- function A(s, t) {
393
- const e = t?.path, n = t?.isDirectory;
388
+ function v(s, t) {
389
+ const e = t?.path, n = t?.isDirectory, r = t?.existenceType ?? "file", i = t?.operation;
394
390
  switch (s.name) {
395
391
  case "InvalidStateError":
396
392
  return new se(e || "unknown", s);
397
393
  case "QuotaExceededError":
398
394
  return new ee(\`No space left on device: \${e || "unknown"}\`, e, s);
399
395
  case "NotFoundError":
400
- return new F("file", e, s);
396
+ return new R(r, e, s);
401
397
  case "TypeMismatchError":
402
- return n !== void 0 ? n ? new L("file", "directory", e || "unknown", s) : new L("directory", "file", e || "unknown", s) : new N("argument", \`Type mismatch: \${e || "unknown"}\`, e, s);
398
+ return n !== void 0 ? n ? new nt("directory", e || "unknown", s) : new nt("file", e || "unknown", s) : new N("argument", \`Type mismatch: \${e || "unknown"}\`, e, s);
403
399
  case "NotAllowedError":
404
400
  case "SecurityError":
405
401
  return new te(e, "unknown", s);
406
402
  case "InvalidModificationError":
407
- return new N("argument", \`Invalid modification: \${e || "unknown"}\`, e, s);
403
+ return i === "remove" ? new rt("ENOTEMPTY", e, s) : new N("argument", \`Invalid modification: \${e || "unknown"}\`, e, s);
408
404
  case "AbortError":
409
405
  return new ne(e || "unknown", s);
410
406
  case "OperationError":
@@ -412,7 +408,7 @@ function A(s, t) {
412
408
  case "TypeError":
413
409
  return new Ct(e || "unknown", s);
414
410
  default:
415
- return new ut(\`I/O error: \${e || "unknown"}\`, e, s);
411
+ return i === "remove" ? new rt("RM_FAILED", e, s) : new ut(\`I/O error: \${e || "unknown"}\`, e, s);
416
412
  }
417
413
  }
418
414
  const Ft = (s, t, e) => {
@@ -445,12 +441,12 @@ const Ft = (s, t, e) => {
445
441
  n.length && o !== void 0 && (a = [i, o]);
446
442
  }
447
443
  return a;
448
- }, $t = "\\0SLASH" + Math.random() + "\\0", Mt = "\\0OPEN" + Math.random() + "\\0", at = "\\0CLOSE" + Math.random() + "\\0", Pt = "\\0COMMA" + Math.random() + "\\0", Tt = "\\0PERIOD" + Math.random() + "\\0", oe = new RegExp($t, "g"), ae = new RegExp(Mt, "g"), ce = new RegExp(at, "g"), le = new RegExp(Pt, "g"), he = new RegExp(Tt, "g"), ue = /\\\\\\\\/g, fe = /\\\\{/g, de = /\\\\}/g, pe = /\\\\,/g, ge = /\\\\./g;
449
- function tt(s) {
444
+ }, $t = "\\0SLASH" + Math.random() + "\\0", Mt = "\\0OPEN" + Math.random() + "\\0", at = "\\0CLOSE" + Math.random() + "\\0", Tt = "\\0COMMA" + Math.random() + "\\0", Pt = "\\0PERIOD" + Math.random() + "\\0", oe = new RegExp($t, "g"), ae = new RegExp(Mt, "g"), ce = new RegExp(at, "g"), le = new RegExp(Tt, "g"), he = new RegExp(Pt, "g"), ue = /\\\\\\\\/g, fe = /\\\\{/g, de = /\\\\}/g, pe = /\\\\,/g, ge = /\\\\./g;
445
+ function K(s) {
450
446
  return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
451
447
  }
452
448
  function we(s) {
453
- return s.replace(ue, $t).replace(fe, Mt).replace(de, at).replace(pe, Pt).replace(ge, Tt);
449
+ return s.replace(ue, $t).replace(fe, Mt).replace(de, at).replace(pe, Tt).replace(ge, Pt);
454
450
  }
455
451
  function me(s) {
456
452
  return s.replace(oe, "\\\\").replace(ae, "{").replace(ce, "}").replace(le, ",").replace(he, ".");
@@ -467,7 +463,7 @@ function Rt(s) {
467
463
  return i.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
468
464
  }
469
465
  function ye(s) {
470
- return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), I(we(s), !0).map(me)) : [];
466
+ return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), k(we(s), !0).map(me)) : [];
471
467
  }
472
468
  function Ee(s) {
473
469
  return "{" + s + "}";
@@ -481,11 +477,11 @@ function xe(s, t) {
481
477
  function be(s, t) {
482
478
  return s >= t;
483
479
  }
484
- function I(s, t) {
480
+ function k(s, t) {
485
481
  const e = [], n = Ft("{", "}", s);
486
482
  if (!n)
487
483
  return [s];
488
- const r = n.pre, i = n.post.length ? I(n.post, !1) : [""];
484
+ const r = n.pre, i = n.post.length ? k(n.post, !1) : [""];
489
485
  if (/\\$$/.test(n.pre))
490
486
  for (let o = 0; o < i.length; o++) {
491
487
  const a = r + "{" + n.body + "}" + i[o];
@@ -494,28 +490,28 @@ function I(s, t) {
494
490
  else {
495
491
  const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
496
492
  if (!l && !h)
497
- return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + at + n.post, I(s)) : [s];
493
+ return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + at + n.post, k(s)) : [s];
498
494
  let c;
499
495
  if (l)
500
496
  c = n.body.split(/\\.\\./);
501
- else if (c = Rt(n.body), c.length === 1 && c[0] !== void 0 && (c = I(c[0], !1).map(Ee), c.length === 1))
497
+ else if (c = Rt(n.body), c.length === 1 && c[0] !== void 0 && (c = k(c[0], !1).map(Ee), c.length === 1))
502
498
  return i.map((u) => n.pre + c[0] + u);
503
499
  let f;
504
500
  if (l && c[0] !== void 0 && c[1] !== void 0) {
505
- const u = tt(c[0]), d = tt(c[1]), g = Math.max(c[0].length, c[1].length);
506
- let p = c.length === 3 && c[2] !== void 0 ? Math.abs(tt(c[2])) : 1, S = xe;
501
+ const u = K(c[0]), d = K(c[1]), g = Math.max(c[0].length, c[1].length);
502
+ let p = c.length === 3 && c[2] !== void 0 ? Math.abs(K(c[2])) : 1, S = xe;
507
503
  d < u && (p *= -1, S = be);
508
- const P = c.some(Se);
504
+ const M = c.some(Se);
509
505
  f = [];
510
506
  for (let x = u; S(x, d); x += p) {
511
507
  let m;
512
508
  if (a)
513
509
  m = String.fromCharCode(x), m === "\\\\" && (m = "");
514
- else if (m = String(x), P) {
510
+ else if (m = String(x), M) {
515
511
  const T = g - m.length;
516
512
  if (T > 0) {
517
- const H = new Array(T + 1).join("0");
518
- x < 0 ? m = "-" + H + m.slice(1) : m = H + m;
513
+ const z = new Array(T + 1).join("0");
514
+ x < 0 ? m = "-" + z + m.slice(1) : m = z + m;
519
515
  }
520
516
  }
521
517
  f.push(m);
@@ -523,7 +519,7 @@ function I(s, t) {
523
519
  } else {
524
520
  f = [];
525
521
  for (let u = 0; u < c.length; u++)
526
- f.push.apply(f, I(c[u], !1));
522
+ f.push.apply(f, k(c[u], !1));
527
523
  }
528
524
  for (let u = 0; u < f.length; u++)
529
525
  for (let d = 0; d < i.length; d++) {
@@ -533,7 +529,7 @@ function I(s, t) {
533
529
  }
534
530
  return e;
535
531
  }
536
- const Oe = 1024 * 64, Z = (s) => {
532
+ const Oe = 1024 * 64, Y = (s) => {
537
533
  if (typeof s != "string")
538
534
  throw new TypeError("invalid pattern");
539
535
  if (s.length > Oe)
@@ -553,7 +549,7 @@ const Oe = 1024 * 64, Z = (s) => {
553
549
  "[:upper:]": ["\\\\p{Lu}", !0],
554
550
  "[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
555
551
  "[:xdigit:]": ["A-Fa-f0-9", !1]
556
- }, R = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), ve = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), dt = (s) => s.join(""), Ae = (s, t) => {
552
+ }, P = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), ve = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), dt = (s) => s.join(""), Ae = (s, t) => {
557
553
  const e = t;
558
554
  if (s.charAt(e) !== "[")
559
555
  throw new Error("not in a brace expression");
@@ -574,27 +570,27 @@ const Oe = 1024 * 64, Z = (s) => {
574
570
  continue;
575
571
  }
576
572
  if (p === "[" && !l) {
577
- for (const [S, [v, P, x]] of Object.entries(De))
573
+ for (const [S, [A, M, x]] of Object.entries(De))
578
574
  if (s.startsWith(S, i)) {
579
575
  if (f)
580
576
  return ["$.", !1, s.length - e, !0];
581
- i += S.length, x ? r.push(v) : n.push(v), a = a || P;
577
+ i += S.length, x ? r.push(A) : n.push(A), a = a || M;
582
578
  continue t;
583
579
  }
584
580
  }
585
581
  if (l = !1, f) {
586
- p > f ? n.push(R(f) + "-" + R(p)) : p === f && n.push(R(p)), f = "", i++;
582
+ p > f ? n.push(P(f) + "-" + P(p)) : p === f && n.push(P(p)), f = "", i++;
587
583
  continue;
588
584
  }
589
585
  if (s.startsWith("-]", i + 1)) {
590
- n.push(R(p + "-")), i += 2;
586
+ n.push(P(p + "-")), i += 2;
591
587
  continue;
592
588
  }
593
589
  if (s.startsWith("-", i + 1)) {
594
590
  f = p, i += 2;
595
591
  continue;
596
592
  }
597
- n.push(R(p)), i++;
593
+ n.push(P(p)), i++;
598
594
  }
599
595
  if (c < i)
600
596
  return ["", !1, 0, !1];
@@ -606,7 +602,7 @@ const Oe = 1024 * 64, Z = (s) => {
606
602
  }
607
603
  const u = "[" + (h ? "^" : "") + dt(n) + "]", d = "[" + (h ? "" : "^") + dt(r) + "]";
608
604
  return [n.length && r.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
609
- }, k = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), Ne = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), pt = (s) => Ne.has(s), Ce = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", j = "(?!\\\\.)", Fe = /* @__PURE__ */ new Set(["[", "."]), $e = /* @__PURE__ */ new Set(["..", "."]), Me = new Set("().*{}+?[]^$\\\\!"), Pe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), ct = "[^/]", gt = ct + "*?", wt = ct + "+?";
605
+ }, I = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), Ne = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), pt = (s) => Ne.has(s), Ce = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", j = "(?!\\\\.)", Fe = /* @__PURE__ */ new Set(["[", "."]), $e = /* @__PURE__ */ new Set(["..", "."]), Me = new Set("().*{}+?[]^$\\\\!"), Te = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), ct = "[^/]", gt = ct + "*?", wt = ct + "+?";
610
606
  class E {
611
607
  type;
612
608
  #s;
@@ -859,8 +855,8 @@ class E {
859
855
  const e = t ?? !!this.#r.dot;
860
856
  if (this.#s === this && this.#d(), !this.type) {
861
857
  const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
862
- const [g, p, S, v] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
863
- return this.#n = this.#n || S, this.#i = this.#i || v, g;
858
+ const [g, p, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
859
+ return this.#n = this.#n || S, this.#i = this.#i || A, g;
864
860
  }).join("");
865
861
  let c = "";
866
862
  if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && $e.has(this.#t[0]))) {
@@ -875,7 +871,7 @@ class E {
875
871
  let f = "";
876
872
  return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
877
873
  c + h + f,
878
- k(h),
874
+ I(h),
879
875
  this.#n = !!this.#n,
880
876
  this.#i
881
877
  ];
@@ -884,7 +880,7 @@ class E {
884
880
  let i = this.#f(e);
885
881
  if (this.isStart() && this.isEnd() && !i && this.type !== "!") {
886
882
  const l = this.toString();
887
- return this.#t = [l], this.type = null, this.#n = void 0, [l, k(this.toString()), !1, !1];
883
+ return this.#t = [l], this.type = null, this.#n = void 0, [l, I(this.toString()), !1, !1];
888
884
  }
889
885
  let o = !n || t || e || !j ? "" : this.#f(!0);
890
886
  o === i && (o = ""), o && (i = \`(?:\${i})(?:\${o})*?\`);
@@ -900,7 +896,7 @@ class E {
900
896
  }
901
897
  return [
902
898
  a,
903
- k(i),
899
+ I(i),
904
900
  this.#n = !!this.#n,
905
901
  this.#i
906
902
  ];
@@ -940,33 +936,33 @@ class E {
940
936
  i += ct, e = !0;
941
937
  continue;
942
938
  }
943
- i += Pe(l);
939
+ i += Te(l);
944
940
  }
945
- return [i, k(t), !!e, o];
941
+ return [i, I(t), !!e, o];
946
942
  }
947
943
  }
948
- const Te = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (Z(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new X(t, e).match(s)), Re = /^\\*+([^+@!?\\*\\[\\(]*)$/, Ie = (s) => (t) => !t.startsWith(".") && t.endsWith(s), ke = (s) => (t) => t.endsWith(s), ze = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), Le = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), He = /^\\*+\\.\\*+$/, We = (s) => !s.startsWith(".") && s.includes("."), _e = (s) => s !== "." && s !== ".." && s.includes("."), je = /^\\.\\*+$/, Ue = (s) => s !== "." && s !== ".." && s.startsWith("."), Be = /^\\*+$/, Ge = (s) => s.length !== 0 && !s.startsWith("."), qe = (s) => s.length !== 0 && s !== "." && s !== "..", Ve = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ye = ([s, t = ""]) => {
949
- const e = It([s]);
944
+ const Pe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (Y(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new Z(t, e).match(s)), Re = /^\\*+([^+@!?\\*\\[\\(]*)$/, ke = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ie = (s) => (t) => t.endsWith(s), Le = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), ze = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), He = /^\\*+\\.\\*+$/, We = (s) => !s.startsWith(".") && s.includes("."), je = (s) => s !== "." && s !== ".." && s.includes("."), _e = /^\\.\\*+$/, Ue = (s) => s !== "." && s !== ".." && s.startsWith("."), Be = /^\\*+$/, Ge = (s) => s.length !== 0 && !s.startsWith("."), qe = (s) => s.length !== 0 && s !== "." && s !== "..", Ve = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ye = ([s, t = ""]) => {
945
+ const e = kt([s]);
950
946
  return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
951
947
  }, Ze = ([s, t = ""]) => {
952
- const e = kt([s]);
948
+ const e = It([s]);
953
949
  return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
954
950
  }, Xe = ([s, t = ""]) => {
955
- const e = kt([s]);
951
+ const e = It([s]);
956
952
  return t ? (n) => e(n) && n.endsWith(t) : e;
957
953
  }, Je = ([s, t = ""]) => {
958
- const e = It([s]);
954
+ const e = kt([s]);
959
955
  return t ? (n) => e(n) && n.endsWith(t) : e;
960
- }, It = ([s]) => {
956
+ }, kt = ([s]) => {
961
957
  const t = s.length;
962
958
  return (e) => e.length === t && !e.startsWith(".");
963
- }, kt = ([s]) => {
959
+ }, It = ([s]) => {
964
960
  const t = s.length;
965
961
  return (e) => e.length === t && e !== "." && e !== "..";
966
- }, zt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", mt = {
962
+ }, Lt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", mt = {
967
963
  win32: { sep: "\\\\" },
968
964
  posix: { sep: "/" }
969
- }, Qe = zt === "win32" ? mt.win32.sep : mt.posix.sep;
965
+ }, Qe = Lt === "win32" ? mt.win32.sep : mt.posix.sep;
970
966
  y.sep = Qe;
971
967
  const O = Symbol("globstar **");
972
968
  y.GLOBSTAR = O;
@@ -1007,17 +1003,17 @@ const b = (s, t = {}) => Object.assign({}, s, t), rs = (s) => {
1007
1003
  });
1008
1004
  };
1009
1005
  y.defaults = rs;
1010
- const Lt = (s, t = {}) => (Z(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ye(s));
1011
- y.braceExpand = Lt;
1012
- const is = (s, t = {}) => new X(s, t).makeRe();
1006
+ const zt = (s, t = {}) => (Y(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ye(s));
1007
+ y.braceExpand = zt;
1008
+ const is = (s, t = {}) => new Z(s, t).makeRe();
1013
1009
  y.makeRe = is;
1014
1010
  const os = (s, t, e = {}) => {
1015
- const n = new X(t, e);
1011
+ const n = new Z(t, e);
1016
1012
  return s = s.filter((r) => n.match(r)), n.options.nonull && !s.length && s.push(t), s;
1017
1013
  };
1018
1014
  y.match = os;
1019
1015
  const yt = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, as = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
1020
- class X {
1016
+ class Z {
1021
1017
  options;
1022
1018
  set;
1023
1019
  pattern;
@@ -1036,7 +1032,7 @@ class X {
1036
1032
  windowsNoMagicRoot;
1037
1033
  regexp;
1038
1034
  constructor(t, e = {}) {
1039
- Z(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || zt, this.isWindows = this.platform === "win32", this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === !1, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = !1, this.nonegate = !!e.nonegate, this.comment = !1, this.empty = !1, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
1035
+ Y(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Lt, this.isWindows = this.platform === "win32", this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === !1, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = !1, this.nonegate = !!e.nonegate, this.comment = !1, this.empty = !1, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
1040
1036
  }
1041
1037
  hasMagic() {
1042
1038
  if (this.options.magicalBraces && this.set.length > 1)
@@ -1244,10 +1240,10 @@ class X {
1244
1240
  matchOne(t, e, n = !1) {
1245
1241
  const r = this.options;
1246
1242
  if (this.isWindows) {
1247
- const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), v = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), P = !v && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, m = P ? 3 : v ? 0 : void 0;
1243
+ const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), M = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, m = M ? 3 : A ? 0 : void 0;
1248
1244
  if (typeof x == "number" && typeof m == "number") {
1249
- const [T, H] = [t[x], e[m]];
1250
- T.toLowerCase() === H.toLowerCase() && (e[m] = T, m > x ? e = e.slice(m) : x > m && (t = t.slice(x)));
1245
+ const [T, z] = [t[x], e[m]];
1246
+ T.toLowerCase() === z.toLowerCase() && (e[m] = T, m > x ? e = e.slice(m) : x > m && (t = t.slice(x)));
1251
1247
  }
1252
1248
  }
1253
1249
  const { optimizationLevel: i = 1 } = this.options;
@@ -1293,17 +1289,17 @@ globstar while\`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
1293
1289
  throw new Error("wtf?");
1294
1290
  }
1295
1291
  braceExpand() {
1296
- return Lt(this.pattern, this.options);
1292
+ return zt(this.pattern, this.options);
1297
1293
  }
1298
1294
  parse(t) {
1299
- Z(t);
1295
+ Y(t);
1300
1296
  const e = this.options;
1301
1297
  if (t === "**")
1302
1298
  return O;
1303
1299
  if (t === "")
1304
1300
  return "";
1305
1301
  let n, r = null;
1306
- (n = t.match(Be)) ? r = e.dot ? qe : Ge : (n = t.match(Re)) ? r = (e.nocase ? e.dot ? Le : ze : e.dot ? ke : Ie)(n[1]) : (n = t.match(Ve)) ? r = (e.nocase ? e.dot ? Ze : Ye : e.dot ? Xe : Je)(n) : (n = t.match(He)) ? r = e.dot ? _e : We : (n = t.match(je)) && (r = Ue);
1302
+ (n = t.match(Be)) ? r = e.dot ? qe : Ge : (n = t.match(Re)) ? r = (e.nocase ? e.dot ? ze : Le : e.dot ? Ie : ke)(n[1]) : (n = t.match(Ve)) ? r = (e.nocase ? e.dot ? Ze : Ye : e.dot ? Xe : Je)(n) : (n = t.match(He)) ? r = e.dot ? je : We : (n = t.match(_e)) && (r = Ue);
1307
1303
  const i = E.fromGlob(t, this.options).toMMPattern();
1308
1304
  return r && typeof i == "object" && Reflect.defineProperty(i, "test", { value: r }), i;
1309
1305
  }
@@ -1368,44 +1364,44 @@ globstar while\`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
1368
1364
  }
1369
1365
  }
1370
1366
  y.AST = E;
1371
- y.Minimatch = X;
1372
- y.escape = Te;
1373
- y.unescape = k;
1367
+ y.Minimatch = Z;
1368
+ y.escape = Pe;
1369
+ y.unescape = I;
1374
1370
  function cs() {
1375
1371
  if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
1376
1372
  throw new Qt();
1377
1373
  }
1378
- async function z(s, t, e) {
1374
+ async function L(s, t, e) {
1379
1375
  return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/")}\`, { mode: t }, e) : e();
1380
1376
  }
1381
- function M(s) {
1377
+ function $(s) {
1382
1378
  return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
1383
1379
  }
1384
1380
  function lt(s) {
1385
1381
  return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
1386
1382
  }
1387
1383
  function it(s) {
1388
- const t = M(s);
1384
+ const t = $(s);
1389
1385
  return t[t.length - 1] || "";
1390
1386
  }
1391
- function et(s) {
1392
- const t = M(s);
1387
+ function tt(s) {
1388
+ const t = $(s);
1393
1389
  return t.pop(), lt(t);
1394
1390
  }
1395
- function G(s) {
1391
+ function B(s) {
1396
1392
  return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
1397
1393
  }
1398
1394
  function ls(s, t = !1) {
1399
1395
  return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
1400
1396
  }
1401
- function st(s, t) {
1397
+ function et(s, t) {
1402
1398
  return y(s, t, {
1403
1399
  dot: !0,
1404
1400
  matchBase: !0
1405
1401
  });
1406
1402
  }
1407
1403
  function Et(s) {
1408
- const t = G(s), e = M(t), n = [];
1404
+ const t = B(s), e = $(t), n = [];
1409
1405
  for (const r of e)
1410
1406
  if (!(r === "." || r === ""))
1411
1407
  if (r === "..") {
@@ -1428,15 +1424,19 @@ async function us(s) {
1428
1424
  }
1429
1425
  async function fs(s, t, e = {}) {
1430
1426
  const n = it(t);
1431
- return z(t, "exclusive", async () => {
1427
+ return L(t, "exclusive", async () => {
1432
1428
  const r = e.recursive ?? !1, i = e.force ?? !1;
1433
1429
  try {
1434
1430
  await s.removeEntry(n, { recursive: r });
1435
1431
  } catch (o) {
1436
- if (o.name === "NotFoundError") {
1437
- if (!i)
1438
- throw new F("file", t, o);
1439
- } else throw o.name === "InvalidModificationError" ? new rt("clear", t, o) : o.name === "TypeMismatchError" && !r ? new L("file", "directory", t, o) : new rt("remove", t, o);
1432
+ if (o.name === "NotFoundError" && i)
1433
+ return;
1434
+ const a = o.name === "TypeMismatchError" && !r;
1435
+ throw v(o, {
1436
+ path: t,
1437
+ operation: "remove",
1438
+ isDirectory: a
1439
+ });
1440
1440
  }
1441
1441
  });
1442
1442
  }
@@ -1467,7 +1467,7 @@ async function ps(s, t) {
1467
1467
  try {
1468
1468
  return await s.createSyncAccessHandle();
1469
1469
  } catch (e) {
1470
- throw A(e, { path: t, isDirectory: !1 });
1470
+ throw v(e, { path: t, isDirectory: !1 });
1471
1471
  }
1472
1472
  }
1473
1473
  class gs {
@@ -1507,14 +1507,13 @@ class gs {
1507
1507
  * This method is called by internal operations to notify clients about
1508
1508
  * changes, even when no specific paths are being watched.
1509
1509
  *
1510
- * @param path - The path that was changed
1511
- * @param type - The type of change (create, change, delete)
1510
+ * @param event - The event describing the change
1512
1511
  */
1513
1512
  async notifyChange(t) {
1514
1513
  if (!this.options.broadcastChannel)
1515
1514
  return;
1516
1515
  const e = t.path;
1517
- if (![...this.watchers.values()].some((i) => st(e, i.pattern) && i.include.some((o) => o && st(e, o)) && !i.exclude.some((o) => o && st(e, o))))
1516
+ if (![...this.watchers.values()].some((i) => et(e, i.pattern) && i.include.some((o) => o && et(e, o)) && !i.exclude.some((o) => o && et(e, o))))
1518
1517
  return;
1519
1518
  let r;
1520
1519
  if (this.options.hashAlgorithm)
@@ -1554,7 +1553,6 @@ class gs {
1554
1553
  * This method sets up the root directory for all subsequent operations.
1555
1554
  * If no root is specified, it will use the OPFS root directory.
1556
1555
  *
1557
- * @param root - The root path for the file system (default: '/')
1558
1556
  * @returns Promise that resolves to true if initialization was successful
1559
1557
  * @throws {OPFSError} If initialization fails
1560
1558
  *
@@ -1593,7 +1591,7 @@ class gs {
1593
1591
  * @param options.broadcastChannel - Custom name for the broadcast channel
1594
1592
  */
1595
1593
  async setOptions(t) {
1596
- t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = G(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
1594
+ t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = B(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
1597
1595
  }
1598
1596
  /**
1599
1597
  * Get a directory handle from a path
@@ -1614,7 +1612,7 @@ class gs {
1614
1612
  * \`\`\`
1615
1613
  */
1616
1614
  async getDirectoryHandle(t, e = !1, n = this.root) {
1617
- const r = Array.isArray(t) ? t : M(t);
1615
+ const r = Array.isArray(t) ? t : $(t);
1618
1616
  let i = n;
1619
1617
  for (const o of r)
1620
1618
  i = await i.getDirectoryHandle(o, { create: e });
@@ -1640,7 +1638,7 @@ class gs {
1640
1638
  * \`\`\`
1641
1639
  */
1642
1640
  async getFileHandle(t, e = !1, n = this.root) {
1643
- const r = M(t);
1641
+ const r = $(t);
1644
1642
  if (r.length === 0)
1645
1643
  throw new Kt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1646
1644
  const i = r.pop();
@@ -1709,17 +1707,17 @@ class gs {
1709
1707
  async readFile(t) {
1710
1708
  await this.mount();
1711
1709
  try {
1712
- return await z(t, "shared", async () => {
1710
+ return await L(t, "shared", async () => {
1713
1711
  const e = await this.open(t);
1714
1712
  try {
1715
1713
  const { size: n } = await this.fstat(e), r = new Uint8Array(n);
1716
- return n > 0 && await this.read(e, r, 0, n, 0), B(r, [r.buffer]);
1714
+ return n > 0 && await this.read(e, r, 0, n, 0), U(r, [r.buffer]);
1717
1715
  } finally {
1718
1716
  await this.close(e);
1719
1717
  }
1720
1718
  });
1721
1719
  } catch (e) {
1722
- throw new F("file", t, e);
1720
+ throw new R("file", t, e);
1723
1721
  }
1724
1722
  }
1725
1723
  /**
@@ -1747,7 +1745,7 @@ class gs {
1747
1745
  async writeFile(t, e) {
1748
1746
  await this.mount();
1749
1747
  const n = e instanceof Uint8Array ? e : new Uint8Array(e);
1750
- await z(t, "exclusive", async () => {
1748
+ await L(t, "exclusive", async () => {
1751
1749
  const r = await this.exists(t), i = await this.open(t, { create: !0, truncate: !0 });
1752
1750
  try {
1753
1751
  await this.write(i, n, 0, n.length, null, !1), await this.fsync(i);
@@ -1782,7 +1780,7 @@ class gs {
1782
1780
  async appendFile(t, e) {
1783
1781
  await this.mount();
1784
1782
  const n = e instanceof Uint8Array ? e : new Uint8Array(e);
1785
- await z(t, "exclusive", async () => {
1783
+ await L(t, "exclusive", async () => {
1786
1784
  const r = await this.open(t, { create: !0 });
1787
1785
  try {
1788
1786
  const { size: i } = await this.fstat(r);
@@ -1816,14 +1814,17 @@ class gs {
1816
1814
  */
1817
1815
  async mkdir(t, e) {
1818
1816
  await this.mount();
1819
- const n = e?.recursive ?? !1, r = M(t);
1817
+ const n = e?.recursive ?? !1, r = $(t);
1820
1818
  let i = this.root;
1821
1819
  for (let o = 0; o < r.length; o++) {
1822
1820
  const a = r[o];
1823
1821
  try {
1824
1822
  i = await i.getDirectoryHandle(a, { create: n || o === r.length - 1 });
1825
1823
  } catch (l) {
1826
- throw l.name === "NotFoundError" ? new F("directory", lt(r.slice(0, o + 1)), l) : l.name === "TypeMismatchError" ? new L("directory", "file", a, l) : new Q("create directory", a, l);
1824
+ throw l.name === "NotFoundError" ? v(l, {
1825
+ path: lt(r.slice(0, o + 1)),
1826
+ existenceType: "directory"
1827
+ }) : l.name === "TypeMismatchError" ? v(l, { path: a, isDirectory: !1 }) : new J("create directory", a, l);
1827
1828
  }
1828
1829
  }
1829
1830
  await this.notifyChange({ path: t, type: D.Added, isDirectory: !0 });
@@ -1863,7 +1864,7 @@ class gs {
1863
1864
  const e = it(t);
1864
1865
  let n;
1865
1866
  try {
1866
- n = await this.getDirectoryHandle(et(t), !1);
1867
+ n = await this.getDirectoryHandle(tt(t), !1);
1867
1868
  const r = this.options.hashAlgorithm, o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
1868
1869
  kind: "file",
1869
1870
  size: o.size,
@@ -1884,9 +1885,9 @@ class gs {
1884
1885
  return a;
1885
1886
  } catch (r) {
1886
1887
  if (r.name === "NotFoundError")
1887
- throw new F("file", t, r);
1888
+ throw new R("file", t, r);
1888
1889
  if (r.name !== "TypeMismatchError")
1889
- throw new Q("stat", t, r);
1890
+ throw new J("stat", t, r);
1890
1891
  }
1891
1892
  try {
1892
1893
  return await n.getDirectoryHandle(e, { create: !1 }), {
@@ -1898,7 +1899,7 @@ class gs {
1898
1899
  isDirectory: !0
1899
1900
  };
1900
1901
  } catch (r) {
1901
- throw new Q("stat", t, r);
1902
+ throw new J("stat", t, r);
1902
1903
  }
1903
1904
  }
1904
1905
  /**
@@ -1953,7 +1954,7 @@ class gs {
1953
1954
  const e = it(t);
1954
1955
  let n = null;
1955
1956
  try {
1956
- n = await this.getDirectoryHandle(et(t), !1);
1957
+ n = await this.getDirectoryHandle(tt(t), !1);
1957
1958
  } catch (r) {
1958
1959
  if (n = null, r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1959
1960
  throw r;
@@ -2003,7 +2004,7 @@ class gs {
2003
2004
  }
2004
2005
  await this.notifyChange({ path: t, type: D.Changed, isDirectory: !0 });
2005
2006
  } catch (e) {
2006
- throw e instanceof w ? e : A(e, { path: t, isDirectory: !0 });
2007
+ throw e instanceof w ? e : v(e, { path: t, isDirectory: !0 });
2007
2008
  }
2008
2009
  }
2009
2010
  /**
@@ -2032,8 +2033,8 @@ class gs {
2032
2033
  */
2033
2034
  async remove(t, e) {
2034
2035
  if (await this.mount(), t === "/")
2035
- throw new rt("root", t);
2036
- const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(et(t), !1), o = await this.stat(t);
2036
+ throw new rt("EROOT", t);
2037
+ const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(tt(t), !1), o = await this.stat(t);
2037
2038
  await fs(i, t, { recursive: n, force: r }), await this.notifyChange({ path: t, type: D.Removed, isDirectory: o.isDirectory });
2038
2039
  }
2039
2040
  /**
@@ -2059,10 +2060,10 @@ class gs {
2059
2060
  try {
2060
2061
  const e = Et(t);
2061
2062
  if (!await this.exists(e))
2062
- throw new F("file", e);
2063
+ throw new R("file", e);
2063
2064
  return e;
2064
2065
  } catch (e) {
2065
- throw e instanceof w ? e : A(e, { path: t });
2066
+ throw e instanceof w ? e : v(e, { path: t });
2066
2067
  }
2067
2068
  }
2068
2069
  /**
@@ -2092,10 +2093,10 @@ class gs {
2092
2093
  try {
2093
2094
  const r = n?.overwrite ?? !1, i = await this.stat(t);
2094
2095
  if (await this.exists(e) && !r)
2095
- throw new K(e);
2096
+ throw new Q(e);
2096
2097
  await this.copy(t, e, { recursive: !0, overwrite: r }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: D.Removed, isDirectory: i.isDirectory }), await this.notifyChange({ path: e, type: D.Added, isDirectory: i.isDirectory });
2097
2098
  } catch (r) {
2098
- throw r instanceof w ? r : A(r, { path: t });
2099
+ throw r instanceof w ? r : v(r, { path: t });
2099
2100
  }
2100
2101
  }
2101
2102
  /**
@@ -2128,15 +2129,15 @@ class gs {
2128
2129
  try {
2129
2130
  const r = n?.recursive ?? !1, i = n?.overwrite ?? !0;
2130
2131
  if (!await this.exists(t))
2131
- throw new F("source", t);
2132
+ throw new R("source", t);
2132
2133
  if (await this.exists(e) && !i)
2133
- throw new K(e);
2134
+ throw new Q(e);
2134
2135
  if ((await this.stat(t)).isFile) {
2135
2136
  const h = await this.readFile(t);
2136
2137
  await this.writeFile(e, h);
2137
2138
  } else {
2138
2139
  if (!r)
2139
- throw new L("file", "directory", t);
2140
+ throw new nt("directory", t);
2140
2141
  await this.mkdir(e, { recursive: !0 });
2141
2142
  const h = await this.readDir(t);
2142
2143
  for (const c of h) {
@@ -2145,7 +2146,7 @@ class gs {
2145
2146
  }
2146
2147
  }
2147
2148
  } catch (r) {
2148
- throw r instanceof w ? r : A(r, { path: t });
2149
+ throw r instanceof w ? r : v(r, { path: t });
2149
2150
  }
2150
2151
  }
2151
2152
  /**
@@ -2218,15 +2219,21 @@ class gs {
2218
2219
  */
2219
2220
  async open(t, e) {
2220
2221
  await this.mount();
2221
- const { create: n = !1, exclusive: r = !1, truncate: i = !1 } = e || {}, o = G(Et(t));
2222
+ const { create: n = !1, exclusive: r = !1, truncate: i = !1 } = e || {}, o = B(Et(t));
2222
2223
  try {
2223
- return n && r ? await z(o, "exclusive", async () => {
2224
+ return n && r ? await L(o, "exclusive", async () => {
2224
2225
  if (await this.exists(o))
2225
- throw new K(o);
2226
+ throw new Q(o);
2226
2227
  return this._openFile(o, n, i);
2227
2228
  }) : await this._openFile(o, n, i);
2228
2229
  } catch (a) {
2229
- throw a instanceof w ? a : A(a, { path: o, isDirectory: !1 });
2230
+ if (a instanceof w)
2231
+ throw a;
2232
+ const l = a && a.name === "TypeMismatchError";
2233
+ throw v(a, {
2234
+ path: o,
2235
+ isDirectory: !!l
2236
+ });
2230
2237
  }
2231
2238
  }
2232
2239
  /**
@@ -2238,7 +2245,7 @@ class gs {
2238
2245
  try {
2239
2246
  await r.getFile();
2240
2247
  } catch (a) {
2241
- throw A(a, { path: t, isDirectory: !0 });
2248
+ throw v(a, { path: t, isDirectory: !0 });
2242
2249
  }
2243
2250
  const i = await ps(r, t);
2244
2251
  n && (i.truncate(0), i.flush());
@@ -2298,11 +2305,11 @@ class gs {
2298
2305
  try {
2299
2306
  const a = i ?? o.position, l = o.syncHandle.getSize(), { isEOF: h, actualLength: c } = ds(a, r, l);
2300
2307
  if (h)
2301
- return B({ bytesRead: 0, buffer: e }, [e.buffer]);
2308
+ return U({ bytesRead: 0, buffer: e }, [e.buffer]);
2302
2309
  const f = e.subarray(n, n + c), u = o.syncHandle.read(f, { at: a });
2303
- return i == null && (o.position = a + u), B({ bytesRead: u, buffer: e }, [e.buffer]);
2310
+ return i == null && (o.position = a + u), U({ bytesRead: u, buffer: e }, [e.buffer]);
2304
2311
  } catch (a) {
2305
- throw _("read", t, o.path, a);
2312
+ throw W("read", t, o.path, a);
2306
2313
  }
2307
2314
  }
2308
2315
  /**
@@ -2333,7 +2340,7 @@ class gs {
2333
2340
  const h = i ?? a.position, c = e.subarray(n, n + l), f = a.syncHandle.write(c, { at: h });
2334
2341
  return (i == null || i === a.position) && (a.position = h + f), o && await this.notifyChange({ path: a.path, type: D.Changed, isDirectory: !1 }), f;
2335
2342
  } catch (h) {
2336
- throw _("write", t, a.path, h);
2343
+ throw W("write", t, a.path, h);
2337
2344
  }
2338
2345
  }
2339
2346
  /**
@@ -2381,7 +2388,7 @@ class gs {
2381
2388
  try {
2382
2389
  n.syncHandle.truncate(e), n.syncHandle.flush(), n.position > e && (n.position = e), await this.notifyChange({ path: n.path, type: D.Changed, isDirectory: !1 });
2383
2390
  } catch (r) {
2384
- throw _("truncate", t, n.path, r);
2391
+ throw W("truncate", t, n.path, r);
2385
2392
  }
2386
2393
  }
2387
2394
  /**
@@ -2403,7 +2410,7 @@ class gs {
2403
2410
  try {
2404
2411
  e.syncHandle.flush();
2405
2412
  } catch (n) {
2406
- throw _("sync", t, e.path, n);
2413
+ throw W("sync", t, e.path, n);
2407
2414
  }
2408
2415
  }
2409
2416
  /**
@@ -2425,8 +2432,6 @@ class gs {
2425
2432
  * This is useful for importing data from external sources or syncing with remote data.
2426
2433
  *
2427
2434
  * @param entries - Array of [path, data] tuples to sync
2428
- * @param options - Options for synchronization
2429
- * @param options.cleanBefore - Whether to clear the file system before syncing (default: false)
2430
2435
  * @returns Promise that resolves when synchronization is complete
2431
2436
  * @throws {OPFSError} If the synchronization fails
2432
2437
  *
@@ -2450,17 +2455,17 @@ class gs {
2450
2455
  await this.mount();
2451
2456
  try {
2452
2457
  for (const [e, n] of t) {
2453
- const r = G(e);
2458
+ const r = B(e);
2454
2459
  let i;
2455
2460
  n instanceof Blob ? i = await us(n) : typeof n == "string" ? i = new TextEncoder().encode(n) : i = n, await this.writeFile(r, i);
2456
2461
  }
2457
2462
  } catch (e) {
2458
- throw e instanceof w ? e : A(e);
2463
+ throw e instanceof w ? e : v(e);
2459
2464
  }
2460
2465
  }
2461
2466
  }
2462
2467
  typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && ot(new gs());
2463
- //# sourceMappingURL=worker-1Wh1cr7P.js.map
2468
+ //# sourceMappingURL=worker-DYYLzR1Y.js.map
2464
2469
  `, p = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", f], { type: "text/javascript;charset=utf-8" });
2465
2470
  function m(a) {
2466
2471
  let n;
@@ -2488,9 +2493,10 @@ function i(a) {
2488
2493
  }
2489
2494
  class y {
2490
2495
  #n;
2496
+ #t;
2491
2497
  promises = this;
2492
2498
  constructor(n) {
2493
- this.#n = u(new m()), n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), this.setOptions(n));
2499
+ this.#t = new m(), this.#n = u(this.#t), n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), this.setOptions(n));
2494
2500
  }
2495
2501
  /**
2496
2502
  * Start watching a file or directory for changes
@@ -2700,12 +2706,6 @@ class y {
2700
2706
  async fsync(n) {
2701
2707
  return this.#n.fsync(n);
2702
2708
  }
2703
- /**
2704
- * Dispose of resources and clean up the file system instance
2705
- */
2706
- dispose() {
2707
- this.#n.dispose();
2708
- }
2709
2709
  /**
2710
2710
  * Synchronize the file system with external data
2711
2711
  */
@@ -2734,6 +2734,19 @@ class y {
2734
2734
  const r = i(n), s = c(t, e);
2735
2735
  return this.#n.appendFile(r, s);
2736
2736
  }
2737
+ /**
2738
+ * Dispose of resources, detach the worker and clean up the file system instance
2739
+ */
2740
+ dispose() {
2741
+ const n = this.#n, t = this.#t;
2742
+ (async () => {
2743
+ try {
2744
+ await n.dispose();
2745
+ } finally {
2746
+ t.terminate();
2747
+ }
2748
+ })();
2749
+ }
2737
2750
  }
2738
2751
  function b(a) {
2739
2752
  return new y(a);
@@ -2747,45 +2760,43 @@ export {
2747
2760
  A as FileSystemOperationError,
2748
2761
  T as FileTypeError,
2749
2762
  R as IOError,
2750
- I as InitializationFailedError,
2751
- C as OPFSError,
2763
+ C as InitializationFailedError,
2764
+ I as OPFSError,
2752
2765
  y as OPFSFileSystem,
2753
- $ as OPFSNotSupportedError,
2754
- D as OperationAbortedError,
2766
+ D as OPFSNotSupportedError,
2767
+ $ as OperationAbortedError,
2755
2768
  _ as OperationNotSupportedError,
2756
2769
  N as PathError,
2757
- z as PathResolutionFailedError,
2758
2770
  k as PermissionError,
2759
- M as StorageError,
2760
- j as TimeoutError,
2761
- W as ValidationError,
2762
- L as WatchEventType,
2763
- U as basename,
2764
- H as buffersEqual,
2765
- B as calculateFileHash,
2766
- G as calculateReadLength,
2767
- q as checkOPFSSupport,
2768
- Y as convertBlobToUint8Array,
2769
- V as createBuffer,
2770
- X as createFDError,
2771
- Z as createSyncHandleSafe,
2771
+ z as StorageError,
2772
+ M as ValidationError,
2773
+ j as WatchEventType,
2774
+ L as basename,
2775
+ W as buffersEqual,
2776
+ U as calculateFileHash,
2777
+ H as calculateReadLength,
2778
+ B as checkOPFSSupport,
2779
+ G as convertBlobToUint8Array,
2780
+ Y as createBuffer,
2781
+ q as createFDError,
2782
+ V as createSyncHandleSafe,
2772
2783
  b as createWorker,
2773
2784
  l as decodeBuffer,
2774
- J as dirname,
2785
+ Z as dirname,
2775
2786
  c as encodeString,
2776
- K as extname,
2787
+ J as extname,
2777
2788
  h as isBinaryFileExtension,
2778
- Q as isPathExcluded,
2779
- nn as joinPath,
2780
- tn as mapDomError,
2781
- en as matchMinimatch,
2782
- rn as normalizeMinimatch,
2783
- sn as normalizePath,
2784
- an as removeEntry,
2785
- on as resolvePath,
2786
- cn as safeCloseSyncHandle,
2787
- hn as splitPath,
2788
- ln as validateReadWriteArgs,
2789
- pn as withLock
2789
+ X as isPathExcluded,
2790
+ K as joinPath,
2791
+ Q as mapDomError,
2792
+ nn as matchMinimatch,
2793
+ tn as normalizeMinimatch,
2794
+ en as normalizePath,
2795
+ rn as removeEntry,
2796
+ sn as resolvePath,
2797
+ an as safeCloseSyncHandle,
2798
+ on as splitPath,
2799
+ cn as validateReadWriteArgs,
2800
+ hn as withLock
2790
2801
  };
2791
2802
  //# sourceMappingURL=index.js.map