opfs-worker 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +204 -880
- package/dist/assets/worker-3SMz_DAt.js.map +1 -0
- package/dist/{helpers-BgMlBRWa.js → helpers-Bm2TWyPQ.js} +290 -251
- package/dist/helpers-Bm2TWyPQ.js.map +1 -0
- package/dist/helpers-BoLdVbGk.cjs +4 -0
- package/dist/helpers-BoLdVbGk.cjs.map +1 -0
- package/dist/index.cjs +532 -579
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +560 -602
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +97 -159
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +14 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +9 -9
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +26 -2
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +7 -9
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-Bra0Mewp.js.map +0 -1
- package/dist/helpers-BgMlBRWa.js.map +0 -1
- package/dist/helpers-DuJbWewc.cjs +0 -4
- package/dist/helpers-DuJbWewc.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { wrap as i } from "comlink";
|
|
2
|
-
import { D as p, F as f, O as d, b as u, a as g, P as m, c as w, S as y, T as b, e as v,
|
|
2
|
+
import { D as p, F as f, O as d, b as u, a as g, P as m, c as w, S as y, T as b, e as v, q as S, p as x, d as E, t as P, k as A, x as F, f as O, v as C, h as T, i as R, j as $, m as _, g as D, n as I, l as M, u as j, r as N, s as k, w as L, o as U } from "./helpers-Bm2TWyPQ.js";
|
|
3
3
|
const r = `/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2019 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
9
|
-
canHandle: (s) =>
|
|
8
|
+
const ht = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Ot = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ut = (s) => typeof s == "object" && s !== null || typeof s == "function", Nt = {
|
|
9
|
+
canHandle: (s) => ut(s) && s[ht],
|
|
10
10
|
serialize(s) {
|
|
11
11
|
const { port1: t, port2: e } = new MessageChannel();
|
|
12
|
-
return
|
|
12
|
+
return Y(s, t), [e, [e]];
|
|
13
13
|
},
|
|
14
14
|
deserialize(s) {
|
|
15
15
|
return s.start(), $t(s);
|
|
16
16
|
}
|
|
17
|
-
},
|
|
18
|
-
canHandle: (s) =>
|
|
17
|
+
}, Ft = {
|
|
18
|
+
canHandle: (s) => ut(s) && L in s,
|
|
19
19
|
serialize({ value: s }) {
|
|
20
20
|
let t;
|
|
21
21
|
return s instanceof Error ? t = {
|
|
@@ -30,66 +30,66 @@ const ut = Symbol("Comlink.proxy"), Tt = Symbol("Comlink.endpoint"), Ft = Symbol
|
|
|
30
30
|
deserialize(s) {
|
|
31
31
|
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, ft = /* @__PURE__ */ new Map([
|
|
34
34
|
["proxy", Nt],
|
|
35
|
-
["throw",
|
|
35
|
+
["throw", Ft]
|
|
36
36
|
]);
|
|
37
|
-
function
|
|
37
|
+
function Tt(s, t) {
|
|
38
38
|
for (const e of s)
|
|
39
39
|
if (t === e || e === "*" || e instanceof RegExp && e.test(t))
|
|
40
40
|
return !0;
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function Y(s, t = globalThis, e = ["*"]) {
|
|
44
44
|
t.addEventListener("message", function n(i) {
|
|
45
45
|
if (!i || !i.data)
|
|
46
46
|
return;
|
|
47
|
-
if (!
|
|
47
|
+
if (!Tt(e, i.origin)) {
|
|
48
48
|
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data),
|
|
52
|
-
let
|
|
51
|
+
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(C);
|
|
52
|
+
let h;
|
|
53
53
|
try {
|
|
54
|
-
const
|
|
54
|
+
const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
|
|
55
55
|
switch (o) {
|
|
56
56
|
case "GET":
|
|
57
|
-
|
|
57
|
+
h = f;
|
|
58
58
|
break;
|
|
59
59
|
case "SET":
|
|
60
|
-
|
|
60
|
+
c[a.slice(-1)[0]] = C(i.data.value), h = !0;
|
|
61
61
|
break;
|
|
62
62
|
case "APPLY":
|
|
63
|
-
|
|
63
|
+
h = f.apply(c, l);
|
|
64
64
|
break;
|
|
65
65
|
case "CONSTRUCT":
|
|
66
66
|
{
|
|
67
|
-
const u = new f(...
|
|
68
|
-
|
|
67
|
+
const u = new f(...l);
|
|
68
|
+
h = It(u);
|
|
69
69
|
}
|
|
70
70
|
break;
|
|
71
71
|
case "ENDPOINT":
|
|
72
72
|
{
|
|
73
73
|
const { port1: u, port2: d } = new MessageChannel();
|
|
74
|
-
|
|
74
|
+
Y(s, d), h = Lt(u, [u]);
|
|
75
75
|
}
|
|
76
76
|
break;
|
|
77
77
|
case "RELEASE":
|
|
78
|
-
|
|
78
|
+
h = void 0;
|
|
79
79
|
break;
|
|
80
80
|
default:
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
} catch (
|
|
84
|
-
|
|
83
|
+
} catch (c) {
|
|
84
|
+
h = { value: c, [L]: 0 };
|
|
85
85
|
}
|
|
86
|
-
Promise.resolve(
|
|
87
|
-
const [f, u] =
|
|
88
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n),
|
|
89
|
-
}).catch((
|
|
90
|
-
const [f, u] =
|
|
86
|
+
Promise.resolve(h).catch((c) => ({ value: c, [L]: 0 })).then((c) => {
|
|
87
|
+
const [f, u] = H(c);
|
|
88
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), dt(t), U in s && typeof s[U] == "function" && s[U]());
|
|
89
|
+
}).catch((c) => {
|
|
90
|
+
const [f, u] = H({
|
|
91
91
|
value: new TypeError("Unserializable return value"),
|
|
92
|
-
[
|
|
92
|
+
[L]: 0
|
|
93
93
|
});
|
|
94
94
|
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
|
|
95
95
|
});
|
|
@@ -98,7 +98,7 @@ function J(s, t = globalThis, e = ["*"]) {
|
|
|
98
98
|
function Mt(s) {
|
|
99
99
|
return s.constructor.name === "MessagePort";
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function dt(s) {
|
|
102
102
|
Mt(s) && s.close();
|
|
103
103
|
}
|
|
104
104
|
function $t(s, t) {
|
|
@@ -114,103 +114,103 @@ function $t(s, t) {
|
|
|
114
114
|
} finally {
|
|
115
115
|
e.delete(r.id);
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), V(s, e, [], t);
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function R(s) {
|
|
120
120
|
if (s)
|
|
121
121
|
throw new Error("Proxy has been released and is not useable");
|
|
122
122
|
}
|
|
123
|
-
function
|
|
124
|
-
return
|
|
123
|
+
function pt(s) {
|
|
124
|
+
return D(s, /* @__PURE__ */ new Map(), {
|
|
125
125
|
type: "RELEASE"
|
|
126
126
|
}).then(() => {
|
|
127
|
-
|
|
127
|
+
dt(s);
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
const t = (
|
|
132
|
-
|
|
130
|
+
const I = /* @__PURE__ */ new WeakMap(), z = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
131
|
+
const t = (I.get(s) || 0) - 1;
|
|
132
|
+
I.set(s, t), t === 0 && pt(s);
|
|
133
133
|
});
|
|
134
|
-
function
|
|
135
|
-
const e = (
|
|
136
|
-
|
|
134
|
+
function Pt(s, t) {
|
|
135
|
+
const e = (I.get(t) || 0) + 1;
|
|
136
|
+
I.set(t, e), z && z.register(s, t, s);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
|
|
138
|
+
function Rt(s) {
|
|
139
|
+
z && z.unregister(s);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function V(s, t, e = [], n = function() {
|
|
142
142
|
}) {
|
|
143
143
|
let i = !1;
|
|
144
144
|
const r = new Proxy(n, {
|
|
145
145
|
get(o, a) {
|
|
146
|
-
if (
|
|
146
|
+
if (R(i), a === Ot)
|
|
147
147
|
return () => {
|
|
148
|
-
|
|
148
|
+
Rt(r), pt(s), t.clear(), i = !0;
|
|
149
149
|
};
|
|
150
150
|
if (a === "then") {
|
|
151
151
|
if (e.length === 0)
|
|
152
152
|
return { then: () => r };
|
|
153
|
-
const
|
|
153
|
+
const l = D(s, t, {
|
|
154
154
|
type: "GET",
|
|
155
|
-
path: e.map((
|
|
155
|
+
path: e.map((h) => h.toString())
|
|
156
156
|
}).then(C);
|
|
157
|
-
return
|
|
157
|
+
return l.then.bind(l);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
159
|
+
return V(s, t, [...e, a]);
|
|
160
160
|
},
|
|
161
|
-
set(o, a,
|
|
162
|
-
|
|
163
|
-
const [
|
|
164
|
-
return
|
|
161
|
+
set(o, a, l) {
|
|
162
|
+
R(i);
|
|
163
|
+
const [h, c] = H(l);
|
|
164
|
+
return D(s, t, {
|
|
165
165
|
type: "SET",
|
|
166
166
|
path: [...e, a].map((f) => f.toString()),
|
|
167
|
-
value:
|
|
168
|
-
},
|
|
167
|
+
value: h
|
|
168
|
+
}, c).then(C);
|
|
169
169
|
},
|
|
170
|
-
apply(o, a,
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
return
|
|
170
|
+
apply(o, a, l) {
|
|
171
|
+
R(i);
|
|
172
|
+
const h = e[e.length - 1];
|
|
173
|
+
if (h === Dt)
|
|
174
|
+
return D(s, t, {
|
|
175
175
|
type: "ENDPOINT"
|
|
176
176
|
}).then(C);
|
|
177
|
-
if (
|
|
178
|
-
return
|
|
179
|
-
const [
|
|
180
|
-
return
|
|
177
|
+
if (h === "bind")
|
|
178
|
+
return V(s, t, e.slice(0, -1));
|
|
179
|
+
const [c, f] = et(l);
|
|
180
|
+
return D(s, t, {
|
|
181
181
|
type: "APPLY",
|
|
182
182
|
path: e.map((u) => u.toString()),
|
|
183
|
-
argumentList:
|
|
183
|
+
argumentList: c
|
|
184
184
|
}, f).then(C);
|
|
185
185
|
},
|
|
186
186
|
construct(o, a) {
|
|
187
|
-
|
|
188
|
-
const [
|
|
189
|
-
return
|
|
187
|
+
R(i);
|
|
188
|
+
const [l, h] = et(a);
|
|
189
|
+
return D(s, t, {
|
|
190
190
|
type: "CONSTRUCT",
|
|
191
|
-
path: e.map((
|
|
192
|
-
argumentList:
|
|
193
|
-
},
|
|
191
|
+
path: e.map((c) => c.toString()),
|
|
192
|
+
argumentList: l
|
|
193
|
+
}, h).then(C);
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
|
-
return
|
|
196
|
+
return Pt(r, s), r;
|
|
197
197
|
}
|
|
198
198
|
function kt(s) {
|
|
199
199
|
return Array.prototype.concat.apply([], s);
|
|
200
200
|
}
|
|
201
201
|
function et(s) {
|
|
202
|
-
const t = s.map(
|
|
202
|
+
const t = s.map(H);
|
|
203
203
|
return [t.map((e) => e[0]), kt(t.map((e) => e[1]))];
|
|
204
204
|
}
|
|
205
|
-
const
|
|
205
|
+
const gt = /* @__PURE__ */ new WeakMap();
|
|
206
206
|
function Lt(s, t) {
|
|
207
|
-
return
|
|
207
|
+
return gt.set(s, t), s;
|
|
208
208
|
}
|
|
209
|
-
function
|
|
210
|
-
return Object.assign(s, { [
|
|
209
|
+
function It(s) {
|
|
210
|
+
return Object.assign(s, { [ht]: !0 });
|
|
211
211
|
}
|
|
212
|
-
function
|
|
213
|
-
for (const [t, e] of
|
|
212
|
+
function H(s) {
|
|
213
|
+
for (const [t, e] of ft)
|
|
214
214
|
if (e.canHandle(s)) {
|
|
215
215
|
const [n, i] = e.serialize(s);
|
|
216
216
|
return [
|
|
@@ -227,28 +227,121 @@ function j(s) {
|
|
|
227
227
|
type: "RAW",
|
|
228
228
|
value: s
|
|
229
229
|
},
|
|
230
|
-
|
|
230
|
+
gt.get(s) || []
|
|
231
231
|
];
|
|
232
232
|
}
|
|
233
233
|
function C(s) {
|
|
234
234
|
switch (s.type) {
|
|
235
235
|
case "HANDLER":
|
|
236
|
-
return
|
|
236
|
+
return ft.get(s.name).deserialize(s.value);
|
|
237
237
|
case "RAW":
|
|
238
238
|
return s.value;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
function D(s, t, e, n) {
|
|
242
242
|
return new Promise((i) => {
|
|
243
|
-
const r =
|
|
243
|
+
const r = zt();
|
|
244
244
|
t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
function
|
|
247
|
+
function zt() {
|
|
248
248
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
249
249
|
}
|
|
250
|
+
class g extends Error {
|
|
251
|
+
constructor(t, e, n, i) {
|
|
252
|
+
super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
class Ht extends g {
|
|
256
|
+
constructor(t) {
|
|
257
|
+
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, t);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
class Wt extends g {
|
|
261
|
+
constructor(t, e, n) {
|
|
262
|
+
super(t, "INVALID_PATH", e, n);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
class _ extends g {
|
|
266
|
+
constructor(t, e) {
|
|
267
|
+
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function jt(s, t = "utf-8") {
|
|
271
|
+
switch (t) {
|
|
272
|
+
case "utf8":
|
|
273
|
+
case "utf-8":
|
|
274
|
+
return new TextEncoder().encode(s);
|
|
275
|
+
case "utf16le":
|
|
276
|
+
case "ucs2":
|
|
277
|
+
case "ucs-2":
|
|
278
|
+
return _t(s);
|
|
279
|
+
case "ascii":
|
|
280
|
+
return qt(s);
|
|
281
|
+
case "latin1":
|
|
282
|
+
return Gt(s);
|
|
283
|
+
case "binary":
|
|
284
|
+
return Uint8Array.from(s, (e) => e.charCodeAt(0));
|
|
285
|
+
case "base64":
|
|
286
|
+
return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
|
|
287
|
+
case "hex":
|
|
288
|
+
if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
|
|
289
|
+
throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
290
|
+
return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
|
|
291
|
+
default:
|
|
292
|
+
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function Ut(s, t = "utf-8") {
|
|
296
|
+
switch (t) {
|
|
297
|
+
case "utf8":
|
|
298
|
+
case "utf-8":
|
|
299
|
+
return new TextDecoder().decode(s);
|
|
300
|
+
case "utf16le":
|
|
301
|
+
case "ucs2":
|
|
302
|
+
case "ucs-2":
|
|
303
|
+
return Bt(s);
|
|
304
|
+
case "latin1":
|
|
305
|
+
return String.fromCharCode(...s);
|
|
306
|
+
case "binary":
|
|
307
|
+
return String.fromCharCode(...s);
|
|
308
|
+
case "ascii":
|
|
309
|
+
return String.fromCharCode(...s.map((e) => e & 127));
|
|
310
|
+
case "base64":
|
|
311
|
+
return btoa(String.fromCharCode(...s));
|
|
312
|
+
case "hex":
|
|
313
|
+
return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
314
|
+
default:
|
|
315
|
+
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function _t(s) {
|
|
319
|
+
const t = new Uint8Array(s.length * 2);
|
|
320
|
+
for (let e = 0; e < s.length; e++) {
|
|
321
|
+
const n = s.charCodeAt(e);
|
|
322
|
+
t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
|
|
323
|
+
}
|
|
324
|
+
return t;
|
|
325
|
+
}
|
|
326
|
+
function Bt(s) {
|
|
327
|
+
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
328
|
+
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
329
|
+
return String.fromCharCode(...t);
|
|
330
|
+
}
|
|
331
|
+
function Gt(s) {
|
|
332
|
+
const t = new Uint8Array(s.length);
|
|
333
|
+
for (let e = 0; e < s.length; e++)
|
|
334
|
+
t[e] = s.charCodeAt(e) & 255;
|
|
335
|
+
return t;
|
|
336
|
+
}
|
|
337
|
+
function qt(s) {
|
|
338
|
+
const t = new Uint8Array(s.length);
|
|
339
|
+
for (let e = 0; e < s.length; e++)
|
|
340
|
+
t[e] = s.charCodeAt(e) & 127;
|
|
341
|
+
return t;
|
|
342
|
+
}
|
|
250
343
|
const mt = (s, t, e) => {
|
|
251
|
-
const n = s instanceof RegExp ? st(s, e) : s, i = t instanceof RegExp ? st(t, e) : t, r = n !== null && i != null &&
|
|
344
|
+
const n = s instanceof RegExp ? st(s, e) : s, i = t instanceof RegExp ? st(t, e) : t, r = n !== null && i != null && Vt(n, i, e);
|
|
252
345
|
return r && {
|
|
253
346
|
start: r[0],
|
|
254
347
|
end: r[1],
|
|
@@ -259,35 +352,35 @@ const mt = (s, t, e) => {
|
|
|
259
352
|
}, st = (s, t) => {
|
|
260
353
|
const e = t.match(s);
|
|
261
354
|
return e ? e[0] : null;
|
|
262
|
-
},
|
|
263
|
-
let n, i, r, o, a,
|
|
264
|
-
if (
|
|
355
|
+
}, Vt = (s, t, e) => {
|
|
356
|
+
let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
357
|
+
if (l >= 0 && h > 0) {
|
|
265
358
|
if (s === t)
|
|
266
|
-
return [
|
|
267
|
-
for (n = [], r = e.length;
|
|
268
|
-
if (
|
|
269
|
-
n.push(
|
|
359
|
+
return [l, h];
|
|
360
|
+
for (n = [], r = e.length; c >= 0 && !a; ) {
|
|
361
|
+
if (c === l)
|
|
362
|
+
n.push(c), l = e.indexOf(s, c + 1);
|
|
270
363
|
else if (n.length === 1) {
|
|
271
364
|
const f = n.pop();
|
|
272
|
-
f !== void 0 && (a = [f,
|
|
365
|
+
f !== void 0 && (a = [f, h]);
|
|
273
366
|
} else
|
|
274
|
-
i = n.pop(), i !== void 0 && i < r && (r = i, o =
|
|
275
|
-
|
|
367
|
+
i = n.pop(), i !== void 0 && i < r && (r = i, o = h), h = e.indexOf(t, c + 1);
|
|
368
|
+
c = l < h && l >= 0 ? l : h;
|
|
276
369
|
}
|
|
277
370
|
n.length && o !== void 0 && (a = [r, o]);
|
|
278
371
|
}
|
|
279
372
|
return a;
|
|
280
|
-
},
|
|
281
|
-
function
|
|
373
|
+
}, wt = "\\0SLASH" + Math.random() + "\\0", yt = "\\0OPEN" + Math.random() + "\\0", J = "\\0CLOSE" + Math.random() + "\\0", Et = "\\0COMMA" + Math.random() + "\\0", St = "\\0PERIOD" + Math.random() + "\\0", Zt = new RegExp(wt, "g"), Xt = new RegExp(yt, "g"), Yt = new RegExp(J, "g"), Jt = new RegExp(Et, "g"), Kt = new RegExp(St, "g"), Qt = /\\\\\\\\/g, te = /\\\\{/g, ee = /\\\\}/g, se = /\\\\,/g, ne = /\\\\./g;
|
|
374
|
+
function B(s) {
|
|
282
375
|
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
283
376
|
}
|
|
284
|
-
function
|
|
285
|
-
return s.replace(
|
|
377
|
+
function ie(s) {
|
|
378
|
+
return s.replace(Qt, wt).replace(te, yt).replace(ee, J).replace(se, Et).replace(ne, St);
|
|
286
379
|
}
|
|
287
|
-
function
|
|
288
|
-
return s.replace(
|
|
380
|
+
function re(s) {
|
|
381
|
+
return s.replace(Zt, "\\\\").replace(Xt, "{").replace(Yt, "}").replace(Jt, ",").replace(Kt, ".");
|
|
289
382
|
}
|
|
290
|
-
function
|
|
383
|
+
function xt(s) {
|
|
291
384
|
if (!s)
|
|
292
385
|
return [""];
|
|
293
386
|
const t = [], e = mt("{", "}", s);
|
|
@@ -295,22 +388,22 @@ function bt(s) {
|
|
|
295
388
|
return s.split(",");
|
|
296
389
|
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
297
390
|
o[o.length - 1] += "{" + i + "}";
|
|
298
|
-
const a =
|
|
391
|
+
const a = xt(r);
|
|
299
392
|
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
300
393
|
}
|
|
301
|
-
function
|
|
302
|
-
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(
|
|
394
|
+
function oe(s) {
|
|
395
|
+
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), M(ie(s), !0).map(re)) : [];
|
|
303
396
|
}
|
|
304
|
-
function
|
|
397
|
+
function ae(s) {
|
|
305
398
|
return "{" + s + "}";
|
|
306
399
|
}
|
|
307
|
-
function
|
|
400
|
+
function ce(s) {
|
|
308
401
|
return /^-?0\\d/.test(s);
|
|
309
402
|
}
|
|
310
|
-
function
|
|
403
|
+
function le(s, t) {
|
|
311
404
|
return s <= t;
|
|
312
405
|
}
|
|
313
|
-
function
|
|
406
|
+
function he(s, t) {
|
|
314
407
|
return s >= t;
|
|
315
408
|
}
|
|
316
409
|
function M(s, t) {
|
|
@@ -324,53 +417,53 @@ function M(s, t) {
|
|
|
324
417
|
e.push(a);
|
|
325
418
|
}
|
|
326
419
|
else {
|
|
327
|
-
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body),
|
|
328
|
-
if (!
|
|
329
|
-
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body +
|
|
330
|
-
let
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
else if (
|
|
334
|
-
return r.map((u) => n.pre +
|
|
420
|
+
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
|
|
421
|
+
if (!l && !h)
|
|
422
|
+
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + J + n.post, M(s)) : [s];
|
|
423
|
+
let c;
|
|
424
|
+
if (l)
|
|
425
|
+
c = n.body.split(/\\.\\./);
|
|
426
|
+
else if (c = xt(n.body), c.length === 1 && c[0] !== void 0 && (c = M(c[0], !1).map(ae), c.length === 1))
|
|
427
|
+
return r.map((u) => n.pre + c[0] + u);
|
|
335
428
|
let f;
|
|
336
|
-
if (
|
|
337
|
-
const u =
|
|
338
|
-
let p =
|
|
339
|
-
d < u && (p *= -1, S =
|
|
340
|
-
const N =
|
|
429
|
+
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
430
|
+
const u = B(c[0]), d = B(c[1]), m = Math.max(c[0].length, c[1].length);
|
|
431
|
+
let p = c.length === 3 && c[2] !== void 0 ? Math.abs(B(c[2])) : 1, S = le;
|
|
432
|
+
d < u && (p *= -1, S = he);
|
|
433
|
+
const N = c.some(ce);
|
|
341
434
|
f = [];
|
|
342
435
|
for (let x = u; S(x, d); x += p) {
|
|
343
|
-
let
|
|
436
|
+
let w;
|
|
344
437
|
if (a)
|
|
345
|
-
|
|
346
|
-
else if (
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
349
|
-
const
|
|
350
|
-
x < 0 ?
|
|
438
|
+
w = String.fromCharCode(x), w === "\\\\" && (w = "");
|
|
439
|
+
else if (w = String(x), N) {
|
|
440
|
+
const F = m - w.length;
|
|
441
|
+
if (F > 0) {
|
|
442
|
+
const P = new Array(F + 1).join("0");
|
|
443
|
+
x < 0 ? w = "-" + P + w.slice(1) : w = P + w;
|
|
351
444
|
}
|
|
352
445
|
}
|
|
353
|
-
f.push(
|
|
446
|
+
f.push(w);
|
|
354
447
|
}
|
|
355
448
|
} else {
|
|
356
449
|
f = [];
|
|
357
|
-
for (let u = 0; u <
|
|
358
|
-
f.push.apply(f, M(
|
|
450
|
+
for (let u = 0; u < c.length; u++)
|
|
451
|
+
f.push.apply(f, M(c[u], !1));
|
|
359
452
|
}
|
|
360
453
|
for (let u = 0; u < f.length; u++)
|
|
361
454
|
for (let d = 0; d < r.length; d++) {
|
|
362
|
-
const
|
|
363
|
-
(!t ||
|
|
455
|
+
const m = i + f[u] + r[d];
|
|
456
|
+
(!t || l || m) && e.push(m);
|
|
364
457
|
}
|
|
365
458
|
}
|
|
366
459
|
return e;
|
|
367
460
|
}
|
|
368
|
-
const
|
|
461
|
+
const ue = 1024 * 64, W = (s) => {
|
|
369
462
|
if (typeof s != "string")
|
|
370
463
|
throw new TypeError("invalid pattern");
|
|
371
|
-
if (s.length >
|
|
464
|
+
if (s.length > ue)
|
|
372
465
|
throw new TypeError("pattern is too long");
|
|
373
|
-
},
|
|
466
|
+
}, fe = {
|
|
374
467
|
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
375
468
|
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
376
469
|
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
@@ -385,60 +478,60 @@ const ie = 1024 * 64, U = (s) => {
|
|
|
385
478
|
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
386
479
|
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
387
480
|
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
388
|
-
},
|
|
481
|
+
}, T = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), de = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), nt = (s) => s.join(""), pe = (s, t) => {
|
|
389
482
|
const e = t;
|
|
390
483
|
if (s.charAt(e) !== "[")
|
|
391
484
|
throw new Error("not in a brace expression");
|
|
392
485
|
const n = [], i = [];
|
|
393
|
-
let r = e + 1, o = !1, a = !1,
|
|
486
|
+
let r = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
|
|
394
487
|
t: for (; r < s.length; ) {
|
|
395
488
|
const p = s.charAt(r);
|
|
396
489
|
if ((p === "!" || p === "^") && r === e + 1) {
|
|
397
|
-
|
|
490
|
+
h = !0, r++;
|
|
398
491
|
continue;
|
|
399
492
|
}
|
|
400
|
-
if (p === "]" && o && !
|
|
401
|
-
|
|
493
|
+
if (p === "]" && o && !l) {
|
|
494
|
+
c = r + 1;
|
|
402
495
|
break;
|
|
403
496
|
}
|
|
404
|
-
if (o = !0, p === "\\\\" && !
|
|
405
|
-
|
|
497
|
+
if (o = !0, p === "\\\\" && !l) {
|
|
498
|
+
l = !0, r++;
|
|
406
499
|
continue;
|
|
407
500
|
}
|
|
408
|
-
if (p === "[" && !
|
|
409
|
-
for (const [S, [
|
|
501
|
+
if (p === "[" && !l) {
|
|
502
|
+
for (const [S, [v, N, x]] of Object.entries(fe))
|
|
410
503
|
if (s.startsWith(S, r)) {
|
|
411
504
|
if (f)
|
|
412
505
|
return ["$.", !1, s.length - e, !0];
|
|
413
|
-
r += S.length, x ? i.push(
|
|
506
|
+
r += S.length, x ? i.push(v) : n.push(v), a = a || N;
|
|
414
507
|
continue t;
|
|
415
508
|
}
|
|
416
509
|
}
|
|
417
|
-
if (
|
|
418
|
-
p > f ? n.push(
|
|
510
|
+
if (l = !1, f) {
|
|
511
|
+
p > f ? n.push(T(f) + "-" + T(p)) : p === f && n.push(T(p)), f = "", r++;
|
|
419
512
|
continue;
|
|
420
513
|
}
|
|
421
514
|
if (s.startsWith("-]", r + 1)) {
|
|
422
|
-
n.push(
|
|
515
|
+
n.push(T(p + "-")), r += 2;
|
|
423
516
|
continue;
|
|
424
517
|
}
|
|
425
518
|
if (s.startsWith("-", r + 1)) {
|
|
426
519
|
f = p, r += 2;
|
|
427
520
|
continue;
|
|
428
521
|
}
|
|
429
|
-
n.push(
|
|
522
|
+
n.push(T(p)), r++;
|
|
430
523
|
}
|
|
431
|
-
if (
|
|
524
|
+
if (c < r)
|
|
432
525
|
return ["", !1, 0, !1];
|
|
433
526
|
if (!n.length && !i.length)
|
|
434
527
|
return ["$.", !1, s.length - e, !0];
|
|
435
|
-
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !
|
|
528
|
+
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
436
529
|
const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
437
|
-
return [
|
|
530
|
+
return [de(p), !1, c - e, !1];
|
|
438
531
|
}
|
|
439
|
-
const u = "[" + (
|
|
440
|
-
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a,
|
|
441
|
-
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"),
|
|
532
|
+
const u = "[" + (h ? "^" : "") + nt(n) + "]", d = "[" + (h ? "" : "^") + nt(i) + "]";
|
|
533
|
+
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
534
|
+
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), ge = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), it = (s) => ge.has(s), me = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", we = /* @__PURE__ */ new Set(["[", "."]), ye = /* @__PURE__ */ new Set(["..", "."]), Ee = new Set("().*{}+?[]^$\\\\!"), Se = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), K = "[^/]", rt = K + "*?", ot = K + "+?";
|
|
442
535
|
class E {
|
|
443
536
|
type;
|
|
444
537
|
#s;
|
|
@@ -450,7 +543,7 @@ class E {
|
|
|
450
543
|
#c;
|
|
451
544
|
#a = !1;
|
|
452
545
|
#i;
|
|
453
|
-
#
|
|
546
|
+
#l;
|
|
454
547
|
// set to true if it's an extglob with no children
|
|
455
548
|
// (which really means one child of '')
|
|
456
549
|
#u = !1;
|
|
@@ -467,7 +560,7 @@ class E {
|
|
|
467
560
|
}
|
|
468
561
|
// reconstructs the pattern
|
|
469
562
|
toString() {
|
|
470
|
-
return this.#
|
|
563
|
+
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("");
|
|
471
564
|
}
|
|
472
565
|
#d() {
|
|
473
566
|
if (this !== this.#s)
|
|
@@ -538,68 +631,68 @@ class E {
|
|
|
538
631
|
e.copyIn(n);
|
|
539
632
|
return e;
|
|
540
633
|
}
|
|
541
|
-
static #
|
|
542
|
-
let r = !1, o = !1, a = -1,
|
|
634
|
+
static #h(t, e, n, i) {
|
|
635
|
+
let r = !1, o = !1, a = -1, l = !1;
|
|
543
636
|
if (e.type === null) {
|
|
544
|
-
let d = n,
|
|
637
|
+
let d = n, m = "";
|
|
545
638
|
for (; d < t.length; ) {
|
|
546
639
|
const p = t.charAt(d++);
|
|
547
640
|
if (r || p === "\\\\") {
|
|
548
|
-
r = !r,
|
|
641
|
+
r = !r, m += p;
|
|
549
642
|
continue;
|
|
550
643
|
}
|
|
551
644
|
if (o) {
|
|
552
|
-
d === a + 1 ? (p === "^" || p === "!") && (
|
|
645
|
+
d === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (o = !1), m += p;
|
|
553
646
|
continue;
|
|
554
647
|
} else if (p === "[") {
|
|
555
|
-
o = !0, a = d,
|
|
648
|
+
o = !0, a = d, l = !1, m += p;
|
|
556
649
|
continue;
|
|
557
650
|
}
|
|
558
651
|
if (!i.noext && it(p) && t.charAt(d) === "(") {
|
|
559
|
-
e.push(
|
|
652
|
+
e.push(m), m = "";
|
|
560
653
|
const S = new E(p, e);
|
|
561
|
-
d = E.#
|
|
654
|
+
d = E.#h(t, S, d, i), e.push(S);
|
|
562
655
|
continue;
|
|
563
656
|
}
|
|
564
|
-
|
|
657
|
+
m += p;
|
|
565
658
|
}
|
|
566
|
-
return e.push(
|
|
659
|
+
return e.push(m), d;
|
|
567
660
|
}
|
|
568
|
-
let
|
|
661
|
+
let h = n + 1, c = new E(null, e);
|
|
569
662
|
const f = [];
|
|
570
663
|
let u = "";
|
|
571
|
-
for (;
|
|
572
|
-
const d = t.charAt(
|
|
664
|
+
for (; h < t.length; ) {
|
|
665
|
+
const d = t.charAt(h++);
|
|
573
666
|
if (r || d === "\\\\") {
|
|
574
667
|
r = !r, u += d;
|
|
575
668
|
continue;
|
|
576
669
|
}
|
|
577
670
|
if (o) {
|
|
578
|
-
|
|
671
|
+
h === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (o = !1), u += d;
|
|
579
672
|
continue;
|
|
580
673
|
} else if (d === "[") {
|
|
581
|
-
o = !0, a =
|
|
674
|
+
o = !0, a = h, l = !1, u += d;
|
|
582
675
|
continue;
|
|
583
676
|
}
|
|
584
|
-
if (it(d) && t.charAt(
|
|
585
|
-
|
|
586
|
-
const
|
|
587
|
-
|
|
677
|
+
if (it(d) && t.charAt(h) === "(") {
|
|
678
|
+
c.push(u), u = "";
|
|
679
|
+
const m = new E(d, c);
|
|
680
|
+
c.push(m), h = E.#h(t, m, h, i);
|
|
588
681
|
continue;
|
|
589
682
|
}
|
|
590
683
|
if (d === "|") {
|
|
591
|
-
|
|
684
|
+
c.push(u), u = "", f.push(c), c = new E(null, e);
|
|
592
685
|
continue;
|
|
593
686
|
}
|
|
594
687
|
if (d === ")")
|
|
595
|
-
return u === "" && e.#t.length === 0 && (e.#u = !0),
|
|
688
|
+
return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
|
|
596
689
|
u += d;
|
|
597
690
|
}
|
|
598
|
-
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)],
|
|
691
|
+
return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
|
|
599
692
|
}
|
|
600
693
|
static fromGlob(t, e = {}) {
|
|
601
694
|
const n = new E(null, void 0, e);
|
|
602
|
-
return E.#
|
|
695
|
+
return E.#h(t, n, 0, e), n;
|
|
603
696
|
}
|
|
604
697
|
// returns the regular expression if there's magic, or the unescaped
|
|
605
698
|
// string if not.
|
|
@@ -690,24 +783,24 @@ class E {
|
|
|
690
783
|
toRegExpSource(t) {
|
|
691
784
|
const e = t ?? !!this.#i.dot;
|
|
692
785
|
if (this.#s === this && this.#d(), !this.type) {
|
|
693
|
-
const
|
|
694
|
-
const [
|
|
695
|
-
return this.#n = this.#n || S, this.#r = this.#r ||
|
|
786
|
+
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
787
|
+
const [m, p, S, v] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
788
|
+
return this.#n = this.#n || S, this.#r = this.#r || v, m;
|
|
696
789
|
}).join("");
|
|
697
|
-
let
|
|
698
|
-
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 &&
|
|
699
|
-
const
|
|
790
|
+
let c = "";
|
|
791
|
+
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && ye.has(this.#t[0]))) {
|
|
792
|
+
const m = we, p = (
|
|
700
793
|
// dots are allowed, and the pattern starts with [ or .
|
|
701
|
-
e &&
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
), S = !e && !t &&
|
|
705
|
-
|
|
794
|
+
e && m.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
795
|
+
h.startsWith("\\\\.") && m.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
796
|
+
h.startsWith("\\\\.\\\\.") && m.has(h.charAt(4))
|
|
797
|
+
), S = !e && !t && m.has(h.charAt(0));
|
|
798
|
+
c = p ? me : S ? k : "";
|
|
706
799
|
}
|
|
707
800
|
let f = "";
|
|
708
801
|
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
709
|
-
|
|
710
|
-
$(
|
|
802
|
+
c + h + f,
|
|
803
|
+
$(h),
|
|
711
804
|
this.#n = !!this.#n,
|
|
712
805
|
this.#r
|
|
713
806
|
];
|
|
@@ -715,8 +808,8 @@ class E {
|
|
|
715
808
|
const n = this.type === "*" || this.type === "+", i = this.type === "!" ? "(?:(?!(?:" : "(?:";
|
|
716
809
|
let r = this.#f(e);
|
|
717
810
|
if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
|
|
718
|
-
const
|
|
719
|
-
return this.#t = [
|
|
811
|
+
const l = this.toString();
|
|
812
|
+
return this.#t = [l], this.type = null, this.#n = void 0, [l, $(this.toString()), !1, !1];
|
|
720
813
|
}
|
|
721
814
|
let o = !n || t || e || !k ? "" : this.#f(!0);
|
|
722
815
|
o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
|
|
@@ -724,11 +817,11 @@ class E {
|
|
|
724
817
|
if (this.type === "!" && this.#u)
|
|
725
818
|
a = (this.isStart() && !e ? k : "") + ot;
|
|
726
819
|
else {
|
|
727
|
-
const
|
|
820
|
+
const l = this.type === "!" ? (
|
|
728
821
|
// !() must match something,but !(x) can match ''
|
|
729
822
|
"))" + (this.isStart() && !e && !t ? k : "") + rt + ")"
|
|
730
823
|
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
731
|
-
a = i + r +
|
|
824
|
+
a = i + r + l;
|
|
732
825
|
}
|
|
733
826
|
return [
|
|
734
827
|
a,
|
|
@@ -748,63 +841,63 @@ class E {
|
|
|
748
841
|
static #p(t, e, n = !1) {
|
|
749
842
|
let i = !1, r = "", o = !1;
|
|
750
843
|
for (let a = 0; a < t.length; a++) {
|
|
751
|
-
const
|
|
844
|
+
const l = t.charAt(a);
|
|
752
845
|
if (i) {
|
|
753
|
-
i = !1, r += (
|
|
846
|
+
i = !1, r += (Ee.has(l) ? "\\\\" : "") + l;
|
|
754
847
|
continue;
|
|
755
848
|
}
|
|
756
|
-
if (
|
|
849
|
+
if (l === "\\\\") {
|
|
757
850
|
a === t.length - 1 ? r += "\\\\\\\\" : i = !0;
|
|
758
851
|
continue;
|
|
759
852
|
}
|
|
760
|
-
if (
|
|
761
|
-
const [
|
|
853
|
+
if (l === "[") {
|
|
854
|
+
const [h, c, f, u] = pe(t, a);
|
|
762
855
|
if (f) {
|
|
763
|
-
r +=
|
|
856
|
+
r += h, o = o || c, a += f - 1, e = e || u;
|
|
764
857
|
continue;
|
|
765
858
|
}
|
|
766
859
|
}
|
|
767
|
-
if (
|
|
860
|
+
if (l === "*") {
|
|
768
861
|
n && t === "*" ? r += ot : r += rt, e = !0;
|
|
769
862
|
continue;
|
|
770
863
|
}
|
|
771
|
-
if (
|
|
772
|
-
r +=
|
|
864
|
+
if (l === "?") {
|
|
865
|
+
r += K, e = !0;
|
|
773
866
|
continue;
|
|
774
867
|
}
|
|
775
|
-
r +=
|
|
868
|
+
r += Se(l);
|
|
776
869
|
}
|
|
777
870
|
return [r, $(t), !!e, o];
|
|
778
871
|
}
|
|
779
872
|
}
|
|
780
|
-
const
|
|
781
|
-
const e =
|
|
873
|
+
const xe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (W(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new j(t, e).match(s)), be = /^\\*+([^+@!?\\*\\[\\(]*)$/, Ae = (s) => (t) => !t.startsWith(".") && t.endsWith(s), ve = (s) => (t) => t.endsWith(s), Ce = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), De = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Oe = /^\\*+\\.\\*+$/, Ne = (s) => !s.startsWith(".") && s.includes("."), Fe = (s) => s !== "." && s !== ".." && s.includes("."), Te = /^\\.\\*+$/, Me = (s) => s !== "." && s !== ".." && s.startsWith("."), $e = /^\\*+$/, Pe = (s) => s.length !== 0 && !s.startsWith("."), Re = (s) => s.length !== 0 && s !== "." && s !== "..", ke = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Le = ([s, t = ""]) => {
|
|
874
|
+
const e = bt([s]);
|
|
782
875
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
783
|
-
},
|
|
784
|
-
const e =
|
|
876
|
+
}, Ie = ([s, t = ""]) => {
|
|
877
|
+
const e = At([s]);
|
|
785
878
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
786
|
-
},
|
|
787
|
-
const e = Dt([s]);
|
|
788
|
-
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
789
|
-
}, Me = ([s, t = ""]) => {
|
|
879
|
+
}, ze = ([s, t = ""]) => {
|
|
790
880
|
const e = At([s]);
|
|
791
881
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
792
|
-
},
|
|
882
|
+
}, He = ([s, t = ""]) => {
|
|
883
|
+
const e = bt([s]);
|
|
884
|
+
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
885
|
+
}, bt = ([s]) => {
|
|
793
886
|
const t = s.length;
|
|
794
887
|
return (e) => e.length === t && !e.startsWith(".");
|
|
795
|
-
},
|
|
888
|
+
}, At = ([s]) => {
|
|
796
889
|
const t = s.length;
|
|
797
890
|
return (e) => e.length === t && e !== "." && e !== "..";
|
|
798
|
-
},
|
|
891
|
+
}, vt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", at = {
|
|
799
892
|
win32: { sep: "\\\\" },
|
|
800
893
|
posix: { sep: "/" }
|
|
801
|
-
},
|
|
802
|
-
y.sep =
|
|
894
|
+
}, We = vt === "win32" ? at.win32.sep : at.posix.sep;
|
|
895
|
+
y.sep = We;
|
|
803
896
|
const A = Symbol("globstar **");
|
|
804
897
|
y.GLOBSTAR = A;
|
|
805
|
-
const
|
|
806
|
-
y.filter =
|
|
807
|
-
const b = (s, t = {}) => Object.assign({}, s, t),
|
|
898
|
+
const je = "[^/]", Ue = je + "*?", _e = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Be = "(?:(?!(?:\\\\/|^)\\\\.).)*?", Ge = (s, t = {}) => (e) => y(e, s, t);
|
|
899
|
+
y.filter = Ge;
|
|
900
|
+
const b = (s, t = {}) => Object.assign({}, s, t), qe = (s) => {
|
|
808
901
|
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
809
902
|
return y;
|
|
810
903
|
const t = y;
|
|
@@ -838,18 +931,18 @@ const b = (s, t = {}) => Object.assign({}, s, t), We = (s) => {
|
|
|
838
931
|
GLOBSTAR: A
|
|
839
932
|
});
|
|
840
933
|
};
|
|
841
|
-
y.defaults =
|
|
842
|
-
const
|
|
843
|
-
y.braceExpand =
|
|
844
|
-
const
|
|
845
|
-
y.makeRe =
|
|
846
|
-
const
|
|
847
|
-
const n = new
|
|
934
|
+
y.defaults = qe;
|
|
935
|
+
const Ct = (s, t = {}) => (W(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : oe(s));
|
|
936
|
+
y.braceExpand = Ct;
|
|
937
|
+
const Ve = (s, t = {}) => new j(s, t).makeRe();
|
|
938
|
+
y.makeRe = Ve;
|
|
939
|
+
const Ze = (s, t, e = {}) => {
|
|
940
|
+
const n = new j(t, e);
|
|
848
941
|
return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
|
|
849
942
|
};
|
|
850
|
-
y.match =
|
|
851
|
-
const ct = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/,
|
|
852
|
-
class
|
|
943
|
+
y.match = Ze;
|
|
944
|
+
const ct = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Xe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
945
|
+
class j {
|
|
853
946
|
options;
|
|
854
947
|
set;
|
|
855
948
|
pattern;
|
|
@@ -868,7 +961,7 @@ class _ {
|
|
|
868
961
|
windowsNoMagicRoot;
|
|
869
962
|
regexp;
|
|
870
963
|
constructor(t, e = {}) {
|
|
871
|
-
|
|
964
|
+
W(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || vt, 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();
|
|
872
965
|
}
|
|
873
966
|
hasMagic() {
|
|
874
967
|
if (this.options.magicalBraces && this.set.length > 1)
|
|
@@ -896,13 +989,13 @@ class _ {
|
|
|
896
989
|
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
897
990
|
let i = this.globParts.map((r, o, a) => {
|
|
898
991
|
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
899
|
-
const
|
|
900
|
-
if (c)
|
|
901
|
-
return [...r.slice(0, 4), ...r.slice(4).map((h) => this.parse(h))];
|
|
992
|
+
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !ct.test(r[2])) && !ct.test(r[3]), h = /^[a-z]:/i.test(r[0]);
|
|
902
993
|
if (l)
|
|
903
|
-
return [r
|
|
994
|
+
return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
|
|
995
|
+
if (h)
|
|
996
|
+
return [r[0], ...r.slice(1).map((c) => this.parse(c))];
|
|
904
997
|
}
|
|
905
|
-
return r.map((
|
|
998
|
+
return r.map((l) => this.parse(l));
|
|
906
999
|
});
|
|
907
1000
|
if (this.debug(this.pattern, i), this.set = i.filter((r) => r.indexOf(!1) === -1), this.isWindows)
|
|
908
1001
|
for (let r = 0; r < this.set.length; r++) {
|
|
@@ -993,12 +1086,12 @@ class _ {
|
|
|
993
1086
|
o++;
|
|
994
1087
|
o > i && n.splice(i + 1, o - i);
|
|
995
1088
|
let a = n[i + 1];
|
|
996
|
-
const
|
|
997
|
-
if (a !== ".." || !
|
|
1089
|
+
const l = n[i + 2], h = n[i + 3];
|
|
1090
|
+
if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
|
|
998
1091
|
continue;
|
|
999
1092
|
e = !0, n.splice(i, 1);
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1093
|
+
const c = n.slice(0);
|
|
1094
|
+
c[i] = "**", t.push(c), i--;
|
|
1002
1095
|
}
|
|
1003
1096
|
if (!this.preserveMultipleSlashes) {
|
|
1004
1097
|
for (let o = 1; o < n.length - 1; o++) {
|
|
@@ -1012,8 +1105,8 @@ class _ {
|
|
|
1012
1105
|
const o = n[r - 1];
|
|
1013
1106
|
if (o && o !== "." && o !== ".." && o !== "**") {
|
|
1014
1107
|
e = !0;
|
|
1015
|
-
const
|
|
1016
|
-
n.splice(r - 1, 2, ...
|
|
1108
|
+
const l = r === 1 && n[r + 1] === "**" ? ["."] : [];
|
|
1109
|
+
n.splice(r - 1, 2, ...l), n.length === 0 && n.push(""), r -= 2;
|
|
1017
1110
|
}
|
|
1018
1111
|
}
|
|
1019
1112
|
}
|
|
@@ -1076,66 +1169,66 @@ class _ {
|
|
|
1076
1169
|
matchOne(t, e, n = !1) {
|
|
1077
1170
|
const i = this.options;
|
|
1078
1171
|
if (this.isWindows) {
|
|
1079
|
-
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]),
|
|
1080
|
-
if (typeof x == "number" && typeof
|
|
1081
|
-
const [
|
|
1082
|
-
|
|
1172
|
+
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]), N = !v && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, w = N ? 3 : v ? 0 : void 0;
|
|
1173
|
+
if (typeof x == "number" && typeof w == "number") {
|
|
1174
|
+
const [F, P] = [t[x], e[w]];
|
|
1175
|
+
F.toLowerCase() === P.toLowerCase() && (e[w] = F, w > x ? e = e.slice(w) : x > w && (t = t.slice(x)));
|
|
1083
1176
|
}
|
|
1084
1177
|
}
|
|
1085
1178
|
const { optimizationLevel: r = 1 } = this.options;
|
|
1086
1179
|
r >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
|
|
1087
|
-
for (var o = 0, a = 0,
|
|
1180
|
+
for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
|
|
1088
1181
|
this.debug("matchOne loop");
|
|
1089
|
-
var
|
|
1090
|
-
if (this.debug(e,
|
|
1182
|
+
var c = e[a], f = t[o];
|
|
1183
|
+
if (this.debug(e, c, f), c === !1)
|
|
1091
1184
|
return !1;
|
|
1092
|
-
if (
|
|
1093
|
-
this.debug("GLOBSTAR", [e,
|
|
1185
|
+
if (c === A) {
|
|
1186
|
+
this.debug("GLOBSTAR", [e, c, f]);
|
|
1094
1187
|
var u = o, d = a + 1;
|
|
1095
|
-
if (d ===
|
|
1096
|
-
for (this.debug("** at the end"); o <
|
|
1188
|
+
if (d === h) {
|
|
1189
|
+
for (this.debug("** at the end"); o < l; o++)
|
|
1097
1190
|
if (t[o] === "." || t[o] === ".." || !i.dot && t[o].charAt(0) === ".")
|
|
1098
1191
|
return !1;
|
|
1099
1192
|
return !0;
|
|
1100
1193
|
}
|
|
1101
|
-
for (; u <
|
|
1102
|
-
var
|
|
1194
|
+
for (; u < l; ) {
|
|
1195
|
+
var m = t[u];
|
|
1103
1196
|
if (this.debug(\`
|
|
1104
|
-
globstar while\`, t, u, e, d,
|
|
1105
|
-
return this.debug("globstar found match!", u,
|
|
1106
|
-
if (
|
|
1197
|
+
globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
1198
|
+
return this.debug("globstar found match!", u, l, m), !0;
|
|
1199
|
+
if (m === "." || m === ".." || !i.dot && m.charAt(0) === ".") {
|
|
1107
1200
|
this.debug("dot detected!", t, u, e, d);
|
|
1108
1201
|
break;
|
|
1109
1202
|
}
|
|
1110
1203
|
this.debug("globstar swallow a segment, and continue"), u++;
|
|
1111
1204
|
}
|
|
1112
1205
|
return !!(n && (this.debug(\`
|
|
1113
|
-
>>> no match, partial?\`, t, u, e, d), u ===
|
|
1206
|
+
>>> no match, partial?\`, t, u, e, d), u === l));
|
|
1114
1207
|
}
|
|
1115
1208
|
let p;
|
|
1116
|
-
if (typeof
|
|
1209
|
+
if (typeof c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, f, p)), !p)
|
|
1117
1210
|
return !1;
|
|
1118
1211
|
}
|
|
1119
|
-
if (o ===
|
|
1212
|
+
if (o === l && a === h)
|
|
1120
1213
|
return !0;
|
|
1121
|
-
if (o ===
|
|
1214
|
+
if (o === l)
|
|
1122
1215
|
return n;
|
|
1123
|
-
if (a ===
|
|
1124
|
-
return o ===
|
|
1216
|
+
if (a === h)
|
|
1217
|
+
return o === l - 1 && t[o] === "";
|
|
1125
1218
|
throw new Error("wtf?");
|
|
1126
1219
|
}
|
|
1127
1220
|
braceExpand() {
|
|
1128
|
-
return
|
|
1221
|
+
return Ct(this.pattern, this.options);
|
|
1129
1222
|
}
|
|
1130
1223
|
parse(t) {
|
|
1131
|
-
|
|
1224
|
+
W(t);
|
|
1132
1225
|
const e = this.options;
|
|
1133
1226
|
if (t === "**")
|
|
1134
1227
|
return A;
|
|
1135
1228
|
if (t === "")
|
|
1136
1229
|
return "";
|
|
1137
1230
|
let n, i = null;
|
|
1138
|
-
(n = t.match(
|
|
1231
|
+
(n = t.match($e)) ? i = e.dot ? Re : Pe : (n = t.match(be)) ? i = (e.nocase ? e.dot ? De : Ce : e.dot ? ve : Ae)(n[1]) : (n = t.match(ke)) ? i = (e.nocase ? e.dot ? Ie : Le : e.dot ? ze : He)(n) : (n = t.match(Oe)) ? i = e.dot ? Fe : Ne : (n = t.match(Te)) && (i = Me);
|
|
1139
1232
|
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1140
1233
|
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1141
1234
|
}
|
|
@@ -1145,18 +1238,18 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1145
1238
|
const t = this.set;
|
|
1146
1239
|
if (!t.length)
|
|
1147
1240
|
return this.regexp = !1, this.regexp;
|
|
1148
|
-
const e = this.options, n = e.noglobstar ?
|
|
1149
|
-
let r = t.map((
|
|
1150
|
-
const
|
|
1151
|
-
if (
|
|
1152
|
-
for (const f of
|
|
1241
|
+
const e = this.options, n = e.noglobstar ? Ue : e.dot ? _e : Be, i = new Set(e.nocase ? ["i"] : []);
|
|
1242
|
+
let r = t.map((l) => {
|
|
1243
|
+
const h = l.map((c) => {
|
|
1244
|
+
if (c instanceof RegExp)
|
|
1245
|
+
for (const f of c.flags.split(""))
|
|
1153
1246
|
i.add(f);
|
|
1154
|
-
return typeof
|
|
1247
|
+
return typeof c == "string" ? Xe(c) : c === A ? A : c._src;
|
|
1155
1248
|
});
|
|
1156
|
-
return
|
|
1157
|
-
const u =
|
|
1158
|
-
|
|
1159
|
-
}),
|
|
1249
|
+
return h.forEach((c, f) => {
|
|
1250
|
+
const u = h[f + 1], d = h[f - 1];
|
|
1251
|
+
c !== A || d === A || (d === void 0 ? u !== void 0 && u !== A ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== A && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = A));
|
|
1252
|
+
}), h.filter((c) => c !== A).join("/");
|
|
1160
1253
|
}).join("|");
|
|
1161
1254
|
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1162
1255
|
r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
|
|
@@ -1188,9 +1281,9 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1188
1281
|
for (let a = i.length - 2; !o && a >= 0; a--)
|
|
1189
1282
|
o = i[a];
|
|
1190
1283
|
for (let a = 0; a < r.length; a++) {
|
|
1191
|
-
const
|
|
1192
|
-
let
|
|
1193
|
-
if (n.matchBase &&
|
|
1284
|
+
const l = r[a];
|
|
1285
|
+
let h = i;
|
|
1286
|
+
if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
|
|
1194
1287
|
return n.flipNegate ? !0 : !this.negate;
|
|
1195
1288
|
}
|
|
1196
1289
|
return n.flipNegate ? !1 : this.negate;
|
|
@@ -1200,136 +1293,44 @@ globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1200
1293
|
}
|
|
1201
1294
|
}
|
|
1202
1295
|
y.AST = E;
|
|
1203
|
-
y.Minimatch =
|
|
1204
|
-
y.escape =
|
|
1296
|
+
y.Minimatch = j;
|
|
1297
|
+
y.escape = xe;
|
|
1205
1298
|
y.unescape = $;
|
|
1206
|
-
class g extends Error {
|
|
1207
|
-
constructor(t, e, n) {
|
|
1208
|
-
super(t), this.code = e, this.path = n, this.name = "OPFSError";
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
class _e extends g {
|
|
1212
|
-
constructor() {
|
|
1213
|
-
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
class q extends g {
|
|
1217
|
-
constructor() {
|
|
1218
|
-
super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
class ht extends g {
|
|
1222
|
-
constructor(t, e) {
|
|
1223
|
-
super(t, "INVALID_PATH", e);
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
class V extends g {
|
|
1227
|
-
constructor(t) {
|
|
1228
|
-
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
function Be(s, t = "utf-8") {
|
|
1232
|
-
switch (t) {
|
|
1233
|
-
case "utf8":
|
|
1234
|
-
case "utf-8":
|
|
1235
|
-
return new TextEncoder().encode(s);
|
|
1236
|
-
case "utf16le":
|
|
1237
|
-
case "ucs2":
|
|
1238
|
-
case "ucs-2":
|
|
1239
|
-
return qe(s);
|
|
1240
|
-
case "ascii":
|
|
1241
|
-
return Xe(s);
|
|
1242
|
-
case "latin1":
|
|
1243
|
-
return Ze(s);
|
|
1244
|
-
case "binary":
|
|
1245
|
-
return Uint8Array.from(s, (e) => e.charCodeAt(0));
|
|
1246
|
-
case "base64":
|
|
1247
|
-
return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
|
|
1248
|
-
case "hex":
|
|
1249
|
-
if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
|
|
1250
|
-
throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
1251
|
-
return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
|
|
1252
|
-
default:
|
|
1253
|
-
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
function Ge(s, t = "utf-8") {
|
|
1257
|
-
switch (t) {
|
|
1258
|
-
case "utf8":
|
|
1259
|
-
case "utf-8":
|
|
1260
|
-
return new TextDecoder().decode(s);
|
|
1261
|
-
case "utf16le":
|
|
1262
|
-
case "ucs2":
|
|
1263
|
-
case "ucs-2":
|
|
1264
|
-
return Ve(s);
|
|
1265
|
-
case "latin1":
|
|
1266
|
-
return String.fromCharCode(...s);
|
|
1267
|
-
case "binary":
|
|
1268
|
-
return String.fromCharCode(...s);
|
|
1269
|
-
case "ascii":
|
|
1270
|
-
return String.fromCharCode(...s.map((e) => e & 127));
|
|
1271
|
-
case "base64":
|
|
1272
|
-
return btoa(String.fromCharCode(...s));
|
|
1273
|
-
case "hex":
|
|
1274
|
-
return Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
1275
|
-
default:
|
|
1276
|
-
return console.warn("Unsupported encoding, falling back to UTF-8"), new TextDecoder().decode(s);
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
function qe(s) {
|
|
1280
|
-
const t = new Uint8Array(s.length * 2);
|
|
1281
|
-
for (let e = 0; e < s.length; e++) {
|
|
1282
|
-
const n = s.charCodeAt(e);
|
|
1283
|
-
t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
|
|
1284
|
-
}
|
|
1285
|
-
return t;
|
|
1286
|
-
}
|
|
1287
|
-
function Ve(s) {
|
|
1288
|
-
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
1289
|
-
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
1290
|
-
return String.fromCharCode(...t);
|
|
1291
|
-
}
|
|
1292
|
-
function Ze(s) {
|
|
1293
|
-
const t = new Uint8Array(s.length);
|
|
1294
|
-
for (let e = 0; e < s.length; e++)
|
|
1295
|
-
t[e] = s.charCodeAt(e) & 255;
|
|
1296
|
-
return t;
|
|
1297
|
-
}
|
|
1298
|
-
function Xe(s) {
|
|
1299
|
-
const t = new Uint8Array(s.length);
|
|
1300
|
-
for (let e = 0; e < s.length; e++)
|
|
1301
|
-
t[e] = s.charCodeAt(e) & 127;
|
|
1302
|
-
return t;
|
|
1303
|
-
}
|
|
1304
1299
|
function Ye() {
|
|
1305
1300
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
1306
|
-
throw new
|
|
1301
|
+
throw new Ht();
|
|
1302
|
+
}
|
|
1303
|
+
async function Q(s, t, e) {
|
|
1304
|
+
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/").toLowerCase()}\`, { mode: t }, e) : e();
|
|
1307
1305
|
}
|
|
1308
|
-
function
|
|
1306
|
+
function O(s) {
|
|
1309
1307
|
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
1310
1308
|
}
|
|
1311
1309
|
function tt(s) {
|
|
1312
1310
|
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
1313
1311
|
}
|
|
1314
1312
|
function Z(s) {
|
|
1315
|
-
const t =
|
|
1313
|
+
const t = O(s);
|
|
1316
1314
|
return t[t.length - 1] || "";
|
|
1317
1315
|
}
|
|
1318
|
-
function
|
|
1319
|
-
const t =
|
|
1316
|
+
function G(s) {
|
|
1317
|
+
const t = O(s);
|
|
1320
1318
|
return t.pop(), tt(t);
|
|
1321
1319
|
}
|
|
1322
|
-
function
|
|
1320
|
+
function X(s) {
|
|
1323
1321
|
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
1324
1322
|
}
|
|
1325
|
-
function
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
return
|
|
1323
|
+
function Je(s, t = !1) {
|
|
1324
|
+
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
1325
|
+
}
|
|
1326
|
+
function q(s, t) {
|
|
1327
|
+
return y(s, t, {
|
|
1328
|
+
dot: !0,
|
|
1329
|
+
matchBase: !0
|
|
1330
|
+
});
|
|
1330
1331
|
}
|
|
1331
|
-
function
|
|
1332
|
-
const t =
|
|
1332
|
+
function Ke(s) {
|
|
1333
|
+
const t = X(s), e = O(t), n = [];
|
|
1333
1334
|
for (const i of e)
|
|
1334
1335
|
if (!(i === "." || i === ""))
|
|
1335
1336
|
if (i === "..") {
|
|
@@ -1340,55 +1341,65 @@ function Je(s) {
|
|
|
1340
1341
|
n.push(i);
|
|
1341
1342
|
return tt(n);
|
|
1342
1343
|
}
|
|
1343
|
-
function
|
|
1344
|
-
return typeof s == "string" ?
|
|
1344
|
+
function Qe(s, t = "utf-8") {
|
|
1345
|
+
return typeof s == "string" ? jt(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
1345
1346
|
}
|
|
1346
|
-
async function
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
} finally {
|
|
1352
|
-
t.close();
|
|
1353
|
-
}
|
|
1347
|
+
async function ts(s, t) {
|
|
1348
|
+
return Q(t, "shared", async () => {
|
|
1349
|
+
const n = await (await s.getFile()).arrayBuffer();
|
|
1350
|
+
return new Uint8Array(n);
|
|
1351
|
+
});
|
|
1354
1352
|
}
|
|
1355
|
-
async function lt(s, t, e, n = {}) {
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1353
|
+
async function lt(s, t, e, n = {}, i) {
|
|
1354
|
+
const r = async () => {
|
|
1355
|
+
let o = null;
|
|
1356
|
+
const a = n.append || !1, l = !a && (n.truncate ?? !0);
|
|
1357
|
+
try {
|
|
1358
|
+
o = await s.createSyncAccessHandle();
|
|
1359
|
+
const h = Qe(t, e), c = a ? o.getSize() : 0;
|
|
1360
|
+
o.write(h, { at: c }), l && o.truncate(h.byteLength), o.flush();
|
|
1361
|
+
} catch (h) {
|
|
1362
|
+
console.error(h);
|
|
1363
|
+
const c = a ? "append" : "write";
|
|
1364
|
+
throw new g(\`Failed to \${c} file\`, \`\${c.toUpperCase()}_FAILED\`, void 0, h);
|
|
1365
|
+
} finally {
|
|
1367
1366
|
try {
|
|
1368
|
-
|
|
1367
|
+
o?.close();
|
|
1369
1368
|
} catch {
|
|
1370
1369
|
}
|
|
1371
|
-
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
return i ? Q(i, "exclusive", r) : r();
|
|
1372
1373
|
}
|
|
1373
|
-
async function
|
|
1374
|
+
async function es(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1374
1375
|
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1375
1376
|
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1376
1377
|
const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
|
|
1377
1378
|
return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1378
1379
|
}
|
|
1379
|
-
async function
|
|
1380
|
+
async function ss(s) {
|
|
1380
1381
|
const t = await s.arrayBuffer();
|
|
1381
1382
|
return new Uint8Array(t);
|
|
1382
1383
|
}
|
|
1383
|
-
|
|
1384
|
+
async function ns(s, t, e = {}) {
|
|
1385
|
+
const n = Z(t);
|
|
1386
|
+
return Q(t, "exclusive", async () => {
|
|
1387
|
+
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1388
|
+
try {
|
|
1389
|
+
await s.removeEntry(n, { recursive: i });
|
|
1390
|
+
} catch (o) {
|
|
1391
|
+
if (o.name === "NotFoundError") {
|
|
1392
|
+
if (!r)
|
|
1393
|
+
throw new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, o);
|
|
1394
|
+
} else throw o.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !i ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR", void 0, o) : new g(\`Failed to remove entry: \${t}\`, "RM_FAILED", void 0, o);
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
class is {
|
|
1384
1399
|
/** Root directory handle for the file system */
|
|
1385
1400
|
root = null;
|
|
1386
|
-
/** Map of watched paths
|
|
1401
|
+
/** Map of watched paths and options */
|
|
1387
1402
|
watchers = /* @__PURE__ */ new Map();
|
|
1388
|
-
/** Interval handle for polling watched paths */
|
|
1389
|
-
watchTimer = null;
|
|
1390
|
-
/** Flag to avoid concurrent scans */
|
|
1391
|
-
scanning = !1;
|
|
1392
1403
|
/** Promise to prevent concurrent mount operations */
|
|
1393
1404
|
mountingPromise = null;
|
|
1394
1405
|
/** BroadcastChannel instance for sending events */
|
|
@@ -1396,7 +1407,7 @@ class ss {
|
|
|
1396
1407
|
/** Configuration options */
|
|
1397
1408
|
options = {
|
|
1398
1409
|
root: "/",
|
|
1399
|
-
|
|
1410
|
+
namespace: "",
|
|
1400
1411
|
maxFileSize: 50 * 1024 * 1024,
|
|
1401
1412
|
hashAlgorithm: null,
|
|
1402
1413
|
broadcastChannel: "opfs-worker"
|
|
@@ -1413,25 +1424,26 @@ class ss {
|
|
|
1413
1424
|
async notifyChange(t) {
|
|
1414
1425
|
if (!this.options.broadcastChannel)
|
|
1415
1426
|
return;
|
|
1416
|
-
|
|
1417
|
-
if (this.
|
|
1427
|
+
const e = t.path;
|
|
1428
|
+
if (![...this.watchers.values()].some((r) => q(e, r.pattern) && r.include.some((o) => o && q(e, o)) && !r.exclude.some((o) => o && q(e, o))))
|
|
1429
|
+
return;
|
|
1430
|
+
let i;
|
|
1431
|
+
if (this.options.hashAlgorithm)
|
|
1418
1432
|
try {
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
} catch (n) {
|
|
1422
|
-
console.warn(\`Failed to calculate hash for \${t.path}:\`, n);
|
|
1433
|
+
i = (await this.stat(e)).hash;
|
|
1434
|
+
} catch {
|
|
1423
1435
|
}
|
|
1424
1436
|
try {
|
|
1425
1437
|
this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1438
|
+
const r = {
|
|
1439
|
+
namespace: this.options.namespace,
|
|
1428
1440
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1429
1441
|
...t,
|
|
1430
|
-
...
|
|
1442
|
+
...i && { hash: i }
|
|
1431
1443
|
};
|
|
1432
|
-
this.broadcastChannel.postMessage(
|
|
1433
|
-
} catch (
|
|
1434
|
-
console.warn("Failed to send event via BroadcastChannel:",
|
|
1444
|
+
this.broadcastChannel.postMessage(r);
|
|
1445
|
+
} catch (r) {
|
|
1446
|
+
console.warn("Failed to send event via BroadcastChannel:", r);
|
|
1435
1447
|
}
|
|
1436
1448
|
}
|
|
1437
1449
|
/**
|
|
@@ -1469,13 +1481,12 @@ class ss {
|
|
|
1469
1481
|
* \`\`\`
|
|
1470
1482
|
*/
|
|
1471
1483
|
async mount(t = this.options.root) {
|
|
1472
|
-
return this.mountingPromise && await this.mountingPromise, t =
|
|
1473
|
-
this.root = null;
|
|
1484
|
+
return this.mountingPromise && await this.mountingPromise, t = X(t), this.mountingPromise = new Promise(async (e, n) => {
|
|
1474
1485
|
try {
|
|
1475
1486
|
const i = await navigator.storage.getDirectory();
|
|
1476
1487
|
t === "/" ? this.root = i : this.root = await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1477
|
-
} catch
|
|
1478
|
-
|
|
1488
|
+
} catch {
|
|
1489
|
+
n(new g("Failed to initialize OPFS", "INIT_FAILED"));
|
|
1479
1490
|
} finally {
|
|
1480
1491
|
this.mountingPromise = null;
|
|
1481
1492
|
}
|
|
@@ -1492,7 +1503,7 @@ class ss {
|
|
|
1492
1503
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1493
1504
|
*/
|
|
1494
1505
|
async setOptions(t) {
|
|
1495
|
-
t.
|
|
1506
|
+
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 = t.root, this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount(this.options.root));
|
|
1496
1507
|
}
|
|
1497
1508
|
/**
|
|
1498
1509
|
* Get a directory handle from a path
|
|
@@ -1513,9 +1524,7 @@ class ss {
|
|
|
1513
1524
|
* \`\`\`
|
|
1514
1525
|
*/
|
|
1515
1526
|
async getDirectoryHandle(t, e = !1, n = this.root) {
|
|
1516
|
-
|
|
1517
|
-
throw new q();
|
|
1518
|
-
const i = Array.isArray(t) ? t : F(t);
|
|
1527
|
+
const i = Array.isArray(t) ? t : O(t);
|
|
1519
1528
|
let r = n;
|
|
1520
1529
|
for (const o of i)
|
|
1521
1530
|
r = await r.getDirectoryHandle(o, { create: e });
|
|
@@ -1541,11 +1550,9 @@ class ss {
|
|
|
1541
1550
|
* \`\`\`
|
|
1542
1551
|
*/
|
|
1543
1552
|
async getFileHandle(t, e = !1, n = this.root) {
|
|
1544
|
-
|
|
1545
|
-
throw new q();
|
|
1546
|
-
const i = F(t);
|
|
1553
|
+
const i = O(t);
|
|
1547
1554
|
if (i.length === 0)
|
|
1548
|
-
throw new
|
|
1555
|
+
throw new Wt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1549
1556
|
const r = i.pop();
|
|
1550
1557
|
return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
|
|
1551
1558
|
}
|
|
@@ -1593,10 +1600,10 @@ class ss {
|
|
|
1593
1600
|
async readFile(t, e = "utf-8") {
|
|
1594
1601
|
await this.mount();
|
|
1595
1602
|
try {
|
|
1596
|
-
const n = await this.getFileHandle(t, !1), i = await
|
|
1597
|
-
return e === "binary" ? i :
|
|
1603
|
+
const n = await this.getFileHandle(t, !1), i = await ts(n, t);
|
|
1604
|
+
return e === "binary" ? i : Ut(i, e);
|
|
1598
1605
|
} catch (n) {
|
|
1599
|
-
throw
|
|
1606
|
+
throw new _(t, n);
|
|
1600
1607
|
}
|
|
1601
1608
|
}
|
|
1602
1609
|
/**
|
|
@@ -1626,8 +1633,8 @@ class ss {
|
|
|
1626
1633
|
*/
|
|
1627
1634
|
async writeFile(t, e, n) {
|
|
1628
1635
|
await this.mount();
|
|
1629
|
-
const i = await this.getFileHandle(t, !0);
|
|
1630
|
-
await lt(
|
|
1636
|
+
const i = await this.exists(t), r = await this.getFileHandle(t, !0);
|
|
1637
|
+
await lt(r, e, n, {}, t), i ? await this.notifyChange({ path: t, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: t, type: "added", isDirectory: !1 });
|
|
1631
1638
|
}
|
|
1632
1639
|
/**
|
|
1633
1640
|
* Append data to a file
|
|
@@ -1654,7 +1661,7 @@ class ss {
|
|
|
1654
1661
|
async appendFile(t, e, n) {
|
|
1655
1662
|
await this.mount();
|
|
1656
1663
|
const i = await this.getFileHandle(t, !0);
|
|
1657
|
-
await lt(i, e, n, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
1664
|
+
await lt(i, e, n, { append: !0 }, t), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
1658
1665
|
}
|
|
1659
1666
|
/**
|
|
1660
1667
|
* Create a directory
|
|
@@ -1678,19 +1685,20 @@ class ss {
|
|
|
1678
1685
|
* \`\`\`
|
|
1679
1686
|
*/
|
|
1680
1687
|
async mkdir(t, e) {
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
const n = e?.recursive ?? !1, i = F(t);
|
|
1688
|
+
await this.mount();
|
|
1689
|
+
const n = e?.recursive ?? !1, i = O(t);
|
|
1684
1690
|
let r = this.root;
|
|
1685
1691
|
for (let o = 0; o < i.length; o++) {
|
|
1686
1692
|
const a = i[o];
|
|
1687
1693
|
try {
|
|
1688
1694
|
r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
|
|
1689
|
-
} catch (
|
|
1690
|
-
throw
|
|
1695
|
+
} catch (l) {
|
|
1696
|
+
throw l.name === "NotFoundError" ? new g(
|
|
1691
1697
|
\`Parent directory does not exist: \${tt(i.slice(0, o + 1))}\`,
|
|
1692
|
-
"ENOENT"
|
|
1693
|
-
|
|
1698
|
+
"ENOENT",
|
|
1699
|
+
void 0,
|
|
1700
|
+
l
|
|
1701
|
+
) : l.name === "TypeMismatchError" ? new g(\`Path segment is not a directory: \${a}\`, "ENOTDIR", void 0, l) : new g("Failed to create directory", "MKDIR_FAILED", void 0, l);
|
|
1694
1702
|
}
|
|
1695
1703
|
}
|
|
1696
1704
|
await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
|
|
@@ -1727,7 +1735,7 @@ class ss {
|
|
|
1727
1735
|
isFile: !1,
|
|
1728
1736
|
isDirectory: !0
|
|
1729
1737
|
};
|
|
1730
|
-
const e = Z(t), n = await this.getDirectoryHandle(
|
|
1738
|
+
const e = Z(t), n = await this.getDirectoryHandle(G(t), !1), i = this.options.hashAlgorithm !== null;
|
|
1731
1739
|
try {
|
|
1732
1740
|
const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
1733
1741
|
kind: "file",
|
|
@@ -1739,15 +1747,15 @@ class ss {
|
|
|
1739
1747
|
};
|
|
1740
1748
|
if (i && this.options.hashAlgorithm)
|
|
1741
1749
|
try {
|
|
1742
|
-
const
|
|
1743
|
-
a.hash =
|
|
1744
|
-
} catch (
|
|
1745
|
-
console.warn(\`Failed to calculate hash for \${t}:\`,
|
|
1750
|
+
const l = await es(o, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
1751
|
+
a.hash = l;
|
|
1752
|
+
} catch (l) {
|
|
1753
|
+
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
1746
1754
|
}
|
|
1747
1755
|
return a;
|
|
1748
1756
|
} catch (r) {
|
|
1749
1757
|
if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
|
|
1750
|
-
throw new g("Failed to stat (file)", "STAT_FAILED");
|
|
1758
|
+
throw new g("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
1751
1759
|
}
|
|
1752
1760
|
try {
|
|
1753
1761
|
return await n.getDirectoryHandle(e, { create: !1 }), {
|
|
@@ -1759,7 +1767,7 @@ class ss {
|
|
|
1759
1767
|
isDirectory: !0
|
|
1760
1768
|
};
|
|
1761
1769
|
} catch (r) {
|
|
1762
|
-
throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT") : new g("Failed to stat (directory)", "STAT_FAILED");
|
|
1770
|
+
throw r.name === "NotFoundError" ? new g(\`No such file or directory: \${t}\`, "ENOENT", void 0, r) : new g("Failed to stat (directory)", "STAT_FAILED", void 0, r);
|
|
1763
1771
|
}
|
|
1764
1772
|
}
|
|
1765
1773
|
/**
|
|
@@ -1814,7 +1822,7 @@ class ss {
|
|
|
1814
1822
|
const e = Z(t);
|
|
1815
1823
|
let n = null;
|
|
1816
1824
|
try {
|
|
1817
|
-
n = await this.getDirectoryHandle(
|
|
1825
|
+
n = await this.getDirectoryHandle(G(t), !1);
|
|
1818
1826
|
} catch (i) {
|
|
1819
1827
|
throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
|
|
1820
1828
|
}
|
|
@@ -1825,14 +1833,14 @@ class ss {
|
|
|
1825
1833
|
} catch (i) {
|
|
1826
1834
|
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1827
1835
|
throw i;
|
|
1836
|
+
try {
|
|
1837
|
+
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1838
|
+
} catch (r) {
|
|
1839
|
+
if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
|
|
1840
|
+
throw r;
|
|
1841
|
+
return !1;
|
|
1842
|
+
}
|
|
1828
1843
|
}
|
|
1829
|
-
try {
|
|
1830
|
-
return await n.getDirectoryHandle(e, { create: !1 }), !0;
|
|
1831
|
-
} catch (i) {
|
|
1832
|
-
if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1833
|
-
throw i;
|
|
1834
|
-
}
|
|
1835
|
-
return !1;
|
|
1836
1844
|
}
|
|
1837
1845
|
/**
|
|
1838
1846
|
* Clear all contents of a directory without removing the directory itself
|
|
@@ -1863,7 +1871,7 @@ class ss {
|
|
|
1863
1871
|
}
|
|
1864
1872
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
1865
1873
|
} catch (e) {
|
|
1866
|
-
throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED");
|
|
1874
|
+
throw e instanceof g ? e : new g(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED", void 0, e);
|
|
1867
1875
|
}
|
|
1868
1876
|
}
|
|
1869
1877
|
/**
|
|
@@ -1891,23 +1899,10 @@ class ss {
|
|
|
1891
1899
|
* \`\`\`
|
|
1892
1900
|
*/
|
|
1893
1901
|
async remove(t, e) {
|
|
1894
|
-
await this.mount()
|
|
1895
|
-
const n = e?.recursive ?? !1, i = e?.force ?? !1;
|
|
1896
|
-
if (t === "/")
|
|
1902
|
+
if (await this.mount(), t === "/")
|
|
1897
1903
|
throw new g("Cannot remove root directory", "EROOT");
|
|
1898
|
-
const
|
|
1899
|
-
|
|
1900
|
-
throw new ht("Invalid path", t);
|
|
1901
|
-
const o = await this.getDirectoryHandle(X(t), !1);
|
|
1902
|
-
try {
|
|
1903
|
-
await o.removeEntry(r, { recursive: n });
|
|
1904
|
-
} catch (a) {
|
|
1905
|
-
if (a.name === "NotFoundError") {
|
|
1906
|
-
if (!i)
|
|
1907
|
-
throw new g(\`No such file or directory: \${t}\`, "ENOENT");
|
|
1908
|
-
} else throw a.name === "InvalidModificationError" ? new g(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY") : a.name === "TypeMismatchError" && !n ? new g(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR") : new g(\`Failed to remove path: \${t}\`, "RM_FAILED");
|
|
1909
|
-
}
|
|
1910
|
-
await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1904
|
+
const n = await this.getDirectoryHandle(G(t), !1);
|
|
1905
|
+
await ns(n, t, e), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1911
1906
|
}
|
|
1912
1907
|
/**
|
|
1913
1908
|
* Resolve a path to an absolute path
|
|
@@ -1930,12 +1925,12 @@ class ss {
|
|
|
1930
1925
|
async realpath(t) {
|
|
1931
1926
|
await this.mount();
|
|
1932
1927
|
try {
|
|
1933
|
-
const e =
|
|
1928
|
+
const e = Ke(t);
|
|
1934
1929
|
if (!await this.exists(e))
|
|
1935
|
-
throw new
|
|
1930
|
+
throw new _(e);
|
|
1936
1931
|
return e;
|
|
1937
1932
|
} catch (e) {
|
|
1938
|
-
throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
|
|
1933
|
+
throw e instanceof g ? e : new g(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED", void 0, e);
|
|
1939
1934
|
}
|
|
1940
1935
|
}
|
|
1941
1936
|
/**
|
|
@@ -1958,10 +1953,10 @@ class ss {
|
|
|
1958
1953
|
await this.mount();
|
|
1959
1954
|
try {
|
|
1960
1955
|
if (!await this.exists(t))
|
|
1961
|
-
throw new
|
|
1956
|
+
throw new _(t);
|
|
1962
1957
|
await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
1963
1958
|
} catch (n) {
|
|
1964
|
-
throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED");
|
|
1959
|
+
throw n instanceof g ? n : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, n);
|
|
1965
1960
|
}
|
|
1966
1961
|
}
|
|
1967
1962
|
/**
|
|
@@ -1994,34 +1989,33 @@ class ss {
|
|
|
1994
1989
|
try {
|
|
1995
1990
|
const i = n?.recursive ?? !1, r = n?.force ?? !0;
|
|
1996
1991
|
if (!await this.exists(t))
|
|
1997
|
-
throw new g(\`Source does not exist: \${t}\`, "ENOENT");
|
|
1992
|
+
throw new g(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
1998
1993
|
if (await this.exists(e) && !r)
|
|
1999
|
-
throw new g(\`Destination already exists: \${e}\`, "EEXIST");
|
|
1994
|
+
throw new g(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2000
1995
|
if ((await this.stat(t)).isFile) {
|
|
2001
|
-
const
|
|
2002
|
-
await this.writeFile(e,
|
|
1996
|
+
const h = await this.readFile(t, "binary");
|
|
1997
|
+
await this.writeFile(e, h);
|
|
2003
1998
|
} else {
|
|
2004
1999
|
if (!i)
|
|
2005
|
-
throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR");
|
|
2000
|
+
throw new g(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR", void 0);
|
|
2006
2001
|
await this.mkdir(e, { recursive: !0 });
|
|
2007
|
-
const
|
|
2008
|
-
for (const
|
|
2009
|
-
const f = \`\${t}/\${
|
|
2002
|
+
const h = await this.readDir(t);
|
|
2003
|
+
for (const c of h) {
|
|
2004
|
+
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2010
2005
|
await this.copy(f, u, { recursive: !0, force: r });
|
|
2011
2006
|
}
|
|
2012
2007
|
}
|
|
2013
|
-
await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
2014
2008
|
} catch (i) {
|
|
2015
|
-
throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED");
|
|
2009
|
+
throw i instanceof g ? i : new g(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED", void 0, i);
|
|
2016
2010
|
}
|
|
2017
2011
|
}
|
|
2018
2012
|
/**
|
|
2019
2013
|
* Start watching a file or directory for changes
|
|
2020
2014
|
*
|
|
2021
|
-
* @param path - The path to watch
|
|
2015
|
+
* @param path - The path to watch (minimatch syntax allowed)
|
|
2022
2016
|
* @param options - Watch options
|
|
2023
2017
|
* @param options.recursive - Whether to watch recursively (default: true)
|
|
2024
|
-
* @param options.
|
|
2018
|
+
* @param options.exclude - Glob pattern(s) to exclude (minimatch).
|
|
2025
2019
|
* @returns Promise that resolves when watching starts
|
|
2026
2020
|
*
|
|
2027
2021
|
* @example
|
|
@@ -2034,21 +2028,27 @@ class ss {
|
|
|
2034
2028
|
*
|
|
2035
2029
|
* // Watch a single file
|
|
2036
2030
|
* await fs.watch('/config.json', { recursive: false });
|
|
2031
|
+
*
|
|
2032
|
+
* // Watch all json files but not in dist directory
|
|
2033
|
+
* await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });
|
|
2034
|
+
*
|
|
2037
2035
|
* \`\`\`
|
|
2038
2036
|
*/
|
|
2039
2037
|
async watch(t, e) {
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2038
|
+
if (!this.options.broadcastChannel)
|
|
2039
|
+
throw new g("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
2040
|
+
const n = {
|
|
2041
|
+
pattern: Je(t, e?.recursive ?? !0),
|
|
2042
|
+
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2043
|
+
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2044
|
+
};
|
|
2045
|
+
this.watchers.set(t, n);
|
|
2045
2046
|
}
|
|
2046
2047
|
/**
|
|
2047
2048
|
* Stop watching a previously watched path
|
|
2048
2049
|
*/
|
|
2049
2050
|
unwatch(t) {
|
|
2050
|
-
|
|
2051
|
-
this.watchers.delete(e), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
2051
|
+
this.watchers.delete(t);
|
|
2052
2052
|
}
|
|
2053
2053
|
/**
|
|
2054
2054
|
* Dispose of resources and clean up the file system instance
|
|
@@ -2057,53 +2057,7 @@ class ss {
|
|
|
2057
2057
|
* to properly clean up resources like the broadcast channel and watch timers.
|
|
2058
2058
|
*/
|
|
2059
2059
|
dispose() {
|
|
2060
|
-
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.
|
|
2061
|
-
}
|
|
2062
|
-
async buildSnapshot(t, e) {
|
|
2063
|
-
const n = /* @__PURE__ */ new Map(), i = e?.recursive ?? !0, r = e?.excludes, o = async (c) => {
|
|
2064
|
-
const l = await this.stat(c);
|
|
2065
|
-
return n.set(c, l), l;
|
|
2066
|
-
}, a = async (c) => {
|
|
2067
|
-
if (L(c, r))
|
|
2068
|
-
return;
|
|
2069
|
-
if ((await o(c)).isDirectory) {
|
|
2070
|
-
const h = await this.readDir(c);
|
|
2071
|
-
for (const f of h) {
|
|
2072
|
-
const u = \`\${c === "/" ? "" : c}/\${f.name}\`;
|
|
2073
|
-
i ? await a(u) : L(u, r) || await o(u);
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
};
|
|
2077
|
-
return await a(t), n;
|
|
2078
|
-
}
|
|
2079
|
-
async scanWatches() {
|
|
2080
|
-
if (!this.scanning) {
|
|
2081
|
-
this.scanning = !0;
|
|
2082
|
-
try {
|
|
2083
|
-
await Promise.all(
|
|
2084
|
-
[...this.watchers.entries()].map(async ([t, { snapshot: e, options: n }]) => {
|
|
2085
|
-
let i;
|
|
2086
|
-
try {
|
|
2087
|
-
i = await this.buildSnapshot(t, n);
|
|
2088
|
-
} catch {
|
|
2089
|
-
i = /* @__PURE__ */ new Map();
|
|
2090
|
-
}
|
|
2091
|
-
for (const [r, o] of i) {
|
|
2092
|
-
const a = e.get(r);
|
|
2093
|
-
L(r, n.excludes) || (a ? (a.mtime !== o.mtime || a.size !== o.size) && await this.notifyChange({ path: r, type: "changed", isDirectory: o.isDirectory }) : await this.notifyChange({ path: r, type: "added", isDirectory: o.isDirectory }));
|
|
2094
|
-
}
|
|
2095
|
-
for (const r of e.keys())
|
|
2096
|
-
if (!L(r, n.excludes) && !i.has(r)) {
|
|
2097
|
-
const o = e.get(r);
|
|
2098
|
-
await this.notifyChange({ path: r, type: "removed", isDirectory: o?.isDirectory ?? !1 });
|
|
2099
|
-
}
|
|
2100
|
-
this.watchers.set(t, { snapshot: i, options: n });
|
|
2101
|
-
})
|
|
2102
|
-
);
|
|
2103
|
-
} finally {
|
|
2104
|
-
this.scanning = !1;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2060
|
+
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
2107
2061
|
}
|
|
2108
2062
|
/**
|
|
2109
2063
|
* Synchronize the file system with external data
|
|
@@ -2138,43 +2092,42 @@ class ss {
|
|
|
2138
2092
|
try {
|
|
2139
2093
|
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
2140
2094
|
for (const [i, r] of t) {
|
|
2141
|
-
const o =
|
|
2095
|
+
const o = X(i);
|
|
2142
2096
|
let a;
|
|
2143
|
-
r instanceof Blob ? a = await
|
|
2097
|
+
r instanceof Blob ? a = await ss(r) : a = r, await this.writeFile(o, a);
|
|
2144
2098
|
}
|
|
2145
|
-
await this.notifyChange({ path: "/", type: "changed", isDirectory: !0 });
|
|
2146
2099
|
} catch (n) {
|
|
2147
|
-
throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED");
|
|
2100
|
+
throw n instanceof g ? n : new g("Failed to sync file system", "SYNC_FAILED", void 0, n);
|
|
2148
2101
|
}
|
|
2149
2102
|
}
|
|
2150
2103
|
}
|
|
2151
|
-
typeof
|
|
2152
|
-
//# sourceMappingURL=worker-
|
|
2104
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && Y(new is());
|
|
2105
|
+
//# sourceMappingURL=worker-3SMz_DAt.js.map
|
|
2153
2106
|
`, s = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", r], { type: "text/javascript;charset=utf-8" });
|
|
2154
|
-
function o(
|
|
2155
|
-
let
|
|
2107
|
+
function o(n) {
|
|
2108
|
+
let t;
|
|
2156
2109
|
try {
|
|
2157
|
-
if (
|
|
2158
|
-
const e = new Worker(
|
|
2110
|
+
if (t = s && (self.URL || self.webkitURL).createObjectURL(s), !t) throw "";
|
|
2111
|
+
const e = new Worker(t, {
|
|
2159
2112
|
type: "module",
|
|
2160
|
-
name:
|
|
2113
|
+
name: n?.name
|
|
2161
2114
|
});
|
|
2162
2115
|
return e.addEventListener("error", () => {
|
|
2163
|
-
(self.URL || self.webkitURL).revokeObjectURL(
|
|
2116
|
+
(self.URL || self.webkitURL).revokeObjectURL(t);
|
|
2164
2117
|
}), e;
|
|
2165
2118
|
} catch {
|
|
2166
2119
|
return new Worker(
|
|
2167
2120
|
"data:text/javascript;charset=utf-8," + encodeURIComponent(r),
|
|
2168
2121
|
{
|
|
2169
2122
|
type: "module",
|
|
2170
|
-
name:
|
|
2123
|
+
name: n?.name
|
|
2171
2124
|
}
|
|
2172
2125
|
);
|
|
2173
2126
|
}
|
|
2174
2127
|
}
|
|
2175
|
-
function h(
|
|
2176
|
-
const
|
|
2177
|
-
return
|
|
2128
|
+
async function h(n) {
|
|
2129
|
+
const t = i(new o());
|
|
2130
|
+
return n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), await t.setOptions(n)), t;
|
|
2178
2131
|
}
|
|
2179
2132
|
export {
|
|
2180
2133
|
p as DirectoryNotFoundError,
|
|
@@ -2187,21 +2140,26 @@ export {
|
|
|
2187
2140
|
y as StorageError,
|
|
2188
2141
|
b as TimeoutError,
|
|
2189
2142
|
v as basename,
|
|
2190
|
-
S as
|
|
2143
|
+
S as buffersEqual,
|
|
2144
|
+
x as calculateFileHash,
|
|
2191
2145
|
E as checkOPFSSupport,
|
|
2192
|
-
|
|
2193
|
-
|
|
2146
|
+
P as convertBlobToUint8Array,
|
|
2147
|
+
A as createBuffer,
|
|
2194
2148
|
h as createWorker,
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2149
|
+
F as decodeBuffer,
|
|
2150
|
+
O as dirname,
|
|
2151
|
+
C as encodeString,
|
|
2152
|
+
T as extname,
|
|
2153
|
+
R as isPathExcluded,
|
|
2154
|
+
$ as joinPath,
|
|
2155
|
+
_ as matchMinimatch,
|
|
2156
|
+
D as normalizeMinimatch,
|
|
2157
|
+
I as normalizePath,
|
|
2158
|
+
M as readFileData,
|
|
2159
|
+
j as removeEntry,
|
|
2160
|
+
N as resolvePath,
|
|
2161
|
+
k as splitPath,
|
|
2162
|
+
L as withLock,
|
|
2163
|
+
U as writeFileData
|
|
2206
2164
|
};
|
|
2207
2165
|
//# sourceMappingURL=index.js.map
|