opfs-worker 0.3.2 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,427 +1,1389 @@
1
1
  import { wrap as i } from "comlink";
2
- import { D as d, F as f, O as p, b as u, a as y, P as m, c as w, S as g, T as v, e as b, k as E, d as S, l as F, h as P, o as x, f as D, m as C, g as T, j as A, n as O, i as _, r as I, s as U, w as R } from "./helpers-DxFcNkZe.js";
3
- const a = `/**
2
+ import { D as p, F as f, O as d, b as u, a as g, P as m, c as w, S as y, T as b, e as v, l as S, d as E, m as x, h as P, p as A, f as F, o as O, g as C, i as T, j as _, n as D, k as R, r as $, s as I, w as M } from "./helpers-BgMlBRWa.js";
3
+ const r = `/**
4
4
  * @license
5
5
  * Copyright 2019 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), C = Symbol("Comlink.finalizer"), p = Symbol("Comlink.thrown"), $ = (e) => typeof e == "object" && e !== null || typeof e == "function", W = {
9
- canHandle: (e) => $(e) && e[H],
10
- serialize(e) {
11
- const { port1: t, port2: r } = new MessageChannel();
12
- return x(e, t), [r, [r]];
8
+ const ut = Symbol("Comlink.proxy"), Tt = Symbol("Comlink.endpoint"), Ft = Symbol("Comlink.releaseProxy"), B = Symbol("Comlink.finalizer"), z = Symbol("Comlink.thrown"), ft = (s) => typeof s == "object" && s !== null || typeof s == "function", Nt = {
9
+ canHandle: (s) => ft(s) && s[ut],
10
+ serialize(s) {
11
+ const { port1: t, port2: e } = new MessageChannel();
12
+ return J(s, t), [e, [e]];
13
13
  },
14
- deserialize(e) {
15
- return e.start(), Y(e);
14
+ deserialize(s) {
15
+ return s.start(), $t(s);
16
16
  }
17
- }, j = {
18
- canHandle: (e) => $(e) && p in e,
19
- serialize({ value: e }) {
17
+ }, Pt = {
18
+ canHandle: (s) => ft(s) && z in s,
19
+ serialize({ value: s }) {
20
20
  let t;
21
- return e instanceof Error ? t = {
21
+ return s instanceof Error ? t = {
22
22
  isError: !0,
23
23
  value: {
24
- message: e.message,
25
- name: e.name,
26
- stack: e.stack
24
+ message: s.message,
25
+ name: s.name,
26
+ stack: s.stack
27
27
  }
28
- } : t = { isError: !1, value: e }, [t, []];
28
+ } : t = { isError: !1, value: s }, [t, []];
29
29
  },
30
- deserialize(e) {
31
- throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
30
+ deserialize(s) {
31
+ throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
32
32
  }
33
- }, z = /* @__PURE__ */ new Map([
34
- ["proxy", W],
35
- ["throw", j]
33
+ }, dt = /* @__PURE__ */ new Map([
34
+ ["proxy", Nt],
35
+ ["throw", Pt]
36
36
  ]);
37
- function V(e, t) {
38
- for (const r of e)
39
- if (t === r || r === "*" || r instanceof RegExp && r.test(t))
37
+ function vt(s, t) {
38
+ for (const e of s)
39
+ if (t === e || e === "*" || e instanceof RegExp && e.test(t))
40
40
  return !0;
41
41
  return !1;
42
42
  }
43
- function x(e, t = globalThis, r = ["*"]) {
44
- t.addEventListener("message", function i(n) {
45
- if (!n || !n.data)
43
+ function J(s, t = globalThis, e = ["*"]) {
44
+ t.addEventListener("message", function n(i) {
45
+ if (!i || !i.data)
46
46
  return;
47
- if (!V(r, n.origin)) {
48
- console.warn(\`Invalid origin '\${n.origin}' for comlink proxy\`);
47
+ if (!vt(e, i.origin)) {
48
+ console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
49
49
  return;
50
50
  }
51
- const { id: a, type: s, path: o } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(d);
52
- let h;
51
+ const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), c = (i.data.argumentList || []).map(C);
52
+ let l;
53
53
  try {
54
- const u = o.slice(0, -1).reduce((f, g) => f[g], e), w = o.reduce((f, g) => f[g], e);
55
- switch (s) {
54
+ const h = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
55
+ switch (o) {
56
56
  case "GET":
57
- h = w;
57
+ l = f;
58
58
  break;
59
59
  case "SET":
60
- u[o.slice(-1)[0]] = d(n.data.value), h = !0;
60
+ h[a.slice(-1)[0]] = C(i.data.value), l = !0;
61
61
  break;
62
62
  case "APPLY":
63
- h = w.apply(u, l);
63
+ l = f.apply(h, c);
64
64
  break;
65
65
  case "CONSTRUCT":
66
66
  {
67
- const f = new w(...l);
68
- h = Q(f);
67
+ const u = new f(...c);
68
+ l = zt(u);
69
69
  }
70
70
  break;
71
71
  case "ENDPOINT":
72
72
  {
73
- const { port1: f, port2: g } = new MessageChannel();
74
- x(e, g), h = J(f, [f]);
73
+ const { port1: u, port2: d } = new MessageChannel();
74
+ J(s, d), l = Lt(u, [u]);
75
75
  }
76
76
  break;
77
77
  case "RELEASE":
78
- h = void 0;
78
+ l = void 0;
79
79
  break;
80
80
  default:
81
81
  return;
82
82
  }
83
- } catch (u) {
84
- h = { value: u, [p]: 0 };
83
+ } catch (h) {
84
+ l = { value: h, [z]: 0 };
85
85
  }
86
- Promise.resolve(h).catch((u) => ({ value: u, [p]: 0 })).then((u) => {
87
- const [w, f] = A(u);
88
- t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f), s === "RELEASE" && (t.removeEventListener("message", i), L(t), C in e && typeof e[C] == "function" && e[C]());
89
- }).catch((u) => {
90
- const [w, f] = A({
86
+ Promise.resolve(l).catch((h) => ({ value: h, [z]: 0 })).then((h) => {
87
+ const [f, u] = j(h);
88
+ t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), pt(t), B in s && typeof s[B] == "function" && s[B]());
89
+ }).catch((h) => {
90
+ const [f, u] = j({
91
91
  value: new TypeError("Unserializable return value"),
92
- [p]: 0
92
+ [z]: 0
93
93
  });
94
- t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f);
94
+ t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
95
95
  });
96
96
  }), t.start && t.start();
97
97
  }
98
- function G(e) {
99
- return e.constructor.name === "MessagePort";
98
+ function Mt(s) {
99
+ return s.constructor.name === "MessagePort";
100
100
  }
101
- function L(e) {
102
- G(e) && e.close();
101
+ function pt(s) {
102
+ Mt(s) && s.close();
103
103
  }
104
- function Y(e, t) {
105
- const r = /* @__PURE__ */ new Map();
106
- return e.addEventListener("message", function(n) {
107
- const { data: a } = n;
108
- if (!a || !a.id)
104
+ function $t(s, t) {
105
+ const e = /* @__PURE__ */ new Map();
106
+ return s.addEventListener("message", function(i) {
107
+ const { data: r } = i;
108
+ if (!r || !r.id)
109
109
  return;
110
- const s = r.get(a.id);
111
- if (s)
110
+ const o = e.get(r.id);
111
+ if (o)
112
112
  try {
113
- s(a);
113
+ o(r);
114
114
  } finally {
115
- r.delete(a.id);
115
+ e.delete(r.id);
116
116
  }
117
- }), M(e, r, [], t);
117
+ }), Y(s, e, [], t);
118
118
  }
119
- function E(e) {
120
- if (e)
119
+ function I(s) {
120
+ if (s)
121
121
  throw new Error("Proxy has been released and is not useable");
122
122
  }
123
- function U(e) {
124
- return y(e, /* @__PURE__ */ new Map(), {
123
+ function gt(s) {
124
+ return O(s, /* @__PURE__ */ new Map(), {
125
125
  type: "RELEASE"
126
126
  }).then(() => {
127
- L(e);
127
+ pt(s);
128
128
  });
129
129
  }
130
- const S = /* @__PURE__ */ new WeakMap(), D = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
131
- const t = (S.get(e) || 0) - 1;
132
- S.set(e, t), t === 0 && U(e);
130
+ const W = /* @__PURE__ */ new WeakMap(), H = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
131
+ const t = (W.get(s) || 0) - 1;
132
+ W.set(s, t), t === 0 && gt(s);
133
133
  });
134
- function X(e, t) {
135
- const r = (S.get(t) || 0) + 1;
136
- S.set(t, r), D && D.register(e, t, e);
134
+ function Rt(s, t) {
135
+ const e = (W.get(t) || 0) + 1;
136
+ W.set(t, e), H && H.register(s, t, s);
137
137
  }
138
- function q(e) {
139
- D && D.unregister(e);
138
+ function It(s) {
139
+ H && H.unregister(s);
140
140
  }
141
- function M(e, t, r = [], i = function() {
141
+ function Y(s, t, e = [], n = function() {
142
142
  }) {
143
- let n = !1;
144
- const a = new Proxy(i, {
145
- get(s, o) {
146
- if (E(n), o === B)
143
+ let i = !1;
144
+ const r = new Proxy(n, {
145
+ get(o, a) {
146
+ if (I(i), a === Ft)
147
147
  return () => {
148
- q(a), U(e), t.clear(), n = !0;
148
+ It(r), gt(s), t.clear(), i = !0;
149
149
  };
150
- if (o === "then") {
151
- if (r.length === 0)
152
- return { then: () => a };
153
- const l = y(e, t, {
150
+ if (a === "then") {
151
+ if (e.length === 0)
152
+ return { then: () => r };
153
+ const c = O(s, t, {
154
154
  type: "GET",
155
- path: r.map((h) => h.toString())
156
- }).then(d);
157
- return l.then.bind(l);
155
+ path: e.map((l) => l.toString())
156
+ }).then(C);
157
+ return c.then.bind(c);
158
158
  }
159
- return M(e, t, [...r, o]);
159
+ return Y(s, t, [...e, a]);
160
160
  },
161
- set(s, o, l) {
162
- E(n);
163
- const [h, u] = A(l);
164
- return y(e, t, {
161
+ set(o, a, c) {
162
+ I(i);
163
+ const [l, h] = j(c);
164
+ return O(s, t, {
165
165
  type: "SET",
166
- path: [...r, o].map((w) => w.toString()),
167
- value: h
168
- }, u).then(d);
166
+ path: [...e, a].map((f) => f.toString()),
167
+ value: l
168
+ }, h).then(C);
169
169
  },
170
- apply(s, o, l) {
171
- E(n);
172
- const h = r[r.length - 1];
173
- if (h === R)
174
- return y(e, t, {
170
+ apply(o, a, c) {
171
+ I(i);
172
+ const l = e[e.length - 1];
173
+ if (l === Tt)
174
+ return O(s, t, {
175
175
  type: "ENDPOINT"
176
- }).then(d);
177
- if (h === "bind")
178
- return M(e, t, r.slice(0, -1));
179
- const [u, w] = v(l);
180
- return y(e, t, {
176
+ }).then(C);
177
+ if (l === "bind")
178
+ return Y(s, t, e.slice(0, -1));
179
+ const [h, f] = et(c);
180
+ return O(s, t, {
181
181
  type: "APPLY",
182
- path: r.map((f) => f.toString()),
183
- argumentList: u
184
- }, w).then(d);
182
+ path: e.map((u) => u.toString()),
183
+ argumentList: h
184
+ }, f).then(C);
185
185
  },
186
- construct(s, o) {
187
- E(n);
188
- const [l, h] = v(o);
189
- return y(e, t, {
186
+ construct(o, a) {
187
+ I(i);
188
+ const [c, l] = et(a);
189
+ return O(s, t, {
190
190
  type: "CONSTRUCT",
191
- path: r.map((u) => u.toString()),
192
- argumentList: l
193
- }, h).then(d);
191
+ path: e.map((h) => h.toString()),
192
+ argumentList: c
193
+ }, l).then(C);
194
194
  }
195
195
  });
196
- return X(a, e), a;
196
+ return Rt(r, s), r;
197
197
  }
198
- function K(e) {
199
- return Array.prototype.concat.apply([], e);
198
+ function kt(s) {
199
+ return Array.prototype.concat.apply([], s);
200
200
  }
201
- function v(e) {
202
- const t = e.map(A);
203
- return [t.map((r) => r[0]), K(t.map((r) => r[1]))];
201
+ function et(s) {
202
+ const t = s.map(j);
203
+ return [t.map((e) => e[0]), kt(t.map((e) => e[1]))];
204
204
  }
205
- const _ = /* @__PURE__ */ new WeakMap();
206
- function J(e, t) {
207
- return _.set(e, t), e;
205
+ const wt = /* @__PURE__ */ new WeakMap();
206
+ function Lt(s, t) {
207
+ return wt.set(s, t), s;
208
208
  }
209
- function Q(e) {
210
- return Object.assign(e, { [H]: !0 });
209
+ function zt(s) {
210
+ return Object.assign(s, { [ut]: !0 });
211
211
  }
212
- function A(e) {
213
- for (const [t, r] of z)
214
- if (r.canHandle(e)) {
215
- const [i, n] = r.serialize(e);
212
+ function j(s) {
213
+ for (const [t, e] of dt)
214
+ if (e.canHandle(s)) {
215
+ const [n, i] = e.serialize(s);
216
216
  return [
217
217
  {
218
218
  type: "HANDLER",
219
219
  name: t,
220
- value: i
220
+ value: n
221
221
  },
222
- n
222
+ i
223
223
  ];
224
224
  }
225
225
  return [
226
226
  {
227
227
  type: "RAW",
228
- value: e
228
+ value: s
229
229
  },
230
- _.get(e) || []
230
+ wt.get(s) || []
231
231
  ];
232
232
  }
233
- function d(e) {
234
- switch (e.type) {
233
+ function C(s) {
234
+ switch (s.type) {
235
235
  case "HANDLER":
236
- return z.get(e.name).deserialize(e.value);
236
+ return dt.get(s.name).deserialize(s.value);
237
237
  case "RAW":
238
- return e.value;
238
+ return s.value;
239
239
  }
240
240
  }
241
- function y(e, t, r, i) {
242
- return new Promise((n) => {
243
- const a = Z();
244
- t.set(a, n), e.start && e.start(), e.postMessage(Object.assign({ id: a }, r), i);
241
+ function O(s, t, e, n) {
242
+ return new Promise((i) => {
243
+ const r = Wt();
244
+ t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
245
245
  });
246
246
  }
247
- function Z() {
247
+ function Wt() {
248
248
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
249
249
  }
250
- class c extends Error {
251
- constructor(t, r, i) {
252
- super(t), this.code = r, this.path = i, this.name = "OPFSError";
250
+ const mt = (s, t, e) => {
251
+ const n = s instanceof RegExp ? st(s, e) : s, i = t instanceof RegExp ? st(t, e) : t, r = n !== null && i != null && Ht(n, i, e);
252
+ return r && {
253
+ start: r[0],
254
+ end: r[1],
255
+ pre: e.slice(0, r[0]),
256
+ body: e.slice(r[0] + n.length, r[1]),
257
+ post: e.slice(r[1] + i.length)
258
+ };
259
+ }, st = (s, t) => {
260
+ const e = t.match(s);
261
+ return e ? e[0] : null;
262
+ }, Ht = (s, t, e) => {
263
+ let n, i, r, o, a, c = e.indexOf(s), l = e.indexOf(t, c + 1), h = c;
264
+ if (c >= 0 && l > 0) {
265
+ if (s === t)
266
+ return [c, l];
267
+ for (n = [], r = e.length; h >= 0 && !a; ) {
268
+ if (h === c)
269
+ n.push(h), c = e.indexOf(s, h + 1);
270
+ else if (n.length === 1) {
271
+ const f = n.pop();
272
+ f !== void 0 && (a = [f, l]);
273
+ } else
274
+ i = n.pop(), i !== void 0 && i < r && (r = i, o = l), l = e.indexOf(t, h + 1);
275
+ h = c < l && c >= 0 ? c : l;
276
+ }
277
+ n.length && o !== void 0 && (a = [r, o]);
278
+ }
279
+ return a;
280
+ }, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0", xt = "\\0PERIOD" + Math.random() + "\\0", jt = new RegExp(yt, "g"), Ut = new RegExp(Et, "g"), _t = new RegExp(K, "g"), Bt = new RegExp(St, "g"), Gt = new RegExp(xt, "g"), qt = /\\\\\\\\/g, Vt = /\\\\{/g, Zt = /\\\\}/g, Xt = /\\\\,/g, Yt = /\\\\./g;
281
+ function G(s) {
282
+ return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
283
+ }
284
+ function Jt(s) {
285
+ return s.replace(qt, yt).replace(Vt, Et).replace(Zt, K).replace(Xt, St).replace(Yt, xt);
286
+ }
287
+ function Kt(s) {
288
+ return s.replace(jt, "\\\\").replace(Ut, "{").replace(_t, "}").replace(Bt, ",").replace(Gt, ".");
289
+ }
290
+ function bt(s) {
291
+ if (!s)
292
+ return [""];
293
+ const t = [], e = mt("{", "}", s);
294
+ if (!e)
295
+ return s.split(",");
296
+ const { pre: n, body: i, post: r } = e, o = n.split(",");
297
+ o[o.length - 1] += "{" + i + "}";
298
+ const a = bt(r);
299
+ return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
300
+ }
301
+ function Qt(s) {
302
+ return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(Jt(s), !0).map(Kt)) : [];
303
+ }
304
+ function te(s) {
305
+ return "{" + s + "}";
306
+ }
307
+ function ee(s) {
308
+ return /^-?0\\d/.test(s);
309
+ }
310
+ function se(s, t) {
311
+ return s <= t;
312
+ }
313
+ function ne(s, t) {
314
+ return s >= t;
315
+ }
316
+ function M(s, t) {
317
+ const e = [], n = mt("{", "}", s);
318
+ if (!n)
319
+ return [s];
320
+ const i = n.pre, r = n.post.length ? M(n.post, !1) : [""];
321
+ if (/\\$$/.test(n.pre))
322
+ for (let o = 0; o < r.length; o++) {
323
+ const a = i + "{" + n.body + "}" + r[o];
324
+ e.push(a);
325
+ }
326
+ else {
327
+ const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), c = o || a, l = n.body.indexOf(",") >= 0;
328
+ if (!c && !l)
329
+ return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + K + n.post, M(s)) : [s];
330
+ let h;
331
+ if (c)
332
+ h = n.body.split(/\\.\\./);
333
+ else if (h = bt(n.body), h.length === 1 && h[0] !== void 0 && (h = M(h[0], !1).map(te), h.length === 1))
334
+ return r.map((u) => n.pre + h[0] + u);
335
+ let f;
336
+ if (c && h[0] !== void 0 && h[1] !== void 0) {
337
+ const u = G(h[0]), d = G(h[1]), w = Math.max(h[0].length, h[1].length);
338
+ let p = h.length === 3 && h[2] !== void 0 ? Math.abs(G(h[2])) : 1, S = se;
339
+ d < u && (p *= -1, S = ne);
340
+ const N = h.some(ee);
341
+ f = [];
342
+ for (let x = u; S(x, d); x += p) {
343
+ let m;
344
+ if (a)
345
+ m = String.fromCharCode(x), m === "\\\\" && (m = "");
346
+ else if (m = String(x), N) {
347
+ const P = w - m.length;
348
+ if (P > 0) {
349
+ const R = new Array(P + 1).join("0");
350
+ x < 0 ? m = "-" + R + m.slice(1) : m = R + m;
351
+ }
352
+ }
353
+ f.push(m);
354
+ }
355
+ } else {
356
+ f = [];
357
+ for (let u = 0; u < h.length; u++)
358
+ f.push.apply(f, M(h[u], !1));
359
+ }
360
+ for (let u = 0; u < f.length; u++)
361
+ for (let d = 0; d < r.length; d++) {
362
+ const w = i + f[u] + r[d];
363
+ (!t || c || w) && e.push(w);
364
+ }
365
+ }
366
+ return e;
367
+ }
368
+ const ie = 1024 * 64, U = (s) => {
369
+ if (typeof s != "string")
370
+ throw new TypeError("invalid pattern");
371
+ if (s.length > ie)
372
+ throw new TypeError("pattern is too long");
373
+ }, re = {
374
+ "[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
375
+ "[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
376
+ "[:ascii:]": ["\\\\x00-\\\\x7f", !1],
377
+ "[:blank:]": ["\\\\p{Zs}\\\\t", !0],
378
+ "[:cntrl:]": ["\\\\p{Cc}", !0],
379
+ "[:digit:]": ["\\\\p{Nd}", !0],
380
+ "[:graph:]": ["\\\\p{Z}\\\\p{C}", !0, !0],
381
+ "[:lower:]": ["\\\\p{Ll}", !0],
382
+ "[:print:]": ["\\\\p{C}", !0],
383
+ "[:punct:]": ["\\\\p{P}", !0],
384
+ "[:space:]": ["\\\\p{Z}\\\\t\\\\r\\\\n\\\\v\\\\f", !0],
385
+ "[:upper:]": ["\\\\p{Lu}", !0],
386
+ "[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
387
+ "[:xdigit:]": ["A-Fa-f0-9", !1]
388
+ }, v = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), oe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), nt = (s) => s.join(""), ae = (s, t) => {
389
+ const e = t;
390
+ if (s.charAt(e) !== "[")
391
+ throw new Error("not in a brace expression");
392
+ const n = [], i = [];
393
+ let r = e + 1, o = !1, a = !1, c = !1, l = !1, h = e, f = "";
394
+ t: for (; r < s.length; ) {
395
+ const p = s.charAt(r);
396
+ if ((p === "!" || p === "^") && r === e + 1) {
397
+ l = !0, r++;
398
+ continue;
399
+ }
400
+ if (p === "]" && o && !c) {
401
+ h = r + 1;
402
+ break;
403
+ }
404
+ if (o = !0, p === "\\\\" && !c) {
405
+ c = !0, r++;
406
+ continue;
407
+ }
408
+ if (p === "[" && !c) {
409
+ for (const [S, [D, N, x]] of Object.entries(re))
410
+ if (s.startsWith(S, r)) {
411
+ if (f)
412
+ return ["$.", !1, s.length - e, !0];
413
+ r += S.length, x ? i.push(D) : n.push(D), a = a || N;
414
+ continue t;
415
+ }
416
+ }
417
+ if (c = !1, f) {
418
+ p > f ? n.push(v(f) + "-" + v(p)) : p === f && n.push(v(p)), f = "", r++;
419
+ continue;
420
+ }
421
+ if (s.startsWith("-]", r + 1)) {
422
+ n.push(v(p + "-")), r += 2;
423
+ continue;
424
+ }
425
+ if (s.startsWith("-", r + 1)) {
426
+ f = p, r += 2;
427
+ continue;
428
+ }
429
+ n.push(v(p)), r++;
430
+ }
431
+ if (h < r)
432
+ return ["", !1, 0, !1];
433
+ if (!n.length && !i.length)
434
+ return ["$.", !1, s.length - e, !0];
435
+ if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !l) {
436
+ const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
437
+ return [oe(p), !1, h - e, !1];
438
+ }
439
+ const u = "[" + (l ? "^" : "") + nt(n) + "]", d = "[" + (l ? "" : "^") + nt(i) + "]";
440
+ return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, h - e, !0];
441
+ }, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), ce = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), it = (s) => ce.has(s), he = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", le = /* @__PURE__ */ new Set(["[", "."]), ue = /* @__PURE__ */ new Set(["..", "."]), fe = new Set("().*{}+?[]^$\\\\!"), de = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), Q = "[^/]", rt = Q + "*?", ot = Q + "+?";
442
+ class E {
443
+ type;
444
+ #s;
445
+ #n;
446
+ #r = !1;
447
+ #t = [];
448
+ #e;
449
+ #o;
450
+ #c;
451
+ #a = !1;
452
+ #i;
453
+ #h;
454
+ // set to true if it's an extglob with no children
455
+ // (which really means one child of '')
456
+ #u = !1;
457
+ constructor(t, e, n = {}) {
458
+ this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#i = this.#s === this ? n : this.#s.#i, 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;
459
+ }
460
+ get hasMagic() {
461
+ if (this.#n !== void 0)
462
+ return this.#n;
463
+ for (const t of this.#t)
464
+ if (typeof t != "string" && (t.type || t.hasMagic))
465
+ return this.#n = !0;
466
+ return this.#n;
467
+ }
468
+ // reconstructs the pattern
469
+ toString() {
470
+ return this.#h !== void 0 ? this.#h : this.type ? this.#h = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#h = this.#t.map((t) => String(t)).join("");
471
+ }
472
+ #d() {
473
+ if (this !== this.#s)
474
+ throw new Error("should only call on root");
475
+ if (this.#a)
476
+ return this;
477
+ this.toString(), this.#a = !0;
478
+ let t;
479
+ for (; t = this.#c.pop(); ) {
480
+ if (t.type !== "!")
481
+ continue;
482
+ let e = t, n = e.#e;
483
+ for (; n; ) {
484
+ for (let i = e.#o + 1; !n.type && i < n.#t.length; i++)
485
+ for (const r of t.#t) {
486
+ if (typeof r == "string")
487
+ throw new Error("string part in extglob AST??");
488
+ r.copyIn(n.#t[i]);
489
+ }
490
+ e = n, n = e.#e;
491
+ }
492
+ }
493
+ return this;
494
+ }
495
+ push(...t) {
496
+ for (const e of t)
497
+ if (e !== "") {
498
+ if (typeof e != "string" && !(e instanceof E && e.#e === this))
499
+ throw new Error("invalid part: " + e);
500
+ this.#t.push(e);
501
+ }
502
+ }
503
+ toJSON() {
504
+ const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
505
+ return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
506
+ }
507
+ isStart() {
508
+ if (this.#s === this)
509
+ return !0;
510
+ if (!this.#e?.isStart())
511
+ return !1;
512
+ if (this.#o === 0)
513
+ return !0;
514
+ const t = this.#e;
515
+ for (let e = 0; e < this.#o; e++) {
516
+ const n = t.#t[e];
517
+ if (!(n instanceof E && n.type === "!"))
518
+ return !1;
519
+ }
520
+ return !0;
521
+ }
522
+ isEnd() {
523
+ if (this.#s === this || this.#e?.type === "!")
524
+ return !0;
525
+ if (!this.#e?.isEnd())
526
+ return !1;
527
+ if (!this.type)
528
+ return this.#e?.isEnd();
529
+ const t = this.#e ? this.#e.#t.length : 0;
530
+ return this.#o === t - 1;
531
+ }
532
+ copyIn(t) {
533
+ typeof t == "string" ? this.push(t) : this.push(t.clone(this));
534
+ }
535
+ clone(t) {
536
+ const e = new E(this.type, t);
537
+ for (const n of this.#t)
538
+ e.copyIn(n);
539
+ return e;
540
+ }
541
+ static #l(t, e, n, i) {
542
+ let r = !1, o = !1, a = -1, c = !1;
543
+ if (e.type === null) {
544
+ let d = n, w = "";
545
+ for (; d < t.length; ) {
546
+ const p = t.charAt(d++);
547
+ if (r || p === "\\\\") {
548
+ r = !r, w += p;
549
+ continue;
550
+ }
551
+ if (o) {
552
+ d === a + 1 ? (p === "^" || p === "!") && (c = !0) : p === "]" && !(d === a + 2 && c) && (o = !1), w += p;
553
+ continue;
554
+ } else if (p === "[") {
555
+ o = !0, a = d, c = !1, w += p;
556
+ continue;
557
+ }
558
+ if (!i.noext && it(p) && t.charAt(d) === "(") {
559
+ e.push(w), w = "";
560
+ const S = new E(p, e);
561
+ d = E.#l(t, S, d, i), e.push(S);
562
+ continue;
563
+ }
564
+ w += p;
565
+ }
566
+ return e.push(w), d;
567
+ }
568
+ let l = n + 1, h = new E(null, e);
569
+ const f = [];
570
+ let u = "";
571
+ for (; l < t.length; ) {
572
+ const d = t.charAt(l++);
573
+ if (r || d === "\\\\") {
574
+ r = !r, u += d;
575
+ continue;
576
+ }
577
+ if (o) {
578
+ l === a + 1 ? (d === "^" || d === "!") && (c = !0) : d === "]" && !(l === a + 2 && c) && (o = !1), u += d;
579
+ continue;
580
+ } else if (d === "[") {
581
+ o = !0, a = l, c = !1, u += d;
582
+ continue;
583
+ }
584
+ if (it(d) && t.charAt(l) === "(") {
585
+ h.push(u), u = "";
586
+ const w = new E(d, h);
587
+ h.push(w), l = E.#l(t, w, l, i);
588
+ continue;
589
+ }
590
+ if (d === "|") {
591
+ h.push(u), u = "", f.push(h), h = new E(null, e);
592
+ continue;
593
+ }
594
+ if (d === ")")
595
+ return u === "" && e.#t.length === 0 && (e.#u = !0), h.push(u), u = "", e.push(...f, h), l;
596
+ u += d;
597
+ }
598
+ return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], l;
599
+ }
600
+ static fromGlob(t, e = {}) {
601
+ const n = new E(null, void 0, e);
602
+ return E.#l(t, n, 0, e), n;
603
+ }
604
+ // returns the regular expression if there's magic, or the unescaped
605
+ // string if not.
606
+ toMMPattern() {
607
+ if (this !== this.#s)
608
+ return this.#s.toMMPattern();
609
+ const t = this.toString(), [e, n, i, r] = this.toRegExpSource();
610
+ if (!(i || this.#n || this.#i.nocase && !this.#i.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
611
+ return n;
612
+ const a = (this.#i.nocase ? "i" : "") + (r ? "u" : "");
613
+ return Object.assign(new RegExp(\`^\${e}$\`, a), {
614
+ _src: e,
615
+ _glob: t
616
+ });
617
+ }
618
+ get options() {
619
+ return this.#i;
620
+ }
621
+ // returns the string match, the regexp source, whether there's magic
622
+ // in the regexp (so a regular expression is required) and whether or
623
+ // not the uflag is needed for the regular expression (for posix classes)
624
+ // TODO: instead of injecting the start/end at this point, just return
625
+ // the BODY of the regexp, along with the start/end portions suitable
626
+ // for binding the start/end in either a joined full-path makeRe context
627
+ // (where we bind to (^|/), or a standalone matchPart context (where
628
+ // we bind to ^, and not /). Otherwise slashes get duped!
629
+ //
630
+ // In part-matching mode, the start is:
631
+ // - if not isStart: nothing
632
+ // - if traversal possible, but not allowed: ^(?!\\.\\.?$)
633
+ // - if dots allowed or not possible: ^
634
+ // - if dots possible and not allowed: ^(?!\\.)
635
+ // end is:
636
+ // - if not isEnd(): nothing
637
+ // - else: $
638
+ //
639
+ // In full-path matching mode, we put the slash at the START of the
640
+ // pattern, so start is:
641
+ // - if first pattern: same as part-matching mode
642
+ // - if not isStart(): nothing
643
+ // - if traversal possible, but not allowed: /(?!\\.\\.?(?:$|/))
644
+ // - if dots allowed or not possible: /
645
+ // - if dots possible and not allowed: /(?!\\.)
646
+ // end is:
647
+ // - if last pattern, same as part-matching mode
648
+ // - else nothing
649
+ //
650
+ // Always put the (?:$|/) on negated tails, though, because that has to be
651
+ // there to bind the end of the negated pattern portion, and it's easier to
652
+ // just stick it in now rather than try to inject it later in the middle of
653
+ // the pattern.
654
+ //
655
+ // We can just always return the same end, and leave it up to the caller
656
+ // to know whether it's going to be used joined or in parts.
657
+ // And, if the start is adjusted slightly, can do the same there:
658
+ // - if not isStart: nothing
659
+ // - if traversal possible, but not allowed: (?:/|^)(?!\\.\\.?$)
660
+ // - if dots allowed or not possible: (?:/|^)
661
+ // - if dots possible and not allowed: (?:/|^)(?!\\.)
662
+ //
663
+ // But it's better to have a simpler binding without a conditional, for
664
+ // performance, so probably better to return both start options.
665
+ //
666
+ // Then the caller just ignores the end if it's not the first pattern,
667
+ // and the start always gets applied.
668
+ //
669
+ // But that's always going to be $ if it's the ending pattern, or nothing,
670
+ // so the caller can just attach $ at the end of the pattern when building.
671
+ //
672
+ // So the todo is:
673
+ // - better detect what kind of start is needed
674
+ // - return both flavors of starting pattern
675
+ // - attach $ at the end of the pattern when creating the actual RegExp
676
+ //
677
+ // Ah, but wait, no, that all only applies to the root when the first pattern
678
+ // is not an extglob. If the first pattern IS an extglob, then we need all
679
+ // that dot prevention biz to live in the extglob portions, because eg
680
+ // +(*|.x*) can match .xy but not .yx.
681
+ //
682
+ // So, return the two flavors if it's #root and the first child is not an
683
+ // AST, otherwise leave it to the child AST to handle it, and there,
684
+ // use the (?:^|/) style of start binding.
685
+ //
686
+ // Even simplified further:
687
+ // - Since the start for a join is eg /(?!\\.) and the start for a part
688
+ // is ^(?!\\.), we can just prepend (?!\\.) to the pattern (either root
689
+ // or start or whatever) and prepend ^ or / at the Regexp construction.
690
+ toRegExpSource(t) {
691
+ const e = t ?? !!this.#i.dot;
692
+ if (this.#s === this && this.#d(), !this.type) {
693
+ const c = this.isStart() && this.isEnd(), l = this.#t.map((d) => {
694
+ const [w, p, S, D] = typeof d == "string" ? E.#p(d, this.#n, c) : d.toRegExpSource(t);
695
+ return this.#n = this.#n || S, this.#r = this.#r || D, w;
696
+ }).join("");
697
+ let h = "";
698
+ if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && ue.has(this.#t[0]))) {
699
+ const w = le, p = (
700
+ // dots are allowed, and the pattern starts with [ or .
701
+ e && w.has(l.charAt(0)) || // the pattern starts with \\., and then [ or .
702
+ l.startsWith("\\\\.") && w.has(l.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
703
+ l.startsWith("\\\\.\\\\.") && w.has(l.charAt(4))
704
+ ), S = !e && !t && w.has(l.charAt(0));
705
+ h = p ? he : S ? k : "";
706
+ }
707
+ let f = "";
708
+ return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
709
+ h + l + f,
710
+ $(l),
711
+ this.#n = !!this.#n,
712
+ this.#r
713
+ ];
714
+ }
715
+ const n = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:";
716
+ let r = this.#f(e);
717
+ if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
718
+ const c = this.toString();
719
+ return this.#t = [c], this.type = null, this.#n = void 0, [c, $(this.toString()), !1, !1];
720
+ }
721
+ let o = !n || t || e || !k ? "" : this.#f(!0);
722
+ o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
723
+ let a = "";
724
+ if (this.type === "!" && this.#u)
725
+ a = (this.isStart() && !e ? k : "") + ot;
726
+ else {
727
+ const c = this.type === "!" ? (
728
+ // !() must match something,but !(x) can match ''
729
+ "))" + (this.isStart() && !e && !t ? k : "") + rt + ")"
730
+ ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
731
+ a = i + r + c;
732
+ }
733
+ return [
734
+ a,
735
+ $(r),
736
+ this.#n = !!this.#n,
737
+ this.#r
738
+ ];
739
+ }
740
+ #f(t) {
741
+ return this.#t.map((e) => {
742
+ if (typeof e == "string")
743
+ throw new Error("string type in extglob ast??");
744
+ const [n, i, r, o] = e.toRegExpSource(t);
745
+ return this.#r = this.#r || o, n;
746
+ }).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
747
+ }
748
+ static #p(t, e, n = !1) {
749
+ let i = !1, r = "", o = !1;
750
+ for (let a = 0; a < t.length; a++) {
751
+ const c = t.charAt(a);
752
+ if (i) {
753
+ i = !1, r += (fe.has(c) ? "\\\\" : "") + c;
754
+ continue;
755
+ }
756
+ if (c === "\\\\") {
757
+ a === t.length - 1 ? r += "\\\\\\\\" : i = !0;
758
+ continue;
759
+ }
760
+ if (c === "[") {
761
+ const [l, h, f, u] = ae(t, a);
762
+ if (f) {
763
+ r += l, o = o || h, a += f - 1, e = e || u;
764
+ continue;
765
+ }
766
+ }
767
+ if (c === "*") {
768
+ n && t === "*" ? r += ot : r += rt, e = !0;
769
+ continue;
770
+ }
771
+ if (c === "?") {
772
+ r += Q, e = !0;
773
+ continue;
774
+ }
775
+ r += de(c);
776
+ }
777
+ return [r, $(t), !!e, o];
253
778
  }
254
779
  }
255
- class tt extends c {
780
+ const pe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (U(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new _(t, e).match(s)), ge = /^\\*+([^+@!?\\*\\[\\(]*)$/, we = (s) => (t) => !t.startsWith(".") && t.endsWith(s), me = (s) => (t) => t.endsWith(s), ye = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), Ee = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Se = /^\\*+\\.\\*+$/, xe = (s) => !s.startsWith(".") && s.includes("."), be = (s) => s !== "." && s !== ".." && s.includes("."), Ae = /^\\.\\*+$/, De = (s) => s !== "." && s !== ".." && s.startsWith("."), Ce = /^\\*+$/, Oe = (s) => s.length !== 0 && !s.startsWith("."), Te = (s) => s.length !== 0 && s !== "." && s !== "..", Fe = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ne = ([s, t = ""]) => {
781
+ const e = At([s]);
782
+ return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
783
+ }, Pe = ([s, t = ""]) => {
784
+ const e = Dt([s]);
785
+ return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
786
+ }, ve = ([s, t = ""]) => {
787
+ const e = Dt([s]);
788
+ return t ? (n) => e(n) && n.endsWith(t) : e;
789
+ }, Me = ([s, t = ""]) => {
790
+ const e = At([s]);
791
+ return t ? (n) => e(n) && n.endsWith(t) : e;
792
+ }, At = ([s]) => {
793
+ const t = s.length;
794
+ return (e) => e.length === t && !e.startsWith(".");
795
+ }, Dt = ([s]) => {
796
+ const t = s.length;
797
+ return (e) => e.length === t && e !== "." && e !== "..";
798
+ }, Ct = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", at = {
799
+ win32: { sep: "\\\\" },
800
+ posix: { sep: "/" }
801
+ }, $e = Ct === "win32" ? at.win32.sep : at.posix.sep;
802
+ y.sep = $e;
803
+ const A = Symbol("globstar **");
804
+ y.GLOBSTAR = A;
805
+ const Re = "[^/]", Ie = Re + "*?", ke = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Le = "(?:(?!(?:\\\\/|^)\\\\.).)*?", ze = (s, t = {}) => (e) => y(e, s, t);
806
+ y.filter = ze;
807
+ const b = (s, t = {}) => Object.assign({}, s, t), We = (s) => {
808
+ if (!s || typeof s != "object" || !Object.keys(s).length)
809
+ return y;
810
+ const t = y;
811
+ return Object.assign((n, i, r = {}) => t(n, i, b(s, r)), {
812
+ Minimatch: class extends t.Minimatch {
813
+ constructor(i, r = {}) {
814
+ super(i, b(s, r));
815
+ }
816
+ static defaults(i) {
817
+ return t.defaults(b(s, i)).Minimatch;
818
+ }
819
+ },
820
+ AST: class extends t.AST {
821
+ /* c8 ignore start */
822
+ constructor(i, r, o = {}) {
823
+ super(i, r, b(s, o));
824
+ }
825
+ /* c8 ignore stop */
826
+ static fromGlob(i, r = {}) {
827
+ return t.AST.fromGlob(i, b(s, r));
828
+ }
829
+ },
830
+ unescape: (n, i = {}) => t.unescape(n, b(s, i)),
831
+ escape: (n, i = {}) => t.escape(n, b(s, i)),
832
+ filter: (n, i = {}) => t.filter(n, b(s, i)),
833
+ defaults: (n) => t.defaults(b(s, n)),
834
+ makeRe: (n, i = {}) => t.makeRe(n, b(s, i)),
835
+ braceExpand: (n, i = {}) => t.braceExpand(n, b(s, i)),
836
+ match: (n, i, r = {}) => t.match(n, i, b(s, r)),
837
+ sep: t.sep,
838
+ GLOBSTAR: A
839
+ });
840
+ };
841
+ y.defaults = We;
842
+ const Ot = (s, t = {}) => (U(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : Qt(s));
843
+ y.braceExpand = Ot;
844
+ const He = (s, t = {}) => new _(s, t).makeRe();
845
+ y.makeRe = He;
846
+ const je = (s, t, e = {}) => {
847
+ const n = new _(t, e);
848
+ return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
849
+ };
850
+ y.match = je;
851
+ const ct = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ue = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
852
+ class _ {
853
+ options;
854
+ set;
855
+ pattern;
856
+ windowsPathsNoEscape;
857
+ nonegate;
858
+ negate;
859
+ comment;
860
+ empty;
861
+ preserveMultipleSlashes;
862
+ partial;
863
+ globSet;
864
+ globParts;
865
+ nocase;
866
+ isWindows;
867
+ platform;
868
+ windowsNoMagicRoot;
869
+ regexp;
870
+ constructor(t, e = {}) {
871
+ U(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ct, 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();
872
+ }
873
+ hasMagic() {
874
+ if (this.options.magicalBraces && this.set.length > 1)
875
+ return !0;
876
+ for (const t of this.set)
877
+ for (const e of t)
878
+ if (typeof e != "string")
879
+ return !0;
880
+ return !1;
881
+ }
882
+ debug(...t) {
883
+ }
884
+ make() {
885
+ const t = this.pattern, e = this.options;
886
+ if (!e.nocomment && t.charAt(0) === "#") {
887
+ this.comment = !0;
888
+ return;
889
+ }
890
+ if (!t) {
891
+ this.empty = !0;
892
+ return;
893
+ }
894
+ this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...r) => console.error(...r)), this.debug(this.pattern, this.globSet);
895
+ const n = this.globSet.map((r) => this.slashSplit(r));
896
+ this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
897
+ let i = this.globParts.map((r, o, a) => {
898
+ if (this.isWindows && this.windowsNoMagicRoot) {
899
+ const c = r[0] === "" && r[1] === "" && (r[2] === "?" || !ct.test(r[2])) && !ct.test(r[3]), l = /^[a-z]:/i.test(r[0]);
900
+ if (c)
901
+ return [...r.slice(0, 4), ...r.slice(4).map((h) => this.parse(h))];
902
+ if (l)
903
+ return [r[0], ...r.slice(1).map((h) => this.parse(h))];
904
+ }
905
+ return r.map((c) => this.parse(c));
906
+ });
907
+ if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(!1) === -1), this.isWindows)
908
+ for (let r = 0; r < this.set.length; r++) {
909
+ const o = this.set[r];
910
+ o[0] === "" && o[1] === "" && this.globParts[r][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
911
+ }
912
+ this.debug(this.pattern, this.set);
913
+ }
914
+ // various transforms to equivalent pattern sets that are
915
+ // faster to process in a filesystem walk. The goal is to
916
+ // eliminate what we can, and push all ** patterns as far
917
+ // to the right as possible, even if it increases the number
918
+ // of patterns that we have to process.
919
+ preprocess(t) {
920
+ if (this.options.noglobstar)
921
+ for (let n = 0; n < t.length; n++)
922
+ for (let i = 0; i < t[n].length; i++)
923
+ t[n][i] === "**" && (t[n][i] = "*");
924
+ const { optimizationLevel: e = 1 } = this.options;
925
+ return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
926
+ }
927
+ // just get rid of adjascent ** portions
928
+ adjascentGlobstarOptimize(t) {
929
+ return t.map((e) => {
930
+ let n = -1;
931
+ for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
932
+ let i = n;
933
+ for (; e[i + 1] === "**"; )
934
+ i++;
935
+ i !== n && e.splice(n, i - n);
936
+ }
937
+ return e;
938
+ });
939
+ }
940
+ // get rid of adjascent ** and resolve .. portions
941
+ levelOneOptimize(t) {
942
+ return t.map((e) => (e = e.reduce((n, i) => {
943
+ const r = n[n.length - 1];
944
+ return i === "**" && r === "**" ? n : i === ".." && r && r !== ".." && r !== "." && r !== "**" ? (n.pop(), n) : (n.push(i), n);
945
+ }, []), e.length === 0 ? [""] : e));
946
+ }
947
+ levelTwoFileOptimize(t) {
948
+ Array.isArray(t) || (t = this.slashSplit(t));
949
+ let e = !1;
950
+ do {
951
+ if (e = !1, !this.preserveMultipleSlashes) {
952
+ for (let i = 1; i < t.length - 1; i++) {
953
+ const r = t[i];
954
+ i === 1 && r === "" && t[0] === "" || (r === "." || r === "") && (e = !0, t.splice(i, 1), i--);
955
+ }
956
+ t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
957
+ }
958
+ let n = 0;
959
+ for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
960
+ const i = t[n - 1];
961
+ i && i !== "." && i !== ".." && i !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
962
+ }
963
+ } while (e);
964
+ return t.length === 0 ? [""] : t;
965
+ }
966
+ // First phase: single-pattern processing
967
+ // <pre> is 1 or more portions
968
+ // <rest> is 1 or more portions
969
+ // <p> is any portion other than ., .., '', or **
970
+ // <e> is . or ''
971
+ //
972
+ // **/.. is *brutal* for filesystem walking performance, because
973
+ // it effectively resets the recursive walk each time it occurs,
974
+ // and ** cannot be reduced out by a .. pattern part like a regexp
975
+ // or most strings (other than .., ., and '') can be.
976
+ //
977
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
978
+ // <pre>/<e>/<rest> -> <pre>/<rest>
979
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
980
+ // **/**/<rest> -> **/<rest>
981
+ //
982
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
983
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
984
+ firstPhasePreProcess(t) {
985
+ let e = !1;
986
+ do {
987
+ e = !1;
988
+ for (let n of t) {
989
+ let i = -1;
990
+ for (; (i = n.indexOf("**", i + 1)) !== -1; ) {
991
+ let o = i;
992
+ for (; n[o + 1] === "**"; )
993
+ o++;
994
+ o > i && n.splice(i + 1, o - i);
995
+ let a = n[i + 1];
996
+ const c = n[i + 2], l = n[i + 3];
997
+ if (a !== ".." || !c || c === "." || c === ".." || !l || l === "." || l === "..")
998
+ continue;
999
+ e = !0, n.splice(i, 1);
1000
+ const h = n.slice(0);
1001
+ h[i] = "**", t.push(h), i--;
1002
+ }
1003
+ if (!this.preserveMultipleSlashes) {
1004
+ for (let o = 1; o < n.length - 1; o++) {
1005
+ const a = n[o];
1006
+ o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (e = !0, n.splice(o, 1), o--);
1007
+ }
1008
+ n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
1009
+ }
1010
+ let r = 0;
1011
+ for (; (r = n.indexOf("..", r + 1)) !== -1; ) {
1012
+ const o = n[r - 1];
1013
+ if (o && o !== "." && o !== ".." && o !== "**") {
1014
+ e = !0;
1015
+ const c = r === 1 && n[r + 1] === "**" ? ["."] : [];
1016
+ n.splice(r - 1, 2, ...c), n.length === 0 && n.push(""), r -= 2;
1017
+ }
1018
+ }
1019
+ }
1020
+ } while (e);
1021
+ return t;
1022
+ }
1023
+ // second phase: multi-pattern dedupes
1024
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
1025
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
1026
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
1027
+ //
1028
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
1029
+ // ^-- not valid because ** doens't follow symlinks
1030
+ secondPhasePreProcess(t) {
1031
+ for (let e = 0; e < t.length - 1; e++)
1032
+ for (let n = e + 1; n < t.length; n++) {
1033
+ const i = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
1034
+ if (i) {
1035
+ t[e] = [], t[n] = i;
1036
+ break;
1037
+ }
1038
+ }
1039
+ return t.filter((e) => e.length);
1040
+ }
1041
+ partsMatch(t, e, n = !1) {
1042
+ let i = 0, r = 0, o = [], a = "";
1043
+ for (; i < t.length && r < e.length; )
1044
+ if (t[i] === e[r])
1045
+ o.push(a === "b" ? e[r] : t[i]), i++, r++;
1046
+ else if (n && t[i] === "**" && e[r] === t[i + 1])
1047
+ o.push(t[i]), i++;
1048
+ else if (n && e[r] === "**" && t[i] === e[r + 1])
1049
+ o.push(e[r]), r++;
1050
+ else if (t[i] === "*" && e[r] && (this.options.dot || !e[r].startsWith(".")) && e[r] !== "**") {
1051
+ if (a === "b")
1052
+ return !1;
1053
+ a = "a", o.push(t[i]), i++, r++;
1054
+ } else if (e[r] === "*" && t[i] && (this.options.dot || !t[i].startsWith(".")) && t[i] !== "**") {
1055
+ if (a === "a")
1056
+ return !1;
1057
+ a = "b", o.push(e[r]), i++, r++;
1058
+ } else
1059
+ return !1;
1060
+ return t.length === e.length && o;
1061
+ }
1062
+ parseNegate() {
1063
+ if (this.nonegate)
1064
+ return;
1065
+ const t = this.pattern;
1066
+ let e = !1, n = 0;
1067
+ for (let i = 0; i < t.length && t.charAt(i) === "!"; i++)
1068
+ e = !e, n++;
1069
+ n && (this.pattern = t.slice(n)), this.negate = e;
1070
+ }
1071
+ // set partial to true to test if, for example,
1072
+ // "/a/b" matches the start of "/*/b/*/d"
1073
+ // Partial means, if you run out of file before you run
1074
+ // out of pattern, then that's fine, as long as all
1075
+ // the parts match.
1076
+ matchOne(t, e, n = !1) {
1077
+ const i = this.options;
1078
+ if (this.isWindows) {
1079
+ 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]), D = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), N = !D && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, m = N ? 3 : D ? 0 : void 0;
1080
+ if (typeof x == "number" && typeof m == "number") {
1081
+ const [P, R] = [t[x], e[m]];
1082
+ P.toLowerCase() === R.toLowerCase() && (e[m] = P, m > x ? e = e.slice(m) : x > m && (t = t.slice(x)));
1083
+ }
1084
+ }
1085
+ const { optimizationLevel: r = 1 } = this.options;
1086
+ r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
1087
+ for (var o = 0, a = 0, c = t.length, l = e.length; o < c && a < l; o++, a++) {
1088
+ this.debug("matchOne loop");
1089
+ var h = e[a], f = t[o];
1090
+ if (this.debug(e, h, f), h === !1)
1091
+ return !1;
1092
+ if (h === A) {
1093
+ this.debug("GLOBSTAR", [e, h, f]);
1094
+ var u = o, d = a + 1;
1095
+ if (d === l) {
1096
+ for (this.debug("** at the end"); o < c; o++)
1097
+ if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
1098
+ return !1;
1099
+ return !0;
1100
+ }
1101
+ for (; u < c; ) {
1102
+ var w = t[u];
1103
+ if (this.debug(\`
1104
+ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
1105
+ return this.debug("globstar found match!", u, c, w), !0;
1106
+ if (w === "." || w === ".." || !i.dot && w.charAt(0) === ".") {
1107
+ this.debug("dot detected!", t, u, e, d);
1108
+ break;
1109
+ }
1110
+ this.debug("globstar swallow a segment, and continue"), u++;
1111
+ }
1112
+ return !!(n && (this.debug(\`
1113
+ >>> no match, partial?\`, t, u, e, d), u === c));
1114
+ }
1115
+ let p;
1116
+ if (typeof h == "string" ? (p = f === h, this.debug("string match", h, f, p)) : (p = h.test(f), this.debug("pattern match", h, f, p)), !p)
1117
+ return !1;
1118
+ }
1119
+ if (o === c && a === l)
1120
+ return !0;
1121
+ if (o === c)
1122
+ return n;
1123
+ if (a === l)
1124
+ return o === c - 1 && t[o] === "";
1125
+ throw new Error("wtf?");
1126
+ }
1127
+ braceExpand() {
1128
+ return Ot(this.pattern, this.options);
1129
+ }
1130
+ parse(t) {
1131
+ U(t);
1132
+ const e = this.options;
1133
+ if (t === "**")
1134
+ return A;
1135
+ if (t === "")
1136
+ return "";
1137
+ let n, i = null;
1138
+ (n = t.match(Ce)) ? i = e.dot ? Te : Oe : (n = t.match(ge)) ? i = (e.nocase ? e.dot ? Ee : ye : e.dot ? me : we)(n[1]) : (n = t.match(Fe)) ? i = (e.nocase ? e.dot ? Pe : Ne : e.dot ? ve : Me)(n) : (n = t.match(Se)) ? i = e.dot ? be : xe : (n = t.match(Ae)) && (i = De);
1139
+ const r = E.fromGlob(t, this.options).toMMPattern();
1140
+ return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
1141
+ }
1142
+ makeRe() {
1143
+ if (this.regexp || this.regexp === !1)
1144
+ return this.regexp;
1145
+ const t = this.set;
1146
+ if (!t.length)
1147
+ return this.regexp = !1, this.regexp;
1148
+ const e = this.options, n = e.noglobstar ? Ie : e.dot ? ke : Le, i = new Set(e.nocase ? ["i"] : []);
1149
+ let r = t.map((c) => {
1150
+ const l = c.map((h) => {
1151
+ if (h instanceof RegExp)
1152
+ for (const f of h.flags.split(""))
1153
+ i.add(f);
1154
+ return typeof h == "string" ? Ue(h) : h === A ? A : h._src;
1155
+ });
1156
+ return l.forEach((h, f) => {
1157
+ const u = l[f + 1], d = l[f - 1];
1158
+ h !== A || d === A || (d === void 0 ? u !== void 0 && u !== A ? l[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : l[f] = n : u === void 0 ? l[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== A && (l[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, l[f + 1] = A));
1159
+ }), l.filter((h) => h !== A).join("/");
1160
+ }).join("|");
1161
+ const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1162
+ r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
1163
+ try {
1164
+ this.regexp = new RegExp(r, [...i].join(""));
1165
+ } catch {
1166
+ this.regexp = !1;
1167
+ }
1168
+ return this.regexp;
1169
+ }
1170
+ slashSplit(t) {
1171
+ return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\\/\\/[^\\/]+/.test(t) ? ["", ...t.split(/\\/+/)] : t.split(/\\/+/);
1172
+ }
1173
+ match(t, e = this.partial) {
1174
+ if (this.debug("match", t, this.pattern), this.comment)
1175
+ return !1;
1176
+ if (this.empty)
1177
+ return t === "";
1178
+ if (t === "/" && e)
1179
+ return !0;
1180
+ const n = this.options;
1181
+ this.isWindows && (t = t.split("\\\\").join("/"));
1182
+ const i = this.slashSplit(t);
1183
+ this.debug(this.pattern, "split", i);
1184
+ const r = this.set;
1185
+ this.debug(this.pattern, "set", r);
1186
+ let o = i[i.length - 1];
1187
+ if (!o)
1188
+ for (let a = i.length - 2; !o && a >= 0; a--)
1189
+ o = i[a];
1190
+ for (let a = 0; a < r.length; a++) {
1191
+ const c = r[a];
1192
+ let l = i;
1193
+ if (n.matchBase && c.length === 1 && (l = [o]), this.matchOne(l, c, e))
1194
+ return n.flipNegate ? !0 : !this.negate;
1195
+ }
1196
+ return n.flipNegate ? !1 : this.negate;
1197
+ }
1198
+ static defaults(t) {
1199
+ return y.defaults(t).Minimatch;
1200
+ }
1201
+ }
1202
+ y.AST = E;
1203
+ y.Minimatch = _;
1204
+ y.escape = pe;
1205
+ y.unescape = $;
1206
+ class g extends Error {
1207
+ constructor(t, e, n) {
1208
+ super(t), this.code = e, this.path = n, this.name = "OPFSError";
1209
+ }
1210
+ }
1211
+ class _e extends g {
256
1212
  constructor() {
257
1213
  super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
258
1214
  }
259
1215
  }
260
- class b extends c {
1216
+ class q extends g {
261
1217
  constructor() {
262
1218
  super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
263
1219
  }
264
1220
  }
265
- class N extends c {
266
- constructor(t, r) {
267
- super(t, "INVALID_PATH", r);
1221
+ class ht extends g {
1222
+ constructor(t, e) {
1223
+ super(t, "INVALID_PATH", e);
268
1224
  }
269
1225
  }
270
- class T extends c {
1226
+ class V extends g {
271
1227
  constructor(t) {
272
1228
  super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
273
1229
  }
274
1230
  }
275
- function et(e, t = "utf-8") {
1231
+ function Be(s, t = "utf-8") {
276
1232
  switch (t) {
277
1233
  case "utf8":
278
1234
  case "utf-8":
279
- return new TextEncoder().encode(e);
1235
+ return new TextEncoder().encode(s);
280
1236
  case "utf16le":
281
1237
  case "ucs2":
282
1238
  case "ucs-2":
283
- return nt(e);
1239
+ return qe(s);
284
1240
  case "ascii":
285
- return st(e);
1241
+ return Xe(s);
286
1242
  case "latin1":
287
- return at(e);
1243
+ return Ze(s);
288
1244
  case "binary":
289
- return Uint8Array.from(e, (r) => r.charCodeAt(0));
1245
+ return Uint8Array.from(s, (e) => e.charCodeAt(0));
290
1246
  case "base64":
291
- return Uint8Array.from(atob(e), (r) => r.charCodeAt(0));
1247
+ return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
292
1248
  case "hex":
293
- if (!/^[\\da-f]+$/i.test(e) || e.length % 2 !== 0)
294
- throw new c("Invalid hex string", "INVALID_HEX_FORMAT");
295
- return Uint8Array.from(e.match(/.{1,2}/g).map((r) => parseInt(r, 16)));
1249
+ if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
1250
+ throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
1251
+ return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
296
1252
  default:
297
- return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(e);
1253
+ return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
298
1254
  }
299
1255
  }
300
- function rt(e, t = "utf-8") {
1256
+ function Ge(s, t = "utf-8") {
301
1257
  switch (t) {
302
1258
  case "utf8":
303
1259
  case "utf-8":
304
- return new TextDecoder().decode(e);
1260
+ return new TextDecoder().decode(s);
305
1261
  case "utf16le":
306
1262
  case "ucs2":
307
1263
  case "ucs-2":
308
- return it(e);
1264
+ return Ve(s);
309
1265
  case "latin1":
310
- return String.fromCharCode(...e);
1266
+ return String.fromCharCode(...s);
311
1267
  case "binary":
312
- return String.fromCharCode(...e);
1268
+ return String.fromCharCode(...s);
313
1269
  case "ascii":
314
- return String.fromCharCode(...e.map((r) => r & 127));
1270
+ return String.fromCharCode(...s.map((e) => e & 127));
315
1271
  case "base64":
316
- return btoa(String.fromCharCode(...e));
1272
+ return btoa(String.fromCharCode(...s));
317
1273
  case "hex":
318
- return Array.from(e).map((r) => r.toString(16).padStart(2, "0")).join("");
1274
+ return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
319
1275
  default:
320
- return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(e);
1276
+ return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
321
1277
  }
322
1278
  }
323
- function nt(e) {
324
- const t = new Uint8Array(e.length * 2);
325
- for (let r = 0; r < e.length; r++) {
326
- const i = e.charCodeAt(r);
327
- t[r * 2] = i & 255, t[r * 2 + 1] = i >> 8;
1279
+ function qe(s) {
1280
+ const t = new Uint8Array(s.length * 2);
1281
+ for (let e = 0; e < s.length; e++) {
1282
+ const n = s.charCodeAt(e);
1283
+ t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
328
1284
  }
329
1285
  return t;
330
1286
  }
331
- function it(e) {
332
- e.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), e = e.slice(0, e.length - 1));
333
- const t = new Uint16Array(e.buffer, e.byteOffset, e.byteLength / 2);
1287
+ function Ve(s) {
1288
+ s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
1289
+ const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
334
1290
  return String.fromCharCode(...t);
335
1291
  }
336
- function at(e) {
337
- const t = new Uint8Array(e.length);
338
- for (let r = 0; r < e.length; r++)
339
- t[r] = e.charCodeAt(r) & 255;
1292
+ function Ze(s) {
1293
+ const t = new Uint8Array(s.length);
1294
+ for (let e = 0; e < s.length; e++)
1295
+ t[e] = s.charCodeAt(e) & 255;
340
1296
  return t;
341
1297
  }
342
- function st(e) {
343
- const t = new Uint8Array(e.length);
344
- for (let r = 0; r < e.length; r++)
345
- t[r] = e.charCodeAt(r) & 127;
1298
+ function Xe(s) {
1299
+ const t = new Uint8Array(s.length);
1300
+ for (let e = 0; e < s.length; e++)
1301
+ t[e] = s.charCodeAt(e) & 127;
346
1302
  return t;
347
1303
  }
348
- function ot() {
1304
+ function Ye() {
349
1305
  if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
350
- throw new tt();
1306
+ throw new _e();
351
1307
  }
352
- function m(e) {
353
- return Array.isArray(e) ? e : (e.startsWith("~/") ? e.slice(2) : e).split("/").filter(Boolean);
1308
+ function F(s) {
1309
+ return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
354
1310
  }
355
- function I(e) {
356
- return typeof e == "string" ? e ?? "/" : \`/\${e.join("/")}\`;
1311
+ function tt(s) {
1312
+ return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
357
1313
  }
358
- function O(e) {
359
- const t = m(e);
1314
+ function Z(s) {
1315
+ const t = F(s);
360
1316
  return t[t.length - 1] || "";
361
1317
  }
362
- function P(e) {
363
- const t = m(e);
364
- return t.pop(), I(t);
1318
+ function X(s) {
1319
+ const t = F(s);
1320
+ return t.pop(), tt(t);
1321
+ }
1322
+ function T(s) {
1323
+ return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
365
1324
  }
366
- function F(e) {
367
- return !e || e === "/" ? "/" : e.startsWith("~/") ? \`/\${e.slice(2)}\` : e.startsWith("/") ? e : \`/\${e}\`;
1325
+ function L(s, t) {
1326
+ if (!t || Array.isArray(t) && t.length === 0)
1327
+ return !1;
1328
+ const e = T(s);
1329
+ return (Array.isArray(t) ? t : [t]).some((i) => y(e, i, { dot: !0 }));
368
1330
  }
369
- function ct(e) {
370
- const t = F(e), r = m(t), i = [];
371
- for (const n of r)
372
- if (!(n === "." || n === ""))
373
- if (n === "..") {
374
- if (i.length === 0)
1331
+ function Je(s) {
1332
+ const t = T(s), e = F(t), n = [];
1333
+ for (const i of e)
1334
+ if (!(i === "." || i === ""))
1335
+ if (i === "..") {
1336
+ if (n.length === 0)
375
1337
  continue;
376
- i.pop();
1338
+ n.pop();
377
1339
  } else
378
- i.push(n);
379
- return I(i);
1340
+ n.push(i);
1341
+ return tt(n);
380
1342
  }
381
- function lt(e, t = "utf-8") {
382
- return typeof e == "string" ? et(e, t) : e instanceof Uint8Array ? e : new Uint8Array(e);
1343
+ function Ke(s, t = "utf-8") {
1344
+ return typeof s == "string" ? Be(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
383
1345
  }
384
- async function ht(e) {
385
- const t = await e.createSyncAccessHandle();
1346
+ async function Qe(s) {
1347
+ const t = await s.createSyncAccessHandle();
386
1348
  try {
387
- const r = t.getSize(), i = new Uint8Array(r);
388
- return t.read(i, { at: 0 }), i;
1349
+ const e = t.getSize(), n = new Uint8Array(e);
1350
+ return t.read(n, { at: 0 }), n;
389
1351
  } finally {
390
1352
  t.close();
391
1353
  }
392
1354
  }
393
- async function k(e, t, r, i = {}) {
394
- let n = null;
1355
+ async function lt(s, t, e, n = {}) {
1356
+ let i = null;
395
1357
  try {
396
- n = await e.createSyncAccessHandle();
397
- const a = lt(t, r), s = i.append ? n.getSize() : 0;
398
- n.write(a, { at: s }), i.truncate && !i.append && n.truncate(a.byteLength), n.flush();
399
- } catch (a) {
400
- console.error(a);
401
- const s = i.append ? "append" : "write";
402
- throw new c(\`Failed to \${s} file\`, \`\${s.toUpperCase()}_FAILED\`);
1358
+ i = await s.createSyncAccessHandle();
1359
+ const r = Ke(t, e), o = n.append ? i.getSize() : 0;
1360
+ i.write(r, { at: o }), n.truncate && !n.append && i.truncate(r.byteLength), i.flush();
1361
+ } catch (r) {
1362
+ console.error(r);
1363
+ const o = n.append ? "append" : "write";
1364
+ throw new g(\`Failed to \${o} file\`, \`\${o.toUpperCase()}_FAILED\`);
403
1365
  } finally {
404
- if (n)
1366
+ if (i)
405
1367
  try {
406
- n.close();
1368
+ i.close();
407
1369
  } catch {
408
1370
  }
409
1371
  }
410
1372
  }
411
- async function ut(e, t = "SHA-1", r = 50 * 1024 * 1024) {
412
- if (e instanceof File && (e = await e.arrayBuffer()), e.byteLength > r)
413
- throw new Error(\`File size \${e.byteLength} bytes exceeds maximum allowed size \${r} bytes\`);
414
- const i = new Uint8Array(e), n = await crypto.subtle.digest(t, i);
415
- return Array.from(new Uint8Array(n)).map((s) => s.toString(16).padStart(2, "0")).join("");
1373
+ async function ts(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1374
+ if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
1375
+ throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
1376
+ const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
1377
+ return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
416
1378
  }
417
- async function ft(e) {
418
- const t = await e.arrayBuffer();
1379
+ async function es(s) {
1380
+ const t = await s.arrayBuffer();
419
1381
  return new Uint8Array(t);
420
1382
  }
421
- class wt {
1383
+ class ss {
422
1384
  /** Root directory handle for the file system */
423
1385
  root = null;
424
- /** Map of watched paths to their last known state */
1386
+ /** Map of watched paths to their last known state and options */
425
1387
  watchers = /* @__PURE__ */ new Map();
426
1388
  /** Interval handle for polling watched paths */
427
1389
  watchTimer = null;
@@ -433,6 +1395,7 @@ class wt {
433
1395
  broadcastChannel = null;
434
1396
  /** Configuration options */
435
1397
  options = {
1398
+ root: "/",
436
1399
  watchInterval: 1e3,
437
1400
  maxFileSize: 50 * 1024 * 1024,
438
1401
  hashAlgorithm: null,
@@ -450,38 +1413,39 @@ class wt {
450
1413
  async notifyChange(t) {
451
1414
  if (!this.options.broadcastChannel)
452
1415
  return;
453
- let r;
1416
+ let e;
454
1417
  if (this.options.hashAlgorithm && !t.isDirectory && t.type !== "removed")
455
1418
  try {
456
- const i = await this.stat(t.path);
457
- i.isFile && i.hash && (r = i.hash);
458
- } catch (i) {
459
- console.warn(\`Failed to calculate hash for \${t.path}:\`, i);
1419
+ const n = await this.stat(t.path);
1420
+ n.isFile && n.hash && (e = n.hash);
1421
+ } catch (n) {
1422
+ console.warn(\`Failed to calculate hash for \${t.path}:\`, n);
460
1423
  }
461
1424
  try {
462
1425
  this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
463
- const i = {
464
- root: this.root.name,
1426
+ const n = {
1427
+ root: this.options.root,
465
1428
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
466
1429
  ...t,
467
- ...r && { hash: r }
1430
+ ...e && { hash: e }
468
1431
  };
469
- this.broadcastChannel.postMessage(i);
470
- } catch (i) {
471
- console.warn("Failed to send event via BroadcastChannel:", i);
1432
+ this.broadcastChannel.postMessage(n);
1433
+ } catch (n) {
1434
+ console.warn("Failed to send event via BroadcastChannel:", n);
472
1435
  }
473
1436
  }
474
1437
  /**
475
1438
  * Creates a new OPFSFileSystem instance
476
1439
  *
477
1440
  * @param options - Optional configuration options
1441
+ * @param options.root - Root path for the file system (default: '/')
478
1442
  * @param options.watchInterval - Polling interval in milliseconds for file watching
479
1443
  * @param options.hashAlgorithm - Hash algorithm for file hashing
480
1444
  * @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)
481
1445
  * @throws {OPFSError} If OPFS is not supported in the current browser
482
1446
  */
483
1447
  constructor(t) {
484
- ot(), t && this.setOptions(t), this.mount("/");
1448
+ Ye(), t && this.setOptions(t);
485
1449
  }
486
1450
  /**
487
1451
  * Initialize the file system within a given directory
@@ -504,14 +1468,14 @@ class wt {
504
1468
  * await fs.mount('/my-app');
505
1469
  * \`\`\`
506
1470
  */
507
- async mount(t = "/") {
508
- return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (r, i) => {
1471
+ async mount(t = this.options.root) {
1472
+ return this.mountingPromise && await this.mountingPromise, t = T(t), this.mountingPromise = new Promise(async (e, n) => {
509
1473
  this.root = null;
510
1474
  try {
511
- const n = await navigator.storage.getDirectory();
512
- t === "/" ? this.root = n : this.root = await this.getDirectoryHandle(t, !0, n), r(!0);
513
- } catch (n) {
514
- console.error(n), i(new c("Failed to initialize OPFS", "INIT_FAILED"));
1475
+ const i = await navigator.storage.getDirectory();
1476
+ t === "/" ? this.root = i : this.root = await this.getDirectoryHandle(t, !0, i), e(!0);
1477
+ } catch (i) {
1478
+ console.error(i), n(new g("Failed to initialize OPFS", "INIT_FAILED"));
515
1479
  } finally {
516
1480
  this.mountingPromise = null;
517
1481
  }
@@ -521,31 +1485,14 @@ class wt {
521
1485
  * Update configuration options
522
1486
  *
523
1487
  * @param options - Configuration options to update
1488
+ * @param options.root - Root path for the file system
524
1489
  * @param options.watchInterval - Polling interval in milliseconds for file watching
525
1490
  * @param options.hashAlgorithm - Hash algorithm for file hashing
526
1491
  * @param options.maxFileSize - Maximum file size for hashing in bytes
527
1492
  * @param options.broadcastChannel - Custom name for the broadcast channel
528
1493
  */
529
- setOptions(t) {
530
- t.watchInterval !== void 0 && (this.options.watchInterval = t.watchInterval), 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);
531
- }
532
- /**
533
- * Automatically mount the OPFS root if not already mounted
534
- *
535
- * This method is called internally when file operations are performed
536
- * without explicitly mounting first.
537
- *
538
- * @returns Promise that resolves when auto-mount is complete
539
- * @throws {OPFSError} If auto-mount fails
540
- */
541
- async ensureMounted() {
542
- if (!this.root) {
543
- if (this.mountingPromise) {
544
- await this.mountingPromise;
545
- return;
546
- }
547
- throw new c("OPFS not mounted", "NOT_MOUNTED");
548
- }
1494
+ async setOptions(t) {
1495
+ t.watchInterval !== void 0 && (this.options.watchInterval = t.watchInterval), 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.root !== void 0 && (this.options.root = t.root, await this.mount(this.options.root));
549
1496
  }
550
1497
  /**
551
1498
  * Get a directory handle from a path
@@ -565,14 +1512,14 @@ class wt {
565
1512
  * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
566
1513
  * \`\`\`
567
1514
  */
568
- async getDirectoryHandle(t, r = !1, i = this.root) {
569
- if (!i)
570
- throw new b();
571
- const n = Array.isArray(t) ? t : m(t);
572
- let a = i;
573
- for (const s of n)
574
- a = await a.getDirectoryHandle(s, { create: r });
575
- return a;
1515
+ async getDirectoryHandle(t, e = !1, n = this.root) {
1516
+ if (!n)
1517
+ throw new q();
1518
+ const i = Array.isArray(t) ? t : F(t);
1519
+ let r = n;
1520
+ for (const o of i)
1521
+ r = await r.getDirectoryHandle(o, { create: e });
1522
+ return r;
576
1523
  }
577
1524
  /**
578
1525
  * Get a file handle from a path
@@ -593,14 +1540,14 @@ class wt {
593
1540
  * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
594
1541
  * \`\`\`
595
1542
  */
596
- async getFileHandle(t, r = !1, i = this.root) {
597
- if (!i)
598
- throw new b();
599
- const n = m(t);
600
- if (n.length === 0)
601
- throw new N("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
602
- const a = n.pop();
603
- return (await this.getDirectoryHandle(n, r, i)).getFileHandle(a, { create: r });
1543
+ async getFileHandle(t, e = !1, n = this.root) {
1544
+ if (!n)
1545
+ throw new q();
1546
+ const i = F(t);
1547
+ if (i.length === 0)
1548
+ throw new ht("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1549
+ const r = i.pop();
1550
+ return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
604
1551
  }
605
1552
  /**
606
1553
  * Get a complete index of all files and directories in the file system
@@ -622,15 +1569,15 @@ class wt {
622
1569
  * \`\`\`
623
1570
  */
624
1571
  async index() {
625
- const t = /* @__PURE__ */ new Map(), r = async (i) => {
626
- const n = await this.readDir(i);
627
- for (const a of n) {
628
- const s = \`\${i === "/" ? "" : i}/\${a.name}\`;
1572
+ const t = /* @__PURE__ */ new Map(), e = async (n) => {
1573
+ const i = await this.readDir(n);
1574
+ for (const r of i) {
1575
+ const o = \`\${n === "/" ? "" : n}/\${r.name}\`;
629
1576
  try {
630
- const o = await this.stat(s);
631
- t.set(s, o), o.isDirectory && await r(s);
632
- } catch (o) {
633
- console.warn(\`Skipping broken entry: \${s}\`, o);
1577
+ const a = await this.stat(o);
1578
+ t.set(o, a), a.isDirectory && await e(o);
1579
+ } catch (a) {
1580
+ console.warn(\`Skipping broken entry: \${o}\`, a);
634
1581
  }
635
1582
  }
636
1583
  };
@@ -641,15 +1588,15 @@ class wt {
641
1588
  ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
642
1589
  isFile: !1,
643
1590
  isDirectory: !0
644
- }), await r("/"), t;
1591
+ }), await e("/"), t;
645
1592
  }
646
- async readFile(t, r = "utf-8") {
647
- await this.ensureMounted();
1593
+ async readFile(t, e = "utf-8") {
1594
+ await this.mount();
648
1595
  try {
649
- const i = await this.getFileHandle(t, !1), n = await ht(i);
650
- return r === "binary" ? n : rt(n, r);
651
- } catch (i) {
652
- throw console.error(i), new T(t);
1596
+ const n = await this.getFileHandle(t, !1), i = await Qe(n);
1597
+ return e === "binary" ? i : Ge(i, e);
1598
+ } catch (n) {
1599
+ throw console.error(n), new V(t);
653
1600
  }
654
1601
  }
655
1602
  /**
@@ -677,10 +1624,10 @@ class wt {
677
1624
  * await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');
678
1625
  * \`\`\`
679
1626
  */
680
- async writeFile(t, r, i) {
681
- await this.ensureMounted();
682
- const n = await this.getFileHandle(t, !0);
683
- await k(n, r, i, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
1627
+ async writeFile(t, e, n) {
1628
+ await this.mount();
1629
+ const i = await this.getFileHandle(t, !0);
1630
+ await lt(i, e, n, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
684
1631
  }
685
1632
  /**
686
1633
  * Append data to a file
@@ -704,10 +1651,10 @@ class wt {
704
1651
  * await fs.appendFile('/data/binary.dat', additionalData);
705
1652
  * \`\`\`
706
1653
  */
707
- async appendFile(t, r, i) {
708
- await this.ensureMounted();
709
- const n = await this.getFileHandle(t, !0);
710
- await k(n, r, i, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
1654
+ async appendFile(t, e, n) {
1655
+ await this.mount();
1656
+ const i = await this.getFileHandle(t, !0);
1657
+ await lt(i, e, n, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
711
1658
  }
712
1659
  /**
713
1660
  * Create a directory
@@ -730,20 +1677,20 @@ class wt {
730
1677
  * await fs.mkdir('/users/john/documents/projects', { recursive: true });
731
1678
  * \`\`\`
732
1679
  */
733
- async mkdir(t, r) {
734
- if (await this.ensureMounted(), !this.root)
735
- throw new b();
736
- const i = r?.recursive ?? !1, n = m(t);
737
- let a = this.root;
738
- for (let s = 0; s < n.length; s++) {
739
- const o = n[s];
1680
+ async mkdir(t, e) {
1681
+ if (await this.mount(), !this.root)
1682
+ throw new q();
1683
+ const n = e?.recursive ?? !1, i = F(t);
1684
+ let r = this.root;
1685
+ for (let o = 0; o < i.length; o++) {
1686
+ const a = i[o];
740
1687
  try {
741
- a = await a.getDirectoryHandle(o, { create: i || s === n.length - 1 });
742
- } catch (l) {
743
- throw l.name === "NotFoundError" ? new c(
744
- \`Parent directory does not exist: \${I(n.slice(0, s + 1))}\`,
1688
+ r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
1689
+ } catch (c) {
1690
+ throw c.name === "NotFoundError" ? new g(
1691
+ \`Parent directory does not exist: \${tt(i.slice(0, o + 1))}\`,
745
1692
  "ENOENT"
746
- ) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${o}\`, "ENOTDIR") : new c("Failed to create directory", "MKDIR_FAILED");
1693
+ ) : c.name === "TypeMismatchError" ? new g(\`Path segment is not a directory: \${a}\`, "ENOTDIR") : new g("Failed to create directory", "MKDIR_FAILED");
747
1694
  }
748
1695
  }
749
1696
  await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
@@ -771,7 +1718,7 @@ class wt {
771
1718
  * \`\`\`
772
1719
  */
773
1720
  async stat(t) {
774
- if (await this.ensureMounted(), t === "/")
1721
+ if (await this.mount(), t === "/")
775
1722
  return {
776
1723
  kind: "directory",
777
1724
  size: 0,
@@ -780,30 +1727,30 @@ class wt {
780
1727
  isFile: !1,
781
1728
  isDirectory: !0
782
1729
  };
783
- const r = O(t), i = await this.getDirectoryHandle(P(t), !1), n = this.options.hashAlgorithm !== null;
1730
+ const e = Z(t), n = await this.getDirectoryHandle(X(t), !1), i = this.options.hashAlgorithm !== null;
784
1731
  try {
785
- const s = await (await i.getFileHandle(r, { create: !1 })).getFile(), o = {
1732
+ const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
786
1733
  kind: "file",
787
- size: s.size,
788
- mtime: new Date(s.lastModified).toISOString(),
789
- ctime: new Date(s.lastModified).toISOString(),
1734
+ size: o.size,
1735
+ mtime: new Date(o.lastModified).toISOString(),
1736
+ ctime: new Date(o.lastModified).toISOString(),
790
1737
  isFile: !0,
791
1738
  isDirectory: !1
792
1739
  };
793
- if (n && this.options.hashAlgorithm)
1740
+ if (i && this.options.hashAlgorithm)
794
1741
  try {
795
- const l = await ut(s, this.options.hashAlgorithm, this.options.maxFileSize);
796
- o.hash = l;
797
- } catch (l) {
798
- console.warn(\`Failed to calculate hash for \${t}:\`, l);
1742
+ const c = await ts(o, this.options.hashAlgorithm, this.options.maxFileSize);
1743
+ a.hash = c;
1744
+ } catch (c) {
1745
+ console.warn(\`Failed to calculate hash for \${t}:\`, c);
799
1746
  }
800
- return o;
801
- } catch (a) {
802
- if (a.name !== "TypeMismatchError" && a.name !== "NotFoundError")
803
- throw new c("Failed to stat (file)", "STAT_FAILED");
1747
+ return a;
1748
+ } catch (r) {
1749
+ if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
1750
+ throw new g("Failed to stat (file)", "STAT_FAILED");
804
1751
  }
805
1752
  try {
806
- return await i.getDirectoryHandle(r, { create: !1 }), {
1753
+ return await n.getDirectoryHandle(e, { create: !1 }), {
807
1754
  kind: "directory",
808
1755
  size: 0,
809
1756
  mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
@@ -811,8 +1758,8 @@ class wt {
811
1758
  isFile: !1,
812
1759
  isDirectory: !0
813
1760
  };
814
- } catch (a) {
815
- throw a.name === "NotFoundError" ? new c(\`No such file or directory: \${t}\`, "ENOENT") : new c("Failed to stat (directory)", "STAT_FAILED");
1761
+ } catch (r) {
1762
+ throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT") : new g("Failed to stat (directory)", "STAT_FAILED");
816
1763
  }
817
1764
  }
818
1765
  /**
@@ -834,18 +1781,18 @@ class wt {
834
1781
  * \`\`\`
835
1782
  */
836
1783
  async readDir(t) {
837
- await this.ensureMounted();
838
- const r = await this.getDirectoryHandle(t, !1), i = [];
839
- for await (const [n, a] of r.entries()) {
840
- const s = a.kind === "file";
841
- i.push({
842
- name: n,
843
- kind: a.kind,
844
- isFile: s,
845
- isDirectory: !s
1784
+ await this.mount();
1785
+ const e = await this.getDirectoryHandle(t, !1), n = [];
1786
+ for await (const [i, r] of e.entries()) {
1787
+ const o = r.kind === "file";
1788
+ n.push({
1789
+ name: i,
1790
+ kind: r.kind,
1791
+ isFile: o,
1792
+ isDirectory: !o
846
1793
  });
847
1794
  }
848
- return i;
1795
+ return n;
849
1796
  }
850
1797
  /**
851
1798
  * Check if a file or directory exists
@@ -862,28 +1809,28 @@ class wt {
862
1809
  * \`\`\`
863
1810
  */
864
1811
  async exists(t) {
865
- if (await this.ensureMounted(), t === "/")
1812
+ if (await this.mount(), t === "/")
866
1813
  return !0;
867
- const r = O(t);
868
- let i = null;
1814
+ const e = Z(t);
1815
+ let n = null;
869
1816
  try {
870
- i = await this.getDirectoryHandle(P(t), !1);
871
- } catch (n) {
872
- throw (n.name === "NotFoundError" || n.name === "TypeMismatchError") && (i = null), n;
1817
+ n = await this.getDirectoryHandle(X(t), !1);
1818
+ } catch (i) {
1819
+ throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
873
1820
  }
874
- if (!i || !r)
1821
+ if (!n || !e)
875
1822
  return !1;
876
1823
  try {
877
- return await i.getFileHandle(r, { create: !1 }), !0;
878
- } catch (n) {
879
- if (n.name !== "NotFoundError" && n.name !== "TypeMismatchError")
880
- throw n;
1824
+ return await n.getFileHandle(e, { create: !1 }), !0;
1825
+ } catch (i) {
1826
+ if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1827
+ throw i;
881
1828
  }
882
1829
  try {
883
- return await i.getDirectoryHandle(r, { create: !1 }), !0;
884
- } catch (n) {
885
- if (n.name !== "NotFoundError" && n.name !== "TypeMismatchError")
886
- throw n;
1830
+ return await n.getDirectoryHandle(e, { create: !1 }), !0;
1831
+ } catch (i) {
1832
+ if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1833
+ throw i;
887
1834
  }
888
1835
  return !1;
889
1836
  }
@@ -907,16 +1854,16 @@ class wt {
907
1854
  * \`\`\`
908
1855
  */
909
1856
  async clear(t = "/") {
910
- await this.ensureMounted();
1857
+ await this.mount();
911
1858
  try {
912
- const r = await this.readDir(t);
913
- for (const i of r) {
914
- const n = \`\${t === "/" ? "" : t}/\${i.name}\`;
915
- await this.remove(n, { recursive: !0 });
1859
+ const e = await this.readDir(t);
1860
+ for (const n of e) {
1861
+ const i = \`\${t === "/" ? "" : t}/\${n.name}\`;
1862
+ await this.remove(i, { recursive: !0 });
916
1863
  }
917
1864
  await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
918
- } catch (r) {
919
- throw r instanceof c ? r : new c(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED");
1865
+ } catch (e) {
1866
+ throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED");
920
1867
  }
921
1868
  }
922
1869
  /**
@@ -943,22 +1890,22 @@ class wt {
943
1890
  * await fs.rm('/maybe/exists', { force: true });
944
1891
  * \`\`\`
945
1892
  */
946
- async remove(t, r) {
947
- await this.ensureMounted();
948
- const i = r?.recursive ?? !1, n = r?.force ?? !1;
1893
+ async remove(t, e) {
1894
+ await this.mount();
1895
+ const n = e?.recursive ?? !1, i = e?.force ?? !1;
949
1896
  if (t === "/")
950
- throw new c("Cannot remove root directory", "EROOT");
951
- const a = O(t);
952
- if (!a)
953
- throw new N("Invalid path", t);
954
- const s = await this.getDirectoryHandle(P(t), !1);
1897
+ throw new g("Cannot remove root directory", "EROOT");
1898
+ const r = Z(t);
1899
+ if (!r)
1900
+ throw new ht("Invalid path", t);
1901
+ const o = await this.getDirectoryHandle(X(t), !1);
955
1902
  try {
956
- await s.removeEntry(a, { recursive: i });
957
- } catch (o) {
958
- if (o.name === "NotFoundError") {
959
- if (!n)
960
- throw new c(\`No such file or directory: \${t}\`, "ENOENT");
961
- } else throw o.name === "InvalidModificationError" ? new c(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : o.name === "TypeMismatchError" && !i ? new c(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new c(\`Failed to remove path: \${t}\`, "RM_FAILED");
1903
+ await o.removeEntry(r, { recursive: n });
1904
+ } catch (a) {
1905
+ if (a.name === "NotFoundError") {
1906
+ if (!i)
1907
+ throw new g(\`No such file or directory: \${t}\`, "ENOENT");
1908
+ } else throw a.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : a.name === "TypeMismatchError" && !n ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new g(\`Failed to remove path: \${t}\`, "RM_FAILED");
962
1909
  }
963
1910
  await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
964
1911
  }
@@ -981,14 +1928,14 @@ class wt {
981
1928
  * \`\`\`
982
1929
  */
983
1930
  async realpath(t) {
984
- await this.ensureMounted();
1931
+ await this.mount();
985
1932
  try {
986
- const r = ct(t);
987
- if (!await this.exists(r))
988
- throw new T(r);
989
- return r;
990
- } catch (r) {
991
- throw r instanceof c ? r : new c(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
1933
+ const e = Je(t);
1934
+ if (!await this.exists(e))
1935
+ throw new V(e);
1936
+ return e;
1937
+ } catch (e) {
1938
+ throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
992
1939
  }
993
1940
  }
994
1941
  /**
@@ -1007,14 +1954,14 @@ class wt {
1007
1954
  * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
1008
1955
  * \`\`\`
1009
1956
  */
1010
- async rename(t, r) {
1011
- await this.ensureMounted();
1957
+ async rename(t, e) {
1958
+ await this.mount();
1012
1959
  try {
1013
1960
  if (!await this.exists(t))
1014
- throw new T(t);
1015
- await this.copy(t, r, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: r, type: "added", isDirectory: !1 });
1016
- } catch (i) {
1017
- throw i instanceof c ? i : new c(\`Failed to rename from \${t} to \${r}\`, "RENAME_FAILED");
1961
+ throw new V(t);
1962
+ await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
1963
+ } catch (n) {
1964
+ throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED");
1018
1965
  }
1019
1966
  }
1020
1967
  /**
@@ -1042,39 +1989,57 @@ class wt {
1042
1989
  * await fs.copy('/source', '/dest', { recursive: true, force: false });
1043
1990
  * \`\`\`
1044
1991
  */
1045
- async copy(t, r, i) {
1046
- await this.ensureMounted();
1992
+ async copy(t, e, n) {
1993
+ await this.mount();
1047
1994
  try {
1048
- const n = i?.recursive ?? !1, a = i?.force ?? !0;
1995
+ const i = n?.recursive ?? !1, r = n?.force ?? !0;
1049
1996
  if (!await this.exists(t))
1050
- throw new c(\`Source does not exist: \${t}\`, "ENOENT");
1051
- if (await this.exists(r) && !a)
1052
- throw new c(\`Destination already exists: \${r}\`, "EEXIST");
1997
+ throw new g(\`Source does not exist: \${t}\`, "ENOENT");
1998
+ if (await this.exists(e) && !r)
1999
+ throw new g(\`Destination already exists: \${e}\`, "EEXIST");
1053
2000
  if ((await this.stat(t)).isFile) {
1054
- const h = await this.readFile(t, "binary");
1055
- await this.writeFile(r, h);
2001
+ const l = await this.readFile(t, "binary");
2002
+ await this.writeFile(e, l);
1056
2003
  } else {
1057
- if (!n)
1058
- throw new c(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR");
1059
- await this.mkdir(r, { recursive: !0 });
1060
- const h = await this.readDir(t);
1061
- for (const u of h) {
1062
- const w = \`\${t}/\${u.name}\`, f = \`\${r}/\${u.name}\`;
1063
- await this.copy(w, f, { recursive: !0, force: a });
2004
+ if (!i)
2005
+ throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR");
2006
+ await this.mkdir(e, { recursive: !0 });
2007
+ const l = await this.readDir(t);
2008
+ for (const h of l) {
2009
+ const f = \`\${t}/\${h.name}\`, u = \`\${e}/\${h.name}\`;
2010
+ await this.copy(f, u, { recursive: !0, force: r });
1064
2011
  }
1065
2012
  }
1066
- await this.notifyChange({ path: r, type: "added", isDirectory: !1 });
1067
- } catch (n) {
1068
- throw n instanceof c ? n : new c(\`Failed to copy from \${t} to \${r}\`, "CP_FAILED");
2013
+ await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
2014
+ } catch (i) {
2015
+ throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED");
1069
2016
  }
1070
2017
  }
1071
2018
  /**
1072
2019
  * Start watching a file or directory for changes
2020
+ *
2021
+ * @param path - The path to watch
2022
+ * @param options - Watch options
2023
+ * @param options.recursive - Whether to watch recursively (default: true)
2024
+ * @param options.excludes - Glob pattern(s) to exclude (minimatch).
2025
+ * @returns Promise that resolves when watching starts
2026
+ *
2027
+ * @example
2028
+ * \`\`\`typescript
2029
+ * // Watch entire directory tree recursively (default)
2030
+ * await fs.watch('/data');
2031
+ *
2032
+ * // Watch only immediate children (shallow)
2033
+ * await fs.watch('/data', { recursive: false });
2034
+ *
2035
+ * // Watch a single file
2036
+ * await fs.watch('/config.json', { recursive: false });
2037
+ * \`\`\`
1073
2038
  */
1074
- async watch(t) {
1075
- await this.ensureMounted();
1076
- const r = F(t), i = await this.buildSnapshot(r);
1077
- this.watchers.set(r, i), this.watchTimer || (this.watchTimer = setInterval(() => {
2039
+ async watch(t, e) {
2040
+ await this.mount();
2041
+ const n = T(t), i = { recursive: !0, ...e }, r = await this.buildSnapshot(n, i);
2042
+ this.watchers.set(n, { snapshot: r, options: i }), this.watchTimer || (this.watchTimer = setInterval(() => {
1078
2043
  this.scanWatches();
1079
2044
  }, this.options.watchInterval));
1080
2045
  }
@@ -1082,8 +2047,8 @@ class wt {
1082
2047
  * Stop watching a previously watched path
1083
2048
  */
1084
2049
  unwatch(t) {
1085
- const r = F(t);
1086
- this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
2050
+ const e = T(t);
2051
+ this.watchers.delete(e), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
1087
2052
  }
1088
2053
  /**
1089
2054
  * Dispose of resources and clean up the file system instance
@@ -1094,41 +2059,45 @@ class wt {
1094
2059
  dispose() {
1095
2060
  this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null), this.watchers.clear();
1096
2061
  }
1097
- async buildSnapshot(t) {
1098
- const r = /* @__PURE__ */ new Map(), i = async (n) => {
1099
- const a = await this.stat(n);
1100
- if (r.set(n, a), a.isDirectory) {
1101
- const s = await this.readDir(n);
1102
- for (const o of s) {
1103
- const l = \`\${n === "/" ? "" : n}/\${o.name}\`;
1104
- await i(l);
2062
+ async buildSnapshot(t, e) {
2063
+ const n = /* @__PURE__ */ new Map(), i = e?.recursive ?? !0, r = e?.excludes, o = async (c) => {
2064
+ const l = await this.stat(c);
2065
+ return n.set(c, l), l;
2066
+ }, a = async (c) => {
2067
+ if (L(c, r))
2068
+ return;
2069
+ if ((await o(c)).isDirectory) {
2070
+ const h = await this.readDir(c);
2071
+ for (const f of h) {
2072
+ const u = \`\${c === "/" ? "" : c}/\${f.name}\`;
2073
+ i ? await a(u) : L(u, r) || await o(u);
1105
2074
  }
1106
2075
  }
1107
2076
  };
1108
- return await i(t), r;
2077
+ return await a(t), n;
1109
2078
  }
1110
2079
  async scanWatches() {
1111
2080
  if (!this.scanning) {
1112
2081
  this.scanning = !0;
1113
2082
  try {
1114
2083
  await Promise.all(
1115
- [...this.watchers.entries()].map(async ([t, r]) => {
2084
+ [...this.watchers.entries()].map(async ([t, { snapshot: e, options: n }]) => {
1116
2085
  let i;
1117
2086
  try {
1118
- i = await this.buildSnapshot(t);
2087
+ i = await this.buildSnapshot(t, n);
1119
2088
  } catch {
1120
2089
  i = /* @__PURE__ */ new Map();
1121
2090
  }
1122
- for (const [n, a] of i) {
1123
- const s = r.get(n);
1124
- s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: n, type: "changed", isDirectory: a.isDirectory }) : await this.notifyChange({ path: n, type: "added", isDirectory: a.isDirectory });
2091
+ for (const [r, o] of i) {
2092
+ const a = e.get(r);
2093
+ L(r, n.excludes) || (a ? (a.mtime !== o.mtime || a.size !== o.size) && await this.notifyChange({ path: r, type: "changed", isDirectory: o.isDirectory }) : await this.notifyChange({ path: r, type: "added", isDirectory: o.isDirectory }));
1125
2094
  }
1126
- for (const n of r.keys())
1127
- if (!i.has(n)) {
1128
- const a = r.get(n);
1129
- await this.notifyChange({ path: n, type: "removed", isDirectory: a?.isDirectory ?? !1 });
2095
+ for (const r of e.keys())
2096
+ if (!L(r, n.excludes) && !i.has(r)) {
2097
+ const o = e.get(r);
2098
+ await this.notifyChange({ path: r, type: "removed", isDirectory: o?.isDirectory ?? !1 });
1130
2099
  }
1131
- this.watchers.set(t, i);
2100
+ this.watchers.set(t, { snapshot: i, options: n });
1132
2101
  })
1133
2102
  );
1134
2103
  } finally {
@@ -1164,28 +2133,28 @@ class wt {
1164
2133
  * await fs.sync(entries, { cleanBefore: true });
1165
2134
  * \`\`\`
1166
2135
  */
1167
- async sync(t, r) {
1168
- await this.ensureMounted();
2136
+ async sync(t, e) {
2137
+ await this.mount();
1169
2138
  try {
1170
- (r?.cleanBefore ?? !1) && await this.clear("/");
1171
- for (const [n, a] of t) {
1172
- const s = F(n);
1173
- let o;
1174
- a instanceof Blob ? o = await ft(a) : o = a, await this.writeFile(s, o);
2139
+ (e?.cleanBefore ?? !1) && await this.clear("/");
2140
+ for (const [i, r] of t) {
2141
+ const o = T(i);
2142
+ let a;
2143
+ r instanceof Blob ? a = await es(r) : a = r, await this.writeFile(o, a);
1175
2144
  }
1176
2145
  await this.notifyChange({ path: "/", type: "changed", isDirectory: !0 });
1177
- } catch (i) {
1178
- throw i instanceof c ? i : new c("Failed to sync file system", "SYNC_FAILED");
2146
+ } catch (n) {
2147
+ throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED");
1179
2148
  }
1180
2149
  }
1181
2150
  }
1182
- typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && x(new wt());
1183
- //# sourceMappingURL=worker-CLK22qZk.js.map
1184
- `, r = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", a], { type: "text/javascript;charset=utf-8" });
2151
+ typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && J(new ss());
2152
+ //# sourceMappingURL=worker-Bra0Mewp.js.map
2153
+ `, s = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", r], { type: "text/javascript;charset=utf-8" });
1185
2154
  function o(t) {
1186
2155
  let n;
1187
2156
  try {
1188
- if (n = r && (self.URL || self.webkitURL).createObjectURL(r), !n) throw "";
2157
+ if (n = s && (self.URL || self.webkitURL).createObjectURL(s), !n) throw "";
1189
2158
  const e = new Worker(n, {
1190
2159
  type: "module",
1191
2160
  name: t?.name
@@ -1195,7 +2164,7 @@ function o(t) {
1195
2164
  }), e;
1196
2165
  } catch {
1197
2166
  return new Worker(
1198
- "data:text/javascript;charset=utf-8," + encodeURIComponent(a),
2167
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(r),
1199
2168
  {
1200
2169
  type: "module",
1201
2170
  name: t?.name
@@ -1203,35 +2172,36 @@ function o(t) {
1203
2172
  );
1204
2173
  }
1205
2174
  }
1206
- function c(t) {
2175
+ function h(t) {
1207
2176
  const n = i(new o());
1208
2177
  return t && n.setOptions(t), n;
1209
2178
  }
1210
2179
  export {
1211
- d as DirectoryNotFoundError,
2180
+ p as DirectoryNotFoundError,
1212
2181
  f as FileNotFoundError,
1213
- p as OPFSError,
2182
+ d as OPFSError,
1214
2183
  u as OPFSNotMountedError,
1215
- y as OPFSNotSupportedError,
2184
+ g as OPFSNotSupportedError,
1216
2185
  m as PathError,
1217
2186
  w as PermissionError,
1218
- g as StorageError,
1219
- v as TimeoutError,
1220
- b as basename,
1221
- E as calculateFileHash,
1222
- S as checkOPFSSupport,
1223
- F as convertBlobToUint8Array,
2187
+ y as StorageError,
2188
+ b as TimeoutError,
2189
+ v as basename,
2190
+ S as calculateFileHash,
2191
+ E as checkOPFSSupport,
2192
+ x as convertBlobToUint8Array,
1224
2193
  P as createBuffer,
1225
- c as createWorker,
1226
- x as decodeBuffer,
1227
- D as dirname,
1228
- C as encodeString,
1229
- T as extname,
1230
- A as joinPath,
1231
- O as normalizePath,
1232
- _ as readFileData,
1233
- I as resolvePath,
1234
- U as splitPath,
1235
- R as writeFileData
2194
+ h as createWorker,
2195
+ A as decodeBuffer,
2196
+ F as dirname,
2197
+ O as encodeString,
2198
+ C as extname,
2199
+ T as isPathExcluded,
2200
+ _ as joinPath,
2201
+ D as normalizePath,
2202
+ R as readFileData,
2203
+ $ as resolvePath,
2204
+ I as splitPath,
2205
+ M as writeFileData
1236
2206
  };
1237
2207
  //# sourceMappingURL=index.js.map