opfs-worker 2.1.0 → 2.1.2

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