opfs-worker 0.2.2 → 0.2.4

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.js CHANGED
@@ -1,63 +1,63 @@
1
1
  import { wrap as i, proxy as o } from "comlink";
2
- import { D as u, F as d, O as p, b as w, a as y, P as m, c as g, S as v, T as E, e as S, k as F, d as b, l as P, h as x, o as A, f as T, m as O, g as I, j as _, n as D, i as k, r as C, s as U, w as R } from "./helpers-Co-qCBmA.js";
2
+ import { D as d, F as u, O as p, b as w, a as y, P as m, c as g, S as v, T as E, e as S, k as F, d as b, l as P, h as x, o as T, f as I, m as A, g as O, j as _, n as C, i as D, r as k, s as U, w as R } from "./helpers-Co-qCBmA.js";
3
3
  const a = `/**
4
4
  * @license
5
5
  * Copyright 2019 Google LLC
6
6
  * SPDX-License-Identifier: Apache-2.0
7
7
  */
8
- const H = 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 = {
9
- canHandle: (e) => $(e) && e[H],
10
- serialize(e) {
11
- const { port1: t, port2: r } = new MessageChannel();
12
- return O(e, t), [r, [r]];
8
+ const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), p = Symbol("Comlink.thrown"), $ = (t) => typeof t == "object" && t !== null || typeof t == "function", W = {
9
+ canHandle: (t) => $(t) && t[H],
10
+ serialize(t) {
11
+ const { port1: e, port2: r } = new MessageChannel();
12
+ return O(t, e), [r, [r]];
13
13
  },
14
- deserialize(e) {
15
- return e.start(), Y(e);
14
+ deserialize(t) {
15
+ return t.start(), Y(t);
16
16
  }
17
17
  }, j = {
18
- canHandle: (e) => $(e) && p in e,
19
- serialize({ value: e }) {
20
- let t;
21
- return e instanceof Error ? t = {
18
+ canHandle: (t) => $(t) && p in t,
19
+ serialize({ value: t }) {
20
+ let e;
21
+ return t instanceof Error ? e = {
22
22
  isError: !0,
23
23
  value: {
24
- message: e.message,
25
- name: e.name,
26
- stack: e.stack
24
+ message: t.message,
25
+ name: t.name,
26
+ stack: t.stack
27
27
  }
28
- } : t = { isError: !1, value: e }, [t, []];
28
+ } : e = { isError: !1, value: t }, [e, []];
29
29
  },
30
- deserialize(e) {
31
- throw e.isError ? Object.assign(new Error(e.value.message), e.value) : e.value;
30
+ deserialize(t) {
31
+ throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
32
32
  }
33
33
  }, U = /* @__PURE__ */ new Map([
34
34
  ["proxy", W],
35
35
  ["throw", j]
36
36
  ]);
37
- function V(e, t) {
38
- for (const r of e)
39
- if (t === r || r === "*" || r instanceof RegExp && r.test(t))
37
+ function V(t, e) {
38
+ for (const r of t)
39
+ if (e === r || r === "*" || r instanceof RegExp && r.test(e))
40
40
  return !0;
41
41
  return !1;
42
42
  }
43
- function O(e, t = globalThis, r = ["*"]) {
44
- t.addEventListener("message", function a(n) {
43
+ function O(t, e = globalThis, r = ["*"]) {
44
+ e.addEventListener("message", function a(n) {
45
45
  if (!n || !n.data)
46
46
  return;
47
47
  if (!V(r, n.origin)) {
48
48
  console.warn(\`Invalid origin '\${n.origin}' for comlink proxy\`);
49
49
  return;
50
50
  }
51
- const { id: s, type: o, path: i } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(d);
51
+ const { id: i, type: o, path: s } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(y);
52
52
  let u;
53
53
  try {
54
- const f = i.slice(0, -1).reduce((h, g) => h[g], e), w = i.reduce((h, g) => h[g], e);
54
+ const f = s.slice(0, -1).reduce((h, g) => h[g], t), w = s.reduce((h, g) => h[g], t);
55
55
  switch (o) {
56
56
  case "GET":
57
57
  u = w;
58
58
  break;
59
59
  case "SET":
60
- f[i.slice(-1)[0]] = d(n.data.value), u = !0;
60
+ f[s.slice(-1)[0]] = y(n.data.value), u = !0;
61
61
  break;
62
62
  case "APPLY":
63
63
  u = w.apply(f, l);
@@ -71,7 +71,7 @@ function O(e, t = globalThis, r = ["*"]) {
71
71
  case "ENDPOINT":
72
72
  {
73
73
  const { port1: h, port2: g } = new MessageChannel();
74
- O(e, g), u = J(h, [h]);
74
+ O(t, g), u = J(h, [h]);
75
75
  }
76
76
  break;
77
77
  case "RELEASE":
@@ -85,138 +85,138 @@ function O(e, t = globalThis, r = ["*"]) {
85
85
  }
86
86
  Promise.resolve(u).catch((f) => ({ value: f, [p]: 0 })).then((f) => {
87
87
  const [w, h] = A(f);
88
- 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]());
88
+ e.postMessage(Object.assign(Object.assign({}, w), { id: i }), h), o === "RELEASE" && (e.removeEventListener("message", a), L(e), I in t && typeof t[I] == "function" && t[I]());
89
89
  }).catch((f) => {
90
90
  const [w, h] = A({
91
91
  value: new TypeError("Unserializable return value"),
92
92
  [p]: 0
93
93
  });
94
- t.postMessage(Object.assign(Object.assign({}, w), { id: s }), h);
94
+ e.postMessage(Object.assign(Object.assign({}, w), { id: i }), h);
95
95
  });
96
- }), t.start && t.start();
96
+ }), e.start && e.start();
97
97
  }
98
- function G(e) {
99
- return e.constructor.name === "MessagePort";
98
+ function G(t) {
99
+ return t.constructor.name === "MessagePort";
100
100
  }
101
- function L(e) {
102
- G(e) && e.close();
101
+ function L(t) {
102
+ G(t) && t.close();
103
103
  }
104
- function Y(e, t) {
104
+ function Y(t, e) {
105
105
  const r = /* @__PURE__ */ new Map();
106
- return e.addEventListener("message", function(n) {
107
- const { data: s } = n;
108
- if (!s || !s.id)
106
+ return t.addEventListener("message", function(n) {
107
+ const { data: i } = n;
108
+ if (!i || !i.id)
109
109
  return;
110
- const o = r.get(s.id);
110
+ const o = r.get(i.id);
111
111
  if (o)
112
112
  try {
113
- o(s);
113
+ o(i);
114
114
  } finally {
115
- r.delete(s.id);
115
+ r.delete(i.id);
116
116
  }
117
- }), x(e, r, [], t);
117
+ }), P(t, r, [], e);
118
118
  }
119
- function E(e) {
120
- if (e)
119
+ function E(t) {
120
+ if (t)
121
121
  throw new Error("Proxy has been released and is not useable");
122
122
  }
123
- function z(e) {
124
- return y(e, /* @__PURE__ */ new Map(), {
123
+ function z(t) {
124
+ return d(t, /* @__PURE__ */ new Map(), {
125
125
  type: "RELEASE"
126
126
  }).then(() => {
127
- L(e);
127
+ L(t);
128
128
  });
129
129
  }
130
- const F = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((e) => {
131
- const t = (F.get(e) || 0) - 1;
132
- F.set(e, t), t === 0 && z(e);
130
+ const F = /* @__PURE__ */ new WeakMap(), S = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
131
+ const e = (F.get(t) || 0) - 1;
132
+ F.set(t, e), e === 0 && z(t);
133
133
  });
134
- function X(e, t) {
135
- const r = (F.get(t) || 0) + 1;
136
- F.set(t, r), S && S.register(e, t, e);
134
+ function X(t, e) {
135
+ const r = (F.get(e) || 0) + 1;
136
+ F.set(e, r), S && S.register(t, e, t);
137
137
  }
138
- function q(e) {
139
- S && S.unregister(e);
138
+ function q(t) {
139
+ S && S.unregister(t);
140
140
  }
141
- function x(e, t, r = [], a = function() {
141
+ function P(t, e, r = [], a = function() {
142
142
  }) {
143
143
  let n = !1;
144
- const s = new Proxy(a, {
145
- get(o, i) {
146
- if (E(n), i === B)
144
+ const i = new Proxy(a, {
145
+ get(o, s) {
146
+ if (E(n), s === B)
147
147
  return () => {
148
- q(s), z(e), t.clear(), n = !0;
148
+ q(i), z(t), e.clear(), n = !0;
149
149
  };
150
- if (i === "then") {
150
+ if (s === "then") {
151
151
  if (r.length === 0)
152
- return { then: () => s };
153
- const l = y(e, t, {
152
+ return { then: () => i };
153
+ const l = d(t, e, {
154
154
  type: "GET",
155
155
  path: r.map((u) => u.toString())
156
- }).then(d);
156
+ }).then(y);
157
157
  return l.then.bind(l);
158
158
  }
159
- return x(e, t, [...r, i]);
159
+ return P(t, e, [...r, s]);
160
160
  },
161
- set(o, i, l) {
161
+ set(o, s, l) {
162
162
  E(n);
163
163
  const [u, f] = A(l);
164
- return y(e, t, {
164
+ return d(t, e, {
165
165
  type: "SET",
166
- path: [...r, i].map((w) => w.toString()),
166
+ path: [...r, s].map((w) => w.toString()),
167
167
  value: u
168
- }, f).then(d);
168
+ }, f).then(y);
169
169
  },
170
- apply(o, i, l) {
170
+ apply(o, s, l) {
171
171
  E(n);
172
172
  const u = r[r.length - 1];
173
173
  if (u === R)
174
- return y(e, t, {
174
+ return d(t, e, {
175
175
  type: "ENDPOINT"
176
- }).then(d);
176
+ }).then(y);
177
177
  if (u === "bind")
178
- return x(e, t, r.slice(0, -1));
179
- const [f, w] = v(l);
180
- return y(e, t, {
178
+ return P(t, e, r.slice(0, -1));
179
+ const [f, w] = k(l);
180
+ return d(t, e, {
181
181
  type: "APPLY",
182
182
  path: r.map((h) => h.toString()),
183
183
  argumentList: f
184
- }, w).then(d);
184
+ }, w).then(y);
185
185
  },
186
- construct(o, i) {
186
+ construct(o, s) {
187
187
  E(n);
188
- const [l, u] = v(i);
189
- return y(e, t, {
188
+ const [l, u] = k(s);
189
+ return d(t, e, {
190
190
  type: "CONSTRUCT",
191
191
  path: r.map((f) => f.toString()),
192
192
  argumentList: l
193
- }, u).then(d);
193
+ }, u).then(y);
194
194
  }
195
195
  });
196
- return X(s, e), s;
196
+ return X(i, t), i;
197
197
  }
198
- function K(e) {
199
- return Array.prototype.concat.apply([], e);
198
+ function K(t) {
199
+ return Array.prototype.concat.apply([], t);
200
200
  }
201
- function v(e) {
202
- const t = e.map(A);
203
- return [t.map((r) => r[0]), K(t.map((r) => r[1]))];
201
+ function k(t) {
202
+ const e = t.map(A);
203
+ return [e.map((r) => r[0]), K(e.map((r) => r[1]))];
204
204
  }
205
205
  const _ = /* @__PURE__ */ new WeakMap();
206
- function J(e, t) {
207
- return _.set(e, t), e;
206
+ function J(t, e) {
207
+ return _.set(t, e), t;
208
208
  }
209
- function Q(e) {
210
- return Object.assign(e, { [H]: !0 });
209
+ function Q(t) {
210
+ return Object.assign(t, { [H]: !0 });
211
211
  }
212
- function A(e) {
213
- for (const [t, r] of U)
214
- if (r.canHandle(e)) {
215
- const [a, n] = r.serialize(e);
212
+ function A(t) {
213
+ for (const [e, r] of U)
214
+ if (r.canHandle(t)) {
215
+ const [a, n] = r.serialize(t);
216
216
  return [
217
217
  {
218
218
  type: "HANDLER",
219
- name: t,
219
+ name: e,
220
220
  value: a
221
221
  },
222
222
  n
@@ -225,31 +225,31 @@ function A(e) {
225
225
  return [
226
226
  {
227
227
  type: "RAW",
228
- value: e
228
+ value: t
229
229
  },
230
- _.get(e) || []
230
+ _.get(t) || []
231
231
  ];
232
232
  }
233
- function d(e) {
234
- switch (e.type) {
233
+ function y(t) {
234
+ switch (t.type) {
235
235
  case "HANDLER":
236
- return U.get(e.name).deserialize(e.value);
236
+ return U.get(t.name).deserialize(t.value);
237
237
  case "RAW":
238
- return e.value;
238
+ return t.value;
239
239
  }
240
240
  }
241
- function y(e, t, r, a) {
241
+ function d(t, e, r, a) {
242
242
  return new Promise((n) => {
243
- const s = Z();
244
- t.set(s, n), e.start && e.start(), e.postMessage(Object.assign({ id: s }, r), a);
243
+ const i = Z();
244
+ e.set(i, n), t.start && t.start(), t.postMessage(Object.assign({ id: i }, r), a);
245
245
  });
246
246
  }
247
247
  function Z() {
248
248
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
249
249
  }
250
250
  class c extends Error {
251
- constructor(t, r, a) {
252
- super(t), this.code = r, this.path = a, this.name = "OPFSError";
251
+ constructor(e, r, a) {
252
+ super(e), this.code = r, this.path = a, this.name = "OPFSError";
253
253
  }
254
254
  }
255
255
  class ee extends c {
@@ -257,118 +257,118 @@ class ee extends c {
257
257
  super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
258
258
  }
259
259
  }
260
- class D extends c {
260
+ class T extends c {
261
261
  constructor() {
262
262
  super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
263
263
  }
264
264
  }
265
- class k extends c {
266
- constructor(t, r) {
267
- super(t, "INVALID_PATH", r);
265
+ class v extends c {
266
+ constructor(e, r) {
267
+ super(e, "INVALID_PATH", r);
268
268
  }
269
269
  }
270
- class b extends c {
271
- constructor(t) {
272
- super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
270
+ class D extends c {
271
+ constructor(e) {
272
+ super(\`File not found: \${e}\`, "FILE_NOT_FOUND", e);
273
273
  }
274
274
  }
275
- function te(e, t = "utf-8") {
276
- switch (t) {
275
+ function te(t, e = "utf-8") {
276
+ switch (e) {
277
277
  case "utf8":
278
278
  case "utf-8":
279
- return new TextEncoder().encode(e);
279
+ return new TextEncoder().encode(t);
280
280
  case "utf16le":
281
281
  case "ucs2":
282
282
  case "ucs-2":
283
- return ne(e);
283
+ return ne(t);
284
284
  case "ascii":
285
- return ie(e);
285
+ return se(t);
286
286
  case "latin1":
287
- return se(e);
287
+ return ie(t);
288
288
  case "binary":
289
- return Uint8Array.from(e, (r) => r.charCodeAt(0));
289
+ return Uint8Array.from(t, (r) => r.charCodeAt(0));
290
290
  case "base64":
291
- return Uint8Array.from(atob(e), (r) => r.charCodeAt(0));
291
+ return Uint8Array.from(atob(t), (r) => r.charCodeAt(0));
292
292
  case "hex":
293
- if (!/^[\\da-f]+$/i.test(e) || e.length % 2 !== 0)
293
+ if (!/^[\\da-f]+$/i.test(t) || t.length % 2 !== 0)
294
294
  throw new c("Invalid hex string", "INVALID_HEX_FORMAT");
295
- return Uint8Array.from(e.match(/.{1,2}/g).map((r) => parseInt(r, 16)));
295
+ return Uint8Array.from(t.match(/.{1,2}/g).map((r) => parseInt(r, 16)));
296
296
  default:
297
- return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(e);
297
+ return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(t);
298
298
  }
299
299
  }
300
- function re(e, t = "utf-8") {
301
- switch (t) {
300
+ function re(t, e = "utf-8") {
301
+ switch (e) {
302
302
  case "utf8":
303
303
  case "utf-8":
304
- return new TextDecoder().decode(e);
304
+ return new TextDecoder().decode(t);
305
305
  case "utf16le":
306
306
  case "ucs2":
307
307
  case "ucs-2":
308
- return ae(e);
308
+ return ae(t);
309
309
  case "latin1":
310
- return String.fromCharCode(...e);
310
+ return String.fromCharCode(...t);
311
311
  case "binary":
312
- return String.fromCharCode(...e);
312
+ return String.fromCharCode(...t);
313
313
  case "ascii":
314
- return String.fromCharCode(...e.map((r) => r & 127));
314
+ return String.fromCharCode(...t.map((r) => r & 127));
315
315
  case "base64":
316
- return btoa(String.fromCharCode(...e));
316
+ return btoa(String.fromCharCode(...t));
317
317
  case "hex":
318
- return Array.from(e).map((r) => r.toString(16).padStart(2, "0")).join("");
318
+ return Array.from(t).map((r) => r.toString(16).padStart(2, "0")).join("");
319
319
  default:
320
- return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(e);
320
+ return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(t);
321
321
  }
322
322
  }
323
- function ne(e) {
324
- const t = new Uint8Array(e.length * 2);
325
- for (let r = 0; r < e.length; r++) {
326
- const a = e.charCodeAt(r);
327
- t[r * 2] = a & 255, t[r * 2 + 1] = a >> 8;
323
+ function ne(t) {
324
+ const e = new Uint8Array(t.length * 2);
325
+ for (let r = 0; r < t.length; r++) {
326
+ const a = t.charCodeAt(r);
327
+ e[r * 2] = a & 255, e[r * 2 + 1] = a >> 8;
328
328
  }
329
- return t;
329
+ return e;
330
330
  }
331
- function ae(e) {
332
- e.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), e = e.slice(0, e.length - 1));
333
- const t = new Uint16Array(e.buffer, e.byteOffset, e.byteLength / 2);
334
- return String.fromCharCode(...t);
331
+ function ae(t) {
332
+ t.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), t = t.slice(0, t.length - 1));
333
+ const e = new Uint16Array(t.buffer, t.byteOffset, t.byteLength / 2);
334
+ return String.fromCharCode(...e);
335
335
  }
336
- function se(e) {
337
- const t = new Uint8Array(e.length);
338
- for (let r = 0; r < e.length; r++)
339
- t[r] = e.charCodeAt(r) & 255;
340
- return t;
336
+ function ie(t) {
337
+ const e = new Uint8Array(t.length);
338
+ for (let r = 0; r < t.length; r++)
339
+ e[r] = t.charCodeAt(r) & 255;
340
+ return e;
341
341
  }
342
- function ie(e) {
343
- const t = new Uint8Array(e.length);
344
- for (let r = 0; r < e.length; r++)
345
- t[r] = e.charCodeAt(r) & 127;
346
- return t;
342
+ function se(t) {
343
+ const e = new Uint8Array(t.length);
344
+ for (let r = 0; r < t.length; r++)
345
+ e[r] = t.charCodeAt(r) & 127;
346
+ return e;
347
347
  }
348
348
  function oe() {
349
349
  if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
350
350
  throw new ee();
351
351
  }
352
- function m(e) {
353
- return Array.isArray(e) ? e : e.split("/").filter(Boolean);
352
+ function m(t) {
353
+ return Array.isArray(t) ? t : t.split("/").filter(Boolean);
354
354
  }
355
- function N(e) {
356
- return typeof e == "string" ? e ?? "/" : \`/\${e.join("/")}\`;
355
+ function x(t) {
356
+ return typeof t == "string" ? t ?? "/" : \`/\${t.join("/")}\`;
357
357
  }
358
- function P(e) {
359
- const t = m(e);
360
- return t[t.length - 1] || "";
358
+ function b(t) {
359
+ const e = m(t);
360
+ return e[e.length - 1] || "";
361
361
  }
362
- function M(e) {
363
- const t = m(e);
364
- return t.pop(), N(t);
362
+ function M(t) {
363
+ const e = m(t);
364
+ return e.pop(), x(e);
365
365
  }
366
- function I(e) {
367
- return !e || e === "/" ? "/" : e.startsWith("/") ? e : \`/\${e}\`;
366
+ function C(t) {
367
+ return !t || t === "/" ? "/" : t.startsWith("/") ? t : \`/\${t}\`;
368
368
  }
369
- function ce(e) {
370
- const t = m(e), r = [];
371
- for (const a of t)
369
+ function ce(t) {
370
+ const e = m(t), r = [];
371
+ for (const a of e)
372
372
  if (!(a === "." || a === ""))
373
373
  if (a === "..") {
374
374
  if (r.length === 0)
@@ -376,28 +376,28 @@ function ce(e) {
376
376
  r.pop();
377
377
  } else
378
378
  r.push(a);
379
- return N(r);
379
+ return x(r);
380
380
  }
381
- function le(e, t = "utf-8") {
382
- return typeof e == "string" ? te(e, t) : e instanceof Uint8Array ? e : new Uint8Array(e);
381
+ function le(t, e = "utf-8") {
382
+ return typeof t == "string" ? te(t, e) : t instanceof Uint8Array ? t : new Uint8Array(t);
383
383
  }
384
- async function ue(e) {
385
- const t = await e.createSyncAccessHandle();
384
+ async function ue(t) {
385
+ const e = await t.createSyncAccessHandle();
386
386
  try {
387
- const r = t.getSize(), a = new Uint8Array(r);
388
- return t.read(a, { at: 0 }), a;
387
+ const r = e.getSize(), a = new Uint8Array(r);
388
+ return e.read(a, { at: 0 }), a;
389
389
  } finally {
390
- t.close();
390
+ e.close();
391
391
  }
392
392
  }
393
- async function C(e, t, r, a = {}) {
393
+ async function N(t, e, r, a = {}) {
394
394
  let n = null;
395
395
  try {
396
- n = await e.createSyncAccessHandle();
397
- const s = le(t, r), o = a.append ? n.getSize() : 0;
398
- n.write(s, { at: o }), a.truncate && !a.append && n.truncate(s.byteLength), n.flush();
399
- } catch (s) {
400
- console.error(s);
396
+ n = await t.createSyncAccessHandle();
397
+ const i = le(e, r), o = a.append ? n.getSize() : 0;
398
+ n.write(i, { at: o }), a.truncate && !a.append && n.truncate(i.byteLength), n.flush();
399
+ } catch (i) {
400
+ console.error(i);
401
401
  const o = a.append ? "append" : "write";
402
402
  throw new c(\`Failed to \${o} file\`, \`\${o.toUpperCase()}_FAILED\`);
403
403
  } finally {
@@ -408,17 +408,17 @@ async function C(e, t, r, a = {}) {
408
408
  }
409
409
  }
410
410
  }
411
- async function fe(e, t = "SHA-1") {
411
+ async function fe(t, e = "SHA-1") {
412
412
  try {
413
- const r = new Uint8Array(e), a = await crypto.subtle.digest(t, r);
414
- return Array.from(new Uint8Array(a)).map((s) => s.toString(16).padStart(2, "0")).join("");
413
+ const r = new Uint8Array(t), a = await crypto.subtle.digest(e, r);
414
+ return Array.from(new Uint8Array(a)).map((i) => i.toString(16).padStart(2, "0")).join("");
415
415
  } catch (r) {
416
- throw console.warn(\`Failed to calculate \${t} hash:\`, r), r;
416
+ throw console.warn(\`Failed to calculate \${e} hash:\`, r), r;
417
417
  }
418
418
  }
419
- async function he(e) {
420
- const t = await e.arrayBuffer();
421
- return new Uint8Array(t);
419
+ async function he(t) {
420
+ const e = await t.arrayBuffer();
421
+ return new Uint8Array(e);
422
422
  }
423
423
  class we {
424
424
  /** Root directory handle for the file system */
@@ -435,6 +435,21 @@ class we {
435
435
  scanning = !1;
436
436
  /** Promise to prevent concurrent mount operations */
437
437
  mountingPromise = null;
438
+ /**
439
+ * Notify about internal changes to the file system
440
+ *
441
+ * This method is called by internal operations to notify clients about
442
+ * changes, even when no specific paths are being watched.
443
+ *
444
+ * @param path - The path that was changed
445
+ * @param type - The type of change (create, change, delete)
446
+ */
447
+ notifyInternalChange(e, r) {
448
+ this.watchCallback && this.watchCallback({
449
+ path: e,
450
+ type: r
451
+ });
452
+ }
438
453
  /**
439
454
  * Creates a new OPFSFileSystem instance
440
455
  *
@@ -442,8 +457,8 @@ class we {
442
457
  * @param watchOptions - Optional configuration for watching
443
458
  * @throws {OPFSError} If OPFS is not supported in the current browser
444
459
  */
445
- constructor(t, r) {
446
- oe(), t && (this.watchCallback = t, r?.watchInterval && (this.watchInterval = r.watchInterval)), this.mount("/");
460
+ constructor(e, r) {
461
+ oe(), e && (this.watchCallback = e, r?.watchInterval && (this.watchInterval = r.watchInterval)), this.mount("/");
447
462
  }
448
463
  /**
449
464
  * Initialize the file system within a given directory
@@ -466,12 +481,12 @@ class we {
466
481
  * await fs.mount('/my-app');
467
482
  * \`\`\`
468
483
  */
469
- async mount(t = "/") {
484
+ async mount(e = "/") {
470
485
  return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (r, a) => {
471
486
  this.root = null;
472
487
  try {
473
488
  const n = await navigator.storage.getDirectory();
474
- t === "/" ? this.root = n : this.root = await this.getDirectoryHandle(t, !0, n), r(!0);
489
+ e === "/" ? this.root = n : this.root = await this.getDirectoryHandle(e, !0, n), r(!0);
475
490
  } catch (n) {
476
491
  console.error(n), a(new c("Failed to initialize OPFS", "INIT_FAILED"));
477
492
  } finally {
@@ -485,8 +500,8 @@ class we {
485
500
  * @param callback - The callback function to invoke when files change
486
501
  * @param options - Optional configuration for watching
487
502
  */
488
- setWatchCallback(t, r) {
489
- this.watchCallback = t, r?.watchInterval && (this.watchInterval = r.watchInterval);
503
+ setWatchCallback(e, r) {
504
+ this.watchCallback = e, r?.watchInterval && (this.watchInterval = r.watchInterval);
490
505
  }
491
506
  /**
492
507
  * Automatically mount the OPFS root if not already mounted
@@ -524,14 +539,14 @@ class we {
524
539
  * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
525
540
  * \`\`\`
526
541
  */
527
- async getDirectoryHandle(t, r = !1, a = this.root) {
542
+ async getDirectoryHandle(e, r = !1, a = this.root) {
528
543
  if (!a)
529
- throw new D();
530
- const n = Array.isArray(t) ? t : m(t);
531
- let s = a;
544
+ throw new T();
545
+ const n = Array.isArray(e) ? e : m(e);
546
+ let i = a;
532
547
  for (const o of n)
533
- s = await s.getDirectoryHandle(o, { create: r });
534
- return s;
548
+ i = await i.getDirectoryHandle(o, { create: r });
549
+ return i;
535
550
  }
536
551
  /**
537
552
  * Get a file handle from a path
@@ -552,14 +567,14 @@ class we {
552
567
  * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
553
568
  * \`\`\`
554
569
  */
555
- async getFileHandle(t, r = !1, a = this.root) {
570
+ async getFileHandle(e, r = !1, a = this.root) {
556
571
  if (!a)
557
- throw new D();
558
- const n = m(t);
572
+ throw new T();
573
+ const n = m(e);
559
574
  if (n.length === 0)
560
- throw new k("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
561
- const s = n.pop();
562
- return (await this.getDirectoryHandle(n, r, a)).getFileHandle(s, { create: r });
575
+ throw new v("Path must not be empty", Array.isArray(e) ? e.join("/") : e);
576
+ const i = n.pop();
577
+ return (await this.getDirectoryHandle(n, r, a)).getFileHandle(i, { create: r });
563
578
  }
564
579
  /**
565
580
  * Recursively list all files and directories with their stats
@@ -598,16 +613,16 @@ class we {
598
613
  * }
599
614
  * \`\`\`
600
615
  */
601
- async index(t) {
616
+ async index(e) {
602
617
  const r = /* @__PURE__ */ new Map(), a = async (n) => {
603
- const s = await this.readdir(n, { withFileTypes: !0 });
604
- for (const o of s) {
605
- const i = \`\${n === "/" ? "" : n}/\${o.name}\`;
618
+ const i = await this.readdir(n, { withFileTypes: !0 });
619
+ for (const o of i) {
620
+ const s = \`\${n === "/" ? "" : n}/\${o.name}\`;
606
621
  try {
607
- const l = await this.stat(i, t);
608
- r.set(i, l), l.isDirectory && await a(i);
622
+ const l = await this.stat(s, e);
623
+ r.set(s, l), l.isDirectory && await a(s);
609
624
  } catch (l) {
610
- console.warn(\`Skipping broken entry: \${i}\`, l);
625
+ console.warn(\`Skipping broken entry: \${s}\`, l);
611
626
  }
612
627
  }
613
628
  };
@@ -620,13 +635,13 @@ class we {
620
635
  isDirectory: !0
621
636
  }), await a("/"), r;
622
637
  }
623
- async readFile(t, r = "utf-8") {
638
+ async readFile(e, r = "utf-8") {
624
639
  await this.ensureMounted();
625
640
  try {
626
- const a = await this.getFileHandle(t, !1), n = await ue(a);
641
+ const a = await this.getFileHandle(e, !1), n = await ue(a);
627
642
  return r === "binary" ? n : re(n, r);
628
643
  } catch (a) {
629
- throw console.error(a), new b(t);
644
+ throw console.error(a), new D(e);
630
645
  }
631
646
  }
632
647
  /**
@@ -654,10 +669,10 @@ class we {
654
669
  * await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');
655
670
  * \`\`\`
656
671
  */
657
- async writeFile(t, r, a) {
672
+ async writeFile(e, r, a) {
658
673
  await this.ensureMounted();
659
- const n = await this.getFileHandle(t, !0);
660
- await C(n, r, a, { truncate: !0 });
674
+ const n = await this.getFileHandle(e, !0);
675
+ await N(n, r, a, { truncate: !0 }), this.notifyInternalChange(e, "change");
661
676
  }
662
677
  /**
663
678
  * Append data to a file
@@ -681,10 +696,10 @@ class we {
681
696
  * await fs.appendFile('/data/binary.dat', additionalData);
682
697
  * \`\`\`
683
698
  */
684
- async appendFile(t, r, a) {
699
+ async appendFile(e, r, a) {
685
700
  await this.ensureMounted();
686
- const n = await this.getFileHandle(t, !0);
687
- await C(n, r, a, { append: !0 });
701
+ const n = await this.getFileHandle(e, !0);
702
+ await N(n, r, a, { append: !0 }), this.notifyInternalChange(e, "change");
688
703
  }
689
704
  /**
690
705
  * Create a directory
@@ -707,22 +722,23 @@ class we {
707
722
  * await fs.mkdir('/users/john/documents/projects', { recursive: true });
708
723
  * \`\`\`
709
724
  */
710
- async mkdir(t, r) {
725
+ async mkdir(e, r) {
711
726
  if (await this.ensureMounted(), !this.root)
712
- throw new D();
713
- const a = r?.recursive ?? !1, n = m(t);
714
- let s = this.root;
727
+ throw new T();
728
+ const a = r?.recursive ?? !1, n = m(e);
729
+ let i = this.root;
715
730
  for (let o = 0; o < n.length; o++) {
716
- const i = n[o];
731
+ const s = n[o];
717
732
  try {
718
- s = await s.getDirectoryHandle(i, { create: a || o === n.length - 1 });
733
+ i = await i.getDirectoryHandle(s, { create: a || o === n.length - 1 });
719
734
  } catch (l) {
720
735
  throw l.name === "NotFoundError" ? new c(
721
- \`Parent directory does not exist: \${N(n.slice(0, o + 1))}\`,
736
+ \`Parent directory does not exist: \${x(n.slice(0, o + 1))}\`,
722
737
  "ENOENT"
723
- ) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${i}\`, "ENOTDIR") : new c("Failed to create directory", "MKDIR_FAILED");
738
+ ) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${s}\`, "ENOTDIR") : new c("Failed to create directory", "MKDIR_FAILED");
724
739
  }
725
740
  }
741
+ this.notifyInternalChange(e, "create");
726
742
  }
727
743
  /**
728
744
  * Get file or directory stats
@@ -753,9 +769,17 @@ class we {
753
769
  * console.log(\`Hash: \${statsWithHash.hash}\`);
754
770
  * \`\`\`
755
771
  */
756
- async stat(t, r) {
757
- await this.ensureMounted();
758
- const a = P(t), n = await this.getDirectoryHandle(M(t), !1), s = r?.includeHash ?? !1, o = r?.hashAlgorithm ?? "SHA-1";
772
+ async stat(e, r) {
773
+ if (await this.ensureMounted(), e === "/")
774
+ return {
775
+ kind: "directory",
776
+ size: 0,
777
+ mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
778
+ ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
779
+ isFile: !1,
780
+ isDirectory: !0
781
+ };
782
+ const a = b(e), n = await this.getDirectoryHandle(M(e), !1), i = r?.includeHash ?? !1, o = r?.hashAlgorithm ?? "SHA-1";
759
783
  try {
760
784
  const l = await (await n.getFileHandle(a, { create: !1 })).getFile(), u = {
761
785
  kind: "file",
@@ -765,16 +789,16 @@ class we {
765
789
  isFile: !0,
766
790
  isDirectory: !1
767
791
  };
768
- if (s)
792
+ if (i)
769
793
  try {
770
794
  const f = new Uint8Array(await l.arrayBuffer()), w = await fe(f, o);
771
795
  u.hash = w;
772
796
  } catch (f) {
773
- console.warn(\`Failed to calculate hash for \${t}:\`, f);
797
+ console.warn(\`Failed to calculate hash for \${e}:\`, f);
774
798
  }
775
799
  return u;
776
- } catch (i) {
777
- if (i.name !== "TypeMismatchError" && i.name !== "NotFoundError")
800
+ } catch (s) {
801
+ if (s.name !== "TypeMismatchError" && s.name !== "NotFoundError")
778
802
  throw new c("Failed to stat (file)", "STAT_FAILED");
779
803
  }
780
804
  try {
@@ -786,30 +810,30 @@ class we {
786
810
  isFile: !1,
787
811
  isDirectory: !0
788
812
  };
789
- } catch (i) {
790
- throw i.name === "NotFoundError" ? new c(\`No such file or directory: \${t}\`, "ENOENT") : new c("Failed to stat (directory)", "STAT_FAILED");
813
+ } catch (s) {
814
+ throw s.name === "NotFoundError" ? new c(\`No such file or directory: \${e}\`, "ENOENT") : new c("Failed to stat (directory)", "STAT_FAILED");
791
815
  }
792
816
  }
793
- async readdir(t, r) {
817
+ async readdir(e, r) {
794
818
  await this.ensureMounted();
795
- const a = r?.withFileTypes ?? !1, n = await this.getDirectoryHandle(t, !1);
819
+ const a = r?.withFileTypes ?? !1, n = await this.getDirectoryHandle(e, !1);
796
820
  if (a) {
797
- const s = [];
798
- for await (const [o, i] of n.entries()) {
799
- const l = i.kind === "file";
800
- s.push({
821
+ const i = [];
822
+ for await (const [o, s] of n.entries()) {
823
+ const l = s.kind === "file";
824
+ i.push({
801
825
  name: o,
802
- kind: i.kind,
826
+ kind: s.kind,
803
827
  isFile: l,
804
828
  isDirectory: !l
805
829
  });
806
830
  }
807
- return s;
831
+ return i;
808
832
  } else {
809
- const s = [];
833
+ const i = [];
810
834
  for await (const [o] of n.entries())
811
- s.push(o);
812
- return s;
835
+ i.push(o);
836
+ return i;
813
837
  }
814
838
  }
815
839
  /**
@@ -826,12 +850,13 @@ class we {
826
850
  * console.log(\`File exists: \${exists}\`);
827
851
  * \`\`\`
828
852
  */
829
- async exists(t) {
830
- await this.ensureMounted();
831
- const r = P(t);
853
+ async exists(e) {
854
+ if (await this.ensureMounted(), e === "/")
855
+ return !0;
856
+ const r = b(e);
832
857
  let a = null;
833
858
  try {
834
- a = await this.getDirectoryHandle(M(t), !1);
859
+ a = await this.getDirectoryHandle(M(e), !1);
835
860
  } catch (n) {
836
861
  throw (n.name === "NotFoundError" || n.name === "TypeMismatchError") && (a = null), n;
837
862
  }
@@ -870,16 +895,17 @@ class we {
870
895
  * await fs.clear('/data');
871
896
  * \`\`\`
872
897
  */
873
- async clear(t = "/") {
898
+ async clear(e = "/") {
874
899
  await this.ensureMounted();
875
900
  try {
876
- const r = await this.readdir(t, { withFileTypes: !0 });
901
+ const r = await this.readdir(e, { withFileTypes: !0 });
877
902
  for (const a of r) {
878
- const n = \`\${t === "/" ? "" : t}/\${a.name}\`;
903
+ const n = \`\${e === "/" ? "" : e}/\${a.name}\`;
879
904
  await this.remove(n, { recursive: !0 });
880
905
  }
906
+ this.notifyInternalChange(e, "change");
881
907
  } catch (r) {
882
- throw r instanceof c ? r : new c(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED");
908
+ throw r instanceof c ? r : new c(\`Failed to clear directory: \${e}\`, "CLEAR_FAILED");
883
909
  }
884
910
  }
885
911
  /**
@@ -906,20 +932,24 @@ class we {
906
932
  * await fs.rm('/maybe/exists', { force: true });
907
933
  * \`\`\`
908
934
  */
909
- async remove(t, r) {
935
+ async remove(e, r) {
910
936
  await this.ensureMounted();
911
- const a = r?.recursive ?? !1, n = r?.force ?? !1, s = P(t);
912
- if (!s)
913
- throw new k("Invalid path", t);
914
- const o = await this.getDirectoryHandle(M(t), !1);
937
+ const a = r?.recursive ?? !1, n = r?.force ?? !1;
938
+ if (e === "/")
939
+ throw new c("Cannot remove root directory", "EROOT");
940
+ const i = b(e);
941
+ if (!i)
942
+ throw new v("Invalid path", e);
943
+ const o = await this.getDirectoryHandle(M(e), !1);
915
944
  try {
916
- await o.removeEntry(s, { recursive: a });
917
- } catch (i) {
918
- if (i.name === "NotFoundError") {
945
+ await o.removeEntry(i, { recursive: a });
946
+ } catch (s) {
947
+ if (s.name === "NotFoundError") {
919
948
  if (!n)
920
- throw new c(\`No such file or directory: \${t}\`, "ENOENT");
921
- } else throw i.name === "InvalidModificationError" ? new c(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : i.name === "TypeMismatchError" && !a ? new c(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new c(\`Failed to remove path: \${t}\`, "RM_FAILED");
949
+ throw new c(\`No such file or directory: \${e}\`, "ENOENT");
950
+ } else throw s.name === "InvalidModificationError" ? new c(\`Directory not empty: \${e}. Use recursive option to force removal.\`, "ENOTEMPTY") : s.name === "TypeMismatchError" && !a ? new c(\`Cannot remove directory without recursive option: \${e}\`, "EISDIR") : new c(\`Failed to remove path: \${e}\`, "RM_FAILED");
922
951
  }
952
+ this.notifyInternalChange(e, "delete");
923
953
  }
924
954
  /**
925
955
  * Resolve a path to an absolute path
@@ -939,15 +969,15 @@ class we {
939
969
  * console.log(absolute); // '/data/file.txt'
940
970
  * \`\`\`
941
971
  */
942
- async realpath(t) {
972
+ async realpath(e) {
943
973
  await this.ensureMounted();
944
974
  try {
945
- const r = ce(t);
975
+ const r = ce(e);
946
976
  if (!await this.exists(r))
947
- throw new b(r);
977
+ throw new D(r);
948
978
  return r;
949
979
  } catch (r) {
950
- throw r instanceof c ? r : new c(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
980
+ throw r instanceof c ? r : new c(\`Failed to resolve path: \${e}\`, "REALPATH_FAILED");
951
981
  }
952
982
  }
953
983
  /**
@@ -966,14 +996,14 @@ class we {
966
996
  * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
967
997
  * \`\`\`
968
998
  */
969
- async rename(t, r) {
999
+ async rename(e, r) {
970
1000
  await this.ensureMounted();
971
1001
  try {
972
- if (!await this.exists(t))
973
- throw new b(t);
974
- await this.copy(t, r, { recursive: !0 }), await this.remove(t, { recursive: !0 });
1002
+ if (!await this.exists(e))
1003
+ throw new D(e);
1004
+ await this.copy(e, r, { recursive: !0 }), await this.remove(e, { recursive: !0 }), this.notifyInternalChange(e, "delete"), this.notifyInternalChange(r, "create");
975
1005
  } catch (a) {
976
- throw a instanceof c ? a : new c(\`Failed to rename from \${t} to \${r}\`, "RENAME_FAILED");
1006
+ throw a instanceof c ? a : new c(\`Failed to rename from \${e} to \${r}\`, "RENAME_FAILED");
977
1007
  }
978
1008
  }
979
1009
  /**
@@ -1001,37 +1031,38 @@ class we {
1001
1031
  * await fs.copy('/source', '/dest', { recursive: true, force: false });
1002
1032
  * \`\`\`
1003
1033
  */
1004
- async copy(t, r, a) {
1034
+ async copy(e, r, a) {
1005
1035
  await this.ensureMounted();
1006
1036
  try {
1007
- const n = a?.recursive ?? !1, s = a?.force ?? !0;
1008
- if (!await this.exists(t))
1009
- throw new c(\`Source does not exist: \${t}\`, "ENOENT");
1010
- if (await this.exists(r) && !s)
1037
+ const n = a?.recursive ?? !1, i = a?.force ?? !0;
1038
+ if (!await this.exists(e))
1039
+ throw new c(\`Source does not exist: \${e}\`, "ENOENT");
1040
+ if (await this.exists(r) && !i)
1011
1041
  throw new c(\`Destination already exists: \${r}\`, "EEXIST");
1012
- if ((await this.stat(t)).isFile) {
1013
- const u = await this.readFile(t, "binary");
1042
+ if ((await this.stat(e)).isFile) {
1043
+ const u = await this.readFile(e, "binary");
1014
1044
  await this.writeFile(r, u);
1015
1045
  } else {
1016
1046
  if (!n)
1017
- throw new c(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR");
1047
+ throw new c(\`Cannot copy directory without recursive option: \${e}\`, "EISDIR");
1018
1048
  await this.mkdir(r, { recursive: !0 });
1019
- const u = await this.readdir(t, { withFileTypes: !0 });
1049
+ const u = await this.readdir(e, { withFileTypes: !0 });
1020
1050
  for (const f of u) {
1021
- const w = \`\${t}/\${f.name}\`, h = \`\${r}/\${f.name}\`;
1022
- await this.copy(w, h, { recursive: !0, force: s });
1051
+ const w = \`\${e}/\${f.name}\`, h = \`\${r}/\${f.name}\`;
1052
+ await this.copy(w, h, { recursive: !0, force: i });
1023
1053
  }
1024
1054
  }
1055
+ this.notifyInternalChange(r, "create");
1025
1056
  } catch (n) {
1026
- throw n instanceof c ? n : new c(\`Failed to copy from \${t} to \${r}\`, "CP_FAILED");
1057
+ throw n instanceof c ? n : new c(\`Failed to copy from \${e} to \${r}\`, "CP_FAILED");
1027
1058
  }
1028
1059
  }
1029
1060
  /**
1030
1061
  * Start watching a file or directory for changes
1031
1062
  */
1032
- async watch(t) {
1063
+ async watch(e) {
1033
1064
  await this.ensureMounted();
1034
- const r = I(t), a = await this.buildSnapshot(r);
1065
+ const r = C(e), a = await this.buildSnapshot(r);
1035
1066
  this.watchers.set(r, a), this.watchTimer || (this.watchTimer = setInterval(() => {
1036
1067
  this.scanWatches();
1037
1068
  }, this.watchInterval));
@@ -1039,46 +1070,46 @@ class we {
1039
1070
  /**
1040
1071
  * Stop watching a previously watched path
1041
1072
  */
1042
- unwatch(t) {
1043
- const r = I(t);
1073
+ unwatch(e) {
1074
+ const r = C(e);
1044
1075
  this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
1045
1076
  }
1046
- async buildSnapshot(t) {
1077
+ async buildSnapshot(e) {
1047
1078
  const r = /* @__PURE__ */ new Map(), a = async (n) => {
1048
- const s = await this.stat(n);
1049
- if (r.set(n, s), s.isDirectory) {
1079
+ const i = await this.stat(n);
1080
+ if (r.set(n, i), i.isDirectory) {
1050
1081
  const o = await this.readdir(n, { withFileTypes: !0 });
1051
- for (const i of o) {
1052
- const l = \`\${n === "/" ? "" : n}/\${i.name}\`;
1082
+ for (const s of o) {
1083
+ const l = \`\${n === "/" ? "" : n}/\${s.name}\`;
1053
1084
  await a(l);
1054
1085
  }
1055
1086
  }
1056
1087
  };
1057
- return await a(t), r;
1088
+ return await a(e), r;
1058
1089
  }
1059
1090
  async scanWatches() {
1060
1091
  if (!this.scanning) {
1061
1092
  this.scanning = !0;
1062
1093
  try {
1063
1094
  await Promise.all(
1064
- [...this.watchers.entries()].map(async ([t, r]) => {
1095
+ [...this.watchers.entries()].map(async ([e, r]) => {
1065
1096
  let a;
1066
1097
  try {
1067
- a = await this.buildSnapshot(t);
1098
+ a = await this.buildSnapshot(e);
1068
1099
  } catch {
1069
1100
  a = /* @__PURE__ */ new Map();
1070
1101
  }
1071
1102
  const n = [];
1072
- for (const [s, o] of a) {
1073
- const i = r.get(s);
1074
- i ? (i.mtime !== o.mtime || i.size !== o.size) && n.push({ path: s, type: "change" }) : n.push({ path: s, type: "create" });
1103
+ for (const [i, o] of a) {
1104
+ const s = r.get(i);
1105
+ s ? (s.mtime !== o.mtime || s.size !== o.size) && n.push({ path: i, type: "change" }) : n.push({ path: i, type: "create" });
1075
1106
  }
1076
- for (const s of r.keys())
1077
- a.has(s) || n.push({ path: s, type: "delete" });
1107
+ for (const i of r.keys())
1108
+ a.has(i) || n.push({ path: i, type: "delete" });
1078
1109
  if (n.length && this.watchCallback)
1079
- for (const s of n)
1080
- this.watchCallback(s);
1081
- this.watchers.set(t, a);
1110
+ for (const i of n)
1111
+ this.watchCallback(i);
1112
+ this.watchers.set(e, a);
1082
1113
  })
1083
1114
  );
1084
1115
  } finally {
@@ -1114,51 +1145,52 @@ class we {
1114
1145
  * await fs.sync(entries, { cleanBefore: true });
1115
1146
  * \`\`\`
1116
1147
  */
1117
- async sync(t, r) {
1148
+ async sync(e, r) {
1118
1149
  await this.ensureMounted();
1119
1150
  try {
1120
1151
  (r?.cleanBefore ?? !1) && await this.clear("/");
1121
- for (const [n, s] of t) {
1122
- const o = I(n);
1123
- let i;
1124
- s instanceof Blob ? i = await he(s) : i = s, await this.writeFile(o, i);
1152
+ for (const [n, i] of e) {
1153
+ const o = C(n);
1154
+ let s;
1155
+ i instanceof Blob ? s = await he(i) : s = i, await this.writeFile(o, s);
1125
1156
  }
1157
+ this.notifyInternalChange("/", "change");
1126
1158
  } catch (a) {
1127
1159
  throw a instanceof c ? a : new c("Failed to sync file system", "SYNC_FAILED");
1128
1160
  }
1129
1161
  }
1130
1162
  }
1131
1163
  typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && O(new we());
1132
- //# sourceMappingURL=worker-CMvl9yOu.js.map
1164
+ //# sourceMappingURL=worker-DCm4BiWM.js.map
1133
1165
  `, r = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", a], { type: "text/javascript;charset=utf-8" });
