accessify-widget 0.3.5 → 0.3.7
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/accessify.min.js +1 -1
- package/dist/accessify.min.js.map +1 -1
- package/dist/accessify.mjs +1 -1
- package/dist/{index-BTkeEVoS.js → index-C_cEJXg7.js} +79 -33
- package/dist/{index-BTkeEVoS.js.map → index-C_cEJXg7.js.map} +1 -1
- package/dist/{keyboard-nav-BZ4ei-Lt.js → keyboard-nav-BN8NOhTx.js} +2 -2
- package/dist/{keyboard-nav-BZ4ei-Lt.js.map → keyboard-nav-BN8NOhTx.js.map} +1 -1
- package/dist/{page-structure-JY54Sj14.js → page-structure-CK_agCbv.js} +2 -2
- package/dist/{page-structure-JY54Sj14.js.map → page-structure-CK_agCbv.js.map} +1 -1
- package/dist/widget.js +1 -1
- package/dist/widget.js.map +1 -1
- package/package.json +1 -1
package/dist/accessify.mjs
CHANGED
|
@@ -6433,14 +6433,14 @@ function FeatureGrid($$anchor, $$props) {
|
|
|
6433
6433
|
const FEATURE_LOADERS = {
|
|
6434
6434
|
contrast: () => import("./contrast-CqsICAkU.js"),
|
|
6435
6435
|
"text-size": () => import("./text-size-C6OFhCGi.js"),
|
|
6436
|
-
"keyboard-nav": () => import("./keyboard-nav-
|
|
6436
|
+
"keyboard-nav": () => import("./keyboard-nav-BN8NOhTx.js"),
|
|
6437
6437
|
"link-highlight": () => import("./link-highlight-DBGm067Y.js"),
|
|
6438
6438
|
"reading-guide": () => import("./reading-guide-VT8NciIL.js"),
|
|
6439
6439
|
"reading-mask": () => import("./reading-mask-BABChuCz.js"),
|
|
6440
6440
|
"animation-stop": () => import("./animation-stop-C0MwseK0.js"),
|
|
6441
6441
|
"hide-images": () => import("./hide-images-B_LeCBcd.js"),
|
|
6442
6442
|
"big-cursor": () => import("./big-cursor-B2UKu9dQ.js"),
|
|
6443
|
-
"page-structure": () => import("./page-structure-
|
|
6443
|
+
"page-structure": () => import("./page-structure-CK_agCbv.js"),
|
|
6444
6444
|
tts: () => import("./tts-CjszLRnb.js"),
|
|
6445
6445
|
"text-simplify": () => import("./text-simplify-Cvhpio7g.js"),
|
|
6446
6446
|
"alt-text": () => Promise.resolve().then(() => altText)
|
|
@@ -6811,16 +6811,28 @@ async function translateSingleText(text, sourceLang, targetLang) {
|
|
|
6811
6811
|
}
|
|
6812
6812
|
}
|
|
6813
6813
|
async function translateTexts(texts, sourceLang, targetLang) {
|
|
6814
|
-
const
|
|
6815
|
-
const
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6814
|
+
const SEP = "\n\n";
|
|
6815
|
+
const BATCH_CHAR_LIMIT = 4e3;
|
|
6816
|
+
const results = new Array(texts.length).fill("");
|
|
6817
|
+
let batchStart = 0;
|
|
6818
|
+
while (batchStart < texts.length) {
|
|
6819
|
+
const batchTexts = [];
|
|
6820
|
+
let charCount = 0;
|
|
6821
|
+
let i = batchStart;
|
|
6822
|
+
while (i < texts.length) {
|
|
6823
|
+
const nextLen = texts[i].length + SEP.length;
|
|
6824
|
+
if (charCount + nextLen > BATCH_CHAR_LIMIT && batchTexts.length > 0) break;
|
|
6825
|
+
batchTexts.push(texts[i]);
|
|
6826
|
+
charCount += nextLen;
|
|
6827
|
+
i++;
|
|
6828
|
+
}
|
|
6829
|
+
const joined = batchTexts.join(SEP);
|
|
6830
|
+
const translated = await translateSingleText(joined, sourceLang, targetLang);
|
|
6831
|
+
const lines = translated.split(/\n\s*\n/);
|
|
6832
|
+
for (let j = 0; j < batchTexts.length; j++) {
|
|
6833
|
+
results[batchStart + j] = (lines[j] || "").trim() || batchTexts[j];
|
|
6834
|
+
}
|
|
6835
|
+
batchStart = i;
|
|
6824
6836
|
}
|
|
6825
6837
|
return results;
|
|
6826
6838
|
}
|
|
@@ -6877,19 +6889,55 @@ function groupTextNodes(textNodes) {
|
|
|
6877
6889
|
const siblings = textNodes.filter((n) => !assigned.has(n) && findBlockAncestor(n) === block2);
|
|
6878
6890
|
if (siblings.length > 1) {
|
|
6879
6891
|
for (const s of siblings) assigned.add(s);
|
|
6880
|
-
|
|
6881
|
-
|
|
6882
|
-
|
|
6883
|
-
|
|
6884
|
-
});
|
|
6892
|
+
const fullText = (block2.textContent?.trim() || "").replace(/\s+/g, " ");
|
|
6893
|
+
const shortNodes = siblings.filter((n) => n.data.trim().length <= 2).length;
|
|
6894
|
+
const charPerNode = shortNodes > siblings.length * 0.5;
|
|
6895
|
+
groups.push({ nodes: siblings, fullText, singleNode: false, charPerNode });
|
|
6885
6896
|
continue;
|
|
6886
6897
|
}
|
|
6887
6898
|
}
|
|
6888
6899
|
assigned.add(node);
|
|
6889
|
-
groups.push({ nodes: [node], fullText: node.data.trim(), singleNode: true });
|
|
6900
|
+
groups.push({ nodes: [node], fullText: node.data.trim(), singleNode: true, charPerNode: false });
|
|
6890
6901
|
}
|
|
6891
6902
|
return groups;
|
|
6892
6903
|
}
|
|
6904
|
+
function distributeCharsToNodes(nodes, translated) {
|
|
6905
|
+
const origLengths = nodes.map((n) => n.data.trim().length);
|
|
6906
|
+
const origWhitespace = nodes.map((n) => ({
|
|
6907
|
+
leading: n.data.match(/^\s*/)?.[0] || "",
|
|
6908
|
+
trailing: n.data.match(/\s*$/)?.[0] || ""
|
|
6909
|
+
}));
|
|
6910
|
+
let charIdx = 0;
|
|
6911
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
6912
|
+
const origLen = origLengths[i];
|
|
6913
|
+
if (origLen === 0) {
|
|
6914
|
+
continue;
|
|
6915
|
+
}
|
|
6916
|
+
const chunk = translated.slice(charIdx, charIdx + origLen);
|
|
6917
|
+
charIdx += origLen;
|
|
6918
|
+
nodes[i].data = origWhitespace[i].leading + chunk + origWhitespace[i].trailing;
|
|
6919
|
+
}
|
|
6920
|
+
if (charIdx < translated.length) {
|
|
6921
|
+
const overflow = translated.slice(charIdx);
|
|
6922
|
+
for (let i = nodes.length - 1; i >= 0; i--) {
|
|
6923
|
+
if (origLengths[i] > 0) {
|
|
6924
|
+
nodes[i].data = nodes[i].data.trimEnd() + overflow + origWhitespace[i].trailing;
|
|
6925
|
+
break;
|
|
6926
|
+
}
|
|
6927
|
+
}
|
|
6928
|
+
}
|
|
6929
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
6930
|
+
if (origLengths[i] > 0) {
|
|
6931
|
+
const assigned = translated.slice(
|
|
6932
|
+
origLengths.slice(0, i).reduce((a, b) => a + b, 0),
|
|
6933
|
+
origLengths.slice(0, i + 1).reduce((a, b) => a + b, 0)
|
|
6934
|
+
);
|
|
6935
|
+
if (!assigned) {
|
|
6936
|
+
nodes[i].data = origWhitespace[i].leading + origWhitespace[i].trailing;
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6939
|
+
}
|
|
6940
|
+
}
|
|
6893
6941
|
function findBlockAncestor(node) {
|
|
6894
6942
|
let el = node.parentElement;
|
|
6895
6943
|
while (el && el !== document.body) {
|
|
@@ -6931,23 +6979,21 @@ async function translatePage(targetLang) {
|
|
|
6931
6979
|
});
|
|
6932
6980
|
observerPaused = true;
|
|
6933
6981
|
for (const group of nodeGroups) {
|
|
6982
|
+
const replacement = lookup.get(group.fullText);
|
|
6983
|
+
if (!replacement) continue;
|
|
6934
6984
|
if (group.singleNode) {
|
|
6935
6985
|
const node = group.nodes[0];
|
|
6936
|
-
const
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
}
|
|
6986
|
+
const leading = node.data.match(/^\s*/)?.[0] || "";
|
|
6987
|
+
const trailing = node.data.match(/\s*$/)?.[0] || "";
|
|
6988
|
+
node.data = leading + replacement + trailing;
|
|
6989
|
+
} else if (group.charPerNode) {
|
|
6990
|
+
distributeCharsToNodes(group.nodes, replacement);
|
|
6942
6991
|
} else {
|
|
6943
|
-
const
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
for (let i = 1; i < group.nodes.length; i++) {
|
|
6949
|
-
group.nodes[i].data = "";
|
|
6950
|
-
}
|
|
6992
|
+
const firstNode = group.nodes[0];
|
|
6993
|
+
const leading = firstNode.data.match(/^\s*/)?.[0] || "";
|
|
6994
|
+
firstNode.data = leading + replacement;
|
|
6995
|
+
for (let i = 1; i < group.nodes.length; i++) {
|
|
6996
|
+
group.nodes[i].data = "";
|
|
6951
6997
|
}
|
|
6952
6998
|
}
|
|
6953
6999
|
}
|
|
@@ -8536,4 +8582,4 @@ export {
|
|
|
8536
8582
|
init as i,
|
|
8537
8583
|
t
|
|
8538
8584
|
};
|
|
8539
|
-
//# sourceMappingURL=index-
|
|
8585
|
+
//# sourceMappingURL=index-C_cEJXg7.js.map
|