@filens/converter-client 0.1.0 → 0.1.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.
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var y = (e, t, r) =>
|
|
4
|
-
import { gunzipSync as
|
|
5
|
-
function
|
|
6
|
-
if (e != null && e.aborted) throw
|
|
1
|
+
var lt = Object.defineProperty;
|
|
2
|
+
var Ft = (e, t, r) => t in e ? lt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var y = (e, t, r) => Ft(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { gunzipSync as gt } from "fflate";
|
|
5
|
+
function p(e) {
|
|
6
|
+
if (e != null && e.aborted) throw K();
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function K() {
|
|
9
9
|
return Object.assign(new Error("The conversion was aborted."), { name: "AbortError" });
|
|
10
10
|
}
|
|
11
11
|
function f(e, t) {
|
|
12
12
|
return t ? new Promise((r, o) => {
|
|
13
|
-
const a = () => o(
|
|
13
|
+
const a = () => o(K());
|
|
14
14
|
e.then(
|
|
15
15
|
(s) => {
|
|
16
16
|
t.removeEventListener("abort", a), r(s);
|
|
@@ -33,140 +33,140 @@ function D(e) {
|
|
|
33
33
|
return t;
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function X(e) {
|
|
37
37
|
return /^(?:https?:|blob:|\/|\.{1,2}\/)/i.test(e);
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function Q(e) {
|
|
40
40
|
return e.trimStart().toLowerCase().startsWith("data:");
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function Z(e) {
|
|
43
43
|
const t = atob(e), r = new Uint8Array(t.length);
|
|
44
44
|
for (let o = 0; o < r.length; o++) r[o] = t.charCodeAt(o);
|
|
45
45
|
return r;
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function q(e) {
|
|
48
48
|
var m;
|
|
49
49
|
const t = e.trimStart(), r = t.indexOf(",");
|
|
50
50
|
if (r < 0) throw new Error("Conversion data URL is missing its payload separator.");
|
|
51
51
|
const o = t.slice(0, r), a = t.slice(r + 1), s = (m = o.match(/^data:([^;,]+)/i)) == null ? void 0 : m[1];
|
|
52
|
-
if (/;base64$/i.test(o)) return { bytes:
|
|
53
|
-
const
|
|
54
|
-
let
|
|
55
|
-
for (let i = 0; i <
|
|
56
|
-
if (
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
c
|
|
52
|
+
if (/;base64$/i.test(o)) return { bytes: Z(a), contentType: s };
|
|
53
|
+
const n = new TextEncoder().encode(a);
|
|
54
|
+
let c = 0;
|
|
55
|
+
for (let i = 0; i < n.length; i++) {
|
|
56
|
+
if (n[i] === 37) {
|
|
57
|
+
const d = $(n[i + 1]), l = $(n[i + 2]);
|
|
58
|
+
if (d >= 0 && l >= 0) {
|
|
59
|
+
n[c++] = d << 4 | l, i += 2;
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
c
|
|
63
|
+
n[c++] = n[i];
|
|
64
64
|
}
|
|
65
|
-
return { bytes:
|
|
65
|
+
return { bytes: n.subarray(0, c), contentType: s };
|
|
66
66
|
}
|
|
67
67
|
function $(e) {
|
|
68
68
|
if (e >= 48 && e <= 57) return e - 48;
|
|
69
69
|
const t = e | 32;
|
|
70
70
|
return t >= 97 && t <= 102 ? t - 87 : -1;
|
|
71
71
|
}
|
|
72
|
-
async function
|
|
72
|
+
async function tt(e, t = globalThis.fetch, r, o = 1 / 0) {
|
|
73
73
|
var s;
|
|
74
|
-
const a = (
|
|
75
|
-
if (
|
|
74
|
+
const a = (n) => {
|
|
75
|
+
if (n > o) throw new Error("Conversion source exceeds the preview byte limit.");
|
|
76
76
|
};
|
|
77
|
-
if (
|
|
77
|
+
if (xt(e)) {
|
|
78
78
|
a(e.size);
|
|
79
|
-
const
|
|
80
|
-
return a(
|
|
79
|
+
const n = new Uint8Array(await f(e.arrayBuffer(), r));
|
|
80
|
+
return a(n.length), n;
|
|
81
81
|
}
|
|
82
82
|
if (e instanceof ArrayBuffer)
|
|
83
83
|
return a(e.byteLength), new Uint8Array(e);
|
|
84
84
|
if (ArrayBuffer.isView(e))
|
|
85
85
|
return a(e.byteLength), new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
86
86
|
if (typeof e == "string") {
|
|
87
|
-
if (
|
|
87
|
+
if (Q(e)) {
|
|
88
88
|
a(Math.max(0, e.length - e.indexOf(",") - 1) / 3);
|
|
89
|
-
const
|
|
90
|
-
return a(
|
|
89
|
+
const c = q(e).bytes;
|
|
90
|
+
return a(c.length), c;
|
|
91
91
|
}
|
|
92
|
-
if (
|
|
92
|
+
if (X(e)) {
|
|
93
93
|
if (!t) throw new Error("A fetch implementation is required to load a conversion source URL.");
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
throw new Error(`Failed to fetch conversion source: ${
|
|
94
|
+
const c = await f(t(e, { signal: r }), r);
|
|
95
|
+
if (p(r), !c.ok)
|
|
96
|
+
throw new Error(`Failed to fetch conversion source: ${c.status} ${c.statusText}`.trim());
|
|
97
97
|
try {
|
|
98
|
-
if (a(Number(
|
|
99
|
-
const i = new Uint8Array(await f(
|
|
98
|
+
if (a(Number(c.headers.get("content-length"))), !Number.isFinite(o) || !c.body) {
|
|
99
|
+
const i = new Uint8Array(await f(c.arrayBuffer(), r));
|
|
100
100
|
return a(i.length), i;
|
|
101
101
|
}
|
|
102
|
-
const m =
|
|
102
|
+
const m = c.body.getReader();
|
|
103
103
|
try {
|
|
104
104
|
const i = [];
|
|
105
|
-
let
|
|
105
|
+
let d = 0;
|
|
106
106
|
for (; ; ) {
|
|
107
|
-
const { value:
|
|
108
|
-
if (
|
|
109
|
-
|
|
107
|
+
const { value: g, done: A } = await f(m.read(), r);
|
|
108
|
+
if (A) break;
|
|
109
|
+
d += g.length, a(d), i.push(g);
|
|
110
110
|
}
|
|
111
|
-
const l = new Uint8Array(
|
|
112
|
-
let
|
|
113
|
-
for (const
|
|
114
|
-
l.set(
|
|
111
|
+
const l = new Uint8Array(d);
|
|
112
|
+
let h = 0;
|
|
113
|
+
for (const g of i)
|
|
114
|
+
l.set(g, h), h += g.length;
|
|
115
115
|
return l;
|
|
116
116
|
} finally {
|
|
117
117
|
await m.cancel().catch(() => {
|
|
118
118
|
}), m.releaseLock();
|
|
119
119
|
}
|
|
120
120
|
} catch (m) {
|
|
121
|
-
throw await ((s =
|
|
121
|
+
throw await ((s = c.body) == null ? void 0 : s.cancel().catch(() => {
|
|
122
122
|
})), m;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
a(e.length);
|
|
126
|
-
const
|
|
127
|
-
return a(
|
|
126
|
+
const n = new TextEncoder().encode(e);
|
|
127
|
+
return a(n.length), n;
|
|
128
128
|
}
|
|
129
129
|
throw new Error("Unsupported conversion source type.");
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function xt(e) {
|
|
132
132
|
return typeof e == "object" && e !== null && "arrayBuffer" in e && typeof e.arrayBuffer == "function";
|
|
133
133
|
}
|
|
134
|
-
async function
|
|
134
|
+
async function ft(e) {
|
|
135
135
|
var r;
|
|
136
136
|
if (((r = e.headers.get("content-type")) == null ? void 0 : r.split(";", 1)[0]) !== "application/wasm+gzip") return e;
|
|
137
137
|
if (typeof DecompressionStream < "u" && e.body)
|
|
138
138
|
return new Response(e.body.pipeThrough(new DecompressionStream("gzip")), {
|
|
139
139
|
headers: { "content-type": "application/wasm" }
|
|
140
140
|
});
|
|
141
|
-
const t =
|
|
141
|
+
const t = gt(new Uint8Array(await e.arrayBuffer()));
|
|
142
142
|
return new Response(t, { headers: { "content-type": "application/wasm" } });
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
const t = D(() =>
|
|
144
|
+
function T(e) {
|
|
145
|
+
const t = D(() => rt(e.wasm, e.fetch));
|
|
146
146
|
return async (r) => {
|
|
147
147
|
const o = r.signal;
|
|
148
|
-
|
|
149
|
-
const a = new
|
|
148
|
+
p(o);
|
|
149
|
+
const a = new at({
|
|
150
150
|
args: r.args,
|
|
151
151
|
files: r.files,
|
|
152
152
|
captureStdio: r.captureStdio
|
|
153
153
|
}), s = await f(t(), o);
|
|
154
|
-
|
|
155
|
-
const
|
|
154
|
+
p(o);
|
|
155
|
+
const n = await f(WebAssembly.instantiate(s, {
|
|
156
156
|
wasi_snapshot_preview1: a.imports
|
|
157
157
|
}), o);
|
|
158
|
-
|
|
159
|
-
let
|
|
158
|
+
p(o), a.setInstance(n);
|
|
159
|
+
let c = 0;
|
|
160
160
|
try {
|
|
161
|
-
|
|
161
|
+
n.exports._start();
|
|
162
162
|
} catch (m) {
|
|
163
|
-
if (m instanceof
|
|
164
|
-
|
|
163
|
+
if (m instanceof et)
|
|
164
|
+
c = m.code;
|
|
165
165
|
else
|
|
166
166
|
throw m;
|
|
167
167
|
}
|
|
168
168
|
return {
|
|
169
|
-
exitCode:
|
|
169
|
+
exitCode: c,
|
|
170
170
|
...r.captureStdio ? { stdout: a.readStdio(1), stderr: a.readStdio(2) } : {},
|
|
171
171
|
files: Object.fromEntries((r.readFiles ?? []).flatMap((m) => {
|
|
172
172
|
const i = a.readFileIfPresent(m);
|
|
@@ -175,34 +175,34 @@ function B(e) {
|
|
|
175
175
|
};
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
|
-
async function
|
|
178
|
+
async function rt(e, t = globalThis.fetch) {
|
|
179
179
|
const r = typeof e == "function" ? await e() : await e;
|
|
180
180
|
if (r instanceof WebAssembly.Module)
|
|
181
181
|
return r;
|
|
182
|
-
if (typeof r == "string" ||
|
|
182
|
+
if (typeof r == "string" || ht(r)) {
|
|
183
183
|
if (!t)
|
|
184
184
|
throw new Error("A fetch implementation is required to load converter WASM from a URL.");
|
|
185
|
-
return
|
|
185
|
+
return P(await t(String(r)));
|
|
186
186
|
}
|
|
187
|
-
return typeof Response < "u" && r instanceof Response ?
|
|
187
|
+
return typeof Response < "u" && r instanceof Response ? P(r) : WebAssembly.compile(r);
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function ht(e) {
|
|
190
190
|
return typeof URL < "u" && e instanceof URL;
|
|
191
191
|
}
|
|
192
|
-
async function
|
|
192
|
+
async function P(e) {
|
|
193
193
|
var r;
|
|
194
194
|
if (!e.ok)
|
|
195
195
|
throw new Error(`Failed to fetch converter WASM: ${e.status} ${e.statusText}`.trim());
|
|
196
|
-
const t = await
|
|
196
|
+
const t = await ft(e);
|
|
197
197
|
return typeof WebAssembly.compileStreaming == "function" && ((r = t.headers.get("content-type")) == null ? void 0 : r.split(";", 1)[0]) === "application/wasm" ? WebAssembly.compileStreaming(t) : WebAssembly.compile(await t.arrayBuffer());
|
|
198
198
|
}
|
|
199
|
-
class
|
|
199
|
+
class et extends Error {
|
|
200
200
|
constructor(t) {
|
|
201
201
|
super(`WASI exited with code ${t}`), this.code = t;
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
|
-
const u = 0, x = 8,
|
|
205
|
-
class
|
|
204
|
+
const u = 0, x = 8, wt = 20, z = 28, S = 31, C = 44, G = 54, I = 55, ot = 2, O = 3, W = 4, H = 1, yt = 2, bt = 4, vt = 8, V = 1;
|
|
205
|
+
class at {
|
|
206
206
|
constructor(t) {
|
|
207
207
|
y(this, "imports", {
|
|
208
208
|
args_get: (t, r) => this.argsGet(t, r),
|
|
@@ -223,12 +223,12 @@ class ot {
|
|
|
223
223
|
fd_write: (t, r, o, a) => this.fdWrite(t, r, o, a),
|
|
224
224
|
path_create_directory: (t, r, o) => this.pathCreateDirectory(t, r, o),
|
|
225
225
|
path_filestat_get: (t, r, o, a, s) => this.pathFilestatGet(t, o, a, s),
|
|
226
|
-
path_open: (t, r, o, a, s,
|
|
226
|
+
path_open: (t, r, o, a, s, n, c, m, i) => this.pathOpen(t, o, a, s, m, i),
|
|
227
227
|
path_remove_directory: (t, r, o) => this.pathRemoveDirectory(t, r, o),
|
|
228
228
|
path_unlink_file: (t, r, o) => this.pathUnlinkFile(t, r, o),
|
|
229
229
|
poll_oneoff: (t, r, o, a) => this.pollOneoff(a),
|
|
230
230
|
proc_exit: (t) => {
|
|
231
|
-
throw new
|
|
231
|
+
throw new et(t);
|
|
232
232
|
},
|
|
233
233
|
random_get: (t, r) => this.randomGet(t, r),
|
|
234
234
|
sched_yield: () => u
|
|
@@ -257,14 +257,14 @@ class ot {
|
|
|
257
257
|
return new TextDecoder().decode(new Uint8Array(this.stdio[t]));
|
|
258
258
|
}
|
|
259
259
|
readFile(t) {
|
|
260
|
-
const r = this.files.get(
|
|
260
|
+
const r = this.files.get(j(t));
|
|
261
261
|
if (!r)
|
|
262
262
|
throw new Error(`WASM file was not written: ${t}`);
|
|
263
263
|
const o = new Uint8Array(r.byteLength);
|
|
264
264
|
return o.set(r), o;
|
|
265
265
|
}
|
|
266
266
|
readFileIfPresent(t) {
|
|
267
|
-
return this.files.has(
|
|
267
|
+
return this.files.has(j(t)) ? this.readFile(t) : void 0;
|
|
268
268
|
}
|
|
269
269
|
get memory() {
|
|
270
270
|
var r;
|
|
@@ -280,7 +280,7 @@ class ot {
|
|
|
280
280
|
return new DataView(this.memory.buffer);
|
|
281
281
|
}
|
|
282
282
|
argsSizesGet(t, r) {
|
|
283
|
-
return this.view.setUint32(t, this.args.length, !0), this.view.setUint32(r,
|
|
283
|
+
return this.view.setUint32(t, this.args.length, !0), this.view.setUint32(r, kt(this.args), !0), u;
|
|
284
284
|
}
|
|
285
285
|
argsGet(t, r) {
|
|
286
286
|
return this.writeStringList(this.args, t, r);
|
|
@@ -296,12 +296,12 @@ class ot {
|
|
|
296
296
|
}
|
|
297
297
|
fdFdstatGet(t, r) {
|
|
298
298
|
const o = this.fds.get(t);
|
|
299
|
-
return o ? (this.bytes.fill(0, r, r + 24), this.bytes[r] =
|
|
299
|
+
return o ? (this.bytes.fill(0, r, r + 24), this.bytes[r] = jt(o), this.view.setBigUint64(r + 8, 0xffffffffffffffffn, !0), this.view.setBigUint64(r + 16, 0xffffffffffffffffn, !0), u) : x;
|
|
300
300
|
}
|
|
301
301
|
fdFilestatGet(t, r) {
|
|
302
302
|
var a;
|
|
303
303
|
const o = this.fds.get(t);
|
|
304
|
-
return o ? o.kind === "file" ? (this.writeFilestat(r,
|
|
304
|
+
return o ? o.kind === "file" ? (this.writeFilestat(r, W, ((a = this.files.get(o.path)) == null ? void 0 : a.byteLength) ?? 0), u) : o.kind === "dir" ? (this.writeFilestat(r, O, 0), u) : (this.writeFilestat(r, ot, 0), u) : x;
|
|
305
305
|
}
|
|
306
306
|
fdPrestatGet(t, r) {
|
|
307
307
|
const o = this.fds.get(t);
|
|
@@ -314,20 +314,20 @@ class ot {
|
|
|
314
314
|
const s = new TextEncoder().encode(a.path);
|
|
315
315
|
return this.bytes.set(s.subarray(0, o), r), u;
|
|
316
316
|
}
|
|
317
|
-
fdRead(t, r, o, a, s,
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
317
|
+
fdRead(t, r, o, a, s, n = !0) {
|
|
318
|
+
const c = this.fds.get(t);
|
|
319
|
+
if (!c)
|
|
320
320
|
return x;
|
|
321
|
-
if (
|
|
322
|
-
return this.view.setUint32(a, 0, !0),
|
|
323
|
-
const m = this.files.get(
|
|
324
|
-
let i = s ??
|
|
325
|
-
for (const [l,
|
|
326
|
-
const
|
|
327
|
-
if (this.bytes.set(
|
|
321
|
+
if (c.kind !== "file")
|
|
322
|
+
return this.view.setUint32(a, 0, !0), c.kind === "dir" ? S : u;
|
|
323
|
+
const m = this.files.get(c.path) ?? new Uint8Array();
|
|
324
|
+
let i = s ?? c.position, d = 0;
|
|
325
|
+
for (const [l, h] of this.iovs(r, o)) {
|
|
326
|
+
const g = m.subarray(i, i + h);
|
|
327
|
+
if (this.bytes.set(g, l), i += g.byteLength, d += g.byteLength, g.byteLength < h)
|
|
328
328
|
break;
|
|
329
329
|
}
|
|
330
|
-
return
|
|
330
|
+
return n && s === void 0 && (c.position = i), this.view.setUint32(a, d, !0), u;
|
|
331
331
|
}
|
|
332
332
|
fdSeek(t, r, o, a) {
|
|
333
333
|
var m;
|
|
@@ -335,8 +335,8 @@ class ot {
|
|
|
335
335
|
if (!s || s.kind !== "file")
|
|
336
336
|
return (s == null ? void 0 : s.kind) === "dir" ? S : x;
|
|
337
337
|
if (o !== 0 && o !== 1 && o !== 2) return z;
|
|
338
|
-
const
|
|
339
|
-
return !Number.isSafeInteger(
|
|
338
|
+
const c = (o === 0 ? 0 : o === 1 ? s.position : o === 2 ? ((m = this.files.get(s.path)) == null ? void 0 : m.byteLength) ?? 0 : -1) + Number(r);
|
|
339
|
+
return !Number.isSafeInteger(c) || c < 0 ? z : (s.position = c, this.view.setBigUint64(a, BigInt(c), !0), u);
|
|
340
340
|
}
|
|
341
341
|
fdTell(t, r) {
|
|
342
342
|
const o = this.fds.get(t);
|
|
@@ -346,59 +346,59 @@ class ot {
|
|
|
346
346
|
const s = this.fds.get(t);
|
|
347
347
|
if (!s)
|
|
348
348
|
return x;
|
|
349
|
-
let
|
|
349
|
+
let n = 0;
|
|
350
350
|
if (s.kind === "stdio") {
|
|
351
|
-
for (const [
|
|
351
|
+
for (const [c, m] of this.iovs(r, o)) {
|
|
352
352
|
const i = this.captureStdio ? this.stdio[s.fd] : void 0;
|
|
353
353
|
if (i) {
|
|
354
|
-
const
|
|
355
|
-
for (let
|
|
354
|
+
const d = c + Math.min(m, Math.max(0, 1048576 - i.length)), l = this.bytes;
|
|
355
|
+
for (let h = c; h < d; h++) i.push(l[h]);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
n += m;
|
|
358
358
|
}
|
|
359
|
-
return this.view.setUint32(a,
|
|
359
|
+
return this.view.setUint32(a, n, !0), u;
|
|
360
360
|
}
|
|
361
361
|
if (s.kind !== "file")
|
|
362
362
|
return S;
|
|
363
|
-
for (const [
|
|
364
|
-
const i = this.bytes.subarray(
|
|
365
|
-
this.writeFileChunk(s, i),
|
|
363
|
+
for (const [c, m] of this.iovs(r, o)) {
|
|
364
|
+
const i = this.bytes.subarray(c, c + m);
|
|
365
|
+
this.writeFileChunk(s, i), n += m;
|
|
366
366
|
}
|
|
367
|
-
return this.view.setUint32(a,
|
|
367
|
+
return this.view.setUint32(a, n, !0), u;
|
|
368
368
|
}
|
|
369
369
|
pathCreateDirectory(t, r, o) {
|
|
370
370
|
const a = this.readPath(t, r, o);
|
|
371
|
-
return a ? (this.ensureParentDir(a), this.files.has(a) ?
|
|
371
|
+
return a ? (this.ensureParentDir(a), this.files.has(a) ? G : (this.dirs.add(a), u)) : x;
|
|
372
372
|
}
|
|
373
373
|
pathFilestatGet(t, r, o, a) {
|
|
374
|
-
var
|
|
374
|
+
var n;
|
|
375
375
|
const s = this.readPath(t, r, o);
|
|
376
|
-
return s ? this.files.has(s) ? (this.writeFilestat(a,
|
|
376
|
+
return s ? this.files.has(s) ? (this.writeFilestat(a, W, ((n = this.files.get(s)) == null ? void 0 : n.byteLength) ?? 0), u) : this.dirs.has(s) ? (this.writeFilestat(a, O, 0), u) : C : x;
|
|
377
377
|
}
|
|
378
|
-
pathOpen(t, r, o, a, s,
|
|
378
|
+
pathOpen(t, r, o, a, s, n) {
|
|
379
379
|
var i;
|
|
380
|
-
const
|
|
381
|
-
if (!
|
|
380
|
+
const c = this.readPath(t, r, o);
|
|
381
|
+
if (!c)
|
|
382
382
|
return x;
|
|
383
|
-
if (a &
|
|
384
|
-
return
|
|
385
|
-
if (!!(a &
|
|
386
|
-
return this.dirs.has(
|
|
387
|
-
if (this.files.has(
|
|
388
|
-
a &
|
|
383
|
+
if (a & H && a & bt && (this.files.has(c) || this.dirs.has(c)))
|
|
384
|
+
return wt;
|
|
385
|
+
if (!!(a & yt))
|
|
386
|
+
return this.dirs.has(c) ? this.openDescriptor({ kind: "dir", path: c, position: 0 }, n) : this.files.has(c) ? G : C;
|
|
387
|
+
if (this.files.has(c))
|
|
388
|
+
a & vt && this.files.set(c, new Uint8Array());
|
|
389
389
|
else {
|
|
390
|
-
if (!(a &
|
|
391
|
-
return this.dirs.has(
|
|
392
|
-
this.ensureParentDir(
|
|
390
|
+
if (!(a & H))
|
|
391
|
+
return this.dirs.has(c) ? S : C;
|
|
392
|
+
this.ensureParentDir(c), this.files.set(c, new Uint8Array());
|
|
393
393
|
}
|
|
394
394
|
return this.openDescriptor(
|
|
395
395
|
{
|
|
396
396
|
kind: "file",
|
|
397
|
-
path:
|
|
398
|
-
position: s &
|
|
399
|
-
append: !!(s &
|
|
397
|
+
path: c,
|
|
398
|
+
position: s & V ? ((i = this.files.get(c)) == null ? void 0 : i.byteLength) ?? 0 : 0,
|
|
399
|
+
append: !!(s & V)
|
|
400
400
|
},
|
|
401
|
-
|
|
401
|
+
n
|
|
402
402
|
);
|
|
403
403
|
}
|
|
404
404
|
pathRemoveDirectory(t, r, o) {
|
|
@@ -406,13 +406,13 @@ class ot {
|
|
|
406
406
|
if (!a)
|
|
407
407
|
return x;
|
|
408
408
|
if (a === "/" || a === "/work")
|
|
409
|
-
return
|
|
409
|
+
return I;
|
|
410
410
|
for (const s of this.dirs)
|
|
411
|
-
if (s !== a &&
|
|
412
|
-
return
|
|
411
|
+
if (s !== a && N(s) === a)
|
|
412
|
+
return I;
|
|
413
413
|
for (const s of this.files.keys())
|
|
414
|
-
if (
|
|
415
|
-
return
|
|
414
|
+
if (N(s) === a)
|
|
415
|
+
return I;
|
|
416
416
|
return this.dirs.delete(a) ? u : C;
|
|
417
417
|
}
|
|
418
418
|
pathUnlinkFile(t, r, o) {
|
|
@@ -434,8 +434,8 @@ class ot {
|
|
|
434
434
|
writeStringList(t, r, o) {
|
|
435
435
|
let a = o;
|
|
436
436
|
for (let s = 0; s < t.length; s += 1) {
|
|
437
|
-
const
|
|
438
|
-
this.view.setUint32(r + s * 4, a, !0), this.bytes.set(
|
|
437
|
+
const n = new TextEncoder().encode(t[s]);
|
|
438
|
+
this.view.setUint32(r + s * 4, a, !0), this.bytes.set(n, a), this.bytes[a + n.byteLength] = 0, a += n.byteLength + 1;
|
|
439
439
|
}
|
|
440
440
|
return u;
|
|
441
441
|
}
|
|
@@ -452,7 +452,7 @@ class ot {
|
|
|
452
452
|
if (!a || a.kind !== "dir")
|
|
453
453
|
return null;
|
|
454
454
|
const s = new TextDecoder().decode(this.bytes.subarray(r, r + o));
|
|
455
|
-
return
|
|
455
|
+
return _t(a.path, s);
|
|
456
456
|
}
|
|
457
457
|
openDescriptor(t, r) {
|
|
458
458
|
const o = this.nextFd++;
|
|
@@ -462,45 +462,45 @@ class ot {
|
|
|
462
462
|
this.bytes.fill(0, t, t + 64), this.bytes[t + 16] = r, this.view.setBigUint64(t + 24, 1n, !0), this.view.setBigUint64(t + 32, BigInt(o), !0);
|
|
463
463
|
}
|
|
464
464
|
writeInitialFile(t, r) {
|
|
465
|
-
const o =
|
|
465
|
+
const o = j(t);
|
|
466
466
|
this.ensureParentDir(o);
|
|
467
467
|
const a = new Uint8Array(r.byteLength);
|
|
468
468
|
a.set(r), this.files.set(o, a);
|
|
469
469
|
}
|
|
470
470
|
ensureParentDir(t) {
|
|
471
|
-
const r =
|
|
471
|
+
const r = N(t);
|
|
472
472
|
r === t || this.dirs.has(r) || (this.ensureParentDir(r), this.dirs.add(r));
|
|
473
473
|
}
|
|
474
474
|
writeFileChunk(t, r) {
|
|
475
475
|
if (!r.byteLength) return;
|
|
476
476
|
const o = this.files.get(t.path) ?? new Uint8Array(), a = t.append ? o.byteLength : t.position, s = Math.max(o.byteLength, a + r.byteLength);
|
|
477
|
-
let
|
|
477
|
+
let n;
|
|
478
478
|
if (s <= o.buffer.byteLength)
|
|
479
|
-
|
|
479
|
+
n = new Uint8Array(o.buffer, 0, s);
|
|
480
480
|
else {
|
|
481
|
-
const
|
|
482
|
-
|
|
481
|
+
const c = new Uint8Array(Math.max(s, o.buffer.byteLength * 2));
|
|
482
|
+
c.set(o), n = c.subarray(0, s);
|
|
483
483
|
}
|
|
484
|
-
|
|
484
|
+
n.set(r, a), this.files.set(t.path, n), t.position = a + r.byteLength;
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
|
-
function
|
|
487
|
+
function kt(e) {
|
|
488
488
|
return e.reduce((t, r) => t + new TextEncoder().encode(r).byteLength + 1, 0);
|
|
489
489
|
}
|
|
490
|
-
function
|
|
490
|
+
function jt(e) {
|
|
491
491
|
switch (e.kind) {
|
|
492
492
|
case "dir":
|
|
493
|
-
return N;
|
|
494
|
-
case "file":
|
|
495
493
|
return O;
|
|
494
|
+
case "file":
|
|
495
|
+
return W;
|
|
496
496
|
default:
|
|
497
|
-
return
|
|
497
|
+
return ot;
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
|
-
function
|
|
501
|
-
return t.startsWith("/") ?
|
|
500
|
+
function _t(e, t) {
|
|
501
|
+
return t.startsWith("/") ? j(t) : j(`${e}/${t}`);
|
|
502
502
|
}
|
|
503
|
-
function
|
|
503
|
+
function j(e) {
|
|
504
504
|
const t = [];
|
|
505
505
|
for (const r of e.replace(/\\/g, "/").split("/"))
|
|
506
506
|
if (!(!r || r === ".")) {
|
|
@@ -512,14 +512,34 @@ function _(e) {
|
|
|
512
512
|
}
|
|
513
513
|
return `/${t.join("/")}`;
|
|
514
514
|
}
|
|
515
|
-
function
|
|
516
|
-
const t =
|
|
515
|
+
function N(e) {
|
|
516
|
+
const t = j(e);
|
|
517
517
|
if (t === "/")
|
|
518
518
|
return "/";
|
|
519
519
|
const r = t.lastIndexOf("/");
|
|
520
520
|
return r <= 0 ? "/" : t.slice(0, r);
|
|
521
521
|
}
|
|
522
|
-
const
|
|
522
|
+
const st = [
|
|
523
|
+
{
|
|
524
|
+
sourceFormat: "psd",
|
|
525
|
+
targetFormat: "png"
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
sourceFormat: "psb",
|
|
529
|
+
targetFormat: "png"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
sourceFormat: "ai",
|
|
533
|
+
targetFormat: "pdf"
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
sourceFormat: "eps",
|
|
537
|
+
targetFormat: "pdf"
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
sourceFormat: "ps",
|
|
541
|
+
targetFormat: "pdf"
|
|
542
|
+
},
|
|
523
543
|
{
|
|
524
544
|
sourceFormat: "docx",
|
|
525
545
|
targetFormat: "docx"
|
|
@@ -1744,7 +1764,7 @@ const at = [
|
|
|
1744
1764
|
sourceFormat: "ppm",
|
|
1745
1765
|
targetFormat: "png"
|
|
1746
1766
|
}
|
|
1747
|
-
],
|
|
1767
|
+
], Et = [
|
|
1748
1768
|
{
|
|
1749
1769
|
sourceFormat: "dng",
|
|
1750
1770
|
targetFormat: "jpg"
|
|
@@ -1837,116 +1857,116 @@ const at = [
|
|
|
1837
1857
|
sourceFormat: "icns",
|
|
1838
1858
|
targetFormat: "png"
|
|
1839
1859
|
}
|
|
1840
|
-
],
|
|
1841
|
-
|
|
1842
|
-
),
|
|
1843
|
-
|
|
1860
|
+
], St = new Set(
|
|
1861
|
+
st.map((e) => k(e.sourceFormat))
|
|
1862
|
+
), Ct = new Set(
|
|
1863
|
+
st.map(
|
|
1844
1864
|
(e) => `${k(e.sourceFormat)}->${k(e.targetFormat)}`
|
|
1845
1865
|
)
|
|
1846
|
-
),
|
|
1847
|
-
|
|
1866
|
+
), At = new Set(
|
|
1867
|
+
Et.map(
|
|
1848
1868
|
(e) => `${k(e.sourceFormat)}->${k(e.targetFormat)}`
|
|
1849
1869
|
)
|
|
1850
1870
|
);
|
|
1851
|
-
class
|
|
1871
|
+
class L extends Error {
|
|
1852
1872
|
constructor(t) {
|
|
1853
1873
|
super(t.errorMessage || t.errorCode || "WASM conversion failed."), this.result = t, this.name = "WasmConversionError";
|
|
1854
1874
|
}
|
|
1855
1875
|
}
|
|
1856
|
-
function
|
|
1857
|
-
const t =
|
|
1876
|
+
function Kt(e) {
|
|
1877
|
+
const t = T(e), r = e.officeWasm ? T({ wasm: e.officeWasm, fetch: e.fetch }) : void 0, o = e.postscriptWasm ? T({ wasm: e.postscriptWasm, fetch: e.fetch }) : void 0, a = e.imageWasm ? D(() => rt(e.imageWasm, e.fetch)) : void 0, s = e.imageWasm ? T({ wasm: a, fetch: e.fetch }) : void 0, n = a ? Tt(a) : void 0;
|
|
1858
1878
|
return {
|
|
1859
|
-
async convert(c,
|
|
1860
|
-
|
|
1861
|
-
const
|
|
1862
|
-
|
|
1863
|
-
const
|
|
1879
|
+
async convert(c, m) {
|
|
1880
|
+
p(m.signal);
|
|
1881
|
+
const i = k(c.sourceFormat), d = k(c.targetFormat), l = Ut(i, d), h = `/work/input.${i}`, g = `/work/output.${d}`, A = "/work/options.json", _ = "/work/result.json", R = await tt(c.source, e.fetch, m.signal);
|
|
1882
|
+
p(m.signal);
|
|
1883
|
+
const ut = JSON.stringify({
|
|
1864
1884
|
...c.password ? { password: c.password } : {},
|
|
1865
1885
|
...c.locale ? { locale: c.locale } : {}
|
|
1866
|
-
}),
|
|
1867
|
-
if (
|
|
1868
|
-
const v = await
|
|
1869
|
-
if (
|
|
1886
|
+
}), B = !!(s && At.has(l));
|
|
1887
|
+
if (B && d === "jpg" && n) {
|
|
1888
|
+
const v = await n(R, m.signal);
|
|
1889
|
+
if (p(m.signal), v) return v;
|
|
1870
1890
|
}
|
|
1871
|
-
const
|
|
1891
|
+
const dt = !!(o && d === "pdf" && ["eps", "ps", "ai"].includes(i)) ? o : B ? s : t, M = (v, pt) => v({
|
|
1872
1892
|
args: [
|
|
1873
|
-
|
|
1893
|
+
B ? "converter-image" : "converter-core",
|
|
1874
1894
|
"--input",
|
|
1875
|
-
|
|
1895
|
+
h,
|
|
1876
1896
|
"--output",
|
|
1877
1897
|
g,
|
|
1878
1898
|
"--source",
|
|
1879
|
-
m,
|
|
1880
|
-
"--target",
|
|
1881
1899
|
i,
|
|
1900
|
+
"--target",
|
|
1901
|
+
d,
|
|
1882
1902
|
"--options",
|
|
1883
|
-
|
|
1903
|
+
A,
|
|
1884
1904
|
"--result",
|
|
1885
|
-
|
|
1905
|
+
_
|
|
1886
1906
|
],
|
|
1887
1907
|
files: {
|
|
1888
|
-
[
|
|
1889
|
-
[
|
|
1908
|
+
[h]: pt,
|
|
1909
|
+
[A]: new TextEncoder().encode(ut)
|
|
1890
1910
|
},
|
|
1891
|
-
readFiles: [
|
|
1892
|
-
signal:
|
|
1911
|
+
readFiles: [_, g],
|
|
1912
|
+
signal: m.signal
|
|
1893
1913
|
});
|
|
1894
|
-
let E = await
|
|
1914
|
+
let E = await M(dt, R), b = U(E.files[_]);
|
|
1895
1915
|
if (!b.ok && b.errorCode === "engine_unavailable" && b.requiredModule === "office" && r) {
|
|
1896
|
-
const v = await
|
|
1897
|
-
|
|
1916
|
+
const v = await M(r, R);
|
|
1917
|
+
Y(U(v.files[_]), v.exitCode), E = await M(t, v.files[g]), b = U(E.files[_]);
|
|
1898
1918
|
}
|
|
1899
|
-
return
|
|
1919
|
+
return p(m.signal), Y(b, E.exitCode), {
|
|
1900
1920
|
source: E.files[g],
|
|
1901
|
-
format: k(b.targetFormat ||
|
|
1921
|
+
format: k(b.targetFormat || d),
|
|
1902
1922
|
contentType: b.contentType,
|
|
1903
1923
|
warnings: b.warnings
|
|
1904
1924
|
};
|
|
1905
1925
|
}
|
|
1906
1926
|
};
|
|
1907
1927
|
}
|
|
1908
|
-
function
|
|
1909
|
-
if (!e.ok) throw new
|
|
1928
|
+
function Y(e, t) {
|
|
1929
|
+
if (!e.ok) throw new L(e);
|
|
1910
1930
|
if (t !== 0)
|
|
1911
|
-
throw new
|
|
1931
|
+
throw new L({
|
|
1912
1932
|
...e,
|
|
1913
1933
|
ok: !1,
|
|
1914
1934
|
errorCode: e.errorCode || "conversion_failed",
|
|
1915
1935
|
errorMessage: e.errorMessage || `converter WASM exited with code ${t}`
|
|
1916
1936
|
});
|
|
1917
1937
|
}
|
|
1918
|
-
function
|
|
1938
|
+
function Tt(e) {
|
|
1919
1939
|
const t = D(async () => {
|
|
1920
|
-
const r = await e(), o = new Set(WebAssembly.Module.exports(r).map((
|
|
1921
|
-
if (!["filens_image_alloc", "filens_image_free", "filens_image_preview", "memory"].every((
|
|
1922
|
-
const a = new
|
|
1940
|
+
const r = await e(), o = new Set(WebAssembly.Module.exports(r).map((n) => n.name));
|
|
1941
|
+
if (!["filens_image_alloc", "filens_image_free", "filens_image_preview", "memory"].every((n) => o.has(n))) return null;
|
|
1942
|
+
const a = new at({ args: ["converter-image"], files: {} }), s = await WebAssembly.instantiate(r, { wasi_snapshot_preview1: a.imports });
|
|
1923
1943
|
return a.setInstance(s), s.exports;
|
|
1924
1944
|
});
|
|
1925
1945
|
return async (r, o) => {
|
|
1926
1946
|
const a = await f(t(), o);
|
|
1927
|
-
if (
|
|
1928
|
-
let s = 0,
|
|
1947
|
+
if (p(o), !a || r.length === 0) return null;
|
|
1948
|
+
let s = 0, n = 0, c = 0;
|
|
1929
1949
|
try {
|
|
1930
1950
|
if (s = a.filens_image_alloc(r.length) >>> 0, !s) throw new Error("Image core could not allocate its input buffer.");
|
|
1931
1951
|
new Uint8Array(a.memory.buffer).set(r, s);
|
|
1932
1952
|
const m = a.filens_image_preview(s, r.length);
|
|
1933
|
-
if (
|
|
1934
|
-
const i = new Uint8Array(a.memory.buffer,
|
|
1935
|
-
if (
|
|
1936
|
-
const l =
|
|
1937
|
-
if (!l.ok) throw new
|
|
1938
|
-
return { source: i.slice(4 +
|
|
1953
|
+
if (n = Number(m & 0xffffffffn), c = Number(m >> 32n), !n || c < 4 || n + c > a.memory.buffer.byteLength) throw new Error("Image core returned an invalid preview buffer.");
|
|
1954
|
+
const i = new Uint8Array(a.memory.buffer, n, c), d = new DataView(i.buffer, i.byteOffset, 4).getUint32(0, !0);
|
|
1955
|
+
if (d > i.length - 4) throw new Error("Image core returned invalid preview metadata.");
|
|
1956
|
+
const l = U(i.subarray(4, 4 + d));
|
|
1957
|
+
if (!l.ok) throw new L(l);
|
|
1958
|
+
return { source: i.slice(4 + d), format: "jpg", contentType: l.contentType, warnings: l.warnings };
|
|
1939
1959
|
} finally {
|
|
1940
|
-
|
|
1960
|
+
n && c && a.filens_image_free(n, c), s && a.filens_image_free(s, r.length);
|
|
1941
1961
|
}
|
|
1942
1962
|
};
|
|
1943
1963
|
}
|
|
1944
|
-
function
|
|
1964
|
+
function Ut(e, t) {
|
|
1945
1965
|
const r = `${e}->${t}`;
|
|
1946
|
-
if (
|
|
1966
|
+
if (Ct.has(r))
|
|
1947
1967
|
return r;
|
|
1948
|
-
const o =
|
|
1949
|
-
throw new
|
|
1968
|
+
const o = St.has(e) ? `unsupported conversion pair: ${e} -> ${t}` : `unsupported source format: ${e}`;
|
|
1969
|
+
throw new L({
|
|
1950
1970
|
ok: !1,
|
|
1951
1971
|
sourceFormat: e,
|
|
1952
1972
|
targetFormat: t,
|
|
@@ -1956,7 +1976,7 @@ function Tt(e, t) {
|
|
|
1956
1976
|
metrics: {}
|
|
1957
1977
|
});
|
|
1958
1978
|
}
|
|
1959
|
-
function
|
|
1979
|
+
function U(e) {
|
|
1960
1980
|
const t = new TextDecoder().decode(e), r = JSON.parse(t);
|
|
1961
1981
|
return {
|
|
1962
1982
|
...r,
|
|
@@ -1966,60 +1986,60 @@ function A(e) {
|
|
|
1966
1986
|
function k(e) {
|
|
1967
1987
|
return e.trim().replace(/^\./, "").toLowerCase();
|
|
1968
1988
|
}
|
|
1969
|
-
const
|
|
1970
|
-
function
|
|
1989
|
+
const J = 64 * 1024 * 1024;
|
|
1990
|
+
function Xt() {
|
|
1971
1991
|
return {
|
|
1972
1992
|
async convert(e, t) {
|
|
1973
1993
|
const r = e.sourceFormat.replace(/^\./, "").toLowerCase(), o = e.targetFormat.replace(/^\./, "").toLowerCase();
|
|
1974
1994
|
if (!(["heic", "heif"].includes(r) && o === "png"))
|
|
1975
1995
|
throw new Error(`Unsupported media conversion: ${r} -> ${o}.`);
|
|
1976
|
-
if (
|
|
1996
|
+
if (p(t.signal), (e.source instanceof Blob ? e.source.size : typeof e.source == "string" ? 0 : e.source.byteLength) > J)
|
|
1977
1997
|
throw new Error("HEIF input exceeds the 64 MiB preview limit.");
|
|
1978
|
-
const a = ArrayBuffer.isView(e.source) ? e.source.slice() : e.source instanceof ArrayBuffer ? e.source.slice(0) : e.source, s = await
|
|
1979
|
-
|
|
1980
|
-
const
|
|
1981
|
-
return
|
|
1998
|
+
const a = ArrayBuffer.isView(e.source) ? e.source.slice() : e.source instanceof ArrayBuffer ? e.source.slice(0) : e.source, s = await tt(a, globalThis.fetch, t.signal, J);
|
|
1999
|
+
p(t.signal);
|
|
2000
|
+
const n = await f(import("./media-runtime-Chg4A2un.js"), t.signal);
|
|
2001
|
+
return p(t.signal), n.convertMedia(s, r, t.signal);
|
|
1982
2002
|
}
|
|
1983
2003
|
};
|
|
1984
2004
|
}
|
|
1985
|
-
class
|
|
2005
|
+
class ct extends Error {
|
|
1986
2006
|
constructor(t, r, o) {
|
|
1987
2007
|
const a = `Conversion failed: ${t} ${r}`.trim(), s = (o == null ? void 0 : o.errorMessage) || (o == null ? void 0 : o.errorCode);
|
|
1988
2008
|
super(s ? `${a}: ${s}` : a), this.status = t, this.statusText = r, this.result = o, this.name = "HttpConversionError";
|
|
1989
2009
|
}
|
|
1990
2010
|
}
|
|
1991
|
-
function
|
|
2011
|
+
function Qt(e) {
|
|
1992
2012
|
const t = e.fetch ?? globalThis.fetch;
|
|
1993
2013
|
if (!t)
|
|
1994
2014
|
throw new Error("A fetch implementation is required for HTTP conversion.");
|
|
1995
2015
|
return {
|
|
1996
2016
|
async convert(r, o) {
|
|
1997
2017
|
const a = o.signal;
|
|
1998
|
-
|
|
2018
|
+
p(a);
|
|
1999
2019
|
const s = new FormData();
|
|
2000
|
-
s.set("sourceFormat", r.sourceFormat), s.set("targetFormat", r.targetFormat), r.name && s.set("name", r.name), r.password && s.set("password", r.password), r.locale && s.set("locale", r.locale), s.set("file", await
|
|
2001
|
-
const
|
|
2002
|
-
|
|
2003
|
-
const
|
|
2020
|
+
s.set("sourceFormat", r.sourceFormat), s.set("targetFormat", r.targetFormat), r.name && s.set("name", r.name), r.password && s.set("password", r.password), r.locale && s.set("locale", r.locale), s.set("file", await Mt(r.source, r, t, a), Dt(r)), p(a);
|
|
2021
|
+
const n = typeof e.headers == "function" ? e.headers(r) : e.headers;
|
|
2022
|
+
p(a);
|
|
2023
|
+
const c = await f(t(e.endpoint, {
|
|
2004
2024
|
method: "POST",
|
|
2005
2025
|
body: s,
|
|
2006
2026
|
signal: a,
|
|
2007
2027
|
credentials: e.credentials,
|
|
2008
|
-
headers:
|
|
2028
|
+
headers: n
|
|
2009
2029
|
}), a);
|
|
2010
|
-
if (
|
|
2011
|
-
throw await f(
|
|
2030
|
+
if (p(a), !c.ok)
|
|
2031
|
+
throw await f(Lt(c, r), a);
|
|
2012
2032
|
if ((e.responseType ?? "json") === "blob")
|
|
2013
|
-
return f(
|
|
2014
|
-
const m = await f(
|
|
2015
|
-
return
|
|
2033
|
+
return f(Nt(c, r.targetFormat), a);
|
|
2034
|
+
const m = await f(c.json(), a);
|
|
2035
|
+
return p(a), It(m, r, c);
|
|
2016
2036
|
}
|
|
2017
2037
|
};
|
|
2018
2038
|
}
|
|
2019
|
-
async function
|
|
2020
|
-
return new
|
|
2039
|
+
async function Lt(e, t) {
|
|
2040
|
+
return new ct(e.status, e.statusText, await Rt(e, t));
|
|
2021
2041
|
}
|
|
2022
|
-
function
|
|
2042
|
+
function Zt(e) {
|
|
2023
2043
|
return {
|
|
2024
2044
|
async convert(t) {
|
|
2025
2045
|
const r = e.find(
|
|
@@ -2037,7 +2057,7 @@ function Xt(e) {
|
|
|
2037
2057
|
}
|
|
2038
2058
|
};
|
|
2039
2059
|
}
|
|
2040
|
-
async function
|
|
2060
|
+
async function Rt(e, t) {
|
|
2041
2061
|
var a;
|
|
2042
2062
|
const r = ((a = e.headers.get("content-type")) == null ? void 0 : a.toLowerCase()) ?? "";
|
|
2043
2063
|
if (r.includes("application/json") || r.includes("+json"))
|
|
@@ -2046,7 +2066,7 @@ async function Lt(e, t) {
|
|
|
2046
2066
|
} catch {
|
|
2047
2067
|
return;
|
|
2048
2068
|
}
|
|
2049
|
-
const o =
|
|
2069
|
+
const o = Bt(e.headers, t);
|
|
2050
2070
|
return o.errorCode || o.errorMessage ? o : void 0;
|
|
2051
2071
|
}
|
|
2052
2072
|
function nt(e, t) {
|
|
@@ -2067,7 +2087,7 @@ function nt(e, t) {
|
|
|
2067
2087
|
metrics: r.metrics && typeof r.metrics == "object" ? r.metrics : void 0
|
|
2068
2088
|
};
|
|
2069
2089
|
}
|
|
2070
|
-
function
|
|
2090
|
+
function Bt(e, t) {
|
|
2071
2091
|
return {
|
|
2072
2092
|
ok: w(e, "x-preview-ok") === "true" ? !0 : w(e, "x-preview-ok") === "false" ? !1 : void 0,
|
|
2073
2093
|
format: w(e, "x-preview-format") ?? void 0,
|
|
@@ -2075,25 +2095,25 @@ function Rt(e, t) {
|
|
|
2075
2095
|
targetFormat: w(e, "x-preview-target-format") ?? F(t.targetFormat),
|
|
2076
2096
|
backend: w(e, "x-preview-backend") ?? void 0,
|
|
2077
2097
|
fidelity: w(e, "x-preview-fidelity") ?? void 0,
|
|
2078
|
-
warnings:
|
|
2098
|
+
warnings: it(e) ?? [],
|
|
2079
2099
|
errorCode: w(e, "x-preview-error-code") ?? void 0,
|
|
2080
2100
|
errorMessage: w(e, "x-preview-error-message") ?? void 0
|
|
2081
2101
|
};
|
|
2082
2102
|
}
|
|
2083
|
-
async function
|
|
2103
|
+
async function Mt(e, t, r, o) {
|
|
2084
2104
|
const a = zt(t.name, t.sourceFormat);
|
|
2085
2105
|
if (e instanceof Blob)
|
|
2086
2106
|
return e.type || a === "application/octet-stream" ? e : new Blob([e], {
|
|
2087
2107
|
type: a
|
|
2088
2108
|
});
|
|
2089
2109
|
if (typeof e == "string") {
|
|
2090
|
-
if (
|
|
2091
|
-
return
|
|
2092
|
-
if (
|
|
2110
|
+
if (Q(e))
|
|
2111
|
+
return Wt(e, a);
|
|
2112
|
+
if (X(e)) {
|
|
2093
2113
|
const s = await f(r(e, { signal: o }), o);
|
|
2094
|
-
if (
|
|
2095
|
-
const
|
|
2096
|
-
return
|
|
2114
|
+
if (p(o), !s.ok) throw new Error(`Failed to fetch conversion source: ${s.status} ${s.statusText}`.trim());
|
|
2115
|
+
const n = await f(s.blob(), o);
|
|
2116
|
+
return p(o), n.type ? n : new Blob([n], { type: a });
|
|
2097
2117
|
}
|
|
2098
2118
|
return new Blob([e], {
|
|
2099
2119
|
type: a === "application/octet-stream" ? "text/plain" : a
|
|
@@ -2102,8 +2122,8 @@ async function Bt(e, t, r, o) {
|
|
|
2102
2122
|
if (ArrayBuffer.isView(e)) {
|
|
2103
2123
|
const s = new Uint8Array(e.buffer, e.byteOffset, e.byteLength);
|
|
2104
2124
|
if (s.buffer instanceof ArrayBuffer) return new Blob([s], { type: a });
|
|
2105
|
-
const
|
|
2106
|
-
return
|
|
2125
|
+
const n = new Uint8Array(s.byteLength);
|
|
2126
|
+
return n.set(s), new Blob([n.buffer], {
|
|
2107
2127
|
type: a
|
|
2108
2128
|
});
|
|
2109
2129
|
}
|
|
@@ -2111,13 +2131,13 @@ async function Bt(e, t, r, o) {
|
|
|
2111
2131
|
type: a
|
|
2112
2132
|
});
|
|
2113
2133
|
}
|
|
2114
|
-
function
|
|
2134
|
+
function It(e, t, r) {
|
|
2115
2135
|
if (!e || typeof e != "object")
|
|
2116
2136
|
throw new Error("Conversion response must be a JSON object.");
|
|
2117
2137
|
const o = e;
|
|
2118
2138
|
if (o.ok === !1 || typeof o.errorCode == "string" || typeof o.errorMessage == "string")
|
|
2119
|
-
throw new
|
|
2120
|
-
const a =
|
|
2139
|
+
throw new ct(r.status, r.statusText, nt(o, t));
|
|
2140
|
+
const a = Ot(o), s = String(o.format ?? o.targetFormat ?? t.targetFormat);
|
|
2121
2141
|
return {
|
|
2122
2142
|
source: a,
|
|
2123
2143
|
format: s,
|
|
@@ -2126,33 +2146,33 @@ function Mt(e, t, r) {
|
|
|
2126
2146
|
cacheKey: typeof o.cacheKey == "string" ? o.cacheKey : void 0
|
|
2127
2147
|
};
|
|
2128
2148
|
}
|
|
2129
|
-
async function
|
|
2149
|
+
async function Nt(e, t) {
|
|
2130
2150
|
return {
|
|
2131
2151
|
source: await e.blob(),
|
|
2132
2152
|
format: w(e.headers, "x-preview-format") ?? t,
|
|
2133
2153
|
contentType: e.headers.get("content-type") ?? void 0,
|
|
2134
|
-
warnings:
|
|
2154
|
+
warnings: it(e.headers),
|
|
2135
2155
|
cacheKey: w(e.headers, "x-preview-cache-key")
|
|
2136
2156
|
};
|
|
2137
2157
|
}
|
|
2138
|
-
function
|
|
2158
|
+
function Ot(e) {
|
|
2139
2159
|
if (typeof e.url == "string")
|
|
2140
2160
|
return e.url;
|
|
2141
2161
|
if (typeof e.dataUrl == "string")
|
|
2142
2162
|
return e.dataUrl;
|
|
2143
2163
|
if (typeof e.base64 == "string")
|
|
2144
|
-
return
|
|
2164
|
+
return Z(e.base64);
|
|
2145
2165
|
if (typeof e.text == "string")
|
|
2146
2166
|
return new TextEncoder().encode(e.text);
|
|
2147
2167
|
throw new Error("Conversion JSON response must include url, dataUrl, base64, or text.");
|
|
2148
2168
|
}
|
|
2149
|
-
function
|
|
2150
|
-
const { bytes: r, contentType: o } =
|
|
2169
|
+
function Wt(e, t = "application/octet-stream") {
|
|
2170
|
+
const { bytes: r, contentType: o } = q(e);
|
|
2151
2171
|
return new Blob([r], {
|
|
2152
2172
|
type: o ?? t
|
|
2153
2173
|
});
|
|
2154
2174
|
}
|
|
2155
|
-
function
|
|
2175
|
+
function it(e) {
|
|
2156
2176
|
const t = w(e, "x-preview-warnings");
|
|
2157
2177
|
if (t)
|
|
2158
2178
|
try {
|
|
@@ -2167,19 +2187,19 @@ function w(e, t) {
|
|
|
2167
2187
|
}
|
|
2168
2188
|
function Dt(e) {
|
|
2169
2189
|
const t = F(e.sourceFormat), r = F(e.targetFormat), o = t || r || "bin", a = $t(e.name) || `input.${o}`;
|
|
2170
|
-
return
|
|
2190
|
+
return mt(a) ? a : `${a}.${o}`;
|
|
2171
2191
|
}
|
|
2172
2192
|
function $t(e) {
|
|
2173
2193
|
var o, a;
|
|
2174
2194
|
const r = ((a = (((o = String(e ?? "").split(/[?#]/, 1)[0]) == null ? void 0 : o.trim()) ?? "").split(/[\\/]/).pop()) == null ? void 0 : a.trim()) ?? "";
|
|
2175
|
-
return
|
|
2195
|
+
return Pt(r);
|
|
2176
2196
|
}
|
|
2177
|
-
function
|
|
2197
|
+
function Pt(e) {
|
|
2178
2198
|
const t = e.replace(/[^\w.+-]+/g, "_").replace(/^_+|_+$/g, "");
|
|
2179
2199
|
return !t || t === "." || t === ".." ? "" : t;
|
|
2180
2200
|
}
|
|
2181
2201
|
function zt(e, t) {
|
|
2182
|
-
const r =
|
|
2202
|
+
const r = mt(e);
|
|
2183
2203
|
switch (F(r || t || "")) {
|
|
2184
2204
|
case "dng":
|
|
2185
2205
|
case "cr2":
|
|
@@ -2217,6 +2237,14 @@ function zt(e, t) {
|
|
|
2217
2237
|
return "image/x-icon";
|
|
2218
2238
|
case "icns":
|
|
2219
2239
|
return "application/x-icns";
|
|
2240
|
+
case "psd":
|
|
2241
|
+
case "psb":
|
|
2242
|
+
return "image/vnd.adobe.photoshop";
|
|
2243
|
+
case "ai":
|
|
2244
|
+
return "application/illustrator";
|
|
2245
|
+
case "eps":
|
|
2246
|
+
case "ps":
|
|
2247
|
+
return "application/postscript";
|
|
2220
2248
|
case "ppm":
|
|
2221
2249
|
return "image/x-portable-pixmap";
|
|
2222
2250
|
case "doc":
|
|
@@ -2697,15 +2725,15 @@ function zt(e, t) {
|
|
|
2697
2725
|
return "application/octet-stream";
|
|
2698
2726
|
}
|
|
2699
2727
|
}
|
|
2700
|
-
function
|
|
2728
|
+
function mt(e) {
|
|
2701
2729
|
var s;
|
|
2702
|
-
const r = (((s = String(e ?? "").split(/[?#]/, 1)[0]) == null ? void 0 : s.trim()) ?? "").split(/[\\/]/).pop() ?? "", o =
|
|
2730
|
+
const r = (((s = String(e ?? "").split(/[?#]/, 1)[0]) == null ? void 0 : s.trim()) ?? "").split(/[\\/]/).pop() ?? "", o = Gt(r);
|
|
2703
2731
|
if (o)
|
|
2704
2732
|
return o;
|
|
2705
2733
|
const a = r.lastIndexOf(".");
|
|
2706
2734
|
return a < 0 || a === r.length - 1 ? "" : a === 0 && r.indexOf(".", 1) < 0 ? F(r.slice(1)) : F(r.slice(a + 1));
|
|
2707
2735
|
}
|
|
2708
|
-
function
|
|
2736
|
+
function Gt(e) {
|
|
2709
2737
|
const t = e.trim().toLowerCase();
|
|
2710
2738
|
return t ? t === "dockerfile" || t.startsWith("dockerfile.") ? "dockerfile" : t === "makefile" || t === "gnumakefile" || t === "bsdmakefile" ? "make" : t === "cmakelists.txt" ? "cmake" : "" : "";
|
|
2711
2739
|
}
|
|
@@ -2713,12 +2741,12 @@ function F(e) {
|
|
|
2713
2741
|
return e.trim().replace(/^\./, "").toLowerCase();
|
|
2714
2742
|
}
|
|
2715
2743
|
export {
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2744
|
+
ct as H,
|
|
2745
|
+
L as W,
|
|
2746
|
+
Xt as a,
|
|
2747
|
+
Zt as b,
|
|
2748
|
+
Qt as c,
|
|
2749
|
+
Kt as d,
|
|
2750
|
+
T as e,
|
|
2751
|
+
p as t
|
|
2724
2752
|
};
|