opfs-worker 0.4.2 → 0.5.1

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,21 +1,21 @@
1
1
  import { wrap as i } from "comlink";
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";
2
+ import { B as p, D as f, F as d, O as u, b as g, a as m, P as w, c as y, S as b, T as v, e as x, t as S, q as E, d as A, u as P, l as F, y as O, f as C, x as T, k as R, i as $, h as _, j as D, m as I, g as j, n as N, o as M, v as k, r as L, s as z, w as U, p as W } from "./helpers-DcIl7KL0.js";
3
3
  const r = `/**
4
4
  * @license
5
5
  * Copyright 2019 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
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 = {
8
+ const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ft = (s) => typeof s == "object" && s !== null || typeof s == "function", Ft = {
9
9
  canHandle: (s) => ft(s) && s[ut],
10
10
  serialize(s) {
11
11
  const { port1: t, port2: e } = new MessageChannel();
12
12
  return J(s, t), [e, [e]];
13
13
  },
14
14
  deserialize(s) {
15
- return s.start(), $t(s);
15
+ return s.start(), Pt(s);
16
16
  }
17
- }, Pt = {
18
- canHandle: (s) => ft(s) && z in s,
17
+ }, Tt = {
18
+ canHandle: (s) => ft(s) && L in s,
19
19
  serialize({ value: s }) {
20
20
  let t;
21
21
  return s instanceof Error ? t = {
@@ -31,10 +31,10 @@ const ut = Symbol("Comlink.proxy"), Tt = Symbol("Comlink.endpoint"), Ft = Symbol
31
31
  throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
32
32
  }
33
33
  }, dt = /* @__PURE__ */ new Map([
34
- ["proxy", Nt],
35
- ["throw", Pt]
34
+ ["proxy", Ft],
35
+ ["throw", Tt]
36
36
  ]);
37
- function vt(s, t) {
37
+ function Mt(s, t) {
38
38
  for (const e of s)
39
39
  if (t === e || e === "*" || e instanceof RegExp && e.test(t))
40
40
  return !0;
@@ -44,64 +44,64 @@ function J(s, t = globalThis, e = ["*"]) {
44
44
  t.addEventListener("message", function n(i) {
45
45
  if (!i || !i.data)
46
46
  return;
47
- if (!vt(e, i.origin)) {
47
+ if (!Mt(e, i.origin)) {
48
48
  console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
49
49
  return;
50
50
  }
51
- const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), c = (i.data.argumentList || []).map(C);
52
- let l;
51
+ const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(C);
52
+ let h;
53
53
  try {
54
- const h = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
54
+ const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
55
55
  switch (o) {
56
56
  case "GET":
57
- l = f;
57
+ h = f;
58
58
  break;
59
59
  case "SET":
60
- h[a.slice(-1)[0]] = C(i.data.value), l = !0;
60
+ c[a.slice(-1)[0]] = C(i.data.value), h = !0;
61
61
  break;
62
62
  case "APPLY":
63
- l = f.apply(h, c);
63
+ h = f.apply(c, l);
64
64
  break;
65
65
  case "CONSTRUCT":
66
66
  {
67
- const u = new f(...c);
68
- l = zt(u);
67
+ const u = new f(...l);
68
+ h = zt(u);
69
69
  }
70
70
  break;
71
71
  case "ENDPOINT":
72
72
  {
73
73
  const { port1: u, port2: d } = new MessageChannel();
74
- J(s, d), l = Lt(u, [u]);
74
+ J(s, d), h = It(u, [u]);
75
75
  }
76
76
  break;
77
77
  case "RELEASE":
78
- l = void 0;
78
+ h = void 0;
79
79
  break;
80
80
  default:
81
81
  return;
82
82
  }
83
- } catch (h) {
84
- l = { value: h, [z]: 0 };
83
+ } catch (c) {
84
+ h = { value: c, [L]: 0 };
85
85
  }
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({
86
+ Promise.resolve(h).catch((c) => ({ value: c, [L]: 0 })).then((c) => {
87
+ const [f, u] = H(c);
88
+ t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), pt(t), U in s && typeof s[U] == "function" && s[U]());
89
+ }).catch((c) => {
90
+ const [f, u] = H({
91
91
  value: new TypeError("Unserializable return value"),
92
- [z]: 0
92
+ [L]: 0
93
93
  });
94
94
  t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
95
95
  });
96
96
  }), t.start && t.start();
97
97
  }
98
- function Mt(s) {
98
+ function $t(s) {
99
99
  return s.constructor.name === "MessagePort";
100
100
  }
101
101
  function pt(s) {
102
- Mt(s) && s.close();
102
+ $t(s) && s.close();
103
103
  }
104
- function $t(s, t) {
104
+ function Pt(s, t) {
105
105
  const e = /* @__PURE__ */ new Map();
106
106
  return s.addEventListener("message", function(i) {
107
107
  const { data: r } = i;
@@ -114,9 +114,9 @@ function $t(s, t) {
114
114
  } finally {
115
115
  e.delete(r.id);
116
116
  }
117
- }), Y(s, e, [], t);
117
+ }), X(s, e, [], t);
118
118
  }
119
- function I(s) {
119
+ function R(s) {
120
120
  if (s)
121
121
  throw new Error("Proxy has been released and is not useable");
122
122
  }
@@ -127,89 +127,89 @@ function gt(s) {
127
127
  pt(s);
128
128
  });
129
129
  }
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);
130
+ const I = /* @__PURE__ */ new WeakMap(), z = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
131
+ const t = (I.get(s) || 0) - 1;
132
+ I.set(s, t), t === 0 && gt(s);
133
133
  });
134
134
  function Rt(s, t) {
135
- const e = (W.get(t) || 0) + 1;
136
- W.set(t, e), H && H.register(s, t, s);
135
+ const e = (I.get(t) || 0) + 1;
136
+ I.set(t, e), z && z.register(s, t, s);
137
137
  }
138
- function It(s) {
139
- H && H.unregister(s);
138
+ function kt(s) {
139
+ z && z.unregister(s);
140
140
  }
141
- function Y(s, t, e = [], n = function() {
141
+ function X(s, t, e = [], n = function() {
142
142
  }) {
143
143
  let i = !1;
144
144
  const r = new Proxy(n, {
145
145
  get(o, a) {
146
- if (I(i), a === Ft)
146
+ if (R(i), a === Nt)
147
147
  return () => {
148
- It(r), gt(s), t.clear(), i = !0;
148
+ kt(r), gt(s), t.clear(), i = !0;
149
149
  };
150
150
  if (a === "then") {
151
151
  if (e.length === 0)
152
152
  return { then: () => r };
153
- const c = O(s, t, {
153
+ const l = O(s, t, {
154
154
  type: "GET",
155
- path: e.map((l) => l.toString())
155
+ path: e.map((h) => h.toString())
156
156
  }).then(C);
157
- return c.then.bind(c);
157
+ return l.then.bind(l);
158
158
  }
159
- return Y(s, t, [...e, a]);
159
+ return X(s, t, [...e, a]);
160
160
  },
161
- set(o, a, c) {
162
- I(i);
163
- const [l, h] = j(c);
161
+ set(o, a, l) {
162
+ R(i);
163
+ const [h, c] = H(l);
164
164
  return O(s, t, {
165
165
  type: "SET",
166
166
  path: [...e, a].map((f) => f.toString()),
167
- value: l
168
- }, h).then(C);
167
+ value: h
168
+ }, c).then(C);
169
169
  },
170
- apply(o, a, c) {
171
- I(i);
172
- const l = e[e.length - 1];
173
- if (l === Tt)
170
+ apply(o, a, l) {
171
+ R(i);
172
+ const h = e[e.length - 1];
173
+ if (h === Dt)
174
174
  return O(s, t, {
175
175
  type: "ENDPOINT"
176
176
  }).then(C);
177
- if (l === "bind")
178
- return Y(s, t, e.slice(0, -1));
179
- const [h, f] = et(c);
177
+ if (h === "bind")
178
+ return X(s, t, e.slice(0, -1));
179
+ const [c, f] = st(l);
180
180
  return O(s, t, {
181
181
  type: "APPLY",
182
182
  path: e.map((u) => u.toString()),
183
- argumentList: h
183
+ argumentList: c
184
184
  }, f).then(C);
185
185
  },
186
186
  construct(o, a) {
187
- I(i);
188
- const [c, l] = et(a);
187
+ R(i);
188
+ const [l, h] = st(a);
189
189
  return O(s, t, {
190
190
  type: "CONSTRUCT",
191
- path: e.map((h) => h.toString()),
192
- argumentList: c
193
- }, l).then(C);
191
+ path: e.map((c) => c.toString()),
192
+ argumentList: l
193
+ }, h).then(C);
194
194
  }
195
195
  });
196
196
  return Rt(r, s), r;
197
197
  }
198
- function kt(s) {
198
+ function Lt(s) {
199
199
  return Array.prototype.concat.apply([], s);
200
200
  }
201
- function et(s) {
202
- const t = s.map(j);
203
- return [t.map((e) => e[0]), kt(t.map((e) => e[1]))];
201
+ function st(s) {
202
+ const t = s.map(H);
203
+ return [t.map((e) => e[0]), Lt(t.map((e) => e[1]))];
204
204
  }
205
- const wt = /* @__PURE__ */ new WeakMap();
206
- function Lt(s, t) {
207
- return wt.set(s, t), s;
205
+ const mt = /* @__PURE__ */ new WeakMap();
206
+ function It(s, t) {
207
+ return mt.set(s, t), s;
208
208
  }
209
209
  function zt(s) {
210
210
  return Object.assign(s, { [ut]: !0 });
211
211
  }
212
- function j(s) {
212
+ function H(s) {
213
213
  for (const [t, e] of dt)
214
214
  if (e.canHandle(s)) {
215
215
  const [n, i] = e.serialize(s);
@@ -227,7 +227,7 @@ function j(s) {
227
227
  type: "RAW",
228
228
  value: s
229
229
  },
230
- wt.get(s) || []
230
+ mt.get(s) || []
231
231
  ];
232
232
  }
233
233
  function C(s) {
@@ -240,15 +240,108 @@ function C(s) {
240
240
  }
241
241
  function O(s, t, e, n) {
242
242
  return new Promise((i) => {
243
- const r = Wt();
243
+ const r = Ht();
244
244
  t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
245
245
  });
246
246
  }
247
- function Wt() {
247
+ function Ht() {
248
248
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
249
249
  }
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);
250
+ class g extends Error {
251
+ constructor(t, e, n, i) {
252
+ super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
253
+ }
254
+ }
255
+ class Wt extends g {
256
+ constructor(t) {
257
+ super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, t);
258
+ }
259
+ }
260
+ class jt extends g {
261
+ constructor(t, e, n) {
262
+ super(t, "INVALID_PATH", e, n);
263
+ }
264
+ }
265
+ class _ extends g {
266
+ constructor(t, e) {
267
+ super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
268
+ }
269
+ }
270
+ function Ut(s, t = "utf-8") {
271
+ switch (t) {
272
+ case "utf8":
273
+ case "utf-8":
274
+ return new TextEncoder().encode(s);
275
+ case "utf16le":
276
+ case "ucs2":
277
+ case "ucs-2":
278
+ return Bt(s);
279
+ case "ascii":
280
+ return Vt(s);
281
+ case "latin1":
282
+ return qt(s);
283
+ case "binary":
284
+ return Uint8Array.from(s, (e) => e.charCodeAt(0));
285
+ case "base64":
286
+ return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
287
+ case "hex":
288
+ if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
289
+ throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
290
+ return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
291
+ default:
292
+ return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
293
+ }
294
+ }
295
+ function _t(s, t = "utf-8") {
296
+ switch (t) {
297
+ case "utf8":
298
+ case "utf-8":
299
+ return new TextDecoder().decode(s);
300
+ case "utf16le":
301
+ case "ucs2":
302
+ case "ucs-2":
303
+ return Gt(s);
304
+ case "latin1":
305
+ return String.fromCharCode(...s);
306
+ case "binary":
307
+ return String.fromCharCode(...s);
308
+ case "ascii":
309
+ return String.fromCharCode(...s.map((e) => e & 127));
310
+ case "base64":
311
+ return btoa(String.fromCharCode(...s));
312
+ case "hex":
313
+ return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
314
+ default:
315
+ return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
316
+ }
317
+ }
318
+ function Bt(s) {
319
+ const t = new Uint8Array(s.length * 2);
320
+ for (let e = 0; e < s.length; e++) {
321
+ const n = s.charCodeAt(e);
322
+ t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
323
+ }
324
+ return t;
325
+ }
326
+ function Gt(s) {
327
+ s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
328
+ const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
329
+ return String.fromCharCode(...t);
330
+ }
331
+ function qt(s) {
332
+ const t = new Uint8Array(s.length);
333
+ for (let e = 0; e < s.length; e++)
334
+ t[e] = s.charCodeAt(e) & 255;
335
+ return t;
336
+ }
337
+ function Vt(s) {
338
+ const t = new Uint8Array(s.length);
339
+ for (let e = 0; e < s.length; e++)
340
+ t[e] = s.charCodeAt(e) & 127;
341
+ return t;
342
+ }
343
+ const wt = (s, t, e) => {
344
+ const n = s instanceof RegExp ? nt(s, e) : s, i = t instanceof RegExp ? nt(t, e) : t, r = n !== null && i != null && Xt(n, i, e);
252
345
  return r && {
253
346
  start: r[0],
254
347
  end: r[1],
@@ -256,65 +349,65 @@ const mt = (s, t, e) => {
256
349
  body: e.slice(r[0] + n.length, r[1]),
257
350
  post: e.slice(r[1] + i.length)
258
351
  };
259
- }, st = (s, t) => {
352
+ }, nt = (s, t) => {
260
353
  const e = t.match(s);
261
354
  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) {
355
+ }, Xt = (s, t, e) => {
356
+ let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
357
+ if (l >= 0 && h > 0) {
265
358
  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);
359
+ return [l, h];
360
+ for (n = [], r = e.length; c >= 0 && !a; ) {
361
+ if (c === l)
362
+ n.push(c), l = e.indexOf(s, c + 1);
270
363
  else if (n.length === 1) {
271
364
  const f = n.pop();
272
- f !== void 0 && (a = [f, l]);
365
+ f !== void 0 && (a = [f, h]);
273
366
  } 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;
367
+ i = n.pop(), i !== void 0 && i < r && (r = i, o = h), h = e.indexOf(t, c + 1);
368
+ c = l < h && l >= 0 ? l : h;
276
369
  }
277
370
  n.length && o !== void 0 && (a = [r, o]);
278
371
  }
279
372
  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) {
373
+ }, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0", bt = "\\0PERIOD" + Math.random() + "\\0", Yt = new RegExp(yt, "g"), Zt = new RegExp(Et, "g"), Jt = new RegExp(K, "g"), Kt = new RegExp(St, "g"), Qt = new RegExp(bt, "g"), te = /\\\\\\\\/g, ee = /\\\\{/g, se = /\\\\}/g, ne = /\\\\,/g, ie = /\\\\./g;
374
+ function B(s) {
282
375
  return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
283
376
  }
284
- function Jt(s) {
285
- return s.replace(qt, yt).replace(Vt, Et).replace(Zt, K).replace(Xt, St).replace(Yt, xt);
377
+ function re(s) {
378
+ return s.replace(te, yt).replace(ee, Et).replace(se, K).replace(ne, St).replace(ie, bt);
286
379
  }
287
- function Kt(s) {
288
- return s.replace(jt, "\\\\").replace(Ut, "{").replace(_t, "}").replace(Bt, ",").replace(Gt, ".");
380
+ function oe(s) {
381
+ return s.replace(Yt, "\\\\").replace(Zt, "{").replace(Jt, "}").replace(Kt, ",").replace(Qt, ".");
289
382
  }
290
- function bt(s) {
383
+ function xt(s) {
291
384
  if (!s)
292
385
  return [""];
293
- const t = [], e = mt("{", "}", s);
386
+ const t = [], e = wt("{", "}", s);
294
387
  if (!e)
295
388
  return s.split(",");
296
389
  const { pre: n, body: i, post: r } = e, o = n.split(",");
297
390
  o[o.length - 1] += "{" + i + "}";
298
- const a = bt(r);
391
+ const a = xt(r);
299
392
  return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
300
393
  }
301
- function Qt(s) {
302
- return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(Jt(s), !0).map(Kt)) : [];
394
+ function ae(s) {
395
+ return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(re(s), !0).map(oe)) : [];
303
396
  }
304
- function te(s) {
397
+ function ce(s) {
305
398
  return "{" + s + "}";
306
399
  }
307
- function ee(s) {
400
+ function le(s) {
308
401
  return /^-?0\\d/.test(s);
309
402
  }
310
- function se(s, t) {
403
+ function he(s, t) {
311
404
  return s <= t;
312
405
  }
313
- function ne(s, t) {
406
+ function ue(s, t) {
314
407
  return s >= t;
315
408
  }
316
409
  function M(s, t) {
317
- const e = [], n = mt("{", "}", s);
410
+ const e = [], n = wt("{", "}", s);
318
411
  if (!n)
319
412
  return [s];
320
413
  const i = n.pre, r = n.post.length ? M(n.post, !1) : [""];
@@ -324,53 +417,53 @@ function M(s, t) {
324
417
  e.push(a);
325
418
  }
326
419
  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)
420
+ const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
421
+ if (!l && !h)
329
422
  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);
423
+ let c;
424
+ if (l)
425
+ c = n.body.split(/\\.\\./);
426
+ else if (c = xt(n.body), c.length === 1 && c[0] !== void 0 && (c = M(c[0], !1).map(ce), c.length === 1))
427
+ return r.map((u) => n.pre + c[0] + u);
335
428
  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);
429
+ if (l && c[0] !== void 0 && c[1] !== void 0) {
430
+ const u = B(c[0]), d = B(c[1]), m = Math.max(c[0].length, c[1].length);
431
+ let p = c.length === 3 && c[2] !== void 0 ? Math.abs(B(c[2])) : 1, S = he;
432
+ d < u && (p *= -1, S = ue);
433
+ const N = c.some(le);
341
434
  f = [];
342
- for (let x = u; S(x, d); x += p) {
343
- let m;
435
+ for (let b = u; S(b, d); b += p) {
436
+ let w;
344
437
  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;
438
+ w = String.fromCharCode(b), w === "\\\\" && (w = "");
439
+ else if (w = String(b), N) {
440
+ const F = m - w.length;
441
+ if (F > 0) {
442
+ const P = new Array(F + 1).join("0");
443
+ b < 0 ? w = "-" + P + w.slice(1) : w = P + w;
351
444
  }
352
445
  }
353
- f.push(m);
446
+ f.push(w);
354
447
  }
355
448
  } else {
356
449
  f = [];
357
- for (let u = 0; u < h.length; u++)
358
- f.push.apply(f, M(h[u], !1));
450
+ for (let u = 0; u < c.length; u++)
451
+ f.push.apply(f, M(c[u], !1));
359
452
  }
360
453
  for (let u = 0; u < f.length; u++)
361
454
  for (let d = 0; d < r.length; d++) {
362
- const w = i + f[u] + r[d];
363
- (!t || c || w) && e.push(w);
455
+ const m = i + f[u] + r[d];
456
+ (!t || l || m) && e.push(m);
364
457
  }
365
458
  }
366
459
  return e;
367
460
  }
368
- const ie = 1024 * 64, U = (s) => {
461
+ const fe = 1024 * 64, W = (s) => {
369
462
  if (typeof s != "string")
370
463
  throw new TypeError("invalid pattern");
371
- if (s.length > ie)
464
+ if (s.length > fe)
372
465
  throw new TypeError("pattern is too long");
373
- }, re = {
466
+ }, de = {
374
467
  "[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
375
468
  "[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
376
469
  "[:ascii:]": ["\\\\x00-\\\\x7f", !1],
@@ -385,60 +478,60 @@ const ie = 1024 * 64, U = (s) => {
385
478
  "[:upper:]": ["\\\\p{Lu}", !0],
386
479
  "[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
387
480
  "[: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) => {
481
+ }, T = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), pe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), it = (s) => s.join(""), ge = (s, t) => {
389
482
  const e = t;
390
483
  if (s.charAt(e) !== "[")
391
484
  throw new Error("not in a brace expression");
392
485
  const n = [], i = [];
393
- let r = e + 1, o = !1, a = !1, c = !1, l = !1, h = e, f = "";
486
+ let r = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
394
487
  t: for (; r < s.length; ) {
395
488
  const p = s.charAt(r);
396
489
  if ((p === "!" || p === "^") && r === e + 1) {
397
- l = !0, r++;
490
+ h = !0, r++;
398
491
  continue;
399
492
  }
400
- if (p === "]" && o && !c) {
401
- h = r + 1;
493
+ if (p === "]" && o && !l) {
494
+ c = r + 1;
402
495
  break;
403
496
  }
404
- if (o = !0, p === "\\\\" && !c) {
405
- c = !0, r++;
497
+ if (o = !0, p === "\\\\" && !l) {
498
+ l = !0, r++;
406
499
  continue;
407
500
  }
408
- if (p === "[" && !c) {
409
- for (const [S, [D, N, x]] of Object.entries(re))
501
+ if (p === "[" && !l) {
502
+ for (const [S, [v, N, b]] of Object.entries(de))
410
503
  if (s.startsWith(S, r)) {
411
504
  if (f)
412
505
  return ["$.", !1, s.length - e, !0];
413
- r += S.length, x ? i.push(D) : n.push(D), a = a || N;
506
+ r += S.length, b ? i.push(v) : n.push(v), a = a || N;
414
507
  continue t;
415
508
  }
416
509
  }
417
- if (c = !1, f) {
418
- p > f ? n.push(v(f) + "-" + v(p)) : p === f && n.push(v(p)), f = "", r++;
510
+ if (l = !1, f) {
511
+ p > f ? n.push(T(f) + "-" + T(p)) : p === f && n.push(T(p)), f = "", r++;
419
512
  continue;
420
513
  }
421
514
  if (s.startsWith("-]", r + 1)) {
422
- n.push(v(p + "-")), r += 2;
515
+ n.push(T(p + "-")), r += 2;
423
516
  continue;
424
517
  }
425
518
  if (s.startsWith("-", r + 1)) {
426
519
  f = p, r += 2;
427
520
  continue;
428
521
  }
429
- n.push(v(p)), r++;
522
+ n.push(T(p)), r++;
430
523
  }
431
- if (h < r)
524
+ if (c < r)
432
525
  return ["", !1, 0, !1];
433
526
  if (!n.length && !i.length)
434
527
  return ["$.", !1, s.length - e, !0];
435
- if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !l) {
528
+ if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
436
529
  const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
437
- return [oe(p), !1, h - e, !1];
530
+ return [pe(p), !1, c - e, !1];
438
531
  }
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 + "+?";
532
+ const u = "[" + (h ? "^" : "") + it(n) + "]", d = "[" + (h ? "" : "^") + it(i) + "]";
533
+ return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
534
+ }, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), me = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), rt = (s) => me.has(s), we = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", ye = /* @__PURE__ */ new Set(["[", "."]), Ee = /* @__PURE__ */ new Set(["..", "."]), Se = new Set("().*{}+?[]^$\\\\!"), be = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), Q = "[^/]", ot = Q + "*?", at = Q + "+?";
442
535
  class E {
443
536
  type;
444
537
  #s;
@@ -450,7 +543,7 @@ class E {
450
543
  #c;
451
544
  #a = !1;
452
545
  #i;
453
- #h;
546
+ #l;
454
547
  // set to true if it's an extglob with no children
455
548
  // (which really means one child of '')
456
549
  #u = !1;
@@ -467,7 +560,7 @@ class E {
467
560
  }
468
561
  // reconstructs the pattern
469
562
  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("");
563
+ return this.#l !== void 0 ? this.#l : this.type ? this.#l = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#l = this.#t.map((t) => String(t)).join("");
471
564
  }
472
565
  #d() {
473
566
  if (this !== this.#s)
@@ -538,68 +631,68 @@ class E {
538
631
  e.copyIn(n);
539
632
  return e;
540
633
  }
541
- static #l(t, e, n, i) {
542
- let r = !1, o = !1, a = -1, c = !1;
634
+ static #h(t, e, n, i) {
635
+ let r = !1, o = !1, a = -1, l = !1;
543
636
  if (e.type === null) {
544
- let d = n, w = "";
637
+ let d = n, m = "";
545
638
  for (; d < t.length; ) {
546
639
  const p = t.charAt(d++);
547
640
  if (r || p === "\\\\") {
548
- r = !r, w += p;
641
+ r = !r, m += p;
549
642
  continue;
550
643
  }
551
644
  if (o) {
552
- d === a + 1 ? (p === "^" || p === "!") && (c = !0) : p === "]" && !(d === a + 2 && c) && (o = !1), w += p;
645
+ d === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (o = !1), m += p;
553
646
  continue;
554
647
  } else if (p === "[") {
555
- o = !0, a = d, c = !1, w += p;
648
+ o = !0, a = d, l = !1, m += p;
556
649
  continue;
557
650
  }
558
- if (!i.noext && it(p) && t.charAt(d) === "(") {
559
- e.push(w), w = "";
651
+ if (!i.noext && rt(p) && t.charAt(d) === "(") {
652
+ e.push(m), m = "";
560
653
  const S = new E(p, e);
561
- d = E.#l(t, S, d, i), e.push(S);
654
+ d = E.#h(t, S, d, i), e.push(S);
562
655
  continue;
563
656
  }
564
- w += p;
657
+ m += p;
565
658
  }
566
- return e.push(w), d;
659
+ return e.push(m), d;
567
660
  }
568
- let l = n + 1, h = new E(null, e);
661
+ let h = n + 1, c = new E(null, e);
569
662
  const f = [];
570
663
  let u = "";
571
- for (; l < t.length; ) {
572
- const d = t.charAt(l++);
664
+ for (; h < t.length; ) {
665
+ const d = t.charAt(h++);
573
666
  if (r || d === "\\\\") {
574
667
  r = !r, u += d;
575
668
  continue;
576
669
  }
577
670
  if (o) {
578
- l === a + 1 ? (d === "^" || d === "!") && (c = !0) : d === "]" && !(l === a + 2 && c) && (o = !1), u += d;
671
+ h === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (o = !1), u += d;
579
672
  continue;
580
673
  } else if (d === "[") {
581
- o = !0, a = l, c = !1, u += d;
674
+ o = !0, a = h, l = !1, u += d;
582
675
  continue;
583
676
  }
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);
677
+ if (rt(d) && t.charAt(h) === "(") {
678
+ c.push(u), u = "";
679
+ const m = new E(d, c);
680
+ c.push(m), h = E.#h(t, m, h, i);
588
681
  continue;
589
682
  }
590
683
  if (d === "|") {
591
- h.push(u), u = "", f.push(h), h = new E(null, e);
684
+ c.push(u), u = "", f.push(c), c = new E(null, e);
592
685
  continue;
593
686
  }
594
687
  if (d === ")")
595
- return u === "" && e.#t.length === 0 && (e.#u = !0), h.push(u), u = "", e.push(...f, h), l;
688
+ return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
596
689
  u += d;
597
690
  }
598
- return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], l;
691
+ return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
599
692
  }
600
693
  static fromGlob(t, e = {}) {
601
694
  const n = new E(null, void 0, e);
602
- return E.#l(t, n, 0, e), n;
695
+ return E.#h(t, n, 0, e), n;
603
696
  }
604
697
  // returns the regular expression if there's magic, or the unescaped
605
698
  // string if not.
@@ -690,24 +783,24 @@ class E {
690
783
  toRegExpSource(t) {
691
784
  const e = t ?? !!this.#i.dot;
692
785
  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;
786
+ const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
787
+ const [m, p, S, v] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
788
+ return this.#n = this.#n || S, this.#r = this.#r || v, m;
696
789
  }).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 = (
790
+ let c = "";
791
+ if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Ee.has(this.#t[0]))) {
792
+ const m = ye, p = (
700
793
  // 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 : "";
794
+ e && m.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
795
+ h.startsWith("\\\\.") && m.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
796
+ h.startsWith("\\\\.\\\\.") && m.has(h.charAt(4))
797
+ ), S = !e && !t && m.has(h.charAt(0));
798
+ c = p ? we : S ? k : "";
706
799
  }
707
800
  let f = "";
708
801
  return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
709
- h + l + f,
710
- $(l),
802
+ c + h + f,
803
+ $(h),
711
804
  this.#n = !!this.#n,
712
805
  this.#r
713
806
  ];
@@ -715,20 +808,20 @@ class E {
715
808
  const n = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:";
716
809
  let r = this.#f(e);
717
810
  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];
811
+ const l = this.toString();
812
+ return this.#t = [l], this.type = null, this.#n = void 0, [l, $(this.toString()), !1, !1];
720
813
  }
721
814
  let o = !n || t || e || !k ? "" : this.#f(!0);
722
815
  o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
723
816
  let a = "";
724
817
  if (this.type === "!" && this.#u)
725
- a = (this.isStart() && !e ? k : "") + ot;
818
+ a = (this.isStart() && !e ? k : "") + at;
726
819
  else {
727
- const c = this.type === "!" ? (
820
+ const l = this.type === "!" ? (
728
821
  // !() must match something,but !(x) can match ''
729
- "))" + (this.isStart() && !e && !t ? k : "") + rt + ")"
822
+ "))" + (this.isStart() && !e && !t ? k : "") + ot + ")"
730
823
  ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
731
- a = i + r + c;
824
+ a = i + r + l;
732
825
  }
733
826
  return [
734
827
  a,
@@ -748,108 +841,108 @@ class E {
748
841
  static #p(t, e, n = !1) {
749
842
  let i = !1, r = "", o = !1;
750
843
  for (let a = 0; a < t.length; a++) {
751
- const c = t.charAt(a);
844
+ const l = t.charAt(a);
752
845
  if (i) {
753
- i = !1, r += (fe.has(c) ? "\\\\" : "") + c;
846
+ i = !1, r += (Se.has(l) ? "\\\\" : "") + l;
754
847
  continue;
755
848
  }
756
- if (c === "\\\\") {
849
+ if (l === "\\\\") {
757
850
  a === t.length - 1 ? r += "\\\\\\\\" : i = !0;
758
851
  continue;
759
852
  }
760
- if (c === "[") {
761
- const [l, h, f, u] = ae(t, a);
853
+ if (l === "[") {
854
+ const [h, c, f, u] = ge(t, a);
762
855
  if (f) {
763
- r += l, o = o || h, a += f - 1, e = e || u;
856
+ r += h, o = o || c, a += f - 1, e = e || u;
764
857
  continue;
765
858
  }
766
859
  }
767
- if (c === "*") {
768
- n && t === "*" ? r += ot : r += rt, e = !0;
860
+ if (l === "*") {
861
+ n && t === "*" ? r += at : r += ot, e = !0;
769
862
  continue;
770
863
  }
771
- if (c === "?") {
864
+ if (l === "?") {
772
865
  r += Q, e = !0;
773
866
  continue;
774
867
  }
775
- r += de(c);
868
+ r += be(l);
776
869
  }
777
870
  return [r, $(t), !!e, o];
778
871
  }
779
872
  }
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 = ""]) => {
873
+ const xe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (W(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new j(t, e).match(s)), Ae = /^\\*+([^+@!?\\*\\[\\(]*)$/, ve = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ce = (s) => (t) => t.endsWith(s), Oe = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), De = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Ne = /^\\*+\\.\\*+$/, Fe = (s) => !s.startsWith(".") && s.includes("."), Te = (s) => s !== "." && s !== ".." && s.includes("."), Me = /^\\.\\*+$/, $e = (s) => s !== "." && s !== ".." && s.startsWith("."), Pe = /^\\*+$/, Re = (s) => s.length !== 0 && !s.startsWith("."), ke = (s) => s.length !== 0 && s !== "." && s !== "..", Le = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ie = ([s, t = ""]) => {
781
874
  const e = At([s]);
782
875
  return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
783
- }, Pe = ([s, t = ""]) => {
784
- const e = Dt([s]);
876
+ }, ze = ([s, t = ""]) => {
877
+ const e = vt([s]);
785
878
  return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
786
- }, ve = ([s, t = ""]) => {
787
- const e = Dt([s]);
879
+ }, He = ([s, t = ""]) => {
880
+ const e = vt([s]);
788
881
  return t ? (n) => e(n) && n.endsWith(t) : e;
789
- }, Me = ([s, t = ""]) => {
882
+ }, We = ([s, t = ""]) => {
790
883
  const e = At([s]);
791
884
  return t ? (n) => e(n) && n.endsWith(t) : e;
792
885
  }, At = ([s]) => {
793
886
  const t = s.length;
794
887
  return (e) => e.length === t && !e.startsWith(".");
795
- }, Dt = ([s]) => {
888
+ }, vt = ([s]) => {
796
889
  const t = s.length;
797
890
  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 = {
891
+ }, Ct = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", ct = {
799
892
  win32: { sep: "\\\\" },
800
893
  posix: { sep: "/" }
801
- }, $e = Ct === "win32" ? at.win32.sep : at.posix.sep;
802
- y.sep = $e;
894
+ }, je = Ct === "win32" ? ct.win32.sep : ct.posix.sep;
895
+ y.sep = je;
803
896
  const A = Symbol("globstar **");
804
897
  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) => {
898
+ const Ue = "[^/]", _e = Ue + "*?", Be = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Ge = "(?:(?!(?:\\\\/|^)\\\\.).)*?", qe = (s, t = {}) => (e) => y(e, s, t);
899
+ y.filter = qe;
900
+ const x = (s, t = {}) => Object.assign({}, s, t), Ve = (s) => {
808
901
  if (!s || typeof s != "object" || !Object.keys(s).length)
809
902
  return y;
810
903
  const t = y;
811
- return Object.assign((n, i, r = {}) => t(n, i, b(s, r)), {
904
+ return Object.assign((n, i, r = {}) => t(n, i, x(s, r)), {
812
905
  Minimatch: class extends t.Minimatch {
813
906
  constructor(i, r = {}) {
814
- super(i, b(s, r));
907
+ super(i, x(s, r));
815
908
  }
816
909
  static defaults(i) {
817
- return t.defaults(b(s, i)).Minimatch;
910
+ return t.defaults(x(s, i)).Minimatch;
818
911
  }
819
912
  },
820
913
  AST: class extends t.AST {
821
914
  /* c8 ignore start */
822
915
  constructor(i, r, o = {}) {
823
- super(i, r, b(s, o));
916
+ super(i, r, x(s, o));
824
917
  }
825
918
  /* c8 ignore stop */
826
919
  static fromGlob(i, r = {}) {
827
- return t.AST.fromGlob(i, b(s, r));
920
+ return t.AST.fromGlob(i, x(s, r));
828
921
  }
829
922
  },
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)),
923
+ unescape: (n, i = {}) => t.unescape(n, x(s, i)),
924
+ escape: (n, i = {}) => t.escape(n, x(s, i)),
925
+ filter: (n, i = {}) => t.filter(n, x(s, i)),
926
+ defaults: (n) => t.defaults(x(s, n)),
927
+ makeRe: (n, i = {}) => t.makeRe(n, x(s, i)),
928
+ braceExpand: (n, i = {}) => t.braceExpand(n, x(s, i)),
929
+ match: (n, i, r = {}) => t.match(n, i, x(s, r)),
837
930
  sep: t.sep,
838
931
  GLOBSTAR: A
839
932
  });
840
933
  };
841
- y.defaults = We;
842
- const Ot = (s, t = {}) => (U(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : Qt(s));
934
+ y.defaults = Ve;
935
+ const Ot = (s, t = {}) => (W(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ae(s));
843
936
  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);
937
+ const Xe = (s, t = {}) => new j(s, t).makeRe();
938
+ y.makeRe = Xe;
939
+ const Ye = (s, t, e = {}) => {
940
+ const n = new j(t, e);
848
941
  return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
849
942
  };
850
- y.match = je;
851
- const ct = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ue = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
852
- class _ {
943
+ y.match = Ye;
944
+ const lt = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ze = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
945
+ class j {
853
946
  options;
854
947
  set;
855
948
  pattern;
@@ -868,7 +961,7 @@ class _ {
868
961
  windowsNoMagicRoot;
869
962
  regexp;
870
963
  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();
964
+ W(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
965
  }
873
966
  hasMagic() {
874
967
  if (this.options.magicalBraces && this.set.length > 1)
@@ -896,13 +989,13 @@ class _ {
896
989
  this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
897
990
  let i = this.globParts.map((r, o, a) => {
898
991
  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))];
992
+ const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !lt.test(r[2])) && !lt.test(r[3]), h = /^[a-z]:/i.test(r[0]);
902
993
  if (l)
903
- return [r[0], ...r.slice(1).map((h) => this.parse(h))];
994
+ return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
995
+ if (h)
996
+ return [r[0], ...r.slice(1).map((c) => this.parse(c))];
904
997
  }
905
- return r.map((c) => this.parse(c));
998
+ return r.map((l) => this.parse(l));
906
999
  });
907
1000
  if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(!1) === -1), this.isWindows)
908
1001
  for (let r = 0; r < this.set.length; r++) {
@@ -993,12 +1086,12 @@ class _ {
993
1086
  o++;
994
1087
  o > i && n.splice(i + 1, o - i);
995
1088
  let a = n[i + 1];
996
- const c = n[i + 2], l = n[i + 3];
997
- if (a !== ".." || !c || c === "." || c === ".." || !l || l === "." || l === "..")
1089
+ const l = n[i + 2], h = n[i + 3];
1090
+ if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
998
1091
  continue;
999
1092
  e = !0, n.splice(i, 1);
1000
- const h = n.slice(0);
1001
- h[i] = "**", t.push(h), i--;
1093
+ const c = n.slice(0);
1094
+ c[i] = "**", t.push(c), i--;
1002
1095
  }
1003
1096
  if (!this.preserveMultipleSlashes) {
1004
1097
  for (let o = 1; o < n.length - 1; o++) {
@@ -1012,8 +1105,8 @@ class _ {
1012
1105
  const o = n[r - 1];
1013
1106
  if (o && o !== "." && o !== ".." && o !== "**") {
1014
1107
  e = !0;
1015
- const c = r === 1 && n[r + 1] === "**" ? ["."] : [];
1016
- n.splice(r - 1, 2, ...c), n.length === 0 && n.push(""), r -= 2;
1108
+ const l = r === 1 && n[r + 1] === "**" ? ["."] : [];
1109
+ n.splice(r - 1, 2, ...l), n.length === 0 && n.push(""), r -= 2;
1017
1110
  }
1018
1111
  }
1019
1112
  }
@@ -1076,66 +1169,66 @@ class _ {
1076
1169
  matchOne(t, e, n = !1) {
1077
1170
  const i = this.options;
1078
1171
  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)));
1172
+ const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), v = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), N = !v && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), b = S ? 3 : p ? 0 : void 0, w = N ? 3 : v ? 0 : void 0;
1173
+ if (typeof b == "number" && typeof w == "number") {
1174
+ const [F, P] = [t[b], e[w]];
1175
+ F.toLowerCase() === P.toLowerCase() && (e[w] = F, w > b ? e = e.slice(w) : b > w && (t = t.slice(b)));
1083
1176
  }
1084
1177
  }
1085
1178
  const { optimizationLevel: r = 1 } = this.options;
1086
1179
  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++) {
1180
+ for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
1088
1181
  this.debug("matchOne loop");
1089
- var h = e[a], f = t[o];
1090
- if (this.debug(e, h, f), h === !1)
1182
+ var c = e[a], f = t[o];
1183
+ if (this.debug(e, c, f), c === !1)
1091
1184
  return !1;
1092
- if (h === A) {
1093
- this.debug("GLOBSTAR", [e, h, f]);
1185
+ if (c === A) {
1186
+ this.debug("GLOBSTAR", [e, c, f]);
1094
1187
  var u = o, d = a + 1;
1095
- if (d === l) {
1096
- for (this.debug("** at the end"); o < c; o++)
1188
+ if (d === h) {
1189
+ for (this.debug("** at the end"); o < l; o++)
1097
1190
  if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
1098
1191
  return !1;
1099
1192
  return !0;
1100
1193
  }
1101
- for (; u < c; ) {
1102
- var w = t[u];
1194
+ for (; u < l; ) {
1195
+ var m = t[u];
1103
1196
  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) === ".") {
1197
+ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
1198
+ return this.debug("globstar found match!", u, l, m), !0;
1199
+ if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
1107
1200
  this.debug("dot detected!", t, u, e, d);
1108
1201
  break;
1109
1202
  }
1110
1203
  this.debug("globstar swallow a segment, and continue"), u++;
1111
1204
  }
1112
1205
  return !!(n && (this.debug(\`
1113
- >>> no match, partial?\`, t, u, e, d), u === c));
1206
+ >>> no match, partial?\`, t, u, e, d), u === l));
1114
1207
  }
1115
1208
  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)
1209
+ if (typeof c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, f, p)), !p)
1117
1210
  return !1;
1118
1211
  }
1119
- if (o === c && a === l)
1212
+ if (o === l && a === h)
1120
1213
  return !0;
1121
- if (o === c)
1214
+ if (o === l)
1122
1215
  return n;
1123
- if (a === l)
1124
- return o === c - 1 && t[o] === "";
1216
+ if (a === h)
1217
+ return o === l - 1 && t[o] === "";
1125
1218
  throw new Error("wtf?");
1126
1219
  }
1127
1220
  braceExpand() {
1128
1221
  return Ot(this.pattern, this.options);
1129
1222
  }
1130
1223
  parse(t) {
1131
- U(t);
1224
+ W(t);
1132
1225
  const e = this.options;
1133
1226
  if (t === "**")
1134
1227
  return A;
1135
1228
  if (t === "")
1136
1229
  return "";
1137
1230
  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);
1231
+ (n = t.match(Pe)) ? i = e.dot ? ke : Re : (n = t.match(Ae)) ? i = (e.nocase ? e.dot ? De : Oe : e.dot ? Ce : ve)(n[1]) : (n = t.match(Le)) ? i = (e.nocase ? e.dot ? ze : Ie : e.dot ? He : We)(n) : (n = t.match(Ne)) ? i = e.dot ? Te : Fe : (n = t.match(Me)) && (i = $e);
1139
1232
  const r = E.fromGlob(t, this.options).toMMPattern();
1140
1233
  return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
1141
1234
  }
@@ -1145,18 +1238,18 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
1145
1238
  const t = this.set;
1146
1239
  if (!t.length)
1147
1240
  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(""))
1241
+ const e = this.options, n = e.noglobstar ? _e : e.dot ? Be : Ge, i = new Set(e.nocase ? ["i"] : []);
1242
+ let r = t.map((l) => {
1243
+ const h = l.map((c) => {
1244
+ if (c instanceof RegExp)
1245
+ for (const f of c.flags.split(""))
1153
1246
  i.add(f);
1154
- return typeof h == "string" ? Ue(h) : h === A ? A : h._src;
1247
+ return typeof c == "string" ? Ze(c) : c === A ? A : c._src;
1155
1248
  });
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("/");
1249
+ return h.forEach((c, f) => {
1250
+ const u = h[f + 1], d = h[f - 1];
1251
+ c !== A || d === A || (d === void 0 ? u !== void 0 && u !== A ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== A && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = A));
1252
+ }), h.filter((c) => c !== A).join("/");
1160
1253
  }).join("|");
1161
1254
  const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1162
1255
  r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
@@ -1188,9 +1281,9 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
1188
1281
  for (let a = i.length - 2; !o && a >= 0; a--)
1189
1282
  o = i[a];
1190
1283
  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))
1284
+ const l = r[a];
1285
+ let h = i;
1286
+ if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
1194
1287
  return n.flipNegate ? !0 : !this.negate;
1195
1288
  }
1196
1289
  return n.flipNegate ? !1 : this.negate;
@@ -1200,136 +1293,107 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
1200
1293
  }
1201
1294
  }
1202
1295
  y.AST = E;
1203
- y.Minimatch = _;
1204
- y.escape = pe;
1296
+ y.Minimatch = j;
1297
+ y.escape = xe;
1205
1298
  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 {
1212
- constructor() {
1213
- super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
1214
- }
1215
- }
1216
- class q extends g {
1217
- constructor() {
1218
- super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
1219
- }
1220
- }
1221
- class ht extends g {
1222
- constructor(t, e) {
1223
- super(t, "INVALID_PATH", e);
1224
- }
1225
- }
1226
- class V extends g {
1227
- constructor(t) {
1228
- super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
1229
- }
1230
- }
1231
- function Be(s, t = "utf-8") {
1232
- switch (t) {
1233
- case "utf8":
1234
- case "utf-8":
1235
- return new TextEncoder().encode(s);
1236
- case "utf16le":
1237
- case "ucs2":
1238
- case "ucs-2":
1239
- return qe(s);
1240
- case "ascii":
1241
- return Xe(s);
1242
- case "latin1":
1243
- return Ze(s);
1244
- case "binary":
1245
- return Uint8Array.from(s, (e) => e.charCodeAt(0));
1246
- case "base64":
1247
- return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
1248
- case "hex":
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)));
1252
- default:
1253
- return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
1254
- }
1255
- }
1256
- function Ge(s, t = "utf-8") {
1257
- switch (t) {
1258
- case "utf8":
1259
- case "utf-8":
1260
- return new TextDecoder().decode(s);
1261
- case "utf16le":
1262
- case "ucs2":
1263
- case "ucs-2":
1264
- return Ve(s);
1265
- case "latin1":
1266
- return String.fromCharCode(...s);
1267
- case "binary":
1268
- return String.fromCharCode(...s);
1269
- case "ascii":
1270
- return String.fromCharCode(...s.map((e) => e & 127));
1271
- case "base64":
1272
- return btoa(String.fromCharCode(...s));
1273
- case "hex":
1274
- return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
1275
- default:
1276
- return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
1277
- }
1278
- }
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;
1284
- }
1285
- return t;
1286
- }
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);
1290
- return String.fromCharCode(...t);
1291
- }
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;
1296
- return t;
1297
- }
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;
1302
- return t;
1299
+ const Je = [
1300
+ // Images
1301
+ ".jpg",
1302
+ ".jpeg",
1303
+ ".png",
1304
+ ".gif",
1305
+ ".bmp",
1306
+ ".webp",
1307
+ ".svg",
1308
+ ".ico",
1309
+ ".tiff",
1310
+ ".tga",
1311
+ // Audio
1312
+ ".mp3",
1313
+ ".wav",
1314
+ ".ogg",
1315
+ ".flac",
1316
+ ".aac",
1317
+ ".wma",
1318
+ ".m4a",
1319
+ // Video
1320
+ ".mp4",
1321
+ ".avi",
1322
+ ".mov",
1323
+ ".wmv",
1324
+ ".flv",
1325
+ ".webm",
1326
+ ".mkv",
1327
+ ".m4v",
1328
+ // Documents
1329
+ ".pdf",
1330
+ ".doc",
1331
+ ".docx",
1332
+ ".xls",
1333
+ ".xlsx",
1334
+ ".ppt",
1335
+ ".pptx",
1336
+ // Archives
1337
+ ".zip",
1338
+ ".rar",
1339
+ ".7z",
1340
+ ".tar",
1341
+ ".gz",
1342
+ ".bz2",
1343
+ // Executables
1344
+ ".exe",
1345
+ ".dll",
1346
+ ".so",
1347
+ ".dylib",
1348
+ ".bin",
1349
+ // Other binary formats
1350
+ ".dat",
1351
+ ".db",
1352
+ ".sqlite",
1353
+ ".bin",
1354
+ ".obj",
1355
+ ".fbx",
1356
+ ".3ds"
1357
+ ];
1358
+ function G(s) {
1359
+ const t = s.toLowerCase().substring(s.lastIndexOf("."));
1360
+ return Je.includes(t);
1303
1361
  }
1304
- function Ye() {
1362
+ function Ke() {
1305
1363
  if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
1306
- throw new _e();
1364
+ throw new Wt();
1307
1365
  }
1308
- function F(s) {
1366
+ async function tt(s, t, e) {
1367
+ return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/").toLowerCase()}\`, { mode: t }, e) : e();
1368
+ }
1369
+ function D(s) {
1309
1370
  return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
1310
1371
  }
1311
- function tt(s) {
1372
+ function et(s) {
1312
1373
  return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
1313
1374
  }
1314
- function Z(s) {
1315
- const t = F(s);
1375
+ function Y(s) {
1376
+ const t = D(s);
1316
1377
  return t[t.length - 1] || "";
1317
1378
  }
1318
- function X(s) {
1319
- const t = F(s);
1320
- return t.pop(), tt(t);
1379
+ function q(s) {
1380
+ const t = D(s);
1381
+ return t.pop(), et(t);
1321
1382
  }
1322
- function T(s) {
1383
+ function Z(s) {
1323
1384
  return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
1324
1385
  }
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 }));
1386
+ function Qe(s, t = !1) {
1387
+ return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
1388
+ }
1389
+ function V(s, t) {
1390
+ return y(s, t, {
1391
+ dot: !0,
1392
+ matchBase: !0
1393
+ });
1330
1394
  }
1331
- function Je(s) {
1332
- const t = T(s), e = F(t), n = [];
1395
+ function ts(s) {
1396
+ const t = Z(s), e = D(t), n = [];
1333
1397
  for (const i of e)
1334
1398
  if (!(i === "." || i === ""))
1335
1399
  if (i === "..") {
@@ -1338,57 +1402,67 @@ function Je(s) {
1338
1402
  n.pop();
1339
1403
  } else
1340
1404
  n.push(i);
1341
- return tt(n);
1405
+ return et(n);
1342
1406
  }
1343
- function Ke(s, t = "utf-8") {
1344
- return typeof s == "string" ? Be(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
1407
+ function es(s, t = "utf-8") {
1408
+ return typeof s == "string" ? Ut(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
1345
1409
  }
1346
- async function Qe(s) {
1347
- const t = await s.createSyncAccessHandle();
1348
- try {
1349
- const e = t.getSize(), n = new Uint8Array(e);
1350
- return t.read(n, { at: 0 }), n;
1351
- } finally {
1352
- t.close();
1353
- }
1410
+ async function ss(s, t) {
1411
+ return tt(t, "shared", async () => {
1412
+ const n = await (await s.getFile()).arrayBuffer();
1413
+ return new Uint8Array(n);
1414
+ });
1354
1415
  }
1355
- async function lt(s, t, e, n = {}) {
1356
- let i = null;
1357
- try {
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\`);
1365
- } finally {
1366
- if (i)
1416
+ async function ht(s, t, e, n, i = {}) {
1417
+ const r = async () => {
1418
+ let o = null;
1419
+ const a = i.append || !1, l = !a && (i.truncate ?? !0);
1420
+ try {
1421
+ o = await s.createSyncAccessHandle();
1422
+ const h = es(t, e), c = a ? o.getSize() : 0;
1423
+ o.write(h, { at: c }), l && o.truncate(h.byteLength), o.flush();
1424
+ } catch (h) {
1425
+ console.error(h);
1426
+ const c = a ? "append" : "write";
1427
+ throw new g(\`Failed to \${c} file\`, \`\${c.toUpperCase()}_FAILED\`, void 0, h);
1428
+ } finally {
1367
1429
  try {
1368
- i.close();
1430
+ o?.close();
1369
1431
  } catch {
1370
1432
  }
1371
- }
1433
+ }
1434
+ };
1435
+ return n ? tt(n, "exclusive", r) : r();
1372
1436
  }
1373
- async function ts(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1437
+ async function ns(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1374
1438
  if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
1375
1439
  throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
1376
1440
  const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
1377
1441
  return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
1378
1442
  }
1379
- async function es(s) {
1443
+ async function is(s) {
1380
1444
  const t = await s.arrayBuffer();
1381
1445
  return new Uint8Array(t);
1382
1446
  }
1383
- class ss {
1447
+ async function rs(s, t, e = {}) {
1448
+ const n = Y(t);
1449
+ return tt(t, "exclusive", async () => {
1450
+ const i = e.recursive ?? !1, r = e.force ?? !1;
1451
+ try {
1452
+ await s.removeEntry(n, { recursive: i });
1453
+ } catch (o) {
1454
+ if (o.name === "NotFoundError") {
1455
+ if (!r)
1456
+ throw new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, o);
1457
+ } else throw o.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !i ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR", void 0, o) : new g(\`Failed to remove entry: \${t}\`, "RM_FAILED", void 0, o);
1458
+ }
1459
+ });
1460
+ }
1461
+ class os {
1384
1462
  /** Root directory handle for the file system */
1385
1463
  root = null;
1386
- /** Map of watched paths to their last known state and options */
1464
+ /** Map of watched paths and options */
1387
1465
  watchers = /* @__PURE__ */ new Map();
1388
- /** Interval handle for polling watched paths */
1389
- watchTimer = null;
1390
- /** Flag to avoid concurrent scans */
1391
- scanning = !1;
1392
1466
  /** Promise to prevent concurrent mount operations */
1393
1467
  mountingPromise = null;
1394
1468
  /** BroadcastChannel instance for sending events */
@@ -1396,7 +1470,7 @@ class ss {
1396
1470
  /** Configuration options */
1397
1471
  options = {
1398
1472
  root: "/",
1399
- watchInterval: 1e3,
1473
+ namespace: "",
1400
1474
  maxFileSize: 50 * 1024 * 1024,
1401
1475
  hashAlgorithm: null,
1402
1476
  broadcastChannel: "opfs-worker"
@@ -1413,25 +1487,26 @@ class ss {
1413
1487
  async notifyChange(t) {
1414
1488
  if (!this.options.broadcastChannel)
1415
1489
  return;
1416
- let e;
1417
- if (this.options.hashAlgorithm && !t.isDirectory && t.type !== "removed")
1490
+ const e = t.path;
1491
+ if (![...this.watchers.values()].some((r) => V(e, r.pattern) && r.include.some((o) => o && V(e, o)) && !r.exclude.some((o) => o && V(e, o))))
1492
+ return;
1493
+ let i;
1494
+ if (this.options.hashAlgorithm)
1418
1495
  try {
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);
1496
+ i = (await this.stat(e)).hash;
1497
+ } catch {
1423
1498
  }
1424
1499
  try {
1425
1500
  this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
1426
- const n = {
1427
- root: this.options.root,
1501
+ const r = {
1502
+ namespace: this.options.namespace,
1428
1503
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1429
1504
  ...t,
1430
- ...e && { hash: e }
1505
+ ...i && { hash: i }
1431
1506
  };
1432
- this.broadcastChannel.postMessage(n);
1433
- } catch (n) {
1434
- console.warn("Failed to send event via BroadcastChannel:", n);
1507
+ this.broadcastChannel.postMessage(r);
1508
+ } catch (r) {
1509
+ console.warn("Failed to send event via BroadcastChannel:", r);
1435
1510
  }
1436
1511
  }
1437
1512
  /**
@@ -1445,7 +1520,7 @@ class ss {
1445
1520
  * @throws {OPFSError} If OPFS is not supported in the current browser
1446
1521
  */
1447
1522
  constructor(t) {
1448
- Ye(), t && this.setOptions(t);
1523
+ Ke(), t && this.setOptions(t);
1449
1524
  }
1450
1525
  /**
1451
1526
  * Initialize the file system within a given directory
@@ -1469,13 +1544,12 @@ class ss {
1469
1544
  * \`\`\`
1470
1545
  */
1471
1546
  async mount(t = this.options.root) {
1472
- return this.mountingPromise && await this.mountingPromise, t = T(t), this.mountingPromise = new Promise(async (e, n) => {
1473
- this.root = null;
1547
+ return this.mountingPromise && await this.mountingPromise, t = Z(t), this.mountingPromise = new Promise(async (e, n) => {
1474
1548
  try {
1475
1549
  const i = await navigator.storage.getDirectory();
1476
1550
  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"));
1551
+ } catch {
1552
+ n(new g("Failed to initialize OPFS", "INIT_FAILED"));
1479
1553
  } finally {
1480
1554
  this.mountingPromise = null;
1481
1555
  }
@@ -1492,7 +1566,7 @@ class ss {
1492
1566
  * @param options.broadcastChannel - Custom name for the broadcast channel
1493
1567
  */
1494
1568
  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));
1569
+ t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = t.root, this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount(this.options.root));
1496
1570
  }
1497
1571
  /**
1498
1572
  * Get a directory handle from a path
@@ -1513,9 +1587,7 @@ class ss {
1513
1587
  * \`\`\`
1514
1588
  */
1515
1589
  async getDirectoryHandle(t, e = !1, n = this.root) {
1516
- if (!n)
1517
- throw new q();
1518
- const i = Array.isArray(t) ? t : F(t);
1590
+ const i = Array.isArray(t) ? t : D(t);
1519
1591
  let r = n;
1520
1592
  for (const o of i)
1521
1593
  r = await r.getDirectoryHandle(o, { create: e });
@@ -1541,11 +1613,9 @@ class ss {
1541
1613
  * \`\`\`
1542
1614
  */
1543
1615
  async getFileHandle(t, e = !1, n = this.root) {
1544
- if (!n)
1545
- throw new q();
1546
- const i = F(t);
1616
+ const i = D(t);
1547
1617
  if (i.length === 0)
1548
- throw new ht("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1618
+ throw new jt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1549
1619
  const r = i.pop();
1550
1620
  return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
1551
1621
  }
@@ -1590,13 +1660,13 @@ class ss {
1590
1660
  isDirectory: !0
1591
1661
  }), await e("/"), t;
1592
1662
  }
1593
- async readFile(t, e = "utf-8") {
1594
- await this.mount();
1663
+ async readFile(t, e) {
1664
+ await this.mount(), e || (e = G(t) ? "binary" : "utf-8");
1595
1665
  try {
1596
- const n = await this.getFileHandle(t, !1), i = await Qe(n);
1597
- return e === "binary" ? i : Ge(i, e);
1666
+ const n = await this.getFileHandle(t, !1), i = await ss(n, t);
1667
+ return e === "binary" ? i : _t(i, e);
1598
1668
  } catch (n) {
1599
- throw console.error(n), new V(t);
1669
+ throw new _(t, n);
1600
1670
  }
1601
1671
  }
1602
1672
  /**
@@ -1626,8 +1696,8 @@ class ss {
1626
1696
  */
1627
1697
  async writeFile(t, e, n) {
1628
1698
  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 });
1699
+ const i = await this.exists(t), r = await this.getFileHandle(t, !0);
1700
+ n || (n = typeof e != "string" || G(t) ? "binary" : "utf-8"), await ht(r, e, n, t), i ? await this.notifyChange({ path: t, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: t, type: "added", isDirectory: !1 });
1631
1701
  }
1632
1702
  /**
1633
1703
  * Append data to a file
@@ -1654,7 +1724,7 @@ class ss {
1654
1724
  async appendFile(t, e, n) {
1655
1725
  await this.mount();
1656
1726
  const i = await this.getFileHandle(t, !0);
1657
- await lt(i, e, n, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
1727
+ n || (n = typeof e != "string" || G(t) ? "binary" : "utf-8"), await ht(i, e, n, t, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
1658
1728
  }
1659
1729
  /**
1660
1730
  * Create a directory
@@ -1678,19 +1748,20 @@ class ss {
1678
1748
  * \`\`\`
1679
1749
  */
1680
1750
  async mkdir(t, e) {
1681
- if (await this.mount(), !this.root)
1682
- throw new q();
1683
- const n = e?.recursive ?? !1, i = F(t);
1751
+ await this.mount();
1752
+ const n = e?.recursive ?? !1, i = D(t);
1684
1753
  let r = this.root;
1685
1754
  for (let o = 0; o < i.length; o++) {
1686
1755
  const a = i[o];
1687
1756
  try {
1688
1757
  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))}\`,
1692
- "ENOENT"
1693
- ) : c.name === "TypeMismatchError" ? new g(\`Path segment is not a directory: \${a}\`, "ENOTDIR") : new g("Failed to create directory", "MKDIR_FAILED");
1758
+ } catch (l) {
1759
+ throw l.name === "NotFoundError" ? new g(
1760
+ \`Parent directory does not exist: \${et(i.slice(0, o + 1))}\`,
1761
+ "ENOENT",
1762
+ void 0,
1763
+ l
1764
+ ) : l.name === "TypeMismatchError" ? new g(\`Path segment is not a directory: \${a}\`, "ENOTDIR", void 0, l) : new g("Failed to create directory", "MKDIR_FAILED", void 0, l);
1694
1765
  }
1695
1766
  }
1696
1767
  await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
@@ -1727,7 +1798,7 @@ class ss {
1727
1798
  isFile: !1,
1728
1799
  isDirectory: !0
1729
1800
  };
1730
- const e = Z(t), n = await this.getDirectoryHandle(X(t), !1), i = this.options.hashAlgorithm !== null;
1801
+ const e = Y(t), n = await this.getDirectoryHandle(q(t), !1), i = this.options.hashAlgorithm !== null;
1731
1802
  try {
1732
1803
  const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
1733
1804
  kind: "file",
@@ -1739,15 +1810,15 @@ class ss {
1739
1810
  };
1740
1811
  if (i && this.options.hashAlgorithm)
1741
1812
  try {
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);
1813
+ const l = await ns(o, this.options.hashAlgorithm, this.options.maxFileSize);
1814
+ a.hash = l;
1815
+ } catch (l) {
1816
+ console.warn(\`Failed to calculate hash for \${t}:\`, l);
1746
1817
  }
1747
1818
  return a;
1748
1819
  } catch (r) {
1749
1820
  if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
1750
- throw new g("Failed to stat (file)", "STAT_FAILED");
1821
+ throw new g("Failed to stat (file)", "STAT_FAILED", void 0, r);
1751
1822
  }
1752
1823
  try {
1753
1824
  return await n.getDirectoryHandle(e, { create: !1 }), {
@@ -1759,7 +1830,7 @@ class ss {
1759
1830
  isDirectory: !0
1760
1831
  };
1761
1832
  } catch (r) {
1762
- throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT") : new g("Failed to stat (directory)", "STAT_FAILED");
1833
+ throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, r) : new g("Failed to stat (directory)", "STAT_FAILED", void 0, r);
1763
1834
  }
1764
1835
  }
1765
1836
  /**
@@ -1811,10 +1882,10 @@ class ss {
1811
1882
  async exists(t) {
1812
1883
  if (await this.mount(), t === "/")
1813
1884
  return !0;
1814
- const e = Z(t);
1885
+ const e = Y(t);
1815
1886
  let n = null;
1816
1887
  try {
1817
- n = await this.getDirectoryHandle(X(t), !1);
1888
+ n = await this.getDirectoryHandle(q(t), !1);
1818
1889
  } catch (i) {
1819
1890
  throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
1820
1891
  }
@@ -1825,14 +1896,14 @@ class ss {
1825
1896
  } catch (i) {
1826
1897
  if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1827
1898
  throw i;
1899
+ try {
1900
+ return await n.getDirectoryHandle(e, { create: !1 }), !0;
1901
+ } catch (r) {
1902
+ if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1903
+ throw r;
1904
+ return !1;
1905
+ }
1828
1906
  }
1829
- try {
1830
- return await n.getDirectoryHandle(e, { create: !1 }), !0;
1831
- } catch (i) {
1832
- if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1833
- throw i;
1834
- }
1835
- return !1;
1836
1907
  }
1837
1908
  /**
1838
1909
  * Clear all contents of a directory without removing the directory itself
@@ -1863,7 +1934,7 @@ class ss {
1863
1934
  }
1864
1935
  await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
1865
1936
  } catch (e) {
1866
- throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED");
1937
+ throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED", void 0, e);
1867
1938
  }
1868
1939
  }
1869
1940
  /**
@@ -1891,23 +1962,10 @@ class ss {
1891
1962
  * \`\`\`
1892
1963
  */
1893
1964
  async remove(t, e) {
1894
- await this.mount();
1895
- const n = e?.recursive ?? !1, i = e?.force ?? !1;
1896
- if (t === "/")
1965
+ if (await this.mount(), t === "/")
1897
1966
  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);
1902
- try {
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");
1909
- }
1910
- await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
1967
+ const n = await this.getDirectoryHandle(q(t), !1);
1968
+ await rs(n, t, e), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
1911
1969
  }
1912
1970
  /**
1913
1971
  * Resolve a path to an absolute path
@@ -1930,12 +1988,12 @@ class ss {
1930
1988
  async realpath(t) {
1931
1989
  await this.mount();
1932
1990
  try {
1933
- const e = Je(t);
1991
+ const e = ts(t);
1934
1992
  if (!await this.exists(e))
1935
- throw new V(e);
1993
+ throw new _(e);
1936
1994
  return e;
1937
1995
  } catch (e) {
1938
- throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
1996
+ throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED", void 0, e);
1939
1997
  }
1940
1998
  }
1941
1999
  /**
@@ -1958,10 +2016,10 @@ class ss {
1958
2016
  await this.mount();
1959
2017
  try {
1960
2018
  if (!await this.exists(t))
1961
- throw new V(t);
2019
+ throw new _(t);
1962
2020
  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
2021
  } catch (n) {
1964
- throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED");
2022
+ throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, n);
1965
2023
  }
1966
2024
  }
1967
2025
  /**
@@ -1994,34 +2052,33 @@ class ss {
1994
2052
  try {
1995
2053
  const i = n?.recursive ?? !1, r = n?.force ?? !0;
1996
2054
  if (!await this.exists(t))
1997
- throw new g(\`Source does not exist: \${t}\`, "ENOENT");
2055
+ throw new g(\`Source does not exist: \${t}\`, "ENOENT", void 0);
1998
2056
  if (await this.exists(e) && !r)
1999
- throw new g(\`Destination already exists: \${e}\`, "EEXIST");
2057
+ throw new g(\`Destination already exists: \${e}\`, "EEXIST", void 0);
2000
2058
  if ((await this.stat(t)).isFile) {
2001
- const l = await this.readFile(t, "binary");
2002
- await this.writeFile(e, l);
2059
+ const h = await this.readFile(t, "binary");
2060
+ await this.writeFile(e, h);
2003
2061
  } else {
2004
2062
  if (!i)
2005
- throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR");
2063
+ throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR", void 0);
2006
2064
  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}\`;
2065
+ const h = await this.readDir(t);
2066
+ for (const c of h) {
2067
+ const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
2010
2068
  await this.copy(f, u, { recursive: !0, force: r });
2011
2069
  }
2012
2070
  }
2013
- await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
2014
2071
  } catch (i) {
2015
- throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED");
2072
+ throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED", void 0, i);
2016
2073
  }
2017
2074
  }
2018
2075
  /**
2019
2076
  * Start watching a file or directory for changes
2020
2077
  *
2021
- * @param path - The path to watch
2078
+ * @param path - The path to watch (minimatch syntax allowed)
2022
2079
  * @param options - Watch options
2023
2080
  * @param options.recursive - Whether to watch recursively (default: true)
2024
- * @param options.excludes - Glob pattern(s) to exclude (minimatch).
2081
+ * @param options.exclude - Glob pattern(s) to exclude (minimatch).
2025
2082
  * @returns Promise that resolves when watching starts
2026
2083
  *
2027
2084
  * @example
@@ -2034,21 +2091,27 @@ class ss {
2034
2091
  *
2035
2092
  * // Watch a single file
2036
2093
  * await fs.watch('/config.json', { recursive: false });
2094
+ *
2095
+ * // Watch all json files but not in dist directory
2096
+ * await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });
2097
+ *
2037
2098
  * \`\`\`
2038
2099
  */
2039
2100
  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(() => {
2043
- this.scanWatches();
2044
- }, this.options.watchInterval));
2101
+ if (!this.options.broadcastChannel)
2102
+ throw new g("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
2103
+ const n = {
2104
+ pattern: Qe(t, e?.recursive ?? !0),
2105
+ include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
2106
+ exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
2107
+ };
2108
+ this.watchers.set(t, n);
2045
2109
  }
2046
2110
  /**
2047
2111
  * Stop watching a previously watched path
2048
2112
  */
2049
2113
  unwatch(t) {
2050
- const e = T(t);
2051
- this.watchers.delete(e), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
2114
+ this.watchers.delete(t);
2052
2115
  }
2053
2116
  /**
2054
2117
  * Dispose of resources and clean up the file system instance
@@ -2057,53 +2120,7 @@ class ss {
2057
2120
  * to properly clean up resources like the broadcast channel and watch timers.
2058
2121
  */
2059
2122
  dispose() {
2060
- this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null), this.watchers.clear();
2061
- }
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);
2074
- }
2075
- }
2076
- };
2077
- return await a(t), n;
2078
- }
2079
- async scanWatches() {
2080
- if (!this.scanning) {
2081
- this.scanning = !0;
2082
- try {
2083
- await Promise.all(
2084
- [...this.watchers.entries()].map(async ([t, { snapshot: e, options: n }]) => {
2085
- let i;
2086
- try {
2087
- i = await this.buildSnapshot(t, n);
2088
- } catch {
2089
- i = /* @__PURE__ */ new Map();
2090
- }
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 }));
2094
- }
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 });
2099
- }
2100
- this.watchers.set(t, { snapshot: i, options: n });
2101
- })
2102
- );
2103
- } finally {
2104
- this.scanning = !1;
2105
- }
2106
- }
2123
+ this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
2107
2124
  }
2108
2125
  /**
2109
2126
  * Synchronize the file system with external data
@@ -2138,70 +2155,76 @@ class ss {
2138
2155
  try {
2139
2156
  (e?.cleanBefore ?? !1) && await this.clear("/");
2140
2157
  for (const [i, r] of t) {
2141
- const o = T(i);
2158
+ const o = Z(i);
2142
2159
  let a;
2143
- r instanceof Blob ? a = await es(r) : a = r, await this.writeFile(o, a);
2160
+ r instanceof Blob ? a = await is(r) : a = r, await this.writeFile(o, a);
2144
2161
  }
2145
- await this.notifyChange({ path: "/", type: "changed", isDirectory: !0 });
2146
2162
  } catch (n) {
2147
- throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED");
2163
+ throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED", void 0, n);
2148
2164
  }
2149
2165
  }
2150
2166
  }
2151
- typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && J(new ss());
2152
- //# sourceMappingURL=worker-Bra0Mewp.js.map
2167
+ typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && J(new os());
2168
+ //# sourceMappingURL=worker-DYhMhDRt.js.map
2153
2169
  `, s = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", r], { type: "text/javascript;charset=utf-8" });
