accessify-widget 0.3.9 → 0.3.11

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-DabFemHm.js";
1
+ import { d, i } from "./index-CK-JGSFG.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-BAnuU08t.js"),
6436
+ "keyboard-nav": () => import("./keyboard-nav-BK_UYLtc.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-DjY63saM.js"),
6443
+ "page-structure": () => import("./page-structure-C7f5kvRE.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)
@@ -8162,82 +8162,110 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8162
8162
  }
8163
8163
  });
8164
8164
  }
8165
- const INFO_BADGE_CLASS = "accessify-alt-badge";
8166
- const INFO_TOOLTIP_CLASS = "accessify-alt-tooltip";
8167
- let styleEl = null;
8168
- function injectBadgeStyles() {
8169
- if (styleEl) return;
8170
- styleEl = document.createElement("style");
8171
- styleEl.textContent = `
8172
- .${INFO_BADGE_CLASS} {
8173
- position: absolute;
8174
- top: 6px;
8175
- left: 6px;
8176
- width: 22px;
8177
- height: 22px;
8178
- border-radius: 50%;
8179
- background: rgba(0,0,0,0.55);
8180
- color: #fff;
8181
- font: bold 13px/22px sans-serif;
8182
- text-align: center;
8183
- cursor: default;
8184
- z-index: 10;
8185
- pointer-events: auto;
8186
- transition: background 0.15s;
8187
- box-shadow: 0 1px 3px rgba(0,0,0,0.3);
8188
- }
8189
- .${INFO_BADGE_CLASS}:hover {
8190
- background: rgba(0,0,0,0.8);
8191
- }
8192
- .${INFO_TOOLTIP_CLASS} {
8193
- display: none;
8194
- position: absolute;
8195
- top: 32px;
8196
- left: 0;
8197
- min-width: 180px;
8198
- max-width: 300px;
8199
- padding: 8px 10px;
8200
- background: rgba(0,0,0,0.85);
8201
- color: #fff;
8202
- font: normal 12px/1.4 sans-serif;
8203
- border-radius: 6px;
8204
- z-index: 11;
8205
- pointer-events: none;
8206
- word-wrap: break-word;
8207
- box-shadow: 0 2px 8px rgba(0,0,0,0.3);
8208
- }
8209
- .${INFO_BADGE_CLASS}:hover + .${INFO_TOOLTIP_CLASS},
8210
- .${INFO_BADGE_CLASS}:focus + .${INFO_TOOLTIP_CLASS} {
8211
- display: block;
8212
- }
8213
- `;
8214
- document.head.appendChild(styleEl);
8215
- }
8165
+ const BADGE_ATTR = "data-accessify-badge";
8216
8166
  function addInfoBadge(target, altText2) {
8217
- const parent = target.tagName === "IMG" ? target.parentElement : target;
8218
- if (!parent) return;
8219
- if (parent.querySelector(`.${INFO_BADGE_CLASS}`)) return;
8220
- const pos = getComputedStyle(parent).position;
8221
- if (pos === "static") parent.style.position = "relative";
8222
- const badge = document.createElement("span");
8223
- badge.className = INFO_BADGE_CLASS;
8167
+ if (target.getAttribute(BADGE_ATTR)) return;
8168
+ const rect = target.getBoundingClientRect();
8169
+ if (rect.width < 40 || rect.height < 40) {
8170
+ if (target.tagName === "IMG") {
8171
+ const obs = new IntersectionObserver((entries) => {
8172
+ for (const entry of entries) {
8173
+ if (entry.isIntersecting && entry.boundingClientRect.width >= 40) {
8174
+ obs.disconnect();
8175
+ if (enabled && !target.getAttribute(BADGE_ATTR)) {
8176
+ addInfoBadge(target, altText2);
8177
+ }
8178
+ }
8179
+ }
8180
+ });
8181
+ obs.observe(target);
8182
+ setTimeout(() => obs.disconnect(), 3e4);
8183
+ }
8184
+ return;
8185
+ }
8186
+ target.setAttribute(BADGE_ATTR, "1");
8187
+ const container = document.createElement("div");
8188
+ Object.assign(container.style, {
8189
+ position: "fixed",
8190
+ top: `${rect.top + 6}px`,
8191
+ left: `${rect.left + 6}px`,
8192
+ zIndex: "99999",
8193
+ pointerEvents: "auto"
8194
+ });
8195
+ container.setAttribute("data-accessify-badge-container", "1");
8196
+ const badge = document.createElement("div");
8197
+ Object.assign(badge.style, {
8198
+ width: "24px",
8199
+ height: "24px",
8200
+ borderRadius: "50%",
8201
+ background: "rgba(0,0,0,0.6)",
8202
+ color: "#fff",
8203
+ fontFamily: "sans-serif",
8204
+ fontWeight: "bold",
8205
+ fontSize: "14px",
8206
+ lineHeight: "24px",
8207
+ textAlign: "center",
8208
+ cursor: "default",
8209
+ boxShadow: "0 1px 4px rgba(0,0,0,0.4)",
8210
+ transition: "background 0.15s"
8211
+ });
8224
8212
  badge.textContent = "i";
8225
8213
  badge.setAttribute("aria-hidden", "true");
8226
- const tooltip = document.createElement("span");
8227
- tooltip.className = INFO_TOOLTIP_CLASS;
8214
+ const tooltip = document.createElement("div");
8215
+ Object.assign(tooltip.style, {
8216
+ display: "none",
8217
+ position: "absolute",
8218
+ top: "28px",
8219
+ left: "0",
8220
+ minWidth: "160px",
8221
+ maxWidth: "300px",
8222
+ padding: "8px 10px",
8223
+ background: "rgba(0,0,0,0.88)",
8224
+ color: "#fff",
8225
+ fontFamily: "sans-serif",
8226
+ fontSize: "12px",
8227
+ lineHeight: "1.4",
8228
+ borderRadius: "6px",
8229
+ pointerEvents: "none",
8230
+ wordWrap: "break-word",
8231
+ boxShadow: "0 2px 8px rgba(0,0,0,0.3)"
8232
+ });
8228
8233
  tooltip.textContent = altText2;
8229
- parent.appendChild(badge);
8230
- parent.appendChild(tooltip);
8234
+ badge.addEventListener("mouseenter", () => {
8235
+ badge.style.background = "rgba(0,0,0,0.85)";
8236
+ tooltip.style.display = "block";
8237
+ });
8238
+ badge.addEventListener("mouseleave", () => {
8239
+ badge.style.background = "rgba(0,0,0,0.6)";
8240
+ tooltip.style.display = "none";
8241
+ });
8242
+ container.appendChild(badge);
8243
+ container.appendChild(tooltip);
8244
+ document.body.appendChild(container);
8245
+ const updatePos = () => {
8246
+ const r = target.getBoundingClientRect();
8247
+ container.style.top = `${r.top + 6}px`;
8248
+ container.style.left = `${r.left + 6}px`;
8249
+ container.style.display = r.bottom < 0 || r.top > window.innerHeight ? "none" : "";
8250
+ };
8251
+ const scrollHandler = () => requestAnimationFrame(updatePos);
8252
+ window.addEventListener("scroll", scrollHandler, { passive: true });
8253
+ window.addEventListener("resize", scrollHandler, { passive: true });
8254
+ container._cleanup = () => {
8255
+ window.removeEventListener("scroll", scrollHandler);
8256
+ window.removeEventListener("resize", scrollHandler);
8257
+ };
8231
8258
  }
