opfs-worker 2.1.0 → 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 (111) hide show
  1. package/README.md +51 -37
  2. package/dist/BaseOPFS-Bu7FZtCb.cjs +2 -0
  3. package/dist/BaseOPFS-Bu7FZtCb.cjs.map +1 -0
  4. package/dist/{BaseOPFS-Cylz6ijk.js → BaseOPFS-C3NE4BKr.js} +804 -484
  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-BKSAJJeh.js → OPFSAsync-aeLUdIqd.js} +19 -19
  9. package/dist/OPFSAsync-aeLUdIqd.js.map +1 -0
  10. package/dist/OPFSFacade-BJv2yuWU.cjs +2 -0
  11. package/dist/OPFSFacade-BJv2yuWU.cjs.map +1 -0
  12. package/dist/OPFSFacade-DiogtQoq.js +308 -0
  13. package/dist/OPFSFacade-DiogtQoq.js.map +1 -0
  14. package/dist/OPFSSync-3qlSBYmz.cjs +2 -0
  15. package/dist/OPFSSync-3qlSBYmz.cjs.map +1 -0
  16. package/dist/{OPFSSync-CsSQkpk5.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 +60 -9
  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-Y4Mg6qte.js.map → createOPFSAsync-B611B63X.js.map} +1 -1
  25. package/dist/createOPFSAsync-BATjJg8k.cjs +2 -0
  26. package/dist/{createOPFSAsync-BwKDmHsy.cjs.map → createOPFSAsync-BATjJg8k.cjs.map} +1 -1
  27. package/dist/createOPFSDedicated-DgudPTB8.js +2676 -0
  28. package/dist/createOPFSDedicated-DgudPTB8.js.map +1 -0
  29. package/dist/createOPFSDedicated-EmIwluQo.cjs +2597 -0
  30. package/dist/createOPFSDedicated-EmIwluQo.cjs.map +1 -0
  31. package/dist/{createOPFSShared-CGdd__PH.js → createOPFSShared-BWYln8jJ.js} +2 -2
  32. package/dist/{createOPFSShared-CGdd__PH.js.map → createOPFSShared-BWYln8jJ.js.map} +1 -1
  33. package/dist/{createOPFSShared-CskROt7U.cjs → createOPFSShared-DPJpCd7z.cjs} +2 -2
  34. package/dist/{createOPFSShared-CskROt7U.cjs.map → createOPFSShared-DPJpCd7z.cjs.map} +1 -1
  35. package/dist/dedicated.worker.js +1104 -790
  36. package/dist/dedicated.worker.js.map +1 -1
  37. package/dist/facade/OPFSFacade.d.ts +21 -3
  38. package/dist/facade/OPFSFacade.d.ts.map +1 -1
  39. package/dist/facade/createOPFSDedicated.d.ts +4 -2
  40. package/dist/facade/createOPFSDedicated.d.ts.map +1 -1
  41. package/dist/index.async.cjs +1 -1
  42. package/dist/index.async.js +33 -32
  43. package/dist/index.cjs +1 -1
  44. package/dist/index.d.ts +1 -5
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +44 -43
  47. package/dist/index.pure.cjs +1 -1
  48. package/dist/index.pure.js +38 -37
  49. package/dist/index.sharedworker.cjs +1 -1
  50. package/dist/index.sharedworker.js +34 -33
  51. package/dist/index.sync.cjs +1 -1
  52. package/dist/index.sync.d.ts +2 -0
  53. package/dist/index.sync.d.ts.map +1 -1
  54. package/dist/index.sync.js +34 -32
  55. package/dist/shared.worker.js +1101 -791
  56. package/dist/shared.worker.js.map +1 -1
  57. package/dist/types.d.ts +38 -5
  58. package/dist/types.d.ts.map +1 -1
  59. package/dist/utils/helpers.d.ts +13 -3
  60. package/dist/utils/helpers.d.ts.map +1 -1
  61. package/dist/worker/createDedicatedWorker.d.ts +8 -3
  62. package/dist/worker/createDedicatedWorker.d.ts.map +1 -1
  63. package/docs/README.md +13 -25
  64. package/docs/api/README.md +221 -0
  65. package/docs/api/file-descriptors.md +137 -0
  66. package/docs/guides/async.md +4 -4
  67. package/docs/guides/dedicated.md +10 -8
  68. package/docs/guides/hashing.md +3 -3
  69. package/docs/guides/pure.md +4 -4
  70. package/docs/guides/sharedworker.md +2 -2
  71. package/docs/guides/streaming.md +146 -12
  72. package/docs/guides/watching.md +3 -3
  73. package/docs/migration.md +10 -11
  74. package/docs/types.md +93 -155
  75. package/package.json +20 -9
  76. package/src/core/BaseOPFS.ts +194 -29
  77. package/src/core/OPFSAsync.ts +4 -5
  78. package/src/core/OPFSSync.ts +6 -7
  79. package/src/facade/OPFSFacade.ts +51 -4
  80. package/src/facade/createOPFSDedicated.ts +4 -2
  81. package/src/index.sync.ts +2 -0
  82. package/src/index.ts +1 -5
  83. package/src/types.ts +42 -3
  84. package/src/utils/helpers.ts +32 -6
  85. package/src/worker/createDedicatedWorker.ts +85 -7
  86. package/src/worker/dedicated.worker.ts +12 -1
  87. package/dist/BaseOPFS-BPw9AIQ-.cjs +0 -4
  88. package/dist/BaseOPFS-BPw9AIQ-.cjs.map +0 -1
  89. package/dist/BaseOPFS-Cylz6ijk.js.map +0 -1
  90. package/dist/OPFSAsync-BKSAJJeh.js.map +0 -1
  91. package/dist/OPFSAsync-s2P7y3sw.cjs +0 -2
  92. package/dist/OPFSAsync-s2P7y3sw.cjs.map +0 -1
  93. package/dist/OPFSFacade-DePnNRgt.cjs +0 -2
  94. package/dist/OPFSFacade-DePnNRgt.cjs.map +0 -1
  95. package/dist/OPFSFacade-XohWlHuu.js +0 -281
  96. package/dist/OPFSFacade-XohWlHuu.js.map +0 -1
  97. package/dist/OPFSSync-C7KBepe_.cjs +0 -2
  98. package/dist/OPFSSync-C7KBepe_.cjs.map +0 -1
  99. package/dist/OPFSSync-CsSQkpk5.js.map +0 -1
  100. package/dist/assets/dedicated.worker-nY3tK4zi.js.map +0 -1
  101. package/dist/createOPFSAsync-BwKDmHsy.cjs +0 -2
  102. package/dist/createOPFSAsync-Y4Mg6qte.js +0 -10
  103. package/dist/createOPFSDedicated-CsnV6MLP.js +0 -2333
  104. package/dist/createOPFSDedicated-CsnV6MLP.js.map +0 -1
  105. package/dist/createOPFSDedicated-pKTRWLdz.cjs +0 -2283
  106. package/dist/createOPFSDedicated-pKTRWLdz.cjs.map +0 -1
  107. package/docs/api/backend.md +0 -36
  108. package/docs/api/create.md +0 -82
  109. package/docs/api/facade.md +0 -52
  110. package/docs/choosing-a-mode.md +0 -41
  111. package/docs/file-descriptors.md +0 -695
