opfs-worker 2.1.1 → 2.1.2

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