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