@@ -1,19 +1,14 @@
1
- /**
2
- * @license
3
- * Copyright 2019 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- const Et = Symbol("Comlink.proxy"), It = Symbol("Comlink.endpoint"), zt = Symbol("Comlink.releaseProxy"), Y = Symbol("Comlink.finalizer"), H = Symbol("Comlink.thrown"), St = (s) => typeof s == "object" && s !== null || typeof s == "function", Lt = {
7
- canHandle: (s) => St(s) && s[Et],
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(), jt(s);
8
+ return s.start(), qt(s);
14
9
  }
15
- }, _t = {
16
- canHandle: (s) => St(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 Et = Symbol("Comlink.proxy"), It = Symbol("Comlink.endpoint"), zt = 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", Lt],
33
- ["throw", _t]
26
+ }, At = /* @__PURE__ */ new Map([
27
+ ["proxy", Ht],
28
+ ["throw", Bt]
34
29
  ]);
35
- function Wt(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 (!Wt(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: a } = Object.assign({ path: [] }, r.data), l = (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 c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.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
- c[a.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(c, l);
56
+ l = u.apply(h, c);
62
57
  break;
63
58
  case "CONSTRUCT":
64
59
  {
65
- const u = new f(...l);
66
- h = qt(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 = At(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 (c) {
82
- h = { value: c, [H]: 0 };
76
+ } catch (h) {
77
+ l = { value: h, [I]: 0 };
83
78
  }
84
- Promise.resolve(h).catch((c) => ({ value: c, [H]: 0 })).then((c) => {
85
- const [f, u] = G(c);
86
- t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u), o === "RELEASE" && (t.removeEventListener("message", n), bt(t), Y in s && typeof s[Y] == "function" && s[Y]());
87
- }).catch((c) => {
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 Ht(s) {
91
+ function Gt(s) {
97
92
  return s.constructor.name === "MessagePort";
98
93
  }
99
- function bt(s) {
100
- Ht(s) && s.close();
94
+ function Ot(s) {
95
+ Gt(s) && s.close();
101
96
  }
102
- function jt(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 jt(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 Ot(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
- bt(s);
120
+ Ot(s);
126
121
  });
127
122
  }
128
- const U = /* @__PURE__ */ new WeakMap(), B = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
129
- const t = (U.get(s) || 0) - 1;
130
- U.set(s, t), t === 0 && Ot(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 = (U.get(t) || 0) + 1;
134
- U.set(t, e), B && B.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 Bt(s) {
137
- B && B.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, {
136
+ let n = !1;
137
+ const i = new Proxy(r, {
143
138
  get(o, a) {
144
- if (_(r), a === zt)
139
+ if (_(n), a === jt)
145
140
  return () => {
146
- Bt(i), Ot(s), t.clear(), r = !0;
141
+ Xt(i), Mt(s), t.clear(), n = !0;
147
142
  };
148
143
  if (a === "then") {
149
144
  if (e.length === 0)
150
145
  return { then: () => i };
151
- const l = 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 l.then.bind(l);
148
+ path: e.map((l) => l.toString())
149
+ }).then($);
150
+ return c.then.bind(c);
156
151
  }
157
- return K(s, t, [...e, a]);
152
+ return J(s, t, [...e, a]);
158
153
  },
159
- set(o, a, l) {
160
- _(r);
161
- const [h, c] = G(l);
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, a].map((f) => f.toString()),
165
- value: h
166
- }, c).then(M);
159
+ path: [...e, a].map((u) => u.toString()),
160
+ value: l
161
+ }, h).then($);
167
162
  },
168
- apply(o, a, l) {
169
- _(r);
170
- const h = e[e.length - 1];
171
- if (h === It)
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 [c, f] = ct(l);
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: c
182
- }, f).then(M);
175
+ path: e.map((f) => f.toString()),
176
+ argumentList: h
177
+ }, u).then($);
183
178
  },
184
179
  construct(o, a) {
185
- _(r);
186
- const [l, h] = ct(a);
187
- return C(s, t, {
180
+ _(n);
181
+ const [c, l] = ct(a);
182
+ return v(s, t, {
188
183
  type: "CONSTRUCT",
189
- path: e.map((c) => c.toString()),
190
- argumentList: l
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 Gt(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]), Gt(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 Dt = /* @__PURE__ */ new WeakMap();
204
- function At(s, t) {
205
- return Dt.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 qt(s) {
208
- return Object.assign(s, { [Et]: !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
- Dt.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 = Vt();
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 Vt() {
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 Yt = {
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 = Yt[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 Zt 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 Xt 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 Jt 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 Qt 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 Kt 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 te 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 ee 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 D(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 Kt(e || "unknown", s);
380
+ return new ne(e || "unknown", s);
386
381
  case "QuotaExceededError":
387
- return new Qt(`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 Jt(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 te(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
- const vt = (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 && se(n, r, e);
402
+ const Nt = (s, t, 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
- }, se = (s, t, e) => {
420
- let n, r, i, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
421
- if (l >= 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 [l, h];
424
- for (n = [], i = e.length; c >= 0 && !a; ) {
425
- if (c === l)
426
- n.push(c), l = e.indexOf(s, c + 1);
427
- else if (n.length === 1) {
428
- const f = n.pop();
429
- f !== void 0 && (a = [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, c + 1);
432
- c = l < h && l >= 0 ? l : 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 && (a = [i, o]);
429
+ r.length && o !== void 0 && (a = [i, o]);
435
430
  }
436
431
  return a;
437
- }, Nt = "\0SLASH" + Math.random() + "\0", Tt = "\0OPEN" + Math.random() + "\0", it = "\0CLOSE" + Math.random() + "\0", Mt = "\0COMMA" + Math.random() + "\0", Ct = "\0PERIOD" + Math.random() + "\0", ne = new RegExp(Nt, "g"), re = new RegExp(Tt, "g"), ie = new RegExp(it, "g"), oe = new RegExp(Mt, "g"), ae = new RegExp(Ct, "g"), ce = /\\\\/g, le = /\\{/g, he = /\\}/g, ue = /\\,/g, fe = /\\./g;
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 de(s) {
442
- return s.replace(ce, Nt).replace(le, Tt).replace(he, it).replace(ue, Mt).replace(fe, Ct);
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 pe(s) {
445
- return s.replace(ne, "\\").replace(re, "{").replace(ie, "}").replace(oe, ",").replace(ae, ".");
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
- const t = [], e = vt("{", "}", s);
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 a = Pt(i);
448
+ const { pre: r, body: n, post: i } = e, o = r.split(",");
449
+ o[o.length - 1] += "{" + n + "}";
450
+ const a = kt(i);
456
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 ge(s) {
459
- return s ? (s.slice(0, 2) === "{}" && (s = "\\{\\}" + s.slice(2)), F(de(s), !0).map(pe)) : [];
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 we(s) {
459
+ function xe(s) {
462
460
  return "{" + s + "}";
463
461
  }
464
- function me(s) {
462
+ function Ae(s) {
465
463
  return /^-?0\d/.test(s);
466
464
  }
467
- function ye(s, t) {
465
+ function Oe(s, t) {
468
466
  return s <= t;
469
467
  }
470
- function Ee(s, t) {
468
+ function Me(s, t) {
471
469
  return s >= t;
472
470
  }
473
- function F(s, t) {
474
- const e = [], n = vt("{", "}", 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 a = r + "{" + n.body + "}" + i[o];
481
- e.push(a);
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), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
485
- if (!l && !h)
486
- return n.post.match(/,(?!,).*\}/) ? (s = n.pre + "{" + n.body + it + n.post, F(s)) : [s];
487
- let c;
488
- if (l)
489
- c = n.body.split(/\.\./);
490
- else if (c = Pt(n.body), c.length === 1 && c[0] !== void 0 && (c = F(c[0], !1).map(we), c.length === 1))
491
- return i.map((u) => n.pre + c[0] + u);
492
- let f;
493
- if (l && c[0] !== void 0 && c[1] !== void 0) {
494
- const u = X(c[0]), d = X(c[1]), g = Math.max(c[0].length, c[1].length);
495
- let p = c.length === 3 && c[2] !== void 0 ? Math.abs(X(c[2])) : 1, S = ye;
496
- d < u && (p *= -1, S = Ee);
497
- const $ = c.some(me);
498
- f = [];
499
- for (let x = u; S(x, d); x += p) {
500
- let m;
501
- if (a)
502
- m = String.fromCharCode(x), m === "\\" && (m = "");
503
- else if (m = String(x), $) {
504
- const k = g - m.length;
505
- if (k > 0) {
506
- const L = new Array(k + 1).join("0");
507
- x < 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;
511
504
  }
512
- } else {
513
- f = [];
514
- for (let u = 0; u < c.length; u++)
515
- f.push.apply(f, F(c[u], !1));
516
505
  }
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 || l || g) && e.push(g);
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;
528
+ }
529
+ return C(n, c + "{" + a.body + "}" + a.post, [""], t, e, i);
530
+ }
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 Se = 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 > Se)
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 Se = 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, "\\$&"), be = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), dt = (s) => s.join(""), Oe = (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, a = !1, l = !1, h = !1, c = 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 && !l) {
558
- c = i + 1;
585
+ if (d === "]" && o && !c) {
586
+ h = i + 1;
559
587
  break;
560
588
  }
561
- if (o = !0, p === "\\" && !l) {
562
- l = !0, i++;
589
+ if (o = !0, d === "\\" && !c) {
590
+ c = !0, i++;
563
591
  continue;
564
592
  }
565
- if (p === "[" && !l) {
566
- for (const [S, [N, $, x]] 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, x ? r.push(N) : n.push(N), a = a || $;
598
+ i += E.length, D ? n.push(y) : r.push(y), a = a || m;
571
599
  continue t;
572
600
  }
573
601
  }
574
- if (l = !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 (c < 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 [be(p), !1, c - 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, a, c - e, !0];
598
- }, I = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1"), De = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), pt = (s) => De.has(s), Ae = "(?!(?:^|/)\\.\\.?(?:$|/))", W = "(?!\\.)", ve = /* @__PURE__ */ new Set(["[", "."]), Ne = /* @__PURE__ */ new Set(["..", "."]), Te = new Set("().*{}+?[]^$\\!"), Me = (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, a = -1, l = !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 === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (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, a = d, l = !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, c = 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 === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (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, a = h, l = !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
- c.push(u), u = "";
743
- const g = new E(d, c);
744
- c.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
- c.push(u), u = "", f.push(c), c = 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), c.push(u), u = "", e.push(...f, c), 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 a = (this.#r.nocase ? "i" : "") + (i ? "u" : "");
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" : "");
770
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 l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
851
- const [g, p, S, N] = typeof d == "string" ? E.#p(d, this.#n, l) : 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 c = "";
855
- if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Ne.has(this.#t[0]))) {
856
- const g = ve, 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
- c = p ? Ae : 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
- c + 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 l = this.toString();
876
- return this.#t = [l], this.type = null, this.#n = void 0, [l, 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
1013
  let a = "";
881
- if (this.type === "!" && this.#u)
882
- a = (this.isStart() && !e ? W : "") + wt;
1014
+ if (this.type === "!" && this.#h)
1015
+ a = (this.isStart() && !e ? z : "") + yt;
883
1016
  else {
884
- const l = 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
- a = r + i + l;
1021
+ a = n + i + c;
889
1022
  }
890
1023
  return [
891
1024
  a,
892
- I(i),
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;
907
- for (let a = 0; a < t.length; a++) {
908
- const l = t.charAt(a);
909
- if (r) {
910
- r = !1, i += (Te.has(l) ? "\\" : "") + l;
1053
+ static #A(t, e, r = !1) {
1054
+ let n = !1, i = "", o = !1, a = !1;
1055
+ for (let c = 0; c < t.length; c++) {
1056
+ const l = t.charAt(c);
1057
+ if (n) {
1058
+ n = !1, i += (Ie.has(l) ? "\\" : "") + l;
911
1059
  continue;
912
1060
  }
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;
913
1068
  if (l === "\\") {
914
- a === t.length - 1 ? i += "\\\\" : r = !0;
1069
+ c === t.length - 1 ? i += "\\\\" : n = !0;
915
1070
  continue;
916
1071
  }
917
1072
  if (l === "[") {
918
- const [h, c, f, u] = Oe(t, a);
1073
+ const [h, u, f, p] = ve(t, c);
919
1074
  if (f) {
920
- i += h, o = o || c, a += 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 (l === "*") {
925
- n && t === "*" ? i += wt : i += gt, e = !0;
926
- continue;
927
- }
928
1079
  if (l === "?") {
929
- i += ot, e = !0;
1080
+ i += it, e = !0;
930
1081
  continue;
931
1082
  }
932
- i += Me(l);
1083
+ i += Le(l);
933
1084
  }
934
- return [i, I(t), !!e, o];
935
- }
936
- }
937
- const Ce = (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 = /^\*+([^+@!?\*\[\(]*)$/, $e = (s) => (t) => !t.startsWith(".") && t.endsWith(s), ke = (s) => (t) => t.endsWith(s), Re = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), Fe = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Ie = /^\*+\.\*+$/, ze = (s) => !s.startsWith(".") && s.includes("."), Le = (s) => s !== "." && s !== ".." && s.includes("."), _e = /^\.\*+$/, We = (s) => s !== "." && s !== ".." && s.startsWith("."), He = /^\*+$/, je = (s) => s.length !== 0 && !s.startsWith("."), Ue = (s) => s.length !== 0 && s !== "." && s !== "..", Be = /^\?+([^+@!?\*\[\(]*)?$/, Ge = ([s, t = ""]) => {
938
- const e = $t([s]);
939
- return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
940
- }, qe = ([s, t = ""]) => {
941
- const e = kt([s]);
942
- return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
943
- }, Ve = ([s, t = ""]) => {
944
- const e = kt([s]);
945
- return t ? (n) => e(n) && n.endsWith(t) : e;
946
- }, Ye = ([s, t = ""]) => {
947
- const e = $t([s]);
948
- return t ? (n) => e(n) && n.endsWith(t) : e;
949
- }, $t = ([s]) => {
1085
+ return [i, R(t), !!e, o];
1086
+ }
1087
+ }
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 = ""]) => {
1090
+ const e = Rt([s]);
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 = ""]) => {
1099
+ const e = Rt([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
- }, kt = ([s]) => {
1104
+ }, Ft = ([s]) => {
953
1105
  const t = s.length;
954
1106
  return (e) => e.length === t && e !== "." && e !== "..";
955
- }, Rt = 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
- }, Ze = Rt === "win32" ? mt.win32.sep : mt.posix.sep;
959
- y.sep = Ze;
960
- const O = Symbol("globstar **");
961
- y.GLOBSTAR = O;
962
- const Xe = "[^/]", Je = Xe + "*?", Qe = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?", Ke = "(?:(?!(?:\\/|^)\\.).)*?", ts = (s, t = {}) => (e) => y(e, s, t);
963
- y.filter = ts;
964
- const b = (s, t = {}) => Object.assign({}, s, t), es = (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, b(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, b(s, i));
1122
+ constructor(n, i = {}) {
1123
+ super(n, O(s, i));
972
1124
  }
973
- static defaults(r) {
974
- return t.defaults(b(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, b(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, b(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, b(s, r)),
988
- escape: (n, r = {}) => t.escape(n, b(s, r)),
989
- filter: (n, r = {}) => t.filter(n, b(s, r)),
990
- defaults: (n) => t.defaults(b(s, n)),
991
- makeRe: (n, r = {}) => t.makeRe(n, b(s, r)),
992
- braceExpand: (n, r = {}) => t.braceExpand(n, b(s, r)),
993
- match: (n, r, i = {}) => t.match(n, r, b(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: O
1147
+ GLOBSTAR: S
996
1148
  });
997
1149
  };
998
- y.defaults = es;
999
- const Ft = (s, t = {}) => (q(s), t.nobrace || !/\{(?:(?!\{).)*\}/.test(s) ? [s] : ge(s));
1000
- y.braceExpand = Ft;
1001
- const ss = (s, t = {}) => new V(s, t).makeRe();
1002
- y.makeRe = ss;
1003
- const ns = (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 = ns;
1008
- const yt = /[?*]|[+@!]\(.*?\)|\[|\]/, rs = (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 || Rt, 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, a) => {
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 l = i[0] === "" && i[1] === "" && (i[2] === "?" || !yt.test(i[2])) && !yt.test(i[3]), h = /^[a-z]:/i.test(i[0]);
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
+ ];
1057
1217
  if (l)
1058
- return [...i.slice(0, 4), ...i.slice(4).map((c) => this.parse(c))];
1059
- if (h)
1060
- return [i[0], ...i.slice(1).map((c) => this.parse(c))];
1218
+ return [i[0], ...i.slice(1).map((h) => this.parse(h))];
1061
1219
  }
1062
- return i.map((l) => this.parse(l));
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 a = n[r + 1];
1153
- const l = n[r + 2], h = n[r + 3];
1154
- if (a !== ".." || !l || l === "." || l === ".." || !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 c = n.slice(0);
1158
- c[r] = "**", t.push(c), 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 a = n[o];
1163
- o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (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 l = i === 1 && n[i + 1] === "**" ? ["."] : [];
1173
- n.splice(i - 1, 2, ...l), 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 = [], a = "";
1200
- for (; r < t.length && i < e.length; )
1201
- if (t[r] === e[i])
1202
- o.push(a === "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] !== "**") {
1365
+ else if (t[n] === "*" && e[i] && (this.options.dot || !e[i].startsWith(".")) && e[i] !== "**") {
1208
1366
  if (a === "b")
1209
1367
  return !1;
1210
- a = "a", o.push(t[r]), r++, i++;
1211
- } else if (e[i] === "*" && t[r] && (this.options.dot || !t[r].startsWith(".")) && t[r] !== "**") {
1368
+ a = "a", o.push(t[n]), n++, i++;
1369
+ } else if (e[i] === "*" && t[n] && (this.options.dot || !t[n].startsWith(".")) && t[n] !== "**") {
1212
1370
  if (a === "a")
1213
1371
  return !1;
1214
- a = "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]), $ = !N && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, m = $ ? 3 : N ? 0 : void 0;
1237
- if (typeof x == "number" && typeof m == "number") {
1238
- const [k, L] = [t[x], e[m]];
1239
- k.toLowerCase() === L.toLowerCase() && (e[m] = k, m > x ? e = e.slice(m) : x > m && (t = t.slice(x)));
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, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
1245
- this.debug("matchOne loop");
1246
- var c = e[a], f = t[o];
1247
- if (this.debug(e, c, f), c === !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 (c === O) {
1250
- this.debug("GLOBSTAR", [e, c, f]);
1251
- var u = o, d = a + 1;
1252
- if (d === h) {
1253
- for (this.debug("** at the end"); o < l; o++)
1254
- if (t[o] === "." || t[o] === ".." || !r.dot && t[o].charAt(0) === ".")
1255
- return !1;
1256
- return !0;
1257
- }
1258
- for (; u < l; ) {
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, l, 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 === l));
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 c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, 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 === l && a === 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
1495
  if (o === l)
1279
- return n;
1280
- if (a === h)
1496
+ return r;
1497
+ if (a === c)
1281
1498
  return o === l - 1 && t[o] === "";
1282
1499
  throw new Error("wtf?");
1283
1500
  }
1284
1501
  braceExpand() {
1285
- return Ft(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 O;
1508
+ return S;
1292
1509
  if (t === "")
1293
1510
  return "";
1294
- let n, r = null;
1295
- (n = t.match(He)) ? r = e.dot ? Ue : je : (n = t.match(Pe)) ? r = (e.nocase ? e.dot ? Fe : Re : e.dot ? ke : $e)(n[1]) : (n = t.match(Be)) ? r = (e.nocase ? e.dot ? qe : Ge : e.dot ? Ve : Ye)(n) : (n = t.match(Ie)) ? r = e.dot ? Le : ze : (n = t.match(_e)) && (r = We);
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 ? Je : e.dot ? Qe : Ke, r = new Set(e.nocase ? ["i"] : []);
1306
- let i = t.map((l) => {
1307
- const h = l.map((c) => {
1308
- if (c instanceof RegExp)
1309
- for (const f of c.flags.split(""))
1310
- r.add(f);
1311
- return typeof c == "string" ? rs(c) : c === O ? O : c._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((c, f) => {
1314
- const u = h[f + 1], d = h[f - 1];
1315
- c !== O || d === O || (d === void 0 ? u !== void 0 && u !== O ? h[f + 1] = "(?:\\/|" + n + "\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\/|" + n + ")?" : u !== O && (h[f - 1] = d + "(?:\\/|\\/" + n + "\\/)" + u, h[f + 1] = O));
1316
- }), h.filter((c) => c !== O).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
1543
  const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1319
- i = "^" + o + i + a + "$", this.negate && (i = "^(?!" + i + ").+$");
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,38 +1559,45 @@ 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 a = r.length - 2; !o && a >= 0; a--)
1346
- o = r[a];
1347
- for (let a = 0; a < i.length; a++) {
1348
- const l = i[a];
1349
- let h = r;
1350
- if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, 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 = Ce;
1362
- y.unescape = I;
1363
- function is() {
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 Zt();
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}`;
1594
+ }
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();
1369
1601
  }
1370
1602
  function P(s) {
1371
1603
  return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
@@ -1377,63 +1609,59 @@ function st(s) {
1377
1609
  const t = P(s);
1378
1610
  return t[t.length - 1] || "";
1379
1611
  }
1380
- function J(s) {
1612
+ function Y(s) {
1381
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 os(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 as(s) {
1397
- const t = nt(s), e = P(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 cs(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 ls(s) {
1415
- const t = await s.arrayBuffer();
1416
- return new Uint8Array(t);
1417
- }
1418
- async function hs(s, t, e = {}) {
1419
- const n = st(t);
1420
- return z(t, async () => {
1421
- 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;
1422
1650
  try {
1423
- await s.removeEntry(n, { recursive: r });
1651
+ await s.removeEntry(r, { recursive: n });
1424
1652
  } catch (o) {
1425
1653
  if (o.name === "NotFoundError" && i)
1426
1654
  return;
1427
- const a = o.name === "TypeMismatchError" && !r;
1428
- throw D(o, {
1655
+ const a = o.name === "TypeMismatchError" && !n;
1656
+ throw A(o, {
1429
1657
  path: t,
1430
1658
  operation: "remove",
1431
1659
  isDirectory: a
1432
1660
  });
1433
1661
  }
1434
- });
1662
+ }, e.root ?? "/");
1435
1663
  }
1436
- class us {
1664
+ class bs {
1437
1665
  /** Root directory handle for the file system */
1438
1666
  root;
1439
1667
  /** Map of watched paths and options */
@@ -1462,12 +1690,12 @@ class us {
1462
1690
  if (!this.options.broadcastChannel)
1463
1691
  return;
1464
1692
  const e = t.path;
1465
- 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))))
1466
1694
  return;
1467
- let r;
1695
+ let n;
1468
1696
  if (this.options.hashAlgorithm)
1469
1697
  try {
1470
- r = (await this.stat(e)).hash;
1698
+ n = (await this.stat(e)).hash;
1471
1699
  } catch {
1472
1700
  }
1473
1701
  try {
@@ -1476,7 +1704,7 @@ class us {
1476
1704
  namespace: this.options.namespace,
1477
1705
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1478
1706
  ...t,
1479
- ...r && { hash: r }
1707
+ ...n && { hash: n }
1480
1708
  };
1481
1709
  this.broadcastChannel.postMessage(i);
1482
1710
  } catch (i) {
@@ -1484,7 +1712,11 @@ class us {
1484
1712
  }
1485
1713
  }
1486
1714
  constructor(t) {
1487
- is(), 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);
1488
1720
  }
1489
1721
  /**
1490
1722
  * Initialize the file system within a given directory.
@@ -1492,12 +1724,12 @@ class us {
1492
1724
  */
1493
1725
  async mount() {
1494
1726
  const t = this.options.root;
1495
- 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) => {
1496
1728
  try {
1497
- const r = await navigator.storage.getDirectory();
1498
- this.root = t === "/" ? r : await this.getDirectoryHandle(t, !0, r), e(!0);
1499
- } catch (r) {
1500
- n(new ee(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));
1501
1733
  } finally {
1502
1734
  this.mountingPromise = null;
1503
1735
  }
@@ -1514,7 +1746,7 @@ class us {
1514
1746
  * @param options.broadcastChannel - Custom name for the broadcast channel
1515
1747
  */
1516
1748
  async setOptions(t) {
1517
- 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());
1518
1750
  }
1519
1751
  /**
1520
1752
  * Get a directory handle from a path
@@ -1534,10 +1766,10 @@ class us {
1534
1766
  * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
1535
1767
  * ```
1536
1768
  */
1537
- async getDirectoryHandle(t, e = !1, n = this.root) {
1538
- const r = Array.isArray(t) ? t : P(t);
1539
- let i = n;
1540
- 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)
1541
1773
  i = await i.getDirectoryHandle(o, { create: e });
1542
1774
  return i;
1543
1775
  }
@@ -1560,12 +1792,12 @@ class us {
1560
1792
  * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
1561
1793
  * ```
1562
1794
  */
1563
- async getFileHandle(t, e = !1, n = this.root) {
1564
- const r = P(t);
1565
- if (r.length === 0)
1566
- throw new Xt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1567
- const i = r.pop();
1568
- 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 });
1569
1801
  }
1570
1802
  /**
1571
1803
  * Get a complete index of all files and directories in the file system
@@ -1587,10 +1819,10 @@ class us {
1587
1819
  * ```
1588
1820
  */
1589
1821
  async index() {
1590
- const t = /* @__PURE__ */ new Map(), e = async (n) => {
1591
- const r = await this.readDir(n);
1592
- for (const i of r) {
1593
- 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}`;
1594
1826
  try {
1595
1827
  const a = await this.stat(o);
1596
1828
  t.set(o, a), a.isDirectory && await e(o);
@@ -1631,20 +1863,20 @@ class us {
1631
1863
  */
1632
1864
  async mkdir(t, e) {
1633
1865
  await this.mount();
1634
- const n = e?.recursive ?? !1, r = P(t);
1866
+ const r = e?.recursive ?? !1, n = P(t);
1635
1867
  let i = this.root;
1636
- for (let o = 0; o < r.length; o++) {
1637
- const a = r[o];
1868
+ for (let o = 0; o < n.length; o++) {
1869
+ const a = n[o];
1638
1870
  try {
1639
- i = await i.getDirectoryHandle(a, { create: n || o === r.length - 1 });
1640
- } catch (l) {
1641
- throw l.name === "NotFoundError" ? D(l, {
1642
- 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)),
1643
1875
  existenceType: "directory"
1644
- }) : l.name === "TypeMismatchError" ? D(l, { path: a, isDirectory: !1 }) : new Z("create directory", a, l);
1876
+ }) : c.name === "TypeMismatchError" ? A(c, { path: a, isDirectory: !1 }) : new V("create directory", a, c);
1645
1877
  }
1646
1878
  }
1647
- await this.notifyChange({ path: t, type: A.Added, isDirectory: !0 });
1879
+ await this.notifyChange({ path: t, type: M.Added, isDirectory: !0 });
1648
1880
  }
1649
1881
  /**
1650
1882
  * Get file or directory statistics
@@ -1679,10 +1911,10 @@ class us {
1679
1911
  isDirectory: !0
1680
1912
  };
1681
1913
  const e = st(t);
1682
- let n;
1914
+ let r;
1683
1915
  try {
1684
- n = await this.getDirectoryHandle(J(t), !1);
1685
- const r = this.options.hashAlgorithm, o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
1916
+ r = await this.getDirectoryHandle(Y(t), !1);
1917
+ const n = this.options.hashAlgorithm, o = await (await r.getFileHandle(e, { create: !1 })).getFile(), a = {
1686
1918
  kind: "file",
1687
1919
  size: o.size,
1688
1920
  mtime: new Date(o.lastModified).toISOString(),
@@ -1690,24 +1922,24 @@ class us {
1690
1922
  isFile: !0,
1691
1923
  isDirectory: !1
1692
1924
  };
1693
- if (r === "etag")
1925
+ if (n === "etag")
1694
1926
  a.hash = `${o.lastModified.toString(36)}-${o.size.toString(36)}`;
1695
- else if (typeof r == "string")
1927
+ else if (typeof n == "string")
1696
1928
  try {
1697
- const l = await cs(o, r, this.options.maxFileSize);
1698
- a.hash = l;
1699
- } catch (l) {
1700
- console.warn(`Failed to calculate hash for ${t}:`, l);
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);
1701
1933
  }
1702
1934
  return a;
1703
- } catch (r) {
1704
- if (r.name === "NotFoundError")
1705
- throw new j("file", t, r);
1706
- if (r.name !== "TypeMismatchError")
1707
- throw new Z("stat", t, r);
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);
1708
1940
  }
1709
1941
  try {
1710
- return await n.getDirectoryHandle(e, { create: !1 }), {
1942
+ return await r.getDirectoryHandle(e, { create: !1 }), {
1711
1943
  kind: "directory",
1712
1944
  size: 0,
1713
1945
  mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
@@ -1715,8 +1947,8 @@ class us {
1715
1947
  isFile: !1,
1716
1948
  isDirectory: !0
1717
1949
  };
1718
- } catch (r) {
1719
- throw new Z("stat", t, r);
1950
+ } catch (n) {
1951
+ throw new V("stat", t, n);
1720
1952
  }
1721
1953
  }
1722
1954
  /**
@@ -1739,17 +1971,17 @@ class us {
1739
1971
  */
1740
1972
  async readDir(t) {
1741
1973
  await this.mount();
1742
- const e = await this.getDirectoryHandle(t, !1), n = [];
1743
- 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()) {
1744
1976
  const o = i.kind === "file";
1745
- n.push({
1746
- name: r,
1977
+ r.push({
1978
+ name: n,
1747
1979
  kind: i.kind,
1748
1980
  isFile: o,
1749
1981
  isDirectory: !o
1750
1982
  });
1751
1983
  }
1752
- return n;
1984
+ return r;
1753
1985
  }
1754
1986
  /**
1755
1987
  * Check if a file or directory exists
@@ -1769,22 +2001,22 @@ class us {
1769
2001
  if (await this.mount(), t === "/")
1770
2002
  return !0;
1771
2003
  const e = st(t);
1772
- let n = null;
2004
+ let r = null;
1773
2005
  try {
1774
- n = await this.getDirectoryHandle(J(t), !1);
1775
- } catch (r) {
1776
- if (n = null, r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1777
- 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;
1778
2010
  }
1779
- if (!n || !e)
2011
+ if (!r || !e)
1780
2012
  return !1;
1781
2013
  try {
1782
- return await n.getFileHandle(e, { create: !1 }), !0;
1783
- } catch (r) {
1784
- if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1785
- 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;
1786
2018
  try {
1787
- return await n.getDirectoryHandle(e, { create: !1 }), !0;
2019
+ return await r.getDirectoryHandle(e, { create: !1 }), !0;
1788
2020
  } catch (i) {
1789
2021
  if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1790
2022
  throw i;
@@ -1815,13 +2047,13 @@ class us {
1815
2047
  await this.mount();
1816
2048
  try {
1817
2049
  const e = await this.readDir(t);
1818
- for (const n of e) {
1819
- const r = `${t === "/" ? "" : t}/${n.name}`;
1820
- 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 });
1821
2053
  }
1822
- await this.notifyChange({ path: t, type: A.Changed, isDirectory: !0 });
2054
+ await this.notifyChange({ path: t, type: M.Changed, isDirectory: !0 });
1823
2055
  } catch (e) {
1824
- throw e instanceof w ? e : D(e, { path: t, isDirectory: !0 });
2056
+ throw e instanceof w ? e : A(e, { path: t, isDirectory: !0 });
1825
2057
  }
1826
2058
  }
1827
2059
  /**
@@ -1850,9 +2082,9 @@ class us {
1850
2082
  */
1851
2083
  async remove(t, e) {
1852
2084
  if (await this.mount(), t === "/")
1853
- throw new et("EROOT", t);
1854
- const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(J(t), !1), o = await this.stat(t);
1855
- 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 });
1856
2088
  }
1857
2089
  /**
1858
2090
  * Resolve a path to an absolute path
@@ -1875,12 +2107,12 @@ class us {
1875
2107
  async realpath(t) {
1876
2108
  await this.mount();
1877
2109
  try {
1878
- const e = as(t);
2110
+ const e = Lt(t);
1879
2111
  if (!await this.exists(e))
1880
- throw new j("file", e);
2112
+ throw new L("file", e);
1881
2113
  return e;
1882
2114
  } catch (e) {
1883
- throw e instanceof w ? e : D(e, { path: t });
2115
+ throw e instanceof w ? e : A(e, { path: t });
1884
2116
  }
1885
2117
  }
1886
2118
  /**
@@ -1905,15 +2137,15 @@ class us {
1905
2137
  * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
1906
2138
  * ```
1907
2139
  */
1908
- async rename(t, e, n) {
2140
+ async rename(t, e, r) {
1909
2141
  await this.mount();
1910
2142
  try {
1911
- const r = n?.overwrite ?? !1, i = await this.stat(t);
1912
- if (await this.exists(e) && !r)
2143
+ const n = r?.overwrite ?? !1, i = await this.stat(t);
2144
+ if (await this.exists(e) && !n)
1913
2145
  throw new ut(e);
1914
- 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 });
1915
- } catch (r) {
1916
- throw r instanceof w ? r : D(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 });
1917
2149
  }
1918
2150
  }
1919
2151
  /**
@@ -1941,29 +2173,29 @@ class us {
1941
2173
  * await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
1942
2174
  * ```
1943
2175
  */
1944
- async copy(t, e, n) {
2176
+ async copy(t, e, r) {
1945
2177
  await this.mount();
1946
2178
  try {
1947
- const r = n?.recursive ?? !1, i = n?.overwrite ?? !0;
2179
+ const n = r?.recursive ?? !1, i = r?.overwrite ?? !0;
1948
2180
  if (!await this.exists(t))
1949
- throw new j("source", t);
2181
+ throw new L("source", t);
1950
2182
  if (await this.exists(e) && !i)
1951
2183
  throw new ut(e);
1952
2184
  if ((await this.stat(t)).isFile) {
1953
- const h = await this.readFile(t);
1954
- await this.writeFile(e, h);
2185
+ const l = await this.readFile(t);
2186
+ await this.writeFile(e, l);
1955
2187
  } else {
1956
- if (!r)
1957
- throw new tt("directory", t);
2188
+ if (!n)
2189
+ throw new Q("directory", t);
1958
2190
  await this.mkdir(e, { recursive: !0 });
1959
- const h = await this.readDir(t);
1960
- for (const c of h) {
1961
- const f = `${t}/${c.name}`, u = `${e}/${c.name}`;
1962
- 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 });
1963
2195
  }
1964
2196
  }
1965
- } catch (r) {
1966
- throw r instanceof w ? r : D(r, { path: t });
2197
+ } catch (n) {
2198
+ throw n instanceof w ? n : A(n, { path: t });
1967
2199
  }
1968
2200
  }
1969
2201
  /**
@@ -1993,13 +2225,13 @@ class us {
1993
2225
  */
1994
2226
  async watch(t, e) {
1995
2227
  if (!this.options.broadcastChannel)
1996
- throw new v("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
1997
- const n = {
1998
- pattern: os(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),
1999
2231
  include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
2000
2232
  exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
2001
2233
  };
2002
- this.watchers.set(t, n);
2234
+ this.watchers.set(t, r);
2003
2235
  }
2004
2236
  /**
2005
2237
  * Stop watching a previously watched path
@@ -2008,32 +2240,90 @@ class us {
2008
2240
  this.watchers.delete(t);
2009
2241
  }
2010
2242
  /**
2011
- * Bulk-create files from `[path, data]` entries (strings, bytes, or Blobs).
2243
+ * Read a file as a `Blob` without copying its bytes into memory.
2244
+ *
2245
+ * OPFS hands back a disk-backed `File`, so the browser can stream it on
2246
+ * demand — pass it to `URL.createObjectURL()` for `<video>` / `<audio>` /
2247
+ * `<img>` and only the played range is actually read. Structured clone keeps
2248
+ * the reference intact when the file system runs in a worker.
2249
+ *
2250
+ * @param path - Path to the file
2251
+ * @returns Lazy `File` handle backed by OPFS storage
2252
+ * @throws {OPFSError} If the path is missing or is a directory
2253
+ *
2254
+ * @example
2255
+ * ```typescript
2256
+ * const blob = await fs.readBlob('/media/clip.mp4');
2257
+ * video.src = URL.createObjectURL(blob);
2258
+ * ```
2259
+ */
2260
+ async readBlob(t) {
2261
+ await this.mount();
2262
+ try {
2263
+ return await (await this.getFileHandle(t, !1)).getFile();
2264
+ } catch (e) {
2265
+ throw e instanceof w ? e : A(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2266
+ }
2267
+ }
2268
+ /**
2269
+ * Bulk-import files from `[path, data]` entries (strings, bytes, Blobs, or Files).
2270
+ * Each entry is written via {@link writeStream} so large Blobs/Files are not
2271
+ * fully buffered in memory.
2012
2272
  *
2013
- * @param entries - Array of `[path, data]` tuples
2273
+ * Accepts an array of tuples, a `Map`, or any iterable of `[path, data]` pairs.
2274
+ *
2275
+ * @param entries - Files to write
2276
+ * @param onProgress - Per-chunk progress with path, index, and byte counts
2277
+ * @returns Written paths, count, and total bytes
2014
2278
  * @throws {OPFSError} If a write fails
2015
2279
  *
2016
2280
  * @example
2017
2281
  * ```typescript
2018
- * await fs.createIndex([
2282
+ * const result = await fs.importFiles([
2019
2283
  * ['/config.json', JSON.stringify({ theme: 'dark' })],
2020
2284
  * ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],
2021
- * ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })],
2022
- * ]);
2285
+ * ['/upload.txt', fileFromInput],
2286
+ * ], (p) => console.log(`${p.path}: ${p.bytesWritten}/${p.bytesTotal}`));
2287
+ *
2288
+ * console.log(result.count, result.bytesWritten, result.paths);
2023
2289
  * ```
2024
2290
  */
2025
- async createIndex(t) {
2291
+ async importFiles(t, e) {
2026
2292
  await this.mount();
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;
2027
2295
  try {
2028
- for (const [e, n] of t) {
2029
- const r = nt(e);
2030
- let i;
2031
- n instanceof Blob ? i = await ls(n) : typeof n == "string" ? i = new TextEncoder().encode(n) : i = n, await this.writeFile(r, i);
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,
2307
+ totalBytes: o
2308
+ }) : void 0
2309
+ );
2310
+ a += g;
2032
2311
  }
2033
- } catch (e) {
2034
- throw e instanceof w ? e : D(e);
2312
+ return {
2313
+ paths: i,
2314
+ count: n,
2315
+ bytesWritten: a
2316
+ };
2317
+ } catch (c) {
2318
+ throw c instanceof w ? c : A(c);
2035
2319
  }
2036
2320
  }
2321
+ /**
2322
+ * @deprecated Use {@link importFiles} instead.
2323
+ */
2324
+ async createIndex(t) {
2325
+ Os(), await this.importFiles(t);
2326
+ }
2037
2327
  /**
2038
2328
  * Dispose of resources and clean up the file system instance
2039
2329
  */
@@ -2041,76 +2331,96 @@ class us {
2041
2331
  this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
2042
2332
  }
2043
2333
  }
2044
- const T = "file descriptors are not available in the async backend, use the dedicated worker backend (`createOPFSDedicated`) for positional I/O";
2045
- class fs extends us {
2334
+ function xs(s) {
2335
+ return typeof s == "string" ? new TextEncoder().encode(s).byteLength : s instanceof Blob ? s.size : s.byteLength;
2336
+ }
2337
+ function As(s) {
2338
+ if (s instanceof Blob)
2339
+ return { stream: s.stream(), size: s.size };
2340
+ const t = typeof s == "string" ? new TextEncoder().encode(s) : s;
2341
+ return {
2342
+ size: t.byteLength,
2343
+ stream: new ReadableStream({
2344
+ start(e) {
2345
+ e.enqueue(t), e.close();
2346
+ }
2347
+ })
2348
+ };
2349
+ }
2350
+ let St = !1;
2351
+ function Os() {
2352
+ St || (St = !0, console.warn("[opfs-worker] createIndex() is deprecated; use importFiles() instead"));
2353
+ }
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 {
2046
2356
  async readFile(t) {
2047
2357
  await this.mount();
2048
2358
  try {
2049
- return await z(t, async () => {
2050
- const n = await (await this.getFileHandle(t, !1)).getFile(), r = new Uint8Array(await n.arrayBuffer());
2051
- return At(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]);
2052
2362
  });
2053
2363
  } catch (e) {
2054
- throw e instanceof w ? e : D(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2364
+ throw e instanceof w ? e : A(e, { path: t, isDirectory: e?.name === "TypeMismatchError" });
2055
2365
  }
2056
2366
  }
2057
2367
  async writeFile(t, e) {
2058
2368
  await this.mount();
2059
- const n = e instanceof Uint8Array ? e : new Uint8Array(e);
2369
+ const r = e instanceof Uint8Array ? e : new Uint8Array(e);
2060
2370
  try {
2061
- await z(t, async () => {
2062
- const r = await this.exists(t), i = await this.getFileHandle(t, !0);
2063
- 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 });
2064
2374
  });
2065
- } catch (r) {
2066
- throw r instanceof w ? r : D(r, { path: t, isDirectory: r?.name === "TypeMismatchError" });
2375
+ } catch (n) {
2376
+ throw n instanceof w ? n : A(n, { path: t, isDirectory: n?.name === "TypeMismatchError" });
2067
2377
  }
2068
2378
  }
2069
2379
  async appendFile(t, e) {
2070
2380
  await this.mount();
2071
- const n = e instanceof Uint8Array ? e : new Uint8Array(e);
2381
+ const r = e instanceof Uint8Array ? e : new Uint8Array(e);
2072
2382
  try {
2073
- await z(t, async () => {
2074
- 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();
2075
2385
  await this._writeStream(
2076
- r,
2077
- async (o) => o.write({ type: "write", position: i, data: n }),
2386
+ n,
2387
+ async (o) => o.write({ type: "write", position: i, data: r }),
2078
2388
  { keepExistingData: !0 }
2079
- ), await this.notifyChange({ path: t, type: A.Changed, isDirectory: !1 });
2389
+ ), await this.notifyChange({ path: t, type: M.Changed, isDirectory: !1 });
2080
2390
  });
2081
- } catch (r) {
2082
- throw r instanceof w ? r : D(r, { path: t, isDirectory: r?.name === "TypeMismatchError" });
2391
+ } catch (n) {
2392
+ throw n instanceof w ? n : A(n, { path: t, isDirectory: n?.name === "TypeMismatchError" });
2083
2393
  }
2084
2394
  }
2085
- async writeStream(t, e, n) {
2395
+ async writeStream(t, e, r) {
2086
2396
  await this.mount();
2087
2397
  try {
2088
- return await z(t, async () => {
2089
- const r = await this.exists(t), i = await this.getFileHandle(t, !0), o = e.getReader();
2398
+ return await this.withPathLock(t, async () => {
2399
+ const n = await this.exists(t), i = await this.getFileHandle(t, !0), o = e.getReader();
2090
2400
  let a = 0;
2091
2401
  try {
2092
- await this._writeStream(i, async (l) => {
2402
+ await this._writeStream(i, async (c) => {
2093
2403
  for (; ; ) {
2094
- const { done: h, value: c } = await o.read();
2095
- if (h)
2404
+ const { done: l, value: h } = await o.read();
2405
+ if (l)
2096
2406
  break;
2097
- await l.write(c), a += c.byteLength, await n?.(a);
2407
+ await c.write(h), a += h.byteLength, await r?.(a);
2098
2408
  }
2099
2409
  });
2100
- } catch (l) {
2101
- throw await o.cancel(l).catch(() => {
2102
- }), l;
2410
+ } catch (c) {
2411
+ throw await o.cancel(c).catch(() => {
2412
+ }), c;
2103
2413
  } finally {
2104
2414
  o.releaseLock();
2105
2415
  }
2106
2416
  return await this.notifyChange({
2107
2417
  path: t,
2108
- type: r ? A.Changed : A.Added,
2418
+ type: n ? M.Changed : M.Added,
2109
2419
  isDirectory: !1
2110
2420
  }), a;
2111
2421
  });
2112
- } catch (r) {
2113
- throw r instanceof w ? r : D(r, { path: t, isDirectory: r?.name === "TypeMismatchError" });
2422
+ } catch (n) {
2423
+ throw n instanceof w ? n : A(n, { path: t, isDirectory: n?.name === "TypeMismatchError" });
2114
2424
  }
2115
2425
  }
2116
2426
  /**
@@ -2118,49 +2428,49 @@ class fs extends us {
2118
2428
  * Aborts the stream (discarding the swap file) if the callback fails.
2119
2429
  * @private
2120
2430
  */
2121
- async _writeStream(t, e, n) {
2431
+ async _writeStream(t, e, r) {
2122
2432
  if (typeof t.createWritable != "function")
2123
- throw new v("createWritable() is not available in this browser (Safari supports it since version 26), use the dedicated worker backend (`createOPFSDedicated`) instead");
2124
- 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);
2125
2435
  try {
2126
- await e(r);
2436
+ await e(n);
2127
2437
  } catch (i) {
2128
- throw await r.abort().catch(() => {
2438
+ throw await n.abort().catch(() => {
2129
2439
  }), i;
2130
2440
  }
2131
- await r.close();
2441
+ await n.close();
2132
2442
  }
2133
2443
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2134
2444
  async open(t, e) {
2135
- throw new v(T);
2445
+ throw new T(N);
2136
2446
  }
2137
2447
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2138
2448
  async close(t) {
2139
- throw new v(T);
2449
+ throw new T(N);
2140
2450
  }
2141
2451
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2142
- async read(t, e, n, r, i) {
2143
- throw new v(T);
2452
+ async read(t, e, r, n, i) {
2453
+ throw new T(N);
2144
2454
  }
2145
2455
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2146
- async write(t, e, n, r, i, o) {
2147
- throw new v(T);
2456
+ async write(t, e, r, n, i, o) {
2457
+ throw new T(N);
2148
2458
  }
2149
2459
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2150
2460
  async fstat(t) {
2151
- throw new v(T);
2461
+ throw new T(N);
2152
2462
  }
2153
2463
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2154
2464
  async ftruncate(t, e) {
2155
- throw new v(T);
2465
+ throw new T(N);
2156
2466
  }
2157
2467
  /** @throws {OperationNotSupportedError} Always — no FD support in the async backend */
2158
2468
  async fsync(t) {
2159
- throw new v(T);
2469
+ throw new T(N);
2160
2470
  }
2161
2471
  }
2162
- const ds = new fs();
2472
+ const Ts = new Ms();
2163
2473
  globalThis.onconnect = (s) => {
2164
- rt(ds, s.ports[0]);
2474
+ nt(Ts, s.ports[0]);
2165
2475
  };
2166
2476
  //# sourceMappingURL=shared.worker.js.map