accessify-widget 0.3.5 → 0.3.6

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.
@@ -1,4 +1,4 @@
1
- import { d, i } from "./index-BTkeEVoS.js";
1
+ import { d, i } from "./index-DDv0soH8.js";
2
2
  export {
3
3
  d as destroy,
4
4
  i as init
@@ -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-BZ4ei-Lt.js"),
6436
+ "keyboard-nav": () => import("./keyboard-nav-DYBrrE4b.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-JY54Sj14.js"),
6443
+ "page-structure": () => import("./page-structure-BTemvR2X.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)
@@ -6877,19 +6877,55 @@ function groupTextNodes(textNodes) {
6877
6877
  const siblings = textNodes.filter((n) => !assigned.has(n) && findBlockAncestor(n) === block2);
6878
6878
  if (siblings.length > 1) {
6879
6879
  for (const s of siblings) assigned.add(s);
6880
- groups.push({
6881
- nodes: siblings,
6882
- fullText: siblings.map((n) => n.data.trim()).filter(Boolean).join(" "),
6883
- singleNode: false
6884
- });
6880
+ const fullText = (block2.textContent?.trim() || "").replace(/\s+/g, " ");
6881
+ const shortNodes = siblings.filter((n) => n.data.trim().length <= 2).length;
6882
+ const charPerNode = shortNodes > siblings.length * 0.5;
6883
+ groups.push({ nodes: siblings, fullText, singleNode: false, charPerNode });
6885
6884
  continue;
6886
6885
  }
6887
6886
  }
6888
6887
  assigned.add(node);
6889
- groups.push({ nodes: [node], fullText: node.data.trim(), singleNode: true });
6888
+ groups.push({ nodes: [node], fullText: node.data.trim(), singleNode: true, charPerNode: false });
6890
6889
  }
6891
6890
  return groups;
6892
6891
  }
6892
+ function distributeCharsToNodes(nodes, translated) {
6893
+ const origLengths = nodes.map((n) => n.data.trim().length);
6894
+ const origWhitespace = nodes.map((n) => ({
6895
+ leading: n.data.match(/^\s*/)?.[0] || "",
6896
+ trailing: n.data.match(/\s*$/)?.[0] || ""
6897
+ }));
6898
+ let charIdx = 0;
6899
+ for (let i = 0; i < nodes.length; i++) {
6900
+ const origLen = origLengths[i];
6901
+ if (origLen === 0) {
6902
+ continue;
6903
+ }
6904
+ const chunk = translated.slice(charIdx, charIdx + origLen);
6905
+ charIdx += origLen;
6906
+ nodes[i].data = origWhitespace[i].leading + chunk + origWhitespace[i].trailing;
6907
+ }
6908
+ if (charIdx < translated.length) {
6909
+ const overflow = translated.slice(charIdx);
6910
+ for (let i = nodes.length - 1; i >= 0; i--) {
6911
+ if (origLengths[i] > 0) {
6912
+ nodes[i].data = nodes[i].data.trimEnd() + overflow + origWhitespace[i].trailing;
6913
+ break;
6914
+ }
6915
+ }
6916
+ }
6917
+ for (let i = 0; i < nodes.length; i++) {
6918
+ if (origLengths[i] > 0) {
6919
+ const assigned = translated.slice(
6920
+ origLengths.slice(0, i).reduce((a, b) => a + b, 0),
6921
+ origLengths.slice(0, i + 1).reduce((a, b) => a + b, 0)
6922
+ );
6923
+ if (!assigned) {
6924
+ nodes[i].data = origWhitespace[i].leading + origWhitespace[i].trailing;
6925
+ }
6926
+ }
6927
+ }
6928
+ }
6893
6929
  function findBlockAncestor(node) {
6894
6930
  let el = node.parentElement;
6895
6931
  while (el && el !== document.body) {
@@ -6931,23 +6967,21 @@ async function translatePage(targetLang) {
6931
6967
  });
6932
6968
  observerPaused = true;
6933
6969
  for (const group of nodeGroups) {
6970
+ const replacement = lookup.get(group.fullText);
6971
+ if (!replacement) continue;
6934
6972
  if (group.singleNode) {
6935
6973
  const node = group.nodes[0];
6936
- const replacement = lookup.get(group.fullText);
6937
- if (replacement) {
6938
- const leading = node.data.match(/^\s*/)?.[0] || "";
6939
- const trailing = node.data.match(/\s*$/)?.[0] || "";
6940
- node.data = leading + replacement + trailing;
6941
- }
6974
+ const leading = node.data.match(/^\s*/)?.[0] || "";
6975
+ const trailing = node.data.match(/\s*$/)?.[0] || "";
6976
+ node.data = leading + replacement + trailing;
6977
+ } else if (group.charPerNode) {
6978
+ distributeCharsToNodes(group.nodes, replacement);
6942
6979
  } else {
6943
- const replacement = lookup.get(group.fullText);
6944
- if (replacement) {
6945
- const firstNode = group.nodes[0];
6946
- const leading = firstNode.data.match(/^\s*/)?.[0] || "";
6947
- firstNode.data = leading + replacement;
6948
- for (let i = 1; i < group.nodes.length; i++) {
6949
- group.nodes[i].data = "";
6950
- }
6980
+ const firstNode = group.nodes[0];
6981
+ const leading = firstNode.data.match(/^\s*/)?.[0] || "";
6982
+ firstNode.data = leading + replacement;
6983
+ for (let i = 1; i < group.nodes.length; i++) {
6984
+ group.nodes[i].data = "";
6951
6985
  }
6952
6986
  }
6953
6987
  }
@@ -8536,4 +8570,4 @@ export {
8536
8570
  init as i,
8537
8571
  t
8538
8572
  };
8539
- //# sourceMappingURL=index-BTkeEVoS.js.map
8573
+ //# sourceMappingURL=index-DDv0soH8.js.map