accessify-widget 0.3.4 → 0.3.5

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-DcqLuguC.js";
1
+ import { d, i } from "./index-BTkeEVoS.js";
2
2
  export {
3
3
  d as destroy,
4
4
  i as init
@@ -4779,7 +4779,7 @@ const deJson = {
4779
4779
  "feature.textSimplify": "Text vereinfachen",
4780
4780
  "feature.textSimplify.desc": "Text in Einfache Sprache umwandeln",
4781
4781
  "feature.altText": "Bildbeschreibung",
4782
- "feature.altText.desc": "Bilder per Klick beschreiben lassen",
4782
+ "feature.altText.desc": "Bildbeschreibungen per Hover anzeigen und fehlende automatisch erzeugen",
4783
4783
  "feature.autoScan": "WCAG-Prüfung",
4784
4784
  "feature.autoScan.desc": "Seite auf Barrierefreiheit prüfen",
4785
4785
  "feature.saturation": "Sättigung",
@@ -4868,7 +4868,7 @@ const enJson = {
4868
4868
  "feature.textSimplify": "Simplify Text",
4869
4869
  "feature.textSimplify.desc": "Simplify text for easier understanding",
4870
4870
  "feature.altText": "Image Description",
4871
- "feature.altText.desc": "Click images to get AI descriptions",
4871
+ "feature.altText.desc": "Show image descriptions on hover and auto-generate missing ones",
4872
4872
  "feature.autoScan": "WCAG Scan",
4873
4873
  "feature.autoScan.desc": "Scan page for accessibility issues",
4874
4874
  "feature.saturation": "Saturation",
@@ -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-BYCst88Y.js"),
6436
+ "keyboard-nav": () => import("./keyboard-nav-BZ4ei-Lt.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-MGMdSnYw.js"),
6443
+ "page-structure": () => import("./page-structure-JY54Sj14.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)
@@ -6866,6 +6866,38 @@ function getTranslatableAttributes(root2 = document.body) {
6866
6866
  }
6867
6867
  return attrs;
6868
6868
  }
6869
+ const BLOCK_TAGS = /* @__PURE__ */ new Set(["H1", "H2", "H3", "H4", "H5", "H6", "P", "LI", "TD", "TH", "CAPTION", "FIGCAPTION", "BLOCKQUOTE", "DT", "DD"]);
6870
+ function groupTextNodes(textNodes) {
6871
+ const groups = [];
6872
+ const assigned = /* @__PURE__ */ new Set();
6873
+ for (const node of textNodes) {
6874
+ if (assigned.has(node)) continue;
6875
+ const block2 = findBlockAncestor(node);
6876
+ if (block2 && BLOCK_TAGS.has(block2.tagName)) {
6877
+ const siblings = textNodes.filter((n) => !assigned.has(n) && findBlockAncestor(n) === block2);
6878
+ if (siblings.length > 1) {
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
+ });
6885
+ continue;
6886
+ }
6887
+ }
6888
+ assigned.add(node);
6889
+ groups.push({ nodes: [node], fullText: node.data.trim(), singleNode: true });
6890
+ }
6891
+ return groups;
6892
+ }
6893
+ function findBlockAncestor(node) {
6894
+ let el = node.parentElement;
6895
+ while (el && el !== document.body) {
6896
+ if (BLOCK_TAGS.has(el.tagName)) return el;
6897
+ el = el.parentElement;
6898
+ }
6899
+ return null;
6900
+ }
6869
6901
  async function translatePage(targetLang) {
6870
6902
  const pageLang = document.documentElement.lang?.split("-")[0] || "auto";
6871
6903
  const textNodes = getTranslatableTextNodes();
@@ -6883,8 +6915,9 @@ async function translatePage(targetLang) {
6883
6915
  savedAttrs.push(entry);
6884
6916
  }
6885
6917
  }
6918
+ const nodeGroups = groupTextNodes(textNodes);
6886
6919
  const allTexts = [
6887
- ...textNodes.map((n) => n.data.trim()),
6920
+ ...nodeGroups.map((g) => g.fullText),
6888
6921
  ...attrEntries.map((a) => a.original.trim())
6889
6922
  ].filter(Boolean);
6890
6923
  const uniqueTexts = [...new Set(allTexts)];
@@ -6897,13 +6930,25 @@ async function translatePage(targetLang) {
6897
6930
  }
6898
6931
  });
6899
6932
  observerPaused = true;
6900
- for (const node of textNodes) {
6901
- const trimmed = node.data.trim();
6902
- const replacement = lookup.get(trimmed);
6903
- if (replacement) {
6904
- const leading = node.data.match(/^\s*/)?.[0] || "";
6905
- const trailing = node.data.match(/\s*$/)?.[0] || "";
6906
- node.data = leading + replacement + trailing;
6933
+ for (const group of nodeGroups) {
6934
+ if (group.singleNode) {
6935
+ 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
+ }
6942
+ } 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
+ }
6951
+ }
6907
6952
  }
6908
6953
  }
6909
6954
  for (const entry of attrEntries) {
@@ -8075,6 +8120,79 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8075
8120
  img.removeAttribute("title");
8076
8121
  img.removeAttribute("data-accessify-title");
8077
8122
  });
