@readium/guided-navigation 1.0.0 → 1.0.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/a11y.js CHANGED
@@ -1 +1 @@
1
- import{normalizeWhitespace as c}from"./text.js";import{hasExplicitRole as g}from"./roles.js";function p(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function x(t){let s="";const u=r=>{r.nodeType===3&&(s+=r.nodeValue??"");for(let i=r.firstChild;i;i=i.nextSibling)u(i)};return u(t),s}function h(t){return c(x(t),!0).trim()}function d(t){let s="";const u=(r,i)=>{if(r.nodeType===3){s+=r.nodeValue??"";return}if(!(r.nodeType===1&&!i&&g(r)))for(let e=r.firstChild;e;e=e.nextSibling)u(e,!1)};return u(t,!0),s}function T(t){return c(d(t),!0).trim()}function w(t){if(p(t))return[null,!1];const s=(t.getAttribute("aria-labelledby")??"").trim();if(s){const e=[...new Set(s.split(/\s+/).filter(Boolean))],n=t.ownerDocument,l=e.map(o=>n.getElementById(o)).filter(o=>o!==null);if(l.length>0){let o="";l.forEach((f,b)=>{if(p(f))return;const m=f.getAttribute("aria-label");o+=m||d(f),b<l.length-1&&(o+=" ")});const a=c(o,!0).trim();if(a!=="")return[a,!0]}}const u=(t.getAttribute("aria-label")??"").trim();if(u)return[u,!0];const r=(t.getAttribute("aria-describedby")??"").trim();if(r){const n=[...new Set(r.split(/\s+/).filter(Boolean))].map(l=>t.ownerDocument.getElementById(l)).filter(l=>l!==null);if(n.length>0){const l=n.map(a=>d(a)).join(" "),o=c(l,!0).trim();if(o!=="")return[o,!0]}}const i=t.tagName.toLowerCase();if(i==="img"){const e=(t.getAttribute("alt")??"").trim();if(e)return[e,!0];const n=(t.getAttribute("title")??"").trim();if(n)return[n,!0]}else if(i==="svg"){const e=t.querySelector(":scope > title");if(e){const n=h(e);if(n)return[n,!0]}}else if(i==="math"){const e=(t.getAttribute("alttext")??"").trim();if(e)return[e,!0]}return[null,!0]}const y={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function S(t){return y[t]??["",void 0]}const B=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{S as convertElementToSSMLTag,w as extractNodeAria,h as normalizedNodeText,T as normalizedNodeTextExcludingExplicitRoles,B as skippedElements};
1
+ import{normalizeWhitespace as c}from"./text.js";import{hasExplicitRole as b}from"./roles.js";function g(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function x(t){let s="";const a=r=>{r.nodeType===3&&(s+=r.nodeValue??"");for(let i=r.firstChild;i;i=i.nextSibling)a(i)};return a(t),s}function h(t){return c(x(t),!0).trim()}function d(t){let s="";const a=(r,i)=>{if(r.nodeType===3){s+=r.nodeValue??"";return}if(!(r.nodeType===1&&!i&&b(r)))for(let e=r.firstChild;e;e=e.nextSibling)a(e,!1)};return a(t,!0),s}function T(t){return c(d(t),!0).trim()}function w(t){if(g(t))return[null,!1];const s=(t.getAttribute("aria-labelledby")??"").trim();if(s){const e=[...new Set(s.split(/\s+/).filter(Boolean))],n=t.ownerDocument,l=e.map(o=>n.getElementById(o)).filter(o=>o!==null);if(l.length>0){let o="";l.forEach((f,p)=>{const m=f.getAttribute("aria-label");o+=m||d(f),p<l.length-1&&(o+=" ")});const u=c(o,!0).trim();if(u!=="")return[u,!0]}}const a=(t.getAttribute("aria-label")??"").trim();if(a)return[a,!0];const r=(t.getAttribute("aria-describedby")??"").trim();if(r){const n=[...new Set(r.split(/\s+/).filter(Boolean))].map(l=>t.ownerDocument.getElementById(l)).filter(l=>l!==null);if(n.length>0){const l=n.map(u=>d(u)).join(" "),o=c(l,!0).trim();if(o!=="")return[o,!0]}}const i=t.tagName.toLowerCase();if(i==="img"){const e=(t.getAttribute("alt")??"").trim();if(e)return[e,!0];const n=(t.getAttribute("title")??"").trim();if(n)return[n,!0]}else if(i==="svg"){const e=t.querySelector(":scope > title");if(e){const n=h(e);if(n)return[n,!0]}}else if(i==="math"){const e=(t.getAttribute("alttext")??"").trim();if(e)return[e,!0]}return[null,!0]}const y={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function S(t){return y[t]??["",void 0]}const B=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{S as convertElementToSSMLTag,w as extractNodeAria,h as normalizedNodeText,T as normalizedNodeTextExcludingExplicitRoles,B as skippedElements};
@@ -8,6 +8,7 @@ renaming, or removing a fixture.
8
8
  | Role | Fixtures |
9
9
  | --- | --- |
10
10
  | `abstract` | `abstract-epub-type`, `abstract-role-aria` |
11
+ | `accessible-name` | `accessible-name-labelledby-aria-hidden`, `accessible-name-labelledby-hidden-attribute` |
11
12
  | `acknowledgments` | `acknowledgments-epub-type`, `acknowledgments-role-aria` |
12
13
  | `afterword` | `afterword-epub-type`, `afterword-role-aria` |
13
14
  | `appendix` | `appendix-epub-type`, `appendix-role-aria` |
@@ -77,4 +78,4 @@ renaming, or removing a fixture.
77
78
  | `toc` | `toc-epub-type`, `toc-role-aria` |
78
79
  | `video` | `video-html-native`, `video-no-description` |
79
80
 
80
- 178 fixtures across 69 roles.
81
+ 180 fixtures across 70 roles.
@@ -0,0 +1,31 @@
1
+ {
2
+ "children": [
3
+ {
4
+ "role": [
5
+ "paragraph"
6
+ ],
7
+ "text": {
8
+ "language": "en",
9
+ "plain": "Into speech.",
10
+ "ssml": "Into speech. <readium:link id=\"link1\" />"
11
+ },
12
+ "children": [
13
+ {
14
+ "id": "link1",
15
+ "textref": "#gloss",
16
+ "text": {
17
+ "plain": "see glossary entry"
18
+ }
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "role": [
24
+ "paragraph"
25
+ ],
26
+ "text": {
27
+ "plain": "synthesized speech can be created."
28
+ }
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,3 @@
1
+ <p>Into speech. <a href="#gloss" aria-labelledby="lbl">*</a></p>
2
+ <p>synthesized speech can be created.</p>
3
+ <span id="lbl" aria-hidden="true">see glossary entry</span>
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "accessible-name-labelledby-aria-hidden",
3
+ "description": "A link named via aria-labelledby pointing at an element marked aria-hidden=\"true\": the hidden label still names the link, and is not emitted on its own",
4
+ "role": "accessible-name",
5
+ "rolesCovered": [
6
+ "paragraph"
7
+ ],
8
+ "sourceRef": "https://www.w3.org/TR/accname/#computation-steps",
9
+ "inputKind": "fragment"
10
+ }
@@ -0,0 +1,31 @@
1
+ {
2
+ "children": [
3
+ {
4
+ "role": [
5
+ "paragraph"
6
+ ],
7
+ "text": {
8
+ "language": "en",
9
+ "plain": "Into speech.",
10
+ "ssml": "Into speech. <readium:link id=\"link1\" />"
11
+ },
12
+ "children": [
13
+ {
14
+ "id": "link1",
15
+ "textref": "#gloss",
16
+ "text": {
17
+ "plain": "see glossary entry"
18
+ }
19
+ }
20
+ ]
21
+ },
22
+ {
23
+ "role": [
24
+ "paragraph"
25
+ ],
26
+ "text": {
27
+ "plain": "synthesized speech can be created."
28
+ }
29
+ }
30
+ ]
31
+ }
@@ -0,0 +1,3 @@
1
+ <p>Into speech. <a href="#gloss" aria-labelledby="lbl">*</a></p>
2
+ <p>synthesized speech can be created.</p>
3
+ <span id="lbl" hidden>see glossary entry</span>
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "accessible-name-labelledby-hidden-attribute",
3
+ "description": "A link named via aria-labelledby pointing at an element hidden with the native hidden attribute: the hidden label still names the link, and is not emitted on its own",
4
+ "role": "accessible-name",
5
+ "rolesCovered": [
6
+ "paragraph"
7
+ ],
8
+ "sourceRef": "https://www.w3.org/TR/accname/#computation-steps",
9
+ "inputKind": "fragment"
10
+ }
@@ -19,6 +19,26 @@
19
19
  "gnd": "gnd.json"
20
20
  }
21
21
  },
22
+ {
23
+ "id": "accessible-name-labelledby-aria-hidden",
24
+ "dir": "accessible-name-labelledby-aria-hidden",
25
+ "role": "accessible-name",
26
+ "description": "A link named via aria-labelledby pointing at an element marked aria-hidden=\"true\": the hidden label still names the link, and is not emitted on its own",
27
+ "files": {
28
+ "input": "input.html",
29
+ "gnd": "gnd.json"
30
+ }
31
+ },
32
+ {
33
+ "id": "accessible-name-labelledby-hidden-attribute",
34
+ "dir": "accessible-name-labelledby-hidden-attribute",
35
+ "role": "accessible-name",
36
+ "description": "A link named via aria-labelledby pointing at an element hidden with the native hidden attribute: the hidden label still names the link, and is not emitted on its own",
37
+ "files": {
38
+ "input": "input.html",
39
+ "gnd": "gnd.json"
40
+ }
41
+ },
22
42
  {
23
43
  "id": "acknowledgments-epub-type",
24
44
  "dir": "acknowledgments-epub-type",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/guided-navigation",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "description": "Guided Navigation document generation from HTML and XHTML content",
6
6
  "author": "readium",
@@ -41,8 +41,8 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "css-selector-generator": "^3.9.4",
44
- "@readium/helpers": "1.2.0",
45
- "@readium/shared": "2.7.0"
44
+ "@readium/shared": "2.7.0",
45
+ "@readium/helpers": "1.2.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@jest/environment-jsdom-abstract": "^30.5.2",
package/src/a11y.ts CHANGED
@@ -69,8 +69,8 @@ export function extractNodeAria(el: Element): [string | null, boolean] {
69
69
 
70
70
  if (labelNodes.length > 0) {
71
71
  let text = "";
72
+ // Directly-referenced label nodes count even when hidden (AccName 2.A).
72
73
  labelNodes.forEach((n, i) => {
73
- if (nodeIsHidden(n)) return;
74
74
  const label = n.getAttribute("aria-label");
75
75
  text += label ? label : nodeTextExcludingExplicitRoles(n);
76
76
  if (i < labelNodes.length - 1) text += " ";