@jay-framework/a11y-validator 0.22.0 → 0.22.2

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -0
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -208,6 +208,7 @@ const validate = (ctx) => {
208
208
  }
209
209
  }
210
210
  });
211
+ checkDuplicateAdjacentText(ctx.body, findings);
211
212
  if (ctx.head) {
212
213
  const viewport = ctx.head.meta.find((m) => m.name?.toLowerCase() === "viewport");
213
214
  if (viewport) {
@@ -268,6 +269,35 @@ function collectLabelForIds(el, ids) {
268
269
  collectLabelForIds(child, ids);
269
270
  }
270
271
  }
272
+ function getVisibleText(el) {
273
+ if (el.getAttribute?.("aria-hidden") === "true")
274
+ return "";
275
+ return (el.textContent ?? "").trim().replace(/\s+/g, " ");
276
+ }
277
+ function checkDuplicateAdjacentText(root, findings) {
278
+ function walk(el) {
279
+ const children = (el.childNodes ?? []).filter((n) => n.nodeType === 1);
280
+ for (let i = 0; i < children.length - 1; i++) {
281
+ const current = children[i];
282
+ const next = children[i + 1];
283
+ const currentText = getVisibleText(current);
284
+ const nextText = getVisibleText(next);
285
+ if (currentText && nextText && currentText === nextText && current.getAttribute?.("aria-hidden") !== "true" && next.getAttribute?.("aria-hidden") !== "true") {
286
+ const tag = next.rawTagName?.toLowerCase() || "element";
287
+ findings.push({
288
+ severity: "warning",
289
+ message: `Adjacent <${current.rawTagName?.toLowerCase()}> and <${tag}> have identical text "${currentText.slice(0, 40)}${currentText.length > 40 ? "..." : ""}" — screen readers will announce it twice`,
290
+ suggestion: 'Add aria-hidden="true" to the decorative duplicate. If both are meaningful, differentiate their text content.',
291
+ element: `<${tag}>`
292
+ });
293
+ }
294
+ }
295
+ for (const child of children) {
296
+ walk(child);
297
+ }
298
+ }
299
+ walk(root);
300
+ }
271
301
  export {
272
302
  validate
273
303
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/a11y-validator",
3
- "version": "0.22.0",
3
+ "version": "0.22.2",
4
4
  "type": "module",
5
5
  "description": "Accessibility validation plugin for Jay Framework — checks jay-html templates for WCAG best practices",
6
6
  "license": "Apache-2.0",
@@ -24,11 +24,11 @@
24
24
  "test": "vitest run"
25
25
  },
26
26
  "dependencies": {
27
- "@jay-framework/compiler-shared": "^0.22.0"
27
+ "@jay-framework/compiler-shared": "^0.22.2"
28
28
  },
29
29
  "devDependencies": {
30
- "@jay-framework/dev-environment": "^0.22.0",
31
- "@jay-framework/jay-stack-cli": "^0.22.0",
30
+ "@jay-framework/dev-environment": "^0.22.2",
31
+ "@jay-framework/jay-stack-cli": "^0.22.2",
32
32
  "@types/node": "^22.15.21",
33
33
  "node-html-parser": "^6.1.0",
34
34
  "rimraf": "^5.0.5",