getpatter 0.5.1 → 0.5.3

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,1631 @@
1
+ import {
2
+ __commonJS,
3
+ __esm,
4
+ __glob
5
+ } from "./chunk-QHHBUCMT.mjs";
6
+
7
+ // node_modules/onnxruntime-common/dist/cjs/backend-impl.js
8
+ var require_backend_impl = __commonJS({
9
+ "node_modules/onnxruntime-common/dist/cjs/backend-impl.js"(exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.resolveBackendAndExecutionProviders = exports.registerBackend = void 0;
13
+ var backends = /* @__PURE__ */ new Map();
14
+ var backendsSortedByPriority = [];
15
+ var registerBackend = (name, backend, priority) => {
16
+ if (backend && typeof backend.init === "function" && typeof backend.createInferenceSessionHandler === "function") {
17
+ const currentBackend = backends.get(name);
18
+ if (currentBackend === void 0) {
19
+ backends.set(name, { backend, priority });
20
+ } else if (currentBackend.priority > priority) {
21
+ return;
22
+ } else if (currentBackend.priority === priority) {
23
+ if (currentBackend.backend !== backend) {
24
+ throw new Error(`cannot register backend "${name}" using priority ${priority}`);
25
+ }
26
+ }
27
+ if (priority >= 0) {
28
+ const i = backendsSortedByPriority.indexOf(name);
29
+ if (i !== -1) {
30
+ backendsSortedByPriority.splice(i, 1);
31
+ }
32
+ for (let i2 = 0; i2 < backendsSortedByPriority.length; i2++) {
33
+ if (backends.get(backendsSortedByPriority[i2]).priority <= priority) {
34
+ backendsSortedByPriority.splice(i2, 0, name);
35
+ return;
36
+ }
37
+ }
38
+ backendsSortedByPriority.push(name);
39
+ }
40
+ return;
41
+ }
42
+ throw new TypeError("not a valid backend");
43
+ };
44
+ exports.registerBackend = registerBackend;
45
+ var tryResolveAndInitializeBackend = async (backendName) => {
46
+ const backendInfo = backends.get(backendName);
47
+ if (!backendInfo) {
48
+ return "backend not found.";
49
+ }
50
+ if (backendInfo.initialized) {
51
+ return backendInfo.backend;
52
+ } else if (backendInfo.aborted) {
53
+ return backendInfo.error;
54
+ } else {
55
+ const isInitializing = !!backendInfo.initPromise;
56
+ try {
57
+ if (!isInitializing) {
58
+ backendInfo.initPromise = backendInfo.backend.init(backendName);
59
+ }
60
+ await backendInfo.initPromise;
61
+ backendInfo.initialized = true;
62
+ return backendInfo.backend;
63
+ } catch (e) {
64
+ if (!isInitializing) {
65
+ backendInfo.error = `${e}`;
66
+ backendInfo.aborted = true;
67
+ }
68
+ return backendInfo.error;
69
+ } finally {
70
+ delete backendInfo.initPromise;
71
+ }
72
+ }
73
+ };
74
+ var resolveBackendAndExecutionProviders = async (options) => {
75
+ const eps = options.executionProviders || [];
76
+ const backendHints = eps.map((i) => typeof i === "string" ? i : i.name);
77
+ const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
78
+ let backend;
79
+ const errors = [];
80
+ const availableBackendNames = /* @__PURE__ */ new Set();
81
+ for (const backendName of backendNames) {
82
+ const resolveResult = await tryResolveAndInitializeBackend(backendName);
83
+ if (typeof resolveResult === "string") {
84
+ errors.push({ name: backendName, err: resolveResult });
85
+ } else {
86
+ if (!backend) {
87
+ backend = resolveResult;
88
+ }
89
+ if (backend === resolveResult) {
90
+ availableBackendNames.add(backendName);
91
+ }
92
+ }
93
+ }
94
+ if (!backend) {
95
+ throw new Error(`no available backend found. ERR: ${errors.map((e) => `[${e.name}] ${e.err}`).join(", ")}`);
96
+ }
97
+ for (const { name, err } of errors) {
98
+ if (backendHints.includes(name)) {
99
+ console.warn(`removing requested execution provider "${name}" from session options because it is not available: ${err}`);
100
+ }
101
+ }
102
+ const filteredEps = eps.filter((i) => availableBackendNames.has(typeof i === "string" ? i : i.name));
103
+ return [
104
+ backend,
105
+ new Proxy(options, {
106
+ get: (target, prop) => {
107
+ if (prop === "executionProviders") {
108
+ return filteredEps;
109
+ }
110
+ return Reflect.get(target, prop);
111
+ }
112
+ })
113
+ ];
114
+ };
115
+ exports.resolveBackendAndExecutionProviders = resolveBackendAndExecutionProviders;
116
+ }
117
+ });
118
+
119
+ // node_modules/onnxruntime-common/dist/cjs/backend.js
120
+ var require_backend = __commonJS({
121
+ "node_modules/onnxruntime-common/dist/cjs/backend.js"(exports) {
122
+ "use strict";
123
+ Object.defineProperty(exports, "__esModule", { value: true });
124
+ exports.registerBackend = void 0;
125
+ var backend_impl_js_1 = require_backend_impl();
126
+ Object.defineProperty(exports, "registerBackend", { enumerable: true, get: function() {
127
+ return backend_impl_js_1.registerBackend;
128
+ } });
129
+ }
130
+ });
131
+
132
+ // node_modules/onnxruntime-common/dist/cjs/version.js
133
+ var require_version = __commonJS({
134
+ "node_modules/onnxruntime-common/dist/cjs/version.js"(exports) {
135
+ "use strict";
136
+ Object.defineProperty(exports, "__esModule", { value: true });
137
+ exports.version = void 0;
138
+ exports.version = "1.18.0";
139
+ }
140
+ });
141
+
142
+ // node_modules/onnxruntime-common/dist/cjs/env-impl.js
143
+ var require_env_impl = __commonJS({
144
+ "node_modules/onnxruntime-common/dist/cjs/env-impl.js"(exports) {
145
+ "use strict";
146
+ Object.defineProperty(exports, "__esModule", { value: true });
147
+ exports.env = void 0;
148
+ var version_js_1 = require_version();
149
+ var logLevelValue = "warning";
150
+ exports.env = {
151
+ wasm: {},
152
+ webgl: {},
153
+ webgpu: {},
154
+ versions: { common: version_js_1.version },
155
+ set logLevel(value) {
156
+ if (value === void 0) {
157
+ return;
158
+ }
159
+ if (typeof value !== "string" || ["verbose", "info", "warning", "error", "fatal"].indexOf(value) === -1) {
160
+ throw new Error(`Unsupported logging level: ${value}`);
161
+ }
162
+ logLevelValue = value;
163
+ },
164
+ get logLevel() {
165
+ return logLevelValue;
166
+ }
167
+ };
168
+ Object.defineProperty(exports.env, "logLevel", { enumerable: true });
169
+ }
170
+ });
171
+
172
+ // node_modules/onnxruntime-common/dist/cjs/env.js
173
+ var require_env = __commonJS({
174
+ "node_modules/onnxruntime-common/dist/cjs/env.js"(exports) {
175
+ "use strict";
176
+ Object.defineProperty(exports, "__esModule", { value: true });
177
+ exports.env = void 0;
178
+ var env_impl_js_1 = require_env_impl();
179
+ exports.env = env_impl_js_1.env;
180
+ }
181
+ });
182
+
183
+ // node_modules/onnxruntime-common/dist/cjs/tensor-conversion-impl.js
184
+ var require_tensor_conversion_impl = __commonJS({
185
+ "node_modules/onnxruntime-common/dist/cjs/tensor-conversion-impl.js"(exports) {
186
+ "use strict";
187
+ Object.defineProperty(exports, "__esModule", { value: true });
188
+ exports.tensorToImageData = exports.tensorToDataURL = void 0;
189
+ var tensorToDataURL = (tensor, options) => {
190
+ const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
191
+ canvas.width = tensor.dims[3];
192
+ canvas.height = tensor.dims[2];
193
+ const pixels2DContext = canvas.getContext("2d");
194
+ if (pixels2DContext != null) {
195
+ let width;
196
+ let height;
197
+ if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
198
+ width = tensor.dims[2];
199
+ height = tensor.dims[3];
200
+ } else {
201
+ width = tensor.dims[3];
202
+ height = tensor.dims[2];
203
+ }
204
+ const inputformat = options?.format !== void 0 ? options.format : "RGB";
205
+ const norm = options?.norm;
206
+ let normMean;
207
+ let normBias;
208
+ if (norm === void 0 || norm.mean === void 0) {
209
+ normMean = [255, 255, 255, 255];
210
+ } else {
211
+ if (typeof norm.mean === "number") {
212
+ normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
213
+ } else {
214
+ normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 0];
215
+ if (norm.mean[3] !== void 0) {
216
+ normMean[3] = norm.mean[3];
217
+ }
218
+ }
219
+ }
220
+ if (norm === void 0 || norm.bias === void 0) {
221
+ normBias = [0, 0, 0, 0];
222
+ } else {
223
+ if (typeof norm.bias === "number") {
224
+ normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
225
+ } else {
226
+ normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
227
+ if (norm.bias[3] !== void 0) {
228
+ normBias[3] = norm.bias[3];
229
+ }
230
+ }
231
+ }
232
+ const stride = height * width;
233
+ let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
234
+ if (inputformat === "RGBA") {
235
+ rTensorPointer = 0;
236
+ gTensorPointer = stride;
237
+ bTensorPointer = stride * 2;
238
+ aTensorPointer = stride * 3;
239
+ } else if (inputformat === "RGB") {
240
+ rTensorPointer = 0;
241
+ gTensorPointer = stride;
242
+ bTensorPointer = stride * 2;
243
+ } else if (inputformat === "RBG") {
244
+ rTensorPointer = 0;
245
+ bTensorPointer = stride;
246
+ gTensorPointer = stride * 2;
247
+ }
248
+ for (let i = 0; i < height; i++) {
249
+ for (let j = 0; j < width; j++) {
250
+ const R = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
251
+ const G = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
252
+ const B = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
253
+ const A = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
254
+ pixels2DContext.fillStyle = "rgba(" + R + "," + G + "," + B + "," + A + ")";
255
+ pixels2DContext.fillRect(j, i, 1, 1);
256
+ }
257
+ }
258
+ if ("toDataURL" in canvas) {
259
+ return canvas.toDataURL();
260
+ } else {
261
+ throw new Error("toDataURL is not supported");
262
+ }
263
+ } else {
264
+ throw new Error("Can not access image data");
265
+ }
266
+ };
267
+ exports.tensorToDataURL = tensorToDataURL;
268
+ var tensorToImageData = (tensor, options) => {
269
+ const pixels2DContext = typeof document !== "undefined" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d");
270
+ let image;
271
+ if (pixels2DContext != null) {
272
+ let width;
273
+ let height;
274
+ let channels;
275
+ if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
276
+ width = tensor.dims[2];
277
+ height = tensor.dims[1];
278
+ channels = tensor.dims[3];
279
+ } else {
280
+ width = tensor.dims[3];
281
+ height = tensor.dims[2];
282
+ channels = tensor.dims[1];
283
+ }
284
+ const inputformat = options !== void 0 ? options.format !== void 0 ? options.format : "RGB" : "RGB";
285
+ const norm = options?.norm;
286
+ let normMean;
287
+ let normBias;
288
+ if (norm === void 0 || norm.mean === void 0) {
289
+ normMean = [255, 255, 255, 255];
290
+ } else {
291
+ if (typeof norm.mean === "number") {
292
+ normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
293
+ } else {
294
+ normMean = [norm.mean[0], norm.mean[1], norm.mean[2], 255];
295
+ if (norm.mean[3] !== void 0) {
296
+ normMean[3] = norm.mean[3];
297
+ }
298
+ }
299
+ }
300
+ if (norm === void 0 || norm.bias === void 0) {
301
+ normBias = [0, 0, 0, 0];
302
+ } else {
303
+ if (typeof norm.bias === "number") {
304
+ normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
305
+ } else {
306
+ normBias = [norm.bias[0], norm.bias[1], norm.bias[2], 0];
307
+ if (norm.bias[3] !== void 0) {
308
+ normBias[3] = norm.bias[3];
309
+ }
310
+ }
311
+ }
312
+ const stride = height * width;
313
+ if (options !== void 0) {
314
+ if (options.format !== void 0 && (channels === 4 && options.format !== "RGBA") || channels === 3 && (options.format !== "RGB" && options.format !== "BGR")) {
315
+ throw new Error("Tensor format doesn't match input tensor dims");
316
+ }
317
+ }
318
+ const step = 4;
319
+ let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
320
+ let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
321
+ if (inputformat === "RGBA") {
322
+ rTensorPointer = 0;
323
+ gTensorPointer = stride;
324
+ bTensorPointer = stride * 2;
325
+ aTensorPointer = stride * 3;
326
+ } else if (inputformat === "RGB") {
327
+ rTensorPointer = 0;
328
+ gTensorPointer = stride;
329
+ bTensorPointer = stride * 2;
330
+ } else if (inputformat === "RBG") {
331
+ rTensorPointer = 0;
332
+ bTensorPointer = stride;
333
+ gTensorPointer = stride * 2;
334
+ }
335
+ image = pixels2DContext.createImageData(width, height);
336
+ for (let i = 0; i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) {
337
+ image.data[rImagePointer] = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
338
+ image.data[gImagePointer] = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
339
+ image.data[bImagePointer] = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
340
+ image.data[aImagePointer] = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
341
+ }
342
+ } else {
343
+ throw new Error("Can not access image data");
344
+ }
345
+ return image;
346
+ };
347
+ exports.tensorToImageData = tensorToImageData;
348
+ }
349
+ });
350
+
351
+ // node_modules/onnxruntime-common/dist/cjs/tensor-factory-impl.js
352
+ var require_tensor_factory_impl = __commonJS({
353
+ "node_modules/onnxruntime-common/dist/cjs/tensor-factory-impl.js"(exports) {
354
+ "use strict";
355
+ Object.defineProperty(exports, "__esModule", { value: true });
356
+ exports.tensorFromPinnedBuffer = exports.tensorFromGpuBuffer = exports.tensorFromTexture = exports.tensorFromImage = exports.bufferToTensor = void 0;
357
+ var tensor_impl_js_1 = require_tensor_impl();
358
+ var bufferToTensor = (buffer, options) => {
359
+ if (buffer === void 0) {
360
+ throw new Error("Image buffer must be defined");
361
+ }
362
+ if (options.height === void 0 || options.width === void 0) {
363
+ throw new Error("Image height and width must be defined");
364
+ }
365
+ if (options.tensorLayout === "NHWC") {
366
+ throw new Error("NHWC Tensor layout is not supported yet");
367
+ }
368
+ const { height, width } = options;
369
+ const norm = options.norm ?? { mean: 255, bias: 0 };
370
+ let normMean;
371
+ let normBias;
372
+ if (typeof norm.mean === "number") {
373
+ normMean = [norm.mean, norm.mean, norm.mean, norm.mean];
374
+ } else {
375
+ normMean = [norm.mean[0], norm.mean[1], norm.mean[2], norm.mean[3] ?? 255];
376
+ }
377
+ if (typeof norm.bias === "number") {
378
+ normBias = [norm.bias, norm.bias, norm.bias, norm.bias];
379
+ } else {
380
+ normBias = [norm.bias[0], norm.bias[1], norm.bias[2], norm.bias[3] ?? 0];
381
+ }
382
+ const inputformat = options.format !== void 0 ? options.format : "RGBA";
383
+ const outputformat = options.tensorFormat !== void 0 ? options.tensorFormat !== void 0 ? options.tensorFormat : "RGB" : "RGB";
384
+ const stride = height * width;
385
+ const float32Data = outputformat === "RGBA" ? new Float32Array(stride * 4) : new Float32Array(stride * 3);
386
+ let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
387
+ let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
388
+ if (inputformat === "RGB") {
389
+ step = 3;
390
+ rImagePointer = 0;
391
+ gImagePointer = 1;
392
+ bImagePointer = 2;
393
+ aImagePointer = -1;
394
+ }
395
+ if (outputformat === "RGBA") {
396
+ aTensorPointer = stride * 3;
397
+ } else if (outputformat === "RBG") {
398
+ rTensorPointer = 0;
399
+ bTensorPointer = stride;
400
+ gTensorPointer = stride * 2;
401
+ } else if (outputformat === "BGR") {
402
+ bTensorPointer = 0;
403
+ gTensorPointer = stride;
404
+ rTensorPointer = stride * 2;
405
+ }
406
+ for (let i = 0; i < stride; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) {
407
+ float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias[0]) / normMean[0];
408
+ float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias[1]) / normMean[1];
409
+ float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias[2]) / normMean[2];
410
+ if (aTensorPointer !== -1 && aImagePointer !== -1) {
411
+ float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
412
+ }
413
+ }
414
+ const outputTensor = outputformat === "RGBA" ? new tensor_impl_js_1.Tensor("float32", float32Data, [1, 4, height, width]) : new tensor_impl_js_1.Tensor("float32", float32Data, [1, 3, height, width]);
415
+ return outputTensor;
416
+ };
417
+ exports.bufferToTensor = bufferToTensor;
418
+ var tensorFromImage = async (image, options) => {
419
+ const isHTMLImageEle = typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement;
420
+ const isImageDataEle = typeof ImageData !== "undefined" && image instanceof ImageData;
421
+ const isImageBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
422
+ const isString = typeof image === "string";
423
+ let data;
424
+ let bufferToTensorOptions = options ?? {};
425
+ const createCanvas = () => {
426
+ if (typeof document !== "undefined") {
427
+ return document.createElement("canvas");
428
+ } else if (typeof OffscreenCanvas !== "undefined") {
429
+ return new OffscreenCanvas(1, 1);
430
+ } else {
431
+ throw new Error("Canvas is not supported");
432
+ }
433
+ };
434
+ const createCanvasContext = (canvas) => {
435
+ if (canvas instanceof HTMLCanvasElement) {
436
+ return canvas.getContext("2d");
437
+ } else if (canvas instanceof OffscreenCanvas) {
438
+ return canvas.getContext("2d");
439
+ } else {
440
+ return null;
441
+ }
442
+ };
443
+ if (isHTMLImageEle) {
444
+ const canvas = createCanvas();
445
+ canvas.width = image.width;
446
+ canvas.height = image.height;
447
+ const pixels2DContext = createCanvasContext(canvas);
448
+ if (pixels2DContext != null) {
449
+ let height = image.height;
450
+ let width = image.width;
451
+ if (options !== void 0 && options.resizedHeight !== void 0 && options.resizedWidth !== void 0) {
452
+ height = options.resizedHeight;
453
+ width = options.resizedWidth;
454
+ }
455
+ if (options !== void 0) {
456
+ bufferToTensorOptions = options;
457
+ if (options.tensorFormat !== void 0) {
458
+ throw new Error("Image input config format must be RGBA for HTMLImageElement");
459
+ } else {
460
+ bufferToTensorOptions.tensorFormat = "RGBA";
461
+ }
462
+ bufferToTensorOptions.height = height;
463
+ bufferToTensorOptions.width = width;
464
+ } else {
465
+ bufferToTensorOptions.tensorFormat = "RGBA";
466
+ bufferToTensorOptions.height = height;
467
+ bufferToTensorOptions.width = width;
468
+ }
469
+ pixels2DContext.drawImage(image, 0, 0);
470
+ data = pixels2DContext.getImageData(0, 0, width, height).data;
471
+ } else {
472
+ throw new Error("Can not access image data");
473
+ }
474
+ } else if (isImageDataEle) {
475
+ let height;
476
+ let width;
477
+ if (options !== void 0 && options.resizedWidth !== void 0 && options.resizedHeight !== void 0) {
478
+ height = options.resizedHeight;
479
+ width = options.resizedWidth;
480
+ } else {
481
+ height = image.height;
482
+ width = image.width;
483
+ }
484
+ if (options !== void 0) {
485
+ bufferToTensorOptions = options;
486
+ }
487
+ bufferToTensorOptions.format = "RGBA";
488
+ bufferToTensorOptions.height = height;
489
+ bufferToTensorOptions.width = width;
490
+ if (options !== void 0) {
491
+ const tempCanvas = createCanvas();
492
+ tempCanvas.width = width;
493
+ tempCanvas.height = height;
494
+ const pixels2DContext = createCanvasContext(tempCanvas);
495
+ if (pixels2DContext != null) {
496
+ pixels2DContext.putImageData(image, 0, 0);
497
+ data = pixels2DContext.getImageData(0, 0, width, height).data;
498
+ } else {
499
+ throw new Error("Can not access image data");
500
+ }
501
+ } else {
502
+ data = image.data;
503
+ }
504
+ } else if (isImageBitmap) {
505
+ if (options === void 0) {
506
+ throw new Error("Please provide image config with format for Imagebitmap");
507
+ }
508
+ const canvas = createCanvas();
509
+ canvas.width = image.width;
510
+ canvas.height = image.height;
511
+ const pixels2DContext = createCanvasContext(canvas);
512
+ if (pixels2DContext != null) {
513
+ const height = image.height;
514
+ const width = image.width;
515
+ pixels2DContext.drawImage(image, 0, 0, width, height);
516
+ data = pixels2DContext.getImageData(0, 0, width, height).data;
517
+ bufferToTensorOptions.height = height;
518
+ bufferToTensorOptions.width = width;
519
+ return (0, exports.bufferToTensor)(data, bufferToTensorOptions);
520
+ } else {
521
+ throw new Error("Can not access image data");
522
+ }
523
+ } else if (isString) {
524
+ return new Promise((resolve, reject) => {
525
+ const canvas = createCanvas();
526
+ const context = createCanvasContext(canvas);
527
+ if (!image || !context) {
528
+ return reject();
529
+ }
530
+ const newImage = new Image();
531
+ newImage.crossOrigin = "Anonymous";
532
+ newImage.src = image;
533
+ newImage.onload = () => {
534
+ canvas.width = newImage.width;
535
+ canvas.height = newImage.height;
536
+ context.drawImage(newImage, 0, 0, canvas.width, canvas.height);
537
+ const img = context.getImageData(0, 0, canvas.width, canvas.height);
538
+ bufferToTensorOptions.height = canvas.height;
539
+ bufferToTensorOptions.width = canvas.width;
540
+ resolve((0, exports.bufferToTensor)(img.data, bufferToTensorOptions));
541
+ };
542
+ });
543
+ } else {
544
+ throw new Error("Input data provided is not supported - aborted tensor creation");
545
+ }
546
+ if (data !== void 0) {
547
+ return (0, exports.bufferToTensor)(data, bufferToTensorOptions);
548
+ } else {
549
+ throw new Error("Input data provided is not supported - aborted tensor creation");
550
+ }
551
+ };
552
+ exports.tensorFromImage = tensorFromImage;
553
+ var tensorFromTexture = (texture, options) => {
554
+ const { width, height, download, dispose } = options;
555
+ const dims = [1, height, width, 4];
556
+ return new tensor_impl_js_1.Tensor({ location: "texture", type: "float32", texture, dims, download, dispose });
557
+ };
558
+ exports.tensorFromTexture = tensorFromTexture;
559
+ var tensorFromGpuBuffer = (gpuBuffer, options) => {
560
+ const { dataType, dims, download, dispose } = options;
561
+ return new tensor_impl_js_1.Tensor({ location: "gpu-buffer", type: dataType ?? "float32", gpuBuffer, dims, download, dispose });
562
+ };
563
+ exports.tensorFromGpuBuffer = tensorFromGpuBuffer;
564
+ var tensorFromPinnedBuffer = (type, buffer, dims) => new tensor_impl_js_1.Tensor({ location: "cpu-pinned", type, data: buffer, dims: dims ?? [buffer.length] });
565
+ exports.tensorFromPinnedBuffer = tensorFromPinnedBuffer;
566
+ }
567
+ });
568
+
569
+ // node_modules/onnxruntime-common/dist/cjs/tensor-impl-type-mapping.js
570
+ var require_tensor_impl_type_mapping = __commonJS({
571
+ "node_modules/onnxruntime-common/dist/cjs/tensor-impl-type-mapping.js"(exports) {
572
+ "use strict";
573
+ Object.defineProperty(exports, "__esModule", { value: true });
574
+ exports.checkTypedArray = exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = void 0;
575
+ exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = /* @__PURE__ */ new Map([
576
+ ["float32", Float32Array],
577
+ ["uint8", Uint8Array],
578
+ ["int8", Int8Array],
579
+ ["uint16", Uint16Array],
580
+ ["int16", Int16Array],
581
+ ["int32", Int32Array],
582
+ ["bool", Uint8Array],
583
+ ["float64", Float64Array],
584
+ ["uint32", Uint32Array]
585
+ ]);
586
+ exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = /* @__PURE__ */ new Map([
587
+ [Float32Array, "float32"],
588
+ [Uint8Array, "uint8"],
589
+ [Int8Array, "int8"],
590
+ [Uint16Array, "uint16"],
591
+ [Int16Array, "int16"],
592
+ [Int32Array, "int32"],
593
+ [Float64Array, "float64"],
594
+ [Uint32Array, "uint32"]
595
+ ]);
596
+ var isTypedArrayChecked = false;
597
+ var checkTypedArray = () => {
598
+ if (!isTypedArrayChecked) {
599
+ isTypedArrayChecked = true;
600
+ const isBigInt64ArrayAvailable = typeof BigInt64Array !== "undefined" && BigInt64Array.from;
601
+ const isBigUint64ArrayAvailable = typeof BigUint64Array !== "undefined" && BigUint64Array.from;
602
+ const isFloat16ArrayAvailable = typeof Float16Array !== "undefined" && Float16Array.from;
603
+ if (isBigInt64ArrayAvailable) {
604
+ exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64", BigInt64Array);
605
+ exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, "int64");
606
+ }
607
+ if (isBigUint64ArrayAvailable) {
608
+ exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64", BigUint64Array);
609
+ exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, "uint64");
610
+ }
611
+ if (isFloat16ArrayAvailable) {
612
+ exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Float16Array);
613
+ exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array, "float16");
614
+ } else {
615
+ exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Uint16Array);
616
+ }
617
+ }
618
+ };
619
+ exports.checkTypedArray = checkTypedArray;
620
+ }
621
+ });
622
+
623
+ // node_modules/onnxruntime-common/dist/cjs/tensor-utils-impl.js
624
+ var require_tensor_utils_impl = __commonJS({
625
+ "node_modules/onnxruntime-common/dist/cjs/tensor-utils-impl.js"(exports) {
626
+ "use strict";
627
+ Object.defineProperty(exports, "__esModule", { value: true });
628
+ exports.tensorReshape = exports.calculateSize = void 0;
629
+ var tensor_impl_js_1 = require_tensor_impl();
630
+ var calculateSize = (dims) => {
631
+ let size = 1;
632
+ for (let i = 0; i < dims.length; i++) {
633
+ const dim = dims[i];
634
+ if (typeof dim !== "number" || !Number.isSafeInteger(dim)) {
635
+ throw new TypeError(`dims[${i}] must be an integer, got: ${dim}`);
636
+ }
637
+ if (dim < 0) {
638
+ throw new RangeError(`dims[${i}] must be a non-negative integer, got: ${dim}`);
639
+ }
640
+ size *= dim;
641
+ }
642
+ return size;
643
+ };
644
+ exports.calculateSize = calculateSize;
645
+ var tensorReshape = (tensor, dims) => {
646
+ switch (tensor.location) {
647
+ case "cpu":
648
+ return new tensor_impl_js_1.Tensor(tensor.type, tensor.data, dims);
649
+ case "cpu-pinned":
650
+ return new tensor_impl_js_1.Tensor({
651
+ location: "cpu-pinned",
652
+ data: tensor.data,
653
+ type: tensor.type,
654
+ dims
655
+ });
656
+ case "texture":
657
+ return new tensor_impl_js_1.Tensor({
658
+ location: "texture",
659
+ texture: tensor.texture,
660
+ type: tensor.type,
661
+ dims
662
+ });
663
+ case "gpu-buffer":
664
+ return new tensor_impl_js_1.Tensor({
665
+ location: "gpu-buffer",
666
+ gpuBuffer: tensor.gpuBuffer,
667
+ type: tensor.type,
668
+ dims
669
+ });
670
+ default:
671
+ throw new Error(`tensorReshape: tensor location ${tensor.location} is not supported`);
672
+ }
673
+ };
674
+ exports.tensorReshape = tensorReshape;
675
+ }
676
+ });
677
+
678
+ // node_modules/onnxruntime-common/dist/cjs/tensor-impl.js
679
+ var require_tensor_impl = __commonJS({
680
+ "node_modules/onnxruntime-common/dist/cjs/tensor-impl.js"(exports) {
681
+ "use strict";
682
+ Object.defineProperty(exports, "__esModule", { value: true });
683
+ exports.Tensor = void 0;
684
+ var tensor_conversion_impl_js_1 = require_tensor_conversion_impl();
685
+ var tensor_factory_impl_js_1 = require_tensor_factory_impl();
686
+ var tensor_impl_type_mapping_js_1 = require_tensor_impl_type_mapping();
687
+ var tensor_utils_impl_js_1 = require_tensor_utils_impl();
688
+ var Tensor = class {
689
+ /**
690
+ * implementation.
691
+ */
692
+ constructor(arg0, arg1, arg2) {
693
+ (0, tensor_impl_type_mapping_js_1.checkTypedArray)();
694
+ let type;
695
+ let dims;
696
+ if (typeof arg0 === "object" && "location" in arg0) {
697
+ this.dataLocation = arg0.location;
698
+ type = arg0.type;
699
+ dims = arg0.dims;
700
+ switch (arg0.location) {
701
+ case "cpu-pinned": {
702
+ const expectedTypedArrayConstructor = tensor_impl_type_mapping_js_1.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
703
+ if (!expectedTypedArrayConstructor) {
704
+ throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
705
+ }
706
+ if (!(arg0.data instanceof expectedTypedArrayConstructor)) {
707
+ throw new TypeError(`buffer should be of type ${expectedTypedArrayConstructor.name}`);
708
+ }
709
+ this.cpuData = arg0.data;
710
+ break;
711
+ }
712
+ case "texture": {
713
+ if (type !== "float32") {
714
+ throw new TypeError(`unsupported type "${type}" to create tensor from texture`);
715
+ }
716
+ this.gpuTextureData = arg0.texture;
717
+ this.downloader = arg0.download;
718
+ this.disposer = arg0.dispose;
719
+ break;
720
+ }
721
+ case "gpu-buffer": {
722
+ if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint8" && type !== "bool") {
723
+ throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
724
+ }
725
+ this.gpuBufferData = arg0.gpuBuffer;
726
+ this.downloader = arg0.download;
727
+ this.disposer = arg0.dispose;
728
+ break;
729
+ }
730
+ default:
731
+ throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
732
+ }
733
+ } else {
734
+ let data;
735
+ let maybeDims;
736
+ if (typeof arg0 === "string") {
737
+ type = arg0;
738
+ maybeDims = arg2;
739
+ if (arg0 === "string") {
740
+ if (!Array.isArray(arg1)) {
741
+ throw new TypeError("A string tensor's data must be a string array.");
742
+ }
743
+ data = arg1;
744
+ } else {
745
+ const typedArrayConstructor = tensor_impl_type_mapping_js_1.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
746
+ if (typedArrayConstructor === void 0) {
747
+ throw new TypeError(`Unsupported tensor type: ${arg0}.`);
748
+ }
749
+ if (Array.isArray(arg1)) {
750
+ if (arg0 === "float16" && typedArrayConstructor === Uint16Array) {
751
+ throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");
752
+ } else if (arg0 === "uint64" || arg0 === "int64") {
753
+ data = typedArrayConstructor.from(arg1, BigInt);
754
+ } else {
755
+ data = typedArrayConstructor.from(arg1);
756
+ }
757
+ } else if (arg1 instanceof typedArrayConstructor) {
758
+ data = arg1;
759
+ } else {
760
+ throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
761
+ }
762
+ }
763
+ } else {
764
+ maybeDims = arg1;
765
+ if (Array.isArray(arg0)) {
766
+ if (arg0.length === 0) {
767
+ throw new TypeError("Tensor type cannot be inferred from an empty array.");
768
+ }
769
+ const firstElementType = typeof arg0[0];
770
+ if (firstElementType === "string") {
771
+ type = "string";
772
+ data = arg0;
773
+ } else if (firstElementType === "boolean") {
774
+ type = "bool";
775
+ data = Uint8Array.from(arg0);
776
+ } else {
777
+ throw new TypeError(`Invalid element type of data array: ${firstElementType}.`);
778
+ }
779
+ } else {
780
+ const mappedType = tensor_impl_type_mapping_js_1.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
781
+ if (mappedType === void 0) {
782
+ throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
783
+ }
784
+ type = mappedType;
785
+ data = arg0;
786
+ }
787
+ }
788
+ if (maybeDims === void 0) {
789
+ maybeDims = [data.length];
790
+ } else if (!Array.isArray(maybeDims)) {
791
+ throw new TypeError("A tensor's dims must be a number array");
792
+ }
793
+ dims = maybeDims;
794
+ this.cpuData = data;
795
+ this.dataLocation = "cpu";
796
+ }
797
+ const size = (0, tensor_utils_impl_js_1.calculateSize)(dims);
798
+ if (this.cpuData && size !== this.cpuData.length) {
799
+ throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
800
+ }
801
+ this.type = type;
802
+ this.dims = dims;
803
+ this.size = size;
804
+ }
805
+ // #endregion
806
+ // #region factory
807
+ static async fromImage(image, options) {
808
+ return (0, tensor_factory_impl_js_1.tensorFromImage)(image, options);
809
+ }
810
+ static fromTexture(texture, options) {
811
+ return (0, tensor_factory_impl_js_1.tensorFromTexture)(texture, options);
812
+ }
813
+ static fromGpuBuffer(gpuBuffer, options) {
814
+ return (0, tensor_factory_impl_js_1.tensorFromGpuBuffer)(gpuBuffer, options);
815
+ }
816
+ static fromPinnedBuffer(type, buffer, dims) {
817
+ return (0, tensor_factory_impl_js_1.tensorFromPinnedBuffer)(type, buffer, dims);
818
+ }
819
+ // #endregion
820
+ // #region conversions
821
+ toDataURL(options) {
822
+ return (0, tensor_conversion_impl_js_1.tensorToDataURL)(this, options);
823
+ }
824
+ toImageData(options) {
825
+ return (0, tensor_conversion_impl_js_1.tensorToImageData)(this, options);
826
+ }
827
+ // #endregion
828
+ // #region properties
829
+ get data() {
830
+ this.ensureValid();
831
+ if (!this.cpuData) {
832
+ 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.");
833
+ }
834
+ return this.cpuData;
835
+ }
836
+ get location() {
837
+ return this.dataLocation;
838
+ }
839
+ get texture() {
840
+ this.ensureValid();
841
+ if (!this.gpuTextureData) {
842
+ throw new Error("The data is not stored as a WebGL texture.");
843
+ }
844
+ return this.gpuTextureData;
845
+ }
846
+ get gpuBuffer() {
847
+ this.ensureValid();
848
+ if (!this.gpuBufferData) {
849
+ throw new Error("The data is not stored as a WebGPU buffer.");
850
+ }
851
+ return this.gpuBufferData;
852
+ }
853
+ // #endregion
854
+ // #region methods
855
+ async getData(releaseData) {
856
+ this.ensureValid();
857
+ switch (this.dataLocation) {
858
+ case "cpu":
859
+ case "cpu-pinned":
860
+ return this.data;
861
+ case "texture":
862
+ case "gpu-buffer": {
863
+ if (!this.downloader) {
864
+ throw new Error("The current tensor is not created with a specified data downloader.");
865
+ }
866
+ if (this.isDownloading) {
867
+ throw new Error("The current tensor is being downloaded.");
868
+ }
869
+ try {
870
+ this.isDownloading = true;
871
+ const data = await this.downloader();
872
+ this.downloader = void 0;
873
+ this.dataLocation = "cpu";
874
+ this.cpuData = data;
875
+ if (releaseData && this.disposer) {
876
+ this.disposer();
877
+ this.disposer = void 0;
878
+ }
879
+ return data;
880
+ } finally {
881
+ this.isDownloading = false;
882
+ }
883
+ }
884
+ default:
885
+ throw new Error(`cannot get data from location: ${this.dataLocation}`);
886
+ }
887
+ }
888
+ dispose() {
889
+ if (this.isDownloading) {
890
+ throw new Error("The current tensor is being downloaded.");
891
+ }
892
+ if (this.disposer) {
893
+ this.disposer();
894
+ this.disposer = void 0;
895
+ }
896
+ this.cpuData = void 0;
897
+ this.gpuTextureData = void 0;
898
+ this.gpuBufferData = void 0;
899
+ this.downloader = void 0;
900
+ this.isDownloading = void 0;
901
+ this.dataLocation = "none";
902
+ }
903
+ // #endregion
904
+ // #region tensor utilities
905
+ ensureValid() {
906
+ if (this.dataLocation === "none") {
907
+ throw new Error("The tensor is disposed.");
908
+ }
909
+ }
910
+ reshape(dims) {
911
+ this.ensureValid();
912
+ if (this.downloader || this.disposer) {
913
+ throw new Error("Cannot reshape a tensor that owns GPU resource.");
914
+ }
915
+ return (0, tensor_utils_impl_js_1.tensorReshape)(this, dims);
916
+ }
917
+ };
918
+ exports.Tensor = Tensor;
919
+ }
920
+ });
921
+
922
+ // node_modules/onnxruntime-common/dist/cjs/tensor.js
923
+ var require_tensor = __commonJS({
924
+ "node_modules/onnxruntime-common/dist/cjs/tensor.js"(exports) {
925
+ "use strict";
926
+ Object.defineProperty(exports, "__esModule", { value: true });
927
+ exports.Tensor = void 0;
928
+ var tensor_impl_js_1 = require_tensor_impl();
929
+ exports.Tensor = tensor_impl_js_1.Tensor;
930
+ }
931
+ });
932
+
933
+ // node_modules/onnxruntime-common/dist/cjs/trace.js
934
+ var require_trace = __commonJS({
935
+ "node_modules/onnxruntime-common/dist/cjs/trace.js"(exports) {
936
+ "use strict";
937
+ Object.defineProperty(exports, "__esModule", { value: true });
938
+ exports.TRACE_FUNC_END = exports.TRACE_FUNC_BEGIN = exports.TRACE = void 0;
939
+ var env_impl_js_1 = require_env_impl();
940
+ var TRACE = (deviceType, label) => {
941
+ if (typeof env_impl_js_1.env.trace === "undefined" ? !env_impl_js_1.env.wasm.trace : !env_impl_js_1.env.trace) {
942
+ return;
943
+ }
944
+ console.timeStamp(`${deviceType}::ORT::${label}`);
945
+ };
946
+ exports.TRACE = TRACE;
947
+ var TRACE_FUNC = (msg, extraMsg) => {
948
+ const stack = new Error().stack?.split(/\r\n|\r|\n/g) || [];
949
+ let hasTraceFunc = false;
950
+ for (let i = 0; i < stack.length; i++) {
951
+ if (hasTraceFunc && !stack[i].includes("TRACE_FUNC")) {
952
+ let label = `FUNC_${msg}::${stack[i].trim().split(" ")[1]}`;
953
+ if (extraMsg) {
954
+ label += `::${extraMsg}`;
955
+ }
956
+ (0, exports.TRACE)("CPU", label);
957
+ return;
958
+ }
959
+ if (stack[i].includes("TRACE_FUNC")) {
960
+ hasTraceFunc = true;
961
+ }
962
+ }
963
+ };
964
+ var TRACE_FUNC_BEGIN = (extraMsg) => {
965
+ if (typeof env_impl_js_1.env.trace === "undefined" ? !env_impl_js_1.env.wasm.trace : !env_impl_js_1.env.trace) {
966
+ return;
967
+ }
968
+ TRACE_FUNC("BEGIN", extraMsg);
969
+ };
970
+ exports.TRACE_FUNC_BEGIN = TRACE_FUNC_BEGIN;
971
+ var TRACE_FUNC_END = (extraMsg) => {
972
+ if (typeof env_impl_js_1.env.trace === "undefined" ? !env_impl_js_1.env.wasm.trace : !env_impl_js_1.env.trace) {
973
+ return;
974
+ }
975
+ TRACE_FUNC("END", extraMsg);
976
+ };
977
+ exports.TRACE_FUNC_END = TRACE_FUNC_END;
978
+ }
979
+ });
980
+
981
+ // node_modules/onnxruntime-common/dist/cjs/inference-session-impl.js
982
+ var require_inference_session_impl = __commonJS({
983
+ "node_modules/onnxruntime-common/dist/cjs/inference-session-impl.js"(exports) {
984
+ "use strict";
985
+ Object.defineProperty(exports, "__esModule", { value: true });
986
+ exports.InferenceSession = void 0;
987
+ var backend_impl_js_1 = require_backend_impl();
988
+ var tensor_js_1 = require_tensor();
989
+ var trace_js_1 = require_trace();
990
+ var InferenceSession = class _InferenceSession {
991
+ constructor(handler) {
992
+ this.handler = handler;
993
+ }
994
+ async run(feeds, arg1, arg2) {
995
+ (0, trace_js_1.TRACE_FUNC_BEGIN)();
996
+ const fetches = {};
997
+ let options = {};
998
+ if (typeof feeds !== "object" || feeds === null || feeds instanceof tensor_js_1.Tensor || Array.isArray(feeds)) {
999
+ throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
1000
+ }
1001
+ let isFetchesEmpty = true;
1002
+ if (typeof arg1 === "object") {
1003
+ if (arg1 === null) {
1004
+ throw new TypeError("Unexpected argument[1]: cannot be null.");
1005
+ }
1006
+ if (arg1 instanceof tensor_js_1.Tensor) {
1007
+ throw new TypeError("'fetches' cannot be a Tensor");
1008
+ }
1009
+ if (Array.isArray(arg1)) {
1010
+ if (arg1.length === 0) {
1011
+ throw new TypeError("'fetches' cannot be an empty array.");
1012
+ }
1013
+ isFetchesEmpty = false;
1014
+ for (const name of arg1) {
1015
+ if (typeof name !== "string") {
1016
+ throw new TypeError("'fetches' must be a string array or an object.");
1017
+ }
1018
+ if (this.outputNames.indexOf(name) === -1) {
1019
+ throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
1020
+ }
1021
+ fetches[name] = null;
1022
+ }
1023
+ if (typeof arg2 === "object" && arg2 !== null) {
1024
+ options = arg2;
1025
+ } else if (typeof arg2 !== "undefined") {
1026
+ throw new TypeError("'options' must be an object.");
1027
+ }
1028
+ } else {
1029
+ let isFetches = false;
1030
+ const arg1Keys = Object.getOwnPropertyNames(arg1);
1031
+ for (const name of this.outputNames) {
1032
+ if (arg1Keys.indexOf(name) !== -1) {
1033
+ const v = arg1[name];
1034
+ if (v === null || v instanceof tensor_js_1.Tensor) {
1035
+ isFetches = true;
1036
+ isFetchesEmpty = false;
1037
+ fetches[name] = v;
1038
+ }
1039
+ }
1040
+ }
1041
+ if (isFetches) {
1042
+ if (typeof arg2 === "object" && arg2 !== null) {
1043
+ options = arg2;
1044
+ } else if (typeof arg2 !== "undefined") {
1045
+ throw new TypeError("'options' must be an object.");
1046
+ }
1047
+ } else {
1048
+ options = arg1;
1049
+ }
1050
+ }
1051
+ } else if (typeof arg1 !== "undefined") {
1052
+ throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
1053
+ }
1054
+ for (const name of this.inputNames) {
1055
+ if (typeof feeds[name] === "undefined") {
1056
+ throw new Error(`input '${name}' is missing in 'feeds'.`);
1057
+ }
1058
+ }
1059
+ if (isFetchesEmpty) {
1060
+ for (const name of this.outputNames) {
1061
+ fetches[name] = null;
1062
+ }
1063
+ }
1064
+ const results = await this.handler.run(feeds, fetches, options);
1065
+ const returnValue = {};
1066
+ for (const key in results) {
1067
+ if (Object.hasOwnProperty.call(results, key)) {
1068
+ const result = results[key];
1069
+ if (result instanceof tensor_js_1.Tensor) {
1070
+ returnValue[key] = result;
1071
+ } else {
1072
+ returnValue[key] = new tensor_js_1.Tensor(result.type, result.data, result.dims);
1073
+ }
1074
+ }
1075
+ }
1076
+ (0, trace_js_1.TRACE_FUNC_END)();
1077
+ return returnValue;
1078
+ }
1079
+ async release() {
1080
+ return this.handler.dispose();
1081
+ }
1082
+ static async create(arg0, arg1, arg2, arg3) {
1083
+ (0, trace_js_1.TRACE_FUNC_BEGIN)();
1084
+ let filePathOrUint8Array;
1085
+ let options = {};
1086
+ if (typeof arg0 === "string") {
1087
+ filePathOrUint8Array = arg0;
1088
+ if (typeof arg1 === "object" && arg1 !== null) {
1089
+ options = arg1;
1090
+ } else if (typeof arg1 !== "undefined") {
1091
+ throw new TypeError("'options' must be an object.");
1092
+ }
1093
+ } else if (arg0 instanceof Uint8Array) {
1094
+ filePathOrUint8Array = arg0;
1095
+ if (typeof arg1 === "object" && arg1 !== null) {
1096
+ options = arg1;
1097
+ } else if (typeof arg1 !== "undefined") {
1098
+ throw new TypeError("'options' must be an object.");
1099
+ }
1100
+ } else if (arg0 instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && arg0 instanceof SharedArrayBuffer) {
1101
+ const buffer = arg0;
1102
+ let byteOffset = 0;
1103
+ let byteLength = arg0.byteLength;
1104
+ if (typeof arg1 === "object" && arg1 !== null) {
1105
+ options = arg1;
1106
+ } else if (typeof arg1 === "number") {
1107
+ byteOffset = arg1;
1108
+ if (!Number.isSafeInteger(byteOffset)) {
1109
+ throw new RangeError("'byteOffset' must be an integer.");
1110
+ }
1111
+ if (byteOffset < 0 || byteOffset >= buffer.byteLength) {
1112
+ throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`);
1113
+ }
1114
+ byteLength = arg0.byteLength - byteOffset;
1115
+ if (typeof arg2 === "number") {
1116
+ byteLength = arg2;
1117
+ if (!Number.isSafeInteger(byteLength)) {
1118
+ throw new RangeError("'byteLength' must be an integer.");
1119
+ }
1120
+ if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) {
1121
+ throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`);
1122
+ }
1123
+ if (typeof arg3 === "object" && arg3 !== null) {
1124
+ options = arg3;
1125
+ } else if (typeof arg3 !== "undefined") {
1126
+ throw new TypeError("'options' must be an object.");
1127
+ }
1128
+ } else if (typeof arg2 !== "undefined") {
1129
+ throw new TypeError("'byteLength' must be a number.");
1130
+ }
1131
+ } else if (typeof arg1 !== "undefined") {
1132
+ throw new TypeError("'options' must be an object.");
1133
+ }
1134
+ filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength);
1135
+ } else {
1136
+ throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
1137
+ }
1138
+ const [backend, optionsWithValidatedEPs] = await (0, backend_impl_js_1.resolveBackendAndExecutionProviders)(options);
1139
+ const handler = await backend.createInferenceSessionHandler(filePathOrUint8Array, optionsWithValidatedEPs);
1140
+ (0, trace_js_1.TRACE_FUNC_END)();
1141
+ return new _InferenceSession(handler);
1142
+ }
1143
+ startProfiling() {
1144
+ this.handler.startProfiling();
1145
+ }
1146
+ endProfiling() {
1147
+ this.handler.endProfiling();
1148
+ }
1149
+ get inputNames() {
1150
+ return this.handler.inputNames;
1151
+ }
1152
+ get outputNames() {
1153
+ return this.handler.outputNames;
1154
+ }
1155
+ };
1156
+ exports.InferenceSession = InferenceSession;
1157
+ }
1158
+ });
1159
+
1160
+ // node_modules/onnxruntime-common/dist/cjs/inference-session.js
1161
+ var require_inference_session = __commonJS({
1162
+ "node_modules/onnxruntime-common/dist/cjs/inference-session.js"(exports) {
1163
+ "use strict";
1164
+ Object.defineProperty(exports, "__esModule", { value: true });
1165
+ exports.InferenceSession = void 0;
1166
+ var inference_session_impl_js_1 = require_inference_session_impl();
1167
+ exports.InferenceSession = inference_session_impl_js_1.InferenceSession;
1168
+ }
1169
+ });
1170
+
1171
+ // node_modules/onnxruntime-common/dist/cjs/tensor-conversion.js
1172
+ var require_tensor_conversion = __commonJS({
1173
+ "node_modules/onnxruntime-common/dist/cjs/tensor-conversion.js"(exports) {
1174
+ "use strict";
1175
+ Object.defineProperty(exports, "__esModule", { value: true });
1176
+ }
1177
+ });
1178
+
1179
+ // node_modules/onnxruntime-common/dist/cjs/tensor-factory.js
1180
+ var require_tensor_factory = __commonJS({
1181
+ "node_modules/onnxruntime-common/dist/cjs/tensor-factory.js"(exports) {
1182
+ "use strict";
1183
+ Object.defineProperty(exports, "__esModule", { value: true });
1184
+ }
1185
+ });
1186
+
1187
+ // node_modules/onnxruntime-common/dist/cjs/onnx-model.js
1188
+ var require_onnx_model = __commonJS({
1189
+ "node_modules/onnxruntime-common/dist/cjs/onnx-model.js"(exports) {
1190
+ "use strict";
1191
+ Object.defineProperty(exports, "__esModule", { value: true });
1192
+ }
1193
+ });
1194
+
1195
+ // node_modules/onnxruntime-common/dist/cjs/onnx-value.js
1196
+ var require_onnx_value = __commonJS({
1197
+ "node_modules/onnxruntime-common/dist/cjs/onnx-value.js"(exports) {
1198
+ "use strict";
1199
+ Object.defineProperty(exports, "__esModule", { value: true });
1200
+ }
1201
+ });
1202
+
1203
+ // node_modules/onnxruntime-common/dist/cjs/training-session-impl.js
1204
+ var require_training_session_impl = __commonJS({
1205
+ "node_modules/onnxruntime-common/dist/cjs/training-session-impl.js"(exports) {
1206
+ "use strict";
1207
+ Object.defineProperty(exports, "__esModule", { value: true });
1208
+ exports.TrainingSession = void 0;
1209
+ var backend_impl_js_1 = require_backend_impl();
1210
+ var tensor_js_1 = require_tensor();
1211
+ var noBackendErrMsg = "Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.";
1212
+ var TrainingSession = class _TrainingSession {
1213
+ constructor(handler, hasOptimizerModel, hasEvalModel) {
1214
+ this.handler = handler;
1215
+ this.hasOptimizerModel = hasOptimizerModel;
1216
+ this.hasEvalModel = hasEvalModel;
1217
+ }
1218
+ get trainingInputNames() {
1219
+ return this.handler.inputNames;
1220
+ }
1221
+ get trainingOutputNames() {
1222
+ return this.handler.outputNames;
1223
+ }
1224
+ get evalInputNames() {
1225
+ if (this.hasEvalModel) {
1226
+ return this.handler.evalInputNames;
1227
+ } else {
1228
+ throw new Error("This training session has no evalModel loaded.");
1229
+ }
1230
+ }
1231
+ get evalOutputNames() {
1232
+ if (this.hasEvalModel) {
1233
+ return this.handler.evalOutputNames;
1234
+ } else {
1235
+ throw new Error("This training session has no evalModel loaded.");
1236
+ }
1237
+ }
1238
+ static async create(trainingOptions, sessionOptions) {
1239
+ const evalModel = trainingOptions.evalModel || "";
1240
+ const optimizerModel = trainingOptions.optimizerModel || "";
1241
+ const options = sessionOptions || {};
1242
+ const [backend, optionsWithValidatedEPs] = await (0, backend_impl_js_1.resolveBackendAndExecutionProviders)(options);
1243
+ if (backend.createTrainingSessionHandler) {
1244
+ const handler = await backend.createTrainingSessionHandler(trainingOptions.checkpointState, trainingOptions.trainModel, evalModel, optimizerModel, optionsWithValidatedEPs);
1245
+ return new _TrainingSession(handler, !!trainingOptions.optimizerModel, !!trainingOptions.evalModel);
1246
+ } else {
1247
+ throw new Error(noBackendErrMsg);
1248
+ }
1249
+ }
1250
+ /**
1251
+ * Helper function for runTrainStep and future runStep methods that handles the type-narrowing conversion from
1252
+ * the given parameters to SessionHandler.FetchesType and RunOptions.
1253
+ *
1254
+ * @param inputNames the feeds object is checked that they contain all input names in the provided list of input
1255
+ * names.
1256
+ * @param outputNames the fetches object is checked that their keys match up with valid names in the list of output
1257
+ * names.
1258
+ * @param feeds the required input
1259
+ * @param arg1 narrowed & converted into the SessionHandler.FetchesType or RunOptions object
1260
+ * @param arg2 optional RunOptions object.
1261
+ * @returns
1262
+ */
1263
+ typeNarrowingForRunStep(inputNames, outputNames, feeds, arg1, arg2) {
1264
+ const fetches = {};
1265
+ let options = {};
1266
+ if (typeof feeds !== "object" || feeds === null || feeds instanceof tensor_js_1.Tensor || Array.isArray(feeds)) {
1267
+ throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
1268
+ }
1269
+ let isFetchesEmpty = true;
1270
+ if (typeof arg1 === "object") {
1271
+ if (arg1 === null) {
1272
+ throw new TypeError("Unexpected argument[1]: cannot be null.");
1273
+ }
1274
+ if (arg1 instanceof tensor_js_1.Tensor) {
1275
+ throw new TypeError("'fetches' cannot be a Tensor");
1276
+ }
1277
+ if (Array.isArray(arg1)) {
1278
+ if (arg1.length === 0) {
1279
+ throw new TypeError("'fetches' cannot be an empty array.");
1280
+ }
1281
+ isFetchesEmpty = false;
1282
+ for (const name of arg1) {
1283
+ if (typeof name !== "string") {
1284
+ throw new TypeError("'fetches' must be a string array or an object.");
1285
+ }
1286
+ if (outputNames.indexOf(name) === -1) {
1287
+ throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
1288
+ }
1289
+ fetches[name] = null;
1290
+ }
1291
+ if (typeof arg2 === "object" && arg2 !== null) {
1292
+ options = arg2;
1293
+ } else if (typeof arg2 !== "undefined") {
1294
+ throw new TypeError("'options' must be an object.");
1295
+ }
1296
+ } else {
1297
+ let isFetches = false;
1298
+ const arg1Keys = Object.getOwnPropertyNames(arg1);
1299
+ for (const name of outputNames) {
1300
+ if (arg1Keys.indexOf(name) !== -1) {
1301
+ const v = arg1[name];
1302
+ if (v === null || v instanceof tensor_js_1.Tensor) {
1303
+ isFetches = true;
1304
+ isFetchesEmpty = false;
1305
+ fetches[name] = v;
1306
+ }
1307
+ }
1308
+ }
1309
+ if (isFetches) {
1310
+ if (typeof arg2 === "object" && arg2 !== null) {
1311
+ options = arg2;
1312
+ } else if (typeof arg2 !== "undefined") {
1313
+ throw new TypeError("'options' must be an object.");
1314
+ }
1315
+ } else {
1316
+ options = arg1;
1317
+ }
1318
+ }
1319
+ } else if (typeof arg1 !== "undefined") {
1320
+ throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
1321
+ }
1322
+ for (const name of inputNames) {
1323
+ if (typeof feeds[name] === "undefined") {
1324
+ throw new Error(`input '${name}' is missing in 'feeds'.`);
1325
+ }
1326
+ }
1327
+ if (isFetchesEmpty) {
1328
+ for (const name of outputNames) {
1329
+ fetches[name] = null;
1330
+ }
1331
+ }
1332
+ return [fetches, options];
1333
+ }
1334
+ /**
1335
+ * Helper method for runTrainStep and any other runStep methods. Takes the ReturnType result from the SessionHandler
1336
+ * and changes it into a map of Tensors.
1337
+ *
1338
+ * @param results
1339
+ * @returns
1340
+ */
1341
+ convertHandlerReturnTypeToMapOfTensors(results) {
1342
+ const returnValue = {};
1343
+ for (const key in results) {
1344
+ if (Object.hasOwnProperty.call(results, key)) {
1345
+ const result = results[key];
1346
+ if (result instanceof tensor_js_1.Tensor) {
1347
+ returnValue[key] = result;
1348
+ } else {
1349
+ returnValue[key] = new tensor_js_1.Tensor(result.type, result.data, result.dims);
1350
+ }
1351
+ }
1352
+ }
1353
+ return returnValue;
1354
+ }
1355
+ async lazyResetGrad() {
1356
+ await this.handler.lazyResetGrad();
1357
+ }
1358
+ async runTrainStep(feeds, arg1, arg2) {
1359
+ const [fetches, options] = this.typeNarrowingForRunStep(this.trainingInputNames, this.trainingOutputNames, feeds, arg1, arg2);
1360
+ const results = await this.handler.runTrainStep(feeds, fetches, options);
1361
+ return this.convertHandlerReturnTypeToMapOfTensors(results);
1362
+ }
1363
+ async runOptimizerStep(options) {
1364
+ if (this.hasOptimizerModel) {
1365
+ await this.handler.runOptimizerStep(options || {});
1366
+ } else {
1367
+ throw new Error("This TrainingSession has no OptimizerModel loaded.");
1368
+ }
1369
+ }
1370
+ async runEvalStep(feeds, arg1, arg2) {
1371
+ if (this.hasEvalModel) {
1372
+ const [fetches, options] = this.typeNarrowingForRunStep(this.evalInputNames, this.evalOutputNames, feeds, arg1, arg2);
1373
+ const results = await this.handler.runEvalStep(feeds, fetches, options);
1374
+ return this.convertHandlerReturnTypeToMapOfTensors(results);
1375
+ } else {
1376
+ throw new Error("This TrainingSession has no EvalModel loaded.");
1377
+ }
1378
+ }
1379
+ async getParametersSize(trainableOnly = true) {
1380
+ return this.handler.getParametersSize(trainableOnly);
1381
+ }
1382
+ async loadParametersBuffer(array, trainableOnly = true) {
1383
+ const paramsSize = await this.getParametersSize(trainableOnly);
1384
+ if (array.length !== 4 * paramsSize) {
1385
+ throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");
1386
+ }
1387
+ return this.handler.loadParametersBuffer(array, trainableOnly);
1388
+ }
1389
+ async getContiguousParameters(trainableOnly = true) {
1390
+ return this.handler.getContiguousParameters(trainableOnly);
1391
+ }
1392
+ async release() {
1393
+ return this.handler.dispose();
1394
+ }
1395
+ };
1396
+ exports.TrainingSession = TrainingSession;
1397
+ }
1398
+ });
1399
+
1400
+ // node_modules/onnxruntime-common/dist/cjs/training-session.js
1401
+ var require_training_session = __commonJS({
1402
+ "node_modules/onnxruntime-common/dist/cjs/training-session.js"(exports) {
1403
+ "use strict";
1404
+ Object.defineProperty(exports, "__esModule", { value: true });
1405
+ exports.TrainingSession = void 0;
1406
+ var training_session_impl_js_1 = require_training_session_impl();
1407
+ exports.TrainingSession = training_session_impl_js_1.TrainingSession;
1408
+ }
1409
+ });
1410
+
1411
+ // node_modules/onnxruntime-common/dist/cjs/index.js
1412
+ var require_cjs = __commonJS({
1413
+ "node_modules/onnxruntime-common/dist/cjs/index.js"(exports) {
1414
+ "use strict";
1415
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
1416
+ if (k2 === void 0) k2 = k;
1417
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1418
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1419
+ desc = { enumerable: true, get: function() {
1420
+ return m[k];
1421
+ } };
1422
+ }
1423
+ Object.defineProperty(o, k2, desc);
1424
+ }) : (function(o, m, k, k2) {
1425
+ if (k2 === void 0) k2 = k;
1426
+ o[k2] = m[k];
1427
+ }));
1428
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
1429
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
1430
+ };
1431
+ Object.defineProperty(exports, "__esModule", { value: true });
1432
+ __exportStar(require_backend(), exports);
1433
+ __exportStar(require_env(), exports);
1434
+ __exportStar(require_inference_session(), exports);
1435
+ __exportStar(require_tensor(), exports);
1436
+ __exportStar(require_tensor_conversion(), exports);
1437
+ __exportStar(require_tensor_factory(), exports);
1438
+ __exportStar(require_trace(), exports);
1439
+ __exportStar(require_onnx_model(), exports);
1440
+ __exportStar(require_onnx_value(), exports);
1441
+ __exportStar(require_training_session(), exports);
1442
+ }
1443
+ });
1444
+
1445
+ // node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/onnxruntime_binding.node
1446
+ var require_onnxruntime_binding = __commonJS({
1447
+ "node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/onnxruntime_binding.node"(exports, module) {
1448
+ module.exports = "./onnxruntime_binding-5PVQ7RFC.node";
1449
+ }
1450
+ });
1451
+
1452
+ // node_modules/onnxruntime-node/bin/napi-v3/darwin/x64/onnxruntime_binding.node
1453
+ var require_onnxruntime_binding2 = __commonJS({
1454
+ "node_modules/onnxruntime-node/bin/napi-v3/darwin/x64/onnxruntime_binding.node"(exports, module) {
1455
+ module.exports = "./onnxruntime_binding-FNOPH2XG.node";
1456
+ }
1457
+ });
1458
+
1459
+ // node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/onnxruntime_binding.node
1460
+ var require_onnxruntime_binding3 = __commonJS({
1461
+ "node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/onnxruntime_binding.node"(exports, module) {
1462
+ module.exports = "./onnxruntime_binding-HSGOY4IT.node";
1463
+ }
1464
+ });
1465
+
1466
+ // node_modules/onnxruntime-node/bin/napi-v3/linux/x64/onnxruntime_binding.node
1467
+ var require_onnxruntime_binding4 = __commonJS({
1468
+ "node_modules/onnxruntime-node/bin/napi-v3/linux/x64/onnxruntime_binding.node"(exports, module) {
1469
+ module.exports = "./onnxruntime_binding-4Q2WV26X.node";
1470
+ }
1471
+ });
1472
+
1473
+ // node_modules/onnxruntime-node/bin/napi-v3/win32/arm64/onnxruntime_binding.node
1474
+ var require_onnxruntime_binding5 = __commonJS({
1475
+ "node_modules/onnxruntime-node/bin/napi-v3/win32/arm64/onnxruntime_binding.node"(exports, module) {
1476
+ module.exports = "./onnxruntime_binding-OY2N3XIT.node";
1477
+ }
1478
+ });
1479
+
1480
+ // node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node
1481
+ var require_onnxruntime_binding6 = __commonJS({
1482
+ "node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node"(exports, module) {
1483
+ module.exports = "./onnxruntime_binding-ZPEJPBCV.node";
1484
+ }
1485
+ });
1486
+
1487
+ // require("../bin/napi-v3/**/*/**/*/onnxruntime_binding.node") in node_modules/onnxruntime-node/dist/binding.js
1488
+ var globRequire_bin_napi_v3_onnxruntime_binding_node;
1489
+ var init_ = __esm({
1490
+ 'require("../bin/napi-v3/**/*/**/*/onnxruntime_binding.node") in node_modules/onnxruntime-node/dist/binding.js'() {
1491
+ globRequire_bin_napi_v3_onnxruntime_binding_node = __glob({
1492
+ "../bin/napi-v3/darwin/arm64/onnxruntime_binding.node": () => require_onnxruntime_binding(),
1493
+ "../bin/napi-v3/darwin/x64/onnxruntime_binding.node": () => require_onnxruntime_binding2(),
1494
+ "../bin/napi-v3/linux/arm64/onnxruntime_binding.node": () => require_onnxruntime_binding3(),
1495
+ "../bin/napi-v3/linux/x64/onnxruntime_binding.node": () => require_onnxruntime_binding4(),
1496
+ "../bin/napi-v3/win32/arm64/onnxruntime_binding.node": () => require_onnxruntime_binding5(),
1497
+ "../bin/napi-v3/win32/x64/onnxruntime_binding.node": () => require_onnxruntime_binding6()
1498
+ });
1499
+ }
1500
+ });
1501
+
1502
+ // node_modules/onnxruntime-node/dist/binding.js
1503
+ var require_binding = __commonJS({
1504
+ "node_modules/onnxruntime-node/dist/binding.js"(exports) {
1505
+ "use strict";
1506
+ init_();
1507
+ Object.defineProperty(exports, "__esModule", { value: true });
1508
+ exports.binding = void 0;
1509
+ exports.binding = globRequire_bin_napi_v3_onnxruntime_binding_node(`../bin/napi-v3/${process.platform}/${process.arch}/onnxruntime_binding.node`);
1510
+ }
1511
+ });
1512
+
1513
+ // node_modules/onnxruntime-node/dist/backend.js
1514
+ var require_backend2 = __commonJS({
1515
+ "node_modules/onnxruntime-node/dist/backend.js"(exports) {
1516
+ "use strict";
1517
+ var __classPrivateFieldSet = exports && exports.__classPrivateFieldSet || function(receiver, state, value, kind, f) {
1518
+ if (kind === "m") throw new TypeError("Private method is not writable");
1519
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1520
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1521
+ return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
1522
+ };
1523
+ var __classPrivateFieldGet = exports && exports.__classPrivateFieldGet || function(receiver, state, kind, f) {
1524
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1525
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1526
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1527
+ };
1528
+ var _OnnxruntimeSessionHandler_inferenceSession;
1529
+ Object.defineProperty(exports, "__esModule", { value: true });
1530
+ exports.listSupportedBackends = exports.onnxruntimeBackend = void 0;
1531
+ var binding_1 = require_binding();
1532
+ var OnnxruntimeSessionHandler = class {
1533
+ constructor(pathOrBuffer, options) {
1534
+ _OnnxruntimeSessionHandler_inferenceSession.set(this, void 0);
1535
+ __classPrivateFieldSet(this, _OnnxruntimeSessionHandler_inferenceSession, new binding_1.binding.InferenceSession(), "f");
1536
+ if (typeof pathOrBuffer === "string") {
1537
+ __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").loadModel(pathOrBuffer, options);
1538
+ } else {
1539
+ __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
1540
+ }
1541
+ this.inputNames = __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").inputNames;
1542
+ this.outputNames = __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").outputNames;
1543
+ }
1544
+ async dispose() {
1545
+ __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").dispose();
1546
+ }
1547
+ startProfiling() {
1548
+ }
1549
+ endProfiling() {
1550
+ }
1551
+ async run(feeds, fetches, options) {
1552
+ return new Promise((resolve, reject) => {
1553
+ setImmediate(() => {
1554
+ try {
1555
+ resolve(__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").run(feeds, fetches, options));
1556
+ } catch (e) {
1557
+ reject(e);
1558
+ }
1559
+ });
1560
+ });
1561
+ }
1562
+ };
1563
+ _OnnxruntimeSessionHandler_inferenceSession = /* @__PURE__ */ new WeakMap();
1564
+ var OnnxruntimeBackend = class {
1565
+ async init() {
1566
+ return Promise.resolve();
1567
+ }
1568
+ async createInferenceSessionHandler(pathOrBuffer, options) {
1569
+ return new Promise((resolve, reject) => {
1570
+ setImmediate(() => {
1571
+ try {
1572
+ resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
1573
+ } catch (e) {
1574
+ reject(e);
1575
+ }
1576
+ });
1577
+ });
1578
+ }
1579
+ };
1580
+ exports.onnxruntimeBackend = new OnnxruntimeBackend();
1581
+ exports.listSupportedBackends = binding_1.binding.listSupportedBackends;
1582
+ }
1583
+ });
1584
+
1585
+ // node_modules/onnxruntime-node/dist/version.js
1586
+ var require_version2 = __commonJS({
1587
+ "node_modules/onnxruntime-node/dist/version.js"(exports) {
1588
+ "use strict";
1589
+ Object.defineProperty(exports, "__esModule", { value: true });
1590
+ exports.version = void 0;
1591
+ exports.version = "1.18.0";
1592
+ }
1593
+ });
1594
+
1595
+ // node_modules/onnxruntime-node/dist/index.js
1596
+ var require_dist = __commonJS({
1597
+ "node_modules/onnxruntime-node/dist/index.js"(exports) {
1598
+ var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
1599
+ if (k2 === void 0) k2 = k;
1600
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1601
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1602
+ desc = { enumerable: true, get: function() {
1603
+ return m[k];
1604
+ } };
1605
+ }
1606
+ Object.defineProperty(o, k2, desc);
1607
+ }) : (function(o, m, k, k2) {
1608
+ if (k2 === void 0) k2 = k;
1609
+ o[k2] = m[k];
1610
+ }));
1611
+ var __exportStar = exports && exports.__exportStar || function(m, exports2) {
1612
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p)) __createBinding(exports2, m, p);
1613
+ };
1614
+ Object.defineProperty(exports, "__esModule", { value: true });
1615
+ exports.listSupportedBackends = void 0;
1616
+ __exportStar(require_cjs(), exports);
1617
+ var backend_1 = require_backend2();
1618
+ Object.defineProperty(exports, "listSupportedBackends", { enumerable: true, get: function() {
1619
+ return backend_1.listSupportedBackends;
1620
+ } });
1621
+ var onnxruntime_common_1 = require_cjs();
1622
+ var version_1 = require_version2();
1623
+ var backend_2 = require_backend2();
1624
+ var backends = (0, backend_2.listSupportedBackends)();
1625
+ for (const backend of backends) {
1626
+ (0, onnxruntime_common_1.registerBackend)(backend.name, backend_2.onnxruntimeBackend, 100);
1627
+ }
1628
+ Object.defineProperty(onnxruntime_common_1.env.versions, "node", { value: version_1.version, enumerable: true });
1629
+ }
1630
+ });
1631
+ export default require_dist();