opfs-worker 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,19 +1,19 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("comlink"),a=`/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("comlink"),n=require("./helpers-hEpet7x7.cjs"),i=`/**
2
2
  * @license
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- const k = Symbol("Comlink.proxy"), U = Symbol("Comlink.endpoint"), z = Symbol("Comlink.releaseProxy"), T = Symbol("Comlink.finalizer"), E = Symbol("Comlink.thrown"), C = (e) => typeof e == "object" && e !== null || typeof e == "function", _ = {
7
- canHandle: (e) => C(e) && e[k],
6
+ const M = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), T = Symbol("Comlink.finalizer"), p = Symbol("Comlink.thrown"), $ = (e) => typeof e == "object" && e !== null || typeof e == "function", W = {
7
+ canHandle: (e) => $(e) && e[M],
8
8
  serialize(e) {
9
9
  const { port1: t, port2: r } = new MessageChannel();
10
- return x(e, t), [r, [r]];
10
+ return N(e, t), [r, [r]];
11
11
  },
12
12
  deserialize(e) {
13
- return e.start(), j(e);
13
+ return e.start(), Y(e);
14
14
  }
15
- }, R = {
16
- canHandle: (e) => C(e) && E in e,
15
+ }, j = {
16
+ canHandle: (e) => $(e) && p in e,
17
17
  serialize({ value: e }) {
18
18
  let t;
19
19
  return e instanceof Error ? t = {
@@ -28,34 +28,34 @@ const k = Symbol("Comlink.proxy"), U = Symbol("Comlink.endpoint"), z = Symbol("C
28
28
  deserialize(e) {
29
29
  throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
30
30
  }
31
- }, M = /* @__PURE__ */ new Map([
32
- ["proxy", _],
33
- ["throw", R]
31
+ }, U = /* @__PURE__ */ new Map([
32
+ ["proxy", W],
33
+ ["throw", j]
34
34
  ]);
35
- function W(e, t) {
35
+ function V(e, t) {
36
36
  for (const r of e)
37
37
  if (t === r || r === "*" || r instanceof RegExp && r.test(t))
38
38
  return !0;
39
39
  return !1;
40
40
  }
41
- function x(e, t = globalThis, r = ["*"]) {
41
+ function N(e, t = globalThis, r = ["*"]) {
42
42
  t.addEventListener("message", function a(n) {
43
43
  if (!n || !n.data)
44
44
  return;
45
- if (!W(r, n.origin)) {
45
+ if (!V(r, n.origin)) {
46
46
  console.warn(\`Invalid origin '\${n.origin}' for comlink proxy\`);
47
47
  return;
48
48
  }
49
- const { id: s, type: i, path: o } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map(d);
49
+ const { id: s, type: o, path: i } = Object.assign({ path: [] }, n.data), c = (n.data.argumentList || []).map(y);
50
50
  let f;
51
51
  try {
52
- const u = o.slice(0, -1).reduce((h, g) => h[g], e), w = o.reduce((h, g) => h[g], e);
53
- switch (i) {
52
+ const u = i.slice(0, -1).reduce((h, g) => h[g], e), w = i.reduce((h, g) => h[g], e);
53
+ switch (o) {
54
54
  case "GET":
55
55
  f = w;
56
56
  break;
57
57
  case "SET":
58
- u[o.slice(-1)[0]] = d(n.data.value), f = !0;
58
+ u[i.slice(-1)[0]] = y(n.data.value), f = !0;
59
59
  break;
60
60
  case "APPLY":
61
61
  f = w.apply(u, c);
@@ -63,13 +63,13 @@ function x(e, t = globalThis, r = ["*"]) {
63
63
  case "CONSTRUCT":
64
64
  {
65
65
  const h = new w(...c);
66
- f = q(h);
66
+ f = Q(h);
67
67
  }
68
68
  break;
69
69
  case "ENDPOINT":
70
70
  {
71
71
  const { port1: h, port2: g } = new MessageChannel();
72
- x(e, g), f = X(h, [h]);
72
+ N(e, g), f = J(h, [h]);
73
73
  }
74
74
  break;
75
75
  case "RELEASE":
@@ -79,136 +79,136 @@ function x(e, t = globalThis, r = ["*"]) {
79
79
  return;
80
80
  }
81
81
  } catch (u) {
82
- f = { value: u, [E]: 0 };
82
+ f = { value: u, [p]: 0 };
83
83
  }
84
- Promise.resolve(f).catch((u) => ({ value: u, [E]: 0 })).then((u) => {
84
+ Promise.resolve(f).catch((u) => ({ value: u, [p]: 0 })).then((u) => {
85
85
  const [w, h] = A(u);
86
- t.postMessage(Object.assign(Object.assign({}, w), { id: s }), h), i === "RELEASE" && (t.removeEventListener("message", a), v(t), T in e && typeof e[T] == "function" && e[T]());
86
+ t.postMessage(Object.assign(Object.assign({}, w), { id: s }), h), o === "RELEASE" && (t.removeEventListener("message", a), L(t), T in e && typeof e[T] == "function" && e[T]());
87
87
  }).catch((u) => {
88
88
  const [w, h] = A({
89
89
  value: new TypeError("Unserializable return value"),
90
- [E]: 0
90
+ [p]: 0
91
91
  });
92
92
  t.postMessage(Object.assign(Object.assign({}, w), { id: s }), h);
93
93
  });
94
94
  }), t.start && t.start();
95
95
  }
96
- function B(e) {
96
+ function G(e) {
97
97
  return e.constructor.name === "MessagePort";
98
98
  }
99
- function v(e) {
100
- B(e) && e.close();
99
+ function L(e) {
100
+ G(e) && e.close();
101
101
  }
102
- function j(e, t) {
102
+ function Y(e, t) {
103
103
  const r = /* @__PURE__ */ new Map();
104
104
  return e.addEventListener("message", function(n) {
105
105
  const { data: s } = n;
106
106
  if (!s || !s.id)
107
107
  return;
108
- const i = r.get(s.id);
109
- if (i)
108
+ const o = r.get(s.id);
109
+ if (o)
110
110
  try {
111
- i(s);
111
+ o(s);
112
112
  } finally {
113
113
  r.delete(s.id);
114
114
  }
115
- }), I(e, r, [], t);
115
+ }), P(e, r, [], t);
116
116
  }
117
- function p(e) {
117
+ function E(e) {
118
118
  if (e)
119
119
  throw new Error("Proxy has been released and is not useable");
120
120
  }
121
- function $(e) {
122
- return m(e, /* @__PURE__ */ new Map(), {
121
+ function z(e) {
122
+ return d(e, /* @__PURE__ */ new Map(), {
123
123
  type: "RELEASE"
124
124
  }).then(() => {
125
- v(e);
125
+ L(e);
126
126
  });
127
127
  }
128
128
  const F = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
129
129
  const t = (F.get(e) || 0) - 1;
130
- F.set(e, t), t === 0 && $(e);
130
+ F.set(e, t), t === 0 && z(e);
131
131
  });
132
- function V(e, t) {
132
+ function X(e, t) {
133
133
  const r = (F.get(t) || 0) + 1;
134
134
  F.set(t, r), S && S.register(e, t, e);
135
135
  }
136
- function G(e) {
136
+ function q(e) {
137
137
  S && S.unregister(e);
138
138
  }
139
- function I(e, t, r = [], a = function() {
139
+ function P(e, t, r = [], a = function() {
140
140
  }) {
141
141
  let n = !1;
142
142
  const s = new Proxy(a, {
143
- get(i, o) {
144
- if (p(n), o === z)
143
+ get(o, i) {
144
+ if (E(n), i === B)
145
145
  return () => {
146
- G(s), $(e), t.clear(), n = !0;
146
+ q(s), z(e), t.clear(), n = !0;
147
147
  };
148
- if (o === "then") {
148
+ if (i === "then") {
149
149
  if (r.length === 0)
150
150
  return { then: () => s };
151
- const c = m(e, t, {
151
+ const c = d(e, t, {
152
152
  type: "GET",
153
153
  path: r.map((f) => f.toString())
154
- }).then(d);
154
+ }).then(y);
155
155
  return c.then.bind(c);
156
156
  }
157
- return I(e, t, [...r, o]);
157
+ return P(e, t, [...r, i]);
158
158
  },
159
- set(i, o, c) {
160
- p(n);
159
+ set(o, i, c) {
160
+ E(n);
161
161
  const [f, u] = A(c);
162
- return m(e, t, {
162
+ return d(e, t, {
163
163
  type: "SET",
164
- path: [...r, o].map((w) => w.toString()),
164
+ path: [...r, i].map((w) => w.toString()),
165
165
  value: f
166
- }, u).then(d);
166
+ }, u).then(y);
167
167
  },
168
- apply(i, o, c) {
169
- p(n);
168
+ apply(o, i, c) {
169
+ E(n);
170
170
  const f = r[r.length - 1];
171
- if (f === U)
172
- return m(e, t, {
171
+ if (f === R)
172
+ return d(e, t, {
173
173
  type: "ENDPOINT"
174
- }).then(d);
174
+ }).then(y);
175
175
  if (f === "bind")
176
- return I(e, t, r.slice(0, -1));
177
- const [u, w] = O(c);
178
- return m(e, t, {
176
+ return P(e, t, r.slice(0, -1));
177
+ const [u, w] = k(c);
178
+ return d(e, t, {
179
179
  type: "APPLY",
180
180
  path: r.map((h) => h.toString()),
181
181
  argumentList: u
182
- }, w).then(d);
182
+ }, w).then(y);
183
183
  },
184
- construct(i, o) {
185
- p(n);
186
- const [c, f] = O(o);
187
- return m(e, t, {
184
+ construct(o, i) {
185
+ E(n);
186
+ const [c, f] = k(i);
187
+ return d(e, t, {
188
188
  type: "CONSTRUCT",
189
189
  path: r.map((u) => u.toString()),
190
190
  argumentList: c
191
- }, f).then(d);
191
+ }, f).then(y);
192
192
  }
193
193
  });
194
- return V(s, e), s;
194
+ return X(s, e), s;
195
195
  }
196
- function Y(e) {
196
+ function K(e) {
197
197
  return Array.prototype.concat.apply([], e);
198
198
  }
199
- function O(e) {
199
+ function k(e) {
200
200
  const t = e.map(A);
201
- return [t.map((r) => r[0]), Y(t.map((r) => r[1]))];
201
+ return [t.map((r) => r[0]), K(t.map((r) => r[1]))];
202
202
  }
203
- const L = /* @__PURE__ */ new WeakMap();
204
- function X(e, t) {
205
- return L.set(e, t), e;
203
+ const _ = /* @__PURE__ */ new WeakMap();
204
+ function J(e, t) {
205
+ return _.set(e, t), e;
206
206
  }
207
- function q(e) {
208
- return Object.assign(e, { [k]: !0 });
207
+ function Q(e) {
208
+ return Object.assign(e, { [M]: !0 });
209
209
  }
210
210
  function A(e) {
211
- for (const [t, r] of M)
211
+ for (const [t, r] of U)
212
212
  if (r.canHandle(e)) {
213
213
  const [a, n] = r.serialize(e);
214
214
  return [
@@ -225,24 +225,24 @@ function A(e) {
225
225
  type: "RAW",
226
226
  value: e
227
227
  },
228
- L.get(e) || []
228
+ _.get(e) || []
229
229
  ];
230
230
  }
231
- function d(e) {
231
+ function y(e) {
232
232
  switch (e.type) {
233
233
  case "HANDLER":
234
- return M.get(e.name).deserialize(e.value);
234
+ return U.get(e.name).deserialize(e.value);
235
235
  case "RAW":
236
236
  return e.value;
237
237
  }
238
238
  }
239
- function m(e, t, r, a) {
239
+ function d(e, t, r, a) {
240
240
  return new Promise((n) => {
241
- const s = K();
241
+ const s = Z();
242
242
  t.set(s, n), e.start && e.start(), e.postMessage(Object.assign({ id: s }, r), a);
243
243
  });
244
244
  }
245
- function K() {
245
+ function Z() {
246
246
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
247
247
  }
248
248
  class l extends Error {
@@ -250,7 +250,7 @@ class l extends Error {
250
250
  super(t), this.code = r, this.path = a, this.name = "OPFSError";
251
251
  }
252
252
  }
253
- class J extends l {
253
+ class ee extends l {
254
254
  constructor() {
255
255
  super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
256
256
  }
@@ -260,7 +260,7 @@ class D extends l {
260
260
  super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
261
261
  }
262
262
  }
263
- class P extends l {
263
+ class v extends l {
264
264
  constructor(t, r) {
265
265
  super(t, "INVALID_PATH", r);
266
266
  }
@@ -270,7 +270,7 @@ class b extends l {
270
270
  super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
271
271
  }
272
272
  }
273
- function Q(e, t = "utf-8") {
273
+ function te(e, t = "utf-8") {
274
274
  switch (t) {
275
275
  case "utf8":
276
276
  case "utf-8":
@@ -278,11 +278,11 @@ function Q(e, t = "utf-8") {
278
278
  case "utf16le":
279
279
  case "ucs2":
280
280
  case "ucs-2":
281
- return ee(e);
282
- case "ascii":
283
281
  return ne(e);
282
+ case "ascii":
283
+ return ie(e);
284
284
  case "latin1":
285
- return re(e);
285
+ return se(e);
286
286
  case "binary":
287
287
  return Uint8Array.from(e, (r) => r.charCodeAt(0));
288
288
  case "base64":
@@ -295,7 +295,7 @@ function Q(e, t = "utf-8") {
295
295
  return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(e);
296
296
  }
297
297
  }
298
- function Z(e, t = "utf-8") {
298
+ function re(e, t = "utf-8") {
299
299
  switch (t) {
300
300
  case "utf8":
301
301
  case "utf-8":
@@ -303,7 +303,7 @@ function Z(e, t = "utf-8") {
303
303
  case "utf16le":
304
304
  case "ucs2":
305
305
  case "ucs-2":
306
- return te(e);
306
+ return ae(e);
307
307
  case "latin1":
308
308
  return String.fromCharCode(...e);
309
309
  case "binary":
@@ -318,7 +318,7 @@ function Z(e, t = "utf-8") {
318
318
  return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(e);
319
319
  }
320
320
  }
321
- function ee(e) {
321
+ function ne(e) {
322
322
  const t = new Uint8Array(e.length * 2);
323
323
  for (let r = 0; r < e.length; r++) {
324
324
  const a = e.charCodeAt(r);
@@ -326,37 +326,60 @@ function ee(e) {
326
326
  }
327
327
  return t;
328
328
  }
329
- function te(e) {
329
+ function ae(e) {
330
330
  e.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), e = e.slice(0, e.length - 1));
331
331
  const t = new Uint16Array(e.buffer, e.byteOffset, e.byteLength / 2);
332
332
  return String.fromCharCode(...t);
333
333
  }
334
- function re(e) {
334
+ function se(e) {
335
335
  const t = new Uint8Array(e.length);
336
336
  for (let r = 0; r < e.length; r++)
337
337
  t[r] = e.charCodeAt(r) & 255;
338
338
  return t;
339
339
  }
340
- function ne(e) {
340
+ function ie(e) {
341
341
  const t = new Uint8Array(e.length);
342
342
  for (let r = 0; r < e.length; r++)
343
343
  t[r] = e.charCodeAt(r) & 127;
344
344
  return t;
345
345
  }
346
- function ae() {
346
+ function oe() {
347
347
  if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
348
- throw new J();
348
+ throw new ee();
349
349
  }
350
- function y(e) {
350
+ function m(e) {
351
351
  return Array.isArray(e) ? e : e.split("/").filter(Boolean);
352
352
  }
353
- function N(e) {
353
+ function H(e) {
354
354
  return typeof e == "string" ? e ?? "/" : \`/\${e.join("/")}\`;
355
355
  }
356
- function se(e, t = "utf-8") {
357
- return typeof e == "string" ? Q(e, t) : e instanceof Uint8Array ? e : new Uint8Array(e);
356
+ function I(e) {
357
+ const t = m(e);
358
+ return t[t.length - 1] || "";
359
+ }
360
+ function x(e) {
361
+ const t = m(e);
362
+ return t.pop(), H(t);
363
+ }
364
+ function O(e) {
365
+ return !e || e === "/" ? "/" : e.startsWith("/") ? e : \`/\${e}\`;
366
+ }
367
+ function ce(e) {
368
+ const t = m(e), r = [];
369
+ for (const a of t)
370
+ if (!(a === "." || a === ""))
371
+ if (a === "..") {
372
+ if (r.length === 0)
373
+ continue;
374
+ r.pop();
375
+ } else
376
+ r.push(a);
377
+ return H(r);
378
+ }
379
+ function le(e, t = "utf-8") {
380
+ return typeof e == "string" ? te(e, t) : e instanceof Uint8Array ? e : new Uint8Array(e);
358
381
  }
359
- async function ie(e) {
382
+ async function fe(e) {
360
383
  const t = await e.createSyncAccessHandle();
361
384
  try {
362
385
  const r = t.getSize(), a = new Uint8Array(r);
@@ -365,16 +388,16 @@ async function ie(e) {
365
388
  t.close();
366
389
  }
367
390
  }
368
- async function H(e, t, r, a = {}) {
391
+ async function C(e, t, r, a = {}) {
369
392
  let n = null;
370
393
  try {
371
394
  n = await e.createSyncAccessHandle();
372
- const s = se(t, r), i = a.append ? n.getSize() : 0;
373
- n.write(s, { at: i }), a.truncate && !a.append && n.truncate(s.byteLength), n.flush();
395
+ const s = le(t, r), o = a.append ? n.getSize() : 0;
396
+ n.write(s, { at: o }), a.truncate && !a.append && n.truncate(s.byteLength), n.flush();
374
397
  } catch (s) {
375
398
  console.error(s);
376
- const i = a.append ? "append" : "write";
377
- throw new l(\`Failed to \${i} file\`, \`\${i.toUpperCase()}_FAILED\`);
399
+ const o = a.append ? "append" : "write";
400
+ throw new l(\`Failed to \${o} file\`, \`\${o.toUpperCase()}_FAILED\`);
378
401
  } finally {
379
402
  if (n)
380
403
  try {
@@ -383,7 +406,7 @@ async function H(e, t, r, a = {}) {
383
406
  }
384
407
  }
385
408
  }
386
- async function oe(e, t = "SHA-1") {
409
+ async function ue(e, t = "SHA-1") {
387
410
  try {
388
411
  const r = new Uint8Array(e), a = await crypto.subtle.digest(t, r);
389
412
  return Array.from(new Uint8Array(a)).map((s) => s.toString(16).padStart(2, "0")).join("");
@@ -391,7 +414,11 @@ async function oe(e, t = "SHA-1") {
391
414
  throw console.warn(\`Failed to calculate \${t} hash:\`, r), r;
392
415
  }
393
416
  }
394
- class ce {
417
+ async function he(e) {
418
+ const t = await e.arrayBuffer();
419
+ return new Uint8Array(t);
420
+ }
421
+ class we {
395
422
  /** Root directory handle for the file system */
396
423
  root = null;
397
424
  /** Watch event callback */
@@ -410,7 +437,7 @@ class ce {
410
437
  * @throws {OPFSError} If OPFS is not supported in the current browser
411
438
  */
412
439
  constructor() {
413
- ae();
440
+ oe();
414
441
  }
415
442
  /**
416
443
  * Initialize the file system within a given directory
@@ -457,10 +484,10 @@ class ce {
457
484
  async getDirectoryHandle(t, r = !1, a = this.root) {
458
485
  if (!a)
459
486
  throw new D();
460
- const n = Array.isArray(t) ? t : y(t);
487
+ const n = Array.isArray(t) ? t : m(t);
461
488
  let s = a;
462
- for (const i of n)
463
- s = await s.getDirectoryHandle(i, { create: r });
489
+ for (const o of n)
490
+ s = await s.getDirectoryHandle(o, { create: r });
464
491
  return s;
465
492
  }
466
493
  /**
@@ -485,9 +512,9 @@ class ce {
485
512
  async getFileHandle(t, r = !1, a = this.root) {
486
513
  if (!a)
487
514
  throw new D();
488
- const n = y(t);
515
+ const n = m(t);
489
516
  if (n.length === 0)
490
- throw new P("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
517
+ throw new v("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
491
518
  const s = n.pop();
492
519
  return (await this.getDirectoryHandle(n, r, a)).getFileHandle(s, { create: r });
493
520
  }
@@ -531,13 +558,13 @@ class ce {
531
558
  async index(t) {
532
559
  const r = /* @__PURE__ */ new Map(), a = async (n) => {
533
560
  const s = await this.readdir(n, { withFileTypes: !0 });
534
- for (const i of s) {
535
- const o = \`\${n === "/" ? "" : n}/\${i.name}\`;
561
+ for (const o of s) {
562
+ const i = \`\${n === "/" ? "" : n}/\${o.name}\`;
536
563
  try {
537
- const c = await this.stat(o, t);
538
- r.set(o, c), c.isDirectory && await a(o);
564
+ const c = await this.stat(i, t);
565
+ r.set(i, c), c.isDirectory && await a(i);
539
566
  } catch (c) {
540
- console.warn(\`Skipping broken entry: \${o}\`, c);
567
+ console.warn(\`Skipping broken entry: \${i}\`, c);
541
568
  }
542
569
  }
543
570
  };
@@ -552,8 +579,8 @@ class ce {
552
579
  }
553
580
  async readFile(t, r = "utf-8") {
554
581
  try {
555
- const a = await this.getFileHandle(t, !1), n = await ie(a);
556
- return r === "binary" ? n : Z(n, r);
582
+ const a = await this.getFileHandle(t, !1), n = await fe(a);
583
+ return r === "binary" ? n : re(n, r);
557
584
  } catch (a) {
558
585
  throw console.error(a), new b(t);
559
586
  }
@@ -585,7 +612,7 @@ class ce {
585
612
  */
586
613
  async writeFile(t, r, a) {
587
614
  const n = await this.getFileHandle(t, !0);
588
- await H(n, r, a, { truncate: !0 });
615
+ await C(n, r, a, { truncate: !0 });
589
616
  }
590
617
  /**
591
618
  * Append data to a file
@@ -611,7 +638,7 @@ class ce {
611
638
  */
612
639
  async appendFile(t, r, a) {
613
640
  const n = await this.getFileHandle(t, !0);
614
- await H(n, r, a, { append: !0 });
641
+ await C(n, r, a, { append: !0 });
615
642
  }
616
643
  /**
617
644
  * Create a directory
@@ -637,17 +664,17 @@ class ce {
637
664
  async mkdir(t, r) {
638
665
  if (!this.root)
639
666
  throw new D();
640
- const a = r?.recursive ?? !1, n = y(t);
667
+ const a = r?.recursive ?? !1, n = m(t);
641
668
  let s = this.root;
642
- for (let i = 0; i < n.length; i++) {
643
- const o = n[i];
669
+ for (let o = 0; o < n.length; o++) {
670
+ const i = n[o];
644
671
  try {
645
- s = await s.getDirectoryHandle(o, { create: a || i === n.length - 1 });
672
+ s = await s.getDirectoryHandle(i, { create: a || o === n.length - 1 });
646
673
  } catch (c) {
647
674
  throw c.name === "NotFoundError" ? new l(
648
- \`Parent directory does not exist: \${N(n.slice(0, i + 1))}\`,
675
+ \`Parent directory does not exist: \${H(n.slice(0, o + 1))}\`,
649
676
  "ENOENT"
650
- ) : c.name === "TypeMismatchError" ? new l(\`Path segment is not a directory: \${o}\`, "ENOTDIR") : new l("Failed to create directory", "MKDIR_FAILED");
677
+ ) : c.name === "TypeMismatchError" ? new l(\`Path segment is not a directory: \${i}\`, "ENOTDIR") : new l("Failed to create directory", "MKDIR_FAILED");
651
678
  }
652
679
  }
653
680
  }
@@ -681,51 +708,50 @@ class ce {
681
708
  * \`\`\`
682
709
  */
683
710
  async stat(t, r) {
684
- const a = y(t), n = a.pop(), s = await this.getDirectoryHandle(a, !1), i = r?.includeHash ?? !1, o = r?.hashAlgorithm ?? "SHA-1";
711
+ const a = I(t), n = await this.getDirectoryHandle(x(t), !1), s = r?.includeHash ?? !1, o = r?.hashAlgorithm ?? "SHA-1";
685
712
  try {
686
- const f = await (await s.getFileHandle(n, { create: !1 })).getFile(), u = {
713
+ const c = await (await n.getFileHandle(a, { create: !1 })).getFile(), f = {
687
714
  kind: "file",
688
- size: f.size,
689
- mtime: new Date(f.lastModified).toISOString(),
690
- ctime: new Date(f.lastModified).toISOString(),
715
+ size: c.size,
716
+ mtime: new Date(c.lastModified).toISOString(),
717
+ ctime: new Date(c.lastModified).toISOString(),
691
718
  isFile: !0,
692
719
  isDirectory: !1
693
720
  };
694
- if (i)
721
+ if (s)
695
722
  try {
696
- const w = new Uint8Array(await f.arrayBuffer()), h = await oe(w, o);
697
- u.hash = h;
698
- } catch (w) {
699
- console.warn(\`Failed to calculate hash for \${t}:\`, w);
723
+ const u = new Uint8Array(await c.arrayBuffer()), w = await ue(u, o);
724
+ f.hash = w;
725
+ } catch (u) {
726
+ console.warn(\`Failed to calculate hash for \${t}:\`, u);
700
727
  }
701
- return u;
702
- } catch (c) {
703
- if (c.name !== "TypeMismatchError" && c.name !== "NotFoundError")
728
+ return f;
729
+ } catch (i) {
730
+ if (i.name !== "TypeMismatchError" && i.name !== "NotFoundError")
704
731
  throw new l("Failed to stat (file)", "STAT_FAILED");
705
732
  }
706
733
  try {
707
- return await s.getDirectoryHandle(n, { create: !1 }), {
734
+ return await n.getDirectoryHandle(a, { create: !1 }), {
708
735
  kind: "directory",
709
736
  size: 0,
710
737
  mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
711
738
  ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
712
739
  isFile: !1,
713
740
  isDirectory: !0
714
- // Directories don't have hashes
715
741
  };
716
- } catch (c) {
717
- throw c.name === "NotFoundError" ? new l(\`No such file or directory: \${t}\`, "ENOENT") : new l("Failed to stat (directory)", "STAT_FAILED");
742
+ } catch (i) {
743
+ throw i.name === "NotFoundError" ? new l(\`No such file or directory: \${t}\`, "ENOENT") : new l("Failed to stat (directory)", "STAT_FAILED");
718
744
  }
719
745
  }
720
746
  async readdir(t, r) {
721
747
  const a = r?.withFileTypes ?? !1, n = await this.getDirectoryHandle(t, !1);
722
748
  if (a) {
723
749
  const s = [];
724
- for await (const [i, o] of n.entries()) {
725
- const c = o.kind === "file";
750
+ for await (const [o, i] of n.entries()) {
751
+ const c = i.kind === "file";
726
752
  s.push({
727
- name: i,
728
- kind: o.kind,
753
+ name: o,
754
+ kind: i.kind,
729
755
  isFile: c,
730
756
  isDirectory: !c
731
757
  });
@@ -733,8 +759,8 @@ class ce {
733
759
  return s;
734
760
  } else {
735
761
  const s = [];
736
- for await (const [i] of n.entries())
737
- s.push(i);
762
+ for await (const [o] of n.entries())
763
+ s.push(o);
738
764
  return s;
739
765
  }
740
766
  }
@@ -753,26 +779,26 @@ class ce {
753
779
  * \`\`\`
754
780
  */
755
781
  async exists(t) {
756
- const r = y(t), a = r.pop();
757
- let n = null;
782
+ const r = I(t);
783
+ let a = null;
758
784
  try {
759
- n = await this.getDirectoryHandle(r, !1);
760
- } catch (s) {
761
- throw (s.name === "NotFoundError" || s.name === "TypeMismatchError") && (n = null), s;
785
+ a = await this.getDirectoryHandle(x(t), !1);
786
+ } catch (n) {
787
+ throw (n.name === "NotFoundError" || n.name === "TypeMismatchError") && (a = null), n;
762
788
  }
763
- if (!n || !a)
789
+ if (!a || !r)
764
790
  return !1;
765
791
  try {
766
- return await n.getFileHandle(a, { create: !1 }), !0;
767
- } catch (s) {
768
- if (s.name !== "NotFoundError" && s.name !== "TypeMismatchError")
769
- throw s;
792
+ return await a.getFileHandle(r, { create: !1 }), !0;
793
+ } catch (n) {
794
+ if (n.name !== "NotFoundError" && n.name !== "TypeMismatchError")
795
+ throw n;
770
796
  }
771
797
  try {
772
- return await n.getDirectoryHandle(a, { create: !1 }), !0;
773
- } catch (s) {
774
- if (s.name !== "NotFoundError" && s.name !== "TypeMismatchError")
775
- throw s;
798
+ return await a.getDirectoryHandle(r, { create: !1 }), !0;
799
+ } catch (n) {
800
+ if (n.name !== "NotFoundError" && n.name !== "TypeMismatchError")
801
+ throw n;
776
802
  }
777
803
  return !1;
778
804
  }
@@ -831,17 +857,17 @@ class ce {
831
857
  * \`\`\`
832
858
  */
833
859
  async remove(t, r) {
834
- const a = r?.recursive ?? !1, n = r?.force ?? !1, s = y(t), i = s.pop();
835
- if (!i)
836
- throw new P("Invalid path", t);
837
- const o = await this.getDirectoryHandle(s, !1);
860
+ const a = r?.recursive ?? !1, n = r?.force ?? !1, s = I(t);
861
+ if (!s)
862
+ throw new v("Invalid path", t);
863
+ const o = await this.getDirectoryHandle(x(t), !1);
838
864
  try {
839
- await o.removeEntry(i, { recursive: a });
840
- } catch (c) {
841
- if (c.name === "NotFoundError") {
865
+ await o.removeEntry(s, { recursive: a });
866
+ } catch (i) {
867
+ if (i.name === "NotFoundError") {
842
868
  if (!n)
843
869
  throw new l(\`No such file or directory: \${t}\`, "ENOENT");
844
- } else throw c.name === "InvalidModificationError" ? new l(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : c.name === "TypeMismatchError" && !a ? new l(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new l(\`Failed to remove path: \${t}\`, "RM_FAILED");
870
+ } else throw i.name === "InvalidModificationError" ? new l(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : i.name === "TypeMismatchError" && !a ? new l(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new l(\`Failed to remove path: \${t}\`, "RM_FAILED");
845
871
  }
846
872
  }
847
873
  /**
@@ -864,19 +890,10 @@ class ce {
864
890
  */
865
891
  async realpath(t) {
866
892
  try {
867
- const r = y(t), a = [];
868
- for (const i of r)
869
- if (!(i === "." || i === ""))
870
- if (i === "..") {
871
- if (a.length === 0)
872
- throw new l("Path escapes root", "EINVAL");
873
- a.length > 0 && a.pop();
874
- } else
875
- a.push(i);
876
- const n = N(a);
877
- if (!await this.exists(n))
878
- throw new b(n);
879
- return n;
893
+ const r = ce(t);
894
+ if (!await this.exists(r))
895
+ throw new b(r);
896
+ return r;
880
897
  } catch (r) {
881
898
  throw r instanceof l ? r : new l(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
882
899
  }
@@ -959,7 +976,7 @@ class ce {
959
976
  * Start watching a file or directory for changes
960
977
  */
961
978
  async watch(t) {
962
- const r = t.startsWith("/") ? t : \`/\${t}\`, a = await this.buildSnapshot(r);
979
+ const r = O(t), a = await this.buildSnapshot(r);
963
980
  this.watchers.set(r, a), this.watchTimer || (this.watchTimer = setInterval(() => {
964
981
  this.scanWatches();
965
982
  }, this.watchInterval));
@@ -968,16 +985,16 @@ class ce {
968
985
  * Stop watching a previously watched path
969
986
  */
970
987
  unwatch(t) {
971
- const r = t.startsWith("/") ? t : \`/\${t}\`;
988
+ const r = O(t);
972
989
  this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
973
990
  }
974
991
  async buildSnapshot(t) {
975
992
  const r = /* @__PURE__ */ new Map(), a = async (n) => {
976
993
  const s = await this.stat(n);
977
994
  if (r.set(n, s), s.isDirectory) {
978
- const i = await this.readdir(n, { withFileTypes: !0 });
979
- for (const o of i) {
980
- const c = \`\${n === "/" ? "" : n}/\${o.name}\`;
995
+ const o = await this.readdir(n, { withFileTypes: !0 });
996
+ for (const i of o) {
997
+ const c = \`\${n === "/" ? "" : n}/\${i.name}\`;
981
998
  await a(c);
982
999
  }
983
1000
  }
@@ -997,9 +1014,9 @@ class ce {
997
1014
  a = /* @__PURE__ */ new Map();
998
1015
  }
999
1016
  const n = [];
1000
- for (const [s, i] of a) {
1001
- const o = r.get(s);
1002
- o ? (o.mtime !== i.mtime || o.size !== i.size) && n.push({ path: s, type: "change" }) : n.push({ path: s, type: "create" });
1017
+ for (const [s, o] of a) {
1018
+ const i = r.get(s);
1019
+ i ? (i.mtime !== o.mtime || i.size !== o.size) && n.push({ path: s, type: "change" }) : n.push({ path: s, type: "create" });
1003
1020
  }
1004
1021
  for (const s of r.keys())
1005
1022
  a.has(s) || n.push({ path: s, type: "delete" });
@@ -1046,21 +1063,16 @@ class ce {
1046
1063
  try {
1047
1064
  (r?.cleanBefore ?? !1) && await this.clear("/");
1048
1065
  for (const [n, s] of t) {
1049
- const i = n.startsWith("/") ? n : \`/\${n}\`;
1050
- let o;
1051
- if (s instanceof Blob) {
1052
- const c = await s.arrayBuffer();
1053
- o = new Uint8Array(c);
1054
- } else
1055
- o = s;
1056
- await this.writeFile(i, o);
1066
+ const o = O(n);
1067
+ let i;
1068
+ s instanceof Blob ? i = await he(s) : i = s, await this.writeFile(o, i);
1057
1069
  }
1058
1070
  } catch (a) {
1059
1071
  throw a instanceof l ? a : new l("Failed to sync file system", "SYNC_FAILED");
1060
1072
  }
1061
1073
  }
1062
1074
  }
1063
- typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && x(new ce());
1064
- //# sourceMappingURL=worker-D5GbafFH.js.map
1065
- `,r=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",a],{type:"text/javascript;charset=utf-8"});function s(t){let n;try{if(n=r&&(self.URL||self.webkitURL).createObjectURL(r),!n)throw"";const e=new Worker(n,{type:"module",name:t?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(n)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(a),{type:"module",name:t?.name})}}function o(){return i.wrap(new s)}exports.createWorker=o;
1075
+ typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && N(new we());
1076
+ //# sourceMappingURL=worker-ChfzBM-o.js.map
1077
+ `,a=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",i],{type:"text/javascript;charset=utf-8"});function s(r){let e;try{if(e=a&&(self.URL||self.webkitURL).createObjectURL(a),!e)throw"";const t=new Worker(e,{type:"module",name:r?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(e)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(i),{type:"module",name:r?.name})}}function c(){return o.wrap(new s)}exports.DirectoryNotFoundError=n.DirectoryNotFoundError;exports.FileNotFoundError=n.FileNotFoundError;exports.OPFSError=n.OPFSError;exports.OPFSNotMountedError=n.OPFSNotMountedError;exports.OPFSNotSupportedError=n.OPFSNotSupportedError;exports.PathError=n.PathError;exports.PermissionError=n.PermissionError;exports.StorageError=n.StorageError;exports.TimeoutError=n.TimeoutError;exports.basename=n.basename;exports.calculateFileHash=n.calculateFileHash;exports.checkOPFSSupport=n.checkOPFSSupport;exports.convertBlobToUint8Array=n.convertBlobToUint8Array;exports.createBuffer=n.createBuffer;exports.decodeBuffer=n.decodeBuffer;exports.dirname=n.dirname;exports.encodeString=n.encodeString;exports.extname=n.extname;exports.joinPath=n.joinPath;exports.normalizePath=n.normalizePath;exports.readFileData=n.readFileData;exports.resolvePath=n.resolvePath;exports.splitPath=n.splitPath;exports.writeFileData=n.writeFileData;exports.createWorker=c;
1066
1078
  //# sourceMappingURL=index.cjs.map