1134
- function s(e) {
1166
+ function s(t) {
1135
1167
  let n;
1136
1168
  try {
1137
1169
  if (n = r && (self.URL || self.webkitURL).createObjectURL(r), !n) throw "";
1138
- const t = new Worker(n, {
1170
+ const e = new Worker(n, {
1139
1171
  type: "module",
1140
- name: e?.name
1172
+ name: t?.name
1141
1173
  });
1142
- return t.addEventListener("error", () => {
1174
+ return e.addEventListener("error", () => {
1143
1175
  (self.URL || self.webkitURL).revokeObjectURL(n);
1144
- }), t;
1176
+ }), e;
1145
1177
  } catch {
1146
1178
  return new Worker(
1147
1179
  "data:text/javascript;charset=utf-8," + encodeURIComponent(a),
1148
1180
  {
1149
1181
  type: "module",
1150
- name: e?.name
1182
+ name: t?.name
1151
1183
  }
1152
1184
  );
1153
1185
  }
1154
1186
  }
1155
- function l(e, n) {
1156
- const t = i(new s());
1157
- return e && t.setWatchCallback(o(e), n), t;
1187
+ function l(t, n) {
1188
+ const e = i(new s());
1189
+ return t && e.setWatchCallback(o(t), n), e;
1158
1190
  }
1159
1191
  export {
1160
- u as DirectoryNotFoundError,
1161
- d as FileNotFoundError,
1192
+ d as DirectoryNotFoundError,
1193
+ u as FileNotFoundError,
1162
1194
  p as OPFSError,
1163
1195
  w as OPFSNotMountedError,
1164
1196
  y as OPFSNotSupportedError,
@@ -1172,14 +1204,14 @@ export {
1172
1204
  P as convertBlobToUint8Array,
1173
1205
  x as createBuffer,
1174
1206
  l as createWorker,
1175
- A as decodeBuffer,
1176
- T as dirname,
1177
- O as encodeString,
1178
- I as extname,
1207
+ T as decodeBuffer,
1208
+ I as dirname,
1209
+ A as encodeString,
1210
+ O as extname,
1179
1211
  _ as joinPath,
1180
- D as normalizePath,
1181
- k as readFileData,
1182
- C as resolvePath,
1212
+ C as normalizePath,
1213
+ D as readFileData,
1214
+ k as resolvePath,
1183
1215
  U as splitPath,
1184
1216
  R as writeFileData
1185
1217
  };