accessify-widget 0.2.2 → 0.2.3

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-i-tNypvI.js";
1
+ import { d, i } from "./index-CsJDqdBW.js";
2
2
  export {
3
3
  d as destroy,
4
4
  i as init
@@ -6310,14 +6310,14 @@ 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-CkAYxUc1.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
6317
  "animation-stop": () => import("./animation-stop-DXebPS8D.js"),
6318
6318
  "hide-images": () => import("./hide-images-DJwmsV2C.js"),
6319
6319
  "big-cursor": () => import("./big-cursor-B2UKu9dQ.js"),
6320
- "page-structure": () => import("./page-structure-GqhCQsl3.js"),
6320
+ "page-structure": () => import("./page-structure-yWkBKmwo.js"),
6321
6321
  tts: () => import("./tts-CjszLRnb.js"),
6322
6322
  "text-simplify": () => import("./text-simplify-C9gzE3t0.js"),
6323
6323
  "alt-text": () => Promise.resolve().then(() => altText)
@@ -7596,14 +7596,13 @@ function persistAltTextToServer(siteKey, proxyUrl, imageUrl, altText2, lang) {
7596
7596
  }
7597
7597
  }
7598
7598
  let autoApplied = false;
7599
- async function autoApplyCachedAltTexts() {
7599
+ async function autoApplyCachedAltTexts(widgetConfig) {
7600
7600
  if (autoApplied) return 0;
7601
7601
  autoApplied = true;
7602
7602
  const cache = /* @__PURE__ */ new Map();
7603
- const widgetConfig = window.Accessify?.config;
7604
7603
  const siteKey = widgetConfig?.siteKey;
7605
7604
  const proxyUrl = widgetConfig?.proxyUrl || "";
7606
- const pageLang = document.documentElement.lang?.split("-")[0] || "en";
7605
+ const pageLang = widgetConfig?.lang?.split("-")[0] || document.documentElement.lang?.split("-")[0] || "en";
7607
7606
  if (siteKey) {
7608
7607
  const serverCache = await fetchServerAltTexts(siteKey, proxyUrl, pageLang);
7609
7608
  for (const [url, alt] of serverCache) {
@@ -7613,8 +7612,29 @@ async function autoApplyCachedAltTexts() {
7613
7612
  }
7614
7613
  }
7615
7614
  const localCache = await getAllCachedAltTexts();
7615
+ const localOnly = [];
7616
7616
  for (const [url, alt] of localCache) {
7617
- if (!cache.has(url)) cache.set(url, alt);
7617
+ if (!cache.has(url)) {
7618
+ cache.set(url, alt);
7619
+ localOnly.push({ imageUrl: url, altText: alt });
7620
+ }
7621
+ }
7622
+ if (siteKey && localOnly.length > 0) {
7623
+ try {
7624
+ const base = proxyUrl || DEFAULT_API_BASE;
7625
+ const pageUrl = window.location.origin + window.location.pathname;
7626
+ fetch(`${base}/v1/cache/batch-persist-alt-text`, {
7627
+ method: "POST",
7628
+ headers: { "Content-Type": "application/json" },
7629
+ body: JSON.stringify({
7630
+ siteKey,
7631
+ pageUrl,
7632
+ entries: localOnly.map((e) => ({ ...e, lang: pageLang }))
7633
+ })
7634
+ }).catch(() => {
7635
+ });
7636
+ } catch {
7637
+ }
7618
7638
  }
7619
7639
  if (cache.size === 0) return 0;
7620
7640
  let applied = 0;
@@ -8310,7 +8330,7 @@ async function init(userConfig = {}) {
8310
8330
  }
8311
8331
  });
8312
8332
  document.body.appendChild(containerEl);
8313
- autoApplyCachedAltTexts().catch(() => {
8333
+ autoApplyCachedAltTexts(config).catch(() => {
8314
8334
  });
8315
8335
  config.onReady?.();
8316
8336
  }
@@ -8353,4 +8373,4 @@ export {
8353
8373
  init as i,
8354
8374
  t
8355
8375
  };
8356
- //# sourceMappingURL=index-i-tNypvI.js.map
8376
+ //# sourceMappingURL=index-CsJDqdBW.js.map