opfs-worker 2.0.0 → 2.1.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.
Files changed (135) hide show
  1. package/README.md +62 -439
  2. package/dist/BaseOPFS-BPw9AIQ-.cjs +4 -0
  3. package/dist/BaseOPFS-BPw9AIQ-.cjs.map +1 -0
  4. package/dist/BaseOPFS-Cylz6ijk.js +2036 -0
  5. package/dist/BaseOPFS-Cylz6ijk.js.map +1 -0
  6. package/dist/OPFSAsync-BKSAJJeh.js +124 -0
  7. package/dist/OPFSAsync-BKSAJJeh.js.map +1 -0
  8. package/dist/OPFSAsync-s2P7y3sw.cjs +2 -0
  9. package/dist/OPFSAsync-s2P7y3sw.cjs.map +1 -0
  10. package/dist/OPFSFacade-DePnNRgt.cjs +2 -0
  11. package/dist/OPFSFacade-DePnNRgt.cjs.map +1 -0
  12. package/dist/OPFSFacade-XohWlHuu.js +281 -0
  13. package/dist/OPFSFacade-XohWlHuu.js.map +1 -0
  14. package/dist/OPFSSync-C7KBepe_.cjs +2 -0
  15. package/dist/OPFSSync-C7KBepe_.cjs.map +1 -0
  16. package/dist/OPFSSync-CsSQkpk5.js +208 -0
  17. package/dist/OPFSSync-CsSQkpk5.js.map +1 -0
  18. package/dist/assets/dedicated.worker-nY3tK4zi.js.map +1 -0
  19. package/dist/{OPFSWorker.d.ts → core/BaseOPFS.d.ts} +34 -304
  20. package/dist/core/BaseOPFS.d.ts.map +1 -0
  21. package/dist/core/OPFSAsync.d.ts +55 -0
  22. package/dist/core/OPFSAsync.d.ts.map +1 -0
  23. package/dist/core/OPFSSync.d.ts +54 -0
  24. package/dist/core/OPFSSync.d.ts.map +1 -0
  25. package/dist/createOPFSAsync-BwKDmHsy.cjs +2 -0
  26. package/dist/createOPFSAsync-BwKDmHsy.cjs.map +1 -0
  27. package/dist/createOPFSAsync-Y4Mg6qte.js +10 -0
  28. package/dist/createOPFSAsync-Y4Mg6qte.js.map +1 -0
  29. package/dist/createOPFSDedicated-CsnV6MLP.js +2333 -0
  30. package/dist/createOPFSDedicated-CsnV6MLP.js.map +1 -0
  31. package/dist/createOPFSDedicated-pKTRWLdz.cjs +2283 -0
  32. package/dist/createOPFSDedicated-pKTRWLdz.cjs.map +1 -0
  33. package/dist/createOPFSShared-CGdd__PH.js +23 -0
  34. package/dist/createOPFSShared-CGdd__PH.js.map +1 -0
  35. package/dist/createOPFSShared-CskROt7U.cjs +2 -0
  36. package/dist/createOPFSShared-CskROt7U.cjs.map +1 -0
  37. package/dist/dedicated.worker.js +2281 -0
  38. package/dist/dedicated.worker.js.map +1 -0
  39. package/dist/{OPFSFacade.d.ts → facade/OPFSFacade.d.ts} +31 -23
  40. package/dist/facade/OPFSFacade.d.ts.map +1 -0
  41. package/dist/facade/createOPFSAsync.d.ts +16 -0
  42. package/dist/facade/createOPFSAsync.d.ts.map +1 -0
  43. package/dist/facade/createOPFSDedicated.d.ts +17 -0
  44. package/dist/facade/createOPFSDedicated.d.ts.map +1 -0
  45. package/dist/facade/createOPFSShared.d.ts +24 -0
  46. package/dist/facade/createOPFSShared.d.ts.map +1 -0
  47. package/dist/index.async.cjs +2 -0
  48. package/dist/index.async.cjs.map +1 -0
  49. package/dist/index.async.d.ts +10 -0
  50. package/dist/index.async.d.ts.map +1 -0
  51. package/dist/index.async.js +55 -0
  52. package/dist/index.async.js.map +1 -0
  53. package/dist/index.cjs +1 -2477
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.ts +17 -3
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +61 -2828
  58. package/dist/index.js.map +1 -1
  59. package/dist/index.pure.cjs +1 -1
  60. package/dist/index.pure.cjs.map +1 -1
  61. package/dist/index.pure.d.ts +3 -1
  62. package/dist/index.pure.d.ts.map +1 -1
  63. package/dist/index.pure.js +50 -1053
  64. package/dist/index.pure.js.map +1 -1
  65. package/dist/index.sharedworker.cjs +2 -0
  66. package/dist/index.sharedworker.cjs.map +1 -0
  67. package/dist/index.sharedworker.d.ts +11 -0
  68. package/dist/index.sharedworker.d.ts.map +1 -0
  69. package/dist/index.sharedworker.js +55 -0
  70. package/dist/index.sharedworker.js.map +1 -0
  71. package/dist/index.sync.cjs +2 -0
  72. package/dist/index.sync.cjs.map +1 -0
  73. package/dist/index.sync.d.ts +11 -0
  74. package/dist/index.sync.d.ts.map +1 -0
  75. package/dist/index.sync.js +55 -0
  76. package/dist/index.sync.js.map +1 -0
  77. package/dist/shared.worker.js +2166 -0
  78. package/dist/shared.worker.js.map +1 -0
  79. package/dist/types.d.ts +9 -4
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/worker/createDedicatedWorker.d.ts +30 -0
  82. package/dist/worker/createDedicatedWorker.d.ts.map +1 -0
  83. package/dist/worker/createSharedWorker.d.ts +37 -0
  84. package/dist/worker/createSharedWorker.d.ts.map +1 -0
  85. package/dist/worker/dedicated.worker.d.ts +2 -0
  86. package/dist/worker/dedicated.worker.d.ts.map +1 -0
  87. package/dist/worker/shared.worker.d.ts +2 -0
  88. package/dist/worker/shared.worker.d.ts.map +1 -0
  89. package/docs/README.md +30 -0
  90. package/docs/api/backend.md +36 -0
  91. package/docs/api/create.md +82 -0
  92. package/docs/api/facade.md +52 -0
  93. package/docs/choosing-a-mode.md +41 -0
  94. package/docs/file-descriptors.md +8 -9
  95. package/docs/guides/async.md +36 -0
  96. package/docs/guides/dedicated.md +76 -0
  97. package/docs/guides/hashing.md +34 -0
  98. package/docs/guides/pure.md +46 -0
  99. package/docs/guides/sharedworker.md +57 -0
  100. package/docs/guides/streaming.md +51 -0
  101. package/docs/guides/watching.md +35 -0
  102. package/docs/migration.md +41 -0
  103. package/docs/types.md +20 -6
  104. package/package.json +42 -3
  105. package/src/{OPFSWorker.ts → core/BaseOPFS.ts} +54 -647
  106. package/src/core/OPFSAsync.ts +248 -0
  107. package/src/core/OPFSSync.ts +460 -0
  108. package/src/{OPFSFacade.ts → facade/OPFSFacade.ts} +83 -54
  109. package/src/facade/createOPFSAsync.ts +22 -0
  110. package/src/facade/createOPFSDedicated.ts +23 -0
  111. package/src/facade/createOPFSShared.ts +30 -0
  112. package/src/index.async.ts +11 -0
  113. package/src/index.pure.ts +3 -2
  114. package/src/index.sharedworker.ts +12 -0
  115. package/src/index.sync.ts +12 -0
  116. package/src/index.ts +37 -8
  117. package/src/types.ts +8 -4
  118. package/src/worker/createDedicatedWorker.ts +74 -0
  119. package/src/worker/createSharedWorker.ts +67 -0
  120. package/src/worker/dedicated.worker.ts +13 -0
  121. package/src/worker/shared.worker.ts +17 -0
  122. package/dist/OPFSFacade.d.ts.map +0 -1
  123. package/dist/OPFSWorker.d.ts.map +0 -1
  124. package/dist/assets/worker.entry-DUlEoroc.js.map +0 -1
  125. package/dist/createOPFSWorker.d.ts +0 -17
  126. package/dist/createOPFSWorker.d.ts.map +0 -1
  127. package/dist/helpers-DNj8ZoMu.cjs +0 -4
  128. package/dist/helpers-DNj8ZoMu.cjs.map +0 -1
  129. package/dist/helpers-WY2jfbOT.js +0 -1427
  130. package/dist/helpers-WY2jfbOT.js.map +0 -1
  131. package/dist/worker.entry.d.ts +0 -2
  132. package/dist/worker.entry.d.ts.map +0 -1
  133. package/docs/api-reference.md +0 -815
  134. package/src/createOPFSWorker.ts +0 -57
  135. package/src/worker.entry.ts +0 -6
