@bevyra/avatar 0.0.0-stage → 0.1.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.
@@ -0,0 +1,1406 @@
1
+ /*!
2
+ * ONNX Runtime Web v1.23.2
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ var He = Object.defineProperty, Ar = Object.getOwnPropertyDescriptor, Or = Object.getOwnPropertyNames, Cr = Object.prototype.hasOwnProperty, Rr = ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (t, r) => (typeof require < "u" ? require : t)[r] }) : e)(function(e) {
7
+ if (typeof require < "u") return require.apply(this, arguments);
8
+ throw Error('Dynamic require of "' + e + '" is not supported');
9
+ }), b = (e, t) => () => (e && (t = e(e = 0)), t), qe = (e, t) => {
10
+ for (var r in t) He(e, r, { get: t[r], enumerable: !0 });
11
+ }, Ur = (e, t, r, n) => {
12
+ if (t && typeof t == "object" || typeof t == "function") for (let a of Or(t)) !Cr.call(e, a) && a !== r && He(e, a, { get: () => t[a], enumerable: !(n = Ar(t, a)) || n.enumerable });
13
+ return e;
14
+ }, Pt = (e) => Ur(He({}, "__esModule", { value: !0 }), e), ue, z, Oe, wt, $t, _t = b(() => {
15
+ ue = /* @__PURE__ */ new Map(), z = [], Oe = (e, t, r) => {
16
+ if (t && typeof t.init == "function" && typeof t.createInferenceSessionHandler == "function") {
17
+ let n = ue.get(e);
18
+ if (n === void 0) ue.set(e, { backend: t, priority: r });
19
+ else {
20
+ if (n.priority > r) return;
21
+ if (n.priority === r && n.backend !== t) throw new Error(`cannot register backend "${e}" using priority ${r}`);
22
+ }
23
+ if (r >= 0) {
24
+ let a = z.indexOf(e);
25
+ a !== -1 && z.splice(a, 1);
26
+ for (let i = 0; i < z.length; i++) if (ue.get(z[i]).priority <= r) {
27
+ z.splice(i, 0, e);
28
+ return;
29
+ }
30
+ z.push(e);
31
+ }
32
+ return;
33
+ }
34
+ throw new TypeError("not a valid backend");
35
+ }, wt = async (e) => {
36
+ let t = ue.get(e);
37
+ if (!t) return "backend not found.";
38
+ if (t.initialized) return t.backend;
39
+ if (t.aborted) return t.error;
40
+ {
41
+ let r = !!t.initPromise;
42
+ try {
43
+ return r || (t.initPromise = t.backend.init(e)), await t.initPromise, t.initialized = !0, t.backend;
44
+ } catch (n) {
45
+ return r || (t.error = `${n}`, t.aborted = !0), t.error;
46
+ } finally {
47
+ delete t.initPromise;
48
+ }
49
+ }
50
+ }, $t = async (e) => {
51
+ let t = e.executionProviders || [], r = t.map((s) => typeof s == "string" ? s : s.name), n = r.length === 0 ? z : r, a, i = [], o = /* @__PURE__ */ new Set();
52
+ for (let s of n) {
53
+ let u = await wt(s);
54
+ typeof u == "string" ? i.push({ name: s, err: u }) : (a || (a = u), a === u && o.add(s));
55
+ }
56
+ if (!a) throw new Error(`no available backend found. ERR: ${i.map((s) => `[${s.name}] ${s.err}`).join(", ")}`);
57
+ for (let { name: s, err: u } of i) r.includes(s) && console.warn(`removing requested execution provider "${s}" from session options because it is not available: ${u}`);
58
+ let l = t.filter((s) => o.has(typeof s == "string" ? s : s.name));
59
+ return [a, new Proxy(e, { get: (s, u) => u === "executionProviders" ? l : Reflect.get(s, u) })];
60
+ };
61
+ }), Lr = b(() => {
62
+ _t();
63
+ }), Mt, Ir = b(() => {
64
+ Mt = "1.23.2";
65
+ }), Le, I, St = b(() => {
66
+ Ir(), Le = "warning", I = { wasm: {}, webgl: {}, webgpu: {}, versions: { common: Mt }, set logLevel(e) {
67
+ if (e !== void 0) {
68
+ if (typeof e != "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(e) === -1) throw new Error(`Unsupported logging level: ${e}`);
69
+ Le = e;
70
+ }
71
+ }, get logLevel() {
72
+ return Le;
73
+ } }, Object.defineProperty(I, "logLevel", { enumerable: !0 });
74
+ }), A, xr = b(() => {
75
+ St(), A = I;
76
+ }), Bt, Nt, Pr = b(() => {
77
+ Bt = (e, t) => {
78
+ let r = typeof document < "u" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
79
+ r.width = e.dims[3], r.height = e.dims[2];
80
+ let n = r.getContext("2d");
81
+ if (n != null) {
82
+ let a, i;
83
+ t?.tensorLayout !== void 0 && t.tensorLayout === "NHWC" ? (a = e.dims[2], i = e.dims[3]) : (a = e.dims[3], i = e.dims[2]);
84
+ let o = t?.format !== void 0 ? t.format : "RGB", l = t?.norm, s, u;
85
+ l === void 0 || l.mean === void 0 ? s = [255, 255, 255, 255] : typeof l.mean == "number" ? s = [l.mean, l.mean, l.mean, l.mean] : (s = [l.mean[0], l.mean[1], l.mean[2], 0], l.mean[3] !== void 0 && (s[3] = l.mean[3])), l === void 0 || l.bias === void 0 ? u = [0, 0, 0, 0] : typeof l.bias == "number" ? u = [l.bias, l.bias, l.bias, l.bias] : (u = [l.bias[0], l.bias[1], l.bias[2], 0], l.bias[3] !== void 0 && (u[3] = l.bias[3]));
86
+ let f = i * a, p = 0, d = f, w = f * 2, h = -1;
87
+ o === "RGBA" ? (p = 0, d = f, w = f * 2, h = f * 3) : o === "RGB" ? (p = 0, d = f, w = f * 2) : o === "RBG" && (p = 0, w = f, d = f * 2);
88
+ for (let v = 0; v < i; v++) for (let C = 0; C < a; C++) {
89
+ let m = (e.data[p++] - u[0]) * s[0], c = (e.data[d++] - u[1]) * s[1], y = (e.data[w++] - u[2]) * s[2], E = h === -1 ? 255 : (e.data[h++] - u[3]) * s[3];
90
+ n.fillStyle = "rgba(" + m + "," + c + "," + y + "," + E + ")", n.fillRect(C, v, 1, 1);
91
+ }
92
+ if ("toDataURL" in r) return r.toDataURL();
93
+ throw new Error("toDataURL is not supported");
94
+ } else throw new Error("Can not access image data");
95
+ }, Nt = (e, t) => {
96
+ let r = typeof document < "u" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d"), n;
97
+ if (r != null) {
98
+ let a, i, o;
99
+ t?.tensorLayout !== void 0 && t.tensorLayout === "NHWC" ? (a = e.dims[2], i = e.dims[1], o = e.dims[3]) : (a = e.dims[3], i = e.dims[2], o = e.dims[1]);
100
+ let l = t !== void 0 && t.format !== void 0 ? t.format : "RGB", s = t?.norm, u, f;
101
+ s === void 0 || s.mean === void 0 ? u = [255, 255, 255, 255] : typeof s.mean == "number" ? u = [s.mean, s.mean, s.mean, s.mean] : (u = [s.mean[0], s.mean[1], s.mean[2], 255], s.mean[3] !== void 0 && (u[3] = s.mean[3])), s === void 0 || s.bias === void 0 ? f = [0, 0, 0, 0] : typeof s.bias == "number" ? f = [s.bias, s.bias, s.bias, s.bias] : (f = [s.bias[0], s.bias[1], s.bias[2], 0], s.bias[3] !== void 0 && (f[3] = s.bias[3]));
102
+ let p = i * a;
103
+ if (t !== void 0 && (t.format !== void 0 && o === 4 && t.format !== "RGBA" || o === 3 && t.format !== "RGB" && t.format !== "BGR")) throw new Error("Tensor format doesn't match input tensor dims");
104
+ let d = 4, w = 0, h = 1, v = 2, C = 3, m = 0, c = p, y = p * 2, E = -1;
105
+ l === "RGBA" ? (m = 0, c = p, y = p * 2, E = p * 3) : l === "RGB" ? (m = 0, c = p, y = p * 2) : l === "RBG" && (m = 0, y = p, c = p * 2), n = r.createImageData(a, i);
106
+ for (let x = 0; x < i * a; w += d, h += d, v += d, C += d, x++) n.data[w] = (e.data[m++] - f[0]) * u[0], n.data[h] = (e.data[c++] - f[1]) * u[1], n.data[v] = (e.data[y++] - f[2]) * u[2], n.data[C] = E === -1 ? 255 : (e.data[E++] - f[3]) * u[3];
107
+ } else throw new Error("Can not access image data");
108
+ return n;
109
+ };
110
+ }), ye, kt, Dt, Gt, Ft, jt, $r = b(() => {
111
+ Ze(), ye = (e, t) => {
112
+ if (e === void 0) throw new Error("Image buffer must be defined");
113
+ if (t.height === void 0 || t.width === void 0) throw new Error("Image height and width must be defined");
114
+ if (t.tensorLayout === "NHWC") throw new Error("NHWC Tensor layout is not supported yet");
115
+ let { height: r, width: n } = t, a = t.norm ?? { mean: 255, bias: 0 }, i, o;
116
+ typeof a.mean == "number" ? i = [a.mean, a.mean, a.mean, a.mean] : i = [a.mean[0], a.mean[1], a.mean[2], a.mean[3] ?? 255], typeof a.bias == "number" ? o = [a.bias, a.bias, a.bias, a.bias] : o = [a.bias[0], a.bias[1], a.bias[2], a.bias[3] ?? 0];
117
+ let l = t.format !== void 0 ? t.format : "RGBA", s = t.tensorFormat !== void 0 && t.tensorFormat !== void 0 ? t.tensorFormat : "RGB", u = r * n, f = s === "RGBA" ? new Float32Array(u * 4) : new Float32Array(u * 3), p = 4, d = 0, w = 1, h = 2, v = 3, C = 0, m = u, c = u * 2, y = -1;
118
+ l === "RGB" && (p = 3, d = 0, w = 1, h = 2, v = -1), s === "RGBA" ? y = u * 3 : s === "RBG" ? (C = 0, c = u, m = u * 2) : s === "BGR" && (c = 0, m = u, C = u * 2);
119
+ for (let E = 0; E < u; E++, d += p, h += p, w += p, v += p) f[C++] = (e[d] + o[0]) / i[0], f[m++] = (e[w] + o[1]) / i[1], f[c++] = (e[h] + o[2]) / i[2], y !== -1 && v !== -1 && (f[y++] = (e[v] + o[3]) / i[3]);
120
+ return s === "RGBA" ? new M("float32", f, [1, 4, r, n]) : new M("float32", f, [1, 3, r, n]);
121
+ }, kt = async (e, t) => {
122
+ let r = typeof HTMLImageElement < "u" && e instanceof HTMLImageElement, n = typeof ImageData < "u" && e instanceof ImageData, a = typeof ImageBitmap < "u" && e instanceof ImageBitmap, i = typeof e == "string", o, l = t ?? {}, s = () => {
123
+ if (typeof document < "u") return document.createElement("canvas");
124
+ if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(1, 1);
125
+ throw new Error("Canvas is not supported");
126
+ }, u = (f) => typeof HTMLCanvasElement < "u" && f instanceof HTMLCanvasElement || f instanceof OffscreenCanvas ? f.getContext("2d") : null;
127
+ if (r) {
128
+ let f = s();
129
+ f.width = e.width, f.height = e.height;
130
+ let p = u(f);
131
+ if (p != null) {
132
+ let d = e.height, w = e.width;
133
+ if (t !== void 0 && t.resizedHeight !== void 0 && t.resizedWidth !== void 0 && (d = t.resizedHeight, w = t.resizedWidth), t !== void 0) {
134
+ if (l = t, t.tensorFormat !== void 0) throw new Error("Image input config format must be RGBA for HTMLImageElement");
135
+ l.tensorFormat = "RGBA", l.height = d, l.width = w;
136
+ } else l.tensorFormat = "RGBA", l.height = d, l.width = w;
137
+ p.drawImage(e, 0, 0), o = p.getImageData(0, 0, w, d).data;
138
+ } else throw new Error("Can not access image data");
139
+ } else if (n) {
140
+ let f, p;
141
+ if (t !== void 0 && t.resizedWidth !== void 0 && t.resizedHeight !== void 0 ? (f = t.resizedHeight, p = t.resizedWidth) : (f = e.height, p = e.width), t !== void 0 && (l = t), l.format = "RGBA", l.height = f, l.width = p, t !== void 0) {
142
+ let d = s();
143
+ d.width = p, d.height = f;
144
+ let w = u(d);
145
+ if (w != null) w.putImageData(e, 0, 0), o = w.getImageData(0, 0, p, f).data;
146
+ else throw new Error("Can not access image data");
147
+ } else o = e.data;
148
+ } else if (a) {
149
+ if (t === void 0) throw new Error("Please provide image config with format for Imagebitmap");
150
+ let f = s();
151
+ f.width = e.width, f.height = e.height;
152
+ let p = u(f);
153
+ if (p != null) {
154
+ let d = e.height, w = e.width;
155
+ return p.drawImage(e, 0, 0, w, d), o = p.getImageData(0, 0, w, d).data, l.height = d, l.width = w, ye(o, l);
156
+ } else throw new Error("Can not access image data");
157
+ } else {
158
+ if (i) return new Promise((f, p) => {
159
+ let d = s(), w = u(d);
160
+ if (!e || !w) return p();
161
+ let h = new Image();
162
+ h.crossOrigin = "Anonymous", h.src = e, h.onload = () => {
163
+ d.width = h.width, d.height = h.height, w.drawImage(h, 0, 0, d.width, d.height);
164
+ let v = w.getImageData(0, 0, d.width, d.height);
165
+ l.height = d.height, l.width = d.width, f(ye(v.data, l));
166
+ };
167
+ });
168
+ throw new Error("Input data provided is not supported - aborted tensor creation");
169
+ }
170
+ if (o !== void 0) return ye(o, l);
171
+ throw new Error("Input data provided is not supported - aborted tensor creation");
172
+ }, Dt = (e, t) => {
173
+ let { width: r, height: n, download: a, dispose: i } = t, o = [1, n, r, 4];
174
+ return new M({ location: "texture", type: "float32", texture: e, dims: o, download: a, dispose: i });
175
+ }, Gt = (e, t) => {
176
+ let { dataType: r, dims: n, download: a, dispose: i } = t;
177
+ return new M({ location: "gpu-buffer", type: r ?? "float32", gpuBuffer: e, dims: n, download: a, dispose: i });
178
+ }, Ft = (e, t) => {
179
+ let { dataType: r, dims: n, download: a, dispose: i } = t;
180
+ return new M({ location: "ml-tensor", type: r ?? "float32", mlTensor: e, dims: n, download: a, dispose: i });
181
+ }, jt = (e, t, r) => new M({ location: "cpu-pinned", type: e, data: t, dims: r ?? [t.length] });
182
+ }), K, we, Ie, Wt, _r = b(() => {
183
+ K = /* @__PURE__ */ new Map([["float32", Float32Array], ["uint8", Uint8Array], ["int8", Int8Array], ["uint16", Uint16Array], ["int16", Int16Array], ["int32", Int32Array], ["bool", Uint8Array], ["float64", Float64Array], ["uint32", Uint32Array], ["int4", Uint8Array], ["uint4", Uint8Array]]), we = /* @__PURE__ */ new Map([[Float32Array, "float32"], [Uint8Array, "uint8"], [Int8Array, "int8"], [Uint16Array, "uint16"], [Int16Array, "int16"], [Int32Array, "int32"], [Float64Array, "float64"], [Uint32Array, "uint32"]]), Ie = !1, Wt = () => {
184
+ if (!Ie) {
185
+ Ie = !0;
186
+ let e = typeof BigInt64Array < "u" && BigInt64Array.from, t = typeof BigUint64Array < "u" && BigUint64Array.from, r = globalThis.Float16Array, n = typeof r < "u" && r.from;
187
+ e && (K.set("int64", BigInt64Array), we.set(BigInt64Array, "int64")), t && (K.set("uint64", BigUint64Array), we.set(BigUint64Array, "uint64")), n ? (K.set("float16", r), we.set(r, "float16")) : K.set("float16", Uint16Array);
188
+ }
189
+ };
190
+ }), Vt, zt, Mr = b(() => {
191
+ Ze(), Vt = (e) => {
192
+ let t = 1;
193
+ for (let r = 0; r < e.length; r++) {
194
+ let n = e[r];
195
+ if (typeof n != "number" || !Number.isSafeInteger(n)) throw new TypeError(`dims[${r}] must be an integer, got: ${n}`);
196
+ if (n < 0) throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${n}`);
197
+ t *= n;
198
+ }
199
+ return t;
200
+ }, zt = (e, t) => {
201
+ switch (e.location) {
202
+ case "cpu":
203
+ return new M(e.type, e.data, t);
204
+ case "cpu-pinned":
205
+ return new M({ location: "cpu-pinned", data: e.data, type: e.type, dims: t });
206
+ case "texture":
207
+ return new M({ location: "texture", texture: e.texture, type: e.type, dims: t });
208
+ case "gpu-buffer":
209
+ return new M({ location: "gpu-buffer", gpuBuffer: e.gpuBuffer, type: e.type, dims: t });
210
+ case "ml-tensor":
211
+ return new M({ location: "ml-tensor", mlTensor: e.mlTensor, type: e.type, dims: t });
212
+ default:
213
+ throw new Error(`tensorReshape: tensor location ${e.location} is not supported`);
214
+ }
215
+ };
216
+ }), M, Ze = b(() => {
217
+ Pr(), $r(), _r(), Mr(), M = class {
218
+ constructor(e, t, r) {
219
+ Wt();
220
+ let n, a;
221
+ if (typeof e == "object" && "location" in e) switch (this.dataLocation = e.location, n = e.type, a = e.dims, e.location) {
222
+ case "cpu-pinned": {
223
+ let o = K.get(n);
224
+ if (!o) throw new TypeError(`unsupported type "${n}" to create tensor from pinned buffer`);
225
+ if (!(e.data instanceof o)) throw new TypeError(`buffer should be of type ${o.name}`);
226
+ this.cpuData = e.data;
227
+ break;
228
+ }
229
+ case "texture": {
230
+ if (n !== "float32") throw new TypeError(`unsupported type "${n}" to create tensor from texture`);
231
+ this.gpuTextureData = e.texture, this.downloader = e.download, this.disposer = e.dispose;
232
+ break;
233
+ }
234
+ case "gpu-buffer": {
235
+ if (n !== "float32" && n !== "float16" && n !== "int32" && n !== "int64" && n !== "uint32" && n !== "uint8" && n !== "bool" && n !== "uint4" && n !== "int4") throw new TypeError(`unsupported type "${n}" to create tensor from gpu buffer`);
236
+ this.gpuBufferData = e.gpuBuffer, this.downloader = e.download, this.disposer = e.dispose;
237
+ break;
238
+ }
239
+ case "ml-tensor": {
240
+ if (n !== "float32" && n !== "float16" && n !== "int32" && n !== "int64" && n !== "uint32" && n !== "uint64" && n !== "int8" && n !== "uint8" && n !== "bool" && n !== "uint4" && n !== "int4") throw new TypeError(`unsupported type "${n}" to create tensor from MLTensor`);
241
+ this.mlTensorData = e.mlTensor, this.downloader = e.download, this.disposer = e.dispose;
242
+ break;
243
+ }
244
+ default:
245
+ throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
246
+ }
247
+ else {
248
+ let o, l;
249
+ if (typeof e == "string") if (n = e, l = r, e === "string") {
250
+ if (!Array.isArray(t)) throw new TypeError("A string tensor's data must be a string array.");
251
+ o = t;
252
+ } else {
253
+ let s = K.get(e);
254
+ if (s === void 0) throw new TypeError(`Unsupported tensor type: ${e}.`);
255
+ if (Array.isArray(t)) {
256
+ if (e === "float16" && s === Uint16Array || e === "uint4" || e === "int4") throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${s.name} as data.`);
257
+ e === "uint64" || e === "int64" ? o = s.from(t, BigInt) : o = s.from(t);
258
+ } else if (t instanceof s) o = t;
259
+ else if (t instanceof Uint8ClampedArray) if (e === "uint8") o = Uint8Array.from(t);
260
+ else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");
261
+ else if (e === "float16" && t instanceof Uint16Array && s !== Uint16Array) o = new globalThis.Float16Array(t.buffer, t.byteOffset, t.length);
262
+ else throw new TypeError(`A ${n} tensor's data must be type of ${s}`);
263
+ }
264
+ else if (l = t, Array.isArray(e)) {
265
+ if (e.length === 0) throw new TypeError("Tensor type cannot be inferred from an empty array.");
266
+ let s = typeof e[0];
267
+ if (s === "string") n = "string", o = e;
268
+ else if (s === "boolean") n = "bool", o = Uint8Array.from(e);
269
+ else throw new TypeError(`Invalid element type of data array: ${s}.`);
270
+ } else if (e instanceof Uint8ClampedArray) n = "uint8", o = Uint8Array.from(e);
271
+ else {
272
+ let s = we.get(e.constructor);
273
+ if (s === void 0) throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);
274
+ n = s, o = e;
275
+ }
276
+ if (l === void 0) l = [o.length];
277
+ else if (!Array.isArray(l)) throw new TypeError("A tensor's dims must be a number array");
278
+ a = l, this.cpuData = o, this.dataLocation = "cpu";
279
+ }
280
+ let i = Vt(a);
281
+ if (this.cpuData && i !== this.cpuData.length && !((n === "uint4" || n === "int4") && Math.ceil(i / 2) === this.cpuData.length)) throw new Error(`Tensor's size(${i}) does not match data length(${this.cpuData.length}).`);
282
+ this.type = n, this.dims = a, this.size = i;
283
+ }
284
+ static async fromImage(e, t) {
285
+ return kt(e, t);
286
+ }
287
+ static fromTexture(e, t) {
288
+ return Dt(e, t);
289
+ }
290
+ static fromGpuBuffer(e, t) {
291
+ return Gt(e, t);
292
+ }
293
+ static fromMLTensor(e, t) {
294
+ return Ft(e, t);
295
+ }
296
+ static fromPinnedBuffer(e, t, r) {
297
+ return jt(e, t, r);
298
+ }
299
+ toDataURL(e) {
300
+ return Bt(this, e);
301
+ }
302
+ toImageData(e) {
303
+ return Nt(this, e);
304
+ }
305
+ get data() {
306
+ if (this.ensureValid(), !this.cpuData) throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");
307
+ return this.cpuData;
308
+ }
309
+ get location() {
310
+ return this.dataLocation;
311
+ }
312
+ get texture() {
313
+ if (this.ensureValid(), !this.gpuTextureData) throw new Error("The data is not stored as a WebGL texture.");
314
+ return this.gpuTextureData;
315
+ }
316
+ get gpuBuffer() {
317
+ if (this.ensureValid(), !this.gpuBufferData) throw new Error("The data is not stored as a WebGPU buffer.");
318
+ return this.gpuBufferData;
319
+ }
320
+ get mlTensor() {
321
+ if (this.ensureValid(), !this.mlTensorData) throw new Error("The data is not stored as a WebNN MLTensor.");
322
+ return this.mlTensorData;
323
+ }
324
+ async getData(e) {
325
+ switch (this.ensureValid(), this.dataLocation) {
326
+ case "cpu":
327
+ case "cpu-pinned":
328
+ return this.data;
329
+ case "texture":
330
+ case "gpu-buffer":
331
+ case "ml-tensor": {
332
+ if (!this.downloader) throw new Error("The current tensor is not created with a specified data downloader.");
333
+ if (this.isDownloading) throw new Error("The current tensor is being downloaded.");
334
+ try {
335
+ this.isDownloading = !0;
336
+ let t = await this.downloader();
337
+ return this.downloader = void 0, this.dataLocation = "cpu", this.cpuData = t, e && this.disposer && (this.disposer(), this.disposer = void 0), t;
338
+ } finally {
339
+ this.isDownloading = !1;
340
+ }
341
+ }
342
+ default:
343
+ throw new Error(`cannot get data from location: ${this.dataLocation}`);
344
+ }
345
+ }
346
+ dispose() {
347
+ if (this.isDownloading) throw new Error("The current tensor is being downloaded.");
348
+ this.disposer && (this.disposer(), this.disposer = void 0), this.cpuData = void 0, this.gpuTextureData = void 0, this.gpuBufferData = void 0, this.mlTensorData = void 0, this.downloader = void 0, this.isDownloading = void 0, this.dataLocation = "none";
349
+ }
350
+ ensureValid() {
351
+ if (this.dataLocation === "none") throw new Error("The tensor is disposed.");
352
+ }
353
+ reshape(e) {
354
+ if (this.ensureValid(), this.downloader || this.disposer) throw new Error("Cannot reshape a tensor that owns GPU resource.");
355
+ return zt(this, e);
356
+ }
357
+ };
358
+ }), N, Ht = b(() => {
359
+ Ze(), N = M;
360
+ }), We, xe, ne, ae, oe, ie, qt = b(() => {
361
+ St(), We = (e, t) => {
362
+ (typeof I.trace > "u" ? !I.wasm.trace : !I.trace) || console.timeStamp(`${e}::ORT::${t}`);
363
+ }, xe = (e, t) => {
364
+ let r = new Error().stack?.split(/\r\n|\r|\n/g) || [], n = !1;
365
+ for (let a = 0; a < r.length; a++) {
366
+ if (n && !r[a].includes("TRACE_FUNC")) {
367
+ let i = `FUNC_${e}::${r[a].trim().split(" ")[1]}`;
368
+ t && (i += `::${t}`), We("CPU", i);
369
+ return;
370
+ }
371
+ r[a].includes("TRACE_FUNC") && (n = !0);
372
+ }
373
+ }, ne = (e) => {
374
+ (typeof I.trace > "u" ? !I.wasm.trace : !I.trace) || xe("BEGIN", e);
375
+ }, ae = (e) => {
376
+ (typeof I.trace > "u" ? !I.wasm.trace : !I.trace) || xe("END", e);
377
+ }, oe = (e) => {
378
+ (typeof I.trace > "u" ? !I.wasm.trace : !I.trace) || console.time(`ORT::${e}`);
379
+ }, ie = (e) => {
380
+ (typeof I.trace > "u" ? !I.wasm.trace : !I.trace) || console.timeEnd(`ORT::${e}`);
381
+ };
382
+ }), Zt, Sr = b(() => {
383
+ _t(), Ht(), qt(), Zt = class Jt {
384
+ constructor(t) {
385
+ this.handler = t;
386
+ }
387
+ async run(t, r, n) {
388
+ ne(), oe("InferenceSession.run");
389
+ let a = {}, i = {};
390
+ if (typeof t != "object" || t === null || t instanceof N || Array.isArray(t)) throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
391
+ let o = !0;
392
+ if (typeof r == "object") {
393
+ if (r === null) throw new TypeError("Unexpected argument[1]: cannot be null.");
394
+ if (r instanceof N) throw new TypeError("'fetches' cannot be a Tensor");
395
+ if (Array.isArray(r)) {
396
+ if (r.length === 0) throw new TypeError("'fetches' cannot be an empty array.");
397
+ o = !1;
398
+ for (let u of r) {
399
+ if (typeof u != "string") throw new TypeError("'fetches' must be a string array or an object.");
400
+ if (this.outputNames.indexOf(u) === -1) throw new RangeError(`'fetches' contains invalid output name: ${u}.`);
401
+ a[u] = null;
402
+ }
403
+ if (typeof n == "object" && n !== null) i = n;
404
+ else if (typeof n < "u") throw new TypeError("'options' must be an object.");
405
+ } else {
406
+ let u = !1, f = Object.getOwnPropertyNames(r);
407
+ for (let p of this.outputNames) if (f.indexOf(p) !== -1) {
408
+ let d = r[p];
409
+ (d === null || d instanceof N) && (u = !0, o = !1, a[p] = d);
410
+ }
411
+ if (u) {
412
+ if (typeof n == "object" && n !== null) i = n;
413
+ else if (typeof n < "u") throw new TypeError("'options' must be an object.");
414
+ } else i = r;
415
+ }
416
+ } else if (typeof r < "u") throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
417
+ for (let u of this.inputNames) if (typeof t[u] > "u") throw new Error(`input '${u}' is missing in 'feeds'.`);
418
+ if (o) for (let u of this.outputNames) a[u] = null;
419
+ let l = await this.handler.run(t, a, i), s = {};
420
+ for (let u in l) if (Object.hasOwnProperty.call(l, u)) {
421
+ let f = l[u];
422
+ f instanceof N ? s[u] = f : s[u] = new N(f.type, f.data, f.dims);
423
+ }
424
+ return ie("InferenceSession.run"), ae(), s;
425
+ }
426
+ async release() {
427
+ return this.handler.dispose();
428
+ }
429
+ static async create(t, r, n, a) {
430
+ ne(), oe("InferenceSession.create");
431
+ let i, o = {};
432
+ if (typeof t == "string") {
433
+ if (i = t, typeof r == "object" && r !== null) o = r;
434
+ else if (typeof r < "u") throw new TypeError("'options' must be an object.");
435
+ } else if (t instanceof Uint8Array) {
436
+ if (i = t, typeof r == "object" && r !== null) o = r;
437
+ else if (typeof r < "u") throw new TypeError("'options' must be an object.");
438
+ } else if (t instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && t instanceof SharedArrayBuffer) {
439
+ let f = t, p = 0, d = t.byteLength;
440
+ if (typeof r == "object" && r !== null) o = r;
441
+ else if (typeof r == "number") {
442
+ if (p = r, !Number.isSafeInteger(p)) throw new RangeError("'byteOffset' must be an integer.");
443
+ if (p < 0 || p >= f.byteLength) throw new RangeError(`'byteOffset' is out of range [0, ${f.byteLength}).`);
444
+ if (d = t.byteLength - p, typeof n == "number") {
445
+ if (d = n, !Number.isSafeInteger(d)) throw new RangeError("'byteLength' must be an integer.");
446
+ if (d <= 0 || p + d > f.byteLength) throw new RangeError(`'byteLength' is out of range (0, ${f.byteLength - p}].`);
447
+ if (typeof a == "object" && a !== null) o = a;
448
+ else if (typeof a < "u") throw new TypeError("'options' must be an object.");
449
+ } else if (typeof n < "u") throw new TypeError("'byteLength' must be a number.");
450
+ } else if (typeof r < "u") throw new TypeError("'options' must be an object.");
451
+ i = new Uint8Array(f, p, d);
452
+ } else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
453
+ let [l, s] = await $t(o), u = await l.createInferenceSessionHandler(i, s);
454
+ return ie("InferenceSession.create"), ae(), new Jt(u);
455
+ }
456
+ startProfiling() {
457
+ this.handler.startProfiling();
458
+ }
459
+ endProfiling() {
460
+ this.handler.endProfiling();
461
+ }
462
+ get inputNames() {
463
+ return this.handler.inputNames;
464
+ }
465
+ get outputNames() {
466
+ return this.handler.outputNames;
467
+ }
468
+ get inputMetadata() {
469
+ return this.handler.inputMetadata;
470
+ }
471
+ get outputMetadata() {
472
+ return this.handler.outputMetadata;
473
+ }
474
+ };
475
+ }), Je, Br = b(() => {
476
+ Sr(), Je = Zt;
477
+ }), Nr = b(() => {
478
+ }), kr = b(() => {
479
+ }), Dr = b(() => {
480
+ }), Gr = b(() => {
481
+ }), Fr = {};
482
+ qe(Fr, { InferenceSession: () => Je, TRACE: () => We, TRACE_EVENT_BEGIN: () => oe, TRACE_EVENT_END: () => ie, TRACE_FUNC_BEGIN: () => ne, TRACE_FUNC_END: () => ae, Tensor: () => N, env: () => A, registerBackend: () => Oe });
483
+ var Q = b(() => {
484
+ Lr(), xr(), Br(), Ht(), Nr(), kr(), qt(), Dr(), Gr();
485
+ }), Ye = b(() => {
486
+ }), Yt = {};
487
+ qe(Yt, { default: () => Kt });
488
+ var Pe, $e, Kt, jr = b(() => {
489
+ sr(), se(), Qe(), Pe = "ort-wasm-proxy-worker", $e = globalThis.self?.name === Pe, $e && (self.onmessage = (e) => {
490
+ let { type: t, in: r } = e.data;
491
+ try {
492
+ switch (t) {
493
+ case "init-wasm":
494
+ Xe(r.wasm).then(() => {
495
+ at(r).then(() => {
496
+ postMessage({ type: t });
497
+ }, (n) => {
498
+ postMessage({ type: t, err: n });
499
+ });
500
+ }, (n) => {
501
+ postMessage({ type: t, err: n });
502
+ });
503
+ break;
504
+ case "init-ep": {
505
+ let { epName: n, env: a } = r;
506
+ ot(a, n).then(() => {
507
+ postMessage({ type: t });
508
+ }, (i) => {
509
+ postMessage({ type: t, err: i });
510
+ });
511
+ break;
512
+ }
513
+ case "copy-from": {
514
+ let { buffer: n } = r, a = Re(n);
515
+ postMessage({ type: t, out: a });
516
+ break;
517
+ }
518
+ case "create": {
519
+ let { model: n, options: a } = r;
520
+ it(n, a).then((i) => {
521
+ postMessage({ type: t, out: i });
522
+ }, (i) => {
523
+ postMessage({ type: t, err: i });
524
+ });
525
+ break;
526
+ }
527
+ case "release":
528
+ st(r), postMessage({ type: t });
529
+ break;
530
+ case "run": {
531
+ let { sessionId: n, inputIndices: a, inputs: i, outputIndices: o, options: l } = r;
532
+ lt(n, a, i, o, new Array(o.length).fill(null), l).then((s) => {
533
+ s.some((u) => u[3] !== "cpu") ? postMessage({ type: t, err: "Proxy does not support non-cpu tensor location." }) : postMessage({ type: t, out: s }, ft([...i, ...s]));
534
+ }, (s) => {
535
+ postMessage({ type: t, err: s });
536
+ });
537
+ break;
538
+ }
539
+ case "end-profiling":
540
+ ut(r), postMessage({ type: t });
541
+ break;
542
+ default:
543
+ }
544
+ } catch (n) {
545
+ postMessage({ type: t, err: n });
546
+ }
547
+ }), Kt = $e ? null : (e) => new Worker(e ?? _, { type: "module", name: Pe });
548
+ }), _e, ht, mt, _, Ke, ge, yt, gt, Me, bt, Se, Qt, Be, Xt, Qe = b(() => {
549
+ Ye(), _e = typeof location > "u" ? void 0 : location.origin, ht = import.meta.url > "file:" && import.meta.url < "file;", mt = () => {
550
+ {
551
+ if (ht) {
552
+ let e = URL;
553
+ return new URL(new e("ort.wasm.min.mjs", import.meta.url).href, _e).href;
554
+ }
555
+ return import.meta.url;
556
+ }
557
+ }, _ = mt(), Ke = () => {
558
+ if (_ && !_.startsWith("blob:")) return _.substring(0, _.lastIndexOf("/") + 1);
559
+ }, ge = (e, t) => {
560
+ try {
561
+ let r = t ?? _;
562
+ return (r ? new URL(e, r) : new URL(e)).origin === _e;
563
+ } catch {
564
+ return !1;
565
+ }
566
+ }, yt = (e, t) => {
567
+ let r = t ?? _;
568
+ try {
569
+ return (r ? new URL(e, r) : new URL(e)).href;
570
+ } catch {
571
+ return;
572
+ }
573
+ }, gt = (e, t) => `${t ?? "./"}${e}`, Me = async (e) => {
574
+ let t = await (await fetch(e, { credentials: "same-origin" })).blob();
575
+ return URL.createObjectURL(t);
576
+ }, bt = async (e) => (await import(
577
+ /*webpackIgnore:true*/
578
+ e
579
+ )).default, Se = (jr(), Pt(Yt)).default, Qt = async () => {
580
+ if (!_) throw new Error("Failed to load proxy worker: cannot determine the script source URL.");
581
+ if (ge(_)) return [void 0, Se()];
582
+ let e = await Me(_);
583
+ return [e, Se(e)];
584
+ }, Be = void 0, Xt = async (e, t, r, n) => {
585
+ let a = Be && !(e || t);
586
+ if (a) if (_) a = ge(_);
587
+ else if (n && !r) a = !0;
588
+ else throw new Error("cannot determine the script source URL.");
589
+ if (a) return [void 0, Be];
590
+ {
591
+ let i = "ort-wasm-simd-threaded.mjs", o = e ?? yt(i, t), l = r && o && !ge(o, t), s = l ? await Me(o) : o ?? gt(i, t);
592
+ return [l ? s : void 0, await bt(s)];
593
+ }
594
+ };
595
+ }), Ne, be, fe, ke, vt, Et, Tt, Xe, O, se = b(() => {
596
+ Qe(), be = !1, fe = !1, ke = !1, vt = () => {
597
+ if (typeof SharedArrayBuffer > "u") return !1;
598
+ try {
599
+ return typeof MessageChannel < "u" && new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)), WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 5, 4, 1, 3, 1, 1, 10, 11, 1, 9, 0, 65, 0, 254, 16, 2, 0, 26, 11]));
600
+ } catch {
601
+ return !1;
602
+ }
603
+ }, Et = () => {
604
+ try {
605
+ return WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 10, 30, 1, 28, 0, 65, 0, 253, 15, 253, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 253, 186, 1, 26, 11]));
606
+ } catch {
607
+ return !1;
608
+ }
609
+ }, Tt = () => {
610
+ try {
611
+ return WebAssembly.validate(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 19, 1, 17, 0, 65, 1, 253, 15, 65, 2, 253, 15, 65, 3, 253, 15, 253, 147, 2, 11]));
612
+ } catch {
613
+ return !1;
614
+ }
615
+ }, Xe = async (e) => {
616
+ if (be) return Promise.resolve();
617
+ if (fe) throw new Error("multiple calls to 'initializeWebAssembly()' detected.");
618
+ if (ke) throw new Error("previous call to 'initializeWebAssembly()' failed.");
619
+ fe = !0;
620
+ let t = e.initTimeout, r = e.numThreads;
621
+ if (e.simd !== !1) {
622
+ if (e.simd === "relaxed") {
623
+ if (!Tt()) throw new Error("Relaxed WebAssembly SIMD is not supported in the current environment.");
624
+ } else if (!Et()) throw new Error("WebAssembly SIMD is not supported in the current environment.");
625
+ }
626
+ let n = vt();
627
+ r > 1 && !n && (typeof self < "u" && !self.crossOriginIsolated && console.warn("env.wasm.numThreads is set to " + r + ", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."), console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."), e.numThreads = r = 1);
628
+ let a = e.wasmPaths, i = typeof a == "string" ? a : void 0, o = a?.mjs, l = o?.href ?? o, s = a?.wasm, u = s?.href ?? s, f = e.wasmBinary, [p, d] = await Xt(l, i, r > 1, !!f || !!u), w = !1, h = [];
629
+ if (t > 0 && h.push(new Promise((v) => {
630
+ setTimeout(() => {
631
+ w = !0, v();
632
+ }, t);
633
+ })), h.push(new Promise((v, C) => {
634
+ let m = { numThreads: r };
635
+ if (f) m.wasmBinary = f;
636
+ else if (u || i) m.locateFile = (c) => u ?? i + c;
637
+ else if (l && l.indexOf("blob:") !== 0) m.locateFile = (c) => new URL(c, l).href;
638
+ else if (p) {
639
+ let c = Ke();
640
+ c && (m.locateFile = (y) => c + y);
641
+ }
642
+ d(m).then((c) => {
643
+ fe = !1, be = !0, Ne = c, v(), p && URL.revokeObjectURL(p);
644
+ }, (c) => {
645
+ fe = !1, ke = !0, C(c);
646
+ });
647
+ })), await Promise.race(h), w) throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`);
648
+ }, O = () => {
649
+ if (be && Ne) return Ne;
650
+ throw new Error("WebAssembly is not initialized yet.");
651
+ };
652
+ }), B, Ce, T, et = b(() => {
653
+ se(), B = (e, t) => {
654
+ let r = O(), n = r.lengthBytesUTF8(e) + 1, a = r._malloc(n);
655
+ return r.stringToUTF8(e, a, n), t.push(a), a;
656
+ }, Ce = (e, t, r, n) => {
657
+ if (typeof e == "object" && e !== null) {
658
+ if (r.has(e)) throw new Error("Circular reference in options");
659
+ r.add(e);
660
+ }
661
+ Object.entries(e).forEach(([a, i]) => {
662
+ let o = t ? t + a : a;
663
+ if (typeof i == "object") Ce(i, o + ".", r, n);
664
+ else if (typeof i == "string" || typeof i == "number") n(o, i.toString());
665
+ else if (typeof i == "boolean") n(o, i ? "1" : "0");
666
+ else throw new Error(`Can't handle extra config type: ${typeof i}`);
667
+ });
668
+ }, T = (e) => {
669
+ let t = O(), r = t.stackSave();
670
+ try {
671
+ let n = t.PTR_SIZE, a = t.stackAlloc(2 * n);
672
+ t._OrtGetLastError(a, a + n);
673
+ let i = Number(t.getValue(a, n === 4 ? "i32" : "i64")), o = t.getValue(a + n, "*"), l = o ? t.UTF8ToString(o) : "";
674
+ throw new Error(`${e} ERROR_CODE: ${i}, ERROR_MESSAGE: ${l}`);
675
+ } finally {
676
+ t.stackRestore(r);
677
+ }
678
+ };
679
+ }), er, Wr = b(() => {
680
+ se(), et(), er = (e) => {
681
+ let t = O(), r = 0, n = [], a = e || {};
682
+ try {
683
+ if (e?.logSeverityLevel === void 0) a.logSeverityLevel = 2;
684
+ else if (typeof e.logSeverityLevel != "number" || !Number.isInteger(e.logSeverityLevel) || e.logSeverityLevel < 0 || e.logSeverityLevel > 4) throw new Error(`log severity level is not valid: ${e.logSeverityLevel}`);
685
+ if (e?.logVerbosityLevel === void 0) a.logVerbosityLevel = 0;
686
+ else if (typeof e.logVerbosityLevel != "number" || !Number.isInteger(e.logVerbosityLevel)) throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);
687
+ e?.terminate === void 0 && (a.terminate = !1);
688
+ let i = 0;
689
+ return e?.tag !== void 0 && (i = B(e.tag, n)), r = t._OrtCreateRunOptions(a.logSeverityLevel, a.logVerbosityLevel, !!a.terminate, i), r === 0 && T("Can't create run options."), e?.extra !== void 0 && Ce(e.extra, "", /* @__PURE__ */ new WeakSet(), (o, l) => {
690
+ let s = B(o, n), u = B(l, n);
691
+ t._OrtAddRunConfigEntry(r, s, u) !== 0 && T(`Can't set a run config entry: ${o} - ${l}.`);
692
+ }), [r, n];
693
+ } catch (i) {
694
+ throw r !== 0 && t._OrtReleaseRunOptions(r), n.forEach((o) => t._free(o)), i;
695
+ }
696
+ };
697
+ }), At, Ot, Ct, pe, Rt, tr, Vr = b(() => {
698
+ se(), et(), At = (e) => {
699
+ switch (e) {
700
+ case "disabled":
701
+ return 0;
702
+ case "basic":
703
+ return 1;
704
+ case "extended":
705
+ return 2;
706
+ case "layout":
707
+ return 3;
708
+ case "all":
709
+ return 99;
710
+ default:
711
+ throw new Error(`unsupported graph optimization level: ${e}`);
712
+ }
713
+ }, Ot = (e) => {
714
+ switch (e) {
715
+ case "sequential":
716
+ return 0;
717
+ case "parallel":
718
+ return 1;
719
+ default:
720
+ throw new Error(`unsupported execution mode: ${e}`);
721
+ }
722
+ }, Ct = (e) => {
723
+ e.extra || (e.extra = {}), e.extra.session || (e.extra.session = {});
724
+ let t = e.extra.session;
725
+ t.use_ort_model_bytes_directly || (t.use_ort_model_bytes_directly = "1"), e.executionProviders && e.executionProviders.some((r) => (typeof r == "string" ? r : r.name) === "webgpu") && (e.enableMemPattern = !1);
726
+ }, pe = (e, t, r, n) => {
727
+ let a = B(t, n), i = B(r, n);
728
+ O()._OrtAddSessionConfigEntry(e, a, i) !== 0 && T(`Can't set a session config entry: ${t} - ${r}.`);
729
+ }, Rt = async (e, t, r) => {
730
+ for (let n of t) {
731
+ let a = typeof n == "string" ? n : n.name, i = [];
732
+ switch (a) {
733
+ case "webnn":
734
+ if (a = "WEBNN", typeof n != "string") {
735
+ let f = n?.deviceType;
736
+ f && pe(e, "deviceType", f, r);
737
+ }
738
+ break;
739
+ case "webgpu":
740
+ if (a = "JS", typeof n != "string") {
741
+ let f = n;
742
+ if (f?.preferredLayout) {
743
+ if (f.preferredLayout !== "NCHW" && f.preferredLayout !== "NHWC") throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${f.preferredLayout}`);
744
+ pe(e, "preferredLayout", f.preferredLayout, r);
745
+ }
746
+ }
747
+ break;
748
+ case "wasm":
749
+ case "cpu":
750
+ continue;
751
+ default:
752
+ throw new Error(`not supported execution provider: ${a}`);
753
+ }
754
+ let o = B(a, r), l = i.length, s = 0, u = 0;
755
+ if (l > 0) {
756
+ s = O()._malloc(l * O().PTR_SIZE), r.push(s), u = O()._malloc(l * O().PTR_SIZE), r.push(u);
757
+ for (let f = 0; f < l; f++) O().setValue(s + f * O().PTR_SIZE, i[f][0], "*"), O().setValue(u + f * O().PTR_SIZE, i[f][1], "*");
758
+ }
759
+ await O()._OrtAppendExecutionProvider(e, o, s, u, l) !== 0 && T(`Can't append execution provider: ${a}.`);
760
+ }
761
+ }, tr = async (e) => {
762
+ let t = O(), r = 0, n = [], a = e || {};
763
+ Ct(a);
764
+ try {
765
+ let i = At(a.graphOptimizationLevel ?? "all"), o = Ot(a.executionMode ?? "sequential"), l = typeof a.logId == "string" ? B(a.logId, n) : 0, s = a.logSeverityLevel ?? 2;
766
+ if (!Number.isInteger(s) || s < 0 || s > 4) throw new Error(`log severity level is not valid: ${s}`);
767
+ let u = a.logVerbosityLevel ?? 0;
768
+ if (!Number.isInteger(u) || u < 0 || u > 4) throw new Error(`log verbosity level is not valid: ${u}`);
769
+ let f = typeof a.optimizedModelFilePath == "string" ? B(a.optimizedModelFilePath, n) : 0;
770
+ if (r = t._OrtCreateSessionOptions(i, !!a.enableCpuMemArena, !!a.enableMemPattern, o, !!a.enableProfiling, 0, l, s, u, f), r === 0 && T("Can't create session options."), a.executionProviders && await Rt(r, a.executionProviders, n), a.enableGraphCapture !== void 0) {
771
+ if (typeof a.enableGraphCapture != "boolean") throw new Error(`enableGraphCapture must be a boolean value: ${a.enableGraphCapture}`);
772
+ pe(r, "enableGraphCapture", a.enableGraphCapture.toString(), n);
773
+ }
774
+ if (a.freeDimensionOverrides) for (let [p, d] of Object.entries(a.freeDimensionOverrides)) {
775
+ if (typeof p != "string") throw new Error(`free dimension override name must be a string: ${p}`);
776
+ if (typeof d != "number" || !Number.isInteger(d) || d < 0) throw new Error(`free dimension override value must be a non-negative integer: ${d}`);
777
+ let w = B(p, n);
778
+ t._OrtAddFreeDimensionOverride(r, w, d) !== 0 && T(`Can't set a free dimension override: ${p} - ${d}.`);
779
+ }
780
+ return a.extra !== void 0 && Ce(a.extra, "", /* @__PURE__ */ new WeakSet(), (p, d) => {
781
+ pe(r, p, d, n);
782
+ }), [r, n];
783
+ } catch (i) {
784
+ throw r !== 0 && t._OrtReleaseSessionOptions(r) !== 0 && T("Can't release session options."), n.forEach((o) => t._free(o)), i;
785
+ }
786
+ };
787
+ }), te, Ae, re, rr, nr, tt, rt, ar, or = b(() => {
788
+ te = (e) => {
789
+ switch (e) {
790
+ case "int8":
791
+ return 3;
792
+ case "uint8":
793
+ return 2;
794
+ case "bool":
795
+ return 9;
796
+ case "int16":
797
+ return 5;
798
+ case "uint16":
799
+ return 4;
800
+ case "int32":
801
+ return 6;
802
+ case "uint32":
803
+ return 12;
804
+ case "float16":
805
+ return 10;
806
+ case "float32":
807
+ return 1;
808
+ case "float64":
809
+ return 11;
810
+ case "string":
811
+ return 8;
812
+ case "int64":
813
+ return 7;
814
+ case "uint64":
815
+ return 13;
816
+ case "int4":
817
+ return 22;
818
+ case "uint4":
819
+ return 21;
820
+ default:
821
+ throw new Error(`unsupported data type: ${e}`);
822
+ }
823
+ }, Ae = (e) => {
824
+ switch (e) {
825
+ case 3:
826
+ return "int8";
827
+ case 2:
828
+ return "uint8";
829
+ case 9:
830
+ return "bool";
831
+ case 5:
832
+ return "int16";
833
+ case 4:
834
+ return "uint16";
835
+ case 6:
836
+ return "int32";
837
+ case 12:
838
+ return "uint32";
839
+ case 10:
840
+ return "float16";
841
+ case 1:
842
+ return "float32";
843
+ case 11:
844
+ return "float64";
845
+ case 8:
846
+ return "string";
847
+ case 7:
848
+ return "int64";
849
+ case 13:
850
+ return "uint64";
851
+ case 22:
852
+ return "int4";
853
+ case 21:
854
+ return "uint4";
855
+ default:
856
+ throw new Error(`unsupported data type: ${e}`);
857
+ }
858
+ }, re = (e, t) => {
859
+ let r = [-1, 4, 1, 1, 2, 2, 4, 8, -1, 1, 2, 8, 4, 8, -1, -1, -1, -1, -1, -1, -1, 0.5, 0.5][e], n = typeof t == "number" ? t : t.reduce((a, i) => a * i, 1);
860
+ return r > 0 ? Math.ceil(n * r) : void 0;
861
+ }, rr = (e) => {
862
+ switch (e) {
863
+ case "float16":
864
+ return typeof Float16Array < "u" && Float16Array.from ? Float16Array : Uint16Array;
865
+ case "float32":
866
+ return Float32Array;
867
+ case "uint8":
868
+ return Uint8Array;
869
+ case "int8":
870
+ return Int8Array;
871
+ case "uint16":
872
+ return Uint16Array;
873
+ case "int16":
874
+ return Int16Array;
875
+ case "int32":
876
+ return Int32Array;
877
+ case "bool":
878
+ return Uint8Array;
879
+ case "float64":
880
+ return Float64Array;
881
+ case "uint32":
882
+ return Uint32Array;
883
+ case "int64":
884
+ return BigInt64Array;
885
+ case "uint64":
886
+ return BigUint64Array;
887
+ default:
888
+ throw new Error(`unsupported type: ${e}`);
889
+ }
890
+ }, nr = (e) => {
891
+ switch (e) {
892
+ case "verbose":
893
+ return 0;
894
+ case "info":
895
+ return 1;
896
+ case "warning":
897
+ return 2;
898
+ case "error":
899
+ return 3;
900
+ case "fatal":
901
+ return 4;
902
+ default:
903
+ throw new Error(`unsupported logging level: ${e}`);
904
+ }
905
+ }, tt = (e) => e === "float32" || e === "float16" || e === "int32" || e === "int64" || e === "uint32" || e === "uint8" || e === "bool" || e === "uint4" || e === "int4", rt = (e) => e === "float32" || e === "float16" || e === "int32" || e === "int64" || e === "uint32" || e === "uint64" || e === "int8" || e === "uint8" || e === "bool" || e === "uint4" || e === "int4", ar = (e) => {
906
+ switch (e) {
907
+ case "none":
908
+ return 0;
909
+ case "cpu":
910
+ return 1;
911
+ case "cpu-pinned":
912
+ return 2;
913
+ case "texture":
914
+ return 3;
915
+ case "gpu-buffer":
916
+ return 4;
917
+ case "ml-tensor":
918
+ return 5;
919
+ default:
920
+ throw new Error(`unsupported data location: ${e}`);
921
+ }
922
+ };
923
+ }), nt, ir = b(() => {
924
+ Ye(), nt = async (e) => {
925
+ if (typeof e == "string") {
926
+ let t = await fetch(e);
927
+ if (!t.ok) throw new Error(`failed to load external data file: ${e}`);
928
+ let r = t.headers.get("Content-Length"), n = r ? parseInt(r, 10) : 0;
929
+ if (n < 1073741824) return new Uint8Array(await t.arrayBuffer());
930
+ {
931
+ if (!t.body) throw new Error(`failed to load external data file: ${e}, no response body.`);
932
+ let a = t.body.getReader(), i;
933
+ try {
934
+ i = new ArrayBuffer(n);
935
+ } catch (l) {
936
+ if (l instanceof RangeError) {
937
+ let s = Math.ceil(n / 65536);
938
+ i = new WebAssembly.Memory({ initial: s, maximum: s }).buffer;
939
+ } else throw l;
940
+ }
941
+ let o = 0;
942
+ for (; ; ) {
943
+ let { done: l, value: s } = await a.read();
944
+ if (l) break;
945
+ let u = s.byteLength;
946
+ new Uint8Array(i, o, u).set(s), o += u;
947
+ }
948
+ return new Uint8Array(i, 0, n);
949
+ }
950
+ } else return e instanceof Blob ? new Uint8Array(await e.arrayBuffer()) : e instanceof Uint8Array ? e : new Uint8Array(e);
951
+ };
952
+ }), Ut, at, ot, Z, Lt, De, Re, it, st, Ge, lt, ut, ft, sr = b(() => {
953
+ Q(), Wr(), Vr(), or(), se(), et(), ir(), Ut = (e, t) => {
954
+ O()._OrtInit(e, t) !== 0 && T("Can't initialize onnxruntime.");
955
+ }, at = async (e) => {
956
+ Ut(e.wasm.numThreads, nr(e.logLevel));
957
+ }, ot = async (e, t) => {
958
+ O().asyncInit?.();
959
+ let r = e.webgpu.adapter;
960
+ if (t === "webgpu") {
961
+ if (typeof navigator > "u" || !navigator.gpu) throw new Error("WebGPU is not supported in current environment");
962
+ if (r) {
963
+ if (typeof r.limits != "object" || typeof r.features != "object" || typeof r.requestDevice != "function") throw new Error("Invalid GPU adapter set in `env.webgpu.adapter`. It must be a GPUAdapter object.");
964
+ } else {
965
+ let n = e.webgpu.powerPreference;
966
+ if (n !== void 0 && n !== "low-power" && n !== "high-performance") throw new Error(`Invalid powerPreference setting: "${n}"`);
967
+ let a = e.webgpu.forceFallbackAdapter;
968
+ if (a !== void 0 && typeof a != "boolean") throw new Error(`Invalid forceFallbackAdapter setting: "${a}"`);
969
+ if (r = await navigator.gpu.requestAdapter({ powerPreference: n, forceFallbackAdapter: a }), !r) throw new Error('Failed to get GPU adapter. You may need to enable flag "--enable-unsafe-webgpu" if you are using Chrome.');
970
+ }
971
+ }
972
+ if (t === "webnn" && (typeof navigator > "u" || !navigator.ml)) throw new Error("WebNN is not supported in current environment");
973
+ }, Z = /* @__PURE__ */ new Map(), Lt = (e) => {
974
+ let t = O(), r = t.stackSave();
975
+ try {
976
+ let n = t.PTR_SIZE, a = t.stackAlloc(2 * n);
977
+ t._OrtGetInputOutputCount(e, a, a + n) !== 0 && T("Can't get session input/output count.");
978
+ let i = n === 4 ? "i32" : "i64";
979
+ return [Number(t.getValue(a, i)), Number(t.getValue(a + n, i))];
980
+ } finally {
981
+ t.stackRestore(r);
982
+ }
983
+ }, De = (e, t) => {
984
+ let r = O(), n = r.stackSave(), a = 0;
985
+ try {
986
+ let i = r.PTR_SIZE, o = r.stackAlloc(2 * i);
987
+ r._OrtGetInputOutputMetadata(e, t, o, o + i) !== 0 && T("Can't get session input/output metadata.");
988
+ let l = Number(r.getValue(o, "*"));
989
+ a = Number(r.getValue(o + i, "*"));
990
+ let s = r.HEAP32[a / 4];
991
+ if (s === 0) return [l, 0];
992
+ let u = r.HEAPU32[a / 4 + 1], f = [];
993
+ for (let p = 0; p < u; p++) {
994
+ let d = Number(r.getValue(a + 8 + p * i, "*"));
995
+ f.push(d !== 0 ? r.UTF8ToString(d) : Number(r.getValue(a + 8 + (p + u) * i, "*")));
996
+ }
997
+ return [l, s, f];
998
+ } finally {
999
+ r.stackRestore(n), a !== 0 && r._OrtFree(a);
1000
+ }
1001
+ }, Re = (e) => {
1002
+ let t = O(), r = t._malloc(e.byteLength);
1003
+ if (r === 0) throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);
1004
+ return t.HEAPU8.set(e, r), [r, e.byteLength];
1005
+ }, it = async (e, t) => {
1006
+ let r, n, a = O();
1007
+ Array.isArray(e) ? [r, n] = e : e.buffer === a.HEAPU8.buffer ? [r, n] = [e.byteOffset, e.byteLength] : [r, n] = Re(e);
1008
+ let i = 0, o = 0, l = [], s = [], u = [];
1009
+ try {
1010
+ if ([o, l] = await tr(t), t?.externalData && a.mountExternalData) {
1011
+ let c = [];
1012
+ for (let y of t.externalData) {
1013
+ let E = typeof y == "string" ? y : y.path;
1014
+ c.push(nt(typeof y == "string" ? y : y.data).then((x) => {
1015
+ a.mountExternalData(E, x);
1016
+ }));
1017
+ }
1018
+ await Promise.all(c);
1019
+ }
1020
+ for (let c of t?.executionProviders ?? []) if ((typeof c == "string" ? c : c.name) === "webnn") {
1021
+ if (a.shouldTransferToMLTensor = !1, typeof c != "string") {
1022
+ let y = c, E = y?.context, x = y?.gpuDevice, P = y?.deviceType, q = y?.powerPreference;
1023
+ E ? a.currentContext = E : x ? a.currentContext = await a.webnnCreateMLContext(x) : a.currentContext = await a.webnnCreateMLContext({ deviceType: P, powerPreference: q });
1024
+ } else a.currentContext = await a.webnnCreateMLContext();
1025
+ break;
1026
+ }
1027
+ i = await a._OrtCreateSession(r, n, o), a.webgpuOnCreateSession?.(i), i === 0 && T("Can't create a session."), a.jsepOnCreateSession?.(), a.currentContext && (a.webnnRegisterMLContext(i, a.currentContext), a.currentContext = void 0, a.shouldTransferToMLTensor = !0);
1028
+ let [f, p] = Lt(i), d = !!t?.enableGraphCapture, w = [], h = [], v = [], C = [], m = [];
1029
+ for (let c = 0; c < f; c++) {
1030
+ let [y, E, x] = De(i, c);
1031
+ y === 0 && T("Can't get an input name."), s.push(y);
1032
+ let P = a.UTF8ToString(y);
1033
+ w.push(P), v.push(E === 0 ? { name: P, isTensor: !1 } : { name: P, isTensor: !0, type: Ae(E), shape: x });
1034
+ }
1035
+ for (let c = 0; c < p; c++) {
1036
+ let [y, E, x] = De(i, c + f);
1037
+ y === 0 && T("Can't get an output name."), u.push(y);
1038
+ let P = a.UTF8ToString(y);
1039
+ h.push(P), C.push(E === 0 ? { name: P, isTensor: !1 } : { name: P, isTensor: !0, type: Ae(E), shape: x });
1040
+ }
1041
+ return Z.set(i, [i, s, u, null, d, !1]), [i, w, h, v, C];
1042
+ } catch (f) {
1043
+ throw s.forEach((p) => a._OrtFree(p)), u.forEach((p) => a._OrtFree(p)), i !== 0 && a._OrtReleaseSession(i) !== 0 && T("Can't release session."), f;
1044
+ } finally {
1045
+ a._free(r), o !== 0 && a._OrtReleaseSessionOptions(o) !== 0 && T("Can't release session options."), l.forEach((f) => a._free(f)), a.unmountExternalData?.();
1046
+ }
1047
+ }, st = (e) => {
1048
+ let t = O(), r = Z.get(e);
1049
+ if (!r) throw new Error(`cannot release session. invalid session id: ${e}`);
1050
+ let [n, a, i, o, l] = r;
1051
+ o && (l && t._OrtClearBoundOutputs(o.handle) !== 0 && T("Can't clear bound outputs."), t._OrtReleaseBinding(o.handle) !== 0 && T("Can't release IO binding.")), t.jsepOnReleaseSession?.(e), t.webnnOnReleaseSession?.(e), t.webgpuOnReleaseSession?.(e), a.forEach((s) => t._OrtFree(s)), i.forEach((s) => t._OrtFree(s)), t._OrtReleaseSession(n) !== 0 && T("Can't release session."), Z.delete(e);
1052
+ }, Ge = async (e, t, r, n, a, i, o = !1) => {
1053
+ if (!e) {
1054
+ t.push(0);
1055
+ return;
1056
+ }
1057
+ let l = O(), s = l.PTR_SIZE, u = e[0], f = e[1], p = e[3], d = p, w, h;
1058
+ if (u === "string" && (p === "gpu-buffer" || p === "ml-tensor")) throw new Error("String tensor is not supported on GPU.");
1059
+ if (o && p !== "gpu-buffer") throw new Error(`External buffer must be provided for input/output index ${i} when enableGraphCapture is true.`);
1060
+ if (p === "gpu-buffer") {
1061
+ let m = e[2].gpuBuffer;
1062
+ h = re(te(u), f);
1063
+ {
1064
+ let c = l.jsepRegisterBuffer;
1065
+ if (!c) throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');
1066
+ w = c(n, i, m, h);
1067
+ }
1068
+ } else if (p === "ml-tensor") {
1069
+ let m = e[2].mlTensor;
1070
+ h = re(te(u), f);
1071
+ let c = l.webnnRegisterMLTensor;
1072
+ if (!c) throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
1073
+ w = c(n, m, te(u), f);
1074
+ } else {
1075
+ let m = e[2];
1076
+ if (Array.isArray(m)) {
1077
+ h = s * m.length, w = l._malloc(h), r.push(w);
1078
+ for (let c = 0; c < m.length; c++) {
1079
+ if (typeof m[c] != "string") throw new TypeError(`tensor data at index ${c} is not a string`);
1080
+ l.setValue(w + c * s, B(m[c], r), "*");
1081
+ }
1082
+ } else {
1083
+ let c = l.webnnIsGraphInput, y = l.webnnIsGraphOutput;
1084
+ if (u !== "string" && c && y) {
1085
+ let E = l.UTF8ToString(a);
1086
+ if (c(n, E) || y(n, E)) {
1087
+ let x = te(u);
1088
+ h = re(x, f), d = "ml-tensor";
1089
+ let P = l.webnnCreateTemporaryTensor, q = l.webnnUploadTensor;
1090
+ if (!P || !q) throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');
1091
+ let X = await P(n, x, f);
1092
+ q(X, new Uint8Array(m.buffer, m.byteOffset, m.byteLength)), w = X;
1093
+ } else h = m.byteLength, w = l._malloc(h), r.push(w), l.HEAPU8.set(new Uint8Array(m.buffer, m.byteOffset, h), w);
1094
+ } else h = m.byteLength, w = l._malloc(h), r.push(w), l.HEAPU8.set(new Uint8Array(m.buffer, m.byteOffset, h), w);
1095
+ }
1096
+ }
1097
+ let v = l.stackSave(), C = l.stackAlloc(4 * f.length);
1098
+ try {
1099
+ f.forEach((c, y) => l.setValue(C + y * s, c, s === 4 ? "i32" : "i64"));
1100
+ let m = l._OrtCreateTensor(te(u), w, h, C, f.length, ar(d));
1101
+ m === 0 && T(`Can't create tensor for input/output. session=${n}, index=${i}.`), t.push(m);
1102
+ } finally {
1103
+ l.stackRestore(v);
1104
+ }
1105
+ }, lt = async (e, t, r, n, a, i) => {
1106
+ let o = O(), l = o.PTR_SIZE, s = Z.get(e);
1107
+ if (!s) throw new Error(`cannot run inference. invalid session id: ${e}`);
1108
+ let u = s[0], f = s[1], p = s[2], d = s[3], w = s[4];
1109
+ s[5];
1110
+ let h = t.length, v = n.length, C = 0, m = [], c = [], y = [], E = [], x = o.stackSave(), P = o.stackAlloc(h * l), q = o.stackAlloc(h * l), X = o.stackAlloc(v * l), pt = o.stackAlloc(v * l);
1111
+ try {
1112
+ [C, m] = er(i), oe("wasm prepareInputOutputTensor");
1113
+ for (let g = 0; g < h; g++) await Ge(r[g], c, E, e, f[t[g]], t[g], w);
1114
+ for (let g = 0; g < v; g++) await Ge(a[g], y, E, e, p[n[g]], h + n[g], w);
1115
+ ie("wasm prepareInputOutputTensor");
1116
+ for (let g = 0; g < h; g++) o.setValue(P + g * l, c[g], "*"), o.setValue(q + g * l, f[t[g]], "*");
1117
+ for (let g = 0; g < v; g++) o.setValue(X + g * l, y[g], "*"), o.setValue(pt + g * l, p[n[g]], "*");
1118
+ o.jsepOnRunStart?.(u), o.webnnOnRunStart?.(u);
1119
+ let k;
1120
+ k = await o._OrtRun(u, q, P, h, pt, v, X, C), k !== 0 && T("failed to call OrtRun().");
1121
+ let D = [], dt = [];
1122
+ oe("wasm ProcessOutputTensor");
1123
+ for (let g = 0; g < v; g++) {
1124
+ let F = Number(o.getValue(X + g * l, "*"));
1125
+ if (F === y[g]) {
1126
+ D.push(a[g]);
1127
+ continue;
1128
+ }
1129
+ let br = o.stackSave(), j = o.stackAlloc(4 * l), he = !1, U, $ = 0;
1130
+ try {
1131
+ o._OrtGetTensorData(F, j, j + l, j + 2 * l, j + 3 * l) !== 0 && T(`Can't access output tensor data on index ${g}.`);
1132
+ let Ue = l === 4 ? "i32" : "i64", me = Number(o.getValue(j, Ue));
1133
+ $ = o.getValue(j + l, "*");
1134
+ let ct = o.getValue(j + l * 2, "*"), vr = Number(o.getValue(j + l * 3, Ue)), W = [];
1135
+ for (let L = 0; L < vr; L++) W.push(Number(o.getValue(ct + L * l, Ue)));
1136
+ o._OrtFree(ct) !== 0 && T("Can't free memory for tensor dims.");
1137
+ let V = W.reduce((L, R) => L * R, 1);
1138
+ U = Ae(me);
1139
+ let le = d?.outputPreferredLocations[n[g]];
1140
+ if (U === "string") {
1141
+ if (le === "gpu-buffer" || le === "ml-tensor") throw new Error("String tensor is not supported on GPU.");
1142
+ let L = [];
1143
+ for (let R = 0; R < V; R++) {
1144
+ let G = o.getValue($ + R * l, "*"), Er = o.getValue($ + (R + 1) * l, "*"), Tr = R === V - 1 ? void 0 : Er - G;
1145
+ L.push(o.UTF8ToString(G, Tr));
1146
+ }
1147
+ D.push([U, W, L, "cpu"]);
1148
+ } else if (le === "gpu-buffer" && V > 0) {
1149
+ let L = o.jsepGetBuffer;
1150
+ if (!L) throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');
1151
+ let R = L($), G = re(me, V);
1152
+ if (G === void 0 || !tt(U)) throw new Error(`Unsupported data type: ${U}`);
1153
+ he = !0, D.push([U, W, { gpuBuffer: R, download: o.jsepCreateDownloader(R, G, U), dispose: () => {
1154
+ o._OrtReleaseTensor(F) !== 0 && T("Can't release tensor.");
1155
+ } }, "gpu-buffer"]);
1156
+ } else if (le === "ml-tensor" && V > 0) {
1157
+ let L = o.webnnEnsureTensor, R = o.webnnIsGraphInputOutputTypeSupported;
1158
+ if (!L || !R) throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');
1159
+ if (re(me, V) === void 0 || !rt(U)) throw new Error(`Unsupported data type: ${U}`);
1160
+ if (!R(e, U, !1)) throw new Error(`preferredLocation "ml-tensor" for ${U} output is not supported by current WebNN Context.`);
1161
+ let G = await L(e, $, me, W, !1);
1162
+ he = !0, D.push([U, W, { mlTensor: G, download: o.webnnCreateMLTensorDownloader($, U), dispose: () => {
1163
+ o.webnnReleaseTensorId($), o._OrtReleaseTensor(F);
1164
+ } }, "ml-tensor"]);
1165
+ } else if (le === "ml-tensor-cpu-output" && V > 0) {
1166
+ let L = o.webnnCreateMLTensorDownloader($, U)(), R = D.length;
1167
+ he = !0, dt.push((async () => {
1168
+ let G = [R, await L];
1169
+ return o.webnnReleaseTensorId($), o._OrtReleaseTensor(F), G;
1170
+ })()), D.push([U, W, [], "cpu"]);
1171
+ } else {
1172
+ let L = rr(U), R = new L(V);
1173
+ new Uint8Array(R.buffer, R.byteOffset, R.byteLength).set(o.HEAPU8.subarray($, $ + R.byteLength)), D.push([U, W, R, "cpu"]);
1174
+ }
1175
+ } finally {
1176
+ o.stackRestore(br), U === "string" && $ && o._free($), he || o._OrtReleaseTensor(F);
1177
+ }
1178
+ }
1179
+ d && !w && (o._OrtClearBoundOutputs(d.handle) !== 0 && T("Can't clear bound outputs."), Z.set(e, [u, f, p, d, w, !1]));
1180
+ for (let [g, F] of await Promise.all(dt)) D[g][2] = F;
1181
+ return ie("wasm ProcessOutputTensor"), D;
1182
+ } finally {
1183
+ o.webnnOnRunEnd?.(u), o.stackRestore(x), c.forEach((k) => o._OrtReleaseTensor(k)), y.forEach((k) => o._OrtReleaseTensor(k)), E.forEach((k) => o._free(k)), C !== 0 && o._OrtReleaseRunOptions(C), m.forEach((k) => o._free(k));
1184
+ }
1185
+ }, ut = (e) => {
1186
+ let t = O(), r = Z.get(e);
1187
+ if (!r) throw new Error("invalid session id");
1188
+ let n = r[0], a = t._OrtEndProfiling(n);
1189
+ a === 0 && T("Can't get an profile file name."), t._OrtFree(a);
1190
+ }, ft = (e) => {
1191
+ let t = [];
1192
+ for (let r of e) {
1193
+ let n = r[2];
1194
+ !Array.isArray(n) && "buffer" in n && t.push(n.buffer);
1195
+ }
1196
+ return t;
1197
+ };
1198
+ }), H, S, ee, de, ce, ve, Fe, Ee, J, Y, It, lr, ur, fr, pr, dr, cr, wr, hr = b(() => {
1199
+ Q(), sr(), se(), Qe(), H = () => !!A.wasm.proxy && typeof document < "u", ee = !1, de = !1, ce = !1, Ee = /* @__PURE__ */ new Map(), J = (e, t) => {
1200
+ let r = Ee.get(e);
1201
+ r ? r.push(t) : Ee.set(e, [t]);
1202
+ }, Y = () => {
1203
+ if (ee || !de || ce || !S) throw new Error("worker not ready");
1204
+ }, It = (e) => {
1205
+ switch (e.data.type) {
1206
+ case "init-wasm":
1207
+ ee = !1, e.data.err ? (ce = !0, Fe[1](e.data.err)) : (de = !0, Fe[0]()), ve && (URL.revokeObjectURL(ve), ve = void 0);
1208
+ break;
1209
+ case "init-ep":
1210
+ case "copy-from":
1211
+ case "create":
1212
+ case "release":
1213
+ case "run":
1214
+ case "end-profiling": {
1215
+ let t = Ee.get(e.data.type);
1216
+ e.data.err ? t.shift()[1](e.data.err) : t.shift()[0](e.data.out);
1217
+ break;
1218
+ }
1219
+ }
1220
+ }, lr = async () => {
1221
+ if (!de) {
1222
+ if (ee) throw new Error("multiple calls to 'initWasm()' detected.");
1223
+ if (ce) throw new Error("previous call to 'initWasm()' failed.");
1224
+ if (ee = !0, H()) return new Promise((e, t) => {
1225
+ S?.terminate(), Qt().then(([r, n]) => {
1226
+ try {
1227
+ S = n, S.onerror = (i) => t(i), S.onmessage = It, Fe = [e, t];
1228
+ let a = { type: "init-wasm", in: A };
1229
+ if (!a.in.wasm.wasmPaths && r) {
1230
+ let i = Ke();
1231
+ i && (a.in.wasm.wasmPaths = i);
1232
+ }
1233
+ S.postMessage(a), ve = r;
1234
+ } catch (a) {
1235
+ t(a);
1236
+ }
1237
+ }, t);
1238
+ });
1239
+ try {
1240
+ await Xe(A.wasm), await at(A), de = !0;
1241
+ } catch (e) {
1242
+ throw ce = !0, e;
1243
+ } finally {
1244
+ ee = !1;
1245
+ }
1246
+ }
1247
+ }, ur = async (e) => {
1248
+ if (H()) return Y(), new Promise((t, r) => {
1249
+ J("init-ep", [t, r]);
1250
+ let n = { type: "init-ep", in: { epName: e, env: A } };
1251
+ S.postMessage(n);
1252
+ });
1253
+ await ot(A, e);
1254
+ }, fr = async (e) => H() ? (Y(), new Promise((t, r) => {
1255
+ J("copy-from", [t, r]);
1256
+ let n = { type: "copy-from", in: { buffer: e } };
1257
+ S.postMessage(n, [e.buffer]);
1258
+ })) : Re(e), pr = async (e, t) => {
1259
+ if (H()) {
1260
+ if (t?.preferredOutputLocation) throw new Error('session option "preferredOutputLocation" is not supported for proxy.');
1261
+ return Y(), new Promise((r, n) => {
1262
+ J("create", [r, n]);
1263
+ let a = { type: "create", in: { model: e, options: { ...t } } }, i = [];
1264
+ e instanceof Uint8Array && i.push(e.buffer), S.postMessage(a, i);
1265
+ });
1266
+ } else return it(e, t);
1267
+ }, dr = async (e) => {
1268
+ if (H()) return Y(), new Promise((t, r) => {
1269
+ J("release", [t, r]);
1270
+ let n = { type: "release", in: e };
1271
+ S.postMessage(n);
1272
+ });
1273
+ st(e);
1274
+ }, cr = async (e, t, r, n, a, i) => {
1275
+ if (H()) {
1276
+ if (r.some((o) => o[3] !== "cpu")) throw new Error("input tensor on GPU is not supported for proxy.");
1277
+ if (a.some((o) => o)) throw new Error("pre-allocated output tensor is not supported for proxy.");
1278
+ return Y(), new Promise((o, l) => {
1279
+ J("run", [o, l]);
1280
+ let s = r, u = { type: "run", in: { sessionId: e, inputIndices: t, inputs: s, outputIndices: n, options: i } };
1281
+ S.postMessage(u, ft(s));
1282
+ });
1283
+ } else return lt(e, t, r, n, a, i);
1284
+ }, wr = async (e) => {
1285
+ if (H()) return Y(), new Promise((t, r) => {
1286
+ J("end-profiling", [t, r]);
1287
+ let n = { type: "end-profiling", in: e };
1288
+ S.postMessage(n);
1289
+ });
1290
+ ut(e);
1291
+ };
1292
+ }), je, xt, mr, zr = b(() => {
1293
+ Q(), hr(), or(), Ye(), ir(), je = (e, t) => {
1294
+ switch (e.location) {
1295
+ case "cpu":
1296
+ return [e.type, e.dims, e.data, "cpu"];
1297
+ case "gpu-buffer":
1298
+ return [e.type, e.dims, { gpuBuffer: e.gpuBuffer }, "gpu-buffer"];
1299
+ case "ml-tensor":
1300
+ return [e.type, e.dims, { mlTensor: e.mlTensor }, "ml-tensor"];
1301
+ default:
1302
+ throw new Error(`invalid data location: ${e.location} for ${t()}`);
1303
+ }
1304
+ }, xt = (e) => {
1305
+ switch (e[3]) {
1306
+ case "cpu":
1307
+ return new N(e[0], e[2], e[1]);
1308
+ case "gpu-buffer": {
1309
+ let t = e[0];
1310
+ if (!tt(t)) throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);
1311
+ let { gpuBuffer: r, download: n, dispose: a } = e[2];
1312
+ return N.fromGpuBuffer(r, { dataType: t, dims: e[1], download: n, dispose: a });
1313
+ }
1314
+ case "ml-tensor": {
1315
+ let t = e[0];
1316
+ if (!rt(t)) throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);
1317
+ let { mlTensor: r, download: n, dispose: a } = e[2];
1318
+ return N.fromMLTensor(r, { dataType: t, dims: e[1], download: n, dispose: a });
1319
+ }
1320
+ default:
1321
+ throw new Error(`invalid data location: ${e[3]}`);
1322
+ }
1323
+ }, mr = class {
1324
+ async fetchModelAndCopyToWasmMemory(e) {
1325
+ return fr(await nt(e));
1326
+ }
1327
+ async loadModel(e, t) {
1328
+ ne();
1329
+ let r;
1330
+ typeof e == "string" ? r = await this.fetchModelAndCopyToWasmMemory(e) : r = e, [this.sessionId, this.inputNames, this.outputNames, this.inputMetadata, this.outputMetadata] = await pr(r, t), ae();
1331
+ }
1332
+ async dispose() {
1333
+ return dr(this.sessionId);
1334
+ }
1335
+ async run(e, t, r) {
1336
+ ne();
1337
+ let n = [], a = [];
1338
+ Object.entries(e).forEach((p) => {
1339
+ let d = p[0], w = p[1], h = this.inputNames.indexOf(d);
1340
+ if (h === -1) throw new Error(`invalid input '${d}'`);
1341
+ n.push(w), a.push(h);
1342
+ });
1343
+ let i = [], o = [];
1344
+ Object.entries(t).forEach((p) => {
1345
+ let d = p[0], w = p[1], h = this.outputNames.indexOf(d);
1346
+ if (h === -1) throw new Error(`invalid output '${d}'`);
1347
+ i.push(w), o.push(h);
1348
+ });
1349
+ let l = n.map((p, d) => je(p, () => `input "${this.inputNames[a[d]]}"`)), s = i.map((p, d) => p ? je(p, () => `output "${this.outputNames[o[d]]}"`) : null), u = await cr(this.sessionId, a, l, o, s, r), f = {};
1350
+ for (let p = 0; p < u.length; p++) f[this.outputNames[o[p]]] = i[p] ?? xt(u[p]);
1351
+ return ae(), f;
1352
+ }
1353
+ startProfiling() {
1354
+ }
1355
+ endProfiling() {
1356
+ wr(this.sessionId);
1357
+ }
1358
+ };
1359
+ }), yr = {};
1360
+ qe(yr, { OnnxruntimeWebAssemblyBackend: () => ze, initializeFlags: () => Ve, wasmBackend: () => gr });
1361
+ var Ve, ze, gr, Hr = b(() => {
1362
+ Q(), hr(), zr(), Ve = () => {
1363
+ (typeof A.wasm.initTimeout != "number" || A.wasm.initTimeout < 0) && (A.wasm.initTimeout = 0);
1364
+ let e = A.wasm.simd;
1365
+ if (typeof e != "boolean" && e !== void 0 && e !== "fixed" && e !== "relaxed" && (console.warn(`Property "env.wasm.simd" is set to unknown value "${e}". Reset it to \`false\` and ignore SIMD feature checking.`), A.wasm.simd = !1), typeof A.wasm.proxy != "boolean" && (A.wasm.proxy = !1), typeof A.wasm.trace != "boolean" && (A.wasm.trace = !1), typeof A.wasm.numThreads != "number" || !Number.isInteger(A.wasm.numThreads) || A.wasm.numThreads <= 0) if (typeof self < "u" && !self.crossOriginIsolated) A.wasm.numThreads = 1;
1366
+ else {
1367
+ let t = typeof navigator > "u" ? Rr("node:os").cpus().length : navigator.hardwareConcurrency;
1368
+ A.wasm.numThreads = Math.min(4, Math.ceil((t || 1) / 2));
1369
+ }
1370
+ }, ze = class {
1371
+ async init(e) {
1372
+ Ve(), await lr(), await ur(e);
1373
+ }
1374
+ async createInferenceSessionHandler(e, t) {
1375
+ let r = new mr();
1376
+ return await r.loadModel(e, t), r;
1377
+ }
1378
+ }, gr = new ze();
1379
+ });
1380
+ Q();
1381
+ Q();
1382
+ Q();
1383
+ var qr = "1.23.2";
1384
+ {
1385
+ let e = (Hr(), Pt(yr)).wasmBackend;
1386
+ Oe("cpu", e, 10), Oe("wasm", e, 10);
1387
+ }
1388
+ Object.defineProperty(A.versions, "web", { value: qr, enumerable: !0 });
1389
+ let Te;
1390
+ self.onmessage = async ({ data: e }) => {
1391
+ try {
1392
+ if (e.type === "init") {
1393
+ A.logLevel = "error", A.wasm.wasmPaths = e.ortWasmPaths, A.wasm.numThreads = e.threads, Te = await Je.create(new Uint8Array(e.model), {
1394
+ executionProviders: ["wasm"],
1395
+ graphOptimizationLevel: "extended"
1396
+ }), self.postMessage({ id: e.id, ready: !0 });
1397
+ return;
1398
+ }
1399
+ const t = new Float32Array(e.input), n = (await Te.run({
1400
+ [Te.inputNames[0]]: new N("float32", t, [1, 7, 160, 160])
1401
+ }))[Te.outputNames[0]].data;
1402
+ self.postMessage({ id: e.id, corrected: n }, [n.buffer]);
1403
+ } catch (t) {
1404
+ self.postMessage({ id: e.id, error: t instanceof Error ? t.message : String(t) });
1405
+ }
1406
+ };