8123
+ document.querySelectorAll("[data-accessify-bg-alt]").forEach((el) => {
8124
+ el.removeAttribute("role");
8125
+ el.removeAttribute("aria-label");
8126
+ el.removeAttribute("title");
8127
+ el.removeAttribute("data-accessify-bg-alt");
8128
+ });
8129
+ }
8130
+ function scanForBackgroundImages() {
8131
+ const found = [];
8132
+ const candidates = document.querySelectorAll(
8133
+ 'header, [class*="hero"], [class*="banner"], [class*="header"], [class*="bg-"], [class*="background"], [style*="background"]'
8134
+ );
8135
+ for (const el of candidates) {
8136
+ if (el.closest("#accessify-root") || el.closest("accessify-widget")) continue;
8137
+ if (el.getAttribute("data-accessify-bg-alt")) continue;
8138
+ const style = getComputedStyle(el);
8139
+ const bg = style.backgroundImage;
8140
+ if (!bg || bg === "none") continue;
8141
+ const urlMatch = bg.match(/url\(["']?([^"')]+)["']?\)/);
8142
+ if (!urlMatch) continue;
8143
+ const rect = el.getBoundingClientRect();
8144
+ if (rect.width < 100 || rect.height < 100) continue;
8145
+ if (el.getAttribute("role") === "img" && el.getAttribute("aria-label")) continue;
8146
+ found.push(el);
8147
+ }
8148
+ return found;
8149
+ }
8150
+ function getBackgroundImageUrl(el) {
8151
+ const bg = getComputedStyle(el).backgroundImage;
8152
+ const match = bg?.match(/url\(["']?([^"')]+)["']?\)/);
8153
+ return match ? match[1] : null;
8154
+ }
8155
+ function applyBgAlt(el, altText2) {
8156
+ el.setAttribute("role", "img");
8157
+ el.setAttribute("aria-label", altText2);
8158
+ el.setAttribute("title", altText2);
8159
+ el.setAttribute("data-accessify-bg-alt", "auto");
8160
+ }
8161
+ async function generateBgAlts() {
8162
+ if (!aiService || !enabled) return;
8163
+ const bgElements = scanForBackgroundImages();
8164
+ for (const el of bgElements) {
8165
+ if (!enabled) break;
8166
+ const src = getBackgroundImageUrl(el);
8167
+ if (!src) continue;
8168
+ const cached = await getCachedAltText(src);
8169
+ if (cached) {
8170
+ applyBgAlt(el, cached);
8171
+ continue;
8172
+ }
8173
+ try {
8174
+ const ctx = gatherBgContext(el);
8175
+ const alt = await aiService.generateAltText(src, ctx, lang());
8176
+ if (alt && enabled) {
8177
+ applyBgAlt(el, alt);
8178
+ setCachedAltText(src, alt, lang()).catch(() => {
8179
+ });
8180
+ if (siteKey) persistAltTextToServer(siteKey, proxyUrl, src, alt, lang());
8181
+ }
8182
+ } catch (err) {
8183
+ console.warn("[Accessify] Bg alt-text generation failed:", src, err);
8184
+ }
8185
+ }
8186
+ }
8187
+ function gatherBgContext(el) {
8188
+ const parts = [];
8189
+ parts.push(`Element: <${el.tagName.toLowerCase()}>`);
8190
+ if (el.className) parts.push(`Class: ${el.className}`);
8191
+ const text = el.textContent?.trim().slice(0, 100);
8192
+ if (text) parts.push(`Overlay text: ${text}`);
8193
+ const heading = el.querySelector("h1, h2, h3");
8194
+ if (heading?.textContent?.trim()) parts.push(`Heading: ${heading.textContent.trim()}`);
8195
+ return parts.join(". ");
8078
8196
  }
8079
8197
  async function generateAll() {
8080
8198
  if (autoGenerating || !enabled || !aiService) return;
@@ -8176,6 +8294,7 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8176
8294
  }
8177
8295
  }
8178
8296
  generateAll();
8297
+ generateBgAlts();
8179
8298
  applyTitlesToAllImages();
8180
8299
  document.querySelectorAll("img").forEach((img) => {
8181
8300
  if (!img.complete) tryRegisterImage(img);
@@ -8211,7 +8330,7 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8211
8330
  return {
8212
8331
  id: "alt-text",
8213
8332
  name: () => isDE() ? "Bildbeschreibung" : "Image Description",
8214
- description: isDE() ? "Bilder per Klick beschreiben lassen" : "Click images to get AI descriptions",
8333
+ description: isDE() ? "Bildbeschreibungen per Hover anzeigen und fehlende automatisch erzeugen" : "Show image descriptions on hover and auto-generate missing ones",
8215
8334
  icon: "alt-text",
8216
8335
  category: "ai",
8217
8336
  activate,
@@ -8417,4 +8536,4 @@ export {
8417
8536
  init as i,
8418
8537
  t
8419
8538
  };
8420
- //# sourceMappingURL=index-DcqLuguC.js.map
8539
+ //# sourceMappingURL=index-BTkeEVoS.js.map