accessify-widget 0.2.2 → 0.2.4

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.
@@ -6310,16 +6310,16 @@ function FeatureGrid($$anchor, $$props) {
6310
6310
  const FEATURE_LOADERS = {
6311
6311
  contrast: () => import("./contrast-CqsICAkU.js"),
6312
6312
  "text-size": () => import("./text-size-C6OFhCGi.js"),
6313
- "keyboard-nav": () => import("./keyboard-nav-C9zLmfrJ.js"),
6313
+ "keyboard-nav": () => import("./keyboard-nav-kiIcwX2D.js"),
6314
6314
  "link-highlight": () => import("./link-highlight-DBGm067Y.js"),
6315
6315
  "reading-guide": () => import("./reading-guide-VT8NciIL.js"),
6316
6316
  "reading-mask": () => import("./reading-mask-BABChuCz.js"),
6317
- "animation-stop": () => import("./animation-stop-DXebPS8D.js"),
6318
- "hide-images": () => import("./hide-images-DJwmsV2C.js"),
6317
+ "animation-stop": () => import("./animation-stop-CA4Sz28J.js"),
6318
+ "hide-images": () => import("./hide-images-B_LeCBcd.js"),
6319
6319
  "big-cursor": () => import("./big-cursor-B2UKu9dQ.js"),
6320
- "page-structure": () => import("./page-structure-GqhCQsl3.js"),
6320
+ "page-structure": () => import("./page-structure-CqY3jueN.js"),
6321
6321
  tts: () => import("./tts-CjszLRnb.js"),
6322
- "text-simplify": () => import("./text-simplify-C9gzE3t0.js"),
6322
+ "text-simplify": () => import("./text-simplify-B1v6Muvn.js"),
6323
6323
  "alt-text": () => Promise.resolve().then(() => altText)
6324
6324
  };
6325
6325
  let contrastMode = /* @__PURE__ */ state(proxy(readStoredContrastMode()));
@@ -7567,7 +7567,8 @@ async function fetchServerAltTexts(siteKey, proxyUrl, lang) {
7567
7567
  const base = proxyUrl || DEFAULT_API_BASE;
7568
7568
  const pageUrl = window.location.origin + window.location.pathname;
7569
7569
  const res = await fetch(`${base}/v1/manifest?siteKey=${encodeURIComponent(siteKey)}&url=${encodeURIComponent(pageUrl)}&feature=alt_text&variant=${encodeURIComponent(lang)}`, {
7570
- headers: { "Accept": "application/json" }
7570
+ headers: { "Accept": "application/json" },
7571
+ cache: "no-cache"
7571
7572
  });
7572
7573
  if (!res.ok) return map;
7573
7574
  const data = await res.json();
@@ -7596,14 +7597,13 @@ function persistAltTextToServer(siteKey, proxyUrl, imageUrl, altText2, lang) {
7596
7597
  }
7597
7598
  }
7598
7599
  let autoApplied = false;
7599
- async function autoApplyCachedAltTexts() {
7600
+ async function autoApplyCachedAltTexts(widgetConfig) {
7600
7601
  if (autoApplied) return 0;
7601
7602
  autoApplied = true;
7602
7603
  const cache = /* @__PURE__ */ new Map();
7603
- const widgetConfig = window.Accessify?.config;
7604
7604
  const siteKey = widgetConfig?.siteKey;
7605
7605
  const proxyUrl = widgetConfig?.proxyUrl || "";
7606
- const pageLang = document.documentElement.lang?.split("-")[0] || "en";
7606
+ const pageLang = widgetConfig?.lang?.split("-")[0] || document.documentElement.lang?.split("-")[0] || "en";
7607
7607
  if (siteKey) {
7608
7608
  const serverCache = await fetchServerAltTexts(siteKey, proxyUrl, pageLang);
7609
7609
  for (const [url, alt] of serverCache) {
@@ -7613,8 +7613,29 @@ async function autoApplyCachedAltTexts() {
7613
7613
  }
7614
7614
  }
7615
7615
  const localCache = await getAllCachedAltTexts();
7616
+ const localOnly = [];
7616
7617
  for (const [url, alt] of localCache) {
7617
- if (!cache.has(url)) cache.set(url, alt);
7618
+ if (!cache.has(url)) {
7619
+ cache.set(url, alt);
7620
+ localOnly.push({ imageUrl: url, altText: alt });
7621
+ }
7622
+ }
7623
+ if (siteKey && localOnly.length > 0) {
7624
+ try {
7625
+ const base = proxyUrl || DEFAULT_API_BASE;
7626
+ const pageUrl = window.location.origin + window.location.pathname;
7627
+ fetch(`${base}/v1/cache/batch-persist-alt-text`, {
7628
+ method: "POST",
7629
+ headers: { "Content-Type": "application/json" },
7630
+ body: JSON.stringify({
7631
+ siteKey,
7632
+ pageUrl,
7633
+ entries: localOnly.map((e) => ({ ...e, lang: pageLang }))
7634
+ })
7635
+ }).catch(() => {
7636
+ });
7637
+ } catch {
7638
+ }
7618
7639
  }
7619
7640
  if (cache.size === 0) return 0;
7620
7641
  let applied = 0;
@@ -7627,6 +7648,7 @@ async function autoApplyCachedAltTexts() {
7627
7648
  if (cached) {
7628
7649
  img.setAttribute("alt", cached);
7629
7650
  img.setAttribute("title", cached);
7651
+ img.setAttribute("data-accessify-alt", "auto");
7630
7652
  applied++;
7631
7653
  }
7632
7654
  });
@@ -7642,6 +7664,7 @@ async function autoApplyCachedAltTexts() {
7642
7664
  if (c) {
7643
7665
  img.setAttribute("alt", c);
7644
7666
  img.setAttribute("title", c);
7667
+ img.setAttribute("data-accessify-alt", "auto");
7645
7668
  }
7646
7669
  }
7647
7670
  }
@@ -7940,6 +7963,15 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
7940
7963
  });
