opfs-worker 2.0.0 → 2.1.0

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