accessibility-plugin-react 2.30.0 → 2.30.1

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.
package/dist/index.mjs CHANGED
@@ -1336,7 +1336,7 @@ function isFunctionalOrMeaningfulImage(el) {
1336
1336
  return true;
1337
1337
  }
1338
1338
  if (el.closest(
1339
- "[role='graphics-document'], [role='graphics-symbol'], [role='figure'], figure, [class*='chart' i], [id*='chart' i], [class*='graph' i], [id*='graph' i], [class*='diagram' i], [id*='diagram' i]"
1339
+ "[role='graphics-document'], [role='graphics-symbol'], [class*='chart' i], [id*='chart' i], [class*='graph' i], [id*='graph' i], [class*='diagram' i], [id*='diagram' i]"
1340
1340
  ) || el.matches(
1341
1341
  "[role='graphics-document'], [role='graphics-symbol'], [aria-roledescription*='chart' i]"
1342
1342
  )) {
@@ -1359,6 +1359,22 @@ function isFunctionalOrMeaningfulImage(el) {
1359
1359
  if (el.closest("[role='math'], math, [class*='math' i]")) {
1360
1360
  return true;
1361
1361
  }
1362
+ const hasExplicitDecorativeMarker = (node) => {
1363
+ if (node.hasAttribute("data-decorative") && node.getAttribute("data-decorative") !== "false") {
1364
+ return true;
1365
+ }
1366
+ if (node.classList.contains("decorative") || node.classList.contains("deco")) {
1367
+ return true;
1368
+ }
1369
+ const nodeRole = node.getAttribute("role");
1370
+ if (nodeRole === "presentation" || nodeRole === "none") {
1371
+ return true;
1372
+ }
1373
+ return node.getAttribute("aria-hidden") === "true";
1374
+ };
1375
+ if (hasExplicitDecorativeMarker(el) || el.parentElement?.matches("picture") && hasExplicitDecorativeMarker(el.parentElement)) {
1376
+ return false;
1377
+ }
1362
1378
  if (el.hasAttribute("alt")) {
1363
1379
  const alt = el.getAttribute("alt")?.trim();
1364
1380
  if (alt && alt.length > 0) return true;
@@ -1403,7 +1419,7 @@ function isEligibleDecorativeImage(el) {
1403
1419
  if (el.getAttribute("aria-hidden") === "true") {
1404
1420
  return true;
1405
1421
  }
1406
- if (el.hasAttribute("data-decorative") || el.classList.contains("decorative") || el.classList.contains("deco")) {
1422
+ if (el.hasAttribute("data-decorative") && el.getAttribute("data-decorative") !== "false" || el.classList.contains("decorative") || el.classList.contains("deco")) {
1407
1423
  return true;
1408
1424
  }
1409
1425
  if (el.matches("picture")) {
@@ -1439,6 +1455,15 @@ function resolveEffectScope(scope) {
1439
1455
  }
1440
1456
  return document.body ?? null;
1441
1457
  }
1458
+ function resolveActiveContrastPalette(values) {
1459
+ if (isForcedColorsActive()) {
1460
+ return { activePalette: null, fallbackColors: null };
1461
+ }
1462
+ const activeContrastKey = values.contrastMode && values.contrastMode !== "off" && values.contrastMode !== "original" ? String(values.contrastMode) : values.contrast !== void 0 && values.contrast !== 0 && values.contrast !== "0" && values.contrast !== "off" && values.contrast !== "original" ? String(values.contrast) : null;
1463
+ const activePalette = activeContrastKey ? CONTRAST_PALETTES[activeContrastKey] ?? null : null;
1464
+ const fallbackColors = !activePalette ? palette[String(values.contrast)] ?? null : null;
1465
+ return { activePalette, fallbackColors };
1466
+ }
1442
1467
  function applyToElements(elements, values, undo, styledElements, isFinePointer, set) {
1443
1468
  const targetElements = [];
1444
1469
  for (const el of elements) {
@@ -1598,8 +1623,7 @@ function applyToElements(elements, values, undo, styledElements, isFinePointer,
1598
1623
  }
1599
1624
  }
1600
1625
  }
1601
- const activeContrastKey = values.contrastMode && values.contrastMode !== "off" && values.contrastMode !== "original" ? String(values.contrastMode) : values.contrast !== void 0 && values.contrast !== 0 && values.contrast !== "0" && values.contrast !== "off" && values.contrast !== "original" ? String(values.contrast) : null;
1602
- const activePalette = activeContrastKey && !isForcedColorsActive() ? CONTRAST_PALETTES[activeContrastKey] : null;
1626
+ const { activePalette, fallbackColors } = resolveActiveContrastPalette(values);
1603
1627
  if (activePalette) {
1604
1628
  for (const el of targetElements) {
1605
1629
  if (isProtectedFromContrast(el)) continue;
@@ -1647,13 +1671,12 @@ function applyToElements(elements, values, undo, styledElements, isFinePointer,
1647
1671
  }
1648
1672
  }
1649
1673
  if (values.hideVideos && el.matches(
1650
- 'video, iframe[src*="youtube.com/embed/"], iframe[src*="youtube-nocookie.com/embed/"], iframe[src*="youtu.be/"], iframe[src*="player.vimeo.com/video/"], iframe[src*="player.twitch.tv/"], iframe[src*="dailymotion.com/embed/"], iframe[src*="loom.com/embed/"], iframe[src*="wistia."], iframe[data-src*="youtube"], iframe[data-src*="vimeo"], iframe[data-src*="twitch.tv"], iframe[data-src*="dailymotion"], iframe[data-src*="loom.com"]'
1674
+ 'video, [data-video], .video-placeholder, iframe[src*="youtube.com/embed/"], iframe[src*="youtube-nocookie.com/embed/"], iframe[src*="youtu.be/"], iframe[src*="player.vimeo.com/video/"], iframe[src*="player.twitch.tv/"], iframe[src*="dailymotion.com/embed/"], iframe[src*="loom.com/embed/"], iframe[src*="wistia."], iframe[data-src*="youtube"], iframe[data-src*="vimeo"], iframe[data-src*="twitch.tv"], iframe[data-src*="dailymotion"], iframe[data-src*="loom.com"]'
1651
1675
  ))
1652
1676
  set(el, "visibility", "hidden");
1653
- const colors = palette[String(values.contrast)];
1654
- if (colors && !activePalette && !isForcedColorsActive()) {
1655
- set(el, "color", colors[0]);
1656
- set(el, "background-color", colors[1]);
1677
+ if (fallbackColors) {
1678
+ set(el, "color", fallbackColors[0]);
1679
+ set(el, "background-color", fallbackColors[1]);
1657
1680
  }
1658
1681
  if (values.linkHighlight && el.matches("a[href]") && !el.closest("[data-arap-ui]")) {
1659
1682
  const isDisabled = el.getAttribute("aria-disabled") === "true" || el.hasAttribute("disabled") || el.classList.contains("disabled");
@@ -1664,12 +1687,12 @@ function applyToElements(elements, values, undo, styledElements, isFinePointer,
1664
1687
  set(el, "text-decoration-thickness", "2px");
1665
1688
  set(el, "text-underline-offset", "3px");
1666
1689
  } else {
1667
- const colors2 = palette[String(values.linkHighlight)] ?? [
1690
+ const colors = palette[String(values.linkHighlight)] ?? [
1668
1691
  "#111827",
1669
1692
  "#fef08a"
1670
1693
  ];
1671
- set(el, "color", colors2[0]);
1672
- set(el, "background-color", colors2[1]);
1694
+ set(el, "color", colors[0]);
1695
+ set(el, "background-color", colors[1]);
1673
1696
  set(el, "text-decoration", "underline");
1674
1697
  set(el, "text-decoration-thickness", "2px");
1675
1698
  set(el, "text-underline-offset", "3px");
@@ -1735,6 +1758,20 @@ function applyPageSession(values, optionsOrScope) {
1735
1758
  applyContainerFilter(targetRoot);
1736
1759
  }
1737
1760
  }
1761
+ const rootContrast = resolveActiveContrastPalette(values);
1762
+ if (targetRoot && !targetRoot.matches(EXCLUDED)) {
1763
+ if (rootContrast.activePalette) {
1764
+ set(targetRoot, "color", rootContrast.activePalette.text);
1765
+ set(
1766
+ targetRoot,
1767
+ "background-color",
1768
+ rootContrast.activePalette.background
1769
+ );
1770
+ } else if (rootContrast.fallbackColors) {
1771
+ set(targetRoot, "color", rootContrast.fallbackColors[0]);
1772
+ set(targetRoot, "background-color", rootContrast.fallbackColors[1]);
1773
+ }
1774
+ }
1738
1775
  const smartContrastVal = values.smartContrast;
1739
1776
  if ((smartContrastVal === true || smartContrastVal === "aa" || smartContrastVal === "aaa") && !isForcedColorsActive()) {
1740
1777
  const targetLevel = smartContrastVal === "aaa" ? "aaa" : "aa";
@@ -2108,7 +2145,9 @@ function useBuiltinEffects(values, onDisable, optionsOrScope) {
2108
2145
  hasRootAttributeChange = true;
2109
2146
  } else if ((values.hideImages || values.hideVideos) && record.target instanceof HTMLElement && !record.target.closest(
2110
2147
  "[data-arap-ui], [data-arap-diagnostics], .arap-root"
2111
- ) && record.target.matches("img, picture, video, iframe")) {
2148
+ ) && record.target.matches(
2149
+ "img, picture, video, [data-video], .video-placeholder, iframe"
2150
+ )) {
2112
2151
  added.push(record.target);
2113
2152
  }
2114
2153
  } else if (record.type === "childList") {
@@ -13067,6 +13106,177 @@ function createOfflineMockTranslationAdapter(options) {
13067
13106
  }
13068
13107
  };
13069
13108
  }
13109
+ var GOOGLE_TRANSLATE_DEFAULT_ENDPOINT = "https://translate.googleapis.com/translate_a/single";
13110
+ var GOOGLE_TRANSLATE_SUPPORTED_LANGUAGES = [
13111
+ "es",
13112
+ "fr",
13113
+ "de",
13114
+ "si",
13115
+ "ta",
13116
+ "ja",
13117
+ "zh",
13118
+ "ar",
13119
+ "hi",
13120
+ "pt",
13121
+ "ru",
13122
+ "ko",
13123
+ "it",
13124
+ "nl"
13125
+ ];
13126
+ var LETTER_OR_SCRIPT_PATTERN = /\p{L}/u;
13127
+ function parseGoogleTranslateResponse(data) {
13128
+ if (!Array.isArray(data) || !Array.isArray(data[0])) {
13129
+ return "";
13130
+ }
13131
+ const parts = [];
13132
+ for (const segment of data[0]) {
13133
+ if (Array.isArray(segment) && typeof segment[0] === "string") {
13134
+ parts.push(segment[0]);
13135
+ }
13136
+ }
13137
+ return parts.join("");
13138
+ }
13139
+ function createGoogleTranslateAdapter(options) {
13140
+ const endpoint = options?.endpoint ?? GOOGLE_TRANSLATE_DEFAULT_ENDPOINT;
13141
+ const concurrency = Math.max(1, options?.concurrency ?? 6);
13142
+ const fallbackToOffline = options?.fallbackToOffline ?? true;
13143
+ const resolvedFetch = options?.fetchImpl ?? (typeof fetch !== "undefined" ? fetch.bind(globalThis) : void 0);
13144
+ const cache = /* @__PURE__ */ new Map();
13145
+ return {
13146
+ id: "google-translate-adapter",
13147
+ name: "Google Translate",
13148
+ description: "Client-side machine translation powered by Google Translate with automatic offline fallback.",
13149
+ privacyPolicyUrl: "https://policies.google.com/privacy",
13150
+ dataRetention: "transient",
13151
+ dataResidency: "global",
13152
+ supportedTargetLanguages: GOOGLE_TRANSLATE_SUPPORTED_LANGUAGES,
13153
+ translate: async (request) => {
13154
+ if (request.signal?.aborted) {
13155
+ throw new TranslationError(
13156
+ TRANSLATION_ERROR_CODES.ABORTED,
13157
+ "Translation request was aborted."
13158
+ );
13159
+ }
13160
+ const sourceLang = (request.sourceLanguage || "auto").trim().toLowerCase();
13161
+ const baseTarget = request.targetLanguage.trim().toLowerCase().split("-")[0];
13162
+ const pendingKeys = [];
13163
+ const seenKeys = /* @__PURE__ */ new Set();
13164
+ for (const raw of request.texts) {
13165
+ const trimmed = raw.trim();
13166
+ if (!trimmed || !LETTER_OR_SCRIPT_PATTERN.test(trimmed)) {
13167
+ continue;
13168
+ }
13169
+ const cacheKey = `${sourceLang}:${baseTarget}:${trimmed}`;
13170
+ if (!cache.has(cacheKey) && !seenKeys.has(trimmed)) {
13171
+ seenKeys.add(trimmed);
13172
+ pendingKeys.push(trimmed);
13173
+ }
13174
+ }
13175
+ let cursor2 = 0;
13176
+ const translateSingle = async (textKey) => {
13177
+ if (request.signal?.aborted) {
13178
+ throw new TranslationError(
13179
+ TRANSLATION_ERROR_CODES.ABORTED,
13180
+ "Translation request was aborted."
13181
+ );
13182
+ }
13183
+ const cacheKey = `${sourceLang}:${baseTarget}:${textKey}`;
13184
+ if (!resolvedFetch) {
13185
+ if (!fallbackToOffline) {
13186
+ throw new TranslationError(
13187
+ TRANSLATION_ERROR_CODES.NETWORK_ERROR,
13188
+ "Fetch API is not available for Google Translate requests."
13189
+ );
13190
+ }
13191
+ cache.set(
13192
+ cacheKey,
13193
+ translateOfflineText(textKey, request.targetLanguage)
13194
+ );
13195
+ return;
13196
+ }
13197
+ const url = `${endpoint}?client=gtx&sl=${encodeURIComponent(
13198
+ sourceLang
13199
+ )}&tl=${encodeURIComponent(baseTarget)}&dt=t&q=${encodeURIComponent(
13200
+ textKey
13201
+ )}`;
13202
+ try {
13203
+ const response = await resolvedFetch(url, {
13204
+ method: "GET",
13205
+ signal: request.signal
13206
+ });
13207
+ if (!response.ok) {
13208
+ throw new Error(`HTTP ${response.status}`);
13209
+ }
13210
+ const json = await response.json();
13211
+ const parsed = sanitizeTranslationOutput(
13212
+ parseGoogleTranslateResponse(json)
13213
+ );
13214
+ cache.set(cacheKey, parsed || textKey);
13215
+ } catch (err) {
13216
+ const isAbort = request.signal?.aborted || err instanceof Error && err.name === "AbortError" || err instanceof TranslationError && err.code === TRANSLATION_ERROR_CODES.ABORTED;
13217
+ if (isAbort) {
13218
+ throw new TranslationError(
13219
+ TRANSLATION_ERROR_CODES.ABORTED,
13220
+ "Translation request was aborted.",
13221
+ err
13222
+ );
13223
+ }
13224
+ if (!fallbackToOffline) {
13225
+ const msg = err instanceof Error ? err.message : String(err);
13226
+ throw new TranslationError(
13227
+ TRANSLATION_ERROR_CODES.NETWORK_ERROR,
13228
+ `Google Translate request failed: ${msg}`,
13229
+ err
13230
+ );
13231
+ }
13232
+ cache.set(
13233
+ cacheKey,
13234
+ translateOfflineText(textKey, request.targetLanguage)
13235
+ );
13236
+ }
13237
+ };
13238
+ const workerCount = Math.min(concurrency, pendingKeys.length);
13239
+ if (workerCount > 0) {
13240
+ const workers = Array.from({ length: workerCount }, async () => {
13241
+ while (cursor2 < pendingKeys.length) {
13242
+ const nextIndex = cursor2;
13243
+ cursor2 += 1;
13244
+ const key = pendingKeys[nextIndex];
13245
+ if (key !== void 0) {
13246
+ await translateSingle(key);
13247
+ }
13248
+ }
13249
+ });
13250
+ await Promise.all(workers);
13251
+ }
13252
+ const translations = request.texts.map((raw) => {
13253
+ const trimmed = raw.trim();
13254
+ if (!trimmed || !LETTER_OR_SCRIPT_PATTERN.test(trimmed)) {
13255
+ return {
13256
+ original: raw,
13257
+ translated: raw,
13258
+ detectedSourceLanguage: request.sourceLanguage || "en"
13259
+ };
13260
+ }
13261
+ const leading = raw.match(/^\s*/)?.[0] ?? "";
13262
+ const trailing = raw.match(/\s*$/)?.[0] ?? "";
13263
+ const cacheKey = `${sourceLang}:${baseTarget}:${trimmed}`;
13264
+ const translatedCore = cache.get(cacheKey) ?? trimmed;
13265
+ return {
13266
+ original: raw,
13267
+ translated: `${leading}${translatedCore}${trailing}`,
13268
+ detectedSourceLanguage: request.sourceLanguage || "en"
13269
+ };
13270
+ });
13271
+ return {
13272
+ translations,
13273
+ providerId: "google-translate-adapter",
13274
+ timestamp: Date.now(),
13275
+ attribution: "Powered by Google Translate"
13276
+ };
13277
+ }
13278
+ };
13279
+ }
13070
13280
  async function translateHostContent(options) {
13071
13281
  const {
13072
13282
  rootElement = document.body,
@@ -13149,7 +13359,14 @@ var DEFAULT_TARGET_LANGUAGES = [
13149
13359
  { code: "si", label: "Sinhala (\u0DC3\u0DD2\u0D82\u0DC4\u0DBD)" },
13150
13360
  { code: "ta", label: "Tamil (\u0BA4\u0BAE\u0BBF\u0BB4\u0BCD)" },
13151
13361
  { code: "ja", label: "Japanese (\u65E5\u672C\u8A9E)" },
13152
- { code: "zh", label: "Chinese (\u4E2D\u6587)" }
13362
+ { code: "zh", label: "Chinese (\u4E2D\u6587)" },
13363
+ { code: "ar", label: "Arabic (\u0627\u0644\u0639\u0631\u0628\u064A\u0629)" },
13364
+ { code: "hi", label: "Hindi (\u0939\u093F\u0928\u094D\u0926\u0940)" },
13365
+ { code: "pt", label: "Portuguese (Portugu\xEAs)" },
13366
+ { code: "ru", label: "Russian (\u0420\u0443\u0441\u0441\u043A\u0438\u0439)" },
13367
+ { code: "ko", label: "Korean (\uD55C\uAD6D\uC5B4)" },
13368
+ { code: "it", label: "Italian (Italiano)" },
13369
+ { code: "nl", label: "Dutch (Nederlands)" }
13153
13370
  ];
13154
13371
  var TranslationController = ({
13155
13372
  className = "",
@@ -13160,7 +13377,7 @@ var TranslationController = ({
13160
13377
  }) => {
13161
13378
  const { value: isTranslationEnabled, setValue: setIsTranslationEnabled } = useAccessibility("translation", false);
13162
13379
  const [provider] = useState16(() => {
13163
- return customProvider || createOfflineMockTranslationAdapter();
13380
+ return customProvider || createGoogleTranslateAdapter();
13164
13381
  });
13165
13382
  const [targetLang, setTargetLang] = useState16(defaultTargetLanguage);
13166
13383
  const [consent, setConsent] = useState16({
@@ -14707,6 +14924,7 @@ export {
14707
14924
  compositeRgba,
14708
14925
  countWords,
14709
14926
  createCustomPreset,
14927
+ createGoogleTranslateAdapter,
14710
14928
  createInitialPreferencesState,
14711
14929
  createOfflineMockTranslationAdapter,
14712
14930
  createVoiceNavigationSession,