7941
7964
  return missing;
7942
7965
  }
7966
+ function scanAutoApplied() {
7967
+ const images = document.querySelectorAll('img[data-accessify-alt="auto"]');
7968
+ const applied = [];
7969
+ images.forEach((img) => {
7970
+ if (img.closest("#accessify-root")) return;
7971
+ if (!processedImages.has(img)) applied.push(img);
7972
+ });
7973
+ return applied;
7974
+ }
7943
7975
  function applyAltText(img, altText2) {
7944
7976
  img.setAttribute("alt", altText2);
7945
7977
  img.setAttribute("title", altText2);
@@ -8107,8 +8139,23 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8107
8139
  if (enabled) return;
8108
8140
  enabled = true;
8109
8141
  injectStyles();
8110
- missingAltImages = scanForMissingAlt();
8111
- missingAltImages.forEach((img) => img.classList.add(HIGHLIGHT_CLASS));
8142
+ const alreadyApplied = scanAutoApplied();
8143
+ for (const img of alreadyApplied) {
8144
+ const alt = img.getAttribute("alt");
8145
+ processedImages.set(img, { generatedAlt: alt });
8146
+ missingAltImages.push(img);
8147
+ img.classList.add(HIGHLIGHT_CLASS, "accessify-alt-done");
8148
+ addInfoButton(img);
8149
+ img.removeEventListener("mouseenter", onMouseEnter);
8150
+ img.removeEventListener("mouseleave", onMouseLeave);
8151
+ img.addEventListener("mouseenter", onMouseEnter);
8152
+ img.addEventListener("mouseleave", onMouseLeave);
8153
+ }
8154
+ const missing = scanForMissingAlt();
8155
+ for (const img of missing) {
8156
+ missingAltImages.push(img);
8157
+ img.classList.add(HIGHLIGHT_CLASS);
8158
+ }
8112
8159
  updateBadge();
8113
8160
  generateAll();
8114
8161
  document.querySelectorAll("img").forEach((img) => {
@@ -8142,7 +8189,7 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8142
8189
  missingAltImages = [];
8143
8190
  removeStyles();
8144
8191
  }
8145
- autoApplyCachedAltTexts().catch(() => {
8192
+ autoApplyCachedAltTexts({ siteKey, proxyUrl, lang: initialLang }).catch(() => {
8146
8193
  });
8147
8194
  return {
8148
8195
  id: "alt-text",
@@ -8310,7 +8357,7 @@ async function init(userConfig = {}) {
8310
8357
  }
8311
8358
  });
8312
8359
  document.body.appendChild(containerEl);
8313
- autoApplyCachedAltTexts().catch(() => {
8360
+ autoApplyCachedAltTexts(config).catch(() => {
8314
8361
  });
8315
8362
  config.onReady?.();
8316
8363
  }
@@ -8353,4 +8400,4 @@ export {
8353
8400
  init as i,
8354
8401
  t
8355
8402
  };
8356
- //# sourceMappingURL=index-i-tNypvI.js.map
8403
+ //# sourceMappingURL=index-D8e7_na0.js.map