opfs-worker 2.1.0 → 2.1.2

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