2154
- function o(t) {
2155
- let n;
2170
+ function o(n) {
2171
+ let t;
2156
2172
  try {
2157
- if (n = s && (self.URL || self.webkitURL).createObjectURL(s), !n) throw "";
2158
- const e = new Worker(n, {
2173
+ if (t = s && (self.URL || self.webkitURL).createObjectURL(s), !t) throw "";
2174
+ const e = new Worker(t, {
2159
2175
  type: "module",
2160
- name: t?.name
2176
+ name: n?.name
2161
2177
  });
2162
2178
  return e.addEventListener("error", () => {
2163
- (self.URL || self.webkitURL).revokeObjectURL(n);
2179
+ (self.URL || self.webkitURL).revokeObjectURL(t);
2164
2180
  }), e;
2165
2181
  } catch {
2166
2182
  return new Worker(
2167
2183
  "data:text/javascript;charset=utf-8," + encodeURIComponent(r),
2168
2184
  {
2169
2185
  type: "module",
2170
- name: t?.name
2186
+ name: n?.name
2171
2187
  }
2172
2188
  );
2173
2189
  }
2174
2190
  }
2175
- function h(t) {
2176
- const n = i(new o());
2177
- return t && n.setOptions(t), n;
2191
+ async function h(n) {
2192
+ const t = i(new o());
2193
+ return n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), await t.setOptions(n)), t;
2178
2194
  }
2179
2195
  export {
2180
- p as DirectoryNotFoundError,
2181
- f as FileNotFoundError,
2182
- d as OPFSError,
2183
- u as OPFSNotMountedError,
2184
- g as OPFSNotSupportedError,
2185
- m as PathError,
2186
- w as PermissionError,
2187
- y as StorageError,
2188
- b as TimeoutError,
2189
- v as basename,
2190
- S as calculateFileHash,
2191
- E as checkOPFSSupport,
2192
- x as convertBlobToUint8Array,
2193
- P as createBuffer,
2196
+ p as BINARY_FILE_EXTENSIONS,
2197
+ f as DirectoryNotFoundError,
2198
+ d as FileNotFoundError,
2199
+ u as OPFSError,
2200
+ g as OPFSNotMountedError,
2201
+ m as OPFSNotSupportedError,
2202
+ w as PathError,
2203
+ y as PermissionError,
2204
+ b as StorageError,
2205
+ v as TimeoutError,
2206
+ x as basename,
2207
+ S as buffersEqual,
2208
+ E as calculateFileHash,
2209
+ A as checkOPFSSupport,
2210
+ P as convertBlobToUint8Array,
2211
+ F as createBuffer,
2194
2212
  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
2213
+ O as decodeBuffer,
2214
+ C as dirname,
2215
+ T as encodeString,
2216
+ R as extname,
2217
+ $ as isBinaryFileExtension,
2218
+ _ as isPathExcluded,
2219
+ D as joinPath,
2220
+ I as matchMinimatch,
2221
+ j as normalizeMinimatch,
2222
+ N as normalizePath,
2223
+ M as readFileData,
2224
+ k as removeEntry,
2225
+ L as resolvePath,
2226
+ z as splitPath,
2227
+ U as withLock,
2228
+ W as writeFileData
2206
2229
  };
2207
2230
  //# sourceMappingURL=index.js.map