8232
8259
  function removeAllBadges() {
8233
- document.querySelectorAll(`.${INFO_BADGE_CLASS}, .${INFO_TOOLTIP_CLASS}`).forEach((el) => el.remove());
8234
- if (styleEl) {
8235
- styleEl.remove();
8236
- styleEl = null;
8237
- }
8260
+ document.querySelectorAll("[data-accessify-badge-container]").forEach((el) => {
8261
+ el._cleanup?.();
8262
+ el.remove();
8263
+ });
8264
+ document.querySelectorAll(`[${BADGE_ATTR}]`).forEach((el) => {
8265
+ el.removeAttribute(BADGE_ATTR);
8266
+ });
8238
8267
  }
8239
8268
  function addBadgesToAllImages() {
8240
- injectBadgeStyles();
8241
8269
  document.querySelectorAll("img").forEach((img) => {
8242
8270
  if (!isValidImage(img)) return;
8243
8271
  const alt = img.getAttribute("alt") || img.getAttribute("title");
@@ -8405,9 +8433,12 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8405
8433
  generateSingle(img);
8406
8434
  } else {
8407
8435
  const alt = img.getAttribute("alt");
8408
- if (alt && alt.trim() && !img.getAttribute("title")) {
8409
- img.setAttribute("title", alt);
8410
- img.setAttribute("data-accessify-title", "auto");
8436
+ if (alt && alt.trim()) {
8437
+ if (!img.getAttribute("title")) {
8438
+ img.setAttribute("title", alt);
8439
+ img.setAttribute("data-accessify-title", "auto");
8440
+ }
8441
+ addInfoBadge(img, alt.trim());
8411
8442
  }
8412
8443
  }
8413
8444
  }
@@ -8437,13 +8468,15 @@ function createAltTextModule(aiService, initialLang = "de", serverConfig) {
8437
8468
  document.querySelectorAll("img").forEach((img) => {
8438
8469
  if (!img.complete) tryRegisterImage(img);
8439
8470
  });
8440
- setTimeout(() => {
8441
- if (enabled) {
8442
- document.querySelectorAll("img").forEach(tryRegisterImage);
8443
- applyTitlesToAllImages();
8444
- addBadgesToAllImages();
8445
- }
8446
- }, 2e3);
8471
+ for (const delay of [2e3, 5e3, 1e4]) {
8472
+ setTimeout(() => {
8473
+ if (enabled) {
8474
+ document.querySelectorAll("img").forEach(tryRegisterImage);
8475
+ applyTitlesToAllImages();
8476
+ addBadgesToAllImages();
8477
+ }
8478
+ }, delay);
8479
+ }
8447
8480
  domObserver = new MutationObserver((mutations) => {
8448
8481
  for (const m of mutations) {
8449
8482
  for (const node of m.addedNodes) {
@@ -8675,4 +8708,4 @@ export {
8675
8708
  init as i,
8676
8709
  t
8677
8710
  };
8678
- //# sourceMappingURL=index-DabFemHm.js.map
8711
+ //# sourceMappingURL=index-CK-JGSFG.js.map