nexum-code 0.6.14 → 0.6.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -322
- package/dist/{aiflowy-bot-sync-BMV5Lg3y.mjs → aiflowy-bot-sync-C0WrAYbG.mjs} +2 -2
- package/dist/{aiflowy-bot-sync-CY50Z6GW.mjs → aiflowy-bot-sync-DhoRtQfn.mjs} +1 -1
- package/dist/{app-LAoILm5g.mjs → app-0T4efY5b.mjs} +38489 -6252
- package/dist/esm-RYfZ46Tf.mjs +3593 -0
- package/dist/index.min-D4utBuC7.mjs +2990 -0
- package/dist/main.mjs +1 -1
- package/dist/pdf-F2kQiIQy.mjs +26642 -0
- package/dist/pdf.worker-ByxNbF6P.mjs +82061 -0
- package/dist/{src-BMbLXrAA.mjs → src-kwvD0ssv.mjs} +12 -12
- package/package.json +26 -22
- package/scripts/postinstall.mjs +115 -13
- package/dist/esm-CmfJNv9s.mjs +0 -8590
|
@@ -0,0 +1,3593 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __cjsShimDirname } from 'node:path';
|
|
4
|
+
const __filename = __cjsShimFileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = __cjsShimDirname(__filename);
|
|
6
|
+
import { a as __toESM, i as __require, t as __commonJSMin } from "./chunk-apG1qJts.mjs";
|
|
7
|
+
import { t as uo } from "./index.min-D4utBuC7.mjs";
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import https from "https";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import "fs/promises";
|
|
12
|
+
//#region ../../node_modules/.pnpm/@anush008+tokenizers@0.0.0/node_modules/@anush008/tokenizers/index.js
|
|
13
|
+
var require_tokenizers = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
14
|
+
const { existsSync, readFileSync } = __require("fs");
|
|
15
|
+
const { join } = __require("path");
|
|
16
|
+
const { platform, arch } = process;
|
|
17
|
+
let nativeBinding = null;
|
|
18
|
+
let localFileExisted = false;
|
|
19
|
+
let loadError = null;
|
|
20
|
+
function isMusl() {
|
|
21
|
+
if (!process.report || typeof process.report.getReport !== "function") try {
|
|
22
|
+
return readFileSync(__require("child_process").execSync("which ldd").toString().trim(), "utf8").includes("musl");
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const { glibcVersionRuntime } = process.report.getReport().header;
|
|
28
|
+
return !glibcVersionRuntime;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case "android":
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case "arm64":
|
|
35
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.android-arm64.node"));
|
|
36
|
+
try {
|
|
37
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.android-arm64.node");
|
|
38
|
+
else nativeBinding = __require("@anush008/tokenizers-android-arm64");
|
|
39
|
+
} catch (e) {
|
|
40
|
+
loadError = e;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case "arm":
|
|
44
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.android-arm-eabi.node"));
|
|
45
|
+
try {
|
|
46
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.android-arm-eabi.node");
|
|
47
|
+
else nativeBinding = __require("@anush008/tokenizers-android-arm-eabi");
|
|
48
|
+
} catch (e) {
|
|
49
|
+
loadError = e;
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
default: throw new Error(`Unsupported architecture on Android ${arch}`);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case "win32":
|
|
56
|
+
switch (arch) {
|
|
57
|
+
case "x64":
|
|
58
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.win32-x64-msvc.node"));
|
|
59
|
+
try {
|
|
60
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.win32-x64-msvc.node");
|
|
61
|
+
else nativeBinding = __require("./assets/tokenizers.win32-x64-msvc-7FuPBfvC.node");
|
|
62
|
+
} catch (e) {
|
|
63
|
+
loadError = e;
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case "ia32":
|
|
67
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.win32-ia32-msvc.node"));
|
|
68
|
+
try {
|
|
69
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.win32-ia32-msvc.node");
|
|
70
|
+
else nativeBinding = __require("@anush008/tokenizers-win32-ia32-msvc");
|
|
71
|
+
} catch (e) {
|
|
72
|
+
loadError = e;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
case "arm64":
|
|
76
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.win32-arm64-msvc.node"));
|
|
77
|
+
try {
|
|
78
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.win32-arm64-msvc.node");
|
|
79
|
+
else nativeBinding = __require("@anush008/tokenizers-win32-arm64-msvc");
|
|
80
|
+
} catch (e) {
|
|
81
|
+
loadError = e;
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
default: throw new Error(`Unsupported architecture on Windows: ${arch}`);
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case "darwin":
|
|
88
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.darwin-universal.node"));
|
|
89
|
+
try {
|
|
90
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.darwin-universal.node");
|
|
91
|
+
else nativeBinding = __require("@anush008/tokenizers-darwin-universal");
|
|
92
|
+
break;
|
|
93
|
+
} catch {}
|
|
94
|
+
switch (arch) {
|
|
95
|
+
case "x64":
|
|
96
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.darwin-x64.node"));
|
|
97
|
+
try {
|
|
98
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.darwin-x64.node");
|
|
99
|
+
else nativeBinding = __require("@anush008/tokenizers-darwin-x64");
|
|
100
|
+
} catch (e) {
|
|
101
|
+
loadError = e;
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
case "arm64":
|
|
105
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.darwin-arm64.node"));
|
|
106
|
+
try {
|
|
107
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.darwin-arm64.node");
|
|
108
|
+
else nativeBinding = __require("@anush008/tokenizers-darwin-arm64");
|
|
109
|
+
} catch (e) {
|
|
110
|
+
loadError = e;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
default: throw new Error(`Unsupported architecture on macOS: ${arch}`);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
case "freebsd":
|
|
117
|
+
if (arch !== "x64") throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
|
|
118
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.freebsd-x64.node"));
|
|
119
|
+
try {
|
|
120
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.freebsd-x64.node");
|
|
121
|
+
else nativeBinding = __require("@anush008/tokenizers-freebsd-x64");
|
|
122
|
+
} catch (e) {
|
|
123
|
+
loadError = e;
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case "linux":
|
|
127
|
+
switch (arch) {
|
|
128
|
+
case "x64":
|
|
129
|
+
if (isMusl()) {
|
|
130
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.linux-x64-musl.node"));
|
|
131
|
+
try {
|
|
132
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.linux-x64-musl.node");
|
|
133
|
+
else nativeBinding = __require("@anush008/tokenizers-linux-x64-musl");
|
|
134
|
+
} catch (e) {
|
|
135
|
+
loadError = e;
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.linux-x64-gnu.node"));
|
|
139
|
+
try {
|
|
140
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.linux-x64-gnu.node");
|
|
141
|
+
else nativeBinding = __require("@anush008/tokenizers-linux-x64-gnu");
|
|
142
|
+
} catch (e) {
|
|
143
|
+
loadError = e;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
case "arm64":
|
|
148
|
+
if (isMusl()) {
|
|
149
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.linux-arm64-musl.node"));
|
|
150
|
+
try {
|
|
151
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.linux-arm64-musl.node");
|
|
152
|
+
else nativeBinding = __require("@anush008/tokenizers-linux-arm64-musl");
|
|
153
|
+
} catch (e) {
|
|
154
|
+
loadError = e;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.linux-arm64-gnu.node"));
|
|
158
|
+
try {
|
|
159
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.linux-arm64-gnu.node");
|
|
160
|
+
else nativeBinding = __require("@anush008/tokenizers-linux-arm64-gnu");
|
|
161
|
+
} catch (e) {
|
|
162
|
+
loadError = e;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
break;
|
|
166
|
+
case "arm":
|
|
167
|
+
localFileExisted = existsSync(join(__dirname, "tokenizers.linux-arm-gnueabihf.node"));
|
|
168
|
+
try {
|
|
169
|
+
if (localFileExisted) nativeBinding = __require("./tokenizers.linux-arm-gnueabihf.node");
|
|
170
|
+
else nativeBinding = __require("@anush008/tokenizers-linux-arm-gnueabihf");
|
|
171
|
+
} catch (e) {
|
|
172
|
+
loadError = e;
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
default: throw new Error(`Unsupported architecture on Linux: ${arch}`);
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
default: throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
|
|
179
|
+
}
|
|
180
|
+
if (!nativeBinding) {
|
|
181
|
+
if (loadError) throw loadError;
|
|
182
|
+
throw new Error(`Failed to load native binding`);
|
|
183
|
+
}
|
|
184
|
+
const { Decoder, bpeDecoder, byteFallbackDecoder, ctcDecoder, fuseDecoder, metaspaceDecoder, replaceDecoder, sequenceDecoder, stripDecoder, wordPieceDecoder, Encoding, TruncationDirection, TruncationStrategy, Model, BPE, WordPiece, WordLevel, Unigram, Normalizer, prependNormalizer, stripAccentsNormalizer, bertNormalizer, nfdNormalizer, nfkdNormalizer, nfcNormalizer, nfkcNormalizer, stripNormalizer, sequenceNormalizer, lowercase, replace, nmt, precompiled, JsSplitDelimiterBehavior, PreTokenizer, byteLevelPreTokenizer, byteLevelAlphabet, whitespacePreTokenizer, whitespaceSplitPreTokenizer, bertPreTokenizer, metaspacePreTokenizer, splitPreTokenizer, punctuationPreTokenizer, sequencePreTokenizer, charDelimiterSplit, digitsPreTokenizer, Processor, bertProcessing, robertaProcessing, byteLevelProcessing, templateProcessing, sequenceProcessing, PaddingDirection, AddedToken, Tokenizer, Trainer, slice, mergeEncodings } = nativeBinding;
|
|
185
|
+
module.exports.Decoder = Decoder;
|
|
186
|
+
module.exports.bpeDecoder = bpeDecoder;
|
|
187
|
+
module.exports.byteFallbackDecoder = byteFallbackDecoder;
|
|
188
|
+
module.exports.ctcDecoder = ctcDecoder;
|
|
189
|
+
module.exports.fuseDecoder = fuseDecoder;
|
|
190
|
+
module.exports.metaspaceDecoder = metaspaceDecoder;
|
|
191
|
+
module.exports.replaceDecoder = replaceDecoder;
|
|
192
|
+
module.exports.sequenceDecoder = sequenceDecoder;
|
|
193
|
+
module.exports.stripDecoder = stripDecoder;
|
|
194
|
+
module.exports.wordPieceDecoder = wordPieceDecoder;
|
|
195
|
+
module.exports.Encoding = Encoding;
|
|
196
|
+
module.exports.TruncationDirection = TruncationDirection;
|
|
197
|
+
module.exports.TruncationStrategy = TruncationStrategy;
|
|
198
|
+
module.exports.Model = Model;
|
|
199
|
+
module.exports.BPE = BPE;
|
|
200
|
+
module.exports.WordPiece = WordPiece;
|
|
201
|
+
module.exports.WordLevel = WordLevel;
|
|
202
|
+
module.exports.Unigram = Unigram;
|
|
203
|
+
module.exports.Normalizer = Normalizer;
|
|
204
|
+
module.exports.prependNormalizer = prependNormalizer;
|
|
205
|
+
module.exports.stripAccentsNormalizer = stripAccentsNormalizer;
|
|
206
|
+
module.exports.bertNormalizer = bertNormalizer;
|
|
207
|
+
module.exports.nfdNormalizer = nfdNormalizer;
|
|
208
|
+
module.exports.nfkdNormalizer = nfkdNormalizer;
|
|
209
|
+
module.exports.nfcNormalizer = nfcNormalizer;
|
|
210
|
+
module.exports.nfkcNormalizer = nfkcNormalizer;
|
|
211
|
+
module.exports.stripNormalizer = stripNormalizer;
|
|
212
|
+
module.exports.sequenceNormalizer = sequenceNormalizer;
|
|
213
|
+
module.exports.lowercase = lowercase;
|
|
214
|
+
module.exports.replace = replace;
|
|
215
|
+
module.exports.nmt = nmt;
|
|
216
|
+
module.exports.precompiled = precompiled;
|
|
217
|
+
module.exports.JsSplitDelimiterBehavior = JsSplitDelimiterBehavior;
|
|
218
|
+
module.exports.PreTokenizer = PreTokenizer;
|
|
219
|
+
module.exports.byteLevelPreTokenizer = byteLevelPreTokenizer;
|
|
220
|
+
module.exports.byteLevelAlphabet = byteLevelAlphabet;
|
|
221
|
+
module.exports.whitespacePreTokenizer = whitespacePreTokenizer;
|
|
222
|
+
module.exports.whitespaceSplitPreTokenizer = whitespaceSplitPreTokenizer;
|
|
223
|
+
module.exports.bertPreTokenizer = bertPreTokenizer;
|
|
224
|
+
module.exports.metaspacePreTokenizer = metaspacePreTokenizer;
|
|
225
|
+
module.exports.splitPreTokenizer = splitPreTokenizer;
|
|
226
|
+
module.exports.punctuationPreTokenizer = punctuationPreTokenizer;
|
|
227
|
+
module.exports.sequencePreTokenizer = sequencePreTokenizer;
|
|
228
|
+
module.exports.charDelimiterSplit = charDelimiterSplit;
|
|
229
|
+
module.exports.digitsPreTokenizer = digitsPreTokenizer;
|
|
230
|
+
module.exports.Processor = Processor;
|
|
231
|
+
module.exports.bertProcessing = bertProcessing;
|
|
232
|
+
module.exports.robertaProcessing = robertaProcessing;
|
|
233
|
+
module.exports.byteLevelProcessing = byteLevelProcessing;
|
|
234
|
+
module.exports.templateProcessing = templateProcessing;
|
|
235
|
+
module.exports.sequenceProcessing = sequenceProcessing;
|
|
236
|
+
module.exports.PaddingDirection = PaddingDirection;
|
|
237
|
+
module.exports.AddedToken = AddedToken;
|
|
238
|
+
module.exports.Tokenizer = Tokenizer;
|
|
239
|
+
module.exports.Trainer = Trainer;
|
|
240
|
+
module.exports.slice = slice;
|
|
241
|
+
module.exports.mergeEncodings = mergeEncodings;
|
|
242
|
+
}));
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/backend-impl.js
|
|
245
|
+
var require_backend_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
246
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
247
|
+
exports.resolveBackendAndExecutionProviders = exports.registerBackend = void 0;
|
|
248
|
+
const backends = /* @__PURE__ */ new Map();
|
|
249
|
+
const backendsSortedByPriority = [];
|
|
250
|
+
/**
|
|
251
|
+
* Register a backend.
|
|
252
|
+
*
|
|
253
|
+
* @param name - the name as a key to lookup as an execution provider.
|
|
254
|
+
* @param backend - the backend object.
|
|
255
|
+
* @param priority - an integer indicating the priority of the backend. Higher number means higher priority. if priority
|
|
256
|
+
* < 0, it will be considered as a 'beta' version and will not be used as a fallback backend by default.
|
|
257
|
+
*
|
|
258
|
+
* @ignore
|
|
259
|
+
*/
|
|
260
|
+
const registerBackend = (name, backend, priority) => {
|
|
261
|
+
if (backend && typeof backend.init === "function" && typeof backend.createInferenceSessionHandler === "function") {
|
|
262
|
+
const currentBackend = backends.get(name);
|
|
263
|
+
if (currentBackend === void 0) backends.set(name, {
|
|
264
|
+
backend,
|
|
265
|
+
priority
|
|
266
|
+
});
|
|
267
|
+
else if (currentBackend.priority > priority) return;
|
|
268
|
+
else if (currentBackend.priority === priority) {
|
|
269
|
+
if (currentBackend.backend !== backend) throw new Error(`cannot register backend "${name}" using priority ${priority}`);
|
|
270
|
+
}
|
|
271
|
+
if (priority >= 0) {
|
|
272
|
+
const i = backendsSortedByPriority.indexOf(name);
|
|
273
|
+
if (i !== -1) backendsSortedByPriority.splice(i, 1);
|
|
274
|
+
for (let i = 0; i < backendsSortedByPriority.length; i++) if (backends.get(backendsSortedByPriority[i]).priority <= priority) {
|
|
275
|
+
backendsSortedByPriority.splice(i, 0, name);
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
backendsSortedByPriority.push(name);
|
|
279
|
+
}
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
throw new TypeError("not a valid backend");
|
|
283
|
+
};
|
|
284
|
+
exports.registerBackend = registerBackend;
|
|
285
|
+
/**
|
|
286
|
+
* Try to resolve and initialize a backend.
|
|
287
|
+
*
|
|
288
|
+
* @param backendName - the name of the backend.
|
|
289
|
+
* @returns the backend instance if resolved and initialized successfully, or an error message if failed.
|
|
290
|
+
*/
|
|
291
|
+
const tryResolveAndInitializeBackend = async (backendName) => {
|
|
292
|
+
const backendInfo = backends.get(backendName);
|
|
293
|
+
if (!backendInfo) return "backend not found.";
|
|
294
|
+
if (backendInfo.initialized) return backendInfo.backend;
|
|
295
|
+
else if (backendInfo.aborted) return backendInfo.error;
|
|
296
|
+
else {
|
|
297
|
+
const isInitializing = !!backendInfo.initPromise;
|
|
298
|
+
try {
|
|
299
|
+
if (!isInitializing) backendInfo.initPromise = backendInfo.backend.init(backendName);
|
|
300
|
+
await backendInfo.initPromise;
|
|
301
|
+
backendInfo.initialized = true;
|
|
302
|
+
return backendInfo.backend;
|
|
303
|
+
} catch (e) {
|
|
304
|
+
if (!isInitializing) {
|
|
305
|
+
backendInfo.error = `${e}`;
|
|
306
|
+
backendInfo.aborted = true;
|
|
307
|
+
}
|
|
308
|
+
return backendInfo.error;
|
|
309
|
+
} finally {
|
|
310
|
+
delete backendInfo.initPromise;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Resolve execution providers from the specific session options.
|
|
316
|
+
*
|
|
317
|
+
* @param options - the session options object.
|
|
318
|
+
* @returns a promise that resolves to a tuple of an initialized backend instance and a session options object with
|
|
319
|
+
* filtered EP list.
|
|
320
|
+
*
|
|
321
|
+
* @ignore
|
|
322
|
+
*/
|
|
323
|
+
const resolveBackendAndExecutionProviders = async (options) => {
|
|
324
|
+
const eps = options.executionProviders || [];
|
|
325
|
+
const backendHints = eps.map((i) => typeof i === "string" ? i : i.name);
|
|
326
|
+
const backendNames = backendHints.length === 0 ? backendsSortedByPriority : backendHints;
|
|
327
|
+
let backend;
|
|
328
|
+
const errors = [];
|
|
329
|
+
const availableBackendNames = /* @__PURE__ */ new Set();
|
|
330
|
+
for (const backendName of backendNames) {
|
|
331
|
+
const resolveResult = await tryResolveAndInitializeBackend(backendName);
|
|
332
|
+
if (typeof resolveResult === "string") errors.push({
|
|
333
|
+
name: backendName,
|
|
334
|
+
err: resolveResult
|
|
335
|
+
});
|
|
336
|
+
else {
|
|
337
|
+
if (!backend) backend = resolveResult;
|
|
338
|
+
if (backend === resolveResult) availableBackendNames.add(backendName);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (!backend) throw new Error(`no available backend found. ERR: ${errors.map((e) => `[${e.name}] ${e.err}`).join(", ")}`);
|
|
342
|
+
for (const { name, err } of errors) if (backendHints.includes(name)) console.warn(`removing requested execution provider "${name}" from session options because it is not available: ${err}`);
|
|
343
|
+
const filteredEps = eps.filter((i) => availableBackendNames.has(typeof i === "string" ? i : i.name));
|
|
344
|
+
return [backend, new Proxy(options, { get: (target, prop) => {
|
|
345
|
+
if (prop === "executionProviders") return filteredEps;
|
|
346
|
+
return Reflect.get(target, prop);
|
|
347
|
+
} })];
|
|
348
|
+
};
|
|
349
|
+
exports.resolveBackendAndExecutionProviders = resolveBackendAndExecutionProviders;
|
|
350
|
+
}));
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/backend.js
|
|
353
|
+
var require_backend$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
354
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
355
|
+
exports.registerBackend = void 0;
|
|
356
|
+
var backend_impl_js_1 = require_backend_impl();
|
|
357
|
+
Object.defineProperty(exports, "registerBackend", {
|
|
358
|
+
enumerable: true,
|
|
359
|
+
get: function() {
|
|
360
|
+
return backend_impl_js_1.registerBackend;
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}));
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/version.js
|
|
366
|
+
var require_version$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
367
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
368
|
+
exports.version = void 0;
|
|
369
|
+
exports.version = "1.21.0";
|
|
370
|
+
}));
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/env-impl.js
|
|
373
|
+
var require_env_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
374
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
375
|
+
exports.env = void 0;
|
|
376
|
+
const version_js_1 = require_version$1();
|
|
377
|
+
let logLevelValue = "warning";
|
|
378
|
+
exports.env = {
|
|
379
|
+
wasm: {},
|
|
380
|
+
webgl: {},
|
|
381
|
+
webgpu: {},
|
|
382
|
+
versions: { common: version_js_1.version },
|
|
383
|
+
set logLevel(value) {
|
|
384
|
+
if (value === void 0) return;
|
|
385
|
+
if (typeof value !== "string" || [
|
|
386
|
+
"verbose",
|
|
387
|
+
"info",
|
|
388
|
+
"warning",
|
|
389
|
+
"error",
|
|
390
|
+
"fatal"
|
|
391
|
+
].indexOf(value) === -1) throw new Error(`Unsupported logging level: ${value}`);
|
|
392
|
+
logLevelValue = value;
|
|
393
|
+
},
|
|
394
|
+
get logLevel() {
|
|
395
|
+
return logLevelValue;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
Object.defineProperty(exports.env, "logLevel", { enumerable: true });
|
|
399
|
+
}));
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/env.js
|
|
402
|
+
var require_env = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
403
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
404
|
+
exports.env = void 0;
|
|
405
|
+
/**
|
|
406
|
+
* Represent a set of flags as a global singleton.
|
|
407
|
+
*/
|
|
408
|
+
exports.env = require_env_impl().env;
|
|
409
|
+
}));
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-conversion-impl.js
|
|
412
|
+
var require_tensor_conversion_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
413
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
414
|
+
exports.tensorToImageData = exports.tensorToDataURL = void 0;
|
|
415
|
+
/**
|
|
416
|
+
* implementation of Tensor.toDataURL()
|
|
417
|
+
*/
|
|
418
|
+
const tensorToDataURL = (tensor, options) => {
|
|
419
|
+
const canvas = typeof document !== "undefined" ? document.createElement("canvas") : new OffscreenCanvas(1, 1);
|
|
420
|
+
canvas.width = tensor.dims[3];
|
|
421
|
+
canvas.height = tensor.dims[2];
|
|
422
|
+
const pixels2DContext = canvas.getContext("2d");
|
|
423
|
+
if (pixels2DContext != null) {
|
|
424
|
+
let width;
|
|
425
|
+
let height;
|
|
426
|
+
if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
|
|
427
|
+
width = tensor.dims[2];
|
|
428
|
+
height = tensor.dims[3];
|
|
429
|
+
} else {
|
|
430
|
+
width = tensor.dims[3];
|
|
431
|
+
height = tensor.dims[2];
|
|
432
|
+
}
|
|
433
|
+
const inputformat = options?.format !== void 0 ? options.format : "RGB";
|
|
434
|
+
const norm = options?.norm;
|
|
435
|
+
let normMean;
|
|
436
|
+
let normBias;
|
|
437
|
+
if (norm === void 0 || norm.mean === void 0) normMean = [
|
|
438
|
+
255,
|
|
439
|
+
255,
|
|
440
|
+
255,
|
|
441
|
+
255
|
|
442
|
+
];
|
|
443
|
+
else if (typeof norm.mean === "number") normMean = [
|
|
444
|
+
norm.mean,
|
|
445
|
+
norm.mean,
|
|
446
|
+
norm.mean,
|
|
447
|
+
norm.mean
|
|
448
|
+
];
|
|
449
|
+
else {
|
|
450
|
+
normMean = [
|
|
451
|
+
norm.mean[0],
|
|
452
|
+
norm.mean[1],
|
|
453
|
+
norm.mean[2],
|
|
454
|
+
0
|
|
455
|
+
];
|
|
456
|
+
if (norm.mean[3] !== void 0) normMean[3] = norm.mean[3];
|
|
457
|
+
}
|
|
458
|
+
if (norm === void 0 || norm.bias === void 0) normBias = [
|
|
459
|
+
0,
|
|
460
|
+
0,
|
|
461
|
+
0,
|
|
462
|
+
0
|
|
463
|
+
];
|
|
464
|
+
else if (typeof norm.bias === "number") normBias = [
|
|
465
|
+
norm.bias,
|
|
466
|
+
norm.bias,
|
|
467
|
+
norm.bias,
|
|
468
|
+
norm.bias
|
|
469
|
+
];
|
|
470
|
+
else {
|
|
471
|
+
normBias = [
|
|
472
|
+
norm.bias[0],
|
|
473
|
+
norm.bias[1],
|
|
474
|
+
norm.bias[2],
|
|
475
|
+
0
|
|
476
|
+
];
|
|
477
|
+
if (norm.bias[3] !== void 0) normBias[3] = norm.bias[3];
|
|
478
|
+
}
|
|
479
|
+
const stride = height * width;
|
|
480
|
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
481
|
+
if (inputformat === "RGBA") {
|
|
482
|
+
rTensorPointer = 0;
|
|
483
|
+
gTensorPointer = stride;
|
|
484
|
+
bTensorPointer = stride * 2;
|
|
485
|
+
aTensorPointer = stride * 3;
|
|
486
|
+
} else if (inputformat === "RGB") {
|
|
487
|
+
rTensorPointer = 0;
|
|
488
|
+
gTensorPointer = stride;
|
|
489
|
+
bTensorPointer = stride * 2;
|
|
490
|
+
} else if (inputformat === "RBG") {
|
|
491
|
+
rTensorPointer = 0;
|
|
492
|
+
bTensorPointer = stride;
|
|
493
|
+
gTensorPointer = stride * 2;
|
|
494
|
+
}
|
|
495
|
+
for (let i = 0; i < height; i++) for (let j = 0; j < width; j++) {
|
|
496
|
+
const R = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
|
|
497
|
+
const G = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
|
|
498
|
+
const B = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
|
|
499
|
+
const A = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
|
|
500
|
+
pixels2DContext.fillStyle = "rgba(" + R + "," + G + "," + B + "," + A + ")";
|
|
501
|
+
pixels2DContext.fillRect(j, i, 1, 1);
|
|
502
|
+
}
|
|
503
|
+
if ("toDataURL" in canvas) return canvas.toDataURL();
|
|
504
|
+
else throw new Error("toDataURL is not supported");
|
|
505
|
+
} else throw new Error("Can not access image data");
|
|
506
|
+
};
|
|
507
|
+
exports.tensorToDataURL = tensorToDataURL;
|
|
508
|
+
/**
|
|
509
|
+
* implementation of Tensor.toImageData()
|
|
510
|
+
*/
|
|
511
|
+
const tensorToImageData = (tensor, options) => {
|
|
512
|
+
const pixels2DContext = typeof document !== "undefined" ? document.createElement("canvas").getContext("2d") : new OffscreenCanvas(1, 1).getContext("2d");
|
|
513
|
+
let image;
|
|
514
|
+
if (pixels2DContext != null) {
|
|
515
|
+
let width;
|
|
516
|
+
let height;
|
|
517
|
+
let channels;
|
|
518
|
+
if (options?.tensorLayout !== void 0 && options.tensorLayout === "NHWC") {
|
|
519
|
+
width = tensor.dims[2];
|
|
520
|
+
height = tensor.dims[1];
|
|
521
|
+
channels = tensor.dims[3];
|
|
522
|
+
} else {
|
|
523
|
+
width = tensor.dims[3];
|
|
524
|
+
height = tensor.dims[2];
|
|
525
|
+
channels = tensor.dims[1];
|
|
526
|
+
}
|
|
527
|
+
const inputformat = options !== void 0 ? options.format !== void 0 ? options.format : "RGB" : "RGB";
|
|
528
|
+
const norm = options?.norm;
|
|
529
|
+
let normMean;
|
|
530
|
+
let normBias;
|
|
531
|
+
if (norm === void 0 || norm.mean === void 0) normMean = [
|
|
532
|
+
255,
|
|
533
|
+
255,
|
|
534
|
+
255,
|
|
535
|
+
255
|
|
536
|
+
];
|
|
537
|
+
else if (typeof norm.mean === "number") normMean = [
|
|
538
|
+
norm.mean,
|
|
539
|
+
norm.mean,
|
|
540
|
+
norm.mean,
|
|
541
|
+
norm.mean
|
|
542
|
+
];
|
|
543
|
+
else {
|
|
544
|
+
normMean = [
|
|
545
|
+
norm.mean[0],
|
|
546
|
+
norm.mean[1],
|
|
547
|
+
norm.mean[2],
|
|
548
|
+
255
|
|
549
|
+
];
|
|
550
|
+
if (norm.mean[3] !== void 0) normMean[3] = norm.mean[3];
|
|
551
|
+
}
|
|
552
|
+
if (norm === void 0 || norm.bias === void 0) normBias = [
|
|
553
|
+
0,
|
|
554
|
+
0,
|
|
555
|
+
0,
|
|
556
|
+
0
|
|
557
|
+
];
|
|
558
|
+
else if (typeof norm.bias === "number") normBias = [
|
|
559
|
+
norm.bias,
|
|
560
|
+
norm.bias,
|
|
561
|
+
norm.bias,
|
|
562
|
+
norm.bias
|
|
563
|
+
];
|
|
564
|
+
else {
|
|
565
|
+
normBias = [
|
|
566
|
+
norm.bias[0],
|
|
567
|
+
norm.bias[1],
|
|
568
|
+
norm.bias[2],
|
|
569
|
+
0
|
|
570
|
+
];
|
|
571
|
+
if (norm.bias[3] !== void 0) normBias[3] = norm.bias[3];
|
|
572
|
+
}
|
|
573
|
+
const stride = height * width;
|
|
574
|
+
if (options !== void 0) {
|
|
575
|
+
if (options.format !== void 0 && channels === 4 && options.format !== "RGBA" || channels === 3 && options.format !== "RGB" && options.format !== "BGR") throw new Error("Tensor format doesn't match input tensor dims");
|
|
576
|
+
}
|
|
577
|
+
const step = 4;
|
|
578
|
+
let rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
|
579
|
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
580
|
+
if (inputformat === "RGBA") {
|
|
581
|
+
rTensorPointer = 0;
|
|
582
|
+
gTensorPointer = stride;
|
|
583
|
+
bTensorPointer = stride * 2;
|
|
584
|
+
aTensorPointer = stride * 3;
|
|
585
|
+
} else if (inputformat === "RGB") {
|
|
586
|
+
rTensorPointer = 0;
|
|
587
|
+
gTensorPointer = stride;
|
|
588
|
+
bTensorPointer = stride * 2;
|
|
589
|
+
} else if (inputformat === "RBG") {
|
|
590
|
+
rTensorPointer = 0;
|
|
591
|
+
bTensorPointer = stride;
|
|
592
|
+
gTensorPointer = stride * 2;
|
|
593
|
+
}
|
|
594
|
+
image = pixels2DContext.createImageData(width, height);
|
|
595
|
+
for (let i = 0; i < height * width; rImagePointer += step, gImagePointer += step, bImagePointer += step, aImagePointer += step, i++) {
|
|
596
|
+
image.data[rImagePointer] = (tensor.data[rTensorPointer++] - normBias[0]) * normMean[0];
|
|
597
|
+
image.data[gImagePointer] = (tensor.data[gTensorPointer++] - normBias[1]) * normMean[1];
|
|
598
|
+
image.data[bImagePointer] = (tensor.data[bTensorPointer++] - normBias[2]) * normMean[2];
|
|
599
|
+
image.data[aImagePointer] = aTensorPointer === -1 ? 255 : (tensor.data[aTensorPointer++] - normBias[3]) * normMean[3];
|
|
600
|
+
}
|
|
601
|
+
} else throw new Error("Can not access image data");
|
|
602
|
+
return image;
|
|
603
|
+
};
|
|
604
|
+
exports.tensorToImageData = tensorToImageData;
|
|
605
|
+
}));
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-factory-impl.js
|
|
608
|
+
var require_tensor_factory_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
609
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
610
|
+
exports.tensorFromPinnedBuffer = exports.tensorFromMLTensor = exports.tensorFromGpuBuffer = exports.tensorFromTexture = exports.tensorFromImage = exports.bufferToTensor = void 0;
|
|
611
|
+
const tensor_impl_js_1 = require_tensor_impl();
|
|
612
|
+
/**
|
|
613
|
+
* Create a new tensor object from image object
|
|
614
|
+
*
|
|
615
|
+
* @param buffer - Extracted image buffer data - assuming RGBA format
|
|
616
|
+
* @param imageFormat - input image configuration - required configurations height, width, format
|
|
617
|
+
* @param tensorFormat - output tensor configuration - Default is RGB format
|
|
618
|
+
*/
|
|
619
|
+
const bufferToTensor = (buffer, options) => {
|
|
620
|
+
if (buffer === void 0) throw new Error("Image buffer must be defined");
|
|
621
|
+
if (options.height === void 0 || options.width === void 0) throw new Error("Image height and width must be defined");
|
|
622
|
+
if (options.tensorLayout === "NHWC") throw new Error("NHWC Tensor layout is not supported yet");
|
|
623
|
+
const { height, width } = options;
|
|
624
|
+
const norm = options.norm ?? {
|
|
625
|
+
mean: 255,
|
|
626
|
+
bias: 0
|
|
627
|
+
};
|
|
628
|
+
let normMean;
|
|
629
|
+
let normBias;
|
|
630
|
+
if (typeof norm.mean === "number") normMean = [
|
|
631
|
+
norm.mean,
|
|
632
|
+
norm.mean,
|
|
633
|
+
norm.mean,
|
|
634
|
+
norm.mean
|
|
635
|
+
];
|
|
636
|
+
else normMean = [
|
|
637
|
+
norm.mean[0],
|
|
638
|
+
norm.mean[1],
|
|
639
|
+
norm.mean[2],
|
|
640
|
+
norm.mean[3] ?? 255
|
|
641
|
+
];
|
|
642
|
+
if (typeof norm.bias === "number") normBias = [
|
|
643
|
+
norm.bias,
|
|
644
|
+
norm.bias,
|
|
645
|
+
norm.bias,
|
|
646
|
+
norm.bias
|
|
647
|
+
];
|
|
648
|
+
else normBias = [
|
|
649
|
+
norm.bias[0],
|
|
650
|
+
norm.bias[1],
|
|
651
|
+
norm.bias[2],
|
|
652
|
+
norm.bias[3] ?? 0
|
|
653
|
+
];
|
|
654
|
+
const inputformat = options.format !== void 0 ? options.format : "RGBA";
|
|
655
|
+
const outputformat = options.tensorFormat !== void 0 ? options.tensorFormat !== void 0 ? options.tensorFormat : "RGB" : "RGB";
|
|
656
|
+
const stride = height * width;
|
|
657
|
+
const float32Data = outputformat === "RGBA" ? new Float32Array(stride * 4) : new Float32Array(stride * 3);
|
|
658
|
+
let step = 4, rImagePointer = 0, gImagePointer = 1, bImagePointer = 2, aImagePointer = 3;
|
|
659
|
+
let rTensorPointer = 0, gTensorPointer = stride, bTensorPointer = stride * 2, aTensorPointer = -1;
|
|
660
|
+
if (inputformat === "RGB") {
|
|
661
|
+
step = 3;
|
|
662
|
+
rImagePointer = 0;
|
|
663
|
+
gImagePointer = 1;
|
|
664
|
+
bImagePointer = 2;
|
|
665
|
+
aImagePointer = -1;
|
|
666
|
+
}
|
|
667
|
+
if (outputformat === "RGBA") aTensorPointer = stride * 3;
|
|
668
|
+
else if (outputformat === "RBG") {
|
|
669
|
+
rTensorPointer = 0;
|
|
670
|
+
bTensorPointer = stride;
|
|
671
|
+
gTensorPointer = stride * 2;
|
|
672
|
+
} else if (outputformat === "BGR") {
|
|
673
|
+
bTensorPointer = 0;
|
|
674
|
+
gTensorPointer = stride;
|
|
675
|
+
rTensorPointer = stride * 2;
|
|
676
|
+
}
|
|
677
|
+
for (let i = 0; i < stride; i++, rImagePointer += step, bImagePointer += step, gImagePointer += step, aImagePointer += step) {
|
|
678
|
+
float32Data[rTensorPointer++] = (buffer[rImagePointer] + normBias[0]) / normMean[0];
|
|
679
|
+
float32Data[gTensorPointer++] = (buffer[gImagePointer] + normBias[1]) / normMean[1];
|
|
680
|
+
float32Data[bTensorPointer++] = (buffer[bImagePointer] + normBias[2]) / normMean[2];
|
|
681
|
+
if (aTensorPointer !== -1 && aImagePointer !== -1) float32Data[aTensorPointer++] = (buffer[aImagePointer] + normBias[3]) / normMean[3];
|
|
682
|
+
}
|
|
683
|
+
return outputformat === "RGBA" ? new tensor_impl_js_1.Tensor("float32", float32Data, [
|
|
684
|
+
1,
|
|
685
|
+
4,
|
|
686
|
+
height,
|
|
687
|
+
width
|
|
688
|
+
]) : new tensor_impl_js_1.Tensor("float32", float32Data, [
|
|
689
|
+
1,
|
|
690
|
+
3,
|
|
691
|
+
height,
|
|
692
|
+
width
|
|
693
|
+
]);
|
|
694
|
+
};
|
|
695
|
+
exports.bufferToTensor = bufferToTensor;
|
|
696
|
+
/**
|
|
697
|
+
* implementation of Tensor.fromImage().
|
|
698
|
+
*/
|
|
699
|
+
const tensorFromImage = async (image, options) => {
|
|
700
|
+
const isHTMLImageEle = typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement;
|
|
701
|
+
const isImageDataEle = typeof ImageData !== "undefined" && image instanceof ImageData;
|
|
702
|
+
const isImageBitmap = typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap;
|
|
703
|
+
const isString = typeof image === "string";
|
|
704
|
+
let data;
|
|
705
|
+
let bufferToTensorOptions = options ?? {};
|
|
706
|
+
const createCanvas = () => {
|
|
707
|
+
if (typeof document !== "undefined") return document.createElement("canvas");
|
|
708
|
+
else if (typeof OffscreenCanvas !== "undefined") return new OffscreenCanvas(1, 1);
|
|
709
|
+
else throw new Error("Canvas is not supported");
|
|
710
|
+
};
|
|
711
|
+
const createCanvasContext = (canvas) => {
|
|
712
|
+
if (typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement) return canvas.getContext("2d");
|
|
713
|
+
else if (canvas instanceof OffscreenCanvas) return canvas.getContext("2d");
|
|
714
|
+
else return null;
|
|
715
|
+
};
|
|
716
|
+
if (isHTMLImageEle) {
|
|
717
|
+
const canvas = createCanvas();
|
|
718
|
+
canvas.width = image.width;
|
|
719
|
+
canvas.height = image.height;
|
|
720
|
+
const pixels2DContext = createCanvasContext(canvas);
|
|
721
|
+
if (pixels2DContext != null) {
|
|
722
|
+
let height = image.height;
|
|
723
|
+
let width = image.width;
|
|
724
|
+
if (options !== void 0 && options.resizedHeight !== void 0 && options.resizedWidth !== void 0) {
|
|
725
|
+
height = options.resizedHeight;
|
|
726
|
+
width = options.resizedWidth;
|
|
727
|
+
}
|
|
728
|
+
if (options !== void 0) {
|
|
729
|
+
bufferToTensorOptions = options;
|
|
730
|
+
if (options.tensorFormat !== void 0) throw new Error("Image input config format must be RGBA for HTMLImageElement");
|
|
731
|
+
else bufferToTensorOptions.tensorFormat = "RGBA";
|
|
732
|
+
bufferToTensorOptions.height = height;
|
|
733
|
+
bufferToTensorOptions.width = width;
|
|
734
|
+
} else {
|
|
735
|
+
bufferToTensorOptions.tensorFormat = "RGBA";
|
|
736
|
+
bufferToTensorOptions.height = height;
|
|
737
|
+
bufferToTensorOptions.width = width;
|
|
738
|
+
}
|
|
739
|
+
pixels2DContext.drawImage(image, 0, 0);
|
|
740
|
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
741
|
+
} else throw new Error("Can not access image data");
|
|
742
|
+
} else if (isImageDataEle) {
|
|
743
|
+
let height;
|
|
744
|
+
let width;
|
|
745
|
+
if (options !== void 0 && options.resizedWidth !== void 0 && options.resizedHeight !== void 0) {
|
|
746
|
+
height = options.resizedHeight;
|
|
747
|
+
width = options.resizedWidth;
|
|
748
|
+
} else {
|
|
749
|
+
height = image.height;
|
|
750
|
+
width = image.width;
|
|
751
|
+
}
|
|
752
|
+
if (options !== void 0) bufferToTensorOptions = options;
|
|
753
|
+
bufferToTensorOptions.format = "RGBA";
|
|
754
|
+
bufferToTensorOptions.height = height;
|
|
755
|
+
bufferToTensorOptions.width = width;
|
|
756
|
+
if (options !== void 0) {
|
|
757
|
+
const tempCanvas = createCanvas();
|
|
758
|
+
tempCanvas.width = width;
|
|
759
|
+
tempCanvas.height = height;
|
|
760
|
+
const pixels2DContext = createCanvasContext(tempCanvas);
|
|
761
|
+
if (pixels2DContext != null) {
|
|
762
|
+
pixels2DContext.putImageData(image, 0, 0);
|
|
763
|
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
764
|
+
} else throw new Error("Can not access image data");
|
|
765
|
+
} else data = image.data;
|
|
766
|
+
} else if (isImageBitmap) {
|
|
767
|
+
if (options === void 0) throw new Error("Please provide image config with format for Imagebitmap");
|
|
768
|
+
const canvas = createCanvas();
|
|
769
|
+
canvas.width = image.width;
|
|
770
|
+
canvas.height = image.height;
|
|
771
|
+
const pixels2DContext = createCanvasContext(canvas);
|
|
772
|
+
if (pixels2DContext != null) {
|
|
773
|
+
const height = image.height;
|
|
774
|
+
const width = image.width;
|
|
775
|
+
pixels2DContext.drawImage(image, 0, 0, width, height);
|
|
776
|
+
data = pixels2DContext.getImageData(0, 0, width, height).data;
|
|
777
|
+
bufferToTensorOptions.height = height;
|
|
778
|
+
bufferToTensorOptions.width = width;
|
|
779
|
+
return (0, exports.bufferToTensor)(data, bufferToTensorOptions);
|
|
780
|
+
} else throw new Error("Can not access image data");
|
|
781
|
+
} else if (isString) return new Promise((resolve, reject) => {
|
|
782
|
+
const canvas = createCanvas();
|
|
783
|
+
const context = createCanvasContext(canvas);
|
|
784
|
+
if (!image || !context) return reject();
|
|
785
|
+
const newImage = new Image();
|
|
786
|
+
newImage.crossOrigin = "Anonymous";
|
|
787
|
+
newImage.src = image;
|
|
788
|
+
newImage.onload = () => {
|
|
789
|
+
canvas.width = newImage.width;
|
|
790
|
+
canvas.height = newImage.height;
|
|
791
|
+
context.drawImage(newImage, 0, 0, canvas.width, canvas.height);
|
|
792
|
+
const img = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
793
|
+
bufferToTensorOptions.height = canvas.height;
|
|
794
|
+
bufferToTensorOptions.width = canvas.width;
|
|
795
|
+
resolve((0, exports.bufferToTensor)(img.data, bufferToTensorOptions));
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
else throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
799
|
+
if (data !== void 0) return (0, exports.bufferToTensor)(data, bufferToTensorOptions);
|
|
800
|
+
else throw new Error("Input data provided is not supported - aborted tensor creation");
|
|
801
|
+
};
|
|
802
|
+
exports.tensorFromImage = tensorFromImage;
|
|
803
|
+
/**
|
|
804
|
+
* implementation of Tensor.fromTexture().
|
|
805
|
+
*/
|
|
806
|
+
const tensorFromTexture = (texture, options) => {
|
|
807
|
+
const { width, height, download, dispose } = options;
|
|
808
|
+
const dims = [
|
|
809
|
+
1,
|
|
810
|
+
height,
|
|
811
|
+
width,
|
|
812
|
+
4
|
|
813
|
+
];
|
|
814
|
+
return new tensor_impl_js_1.Tensor({
|
|
815
|
+
location: "texture",
|
|
816
|
+
type: "float32",
|
|
817
|
+
texture,
|
|
818
|
+
dims,
|
|
819
|
+
download,
|
|
820
|
+
dispose
|
|
821
|
+
});
|
|
822
|
+
};
|
|
823
|
+
exports.tensorFromTexture = tensorFromTexture;
|
|
824
|
+
/**
|
|
825
|
+
* implementation of Tensor.fromGpuBuffer().
|
|
826
|
+
*/
|
|
827
|
+
const tensorFromGpuBuffer = (gpuBuffer, options) => {
|
|
828
|
+
const { dataType, dims, download, dispose } = options;
|
|
829
|
+
return new tensor_impl_js_1.Tensor({
|
|
830
|
+
location: "gpu-buffer",
|
|
831
|
+
type: dataType ?? "float32",
|
|
832
|
+
gpuBuffer,
|
|
833
|
+
dims,
|
|
834
|
+
download,
|
|
835
|
+
dispose
|
|
836
|
+
});
|
|
837
|
+
};
|
|
838
|
+
exports.tensorFromGpuBuffer = tensorFromGpuBuffer;
|
|
839
|
+
/**
|
|
840
|
+
* implementation of Tensor.fromMLTensor().
|
|
841
|
+
*/
|
|
842
|
+
const tensorFromMLTensor = (mlTensor, options) => {
|
|
843
|
+
const { dataType, dims, download, dispose } = options;
|
|
844
|
+
return new tensor_impl_js_1.Tensor({
|
|
845
|
+
location: "ml-tensor",
|
|
846
|
+
type: dataType ?? "float32",
|
|
847
|
+
mlTensor,
|
|
848
|
+
dims,
|
|
849
|
+
download,
|
|
850
|
+
dispose
|
|
851
|
+
});
|
|
852
|
+
};
|
|
853
|
+
exports.tensorFromMLTensor = tensorFromMLTensor;
|
|
854
|
+
/**
|
|
855
|
+
* implementation of Tensor.fromPinnedBuffer().
|
|
856
|
+
*/
|
|
857
|
+
const tensorFromPinnedBuffer = (type, buffer, dims) => new tensor_impl_js_1.Tensor({
|
|
858
|
+
location: "cpu-pinned",
|
|
859
|
+
type,
|
|
860
|
+
data: buffer,
|
|
861
|
+
dims: dims ?? [buffer.length]
|
|
862
|
+
});
|
|
863
|
+
exports.tensorFromPinnedBuffer = tensorFromPinnedBuffer;
|
|
864
|
+
}));
|
|
865
|
+
//#endregion
|
|
866
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-impl-type-mapping.js
|
|
867
|
+
var require_tensor_impl_type_mapping = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
868
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
869
|
+
exports.checkTypedArray = exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = void 0;
|
|
870
|
+
exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP = new Map([
|
|
871
|
+
["float32", Float32Array],
|
|
872
|
+
["uint8", Uint8Array],
|
|
873
|
+
["int8", Int8Array],
|
|
874
|
+
["uint16", Uint16Array],
|
|
875
|
+
["int16", Int16Array],
|
|
876
|
+
["int32", Int32Array],
|
|
877
|
+
["bool", Uint8Array],
|
|
878
|
+
["float64", Float64Array],
|
|
879
|
+
["uint32", Uint32Array],
|
|
880
|
+
["int4", Uint8Array],
|
|
881
|
+
["uint4", Uint8Array]
|
|
882
|
+
]);
|
|
883
|
+
exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP = new Map([
|
|
884
|
+
[Float32Array, "float32"],
|
|
885
|
+
[Uint8Array, "uint8"],
|
|
886
|
+
[Int8Array, "int8"],
|
|
887
|
+
[Uint16Array, "uint16"],
|
|
888
|
+
[Int16Array, "int16"],
|
|
889
|
+
[Int32Array, "int32"],
|
|
890
|
+
[Float64Array, "float64"],
|
|
891
|
+
[Uint32Array, "uint32"]
|
|
892
|
+
]);
|
|
893
|
+
let isTypedArrayChecked = false;
|
|
894
|
+
const checkTypedArray = () => {
|
|
895
|
+
if (!isTypedArrayChecked) {
|
|
896
|
+
isTypedArrayChecked = true;
|
|
897
|
+
const isBigInt64ArrayAvailable = typeof BigInt64Array !== "undefined" && BigInt64Array.from;
|
|
898
|
+
const isBigUint64ArrayAvailable = typeof BigUint64Array !== "undefined" && BigUint64Array.from;
|
|
899
|
+
const Float16Array = globalThis.Float16Array;
|
|
900
|
+
const isFloat16ArrayAvailable = typeof Float16Array !== "undefined" && Float16Array.from;
|
|
901
|
+
if (isBigInt64ArrayAvailable) {
|
|
902
|
+
exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64", BigInt64Array);
|
|
903
|
+
exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array, "int64");
|
|
904
|
+
}
|
|
905
|
+
if (isBigUint64ArrayAvailable) {
|
|
906
|
+
exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64", BigUint64Array);
|
|
907
|
+
exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array, "uint64");
|
|
908
|
+
}
|
|
909
|
+
if (isFloat16ArrayAvailable) {
|
|
910
|
+
exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Float16Array);
|
|
911
|
+
exports.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(Float16Array, "float16");
|
|
912
|
+
} else exports.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("float16", Uint16Array);
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
exports.checkTypedArray = checkTypedArray;
|
|
916
|
+
}));
|
|
917
|
+
//#endregion
|
|
918
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-utils-impl.js
|
|
919
|
+
var require_tensor_utils_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
920
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
921
|
+
exports.tensorReshape = exports.calculateSize = void 0;
|
|
922
|
+
const tensor_impl_js_1 = require_tensor_impl();
|
|
923
|
+
/**
|
|
924
|
+
* calculate size from dims.
|
|
925
|
+
*
|
|
926
|
+
* @param dims the dims array. May be an illegal input.
|
|
927
|
+
*/
|
|
928
|
+
const calculateSize = (dims) => {
|
|
929
|
+
let size = 1;
|
|
930
|
+
for (let i = 0; i < dims.length; i++) {
|
|
931
|
+
const dim = dims[i];
|
|
932
|
+
if (typeof dim !== "number" || !Number.isSafeInteger(dim)) throw new TypeError(`dims[${i}] must be an integer, got: ${dim}`);
|
|
933
|
+
if (dim < 0) throw new RangeError(`dims[${i}] must be a non-negative integer, got: ${dim}`);
|
|
934
|
+
size *= dim;
|
|
935
|
+
}
|
|
936
|
+
return size;
|
|
937
|
+
};
|
|
938
|
+
exports.calculateSize = calculateSize;
|
|
939
|
+
/**
|
|
940
|
+
* implementation of Tensor.reshape()
|
|
941
|
+
*/
|
|
942
|
+
const tensorReshape = (tensor, dims) => {
|
|
943
|
+
switch (tensor.location) {
|
|
944
|
+
case "cpu": return new tensor_impl_js_1.Tensor(tensor.type, tensor.data, dims);
|
|
945
|
+
case "cpu-pinned": return new tensor_impl_js_1.Tensor({
|
|
946
|
+
location: "cpu-pinned",
|
|
947
|
+
data: tensor.data,
|
|
948
|
+
type: tensor.type,
|
|
949
|
+
dims
|
|
950
|
+
});
|
|
951
|
+
case "texture": return new tensor_impl_js_1.Tensor({
|
|
952
|
+
location: "texture",
|
|
953
|
+
texture: tensor.texture,
|
|
954
|
+
type: tensor.type,
|
|
955
|
+
dims
|
|
956
|
+
});
|
|
957
|
+
case "gpu-buffer": return new tensor_impl_js_1.Tensor({
|
|
958
|
+
location: "gpu-buffer",
|
|
959
|
+
gpuBuffer: tensor.gpuBuffer,
|
|
960
|
+
type: tensor.type,
|
|
961
|
+
dims
|
|
962
|
+
});
|
|
963
|
+
case "ml-tensor": return new tensor_impl_js_1.Tensor({
|
|
964
|
+
location: "ml-tensor",
|
|
965
|
+
mlTensor: tensor.mlTensor,
|
|
966
|
+
type: tensor.type,
|
|
967
|
+
dims
|
|
968
|
+
});
|
|
969
|
+
default: throw new Error(`tensorReshape: tensor location ${tensor.location} is not supported`);
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
exports.tensorReshape = tensorReshape;
|
|
973
|
+
}));
|
|
974
|
+
//#endregion
|
|
975
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-impl.js
|
|
976
|
+
var require_tensor_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
977
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
978
|
+
exports.Tensor = void 0;
|
|
979
|
+
const tensor_conversion_impl_js_1 = require_tensor_conversion_impl();
|
|
980
|
+
const tensor_factory_impl_js_1 = require_tensor_factory_impl();
|
|
981
|
+
const tensor_impl_type_mapping_js_1 = require_tensor_impl_type_mapping();
|
|
982
|
+
const tensor_utils_impl_js_1 = require_tensor_utils_impl();
|
|
983
|
+
/**
|
|
984
|
+
* the implementation of Tensor interface.
|
|
985
|
+
*
|
|
986
|
+
* @ignore
|
|
987
|
+
*/
|
|
988
|
+
var Tensor = class {
|
|
989
|
+
/**
|
|
990
|
+
* implementation.
|
|
991
|
+
*/
|
|
992
|
+
constructor(arg0, arg1, arg2) {
|
|
993
|
+
(0, tensor_impl_type_mapping_js_1.checkTypedArray)();
|
|
994
|
+
let type;
|
|
995
|
+
let dims;
|
|
996
|
+
if (typeof arg0 === "object" && "location" in arg0) {
|
|
997
|
+
this.dataLocation = arg0.location;
|
|
998
|
+
type = arg0.type;
|
|
999
|
+
dims = arg0.dims;
|
|
1000
|
+
switch (arg0.location) {
|
|
1001
|
+
case "cpu-pinned": {
|
|
1002
|
+
const expectedTypedArrayConstructor = tensor_impl_type_mapping_js_1.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(type);
|
|
1003
|
+
if (!expectedTypedArrayConstructor) throw new TypeError(`unsupported type "${type}" to create tensor from pinned buffer`);
|
|
1004
|
+
if (!(arg0.data instanceof expectedTypedArrayConstructor)) throw new TypeError(`buffer should be of type ${expectedTypedArrayConstructor.name}`);
|
|
1005
|
+
this.cpuData = arg0.data;
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
1008
|
+
case "texture":
|
|
1009
|
+
if (type !== "float32") throw new TypeError(`unsupported type "${type}" to create tensor from texture`);
|
|
1010
|
+
this.gpuTextureData = arg0.texture;
|
|
1011
|
+
this.downloader = arg0.download;
|
|
1012
|
+
this.disposer = arg0.dispose;
|
|
1013
|
+
break;
|
|
1014
|
+
case "gpu-buffer":
|
|
1015
|
+
if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") throw new TypeError(`unsupported type "${type}" to create tensor from gpu buffer`);
|
|
1016
|
+
this.gpuBufferData = arg0.gpuBuffer;
|
|
1017
|
+
this.downloader = arg0.download;
|
|
1018
|
+
this.disposer = arg0.dispose;
|
|
1019
|
+
break;
|
|
1020
|
+
case "ml-tensor":
|
|
1021
|
+
if (type !== "float32" && type !== "float16" && type !== "int32" && type !== "int64" && type !== "uint32" && type !== "uint64" && type !== "int8" && type !== "uint8" && type !== "bool" && type !== "uint4" && type !== "int4") throw new TypeError(`unsupported type "${type}" to create tensor from MLTensor`);
|
|
1022
|
+
this.mlTensorData = arg0.mlTensor;
|
|
1023
|
+
this.downloader = arg0.download;
|
|
1024
|
+
this.disposer = arg0.dispose;
|
|
1025
|
+
break;
|
|
1026
|
+
default: throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`);
|
|
1027
|
+
}
|
|
1028
|
+
} else {
|
|
1029
|
+
let data;
|
|
1030
|
+
let maybeDims;
|
|
1031
|
+
if (typeof arg0 === "string") {
|
|
1032
|
+
type = arg0;
|
|
1033
|
+
maybeDims = arg2;
|
|
1034
|
+
if (arg0 === "string") {
|
|
1035
|
+
if (!Array.isArray(arg1)) throw new TypeError("A string tensor's data must be a string array.");
|
|
1036
|
+
data = arg1;
|
|
1037
|
+
} else {
|
|
1038
|
+
const typedArrayConstructor = tensor_impl_type_mapping_js_1.NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
|
|
1039
|
+
if (typedArrayConstructor === void 0) throw new TypeError(`Unsupported tensor type: ${arg0}.`);
|
|
1040
|
+
if (Array.isArray(arg1)) if (arg0 === "float16" && typedArrayConstructor === Uint16Array || arg0 === "uint4" || arg0 === "int4") throw new TypeError(`Creating a ${arg0} tensor from number array is not supported. Please use ${typedArrayConstructor.name} as data.`);
|
|
1041
|
+
else if (arg0 === "uint64" || arg0 === "int64") data = typedArrayConstructor.from(arg1, BigInt);
|
|
1042
|
+
else data = typedArrayConstructor.from(arg1);
|
|
1043
|
+
else if (arg1 instanceof typedArrayConstructor) data = arg1;
|
|
1044
|
+
else if (arg1 instanceof Uint8ClampedArray) if (arg0 === "uint8") data = Uint8Array.from(arg1);
|
|
1045
|
+
else throw new TypeError(`A Uint8ClampedArray tensor's data must be type of uint8`);
|
|
1046
|
+
else if (arg0 === "float16" && arg1 instanceof Uint16Array && typedArrayConstructor !== Uint16Array) data = new globalThis.Float16Array(arg1.buffer, arg1.byteOffset, arg1.length);
|
|
1047
|
+
else throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
|
|
1048
|
+
}
|
|
1049
|
+
} else {
|
|
1050
|
+
maybeDims = arg1;
|
|
1051
|
+
if (Array.isArray(arg0)) {
|
|
1052
|
+
if (arg0.length === 0) throw new TypeError("Tensor type cannot be inferred from an empty array.");
|
|
1053
|
+
const firstElementType = typeof arg0[0];
|
|
1054
|
+
if (firstElementType === "string") {
|
|
1055
|
+
type = "string";
|
|
1056
|
+
data = arg0;
|
|
1057
|
+
} else if (firstElementType === "boolean") {
|
|
1058
|
+
type = "bool";
|
|
1059
|
+
data = Uint8Array.from(arg0);
|
|
1060
|
+
} else throw new TypeError(`Invalid element type of data array: ${firstElementType}.`);
|
|
1061
|
+
} else if (arg0 instanceof Uint8ClampedArray) {
|
|
1062
|
+
type = "uint8";
|
|
1063
|
+
data = Uint8Array.from(arg0);
|
|
1064
|
+
} else {
|
|
1065
|
+
const mappedType = tensor_impl_type_mapping_js_1.NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(arg0.constructor);
|
|
1066
|
+
if (mappedType === void 0) throw new TypeError(`Unsupported type for tensor data: ${arg0.constructor}.`);
|
|
1067
|
+
type = mappedType;
|
|
1068
|
+
data = arg0;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
if (maybeDims === void 0) maybeDims = [data.length];
|
|
1072
|
+
else if (!Array.isArray(maybeDims)) throw new TypeError("A tensor's dims must be a number array");
|
|
1073
|
+
dims = maybeDims;
|
|
1074
|
+
this.cpuData = data;
|
|
1075
|
+
this.dataLocation = "cpu";
|
|
1076
|
+
}
|
|
1077
|
+
const size = (0, tensor_utils_impl_js_1.calculateSize)(dims);
|
|
1078
|
+
if (this.cpuData && size !== this.cpuData.length) if ((type === "uint4" || type === "int4") && Math.ceil(size / 2) === this.cpuData.length) {} else throw new Error(`Tensor's size(${size}) does not match data length(${this.cpuData.length}).`);
|
|
1079
|
+
this.type = type;
|
|
1080
|
+
this.dims = dims;
|
|
1081
|
+
this.size = size;
|
|
1082
|
+
}
|
|
1083
|
+
static async fromImage(image, options) {
|
|
1084
|
+
return (0, tensor_factory_impl_js_1.tensorFromImage)(image, options);
|
|
1085
|
+
}
|
|
1086
|
+
static fromTexture(texture, options) {
|
|
1087
|
+
return (0, tensor_factory_impl_js_1.tensorFromTexture)(texture, options);
|
|
1088
|
+
}
|
|
1089
|
+
static fromGpuBuffer(gpuBuffer, options) {
|
|
1090
|
+
return (0, tensor_factory_impl_js_1.tensorFromGpuBuffer)(gpuBuffer, options);
|
|
1091
|
+
}
|
|
1092
|
+
static fromMLTensor(mlTensor, options) {
|
|
1093
|
+
return (0, tensor_factory_impl_js_1.tensorFromMLTensor)(mlTensor, options);
|
|
1094
|
+
}
|
|
1095
|
+
static fromPinnedBuffer(type, buffer, dims) {
|
|
1096
|
+
return (0, tensor_factory_impl_js_1.tensorFromPinnedBuffer)(type, buffer, dims);
|
|
1097
|
+
}
|
|
1098
|
+
toDataURL(options) {
|
|
1099
|
+
return (0, tensor_conversion_impl_js_1.tensorToDataURL)(this, options);
|
|
1100
|
+
}
|
|
1101
|
+
toImageData(options) {
|
|
1102
|
+
return (0, tensor_conversion_impl_js_1.tensorToImageData)(this, options);
|
|
1103
|
+
}
|
|
1104
|
+
get data() {
|
|
1105
|
+
this.ensureValid();
|
|
1106
|
+
if (!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.");
|
|
1107
|
+
return this.cpuData;
|
|
1108
|
+
}
|
|
1109
|
+
get location() {
|
|
1110
|
+
return this.dataLocation;
|
|
1111
|
+
}
|
|
1112
|
+
get texture() {
|
|
1113
|
+
this.ensureValid();
|
|
1114
|
+
if (!this.gpuTextureData) throw new Error("The data is not stored as a WebGL texture.");
|
|
1115
|
+
return this.gpuTextureData;
|
|
1116
|
+
}
|
|
1117
|
+
get gpuBuffer() {
|
|
1118
|
+
this.ensureValid();
|
|
1119
|
+
if (!this.gpuBufferData) throw new Error("The data is not stored as a WebGPU buffer.");
|
|
1120
|
+
return this.gpuBufferData;
|
|
1121
|
+
}
|
|
1122
|
+
get mlTensor() {
|
|
1123
|
+
this.ensureValid();
|
|
1124
|
+
if (!this.mlTensorData) throw new Error("The data is not stored as a WebNN MLTensor.");
|
|
1125
|
+
return this.mlTensorData;
|
|
1126
|
+
}
|
|
1127
|
+
async getData(releaseData) {
|
|
1128
|
+
this.ensureValid();
|
|
1129
|
+
switch (this.dataLocation) {
|
|
1130
|
+
case "cpu":
|
|
1131
|
+
case "cpu-pinned": return this.data;
|
|
1132
|
+
case "texture":
|
|
1133
|
+
case "gpu-buffer":
|
|
1134
|
+
case "ml-tensor":
|
|
1135
|
+
if (!this.downloader) throw new Error("The current tensor is not created with a specified data downloader.");
|
|
1136
|
+
if (this.isDownloading) throw new Error("The current tensor is being downloaded.");
|
|
1137
|
+
try {
|
|
1138
|
+
this.isDownloading = true;
|
|
1139
|
+
const data = await this.downloader();
|
|
1140
|
+
this.downloader = void 0;
|
|
1141
|
+
this.dataLocation = "cpu";
|
|
1142
|
+
this.cpuData = data;
|
|
1143
|
+
if (releaseData && this.disposer) {
|
|
1144
|
+
this.disposer();
|
|
1145
|
+
this.disposer = void 0;
|
|
1146
|
+
}
|
|
1147
|
+
return data;
|
|
1148
|
+
} finally {
|
|
1149
|
+
this.isDownloading = false;
|
|
1150
|
+
}
|
|
1151
|
+
default: throw new Error(`cannot get data from location: ${this.dataLocation}`);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
dispose() {
|
|
1155
|
+
if (this.isDownloading) throw new Error("The current tensor is being downloaded.");
|
|
1156
|
+
if (this.disposer) {
|
|
1157
|
+
this.disposer();
|
|
1158
|
+
this.disposer = void 0;
|
|
1159
|
+
}
|
|
1160
|
+
this.cpuData = void 0;
|
|
1161
|
+
this.gpuTextureData = void 0;
|
|
1162
|
+
this.gpuBufferData = void 0;
|
|
1163
|
+
this.mlTensorData = void 0;
|
|
1164
|
+
this.downloader = void 0;
|
|
1165
|
+
this.isDownloading = void 0;
|
|
1166
|
+
this.dataLocation = "none";
|
|
1167
|
+
}
|
|
1168
|
+
ensureValid() {
|
|
1169
|
+
if (this.dataLocation === "none") throw new Error("The tensor is disposed.");
|
|
1170
|
+
}
|
|
1171
|
+
reshape(dims) {
|
|
1172
|
+
this.ensureValid();
|
|
1173
|
+
if (this.downloader || this.disposer) throw new Error("Cannot reshape a tensor that owns GPU resource.");
|
|
1174
|
+
return (0, tensor_utils_impl_js_1.tensorReshape)(this, dims);
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
exports.Tensor = Tensor;
|
|
1178
|
+
}));
|
|
1179
|
+
//#endregion
|
|
1180
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor.js
|
|
1181
|
+
var require_tensor = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1182
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1183
|
+
exports.Tensor = void 0;
|
|
1184
|
+
exports.Tensor = require_tensor_impl().Tensor;
|
|
1185
|
+
}));
|
|
1186
|
+
//#endregion
|
|
1187
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/trace.js
|
|
1188
|
+
var require_trace = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1189
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1190
|
+
exports.TRACE_FUNC_END = exports.TRACE_FUNC_BEGIN = exports.TRACE = void 0;
|
|
1191
|
+
const env_impl_js_1 = require_env_impl();
|
|
1192
|
+
/**
|
|
1193
|
+
* @ignore
|
|
1194
|
+
*/
|
|
1195
|
+
const TRACE = (deviceType, label) => {
|
|
1196
|
+
if (typeof env_impl_js_1.env.trace === "undefined" ? !env_impl_js_1.env.wasm.trace : !env_impl_js_1.env.trace) return;
|
|
1197
|
+
console.timeStamp(`${deviceType}::ORT::${label}`);
|
|
1198
|
+
};
|
|
1199
|
+
exports.TRACE = TRACE;
|
|
1200
|
+
const TRACE_FUNC = (msg, extraMsg) => {
|
|
1201
|
+
const stack = (/* @__PURE__ */ new Error()).stack?.split(/\r\n|\r|\n/g) || [];
|
|
1202
|
+
let hasTraceFunc = false;
|
|
1203
|
+
for (let i = 0; i < stack.length; i++) {
|
|
1204
|
+
if (hasTraceFunc && !stack[i].includes("TRACE_FUNC")) {
|
|
1205
|
+
let label = `FUNC_${msg}::${stack[i].trim().split(" ")[1]}`;
|
|
1206
|
+
if (extraMsg) label += `::${extraMsg}`;
|
|
1207
|
+
(0, exports.TRACE)("CPU", label);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
if (stack[i].includes("TRACE_FUNC")) hasTraceFunc = true;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
/**
|
|
1214
|
+
* @ignore
|
|
1215
|
+
*/
|
|
1216
|
+
const TRACE_FUNC_BEGIN = (extraMsg) => {
|
|
1217
|
+
if (typeof env_impl_js_1.env.trace === "undefined" ? !env_impl_js_1.env.wasm.trace : !env_impl_js_1.env.trace) return;
|
|
1218
|
+
TRACE_FUNC("BEGIN", extraMsg);
|
|
1219
|
+
};
|
|
1220
|
+
exports.TRACE_FUNC_BEGIN = TRACE_FUNC_BEGIN;
|
|
1221
|
+
/**
|
|
1222
|
+
* @ignore
|
|
1223
|
+
*/
|
|
1224
|
+
const TRACE_FUNC_END = (extraMsg) => {
|
|
1225
|
+
if (typeof env_impl_js_1.env.trace === "undefined" ? !env_impl_js_1.env.wasm.trace : !env_impl_js_1.env.trace) return;
|
|
1226
|
+
TRACE_FUNC("END", extraMsg);
|
|
1227
|
+
};
|
|
1228
|
+
exports.TRACE_FUNC_END = TRACE_FUNC_END;
|
|
1229
|
+
}));
|
|
1230
|
+
//#endregion
|
|
1231
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/inference-session-impl.js
|
|
1232
|
+
var require_inference_session_impl = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1233
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1234
|
+
exports.InferenceSession = void 0;
|
|
1235
|
+
const backend_impl_js_1 = require_backend_impl();
|
|
1236
|
+
const tensor_js_1 = require_tensor();
|
|
1237
|
+
const trace_js_1 = require_trace();
|
|
1238
|
+
exports.InferenceSession = class InferenceSession {
|
|
1239
|
+
constructor(handler) {
|
|
1240
|
+
this.handler = handler;
|
|
1241
|
+
}
|
|
1242
|
+
async run(feeds, arg1, arg2) {
|
|
1243
|
+
(0, trace_js_1.TRACE_FUNC_BEGIN)();
|
|
1244
|
+
const fetches = {};
|
|
1245
|
+
let options = {};
|
|
1246
|
+
if (typeof feeds !== "object" || feeds === null || feeds instanceof tensor_js_1.Tensor || Array.isArray(feeds)) throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");
|
|
1247
|
+
let isFetchesEmpty = true;
|
|
1248
|
+
if (typeof arg1 === "object") {
|
|
1249
|
+
if (arg1 === null) throw new TypeError("Unexpected argument[1]: cannot be null.");
|
|
1250
|
+
if (arg1 instanceof tensor_js_1.Tensor) throw new TypeError("'fetches' cannot be a Tensor");
|
|
1251
|
+
if (Array.isArray(arg1)) {
|
|
1252
|
+
if (arg1.length === 0) throw new TypeError("'fetches' cannot be an empty array.");
|
|
1253
|
+
isFetchesEmpty = false;
|
|
1254
|
+
for (const name of arg1) {
|
|
1255
|
+
if (typeof name !== "string") throw new TypeError("'fetches' must be a string array or an object.");
|
|
1256
|
+
if (this.outputNames.indexOf(name) === -1) throw new RangeError(`'fetches' contains invalid output name: ${name}.`);
|
|
1257
|
+
fetches[name] = null;
|
|
1258
|
+
}
|
|
1259
|
+
if (typeof arg2 === "object" && arg2 !== null) options = arg2;
|
|
1260
|
+
else if (typeof arg2 !== "undefined") throw new TypeError("'options' must be an object.");
|
|
1261
|
+
} else {
|
|
1262
|
+
let isFetches = false;
|
|
1263
|
+
const arg1Keys = Object.getOwnPropertyNames(arg1);
|
|
1264
|
+
for (const name of this.outputNames) if (arg1Keys.indexOf(name) !== -1) {
|
|
1265
|
+
const v = arg1[name];
|
|
1266
|
+
if (v === null || v instanceof tensor_js_1.Tensor) {
|
|
1267
|
+
isFetches = true;
|
|
1268
|
+
isFetchesEmpty = false;
|
|
1269
|
+
fetches[name] = v;
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
if (isFetches) {
|
|
1273
|
+
if (typeof arg2 === "object" && arg2 !== null) options = arg2;
|
|
1274
|
+
else if (typeof arg2 !== "undefined") throw new TypeError("'options' must be an object.");
|
|
1275
|
+
} else options = arg1;
|
|
1276
|
+
}
|
|
1277
|
+
} else if (typeof arg1 !== "undefined") throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");
|
|
1278
|
+
for (const name of this.inputNames) if (typeof feeds[name] === "undefined") throw new Error(`input '${name}' is missing in 'feeds'.`);
|
|
1279
|
+
if (isFetchesEmpty) for (const name of this.outputNames) fetches[name] = null;
|
|
1280
|
+
const results = await this.handler.run(feeds, fetches, options);
|
|
1281
|
+
const returnValue = {};
|
|
1282
|
+
for (const key in results) if (Object.hasOwnProperty.call(results, key)) {
|
|
1283
|
+
const result = results[key];
|
|
1284
|
+
if (result instanceof tensor_js_1.Tensor) returnValue[key] = result;
|
|
1285
|
+
else returnValue[key] = new tensor_js_1.Tensor(result.type, result.data, result.dims);
|
|
1286
|
+
}
|
|
1287
|
+
(0, trace_js_1.TRACE_FUNC_END)();
|
|
1288
|
+
return returnValue;
|
|
1289
|
+
}
|
|
1290
|
+
async release() {
|
|
1291
|
+
return this.handler.dispose();
|
|
1292
|
+
}
|
|
1293
|
+
static async create(arg0, arg1, arg2, arg3) {
|
|
1294
|
+
(0, trace_js_1.TRACE_FUNC_BEGIN)();
|
|
1295
|
+
let filePathOrUint8Array;
|
|
1296
|
+
let options = {};
|
|
1297
|
+
if (typeof arg0 === "string") {
|
|
1298
|
+
filePathOrUint8Array = arg0;
|
|
1299
|
+
if (typeof arg1 === "object" && arg1 !== null) options = arg1;
|
|
1300
|
+
else if (typeof arg1 !== "undefined") throw new TypeError("'options' must be an object.");
|
|
1301
|
+
} else if (arg0 instanceof Uint8Array) {
|
|
1302
|
+
filePathOrUint8Array = arg0;
|
|
1303
|
+
if (typeof arg1 === "object" && arg1 !== null) options = arg1;
|
|
1304
|
+
else if (typeof arg1 !== "undefined") throw new TypeError("'options' must be an object.");
|
|
1305
|
+
} else if (arg0 instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && arg0 instanceof SharedArrayBuffer) {
|
|
1306
|
+
const buffer = arg0;
|
|
1307
|
+
let byteOffset = 0;
|
|
1308
|
+
let byteLength = arg0.byteLength;
|
|
1309
|
+
if (typeof arg1 === "object" && arg1 !== null) options = arg1;
|
|
1310
|
+
else if (typeof arg1 === "number") {
|
|
1311
|
+
byteOffset = arg1;
|
|
1312
|
+
if (!Number.isSafeInteger(byteOffset)) throw new RangeError("'byteOffset' must be an integer.");
|
|
1313
|
+
if (byteOffset < 0 || byteOffset >= buffer.byteLength) throw new RangeError(`'byteOffset' is out of range [0, ${buffer.byteLength}).`);
|
|
1314
|
+
byteLength = arg0.byteLength - byteOffset;
|
|
1315
|
+
if (typeof arg2 === "number") {
|
|
1316
|
+
byteLength = arg2;
|
|
1317
|
+
if (!Number.isSafeInteger(byteLength)) throw new RangeError("'byteLength' must be an integer.");
|
|
1318
|
+
if (byteLength <= 0 || byteOffset + byteLength > buffer.byteLength) throw new RangeError(`'byteLength' is out of range (0, ${buffer.byteLength - byteOffset}].`);
|
|
1319
|
+
if (typeof arg3 === "object" && arg3 !== null) options = arg3;
|
|
1320
|
+
else if (typeof arg3 !== "undefined") throw new TypeError("'options' must be an object.");
|
|
1321
|
+
} else if (typeof arg2 !== "undefined") throw new TypeError("'byteLength' must be a number.");
|
|
1322
|
+
} else if (typeof arg1 !== "undefined") throw new TypeError("'options' must be an object.");
|
|
1323
|
+
filePathOrUint8Array = new Uint8Array(buffer, byteOffset, byteLength);
|
|
1324
|
+
} else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");
|
|
1325
|
+
const [backend, optionsWithValidatedEPs] = await (0, backend_impl_js_1.resolveBackendAndExecutionProviders)(options);
|
|
1326
|
+
const handler = await backend.createInferenceSessionHandler(filePathOrUint8Array, optionsWithValidatedEPs);
|
|
1327
|
+
(0, trace_js_1.TRACE_FUNC_END)();
|
|
1328
|
+
return new InferenceSession(handler);
|
|
1329
|
+
}
|
|
1330
|
+
startProfiling() {
|
|
1331
|
+
this.handler.startProfiling();
|
|
1332
|
+
}
|
|
1333
|
+
endProfiling() {
|
|
1334
|
+
this.handler.endProfiling();
|
|
1335
|
+
}
|
|
1336
|
+
get inputNames() {
|
|
1337
|
+
return this.handler.inputNames;
|
|
1338
|
+
}
|
|
1339
|
+
get outputNames() {
|
|
1340
|
+
return this.handler.outputNames;
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
}));
|
|
1344
|
+
//#endregion
|
|
1345
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/inference-session.js
|
|
1346
|
+
var require_inference_session = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1347
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1348
|
+
exports.InferenceSession = void 0;
|
|
1349
|
+
exports.InferenceSession = require_inference_session_impl().InferenceSession;
|
|
1350
|
+
}));
|
|
1351
|
+
//#endregion
|
|
1352
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-conversion.js
|
|
1353
|
+
var require_tensor_conversion = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1354
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1355
|
+
}));
|
|
1356
|
+
//#endregion
|
|
1357
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/tensor-factory.js
|
|
1358
|
+
var require_tensor_factory = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1359
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1360
|
+
}));
|
|
1361
|
+
//#endregion
|
|
1362
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/onnx-model.js
|
|
1363
|
+
var require_onnx_model = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1364
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1365
|
+
}));
|
|
1366
|
+
//#endregion
|
|
1367
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/onnx-value.js
|
|
1368
|
+
var require_onnx_value = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1369
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1370
|
+
}));
|
|
1371
|
+
//#endregion
|
|
1372
|
+
//#region ../../node_modules/.pnpm/onnxruntime-common@1.21.0/node_modules/onnxruntime-common/dist/cjs/index.js
|
|
1373
|
+
var require_cjs = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1374
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1375
|
+
if (k2 === void 0) k2 = k;
|
|
1376
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1377
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
1378
|
+
enumerable: true,
|
|
1379
|
+
get: function() {
|
|
1380
|
+
return m[k];
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
Object.defineProperty(o, k2, desc);
|
|
1384
|
+
}) : (function(o, m, k, k2) {
|
|
1385
|
+
if (k2 === void 0) k2 = k;
|
|
1386
|
+
o[k2] = m[k];
|
|
1387
|
+
}));
|
|
1388
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports$2) {
|
|
1389
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$2, p)) __createBinding(exports$2, m, p);
|
|
1390
|
+
};
|
|
1391
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1392
|
+
/**
|
|
1393
|
+
* # ONNX Runtime JavaScript API
|
|
1394
|
+
*
|
|
1395
|
+
* ONNX Runtime JavaScript API is a unified API for all JavaScript usages, including the following NPM packages:
|
|
1396
|
+
*
|
|
1397
|
+
* - [onnxruntime-node](https://www.npmjs.com/package/onnxruntime-node)
|
|
1398
|
+
* - [onnxruntime-web](https://www.npmjs.com/package/onnxruntime-web)
|
|
1399
|
+
* - [onnxruntime-react-native](https://www.npmjs.com/package/onnxruntime-react-native)
|
|
1400
|
+
*
|
|
1401
|
+
* See also:
|
|
1402
|
+
* - [Get Started](https://onnxruntime.ai/docs/get-started/with-javascript/)
|
|
1403
|
+
* - [Inference examples](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/js)
|
|
1404
|
+
*
|
|
1405
|
+
* @packageDocumentation
|
|
1406
|
+
*/
|
|
1407
|
+
__exportStar(require_backend$1(), exports);
|
|
1408
|
+
__exportStar(require_env(), exports);
|
|
1409
|
+
__exportStar(require_inference_session(), exports);
|
|
1410
|
+
__exportStar(require_tensor(), exports);
|
|
1411
|
+
__exportStar(require_tensor_conversion(), exports);
|
|
1412
|
+
__exportStar(require_tensor_factory(), exports);
|
|
1413
|
+
__exportStar(require_trace(), exports);
|
|
1414
|
+
__exportStar(require_onnx_model(), exports);
|
|
1415
|
+
__exportStar(require_onnx_value(), exports);
|
|
1416
|
+
}));
|
|
1417
|
+
//#endregion
|
|
1418
|
+
//#region ../../node_modules/.pnpm/onnxruntime-node@1.21.0/node_modules/onnxruntime-node/dist/binding.js
|
|
1419
|
+
var require_binding = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1420
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1421
|
+
exports.initOrt = exports.binding = void 0;
|
|
1422
|
+
const onnxruntime_common_1 = require_cjs();
|
|
1423
|
+
exports.binding = __require(`../bin/napi-v3/${process.platform}/${process.arch}/onnxruntime_binding.node`);
|
|
1424
|
+
let ortInitialized = false;
|
|
1425
|
+
const initOrt = () => {
|
|
1426
|
+
if (!ortInitialized) {
|
|
1427
|
+
ortInitialized = true;
|
|
1428
|
+
let logLevel = 2;
|
|
1429
|
+
if (onnxruntime_common_1.env.logLevel) switch (onnxruntime_common_1.env.logLevel) {
|
|
1430
|
+
case "verbose":
|
|
1431
|
+
logLevel = 0;
|
|
1432
|
+
break;
|
|
1433
|
+
case "info":
|
|
1434
|
+
logLevel = 1;
|
|
1435
|
+
break;
|
|
1436
|
+
case "warning":
|
|
1437
|
+
logLevel = 2;
|
|
1438
|
+
break;
|
|
1439
|
+
case "error":
|
|
1440
|
+
logLevel = 3;
|
|
1441
|
+
break;
|
|
1442
|
+
case "fatal":
|
|
1443
|
+
logLevel = 4;
|
|
1444
|
+
break;
|
|
1445
|
+
default: throw new Error(`Unsupported log level: ${onnxruntime_common_1.env.logLevel}`);
|
|
1446
|
+
}
|
|
1447
|
+
exports.binding.initOrtOnce(logLevel, onnxruntime_common_1.Tensor);
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
exports.initOrt = initOrt;
|
|
1451
|
+
}));
|
|
1452
|
+
//#endregion
|
|
1453
|
+
//#region ../../node_modules/.pnpm/onnxruntime-node@1.21.0/node_modules/onnxruntime-node/dist/backend.js
|
|
1454
|
+
var require_backend = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1455
|
+
var __classPrivateFieldSet = exports && exports.__classPrivateFieldSet || function(receiver, state, value, kind, f) {
|
|
1456
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
1457
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
1458
|
+
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");
|
|
1459
|
+
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
1460
|
+
};
|
|
1461
|
+
var __classPrivateFieldGet = exports && exports.__classPrivateFieldGet || function(receiver, state, kind, f) {
|
|
1462
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
1463
|
+
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");
|
|
1464
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
1465
|
+
};
|
|
1466
|
+
var _OnnxruntimeSessionHandler_inferenceSession;
|
|
1467
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1468
|
+
exports.listSupportedBackends = exports.onnxruntimeBackend = void 0;
|
|
1469
|
+
const binding_1 = require_binding();
|
|
1470
|
+
var OnnxruntimeSessionHandler = class {
|
|
1471
|
+
constructor(pathOrBuffer, options) {
|
|
1472
|
+
_OnnxruntimeSessionHandler_inferenceSession.set(this, void 0);
|
|
1473
|
+
(0, binding_1.initOrt)();
|
|
1474
|
+
__classPrivateFieldSet(this, _OnnxruntimeSessionHandler_inferenceSession, new binding_1.binding.InferenceSession(), "f");
|
|
1475
|
+
if (typeof pathOrBuffer === "string") __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").loadModel(pathOrBuffer, options);
|
|
1476
|
+
else __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").loadModel(pathOrBuffer.buffer, pathOrBuffer.byteOffset, pathOrBuffer.byteLength, options);
|
|
1477
|
+
this.inputNames = __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").inputNames;
|
|
1478
|
+
this.outputNames = __classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").outputNames;
|
|
1479
|
+
}
|
|
1480
|
+
async dispose() {
|
|
1481
|
+
__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").dispose();
|
|
1482
|
+
}
|
|
1483
|
+
startProfiling() {}
|
|
1484
|
+
endProfiling() {
|
|
1485
|
+
__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").endProfiling();
|
|
1486
|
+
}
|
|
1487
|
+
async run(feeds, fetches, options) {
|
|
1488
|
+
return new Promise((resolve, reject) => {
|
|
1489
|
+
setImmediate(() => {
|
|
1490
|
+
try {
|
|
1491
|
+
resolve(__classPrivateFieldGet(this, _OnnxruntimeSessionHandler_inferenceSession, "f").run(feeds, fetches, options));
|
|
1492
|
+
} catch (e) {
|
|
1493
|
+
reject(e);
|
|
1494
|
+
}
|
|
1495
|
+
});
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
_OnnxruntimeSessionHandler_inferenceSession = /* @__PURE__ */ new WeakMap();
|
|
1500
|
+
var OnnxruntimeBackend = class {
|
|
1501
|
+
async init() {
|
|
1502
|
+
return Promise.resolve();
|
|
1503
|
+
}
|
|
1504
|
+
async createInferenceSessionHandler(pathOrBuffer, options) {
|
|
1505
|
+
return new Promise((resolve, reject) => {
|
|
1506
|
+
setImmediate(() => {
|
|
1507
|
+
try {
|
|
1508
|
+
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
|
|
1509
|
+
} catch (e) {
|
|
1510
|
+
reject(e);
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
exports.onnxruntimeBackend = new OnnxruntimeBackend();
|
|
1517
|
+
exports.listSupportedBackends = binding_1.binding.listSupportedBackends;
|
|
1518
|
+
}));
|
|
1519
|
+
//#endregion
|
|
1520
|
+
//#region ../../node_modules/.pnpm/onnxruntime-node@1.21.0/node_modules/onnxruntime-node/dist/version.js
|
|
1521
|
+
var require_version = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1522
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1523
|
+
exports.version = void 0;
|
|
1524
|
+
exports.version = "1.21.0";
|
|
1525
|
+
}));
|
|
1526
|
+
//#endregion
|
|
1527
|
+
//#region ../../node_modules/.pnpm/onnxruntime-node@1.21.0/node_modules/onnxruntime-node/dist/index.js
|
|
1528
|
+
var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1529
|
+
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1530
|
+
if (k2 === void 0) k2 = k;
|
|
1531
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1532
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
1533
|
+
enumerable: true,
|
|
1534
|
+
get: function() {
|
|
1535
|
+
return m[k];
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
Object.defineProperty(o, k2, desc);
|
|
1539
|
+
}) : (function(o, m, k, k2) {
|
|
1540
|
+
if (k2 === void 0) k2 = k;
|
|
1541
|
+
o[k2] = m[k];
|
|
1542
|
+
}));
|
|
1543
|
+
var __exportStar = exports && exports.__exportStar || function(m, exports$1) {
|
|
1544
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports$1, p)) __createBinding(exports$1, m, p);
|
|
1545
|
+
};
|
|
1546
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1547
|
+
exports.listSupportedBackends = void 0;
|
|
1548
|
+
__exportStar(require_cjs(), exports);
|
|
1549
|
+
var backend_1 = require_backend();
|
|
1550
|
+
Object.defineProperty(exports, "listSupportedBackends", {
|
|
1551
|
+
enumerable: true,
|
|
1552
|
+
get: function() {
|
|
1553
|
+
return backend_1.listSupportedBackends;
|
|
1554
|
+
}
|
|
1555
|
+
});
|
|
1556
|
+
const onnxruntime_common_1 = require_cjs();
|
|
1557
|
+
const version_1 = require_version();
|
|
1558
|
+
const backend_2 = require_backend();
|
|
1559
|
+
const backends = (0, backend_2.listSupportedBackends)();
|
|
1560
|
+
for (const backend of backends) (0, onnxruntime_common_1.registerBackend)(backend.name, backend_2.onnxruntimeBackend, 100);
|
|
1561
|
+
Object.defineProperty(onnxruntime_common_1.env.versions, "node", {
|
|
1562
|
+
value: version_1.version,
|
|
1563
|
+
enumerable: true
|
|
1564
|
+
});
|
|
1565
|
+
}));
|
|
1566
|
+
//#endregion
|
|
1567
|
+
//#region ../../node_modules/.pnpm/progress@2.0.3/node_modules/progress/lib/node-progress.js
|
|
1568
|
+
var require_node_progress = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1569
|
+
/*!
|
|
1570
|
+
* node-progress
|
|
1571
|
+
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
|
1572
|
+
* MIT Licensed
|
|
1573
|
+
*/
|
|
1574
|
+
/**
|
|
1575
|
+
* Expose `ProgressBar`.
|
|
1576
|
+
*/
|
|
1577
|
+
exports = module.exports = ProgressBar;
|
|
1578
|
+
/**
|
|
1579
|
+
* Initialize a `ProgressBar` with the given `fmt` string and `options` or
|
|
1580
|
+
* `total`.
|
|
1581
|
+
*
|
|
1582
|
+
* Options:
|
|
1583
|
+
*
|
|
1584
|
+
* - `curr` current completed index
|
|
1585
|
+
* - `total` total number of ticks to complete
|
|
1586
|
+
* - `width` the displayed width of the progress bar defaulting to total
|
|
1587
|
+
* - `stream` the output stream defaulting to stderr
|
|
1588
|
+
* - `head` head character defaulting to complete character
|
|
1589
|
+
* - `complete` completion character defaulting to "="
|
|
1590
|
+
* - `incomplete` incomplete character defaulting to "-"
|
|
1591
|
+
* - `renderThrottle` minimum time between updates in milliseconds defaulting to 16
|
|
1592
|
+
* - `callback` optional function to call when the progress bar completes
|
|
1593
|
+
* - `clear` will clear the progress bar upon termination
|
|
1594
|
+
*
|
|
1595
|
+
* Tokens:
|
|
1596
|
+
*
|
|
1597
|
+
* - `:bar` the progress bar itself
|
|
1598
|
+
* - `:current` current tick number
|
|
1599
|
+
* - `:total` total ticks
|
|
1600
|
+
* - `:elapsed` time elapsed in seconds
|
|
1601
|
+
* - `:percent` completion percentage
|
|
1602
|
+
* - `:eta` eta in seconds
|
|
1603
|
+
* - `:rate` rate of ticks per second
|
|
1604
|
+
*
|
|
1605
|
+
* @param {string} fmt
|
|
1606
|
+
* @param {object|number} options or total
|
|
1607
|
+
* @api public
|
|
1608
|
+
*/
|
|
1609
|
+
function ProgressBar(fmt, options) {
|
|
1610
|
+
this.stream = options.stream || process.stderr;
|
|
1611
|
+
if (typeof options == "number") {
|
|
1612
|
+
var total = options;
|
|
1613
|
+
options = {};
|
|
1614
|
+
options.total = total;
|
|
1615
|
+
} else {
|
|
1616
|
+
options = options || {};
|
|
1617
|
+
if ("string" != typeof fmt) throw new Error("format required");
|
|
1618
|
+
if ("number" != typeof options.total) throw new Error("total required");
|
|
1619
|
+
}
|
|
1620
|
+
this.fmt = fmt;
|
|
1621
|
+
this.curr = options.curr || 0;
|
|
1622
|
+
this.total = options.total;
|
|
1623
|
+
this.width = options.width || this.total;
|
|
1624
|
+
this.clear = options.clear;
|
|
1625
|
+
this.chars = {
|
|
1626
|
+
complete: options.complete || "=",
|
|
1627
|
+
incomplete: options.incomplete || "-",
|
|
1628
|
+
head: options.head || options.complete || "="
|
|
1629
|
+
};
|
|
1630
|
+
this.renderThrottle = options.renderThrottle !== 0 ? options.renderThrottle || 16 : 0;
|
|
1631
|
+
this.lastRender = -Infinity;
|
|
1632
|
+
this.callback = options.callback || function() {};
|
|
1633
|
+
this.tokens = {};
|
|
1634
|
+
this.lastDraw = "";
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* "tick" the progress bar with optional `len` and optional `tokens`.
|
|
1638
|
+
*
|
|
1639
|
+
* @param {number|object} len or tokens
|
|
1640
|
+
* @param {object} tokens
|
|
1641
|
+
* @api public
|
|
1642
|
+
*/
|
|
1643
|
+
ProgressBar.prototype.tick = function(len, tokens) {
|
|
1644
|
+
if (len !== 0) len = len || 1;
|
|
1645
|
+
if ("object" == typeof len) tokens = len, len = 1;
|
|
1646
|
+
if (tokens) this.tokens = tokens;
|
|
1647
|
+
if (0 == this.curr) this.start = /* @__PURE__ */ new Date();
|
|
1648
|
+
this.curr += len;
|
|
1649
|
+
this.render();
|
|
1650
|
+
if (this.curr >= this.total) {
|
|
1651
|
+
this.render(void 0, true);
|
|
1652
|
+
this.complete = true;
|
|
1653
|
+
this.terminate();
|
|
1654
|
+
this.callback(this);
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
/**
|
|
1659
|
+
* Method to render the progress bar with optional `tokens` to place in the
|
|
1660
|
+
* progress bar's `fmt` field.
|
|
1661
|
+
*
|
|
1662
|
+
* @param {object} tokens
|
|
1663
|
+
* @api public
|
|
1664
|
+
*/
|
|
1665
|
+
ProgressBar.prototype.render = function(tokens, force) {
|
|
1666
|
+
force = force !== void 0 ? force : false;
|
|
1667
|
+
if (tokens) this.tokens = tokens;
|
|
1668
|
+
if (!this.stream.isTTY) return;
|
|
1669
|
+
var now = Date.now();
|
|
1670
|
+
var delta = now - this.lastRender;
|
|
1671
|
+
if (!force && delta < this.renderThrottle) return;
|
|
1672
|
+
else this.lastRender = now;
|
|
1673
|
+
var ratio = this.curr / this.total;
|
|
1674
|
+
ratio = Math.min(Math.max(ratio, 0), 1);
|
|
1675
|
+
var percent = Math.floor(ratio * 100);
|
|
1676
|
+
var incomplete, complete, completeLength;
|
|
1677
|
+
var elapsed = /* @__PURE__ */ new Date() - this.start;
|
|
1678
|
+
var eta = percent == 100 ? 0 : elapsed * (this.total / this.curr - 1);
|
|
1679
|
+
var rate = this.curr / (elapsed / 1e3);
|
|
1680
|
+
var str = this.fmt.replace(":current", this.curr).replace(":total", this.total).replace(":elapsed", isNaN(elapsed) ? "0.0" : (elapsed / 1e3).toFixed(1)).replace(":eta", isNaN(eta) || !isFinite(eta) ? "0.0" : (eta / 1e3).toFixed(1)).replace(":percent", percent.toFixed(0) + "%").replace(":rate", Math.round(rate));
|
|
1681
|
+
var availableSpace = Math.max(0, this.stream.columns - str.replace(":bar", "").length);
|
|
1682
|
+
if (availableSpace && process.platform === "win32") availableSpace = availableSpace - 1;
|
|
1683
|
+
var width = Math.min(this.width, availableSpace);
|
|
1684
|
+
completeLength = Math.round(width * ratio);
|
|
1685
|
+
complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
|
|
1686
|
+
incomplete = Array(Math.max(0, width - completeLength + 1)).join(this.chars.incomplete);
|
|
1687
|
+
if (completeLength > 0) complete = complete.slice(0, -1) + this.chars.head;
|
|
1688
|
+
str = str.replace(":bar", complete + incomplete);
|
|
1689
|
+
if (this.tokens) for (var key in this.tokens) str = str.replace(":" + key, this.tokens[key]);
|
|
1690
|
+
if (this.lastDraw !== str) {
|
|
1691
|
+
this.stream.cursorTo(0);
|
|
1692
|
+
this.stream.write(str);
|
|
1693
|
+
this.stream.clearLine(1);
|
|
1694
|
+
this.lastDraw = str;
|
|
1695
|
+
}
|
|
1696
|
+
};
|
|
1697
|
+
/**
|
|
1698
|
+
* "update" the progress bar to represent an exact percentage.
|
|
1699
|
+
* The ratio (between 0 and 1) specified will be multiplied by `total` and
|
|
1700
|
+
* floored, representing the closest available "tick." For example, if a
|
|
1701
|
+
* progress bar has a length of 3 and `update(0.5)` is called, the progress
|
|
1702
|
+
* will be set to 1.
|
|
1703
|
+
*
|
|
1704
|
+
* A ratio of 0.5 will attempt to set the progress to halfway.
|
|
1705
|
+
*
|
|
1706
|
+
* @param {number} ratio The ratio (between 0 and 1 inclusive) to set the
|
|
1707
|
+
* overall completion to.
|
|
1708
|
+
* @api public
|
|
1709
|
+
*/
|
|
1710
|
+
ProgressBar.prototype.update = function(ratio, tokens) {
|
|
1711
|
+
var delta = Math.floor(ratio * this.total) - this.curr;
|
|
1712
|
+
this.tick(delta, tokens);
|
|
1713
|
+
};
|
|
1714
|
+
/**
|
|
1715
|
+
* "interrupt" the progress bar and write a message above it.
|
|
1716
|
+
* @param {string} message The message to write.
|
|
1717
|
+
* @api public
|
|
1718
|
+
*/
|
|
1719
|
+
ProgressBar.prototype.interrupt = function(message) {
|
|
1720
|
+
this.stream.clearLine();
|
|
1721
|
+
this.stream.cursorTo(0);
|
|
1722
|
+
this.stream.write(message);
|
|
1723
|
+
this.stream.write("\n");
|
|
1724
|
+
this.stream.write(this.lastDraw);
|
|
1725
|
+
};
|
|
1726
|
+
/**
|
|
1727
|
+
* Terminates a progress bar.
|
|
1728
|
+
*
|
|
1729
|
+
* @api public
|
|
1730
|
+
*/
|
|
1731
|
+
ProgressBar.prototype.terminate = function() {
|
|
1732
|
+
if (this.clear) {
|
|
1733
|
+
if (this.stream.clearLine) {
|
|
1734
|
+
this.stream.clearLine();
|
|
1735
|
+
this.stream.cursorTo(0);
|
|
1736
|
+
}
|
|
1737
|
+
} else this.stream.write("\n");
|
|
1738
|
+
};
|
|
1739
|
+
}));
|
|
1740
|
+
//#endregion
|
|
1741
|
+
//#region ../../node_modules/.pnpm/progress@2.0.3/node_modules/progress/index.js
|
|
1742
|
+
var require_progress = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1743
|
+
module.exports = require_node_progress();
|
|
1744
|
+
}));
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region ../../node_modules/.pnpm/@huggingface+blake3-jit@0.0.2/node_modules/@huggingface/blake3-jit/dist/esm/compress.js
|
|
1747
|
+
/**
|
|
1748
|
+
* BLAKE3 Compression Function - Highly Optimized
|
|
1749
|
+
*
|
|
1750
|
+
* Optimization techniques applied (from Fleek Network case study):
|
|
1751
|
+
* 1. Use 16 SMI variables for state instead of TypedArray
|
|
1752
|
+
* 2. Use 16 SMI variables for message words
|
|
1753
|
+
* 3. Fully inlined G function (no function call overhead)
|
|
1754
|
+
* 4. Use `| 0` for integer coercion (forces V8 to use 32-bit ALU)
|
|
1755
|
+
* 5. Hardcoded permutation swaps using only 2 temporary variables
|
|
1756
|
+
* 6. Offset-based access pattern (avoid creating new views)
|
|
1757
|
+
*
|
|
1758
|
+
* The compression function takes:
|
|
1759
|
+
* - cv: 8-word chaining value
|
|
1760
|
+
* - block: 16-word message block (64 bytes)
|
|
1761
|
+
* - counter: 64-bit block counter
|
|
1762
|
+
* - blockLen: number of input bytes in this block
|
|
1763
|
+
* - flags: domain separation flags
|
|
1764
|
+
*
|
|
1765
|
+
* And outputs 8 or 16 words depending on whether this is a root node.
|
|
1766
|
+
*/
|
|
1767
|
+
/**
|
|
1768
|
+
* Compress a single block.
|
|
1769
|
+
*
|
|
1770
|
+
* This is the hot path - every optimization matters here.
|
|
1771
|
+
*
|
|
1772
|
+
* @param cv - Chaining value array
|
|
1773
|
+
* @param cvOff - Offset into cv
|
|
1774
|
+
* @param block - Message block words
|
|
1775
|
+
* @param blockOff - Offset into block
|
|
1776
|
+
* @param out - Output array (8 or 16 words)
|
|
1777
|
+
* @param outOff - Offset into out
|
|
1778
|
+
* @param full - If true, output all 16 words (for XOF); if false, output 8 words
|
|
1779
|
+
* @param counter - 64-bit block counter
|
|
1780
|
+
* @param blockLen - Number of bytes in this block (0-64)
|
|
1781
|
+
* @param flags - Domain separation flags
|
|
1782
|
+
*/
|
|
1783
|
+
function compress(cv, cvOff, block, blockOff, out, outOff, full, counter, blockLen, flags) {
|
|
1784
|
+
let m0 = block[blockOff] | 0;
|
|
1785
|
+
let m1 = block[blockOff + 1] | 0;
|
|
1786
|
+
let m2 = block[blockOff + 2] | 0;
|
|
1787
|
+
let m3 = block[blockOff + 3] | 0;
|
|
1788
|
+
let m4 = block[blockOff + 4] | 0;
|
|
1789
|
+
let m5 = block[blockOff + 5] | 0;
|
|
1790
|
+
let m6 = block[blockOff + 6] | 0;
|
|
1791
|
+
let m7 = block[blockOff + 7] | 0;
|
|
1792
|
+
let m8 = block[blockOff + 8] | 0;
|
|
1793
|
+
let m9 = block[blockOff + 9] | 0;
|
|
1794
|
+
let m10 = block[blockOff + 10] | 0;
|
|
1795
|
+
let m11 = block[blockOff + 11] | 0;
|
|
1796
|
+
let m12 = block[blockOff + 12] | 0;
|
|
1797
|
+
let m13 = block[blockOff + 13] | 0;
|
|
1798
|
+
let m14 = block[blockOff + 14] | 0;
|
|
1799
|
+
let m15 = block[blockOff + 15] | 0;
|
|
1800
|
+
let s0 = cv[cvOff] | 0;
|
|
1801
|
+
let s1 = cv[cvOff + 1] | 0;
|
|
1802
|
+
let s2 = cv[cvOff + 2] | 0;
|
|
1803
|
+
let s3 = cv[cvOff + 3] | 0;
|
|
1804
|
+
let s4 = cv[cvOff + 4] | 0;
|
|
1805
|
+
let s5 = cv[cvOff + 5] | 0;
|
|
1806
|
+
let s6 = cv[cvOff + 6] | 0;
|
|
1807
|
+
let s7 = cv[cvOff + 7] | 0;
|
|
1808
|
+
let s8 = 1779033703;
|
|
1809
|
+
let s9 = 3144134277;
|
|
1810
|
+
let s10 = 1013904242;
|
|
1811
|
+
let s11 = 2773480762;
|
|
1812
|
+
let s12 = counter | 0;
|
|
1813
|
+
let s13 = counter / 4294967296 | 0;
|
|
1814
|
+
let s14 = blockLen | 0;
|
|
1815
|
+
let s15 = flags | 0;
|
|
1816
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
1817
|
+
s12 ^= s0;
|
|
1818
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
1819
|
+
s8 = s8 + s12 | 0;
|
|
1820
|
+
s4 ^= s8;
|
|
1821
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
1822
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
1823
|
+
s12 ^= s0;
|
|
1824
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
1825
|
+
s8 = s8 + s12 | 0;
|
|
1826
|
+
s4 ^= s8;
|
|
1827
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
1828
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
1829
|
+
s13 ^= s1;
|
|
1830
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
1831
|
+
s9 = s9 + s13 | 0;
|
|
1832
|
+
s5 ^= s9;
|
|
1833
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
1834
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
1835
|
+
s13 ^= s1;
|
|
1836
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
1837
|
+
s9 = s9 + s13 | 0;
|
|
1838
|
+
s5 ^= s9;
|
|
1839
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
1840
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
1841
|
+
s14 ^= s2;
|
|
1842
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
1843
|
+
s10 = s10 + s14 | 0;
|
|
1844
|
+
s6 ^= s10;
|
|
1845
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
1846
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
1847
|
+
s14 ^= s2;
|
|
1848
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
1849
|
+
s10 = s10 + s14 | 0;
|
|
1850
|
+
s6 ^= s10;
|
|
1851
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
1852
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
1853
|
+
s15 ^= s3;
|
|
1854
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
1855
|
+
s11 = s11 + s15 | 0;
|
|
1856
|
+
s7 ^= s11;
|
|
1857
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
1858
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
1859
|
+
s15 ^= s3;
|
|
1860
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
1861
|
+
s11 = s11 + s15 | 0;
|
|
1862
|
+
s7 ^= s11;
|
|
1863
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
1864
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
1865
|
+
s15 ^= s0;
|
|
1866
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
1867
|
+
s10 = s10 + s15 | 0;
|
|
1868
|
+
s5 ^= s10;
|
|
1869
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
1870
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
1871
|
+
s15 ^= s0;
|
|
1872
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
1873
|
+
s10 = s10 + s15 | 0;
|
|
1874
|
+
s5 ^= s10;
|
|
1875
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
1876
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
1877
|
+
s12 ^= s1;
|
|
1878
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
1879
|
+
s11 = s11 + s12 | 0;
|
|
1880
|
+
s6 ^= s11;
|
|
1881
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
1882
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
1883
|
+
s12 ^= s1;
|
|
1884
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
1885
|
+
s11 = s11 + s12 | 0;
|
|
1886
|
+
s6 ^= s11;
|
|
1887
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
1888
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
1889
|
+
s13 ^= s2;
|
|
1890
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
1891
|
+
s8 = s8 + s13 | 0;
|
|
1892
|
+
s7 ^= s8;
|
|
1893
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
1894
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
1895
|
+
s13 ^= s2;
|
|
1896
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
1897
|
+
s8 = s8 + s13 | 0;
|
|
1898
|
+
s7 ^= s8;
|
|
1899
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
1900
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
1901
|
+
s14 ^= s3;
|
|
1902
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
1903
|
+
s9 = s9 + s14 | 0;
|
|
1904
|
+
s4 ^= s9;
|
|
1905
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
1906
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
1907
|
+
s14 ^= s3;
|
|
1908
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
1909
|
+
s9 = s9 + s14 | 0;
|
|
1910
|
+
s4 ^= s9;
|
|
1911
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
1912
|
+
{
|
|
1913
|
+
const t0 = m0, t1 = m1;
|
|
1914
|
+
m0 = m2;
|
|
1915
|
+
m2 = m3;
|
|
1916
|
+
m3 = m10;
|
|
1917
|
+
m10 = m12;
|
|
1918
|
+
m12 = m9;
|
|
1919
|
+
m9 = m11;
|
|
1920
|
+
m11 = m5;
|
|
1921
|
+
m5 = t0;
|
|
1922
|
+
m1 = m6;
|
|
1923
|
+
m6 = m4;
|
|
1924
|
+
m4 = m7;
|
|
1925
|
+
m7 = m13;
|
|
1926
|
+
m13 = m14;
|
|
1927
|
+
m14 = m15;
|
|
1928
|
+
m15 = m8;
|
|
1929
|
+
m8 = t1;
|
|
1930
|
+
}
|
|
1931
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
1932
|
+
s12 ^= s0;
|
|
1933
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
1934
|
+
s8 = s8 + s12 | 0;
|
|
1935
|
+
s4 ^= s8;
|
|
1936
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
1937
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
1938
|
+
s12 ^= s0;
|
|
1939
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
1940
|
+
s8 = s8 + s12 | 0;
|
|
1941
|
+
s4 ^= s8;
|
|
1942
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
1943
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
1944
|
+
s13 ^= s1;
|
|
1945
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
1946
|
+
s9 = s9 + s13 | 0;
|
|
1947
|
+
s5 ^= s9;
|
|
1948
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
1949
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
1950
|
+
s13 ^= s1;
|
|
1951
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
1952
|
+
s9 = s9 + s13 | 0;
|
|
1953
|
+
s5 ^= s9;
|
|
1954
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
1955
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
1956
|
+
s14 ^= s2;
|
|
1957
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
1958
|
+
s10 = s10 + s14 | 0;
|
|
1959
|
+
s6 ^= s10;
|
|
1960
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
1961
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
1962
|
+
s14 ^= s2;
|
|
1963
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
1964
|
+
s10 = s10 + s14 | 0;
|
|
1965
|
+
s6 ^= s10;
|
|
1966
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
1967
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
1968
|
+
s15 ^= s3;
|
|
1969
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
1970
|
+
s11 = s11 + s15 | 0;
|
|
1971
|
+
s7 ^= s11;
|
|
1972
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
1973
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
1974
|
+
s15 ^= s3;
|
|
1975
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
1976
|
+
s11 = s11 + s15 | 0;
|
|
1977
|
+
s7 ^= s11;
|
|
1978
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
1979
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
1980
|
+
s15 ^= s0;
|
|
1981
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
1982
|
+
s10 = s10 + s15 | 0;
|
|
1983
|
+
s5 ^= s10;
|
|
1984
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
1985
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
1986
|
+
s15 ^= s0;
|
|
1987
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
1988
|
+
s10 = s10 + s15 | 0;
|
|
1989
|
+
s5 ^= s10;
|
|
1990
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
1991
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
1992
|
+
s12 ^= s1;
|
|
1993
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
1994
|
+
s11 = s11 + s12 | 0;
|
|
1995
|
+
s6 ^= s11;
|
|
1996
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
1997
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
1998
|
+
s12 ^= s1;
|
|
1999
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2000
|
+
s11 = s11 + s12 | 0;
|
|
2001
|
+
s6 ^= s11;
|
|
2002
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2003
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
2004
|
+
s13 ^= s2;
|
|
2005
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2006
|
+
s8 = s8 + s13 | 0;
|
|
2007
|
+
s7 ^= s8;
|
|
2008
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2009
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
2010
|
+
s13 ^= s2;
|
|
2011
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2012
|
+
s8 = s8 + s13 | 0;
|
|
2013
|
+
s7 ^= s8;
|
|
2014
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2015
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
2016
|
+
s14 ^= s3;
|
|
2017
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2018
|
+
s9 = s9 + s14 | 0;
|
|
2019
|
+
s4 ^= s9;
|
|
2020
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2021
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
2022
|
+
s14 ^= s3;
|
|
2023
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2024
|
+
s9 = s9 + s14 | 0;
|
|
2025
|
+
s4 ^= s9;
|
|
2026
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2027
|
+
{
|
|
2028
|
+
const t0 = m0, t1 = m1;
|
|
2029
|
+
m0 = m2;
|
|
2030
|
+
m2 = m3;
|
|
2031
|
+
m3 = m10;
|
|
2032
|
+
m10 = m12;
|
|
2033
|
+
m12 = m9;
|
|
2034
|
+
m9 = m11;
|
|
2035
|
+
m11 = m5;
|
|
2036
|
+
m5 = t0;
|
|
2037
|
+
m1 = m6;
|
|
2038
|
+
m6 = m4;
|
|
2039
|
+
m4 = m7;
|
|
2040
|
+
m7 = m13;
|
|
2041
|
+
m13 = m14;
|
|
2042
|
+
m14 = m15;
|
|
2043
|
+
m15 = m8;
|
|
2044
|
+
m8 = t1;
|
|
2045
|
+
}
|
|
2046
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
2047
|
+
s12 ^= s0;
|
|
2048
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2049
|
+
s8 = s8 + s12 | 0;
|
|
2050
|
+
s4 ^= s8;
|
|
2051
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2052
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
2053
|
+
s12 ^= s0;
|
|
2054
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2055
|
+
s8 = s8 + s12 | 0;
|
|
2056
|
+
s4 ^= s8;
|
|
2057
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2058
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
2059
|
+
s13 ^= s1;
|
|
2060
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2061
|
+
s9 = s9 + s13 | 0;
|
|
2062
|
+
s5 ^= s9;
|
|
2063
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2064
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
2065
|
+
s13 ^= s1;
|
|
2066
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2067
|
+
s9 = s9 + s13 | 0;
|
|
2068
|
+
s5 ^= s9;
|
|
2069
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2070
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
2071
|
+
s14 ^= s2;
|
|
2072
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2073
|
+
s10 = s10 + s14 | 0;
|
|
2074
|
+
s6 ^= s10;
|
|
2075
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2076
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
2077
|
+
s14 ^= s2;
|
|
2078
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2079
|
+
s10 = s10 + s14 | 0;
|
|
2080
|
+
s6 ^= s10;
|
|
2081
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2082
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
2083
|
+
s15 ^= s3;
|
|
2084
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2085
|
+
s11 = s11 + s15 | 0;
|
|
2086
|
+
s7 ^= s11;
|
|
2087
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2088
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
2089
|
+
s15 ^= s3;
|
|
2090
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2091
|
+
s11 = s11 + s15 | 0;
|
|
2092
|
+
s7 ^= s11;
|
|
2093
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2094
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
2095
|
+
s15 ^= s0;
|
|
2096
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2097
|
+
s10 = s10 + s15 | 0;
|
|
2098
|
+
s5 ^= s10;
|
|
2099
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2100
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
2101
|
+
s15 ^= s0;
|
|
2102
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2103
|
+
s10 = s10 + s15 | 0;
|
|
2104
|
+
s5 ^= s10;
|
|
2105
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2106
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
2107
|
+
s12 ^= s1;
|
|
2108
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2109
|
+
s11 = s11 + s12 | 0;
|
|
2110
|
+
s6 ^= s11;
|
|
2111
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2112
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
2113
|
+
s12 ^= s1;
|
|
2114
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2115
|
+
s11 = s11 + s12 | 0;
|
|
2116
|
+
s6 ^= s11;
|
|
2117
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2118
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
2119
|
+
s13 ^= s2;
|
|
2120
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2121
|
+
s8 = s8 + s13 | 0;
|
|
2122
|
+
s7 ^= s8;
|
|
2123
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2124
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
2125
|
+
s13 ^= s2;
|
|
2126
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2127
|
+
s8 = s8 + s13 | 0;
|
|
2128
|
+
s7 ^= s8;
|
|
2129
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2130
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
2131
|
+
s14 ^= s3;
|
|
2132
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2133
|
+
s9 = s9 + s14 | 0;
|
|
2134
|
+
s4 ^= s9;
|
|
2135
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2136
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
2137
|
+
s14 ^= s3;
|
|
2138
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2139
|
+
s9 = s9 + s14 | 0;
|
|
2140
|
+
s4 ^= s9;
|
|
2141
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2142
|
+
{
|
|
2143
|
+
const t0 = m0, t1 = m1;
|
|
2144
|
+
m0 = m2;
|
|
2145
|
+
m2 = m3;
|
|
2146
|
+
m3 = m10;
|
|
2147
|
+
m10 = m12;
|
|
2148
|
+
m12 = m9;
|
|
2149
|
+
m9 = m11;
|
|
2150
|
+
m11 = m5;
|
|
2151
|
+
m5 = t0;
|
|
2152
|
+
m1 = m6;
|
|
2153
|
+
m6 = m4;
|
|
2154
|
+
m4 = m7;
|
|
2155
|
+
m7 = m13;
|
|
2156
|
+
m13 = m14;
|
|
2157
|
+
m14 = m15;
|
|
2158
|
+
m15 = m8;
|
|
2159
|
+
m8 = t1;
|
|
2160
|
+
}
|
|
2161
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
2162
|
+
s12 ^= s0;
|
|
2163
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2164
|
+
s8 = s8 + s12 | 0;
|
|
2165
|
+
s4 ^= s8;
|
|
2166
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2167
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
2168
|
+
s12 ^= s0;
|
|
2169
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2170
|
+
s8 = s8 + s12 | 0;
|
|
2171
|
+
s4 ^= s8;
|
|
2172
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2173
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
2174
|
+
s13 ^= s1;
|
|
2175
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2176
|
+
s9 = s9 + s13 | 0;
|
|
2177
|
+
s5 ^= s9;
|
|
2178
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2179
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
2180
|
+
s13 ^= s1;
|
|
2181
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2182
|
+
s9 = s9 + s13 | 0;
|
|
2183
|
+
s5 ^= s9;
|
|
2184
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2185
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
2186
|
+
s14 ^= s2;
|
|
2187
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2188
|
+
s10 = s10 + s14 | 0;
|
|
2189
|
+
s6 ^= s10;
|
|
2190
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2191
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
2192
|
+
s14 ^= s2;
|
|
2193
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2194
|
+
s10 = s10 + s14 | 0;
|
|
2195
|
+
s6 ^= s10;
|
|
2196
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2197
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
2198
|
+
s15 ^= s3;
|
|
2199
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2200
|
+
s11 = s11 + s15 | 0;
|
|
2201
|
+
s7 ^= s11;
|
|
2202
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2203
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
2204
|
+
s15 ^= s3;
|
|
2205
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2206
|
+
s11 = s11 + s15 | 0;
|
|
2207
|
+
s7 ^= s11;
|
|
2208
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2209
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
2210
|
+
s15 ^= s0;
|
|
2211
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2212
|
+
s10 = s10 + s15 | 0;
|
|
2213
|
+
s5 ^= s10;
|
|
2214
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2215
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
2216
|
+
s15 ^= s0;
|
|
2217
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2218
|
+
s10 = s10 + s15 | 0;
|
|
2219
|
+
s5 ^= s10;
|
|
2220
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2221
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
2222
|
+
s12 ^= s1;
|
|
2223
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2224
|
+
s11 = s11 + s12 | 0;
|
|
2225
|
+
s6 ^= s11;
|
|
2226
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2227
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
2228
|
+
s12 ^= s1;
|
|
2229
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2230
|
+
s11 = s11 + s12 | 0;
|
|
2231
|
+
s6 ^= s11;
|
|
2232
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2233
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
2234
|
+
s13 ^= s2;
|
|
2235
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2236
|
+
s8 = s8 + s13 | 0;
|
|
2237
|
+
s7 ^= s8;
|
|
2238
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2239
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
2240
|
+
s13 ^= s2;
|
|
2241
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2242
|
+
s8 = s8 + s13 | 0;
|
|
2243
|
+
s7 ^= s8;
|
|
2244
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2245
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
2246
|
+
s14 ^= s3;
|
|
2247
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2248
|
+
s9 = s9 + s14 | 0;
|
|
2249
|
+
s4 ^= s9;
|
|
2250
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2251
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
2252
|
+
s14 ^= s3;
|
|
2253
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2254
|
+
s9 = s9 + s14 | 0;
|
|
2255
|
+
s4 ^= s9;
|
|
2256
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2257
|
+
{
|
|
2258
|
+
const t0 = m0, t1 = m1;
|
|
2259
|
+
m0 = m2;
|
|
2260
|
+
m2 = m3;
|
|
2261
|
+
m3 = m10;
|
|
2262
|
+
m10 = m12;
|
|
2263
|
+
m12 = m9;
|
|
2264
|
+
m9 = m11;
|
|
2265
|
+
m11 = m5;
|
|
2266
|
+
m5 = t0;
|
|
2267
|
+
m1 = m6;
|
|
2268
|
+
m6 = m4;
|
|
2269
|
+
m4 = m7;
|
|
2270
|
+
m7 = m13;
|
|
2271
|
+
m13 = m14;
|
|
2272
|
+
m14 = m15;
|
|
2273
|
+
m15 = m8;
|
|
2274
|
+
m8 = t1;
|
|
2275
|
+
}
|
|
2276
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
2277
|
+
s12 ^= s0;
|
|
2278
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2279
|
+
s8 = s8 + s12 | 0;
|
|
2280
|
+
s4 ^= s8;
|
|
2281
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2282
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
2283
|
+
s12 ^= s0;
|
|
2284
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2285
|
+
s8 = s8 + s12 | 0;
|
|
2286
|
+
s4 ^= s8;
|
|
2287
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2288
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
2289
|
+
s13 ^= s1;
|
|
2290
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2291
|
+
s9 = s9 + s13 | 0;
|
|
2292
|
+
s5 ^= s9;
|
|
2293
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2294
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
2295
|
+
s13 ^= s1;
|
|
2296
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2297
|
+
s9 = s9 + s13 | 0;
|
|
2298
|
+
s5 ^= s9;
|
|
2299
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2300
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
2301
|
+
s14 ^= s2;
|
|
2302
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2303
|
+
s10 = s10 + s14 | 0;
|
|
2304
|
+
s6 ^= s10;
|
|
2305
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2306
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
2307
|
+
s14 ^= s2;
|
|
2308
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2309
|
+
s10 = s10 + s14 | 0;
|
|
2310
|
+
s6 ^= s10;
|
|
2311
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2312
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
2313
|
+
s15 ^= s3;
|
|
2314
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2315
|
+
s11 = s11 + s15 | 0;
|
|
2316
|
+
s7 ^= s11;
|
|
2317
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2318
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
2319
|
+
s15 ^= s3;
|
|
2320
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2321
|
+
s11 = s11 + s15 | 0;
|
|
2322
|
+
s7 ^= s11;
|
|
2323
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2324
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
2325
|
+
s15 ^= s0;
|
|
2326
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2327
|
+
s10 = s10 + s15 | 0;
|
|
2328
|
+
s5 ^= s10;
|
|
2329
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2330
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
2331
|
+
s15 ^= s0;
|
|
2332
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2333
|
+
s10 = s10 + s15 | 0;
|
|
2334
|
+
s5 ^= s10;
|
|
2335
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2336
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
2337
|
+
s12 ^= s1;
|
|
2338
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2339
|
+
s11 = s11 + s12 | 0;
|
|
2340
|
+
s6 ^= s11;
|
|
2341
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2342
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
2343
|
+
s12 ^= s1;
|
|
2344
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2345
|
+
s11 = s11 + s12 | 0;
|
|
2346
|
+
s6 ^= s11;
|
|
2347
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2348
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
2349
|
+
s13 ^= s2;
|
|
2350
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2351
|
+
s8 = s8 + s13 | 0;
|
|
2352
|
+
s7 ^= s8;
|
|
2353
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2354
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
2355
|
+
s13 ^= s2;
|
|
2356
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2357
|
+
s8 = s8 + s13 | 0;
|
|
2358
|
+
s7 ^= s8;
|
|
2359
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2360
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
2361
|
+
s14 ^= s3;
|
|
2362
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2363
|
+
s9 = s9 + s14 | 0;
|
|
2364
|
+
s4 ^= s9;
|
|
2365
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2366
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
2367
|
+
s14 ^= s3;
|
|
2368
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2369
|
+
s9 = s9 + s14 | 0;
|
|
2370
|
+
s4 ^= s9;
|
|
2371
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2372
|
+
{
|
|
2373
|
+
const t0 = m0, t1 = m1;
|
|
2374
|
+
m0 = m2;
|
|
2375
|
+
m2 = m3;
|
|
2376
|
+
m3 = m10;
|
|
2377
|
+
m10 = m12;
|
|
2378
|
+
m12 = m9;
|
|
2379
|
+
m9 = m11;
|
|
2380
|
+
m11 = m5;
|
|
2381
|
+
m5 = t0;
|
|
2382
|
+
m1 = m6;
|
|
2383
|
+
m6 = m4;
|
|
2384
|
+
m4 = m7;
|
|
2385
|
+
m7 = m13;
|
|
2386
|
+
m13 = m14;
|
|
2387
|
+
m14 = m15;
|
|
2388
|
+
m15 = m8;
|
|
2389
|
+
m8 = t1;
|
|
2390
|
+
}
|
|
2391
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
2392
|
+
s12 ^= s0;
|
|
2393
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2394
|
+
s8 = s8 + s12 | 0;
|
|
2395
|
+
s4 ^= s8;
|
|
2396
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2397
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
2398
|
+
s12 ^= s0;
|
|
2399
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2400
|
+
s8 = s8 + s12 | 0;
|
|
2401
|
+
s4 ^= s8;
|
|
2402
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2403
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
2404
|
+
s13 ^= s1;
|
|
2405
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2406
|
+
s9 = s9 + s13 | 0;
|
|
2407
|
+
s5 ^= s9;
|
|
2408
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2409
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
2410
|
+
s13 ^= s1;
|
|
2411
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2412
|
+
s9 = s9 + s13 | 0;
|
|
2413
|
+
s5 ^= s9;
|
|
2414
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2415
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
2416
|
+
s14 ^= s2;
|
|
2417
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2418
|
+
s10 = s10 + s14 | 0;
|
|
2419
|
+
s6 ^= s10;
|
|
2420
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2421
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
2422
|
+
s14 ^= s2;
|
|
2423
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2424
|
+
s10 = s10 + s14 | 0;
|
|
2425
|
+
s6 ^= s10;
|
|
2426
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2427
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
2428
|
+
s15 ^= s3;
|
|
2429
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2430
|
+
s11 = s11 + s15 | 0;
|
|
2431
|
+
s7 ^= s11;
|
|
2432
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2433
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
2434
|
+
s15 ^= s3;
|
|
2435
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2436
|
+
s11 = s11 + s15 | 0;
|
|
2437
|
+
s7 ^= s11;
|
|
2438
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2439
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
2440
|
+
s15 ^= s0;
|
|
2441
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2442
|
+
s10 = s10 + s15 | 0;
|
|
2443
|
+
s5 ^= s10;
|
|
2444
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2445
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
2446
|
+
s15 ^= s0;
|
|
2447
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2448
|
+
s10 = s10 + s15 | 0;
|
|
2449
|
+
s5 ^= s10;
|
|
2450
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2451
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
2452
|
+
s12 ^= s1;
|
|
2453
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2454
|
+
s11 = s11 + s12 | 0;
|
|
2455
|
+
s6 ^= s11;
|
|
2456
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2457
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
2458
|
+
s12 ^= s1;
|
|
2459
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2460
|
+
s11 = s11 + s12 | 0;
|
|
2461
|
+
s6 ^= s11;
|
|
2462
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2463
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
2464
|
+
s13 ^= s2;
|
|
2465
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2466
|
+
s8 = s8 + s13 | 0;
|
|
2467
|
+
s7 ^= s8;
|
|
2468
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2469
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
2470
|
+
s13 ^= s2;
|
|
2471
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2472
|
+
s8 = s8 + s13 | 0;
|
|
2473
|
+
s7 ^= s8;
|
|
2474
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2475
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
2476
|
+
s14 ^= s3;
|
|
2477
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2478
|
+
s9 = s9 + s14 | 0;
|
|
2479
|
+
s4 ^= s9;
|
|
2480
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2481
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
2482
|
+
s14 ^= s3;
|
|
2483
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2484
|
+
s9 = s9 + s14 | 0;
|
|
2485
|
+
s4 ^= s9;
|
|
2486
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2487
|
+
{
|
|
2488
|
+
const t0 = m0, t1 = m1;
|
|
2489
|
+
m0 = m2;
|
|
2490
|
+
m2 = m3;
|
|
2491
|
+
m3 = m10;
|
|
2492
|
+
m10 = m12;
|
|
2493
|
+
m12 = m9;
|
|
2494
|
+
m9 = m11;
|
|
2495
|
+
m11 = m5;
|
|
2496
|
+
m5 = t0;
|
|
2497
|
+
m1 = m6;
|
|
2498
|
+
m6 = m4;
|
|
2499
|
+
m4 = m7;
|
|
2500
|
+
m7 = m13;
|
|
2501
|
+
m13 = m14;
|
|
2502
|
+
m14 = m15;
|
|
2503
|
+
m15 = m8;
|
|
2504
|
+
m8 = t1;
|
|
2505
|
+
}
|
|
2506
|
+
s0 = (s0 + s4 | 0) + m0 | 0;
|
|
2507
|
+
s12 ^= s0;
|
|
2508
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2509
|
+
s8 = s8 + s12 | 0;
|
|
2510
|
+
s4 ^= s8;
|
|
2511
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2512
|
+
s0 = (s0 + s4 | 0) + m1 | 0;
|
|
2513
|
+
s12 ^= s0;
|
|
2514
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2515
|
+
s8 = s8 + s12 | 0;
|
|
2516
|
+
s4 ^= s8;
|
|
2517
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2518
|
+
s1 = (s1 + s5 | 0) + m2 | 0;
|
|
2519
|
+
s13 ^= s1;
|
|
2520
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2521
|
+
s9 = s9 + s13 | 0;
|
|
2522
|
+
s5 ^= s9;
|
|
2523
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2524
|
+
s1 = (s1 + s5 | 0) + m3 | 0;
|
|
2525
|
+
s13 ^= s1;
|
|
2526
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2527
|
+
s9 = s9 + s13 | 0;
|
|
2528
|
+
s5 ^= s9;
|
|
2529
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2530
|
+
s2 = (s2 + s6 | 0) + m4 | 0;
|
|
2531
|
+
s14 ^= s2;
|
|
2532
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2533
|
+
s10 = s10 + s14 | 0;
|
|
2534
|
+
s6 ^= s10;
|
|
2535
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2536
|
+
s2 = (s2 + s6 | 0) + m5 | 0;
|
|
2537
|
+
s14 ^= s2;
|
|
2538
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2539
|
+
s10 = s10 + s14 | 0;
|
|
2540
|
+
s6 ^= s10;
|
|
2541
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2542
|
+
s3 = (s3 + s7 | 0) + m6 | 0;
|
|
2543
|
+
s15 ^= s3;
|
|
2544
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2545
|
+
s11 = s11 + s15 | 0;
|
|
2546
|
+
s7 ^= s11;
|
|
2547
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2548
|
+
s3 = (s3 + s7 | 0) + m7 | 0;
|
|
2549
|
+
s15 ^= s3;
|
|
2550
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2551
|
+
s11 = s11 + s15 | 0;
|
|
2552
|
+
s7 ^= s11;
|
|
2553
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2554
|
+
s0 = (s0 + s5 | 0) + m8 | 0;
|
|
2555
|
+
s15 ^= s0;
|
|
2556
|
+
s15 = s15 >>> 16 | s15 << 16;
|
|
2557
|
+
s10 = s10 + s15 | 0;
|
|
2558
|
+
s5 ^= s10;
|
|
2559
|
+
s5 = s5 >>> 12 | s5 << 20;
|
|
2560
|
+
s0 = (s0 + s5 | 0) + m9 | 0;
|
|
2561
|
+
s15 ^= s0;
|
|
2562
|
+
s15 = s15 >>> 8 | s15 << 24;
|
|
2563
|
+
s10 = s10 + s15 | 0;
|
|
2564
|
+
s5 ^= s10;
|
|
2565
|
+
s5 = s5 >>> 7 | s5 << 25;
|
|
2566
|
+
s1 = (s1 + s6 | 0) + m10 | 0;
|
|
2567
|
+
s12 ^= s1;
|
|
2568
|
+
s12 = s12 >>> 16 | s12 << 16;
|
|
2569
|
+
s11 = s11 + s12 | 0;
|
|
2570
|
+
s6 ^= s11;
|
|
2571
|
+
s6 = s6 >>> 12 | s6 << 20;
|
|
2572
|
+
s1 = (s1 + s6 | 0) + m11 | 0;
|
|
2573
|
+
s12 ^= s1;
|
|
2574
|
+
s12 = s12 >>> 8 | s12 << 24;
|
|
2575
|
+
s11 = s11 + s12 | 0;
|
|
2576
|
+
s6 ^= s11;
|
|
2577
|
+
s6 = s6 >>> 7 | s6 << 25;
|
|
2578
|
+
s2 = (s2 + s7 | 0) + m12 | 0;
|
|
2579
|
+
s13 ^= s2;
|
|
2580
|
+
s13 = s13 >>> 16 | s13 << 16;
|
|
2581
|
+
s8 = s8 + s13 | 0;
|
|
2582
|
+
s7 ^= s8;
|
|
2583
|
+
s7 = s7 >>> 12 | s7 << 20;
|
|
2584
|
+
s2 = (s2 + s7 | 0) + m13 | 0;
|
|
2585
|
+
s13 ^= s2;
|
|
2586
|
+
s13 = s13 >>> 8 | s13 << 24;
|
|
2587
|
+
s8 = s8 + s13 | 0;
|
|
2588
|
+
s7 ^= s8;
|
|
2589
|
+
s7 = s7 >>> 7 | s7 << 25;
|
|
2590
|
+
s3 = (s3 + s4 | 0) + m14 | 0;
|
|
2591
|
+
s14 ^= s3;
|
|
2592
|
+
s14 = s14 >>> 16 | s14 << 16;
|
|
2593
|
+
s9 = s9 + s14 | 0;
|
|
2594
|
+
s4 ^= s9;
|
|
2595
|
+
s4 = s4 >>> 12 | s4 << 20;
|
|
2596
|
+
s3 = (s3 + s4 | 0) + m15 | 0;
|
|
2597
|
+
s14 ^= s3;
|
|
2598
|
+
s14 = s14 >>> 8 | s14 << 24;
|
|
2599
|
+
s9 = s9 + s14 | 0;
|
|
2600
|
+
s4 ^= s9;
|
|
2601
|
+
s4 = s4 >>> 7 | s4 << 25;
|
|
2602
|
+
if (full) {
|
|
2603
|
+
out[outOff + 8] = s8 ^ cv[cvOff];
|
|
2604
|
+
out[outOff + 9] = s9 ^ cv[cvOff + 1];
|
|
2605
|
+
out[outOff + 10] = s10 ^ cv[cvOff + 2];
|
|
2606
|
+
out[outOff + 11] = s11 ^ cv[cvOff + 3];
|
|
2607
|
+
out[outOff + 12] = s12 ^ cv[cvOff + 4];
|
|
2608
|
+
out[outOff + 13] = s13 ^ cv[cvOff + 5];
|
|
2609
|
+
out[outOff + 14] = s14 ^ cv[cvOff + 6];
|
|
2610
|
+
out[outOff + 15] = s15 ^ cv[cvOff + 7];
|
|
2611
|
+
}
|
|
2612
|
+
out[outOff] = s0 ^ s8;
|
|
2613
|
+
out[outOff + 1] = s1 ^ s9;
|
|
2614
|
+
out[outOff + 2] = s2 ^ s10;
|
|
2615
|
+
out[outOff + 3] = s3 ^ s11;
|
|
2616
|
+
out[outOff + 4] = s4 ^ s12;
|
|
2617
|
+
out[outOff + 5] = s5 ^ s13;
|
|
2618
|
+
out[outOff + 6] = s6 ^ s14;
|
|
2619
|
+
out[outOff + 7] = s7 ^ s15;
|
|
2620
|
+
}
|
|
2621
|
+
//#endregion
|
|
2622
|
+
//#region ../../node_modules/.pnpm/@huggingface+blake3-jit@0.0.2/node_modules/@huggingface/blake3-jit/dist/esm/constants.js
|
|
2623
|
+
/**
|
|
2624
|
+
* BLAKE3 Constants
|
|
2625
|
+
*
|
|
2626
|
+
* IV values are the same as SHA-256: first 32 bits of the fractional parts
|
|
2627
|
+
* of the square roots of the first 8 primes (2..19)
|
|
2628
|
+
*/
|
|
2629
|
+
const IV = new Uint32Array([
|
|
2630
|
+
1779033703,
|
|
2631
|
+
3144134277,
|
|
2632
|
+
1013904242,
|
|
2633
|
+
2773480762,
|
|
2634
|
+
1359893119,
|
|
2635
|
+
2600822924,
|
|
2636
|
+
528734635,
|
|
2637
|
+
1541459225
|
|
2638
|
+
]);
|
|
2639
|
+
const CHUNK_LEN = 1024;
|
|
2640
|
+
new Uint8Array([
|
|
2641
|
+
0,
|
|
2642
|
+
1,
|
|
2643
|
+
2,
|
|
2644
|
+
3,
|
|
2645
|
+
4,
|
|
2646
|
+
5,
|
|
2647
|
+
6,
|
|
2648
|
+
7,
|
|
2649
|
+
8,
|
|
2650
|
+
9,
|
|
2651
|
+
10,
|
|
2652
|
+
11,
|
|
2653
|
+
12,
|
|
2654
|
+
13,
|
|
2655
|
+
14,
|
|
2656
|
+
15,
|
|
2657
|
+
2,
|
|
2658
|
+
6,
|
|
2659
|
+
3,
|
|
2660
|
+
10,
|
|
2661
|
+
7,
|
|
2662
|
+
0,
|
|
2663
|
+
4,
|
|
2664
|
+
13,
|
|
2665
|
+
1,
|
|
2666
|
+
11,
|
|
2667
|
+
12,
|
|
2668
|
+
5,
|
|
2669
|
+
9,
|
|
2670
|
+
14,
|
|
2671
|
+
15,
|
|
2672
|
+
8,
|
|
2673
|
+
3,
|
|
2674
|
+
4,
|
|
2675
|
+
10,
|
|
2676
|
+
12,
|
|
2677
|
+
13,
|
|
2678
|
+
2,
|
|
2679
|
+
7,
|
|
2680
|
+
14,
|
|
2681
|
+
6,
|
|
2682
|
+
5,
|
|
2683
|
+
9,
|
|
2684
|
+
0,
|
|
2685
|
+
11,
|
|
2686
|
+
15,
|
|
2687
|
+
8,
|
|
2688
|
+
1,
|
|
2689
|
+
10,
|
|
2690
|
+
7,
|
|
2691
|
+
12,
|
|
2692
|
+
9,
|
|
2693
|
+
14,
|
|
2694
|
+
3,
|
|
2695
|
+
13,
|
|
2696
|
+
15,
|
|
2697
|
+
4,
|
|
2698
|
+
0,
|
|
2699
|
+
11,
|
|
2700
|
+
2,
|
|
2701
|
+
5,
|
|
2702
|
+
8,
|
|
2703
|
+
1,
|
|
2704
|
+
6,
|
|
2705
|
+
12,
|
|
2706
|
+
13,
|
|
2707
|
+
9,
|
|
2708
|
+
11,
|
|
2709
|
+
15,
|
|
2710
|
+
10,
|
|
2711
|
+
14,
|
|
2712
|
+
8,
|
|
2713
|
+
7,
|
|
2714
|
+
2,
|
|
2715
|
+
5,
|
|
2716
|
+
3,
|
|
2717
|
+
0,
|
|
2718
|
+
1,
|
|
2719
|
+
6,
|
|
2720
|
+
4,
|
|
2721
|
+
9,
|
|
2722
|
+
14,
|
|
2723
|
+
11,
|
|
2724
|
+
5,
|
|
2725
|
+
8,
|
|
2726
|
+
12,
|
|
2727
|
+
15,
|
|
2728
|
+
1,
|
|
2729
|
+
13,
|
|
2730
|
+
3,
|
|
2731
|
+
0,
|
|
2732
|
+
10,
|
|
2733
|
+
2,
|
|
2734
|
+
6,
|
|
2735
|
+
4,
|
|
2736
|
+
7,
|
|
2737
|
+
11,
|
|
2738
|
+
15,
|
|
2739
|
+
5,
|
|
2740
|
+
0,
|
|
2741
|
+
1,
|
|
2742
|
+
9,
|
|
2743
|
+
8,
|
|
2744
|
+
6,
|
|
2745
|
+
14,
|
|
2746
|
+
10,
|
|
2747
|
+
2,
|
|
2748
|
+
12,
|
|
2749
|
+
3,
|
|
2750
|
+
4,
|
|
2751
|
+
7,
|
|
2752
|
+
13
|
|
2753
|
+
]);
|
|
2754
|
+
//#endregion
|
|
2755
|
+
//#region ../../node_modules/.pnpm/@huggingface+blake3-jit@0.0.2/node_modules/@huggingface/blake3-jit/dist/esm/utils.js
|
|
2756
|
+
/**
|
|
2757
|
+
* BLAKE3 Utility Functions
|
|
2758
|
+
*
|
|
2759
|
+
* Optimized for little-endian systems (most user-facing systems).
|
|
2760
|
+
* BLAKE3 is little-endian friendly - on little-endian systems we can
|
|
2761
|
+
* create Uint32Array views directly over input buffers.
|
|
2762
|
+
*/
|
|
2763
|
+
/**
|
|
2764
|
+
* Detect system endianness at module load time.
|
|
2765
|
+
* On little-endian systems, the byte 0x01 will be at index 0.
|
|
2766
|
+
*/
|
|
2767
|
+
const IS_LITTLE_ENDIAN = new Uint8Array(new Uint32Array([16909060]).buffer)[0] === 4;
|
|
2768
|
+
/**
|
|
2769
|
+
* Read 16 little-endian 32-bit words from a byte array into a Uint32Array.
|
|
2770
|
+
* This is only needed on big-endian systems.
|
|
2771
|
+
*
|
|
2772
|
+
* @param input - Source byte array
|
|
2773
|
+
* @param offset - Starting byte offset in input
|
|
2774
|
+
* @param words - Destination Uint32Array (must have at least 16 elements)
|
|
2775
|
+
*/
|
|
2776
|
+
function readLittleEndianWordsFull(input, offset, words) {
|
|
2777
|
+
for (let i = 0; i < 16; ++i, offset += 4) words[i] = input[offset] | input[offset + 1] << 8 | input[offset + 2] << 16 | input[offset + 3] << 24;
|
|
2778
|
+
}
|
|
2779
|
+
/**
|
|
2780
|
+
* Write N bytes from 32-bit words to output.
|
|
2781
|
+
* Used for variable-length output (XOF mode).
|
|
2782
|
+
*
|
|
2783
|
+
* @param words - Source Uint32Array
|
|
2784
|
+
* @param wordOffset - Starting word offset
|
|
2785
|
+
* @param output - Destination byte array
|
|
2786
|
+
* @param byteOffset - Starting byte offset in destination
|
|
2787
|
+
* @param byteCount - Number of bytes to write
|
|
2788
|
+
*/
|
|
2789
|
+
function writeLittleEndianBytesPartial(words, wordOffset, output, byteOffset, byteCount) {
|
|
2790
|
+
const fullWords = byteCount >>> 2;
|
|
2791
|
+
let i = 0;
|
|
2792
|
+
for (; i < fullWords; ++i, byteOffset += 4) {
|
|
2793
|
+
const w = words[wordOffset + i];
|
|
2794
|
+
output[byteOffset] = w & 255;
|
|
2795
|
+
output[byteOffset + 1] = w >>> 8 & 255;
|
|
2796
|
+
output[byteOffset + 2] = w >>> 16 & 255;
|
|
2797
|
+
output[byteOffset + 3] = w >>> 24 & 255;
|
|
2798
|
+
}
|
|
2799
|
+
const remaining = byteCount & 3;
|
|
2800
|
+
if (remaining > 0) {
|
|
2801
|
+
const w = words[wordOffset + i];
|
|
2802
|
+
output[byteOffset] = w & 255;
|
|
2803
|
+
if (remaining > 1) output[byteOffset + 1] = w >>> 8 & 255;
|
|
2804
|
+
if (remaining > 2) output[byteOffset + 2] = w >>> 16 & 255;
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Encode a UTF-8 string to Uint8Array.
|
|
2809
|
+
* Used for derive_key context strings.
|
|
2810
|
+
*/
|
|
2811
|
+
function encodeUTF8(str) {
|
|
2812
|
+
if (typeof TextEncoder !== "undefined") return new TextEncoder().encode(str);
|
|
2813
|
+
const bytes = [];
|
|
2814
|
+
for (let i = 0; i < str.length; i++) {
|
|
2815
|
+
let c = str.charCodeAt(i);
|
|
2816
|
+
if (c < 128) bytes.push(c);
|
|
2817
|
+
else if (c < 2048) bytes.push(192 | c >> 6, 128 | c & 63);
|
|
2818
|
+
else if (c < 55296 || c >= 57344) bytes.push(224 | c >> 12, 128 | c >> 6 & 63, 128 | c & 63);
|
|
2819
|
+
else {
|
|
2820
|
+
i++;
|
|
2821
|
+
c = 65536 + ((c & 1023) << 10 | str.charCodeAt(i) & 1023);
|
|
2822
|
+
bytes.push(240 | c >> 18, 128 | c >> 12 & 63, 128 | c >> 6 & 63, 128 | c & 63);
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
return new Uint8Array(bytes);
|
|
2826
|
+
}
|
|
2827
|
+
new Uint8Array([
|
|
2828
|
+
0,
|
|
2829
|
+
1,
|
|
2830
|
+
28,
|
|
2831
|
+
2,
|
|
2832
|
+
29,
|
|
2833
|
+
14,
|
|
2834
|
+
24,
|
|
2835
|
+
3,
|
|
2836
|
+
30,
|
|
2837
|
+
22,
|
|
2838
|
+
20,
|
|
2839
|
+
15,
|
|
2840
|
+
25,
|
|
2841
|
+
17,
|
|
2842
|
+
4,
|
|
2843
|
+
8,
|
|
2844
|
+
31,
|
|
2845
|
+
27,
|
|
2846
|
+
13,
|
|
2847
|
+
23,
|
|
2848
|
+
21,
|
|
2849
|
+
19,
|
|
2850
|
+
16,
|
|
2851
|
+
7,
|
|
2852
|
+
26,
|
|
2853
|
+
12,
|
|
2854
|
+
18,
|
|
2855
|
+
6,
|
|
2856
|
+
11,
|
|
2857
|
+
5,
|
|
2858
|
+
10,
|
|
2859
|
+
9
|
|
2860
|
+
]);
|
|
2861
|
+
//#endregion
|
|
2862
|
+
//#region ../../node_modules/.pnpm/@huggingface+blake3-jit@0.0.2/node_modules/@huggingface/blake3-jit/dist/esm/hasher.js
|
|
2863
|
+
/**
|
|
2864
|
+
* BLAKE3 Hasher - Incremental hashing with support for all modes
|
|
2865
|
+
*
|
|
2866
|
+
* Supports:
|
|
2867
|
+
* - Regular hashing
|
|
2868
|
+
* - Keyed hashing (MAC)
|
|
2869
|
+
* - Key derivation (derive_key)
|
|
2870
|
+
* - XOF (eXtendable Output Function) mode
|
|
2871
|
+
*/
|
|
2872
|
+
/**
|
|
2873
|
+
* Output state for XOF (eXtendable Output Function) mode.
|
|
2874
|
+
* Allows reading arbitrary amounts of output.
|
|
2875
|
+
*/
|
|
2876
|
+
var XofReader = class {
|
|
2877
|
+
inputCv;
|
|
2878
|
+
blockWords;
|
|
2879
|
+
counter;
|
|
2880
|
+
blockLen;
|
|
2881
|
+
flags;
|
|
2882
|
+
outputBlock;
|
|
2883
|
+
outputBlockOffset;
|
|
2884
|
+
constructor(inputCv, blockWords, counter, blockLen, flags) {
|
|
2885
|
+
this.inputCv = inputCv;
|
|
2886
|
+
this.blockWords = blockWords;
|
|
2887
|
+
this.counter = counter;
|
|
2888
|
+
this.blockLen = blockLen;
|
|
2889
|
+
this.flags = flags | 8;
|
|
2890
|
+
this.outputBlock = new Uint32Array(16);
|
|
2891
|
+
this.outputBlockOffset = 64;
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Read the next `length` bytes of output.
|
|
2895
|
+
*/
|
|
2896
|
+
read(length) {
|
|
2897
|
+
const output = new Uint8Array(length);
|
|
2898
|
+
let outputOffset = 0;
|
|
2899
|
+
while (outputOffset < length) {
|
|
2900
|
+
if (this.outputBlockOffset >= 64) {
|
|
2901
|
+
compress(this.inputCv, 0, this.blockWords, 0, this.outputBlock, 0, true, this.counter++, this.blockLen, this.flags);
|
|
2902
|
+
this.outputBlockOffset = 0;
|
|
2903
|
+
}
|
|
2904
|
+
const available = 64 - this.outputBlockOffset;
|
|
2905
|
+
const toCopy = Math.min(available, length - outputOffset);
|
|
2906
|
+
const wordOffset = this.outputBlockOffset >>> 2;
|
|
2907
|
+
if ((this.outputBlockOffset & 3) === 0 && toCopy >= 4) {
|
|
2908
|
+
const fullWords = toCopy >>> 2;
|
|
2909
|
+
writeLittleEndianBytesPartial(this.outputBlock, wordOffset, output, outputOffset, fullWords << 2);
|
|
2910
|
+
const bytesCopied = fullWords << 2;
|
|
2911
|
+
outputOffset += bytesCopied;
|
|
2912
|
+
this.outputBlockOffset += bytesCopied;
|
|
2913
|
+
} else {
|
|
2914
|
+
for (let i = 0; i < toCopy; i++) {
|
|
2915
|
+
const wordIdx = this.outputBlockOffset + i >>> 2;
|
|
2916
|
+
const byteIdx = this.outputBlockOffset + i & 3;
|
|
2917
|
+
output[outputOffset + i] = this.outputBlock[wordIdx] >>> (byteIdx << 3) & 255;
|
|
2918
|
+
}
|
|
2919
|
+
outputOffset += toCopy;
|
|
2920
|
+
this.outputBlockOffset += toCopy;
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
return output;
|
|
2924
|
+
}
|
|
2925
|
+
};
|
|
2926
|
+
/**
|
|
2927
|
+
* Chunk state for processing input data.
|
|
2928
|
+
* Each chunk is 1024 bytes and produces an 8-word chaining value.
|
|
2929
|
+
*/
|
|
2930
|
+
var ChunkState = class {
|
|
2931
|
+
chainingValue;
|
|
2932
|
+
chunkCounter;
|
|
2933
|
+
blockWords;
|
|
2934
|
+
blockLen;
|
|
2935
|
+
blocksCompressed;
|
|
2936
|
+
flags;
|
|
2937
|
+
constructor(keyWords, chunkCounter, flags) {
|
|
2938
|
+
this.chainingValue = new Uint32Array(keyWords);
|
|
2939
|
+
this.chunkCounter = chunkCounter;
|
|
2940
|
+
this.blockWords = new Uint32Array(16);
|
|
2941
|
+
this.blockLen = 0;
|
|
2942
|
+
this.blocksCompressed = 0;
|
|
2943
|
+
this.flags = flags;
|
|
2944
|
+
}
|
|
2945
|
+
resetTo(keyWords, chunkCounter, flags) {
|
|
2946
|
+
this.chainingValue.set(keyWords);
|
|
2947
|
+
this.chunkCounter = chunkCounter;
|
|
2948
|
+
this.blockLen = 0;
|
|
2949
|
+
this.blocksCompressed = 0;
|
|
2950
|
+
this.flags = flags;
|
|
2951
|
+
}
|
|
2952
|
+
/**
|
|
2953
|
+
* Get the flags for the current block.
|
|
2954
|
+
*/
|
|
2955
|
+
startFlag() {
|
|
2956
|
+
return this.blocksCompressed === 0 ? 1 : 0;
|
|
2957
|
+
}
|
|
2958
|
+
/**
|
|
2959
|
+
* Update the chunk state with input data.
|
|
2960
|
+
* Returns the number of bytes consumed.
|
|
2961
|
+
*/
|
|
2962
|
+
update(input, inputOffset, inputLen) {
|
|
2963
|
+
let consumed = 0;
|
|
2964
|
+
while (inputLen > 0) {
|
|
2965
|
+
if (this.blockLen === 64) {
|
|
2966
|
+
compress(this.chainingValue, 0, this.blockWords, 0, this.chainingValue, 0, false, this.chunkCounter, 64, this.flags | this.startFlag());
|
|
2967
|
+
this.blocksCompressed++;
|
|
2968
|
+
this.blockLen = 0;
|
|
2969
|
+
}
|
|
2970
|
+
const want = 64 - this.blockLen;
|
|
2971
|
+
const take = Math.min(want, inputLen);
|
|
2972
|
+
if (this.blockLen === 0 && take === 64) readLittleEndianWordsFull(input, inputOffset, this.blockWords);
|
|
2973
|
+
else for (let i = 0; i < take; i++) {
|
|
2974
|
+
const pos = this.blockLen + i;
|
|
2975
|
+
const wordIdx = pos >>> 2;
|
|
2976
|
+
const byteIdx = pos & 3;
|
|
2977
|
+
if (byteIdx === 0) this.blockWords[wordIdx] = input[inputOffset + i];
|
|
2978
|
+
else this.blockWords[wordIdx] |= input[inputOffset + i] << (byteIdx << 3);
|
|
2979
|
+
}
|
|
2980
|
+
this.blockLen += take;
|
|
2981
|
+
inputOffset += take;
|
|
2982
|
+
inputLen -= take;
|
|
2983
|
+
consumed += take;
|
|
2984
|
+
}
|
|
2985
|
+
return consumed;
|
|
2986
|
+
}
|
|
2987
|
+
/**
|
|
2988
|
+
* Finalize this chunk and return its output.
|
|
2989
|
+
* Returns 8 words (chaining value) or 16 words (if root).
|
|
2990
|
+
*/
|
|
2991
|
+
output() {
|
|
2992
|
+
const usedWords = this.blockLen + 3 >>> 2;
|
|
2993
|
+
for (let i = usedWords; i < 16; i++) this.blockWords[i] = 0;
|
|
2994
|
+
return {
|
|
2995
|
+
inputCv: this.chainingValue,
|
|
2996
|
+
blockWords: this.blockWords,
|
|
2997
|
+
blockLen: this.blockLen,
|
|
2998
|
+
counter: this.chunkCounter,
|
|
2999
|
+
flags: this.flags | this.startFlag() | 2
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
/**
|
|
3003
|
+
* Get the number of bytes in this chunk.
|
|
3004
|
+
*/
|
|
3005
|
+
len() {
|
|
3006
|
+
return this.blocksCompressed * 64 + this.blockLen;
|
|
3007
|
+
}
|
|
3008
|
+
};
|
|
3009
|
+
/**
|
|
3010
|
+
* Main BLAKE3 Hasher class.
|
|
3011
|
+
*
|
|
3012
|
+
* Usage:
|
|
3013
|
+
* const hasher = new Hasher();
|
|
3014
|
+
* hasher.update(data);
|
|
3015
|
+
* const hash = hasher.finalize();
|
|
3016
|
+
*
|
|
3017
|
+
* Or with chaining:
|
|
3018
|
+
* const hash = new Hasher().update(data).finalize();
|
|
3019
|
+
*/
|
|
3020
|
+
var Hasher = class Hasher {
|
|
3021
|
+
chunkState;
|
|
3022
|
+
keyWords;
|
|
3023
|
+
cvStack;
|
|
3024
|
+
cvStackLen;
|
|
3025
|
+
flags;
|
|
3026
|
+
parentBlock;
|
|
3027
|
+
parentCv;
|
|
3028
|
+
chunkCv;
|
|
3029
|
+
outWords;
|
|
3030
|
+
finalizeCv;
|
|
3031
|
+
/**
|
|
3032
|
+
* Create a new Hasher.
|
|
3033
|
+
*
|
|
3034
|
+
* @param keyWords - Initial key words (IV for regular hashing)
|
|
3035
|
+
* @param flags - Domain separation flags
|
|
3036
|
+
*/
|
|
3037
|
+
constructor(keyWords, flags) {
|
|
3038
|
+
this.keyWords = keyWords ? new Uint32Array(keyWords) : new Uint32Array(IV);
|
|
3039
|
+
this.flags = flags ?? 0;
|
|
3040
|
+
this.chunkState = new ChunkState(this.keyWords, 0, this.flags);
|
|
3041
|
+
this.cvStack = new Uint32Array(432);
|
|
3042
|
+
this.cvStackLen = 0;
|
|
3043
|
+
this.parentBlock = new Uint32Array(16);
|
|
3044
|
+
this.parentCv = new Uint32Array(8);
|
|
3045
|
+
this.chunkCv = new Uint32Array(8);
|
|
3046
|
+
this.outWords = new Uint32Array(16);
|
|
3047
|
+
this.finalizeCv = new Uint32Array(8);
|
|
3048
|
+
}
|
|
3049
|
+
/**
|
|
3050
|
+
* Reset the hasher to process a new message with the same key/flags.
|
|
3051
|
+
* Reuses all internal buffers — zero allocations.
|
|
3052
|
+
*/
|
|
3053
|
+
reset() {
|
|
3054
|
+
this.chunkState.resetTo(this.keyWords, 0, this.flags);
|
|
3055
|
+
this.cvStackLen = 0;
|
|
3056
|
+
return this;
|
|
3057
|
+
}
|
|
3058
|
+
/**
|
|
3059
|
+
* Create a new keyed hasher (MAC).
|
|
3060
|
+
*
|
|
3061
|
+
* @param key - 32-byte key
|
|
3062
|
+
*/
|
|
3063
|
+
static newKeyed(key) {
|
|
3064
|
+
if (key.length !== 32) throw new Error(`Key must be 32 bytes, got ${key.length}`);
|
|
3065
|
+
const keyWords = new Uint32Array(8);
|
|
3066
|
+
if (IS_LITTLE_ENDIAN) {
|
|
3067
|
+
const view = new Uint32Array(key.buffer, key.byteOffset, 8);
|
|
3068
|
+
keyWords.set(view);
|
|
3069
|
+
} else for (let i = 0; i < 8; i++) {
|
|
3070
|
+
const off = i * 4;
|
|
3071
|
+
keyWords[i] = key[off] | key[off + 1] << 8 | key[off + 2] << 16 | key[off + 3] << 24;
|
|
3072
|
+
}
|
|
3073
|
+
return new Hasher(keyWords, 16);
|
|
3074
|
+
}
|
|
3075
|
+
/**
|
|
3076
|
+
* Create a new key derivation hasher.
|
|
3077
|
+
*
|
|
3078
|
+
* @param context - Context string for domain separation
|
|
3079
|
+
*/
|
|
3080
|
+
static newDeriveKey(context) {
|
|
3081
|
+
const contextBytes = encodeUTF8(context);
|
|
3082
|
+
const contextHasher = new Hasher(new Uint32Array(IV), 32);
|
|
3083
|
+
contextHasher.update(contextBytes);
|
|
3084
|
+
const contextKey = new Uint32Array(8);
|
|
3085
|
+
const output = contextHasher.finalizeOutput();
|
|
3086
|
+
compress(output.inputCv, 0, output.blockWords, 0, contextKey, 0, false, output.counter, output.blockLen, output.flags | 8);
|
|
3087
|
+
return new Hasher(contextKey, 64);
|
|
3088
|
+
}
|
|
3089
|
+
/**
|
|
3090
|
+
* Push a chaining value onto the stack.
|
|
3091
|
+
*/
|
|
3092
|
+
pushCv(cv, cvOffset) {
|
|
3093
|
+
this.cvStack.set(cv.subarray(cvOffset, cvOffset + 8), this.cvStackLen * 8);
|
|
3094
|
+
this.cvStackLen++;
|
|
3095
|
+
}
|
|
3096
|
+
/**
|
|
3097
|
+
* Pop a chaining value from the stack.
|
|
3098
|
+
*/
|
|
3099
|
+
popCv(out, outOffset) {
|
|
3100
|
+
this.cvStackLen--;
|
|
3101
|
+
out.set(this.cvStack.subarray(this.cvStackLen * 8, (this.cvStackLen + 1) * 8), outOffset);
|
|
3102
|
+
}
|
|
3103
|
+
/**
|
|
3104
|
+
* Add a chunk's chaining value and merge completed subtrees.
|
|
3105
|
+
*/
|
|
3106
|
+
addChunkCv(newCv, newCvOffset, totalChunks) {
|
|
3107
|
+
const parentBlock = this.parentBlock;
|
|
3108
|
+
const parentCv = this.parentCv;
|
|
3109
|
+
while ((totalChunks & 1) === 0) {
|
|
3110
|
+
this.popCv(parentBlock, 0);
|
|
3111
|
+
parentBlock.set(newCv.subarray(newCvOffset, newCvOffset + 8), 8);
|
|
3112
|
+
compress(this.keyWords, 0, parentBlock, 0, parentCv, 0, false, 0, 64, this.flags | 4);
|
|
3113
|
+
newCv = parentCv;
|
|
3114
|
+
newCvOffset = 0;
|
|
3115
|
+
totalChunks >>>= 1;
|
|
3116
|
+
}
|
|
3117
|
+
this.pushCv(newCv, newCvOffset);
|
|
3118
|
+
}
|
|
3119
|
+
/**
|
|
3120
|
+
* Update the hasher with input data.
|
|
3121
|
+
*
|
|
3122
|
+
* @param input - Data to hash
|
|
3123
|
+
* @returns this (for chaining)
|
|
3124
|
+
*/
|
|
3125
|
+
update(input) {
|
|
3126
|
+
let inputOffset = 0;
|
|
3127
|
+
let inputLen = input.length;
|
|
3128
|
+
while (inputLen > 0) {
|
|
3129
|
+
if (this.chunkState.len() === 1024) {
|
|
3130
|
+
const output = this.chunkState.output();
|
|
3131
|
+
const chunkCv = this.chunkCv;
|
|
3132
|
+
compress(output.inputCv, 0, output.blockWords, 0, chunkCv, 0, false, output.counter, output.blockLen, output.flags);
|
|
3133
|
+
const totalChunks = this.chunkState.chunkCounter + 1;
|
|
3134
|
+
this.addChunkCv(chunkCv, 0, totalChunks);
|
|
3135
|
+
this.chunkState.resetTo(this.keyWords, totalChunks, this.flags);
|
|
3136
|
+
}
|
|
3137
|
+
const want = CHUNK_LEN - this.chunkState.len();
|
|
3138
|
+
const take = Math.min(want, inputLen);
|
|
3139
|
+
this.chunkState.update(input, inputOffset, take);
|
|
3140
|
+
inputOffset += take;
|
|
3141
|
+
inputLen -= take;
|
|
3142
|
+
}
|
|
3143
|
+
return this;
|
|
3144
|
+
}
|
|
3145
|
+
/**
|
|
3146
|
+
* Get the output parameters (for XOF mode or finalization).
|
|
3147
|
+
*/
|
|
3148
|
+
finalizeOutput() {
|
|
3149
|
+
let output = this.chunkState.output();
|
|
3150
|
+
let parentBlock = this.parentBlock;
|
|
3151
|
+
let cv = this.finalizeCv;
|
|
3152
|
+
if (this.cvStackLen > 0) {
|
|
3153
|
+
compress(output.inputCv, 0, output.blockWords, 0, cv, 0, false, output.counter, output.blockLen, output.flags);
|
|
3154
|
+
while (this.cvStackLen > 0) {
|
|
3155
|
+
this.cvStackLen--;
|
|
3156
|
+
parentBlock.set(this.cvStack.subarray(this.cvStackLen * 8, (this.cvStackLen + 1) * 8), 0);
|
|
3157
|
+
parentBlock.set(cv, 8);
|
|
3158
|
+
if (this.cvStackLen > 0) compress(this.keyWords, 0, parentBlock, 0, cv, 0, false, 0, 64, this.flags | 4);
|
|
3159
|
+
else return {
|
|
3160
|
+
inputCv: this.keyWords,
|
|
3161
|
+
blockWords: parentBlock,
|
|
3162
|
+
blockLen: 64,
|
|
3163
|
+
counter: 0,
|
|
3164
|
+
flags: this.flags | 4
|
|
3165
|
+
};
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
return output;
|
|
3169
|
+
}
|
|
3170
|
+
/**
|
|
3171
|
+
* Finalize the hash and return the result.
|
|
3172
|
+
*
|
|
3173
|
+
* @param outputLength - Number of bytes to output (default: 32)
|
|
3174
|
+
* @returns The hash output
|
|
3175
|
+
*/
|
|
3176
|
+
finalize(outputLength = 32) {
|
|
3177
|
+
const output = this.finalizeOutput();
|
|
3178
|
+
const result = new Uint8Array(outputLength);
|
|
3179
|
+
if (outputLength <= 64) {
|
|
3180
|
+
const outWords = this.outWords;
|
|
3181
|
+
compress(output.inputCv, 0, output.blockWords, 0, outWords, 0, outputLength > 32, output.counter, output.blockLen, output.flags | 8);
|
|
3182
|
+
if (IS_LITTLE_ENDIAN) {
|
|
3183
|
+
const outBytes = new Uint8Array(outWords.buffer);
|
|
3184
|
+
result.set(outBytes.subarray(0, outputLength));
|
|
3185
|
+
} else writeLittleEndianBytesPartial(outWords, 0, result, 0, outputLength);
|
|
3186
|
+
} else {
|
|
3187
|
+
const full = this.finalizeXof().read(outputLength);
|
|
3188
|
+
result.set(full);
|
|
3189
|
+
}
|
|
3190
|
+
return result;
|
|
3191
|
+
}
|
|
3192
|
+
/**
|
|
3193
|
+
* Finalize and return an XOF reader for arbitrary-length output.
|
|
3194
|
+
*/
|
|
3195
|
+
finalizeXof() {
|
|
3196
|
+
const output = this.finalizeOutput();
|
|
3197
|
+
return new XofReader(new Uint32Array(output.inputCv), new Uint32Array(output.blockWords), output.counter, output.blockLen, output.flags);
|
|
3198
|
+
}
|
|
3199
|
+
};
|
|
3200
|
+
//#endregion
|
|
3201
|
+
//#region ../../node_modules/.pnpm/@huggingface+xetchunk-wasm@0.0.6/node_modules/@huggingface/xetchunk-wasm/dist/esm/xet-chunker.js
|
|
3202
|
+
var import_tokenizers = require_tokenizers();
|
|
3203
|
+
var import_dist = /* @__PURE__ */ __toESM(require_dist(), 1);
|
|
3204
|
+
var import_progress = /* @__PURE__ */ __toESM(require_progress(), 1);
|
|
3205
|
+
new Uint8Array([
|
|
3206
|
+
102,
|
|
3207
|
+
151,
|
|
3208
|
+
245,
|
|
3209
|
+
119,
|
|
3210
|
+
91,
|
|
3211
|
+
149,
|
|
3212
|
+
80,
|
|
3213
|
+
222,
|
|
3214
|
+
49,
|
|
3215
|
+
53,
|
|
3216
|
+
203,
|
|
3217
|
+
172,
|
|
3218
|
+
165,
|
|
3219
|
+
151,
|
|
3220
|
+
24,
|
|
3221
|
+
28,
|
|
3222
|
+
157,
|
|
3223
|
+
228,
|
|
3224
|
+
33,
|
|
3225
|
+
16,
|
|
3226
|
+
155,
|
|
3227
|
+
235,
|
|
3228
|
+
43,
|
|
3229
|
+
88,
|
|
3230
|
+
180,
|
|
3231
|
+
208,
|
|
3232
|
+
176,
|
|
3233
|
+
75,
|
|
3234
|
+
147,
|
|
3235
|
+
173,
|
|
3236
|
+
242,
|
|
3237
|
+
41
|
|
3238
|
+
]);
|
|
3239
|
+
//#endregion
|
|
3240
|
+
//#region ../../node_modules/.pnpm/@huggingface+xetchunk-wasm@0.0.6/node_modules/@huggingface/xetchunk-wasm/dist/esm/xorb-hash.js
|
|
3241
|
+
const BLAKE3_NODE_KEY = new Uint8Array([
|
|
3242
|
+
1,
|
|
3243
|
+
126,
|
|
3244
|
+
197,
|
|
3245
|
+
199,
|
|
3246
|
+
165,
|
|
3247
|
+
71,
|
|
3248
|
+
41,
|
|
3249
|
+
150,
|
|
3250
|
+
253,
|
|
3251
|
+
148,
|
|
3252
|
+
102,
|
|
3253
|
+
102,
|
|
3254
|
+
180,
|
|
3255
|
+
138,
|
|
3256
|
+
2,
|
|
3257
|
+
230,
|
|
3258
|
+
93,
|
|
3259
|
+
221,
|
|
3260
|
+
83,
|
|
3261
|
+
111,
|
|
3262
|
+
55,
|
|
3263
|
+
199,
|
|
3264
|
+
109,
|
|
3265
|
+
210,
|
|
3266
|
+
248,
|
|
3267
|
+
99,
|
|
3268
|
+
82,
|
|
3269
|
+
230,
|
|
3270
|
+
74,
|
|
3271
|
+
83,
|
|
3272
|
+
113,
|
|
3273
|
+
63
|
|
3274
|
+
]);
|
|
3275
|
+
Hasher.newKeyed(BLAKE3_NODE_KEY);
|
|
3276
|
+
//#endregion
|
|
3277
|
+
//#region ../../node_modules/.pnpm/@huggingface+xetchunk-wasm@0.0.6/node_modules/@huggingface/xetchunk-wasm/dist/esm/hash-utils.js
|
|
3278
|
+
const ZERO_KEY = new Uint8Array(32);
|
|
3279
|
+
const VERIFICATION_KEY = new Uint8Array([
|
|
3280
|
+
127,
|
|
3281
|
+
24,
|
|
3282
|
+
87,
|
|
3283
|
+
214,
|
|
3284
|
+
206,
|
|
3285
|
+
86,
|
|
3286
|
+
237,
|
|
3287
|
+
102,
|
|
3288
|
+
18,
|
|
3289
|
+
127,
|
|
3290
|
+
249,
|
|
3291
|
+
19,
|
|
3292
|
+
231,
|
|
3293
|
+
165,
|
|
3294
|
+
195,
|
|
3295
|
+
243,
|
|
3296
|
+
164,
|
|
3297
|
+
205,
|
|
3298
|
+
38,
|
|
3299
|
+
213,
|
|
3300
|
+
181,
|
|
3301
|
+
219,
|
|
3302
|
+
73,
|
|
3303
|
+
230,
|
|
3304
|
+
65,
|
|
3305
|
+
36,
|
|
3306
|
+
152,
|
|
3307
|
+
127,
|
|
3308
|
+
40,
|
|
3309
|
+
251,
|
|
3310
|
+
148,
|
|
3311
|
+
195
|
|
3312
|
+
]);
|
|
3313
|
+
Hasher.newKeyed(ZERO_KEY);
|
|
3314
|
+
Hasher.newKeyed(VERIFICATION_KEY);
|
|
3315
|
+
typeof window !== "undefined" && window.document;
|
|
3316
|
+
typeof self === "object" && self.constructor && self.constructor.name;
|
|
3317
|
+
new Promise((r) => {});
|
|
3318
|
+
var hashSize = 65536;
|
|
3319
|
+
makeBuffer(5 << 20);
|
|
3320
|
+
makeHashTable();
|
|
3321
|
+
function makeHashTable() {
|
|
3322
|
+
try {
|
|
3323
|
+
return new Uint32Array(hashSize);
|
|
3324
|
+
} catch (error) {
|
|
3325
|
+
const hashTable2 = new Array(hashSize);
|
|
3326
|
+
for (let i = 0; i < hashSize; i++) hashTable2[i] = 0;
|
|
3327
|
+
return hashTable2;
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
function makeBuffer(size) {
|
|
3331
|
+
return new Uint8Array(size);
|
|
3332
|
+
}
|
|
3333
|
+
"ff".repeat(32);
|
|
3334
|
+
new Uint8Array([
|
|
3335
|
+
"H".charCodeAt(0),
|
|
3336
|
+
"F".charCodeAt(0),
|
|
3337
|
+
"R".charCodeAt(0),
|
|
3338
|
+
"e".charCodeAt(0),
|
|
3339
|
+
"p".charCodeAt(0),
|
|
3340
|
+
"o".charCodeAt(0),
|
|
3341
|
+
"M".charCodeAt(0),
|
|
3342
|
+
"e".charCodeAt(0),
|
|
3343
|
+
"t".charCodeAt(0),
|
|
3344
|
+
"a".charCodeAt(0),
|
|
3345
|
+
"D".charCodeAt(0),
|
|
3346
|
+
"a".charCodeAt(0),
|
|
3347
|
+
"t".charCodeAt(0),
|
|
3348
|
+
"a".charCodeAt(0),
|
|
3349
|
+
0,
|
|
3350
|
+
85,
|
|
3351
|
+
105,
|
|
3352
|
+
103,
|
|
3353
|
+
69,
|
|
3354
|
+
106,
|
|
3355
|
+
123,
|
|
3356
|
+
129,
|
|
3357
|
+
87,
|
|
3358
|
+
131,
|
|
3359
|
+
165,
|
|
3360
|
+
189,
|
|
3361
|
+
217,
|
|
3362
|
+
92,
|
|
3363
|
+
205,
|
|
3364
|
+
209,
|
|
3365
|
+
74,
|
|
3366
|
+
169
|
|
3367
|
+
]);
|
|
3368
|
+
//#endregion
|
|
3369
|
+
//#region ../../node_modules/.pnpm/fastembed@2.1.0_patch_hash=_4a3963818389bb02f958df692b27c167/node_modules/fastembed/lib/esm/fastembed.js
|
|
3370
|
+
var ExecutionProvider;
|
|
3371
|
+
(function(ExecutionProvider) {
|
|
3372
|
+
ExecutionProvider["CPU"] = "cpu";
|
|
3373
|
+
ExecutionProvider["CUDA"] = "cuda";
|
|
3374
|
+
ExecutionProvider["WebGL"] = "webgl";
|
|
3375
|
+
ExecutionProvider["WASM"] = "wasm";
|
|
3376
|
+
ExecutionProvider["XNNPACK"] = "xnnpack";
|
|
3377
|
+
})(ExecutionProvider || (ExecutionProvider = {}));
|
|
3378
|
+
var EmbeddingModel;
|
|
3379
|
+
(function(EmbeddingModel) {
|
|
3380
|
+
EmbeddingModel["AllMiniLML6V2"] = "fast-all-MiniLM-L6-v2";
|
|
3381
|
+
EmbeddingModel["BGEBaseEN"] = "fast-bge-base-en";
|
|
3382
|
+
EmbeddingModel["BGEBaseENV15"] = "fast-bge-base-en-v1.5";
|
|
3383
|
+
EmbeddingModel["BGESmallEN"] = "fast-bge-small-en";
|
|
3384
|
+
EmbeddingModel["BGESmallENV15"] = "fast-bge-small-en-v1.5";
|
|
3385
|
+
EmbeddingModel["BGESmallZH"] = "fast-bge-small-zh-v1.5";
|
|
3386
|
+
EmbeddingModel["MLE5Large"] = "fast-multilingual-e5-large";
|
|
3387
|
+
EmbeddingModel["CUSTOM"] = "custom";
|
|
3388
|
+
})(EmbeddingModel || (EmbeddingModel = {}));
|
|
3389
|
+
var SparseEmbeddingModel;
|
|
3390
|
+
(function(SparseEmbeddingModel) {
|
|
3391
|
+
SparseEmbeddingModel["SpladePPEnV1"] = "prithivida/Splade_PP_en_v1";
|
|
3392
|
+
SparseEmbeddingModel["CUSTOM"] = "custom";
|
|
3393
|
+
})(SparseEmbeddingModel || (SparseEmbeddingModel = {}));
|
|
3394
|
+
function normalize(v) {
|
|
3395
|
+
const norm = Math.sqrt(v.reduce((acc, val) => acc + val * val, 0));
|
|
3396
|
+
const epsilon = 1e-12;
|
|
3397
|
+
return v.map((val) => val / Math.max(norm, epsilon));
|
|
3398
|
+
}
|
|
3399
|
+
function getEmbeddings(data, dimensions) {
|
|
3400
|
+
const [x, y, z] = dimensions;
|
|
3401
|
+
return new Array(x).fill(void 0).map((_, index) => {
|
|
3402
|
+
const startIndex = index * y * z;
|
|
3403
|
+
const endIndex = startIndex + z;
|
|
3404
|
+
return data.slice(startIndex, endIndex);
|
|
3405
|
+
});
|
|
3406
|
+
}
|
|
3407
|
+
var Embedding = class {};
|
|
3408
|
+
var FlagEmbedding = class FlagEmbedding extends Embedding {
|
|
3409
|
+
constructor(tokenizer, session, model) {
|
|
3410
|
+
super();
|
|
3411
|
+
this.tokenizer = tokenizer;
|
|
3412
|
+
this.session = session;
|
|
3413
|
+
this.model = model;
|
|
3414
|
+
}
|
|
3415
|
+
static async init({ model = EmbeddingModel.BGESmallENV15, executionProviders = [ExecutionProvider.CPU], maxLength = 512, cacheDir = "local_cache", showDownloadProgress = true, modelAbsoluteDirPath = "", modelName = "" } = {}) {
|
|
3416
|
+
if (model === EmbeddingModel.CUSTOM) {
|
|
3417
|
+
if (!modelAbsoluteDirPath) throw new Error("For custom model, modelAbsoluteDirPath is required in FlagEmbedding.init");
|
|
3418
|
+
if (!modelName) throw new Error("For custom model, modelName is required in FlagEmbedding.init");
|
|
3419
|
+
}
|
|
3420
|
+
const modelDir = model === EmbeddingModel.CUSTOM ? modelAbsoluteDirPath : await FlagEmbedding.retrieveModel(model, cacheDir, showDownloadProgress);
|
|
3421
|
+
const tokenizer = this.loadTokenizer(modelDir, maxLength);
|
|
3422
|
+
const defaultModelName = model === EmbeddingModel.MLE5Large || model === EmbeddingModel.AllMiniLML6V2 ? "model.onnx" : "model_optimized.onnx";
|
|
3423
|
+
const modelPath = path.join(modelDir.toString(), modelName || defaultModelName);
|
|
3424
|
+
if (!fs.existsSync(modelPath)) throw new Error(`Model file not found at ${modelPath}`);
|
|
3425
|
+
return new FlagEmbedding(tokenizer, await import_dist.InferenceSession.create(modelPath, {
|
|
3426
|
+
executionProviders,
|
|
3427
|
+
graphOptimizationLevel: "all"
|
|
3428
|
+
}), model);
|
|
3429
|
+
}
|
|
3430
|
+
static loadTokenizer(modelDir, maxLength) {
|
|
3431
|
+
const tokenizerPath = path.join(modelDir.toString(), "tokenizer.json");
|
|
3432
|
+
if (!fs.existsSync(tokenizerPath)) throw new Error(`Tokenizer file not found at ${tokenizerPath}`);
|
|
3433
|
+
const configPath = path.join(modelDir.toString(), "config.json");
|
|
3434
|
+
if (!fs.existsSync(configPath)) throw new Error(`Config file not found at ${configPath}`);
|
|
3435
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
3436
|
+
const tokenizerFilePath = path.join(modelDir.toString(), "tokenizer_config.json");
|
|
3437
|
+
if (!fs.existsSync(tokenizerFilePath)) throw new Error(`Tokenizer file not found at ${tokenizerFilePath}`);
|
|
3438
|
+
const tokenizerConfig = JSON.parse(fs.readFileSync(tokenizerFilePath, "utf-8"));
|
|
3439
|
+
maxLength = Math.min(maxLength, tokenizerConfig["model_max_length"]);
|
|
3440
|
+
const tokensMapPath = path.join(modelDir.toString(), "special_tokens_map.json");
|
|
3441
|
+
if (!fs.existsSync(tokensMapPath)) throw new Error(`Tokens map file not found at ${tokensMapPath}`);
|
|
3442
|
+
const tokensMap = JSON.parse(fs.readFileSync(tokensMapPath, "utf-8"));
|
|
3443
|
+
const tokenizer = import_tokenizers.Tokenizer.fromFile(tokenizerPath);
|
|
3444
|
+
tokenizer.setTruncation(maxLength);
|
|
3445
|
+
tokenizer.setPadding({
|
|
3446
|
+
maxLength,
|
|
3447
|
+
padId: config["pad_token_id"],
|
|
3448
|
+
padToken: tokenizerConfig["pad_token"]
|
|
3449
|
+
});
|
|
3450
|
+
for (let token of Object.values(tokensMap)) if (typeof token === "string") tokenizer.addSpecialTokens([token]);
|
|
3451
|
+
else if (isAddedTokenMap(token)) {
|
|
3452
|
+
const addedToken = new import_tokenizers.AddedToken(token["content"], true, {
|
|
3453
|
+
singleWord: token["single_word"],
|
|
3454
|
+
leftStrip: token["lstrip"],
|
|
3455
|
+
rightStrip: token["rstrip"],
|
|
3456
|
+
normalized: token["normalized"]
|
|
3457
|
+
});
|
|
3458
|
+
tokenizer.addAddedTokens([addedToken]);
|
|
3459
|
+
}
|
|
3460
|
+
return tokenizer;
|
|
3461
|
+
}
|
|
3462
|
+
static async downloadFileFromGCS(outputFilePath, model, showDownloadProgress = true) {
|
|
3463
|
+
if (fs.existsSync(outputFilePath)) return outputFilePath;
|
|
3464
|
+
if (model === EmbeddingModel.AllMiniLML6V2) model = "sentence-transformers" + model.substring(model.indexOf("-"));
|
|
3465
|
+
const url = `https://storage.googleapis.com/qdrant-fastembed/${model}.tar.gz`;
|
|
3466
|
+
const fileStream = fs.createWriteStream(outputFilePath);
|
|
3467
|
+
return new Promise((resolve, reject) => {
|
|
3468
|
+
https.get(url, { headers: { "User-Agent": "Mozilla/5.0" } }, (response) => {
|
|
3469
|
+
const totalSizeInBytes = parseInt(response.headers["content-length"] || "0", 10);
|
|
3470
|
+
if (totalSizeInBytes === 0) console.warn(`Warning: Content-length header is missing or zero in the response from ${url}.`);
|
|
3471
|
+
if (showDownloadProgress) {
|
|
3472
|
+
const progressBar = new import_progress.default(`Downloading ${model} [:bar] :percent :etas`, {
|
|
3473
|
+
complete: "=",
|
|
3474
|
+
width: 20,
|
|
3475
|
+
total: totalSizeInBytes
|
|
3476
|
+
});
|
|
3477
|
+
response.on("data", (chunk) => {
|
|
3478
|
+
progressBar.tick(chunk.length, { speed: "N/A" });
|
|
3479
|
+
});
|
|
3480
|
+
}
|
|
3481
|
+
response.on("error", (error) => {
|
|
3482
|
+
reject(error);
|
|
3483
|
+
});
|
|
3484
|
+
response.pipe(fileStream);
|
|
3485
|
+
fileStream.on("finish", () => {
|
|
3486
|
+
fileStream.close();
|
|
3487
|
+
resolve(outputFilePath);
|
|
3488
|
+
});
|
|
3489
|
+
fileStream.on("error", (error) => {
|
|
3490
|
+
reject(error);
|
|
3491
|
+
});
|
|
3492
|
+
}).on("error", (error) => {
|
|
3493
|
+
fs.unlink(outputFilePath, () => {
|
|
3494
|
+
reject(error);
|
|
3495
|
+
});
|
|
3496
|
+
});
|
|
3497
|
+
});
|
|
3498
|
+
}
|
|
3499
|
+
static async decompressToCache(targzPath, cacheDir) {
|
|
3500
|
+
if (path.extname(targzPath.toString()) === ".gz") await uo({
|
|
3501
|
+
file: targzPath,
|
|
3502
|
+
cwd: cacheDir
|
|
3503
|
+
});
|
|
3504
|
+
else throw new Error(`Unsupported file extension: ${targzPath}`);
|
|
3505
|
+
}
|
|
3506
|
+
static async retrieveModel(model, cacheDir, showDownloadProgress = true) {
|
|
3507
|
+
if (!fs.existsSync(cacheDir)) fs.mkdirSync(cacheDir, { mode: 511 });
|
|
3508
|
+
const modelDir = path.join(cacheDir.toString(), model);
|
|
3509
|
+
if (fs.existsSync(modelDir)) return modelDir;
|
|
3510
|
+
const modelTarGz = path.join(cacheDir.toString(), `${model}.tar.gz`);
|
|
3511
|
+
await this.downloadFileFromGCS(modelTarGz, model, showDownloadProgress);
|
|
3512
|
+
await this.decompressToCache(modelTarGz, cacheDir);
|
|
3513
|
+
fs.unlinkSync(modelTarGz);
|
|
3514
|
+
return modelDir;
|
|
3515
|
+
}
|
|
3516
|
+
async *embed(textStrings, batchSize = 256) {
|
|
3517
|
+
for (let i = 0; i < textStrings.length; i += batchSize) {
|
|
3518
|
+
const batchTexts = textStrings.slice(i, i + batchSize);
|
|
3519
|
+
const encodedTexts = await Promise.all(batchTexts.map((textString) => this.tokenizer.encode(textString)));
|
|
3520
|
+
const idsArray = [];
|
|
3521
|
+
const maskArray = [];
|
|
3522
|
+
const typeIdsArray = [];
|
|
3523
|
+
encodedTexts.forEach((text) => {
|
|
3524
|
+
const ids = text.getIds().map(BigInt);
|
|
3525
|
+
const mask = text.getAttentionMask().map(BigInt);
|
|
3526
|
+
const typeIds = text.getTypeIds().map(BigInt);
|
|
3527
|
+
idsArray.push(ids);
|
|
3528
|
+
maskArray.push(mask);
|
|
3529
|
+
typeIdsArray.push(typeIds);
|
|
3530
|
+
});
|
|
3531
|
+
const maxLength = idsArray[0].length;
|
|
3532
|
+
const inputs = {
|
|
3533
|
+
input_ids: new import_dist.Tensor("int64", idsArray.flat(), [batchTexts.length, maxLength]),
|
|
3534
|
+
attention_mask: new import_dist.Tensor("int64", maskArray.flat(), [batchTexts.length, maxLength]),
|
|
3535
|
+
token_type_ids: new import_dist.Tensor("int64", typeIdsArray.flat(), [batchTexts.length, maxLength])
|
|
3536
|
+
};
|
|
3537
|
+
if (this.model === EmbeddingModel.MLE5Large) delete inputs.token_type_ids;
|
|
3538
|
+
const output = await this.session.run(inputs);
|
|
3539
|
+
yield getEmbeddings(output.last_hidden_state.data, output.last_hidden_state.dims).map(normalize);
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
passageEmbed(texts, batchSize = 256) {
|
|
3543
|
+
texts = texts.map((text) => `passage: ${text}`);
|
|
3544
|
+
return this.embed(texts, batchSize);
|
|
3545
|
+
}
|
|
3546
|
+
async queryEmbed(query) {
|
|
3547
|
+
return (await this.embed([`query: ${query}`]).next()).value[0];
|
|
3548
|
+
}
|
|
3549
|
+
listSupportedModels() {
|
|
3550
|
+
return [
|
|
3551
|
+
{
|
|
3552
|
+
model: EmbeddingModel.BGESmallEN,
|
|
3553
|
+
dim: 384,
|
|
3554
|
+
description: "Fast English model"
|
|
3555
|
+
},
|
|
3556
|
+
{
|
|
3557
|
+
model: EmbeddingModel.BGESmallENV15,
|
|
3558
|
+
dim: 384,
|
|
3559
|
+
description: "v1.5 release of the fast, default English model"
|
|
3560
|
+
},
|
|
3561
|
+
{
|
|
3562
|
+
model: EmbeddingModel.BGEBaseEN,
|
|
3563
|
+
dim: 768,
|
|
3564
|
+
description: "Base English model"
|
|
3565
|
+
},
|
|
3566
|
+
{
|
|
3567
|
+
model: EmbeddingModel.BGEBaseENV15,
|
|
3568
|
+
dim: 768,
|
|
3569
|
+
description: "v1.5 release of Base English model"
|
|
3570
|
+
},
|
|
3571
|
+
{
|
|
3572
|
+
model: EmbeddingModel.BGESmallZH,
|
|
3573
|
+
dim: 512,
|
|
3574
|
+
description: "v1.5 release of the fast, Chinese model"
|
|
3575
|
+
},
|
|
3576
|
+
{
|
|
3577
|
+
model: EmbeddingModel.AllMiniLML6V2,
|
|
3578
|
+
dim: 384,
|
|
3579
|
+
description: "Sentence Transformer model, MiniLM-L6-v2"
|
|
3580
|
+
},
|
|
3581
|
+
{
|
|
3582
|
+
model: EmbeddingModel.MLE5Large,
|
|
3583
|
+
dim: 1024,
|
|
3584
|
+
description: "Multilingual model, e5-large. Recommend using this model for non-English languages"
|
|
3585
|
+
}
|
|
3586
|
+
];
|
|
3587
|
+
}
|
|
3588
|
+
};
|
|
3589
|
+
function isAddedTokenMap(token) {
|
|
3590
|
+
return typeof token === "object" && token !== null && "token" in token && "single_word" in token && "rstrip" in token && "lstrip" in token && "normalized" in token;
|
|
3591
|
+
}
|
|
3592
|
+
//#endregion
|
|
3593
|
+
export { EmbeddingModel, FlagEmbedding };
|