opfs-worker 2.0.0 → 2.1.1

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