opfs-worker 2.1.1 → 2.1.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.
Files changed (100) hide show
  1. package/README.md +21 -20
  2. package/dist/BaseOPFS-Bu7FZtCb.cjs +2 -0
  3. package/dist/BaseOPFS-Bu7FZtCb.cjs.map +1 -0
  4. package/dist/{BaseOPFS-BusBkyJX.js → BaseOPFS-C3NE4BKr.js} +790 -548
  5. package/dist/BaseOPFS-C3NE4BKr.js.map +1 -0
  6. package/dist/OPFSAsync-C0RsxCX5.cjs +2 -0
  7. package/dist/OPFSAsync-C0RsxCX5.cjs.map +1 -0
  8. package/dist/{OPFSAsync-CO44W23e.js → OPFSAsync-aeLUdIqd.js} +19 -19
  9. package/dist/OPFSAsync-aeLUdIqd.js.map +1 -0
  10. package/dist/{OPFSFacade-hrNXCn6w.cjs → OPFSFacade-BJv2yuWU.cjs} +2 -2
  11. package/dist/{OPFSFacade-hrNXCn6w.cjs.map → OPFSFacade-BJv2yuWU.cjs.map} +1 -1
  12. package/dist/{OPFSFacade-CEaSqTut.js → OPFSFacade-DiogtQoq.js} +2 -2
  13. package/dist/{OPFSFacade-CEaSqTut.js.map → OPFSFacade-DiogtQoq.js.map} +1 -1
  14. package/dist/OPFSSync-3qlSBYmz.cjs +2 -0
  15. package/dist/OPFSSync-3qlSBYmz.cjs.map +1 -0
  16. package/dist/{OPFSSync-D7obTsl3.js → OPFSSync-CvSOswhW.js} +57 -57
  17. package/dist/OPFSSync-CvSOswhW.js.map +1 -0
  18. package/dist/assets/dedicated.worker-Bqqr9UBA.js.map +1 -0
  19. package/dist/core/BaseOPFS.d.ts +23 -3
  20. package/dist/core/BaseOPFS.d.ts.map +1 -1
  21. package/dist/core/OPFSAsync.d.ts.map +1 -1
  22. package/dist/core/OPFSSync.d.ts.map +1 -1
  23. package/dist/createOPFSAsync-B611B63X.js +10 -0
  24. package/dist/{createOPFSAsync-DdhJYoC0.js.map → createOPFSAsync-B611B63X.js.map} +1 -1
  25. package/dist/createOPFSAsync-BATjJg8k.cjs +2 -0
  26. package/dist/{createOPFSAsync-DyWpvmL-.cjs.map → createOPFSAsync-BATjJg8k.cjs.map} +1 -1
  27. package/dist/{createOPFSDedicated-BwTc0NV5.js → createOPFSDedicated-DgudPTB8.js} +1086 -817
  28. package/dist/createOPFSDedicated-DgudPTB8.js.map +1 -0
  29. package/dist/{createOPFSDedicated-CEeRexom.cjs → createOPFSDedicated-EmIwluQo.cjs} +1037 -797
  30. package/dist/createOPFSDedicated-EmIwluQo.cjs.map +1 -0
  31. package/dist/{createOPFSShared-BSFWsoLe.js → createOPFSShared-BWYln8jJ.js} +2 -2
  32. package/dist/{createOPFSShared-BSFWsoLe.js.map → createOPFSShared-BWYln8jJ.js.map} +1 -1
  33. package/dist/{createOPFSShared-BoCft_BS.cjs → createOPFSShared-DPJpCd7z.cjs} +2 -2
  34. package/dist/{createOPFSShared-BoCft_BS.cjs.map → createOPFSShared-DPJpCd7z.cjs.map} +1 -1
  35. package/dist/dedicated.worker.js +1034 -794
  36. package/dist/dedicated.worker.js.map +1 -1
  37. package/dist/facade/createOPFSDedicated.d.ts +4 -2
  38. package/dist/facade/createOPFSDedicated.d.ts.map +1 -1
  39. package/dist/index.async.cjs +1 -1
  40. package/dist/index.async.js +33 -32
  41. package/dist/index.cjs +1 -1
  42. package/dist/index.d.ts +1 -5
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +44 -43
  45. package/dist/index.pure.cjs +1 -1
  46. package/dist/index.pure.js +38 -37
  47. package/dist/index.sharedworker.cjs +1 -1
  48. package/dist/index.sharedworker.js +34 -33
  49. package/dist/index.sync.cjs +1 -1
  50. package/dist/index.sync.d.ts +2 -0
  51. package/dist/index.sync.d.ts.map +1 -1
  52. package/dist/index.sync.js +34 -32
  53. package/dist/shared.worker.js +1056 -820
  54. package/dist/shared.worker.js.map +1 -1
  55. package/dist/types.d.ts +5 -5
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/utils/helpers.d.ts +13 -3
  58. package/dist/utils/helpers.d.ts.map +1 -1
  59. package/dist/worker/createDedicatedWorker.d.ts +8 -3
  60. package/dist/worker/createDedicatedWorker.d.ts.map +1 -1
  61. package/docs/README.md +18 -0
  62. package/docs/api/README.md +221 -0
  63. package/docs/{file-descriptors.md → api/file-descriptors.md} +13 -13
  64. package/docs/guides/async.md +2 -2
  65. package/docs/guides/dedicated.md +6 -4
  66. package/docs/guides/hashing.md +1 -1
  67. package/docs/guides/pure.md +1 -1
  68. package/docs/guides/sharedworker.md +1 -1
  69. package/docs/guides/streaming.md +2 -2
  70. package/docs/migration.md +8 -9
  71. package/docs/types.md +4 -4
  72. package/package.json +10 -9
  73. package/src/core/BaseOPFS.ts +46 -4
  74. package/src/core/OPFSAsync.ts +4 -5
  75. package/src/core/OPFSSync.ts +6 -7
  76. package/src/facade/createOPFSDedicated.ts +4 -2
  77. package/src/index.sync.ts +2 -0
  78. package/src/index.ts +1 -5
  79. package/src/types.ts +5 -3
  80. package/src/utils/helpers.ts +32 -6
  81. package/src/worker/createDedicatedWorker.ts +85 -7
  82. package/src/worker/dedicated.worker.ts +12 -1
  83. package/dist/BaseOPFS-BusBkyJX.js.map +0 -1
  84. package/dist/BaseOPFS-CYwrD7-q.cjs +0 -4
  85. package/dist/BaseOPFS-CYwrD7-q.cjs.map +0 -1
  86. package/dist/OPFSAsync-B2dR-2VR.cjs +0 -2
  87. package/dist/OPFSAsync-B2dR-2VR.cjs.map +0 -1
  88. package/dist/OPFSAsync-CO44W23e.js.map +0 -1
  89. package/dist/OPFSSync-BPrNtvFS.cjs +0 -2
  90. package/dist/OPFSSync-BPrNtvFS.cjs.map +0 -1
  91. package/dist/OPFSSync-D7obTsl3.js.map +0 -1
  92. package/dist/assets/dedicated.worker-DW6UqFo0.js.map +0 -1
  93. package/dist/createOPFSAsync-DdhJYoC0.js +0 -10
  94. package/dist/createOPFSAsync-DyWpvmL-.cjs +0 -2
  95. package/dist/createOPFSDedicated-BwTc0NV5.js.map +0 -1
  96. package/dist/createOPFSDedicated-CEeRexom.cjs.map +0 -1
  97. package/docs/api/backend.md +0 -36
  98. package/docs/api/create.md +0 -82
  99. package/docs/api/facade.md +0 -53
  100. package/docs/choosing-a-mode.md +0 -41
