opfs-worker 0.3.3 → 0.5.0

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