mtranserver 4.0.20 → 4.0.21
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/dist/core/engine.d.ts +2 -0
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/icon-tjp1feba.png +0 -0
- package/dist/index-B7vzjIqN-ma6ncj8z.css +1 -0
- package/dist/index-D6lVFqDO-3a1nn40g.js +53 -0
- package/dist/{index-wzc7qnpt.html → index-g3cdpfvc.html} +2 -2
- package/dist/index.js +41 -63
- package/dist/index.js.map +4 -4
- package/dist/main.js +79 -101
- package/dist/main.js.map +8 -8
- package/package.json +3 -3
- package/dist/icon-2r5te9sp.png +0 -0
- package/dist/index-B5MwS93W-8btbkjwj.css +0 -1
- package/dist/index-CViVzJTS-xrkq8wea.js +0 -53
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<meta name="darkreader-lock" />
|
|
8
8
|
<title>MTranServer</title>
|
|
9
|
-
<script type="module" crossorigin src="/ui/assets/index-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/ui/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/ui/assets/index-D6lVFqDO.js"></script>
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/ui/assets/index-B7vzjIqN.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="root"></div>
|
package/dist/index.js
CHANGED
|
@@ -1312,7 +1312,8 @@ class TranslationEngine {
|
|
|
1312
1312
|
if (options.html) {
|
|
1313
1313
|
processedText = this._sanitizeHTML(text);
|
|
1314
1314
|
}
|
|
1315
|
-
const { cleanText, replacements } = this.
|
|
1315
|
+
const { cleanText: placeholderText, replacements: placeholderReplacements } = this._hidePlaceholders(processedText, options);
|
|
1316
|
+
const { cleanText, replacements } = this._hideEmojis(placeholderText);
|
|
1316
1317
|
let translation;
|
|
1317
1318
|
try {
|
|
1318
1319
|
if (cleanText.length > this.maxLengthBreak) {
|
|
@@ -1328,6 +1329,7 @@ class TranslationEngine {
|
|
|
1328
1329
|
throw error2;
|
|
1329
1330
|
}
|
|
1330
1331
|
translation = this._restoreEmojis(translation, replacements);
|
|
1332
|
+
translation = this._restorePlaceholders(translation, placeholderReplacements);
|
|
1331
1333
|
return translation;
|
|
1332
1334
|
}
|
|
1333
1335
|
_sanitizeHTML(text) {
|
|
@@ -1484,6 +1486,30 @@ class TranslationEngine {
|
|
|
1484
1486
|
}
|
|
1485
1487
|
return result;
|
|
1486
1488
|
}
|
|
1489
|
+
_hidePlaceholders(text, options = {}) {
|
|
1490
|
+
const replacements = [];
|
|
1491
|
+
const used = new Set;
|
|
1492
|
+
const placeholderRegex = /(\{\d+\}|\[\d+\])/g;
|
|
1493
|
+
const cleanText = text.replace(placeholderRegex, (match) => {
|
|
1494
|
+
let placeholder = `__MTRAN_PH_${replacements.length}__`;
|
|
1495
|
+
let salt = 0;
|
|
1496
|
+
while (text.includes(placeholder) || used.has(placeholder)) {
|
|
1497
|
+
salt += 1;
|
|
1498
|
+
placeholder = `__MTRAN_PH_${replacements.length}_${salt}__`;
|
|
1499
|
+
}
|
|
1500
|
+
used.add(placeholder);
|
|
1501
|
+
replacements.push({ original: match, placeholder });
|
|
1502
|
+
return placeholder;
|
|
1503
|
+
});
|
|
1504
|
+
return { cleanText, replacements };
|
|
1505
|
+
}
|
|
1506
|
+
_restorePlaceholders(text, replacements) {
|
|
1507
|
+
let result = text;
|
|
1508
|
+
for (const { original, placeholder } of replacements) {
|
|
1509
|
+
result = result.split(placeholder).join(original);
|
|
1510
|
+
}
|
|
1511
|
+
return result;
|
|
1512
|
+
}
|
|
1487
1513
|
destroy() {
|
|
1488
1514
|
try {
|
|
1489
1515
|
if (this.model) {
|
|
@@ -4400,7 +4426,7 @@ var init_bergamot_translator = () => {};
|
|
|
4400
4426
|
|
|
4401
4427
|
// src/lib/cld2/cld2.js
|
|
4402
4428
|
var require_cld2 = __commonJS((exports, module) => {
|
|
4403
|
-
var __dirname = "/
|
|
4429
|
+
var __dirname = "/home/xxnuo/projects/MTran/MTranServer/src/lib/cld2", __filename = "/home/xxnuo/projects/MTran/MTranServer/src/lib/cld2/cld2.js";
|
|
4404
4430
|
var loadCLD2 = (() => {
|
|
4405
4431
|
var _scriptName = globalThis.document?.currentScript?.src;
|
|
4406
4432
|
return async function(moduleArg = {}) {
|
|
@@ -5865,11 +5891,11 @@ class Stack {
|
|
|
5865
5891
|
return this.heap[--this.length];
|
|
5866
5892
|
}
|
|
5867
5893
|
}
|
|
5868
|
-
var
|
|
5894
|
+
var perf, warned, PROCESS, emitWarning = (msg, type, code, fn) => {
|
|
5869
5895
|
typeof PROCESS.emitWarning === "function" ? PROCESS.emitWarning(msg, type, code, fn) : console.error(`[${code}] ${type}: ${msg}`);
|
|
5870
5896
|
}, AC, AS, shouldWarn = (code) => !warned.has(code), TYPE, isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n), getUintArray = (max) => !isPosInt(max) ? null : max <= Math.pow(2, 8) ? Uint8Array : max <= Math.pow(2, 16) ? Uint16Array : max <= Math.pow(2, 32) ? Uint32Array : max <= Number.MAX_SAFE_INTEGER ? ZeroArray : null, ZeroArray, LRUCache;
|
|
5871
5897
|
var init_esm2 = __esm(() => {
|
|
5872
|
-
|
|
5898
|
+
perf = typeof performance === "object" && performance && typeof performance.now === "function" ? performance : Date;
|
|
5873
5899
|
warned = new Set;
|
|
5874
5900
|
PROCESS = typeof process === "object" && !!process ? process : {};
|
|
5875
5901
|
AC = globalThis.AbortController;
|
|
@@ -5919,14 +5945,9 @@ var init_esm2 = __esm(() => {
|
|
|
5919
5945
|
#max;
|
|
5920
5946
|
#maxSize;
|
|
5921
5947
|
#dispose;
|
|
5922
|
-
#onInsert;
|
|
5923
5948
|
#disposeAfter;
|
|
5924
5949
|
#fetchMethod;
|
|
5925
5950
|
#memoMethod;
|
|
5926
|
-
#perf;
|
|
5927
|
-
get perf() {
|
|
5928
|
-
return this.#perf;
|
|
5929
|
-
}
|
|
5930
5951
|
ttl;
|
|
5931
5952
|
ttlResolution;
|
|
5932
5953
|
ttlAutopurge;
|
|
@@ -5956,16 +5977,13 @@ var init_esm2 = __esm(() => {
|
|
|
5956
5977
|
#sizes;
|
|
5957
5978
|
#starts;
|
|
5958
5979
|
#ttls;
|
|
5959
|
-
#autopurgeTimers;
|
|
5960
5980
|
#hasDispose;
|
|
5961
5981
|
#hasFetchMethod;
|
|
5962
5982
|
#hasDisposeAfter;
|
|
5963
|
-
#hasOnInsert;
|
|
5964
5983
|
static unsafeExposeInternals(c) {
|
|
5965
5984
|
return {
|
|
5966
5985
|
starts: c.#starts,
|
|
5967
5986
|
ttls: c.#ttls,
|
|
5968
|
-
autopurgeTimers: c.#autopurgeTimers,
|
|
5969
5987
|
sizes: c.#sizes,
|
|
5970
5988
|
keyMap: c.#keyMap,
|
|
5971
5989
|
keyList: c.#keyList,
|
|
@@ -6008,20 +6026,11 @@ var init_esm2 = __esm(() => {
|
|
|
6008
6026
|
get dispose() {
|
|
6009
6027
|
return this.#dispose;
|
|
6010
6028
|
}
|
|
6011
|
-
get onInsert() {
|
|
6012
|
-
return this.#onInsert;
|
|
6013
|
-
}
|
|
6014
6029
|
get disposeAfter() {
|
|
6015
6030
|
return this.#disposeAfter;
|
|
6016
6031
|
}
|
|
6017
6032
|
constructor(options) {
|
|
6018
|
-
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose,
|
|
6019
|
-
if (perf !== undefined) {
|
|
6020
|
-
if (typeof perf?.now !== "function") {
|
|
6021
|
-
throw new TypeError("perf option must have a now() method if specified");
|
|
6022
|
-
}
|
|
6023
|
-
}
|
|
6024
|
-
this.#perf = perf ?? defaultPerf;
|
|
6033
|
+
const { max = 0, ttl, ttlResolution = 1, ttlAutopurge, updateAgeOnGet, updateAgeOnHas, allowStale, dispose, disposeAfter, noDisposeOnSet, noUpdateTTL, maxSize = 0, maxEntrySize = 0, sizeCalculation, fetchMethod, memoMethod, noDeleteOnFetchRejection, noDeleteOnStaleGet, allowStaleOnFetchRejection, allowStaleOnFetchAbort, ignoreFetchAbort } = options;
|
|
6025
6034
|
if (max !== 0 && !isPosInt(max)) {
|
|
6026
6035
|
throw new TypeError("max option must be a nonnegative integer");
|
|
6027
6036
|
}
|
|
@@ -6063,9 +6072,6 @@ var init_esm2 = __esm(() => {
|
|
|
6063
6072
|
if (typeof dispose === "function") {
|
|
6064
6073
|
this.#dispose = dispose;
|
|
6065
6074
|
}
|
|
6066
|
-
if (typeof onInsert === "function") {
|
|
6067
|
-
this.#onInsert = onInsert;
|
|
6068
|
-
}
|
|
6069
6075
|
if (typeof disposeAfter === "function") {
|
|
6070
6076
|
this.#disposeAfter = disposeAfter;
|
|
6071
6077
|
this.#disposed = [];
|
|
@@ -6074,7 +6080,6 @@ var init_esm2 = __esm(() => {
|
|
|
6074
6080
|
this.#disposed = undefined;
|
|
6075
6081
|
}
|
|
6076
6082
|
this.#hasDispose = !!this.#dispose;
|
|
6077
|
-
this.#hasOnInsert = !!this.#onInsert;
|
|
6078
6083
|
this.#hasDisposeAfter = !!this.#disposeAfter;
|
|
6079
6084
|
this.noDisposeOnSet = !!noDisposeOnSet;
|
|
6080
6085
|
this.noUpdateTTL = !!noUpdateTTL;
|
|
@@ -6126,16 +6131,10 @@ var init_esm2 = __esm(() => {
|
|
|
6126
6131
|
const starts = new ZeroArray(this.#max);
|
|
6127
6132
|
this.#ttls = ttls;
|
|
6128
6133
|
this.#starts = starts;
|
|
6129
|
-
|
|
6130
|
-
this.#autopurgeTimers = purgeTimers;
|
|
6131
|
-
this.#setItemTTL = (index, ttl, start = this.#perf.now()) => {
|
|
6134
|
+
this.#setItemTTL = (index, ttl, start = perf.now()) => {
|
|
6132
6135
|
starts[index] = ttl !== 0 ? start : 0;
|
|
6133
6136
|
ttls[index] = ttl;
|
|
6134
|
-
if (
|
|
6135
|
-
clearTimeout(purgeTimers[index]);
|
|
6136
|
-
purgeTimers[index] = undefined;
|
|
6137
|
-
}
|
|
6138
|
-
if (ttl !== 0 && purgeTimers) {
|
|
6137
|
+
if (ttl !== 0 && this.ttlAutopurge) {
|
|
6139
6138
|
const t = setTimeout(() => {
|
|
6140
6139
|
if (this.#isStale(index)) {
|
|
6141
6140
|
this.#delete(this.#keyList[index], "expire");
|
|
@@ -6144,11 +6143,10 @@ var init_esm2 = __esm(() => {
|
|
|
6144
6143
|
if (t.unref) {
|
|
6145
6144
|
t.unref();
|
|
6146
6145
|
}
|
|
6147
|
-
purgeTimers[index] = t;
|
|
6148
6146
|
}
|
|
6149
6147
|
};
|
|
6150
6148
|
this.#updateItemAge = (index) => {
|
|
6151
|
-
starts[index] = ttls[index] !== 0 ?
|
|
6149
|
+
starts[index] = ttls[index] !== 0 ? perf.now() : 0;
|
|
6152
6150
|
};
|
|
6153
6151
|
this.#statusTTL = (status, index) => {
|
|
6154
6152
|
if (ttls[index]) {
|
|
@@ -6165,7 +6163,7 @@ var init_esm2 = __esm(() => {
|
|
|
6165
6163
|
};
|
|
6166
6164
|
let cachedNow = 0;
|
|
6167
6165
|
const getNow = () => {
|
|
6168
|
-
const n =
|
|
6166
|
+
const n = perf.now();
|
|
6169
6167
|
if (this.ttlResolution > 0) {
|
|
6170
6168
|
cachedNow = n;
|
|
6171
6169
|
const t = setTimeout(() => cachedNow = 0, this.ttlResolution);
|
|
@@ -6387,7 +6385,7 @@ var init_esm2 = __esm(() => {
|
|
|
6387
6385
|
const ttl = this.#ttls[i];
|
|
6388
6386
|
const start = this.#starts[i];
|
|
6389
6387
|
if (ttl && start) {
|
|
6390
|
-
const remain = ttl - (
|
|
6388
|
+
const remain = ttl - (perf.now() - start);
|
|
6391
6389
|
entry.ttl = remain;
|
|
6392
6390
|
entry.start = Date.now();
|
|
6393
6391
|
}
|
|
@@ -6408,7 +6406,7 @@ var init_esm2 = __esm(() => {
|
|
|
6408
6406
|
const entry = { value };
|
|
6409
6407
|
if (this.#ttls && this.#starts) {
|
|
6410
6408
|
entry.ttl = this.#ttls[i];
|
|
6411
|
-
const age =
|
|
6409
|
+
const age = perf.now() - this.#starts[i];
|
|
6412
6410
|
entry.start = Math.floor(Date.now() - age);
|
|
6413
6411
|
}
|
|
6414
6412
|
if (this.#sizes) {
|
|
@@ -6423,7 +6421,7 @@ var init_esm2 = __esm(() => {
|
|
|
6423
6421
|
for (const [key, entry] of arr) {
|
|
6424
6422
|
if (entry.start) {
|
|
6425
6423
|
const age = Date.now() - entry.start;
|
|
6426
|
-
entry.start =
|
|
6424
|
+
entry.start = perf.now() - age;
|
|
6427
6425
|
}
|
|
6428
6426
|
this.set(key, entry.value, entry);
|
|
6429
6427
|
}
|
|
@@ -6458,9 +6456,6 @@ var init_esm2 = __esm(() => {
|
|
|
6458
6456
|
if (status)
|
|
6459
6457
|
status.set = "add";
|
|
6460
6458
|
noUpdateTTL = false;
|
|
6461
|
-
if (this.#hasOnInsert) {
|
|
6462
|
-
this.#onInsert?.(v, k, "add");
|
|
6463
|
-
}
|
|
6464
6459
|
} else {
|
|
6465
6460
|
this.#moveToTail(index);
|
|
6466
6461
|
const oldVal = this.#valList[index];
|
|
@@ -6496,9 +6491,6 @@ var init_esm2 = __esm(() => {
|
|
|
6496
6491
|
} else if (status) {
|
|
6497
6492
|
status.set = "update";
|
|
6498
6493
|
}
|
|
6499
|
-
if (this.#hasOnInsert) {
|
|
6500
|
-
this.onInsert?.(v, k, v === oldVal ? "update" : "replace");
|
|
6501
|
-
}
|
|
6502
6494
|
}
|
|
6503
6495
|
if (ttl !== 0 && !this.#ttls) {
|
|
6504
6496
|
this.#initializeTTLTracking();
|
|
@@ -6557,10 +6549,6 @@ var init_esm2 = __esm(() => {
|
|
|
6557
6549
|
}
|
|
6558
6550
|
}
|
|
6559
6551
|
this.#removeItemSize(head);
|
|
6560
|
-
if (this.#autopurgeTimers?.[head]) {
|
|
6561
|
-
clearTimeout(this.#autopurgeTimers[head]);
|
|
6562
|
-
this.#autopurgeTimers[head] = undefined;
|
|
6563
|
-
}
|
|
6564
6552
|
if (free) {
|
|
6565
6553
|
this.#keyList[head] = undefined;
|
|
6566
6554
|
this.#valList[head] = undefined;
|
|
@@ -6643,10 +6631,9 @@ var init_esm2 = __esm(() => {
|
|
|
6643
6631
|
return fetchFail(ac.signal.reason);
|
|
6644
6632
|
}
|
|
6645
6633
|
const bf2 = p;
|
|
6646
|
-
|
|
6647
|
-
if (vl === p || ignoreAbort && updateCache && vl === undefined) {
|
|
6634
|
+
if (this.#valList[index] === p) {
|
|
6648
6635
|
if (v2 === undefined) {
|
|
6649
|
-
if (bf2.__staleWhileFetching
|
|
6636
|
+
if (bf2.__staleWhileFetching) {
|
|
6650
6637
|
this.#valList[index] = bf2.__staleWhileFetching;
|
|
6651
6638
|
} else {
|
|
6652
6639
|
this.#delete(k, "fetch");
|
|
@@ -6895,10 +6882,6 @@ var init_esm2 = __esm(() => {
|
|
|
6895
6882
|
if (this.#size !== 0) {
|
|
6896
6883
|
const index = this.#keyMap.get(k);
|
|
6897
6884
|
if (index !== undefined) {
|
|
6898
|
-
if (this.#autopurgeTimers?.[index]) {
|
|
6899
|
-
clearTimeout(this.#autopurgeTimers?.[index]);
|
|
6900
|
-
this.#autopurgeTimers[index] = undefined;
|
|
6901
|
-
}
|
|
6902
6885
|
deleted = true;
|
|
6903
6886
|
if (this.#size === 1) {
|
|
6904
6887
|
this.#clear(reason);
|
|
@@ -6966,11 +6949,6 @@ var init_esm2 = __esm(() => {
|
|
|
6966
6949
|
if (this.#ttls && this.#starts) {
|
|
6967
6950
|
this.#ttls.fill(0);
|
|
6968
6951
|
this.#starts.fill(0);
|
|
6969
|
-
for (const t of this.#autopurgeTimers ?? []) {
|
|
6970
|
-
if (t !== undefined)
|
|
6971
|
-
clearTimeout(t);
|
|
6972
|
-
}
|
|
6973
|
-
this.#autopurgeTimers?.fill(undefined);
|
|
6974
6952
|
}
|
|
6975
6953
|
if (this.#sizes) {
|
|
6976
6954
|
this.#sizes.fill(0);
|
|
@@ -7448,5 +7426,5 @@ export {
|
|
|
7448
7426
|
MTran
|
|
7449
7427
|
};
|
|
7450
7428
|
|
|
7451
|
-
//# debugId=
|
|
7429
|
+
//# debugId=F76793A5334DBD8464756E2164756E21
|
|
7452
7430
|
//# sourceMappingURL=index.js.map
|