@@ -1,19 +1,14 @@
1
- /**
2
- * @license
3
- * Copyright 2019 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- const St = Symbol("Comlink.proxy"), zt = Symbol("Comlink.endpoint"), Lt = Symbol("Comlink.releaseProxy"), Y = Symbol("Comlink.finalizer"), H = Symbol("Comlink.thrown"), bt = (s) => typeof s == "object" && s !== null || typeof s == "function", _t = {
7
- canHandle: (s) => bt(s) && s[St],
1
+ const bt = /* @__PURE__ */ Symbol("Comlink.proxy"), Wt = /* @__PURE__ */ Symbol("Comlink.endpoint"), jt = /* @__PURE__ */ Symbol("Comlink.releaseProxy"), q = /* @__PURE__ */ Symbol("Comlink.finalizer"), I = /* @__PURE__ */ Symbol("Comlink.thrown"), xt = (s) => typeof s == "object" && s !== null || typeof s == "function", Ht = {
2
+ canHandle: (s) => xt(s) && s[bt],
8
3
  serialize(s) {
9
4
  const { port1: t, port2: e } = new MessageChannel();
10
- return rt(s, t), [e, [e]];
5
+ return nt(s, t), [e, [e]];
11
6
  },
12
7
  deserialize(s) {
13
- return s.start(), Bt(s);
8
+ return s.start(), qt(s);
14
9
  }
15
- }, Wt = {
16
- canHandle: (s) => bt(s) && H in s,
10
+ }, Bt = {
11
+ canHandle: (s) => xt(s) && I in s,
17
12
  serialize({ value: s }) {
18
13
  let t;
19
14
  return s instanceof Error ? t = {
@@ -28,81 +23,81 @@ const St = Symbol("Comlink.proxy"), zt = Symbol("Comlink.endpoint"), Lt = Symbol
28
23
  deserialize(s) {
29
24
  throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
30
25
  }
31
- }, xt = /* @__PURE__ */ new Map([
32
- ["proxy", _t],
33
- ["throw", Wt]
26
+ }, At = /* @__PURE__ */ new Map([
27
+ ["proxy", Ht],
28
+ ["throw", Bt]
34
29
  ]);
35
- function Ht(s, t) {
30
+ function Ut(s, t) {
36
31
  for (const e of s)
37
32
  if (t === e || e === "*" || e instanceof RegExp && e.test(t))
38
33
  return !0;
39
34
  return !1;
40
35
  }
41
- function rt(s, t = globalThis, e = ["*"]) {
42
- t.addEventListener("message", function n(r) {
43
- if (!r || !r.data)
36
+ function nt(s, t = globalThis, e = ["*"]) {
37
+ t.addEventListener("message", function r(n) {
38
+ if (!n || !n.data)
44
39
  return;
45
- if (!Ht(e, r.origin)) {
46
- console.warn(`Invalid origin '${r.origin}' for comlink proxy`);
40
+ if (!Ut(e, n.origin)) {
41
+ console.warn(`Invalid origin '${n.origin}' for comlink proxy`);
47
42
  return;
48
43
  }
49
- const { id: i, type: o, path: c } = Object.assign({ path: [] }, r.data), a = (r.data.argumentList || []).map(M);
50
- let h;
44
+ const { id: i, type: o, path: a } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map($);
45
+ let l;
51
46
  try {
52
- const l = c.slice(0, -1).reduce((u, d) => u[d], s), f = c.reduce((u, d) => u[d], s);
47
+ const h = a.slice(0, -1).reduce((f, p) => f[p], s), u = a.reduce((f, p) => f[p], s);
53
48
  switch (o) {
54
49
  case "GET":
55
- h = f;
50
+ l = u;
56
51
  break;
57
52
  case "SET":
58
- l[c.slice(-1)[0]] = M(r.data.value), h = !0;
53
+ h[a.slice(-1)[0]] = $(n.data.value), l = !0;
59
54
  break;
60
55
  case "APPLY":
61
- h = f.apply(l, a);
56
+ l = u.apply(h, c);
62
57
  break;
63
58
  case "CONSTRUCT":
64
59
  {
65
- const u = new f(...a);
66
- h = Vt(u);
60
+ const f = new u(...c);
61
+ l = Zt(f);
67
62
  }
68
63
  break;
69
64
  case "ENDPOINT":
70
65
  {
71
- const { port1: u, port2: d } = new MessageChannel();
72
- rt(s, d), h = vt(u, [u]);
66
+ const { port1: f, port2: p } = new MessageChannel();
67
+ nt(s, p), l = Dt(f, [f]);
73
68
  }
74
69
  break;
75
70
  case "RELEASE":
76
- h = void 0;
71
+ l = void 0;
77
72
  break;
78
73
  default:
79
74
  return;
80
75
  }
81
- } catch (l) {
82
- h = { value: l, [H]: 0 };
76
+ } catch (h) {
77
+ l = { value: h, [I]: 0 };
83
78
  }
84
- Promise.resolve(h).catch((l) => ({ value: l, [H]: 0 })).then((l) => {
85
- const [f, u] = G(l);
86
- t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u), o === "RELEASE" && (t.removeEventListener("message", n), Ot(t), Y in s && typeof s[Y] == "function" && s[Y]());
87
- }).catch((l) => {
88
- const [f, u] = G({
79
+ Promise.resolve(l).catch((h) => ({ value: h, [I]: 0 })).then((h) => {
80
+ const [u, f] = H(h);
81
+ t.postMessage(Object.assign(Object.assign({}, u), { id: i }), f), o === "RELEASE" && (t.removeEventListener("message", r), Ot(t), q in s && typeof s[q] == "function" && s[q]());
82
+ }).catch((h) => {
83
+ const [u, f] = H({
89
84
  value: new TypeError("Unserializable return value"),
90
- [H]: 0
85
+ [I]: 0
91
86
  });
92
- t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u);
87
+ t.postMessage(Object.assign(Object.assign({}, u), { id: i }), f);
93
88
  });
94
89
  }), t.start && t.start();
95
90
  }
96
- function jt(s) {
91
+ function Gt(s) {
97
92
  return s.constructor.name === "MessagePort";
98
93
  }
99
94
  function Ot(s) {
100
- jt(s) && s.close();
95
+ Gt(s) && s.close();
101
96
  }
102
- function Bt(s, t) {
97
+ function qt(s, t) {
103
98
  const e = /* @__PURE__ */ new Map();
104
- return s.addEventListener("message", function(r) {
105
- const { data: i } = r;
99
+ return s.addEventListener("message", function(n) {
100
+ const { data: i } = n;
106
101
  if (!i || !i.id)
107
102
  return;
108
103
  const o = e.get(i.id);
@@ -112,112 +107,112 @@ function Bt(s, t) {
112
107
  } finally {
113
108
  e.delete(i.id);
114
109
  }
115
- }), K(s, e, [], t);
110
+ }), J(s, e, [], t);
116
111
  }
117
112
  function _(s) {
118
113
  if (s)
119
114
  throw new Error("Proxy has been released and is not useable");
120
115
  }
121
- function Dt(s) {
122
- return C(s, /* @__PURE__ */ new Map(), {
116
+ function Mt(s) {
117
+ return v(s, /* @__PURE__ */ new Map(), {
123
118
  type: "RELEASE"
124
119
  }).then(() => {
125
120
  Ot(s);
126
121
  });
127
122
  }
128
- const B = /* @__PURE__ */ new WeakMap(), U = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
129
- const t = (B.get(s) || 0) - 1;
130
- B.set(s, t), t === 0 && Dt(s);
123
+ const W = /* @__PURE__ */ new WeakMap(), j = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
124
+ const t = (W.get(s) || 0) - 1;
125
+ W.set(s, t), t === 0 && Mt(s);
131
126
  });
132
- function Ut(s, t) {
133
- const e = (B.get(t) || 0) + 1;
134
- B.set(t, e), U && U.register(s, t, s);
127
+ function Vt(s, t) {
128
+ const e = (W.get(t) || 0) + 1;
129
+ W.set(t, e), j && j.register(s, t, s);
135
130
  }
136
- function Gt(s) {
137
- U && U.unregister(s);
131
+ function Xt(s) {
132
+ j && j.unregister(s);
138
133
  }
139
- function K(s, t, e = [], n = function() {
134
+ function J(s, t, e = [], r = function() {
140
135
  }) {
141
- let r = !1;
142
- const i = new Proxy(n, {
143
- get(o, c) {
144
- if (_(r), c === Lt)
136
+ let n = !1;
137
+ const i = new Proxy(r, {
138
+ get(o, a) {
139
+ if (_(n), a === jt)
145
140
  return () => {
146
- Gt(i), Dt(s), t.clear(), r = !0;
141
+ Xt(i), Mt(s), t.clear(), n = !0;
147
142
  };
148
- if (c === "then") {
143
+ if (a === "then") {
149
144
  if (e.length === 0)
150
145
  return { then: () => i };
151
- const a = C(s, t, {
146
+ const c = v(s, t, {
152
147
  type: "GET",
153
- path: e.map((h) => h.toString())
154
- }).then(M);
155
- return a.then.bind(a);
148
+ path: e.map((l) => l.toString())
149
+ }).then($);
150
+ return c.then.bind(c);
156
151
  }
157
- return K(s, t, [...e, c]);
152
+ return J(s, t, [...e, a]);
158
153
  },
159
- set(o, c, a) {
160
- _(r);
161
- const [h, l] = G(a);
162
- return C(s, t, {
154
+ set(o, a, c) {
155
+ _(n);
156
+ const [l, h] = H(c);
157
+ return v(s, t, {
163
158
  type: "SET",
164
- path: [...e, c].map((f) => f.toString()),
165
- value: h
166
- }, l).then(M);
159
+ path: [...e, a].map((u) => u.toString()),
160
+ value: l
161
+ }, h).then($);
167
162
  },
168
- apply(o, c, a) {
169
- _(r);
170
- const h = e[e.length - 1];
171
- if (h === zt)
172
- return C(s, t, {
163
+ apply(o, a, c) {
164
+ _(n);
165
+ const l = e[e.length - 1];
166
+ if (l === Wt)
167
+ return v(s, t, {
173
168
  type: "ENDPOINT"
174
- }).then(M);
175
- if (h === "bind")
176
- return K(s, t, e.slice(0, -1));
177
- const [l, f] = ct(a);
178
- return C(s, t, {
169
+ }).then($);
170
+ if (l === "bind")
171
+ return J(s, t, e.slice(0, -1));
172
+ const [h, u] = ct(c);
173
+ return v(s, t, {
179
174
  type: "APPLY",
180
- path: e.map((u) => u.toString()),
181
- argumentList: l
182
- }, f).then(M);
175
+ path: e.map((f) => f.toString()),
176
+ argumentList: h
177
+ }, u).then($);
183
178
  },
184
- construct(o, c) {
185
- _(r);
186
- const [a, h] = ct(c);
187
- return C(s, t, {
179
+ construct(o, a) {
180
+ _(n);
181
+ const [c, l] = ct(a);
182
+ return v(s, t, {
188
183
  type: "CONSTRUCT",
189
- path: e.map((l) => l.toString()),
190
- argumentList: a
191
- }, h).then(M);
184
+ path: e.map((h) => h.toString()),
185
+ argumentList: c
186
+ }, l).then($);
192
187
  }
193
188
  });
194
- return Ut(i, s), i;
189
+ return Vt(i, s), i;
195
190
  }
196
- function qt(s) {
191
+ function Yt(s) {
197
192
  return Array.prototype.concat.apply([], s);
198
193
  }
199
194
  function ct(s) {
200
- const t = s.map(G);
201
- return [t.map((e) => e[0]), qt(t.map((e) => e[1]))];
195
+ const t = s.map(H);
196
+ return [t.map((e) => e[0]), Yt(t.map((e) => e[1]))];
202
197
  }
203
- const At = /* @__PURE__ */ new WeakMap();
204
- function vt(s, t) {
205
- return At.set(s, t), s;
198
+ const Tt = /* @__PURE__ */ new WeakMap();
199
+ function Dt(s, t) {
200
+ return Tt.set(s, t), s;
206
201
  }
207
- function Vt(s) {
208
- return Object.assign(s, { [St]: !0 });
202
+ function Zt(s) {
203
+ return Object.assign(s, { [bt]: !0 });
209
204
  }
210
- function G(s) {
211
- for (const [t, e] of xt)
205
+ function H(s) {
206
+ for (const [t, e] of At)
212
207
  if (e.canHandle(s)) {
213
- const [n, r] = e.serialize(s);
208
+ const [r, n] = e.serialize(s);
214
209
  return [
215
210
  {
216
211
  type: "HANDLER",
217
212
  name: t,
218
- value: n
213
+ value: r
219
214
  },
220
- r
215
+ n
221
216
  ];
222
217
  }
223
218
  return [
@@ -225,28 +220,28 @@ function G(s) {
225
220
  type: "RAW",
226
221
  value: s
227
222
  },
228
- At.get(s) || []
223
+ Tt.get(s) || []
229
224
  ];
230
225
  }
231
- function M(s) {
226
+ function $(s) {
232
227
  switch (s.type) {
233
228
  case "HANDLER":
234
- return xt.get(s.name).deserialize(s.value);
229
+ return At.get(s.name).deserialize(s.value);
235
230
  case "RAW":
236
231
  return s.value;
237
232
  }
238
233
  }
239
- function C(s, t, e, n) {
240
- return new Promise((r) => {
241
- const i = Yt();
242
- t.set(i, r), s.start && s.start(), s.postMessage(Object.assign({ id: i }, e), n);
234
+ function v(s, t, e, r) {
235
+ return new Promise((n) => {
236
+ const i = Jt();
237
+ t.set(i, n), s.start && s.start(), s.postMessage(Object.assign({ id: i }, e), r);
243
238
  });
244
239
  }
245
- function Yt() {
240
+ function Jt() {
246
241
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
247
242
  }
248
- var A = /* @__PURE__ */ ((s) => (s.Added = "added", s.Changed = "changed", s.Removed = "removed", s))(A || {});
249
- const Zt = {
243
+ var M = /* @__PURE__ */ ((s) => (s.Added = "added", s.Changed = "changed", s.Removed = "removed", s))(M || {});
244
+ const Qt = {
250
245
  ENOENT: -2,
251
246
  // No such file or directory
252
247
  EISDIR: -21,
@@ -282,95 +277,95 @@ class w extends Error {
282
277
  errno;
283
278
  syscall;
284
279
  path;
285
- constructor(t, e, n, r, i) {
286
- super(t, { cause: i }), this.name = e, this.errno = Zt[e] || -1, this.path = n, this.syscall = r;
280
+ constructor(t, e, r, n, i) {
281
+ super(t, { cause: i }), this.name = e, this.errno = Qt[e] || -1, this.path = r, this.syscall = n;
287
282
  }
288
283
  }
289
- class Xt extends w {
284
+ class Kt extends w {
290
285
  constructor(t) {
291
286
  super("OPFS is not supported in this browser", "ENOTSUP", void 0, void 0, t);
292
287
  }
293
288
  }
294
- class Jt extends w {
295
- constructor(t, e, n) {
296
- super(t, "INVALID_PATH", e, "access", n);
289
+ class te extends w {
290
+ constructor(t, e, r) {
291
+ super(t, "INVALID_PATH", e, "access", r);
297
292
  }
298
293
  }
299
- class j extends w {
300
- constructor(t, e, n) {
301
- const r = {
294
+ class L extends w {
295
+ constructor(t, e, r) {
296
+ const n = {
302
297
  file: `File not found: ${e}`,
303
298
  directory: `Directory not found: ${e}`,
304
299
  source: `Source does not exist: ${e}`
305
300
  };
306
- super(r[t], "ENOENT", e, "access", n);
301
+ super(n[t], "ENOENT", e, "access", r);
307
302
  }
308
303
  }
309
- class Qt extends w {
310
- constructor(t, e, n) {
311
- super(`Permission denied for ${e} on: ${t}`, "EACCES", t, e, n);
304
+ class ee extends w {
305
+ constructor(t, e, r) {
306
+ super(`Permission denied for ${e} on: ${t}`, "EACCES", t, e, r);
312
307
  }
313
308
  }
314
- class Kt extends w {
315
- constructor(t, e, n) {
316
- super(t, "ENOSPC", e, "write", n);
309
+ class se extends w {
310
+ constructor(t, e, r) {
311
+ super(t, "ENOSPC", e, "write", r);
317
312
  }
318
313
  }
319
- class te extends w {
314
+ class ne extends w {
320
315
  constructor(t, e) {
321
316
  super(`File is busy: ${t}`, "EBUSY", t, "open", e);
322
317
  }
323
318
  }
324
- class tt extends w {
325
- constructor(t, e, n) {
326
- const r = t === "directory" ? `Is a directory: ${e}` : `Not a directory: ${e}`, i = t === "directory" ? "EISDIR" : "ENOTDIR";
327
- super(r, i, e, "access", n);
319
+ class Q extends w {
320
+ constructor(t, e, r) {
321
+ const n = t === "directory" ? `Is a directory: ${e}` : `Not a directory: ${e}`, i = t === "directory" ? "EISDIR" : "ENOTDIR";
322
+ super(n, i, e, "access", r);
328
323
  }
329
324
  }
330
325
  class lt extends w {
331
- constructor(t, e, n, r) {
326
+ constructor(t, e, r, n) {
332
327
  const i = {
333
328
  argument: "EINVAL",
334
329
  format: "INVALID_FORMAT",
335
330
  descriptor: "EBADF",
336
331
  overflow: "ERANGE"
337
332
  };
338
- super(e, i[t], n, "validate", r);
333
+ super(e, i[t], r, "validate", n);
339
334
  }
340
335
  }
341
- class ee extends w {
336
+ class re extends w {
342
337
  constructor(t, e) {
343
338
  super(`Operation aborted: ${t}`, "EINTR", t, "interrupt", e);
344
339
  }
345
340
  }
346
341
  class ht extends w {
347
- constructor(t, e, n) {
348
- super(t, "EIO", e, "io", n);
342
+ constructor(t, e, r) {
343
+ super(t, "EIO", e, "io", r);
349
344
  }
350
345
  }
351
- class v extends w {
346
+ class T extends w {
352
347
  constructor(t, e) {
353
348
  super(`Operation not supported: ${t}`, "ENOTSUP", t, "operation", e);
354
349
  }
355
350
  }
356
- class et extends w {
357
- constructor(t, e, n) {
358
- const r = {
351
+ class K extends w {
352
+ constructor(t, e, r) {
353
+ const n = {
359
354
  RM_FAILED: `Failed to remove entry: ${e}`,
360
355
  ENOTEMPTY: `Directory not empty: ${e}. Use recursive option to force removal.`,
361
356
  EROOT: "Cannot remove root directory"
362
357
  };
363
- super(r[t] || `Directory operation failed: ${e}`, t, e, "unlink", n);
358
+ super(n[t] || `Directory operation failed: ${e}`, t, e, "unlink", r);
364
359
  }
365
360
  }
366
- class se extends w {
361
+ class ie extends w {
367
362
  constructor(t, e) {
368
363
  super("Failed to initialize OPFS", "INIT_FAILED", t, "init", e);
369
364
  }
370
365
  }
371
- class Z extends w {
372
- constructor(t, e, n) {
373
- super(`Failed to ${t}: ${e}`, `${t.toUpperCase()}_FAILED`, e, t, n);
366
+ class V extends w {
367
+ constructor(t, e, r) {
368
+ super(`Failed to ${t}: ${e}`, `${t.toUpperCase()}_FAILED`, e, t, r);
374
369
  }
375
370
  }
376
371
  class ut extends w {
@@ -378,156 +373,189 @@ class ut extends w {
378
373
  super(`Destination already exists: ${t}`, "EEXIST", t, "open", e);
379
374
  }
380
375
  }
381
- function x(s, t) {
382
- const e = t?.path, n = t?.isDirectory, r = t?.existenceType ?? "file", i = t?.operation;
376
+ function A(s, t) {
377
+ const e = t?.path, r = t?.isDirectory, n = t?.existenceType ?? "file", i = t?.operation;
383
378
  switch (s.name) {
384
379
  case "InvalidStateError":
385
- return new te(e || "unknown", s);
380
+ return new ne(e || "unknown", s);
386
381
  case "QuotaExceededError":
387
- return new Kt(`No space left on device: ${e || "unknown"}`, e, s);
382
+ return new se(`No space left on device: ${e || "unknown"}`, e, s);
388
383
  case "NotFoundError":
389
- return new j(r, e, s);
384
+ return new L(n, e, s);
390
385
  case "TypeMismatchError":
391
- return n !== void 0 ? n ? new tt("directory", e || "unknown", s) : new tt("file", e || "unknown", s) : new lt("argument", `Type mismatch: ${e || "unknown"}`, e, s);
386
+ return r !== void 0 ? r ? new Q("directory", e || "unknown", s) : new Q("file", e || "unknown", s) : new lt("argument", `Type mismatch: ${e || "unknown"}`, e, s);
392
387
  case "NotAllowedError":
393
388
  case "SecurityError":
394
- return new Qt(e, "unknown", s);
389
+ return new ee(e, "unknown", s);
395
390
  case "InvalidModificationError":
396
- return i === "remove" ? new et("ENOTEMPTY", e, s) : new lt("argument", `Invalid modification: ${e || "unknown"}`, e, s);
391
+ return i === "remove" ? new K("ENOTEMPTY", e, s) : new lt("argument", `Invalid modification: ${e || "unknown"}`, e, s);
397
392
  case "AbortError":
398
- return new ee(e || "unknown", s);
393
+ return new re(e || "unknown", s);
399
394
  case "OperationError":
400
395
  return new ht(`Operation failed: ${e || "unknown"}`, e, s);
401
396
  case "TypeError":
402
- return new v(e || "unknown", s);
397
+ return new T(e || "unknown", s);
403
398
  default:
404
- return i === "remove" ? new et("RM_FAILED", e, s) : new ht(`I/O error: ${e || "unknown"}`, e, s);
399
+ return i === "remove" ? new K("RM_FAILED", e, s) : new ht(`I/O error: ${e || "unknown"}`, e, s);
405
400
  }
406
401
  }
407
402
  const Nt = (s, t, e) => {
408
- const n = s instanceof RegExp ? ft(s, e) : s, r = t instanceof RegExp ? ft(t, e) : t, i = n !== null && r != null && ne(n, r, e);
403
+ const r = s instanceof RegExp ? ft(s, e) : s, n = t instanceof RegExp ? ft(t, e) : t, i = r !== null && n != null && oe(r, n, e);
409
404
  return i && {
410
405
  start: i[0],
411
406
  end: i[1],
412
407
  pre: e.slice(0, i[0]),
413
- body: e.slice(i[0] + n.length, i[1]),
414
- post: e.slice(i[1] + r.length)
408
+ body: e.slice(i[0] + r.length, i[1]),
409
+ post: e.slice(i[1] + n.length)
415
410
  };
416
411
  }, ft = (s, t) => {
417
412
  const e = t.match(s);
418
413
  return e ? e[0] : null;
419
- }, ne = (s, t, e) => {
420
- let n, r, i, o, c, a = e.indexOf(s), h = e.indexOf(t, a + 1), l = a;
421
- if (a >= 0 && h > 0) {
414
+ }, oe = (s, t, e) => {
415
+ let r, n, i, o, a, c = e.indexOf(s), l = e.indexOf(t, c + 1), h = c;
416
+ if (c >= 0 && l > 0) {
422
417
  if (s === t)
423
- return [a, h];
424
- for (n = [], i = e.length; l >= 0 && !c; ) {
425
- if (l === a)
426
- n.push(l), a = e.indexOf(s, l + 1);
427
- else if (n.length === 1) {
428
- const f = n.pop();
429
- f !== void 0 && (c = [f, h]);
418
+ return [c, l];
419
+ for (r = [], i = e.length; h >= 0 && !a; ) {
420
+ if (h === c)
421
+ r.push(h), c = e.indexOf(s, h + 1);
422
+ else if (r.length === 1) {
423
+ const u = r.pop();
424
+ u !== void 0 && (a = [u, l]);
430
425
  } else
431
- r = n.pop(), r !== void 0 && r < i && (i = r, o = h), h = e.indexOf(t, l + 1);
432
- l = a < h && a >= 0 ? a : h;
426
+ n = r.pop(), n !== void 0 && n < i && (i = n, o = l), l = e.indexOf(t, h + 1);
427
+ h = c < l && c >= 0 ? c : l;
433
428
  }
434
- n.length && o !== void 0 && (c = [i, o]);
429
+ r.length && o !== void 0 && (a = [i, o]);
435
430
  }
436
- return c;
437
- }, Tt = "\0SLASH" + Math.random() + "\0", Mt = "\0OPEN" + Math.random() + "\0", it = "\0CLOSE" + Math.random() + "\0", Ct = "\0COMMA" + Math.random() + "\0", $t = "\0PERIOD" + Math.random() + "\0", re = new RegExp(Tt, "g"), ie = new RegExp(Mt, "g"), oe = new RegExp(it, "g"), ae = new RegExp(Ct, "g"), ce = new RegExp($t, "g"), le = /\\\\/g, he = /\\{/g, ue = /\\}/g, fe = /\\,/g, de = /\\./g;
431
+ return a;
432
+ }, $t = "\0SLASH" + Math.random() + "\0", vt = "\0OPEN" + Math.random() + "\0", rt = "\0CLOSE" + Math.random() + "\0", Pt = "\0COMMA" + Math.random() + "\0", Ct = "\0PERIOD" + Math.random() + "\0", ae = new RegExp($t, "g"), ce = new RegExp(vt, "g"), le = new RegExp(rt, "g"), he = new RegExp(Pt, "g"), ue = new RegExp(Ct, "g"), fe = /\\\\/g, pe = /\\{/g, de = /\\}/g, ge = /\\,/g, we = /\\\./g, ye = 1e5, me = 4e6;
438
433
  function X(s) {
439
434
  return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
440
435
  }
441
- function pe(s) {
442
- return s.replace(le, Tt).replace(he, Mt).replace(ue, it).replace(fe, Ct).replace(de, $t);
436
+ function Ee(s) {
437
+ return s.replace(fe, $t).replace(pe, vt).replace(de, rt).replace(ge, Pt).replace(we, Ct);
443
438
  }
444
- function ge(s) {
445
- return s.replace(re, "\\").replace(ie, "{").replace(oe, "}").replace(ae, ",").replace(ce, ".");
439
+ function Se(s) {
440
+ return s.replace(ae, "\\").replace(ce, "{").replace(le, "}").replace(he, ",").replace(ue, ".");
446
441
  }
447
- function Pt(s) {
442
+ function kt(s) {
448
443
  if (!s)
449
444
  return [""];
450
445
  const t = [], e = Nt("{", "}", s);
451
446
  if (!e)
452
447
  return s.split(",");
453
- const { pre: n, body: r, post: i } = e, o = n.split(",");
454
- o[o.length - 1] += "{" + r + "}";
455
- const c = Pt(i);
456
- return i.length && (o[o.length - 1] += c.shift(), o.push.apply(o, c)), t.push.apply(t, o), t;
448
+ const { pre: r, body: n, post: i } = e, o = r.split(",");
449
+ o[o.length - 1] += "{" + n + "}";
450
+ const a = kt(i);
451
+ return i.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
457
452
  }
458
- function we(s) {
459
- return s ? (s.slice(0, 2) === "{}" && (s = "\\{\\}" + s.slice(2)), F(pe(s), !0).map(ge)) : [];
453
+ function be(s, t = {}) {
454
+ if (!s)
455
+ return [];
456
+ const { max: e = ye, maxLength: r = me } = t;
457
+ return s.slice(0, 2) === "{}" && (s = "\\{\\}" + s.slice(2)), tt(Ee(s), e, r, !0).map(Se);
460
458
  }
461
- function me(s) {
459
+ function xe(s) {
462
460
  return "{" + s + "}";
463
461
  }
464
- function ye(s) {
462
+ function Ae(s) {
465
463
  return /^-?0\d/.test(s);
466
464
  }
467
- function Ee(s, t) {
465
+ function Oe(s, t) {
468
466
  return s <= t;
469
467
  }
470
- function Se(s, t) {
468
+ function Me(s, t) {
471
469
  return s >= t;
472
470
  }
473
- function F(s, t) {
474
- const e = [], n = Nt("{", "}", s);
475
- if (!n)
476
- return [s];
477
- const r = n.pre, i = n.post.length ? F(n.post, !1) : [""];
478
- if (/\$$/.test(n.pre))
479
- for (let o = 0; o < i.length; o++) {
480
- const c = r + "{" + n.body + "}" + i[o];
481
- e.push(c);
471
+ function C(s, t, e, r, n, i) {
472
+ const o = [];
473
+ let a = 0;
474
+ for (let c = 0; c < s.length; c++)
475
+ for (let l = 0; l < e.length; l++) {
476
+ if (o.length >= r)
477
+ return o;
478
+ const h = s[c] + t + e[l];
479
+ if (!(i && !h)) {
480
+ if (a + h.length > n)
481
+ return o;
482
+ o.push(h), a += h.length;
483
+ }
482
484
  }
483
- else {
484
- const o = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(n.body), c = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(n.body), a = o || c, h = n.body.indexOf(",") >= 0;
485
- if (!a && !h)
486
- return n.post.match(/,(?!,).*\}/) ? (s = n.pre + "{" + n.body + it + n.post, F(s)) : [s];
487
- let l;
488
- if (a)
489
- l = n.body.split(/\.\./);
490
- else if (l = Pt(n.body), l.length === 1 && l[0] !== void 0 && (l = F(l[0], !1).map(me), l.length === 1))
491
- return i.map((u) => n.pre + l[0] + u);
492
- let f;
493
- if (a && l[0] !== void 0 && l[1] !== void 0) {
494
- const u = X(l[0]), d = X(l[1]), g = Math.max(l[0].length, l[1].length);
495
- let p = l.length === 3 && l[2] !== void 0 ? Math.abs(X(l[2])) : 1, S = Ee;
496
- d < u && (p *= -1, S = Se);
497
- const P = l.some(ye);
498
- f = [];
499
- for (let b = u; S(b, d); b += p) {
500
- let m;
501
- if (c)
502
- m = String.fromCharCode(b), m === "\\" && (m = "");
503
- else if (m = String(b), P) {
504
- const k = g - m.length;
505
- if (k > 0) {
506
- const L = new Array(k + 1).join("0");
507
- b < 0 ? m = "-" + L + m.slice(1) : m = L + m;
508
- }
509
- }
510
- f.push(m);
485
+ return o;
486
+ }
487
+ function Te(s, t, e) {
488
+ const r = s.split(/\.\./), n = [];
489
+ if (r[0] === void 0 || r[1] === void 0)
490
+ return n;
491
+ const i = X(r[0]), o = X(r[1]), a = Math.max(r[0].length, r[1].length);
492
+ let c = r.length === 3 && r[2] !== void 0 ? Math.max(Math.abs(X(r[2])), 1) : 1, l = Oe;
493
+ o < i && (c *= -1, l = Me);
494
+ const u = r.some(Ae);
495
+ for (let f = i; l(f, o) && n.length < e; f += c) {
496
+ let p;
497
+ if (t)
498
+ p = String.fromCharCode(f), p === "\\" && (p = "");
499
+ else if (p = String(f), u) {
500
+ const g = a - p.length;
501
+ if (g > 0) {
502
+ const d = new Array(g + 1).join("0");
503
+ f < 0 ? p = "-" + d + p.slice(1) : p = d + p;
504
+ }
505
+ }
506
+ n.push(p);
507
+ }
508
+ return n;
509
+ }
510
+ function tt(s, t, e, r) {
511
+ let n = [""], i = !1, o = !0;
512
+ for (; ; ) {
513
+ const a = Nt("{", "}", s);
514
+ if (!a)
515
+ return C(n, s, [""], t, e, i);
516
+ const c = a.pre;
517
+ if (/\$$/.test(c)) {
518
+ if (n = C(n, c + "{" + a.body + "}", [""], t, e, i && !a.post.length), o = !1, !a.post.length)
519
+ break;
520
+ s = a.post;
521
+ continue;
522
+ }
523
+ const l = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(a.body), h = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(a.body), u = l || h, f = a.body.indexOf(",") >= 0;
524
+ if (!u && !f) {
525
+ if (a.post.match(/,(?!,).*\}/)) {
526
+ s = a.pre + "{" + a.body + rt + a.post, r = !0;
527
+ continue;
511
528
  }
512
- } else {
513
- f = [];
514
- for (let u = 0; u < l.length; u++)
515
- f.push.apply(f, F(l[u], !1));
529
+ return C(n, c + "{" + a.body + "}" + a.post, [""], t, e, i);
516
530
  }
517
- for (let u = 0; u < f.length; u++)
518
- for (let d = 0; d < i.length; d++) {
519
- const g = r + f[u] + i[d];
520
- (!t || a || g) && e.push(g);
531
+ o && (i = r && !u, o = !1);
532
+ let p;
533
+ if (u)
534
+ p = Te(a.body, h, t);
535
+ else {
536
+ let g = kt(a.body);
537
+ if (g.length === 1 && g[0] !== void 0 && (g = tt(g[0], t, e, !1).map(xe), g.length === 1)) {
538
+ if (n = C(n, c + g[0], [""], t, e, i && !a.post.length), !a.post.length)
539
+ break;
540
+ s = a.post;
541
+ continue;
521
542
  }
543
+ p = [];
544
+ for (let d = 0; d < g.length; d++)
545
+ p.push.apply(p, tt(g[d], t, e, !1));
546
+ }
547
+ if (n = C(n, c, p, t, e, i && !a.post.length), !a.post.length)
548
+ break;
549
+ s = a.post;
522
550
  }
523
- return e;
551
+ return n;
524
552
  }
525
- const be = 1024 * 64, q = (s) => {
553
+ const De = 1024 * 64, B = (s) => {
526
554
  if (typeof s != "string")
527
555
  throw new TypeError("invalid pattern");
528
- if (s.length > be)
556
+ if (s.length > De)
529
557
  throw new TypeError("pattern is too long");
530
- }, xe = {
558
+ }, Ne = {
531
559
  "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", !0],
532
560
  "[:alpha:]": ["\\p{L}\\p{Nl}", !0],
533
561
  "[:ascii:]": ["\\x00-\\x7f", !1],
@@ -542,77 +570,138 @@ const be = 1024 * 64, q = (s) => {
542
570
  "[:upper:]": ["\\p{Lu}", !0],
543
571
  "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", !0],
544
572
  "[:xdigit:]": ["A-Fa-f0-9", !1]
545
- }, R = (s) => s.replace(/[[\]\\-]/g, "\\$&"), Oe = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), dt = (s) => s.join(""), De = (s, t) => {
573
+ }, k = (s) => s.replace(/[[\]\\-]/g, "\\$&"), $e = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), pt = (s) => s.join(""), ve = (s, t) => {
546
574
  const e = t;
547
575
  if (s.charAt(e) !== "[")
548
576
  throw new Error("not in a brace expression");
549
- const n = [], r = [];
550
- let i = e + 1, o = !1, c = !1, a = !1, h = !1, l = e, f = "";
577
+ const r = [], n = [];
578
+ let i = e + 1, o = !1, a = !1, c = !1, l = !1, h = e, u = "";
551
579
  t: for (; i < s.length; ) {
552
- const p = s.charAt(i);
553
- if ((p === "!" || p === "^") && i === e + 1) {
554
- h = !0, i++;
580
+ const d = s.charAt(i);
581
+ if ((d === "!" || d === "^") && i === e + 1) {
582
+ l = !0, i++;
555
583
  continue;
556
584
  }
557
- if (p === "]" && o && !a) {
558
- l = i + 1;
585
+ if (d === "]" && o && !c) {
586
+ h = i + 1;
559
587
  break;
560
588
  }
561
- if (o = !0, p === "\\" && !a) {
562
- a = !0, i++;
589
+ if (o = !0, d === "\\" && !c) {
590
+ c = !0, i++;
563
591
  continue;
564
592
  }
565
- if (p === "[" && !a) {
566
- for (const [S, [N, P, b]] of Object.entries(xe))
567
- if (s.startsWith(S, i)) {
568
- if (f)
593
+ if (d === "[" && !c) {
594
+ for (const [E, [y, m, D]] of Object.entries(Ne))
595
+ if (s.startsWith(E, i)) {
596
+ if (u)
569
597
  return ["$.", !1, s.length - e, !0];
570
- i += S.length, b ? r.push(N) : n.push(N), c = c || P;
598
+ i += E.length, D ? n.push(y) : r.push(y), a = a || m;
571
599
  continue t;
572
600
  }
573
601
  }
574
- if (a = !1, f) {
575
- p > f ? n.push(R(f) + "-" + R(p)) : p === f && n.push(R(p)), f = "", i++;
602
+ if (c = !1, u) {
603
+ d > u ? r.push(k(u) + "-" + k(d)) : d === u && r.push(k(d)), u = "", i++;
576
604
  continue;
577
605
  }
578
606
  if (s.startsWith("-]", i + 1)) {
579
- n.push(R(p + "-")), i += 2;
607
+ r.push(k(d + "-")), i += 2;
580
608
  continue;
581
609
  }
582
610
  if (s.startsWith("-", i + 1)) {
583
- f = p, i += 2;
611
+ u = d, i += 2;
584
612
  continue;
585
613
  }
586
- n.push(R(p)), i++;
614
+ r.push(k(d)), i++;
587
615
  }
588
- if (l < i)
616
+ if (h < i)
589
617
  return ["", !1, 0, !1];
590
- if (!n.length && !r.length)
618
+ if (!r.length && !n.length)
591
619
  return ["$.", !1, s.length - e, !0];
592
- if (r.length === 0 && n.length === 1 && /^\\?.$/.test(n[0]) && !h) {
593
- const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
594
- return [Oe(p), !1, l - e, !1];
595
- }
596
- const u = "[" + (h ? "^" : "") + dt(n) + "]", d = "[" + (h ? "" : "^") + dt(r) + "]";
597
- return [n.length && r.length ? "(" + u + "|" + d + ")" : n.length ? u : d, c, l - e, !0];
598
- }, I = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1"), Ae = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), pt = (s) => Ae.has(s), ve = "(?!(?:^|/)\\.\\.?(?:$|/))", W = "(?!\\.)", Ne = /* @__PURE__ */ new Set(["[", "."]), Te = /* @__PURE__ */ new Set(["..", "."]), Me = new Set("().*{}+?[]^$\\!"), Ce = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), ot = "[^/]", gt = ot + "*?", wt = ot + "+?";
599
- class E {
620
+ if (n.length === 0 && r.length === 1 && /^\\?.$/.test(r[0]) && !l) {
621
+ const d = r[0].length === 2 ? r[0].slice(-1) : r[0];
622
+ return [$e(d), !1, h - e, !1];
623
+ }
624
+ const f = "[" + (l ? "^" : "") + pt(r) + "]", p = "[" + (l ? "" : "^") + pt(n) + "]";
625
+ return [r.length && n.length ? "(" + f + "|" + p + ")" : r.length ? f : p, a, h - e, !0];
626
+ }, R = (s, { windowsPathsNoEscape: t = !1, magicalBraces: e = !0 } = {}) => e ? t ? s.replace(/\[([^/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\])\]/g, "$1$2").replace(/\\([^/])/g, "$1") : t ? s.replace(/\[([^/\\{}])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^/\\{}])\]/g, "$1$2").replace(/\\([^/{}])/g, "$1");
627
+ var x;
628
+ const Pe = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), et = (s) => Pe.has(s), dt = (s) => et(s.type), Ce = /* @__PURE__ */ new Map([
629
+ ["!", ["@"]],
630
+ ["?", ["?", "@"]],
631
+ ["@", ["@"]],
632
+ ["*", ["*", "+", "?", "@"]],
633
+ ["+", ["+", "@"]]
634
+ ]), ke = /* @__PURE__ */ new Map([
635
+ ["!", ["?"]],
636
+ ["@", ["?"]],
637
+ ["+", ["?", "*"]]
638
+ ]), Re = /* @__PURE__ */ new Map([
639
+ ["!", ["?", "@"]],
640
+ ["?", ["?", "@"]],
641
+ ["@", ["?", "@"]],
642
+ ["*", ["*", "+", "?", "@"]],
643
+ ["+", ["+", "@", "?", "*"]]
644
+ ]), gt = /* @__PURE__ */ new Map([
645
+ ["!", /* @__PURE__ */ new Map([["!", "@"]])],
646
+ [
647
+ "?",
648
+ /* @__PURE__ */ new Map([
649
+ ["*", "*"],
650
+ ["+", "*"]
651
+ ])
652
+ ],
653
+ [
654
+ "@",
655
+ /* @__PURE__ */ new Map([
656
+ ["!", "!"],
657
+ ["?", "?"],
658
+ ["@", "@"],
659
+ ["*", "*"],
660
+ ["+", "+"]
661
+ ])
662
+ ],
663
+ [
664
+ "+",
665
+ /* @__PURE__ */ new Map([
666
+ ["?", "*"],
667
+ ["*", "*"]
668
+ ])
669
+ ]
670
+ ]), Fe = "(?!(?:^|/)\\.\\.?(?:$|/))", z = "(?!\\.)", _e = /* @__PURE__ */ new Set(["[", "."]), ze = /* @__PURE__ */ new Set(["..", "."]), Ie = new Set("().*{}+?[]^$\\!"), Le = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), it = "[^/]", wt = it + "*?", yt = it + "+?";
671
+ let We = 0;
672
+ class ot {
600
673
  type;
601
674
  #s;
602
675
  #n;
603
- #i = !1;
676
+ #r = !1;
604
677
  #t = [];
605
678
  #e;
606
- #o;
607
- #c;
608
- #a = !1;
609
- #r;
679
+ #a;
610
680
  #l;
681
+ #c = !1;
682
+ #i;
683
+ #o;
611
684
  // set to true if it's an extglob with no children
612
685
  // (which really means one child of '')
613
- #u = !1;
614
- constructor(t, e, n = {}) {
615
- this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#r = this.#s === this ? n : this.#s.#r, this.#c = this.#s === this ? [] : this.#s.#c, t === "!" && !this.#s.#a && this.#c.push(this), this.#o = this.#e ? this.#e.#t.length : 0;
686
+ #h = !1;
687
+ id = ++We;
688
+ get depth() {
689
+ return (this.#e?.depth ?? -1) + 1;
690
+ }
691
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
692
+ return {
693
+ "@@type": "AST",
694
+ id: this.id,
695
+ type: this.type,
696
+ root: this.#s.id,
697
+ parent: this.#e?.id,
698
+ depth: this.depth,
699
+ partsLength: this.#t.length,
700
+ parts: this.#t
701
+ };
702
+ }
703
+ constructor(t, e, r = {}) {
704
+ this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#i = this.#s === this ? r : this.#s.#i, this.#l = this.#s === this ? [] : this.#s.#l, t === "!" && !this.#s.#c && this.#l.push(this), this.#a = this.#e ? this.#e.#t.length : 0;
616
705
  }
617
706
  get hasMagic() {
618
707
  if (this.#n !== void 0)
@@ -624,27 +713,27 @@ class E {
624
713
  }
625
714
  // reconstructs the pattern
626
715
  toString() {
627
- return this.#l !== void 0 ? this.#l : this.type ? this.#l = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#l = this.#t.map((t) => String(t)).join("");
716
+ return this.#o !== void 0 ? this.#o : this.type ? this.#o = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#o = this.#t.map((t) => String(t)).join("");
628
717
  }
629
- #d() {
718
+ #y() {
630
719
  if (this !== this.#s)
631
720
  throw new Error("should only call on root");
632
- if (this.#a)
721
+ if (this.#c)
633
722
  return this;
634
- this.toString(), this.#a = !0;
723
+ this.toString(), this.#c = !0;
635
724
  let t;
636
- for (; t = this.#c.pop(); ) {
725
+ for (; t = this.#l.pop(); ) {
637
726
  if (t.type !== "!")
638
727
  continue;
639
- let e = t, n = e.#e;
640
- for (; n; ) {
641
- for (let r = e.#o + 1; !n.type && r < n.#t.length; r++)
728
+ let e = t, r = e.#e;
729
+ for (; r; ) {
730
+ for (let n = e.#a + 1; !r.type && n < r.#t.length; n++)
642
731
  for (const i of t.#t) {
643
732
  if (typeof i == "string")
644
733
  throw new Error("string part in extglob AST??");
645
- i.copyIn(n.#t[r]);
734
+ i.copyIn(r.#t[n]);
646
735
  }
647
- e = n, n = e.#e;
736
+ e = r, r = e.#e;
648
737
  }
649
738
  }
650
739
  return this;
@@ -652,26 +741,26 @@ class E {
652
741
  push(...t) {
653
742
  for (const e of t)
654
743
  if (e !== "") {
655
- if (typeof e != "string" && !(e instanceof E && e.#e === this))
744
+ if (typeof e != "string" && !(e instanceof x && e.#e === this))
656
745
  throw new Error("invalid part: " + e);
657
746
  this.#t.push(e);
658
747
  }
659
748
  }
660
749
  toJSON() {
661
750
  const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
662
- return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
751
+ return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#c && this.#e?.type === "!") && t.push({}), t;
663
752
  }
664
753
  isStart() {
665
754
  if (this.#s === this)
666
755
  return !0;
667
756
  if (!this.#e?.isStart())
668
757
  return !1;
669
- if (this.#o === 0)
758
+ if (this.#a === 0)
670
759
  return !0;
671
760
  const t = this.#e;
672
- for (let e = 0; e < this.#o; e++) {
673
- const n = t.#t[e];
674
- if (!(n instanceof E && n.type === "!"))
761
+ for (let e = 0; e < this.#a; e++) {
762
+ const r = t.#t[e];
763
+ if (!(r instanceof x && r.type === "!"))
675
764
  return !1;
676
765
  }
677
766
  return !0;
@@ -684,96 +773,140 @@ class E {
684
773
  if (!this.type)
685
774
  return this.#e?.isEnd();
686
775
  const t = this.#e ? this.#e.#t.length : 0;
687
- return this.#o === t - 1;
776
+ return this.#a === t - 1;
688
777
  }
689
778
  copyIn(t) {
690
779
  typeof t == "string" ? this.push(t) : this.push(t.clone(this));
691
780
  }
692
781
  clone(t) {
693
- const e = new E(this.type, t);
694
- for (const n of this.#t)
695
- e.copyIn(n);
782
+ const e = new x(this.type, t);
783
+ for (const r of this.#t)
784
+ e.copyIn(r);
696
785
  return e;
697
786
  }
698
- static #h(t, e, n, r) {
699
- let i = !1, o = !1, c = -1, a = !1;
787
+ static #u(t, e, r, n, i) {
788
+ const o = n.maxExtglobRecursion ?? 2;
789
+ let a = !1, c = !1, l = -1, h = !1;
700
790
  if (e.type === null) {
701
- let d = n, g = "";
791
+ let d = r, E = "";
702
792
  for (; d < t.length; ) {
703
- const p = t.charAt(d++);
704
- if (i || p === "\\") {
705
- i = !i, g += p;
793
+ const y = t.charAt(d++);
794
+ if (a || y === "\\") {
795
+ a = !a, E += y;
706
796
  continue;
707
797
  }
708
- if (o) {
709
- d === c + 1 ? (p === "^" || p === "!") && (a = !0) : p === "]" && !(d === c + 2 && a) && (o = !1), g += p;
798
+ if (c) {
799
+ d === l + 1 ? (y === "^" || y === "!") && (h = !0) : y === "]" && !(d === l + 2 && h) && (c = !1), E += y;
710
800
  continue;
711
- } else if (p === "[") {
712
- o = !0, c = d, a = !1, g += p;
801
+ } else if (y === "[") {
802
+ c = !0, l = d, h = !1, E += y;
713
803
  continue;
714
804
  }
715
- if (!r.noext && pt(p) && t.charAt(d) === "(") {
716
- e.push(g), g = "";
717
- const S = new E(p, e);
718
- d = E.#h(t, S, d, r), e.push(S);
805
+ if (!n.noext && et(y) && t.charAt(d) === "(" && i <= o) {
806
+ e.push(E), E = "";
807
+ const D = new x(y, e);
808
+ d = x.#u(t, D, d, n, i + 1), e.push(D);
719
809
  continue;
720
810
  }
721
- g += p;
811
+ E += y;
722
812
  }
723
- return e.push(g), d;
813
+ return e.push(E), d;
724
814
  }
725
- let h = n + 1, l = new E(null, e);
726
- const f = [];
727
- let u = "";
728
- for (; h < t.length; ) {
729
- const d = t.charAt(h++);
730
- if (i || d === "\\") {
731
- i = !i, u += d;
815
+ let u = r + 1, f = new x(null, e);
816
+ const p = [];
817
+ let g = "";
818
+ for (; u < t.length; ) {
819
+ const d = t.charAt(u++);
820
+ if (a || d === "\\") {
821
+ a = !a, g += d;
732
822
  continue;
733
823
  }
734
- if (o) {
735
- h === c + 1 ? (d === "^" || d === "!") && (a = !0) : d === "]" && !(h === c + 2 && a) && (o = !1), u += d;
824
+ if (c) {
825
+ u === l + 1 ? (d === "^" || d === "!") && (h = !0) : d === "]" && !(u === l + 2 && h) && (c = !1), g += d;
736
826
  continue;
737
827
  } else if (d === "[") {
738
- o = !0, c = h, a = !1, u += d;
828
+ c = !0, l = u, h = !1, g += d;
739
829
  continue;
740
830
  }
741
- if (pt(d) && t.charAt(h) === "(") {
742
- l.push(u), u = "";
743
- const g = new E(d, l);
744
- l.push(g), h = E.#h(t, g, h, r);
831
+ if (!n.noext && et(d) && t.charAt(u) === "(" && /* c8 ignore start - the maxDepth is sufficient here */
832
+ (i <= o || e && e.#f(d))) {
833
+ const y = e && e.#f(d) ? 0 : 1;
834
+ f.push(g), g = "";
835
+ const m = new x(d, f);
836
+ f.push(m), u = x.#u(t, m, u, n, i + y);
745
837
  continue;
746
838
  }
747
839
  if (d === "|") {
748
- l.push(u), u = "", f.push(l), l = new E(null, e);
840
+ f.push(g), g = "", p.push(f), f = new x(null, e);
749
841
  continue;
750
842
  }
751
843
  if (d === ")")
752
- return u === "" && e.#t.length === 0 && (e.#u = !0), l.push(u), u = "", e.push(...f, l), h;
753
- u += d;
844
+ return g === "" && e.#t.length === 0 && (e.#h = !0), f.push(g), g = "", e.push(...p, f), u;
845
+ g += d;
754
846
  }
755
- return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
847
+ return e.type = null, e.#n = void 0, e.#t = [t.substring(r - 1)], u;
848
+ }
849
+ #m(t) {
850
+ return this.#d(t, ke);
851
+ }
852
+ #d(t, e = Ce) {
853
+ if (!t || typeof t != "object" || t.type !== null || t.#t.length !== 1 || this.type === null)
854
+ return !1;
855
+ const r = t.#t[0];
856
+ return !r || typeof r != "object" || r.type === null ? !1 : this.#f(r.type, e);
857
+ }
858
+ #f(t, e = Re) {
859
+ return !!e.get(this.type)?.includes(t);
860
+ }
861
+ #E(t, e) {
862
+ const r = t.#t[0], n = new x(null, r, this.options);
863
+ n.#t.push(""), r.push(n), this.#g(t, e);
864
+ }
865
+ #g(t, e) {
866
+ const r = t.#t[0];
867
+ this.#t.splice(e, 1, ...r.#t);
868
+ for (const n of r.#t)
869
+ typeof n == "object" && (n.#e = this);
870
+ this.#o = void 0;
871
+ }
872
+ #S(t) {
873
+ return !!gt.get(this.type)?.has(t);
874
+ }
875
+ #b(t) {
876
+ if (!t || typeof t != "object" || t.type !== null || t.#t.length !== 1 || this.type === null || this.#t.length !== 1)
877
+ return !1;
878
+ const e = t.#t[0];
879
+ return !e || typeof e != "object" || e.type === null ? !1 : this.#S(e.type);
880
+ }
881
+ #x(t) {
882
+ const e = gt.get(this.type), r = t.#t[0], n = e?.get(r.type);
883
+ if (!n)
884
+ return !1;
885
+ this.#t = r.#t;
886
+ for (const i of this.#t)
887
+ typeof i == "object" && (i.#e = this);
888
+ this.type = n, this.#o = void 0, this.#h = !1;
756
889
  }
757
890
  static fromGlob(t, e = {}) {
758
- const n = new E(null, void 0, e);
759
- return E.#h(t, n, 0, e), n;
891
+ const r = new x(null, void 0, e);
892
+ return x.#u(t, r, 0, e, 0), r;
760
893
  }
761
894
  // returns the regular expression if there's magic, or the unescaped
762
895
  // string if not.
763
896
  toMMPattern() {
764
897
  if (this !== this.#s)
765
898
  return this.#s.toMMPattern();
766
- const t = this.toString(), [e, n, r, i] = this.toRegExpSource();
767
- if (!(r || this.#n || this.#r.nocase && !this.#r.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
768
- return n;
769
- const c = (this.#r.nocase ? "i" : "") + (i ? "u" : "");
770
- return Object.assign(new RegExp(`^${e}$`, c), {
899
+ const t = this.toString(), [e, r, n, i] = this.toRegExpSource();
900
+ if (!(n || this.#n || this.#i.nocase && !this.#i.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
901
+ return r;
902
+ const a = (this.#i.nocase ? "i" : "") + (i ? "u" : "");
903
+ return Object.assign(new RegExp(`^${e}$`, a), {
771
904
  _src: e,
772
905
  _glob: t
773
906
  });
774
907
  }
775
908
  get options() {
776
- return this.#r;
909
+ return this.#i;
777
910
  }
778
911
  // returns the string match, the regexp source, whether there's magic
779
912
  // in the regexp (so a regular expression is required) and whether or
@@ -845,168 +978,187 @@ class E {
845
978
  // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
846
979
  // or start or whatever) and prepend ^ or / at the Regexp construction.
847
980
  toRegExpSource(t) {
848
- const e = t ?? !!this.#r.dot;
849
- if (this.#s === this && this.#d(), !this.type) {
850
- const a = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
851
- const [g, p, S, N] = typeof d == "string" ? E.#p(d, this.#n, a) : d.toRegExpSource(t);
852
- return this.#n = this.#n || S, this.#i = this.#i || N, g;
981
+ const e = t ?? !!this.#i.dot;
982
+ if (this.#s === this && (this.#p(), this.#y()), !dt(this)) {
983
+ const c = this.isStart() && this.isEnd() && !this.#t.some((p) => typeof p != "string"), l = this.#t.map((p) => {
984
+ const [g, d, E, y] = typeof p == "string" ? x.#A(p, this.#n, c) : p.toRegExpSource(t);
985
+ return this.#n = this.#n || E, this.#r = this.#r || y, g;
853
986
  }).join("");
854
- let l = "";
855
- if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Te.has(this.#t[0]))) {
856
- const g = Ne, p = (
987
+ let h = "";
988
+ if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && ze.has(this.#t[0]))) {
989
+ const g = _e, d = (
857
990
  // dots are allowed, and the pattern starts with [ or .
858
- e && g.has(h.charAt(0)) || // the pattern starts with \., and then [ or .
859
- h.startsWith("\\.") && g.has(h.charAt(2)) || // the pattern starts with \.\., and then [ or .
860
- h.startsWith("\\.\\.") && g.has(h.charAt(4))
861
- ), S = !e && !t && g.has(h.charAt(0));
862
- l = p ? ve : S ? W : "";
991
+ e && g.has(l.charAt(0)) || // the pattern starts with \., and then [ or .
992
+ l.startsWith("\\.") && g.has(l.charAt(2)) || // the pattern starts with \.\., and then [ or .
993
+ l.startsWith("\\.\\.") && g.has(l.charAt(4))
994
+ ), E = !e && !t && g.has(l.charAt(0));
995
+ h = d ? Fe : E ? z : "";
863
996
  }
864
- let f = "";
865
- return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\/)"), [
866
- l + h + f,
867
- I(h),
997
+ let u = "";
998
+ return this.isEnd() && this.#s.#c && this.#e?.type === "!" && (u = "(?:$|\\/)"), [
999
+ h + l + u,
1000
+ R(l),
868
1001
  this.#n = !!this.#n,
869
- this.#i
1002
+ this.#r
870
1003
  ];
871
1004
  }
872
- const n = this.type === "*" || this.type === "+", r = this.type === "!" ? "(?:(?!(?:" : "(?:";
873
- let i = this.#f(e);
1005
+ const r = this.type === "*" || this.type === "+", n = this.type === "!" ? "(?:(?!(?:" : "(?:";
1006
+ let i = this.#w(e);
874
1007
  if (this.isStart() && this.isEnd() && !i && this.type !== "!") {
875
- const a = this.toString();
876
- return this.#t = [a], this.type = null, this.#n = void 0, [a, I(this.toString()), !1, !1];
1008
+ const c = this.toString(), l = this;
1009
+ return l.#t = [c], l.type = null, l.#n = void 0, [c, R(this.toString()), !1, !1];
877
1010
  }
878
- let o = !n || t || e || !W ? "" : this.#f(!0);
1011
+ let o = !r || t || e || !z ? "" : this.#w(!0);
879
1012
  o === i && (o = ""), o && (i = `(?:${i})(?:${o})*?`);
880
- let c = "";
881
- if (this.type === "!" && this.#u)
882
- c = (this.isStart() && !e ? W : "") + wt;
1013
+ let a = "";
1014
+ if (this.type === "!" && this.#h)
1015
+ a = (this.isStart() && !e ? z : "") + yt;
883
1016
  else {
884
- const a = this.type === "!" ? (
1017
+ const c = this.type === "!" ? (
885
1018
  // !() must match something,but !(x) can match ''
886
- "))" + (this.isStart() && !e && !t ? W : "") + gt + ")"
1019
+ "))" + (this.isStart() && !e && !t ? z : "") + wt + ")"
887
1020
  ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : `)${this.type}`;
888
- c = r + i + a;
1021
+ a = n + i + c;
889
1022
  }
890
1023
  return [
891
- c,
892
- I(i),
1024
+ a,
1025
+ R(i),
893
1026
  this.#n = !!this.#n,
894
- this.#i
1027
+ this.#r
895
1028
  ];
896
1029
  }
897
- #f(t) {
1030
+ #p() {
1031
+ if (dt(this)) {
1032
+ let t = 0, e = !1;
1033
+ do {
1034
+ e = !0;
1035
+ for (let r = 0; r < this.#t.length; r++) {
1036
+ const n = this.#t[r];
1037
+ typeof n == "object" && (n.#p(), this.#d(n) ? (e = !1, this.#g(n, r)) : this.#m(n) ? (e = !1, this.#E(n, r)) : this.#b(n) && (e = !1, this.#x(n)));
1038
+ }
1039
+ } while (!e && ++t < 10);
1040
+ } else
1041
+ for (const t of this.#t)
1042
+ typeof t == "object" && t.#p();
1043
+ this.#o = void 0;
1044
+ }
1045
+ #w(t) {
898
1046
  return this.#t.map((e) => {
899
1047
  if (typeof e == "string")
900
1048
  throw new Error("string type in extglob ast??");
901
- const [n, r, i, o] = e.toRegExpSource(t);
902
- return this.#i = this.#i || o, n;
1049
+ const [r, n, i, o] = e.toRegExpSource(t);
1050
+ return this.#r = this.#r || o, r;
903
1051
  }).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
904
1052
  }
905
- static #p(t, e, n = !1) {
906
- let r = !1, i = "", o = !1;
1053
+ static #A(t, e, r = !1) {
1054
+ let n = !1, i = "", o = !1, a = !1;
907
1055
  for (let c = 0; c < t.length; c++) {
908
- const a = t.charAt(c);
909
- if (r) {
910
- r = !1, i += (Me.has(a) ? "\\" : "") + a;
1056
+ const l = t.charAt(c);
1057
+ if (n) {
1058
+ n = !1, i += (Ie.has(l) ? "\\" : "") + l;
911
1059
  continue;
912
1060
  }
913
- if (a === "\\") {
914
- c === t.length - 1 ? i += "\\\\" : r = !0;
1061
+ if (l === "*") {
1062
+ if (a)
1063
+ continue;
1064
+ a = !0, i += r && /^[*]+$/.test(t) ? yt : wt, e = !0;
1065
+ continue;
1066
+ } else
1067
+ a = !1;
1068
+ if (l === "\\") {
1069
+ c === t.length - 1 ? i += "\\\\" : n = !0;
915
1070
  continue;
916
1071
  }
917
- if (a === "[") {
918
- const [h, l, f, u] = De(t, c);
1072
+ if (l === "[") {
1073
+ const [h, u, f, p] = ve(t, c);
919
1074
  if (f) {
920
- i += h, o = o || l, c += f - 1, e = e || u;
1075
+ i += h, o = o || u, c += f - 1, e = e || p;
921
1076
  continue;
922
1077
  }
923
1078
  }
924
- if (a === "*") {
925
- n && t === "*" ? i += wt : i += gt, e = !0;
1079
+ if (l === "?") {
1080
+ i += it, e = !0;
926
1081
  continue;
927
1082
  }
928
- if (a === "?") {
929
- i += ot, e = !0;
930
- continue;
931
- }
932
- i += Ce(a);
1083
+ i += Le(l);
933
1084
  }
934
- return [i, I(t), !!e, o];
1085
+ return [i, R(t), !!e, o];
935
1086
  }
936
1087
  }
937
- const $e = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&"), y = (s, t, e = {}) => (q(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new V(t, e).match(s)), Pe = /^\*+([^+@!?\*\[\(]*)$/, ke = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Re = (s) => (t) => t.endsWith(s), Fe = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), Ie = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), ze = /^\*+\.\*+$/, Le = (s) => !s.startsWith(".") && s.includes("."), _e = (s) => s !== "." && s !== ".." && s.includes("."), We = /^\.\*+$/, He = (s) => s !== "." && s !== ".." && s.startsWith("."), je = /^\*+$/, Be = (s) => s.length !== 0 && !s.startsWith("."), Ue = (s) => s.length !== 0 && s !== "." && s !== "..", Ge = /^\?+([^+@!?\*\[\(]*)?$/, qe = ([s, t = ""]) => {
938
- const e = kt([s]);
939
- return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
940
- }, Ve = ([s, t = ""]) => {
1088
+ x = ot;
1089
+ const je = (s, { windowsPathsNoEscape: t = !1, magicalBraces: e = !1 } = {}) => e ? t ? s.replace(/[?*()[\]{}]/g, "[$&]") : s.replace(/[?*()[\]\\{}]/g, "\\$&") : t ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&"), b = (s, t, e = {}) => (B(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new U(t, e).match(s)), He = /^\*+([^+@!?*[(]*)$/, Be = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ue = (s) => (t) => t.endsWith(s), Ge = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), qe = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Ve = /^\*+\.\*+$/, Xe = (s) => !s.startsWith(".") && s.includes("."), Ye = (s) => s !== "." && s !== ".." && s.includes("."), Ze = /^\.\*+$/, Je = (s) => s !== "." && s !== ".." && s.startsWith("."), Qe = /^\*+$/, Ke = (s) => s.length !== 0 && !s.startsWith("."), ts = (s) => s.length !== 0 && s !== "." && s !== "..", es = /^\?+([^+@!?*[(]*)?$/, ss = ([s, t = ""]) => {
941
1090
  const e = Rt([s]);
942
- return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
943
- }, Ye = ([s, t = ""]) => {
1091
+ return t ? (t = t.toLowerCase(), (r) => e(r) && r.toLowerCase().endsWith(t)) : e;
1092
+ }, ns = ([s, t = ""]) => {
1093
+ const e = Ft([s]);
1094
+ return t ? (t = t.toLowerCase(), (r) => e(r) && r.toLowerCase().endsWith(t)) : e;
1095
+ }, rs = ([s, t = ""]) => {
1096
+ const e = Ft([s]);
1097
+ return t ? (r) => e(r) && r.endsWith(t) : e;
1098
+ }, is = ([s, t = ""]) => {
944
1099
  const e = Rt([s]);
945
- return t ? (n) => e(n) && n.endsWith(t) : e;
946
- }, Ze = ([s, t = ""]) => {
947
- const e = kt([s]);
948
- return t ? (n) => e(n) && n.endsWith(t) : e;
949
- }, kt = ([s]) => {
1100
+ return t ? (r) => e(r) && r.endsWith(t) : e;
1101
+ }, Rt = ([s]) => {
950
1102
  const t = s.length;
951
1103
  return (e) => e.length === t && !e.startsWith(".");
952
- }, Rt = ([s]) => {
1104
+ }, Ft = ([s]) => {
953
1105
  const t = s.length;
954
1106
  return (e) => e.length === t && e !== "." && e !== "..";
955
- }, Ft = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", mt = {
1107
+ }, _t = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", mt = {
956
1108
  win32: { sep: "\\" },
957
1109
  posix: { sep: "/" }
958
- }, Xe = Ft === "win32" ? mt.win32.sep : mt.posix.sep;
959
- y.sep = Xe;
960
- const D = Symbol("globstar **");
961
- y.GLOBSTAR = D;
962
- const Je = "[^/]", Qe = Je + "*?", Ke = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?", ts = "(?:(?!(?:\\/|^)\\.).)*?", es = (s, t = {}) => (e) => y(e, s, t);
963
- y.filter = es;
964
- const O = (s, t = {}) => Object.assign({}, s, t), ss = (s) => {
1110
+ }, os = _t === "win32" ? mt.win32.sep : mt.posix.sep;
1111
+ b.sep = os;
1112
+ const S = /* @__PURE__ */ Symbol("globstar **");
1113
+ b.GLOBSTAR = S;
1114
+ const as = "[^/]", cs = as + "*?", ls = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?", hs = "(?:(?!(?:\\/|^)\\.).)*?", us = (s, t = {}) => (e) => b(e, s, t);
1115
+ b.filter = us;
1116
+ const O = (s, t = {}) => Object.assign({}, s, t), fs = (s) => {
965
1117
  if (!s || typeof s != "object" || !Object.keys(s).length)
966
- return y;
967
- const t = y;
968
- return Object.assign((n, r, i = {}) => t(n, r, O(s, i)), {
1118
+ return b;
1119
+ const t = b;
1120
+ return Object.assign((r, n, i = {}) => t(r, n, O(s, i)), {
969
1121
  Minimatch: class extends t.Minimatch {
970
- constructor(r, i = {}) {
971
- super(r, O(s, i));
1122
+ constructor(n, i = {}) {
1123
+ super(n, O(s, i));
972
1124
  }
973
- static defaults(r) {
974
- return t.defaults(O(s, r)).Minimatch;
1125
+ static defaults(n) {
1126
+ return t.defaults(O(s, n)).Minimatch;
975
1127
  }
976
1128
  },
977
1129
  AST: class extends t.AST {
978
1130
  /* c8 ignore start */
979
- constructor(r, i, o = {}) {
980
- super(r, i, O(s, o));
1131
+ constructor(n, i, o = {}) {
1132
+ super(n, i, O(s, o));
981
1133
  }
982
1134
  /* c8 ignore stop */
983
- static fromGlob(r, i = {}) {
984
- return t.AST.fromGlob(r, O(s, i));
1135
+ static fromGlob(n, i = {}) {
1136
+ return t.AST.fromGlob(n, O(s, i));
985
1137
  }
986
1138
  },
987
- unescape: (n, r = {}) => t.unescape(n, O(s, r)),
988
- escape: (n, r = {}) => t.escape(n, O(s, r)),
989
- filter: (n, r = {}) => t.filter(n, O(s, r)),
990
- defaults: (n) => t.defaults(O(s, n)),
991
- makeRe: (n, r = {}) => t.makeRe(n, O(s, r)),
992
- braceExpand: (n, r = {}) => t.braceExpand(n, O(s, r)),
993
- match: (n, r, i = {}) => t.match(n, r, O(s, i)),
1139
+ unescape: (r, n = {}) => t.unescape(r, O(s, n)),
1140
+ escape: (r, n = {}) => t.escape(r, O(s, n)),
1141
+ filter: (r, n = {}) => t.filter(r, O(s, n)),
1142
+ defaults: (r) => t.defaults(O(s, r)),
1143
+ makeRe: (r, n = {}) => t.makeRe(r, O(s, n)),
1144
+ braceExpand: (r, n = {}) => t.braceExpand(r, O(s, n)),
1145
+ match: (r, n, i = {}) => t.match(r, n, O(s, i)),
994
1146
  sep: t.sep,
995
- GLOBSTAR: D
1147
+ GLOBSTAR: S
996
1148
  });
997
1149
  };
998
- y.defaults = ss;
999
- const It = (s, t = {}) => (q(s), t.nobrace || !/\{(?:(?!\{).)*\}/.test(s) ? [s] : we(s));
1000
- y.braceExpand = It;
1001
- const ns = (s, t = {}) => new V(s, t).makeRe();
1002
- y.makeRe = ns;
1003
- const rs = (s, t, e = {}) => {
1004
- const n = new V(t, e);
1005
- return s = s.filter((r) => n.match(r)), n.options.nonull && !s.length && s.push(t), s;
1150
+ b.defaults = fs;
1151
+ const zt = (s, t = {}) => (B(s), t.nobrace || !/\{(?:(?!\{).)*\}/.test(s) ? [s] : be(s, { max: t.braceExpandMax }));
1152
+ b.braceExpand = zt;
1153
+ const ps = (s, t = {}) => new U(s, t).makeRe();
1154
+ b.makeRe = ps;
1155
+ const ds = (s, t, e = {}) => {
1156
+ const r = new U(t, e);
1157
+ return s = s.filter((n) => r.match(n)), r.options.nonull && !s.length && s.push(t), s;
1006
1158
  };
1007
- y.match = rs;
1008
- const yt = /[?*]|[+@!]\(.*?\)|\[|\]/, is = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
1009
- class V {
1159
+ b.match = ds;
1160
+ const Et = /[?*]|[+@!]\(.*?\)|\[|\]/, gs = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
1161
+ class U {
1010
1162
  options;
1011
1163
  set;
1012
1164
  pattern;
@@ -1023,9 +1175,12 @@ class V {
1023
1175
  isWindows;
1024
1176
  platform;
1025
1177
  windowsNoMagicRoot;
1178
+ maxGlobstarRecursion;
1026
1179
  regexp;
1027
1180
  constructor(t, e = {}) {
1028
- q(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ft, 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();
1181
+ B(t), e = e || {}, this.options = e, this.maxGlobstarRecursion = e.maxGlobstarRecursion ?? 200, this.pattern = t, this.platform = e.platform || _t, this.isWindows = this.platform === "win32";
1182
+ const r = "allowWindowsEscape";
1183
+ this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e[r] === !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();
1029
1184
  }
1030
1185
  hasMagic() {
1031
1186
  if (this.options.magicalBraces && this.set.length > 1)
@@ -1049,19 +1204,22 @@ class V {
1049
1204
  return;
1050
1205
  }
1051
1206
  this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...i) => console.error(...i)), this.debug(this.pattern, this.globSet);
1052
- const n = this.globSet.map((i) => this.slashSplit(i));
1053
- this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
1054
- let r = this.globParts.map((i, o, c) => {
1207
+ const r = this.globSet.map((i) => this.slashSplit(i));
1208
+ this.globParts = this.preprocess(r), this.debug(this.pattern, this.globParts);
1209
+ let n = this.globParts.map((i, o, a) => {
1055
1210
  if (this.isWindows && this.windowsNoMagicRoot) {
1056
- const a = i[0] === "" && i[1] === "" && (i[2] === "?" || !yt.test(i[2])) && !yt.test(i[3]), h = /^[a-z]:/i.test(i[0]);
1057
- if (a)
1058
- return [...i.slice(0, 4), ...i.slice(4).map((l) => this.parse(l))];
1059
- if (h)
1060
- return [i[0], ...i.slice(1).map((l) => this.parse(l))];
1211
+ const c = i[0] === "" && i[1] === "" && (i[2] === "?" || !Et.test(i[2])) && !Et.test(i[3]), l = /^[a-z]:/i.test(i[0]);
1212
+ if (c)
1213
+ return [
1214
+ ...i.slice(0, 4),
1215
+ ...i.slice(4).map((h) => this.parse(h))
1216
+ ];
1217
+ if (l)
1218
+ return [i[0], ...i.slice(1).map((h) => this.parse(h))];
1061
1219
  }
1062
- return i.map((a) => this.parse(a));
1220
+ return i.map((c) => this.parse(c));
1063
1221
  });
1064
- if (this.debug(this.pattern, r), this.set = r.filter((i) => i.indexOf(!1) === -1), this.isWindows)
1222
+ if (this.debug(this.pattern, n), this.set = n.filter((i) => i.indexOf(!1) === -1), this.isWindows)
1065
1223
  for (let i = 0; i < this.set.length; i++) {
1066
1224
  const o = this.set[i];
1067
1225
  o[0] === "" && o[1] === "" && this.globParts[i][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
@@ -1075,30 +1233,30 @@ class V {
1075
1233
  // of patterns that we have to process.
1076
1234
  preprocess(t) {
1077
1235
  if (this.options.noglobstar)
1078
- for (let n = 0; n < t.length; n++)
1079
- for (let r = 0; r < t[n].length; r++)
1080
- t[n][r] === "**" && (t[n][r] = "*");
1236
+ for (const r of t)
1237
+ for (let n = 0; n < r.length; n++)
1238
+ r[n] === "**" && (r[n] = "*");
1081
1239
  const { optimizationLevel: e = 1 } = this.options;
1082
1240
  return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
1083
1241
  }
1084
1242
  // just get rid of adjascent ** portions
1085
1243
  adjascentGlobstarOptimize(t) {
1086
1244
  return t.map((e) => {
1087
- let n = -1;
1088
- for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
1089
- let r = n;
1090
- for (; e[r + 1] === "**"; )
1091
- r++;
1092
- r !== n && e.splice(n, r - n);
1245
+ let r = -1;
1246
+ for (; (r = e.indexOf("**", r + 1)) !== -1; ) {
1247
+ let n = r;
1248
+ for (; e[n + 1] === "**"; )
1249
+ n++;
1250
+ n !== r && e.splice(r, n - r);
1093
1251
  }
1094
1252
  return e;
1095
1253
  });
1096
1254
  }
1097
1255
  // get rid of adjascent ** and resolve .. portions
1098
1256
  levelOneOptimize(t) {
1099
- return t.map((e) => (e = e.reduce((n, r) => {
1100
- const i = n[n.length - 1];
1101
- return r === "**" && i === "**" ? n : r === ".." && i && i !== ".." && i !== "." && i !== "**" ? (n.pop(), n) : (n.push(r), n);
1257
+ return t.map((e) => (e = e.reduce((r, n) => {
1258
+ const i = r[r.length - 1];
1259
+ return n === "**" && i === "**" ? r : n === ".." && i && i !== ".." && i !== "." && i !== "**" ? (r.pop(), r) : (r.push(n), r);
1102
1260
  }, []), e.length === 0 ? [""] : e));
1103
1261
  }
1104
1262
  levelTwoFileOptimize(t) {
@@ -1106,16 +1264,16 @@ class V {
1106
1264
  let e = !1;
1107
1265
  do {
1108
1266
  if (e = !1, !this.preserveMultipleSlashes) {
1109
- for (let r = 1; r < t.length - 1; r++) {
1110
- const i = t[r];
1111
- r === 1 && i === "" && t[0] === "" || (i === "." || i === "") && (e = !0, t.splice(r, 1), r--);
1267
+ for (let n = 1; n < t.length - 1; n++) {
1268
+ const i = t[n];
1269
+ n === 1 && i === "" && t[0] === "" || (i === "." || i === "") && (e = !0, t.splice(n, 1), n--);
1112
1270
  }
1113
1271
  t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
1114
1272
  }
1115
- let n = 0;
1116
- for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
1117
- const r = t[n - 1];
1118
- r && r !== "." && r !== ".." && r !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
1273
+ let r = 0;
1274
+ for (; (r = t.indexOf("..", r + 1)) !== -1; ) {
1275
+ const n = t[r - 1];
1276
+ n && n !== "." && n !== ".." && n !== "**" && !(this.isWindows && /^[a-z]:$/i.test(n)) && (e = !0, t.splice(r - 1, 2), r -= 2);
1119
1277
  }
1120
1278
  } while (e);
1121
1279
  return t.length === 0 ? [""] : t;
@@ -1142,35 +1300,35 @@ class V {
1142
1300
  let e = !1;
1143
1301
  do {
1144
1302
  e = !1;
1145
- for (let n of t) {
1146
- let r = -1;
1147
- for (; (r = n.indexOf("**", r + 1)) !== -1; ) {
1148
- let o = r;
1149
- for (; n[o + 1] === "**"; )
1303
+ for (let r of t) {
1304
+ let n = -1;
1305
+ for (; (n = r.indexOf("**", n + 1)) !== -1; ) {
1306
+ let o = n;
1307
+ for (; r[o + 1] === "**"; )
1150
1308
  o++;
1151
- o > r && n.splice(r + 1, o - r);
1152
- let c = n[r + 1];
1153
- const a = n[r + 2], h = n[r + 3];
1154
- if (c !== ".." || !a || a === "." || a === ".." || !h || h === "." || h === "..")
1309
+ o > n && r.splice(n + 1, o - n);
1310
+ let a = r[n + 1];
1311
+ const c = r[n + 2], l = r[n + 3];
1312
+ if (a !== ".." || !c || c === "." || c === ".." || !l || l === "." || l === "..")
1155
1313
  continue;
1156
- e = !0, n.splice(r, 1);
1157
- const l = n.slice(0);
1158
- l[r] = "**", t.push(l), r--;
1314
+ e = !0, r.splice(n, 1);
1315
+ const h = r.slice(0);
1316
+ h[n] = "**", t.push(h), n--;
1159
1317
  }
1160
1318
  if (!this.preserveMultipleSlashes) {
1161
- for (let o = 1; o < n.length - 1; o++) {
1162
- const c = n[o];
1163
- o === 1 && c === "" && n[0] === "" || (c === "." || c === "") && (e = !0, n.splice(o, 1), o--);
1319
+ for (let o = 1; o < r.length - 1; o++) {
1320
+ const a = r[o];
1321
+ o === 1 && a === "" && r[0] === "" || (a === "." || a === "") && (e = !0, r.splice(o, 1), o--);
1164
1322
  }
1165
- n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
1323
+ r[0] === "." && r.length === 2 && (r[1] === "." || r[1] === "") && (e = !0, r.pop());
1166
1324
  }
1167
1325
  let i = 0;
1168
- for (; (i = n.indexOf("..", i + 1)) !== -1; ) {
1169
- const o = n[i - 1];
1326
+ for (; (i = r.indexOf("..", i + 1)) !== -1; ) {
1327
+ const o = r[i - 1];
1170
1328
  if (o && o !== "." && o !== ".." && o !== "**") {
1171
1329
  e = !0;
1172
- const a = i === 1 && n[i + 1] === "**" ? ["."] : [];
1173
- n.splice(i - 1, 2, ...a), n.length === 0 && n.push(""), i -= 2;
1330
+ const c = i === 1 && r[i + 1] === "**" ? ["."] : [];
1331
+ r.splice(i - 1, 2, ...c), r.length === 0 && r.push(""), i -= 2;
1174
1332
  }
1175
1333
  }
1176
1334
  }
@@ -1186,32 +1344,32 @@ class V {
1186
1344
  // ^-- not valid because ** doens't follow symlinks
1187
1345
  secondPhasePreProcess(t) {
1188
1346
  for (let e = 0; e < t.length - 1; e++)
1189
- for (let n = e + 1; n < t.length; n++) {
1190
- const r = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
1191
- if (r) {
1192
- t[e] = [], t[n] = r;
1347
+ for (let r = e + 1; r < t.length; r++) {
1348
+ const n = this.partsMatch(t[e], t[r], !this.preserveMultipleSlashes);
1349
+ if (n) {
1350
+ t[e] = [], t[r] = n;
1193
1351
  break;
1194
1352
  }
1195
1353
  }
1196
1354
  return t.filter((e) => e.length);
1197
1355
  }
1198
- partsMatch(t, e, n = !1) {
1199
- let r = 0, i = 0, o = [], c = "";
1200
- for (; r < t.length && i < e.length; )
1201
- if (t[r] === e[i])
1202
- o.push(c === "b" ? e[i] : t[r]), r++, i++;
1203
- else if (n && t[r] === "**" && e[i] === t[r + 1])
1204
- o.push(t[r]), r++;
1205
- else if (n && e[i] === "**" && t[r] === e[i + 1])
1356
+ partsMatch(t, e, r = !1) {
1357
+ let n = 0, i = 0, o = [], a = "";
1358
+ for (; n < t.length && i < e.length; )
1359
+ if (t[n] === e[i])
1360
+ o.push(a === "b" ? e[i] : t[n]), n++, i++;
1361
+ else if (r && t[n] === "**" && e[i] === t[n + 1])
1362
+ o.push(t[n]), n++;
1363
+ else if (r && e[i] === "**" && t[n] === e[i + 1])
1206
1364
  o.push(e[i]), i++;
1207
- else if (t[r] === "*" && e[i] && (this.options.dot || !e[i].startsWith(".")) && e[i] !== "**") {
1208
- if (c === "b")
1365
+ else if (t[n] === "*" && e[i] && (this.options.dot || !e[i].startsWith(".")) && e[i] !== "**") {
1366
+ if (a === "b")
1209
1367
  return !1;
1210
- c = "a", o.push(t[r]), r++, i++;
1211
- } else if (e[i] === "*" && t[r] && (this.options.dot || !t[r].startsWith(".")) && t[r] !== "**") {
1212
- if (c === "a")
1368
+ a = "a", o.push(t[n]), n++, i++;
1369
+ } else if (e[i] === "*" && t[n] && (this.options.dot || !t[n].startsWith(".")) && t[n] !== "**") {
1370
+ if (a === "a")
1213
1371
  return !1;
1214
- c = "b", o.push(e[i]), r++, i++;
1372
+ a = "b", o.push(e[i]), n++, i++;
1215
1373
  } else
1216
1374
  return !1;
1217
1375
  return t.length === e.length && o;
@@ -1220,81 +1378,140 @@ class V {
1220
1378
  if (this.nonegate)
1221
1379
  return;
1222
1380
  const t = this.pattern;
1223
- let e = !1, n = 0;
1224
- for (let r = 0; r < t.length && t.charAt(r) === "!"; r++)
1225
- e = !e, n++;
1226
- n && (this.pattern = t.slice(n)), this.negate = e;
1381
+ let e = !1, r = 0;
1382
+ for (let n = 0; n < t.length && t.charAt(n) === "!"; n++)
1383
+ e = !e, r++;
1384
+ r && (this.pattern = t.slice(r)), this.negate = e;
1227
1385
  }
1228
1386
  // set partial to true to test if, for example,
1229
1387
  // "/a/b" matches the start of "/*/b/*/d"
1230
1388
  // Partial means, if you run out of file before you run
1231
1389
  // out of pattern, then that's fine, as long as all
1232
1390
  // the parts match.
1233
- matchOne(t, e, n = !1) {
1234
- const r = this.options;
1391
+ matchOne(t, e, r = !1) {
1392
+ let n = 0, i = 0;
1235
1393
  if (this.isWindows) {
1236
- 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]), N = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), P = !N && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), b = S ? 3 : p ? 0 : void 0, m = P ? 3 : N ? 0 : void 0;
1237
- if (typeof b == "number" && typeof m == "number") {
1238
- const [k, L] = [t[b], e[m]];
1239
- k.toLowerCase() === L.toLowerCase() && (e[m] = k, m > b ? e = e.slice(m) : b > m && (t = t.slice(b)));
1394
+ const a = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), c = !a && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), l = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), h = !l && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), u = c ? 3 : a ? 0 : void 0, f = h ? 3 : l ? 0 : void 0;
1395
+ if (typeof u == "number" && typeof f == "number") {
1396
+ const [p, g] = [
1397
+ t[u],
1398
+ e[f]
1399
+ ];
1400
+ p.toLowerCase() === g.toLowerCase() && (e[f] = p, i = f, n = u);
1240
1401
  }
1241
1402
  }
1242
- const { optimizationLevel: i = 1 } = this.options;
1243
- i >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
1244
- for (var o = 0, c = 0, a = t.length, h = e.length; o < a && c < h; o++, c++) {
1245
- this.debug("matchOne loop");
1246
- var l = e[c], f = t[o];
1247
- if (this.debug(e, l, f), l === !1)
1403
+ const { optimizationLevel: o = 1 } = this.options;
1404
+ return o >= 2 && (t = this.levelTwoFileOptimize(t)), e.includes(S) ? this.#s(t, e, r, n, i) : this.#r(t, e, r, n, i);
1405
+ }
1406
+ #s(t, e, r, n, i) {
1407
+ const o = e.indexOf(S, i), a = e.lastIndexOf(S), [c, l, h] = r ? [
1408
+ e.slice(i, o),
1409
+ e.slice(o + 1),
1410
+ []
1411
+ ] : [
1412
+ e.slice(i, o),
1413
+ e.slice(o + 1, a),
1414
+ e.slice(a + 1)
1415
+ ];
1416
+ if (c.length) {
1417
+ const m = t.slice(n, n + c.length);
1418
+ if (!this.#r(m, c, r, 0, 0))
1248
1419
  return !1;
1249
- if (l === D) {
1250
- this.debug("GLOBSTAR", [e, l, f]);
1251
- var u = o, d = c + 1;
1252
- if (d === h) {
1253
- for (this.debug("** at the end"); o < a; o++)
1254
- if (t[o] === "." || t[o] === ".." || !r.dot && t[o].charAt(0) === ".")
1255
- return !1;
1256
- return !0;
1257
- }
1258
- for (; u < a; ) {
1259
- var g = t[u];
1260
- if (this.debug(`
1261
- globstar while`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
1262
- return this.debug("globstar found match!", u, a, g), !0;
1263
- if (g === "." || g === ".." || !r.dot && g.charAt(0) === ".") {
1264
- this.debug("dot detected!", t, u, e, d);
1265
- break;
1266
- }
1267
- this.debug("globstar swallow a segment, and continue"), u++;
1268
- }
1269
- return !!(n && (this.debug(`
1270
- >>> no match, partial?`, t, u, e, d), u === a));
1420
+ n += c.length, i += c.length;
1421
+ }
1422
+ let u = 0;
1423
+ if (h.length) {
1424
+ if (h.length + n > t.length)
1425
+ return !1;
1426
+ let m = t.length - h.length;
1427
+ if (this.#r(t, h, r, m, 0))
1428
+ u = h.length;
1429
+ else {
1430
+ if (t[t.length - 1] !== "" || n + h.length === t.length || (m--, !this.#r(t, h, r, m, 0)))
1431
+ return !1;
1432
+ u = h.length + 1;
1433
+ }
1434
+ }
1435
+ if (!l.length) {
1436
+ let m = !!u;
1437
+ for (let D = n; D < t.length - u; D++) {
1438
+ const G = String(t[D]);
1439
+ if (m = !0, G === "." || G === ".." || !this.options.dot && G.startsWith("."))
1440
+ return !1;
1441
+ }
1442
+ return r || m;
1443
+ }
1444
+ const f = [[[], 0]];
1445
+ let p = f[0], g = 0;
1446
+ const d = [0];
1447
+ for (const m of l)
1448
+ m === S ? (d.push(g), p = [[], 0], f.push(p)) : (p[0].push(m), g++);
1449
+ let E = f.length - 1;
1450
+ const y = t.length - u;
1451
+ for (const m of f)
1452
+ m[1] = y - (d[E--] + m[0].length);
1453
+ return !!this.#n(t, f, n, 0, r, 0, !!u);
1454
+ }
1455
+ // return false for "nope, not matching"
1456
+ // return null for "not matching, cannot keep trying"
1457
+ #n(t, e, r, n, i, o, a) {
1458
+ const c = e[n];
1459
+ if (!c) {
1460
+ for (let u = r; u < t.length; u++) {
1461
+ a = !0;
1462
+ const f = t[u];
1463
+ if (f === "." || f === ".." || !this.options.dot && f.startsWith("."))
1464
+ return !1;
1465
+ }
1466
+ return a;
1467
+ }
1468
+ const [l, h] = c;
1469
+ for (; r <= h; ) {
1470
+ if (this.#r(t.slice(0, r + l.length), l, i, r, 0) && o < this.maxGlobstarRecursion) {
1471
+ const p = this.#n(t, e, r + l.length, n + 1, i, o + 1, a);
1472
+ if (p !== !1)
1473
+ return p;
1271
1474
  }
1272
- let p;
1273
- if (typeof l == "string" ? (p = f === l, this.debug("string match", l, f, p)) : (p = l.test(f), this.debug("pattern match", l, f, p)), !p)
1475
+ const f = t[r];
1476
+ if (f === "." || f === ".." || !this.options.dot && f.startsWith("."))
1274
1477
  return !1;
1478
+ r++;
1275
1479
  }
1276
- if (o === a && c === h)
1480
+ return i || null;
1481
+ }
1482
+ #r(t, e, r, n, i) {
1483
+ let o, a, c, l;
1484
+ for (o = n, a = i, l = t.length, c = e.length; o < l && a < c; o++, a++) {
1485
+ this.debug("matchOne loop");
1486
+ let h = e[a], u = t[o];
1487
+ if (this.debug(e, h, u), h === !1 || h === S)
1488
+ return !1;
1489
+ let f;
1490
+ if (typeof h == "string" ? (f = u === h, this.debug("string match", h, u, f)) : (f = h.test(u), this.debug("pattern match", h, u, f)), !f)
1491
+ return !1;
1492
+ }
1493
+ if (o === l && a === c)
1277
1494
  return !0;
1278
- if (o === a)
1279
- return n;
1280
- if (c === h)
1281
- return o === a - 1 && t[o] === "";
1495
+ if (o === l)
1496
+ return r;
1497
+ if (a === c)
1498
+ return o === l - 1 && t[o] === "";
1282
1499
  throw new Error("wtf?");
1283
1500
  }
1284
1501
  braceExpand() {
1285
- return It(this.pattern, this.options);
1502
+ return zt(this.pattern, this.options);
1286
1503
  }
1287
1504
  parse(t) {
1288
- q(t);
1505
+ B(t);
1289
1506
  const e = this.options;
1290
1507
  if (t === "**")
1291
- return D;
1508
+ return S;
1292
1509
  if (t === "")
1293
1510
  return "";
1294
- let n, r = null;
1295
- (n = t.match(je)) ? r = e.dot ? Ue : Be : (n = t.match(Pe)) ? r = (e.nocase ? e.dot ? Ie : Fe : e.dot ? Re : ke)(n[1]) : (n = t.match(Ge)) ? r = (e.nocase ? e.dot ? Ve : qe : e.dot ? Ye : Ze)(n) : (n = t.match(ze)) ? r = e.dot ? _e : Le : (n = t.match(We)) && (r = He);
1296
- const i = E.fromGlob(t, this.options).toMMPattern();
1297
- return r && typeof i == "object" && Reflect.defineProperty(i, "test", { value: r }), i;
1511
+ let r, n = null;
1512
+ (r = t.match(Qe)) ? n = e.dot ? ts : Ke : (r = t.match(He)) ? n = (e.nocase ? e.dot ? qe : Ge : e.dot ? Ue : Be)(r[1]) : (r = t.match(es)) ? n = (e.nocase ? e.dot ? ns : ss : e.dot ? rs : is)(r) : (r = t.match(Ve)) ? n = e.dot ? Ye : Xe : (r = t.match(Ze)) && (n = Je);
1513
+ const i = ot.fromGlob(t, this.options).toMMPattern();
1514
+ return n && typeof i == "object" && Reflect.defineProperty(i, "test", { value: n }), i;
1298
1515
  }
1299
1516
  makeRe() {
1300
1517
  if (this.regexp || this.regexp === !1)
@@ -1302,30 +1519,38 @@ globstar while`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
1302
1519
  const t = this.set;
1303
1520
  if (!t.length)
1304
1521
  return this.regexp = !1, this.regexp;
1305
- const e = this.options, n = e.noglobstar ? Qe : e.dot ? Ke : ts, r = new Set(e.nocase ? ["i"] : []);
1306
- let i = t.map((a) => {
1307
- const h = a.map((l) => {
1308
- if (l instanceof RegExp)
1309
- for (const f of l.flags.split(""))
1310
- r.add(f);
1311
- return typeof l == "string" ? is(l) : l === D ? D : l._src;
1522
+ const e = this.options, r = e.noglobstar ? cs : e.dot ? ls : hs, n = new Set(e.nocase ? ["i"] : []);
1523
+ let i = t.map((c) => {
1524
+ const l = c.map((u) => {
1525
+ if (u instanceof RegExp)
1526
+ for (const f of u.flags.split(""))
1527
+ n.add(f);
1528
+ return typeof u == "string" ? gs(u) : u === S ? S : u._src;
1529
+ });
1530
+ l.forEach((u, f) => {
1531
+ const p = l[f + 1], g = l[f - 1];
1532
+ u !== S || g === S || (g === void 0 ? p !== void 0 && p !== S ? l[f + 1] = "(?:\\/|" + r + "\\/)?" + p : l[f] = r : p === void 0 ? l[f - 1] = g + "(?:\\/|\\/" + r + ")?" : p !== S && (l[f - 1] = g + "(?:\\/|\\/" + r + "\\/)" + p, l[f + 1] = S));
1312
1533
  });
1313
- return h.forEach((l, f) => {
1314
- const u = h[f + 1], d = h[f - 1];
1315
- l !== D || d === D || (d === void 0 ? u !== void 0 && u !== D ? h[f + 1] = "(?:\\/|" + n + "\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\/|" + n + ")?" : u !== D && (h[f - 1] = d + "(?:\\/|\\/" + n + "\\/)" + u, h[f + 1] = D));
1316
- }), h.filter((l) => l !== D).join("/");
1534
+ const h = l.filter((u) => u !== S);
1535
+ if (this.partial && h.length >= 1) {
1536
+ const u = [];
1537
+ for (let f = 1; f <= h.length; f++)
1538
+ u.push(h.slice(0, f).join("/"));
1539
+ return "(?:" + u.join("|") + ")";
1540
+ }
1541
+ return h.join("/");
1317
1542
  }).join("|");
1318
- const [o, c] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1319
- i = "^" + o + i + c + "$", this.negate && (i = "^(?!" + i + ").+$");
1543
+ const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1544
+ i = "^" + o + i + a + "$", this.partial && (i = "^(?:\\/|" + o + i.slice(1, -1) + a + ")$"), this.negate && (i = "^(?!" + i + ").+$");
1320
1545
  try {
1321
- this.regexp = new RegExp(i, [...r].join(""));
1546
+ this.regexp = new RegExp(i, [...n].join(""));
1322
1547
  } catch {
1323
1548
  this.regexp = !1;
1324
1549
  }
1325
1550
  return this.regexp;
1326
1551
  }
1327
1552
  slashSplit(t) {
1328
- return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\/\/[^\/]+/.test(t) ? ["", ...t.split(/\/+/)] : t.split(/\/+/);
1553
+ return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\/\/[^/]+/.test(t) ? ["", ...t.split(/\/+/)] : t.split(/\/+/);
1329
1554
  }
1330
1555
  match(t, e = this.partial) {
1331
1556
  if (this.debug("match", t, this.pattern), this.comment)
@@ -1334,102 +1559,109 @@ globstar while`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
1334
1559
  return t === "";
1335
1560
  if (t === "/" && e)
1336
1561
  return !0;
1337
- const n = this.options;
1562
+ const r = this.options;
1338
1563
  this.isWindows && (t = t.split("\\").join("/"));
1339
- const r = this.slashSplit(t);
1340
- this.debug(this.pattern, "split", r);
1564
+ const n = this.slashSplit(t);
1565
+ this.debug(this.pattern, "split", n);
1341
1566
  const i = this.set;
1342
1567
  this.debug(this.pattern, "set", i);
1343
- let o = r[r.length - 1];
1568
+ let o = n[n.length - 1];
1344
1569
  if (!o)
1345
- for (let c = r.length - 2; !o && c >= 0; c--)
1346
- o = r[c];
1347
- for (let c = 0; c < i.length; c++) {
1348
- const a = i[c];
1349
- let h = r;
1350
- if (n.matchBase && a.length === 1 && (h = [o]), this.matchOne(h, a, e))
1351
- return n.flipNegate ? !0 : !this.negate;
1570
+ for (let a = n.length - 2; !o && a >= 0; a--)
1571
+ o = n[a];
1572
+ for (const a of i) {
1573
+ let c = n;
1574
+ if (r.matchBase && a.length === 1 && (c = [o]), this.matchOne(c, a, e))
1575
+ return r.flipNegate ? !0 : !this.negate;
1352
1576
  }
1353
- return n.flipNegate ? !1 : this.negate;
1577
+ return r.flipNegate ? !1 : this.negate;
1354
1578
  }
1355
1579
  static defaults(t) {
1356
- return y.defaults(t).Minimatch;
1580
+ return b.defaults(t).Minimatch;
1357
1581
  }
1358
1582
  }
1359
- y.AST = E;
1360
- y.Minimatch = V;
1361
- y.escape = $e;
1362
- y.unescape = I;
1363
- function os() {
1583
+ b.AST = ot;
1584
+ b.Minimatch = U;
1585
+ b.escape = je;
1586
+ b.unescape = R;
1587
+ function ws() {
1364
1588
  if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
1365
- throw new Xt();
1589
+ throw new Kt();
1366
1590
  }
1367
- async function z(s, t) {
1368
- return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(`opfs:${s.replace(/\/+/g, "/")}`, { mode: "exclusive" }, t) : t();
1591
+ function ys(s, t) {
1592
+ const e = F(s || "/"), r = F(Lt(t));
1593
+ return e === "/" ? r : r === "/" ? e : `${e.replace(/\/$/, "")}${r}`;
1369
1594
  }
1370
- function $(s) {
1595
+ async function It(s, t, e = "/") {
1596
+ if (typeof navigator < "u" && navigator.locks?.request) {
1597
+ const r = ys(e, s).replace(/\/+/g, "/");
1598
+ return navigator.locks.request(`opfs:${r}`, { mode: "exclusive" }, t);
1599
+ }
1600
+ return t();
1601
+ }
1602
+ function P(s) {
1371
1603
  return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
1372
1604
  }
1373
1605
  function at(s) {
1374
1606
  return typeof s == "string" ? s ?? "/" : `/${s.join("/")}`;
1375
1607
  }
1376
1608
  function st(s) {
1377
- const t = $(s);
1609
+ const t = P(s);
1378
1610
  return t[t.length - 1] || "";
1379
1611
  }
1380
- function J(s) {
1381
- const t = $(s);
1612
+ function Y(s) {
1613
+ const t = P(s);
1382
1614
  return t.pop(), at(t);
1383
1615
  }
1384
- function nt(s) {
1616
+ function F(s) {
1385
1617
  return !s || s === "/" ? "/" : s.startsWith("~/") ? `/${s.slice(2)}` : s.startsWith("/") ? s : `/${s}`;
1386
1618
  }
1387
- function as(s, t = !1) {
1619
+ function ms(s, t = !1) {
1388
1620
  return s = s.replace(/\/$/, ""), t && !s.includes("*") ? `${s}/**` : s;
1389
1621
  }
1390
- function Q(s, t) {
1391
- return y(s, t, {
1622
+ function Z(s, t) {
1623
+ return b(s, t, {
1392
1624
  dot: !0,
1393
1625
  matchBase: !0
1394
1626
  });
1395
1627
  }
1396
- function cs(s) {
1397
- const t = nt(s), e = $(t), n = [];
1398
- for (const r of e)
1399
- if (!(r === "." || r === ""))
1400
- if (r === "..") {
1401
- if (n.length === 0)
1628
+ function Lt(s) {
1629
+ const t = F(s), e = P(t), r = [];
1630
+ for (const n of e)
1631
+ if (!(n === "." || n === ""))
1632
+ if (n === "..") {
1633
+ if (r.length === 0)
1402
1634
  continue;
1403
- n.pop();
1635
+ r.pop();
1404
1636
  } else
1405
- n.push(r);
1406
- return at(n);
1637
+ r.push(n);
1638
+ return at(r);
1407
1639
  }
1408
- async function ls(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1640
+ async function Es(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1409
1641
  if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
1410
1642
  throw new Error(`File size ${s.byteLength} bytes exceeds maximum allowed size ${e} bytes`);
1411
- const n = new Uint8Array(s), r = await crypto.subtle.digest(t, n);
1412
- return Array.from(new Uint8Array(r)).map((o) => o.toString(16).padStart(2, "0")).join("");
1643
+ const r = new Uint8Array(s), n = await crypto.subtle.digest(t, r);
1644
+ return Array.from(new Uint8Array(n)).map((o) => o.toString(16).padStart(2, "0")).join("");
1413
1645
  }
1414
- async function hs(s, t, e = {}) {
1415
- const n = st(t);
1416
- return z(t, async () => {
1417
- const r = e.recursive ?? !1, i = e.force ?? !1;
1646
+ async function Ss(s, t, e = {}) {
1647
+ const r = st(t);
1648
+ return It(t, async () => {
1649
+ const n = e.recursive ?? !1, i = e.force ?? !1;
1418
1650
  try {
1419
- await s.removeEntry(n, { recursive: r });
1651
+ await s.removeEntry(r, { recursive: n });
1420
1652
  } catch (o) {
1421
1653
  if (o.name === "NotFoundError" && i)
1422
1654
  return;
1423
- const c = o.name === "TypeMismatchError" && !r;
1424
- throw x(o, {
1655
+ const a = o.name === "TypeMismatchError" && !n;
1656
+ throw A(o, {
1425
1657
  path: t,
1426
1658
  operation: "remove",
1427
- isDirectory: c
1659
+ isDirectory: a
1428
1660
  });
1429
1661
  }
1430
- });
1662
+ }, e.root ?? "/");
1431
1663
  }
1432
- class us {
1664
+ class bs {
1433
1665
  /** Root directory handle for the file system */
1434
1666
  root;
1435
1667
  /** Map of watched paths and options */
@@ -1458,12 +1690,12 @@ class us {
1458
1690
  if (!this.options.broadcastChannel)
1459
1691
  return;
1460
1692
  const e = t.path;
1461
- if (![...this.watchers.values()].some((i) => Q(e, i.pattern) && i.include.some((o) => o && Q(e, o)) && !i.exclude.some((o) => o && Q(e, o))))
1693
+ if (![...this.watchers.values()].some((i) => Z(e, i.pattern) && i.include.some((o) => o && Z(e, o)) && !i.exclude.some((o) => o && Z(e, o))))
1462
1694
  return;
1463
- let r;
1695
+ let n;
1464
1696
  if (this.options.hashAlgorithm)
1465
1697
  try {
1466
- r = (await this.stat(e)).hash;
1698
+ n = (await this.stat(e)).hash;
1467
1699
  } catch {
1468
1700
  }
1469
1701
  try {
@@ -1472,7 +1704,7 @@ class us {
1472
1704
  namespace: this.options.namespace,
1473
1705
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1474
1706
  ...t,
1475
- ...r && { hash: r }
1707
+ ...n && { hash: n }
1476
1708
  };
1477
1709
  this.broadcastChannel.postMessage(i);
1478
1710
  } catch (i) {
@@ -1480,7 +1712,11 @@ class us {
1480
1712
  }
1481
1713
  }
1482
1714
  constructor(t) {
1483
- os(), t && this.setOptions(t);
1715
+ ws(), t && this.setOptions(t);
1716
+ }
1717
+ /** Exclusive path lock keyed by absolute OPFS path (`root` + API path). */
1718
+ async withPathLock(t, e) {
1719
+ return It(t, e, this.options.root);
1484
1720
  }
1485
1721
  /**
1486
1722
  * Initialize the file system within a given directory.
@@ -1488,12 +1724,12 @@ class us {
1488
1724
  */
1489
1725
  async mount() {
1490
1726
  const t = this.options.root;
1491
- return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
1727
+ return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, r) => {
1492
1728
  try {
1493
- const r = await navigator.storage.getDirectory();
1494
- this.root = t === "/" ? r : await this.getDirectoryHandle(t, !0, r), e(!0);
1495
- } catch (r) {
1496
- n(new se(t, r));
1729
+ const n = await navigator.storage.getDirectory();
1730
+ this.root = t === "/" ? n : await this.getDirectoryHandle(t, !0, n), e(!0);
1731
+ } catch (n) {
1732
+ r(new ie(t, n));
1497
1733
  } finally {
1498
1734
  this.mountingPromise = null;
1499
1735
  }
@@ -1510,7 +1746,7 @@ class us {
1510
1746
  * @param options.broadcastChannel - Custom name for the broadcast channel
1511
1747
  */
1512
1748
  async setOptions(t) {
1513
- 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 = nt(t.root), this.options.namespace || (this.options.namespace = `opfs-worker:${this.options.root}`), await this.mount());
1749
+ 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 = F(t.root), this.options.namespace || (this.options.namespace = `opfs-worker:${this.options.root}`), await this.mount());
1514
1750
  }
1515
1751
  /**
1516
1752
  * Get a directory handle from a path
@@ -1530,10 +1766,10 @@ class us {
1530
1766
  * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
1531
1767
  * ```
1532
1768
  */
1533
- async getDirectoryHandle(t, e = !1, n = this.root) {
1534
- const r = Array.isArray(t) ? t : $(t);
1535
- let i = n;
1536
- for (const o of r)
1769
+ async getDirectoryHandle(t, e = !1, r = this.root) {
1770
+ const n = Array.isArray(t) ? t : P(t);
1771
+ let i = r;
1772
+ for (const o of n)
1537
1773
  i = await i.getDirectoryHandle(o, { create: e });
1538
1774
  return i;
1539
1775
  }
@@ -1556,12 +1792,12 @@ class us {
1556
1792
  * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
1557
1793
  * ```
1558
1794
  */
1559
- async getFileHandle(t, e = !1, n = this.root) {
1560
- const r = $(t);
1561
- if (r.length === 0)
1562
- throw new Jt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1563
- const i = r.pop();
1564
- return (await this.getDirectoryHandle(r, e, n)).getFileHandle(i, { create: e });
1795
+ async getFileHandle(t, e = !1, r = this.root) {
1796
+ const n = P(t);
1797
+ if (n.length === 0)
1798
+ throw new te("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1799
+ const i = n.pop();
1800
+ return (await this.getDirectoryHandle(n, e, r)).getFileHandle(i, { create: e });
1565
1801
  }
1566
1802
  /**
1567
1803
  * Get a complete index of all files and directories in the file system
@@ -1583,15 +1819,15 @@ class us {
1583
1819
  * ```
1584
1820
  */
1585
1821
  async index() {
1586
- const t = /* @__PURE__ */ new Map(), e = async (n) => {
1587
- const r = await this.readDir(n);
1588
- for (const i of r) {
1589
- const o = `${n === "/" ? "" : n}/${i.name}`;
1822
+ const t = /* @__PURE__ */ new Map(), e = async (r) => {
1823
+ const n = await this.readDir(r);
1824
+ for (const i of n) {
1825
+ const o = `${r === "/" ? "" : r}/${i.name}`;
1590
1826
  try {
1591
- const c = await this.stat(o);
1592
- t.set(o, c), c.isDirectory && await e(o);
1593
- } catch (c) {
1594
- console.warn(`Skipping broken entry: ${o}`, c);
1827
+ const a = await this.stat(o);
1828
+ t.set(o, a), a.isDirectory && await e(o);
1829
+ } catch (a) {
1830
+ console.warn(`Skipping broken entry: ${o}`, a);
1595
1831
  }
1596
1832
  }
1597
1833
  };
@@ -1627,20 +1863,20 @@ class us {
1627
1863
  */
1628
1864
  async mkdir(t, e) {
1629
1865
  await this.mount();
1630
- const n = e?.recursive ?? !1, r = $(t);
1866
+ const r = e?.recursive ?? !1, n = P(t);
1631
1867
  let i = this.root;
1632
- for (let o = 0; o < r.length; o++) {
1633
- const c = r[o];
1868
+ for (let o = 0; o < n.length; o++) {
1869
+ const a = n[o];
1634
1870
  try {
1635
- i = await i.getDirectoryHandle(c, { create: n || o === r.length - 1 });
1636
- } catch (a) {
1637
- throw a.name === "NotFoundError" ? x(a, {
1638
- path: at(r.slice(0, o + 1)),
1871
+ i = await i.getDirectoryHandle(a, { create: r || o === n.length - 1 });
1872
+ } catch (c) {
1873
+ throw c.name === "NotFoundError" ? A(c, {
1874
+ path: at(n.slice(0, o + 1)),
1639
1875
  existenceType: "directory"
1640
- }) : a.name === "TypeMismatchError" ? x(a, { path: c, isDirectory: !1 }) : new Z("create directory", c, a);
1876
+ }) : c.name === "TypeMismatchError" ? A(c, { path: a, isDirectory: !1 }) : new V("create directory", a, c);
1641
1877
  }
1642
1878
  }
1643
- await this.notifyChange({ path: t, type: A.Added, isDirectory: !0 });
1879
+ await this.notifyChange({ path: t, type: M.Added, isDirectory: !0 });
1644
1880
  }
1645
1881
  /**
1646
1882
  * Get file or directory statistics
@@ -1675,10 +1911,10 @@ class us {
1675
1911
  isDirectory: !0
1676
1912
  };
1677
1913
  const e = st(t);
1678
- let n;
1914
+ let r;
1679
1915
  try {
1680
- n = await this.getDirectoryHandle(J(t), !1);
1681
- const r = this.options.hashAlgorithm, o = await (await n.getFileHandle(e, { create: !1 })).getFile(), c = {
1916
+ r = await this.getDirectoryHandle(Y(t), !1);
1917
+ const n = this.options.hashAlgorithm, o = await (await r.getFileHandle(e, { create: !1 })).getFile(), a = {
1682
1918
  kind: "file",
1683
1919
  size: o.size,
1684
1920
  mtime: new Date(o.lastModified).toISOString(),
@@ -1686,24 +1922,24 @@ class us {
1686
1922
  isFile: !0,
1687
1923
  isDirectory: !1
1688
1924
  };
1689
- if (r === "etag")
1690
- c.hash = `${o.lastModified.toString(36)}-${o.size.toString(36)}`;
1691
- else if (typeof r == "string")
1925
+ if (n === "etag")
1926
+ a.hash = `${o.lastModified.toString(36)}-${o.size.toString(36)}`;
1927
+ else if (typeof n == "string")
1692
1928
  try {
1693
- const a = await ls(o, r, this.options.maxFileSize);
1694
- c.hash = a;
1695
- } catch (a) {
1696
- console.warn(`Failed to calculate hash for ${t}:`, a);
1929
+ const c = await Es(o, n, this.options.maxFileSize);
1930
+ a.hash = c;
1931
+ } catch (c) {
1932
+ console.warn(`Failed to calculate hash for ${t}:`, c);
1697
1933
  }
1698
- return c;
1699
- } catch (r) {
1700
- if (r.name === "NotFoundError")
1701
- throw new j("file", t, r);
1702
- if (r.name !== "TypeMismatchError")
1703
- throw new Z("stat", t, r);
1934
+ return a;
1935
+ } catch (n) {
1936
+ if (n.name === "NotFoundError")
1937
+ throw new L("file", t, n);
1938
+ if (n.name !== "TypeMismatchError")
1939
+ throw new V("stat", t, n);
1704
1940
  }
1705
1941
  try {
1706
- return await n.getDirectoryHandle(e, { create: !1 }), {
1942
+ return await r.getDirectoryHandle(e, { create: !1 }), {
1707
1943
  kind: "directory",
1708
1944
  size: 0,
1709
1945
  mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
@@ -1711,8 +1947,8 @@ class us {
1711
1947
  isFile: !1,
1712
1948
  isDirectory: !0
1713
1949
  };
1714
- } catch (r) {
1715
- throw new Z("stat", t, r);
1950
+ } catch (n) {
1951
+ throw new V("stat", t, n);
1716
1952
  }
1717
1953
  }
1718
1954
  /**
@@ -1735,17 +1971,17 @@ class us {
1735
1971
  */
1736
1972
  async readDir(t) {
1737
1973
  await this.mount();
1738
- const e = await this.getDirectoryHandle(t, !1), n = [];
1739
- for await (const [r, i] of e.entries()) {
1974
+ const e = await this.getDirectoryHandle(t, !1), r = [];
1975
+ for await (const [n, i] of e.entries()) {
1740
1976
  const o = i.kind === "file";
1741
- n.push({
1742
- name: r,
1977
+ r.push({
1978
+ name: n,
1743
1979
  kind: i.kind,
1744
1980
  isFile: o,
1745
1981
  isDirectory: !o
1746
1982
  });
1747
1983
  }
1748
- return n;
1984
+ return r;
1749
1985
  }
1750
1986
  /**
1751
1987
  * Check if a file or directory exists
@@ -1765,22 +2001,22 @@ class us {
1765
2001
  if (await this.mount(), t === "/")
1766
2002
  return !0;
1767
2003
  const e = st(t);
1768
- let n = null;
2004
+ let r = null;
1769
2005
  try {
1770
- n = await this.getDirectoryHandle(J(t), !1);
1771
- } catch (r) {
1772
- if (n = null, r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1773
- throw r;
2006
+ r = await this.getDirectoryHandle(Y(t), !1);
2007
+ } catch (n) {
2008
+ if (r = null, n.name !== "NotFoundError" && n.name !== "TypeMismatchError")
2009
+ throw n;
1774
2010
  }
1775
- if (!n || !e)
2011
+ if (!r || !e)
1776
2012
  return !1;
1777
2013
  try {
1778
- return await n.getFileHandle(e, { create: !1 }), !0;
1779
- } catch (r) {
1780
- if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1781
- throw r;
2014
+ return await r.getFileHandle(e, { create: !1 }), !0;
2015
+ } catch (n) {
2016
+ if (n.name !== "NotFoundError" && n.name !== "TypeMismatchError")
2017
+ throw n;
1782
2018
  try {
1783
- return await n.getDirectoryHandle(e, { create: !1 }), !0;
2019
+ return await r.getDirectoryHandle(e, { create: !1 }), !0;
1784
2020
  } catch (i) {
1785
2021
  if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1786
2022
  throw i;
@@ -1811,13 +2047,13 @@ class us {
1811
2047
  await this.mount();
1812
2048
  try {
1813
2049
  const e = await this.readDir(t);
1814
- for (const n of e) {
1815
- const r = `${t === "/" ? "" : t}/${n.name}`;
1816
- await this.remove(r, { recursive: !0 });
2050
+ for (const r of e) {
2051
+ const n = `${t === "/" ? "" : t}/${r.name}`;
2052
+ await this.remove(n, { recursive: !0 });
1817
2053
  }
1818
- await this.notifyChange({ path: t, type: A.Changed, isDirectory: !0 });
2054
+ await this.notifyChange({ path: t, type: M.Changed, isDirectory: !0 });
1819
2055
  } catch (e) {
1820
- throw e instanceof w ? e : x(e, { path: t, isDirectory: !0 });
2056
+ throw e instanceof w ? e : A(e, { path: t, isDirectory: !0 });
1821
2057
  }
1822
2058
  }
1823
2059
  /**
@@ -1846,9 +2082,9 @@ class us {
1846
2082
  */
1847
2083
  async remove(t, e) {
1848
2084
  if (await this.mount(), t === "/")
1849
- throw new et("EROOT", t);
1850
- const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(J(t), !1), o = await this.stat(t);
1851
- await hs(i, t, { recursive: n, force: r }), await this.notifyChange({ path: t, type: A.Removed, isDirectory: o.isDirectory });
2085
+ throw new K("EROOT", t);
2086
+ const { recursive: r = !1, force: n = !1 } = e || {}, i = await this.getDirectoryHandle(Y(t), !1), o = await this.stat(t);
2087
+ await Ss(i, t, { recursive: r, force: n, root: this.options.root }), await this.notifyChange({ path: t, type: M.Removed, isDirectory: o.isDirectory });
1852
2088
  }
1853
2089
  /**
1854
2090
  * Resolve a path to an absolute path
@@ -1871,12 +2107,12 @@ class us {
1871
2107
  async realpath(t) {
1872
2108
  await this.mount();
1873
2109
  try {
1874
- const e = cs(t);
2110
+ const e = Lt(t);
1875
2111
  if (!await this.exists(e))
1876
- throw new j("file", e);
2112
+ throw new L("file", e);
1877
2113
  return e;
1878
2114
  } catch (e) {
1879
- throw e instanceof w ? e : x(e, { path: t });
2115
+ throw e instanceof w ? e : A(e, { path: t });
1880
2116
  }
1881
2117
  }
1882
2118
  /**
@@ -1901,15 +2137,15 @@ class us {
1901
2137
  * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
1902
2138
  * ```
1903
2139
  */
1904
- async rename(t, e, n) {
2140
+ async rename(t, e, r) {
1905
2141
  await this.mount();
1906
2142
  try {
1907
- const r = n?.overwrite ?? !1, i = await this.stat(t);
1908
- if (await this.exists(e) && !r)
2143
+ const n = r?.overwrite ?? !1, i = await this.stat(t);
2144
+ if (await this.exists(e) && !n)
1909
2145
  throw new ut(e);
1910
- await this.copy(t, e, { recursive: !0, overwrite: r }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: A.Removed, isDirectory: i.isDirectory }), await this.notifyChange({ path: e, type: A.Added, isDirectory: i.isDirectory });
1911
- } catch (r) {
1912
- throw r instanceof w ? r : x(r, { path: t });
2146
+ await this.copy(t, e, { recursive: !0, overwrite: n }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: M.Removed, isDirectory: i.isDirectory }), await this.notifyChange({ path: e, type: M.Added, isDirectory: i.isDirectory });
2147
+ } catch (n) {
2148
+ throw n instanceof w ? n : A(n, { path: t });
1913
2149
  }
1914
2150
  }
1915
2151
  /**
@@ -1937,29 +2173,29 @@ class us {
1937
2173
  * await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
1938
2174
  * ```
1939
2175
  */
1940
- async copy(t, e, n) {
2176
+ async copy(t, e, r) {
1941
2177
  await this.mount();
1942
2178
  try {
1943
- const r = n?.recursive ?? !1, i = n?.overwrite ?? !0;
2179
+ const n = r?.recursive ?? !1, i = r?.overwrite ?? !0;
1944
2180
  if (!await this.exists(t))
1945
- throw new j("source", t);
2181
+ throw new L("source", t);
1946
2182
  if (await this.exists(e) && !i)
1947
2183
  throw new ut(e);
1948
2184
  if ((await this.stat(t)).isFile) {
1949
- const h = await this.readFile(t);
1950
- await this.writeFile(e, h);
2185
+ const l = await this.readFile(t);
2186
+ await this.writeFile(e, l);
1951
2187
  } else {
1952
- if (!r)
1953
- throw new tt("directory", t);
2188
+ if (!n)
2189
+ throw new Q("directory", t);
1954
2190
  await this.mkdir(e, { recursive: !0 });
1955
- const h = await this.readDir(t);
1956
- for (const l of h) {
1957
- const f = `${t}/${l.name}`, u = `${e}/${l.name}`;
1958
- await this.copy(f, u, { recursive: !0, overwrite: i });
2191
+ const l = await this.readDir(t);
2192
+ for (const h of l) {
2193
+ const u = `${t}/${h.name}`, f = `${e}/${h.name}`;
2194
+ await this.copy(u, f, { recursive: !0, overwrite: i });
1959
2195
  }
1960
2196
  }
1961
- } catch (r) {
1962
- throw r instanceof w ? r : x(r, { path: t });
2197
+ } catch (n) {
2198
+ throw n instanceof w ? n : A(n, { path: t });
1963
2199
  }
1964
2200
  }
1965
2201
  /**
@@ -1989,13 +2225,13 @@ class us {
1989
2225
  */
1990
2226
  async watch(t, e) {
1991
2227
  if (!this.options.broadcastChannel)
1992
- throw new v("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
1993
- const n = {
1994
- pattern: as(t, e?.recursive ?? !0),
2228
+ throw new T("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
2229
+ const r = {
2230
+ pattern: ms(t, e?.recursive ?? !0),
1995
2231
  include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
1996
2232
  exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
1997
2233
  };
1998
- this.watchers.set(t, n);
2234
+ this.watchers.set(t, r);
1999
2235
  }
2000
2236
  /**
2001
2237
  * Stop watching a previously watched path
@@ -2026,7 +2262,7 @@ class us {
2026
2262
  try {
2027
2263
  return await (await this.getFileHandle(t, !1)).getFile();
2028
2264
  } catch (e) {
2029
- throw e instanceof w ? e : x(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2265
+ throw e instanceof w ? e : A(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2030
2266
  }
2031
2267
  }
2032
2268
  /**
@@ -2054,39 +2290,39 @@ class us {
2054
2290
  */
2055
2291
  async importFiles(t, e) {
2056
2292
  await this.mount();
2057
- const n = [...t].map(([a, h]) => [nt(a), h]), r = n.length, i = n.map(([a]) => a), o = n.reduce((a, [, h]) => a + fs(h), 0);
2058
- let c = 0;
2293
+ const r = [...t].map(([c, l]) => [F(c), l]), n = r.length, i = r.map(([c]) => c), o = r.reduce((c, [, l]) => c + xs(l), 0);
2294
+ let a = 0;
2059
2295
  try {
2060
- for (let a = 0; a < r; a++) {
2061
- const [h, l] = n[a], { stream: f, size: u } = ds(l), d = c, g = await this.writeStream(
2062
- h,
2063
- f,
2064
- e ? (p) => e({
2065
- path: h,
2066
- index: a,
2067
- count: r,
2068
- bytesWritten: p,
2069
- bytesTotal: u,
2070
- totalBytesWritten: d + p,
2296
+ for (let c = 0; c < n; c++) {
2297
+ const [l, h] = r[c], { stream: u, size: f } = As(h), p = a, g = await this.writeStream(
2298
+ l,
2299
+ u,
2300
+ e ? (d) => e({
2301
+ path: l,
2302
+ index: c,
2303
+ count: n,
2304
+ bytesWritten: d,
2305
+ bytesTotal: f,
2306
+ totalBytesWritten: p + d,
2071
2307
  totalBytes: o
2072
2308
  }) : void 0
2073
2309
  );
2074
- c += g;
2310
+ a += g;
2075
2311
  }
2076
2312
  return {
2077
2313
  paths: i,
2078
- count: r,
2079
- bytesWritten: c
2314
+ count: n,
2315
+ bytesWritten: a
2080
2316
  };
2081
- } catch (a) {
2082
- throw a instanceof w ? a : x(a);
2317
+ } catch (c) {
2318
+ throw c instanceof w ? c : A(c);
2083
2319
  }
2084
2320
  }
2085
2321
  /**
2086
2322
  * @deprecated Use {@link importFiles} instead.
2087
2323
  */
2088
2324
  async createIndex(t) {
2089
- ps(), await this.importFiles(t);
2325
+ Os(), await this.importFiles(t);
2090
2326
  }
2091
2327
  /**
2092
2328
  * Dispose of resources and clean up the file system instance
@@ -2095,10 +2331,10 @@ class us {
2095
2331
  this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
2096
2332
  }
2097
2333
  }
2098
- function fs(s) {
2334
+ function xs(s) {
2099
2335
  return typeof s == "string" ? new TextEncoder().encode(s).byteLength : s instanceof Blob ? s.size : s.byteLength;
2100
2336
  }
2101
- function ds(s) {
2337
+ function As(s) {
2102
2338
  if (s instanceof Blob)
2103
2339
  return { stream: s.stream(), size: s.size };
2104
2340
  const t = typeof s == "string" ? new TextEncoder().encode(s) : s;
@@ -2111,80 +2347,80 @@ function ds(s) {
2111
2347
  })
2112
2348
  };
2113
2349
  }
2114
- let Et = !1;
2115
- function ps() {
2116
- Et || (Et = !0, console.warn("[opfs-worker] createIndex() is deprecated; use importFiles() instead"));
2350
+ let St = !1;
2351
+ function Os() {
2352
+ St || (St = !0, console.warn("[opfs-worker] createIndex() is deprecated; use importFiles() instead"));
2117
2353
  }
2118
- const T = "file descriptors are not available in the async backend, use the dedicated worker backend (`createOPFSDedicated`) for positional I/O";
2119
- class gs extends us {
2354
+ const N = "file descriptors are not available in the async backend, use the dedicated worker backend (`createOPFSDedicated`) for positional I/O";
2355
+ class Ms extends bs {
2120
2356
  async readFile(t) {
2121
2357
  await this.mount();
2122
2358
  try {
2123
- return await z(t, async () => {
2124
- const n = await (await this.getFileHandle(t, !1)).getFile(), r = new Uint8Array(await n.arrayBuffer());
2125
- return vt(r, [r.buffer]);
2359
+ return await this.withPathLock(t, async () => {
2360
+ const r = await (await this.getFileHandle(t, !1)).getFile(), n = new Uint8Array(await r.arrayBuffer());
2361
+ return Dt(n, [n.buffer]);
2126
2362
  });
2127
2363
  } catch (e) {
2128
- throw e instanceof w ? e : x(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2364
+ throw e instanceof w ? e : A(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2129
2365
  }
2130
2366
  }
2131
2367
  async writeFile(t, e) {
2132
2368
  await this.mount();
2133
- const n = e instanceof Uint8Array ? e : new Uint8Array(e);
2369
+ const r = e instanceof Uint8Array ? e : new Uint8Array(e);
2134
2370
  try {
2135
- await z(t, async () => {
2136
- const r = await this.exists(t), i = await this.getFileHandle(t, !0);
2137
- await this._writeStream(i, async (o) => o.write(n)), await this.notifyChange({ path: t, type: r ? A.Changed : A.Added, isDirectory: !1 });
2371
+ await this.withPathLock(t, async () => {
2372
+ const n = await this.exists(t), i = await this.getFileHandle(t, !0);
2373
+ await this._writeStream(i, async (o) => o.write(r)), await this.notifyChange({ path: t, type: n ? M.Changed : M.Added, isDirectory: !1 });
2138
2374
  });
2139
- } catch (r) {
2140
- throw r instanceof w ? r : x(r, { path: t, isDirectory: r?.name === "TypeMismatchError" });
2375
+ } catch (n) {
2376
+ throw n instanceof w ? n : A(n, { path: t, isDirectory: n?.name === "TypeMismatchError" });
2141
2377
  }
2142
2378
  }
2143
2379
  async appendFile(t, e) {
2144
2380
  await this.mount();
2145
- const n = e instanceof Uint8Array ? e : new Uint8Array(e);
2381
+ const r = e instanceof Uint8Array ? e : new Uint8Array(e);
2146
2382
  try {
2147
- await z(t, async () => {
2148
- const r = await this.getFileHandle(t, !0), { size: i } = await r.getFile();
2383
+ await this.withPathLock(t, async () => {
2384
+ const n = await this.getFileHandle(t, !0), { size: i } = await n.getFile();
2149
2385
  await this._writeStream(
2150
- r,
2151
- async (o) => o.write({ type: "write", position: i, data: n }),
2386
+ n,
2387
+ async (o) => o.write({ type: "write", position: i, data: r }),
2152
2388
  { keepExistingData: !0 }
2153
- ), await this.notifyChange({ path: t, type: A.Changed, isDirectory: !1 });
2389
+ ), await this.notifyChange({ path: t, type: M.Changed, isDirectory: !1 });
2154
2390
  });
2155
- } catch (r) {
2156
- throw r instanceof w ? r : x(r, { path: t, isDirectory: r?.name === "TypeMismatchError" });
2391
+ } catch (n) {
2392
+ throw n instanceof w ? n : A(n, { path: t, isDirectory: n?.name === "TypeMismatchError" });
2157
2393
  }
2158
2394
  }
2159
- async writeStream(t, e, n) {
2395
+ async writeStream(t, e, r) {
2160
2396
  await this.mount();
2161
2397
  try {
2162
- return await z(t, async () => {
2163
- const r = await this.exists(t), i = await this.getFileHandle(t, !0), o = e.getReader();
2164
- let c = 0;
2398
+ return await this.withPathLock(t, async () => {
2399
+ const n = await this.exists(t), i = await this.getFileHandle(t, !0), o = e.getReader();
2400
+ let a = 0;
2165
2401
  try {
2166
- await this._writeStream(i, async (a) => {
2402
+ await this._writeStream(i, async (c) => {
2167
2403
  for (; ; ) {
2168
- const { done: h, value: l } = await o.read();
2169
- if (h)
2404
+ const { done: l, value: h } = await o.read();
2405
+ if (l)
2170
2406
  break;
2171
- await a.write(l), c += l.byteLength, await n?.(c);
2407
+ await c.write(h), a += h.byteLength, await r?.(a);
2172
2408
  }
2173
2409
  });
2174
- } catch (a) {
2175
- throw await o.cancel(a).catch(() => {
2176
- }), a;
2410
+ } catch (c) {
2411
+ throw await o.cancel(c).catch(() => {
2412
+ }), c;
2177
2413
  } finally {
2178
2414
  o.releaseLock();
2179
2415
  }
2180
2416
  return await this.notifyChange({
2181
2417
  path: t,
2182
- type: r ? A.Changed : A.Added,
2418
+ type: n ? M.Changed : M.Added,
2183
2419
  isDirectory: !1
2184
- }), c;
2420
+ }), a;
2185
2421
  });
2186
- } catch (r) {
2187
- throw r instanceof w ? r : x(r, { path: t, isDirectory: r?.name === "TypeMismatchError" });
2422
+ } catch (n) {
2423
+ throw n instanceof w ? n : A(n, { path: t, isDirectory: n?.name === "TypeMismatchError" });
2188
2424
  }
2189
2425
  }
2190
2426
  /**
@@ -2192,49 +2428,49 @@ class gs extends us {
2192
2428
  * Aborts the stream (discarding the swap file) if the callback fails.
2193
2429
  * @private
2194
2430
  */
2195
- async _writeStream(t, e, n) {
2431
+ async _writeStream(t, e, r) {
2196
2432
  if (typeof t.createWritable != "function")
2197
- throw new v("createWritable() is not available in this browser (Safari supports it since version 26), use the dedicated worker backend (`createOPFSDedicated`) instead");
2198
- const r = await t.createWritable(n);
2433
+ throw new T("createWritable() is not available in this browser (Safari supports it since version 26), use the dedicated worker backend (`createOPFSDedicated`) instead");
2434
+ const n = await t.createWritable(r);
2199
2435
  try {
2200
- await e(r);
2436
+ await e(n);
2201
2437
  } catch (i) {
2202
- throw await r.abort().catch(() => {
2438
+ throw await n.abort().catch(() => {
2203
2439
  }), i;
2204
2440
  }
2205
- await r.close();
2441
+ await n.close();
2206
2442
  }
2207
2443
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2208
2444
  async open(t, e) {
2209
- throw new v(T);
2445
+ throw new T(N);
2210
2446
  }
2211
2447
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2212
2448
  async close(t) {
2213
- throw new v(T);
2449
+ throw new T(N);
2214
2450
  }
2215
2451
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2216
- async read(t, e, n, r, i) {
2217
- throw new v(T);
2452
+ async read(t, e, r, n, i) {
2453
+ throw new T(N);
2218
2454
  }
2219
2455
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2220
- async write(t, e, n, r, i, o) {
2221
- throw new v(T);
2456
+ async write(t, e, r, n, i, o) {
2457
+ throw new T(N);
2222
2458
  }
2223
2459
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2224
2460
  async fstat(t) {
2225
- throw new v(T);
2461
+ throw new T(N);
2226
2462
  }
2227
2463
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2228
2464
  async ftruncate(t, e) {
2229
- throw new v(T);
2465
+ throw new T(N);
2230
2466
  }
2231
2467
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2232
2468
  async fsync(t) {
2233
- throw new v(T);
2469
+ throw new T(N);
2234
2470
  }
2235
2471
  }
2236
- const ws = new gs();
2472
+ const Ts = new Ms();
2237
2473
  globalThis.onconnect = (s) => {
2238
- rt(ws, s.ports[0]);
2474
+ nt(Ts, s.ports[0]);
2239
2475
  };
2240
2476
  //# sourceMappingURL=shared.worker.js.map