accessibility-plugin-react 2.9.0 → 2.10.0

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
@@ -818,6 +818,104 @@ function getScriptSpacingConstraints(element) {
818
818
  script: "standard"
819
819
  };
820
820
  }
821
+ function isFunctionalOrMeaningfulImage(el) {
822
+ try {
823
+ if (el.closest(
824
+ "a, button, [role='button'], [role='link'], [role='menuitem'], [role='tab'], input, select, textarea, summary"
825
+ )) {
826
+ return true;
827
+ }
828
+ if (el.closest(
829
+ "[id*='captcha' i], [class*='captcha' i], [aria-label*='captcha' i], [data-captcha]"
830
+ ) || el.matches(
831
+ "[src*='captcha' i], [alt*='captcha' i], [title*='captcha' i], [id*='captcha' i], [class*='captcha' i]"
832
+ )) {
833
+ return true;
834
+ }
835
+ if (el.closest(
836
+ "[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]"
837
+ ) || el.matches(
838
+ "[role='graphics-document'], [role='graphics-symbol'], [aria-roledescription*='chart' i]"
839
+ )) {
840
+ return true;
841
+ }
842
+ if (el.closest(
843
+ "[role='region'][aria-label*='map' i], [class*='map' i], [id*='map' i], [data-map]"
844
+ ) || el.matches(
845
+ "[src*='maps' i], [src*='tiles' i], [src*='openstreetmap' i], [src*='mapbox' i]"
846
+ )) {
847
+ return true;
848
+ }
849
+ if (el.closest(
850
+ "[class*='qr' i], [id*='qr' i], [class*='barcode' i], [id*='barcode' i]"
851
+ ) || el.matches(
852
+ "[src*='qr' i], [alt*='qr' i], [src*='barcode' i], [alt*='barcode' i]"
853
+ )) {
854
+ return true;
855
+ }
856
+ if (el.closest("[role='math'], math, [class*='math' i]")) {
857
+ return true;
858
+ }
859
+ if (el.hasAttribute("alt")) {
860
+ const alt = el.getAttribute("alt")?.trim();
861
+ if (alt && alt.length > 0) return true;
862
+ }
863
+ if (el.hasAttribute("aria-label")) {
864
+ const label = el.getAttribute("aria-label")?.trim();
865
+ if (label && label.length > 0) return true;
866
+ }
867
+ if (el.hasAttribute("aria-labelledby")) {
868
+ const labelledby = el.getAttribute("aria-labelledby")?.trim();
869
+ if (labelledby && labelledby.length > 0) return true;
870
+ }
871
+ if (el.hasAttribute("title")) {
872
+ const title = el.getAttribute("title")?.trim();
873
+ if (title && title.length > 0) return true;
874
+ }
875
+ const role = el.getAttribute("role");
876
+ if (role && role !== "presentation" && role !== "none" && role !== "img") {
877
+ return true;
878
+ }
879
+ if (role === "img" && (el.hasAttribute("aria-label") || el.hasAttribute("aria-labelledby") || el.hasAttribute("title") || el.hasAttribute("alt") && el.getAttribute("alt")?.trim() !== "")) {
880
+ return true;
881
+ }
882
+ } catch {
883
+ return false;
884
+ }
885
+ return false;
886
+ }
887
+ function isEligibleDecorativeImage(el) {
888
+ try {
889
+ if (isFunctionalOrMeaningfulImage(el)) {
890
+ return false;
891
+ }
892
+ if (el.matches("img, picture")) {
893
+ if (el.hasAttribute("alt") && el.getAttribute("alt")?.trim() === "") {
894
+ return true;
895
+ }
896
+ const role = el.getAttribute("role");
897
+ if (role === "presentation" || role === "none") {
898
+ return true;
899
+ }
900
+ if (el.getAttribute("aria-hidden") === "true") {
901
+ return true;
902
+ }
903
+ if (el.hasAttribute("data-decorative") || el.classList.contains("decorative") || el.classList.contains("deco")) {
904
+ return true;
905
+ }
906
+ if (el.matches("picture")) {
907
+ const childImg = el.querySelector("img");
908
+ if (childImg && isEligibleDecorativeImage(childImg)) {
909
+ return true;
910
+ }
911
+ }
912
+ return false;
913
+ }
914
+ } catch {
915
+ return false;
916
+ }
917
+ return false;
918
+ }
821
919
  function applyPage(values) {
822
920
  const undo = [];
823
921
  function set(element, property, value) {
@@ -1128,8 +1226,23 @@ function applyPage(values) {
1128
1226
  for (const el of elements) {
1129
1227
  if (values.bigCursor) set(el, "cursor", cursor);
1130
1228
  if (values.hideImages) {
1131
- if (el.matches("img, picture")) set(el, "visibility", "hidden");
1132
- set(el, "background-image", "none");
1229
+ if (isEligibleDecorativeImage(el)) {
1230
+ set(el, "visibility", "hidden");
1231
+ }
1232
+ if (!isFunctionalOrMeaningfulImage(el)) {
1233
+ const inlineBg = el.style.backgroundImage;
1234
+ if (inlineBg && inlineBg !== "none") {
1235
+ set(el, "background-image", "none");
1236
+ } else {
1237
+ try {
1238
+ const computedBg = getComputedStyle(el).backgroundImage;
1239
+ if (computedBg && computedBg !== "none") {
1240
+ set(el, "background-image", "none");
1241
+ }
1242
+ } catch {
1243
+ }
1244
+ }
1245
+ }
1133
1246
  }
1134
1247
  if (values.hideVideos && el.matches(
1135
1248
  'video, iframe[src*="youtube.com/embed/"], iframe[src*="youtube-nocookie.com/embed/"], iframe[src*="player.vimeo.com/video/"]'
@@ -3313,22 +3426,24 @@ function FontFamilyController() {
3313
3426
  import { jsx as jsx22, jsxs as jsxs20 } from "react/jsx-runtime";
3314
3427
  var FEATURE_KEY15 = "hideImages";
3315
3428
  var DEFAULT_VALUE15 = false;
3316
- function HideImagesController() {
3429
+ function HideImagesController({
3430
+ label = "Hide Images"
3431
+ } = {}) {
3317
3432
  const { value, setValue } = useAccessibility(
3318
3433
  FEATURE_KEY15,
3319
3434
  DEFAULT_VALUE15
3320
3435
  );
3321
- return /* @__PURE__ */ jsxs20("div", { className: "arap-feature", role: "group", "aria-label": "Hide Images", children: [
3436
+ return /* @__PURE__ */ jsxs20("div", { className: "arap-feature", role: "group", "aria-label": label, children: [
3322
3437
  /* @__PURE__ */ jsxs20("span", { className: "arap-label", children: [
3323
3438
  /* @__PURE__ */ jsx22(FeatureIcon, { name: FEATURE_KEY15 }),
3324
- /* @__PURE__ */ jsx22("span", { children: "Hide Images" })
3439
+ /* @__PURE__ */ jsx22("span", { children: label })
3325
3440
  ] }),
3326
3441
  /* @__PURE__ */ jsx22(
3327
3442
  "button",
3328
3443
  {
3329
3444
  className: `arap-toggle ${value ? "arap-toggle-active" : ""}`,
3330
3445
  onClick: () => setValue(!value),
3331
- "aria-label": "Hide Images",
3446
+ "aria-label": label,
3332
3447
  "aria-pressed": value,
3333
3448
  type: "button",
3334
3449
  children: /* @__PURE__ */ jsx22("span", { className: "arap-toggle-knob", "aria-hidden": "true" })
@@ -3336,6 +3451,7 @@ function HideImagesController() {
3336
3451
  )
3337
3452
  ] });
3338
3453
  }
3454
+ var HideDecorativeImagesController = HideImagesController;
3339
3455
 
3340
3456
  // src/features/HideVideosController.tsx
3341
3457
  import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
@@ -4055,6 +4171,7 @@ export {
4055
4171
  FontFamilyController,
4056
4172
  FontSizeController,
4057
4173
  GrayscaleController,
4174
+ HideDecorativeImagesController,
4058
4175
  HideImagesController,
4059
4176
  HideVideosController,
4060
4177
  HighlightFocusController,
@@ -4088,7 +4205,9 @@ export {
4088
4205
  enLocale,
4089
4206
  findMainLandmark,
4090
4207
  getScriptSpacingConstraints,
4208
+ isEligibleDecorativeImage,
4091
4209
  isForcedColorsActive,
4210
+ isFunctionalOrMeaningfulImage,
4092
4211
  isProtectedFromContrast,
4093
4212
  isProtectedFromFontFamily,
4094
4213
  isProtectedFromTextAlign,