attraverso 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/viewer/index.html CHANGED
@@ -3,9 +3,10 @@
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <link rel="icon" type="image/svg+xml" href="/assets/favicon-BUxCK25s.svg" />
6
7
  <title>Attraverso</title>
7
- <script type="module" crossorigin src="/assets/index-Dk0TlY7z.js"></script>
8
- <link rel="stylesheet" crossorigin href="/assets/index--Q2Bqrsm.css">
8
+ <script type="module" crossorigin src="/assets/index-CZYfyJ8d.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-BuEyBnDM.css">
9
10
  </head>
10
11
  <body>
11
12
  <div id="root"></div>
@@ -1,33 +0,0 @@
1
- import { W as We, B, u } from "../server.js";
2
- import * as s from "fs";
3
- import * as o from "path";
4
- import "os";
5
- import "crypto";
6
- import "node:url";
7
- import "node:path";
8
- import "node:process";
9
- import "node:crypto";
10
- import "node:fs/promises";
11
- import "node:fs";
12
- import "node:os";
13
- import "process";
14
- import "buffer";
15
- import "node:http";
16
- u();
17
- var m = class extends We {
18
- constructor(t) {
19
- super(t), this.rootDir = o.resolve(t), s.existsSync(o.join(this.rootDir)) || s.mkdirSync(this.rootDir);
20
- }
21
- async init(t, e) {
22
- return this.pg = t, { emscriptenOpts: { ...e, preRun: [...e.preRun || [], (r) => {
23
- let c = r.FS.filesystems.NODEFS;
24
- r.FS.mkdir(B), r.FS.mount(c, { root: this.rootDir }, B);
25
- }] } };
26
- }
27
- async closeFs() {
28
- this.pg.Module.FS.quit();
29
- }
30
- };
31
- export {
32
- m as NodeFS
33
- };
@@ -1,308 +0,0 @@
1
- import { G as Ge, R as R$1, T as T$1, p as h, V as Ve, u, x as x$1, U } from "../server.js";
2
- import "fs";
3
- import "path";
4
- import "os";
5
- import "crypto";
6
- import "node:url";
7
- import "node:path";
8
- import "node:process";
9
- import "node:crypto";
10
- import "node:fs/promises";
11
- import "node:fs";
12
- import "node:os";
13
- import "process";
14
- import "buffer";
15
- import "node:http";
16
- u();
17
- var $ = "state.txt", G = "data", T = { DIR: 16384, FILE: 32768 }, H, v, F, M, y, b, m, x, P, D, S, n, C, O, k, w, f, I, W, j, L = class extends Ge {
18
- constructor(e, { initialPoolSize: t = 1e3, maintainedPoolSize: o = 100, debug: i = false } = {}) {
19
- super(e, { debug: i });
20
- R$1(this, n);
21
- R$1(this, H);
22
- R$1(this, v);
23
- R$1(this, F);
24
- R$1(this, M);
25
- R$1(this, y);
26
- R$1(this, b, /* @__PURE__ */ new Map());
27
- R$1(this, m, /* @__PURE__ */ new Map());
28
- R$1(this, x, 0);
29
- R$1(this, P, /* @__PURE__ */ new Map());
30
- R$1(this, D, /* @__PURE__ */ new Map());
31
- this.lastCheckpoint = 0;
32
- this.checkpointInterval = 1e3 * 60;
33
- this.poolCounter = 0;
34
- R$1(this, S, /* @__PURE__ */ new Set());
35
- this.initialPoolSize = t, this.maintainedPoolSize = o;
36
- }
37
- async init(e, t) {
38
- return await T$1(this, n, C).call(this), super.init(e, t);
39
- }
40
- async syncToFs(e = false) {
41
- await this.maybeCheckpointState(), await this.maintainPool(), e || this.flush();
42
- }
43
- async closeFs() {
44
- for (let e of h(this, m).values()) e.close();
45
- h(this, y).flush(), h(this, y).close(), this.pg.Module.FS.quit();
46
- }
47
- async maintainPool(e) {
48
- e = e || this.maintainedPoolSize;
49
- let t = e - this.state.pool.length, o = [];
50
- for (let i = 0; i < t; i++) o.push(new Promise(async (c) => {
51
- ++this.poolCounter;
52
- let a = `${(Date.now() - 1704063600).toString(16).padStart(8, "0")}-${this.poolCounter.toString(16).padStart(8, "0")}`, h$1 = await h(this, F).getFileHandle(a, { create: true }), d = await h$1.createSyncAccessHandle();
53
- h(this, b).set(a, h$1), h(this, m).set(a, d), T$1(this, n, k).call(this, { opp: "createPoolFile", args: [a] }), this.state.pool.push(a), c();
54
- }));
55
- for (let i = 0; i > t; i--) o.push(new Promise(async (c) => {
56
- let a = this.state.pool.pop();
57
- T$1(this, n, k).call(this, { opp: "deletePoolFile", args: [a] });
58
- let h$1 = h(this, b).get(a);
59
- h(this, m).get(a)?.close(), await h(this, F).removeEntry(h$1.name), h(this, b).delete(a), h(this, m).delete(a), c();
60
- }));
61
- await Promise.all(o);
62
- }
63
- _createPoolFileState(e) {
64
- this.state.pool.push(e);
65
- }
66
- _deletePoolFileState(e) {
67
- let t = this.state.pool.indexOf(e);
68
- t > -1 && this.state.pool.splice(t, 1);
69
- }
70
- async maybeCheckpointState() {
71
- Date.now() - this.lastCheckpoint > this.checkpointInterval && await this.checkpointState();
72
- }
73
- async checkpointState() {
74
- let e = new TextEncoder().encode(JSON.stringify(this.state));
75
- h(this, y).truncate(0), h(this, y).write(e, { at: 0 }), h(this, y).flush(), this.lastCheckpoint = Date.now();
76
- }
77
- flush() {
78
- for (let e of h(this, S)) try {
79
- e.flush();
80
- } catch {
81
- }
82
- h(this, S).clear();
83
- }
84
- chmod(e, t) {
85
- T$1(this, n, O).call(this, { opp: "chmod", args: [e, t] }, () => {
86
- this._chmodState(e, t);
87
- });
88
- }
89
- _chmodState(e, t) {
90
- let o = T$1(this, n, f).call(this, e);
91
- o.mode = t;
92
- }
93
- close(e) {
94
- let t = T$1(this, n, I).call(this, e);
95
- h(this, P).delete(e), h(this, D).delete(t);
96
- }
97
- fstat(e) {
98
- let t = T$1(this, n, I).call(this, e);
99
- return this.lstat(t);
100
- }
101
- lstat(e) {
102
- let t = T$1(this, n, f).call(this, e), o = t.type === "file" ? h(this, m).get(t.backingFilename).getSize() : 0, i = 4096;
103
- return { dev: 0, ino: 0, mode: t.mode, nlink: 1, uid: 0, gid: 0, rdev: 0, size: o, blksize: i, blocks: Math.ceil(o / i), atime: t.lastModified, mtime: t.lastModified, ctime: t.lastModified };
104
- }
105
- mkdir(e, t) {
106
- T$1(this, n, O).call(this, { opp: "mkdir", args: [e, t] }, () => {
107
- this._mkdirState(e, t);
108
- });
109
- }
110
- _mkdirState(e, t) {
111
- let o = T$1(this, n, w).call(this, e), i = o.pop(), c = [], a = this.state.root;
112
- for (let d of o) {
113
- if (c.push(e), !Object.prototype.hasOwnProperty.call(a.children, d)) if (t?.recursive) this.mkdir(c.join("/"));
114
- else throw new p("ENOENT", "No such file or directory");
115
- if (a.children[d].type !== "directory") throw new p("ENOTDIR", "Not a directory");
116
- a = a.children[d];
117
- }
118
- if (Object.prototype.hasOwnProperty.call(a.children, i)) throw new p("EEXIST", "File exists");
119
- let h2 = { type: "directory", lastModified: Date.now(), mode: t?.mode || T.DIR, children: {} };
120
- a.children[i] = h2;
121
- }
122
- open(e, t, o) {
123
- if (T$1(this, n, f).call(this, e).type !== "file") throw new p("EISDIR", "Is a directory");
124
- let c = T$1(this, n, W).call(this);
125
- return h(this, P).set(c, e), h(this, D).set(e, c), c;
126
- }
127
- readdir(e) {
128
- let t = T$1(this, n, f).call(this, e);
129
- if (t.type !== "directory") throw new p("ENOTDIR", "Not a directory");
130
- return Object.keys(t.children);
131
- }
132
- read(e, t, o, i, c) {
133
- let a = T$1(this, n, I).call(this, e), h$1 = T$1(this, n, f).call(this, a);
134
- if (h$1.type !== "file") throw new p("EISDIR", "Is a directory");
135
- return h(this, m).get(h$1.backingFilename).read(new Uint8Array(t.buffer, o, i), { at: c });
136
- }
137
- rename(e, t) {
138
- T$1(this, n, O).call(this, { opp: "rename", args: [e, t] }, () => {
139
- this._renameState(e, t, true);
140
- });
141
- }
142
- _renameState(e, t, o = false) {
143
- let i = T$1(this, n, w).call(this, e), c = i.pop(), a = T$1(this, n, f).call(this, i.join("/"));
144
- if (!Object.prototype.hasOwnProperty.call(a.children, c)) throw new p("ENOENT", "No such file or directory");
145
- let h$1 = T$1(this, n, w).call(this, t), d = h$1.pop(), l = T$1(this, n, f).call(this, h$1.join("/"));
146
- if (o && Object.prototype.hasOwnProperty.call(l.children, d)) {
147
- let u2 = l.children[d];
148
- h(this, m).get(u2.backingFilename).truncate(0), this.state.pool.push(u2.backingFilename);
149
- }
150
- l.children[d] = a.children[c], delete a.children[c];
151
- }
152
- rmdir(e) {
153
- T$1(this, n, O).call(this, { opp: "rmdir", args: [e] }, () => {
154
- this._rmdirState(e);
155
- });
156
- }
157
- _rmdirState(e) {
158
- let t = T$1(this, n, w).call(this, e), o = t.pop(), i = T$1(this, n, f).call(this, t.join("/"));
159
- if (!Object.prototype.hasOwnProperty.call(i.children, o)) throw new p("ENOENT", "No such file or directory");
160
- let c = i.children[o];
161
- if (c.type !== "directory") throw new p("ENOTDIR", "Not a directory");
162
- if (Object.keys(c.children).length > 0) throw new p("ENOTEMPTY", "Directory not empty");
163
- delete i.children[o];
164
- }
165
- truncate(e, t = 0) {
166
- let o = T$1(this, n, f).call(this, e);
167
- if (o.type !== "file") throw new p("EISDIR", "Is a directory");
168
- let i = h(this, m).get(o.backingFilename);
169
- if (!i) throw new p("ENOENT", "No such file or directory");
170
- i.truncate(t), h(this, S).add(i);
171
- }
172
- unlink(e) {
173
- T$1(this, n, O).call(this, { opp: "unlink", args: [e] }, () => {
174
- this._unlinkState(e, true);
175
- });
176
- }
177
- _unlinkState(e, t = false) {
178
- let o = T$1(this, n, w).call(this, e), i = o.pop(), c = T$1(this, n, f).call(this, o.join("/"));
179
- if (!Object.prototype.hasOwnProperty.call(c.children, i)) throw new p("ENOENT", "No such file or directory");
180
- let a = c.children[i];
181
- if (a.type !== "file") throw new p("EISDIR", "Is a directory");
182
- if (delete c.children[i], t) {
183
- let h$1 = h(this, m).get(a.backingFilename);
184
- h$1?.truncate(0), h(this, S).add(h$1), h(this, D).has(e) && (h(this, P).delete(h(this, D).get(e)), h(this, D).delete(e));
185
- }
186
- this.state.pool.push(a.backingFilename);
187
- }
188
- utimes(e, t, o) {
189
- T$1(this, n, O).call(this, { opp: "utimes", args: [e, t, o] }, () => {
190
- this._utimesState(e, t, o);
191
- });
192
- }
193
- _utimesState(e, t, o) {
194
- let i = T$1(this, n, f).call(this, e);
195
- i.lastModified = o;
196
- }
197
- writeFile(e, t, o) {
198
- let i = T$1(this, n, w).call(this, e), c = i.pop(), a = T$1(this, n, f).call(this, i.join("/"));
199
- if (Object.prototype.hasOwnProperty.call(a.children, c)) {
200
- let l = a.children[c];
201
- l.lastModified = Date.now(), T$1(this, n, k).call(this, { opp: "setLastModified", args: [e, l.lastModified] });
202
- } else {
203
- if (this.state.pool.length === 0) throw new Error("No more file handles available in the pool");
204
- let l = { type: "file", lastModified: Date.now(), mode: o?.mode || T.FILE, backingFilename: this.state.pool.pop() };
205
- a.children[c] = l, T$1(this, n, k).call(this, { opp: "createFileNode", args: [e, l] });
206
- }
207
- let h$1 = a.children[c], d = h(this, m).get(h$1.backingFilename);
208
- t.length > 0 && (d.write(typeof t == "string" ? new TextEncoder().encode(t) : new Uint8Array(t), { at: 0 }), e.startsWith("/pg_wal") && h(this, S).add(d));
209
- }
210
- _createFileNodeState(e, t) {
211
- let o = T$1(this, n, w).call(this, e), i = o.pop(), c = T$1(this, n, f).call(this, o.join("/"));
212
- c.children[i] = t;
213
- let a = this.state.pool.indexOf(t.backingFilename);
214
- return a > -1 && this.state.pool.splice(a, 1), t;
215
- }
216
- _setLastModifiedState(e, t) {
217
- let o = T$1(this, n, f).call(this, e);
218
- o.lastModified = t;
219
- }
220
- write(e, t, o, i, c) {
221
- let a = T$1(this, n, I).call(this, e), h$1 = T$1(this, n, f).call(this, a);
222
- if (h$1.type !== "file") throw new p("EISDIR", "Is a directory");
223
- let d = h(this, m).get(h$1.backingFilename);
224
- if (!d) throw new p("EBADF", "Bad file descriptor");
225
- let l = d.write(new Uint8Array(t, o, i), { at: c });
226
- return a.startsWith("/pg_wal") && h(this, S).add(d), l;
227
- }
228
- };
229
- H = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), F = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), x = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new WeakMap(), S = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakSet(), C = async function() {
230
- x$1(this, H, await navigator.storage.getDirectory()), x$1(this, v, await T$1(this, n, j).call(this, this.dataDir, { create: true })), x$1(this, F, await T$1(this, n, j).call(this, G, { from: h(this, v), create: true })), x$1(this, M, await h(this, v).getFileHandle($, { create: true })), x$1(this, y, await h(this, M).createSyncAccessHandle());
231
- let e = new ArrayBuffer(h(this, y).getSize());
232
- h(this, y).read(e, { at: 0 });
233
- let t, o = new TextDecoder().decode(e).split(`
234
- `), i = false;
235
- try {
236
- t = JSON.parse(o[0]);
237
- } catch {
238
- t = { root: { type: "directory", lastModified: Date.now(), mode: T.DIR, children: {} }, pool: [] }, h(this, y).truncate(0), h(this, y).write(new TextEncoder().encode(JSON.stringify(t)), { at: 0 }), i = true;
239
- }
240
- this.state = t;
241
- let c = o.slice(1).filter(Boolean).map((l) => JSON.parse(l));
242
- for (let l of c) {
243
- let u2 = `_${l.opp}State`;
244
- if (typeof this[u2] == "function") try {
245
- this[u2].bind(this)(...l.args);
246
- } catch (N) {
247
- console.warn("Error applying OPFS AHP WAL entry", l, N);
248
- }
249
- }
250
- let a = [], h$1 = async (l) => {
251
- if (l.type === "file") try {
252
- let u2 = await h(this, F).getFileHandle(l.backingFilename), N = await u2.createSyncAccessHandle();
253
- h(this, b).set(l.backingFilename, u2), h(this, m).set(l.backingFilename, N);
254
- } catch (u2) {
255
- console.error("Error opening file handle for node", l, u2);
256
- }
257
- else for (let u2 of Object.values(l.children)) a.push(h$1(u2));
258
- };
259
- await h$1(this.state.root);
260
- let d = [];
261
- for (let l of this.state.pool) d.push(new Promise(async (u2) => {
262
- h(this, b).has(l) && console.warn("File handle already exists for pool file", l);
263
- let N = await h(this, F).getFileHandle(l), U2 = await N.createSyncAccessHandle();
264
- h(this, b).set(l, N), h(this, m).set(l, U2), u2();
265
- }));
266
- await Promise.all([...a, ...d]), await this.maintainPool(i ? this.initialPoolSize : this.maintainedPoolSize);
267
- }, O = function(e, t) {
268
- let o = T$1(this, n, k).call(this, e);
269
- try {
270
- t();
271
- } catch (i) {
272
- throw h(this, y).truncate(o), i;
273
- }
274
- }, k = function(e) {
275
- let t = JSON.stringify(e), o = new TextEncoder().encode(`
276
- ${t}`), i = h(this, y).getSize();
277
- return h(this, y).write(o, { at: i }), h(this, S).add(h(this, y)), i;
278
- }, w = function(e) {
279
- return e.split("/").filter(Boolean);
280
- }, f = function(e, t) {
281
- let o = T$1(this, n, w).call(this, e), i = t || this.state.root;
282
- for (let c of o) {
283
- if (i.type !== "directory") throw new p("ENOTDIR", "Not a directory");
284
- if (!Object.prototype.hasOwnProperty.call(i.children, c)) throw new p("ENOENT", "No such file or directory");
285
- i = i.children[c];
286
- }
287
- return i;
288
- }, I = function(e) {
289
- let t = h(this, P).get(e);
290
- if (!t) throw new p("EBADF", "Bad file descriptor");
291
- return t;
292
- }, W = function() {
293
- let e = ++U(this, x)._;
294
- for (; h(this, P).has(e); ) U(this, x)._++;
295
- return e;
296
- }, j = async function(e, t) {
297
- let o = T$1(this, n, w).call(this, e), i = t?.from || h(this, H);
298
- for (let c of o) i = await i.getDirectoryHandle(c, { create: t?.create });
299
- return i;
300
- };
301
- var p = class extends Error {
302
- constructor(A, e) {
303
- super(e), typeof A == "number" ? this.code = A : typeof A == "string" && (this.code = Ve[A]);
304
- }
305
- };
306
- export {
307
- L as OpfsAhpFS
308
- };