@@ -0,0 +1,2036 @@
1
+ var N = /* @__PURE__ */ ((s) => (s.Added = "added", s.Changed = "changed", s.Removed = "removed", s))(N || {});
2
+ const mt = {
3
+ ENOENT: -2,
4
+ // No such file or directory
5
+ EISDIR: -21,
6
+ // Is a directory
7
+ ENOTDIR: -20,
8
+ // Not a directory
9
+ EACCES: -13,
10
+ // Permission denied
11
+ EEXIST: -17,
12
+ // File exists
13
+ ENOTEMPTY: -39,
14
+ // Directory not empty
15
+ EINVAL: -22,
16
+ // Invalid argument
17
+ EIO: -5,
18
+ // I/O error
19
+ ENOSPC: -28,
20
+ // No space left on device
21
+ EBUSY: -16,
22
+ // Device or resource busy
23
+ EINTR: -4,
24
+ // Interrupted system call
25
+ ENOTSUP: -95,
26
+ // Operation not supported
27
+ ERANGE: -34,
28
+ // Result too large
29
+ EBADF: -9,
30
+ // Bad file descriptor
31
+ EROOT: -1
32
+ // Custom: Cannot remove root directory
33
+ };
34
+ class m extends Error {
35
+ errno;
36
+ syscall;
37
+ path;
38
+ constructor(t, e, n, r, i) {
39
+ super(t, { cause: i }), this.name = e, this.errno = mt[e] || -1, this.path = n, this.syscall = r;
40
+ }
41
+ }
42
+ class wt extends m {
43
+ constructor(t) {
44
+ super("OPFS is not supported in this browser", "ENOTSUP", void 0, void 0, t);
45
+ }
46
+ }
47
+ class yt extends m {
48
+ constructor(t, e, n) {
49
+ super(t, "INVALID_PATH", e, "access", n);
50
+ }
51
+ }
52
+ class k extends m {
53
+ constructor(t, e, n) {
54
+ const r = {
55
+ file: `File not found: ${e}`,
56
+ directory: `Directory not found: ${e}`,
57
+ source: `Source does not exist: ${e}`
58
+ };
59
+ super(r[t], "ENOENT", e, "access", n);
60
+ }
61
+ }
62
+ class Et extends m {
63
+ constructor(t, e, n) {
64
+ super(`Permission denied for ${e} on: ${t}`, "EACCES", t, e, n);
65
+ }
66
+ }
67
+ class St extends m {
68
+ constructor(t, e, n) {
69
+ super(t, "ENOSPC", e, "write", n);
70
+ }
71
+ }
72
+ class xt extends m {
73
+ constructor(t, e) {
74
+ super(`File is busy: ${t}`, "EBUSY", t, "open", e);
75
+ }
76
+ }
77
+ class q extends m {
78
+ constructor(t, e, n) {
79
+ const r = t === "directory" ? `Is a directory: ${e}` : `Not a directory: ${e}`, i = t === "directory" ? "EISDIR" : "ENOTDIR";
80
+ super(r, i, e, "access", n);
81
+ }
82
+ }
83
+ class D extends m {
84
+ constructor(t, e, n, r) {
85
+ const i = {
86
+ argument: "EINVAL",
87
+ format: "INVALID_FORMAT",
88
+ descriptor: "EBADF",
89
+ overflow: "ERANGE"
90
+ };
91
+ super(e, i[t], n, "validate", r);
92
+ }
93
+ }
94
+ class vt extends m {
95
+ constructor(t, e) {
96
+ super(`Operation aborted: ${t}`, "EINTR", t, "interrupt", e);
97
+ }
98
+ }
99
+ class J extends m {
100
+ constructor(t, e, n) {
101
+ super(t, "EIO", e, "io", n);
102
+ }
103
+ }
104
+ class it extends m {
105
+ constructor(t, e) {
106
+ super(`Operation not supported: ${t}`, "ENOTSUP", t, "operation", e);
107
+ }
108
+ }
109
+ class G extends m {
110
+ constructor(t, e, n) {
111
+ const r = {
112
+ RM_FAILED: `Failed to remove entry: ${e}`,
113
+ ENOTEMPTY: `Directory not empty: ${e}. Use recursive option to force removal.`,
114
+ EROOT: "Cannot remove root directory"
115
+ };
116
+ super(r[t] || `Directory operation failed: ${e}`, t, e, "unlink", n);
117
+ }
118
+ }
119
+ class bt extends m {
120
+ constructor(t, e) {
121
+ super("Failed to initialize OPFS", "INIT_FAILED", t, "init", e);
122
+ }
123
+ }
124
+ class U extends m {
125
+ constructor(t, e, n) {
126
+ super(`Failed to ${t}: ${e}`, `${t.toUpperCase()}_FAILED`, e, t, n);
127
+ }
128
+ }
129
+ class X extends m {
130
+ constructor(t, e) {
131
+ super(`Destination already exists: ${t}`, "EEXIST", t, "open", e);
132
+ }
133
+ }
134
+ function We(s, t, e, n) {
135
+ const r = `${s.toUpperCase()}_FAILED`;
136
+ return new m(`Failed to ${s} file descriptor: ${t}`, r, e, s, n);
137
+ }
138
+ function O(s, t) {
139
+ const e = t?.path, n = t?.isDirectory, r = t?.existenceType ?? "file", i = t?.operation;
140
+ switch (s.name) {
141
+ case "InvalidStateError":
142
+ return new xt(e || "unknown", s);
143
+ case "QuotaExceededError":
144
+ return new St(`No space left on device: ${e || "unknown"}`, e, s);
145
+ case "NotFoundError":
146
+ return new k(r, e, s);
147
+ case "TypeMismatchError":
148
+ return n !== void 0 ? n ? new q("directory", e || "unknown", s) : new q("file", e || "unknown", s) : new D("argument", `Type mismatch: ${e || "unknown"}`, e, s);
149
+ case "NotAllowedError":
150
+ case "SecurityError":
151
+ return new Et(e, "unknown", s);
152
+ case "InvalidModificationError":
153
+ return i === "remove" ? new G("ENOTEMPTY", e, s) : new D("argument", `Invalid modification: ${e || "unknown"}`, e, s);
154
+ case "AbortError":
155
+ return new vt(e || "unknown", s);
156
+ case "OperationError":
157
+ return new J(`Operation failed: ${e || "unknown"}`, e, s);
158
+ case "TypeError":
159
+ return new it(e || "unknown", s);
160
+ default:
161
+ return i === "remove" ? new G("RM_FAILED", e, s) : new J(`I/O error: ${e || "unknown"}`, e, s);
162
+ }
163
+ }
164
+ const ot = (s, t, e) => {
165
+ const n = s instanceof RegExp ? K(s, e) : s, r = t instanceof RegExp ? K(t, e) : t, i = n !== null && r != null && Ot(n, r, e);
166
+ return i && {
167
+ start: i[0],
168
+ end: i[1],
169
+ pre: e.slice(0, i[0]),
170
+ body: e.slice(i[0] + n.length, i[1]),
171
+ post: e.slice(i[1] + r.length)
172
+ };
173
+ }, K = (s, t) => {
174
+ const e = t.match(s);
175
+ return e ? e[0] : null;
176
+ }, Ot = (s, t, e) => {
177
+ let n, r, i, o, a, c = e.indexOf(s), l = e.indexOf(t, c + 1), h = c;
178
+ if (c >= 0 && l > 0) {
179
+ if (s === t)
180
+ return [c, l];
181
+ for (n = [], i = e.length; h >= 0 && !a; ) {
182
+ if (h === c)
183
+ n.push(h), c = e.indexOf(s, h + 1);
184
+ else if (n.length === 1) {
185
+ const d = n.pop();
186
+ d !== void 0 && (a = [d, l]);
187
+ } else
188
+ r = n.pop(), r !== void 0 && r < i && (i = r, o = l), l = e.indexOf(t, h + 1);
189
+ h = c < l && c >= 0 ? c : l;
190
+ }
191
+ n.length && o !== void 0 && (a = [i, o]);
192
+ }
193
+ return a;
194
+ }, at = "\0SLASH" + Math.random() + "\0", ct = "\0OPEN" + Math.random() + "\0", V = "\0CLOSE" + Math.random() + "\0", ht = "\0COMMA" + Math.random() + "\0", lt = "\0PERIOD" + Math.random() + "\0", At = new RegExp(at, "g"), Dt = new RegExp(ct, "g"), Nt = new RegExp(V, "g"), $t = new RegExp(ht, "g"), Ct = new RegExp(lt, "g"), Tt = /\\\\/g, Mt = /\\{/g, Ft = /\\}/g, It = /\\,/g, Pt = /\\./g;
195
+ function B(s) {
196
+ return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
197
+ }
198
+ function Rt(s) {
199
+ return s.replace(Tt, at).replace(Mt, ct).replace(Ft, V).replace(It, ht).replace(Pt, lt);
200
+ }
201
+ function kt(s) {
202
+ return s.replace(At, "\\").replace(Dt, "{").replace(Nt, "}").replace($t, ",").replace(Ct, ".");
203
+ }
204
+ function ut(s) {
205
+ if (!s)
206
+ return [""];
207
+ const t = [], e = ot("{", "}", s);
208
+ if (!e)
209
+ return s.split(",");
210
+ const { pre: n, body: r, post: i } = e, o = n.split(",");
211
+ o[o.length - 1] += "{" + r + "}";
212
+ const a = ut(i);
213
+ return i.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
214
+ }
215
+ function Lt(s) {
216
+ return s ? (s.slice(0, 2) === "{}" && (s = "\\{\\}" + s.slice(2)), F(Rt(s), !0).map(kt)) : [];
217
+ }
218
+ function zt(s) {
219
+ return "{" + s + "}";
220
+ }
221
+ function jt(s) {
222
+ return /^-?0\d/.test(s);
223
+ }
224
+ function Wt(s, t) {
225
+ return s <= t;
226
+ }
227
+ function Ut(s, t) {
228
+ return s >= t;
229
+ }
230
+ function F(s, t) {
231
+ const e = [], n = ot("{", "}", s);
232
+ if (!n)
233
+ return [s];
234
+ const r = n.pre, i = n.post.length ? F(n.post, !1) : [""];
235
+ if (/\$$/.test(n.pre))
236
+ for (let o = 0; o < i.length; o++) {
237
+ const a = r + "{" + n.body + "}" + i[o];
238
+ e.push(a);
239
+ }
240
+ else {
241
+ const o = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(n.body), a = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(n.body), c = o || a, l = n.body.indexOf(",") >= 0;
242
+ if (!c && !l)
243
+ return n.post.match(/,(?!,).*\}/) ? (s = n.pre + "{" + n.body + V + n.post, F(s)) : [s];
244
+ let h;
245
+ if (c)
246
+ h = n.body.split(/\.\./);
247
+ else if (h = ut(n.body), h.length === 1 && h[0] !== void 0 && (h = F(h[0], !1).map(zt), h.length === 1))
248
+ return i.map((u) => n.pre + h[0] + u);
249
+ let d;
250
+ if (c && h[0] !== void 0 && h[1] !== void 0) {
251
+ const u = B(h[0]), f = B(h[1]), g = Math.max(h[0].length, h[1].length);
252
+ let p = h.length === 3 && h[2] !== void 0 ? Math.abs(B(h[2])) : 1, S = Wt;
253
+ f < u && (p *= -1, S = Ut);
254
+ const C = h.some(jt);
255
+ d = [];
256
+ for (let x = u; S(x, f); x += p) {
257
+ let w;
258
+ if (a)
259
+ w = String.fromCharCode(x), w === "\\" && (w = "");
260
+ else if (w = String(x), C) {
261
+ const T = g - w.length;
262
+ if (T > 0) {
263
+ const P = new Array(T + 1).join("0");
264
+ x < 0 ? w = "-" + P + w.slice(1) : w = P + w;
265
+ }
266
+ }
267
+ d.push(w);
268
+ }
269
+ } else {
270
+ d = [];
271
+ for (let u = 0; u < h.length; u++)
272
+ d.push.apply(d, F(h[u], !1));
273
+ }
274
+ for (let u = 0; u < d.length; u++)
275
+ for (let f = 0; f < i.length; f++) {
276
+ const g = r + d[u] + i[f];
277
+ (!t || c || g) && e.push(g);
278
+ }
279
+ }
280
+ return e;
281
+ }
282
+ const Bt = 1024 * 64, L = (s) => {
283
+ if (typeof s != "string")
284
+ throw new TypeError("invalid pattern");
285
+ if (s.length > Bt)
286
+ throw new TypeError("pattern is too long");
287
+ }, Ht = {
288
+ "[:alnum:]": ["\\p{L}\\p{Nl}\\p{Nd}", !0],
289
+ "[:alpha:]": ["\\p{L}\\p{Nl}", !0],
290
+ "[:ascii:]": ["\\x00-\\x7f", !1],
291
+ "[:blank:]": ["\\p{Zs}\\t", !0],
292
+ "[:cntrl:]": ["\\p{Cc}", !0],
293
+ "[:digit:]": ["\\p{Nd}", !0],
294
+ "[:graph:]": ["\\p{Z}\\p{C}", !0, !0],
295
+ "[:lower:]": ["\\p{Ll}", !0],
296
+ "[:print:]": ["\\p{C}", !0],
297
+ "[:punct:]": ["\\p{P}", !0],
298
+ "[:space:]": ["\\p{Z}\\t\\r\\n\\v\\f", !0],
299
+ "[:upper:]": ["\\p{Lu}", !0],
300
+ "[:word:]": ["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}", !0],
301
+ "[:xdigit:]": ["A-Fa-f0-9", !1]
302
+ }, M = (s) => s.replace(/[[\]\\-]/g, "\\$&"), _t = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), Q = (s) => s.join(""), qt = (s, t) => {
303
+ const e = t;
304
+ if (s.charAt(e) !== "[")
305
+ throw new Error("not in a brace expression");
306
+ const n = [], r = [];
307
+ let i = e + 1, o = !1, a = !1, c = !1, l = !1, h = e, d = "";
308
+ t: for (; i < s.length; ) {
309
+ const p = s.charAt(i);
310
+ if ((p === "!" || p === "^") && i === e + 1) {
311
+ l = !0, i++;
312
+ continue;
313
+ }
314
+ if (p === "]" && o && !c) {
315
+ h = i + 1;
316
+ break;
317
+ }
318
+ if (o = !0, p === "\\" && !c) {
319
+ c = !0, i++;
320
+ continue;
321
+ }
322
+ if (p === "[" && !c) {
323
+ for (const [S, [A, C, x]] of Object.entries(Ht))
324
+ if (s.startsWith(S, i)) {
325
+ if (d)
326
+ return ["$.", !1, s.length - e, !0];
327
+ i += S.length, x ? r.push(A) : n.push(A), a = a || C;
328
+ continue t;
329
+ }
330
+ }
331
+ if (c = !1, d) {
332
+ p > d ? n.push(M(d) + "-" + M(p)) : p === d && n.push(M(p)), d = "", i++;
333
+ continue;
334
+ }
335
+ if (s.startsWith("-]", i + 1)) {
336
+ n.push(M(p + "-")), i += 2;
337
+ continue;
338
+ }
339
+ if (s.startsWith("-", i + 1)) {
340
+ d = p, i += 2;
341
+ continue;
342
+ }
343
+ n.push(M(p)), i++;
344
+ }
345
+ if (h < i)
346
+ return ["", !1, 0, !1];
347
+ if (!n.length && !r.length)
348
+ return ["$.", !1, s.length - e, !0];
349
+ if (r.length === 0 && n.length === 1 && /^\\?.$/.test(n[0]) && !l) {
350
+ const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
351
+ return [_t(p), !1, h - e, !1];
352
+ }
353
+ const u = "[" + (l ? "^" : "") + Q(n) + "]", f = "[" + (l ? "" : "^") + Q(r) + "]";
354
+ return [n.length && r.length ? "(" + u + "|" + f + ")" : n.length ? u : f, a, h - e, !0];
355
+ }, I = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\[([^\/\\])\]/g, "$1") : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, "$1$2").replace(/\\([^\/])/g, "$1"), Gt = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), tt = (s) => Gt.has(s), Vt = "(?!(?:^|/)\\.\\.?(?:$|/))", R = "(?!\\.)", Yt = /* @__PURE__ */ new Set(["[", "."]), Zt = /* @__PURE__ */ new Set(["..", "."]), Jt = new Set("().*{}+?[]^$\\!"), Xt = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), Y = "[^/]", et = Y + "*?", st = Y + "+?";
356
+ class E {
357
+ type;
358
+ #s;
359
+ #n;
360
+ #i = !1;
361
+ #t = [];
362
+ #e;
363
+ #o;
364
+ #c;
365
+ #a = !1;
366
+ #r;
367
+ #h;
368
+ // set to true if it's an extglob with no children
369
+ // (which really means one child of '')
370
+ #u = !1;
371
+ constructor(t, e, n = {}) {
372
+ this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#r = this.#s === this ? n : this.#s.#r, this.#c = this.#s === this ? [] : this.#s.#c, t === "!" && !this.#s.#a && this.#c.push(this), this.#o = this.#e ? this.#e.#t.length : 0;
373
+ }
374
+ get hasMagic() {
375
+ if (this.#n !== void 0)
376
+ return this.#n;
377
+ for (const t of this.#t)
378
+ if (typeof t != "string" && (t.type || t.hasMagic))
379
+ return this.#n = !0;
380
+ return this.#n;
381
+ }
382
+ // reconstructs the pattern
383
+ toString() {
384
+ return this.#h !== void 0 ? this.#h : this.type ? this.#h = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#h = this.#t.map((t) => String(t)).join("");
385
+ }
386
+ #d() {
387
+ if (this !== this.#s)
388
+ throw new Error("should only call on root");
389
+ if (this.#a)
390
+ return this;
391
+ this.toString(), this.#a = !0;
392
+ let t;
393
+ for (; t = this.#c.pop(); ) {
394
+ if (t.type !== "!")
395
+ continue;
396
+ let e = t, n = e.#e;
397
+ for (; n; ) {
398
+ for (let r = e.#o + 1; !n.type && r < n.#t.length; r++)
399
+ for (const i of t.#t) {
400
+ if (typeof i == "string")
401
+ throw new Error("string part in extglob AST??");
402
+ i.copyIn(n.#t[r]);
403
+ }
404
+ e = n, n = e.#e;
405
+ }
406
+ }
407
+ return this;
408
+ }
409
+ push(...t) {
410
+ for (const e of t)
411
+ if (e !== "") {
412
+ if (typeof e != "string" && !(e instanceof E && e.#e === this))
413
+ throw new Error("invalid part: " + e);
414
+ this.#t.push(e);
415
+ }
416
+ }
417
+ toJSON() {
418
+ const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
419
+ return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
420
+ }
421
+ isStart() {
422
+ if (this.#s === this)
423
+ return !0;
424
+ if (!this.#e?.isStart())
425
+ return !1;
426
+ if (this.#o === 0)
427
+ return !0;
428
+ const t = this.#e;
429
+ for (let e = 0; e < this.#o; e++) {
430
+ const n = t.#t[e];
431
+ if (!(n instanceof E && n.type === "!"))
432
+ return !1;
433
+ }
434
+ return !0;
435
+ }
436
+ isEnd() {
437
+ if (this.#s === this || this.#e?.type === "!")
438
+ return !0;
439
+ if (!this.#e?.isEnd())
440
+ return !1;
441
+ if (!this.type)
442
+ return this.#e?.isEnd();
443
+ const t = this.#e ? this.#e.#t.length : 0;
444
+ return this.#o === t - 1;
445
+ }
446
+ copyIn(t) {
447
+ typeof t == "string" ? this.push(t) : this.push(t.clone(this));
448
+ }
449
+ clone(t) {
450
+ const e = new E(this.type, t);
451
+ for (const n of this.#t)
452
+ e.copyIn(n);
453
+ return e;
454
+ }
455
+ static #l(t, e, n, r) {
456
+ let i = !1, o = !1, a = -1, c = !1;
457
+ if (e.type === null) {
458
+ let f = n, g = "";
459
+ for (; f < t.length; ) {
460
+ const p = t.charAt(f++);
461
+ if (i || p === "\\") {
462
+ i = !i, g += p;
463
+ continue;
464
+ }
465
+ if (o) {
466
+ f === a + 1 ? (p === "^" || p === "!") && (c = !0) : p === "]" && !(f === a + 2 && c) && (o = !1), g += p;
467
+ continue;
468
+ } else if (p === "[") {
469
+ o = !0, a = f, c = !1, g += p;
470
+ continue;
471
+ }
472
+ if (!r.noext && tt(p) && t.charAt(f) === "(") {
473
+ e.push(g), g = "";
474
+ const S = new E(p, e);
475
+ f = E.#l(t, S, f, r), e.push(S);
476
+ continue;
477
+ }
478
+ g += p;
479
+ }
480
+ return e.push(g), f;
481
+ }
482
+ let l = n + 1, h = new E(null, e);
483
+ const d = [];
484
+ let u = "";
485
+ for (; l < t.length; ) {
486
+ const f = t.charAt(l++);
487
+ if (i || f === "\\") {
488
+ i = !i, u += f;
489
+ continue;
490
+ }
491
+ if (o) {
492
+ l === a + 1 ? (f === "^" || f === "!") && (c = !0) : f === "]" && !(l === a + 2 && c) && (o = !1), u += f;
493
+ continue;
494
+ } else if (f === "[") {
495
+ o = !0, a = l, c = !1, u += f;
496
+ continue;
497
+ }
498
+ if (tt(f) && t.charAt(l) === "(") {
499
+ h.push(u), u = "";
500
+ const g = new E(f, h);
501
+ h.push(g), l = E.#l(t, g, l, r);
502
+ continue;
503
+ }
504
+ if (f === "|") {
505
+ h.push(u), u = "", d.push(h), h = new E(null, e);
506
+ continue;
507
+ }
508
+ if (f === ")")
509
+ return u === "" && e.#t.length === 0 && (e.#u = !0), h.push(u), u = "", e.push(...d, h), l;
510
+ u += f;
511
+ }
512
+ return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], l;
513
+ }
514
+ static fromGlob(t, e = {}) {
515
+ const n = new E(null, void 0, e);
516
+ return E.#l(t, n, 0, e), n;
517
+ }
518
+ // returns the regular expression if there's magic, or the unescaped
519
+ // string if not.
520
+ toMMPattern() {
521
+ if (this !== this.#s)
522
+ return this.#s.toMMPattern();
523
+ const t = this.toString(), [e, n, r, i] = this.toRegExpSource();
524
+ if (!(r || this.#n || this.#r.nocase && !this.#r.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
525
+ return n;
526
+ const a = (this.#r.nocase ? "i" : "") + (i ? "u" : "");
527
+ return Object.assign(new RegExp(`^${e}$`, a), {
528
+ _src: e,
529
+ _glob: t
530
+ });
531
+ }
532
+ get options() {
533
+ return this.#r;
534
+ }
535
+ // returns the string match, the regexp source, whether there's magic
536
+ // in the regexp (so a regular expression is required) and whether or
537
+ // not the uflag is needed for the regular expression (for posix classes)
538
+ // TODO: instead of injecting the start/end at this point, just return
539
+ // the BODY of the regexp, along with the start/end portions suitable
540
+ // for binding the start/end in either a joined full-path makeRe context
541
+ // (where we bind to (^|/), or a standalone matchPart context (where
542
+ // we bind to ^, and not /). Otherwise slashes get duped!
543
+ //
544
+ // In part-matching mode, the start is:
545
+ // - if not isStart: nothing
546
+ // - if traversal possible, but not allowed: ^(?!\.\.?$)
547
+ // - if dots allowed or not possible: ^
548
+ // - if dots possible and not allowed: ^(?!\.)
549
+ // end is:
550
+ // - if not isEnd(): nothing
551
+ // - else: $
552
+ //
553
+ // In full-path matching mode, we put the slash at the START of the
554
+ // pattern, so start is:
555
+ // - if first pattern: same as part-matching mode
556
+ // - if not isStart(): nothing
557
+ // - if traversal possible, but not allowed: /(?!\.\.?(?:$|/))
558
+ // - if dots allowed or not possible: /
559
+ // - if dots possible and not allowed: /(?!\.)
560
+ // end is:
561
+ // - if last pattern, same as part-matching mode
562
+ // - else nothing
563
+ //
564
+ // Always put the (?:$|/) on negated tails, though, because that has to be
565
+ // there to bind the end of the negated pattern portion, and it's easier to
566
+ // just stick it in now rather than try to inject it later in the middle of
567
+ // the pattern.
568
+ //
569
+ // We can just always return the same end, and leave it up to the caller
570
+ // to know whether it's going to be used joined or in parts.
571
+ // And, if the start is adjusted slightly, can do the same there:
572
+ // - if not isStart: nothing
573
+ // - if traversal possible, but not allowed: (?:/|^)(?!\.\.?$)
574
+ // - if dots allowed or not possible: (?:/|^)
575
+ // - if dots possible and not allowed: (?:/|^)(?!\.)
576
+ //
577
+ // But it's better to have a simpler binding without a conditional, for
578
+ // performance, so probably better to return both start options.
579
+ //
580
+ // Then the caller just ignores the end if it's not the first pattern,
581
+ // and the start always gets applied.
582
+ //
583
+ // But that's always going to be $ if it's the ending pattern, or nothing,
584
+ // so the caller can just attach $ at the end of the pattern when building.
585
+ //
586
+ // So the todo is:
587
+ // - better detect what kind of start is needed
588
+ // - return both flavors of starting pattern
589
+ // - attach $ at the end of the pattern when creating the actual RegExp
590
+ //
591
+ // Ah, but wait, no, that all only applies to the root when the first pattern
592
+ // is not an extglob. If the first pattern IS an extglob, then we need all
593
+ // that dot prevention biz to live in the extglob portions, because eg
594
+ // +(*|.x*) can match .xy but not .yx.
595
+ //
596
+ // So, return the two flavors if it's #root and the first child is not an
597
+ // AST, otherwise leave it to the child AST to handle it, and there,
598
+ // use the (?:^|/) style of start binding.
599
+ //
600
+ // Even simplified further:
601
+ // - Since the start for a join is eg /(?!\.) and the start for a part
602
+ // is ^(?!\.), we can just prepend (?!\.) to the pattern (either root
603
+ // or start or whatever) and prepend ^ or / at the Regexp construction.
604
+ toRegExpSource(t) {
605
+ const e = t ?? !!this.#r.dot;
606
+ if (this.#s === this && this.#d(), !this.type) {
607
+ const c = this.isStart() && this.isEnd(), l = this.#t.map((f) => {
608
+ const [g, p, S, A] = typeof f == "string" ? E.#p(f, this.#n, c) : f.toRegExpSource(t);
609
+ return this.#n = this.#n || S, this.#i = this.#i || A, g;
610
+ }).join("");
611
+ let h = "";
612
+ if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Zt.has(this.#t[0]))) {
613
+ const g = Yt, p = (
614
+ // dots are allowed, and the pattern starts with [ or .
615
+ e && g.has(l.charAt(0)) || // the pattern starts with \., and then [ or .
616
+ l.startsWith("\\.") && g.has(l.charAt(2)) || // the pattern starts with \.\., and then [ or .
617
+ l.startsWith("\\.\\.") && g.has(l.charAt(4))
618
+ ), S = !e && !t && g.has(l.charAt(0));
619
+ h = p ? Vt : S ? R : "";
620
+ }
621
+ let d = "";
622
+ return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (d = "(?:$|\\/)"), [
623
+ h + l + d,
624
+ I(l),
625
+ this.#n = !!this.#n,
626
+ this.#i
627
+ ];
628
+ }
629
+ const n = this.type === "*" || this.type === "+", r = this.type === "!" ? "(?:(?!(?:" : "(?:";
630
+ let i = this.#f(e);
631
+ if (this.isStart() && this.isEnd() && !i && this.type !== "!") {
632
+ const c = this.toString();
633
+ return this.#t = [c], this.type = null, this.#n = void 0, [c, I(this.toString()), !1, !1];
634
+ }
635
+ let o = !n || t || e || !R ? "" : this.#f(!0);
636
+ o === i && (o = ""), o && (i = `(?:${i})(?:${o})*?`);
637
+ let a = "";
638
+ if (this.type === "!" && this.#u)
639
+ a = (this.isStart() && !e ? R : "") + st;
640
+ else {
641
+ const c = this.type === "!" ? (
642
+ // !() must match something,but !(x) can match ''
643
+ "))" + (this.isStart() && !e && !t ? R : "") + et + ")"
644
+ ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : `)${this.type}`;
645
+ a = r + i + c;
646
+ }
647
+ return [
648
+ a,
649
+ I(i),
650
+ this.#n = !!this.#n,
651
+ this.#i
652
+ ];
653
+ }
654
+ #f(t) {
655
+ return this.#t.map((e) => {
656
+ if (typeof e == "string")
657
+ throw new Error("string type in extglob ast??");
658
+ const [n, r, i, o] = e.toRegExpSource(t);
659
+ return this.#i = this.#i || o, n;
660
+ }).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
661
+ }
662
+ static #p(t, e, n = !1) {
663
+ let r = !1, i = "", o = !1;
664
+ for (let a = 0; a < t.length; a++) {
665
+ const c = t.charAt(a);
666
+ if (r) {
667
+ r = !1, i += (Jt.has(c) ? "\\" : "") + c;
668
+ continue;
669
+ }
670
+ if (c === "\\") {
671
+ a === t.length - 1 ? i += "\\\\" : r = !0;
672
+ continue;
673
+ }
674
+ if (c === "[") {
675
+ const [l, h, d, u] = qt(t, a);
676
+ if (d) {
677
+ i += l, o = o || h, a += d - 1, e = e || u;
678
+ continue;
679
+ }
680
+ }
681
+ if (c === "*") {
682
+ n && t === "*" ? i += st : i += et, e = !0;
683
+ continue;
684
+ }
685
+ if (c === "?") {
686
+ i += Y, e = !0;
687
+ continue;
688
+ }
689
+ i += Xt(c);
690
+ }
691
+ return [i, I(t), !!e, o];
692
+ }
693
+ }
694
+ const Kt = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\]]/g, "[$&]") : s.replace(/[?*()[\]\\]/g, "\\$&"), y = (s, t, e = {}) => (L(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new W(t, e).match(s)), Qt = /^\*+([^+@!?\*\[\(]*)$/, te = (s) => (t) => !t.startsWith(".") && t.endsWith(s), ee = (s) => (t) => t.endsWith(s), se = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), ne = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), re = /^\*+\.\*+$/, ie = (s) => !s.startsWith(".") && s.includes("."), oe = (s) => s !== "." && s !== ".." && s.includes("."), ae = /^\.\*+$/, ce = (s) => s !== "." && s !== ".." && s.startsWith("."), he = /^\*+$/, le = (s) => s.length !== 0 && !s.startsWith("."), ue = (s) => s.length !== 0 && s !== "." && s !== "..", fe = /^\?+([^+@!?\*\[\(]*)?$/, de = ([s, t = ""]) => {
695
+ const e = ft([s]);
696
+ return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
697
+ }, pe = ([s, t = ""]) => {
698
+ const e = dt([s]);
699
+ return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
700
+ }, ge = ([s, t = ""]) => {
701
+ const e = dt([s]);
702
+ return t ? (n) => e(n) && n.endsWith(t) : e;
703
+ }, me = ([s, t = ""]) => {
704
+ const e = ft([s]);
705
+ return t ? (n) => e(n) && n.endsWith(t) : e;
706
+ }, ft = ([s]) => {
707
+ const t = s.length;
708
+ return (e) => e.length === t && !e.startsWith(".");
709
+ }, dt = ([s]) => {
710
+ const t = s.length;
711
+ return (e) => e.length === t && e !== "." && e !== "..";
712
+ }, pt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", nt = {
713
+ win32: { sep: "\\" },
714
+ posix: { sep: "/" }
715
+ }, we = pt === "win32" ? nt.win32.sep : nt.posix.sep;
716
+ y.sep = we;
717
+ const b = Symbol("globstar **");
718
+ y.GLOBSTAR = b;
719
+ const ye = "[^/]", Ee = ye + "*?", Se = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?", xe = "(?:(?!(?:\\/|^)\\.).)*?", ve = (s, t = {}) => (e) => y(e, s, t);
720
+ y.filter = ve;
721
+ const v = (s, t = {}) => Object.assign({}, s, t), be = (s) => {
722
+ if (!s || typeof s != "object" || !Object.keys(s).length)
723
+ return y;
724
+ const t = y;
725
+ return Object.assign((n, r, i = {}) => t(n, r, v(s, i)), {
726
+ Minimatch: class extends t.Minimatch {
727
+ constructor(r, i = {}) {
728
+ super(r, v(s, i));
729
+ }
730
+ static defaults(r) {
731
+ return t.defaults(v(s, r)).Minimatch;
732
+ }
733
+ },
734
+ AST: class extends t.AST {
735
+ /* c8 ignore start */
736
+ constructor(r, i, o = {}) {
737
+ super(r, i, v(s, o));
738
+ }
739
+ /* c8 ignore stop */
740
+ static fromGlob(r, i = {}) {
741
+ return t.AST.fromGlob(r, v(s, i));
742
+ }
743
+ },
744
+ unescape: (n, r = {}) => t.unescape(n, v(s, r)),
745
+ escape: (n, r = {}) => t.escape(n, v(s, r)),
746
+ filter: (n, r = {}) => t.filter(n, v(s, r)),
747
+ defaults: (n) => t.defaults(v(s, n)),
748
+ makeRe: (n, r = {}) => t.makeRe(n, v(s, r)),
749
+ braceExpand: (n, r = {}) => t.braceExpand(n, v(s, r)),
750
+ match: (n, r, i = {}) => t.match(n, r, v(s, i)),
751
+ sep: t.sep,
752
+ GLOBSTAR: b
753
+ });
754
+ };
755
+ y.defaults = be;
756
+ const gt = (s, t = {}) => (L(s), t.nobrace || !/\{(?:(?!\{).)*\}/.test(s) ? [s] : Lt(s));
757
+ y.braceExpand = gt;
758
+ const Oe = (s, t = {}) => new W(s, t).makeRe();
759
+ y.makeRe = Oe;
760
+ const Ae = (s, t, e = {}) => {
761
+ const n = new W(t, e);
762
+ return s = s.filter((r) => n.match(r)), n.options.nonull && !s.length && s.push(t), s;
763
+ };
764
+ y.match = Ae;
765
+ const rt = /[?*]|[+@!]\(.*?\)|\[|\]/, De = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
766
+ class W {
767
+ options;
768
+ set;
769
+ pattern;
770
+ windowsPathsNoEscape;
771
+ nonegate;
772
+ negate;
773
+ comment;
774
+ empty;
775
+ preserveMultipleSlashes;
776
+ partial;
777
+ globSet;
778
+ globParts;
779
+ nocase;
780
+ isWindows;
781
+ platform;
782
+ windowsNoMagicRoot;
783
+ regexp;
784
+ constructor(t, e = {}) {
785
+ L(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || pt, 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();
786
+ }
787
+ hasMagic() {
788
+ if (this.options.magicalBraces && this.set.length > 1)
789
+ return !0;
790
+ for (const t of this.set)
791
+ for (const e of t)
792
+ if (typeof e != "string")
793
+ return !0;
794
+ return !1;
795
+ }
796
+ debug(...t) {
797
+ }
798
+ make() {
799
+ const t = this.pattern, e = this.options;
800
+ if (!e.nocomment && t.charAt(0) === "#") {
801
+ this.comment = !0;
802
+ return;
803
+ }
804
+ if (!t) {
805
+ this.empty = !0;
806
+ return;
807
+ }
808
+ this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...i) => console.error(...i)), this.debug(this.pattern, this.globSet);
809
+ const n = this.globSet.map((i) => this.slashSplit(i));
810
+ this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
811
+ let r = this.globParts.map((i, o, a) => {
812
+ if (this.isWindows && this.windowsNoMagicRoot) {
813
+ const c = i[0] === "" && i[1] === "" && (i[2] === "?" || !rt.test(i[2])) && !rt.test(i[3]), l = /^[a-z]:/i.test(i[0]);
814
+ if (c)
815
+ return [...i.slice(0, 4), ...i.slice(4).map((h) => this.parse(h))];
816
+ if (l)
817
+ return [i[0], ...i.slice(1).map((h) => this.parse(h))];
818
+ }
819
+ return i.map((c) => this.parse(c));
820
+ });
821
+ if (this.debug(this.pattern, r), this.set = r.filter((i) => i.indexOf(!1) === -1), this.isWindows)
822
+ for (let i = 0; i < this.set.length; i++) {
823
+ const o = this.set[i];
824
+ o[0] === "" && o[1] === "" && this.globParts[i][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
825
+ }
826
+ this.debug(this.pattern, this.set);
827
+ }
828
+ // various transforms to equivalent pattern sets that are
829
+ // faster to process in a filesystem walk. The goal is to
830
+ // eliminate what we can, and push all ** patterns as far
831
+ // to the right as possible, even if it increases the number
832
+ // of patterns that we have to process.
833
+ preprocess(t) {
834
+ if (this.options.noglobstar)
835
+ for (let n = 0; n < t.length; n++)
836
+ for (let r = 0; r < t[n].length; r++)
837
+ t[n][r] === "**" && (t[n][r] = "*");
838
+ const { optimizationLevel: e = 1 } = this.options;
839
+ return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
840
+ }
841
+ // just get rid of adjascent ** portions
842
+ adjascentGlobstarOptimize(t) {
843
+ return t.map((e) => {
844
+ let n = -1;
845
+ for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
846
+ let r = n;
847
+ for (; e[r + 1] === "**"; )
848
+ r++;
849
+ r !== n && e.splice(n, r - n);
850
+ }
851
+ return e;
852
+ });
853
+ }
854
+ // get rid of adjascent ** and resolve .. portions
855
+ levelOneOptimize(t) {
856
+ return t.map((e) => (e = e.reduce((n, r) => {
857
+ const i = n[n.length - 1];
858
+ return r === "**" && i === "**" ? n : r === ".." && i && i !== ".." && i !== "." && i !== "**" ? (n.pop(), n) : (n.push(r), n);
859
+ }, []), e.length === 0 ? [""] : e));
860
+ }
861
+ levelTwoFileOptimize(t) {
862
+ Array.isArray(t) || (t = this.slashSplit(t));
863
+ let e = !1;
864
+ do {
865
+ if (e = !1, !this.preserveMultipleSlashes) {
866
+ for (let r = 1; r < t.length - 1; r++) {
867
+ const i = t[r];
868
+ r === 1 && i === "" && t[0] === "" || (i === "." || i === "") && (e = !0, t.splice(r, 1), r--);
869
+ }
870
+ t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
871
+ }
872
+ let n = 0;
873
+ for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
874
+ const r = t[n - 1];
875
+ r && r !== "." && r !== ".." && r !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
876
+ }
877
+ } while (e);
878
+ return t.length === 0 ? [""] : t;
879
+ }
880
+ // First phase: single-pattern processing
881
+ // <pre> is 1 or more portions
882
+ // <rest> is 1 or more portions
883
+ // <p> is any portion other than ., .., '', or **
884
+ // <e> is . or ''
885
+ //
886
+ // **/.. is *brutal* for filesystem walking performance, because
887
+ // it effectively resets the recursive walk each time it occurs,
888
+ // and ** cannot be reduced out by a .. pattern part like a regexp
889
+ // or most strings (other than .., ., and '') can be.
890
+ //
891
+ // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
892
+ // <pre>/<e>/<rest> -> <pre>/<rest>
893
+ // <pre>/<p>/../<rest> -> <pre>/<rest>
894
+ // **/**/<rest> -> **/<rest>
895
+ //
896
+ // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
897
+ // this WOULD be allowed if ** did follow symlinks, or * didn't
898
+ firstPhasePreProcess(t) {
899
+ let e = !1;
900
+ do {
901
+ e = !1;
902
+ for (let n of t) {
903
+ let r = -1;
904
+ for (; (r = n.indexOf("**", r + 1)) !== -1; ) {
905
+ let o = r;
906
+ for (; n[o + 1] === "**"; )
907
+ o++;
908
+ o > r && n.splice(r + 1, o - r);
909
+ let a = n[r + 1];
910
+ const c = n[r + 2], l = n[r + 3];
911
+ if (a !== ".." || !c || c === "." || c === ".." || !l || l === "." || l === "..")
912
+ continue;
913
+ e = !0, n.splice(r, 1);
914
+ const h = n.slice(0);
915
+ h[r] = "**", t.push(h), r--;
916
+ }
917
+ if (!this.preserveMultipleSlashes) {
918
+ for (let o = 1; o < n.length - 1; o++) {
919
+ const a = n[o];
920
+ o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (e = !0, n.splice(o, 1), o--);
921
+ }
922
+ n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
923
+ }
924
+ let i = 0;
925
+ for (; (i = n.indexOf("..", i + 1)) !== -1; ) {
926
+ const o = n[i - 1];
927
+ if (o && o !== "." && o !== ".." && o !== "**") {
928
+ e = !0;
929
+ const c = i === 1 && n[i + 1] === "**" ? ["."] : [];
930
+ n.splice(i - 1, 2, ...c), n.length === 0 && n.push(""), i -= 2;
931
+ }
932
+ }
933
+ }
934
+ } while (e);
935
+ return t;
936
+ }
937
+ // second phase: multi-pattern dedupes
938
+ // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
939
+ // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
940
+ // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
941
+ //
942
+ // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
943
+ // ^-- not valid because ** doens't follow symlinks
944
+ secondPhasePreProcess(t) {
945
+ for (let e = 0; e < t.length - 1; e++)
946
+ for (let n = e + 1; n < t.length; n++) {
947
+ const r = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
948
+ if (r) {
949
+ t[e] = [], t[n] = r;
950
+ break;
951
+ }
952
+ }
953
+ return t.filter((e) => e.length);
954
+ }
955
+ partsMatch(t, e, n = !1) {
956
+ let r = 0, i = 0, o = [], a = "";
957
+ for (; r < t.length && i < e.length; )
958
+ if (t[r] === e[i])
959
+ o.push(a === "b" ? e[i] : t[r]), r++, i++;
960
+ else if (n && t[r] === "**" && e[i] === t[r + 1])
961
+ o.push(t[r]), r++;
962
+ else if (n && e[i] === "**" && t[r] === e[i + 1])
963
+ o.push(e[i]), i++;
964
+ else if (t[r] === "*" && e[i] && (this.options.dot || !e[i].startsWith(".")) && e[i] !== "**") {
965
+ if (a === "b")
966
+ return !1;
967
+ a = "a", o.push(t[r]), r++, i++;
968
+ } else if (e[i] === "*" && t[r] && (this.options.dot || !t[r].startsWith(".")) && t[r] !== "**") {
969
+ if (a === "a")
970
+ return !1;
971
+ a = "b", o.push(e[i]), r++, i++;
972
+ } else
973
+ return !1;
974
+ return t.length === e.length && o;
975
+ }
976
+ parseNegate() {
977
+ if (this.nonegate)
978
+ return;
979
+ const t = this.pattern;
980
+ let e = !1, n = 0;
981
+ for (let r = 0; r < t.length && t.charAt(r) === "!"; r++)
982
+ e = !e, n++;
983
+ n && (this.pattern = t.slice(n)), this.negate = e;
984
+ }
985
+ // set partial to true to test if, for example,
986
+ // "/a/b" matches the start of "/*/b/*/d"
987
+ // Partial means, if you run out of file before you run
988
+ // out of pattern, then that's fine, as long as all
989
+ // the parts match.
990
+ matchOne(t, e, n = !1) {
991
+ const r = this.options;
992
+ if (this.isWindows) {
993
+ const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), C = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, w = C ? 3 : A ? 0 : void 0;
994
+ if (typeof x == "number" && typeof w == "number") {
995
+ const [T, P] = [t[x], e[w]];
996
+ T.toLowerCase() === P.toLowerCase() && (e[w] = T, w > x ? e = e.slice(w) : x > w && (t = t.slice(x)));
997
+ }
998
+ }
999
+ const { optimizationLevel: i = 1 } = this.options;
1000
+ i >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
1001
+ for (var o = 0, a = 0, c = t.length, l = e.length; o < c && a < l; o++, a++) {
1002
+ this.debug("matchOne loop");
1003
+ var h = e[a], d = t[o];
1004
+ if (this.debug(e, h, d), h === !1)
1005
+ return !1;
1006
+ if (h === b) {
1007
+ this.debug("GLOBSTAR", [e, h, d]);
1008
+ var u = o, f = a + 1;
1009
+ if (f === l) {
1010
+ for (this.debug("** at the end"); o < c; o++)
1011
+ if (t[o] === "." || t[o] === ".." || !r.dot && t[o].charAt(0) === ".")
1012
+ return !1;
1013
+ return !0;
1014
+ }
1015
+ for (; u < c; ) {
1016
+ var g = t[u];
1017
+ if (this.debug(`
1018
+ globstar while`, t, u, e, f, g), this.matchOne(t.slice(u), e.slice(f), n))
1019
+ return this.debug("globstar found match!", u, c, g), !0;
1020
+ if (g === "." || g === ".." || !r.dot && g.charAt(0) === ".") {
1021
+ this.debug("dot detected!", t, u, e, f);
1022
+ break;
1023
+ }
1024
+ this.debug("globstar swallow a segment, and continue"), u++;
1025
+ }
1026
+ return !!(n && (this.debug(`
1027
+ >>> no match, partial?`, t, u, e, f), u === c));
1028
+ }
1029
+ let p;
1030
+ if (typeof h == "string" ? (p = d === h, this.debug("string match", h, d, p)) : (p = h.test(d), this.debug("pattern match", h, d, p)), !p)
1031
+ return !1;
1032
+ }
1033
+ if (o === c && a === l)
1034
+ return !0;
1035
+ if (o === c)
1036
+ return n;
1037
+ if (a === l)
1038
+ return o === c - 1 && t[o] === "";
1039
+ throw new Error("wtf?");
1040
+ }
1041
+ braceExpand() {
1042
+ return gt(this.pattern, this.options);
1043
+ }
1044
+ parse(t) {
1045
+ L(t);
1046
+ const e = this.options;
1047
+ if (t === "**")
1048
+ return b;
1049
+ if (t === "")
1050
+ return "";
1051
+ let n, r = null;
1052
+ (n = t.match(he)) ? r = e.dot ? ue : le : (n = t.match(Qt)) ? r = (e.nocase ? e.dot ? ne : se : e.dot ? ee : te)(n[1]) : (n = t.match(fe)) ? r = (e.nocase ? e.dot ? pe : de : e.dot ? ge : me)(n) : (n = t.match(re)) ? r = e.dot ? oe : ie : (n = t.match(ae)) && (r = ce);
1053
+ const i = E.fromGlob(t, this.options).toMMPattern();
1054
+ return r && typeof i == "object" && Reflect.defineProperty(i, "test", { value: r }), i;
1055
+ }
1056
+ makeRe() {
1057
+ if (this.regexp || this.regexp === !1)
1058
+ return this.regexp;
1059
+ const t = this.set;
1060
+ if (!t.length)
1061
+ return this.regexp = !1, this.regexp;
1062
+ const e = this.options, n = e.noglobstar ? Ee : e.dot ? Se : xe, r = new Set(e.nocase ? ["i"] : []);
1063
+ let i = t.map((c) => {
1064
+ const l = c.map((h) => {
1065
+ if (h instanceof RegExp)
1066
+ for (const d of h.flags.split(""))
1067
+ r.add(d);
1068
+ return typeof h == "string" ? De(h) : h === b ? b : h._src;
1069
+ });
1070
+ return l.forEach((h, d) => {
1071
+ const u = l[d + 1], f = l[d - 1];
1072
+ h !== b || f === b || (f === void 0 ? u !== void 0 && u !== b ? l[d + 1] = "(?:\\/|" + n + "\\/)?" + u : l[d] = n : u === void 0 ? l[d - 1] = f + "(?:\\/|" + n + ")?" : u !== b && (l[d - 1] = f + "(?:\\/|\\/" + n + "\\/)" + u, l[d + 1] = b));
1073
+ }), l.filter((h) => h !== b).join("/");
1074
+ }).join("|");
1075
+ const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1076
+ i = "^" + o + i + a + "$", this.negate && (i = "^(?!" + i + ").+$");
1077
+ try {
1078
+ this.regexp = new RegExp(i, [...r].join(""));
1079
+ } catch {
1080
+ this.regexp = !1;
1081
+ }
1082
+ return this.regexp;
1083
+ }
1084
+ slashSplit(t) {
1085
+ return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\/\/[^\/]+/.test(t) ? ["", ...t.split(/\/+/)] : t.split(/\/+/);
1086
+ }
1087
+ match(t, e = this.partial) {
1088
+ if (this.debug("match", t, this.pattern), this.comment)
1089
+ return !1;
1090
+ if (this.empty)
1091
+ return t === "";
1092
+ if (t === "/" && e)
1093
+ return !0;
1094
+ const n = this.options;
1095
+ this.isWindows && (t = t.split("\\").join("/"));
1096
+ const r = this.slashSplit(t);
1097
+ this.debug(this.pattern, "split", r);
1098
+ const i = this.set;
1099
+ this.debug(this.pattern, "set", i);
1100
+ let o = r[r.length - 1];
1101
+ if (!o)
1102
+ for (let a = r.length - 2; !o && a >= 0; a--)
1103
+ o = r[a];
1104
+ for (let a = 0; a < i.length; a++) {
1105
+ const c = i[a];
1106
+ let l = r;
1107
+ if (n.matchBase && c.length === 1 && (l = [o]), this.matchOne(l, c, e))
1108
+ return n.flipNegate ? !0 : !this.negate;
1109
+ }
1110
+ return n.flipNegate ? !1 : this.negate;
1111
+ }
1112
+ static defaults(t) {
1113
+ return y.defaults(t).Minimatch;
1114
+ }
1115
+ }
1116
+ y.AST = E;
1117
+ y.Minimatch = W;
1118
+ y.escape = Kt;
1119
+ y.unescape = I;
1120
+ const Ne = [
1121
+ // Images
1122
+ ".jpg",
1123
+ ".jpeg",
1124
+ ".png",
1125
+ ".gif",
1126
+ ".bmp",
1127
+ ".webp",
1128
+ ".ico",
1129
+ ".tiff",
1130
+ ".tga",
1131
+ // Audio
1132
+ ".mp3",
1133
+ ".wav",
1134
+ ".ogg",
1135
+ ".flac",
1136
+ ".aac",
1137
+ ".wma",
1138
+ ".m4a",
1139
+ // Video
1140
+ ".mp4",
1141
+ ".avi",
1142
+ ".mov",
1143
+ ".wmv",
1144
+ ".flv",
1145
+ ".webm",
1146
+ ".mkv",
1147
+ ".m4v",
1148
+ // Documents
1149
+ ".pdf",
1150
+ ".doc",
1151
+ ".docx",
1152
+ ".xls",
1153
+ ".xlsx",
1154
+ ".ppt",
1155
+ ".pptx",
1156
+ // Archives
1157
+ ".zip",
1158
+ ".rar",
1159
+ ".7z",
1160
+ ".tar",
1161
+ ".gz",
1162
+ ".bz2",
1163
+ // Executables
1164
+ ".exe",
1165
+ ".dll",
1166
+ ".so",
1167
+ ".dylib",
1168
+ // Other binary formats
1169
+ ".dat",
1170
+ ".db",
1171
+ ".sqlite",
1172
+ ".bin",
1173
+ ".obj",
1174
+ ".fbx",
1175
+ ".3ds"
1176
+ ];
1177
+ function He(s) {
1178
+ const t = s.lastIndexOf(".");
1179
+ if (t <= 0)
1180
+ return !0;
1181
+ const e = s.slice(t).toLowerCase();
1182
+ return Ne.includes(e);
1183
+ }
1184
+ function $e(s, t = "utf-8") {
1185
+ switch (t) {
1186
+ case "utf8":
1187
+ case "utf-8":
1188
+ return new TextEncoder().encode(s);
1189
+ case "utf16le":
1190
+ case "utf-16le":
1191
+ case "ucs2":
1192
+ case "ucs-2":
1193
+ return Ce(s);
1194
+ case "ascii":
1195
+ return Fe(s);
1196
+ case "latin1":
1197
+ return Me(s);
1198
+ case "binary":
1199
+ return Uint8Array.from(s, (e) => e.charCodeAt(0));
1200
+ case "base64":
1201
+ return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
1202
+ case "hex":
1203
+ if (!/^[\da-f]+$/i.test(s) || s.length % 2 !== 0)
1204
+ throw new D("format", "Invalid hex string");
1205
+ return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
1206
+ default:
1207
+ return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
1208
+ }
1209
+ }
1210
+ function _e(s, t = "utf-8") {
1211
+ switch (t) {
1212
+ case "utf8":
1213
+ case "utf-8":
1214
+ return new TextDecoder().decode(s);
1215
+ case "utf16le":
1216
+ case "utf-16le":
1217
+ case "ucs2":
1218
+ case "ucs-2":
1219
+ return Te(s);
1220
+ case "latin1":
1221
+ return String.fromCharCode(...s);
1222
+ case "ascii":
1223
+ return String.fromCharCode(...s.map((e) => e & 127));
1224
+ case "base64":
1225
+ return btoa(String.fromCharCode(...s));
1226
+ case "hex":
1227
+ return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
1228
+ default:
1229
+ return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
1230
+ }
1231
+ }
1232
+ function Ce(s) {
1233
+ const t = new Uint8Array(s.length * 2);
1234
+ for (let e = 0; e < s.length; e++) {
1235
+ const n = s.charCodeAt(e);
1236
+ t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
1237
+ }
1238
+ return t;
1239
+ }
1240
+ function Te(s) {
1241
+ s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
1242
+ const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
1243
+ return String.fromCharCode(...t);
1244
+ }
1245
+ function Me(s) {
1246
+ const t = new Uint8Array(s.length);
1247
+ for (let e = 0; e < s.length; e++)
1248
+ t[e] = s.charCodeAt(e) & 255;
1249
+ return t;
1250
+ }
1251
+ function Fe(s) {
1252
+ const t = new Uint8Array(s.length);
1253
+ for (let e = 0; e < s.length; e++)
1254
+ t[e] = s.charCodeAt(e) & 127;
1255
+ return t;
1256
+ }
1257
+ function Ie() {
1258
+ if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
1259
+ throw new wt();
1260
+ }
1261
+ async function Pe(s, t) {
1262
+ return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(`opfs:${s.replace(/\/+/g, "/")}`, { mode: "exclusive" }, t) : t();
1263
+ }
1264
+ function $(s) {
1265
+ return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
1266
+ }
1267
+ function Z(s) {
1268
+ return typeof s == "string" ? s ?? "/" : `/${s.join("/")}`;
1269
+ }
1270
+ function z(s) {
1271
+ const t = $(s);
1272
+ return t[t.length - 1] || "";
1273
+ }
1274
+ function H(s) {
1275
+ const t = $(s);
1276
+ return t.pop(), Z(t);
1277
+ }
1278
+ function j(s) {
1279
+ return !s || s === "/" ? "/" : s.startsWith("~/") ? `/${s.slice(2)}` : s.startsWith("/") ? s : `/${s}`;
1280
+ }
1281
+ function Re(s, t = !1) {
1282
+ return s = s.replace(/\/$/, ""), t && !s.includes("*") ? `${s}/**` : s;
1283
+ }
1284
+ function _(s, t) {
1285
+ return y(s, t, {
1286
+ dot: !0,
1287
+ matchBase: !0
1288
+ });
1289
+ }
1290
+ function qe(s, t) {
1291
+ if (!t || Array.isArray(t) && t.length === 0)
1292
+ return !1;
1293
+ const e = j(s);
1294
+ return (Array.isArray(t) ? t : [t]).some((r) => y(e, r, { dot: !0 }));
1295
+ }
1296
+ function ke(s) {
1297
+ const t = j(s), e = $(t), n = [];
1298
+ for (const r of e)
1299
+ if (!(r === "." || r === ""))
1300
+ if (r === "..") {
1301
+ if (n.length === 0)
1302
+ continue;
1303
+ n.pop();
1304
+ } else
1305
+ n.push(r);
1306
+ return Z(n);
1307
+ }
1308
+ function Ge(s) {
1309
+ const t = z(s), e = t.lastIndexOf(".");
1310
+ return e <= 0 || e === t.length - 1 ? "" : t.slice(e);
1311
+ }
1312
+ function Ve(s, t = "utf-8") {
1313
+ return typeof s == "string" ? $e(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
1314
+ }
1315
+ async function Le(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1316
+ if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
1317
+ throw new Error(`File size ${s.byteLength} bytes exceeds maximum allowed size ${e} bytes`);
1318
+ const n = new Uint8Array(s), r = await crypto.subtle.digest(t, n);
1319
+ return Array.from(new Uint8Array(r)).map((o) => o.toString(16).padStart(2, "0")).join("");
1320
+ }
1321
+ function Ye(s, t) {
1322
+ if (s.length !== t.length)
1323
+ return !1;
1324
+ for (let e = 0; e < s.length; e++)
1325
+ if (s[e] !== t[e])
1326
+ return !1;
1327
+ return !0;
1328
+ }
1329
+ async function ze(s) {
1330
+ const t = await s.arrayBuffer();
1331
+ return new Uint8Array(t);
1332
+ }
1333
+ async function je(s, t, e = {}) {
1334
+ const n = z(t);
1335
+ return Pe(t, async () => {
1336
+ const r = e.recursive ?? !1, i = e.force ?? !1;
1337
+ try {
1338
+ await s.removeEntry(n, { recursive: r });
1339
+ } catch (o) {
1340
+ if (o.name === "NotFoundError" && i)
1341
+ return;
1342
+ const a = o.name === "TypeMismatchError" && !r;
1343
+ throw O(o, {
1344
+ path: t,
1345
+ operation: "remove",
1346
+ isDirectory: a
1347
+ });
1348
+ }
1349
+ });
1350
+ }
1351
+ function Ze(s, t, e, n) {
1352
+ if (!Number.isInteger(t) || !Number.isInteger(e))
1353
+ throw new D("argument", "Invalid offset or length");
1354
+ if (t < 0 || e < 0)
1355
+ throw new D("argument", "Negative offset or length not allowed");
1356
+ if (t + e > s)
1357
+ throw new D("overflow", "Operation would overflow buffer");
1358
+ if (n != null && (!Number.isInteger(n) || n < 0))
1359
+ throw new D("argument", "Invalid position");
1360
+ }
1361
+ function Je(s, t, e) {
1362
+ try {
1363
+ t.flush(), t.close();
1364
+ } catch (n) {
1365
+ console.warn(`Warning: Failed to properly close file descriptor ${s} (${e}):`, n);
1366
+ }
1367
+ }
1368
+ function Xe(s, t, e) {
1369
+ if (s >= e)
1370
+ return { isEOF: !0, actualLength: 0 };
1371
+ const n = Math.min(t, e - s);
1372
+ return n <= 0 ? { isEOF: !0, actualLength: 0 } : { isEOF: !1, actualLength: n };
1373
+ }
1374
+ async function Ke(s, t) {
1375
+ try {
1376
+ return await s.createSyncAccessHandle();
1377
+ } catch (e) {
1378
+ throw O(e, { path: t, isDirectory: !1 });
1379
+ }
1380
+ }
1381
+ class Qe {
1382
+ /** Root directory handle for the file system */
1383
+ root;
1384
+ /** Map of watched paths and options */
1385
+ watchers = /* @__PURE__ */ new Map();
1386
+ /** Promise to prevent concurrent mount operations */
1387
+ mountingPromise = null;
1388
+ /** BroadcastChannel instance for sending events */
1389
+ broadcastChannel = null;
1390
+ /** Configuration options */
1391
+ options = {
1392
+ root: "/",
1393
+ namespace: "",
1394
+ maxFileSize: 50 * 1024 * 1024,
1395
+ hashAlgorithm: "etag",
1396
+ broadcastChannel: "opfs-worker"
1397
+ };
1398
+ /**
1399
+ * Notify about internal changes to the file system
1400
+ *
1401
+ * This method is called by internal operations to notify clients about
1402
+ * changes, even when no specific paths are being watched.
1403
+ *
1404
+ * @param event - The event describing the change
1405
+ */
1406
+ async notifyChange(t) {
1407
+ if (!this.options.broadcastChannel)
1408
+ return;
1409
+ const e = t.path;
1410
+ if (![...this.watchers.values()].some((i) => _(e, i.pattern) && i.include.some((o) => o && _(e, o)) && !i.exclude.some((o) => o && _(e, o))))
1411
+ return;
1412
+ let r;
1413
+ if (this.options.hashAlgorithm)
1414
+ try {
1415
+ r = (await this.stat(e)).hash;
1416
+ } catch {
1417
+ }
1418
+ try {
1419
+ this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
1420
+ const i = {
1421
+ namespace: this.options.namespace,
1422
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1423
+ ...t,
1424
+ ...r && { hash: r }
1425
+ };
1426
+ this.broadcastChannel.postMessage(i);
1427
+ } catch (i) {
1428
+ console.warn("Failed to send event via BroadcastChannel:", i);
1429
+ }
1430
+ }
1431
+ constructor(t) {
1432
+ Ie(), t && this.setOptions(t);
1433
+ }
1434
+ /**
1435
+ * Initialize the file system within a given directory.
1436
+ * If no root is specified, uses the OPFS root directory.
1437
+ */
1438
+ async mount() {
1439
+ const t = this.options.root;
1440
+ return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
1441
+ try {
1442
+ const r = await navigator.storage.getDirectory();
1443
+ this.root = t === "/" ? r : await this.getDirectoryHandle(t, !0, r), e(!0);
1444
+ } catch (r) {
1445
+ n(new bt(t, r));
1446
+ } finally {
1447
+ this.mountingPromise = null;
1448
+ }
1449
+ }), this.mountingPromise;
1450
+ }
1451
+ /**
1452
+ * Update configuration options
1453
+ *
1454
+ * @param options - Configuration options to update
1455
+ * @param options.root - Root path for the file system
1456
+ * @param options.watchInterval - Polling interval in milliseconds for file watching
1457
+ * @param options.hashAlgorithm - Hash algorithm for file hashing
1458
+ * @param options.maxFileSize - Maximum file size for hashing in bytes
1459
+ * @param options.broadcastChannel - Custom name for the broadcast channel
1460
+ */
1461
+ async setOptions(t) {
1462
+ 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 = j(t.root), this.options.namespace || (this.options.namespace = `opfs-worker:${this.options.root}`), await this.mount());
1463
+ }
1464
+ /**
1465
+ * Get a directory handle from a path
1466
+ *
1467
+ * Navigates through the directory structure to find or create a directory
1468
+ * at the specified path.
1469
+ *
1470
+ * @param path - The path to the directory (string or array of segments)
1471
+ * @param create - Whether to create the directory if it doesn't exist (default: false)
1472
+ * @param from - The directory to start from (default: root directory)
1473
+ * @returns Promise that resolves to the directory handle
1474
+ * @throws {OPFSError} If the directory cannot be accessed or created
1475
+ *
1476
+ * @example
1477
+ * ```typescript
1478
+ * const docsDir = await fs.getDirectoryHandle('/users/john/documents', true);
1479
+ * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
1480
+ * ```
1481
+ */
1482
+ async getDirectoryHandle(t, e = !1, n = this.root) {
1483
+ const r = Array.isArray(t) ? t : $(t);
1484
+ let i = n;
1485
+ for (const o of r)
1486
+ i = await i.getDirectoryHandle(o, { create: e });
1487
+ return i;
1488
+ }
1489
+ /**
1490
+ * Get a file handle from a path
1491
+ *
1492
+ * Navigates to the parent directory and retrieves or creates a file handle
1493
+ * for the specified file path.
1494
+ *
1495
+ * @param path - The path to the file (string or array of segments)
1496
+ * @param create - Whether to create the file if it doesn't exist (default: false)
1497
+ * @param _from - The directory to start from (default: root directory)
1498
+ * @returns Promise that resolves to the file handle
1499
+ * @throws {PathError} If the path is empty
1500
+ * @throws {OPFSError} If the file cannot be accessed or created
1501
+ *
1502
+ * @example
1503
+ * ```typescript
1504
+ * const fileHandle = await fs.getFileHandle('/config/settings.json', true);
1505
+ * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
1506
+ * ```
1507
+ */
1508
+ async getFileHandle(t, e = !1, n = this.root) {
1509
+ const r = $(t);
1510
+ if (r.length === 0)
1511
+ throw new yt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1512
+ const i = r.pop();
1513
+ return (await this.getDirectoryHandle(r, e, n)).getFileHandle(i, { create: e });
1514
+ }
1515
+ /**
1516
+ * Get a complete index of all files and directories in the file system
1517
+ *
1518
+ * This method recursively traverses the entire file system and returns
1519
+ * a Map containing FileStat objects for every file and directory.
1520
+ *
1521
+ * @returns Promise that resolves to a Map of paths to FileStat objects
1522
+ * @throws {OPFSError} If the file system is not mounted
1523
+ *
1524
+ * @example
1525
+ * ```typescript
1526
+ * const index = await fs.index();
1527
+ * const fileStats = index.get('/data/config.json');
1528
+ * if (fileStats) {
1529
+ * console.log(`File size: ${fileStats.size} bytes`);
1530
+ * if (fileStats.hash) console.log(`Hash: ${fileStats.hash}`);
1531
+ * }
1532
+ * ```
1533
+ */
1534
+ async index() {
1535
+ const t = /* @__PURE__ */ new Map(), e = async (n) => {
1536
+ const r = await this.readDir(n);
1537
+ for (const i of r) {
1538
+ const o = `${n === "/" ? "" : n}/${i.name}`;
1539
+ try {
1540
+ const a = await this.stat(o);
1541
+ t.set(o, a), a.isDirectory && await e(o);
1542
+ } catch (a) {
1543
+ console.warn(`Skipping broken entry: ${o}`, a);
1544
+ }
1545
+ }
1546
+ };
1547
+ return t.set("/", {
1548
+ kind: "directory",
1549
+ size: 0,
1550
+ mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
1551
+ ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
1552
+ isFile: !1,
1553
+ isDirectory: !0
1554
+ }), await e("/"), t;
1555
+ }
1556
+ /**
1557
+ * Create a directory
1558
+ *
1559
+ * Creates a new directory at the specified path. If the recursive option
1560
+ * is enabled, parent directories will be created as needed.
1561
+ *
1562
+ * @param path - The path where the directory should be created
1563
+ * @param options - Options for directory creation
1564
+ * @param options.recursive - Whether to create parent directories if they don't exist (default: false)
1565
+ * @returns Promise that resolves when the directory is created
1566
+ * @throws {OPFSError} If the directory cannot be created
1567
+ *
1568
+ * @example
1569
+ * ```typescript
1570
+ * // Create a single directory
1571
+ * await fs.mkdir('/users/john');
1572
+ *
1573
+ * // Create nested directories
1574
+ * await fs.mkdir('/users/john/documents/projects', { recursive: true });
1575
+ * ```
1576
+ */
1577
+ async mkdir(t, e) {
1578
+ await this.mount();
1579
+ const n = e?.recursive ?? !1, r = $(t);
1580
+ let i = this.root;
1581
+ for (let o = 0; o < r.length; o++) {
1582
+ const a = r[o];
1583
+ try {
1584
+ i = await i.getDirectoryHandle(a, { create: n || o === r.length - 1 });
1585
+ } catch (c) {
1586
+ throw c.name === "NotFoundError" ? O(c, {
1587
+ path: Z(r.slice(0, o + 1)),
1588
+ existenceType: "directory"
1589
+ }) : c.name === "TypeMismatchError" ? O(c, { path: a, isDirectory: !1 }) : new U("create directory", a, c);
1590
+ }
1591
+ }
1592
+ await this.notifyChange({ path: t, type: N.Added, isDirectory: !0 });
1593
+ }
1594
+ /**
1595
+ * Get file or directory statistics
1596
+ *
1597
+ * Returns detailed information about a file or directory, including
1598
+ * size, modification time, and optionally a hash of the file content.
1599
+ *
1600
+ * @param path - The path to the file or directory
1601
+ * @returns Promise that resolves to FileStat object
1602
+ * @throws {OPFSError} If the path does not exist or cannot be accessed
1603
+ *
1604
+ * @example
1605
+ * ```typescript
1606
+ * const stats = await fs.stat('/data/config.json');
1607
+ * console.log(`File size: ${stats.size} bytes`);
1608
+ * console.log(`Last modified: ${stats.mtime}`);
1609
+ *
1610
+ * // If hashing is enabled, hash will be included
1611
+ * if (stats.hash) {
1612
+ * console.log(`Hash: ${stats.hash}`);
1613
+ * }
1614
+ * ```
1615
+ */
1616
+ async stat(t) {
1617
+ if (await this.mount(), t === "/")
1618
+ return {
1619
+ kind: "directory",
1620
+ size: 0,
1621
+ mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
1622
+ ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
1623
+ isFile: !1,
1624
+ isDirectory: !0
1625
+ };
1626
+ const e = z(t);
1627
+ let n;
1628
+ try {
1629
+ n = await this.getDirectoryHandle(H(t), !1);
1630
+ const r = this.options.hashAlgorithm, o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
1631
+ kind: "file",
1632
+ size: o.size,
1633
+ mtime: new Date(o.lastModified).toISOString(),
1634
+ ctime: new Date(o.lastModified).toISOString(),
1635
+ isFile: !0,
1636
+ isDirectory: !1
1637
+ };
1638
+ if (r === "etag")
1639
+ a.hash = `${o.lastModified.toString(36)}-${o.size.toString(36)}`;
1640
+ else if (typeof r == "string")
1641
+ try {
1642
+ const c = await Le(o, r, this.options.maxFileSize);
1643
+ a.hash = c;
1644
+ } catch (c) {
1645
+ console.warn(`Failed to calculate hash for ${t}:`, c);
1646
+ }
1647
+ return a;
1648
+ } catch (r) {
1649
+ if (r.name === "NotFoundError")
1650
+ throw new k("file", t, r);
1651
+ if (r.name !== "TypeMismatchError")
1652
+ throw new U("stat", t, r);
1653
+ }
1654
+ try {
1655
+ return await n.getDirectoryHandle(e, { create: !1 }), {
1656
+ kind: "directory",
1657
+ size: 0,
1658
+ mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
1659
+ ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
1660
+ isFile: !1,
1661
+ isDirectory: !0
1662
+ };
1663
+ } catch (r) {
1664
+ throw new U("stat", t, r);
1665
+ }
1666
+ }
1667
+ /**
1668
+ * Read a directory's contents
1669
+ *
1670
+ * Lists all files and subdirectories within the specified directory.
1671
+ *
1672
+ * @param path - The path to the directory to read
1673
+ * @returns Promise that resolves to an array of detailed file/directory information
1674
+ * @throws {OPFSError} If the directory does not exist or cannot be accessed
1675
+ *
1676
+ * @example
1677
+ * ```typescript
1678
+ * // Get detailed information about files and directories
1679
+ * const detailed = await fs.readDir('/users/john/documents');
1680
+ * detailed.forEach(item => {
1681
+ * console.log(`${item.name} - ${item.isFile ? 'file' : 'directory'}`);
1682
+ * });
1683
+ * ```
1684
+ */
1685
+ async readDir(t) {
1686
+ await this.mount();
1687
+ const e = await this.getDirectoryHandle(t, !1), n = [];
1688
+ for await (const [r, i] of e.entries()) {
1689
+ const o = i.kind === "file";
1690
+ n.push({
1691
+ name: r,
1692
+ kind: i.kind,
1693
+ isFile: o,
1694
+ isDirectory: !o
1695
+ });
1696
+ }
1697
+ return n;
1698
+ }
1699
+ /**
1700
+ * Check if a file or directory exists
1701
+ *
1702
+ * Verifies if a file or directory exists at the specified path.
1703
+ *
1704
+ * @param path - The path to check
1705
+ * @returns Promise that resolves to true if the file or directory exists, false otherwise
1706
+ *
1707
+ * @example
1708
+ * ```typescript
1709
+ * const exists = await fs.exists('/config/settings.json');
1710
+ * console.log(`File exists: ${exists}`);
1711
+ * ```
1712
+ */
1713
+ async exists(t) {
1714
+ if (await this.mount(), t === "/")
1715
+ return !0;
1716
+ const e = z(t);
1717
+ let n = null;
1718
+ try {
1719
+ n = await this.getDirectoryHandle(H(t), !1);
1720
+ } catch (r) {
1721
+ if (n = null, r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1722
+ throw r;
1723
+ }
1724
+ if (!n || !e)
1725
+ return !1;
1726
+ try {
1727
+ return await n.getFileHandle(e, { create: !1 }), !0;
1728
+ } catch (r) {
1729
+ if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1730
+ throw r;
1731
+ try {
1732
+ return await n.getDirectoryHandle(e, { create: !1 }), !0;
1733
+ } catch (i) {
1734
+ if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1735
+ throw i;
1736
+ return !1;
1737
+ }
1738
+ }
1739
+ }
1740
+ /**
1741
+ * Clear all contents of a directory without removing the directory itself
1742
+ *
1743
+ * Removes all files and subdirectories within the specified directory,
1744
+ * but keeps the directory itself.
1745
+ *
1746
+ * @param path - The path to the directory to clear (default: '/')
1747
+ * @returns Promise that resolves when all contents are removed
1748
+ * @throws {OPFSError} If the operation fails
1749
+ *
1750
+ * @example
1751
+ * ```typescript
1752
+ * // Clear root directory contents
1753
+ * await fs.clear('/');
1754
+ *
1755
+ * // Clear specific directory contents
1756
+ * await fs.clear('/data');
1757
+ * ```
1758
+ */
1759
+ async clear(t = "/") {
1760
+ await this.mount();
1761
+ try {
1762
+ const e = await this.readDir(t);
1763
+ for (const n of e) {
1764
+ const r = `${t === "/" ? "" : t}/${n.name}`;
1765
+ await this.remove(r, { recursive: !0 });
1766
+ }
1767
+ await this.notifyChange({ path: t, type: N.Changed, isDirectory: !0 });
1768
+ } catch (e) {
1769
+ throw e instanceof m ? e : O(e, { path: t, isDirectory: !0 });
1770
+ }
1771
+ }
1772
+ /**
1773
+ * Remove files and directories
1774
+ *
1775
+ * Removes files and directories. Similar to Node.js fs.rm().
1776
+ *
1777
+ * @param path - The path to remove
1778
+ * @param options - Options for removal
1779
+ * @param options.recursive - Whether to remove directories and their contents recursively (default: false)
1780
+ * @param options.force - Whether to ignore errors if the path doesn't exist (default: false)
1781
+ * @returns Promise that resolves when the removal is complete
1782
+ * @throws {OPFSError} If the removal fails
1783
+ *
1784
+ * @example
1785
+ * ```typescript
1786
+ * // Remove a file
1787
+ * await fs.rm('/path/to/file.txt');
1788
+ *
1789
+ * // Remove a directory and all its contents
1790
+ * await fs.rm('/path/to/directory', { recursive: true });
1791
+ *
1792
+ * // Remove with force (ignore if doesn't exist)
1793
+ * await fs.rm('/maybe/exists', { force: true });
1794
+ * ```
1795
+ */
1796
+ async remove(t, e) {
1797
+ if (await this.mount(), t === "/")
1798
+ throw new G("EROOT", t);
1799
+ const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(H(t), !1), o = await this.stat(t);
1800
+ await je(i, t, { recursive: n, force: r }), await this.notifyChange({ path: t, type: N.Removed, isDirectory: o.isDirectory });
1801
+ }
1802
+ /**
1803
+ * Resolve a path to an absolute path
1804
+ *
1805
+ * Resolves relative paths and normalizes path segments (like '..' and '.').
1806
+ * Similar to Node.js fs.realpath() but without symlink resolution since OPFS doesn't support symlinks.
1807
+ *
1808
+ * @param path - The path to resolve
1809
+ * @returns Promise that resolves to the absolute normalized path
1810
+ * @throws {FileNotFoundError} If the path does not exist
1811
+ * @throws {OPFSError} If path resolution fails
1812
+ *
1813
+ * @example
1814
+ * ```typescript
1815
+ * // Resolve relative path
1816
+ * const absolute = await fs.realpath('./config/../data/file.txt');
1817
+ * console.log(absolute); // '/data/file.txt'
1818
+ * ```
1819
+ */
1820
+ async realpath(t) {
1821
+ await this.mount();
1822
+ try {
1823
+ const e = ke(t);
1824
+ if (!await this.exists(e))
1825
+ throw new k("file", e);
1826
+ return e;
1827
+ } catch (e) {
1828
+ throw e instanceof m ? e : O(e, { path: t });
1829
+ }
1830
+ }
1831
+ /**
1832
+ * Rename a file or directory
1833
+ *
1834
+ * Changes the name of a file or directory. If the target path already exists,
1835
+ * it will be replaced only if overwrite option is enabled.
1836
+ *
1837
+ * @param oldPath - The current path of the file or directory
1838
+ * @param newPath - The new path for the file or directory
1839
+ * @param options - Options for renaming
1840
+ * @param options.overwrite - Whether to overwrite existing files (default: false)
1841
+ * @returns Promise that resolves when the rename operation is complete
1842
+ * @throws {OPFSError} If the rename operation fails
1843
+ *
1844
+ * @example
1845
+ * ```typescript
1846
+ * // Basic rename (fails if target exists)
1847
+ * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
1848
+ *
1849
+ * // Rename with overwrite
1850
+ * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
1851
+ * ```
1852
+ */
1853
+ async rename(t, e, n) {
1854
+ await this.mount();
1855
+ try {
1856
+ const r = n?.overwrite ?? !1, i = await this.stat(t);
1857
+ if (await this.exists(e) && !r)
1858
+ throw new X(e);
1859
+ await this.copy(t, e, { recursive: !0, overwrite: r }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: N.Removed, isDirectory: i.isDirectory }), await this.notifyChange({ path: e, type: N.Added, isDirectory: i.isDirectory });
1860
+ } catch (r) {
1861
+ throw r instanceof m ? r : O(r, { path: t });
1862
+ }
1863
+ }
1864
+ /**
1865
+ * Copy files and directories
1866
+ *
1867
+ * Copies files and directories. Similar to Node.js fs.cp().
1868
+ *
1869
+ * @param source - The source path to copy from
1870
+ * @param destination - The destination path to copy to
1871
+ * @param options - Options for copying
1872
+ * @param options.recursive - Whether to copy directories recursively (default: false)
1873
+ * @param options.overwrite - Whether to overwrite existing files (default: true)
1874
+ * @returns Promise that resolves when the copy operation is complete
1875
+ * @throws {OPFSError} If the copy operation fails
1876
+ *
1877
+ * @example
1878
+ * ```typescript
1879
+ * // Copy a file
1880
+ * await fs.copy('/source/file.txt', '/dest/file.txt');
1881
+ *
1882
+ * // Copy a directory and all its contents
1883
+ * await fs.copy('/source/dir', '/dest/dir', { recursive: true });
1884
+ *
1885
+ * // Copy without overwriting existing files
1886
+ * await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
1887
+ * ```
1888
+ */
1889
+ async copy(t, e, n) {
1890
+ await this.mount();
1891
+ try {
1892
+ const r = n?.recursive ?? !1, i = n?.overwrite ?? !0;
1893
+ if (!await this.exists(t))
1894
+ throw new k("source", t);
1895
+ if (await this.exists(e) && !i)
1896
+ throw new X(e);
1897
+ if ((await this.stat(t)).isFile) {
1898
+ const l = await this.readFile(t);
1899
+ await this.writeFile(e, l);
1900
+ } else {
1901
+ if (!r)
1902
+ throw new q("directory", t);
1903
+ await this.mkdir(e, { recursive: !0 });
1904
+ const l = await this.readDir(t);
1905
+ for (const h of l) {
1906
+ const d = `${t}/${h.name}`, u = `${e}/${h.name}`;
1907
+ await this.copy(d, u, { recursive: !0, overwrite: i });
1908
+ }
1909
+ }
1910
+ } catch (r) {
1911
+ throw r instanceof m ? r : O(r, { path: t });
1912
+ }
1913
+ }
1914
+ /**
1915
+ * Start watching a file or directory for changes
1916
+ *
1917
+ * @param path - The path to watch (minimatch syntax allowed)
1918
+ * @param options - Watch options
1919
+ * @param options.recursive - Whether to watch recursively (default: true)
1920
+ * @param options.exclude - Glob pattern(s) to exclude (minimatch).
1921
+ * @returns Promise that resolves when watching starts
1922
+ *
1923
+ * @example
1924
+ * ```typescript
1925
+ * // Watch entire directory tree recursively (default)
1926
+ * await fs.watch('/data');
1927
+ *
1928
+ * // Watch only immediate children (shallow)
1929
+ * await fs.watch('/data', { recursive: false });
1930
+ *
1931
+ * // Watch a single file
1932
+ * await fs.watch('/config.json', { recursive: false });
1933
+ *
1934
+ * // Watch all json files but not in dist directory
1935
+ * await fs.watch('/**\/*.json', { recursive: false, exclude: ['dist/**'] });
1936
+ *
1937
+ * ```
1938
+ */
1939
+ async watch(t, e) {
1940
+ if (!this.options.broadcastChannel)
1941
+ throw new it("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
1942
+ const n = {
1943
+ pattern: Re(t, e?.recursive ?? !0),
1944
+ include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
1945
+ exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
1946
+ };
1947
+ this.watchers.set(t, n);
1948
+ }
1949
+ /**
1950
+ * Stop watching a previously watched path
1951
+ */
1952
+ unwatch(t) {
1953
+ this.watchers.delete(t);
1954
+ }
1955
+ /**
1956
+ * Bulk-create files from `[path, data]` entries (strings, bytes, or Blobs).
1957
+ *
1958
+ * @param entries - Array of `[path, data]` tuples
1959
+ * @throws {OPFSError} If a write fails
1960
+ *
1961
+ * @example
1962
+ * ```typescript
1963
+ * await fs.createIndex([
1964
+ * ['/config.json', JSON.stringify({ theme: 'dark' })],
1965
+ * ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],
1966
+ * ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })],
1967
+ * ]);
1968
+ * ```
1969
+ */
1970
+ async createIndex(t) {
1971
+ await this.mount();
1972
+ try {
1973
+ for (const [e, n] of t) {
1974
+ const r = j(e);
1975
+ let i;
1976
+ n instanceof Blob ? i = await ze(n) : typeof n == "string" ? i = new TextEncoder().encode(n) : i = n, await this.writeFile(r, i);
1977
+ }
1978
+ } catch (e) {
1979
+ throw e instanceof m ? e : O(e);
1980
+ }
1981
+ }
1982
+ /**
1983
+ * Dispose of resources and clean up the file system instance
1984
+ */
1985
+ dispose() {
1986
+ this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
1987
+ }
1988
+ }
1989
+ export {
1990
+ X as A,
1991
+ Qe as B,
1992
+ Ze as C,
1993
+ G as D,
1994
+ k as E,
1995
+ xt as F,
1996
+ Je as G,
1997
+ Xe as H,
1998
+ J as I,
1999
+ Ke as J,
2000
+ Ne as K,
2001
+ He as L,
2002
+ $e as M,
2003
+ _e as N,
2004
+ m as O,
2005
+ yt as P,
2006
+ St as S,
2007
+ D as V,
2008
+ N as W,
2009
+ wt as a,
2010
+ Et as b,
2011
+ q as c,
2012
+ vt as d,
2013
+ it as e,
2014
+ bt as f,
2015
+ U as g,
2016
+ We as h,
2017
+ Ie as i,
2018
+ Z as j,
2019
+ z as k,
2020
+ H as l,
2021
+ O as m,
2022
+ j as n,
2023
+ Re as o,
2024
+ _ as p,
2025
+ qe as q,
2026
+ ke as r,
2027
+ $ as s,
2028
+ Ge as t,
2029
+ Ve as u,
2030
+ Le as v,
2031
+ Pe as w,
2032
+ Ye as x,
2033
+ ze as y,
2034
+ je as z
2035
+ };
2036
+ //# sourceMappingURL=BaseOPFS-Cylz6ijk.js.map