lingo.dev 0.63.2 → 0.70.2
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/LICENSE.md +201 -0
- package/bin/cli.mjs +3 -1
- package/build/acorn-7GKKTQAZ.mjs +3047 -0
- package/build/acorn-C2XWIPGO.cjs +3047 -0
- package/build/angular-5ISIBFBY.mjs +2794 -0
- package/build/angular-XQHAJDB2.cjs +2794 -0
- package/build/api-7PZYRHW3.mjs +5 -0
- package/build/api-C35FHFLD.cjs +7 -0
- package/build/babel-DSN33ILH.cjs +6946 -0
- package/build/babel-ZNMMF5TX.mjs +6946 -0
- package/build/chunk-2AI774XU.cjs +130086 -0
- package/build/chunk-DAMIL4EZ.mjs +4533 -0
- package/build/chunk-HEBXNMVQ.mjs +48 -0
- package/build/chunk-IKCNLHD5.cjs +4533 -0
- package/build/chunk-L5BCMCQE.cjs +48 -0
- package/build/chunk-MUWDGJF2.mjs +962 -0
- package/build/chunk-XFD3AFWA.mjs +130086 -0
- package/build/chunk-ZXT7SLL5.cjs +962 -0
- package/build/cli.cjs +134752 -0
- package/build/cli.d.cts +3 -0
- package/build/cli.d.ts +3 -0
- package/build/cli.mjs +134745 -0
- package/build/estree-2CSK435T.mjs +4374 -0
- package/build/estree-N7T576SJ.cjs +4374 -0
- package/build/flow-IBTCTNRO.mjs +26897 -0
- package/build/flow-Y3OXWML5.cjs +26897 -0
- package/build/glimmer-FCD5RY7E.mjs +2847 -0
- package/build/glimmer-N5YT5DMK.cjs +2847 -0
- package/build/graphql-4DMZI42L.mjs +1247 -0
- package/build/graphql-GV4OMB3Z.cjs +1247 -0
- package/build/html-RNXFERLB.mjs +2716 -0
- package/build/html-XMA5LP2U.cjs +2716 -0
- package/build/markdown-6BIFNHAV.mjs +3484 -0
- package/build/markdown-LUUZAIEE.cjs +3484 -0
- package/build/meriyah-IV6VMAUC.mjs +2474 -0
- package/build/meriyah-XSJDPEN3.cjs +2474 -0
- package/build/postcss-PDIS5YQZ.cjs +5057 -0
- package/build/postcss-SDQEBDMO.mjs +5057 -0
- package/build/sdk.cjs +8 -0
- package/build/sdk.d.cts +1 -0
- package/build/sdk.d.ts +1 -0
- package/build/sdk.mjs +8 -0
- package/build/spec.cjs +47 -0
- package/build/spec.d.cts +1 -0
- package/build/spec.d.ts +1 -0
- package/build/spec.mjs +47 -0
- package/build/typescript-TT5RRHSS.cjs +13104 -0
- package/build/typescript-U5HXARXA.mjs +13104 -0
- package/build/yaml-6ITWGIVF.cjs +4223 -0
- package/build/yaml-DDDZYPIN.mjs +4223 -0
- package/package.json +31 -9
- package/readme.md +5 -16
- package/build/react-next.cjs +0 -2
- package/build/react-next.d.cts +0 -1
- package/build/react-next.d.ts +0 -1
- package/build/react-next.mjs +0 -2
- package/build/react.cjs +0 -2
- package/build/react.d.cts +0 -2
- package/build/react.d.ts +0 -2
- package/build/react.mjs +0 -2
- package/content/banner.png +0 -0
|
@@ -0,0 +1,962 @@
|
|
|
1
|
+
import {
|
|
2
|
+
localeCodeSchema,
|
|
3
|
+
z
|
|
4
|
+
} from "./chunk-DAMIL4EZ.mjs";
|
|
5
|
+
import {
|
|
6
|
+
__commonJS,
|
|
7
|
+
__require,
|
|
8
|
+
__toESM
|
|
9
|
+
} from "./chunk-HEBXNMVQ.mjs";
|
|
10
|
+
|
|
11
|
+
// ../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/_assert.js
|
|
12
|
+
var require_assert = __commonJS({
|
|
13
|
+
"../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/_assert.js"(exports) {
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.isBytes = isBytes;
|
|
17
|
+
exports.number = number;
|
|
18
|
+
exports.bool = bool;
|
|
19
|
+
exports.bytes = bytes;
|
|
20
|
+
exports.hash = hash;
|
|
21
|
+
exports.exists = exists;
|
|
22
|
+
exports.output = output;
|
|
23
|
+
function number(n) {
|
|
24
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
25
|
+
throw new Error(`positive integer expected, not ${n}`);
|
|
26
|
+
}
|
|
27
|
+
function bool(b) {
|
|
28
|
+
if (typeof b !== "boolean")
|
|
29
|
+
throw new Error(`boolean expected, not ${b}`);
|
|
30
|
+
}
|
|
31
|
+
function isBytes(a) {
|
|
32
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
|
33
|
+
}
|
|
34
|
+
function bytes(b, ...lengths) {
|
|
35
|
+
if (!isBytes(b))
|
|
36
|
+
throw new Error("Uint8Array expected");
|
|
37
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
38
|
+
throw new Error(`Uint8Array expected of length ${lengths}, not of length=${b.length}`);
|
|
39
|
+
}
|
|
40
|
+
function hash(h) {
|
|
41
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
42
|
+
throw new Error("Hash should be wrapped by utils.wrapConstructor");
|
|
43
|
+
number(h.outputLen);
|
|
44
|
+
number(h.blockLen);
|
|
45
|
+
}
|
|
46
|
+
function exists(instance, checkFinished = true) {
|
|
47
|
+
if (instance.destroyed)
|
|
48
|
+
throw new Error("Hash instance has been destroyed");
|
|
49
|
+
if (checkFinished && instance.finished)
|
|
50
|
+
throw new Error("Hash#digest() has already been called");
|
|
51
|
+
}
|
|
52
|
+
function output(out, instance) {
|
|
53
|
+
bytes(out);
|
|
54
|
+
const min = instance.outputLen;
|
|
55
|
+
if (out.length < min) {
|
|
56
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
var assert = { number, bool, bytes, hash, exists, output };
|
|
60
|
+
exports.default = assert;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/_u64.js
|
|
65
|
+
var require_u64 = __commonJS({
|
|
66
|
+
"../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/_u64.js"(exports) {
|
|
67
|
+
"use strict";
|
|
68
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
exports.add5L = exports.add5H = exports.add4H = exports.add4L = exports.add3H = exports.add3L = exports.rotlBL = exports.rotlBH = exports.rotlSL = exports.rotlSH = exports.rotr32L = exports.rotr32H = exports.rotrBL = exports.rotrBH = exports.rotrSL = exports.rotrSH = exports.shrSL = exports.shrSH = exports.toBig = void 0;
|
|
70
|
+
exports.fromBig = fromBig;
|
|
71
|
+
exports.split = split;
|
|
72
|
+
exports.add = add;
|
|
73
|
+
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
74
|
+
var _32n = /* @__PURE__ */ BigInt(32);
|
|
75
|
+
function fromBig(n, le = false) {
|
|
76
|
+
if (le)
|
|
77
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
78
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
79
|
+
}
|
|
80
|
+
function split(lst, le = false) {
|
|
81
|
+
let Ah = new Uint32Array(lst.length);
|
|
82
|
+
let Al = new Uint32Array(lst.length);
|
|
83
|
+
for (let i = 0; i < lst.length; i++) {
|
|
84
|
+
const { h, l } = fromBig(lst[i], le);
|
|
85
|
+
[Ah[i], Al[i]] = [h, l];
|
|
86
|
+
}
|
|
87
|
+
return [Ah, Al];
|
|
88
|
+
}
|
|
89
|
+
var toBig = (h, l) => BigInt(h >>> 0) << _32n | BigInt(l >>> 0);
|
|
90
|
+
exports.toBig = toBig;
|
|
91
|
+
var shrSH = (h, _l, s) => h >>> s;
|
|
92
|
+
exports.shrSH = shrSH;
|
|
93
|
+
var shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
94
|
+
exports.shrSL = shrSL;
|
|
95
|
+
var rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
96
|
+
exports.rotrSH = rotrSH;
|
|
97
|
+
var rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
98
|
+
exports.rotrSL = rotrSL;
|
|
99
|
+
var rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
100
|
+
exports.rotrBH = rotrBH;
|
|
101
|
+
var rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
102
|
+
exports.rotrBL = rotrBL;
|
|
103
|
+
var rotr32H = (_h, l) => l;
|
|
104
|
+
exports.rotr32H = rotr32H;
|
|
105
|
+
var rotr32L = (h, _l) => h;
|
|
106
|
+
exports.rotr32L = rotr32L;
|
|
107
|
+
var rotlSH = (h, l, s) => h << s | l >>> 32 - s;
|
|
108
|
+
exports.rotlSH = rotlSH;
|
|
109
|
+
var rotlSL = (h, l, s) => l << s | h >>> 32 - s;
|
|
110
|
+
exports.rotlSL = rotlSL;
|
|
111
|
+
var rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
|
|
112
|
+
exports.rotlBH = rotlBH;
|
|
113
|
+
var rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
|
|
114
|
+
exports.rotlBL = rotlBL;
|
|
115
|
+
function add(Ah, Al, Bh, Bl) {
|
|
116
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
117
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
118
|
+
}
|
|
119
|
+
var add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
120
|
+
exports.add3L = add3L;
|
|
121
|
+
var add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
122
|
+
exports.add3H = add3H;
|
|
123
|
+
var add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
124
|
+
exports.add4L = add4L;
|
|
125
|
+
var add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
126
|
+
exports.add4H = add4H;
|
|
127
|
+
var add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
128
|
+
exports.add5L = add5L;
|
|
129
|
+
var add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
130
|
+
exports.add5H = add5H;
|
|
131
|
+
var u64 = {
|
|
132
|
+
fromBig,
|
|
133
|
+
split,
|
|
134
|
+
toBig,
|
|
135
|
+
shrSH,
|
|
136
|
+
shrSL,
|
|
137
|
+
rotrSH,
|
|
138
|
+
rotrSL,
|
|
139
|
+
rotrBH,
|
|
140
|
+
rotrBL,
|
|
141
|
+
rotr32H,
|
|
142
|
+
rotr32L,
|
|
143
|
+
rotlSH,
|
|
144
|
+
rotlSL,
|
|
145
|
+
rotlBH,
|
|
146
|
+
rotlBL,
|
|
147
|
+
add,
|
|
148
|
+
add3L,
|
|
149
|
+
add3H,
|
|
150
|
+
add4L,
|
|
151
|
+
add4H,
|
|
152
|
+
add5H,
|
|
153
|
+
add5L
|
|
154
|
+
};
|
|
155
|
+
exports.default = u64;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// ../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/cryptoNode.js
|
|
160
|
+
var require_cryptoNode = __commonJS({
|
|
161
|
+
"../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/cryptoNode.js"(exports) {
|
|
162
|
+
"use strict";
|
|
163
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
164
|
+
exports.crypto = void 0;
|
|
165
|
+
var nc = __require("node:crypto");
|
|
166
|
+
exports.crypto = nc && typeof nc === "object" && "webcrypto" in nc ? nc.webcrypto : nc && typeof nc === "object" && "randomBytes" in nc ? nc : void 0;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// ../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/utils.js
|
|
171
|
+
var require_utils = __commonJS({
|
|
172
|
+
"../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/utils.js"(exports) {
|
|
173
|
+
"use strict";
|
|
174
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
175
|
+
exports.Hash = exports.nextTick = exports.byteSwapIfBE = exports.byteSwap = exports.isLE = exports.rotl = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
|
|
176
|
+
exports.isBytes = isBytes;
|
|
177
|
+
exports.byteSwap32 = byteSwap32;
|
|
178
|
+
exports.bytesToHex = bytesToHex;
|
|
179
|
+
exports.hexToBytes = hexToBytes;
|
|
180
|
+
exports.asyncLoop = asyncLoop;
|
|
181
|
+
exports.utf8ToBytes = utf8ToBytes;
|
|
182
|
+
exports.toBytes = toBytes;
|
|
183
|
+
exports.concatBytes = concatBytes;
|
|
184
|
+
exports.checkOpts = checkOpts;
|
|
185
|
+
exports.wrapConstructor = wrapConstructor;
|
|
186
|
+
exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
|
|
187
|
+
exports.wrapXOFConstructorWithOpts = wrapXOFConstructorWithOpts;
|
|
188
|
+
exports.randomBytes = randomBytes;
|
|
189
|
+
var crypto_1 = require_cryptoNode();
|
|
190
|
+
var _assert_js_1 = require_assert();
|
|
191
|
+
function isBytes(a) {
|
|
192
|
+
return a instanceof Uint8Array || a != null && typeof a === "object" && a.constructor.name === "Uint8Array";
|
|
193
|
+
}
|
|
194
|
+
var u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
195
|
+
exports.u8 = u8;
|
|
196
|
+
var u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
197
|
+
exports.u32 = u32;
|
|
198
|
+
var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
199
|
+
exports.createView = createView;
|
|
200
|
+
var rotr = (word, shift) => word << 32 - shift | word >>> shift;
|
|
201
|
+
exports.rotr = rotr;
|
|
202
|
+
var rotl = (word, shift) => word << shift | word >>> 32 - shift >>> 0;
|
|
203
|
+
exports.rotl = rotl;
|
|
204
|
+
exports.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
|
205
|
+
var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
206
|
+
exports.byteSwap = byteSwap;
|
|
207
|
+
exports.byteSwapIfBE = exports.isLE ? (n) => n : (n) => (0, exports.byteSwap)(n);
|
|
208
|
+
function byteSwap32(arr) {
|
|
209
|
+
for (let i = 0; i < arr.length; i++) {
|
|
210
|
+
arr[i] = (0, exports.byteSwap)(arr[i]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
214
|
+
function bytesToHex(bytes) {
|
|
215
|
+
(0, _assert_js_1.bytes)(bytes);
|
|
216
|
+
let hex = "";
|
|
217
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
218
|
+
hex += hexes[bytes[i]];
|
|
219
|
+
}
|
|
220
|
+
return hex;
|
|
221
|
+
}
|
|
222
|
+
var asciis = { _0: 48, _9: 57, _A: 65, _F: 70, _a: 97, _f: 102 };
|
|
223
|
+
function asciiToBase16(char) {
|
|
224
|
+
if (char >= asciis._0 && char <= asciis._9)
|
|
225
|
+
return char - asciis._0;
|
|
226
|
+
if (char >= asciis._A && char <= asciis._F)
|
|
227
|
+
return char - (asciis._A - 10);
|
|
228
|
+
if (char >= asciis._a && char <= asciis._f)
|
|
229
|
+
return char - (asciis._a - 10);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
function hexToBytes(hex) {
|
|
233
|
+
if (typeof hex !== "string")
|
|
234
|
+
throw new Error("hex string expected, got " + typeof hex);
|
|
235
|
+
const hl = hex.length;
|
|
236
|
+
const al = hl / 2;
|
|
237
|
+
if (hl % 2)
|
|
238
|
+
throw new Error("padded hex string expected, got unpadded hex of length " + hl);
|
|
239
|
+
const array = new Uint8Array(al);
|
|
240
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
241
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
|
242
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
|
243
|
+
if (n1 === void 0 || n2 === void 0) {
|
|
244
|
+
const char = hex[hi] + hex[hi + 1];
|
|
245
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
246
|
+
}
|
|
247
|
+
array[ai] = n1 * 16 + n2;
|
|
248
|
+
}
|
|
249
|
+
return array;
|
|
250
|
+
}
|
|
251
|
+
var nextTick = async () => {
|
|
252
|
+
};
|
|
253
|
+
exports.nextTick = nextTick;
|
|
254
|
+
async function asyncLoop(iters, tick, cb) {
|
|
255
|
+
let ts = Date.now();
|
|
256
|
+
for (let i = 0; i < iters; i++) {
|
|
257
|
+
cb(i);
|
|
258
|
+
const diff = Date.now() - ts;
|
|
259
|
+
if (diff >= 0 && diff < tick)
|
|
260
|
+
continue;
|
|
261
|
+
await (0, exports.nextTick)();
|
|
262
|
+
ts += diff;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function utf8ToBytes(str) {
|
|
266
|
+
if (typeof str !== "string")
|
|
267
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
268
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
269
|
+
}
|
|
270
|
+
function toBytes(data) {
|
|
271
|
+
if (typeof data === "string")
|
|
272
|
+
data = utf8ToBytes(data);
|
|
273
|
+
(0, _assert_js_1.bytes)(data);
|
|
274
|
+
return data;
|
|
275
|
+
}
|
|
276
|
+
function concatBytes(...arrays) {
|
|
277
|
+
let sum = 0;
|
|
278
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
279
|
+
const a = arrays[i];
|
|
280
|
+
(0, _assert_js_1.bytes)(a);
|
|
281
|
+
sum += a.length;
|
|
282
|
+
}
|
|
283
|
+
const res = new Uint8Array(sum);
|
|
284
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
285
|
+
const a = arrays[i];
|
|
286
|
+
res.set(a, pad);
|
|
287
|
+
pad += a.length;
|
|
288
|
+
}
|
|
289
|
+
return res;
|
|
290
|
+
}
|
|
291
|
+
var Hash = class {
|
|
292
|
+
// Safe version that clones internal state
|
|
293
|
+
clone() {
|
|
294
|
+
return this._cloneInto();
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
exports.Hash = Hash;
|
|
298
|
+
var toStr = {}.toString;
|
|
299
|
+
function checkOpts(defaults, opts) {
|
|
300
|
+
if (opts !== void 0 && toStr.call(opts) !== "[object Object]")
|
|
301
|
+
throw new Error("Options should be object or undefined");
|
|
302
|
+
const merged = Object.assign(defaults, opts);
|
|
303
|
+
return merged;
|
|
304
|
+
}
|
|
305
|
+
function wrapConstructor(hashCons) {
|
|
306
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
307
|
+
const tmp = hashCons();
|
|
308
|
+
hashC.outputLen = tmp.outputLen;
|
|
309
|
+
hashC.blockLen = tmp.blockLen;
|
|
310
|
+
hashC.create = () => hashCons();
|
|
311
|
+
return hashC;
|
|
312
|
+
}
|
|
313
|
+
function wrapConstructorWithOpts(hashCons) {
|
|
314
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
315
|
+
const tmp = hashCons({});
|
|
316
|
+
hashC.outputLen = tmp.outputLen;
|
|
317
|
+
hashC.blockLen = tmp.blockLen;
|
|
318
|
+
hashC.create = (opts) => hashCons(opts);
|
|
319
|
+
return hashC;
|
|
320
|
+
}
|
|
321
|
+
function wrapXOFConstructorWithOpts(hashCons) {
|
|
322
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
323
|
+
const tmp = hashCons({});
|
|
324
|
+
hashC.outputLen = tmp.outputLen;
|
|
325
|
+
hashC.blockLen = tmp.blockLen;
|
|
326
|
+
hashC.create = (opts) => hashCons(opts);
|
|
327
|
+
return hashC;
|
|
328
|
+
}
|
|
329
|
+
function randomBytes(bytesLength = 32) {
|
|
330
|
+
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
|
|
331
|
+
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
332
|
+
}
|
|
333
|
+
if (crypto_1.crypto && typeof crypto_1.crypto.randomBytes === "function") {
|
|
334
|
+
return crypto_1.crypto.randomBytes(bytesLength);
|
|
335
|
+
}
|
|
336
|
+
throw new Error("crypto.getRandomValues must be defined");
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// ../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/sha3.js
|
|
342
|
+
var require_sha3 = __commonJS({
|
|
343
|
+
"../node_modules/.pnpm/@noble+hashes@1.5.0/node_modules/@noble/hashes/sha3.js"(exports) {
|
|
344
|
+
"use strict";
|
|
345
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
346
|
+
exports.shake256 = exports.shake128 = exports.keccak_512 = exports.keccak_384 = exports.keccak_256 = exports.keccak_224 = exports.sha3_512 = exports.sha3_384 = exports.sha3_256 = exports.sha3_224 = exports.Keccak = void 0;
|
|
347
|
+
exports.keccakP = keccakP;
|
|
348
|
+
var _assert_js_1 = require_assert();
|
|
349
|
+
var _u64_js_1 = require_u64();
|
|
350
|
+
var utils_js_1 = require_utils();
|
|
351
|
+
var SHA3_PI = [];
|
|
352
|
+
var SHA3_ROTL = [];
|
|
353
|
+
var _SHA3_IOTA = [];
|
|
354
|
+
var _0n = /* @__PURE__ */ BigInt(0);
|
|
355
|
+
var _1n = /* @__PURE__ */ BigInt(1);
|
|
356
|
+
var _2n = /* @__PURE__ */ BigInt(2);
|
|
357
|
+
var _7n = /* @__PURE__ */ BigInt(7);
|
|
358
|
+
var _256n = /* @__PURE__ */ BigInt(256);
|
|
359
|
+
var _0x71n = /* @__PURE__ */ BigInt(113);
|
|
360
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
|
361
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
362
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
363
|
+
SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
|
|
364
|
+
let t = _0n;
|
|
365
|
+
for (let j = 0; j < 7; j++) {
|
|
366
|
+
R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
|
|
367
|
+
if (R & _2n)
|
|
368
|
+
t ^= _1n << (_1n << /* @__PURE__ */ BigInt(j)) - _1n;
|
|
369
|
+
}
|
|
370
|
+
_SHA3_IOTA.push(t);
|
|
371
|
+
}
|
|
372
|
+
var [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ (0, _u64_js_1.split)(_SHA3_IOTA, true);
|
|
373
|
+
var rotlH = (h, l, s) => s > 32 ? (0, _u64_js_1.rotlBH)(h, l, s) : (0, _u64_js_1.rotlSH)(h, l, s);
|
|
374
|
+
var rotlL = (h, l, s) => s > 32 ? (0, _u64_js_1.rotlBL)(h, l, s) : (0, _u64_js_1.rotlSL)(h, l, s);
|
|
375
|
+
function keccakP(s, rounds = 24) {
|
|
376
|
+
const B = new Uint32Array(5 * 2);
|
|
377
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
378
|
+
for (let x = 0; x < 10; x++)
|
|
379
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
380
|
+
for (let x = 0; x < 10; x += 2) {
|
|
381
|
+
const idx1 = (x + 8) % 10;
|
|
382
|
+
const idx0 = (x + 2) % 10;
|
|
383
|
+
const B0 = B[idx0];
|
|
384
|
+
const B1 = B[idx0 + 1];
|
|
385
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
386
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
387
|
+
for (let y = 0; y < 50; y += 10) {
|
|
388
|
+
s[x + y] ^= Th;
|
|
389
|
+
s[x + y + 1] ^= Tl;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
let curH = s[2];
|
|
393
|
+
let curL = s[3];
|
|
394
|
+
for (let t = 0; t < 24; t++) {
|
|
395
|
+
const shift = SHA3_ROTL[t];
|
|
396
|
+
const Th = rotlH(curH, curL, shift);
|
|
397
|
+
const Tl = rotlL(curH, curL, shift);
|
|
398
|
+
const PI = SHA3_PI[t];
|
|
399
|
+
curH = s[PI];
|
|
400
|
+
curL = s[PI + 1];
|
|
401
|
+
s[PI] = Th;
|
|
402
|
+
s[PI + 1] = Tl;
|
|
403
|
+
}
|
|
404
|
+
for (let y = 0; y < 50; y += 10) {
|
|
405
|
+
for (let x = 0; x < 10; x++)
|
|
406
|
+
B[x] = s[y + x];
|
|
407
|
+
for (let x = 0; x < 10; x++)
|
|
408
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
409
|
+
}
|
|
410
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
411
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
412
|
+
}
|
|
413
|
+
B.fill(0);
|
|
414
|
+
}
|
|
415
|
+
var Keccak = class _Keccak extends utils_js_1.Hash {
|
|
416
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
417
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
418
|
+
super();
|
|
419
|
+
this.blockLen = blockLen;
|
|
420
|
+
this.suffix = suffix;
|
|
421
|
+
this.outputLen = outputLen;
|
|
422
|
+
this.enableXOF = enableXOF;
|
|
423
|
+
this.rounds = rounds;
|
|
424
|
+
this.pos = 0;
|
|
425
|
+
this.posOut = 0;
|
|
426
|
+
this.finished = false;
|
|
427
|
+
this.destroyed = false;
|
|
428
|
+
(0, _assert_js_1.number)(outputLen);
|
|
429
|
+
if (0 >= this.blockLen || this.blockLen >= 200)
|
|
430
|
+
throw new Error("Sha3 supports only keccak-f1600 function");
|
|
431
|
+
this.state = new Uint8Array(200);
|
|
432
|
+
this.state32 = (0, utils_js_1.u32)(this.state);
|
|
433
|
+
}
|
|
434
|
+
keccak() {
|
|
435
|
+
if (!utils_js_1.isLE)
|
|
436
|
+
(0, utils_js_1.byteSwap32)(this.state32);
|
|
437
|
+
keccakP(this.state32, this.rounds);
|
|
438
|
+
if (!utils_js_1.isLE)
|
|
439
|
+
(0, utils_js_1.byteSwap32)(this.state32);
|
|
440
|
+
this.posOut = 0;
|
|
441
|
+
this.pos = 0;
|
|
442
|
+
}
|
|
443
|
+
update(data) {
|
|
444
|
+
(0, _assert_js_1.exists)(this);
|
|
445
|
+
const { blockLen, state } = this;
|
|
446
|
+
data = (0, utils_js_1.toBytes)(data);
|
|
447
|
+
const len = data.length;
|
|
448
|
+
for (let pos = 0; pos < len; ) {
|
|
449
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
450
|
+
for (let i = 0; i < take; i++)
|
|
451
|
+
state[this.pos++] ^= data[pos++];
|
|
452
|
+
if (this.pos === blockLen)
|
|
453
|
+
this.keccak();
|
|
454
|
+
}
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
finish() {
|
|
458
|
+
if (this.finished)
|
|
459
|
+
return;
|
|
460
|
+
this.finished = true;
|
|
461
|
+
const { state, suffix, pos, blockLen } = this;
|
|
462
|
+
state[pos] ^= suffix;
|
|
463
|
+
if ((suffix & 128) !== 0 && pos === blockLen - 1)
|
|
464
|
+
this.keccak();
|
|
465
|
+
state[blockLen - 1] ^= 128;
|
|
466
|
+
this.keccak();
|
|
467
|
+
}
|
|
468
|
+
writeInto(out) {
|
|
469
|
+
(0, _assert_js_1.exists)(this, false);
|
|
470
|
+
(0, _assert_js_1.bytes)(out);
|
|
471
|
+
this.finish();
|
|
472
|
+
const bufferOut = this.state;
|
|
473
|
+
const { blockLen } = this;
|
|
474
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
475
|
+
if (this.posOut >= blockLen)
|
|
476
|
+
this.keccak();
|
|
477
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
478
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
479
|
+
this.posOut += take;
|
|
480
|
+
pos += take;
|
|
481
|
+
}
|
|
482
|
+
return out;
|
|
483
|
+
}
|
|
484
|
+
xofInto(out) {
|
|
485
|
+
if (!this.enableXOF)
|
|
486
|
+
throw new Error("XOF is not possible for this instance");
|
|
487
|
+
return this.writeInto(out);
|
|
488
|
+
}
|
|
489
|
+
xof(bytes) {
|
|
490
|
+
(0, _assert_js_1.number)(bytes);
|
|
491
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
492
|
+
}
|
|
493
|
+
digestInto(out) {
|
|
494
|
+
(0, _assert_js_1.output)(out, this);
|
|
495
|
+
if (this.finished)
|
|
496
|
+
throw new Error("digest() was already called");
|
|
497
|
+
this.writeInto(out);
|
|
498
|
+
this.destroy();
|
|
499
|
+
return out;
|
|
500
|
+
}
|
|
501
|
+
digest() {
|
|
502
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
503
|
+
}
|
|
504
|
+
destroy() {
|
|
505
|
+
this.destroyed = true;
|
|
506
|
+
this.state.fill(0);
|
|
507
|
+
}
|
|
508
|
+
_cloneInto(to) {
|
|
509
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
510
|
+
to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
511
|
+
to.state32.set(this.state32);
|
|
512
|
+
to.pos = this.pos;
|
|
513
|
+
to.posOut = this.posOut;
|
|
514
|
+
to.finished = this.finished;
|
|
515
|
+
to.rounds = rounds;
|
|
516
|
+
to.suffix = suffix;
|
|
517
|
+
to.outputLen = outputLen;
|
|
518
|
+
to.enableXOF = enableXOF;
|
|
519
|
+
to.destroyed = this.destroyed;
|
|
520
|
+
return to;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
exports.Keccak = Keccak;
|
|
524
|
+
var gen = (suffix, blockLen, outputLen) => (0, utils_js_1.wrapConstructor)(() => new Keccak(blockLen, suffix, outputLen));
|
|
525
|
+
exports.sha3_224 = gen(6, 144, 224 / 8);
|
|
526
|
+
exports.sha3_256 = gen(6, 136, 256 / 8);
|
|
527
|
+
exports.sha3_384 = gen(6, 104, 384 / 8);
|
|
528
|
+
exports.sha3_512 = gen(6, 72, 512 / 8);
|
|
529
|
+
exports.keccak_224 = gen(1, 144, 224 / 8);
|
|
530
|
+
exports.keccak_256 = gen(1, 136, 256 / 8);
|
|
531
|
+
exports.keccak_384 = gen(1, 104, 384 / 8);
|
|
532
|
+
exports.keccak_512 = gen(1, 72, 512 / 8);
|
|
533
|
+
var genShake = (suffix, blockLen, outputLen) => (0, utils_js_1.wrapXOFConstructorWithOpts)((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true));
|
|
534
|
+
exports.shake128 = genShake(31, 168, 128 / 8);
|
|
535
|
+
exports.shake256 = genShake(31, 136, 256 / 8);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// ../node_modules/.pnpm/@paralleldrive+cuid2@2.2.2/node_modules/@paralleldrive/cuid2/src/index.js
|
|
540
|
+
var require_src = __commonJS({
|
|
541
|
+
"../node_modules/.pnpm/@paralleldrive+cuid2@2.2.2/node_modules/@paralleldrive/cuid2/src/index.js"(exports, module) {
|
|
542
|
+
"use strict";
|
|
543
|
+
var { sha3_512: sha3 } = require_sha3();
|
|
544
|
+
var defaultLength = 24;
|
|
545
|
+
var bigLength = 32;
|
|
546
|
+
var createEntropy = (length = 4, random = Math.random) => {
|
|
547
|
+
let entropy = "";
|
|
548
|
+
while (entropy.length < length) {
|
|
549
|
+
entropy = entropy + Math.floor(random() * 36).toString(36);
|
|
550
|
+
}
|
|
551
|
+
return entropy;
|
|
552
|
+
};
|
|
553
|
+
function bufToBigInt(buf) {
|
|
554
|
+
let bits = 8n;
|
|
555
|
+
let value = 0n;
|
|
556
|
+
for (const i of buf.values()) {
|
|
557
|
+
const bi = BigInt(i);
|
|
558
|
+
value = (value << bits) + bi;
|
|
559
|
+
}
|
|
560
|
+
return value;
|
|
561
|
+
}
|
|
562
|
+
var hash = (input = "") => {
|
|
563
|
+
return bufToBigInt(sha3(input)).toString(36).slice(1);
|
|
564
|
+
};
|
|
565
|
+
var alphabet = Array.from(
|
|
566
|
+
{ length: 26 },
|
|
567
|
+
(x, i) => String.fromCharCode(i + 97)
|
|
568
|
+
);
|
|
569
|
+
var randomLetter = (random) => alphabet[Math.floor(random() * alphabet.length)];
|
|
570
|
+
var createFingerprint = ({
|
|
571
|
+
globalObj = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : {},
|
|
572
|
+
random = Math.random
|
|
573
|
+
} = {}) => {
|
|
574
|
+
const globals = Object.keys(globalObj).toString();
|
|
575
|
+
const sourceString = globals.length ? globals + createEntropy(bigLength, random) : createEntropy(bigLength, random);
|
|
576
|
+
return hash(sourceString).substring(0, bigLength);
|
|
577
|
+
};
|
|
578
|
+
var createCounter = (count) => () => {
|
|
579
|
+
return count++;
|
|
580
|
+
};
|
|
581
|
+
var initialCountMax = 476782367;
|
|
582
|
+
var init = ({
|
|
583
|
+
// Fallback if the user does not pass in a CSPRNG. This should be OK
|
|
584
|
+
// because we don't rely solely on the random number generator for entropy.
|
|
585
|
+
// We also use the host fingerprint, current time, and a session counter.
|
|
586
|
+
random = Math.random,
|
|
587
|
+
counter = createCounter(Math.floor(random() * initialCountMax)),
|
|
588
|
+
length = defaultLength,
|
|
589
|
+
fingerprint = createFingerprint({ random })
|
|
590
|
+
} = {}) => {
|
|
591
|
+
return function cuid2() {
|
|
592
|
+
const firstLetter = randomLetter(random);
|
|
593
|
+
const time = Date.now().toString(36);
|
|
594
|
+
const count = counter().toString(36);
|
|
595
|
+
const salt = createEntropy(length, random);
|
|
596
|
+
const hashInput = `${time + salt + count + fingerprint}`;
|
|
597
|
+
return `${firstLetter + hash(hashInput).substring(1, length)}`;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
var createId2 = init();
|
|
601
|
+
var isCuid = (id, { minLength = 2, maxLength = bigLength } = {}) => {
|
|
602
|
+
const length = id.length;
|
|
603
|
+
const regex = /^[0-9a-z]+$/;
|
|
604
|
+
try {
|
|
605
|
+
if (typeof id === "string" && length >= minLength && length <= maxLength && regex.test(id))
|
|
606
|
+
return true;
|
|
607
|
+
} finally {
|
|
608
|
+
}
|
|
609
|
+
return false;
|
|
610
|
+
};
|
|
611
|
+
module.exports.getConstants = () => ({ defaultLength, bigLength });
|
|
612
|
+
module.exports.init = init;
|
|
613
|
+
module.exports.createId = createId2;
|
|
614
|
+
module.exports.bufToBigInt = bufToBigInt;
|
|
615
|
+
module.exports.createCounter = createCounter;
|
|
616
|
+
module.exports.createFingerprint = createFingerprint;
|
|
617
|
+
module.exports.isCuid = isCuid;
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
// ../node_modules/.pnpm/@paralleldrive+cuid2@2.2.2/node_modules/@paralleldrive/cuid2/index.js
|
|
622
|
+
var require_cuid2 = __commonJS({
|
|
623
|
+
"../node_modules/.pnpm/@paralleldrive+cuid2@2.2.2/node_modules/@paralleldrive/cuid2/index.js"(exports, module) {
|
|
624
|
+
"use strict";
|
|
625
|
+
var { createId: createId2, init, getConstants, isCuid } = require_src();
|
|
626
|
+
module.exports.createId = createId2;
|
|
627
|
+
module.exports.init = init;
|
|
628
|
+
module.exports.getConstants = getConstants;
|
|
629
|
+
module.exports.isCuid = isCuid;
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
// ../packages/sdk/build/index.mjs
|
|
634
|
+
var import_cuid2 = __toESM(require_cuid2(), 1);
|
|
635
|
+
var engineParamsSchema = z.object({
|
|
636
|
+
apiKey: z.string(),
|
|
637
|
+
apiUrl: z.string().url().default("https://engine.replexica.com"),
|
|
638
|
+
batchSize: z.number().int().gt(0).lte(250).default(25),
|
|
639
|
+
idealBatchItemSize: z.number().int().gt(0).lte(2500).default(250)
|
|
640
|
+
}).passthrough();
|
|
641
|
+
var payloadSchema = z.record(z.string(), z.any());
|
|
642
|
+
var localizationParamsSchema = z.object({
|
|
643
|
+
sourceLocale: localeCodeSchema,
|
|
644
|
+
targetLocale: localeCodeSchema,
|
|
645
|
+
fast: z.boolean().optional()
|
|
646
|
+
});
|
|
647
|
+
var referenceSchema = z.record(localeCodeSchema, payloadSchema);
|
|
648
|
+
var ReplexicaEngine = class {
|
|
649
|
+
config;
|
|
650
|
+
/**
|
|
651
|
+
* Create a new ReplexicaEngine instance
|
|
652
|
+
* @param config - Configuration options for the Engine
|
|
653
|
+
*/
|
|
654
|
+
constructor(config) {
|
|
655
|
+
this.config = engineParamsSchema.parse(config);
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Localize content using the Replexica API
|
|
659
|
+
* @param payload - The content to be localized
|
|
660
|
+
* @param params - Localization parameters including source/target locales and fast mode option
|
|
661
|
+
* @param reference - Optional reference translations to maintain consistency
|
|
662
|
+
* @param progressCallback - Optional callback function to report progress (0-100)
|
|
663
|
+
* @returns Localized content
|
|
664
|
+
* @internal
|
|
665
|
+
*/
|
|
666
|
+
async _localizeRaw(payload, params, reference, progressCallback) {
|
|
667
|
+
const finalPayload = payloadSchema.parse(payload);
|
|
668
|
+
const finalParams = localizationParamsSchema.parse(params);
|
|
669
|
+
const chunkedPayload = this.extractPayloadChunks(finalPayload);
|
|
670
|
+
const processedPayloadChunks = [];
|
|
671
|
+
const workflowId = (0, import_cuid2.createId)();
|
|
672
|
+
for (let i = 0; i < chunkedPayload.length; i++) {
|
|
673
|
+
const chunk = chunkedPayload[i];
|
|
674
|
+
const percentageCompleted = Math.round((i + 1) / chunkedPayload.length * 100);
|
|
675
|
+
if (progressCallback) {
|
|
676
|
+
progressCallback(percentageCompleted);
|
|
677
|
+
}
|
|
678
|
+
const processedPayloadChunk = await this.localizeChunk(
|
|
679
|
+
finalParams.sourceLocale,
|
|
680
|
+
finalParams.targetLocale,
|
|
681
|
+
{ data: chunk, reference },
|
|
682
|
+
workflowId,
|
|
683
|
+
params.fast || false
|
|
684
|
+
);
|
|
685
|
+
processedPayloadChunks.push(processedPayloadChunk);
|
|
686
|
+
}
|
|
687
|
+
return Object.assign({}, ...processedPayloadChunks);
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Localize a single chunk of content
|
|
691
|
+
* @param sourceLocale - Source locale
|
|
692
|
+
* @param targetLocale - Target locale
|
|
693
|
+
* @param payload - Payload containing the chunk to be localized
|
|
694
|
+
* @returns Localized chunk
|
|
695
|
+
*/
|
|
696
|
+
async localizeChunk(sourceLocale, targetLocale, payload, workflowId, fast) {
|
|
697
|
+
const res = await fetch(`${this.config.apiUrl}/i18n`, {
|
|
698
|
+
method: "POST",
|
|
699
|
+
headers: {
|
|
700
|
+
"Content-Type": "application/json",
|
|
701
|
+
Authorization: `Bearer ${this.config.apiKey}`
|
|
702
|
+
},
|
|
703
|
+
body: JSON.stringify(
|
|
704
|
+
{
|
|
705
|
+
params: { workflowId, fast },
|
|
706
|
+
locale: {
|
|
707
|
+
source: sourceLocale,
|
|
708
|
+
target: targetLocale
|
|
709
|
+
},
|
|
710
|
+
data: payload.data,
|
|
711
|
+
reference: payload.reference
|
|
712
|
+
},
|
|
713
|
+
null,
|
|
714
|
+
2
|
|
715
|
+
)
|
|
716
|
+
});
|
|
717
|
+
if (!res.ok) {
|
|
718
|
+
if (res.status === 400) {
|
|
719
|
+
throw new Error(`Invalid request: ${res.statusText}`);
|
|
720
|
+
} else {
|
|
721
|
+
const errorText = await res.text();
|
|
722
|
+
throw new Error(errorText);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const jsonResponse = await res.json();
|
|
726
|
+
return jsonResponse.data || {};
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Extract payload chunks based on the ideal chunk size
|
|
730
|
+
* @param payload - The payload to be chunked
|
|
731
|
+
* @returns An array of payload chunks
|
|
732
|
+
*/
|
|
733
|
+
extractPayloadChunks(payload) {
|
|
734
|
+
const result = [];
|
|
735
|
+
let currentChunk = {};
|
|
736
|
+
let currentChunkItemCount = 0;
|
|
737
|
+
const payloadEntries = Object.entries(payload);
|
|
738
|
+
for (let i = 0; i < payloadEntries.length; i++) {
|
|
739
|
+
const [key, value] = payloadEntries[i];
|
|
740
|
+
currentChunk[key] = value;
|
|
741
|
+
currentChunkItemCount++;
|
|
742
|
+
const currentChunkSize = this.countWordsInRecord(currentChunk);
|
|
743
|
+
if (currentChunkSize > this.config.idealBatchItemSize || currentChunkItemCount >= this.config.batchSize || i === payloadEntries.length - 1) {
|
|
744
|
+
result.push(currentChunk);
|
|
745
|
+
currentChunk = {};
|
|
746
|
+
currentChunkItemCount = 0;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return result;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Count words in a record or array
|
|
753
|
+
* @param payload - The payload to count words in
|
|
754
|
+
* @returns The total number of words
|
|
755
|
+
*/
|
|
756
|
+
countWordsInRecord(payload) {
|
|
757
|
+
if (Array.isArray(payload)) {
|
|
758
|
+
return payload.reduce((acc, item) => acc + this.countWordsInRecord(item), 0);
|
|
759
|
+
} else if (typeof payload === "object" && payload !== null) {
|
|
760
|
+
return Object.values(payload).reduce((acc, item) => acc + this.countWordsInRecord(item), 0);
|
|
761
|
+
} else if (typeof payload === "string") {
|
|
762
|
+
return payload.trim().split(/\s+/).filter(Boolean).length;
|
|
763
|
+
} else {
|
|
764
|
+
return 0;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Localize a typical JavaScript object
|
|
769
|
+
* @param obj - The object to be localized (strings will be extracted and translated)
|
|
770
|
+
* @param params - Localization parameters:
|
|
771
|
+
* - sourceLocale: The source language code (e.g., 'en')
|
|
772
|
+
* - targetLocale: The target language code (e.g., 'es')
|
|
773
|
+
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
|
774
|
+
* @param progressCallback - Optional callback function to report progress (0-100)
|
|
775
|
+
* @returns A new object with the same structure but localized string values
|
|
776
|
+
*/
|
|
777
|
+
async localizeObject(obj, params, progressCallback) {
|
|
778
|
+
return this._localizeRaw(obj, params, void 0, progressCallback);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Localize a single text string
|
|
782
|
+
* @param text - The text string to be localized
|
|
783
|
+
* @param params - Localization parameters:
|
|
784
|
+
* - sourceLocale: The source language code (e.g., 'en')
|
|
785
|
+
* - targetLocale: The target language code (e.g., 'es')
|
|
786
|
+
* - fast: Optional boolean to enable fast mode (faster for bigger batches)
|
|
787
|
+
* @param progressCallback - Optional callback function to report progress (0-100)
|
|
788
|
+
* @returns The localized text string
|
|
789
|
+
*/
|
|
790
|
+
async localizeText(text, params, progressCallback) {
|
|
791
|
+
const response = await this._localizeRaw({ text }, params, void 0, progressCallback);
|
|
792
|
+
return response.text || "";
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Localize a text string to multiple target locales
|
|
796
|
+
* @param text - The text string to be localized
|
|
797
|
+
* @param params - Localization parameters:
|
|
798
|
+
* - sourceLocale: The source language code (e.g., 'en')
|
|
799
|
+
* - targetLocales: An array of target language codes (e.g., ['es', 'fr'])
|
|
800
|
+
* - fast: Optional boolean to enable fast mode (for bigger batches)
|
|
801
|
+
* @returns An array of localized text strings
|
|
802
|
+
*/
|
|
803
|
+
async batchLocalizeText(text, params) {
|
|
804
|
+
const responses = await Promise.all(
|
|
805
|
+
params.targetLocales.map(
|
|
806
|
+
(targetLocale) => this.localizeText(text, {
|
|
807
|
+
sourceLocale: params.sourceLocale,
|
|
808
|
+
targetLocale,
|
|
809
|
+
fast: params.fast
|
|
810
|
+
})
|
|
811
|
+
)
|
|
812
|
+
);
|
|
813
|
+
return responses;
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Localize a chat sequence while preserving speaker names
|
|
817
|
+
* @param chat - Array of chat messages, each with 'name' and 'text' properties
|
|
818
|
+
* @param params - Localization parameters:
|
|
819
|
+
* - sourceLocale: The source language code (e.g., 'en')
|
|
820
|
+
* - targetLocale: The target language code (e.g., 'es')
|
|
821
|
+
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
|
822
|
+
* @param progressCallback - Optional callback function to report progress (0-100)
|
|
823
|
+
* @returns Array of localized chat messages with preserved structure
|
|
824
|
+
*/
|
|
825
|
+
async localizeChat(chat, params, progressCallback) {
|
|
826
|
+
const localized = await this._localizeRaw({ chat }, params, void 0, progressCallback);
|
|
827
|
+
return Object.entries(localized).map(([key, value]) => ({
|
|
828
|
+
name: chat[parseInt(key.split("_")[1])].name,
|
|
829
|
+
text: value
|
|
830
|
+
}));
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Localize an HTML document while preserving structure and formatting
|
|
834
|
+
* Handles both text content and localizable attributes (alt, title, placeholder, meta content)
|
|
835
|
+
* @param html - The HTML document string to be localized
|
|
836
|
+
* @param params - Localization parameters:
|
|
837
|
+
* - sourceLocale: The source language code (e.g., 'en')
|
|
838
|
+
* - targetLocale: The target language code (e.g., 'es')
|
|
839
|
+
* - fast: Optional boolean to enable fast mode (faster but potentially lower quality)
|
|
840
|
+
* @param progressCallback - Optional callback function to report progress (0-100)
|
|
841
|
+
* @returns The localized HTML document as a string, with updated lang attribute
|
|
842
|
+
*/
|
|
843
|
+
async localizeHtml(html, params, progressCallback) {
|
|
844
|
+
const jsdomPackage = await import("./api-7PZYRHW3.mjs");
|
|
845
|
+
const { JSDOM } = jsdomPackage;
|
|
846
|
+
const dom = new JSDOM(html);
|
|
847
|
+
const document = dom.window.document;
|
|
848
|
+
const LOCALIZABLE_ATTRIBUTES = {
|
|
849
|
+
meta: ["content"],
|
|
850
|
+
img: ["alt"],
|
|
851
|
+
input: ["placeholder"],
|
|
852
|
+
a: ["title"]
|
|
853
|
+
};
|
|
854
|
+
const UNLOCALIZABLE_TAGS = ["script", "style"];
|
|
855
|
+
const extractedContent = {};
|
|
856
|
+
const getPath = (node, attribute) => {
|
|
857
|
+
const indices = [];
|
|
858
|
+
let current = node;
|
|
859
|
+
let rootParent = "";
|
|
860
|
+
while (current) {
|
|
861
|
+
const parent = current.parentElement;
|
|
862
|
+
if (!parent) break;
|
|
863
|
+
if (parent === document.documentElement) {
|
|
864
|
+
rootParent = current.nodeName.toLowerCase();
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
const siblings = Array.from(parent.childNodes).filter(
|
|
868
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
|
|
869
|
+
);
|
|
870
|
+
const index = siblings.indexOf(current);
|
|
871
|
+
if (index !== -1) {
|
|
872
|
+
indices.unshift(index);
|
|
873
|
+
}
|
|
874
|
+
current = parent;
|
|
875
|
+
}
|
|
876
|
+
const basePath = rootParent ? `${rootParent}/${indices.join("/")}` : indices.join("/");
|
|
877
|
+
return attribute ? `${basePath}#${attribute}` : basePath;
|
|
878
|
+
};
|
|
879
|
+
const processNode = (node) => {
|
|
880
|
+
let parent = node.parentElement;
|
|
881
|
+
while (parent) {
|
|
882
|
+
if (UNLOCALIZABLE_TAGS.includes(parent.tagName.toLowerCase())) {
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
parent = parent.parentElement;
|
|
886
|
+
}
|
|
887
|
+
if (node.nodeType === 3) {
|
|
888
|
+
const text = node.textContent?.trim() || "";
|
|
889
|
+
if (text) {
|
|
890
|
+
extractedContent[getPath(node)] = text;
|
|
891
|
+
}
|
|
892
|
+
} else if (node.nodeType === 1) {
|
|
893
|
+
const element = node;
|
|
894
|
+
const tagName = element.tagName.toLowerCase();
|
|
895
|
+
const attributes = LOCALIZABLE_ATTRIBUTES[tagName] || [];
|
|
896
|
+
attributes.forEach((attr) => {
|
|
897
|
+
const value = element.getAttribute(attr);
|
|
898
|
+
if (value) {
|
|
899
|
+
extractedContent[getPath(element, attr)] = value;
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
Array.from(element.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
Array.from(document.head.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);
|
|
906
|
+
Array.from(document.body.childNodes).filter((n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()).forEach(processNode);
|
|
907
|
+
const localizedContent = await this._localizeRaw(extractedContent, params, void 0, progressCallback);
|
|
908
|
+
document.documentElement.setAttribute("lang", params.targetLocale);
|
|
909
|
+
Object.entries(localizedContent).forEach(([path, value]) => {
|
|
910
|
+
const [nodePath, attribute] = path.split("#");
|
|
911
|
+
const [rootTag, ...indices] = nodePath.split("/");
|
|
912
|
+
let parent = rootTag === "head" ? document.head : document.body;
|
|
913
|
+
let current = parent;
|
|
914
|
+
for (const index of indices) {
|
|
915
|
+
const siblings = Array.from(parent.childNodes).filter(
|
|
916
|
+
(n) => n.nodeType === 1 || n.nodeType === 3 && n.textContent?.trim()
|
|
917
|
+
);
|
|
918
|
+
current = siblings[parseInt(index)] || null;
|
|
919
|
+
if (current?.nodeType === 1) {
|
|
920
|
+
parent = current;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
if (current) {
|
|
924
|
+
if (attribute) {
|
|
925
|
+
current.setAttribute(attribute, value);
|
|
926
|
+
} else {
|
|
927
|
+
current.textContent = value;
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
return dom.serialize();
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Detect the language of a given text
|
|
935
|
+
* @param text - The text to analyze
|
|
936
|
+
* @returns Promise resolving to a locale code (e.g., 'en', 'es', 'fr')
|
|
937
|
+
*/
|
|
938
|
+
async recognizeLocale(text) {
|
|
939
|
+
const response = await fetch(`${this.config.apiUrl}/recognize`, {
|
|
940
|
+
method: "POST",
|
|
941
|
+
headers: {
|
|
942
|
+
"Content-Type": "application/json",
|
|
943
|
+
Authorization: `Bearer ${this.config.apiKey}`
|
|
944
|
+
},
|
|
945
|
+
body: JSON.stringify({ text })
|
|
946
|
+
});
|
|
947
|
+
if (!response.ok) {
|
|
948
|
+
throw new Error(`Error recognizing locale: ${response.statusText}`);
|
|
949
|
+
}
|
|
950
|
+
const jsonResponse = await response.json();
|
|
951
|
+
return jsonResponse.locale;
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
export {
|
|
956
|
+
ReplexicaEngine
|
|
957
|
+
};
|
|
958
|
+
/*! Bundled license information:
|
|
959
|
+
|
|
960
|
+
@noble/hashes/utils.js:
|
|
961
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
962
|
+
*/
|