opfs-worker 2.1.0 → 2.1.2

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