@readium/guided-navigation 1.1.3 → 1.2.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.
Files changed (135) hide show
  1. package/README.md +1 -1
  2. package/dist/a11y.js +1 -1
  3. package/dist/converter.js +1 -1
  4. package/dist/elementHandlers.js +1 -1
  5. package/dist/emptyPairs.js +1 -0
  6. package/dist/object.js +1 -1
  7. package/dist/prescan.js +1 -1
  8. package/dist/roles.js +1 -1
  9. package/dist/text.js +1 -1
  10. package/dist/textrefFragment.js +1 -1
  11. package/fixtures/ROLES_COVERAGE.md +6 -5
  12. package/fixtures/abbreviation-acronym-html-native/gnd.json +9 -0
  13. package/fixtures/abbreviation-acronym-html-native/input.html +1 -0
  14. package/fixtures/abbreviation-acronym-html-native/meta.json +11 -0
  15. package/fixtures/abbreviation-before-formatting/gnd.json +9 -0
  16. package/fixtures/abbreviation-before-formatting/input.html +1 -0
  17. package/fixtures/abbreviation-before-formatting/meta.json +11 -0
  18. package/fixtures/abbreviation-before-image/gnd.json +24 -0
  19. package/fixtures/abbreviation-before-image/input.html +1 -0
  20. package/fixtures/abbreviation-before-image/meta.json +12 -0
  21. package/fixtures/abbreviation-html-native/gnd.json +9 -0
  22. package/fixtures/abbreviation-html-native/input.html +1 -0
  23. package/fixtures/abbreviation-html-native/meta.json +11 -0
  24. package/fixtures/abbreviation-language/gnd.json +9 -0
  25. package/fixtures/abbreviation-language/input.html +1 -0
  26. package/fixtures/abbreviation-language/meta.json +11 -0
  27. package/fixtures/abbreviation-line-break/gnd.json +9 -0
  28. package/fixtures/abbreviation-line-break/input.html +1 -0
  29. package/fixtures/abbreviation-line-break/meta.json +11 -0
  30. package/fixtures/abbreviation-nested/gnd.json +9 -0
  31. package/fixtures/abbreviation-nested/input.html +1 -0
  32. package/fixtures/abbreviation-nested/meta.json +11 -0
  33. package/fixtures/abbreviation-nested-emphasis/gnd.json +9 -0
  34. package/fixtures/abbreviation-nested-emphasis/input.html +1 -0
  35. package/fixtures/abbreviation-nested-emphasis/meta.json +11 -0
  36. package/fixtures/abbreviation-nested-term/gnd.json +21 -0
  37. package/fixtures/abbreviation-nested-term/input.html +1 -0
  38. package/fixtures/abbreviation-nested-term/meta.json +12 -0
  39. package/fixtures/abbreviation-nested-term-punctuation/gnd.json +26 -0
  40. package/fixtures/abbreviation-nested-term-punctuation/input.html +1 -0
  41. package/fixtures/abbreviation-nested-term-punctuation/meta.json +12 -0
  42. package/fixtures/abbreviation-no-title/gnd.json +8 -0
  43. package/fixtures/abbreviation-no-title/input.html +1 -0
  44. package/fixtures/abbreviation-no-title/meta.json +11 -0
  45. package/fixtures/abbreviation-spanning-terms/gnd.json +33 -0
  46. package/fixtures/abbreviation-spanning-terms/input.html +1 -0
  47. package/fixtures/abbreviation-spanning-terms/meta.json +12 -0
  48. package/fixtures/abbreviation-with-image/gnd.json +24 -0
  49. package/fixtures/abbreviation-with-image/input.html +1 -0
  50. package/fixtures/abbreviation-with-image/meta.json +12 -0
  51. package/fixtures/abbreviation-with-svg-and-math/gnd.json +39 -0
  52. package/fixtures/abbreviation-with-svg-and-math/input.html +1 -0
  53. package/fixtures/abbreviation-with-svg-and-math/meta.json +13 -0
  54. package/fixtures/biblioref-target-descendant-ids/gnd.json +90 -0
  55. package/fixtures/biblioref-target-descendant-ids/input.html +1 -0
  56. package/fixtures/biblioref-target-descendant-ids/meta.json +14 -0
  57. package/fixtures/biblioref-target-in-bibliography-role-aria/gnd.json +59 -0
  58. package/fixtures/biblioref-target-in-bibliography-role-aria/input.html +6 -0
  59. package/fixtures/biblioref-target-in-bibliography-role-aria/meta.json +14 -0
  60. package/fixtures/biblioref-target-mixed-content/gnd.json +63 -0
  61. package/fixtures/biblioref-target-mixed-content/input.html +1 -0
  62. package/fixtures/biblioref-target-mixed-content/meta.json +11 -0
  63. package/fixtures/glossref-sole-content/gnd.json +70 -0
  64. package/fixtures/glossref-sole-content/input.html +5 -0
  65. package/fixtures/glossref-sole-content/meta.json +14 -0
  66. package/fixtures/glossref-target-in-glossary-role-aria/gnd.json +76 -0
  67. package/fixtures/glossref-target-in-glossary-role-aria/input.html +5 -0
  68. package/fixtures/glossref-target-in-glossary-role-aria/meta.json +14 -0
  69. package/fixtures/glossref-target-percent-encoded/gnd.json +68 -0
  70. package/fixtures/glossref-target-percent-encoded/input.html +1 -0
  71. package/fixtures/glossref-target-percent-encoded/meta.json +14 -0
  72. package/fixtures/manifest.json +360 -0
  73. package/fixtures/noteref-after-closing-straight-quote/gnd.json +32 -0
  74. package/fixtures/noteref-after-closing-straight-quote/input.html +1 -0
  75. package/fixtures/noteref-after-closing-straight-quote/meta.json +13 -0
  76. package/fixtures/noteref-after-closing-straight-quote-split/gnd.json +38 -0
  77. package/fixtures/noteref-after-closing-straight-quote-split/input.html +1 -0
  78. package/fixtures/noteref-after-closing-straight-quote-split/meta.json +12 -0
  79. package/fixtures/noteref-enclosed-across-formatting/gnd.json +32 -0
  80. package/fixtures/noteref-enclosed-across-formatting/input.html +1 -0
  81. package/fixtures/noteref-enclosed-across-formatting/meta.json +13 -0
  82. package/fixtures/noteref-enclosed-adjacent-pairs/gnd.json +108 -0
  83. package/fixtures/noteref-enclosed-adjacent-pairs/input.html +1 -0
  84. package/fixtures/noteref-enclosed-adjacent-pairs/meta.json +13 -0
  85. package/fixtures/noteref-enclosed-adjacent-text/gnd.json +34 -0
  86. package/fixtures/noteref-enclosed-adjacent-text/input.html +1 -0
  87. package/fixtures/noteref-enclosed-adjacent-text/meta.json +13 -0
  88. package/fixtures/noteref-enclosed-before-formatting/gnd.json +34 -0
  89. package/fixtures/noteref-enclosed-before-formatting/input.html +1 -0
  90. package/fixtures/noteref-enclosed-before-formatting/meta.json +13 -0
  91. package/fixtures/noteref-enclosed-guillemets-french/gnd.json +103 -0
  92. package/fixtures/noteref-enclosed-guillemets-french/input.html +1 -0
  93. package/fixtures/noteref-enclosed-guillemets-french/meta.json +13 -0
  94. package/fixtures/noteref-enclosed-quotes-chinese/gnd.json +47 -0
  95. package/fixtures/noteref-enclosed-quotes-chinese/input.html +1 -0
  96. package/fixtures/noteref-enclosed-quotes-chinese/meta.json +13 -0
  97. package/fixtures/noteref-enclosed-quotes-german/gnd.json +124 -0
  98. package/fixtures/noteref-enclosed-quotes-german/input.html +1 -0
  99. package/fixtures/noteref-enclosed-quotes-german/meta.json +13 -0
  100. package/fixtures/noteref-enclosed-quotes-swedish/gnd.json +70 -0
  101. package/fixtures/noteref-enclosed-quotes-swedish/input.html +1 -0
  102. package/fixtures/noteref-enclosed-quotes-swedish/meta.json +13 -0
  103. package/fixtures/noteref-enclosed-straight-quotes/gnd.json +32 -0
  104. package/fixtures/noteref-enclosed-straight-quotes/input.html +1 -0
  105. package/fixtures/noteref-enclosed-straight-quotes/meta.json +13 -0
  106. package/fixtures/noteref-in-lone-block/gnd.json +29 -0
  107. package/fixtures/noteref-in-lone-block/input.html +1 -0
  108. package/fixtures/noteref-in-lone-block/meta.json +12 -0
  109. package/fixtures/noteref-target-malformed-escape/gnd.json +32 -0
  110. package/fixtures/noteref-target-malformed-escape/input.html +1 -0
  111. package/fixtures/noteref-target-malformed-escape/meta.json +13 -0
  112. package/fixtures/noteref-target-percent-encoded/gnd.json +32 -0
  113. package/fixtures/noteref-target-percent-encoded/input.html +1 -0
  114. package/fixtures/noteref-target-percent-encoded/meta.json +13 -0
  115. package/fixtures/table-cell-abbreviation/gnd.json +55 -0
  116. package/fixtures/table-cell-abbreviation/input.html +4 -0
  117. package/fixtures/table-cell-abbreviation/meta.json +15 -0
  118. package/fixtures/table-cell-noteref/gnd.json +77 -0
  119. package/fixtures/table-cell-noteref/input.html +5 -0
  120. package/fixtures/table-cell-noteref/meta.json +16 -0
  121. package/package.json +1 -1
  122. package/src/a11y.ts +4 -4
  123. package/src/converter.ts +112 -25
  124. package/src/elementHandlers.ts +64 -11
  125. package/src/emptyPairs.ts +74 -0
  126. package/src/object.ts +4 -0
  127. package/src/prescan.ts +2 -1
  128. package/src/roles.ts +2 -0
  129. package/src/text.ts +3 -1
  130. package/src/textrefFragment.ts +9 -1
  131. package/types/src/converter.d.ts +4 -0
  132. package/types/src/elementHandlers.d.ts +1 -0
  133. package/types/src/emptyPairs.d.ts +3 -0
  134. package/types/src/text.d.ts +1 -0
  135. package/types/src/textrefFragment.d.ts +4 -0
package/README.md CHANGED
@@ -107,7 +107,7 @@ The lower-level pieces are exported too: `encodeCssSelectorFragment(selector)`/`
107
107
  ## Objects
108
108
 
109
109
  - **`role`** can have multiple entries: tag name, ARIA `role`, `epub:type` all contribute, in that order (e.g. `<section epub:type="chapter">` → `["section", "chapter"]`). `role="presentation"`/`"none"` overrides everything to `["presentation"]`.
110
- - **`text`** carries `ssml` when the text needs it (inline formatting, a language shift, or an embedded footnote/pagebreak/image mid-sentence). `ssml` marks embedded objects with a `<readium:noteref id="..." />`-style placeholder whose `id` matches a sibling in `children`.
110
+ - **`text`** carries `ssml` when the text needs it (inline formatting, a language shift, an abbreviation, or an embedded footnote/pagebreak/image mid-sentence). `ssml` marks embedded objects with a `<readium:noteref id="..." />`-style placeholder whose `id` matches a sibling in `children`.
111
111
  - **`math`** nodes carry MathML as-is in `text.ssml` (`<math xmlns="http://www.w3.org/1998/Math/MathML">…</math>`), or other `role="math"` markup's content in `text.plain`, with `alttext`/`aria-label` as `description`.
112
112
  - **`imgref`/`audioref`/`videoref`** are a media element's `src`. **`textref`** is an `href` — reused for navigational-list items (`toc`, `index`...), `noteref`/`backlink`/`biblioref`/`glossref`, and plain links.
113
113
  - **`description`** holds a node's accessible name (`aria-label`, `alt`, `<figcaption>`...) as `description.text` when it differs from its visible text.
package/dist/a11y.js CHANGED
@@ -1 +1 @@
1
- import{normalizeWhitespace as m}from"./text.js";import{hasExplicitRole as w}from"./roles.js";import{nodeLanguage as c,sharedLanguage as g}from"./language.js";function y(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function p(t,o,a){let s="";const l=(r,n)=>{if(r.nodeType===3){const e=r.nodeValue??"";s+=e,e.trim()&&a.add(c(r.parentElement));return}if(!(o&&r.nodeType===1&&!n&&w(r)))for(let e=r.firstChild;e;e=e.nextSibling)l(e,!1)};return l(t,!0),s}function x(t,o){const a=new Set;return{text:m(p(t,o,a),!0).trim(),language:g(a)}}function A(t){return x(t,!1)}function z(t){return x(t,!0)}function B(t){if(y(t))return[null,!1,""];const o=(t.getAttribute("aria-labelledby")??"").trim();if(o){const r=[...new Set(o.split(/\s+/).filter(Boolean))],n=t.ownerDocument,e=r.map(i=>n.getElementById(i)).filter(i=>i!==null);if(e.length>0){let i="";const u=new Set;e.forEach((f,h)=>{const b=f.getAttribute("aria-label");b?(i+=b,u.add(c(f))):i+=p(f,!0,u),h<e.length-1&&(i+=" ")});const d=m(i,!0).trim();if(d!=="")return[d,!0,g(u)]}}const a=(t.getAttribute("aria-label")??"").trim();if(a)return[a,!0,c(t)];const s=(t.getAttribute("aria-describedby")??"").trim();if(s){const n=[...new Set(s.split(/\s+/).filter(Boolean))].map(e=>t.ownerDocument.getElementById(e)).filter(e=>e!==null);if(n.length>0){const e=new Set,i=n.map(d=>p(d,!0,e)).join(" "),u=m(i,!0).trim();if(u!=="")return[u,!0,g(e)]}}const l=t.tagName.toLowerCase();if(l==="img"){const r=(t.getAttribute("alt")??"").trim();if(r)return[r,!0,c(t)];const n=(t.getAttribute("title")??"").trim();if(n)return[n,!0,c(t)]}else if(l==="svg"){const r=t.querySelector(":scope > title");if(r){const{text:n,language:e}=A(r);if(n)return[n,!0,e]}}else if(l==="math"){const r=(t.getAttribute("alttext")??"").trim();if(r)return[r,!0,c(t)]}return[null,!0,""]}const S={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function N(t){return S[t]??["",void 0]}const L=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{N as convertElementToSSMLTag,B as extractNodeAria,A as normalizedNodeText,z as normalizedNodeTextExcludingExplicitRoles,L as skippedElements};
1
+ import{normalizeWhitespace as o}from"./text.js";import{hasExplicitRole as w}from"./roles.js";import{nodeLanguage as d,sharedLanguage as g}from"./language.js";function y(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function p(t,s,a){let u="";const l=(r,n)=>{if(r.nodeType===3){const e=r.nodeValue??"";u+=e,e.trim()&&a.add(d(r.parentElement));return}if(!(s&&r.nodeType===1&&!n&&w(r)))for(let e=r.firstChild;e;e=e.nextSibling)l(e,!1)};return l(t,!0),u}function x(t,s){const a=new Set;return{text:o(p(t,s,a),!0).trim(),language:g(a)}}function A(t){return x(t,!1)}function z(t){return x(t,!0)}function B(t){if(y(t))return[null,!1,""];const s=(t.getAttribute("aria-labelledby")??"").trim();if(s){const r=[...new Set(s.split(/\s+/).filter(Boolean))],n=t.ownerDocument,e=r.map(i=>n.getElementById(i)).filter(i=>i!==null);if(e.length>0){let i="";const c=new Set;e.forEach((m,h)=>{const b=m.getAttribute("aria-label");b?(i+=b,c.add(d(m))):i+=p(m,!0,c),h<e.length-1&&(i+=" ")});const f=o(i,!0).trim();if(f!=="")return[f,!0,g(c)]}}const a=o(t.getAttribute("aria-label")??"",!0).trim();if(a)return[a,!0,d(t)];const u=(t.getAttribute("aria-describedby")??"").trim();if(u){const n=[...new Set(u.split(/\s+/).filter(Boolean))].map(e=>t.ownerDocument.getElementById(e)).filter(e=>e!==null);if(n.length>0){const e=new Set,i=n.map(f=>p(f,!0,e)).join(" "),c=o(i,!0).trim();if(c!=="")return[c,!0,g(e)]}}const l=t.tagName.toLowerCase();if(l==="img"){const r=o(t.getAttribute("alt")??"",!0).trim();if(r)return[r,!0,d(t)];const n=o(t.getAttribute("title")??"",!0).trim();if(n)return[n,!0,d(t)]}else if(l==="svg"){const r=t.querySelector(":scope > title");if(r){const{text:n,language:e}=A(r);if(n)return[n,!0,e]}}else if(l==="math"){const r=o(t.getAttribute("alttext")??"",!0).trim();if(r)return[r,!0,d(t)]}return[null,!0,""]}const S={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function N(t){return S[t]??["",void 0]}const L=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{N as convertElementToSSMLTag,B as extractNodeAria,A as normalizedNodeText,z as normalizedNodeTextExcludingExplicitRoles,L as skippedElements};
package/dist/converter.js CHANGED
@@ -1 +1 @@
1
- import{hasExplicitRole as z,extractNodeRoles as A}from"./roles.js";import{skippedElements as H,extractNodeAria as I,normalizedNodeText as _,normalizedNodeTextExcludingExplicitRoles as D,convertElementToSSMLTag as q}from"./a11y.js";import{normalizeWhitespace as y,ctxEqual as X}from"./text.js";import{ssmlAttrEscape as S,ssmlTextEscape as M,startsWithBindingPunct as G}from"@readium/helpers";import{NavObject as b,isEmptyObj as $,finalizeToGuidedNavigationObject as U,setDescription as x}from"./object.js";import{sniffMediaType as V,isInlineTag as Y}from"./dom.js";import{nodeLanguage as J,declaredLanguage as j,sameLanguage as C}from"./language.js";import{encodeDomRangeFragment as K,encodeTextFragmentDirective as Q}from"./textrefFragment.js";import{resolveRefs as Z}from"./href.js";import{rootAnchorSelector as tt,textrefForSelector as N,selectorForElement as v}from"./selectorGenerator.js";import{generateDomRange as et}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as st}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as it}from"./options.js";import{IdAllocator as rt}from"./idAllocator.js";import{prescan as nt}from"./prescan.js";import{pagebreak as ot,noteref as lt,link as at}from"./elementHandlers.js";const ct="http://www.w3.org/1998/Math/MathML",ht=3,ft=1,dt=new Set(["summary","dfn","span"]);function P(d,t){return dt.has(d)&&t.length>0?!0:!Y(d)}class E{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new rt,this.noterefDepth=0,this.allowNode=null,this.selectorPredicate=null,this.domRangeEnabled=!1,this.textFragmentEnabled=!1,this.leafTextEnabled=!1,this.docRoot=null,this.selectorRoot=null,this.selectorRootAnchor=null,this.root=new b,this.current=this.root,this.foldedCaptions=new Set,this.segments=[],this.textAcc="",this.currentCtx={lang:void 0,tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0,this.lastFlowRange=null,this.lastFlowText=null,this.xmlParsed=t}spawnChild(t,e=1){const s=new E(this.xmlParsed);return s.ids=this.ids,s.suppressed=this.suppressed,s.idAlloc=this.idAlloc,s.noterefDepth=this.noterefDepth+e,s.allowNode=t,s.docRoot=this.docRoot,s.selectorRoot=this.selectorRoot,s.selectorRootAnchor=this.selectorRootAnchor,s.selectorPredicate=this.selectorPredicate,s.domRangeEnabled=this.domRangeEnabled,s.textFragmentEnabled=this.textFragmentEnabled,s.leafTextEnabled=this.leafTextEnabled,s}prescan(t){nt(t,this.ids,this.suppressed)}convert(t){this.prescan(t),this.walk(t),this.flushText()}convertChildren(t){this.prescan(t);for(let e=t.firstChild;e;e=e.nextSibling)this.walk(e);this.flushText()}resultBuilders(){const t=this.root.finalize(e=>N(v(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0?$(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>Z(e,this.baseHref)),t.map(U)}descend(t,e){const s=new b;s.el=t,s.noText=this.foldedCaptions.has(t)||(!z(t)||e.includes("caption"))&&this.current.noText,this.current.children.push(s),this.current.hasChildBlock=!0,this.current=s}appendChild(t){t.noText=this.current.noText,this.current.children.push(t)}walk(t){if(t.nodeType===ht){this.text(t);return}if(t.nodeType!==ft)return;const e=t,s=this.current,c=this.head(e);if(!c)for(let n=e.firstChild;n;n=n.nextSibling)this.walk(n);this.tail(e,c,s)}head(t){const e=t.tagName.toLowerCase();if(H.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[s,c,n]=I(t);if(!c&&t!==this.allowNode)return!0;const a=A(t);if((e==="img"||e==="svg")&&(a.includes("presentation")||s===null&&t.hasAttribute("alt")&&t.getAttribute("alt").trim()===""))return!0;if(e==="br")return this.current.noText||(this.closeSegment(),this.segments.push({kind:"break"}),this.flowEndsWithSpace=!0),!0;if(a.includes("pagebreak"))return!ot(this,t,s,n,a);if(e==="a"&&a.includes("noteref")&&t.getAttribute("href"))return lt(this,t,a),!0;if(e==="a"&&t.getAttribute("href"))return at(this,t,a,s,n),!0;if(e==="img"){const r={role:a},o=t.getAttribute("src");return o&&(r.imgref=o),s&&x(r,s,n),this.placeholder(t,"image",r),!0}if(e==="audio"||e==="video"){const r={role:a};let o=t.getAttribute("src");if(!o){const h=t.querySelector(":scope > source[src]");h&&(o=h.getAttribute("src"))}return e==="audio"?o&&(r.audioref=o):o&&(r.videoref=o),s&&x(r,s,n),this.placeholder(t,e,r),!0}if(a.includes("image")||a.includes("math")){const r={role:a};if(s&&x(r,s,n),a.includes("math")){if(t.namespaceURI===ct)r.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:J(t)};else{const{text:o,language:h}=_(t);o&&(r.text={plain:o,ssml:"",language:h})}r.textref=N(v(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,a.includes("math")?"math":"image",r),!0}if(!P(e,a))return!1;this.flushText(),this.descend(t,a);const g=this.current.object;if(a.length>0&&(g.role=a),s)x(g,s,n),a.includes("figure")&&(this.current.noText=!0);else if(a.includes("figure")){const r=this.implicitCaptionOf(t);if(r){const{text:o,language:h}=D(r);o&&(x(g,o,h),this.current.noText=!0)}}else if(a.includes("table")){const r=this.implicitCaptionOf(t);if(r){const{text:o,language:h}=D(r);o&&(x(g,o,h),this.foldedCaptions.add(r))}}const u=t.getAttribute("id");return u&&(g.id=u),!1}implicitCaptionOf(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling)if(A(e).includes("caption")&&!e.getAttribute("aria-labelledby"))return e;return null}tail(t,e,s){if(e)return;const c=t.tagName.toLowerCase(),n=A(t);if(!n.includes("pagebreak")&&P(c,n)){this.flushText(),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const a=this.leafTextEnabled&&n.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(n)||a)&&this.applyTextref(t),this.current=s}}applyTextref(t){const e=this.current.object,s=v(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=N(s,t),this.domRangeEnabled&&this.lastFlowRange){const c=s?{el:t,selector:s}:void 0,n=et(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,c);n&&(e.textref=K({...n,container:s}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const c=this.docRoot.createRange();c.setStart(...this.lastFlowRange.first),c.setEnd(...this.lastFlowRange.last);const n=st(c);n&&(e.textref=`${e.textref??"#"}${Q(n)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(/^\s*$/.test(e)){(this.textAcc.length>0||this.segments.length>0)&&(this.textAcc+=y(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const s=this.textContext(t);if(X(s,this.currentCtx)||(this.closeSegment(),this.currentCtx=s),this.textAcc+=y(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const c=t;this.flowFirstNode===null&&(this.flowFirstNode=c,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=c,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){const e={lang:j(t.parentElement),tag:""};for(let s=t.parentElement;s&&s!==this.current.el;s=s.parentElement){const[c,n]=q(s.tagName.toLowerCase());if(c&&c!=="break"){e.tag=c,e.attrs=n;break}}return e}updateFlowSpace(){this.textAcc.length>0&&(this.flowEndsWithSpace=this.textAcc.endsWith(" "))}closeSegment(){this.textAcc.length!==0&&(this.segments.push({kind:"text",text:this.textAcc,ctx:this.currentCtx}),this.textAcc="")}resetFlow(){this.segments=[],this.textAcc="",this.currentCtx={lang:void 0,tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0}placeholder(t,e,s,c){if($(s))return;const n=new b;if(n.el=t,n.object=s,this.current.noText){this.appendChild(n);return}this.closeSegment(),this.pendingChildren.push(n),this.segments.push({kind:"placeholder",tag:e,child:n,candidateID:c??t.getAttribute("id")??void 0}),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,s=this.flowFirstNode,c=this.flowFirstOffset,n=this.flowLastNode,a=this.flowLastOffset;if(this.resetFlow(),this.lastFlowRange=null,this.lastFlowText=null,t.length===0)return;for(;t.length>0;){const i=t[0];if(i.kind==="break"){t=t.slice(1);continue}if(i.kind==="text"){const l=i.text.replace(/^\s+/,"");if(l===""){t=t.slice(1);continue}t=[{...i,text:l},...t.slice(1)]}break}for(;t.length>0;){const i=t[t.length-1];if(i.kind==="break"){t=t.slice(0,-1);continue}if(i.kind==="text"){const l=i.text.replace(/\s+$/,"");if(l===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...i,text:l}]}break}if(!t.some(i=>i.kind==="text"&&i.text.trim()!=="")){for(const i of e)this.appendChild(i);return}const u=[];for(const i of t)if(i.kind==="text"&&i.text.trim()!==""){const l=i.ctx.lang;u.some(m=>C(m,l))||u.push(l)}let r=j(this.current.el??null);u.length===1&&(r=u[0]);let o=!1;for(const i of t)if(i.kind!=="text"||i.ctx.tag!==""||!C(i.ctx.lang,r)){o=!0;break}o&&r===void 0&&(r="en");const h=i=>i!==void 0&&!C(i,r);if(o)for(const i of t){if(i.kind!=="placeholder")continue;let l=i.candidateID;(!l||!this.idAlloc.claim(l))&&(l=this.idAlloc.allocate(i.tag,m=>this.ids.has(m))),i.child.object.id=l}let f="",L=!1,T=!1,R=!1,k=!1;for(const i of t)if(i.kind==="text"){const l=i.text.startsWith(" "),m=i.text.replace(/^ +| +$/g,"");if(m===""){k=!0;continue}let p=!1;if(f.length>0){const w=L||k||l;T?p=!0:R?p=w&&!G(m):p=w}p&&(f+=" "),f+=m,L=i.text.endsWith(" "),T=!1,R=!1,k=!1}else i.kind==="break"?T=!0:i.kind==="placeholder"&&(R=!0);const W=t.some(i=>i.kind==="placeholder");this.lastFlowText=f.trim();const O={plain:o&&!W?"":f.trim(),ssml:"",language:r??""};if(o){let i="";for(const l of t)if(l.kind==="text"){let m=l.ctx.tag,p=l.ctx.attrs;if(h(l.ctx.lang)&&(m="lang",p=void 0),m){i+=`<${m}`;for(const[w,B]of Object.entries(p??{}))i+=` ${w}="${S(B)}"`;h(l.ctx.lang)&&(i+=` xml:lang="${S(l.ctx.lang)}"`),i+=`>${M(l.text)}</${m}>`}else i+=M(l.text)}else l.kind==="break"?i+="<break/>":l.kind==="placeholder"&&(i+=`<readium:${l.tag} id="${S(l.child.object.id)}" />`);O.ssml=i}const F=new b;F.object={text:O};for(const i of e)F.children.push(i);this.appendChild(F),s&&n&&(this.lastFlowRange={first:[s,c],last:[n,a]})}}const ut=/<body[\s>]/i;function Lt(d,t,e){const{predicate:s,leafText:c,domRange:n,textFragment:a}=it(e?.textrefs);if(typeof d!="string"){const h=t??(d.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),f=new E(h==="application/xhtml+xml");return f.selectorPredicate=s,f.leafTextEnabled=c,f.domRangeEnabled=n,f.textFragmentEnabled=a,f.docRoot=d.ownerDocument,f.baseHref=e?.href,f.selectorRoot=d,f.selectorRootAnchor=tt(d),f.convert(d),f.result()}let g=t??V(d),u=new DOMParser().parseFromString(d,g);if(g==="application/xhtml+xml"){const h=u.getElementsByTagNameNS("*","parsererror")[0];if(h){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${h.textContent?.trim()??""}`);g="text/html",u=new DOMParser().parseFromString(d,g)}}const r=new E(g==="application/xhtml+xml");r.selectorPredicate=s,r.leafTextEnabled=c,r.textFragmentEnabled=a,r.docRoot=u,r.baseHref=e?.href;const o=u.querySelector("body");return o&&!ut.test(d)?r.convertChildren(o):r.convert(o??u.documentElement),r.result()}export{E as Converter,Lt as parseMarkup};
1
+ import{hasExplicitRole as U,extractNodeRoles as F}from"./roles.js";import{skippedElements as z,extractNodeAria as Y,normalizedNodeText as J,normalizedNodeTextExcludingExplicitRoles as H,convertElementToSSMLTag as K}from"./a11y.js";import{normalizeWhitespace as $,ctxEqual as Q}from"./text.js";import{ssmlTextEscape as P,ssmlAttrEscape as M}from"@readium/helpers";import{NavObject as S,isEmptyObj as I,finalizeToGuidedNavigationObject as Z,setDescription as R}from"./object.js";import{sniffMediaType as _,isAncestorOf as tt,isInlineTag as et}from"./dom.js";import{nodeLanguage as it,declaredLanguage as O,sameLanguage as L}from"./language.js";import{encodeDomRangeFragment as st,encodeTextFragmentDirective as nt}from"./textrefFragment.js";import{resolveRefs as rt}from"./href.js";import{rootAnchorSelector as ot,textrefForSelector as y,selectorForElement as D}from"./selectorGenerator.js";import{generateDomRange as lt}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as at}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as ct}from"./options.js";import{IdAllocator as ht}from"./idAllocator.js";import{prescan as ft}from"./prescan.js";import{pagebreak as dt,noteref as ut,reference as gt,link as mt}from"./elementHandlers.js";import{removeDropped as pt,bindsToPrevious as xt,DROPPED as bt}from"./emptyPairs.js";const wt="http://www.w3.org/1998/Math/MathML",q=3,X=1,Et=new Set(["summary","dfn","span"]);function j(h,t){return Et.has(h)&&t.length>0?!0:!et(h)}class k{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new ht,this.noterefDepth=0,this.allowNode=null,this.selectorPredicate=null,this.domRangeEnabled=!1,this.textFragmentEnabled=!1,this.leafTextEnabled=!1,this.docRoot=null,this.selectorRoot=null,this.selectorRootAnchor=null,this.copy=!1,this.root=new S,this.current=this.root,this.foldedCaptions=new Set,this.segments=[],this.textAcc="",this.currentCtx={lang:void 0,tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0,this.lastFlowRange=null,this.lastFlowText=null,this.xmlParsed=t}spawnChild(t,e=1){const i=new k(this.xmlParsed);return i.ids=this.ids,i.suppressed=this.suppressed,i.idAlloc=this.idAlloc,i.noterefDepth=this.noterefDepth+e,i.allowNode=t,i.docRoot=this.docRoot,i.selectorRoot=this.selectorRoot,i.selectorRootAnchor=this.selectorRootAnchor,i.selectorPredicate=this.selectorPredicate,i.domRangeEnabled=this.domRangeEnabled,i.textFragmentEnabled=this.textFragmentEnabled,i.leafTextEnabled=this.leafTextEnabled,i.copy=this.copy,i}prescan(t){ft(t,this.ids,this.suppressed)}convert(t){this.prescan(t),this.walk(t),this.flushText()}convertChildren(t){this.prescan(t);for(let e=t.firstChild;e;e=e.nextSibling)this.walk(e);this.flushText()}resultBuilders(){const t=this.root.finalize(e=>y(D(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0||t.text?I(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>rt(e,this.baseHref)),t.map(Z)}descend(t,e){const i=new S;i.el=t,i.noText=this.foldedCaptions.has(t)||(!U(t)||e.includes("caption"))&&this.current.noText,this.current.children.push(i),this.current.hasChildBlock=!0,this.current=i}appendChild(t){t.noText=this.current.noText,this.current.children.push(t)}walk(t){if(t.nodeType===q){this.text(t);return}if(t.nodeType!==X)return;const e=t,i=this.current,r=this.head(e);if(!r)for(let n=e.firstChild;n;n=n.nextSibling)this.walk(n);this.tail(e,r,i)}head(t){const e=t.tagName.toLowerCase();if(z.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[i,r,n]=Y(t);if(!r&&t!==this.allowNode)return!0;const o=F(t);if((e==="img"||e==="svg")&&(o.includes("presentation")||i===null&&t.hasAttribute("alt")&&t.getAttribute("alt").trim()===""))return!0;if(e==="br")return!this.current.noText&&!this.textContext(t).abbr&&(this.closeSegment(),this.segments.push({kind:"break"}),this.flowEndsWithSpace=!0),!0;if(o.includes("pagebreak"))return!dt(this,t,i,n,o);if(e==="a"&&o.includes("noteref")&&t.getAttribute("href"))return ut(this,t,o),!0;if(e==="a"&&(o.includes("glossref")||o.includes("biblioref"))&&t.getAttribute("href"))return gt(this,t,o,i,n),!0;if(e==="a"&&t.getAttribute("href"))return mt(this,t,o,i,n),!0;if(e==="img"){const l={role:o},a=t.getAttribute("src");return a&&(l.imgref=a),i&&R(l,i,n),this.placeholder(t,"image",l),!0}if(e==="audio"||e==="video"){const l={role:o};let a=t.getAttribute("src");if(!a){const f=t.querySelector(":scope > source[src]");f&&(a=f.getAttribute("src"))}return e==="audio"?a&&(l.audioref=a):a&&(l.videoref=a),i&&R(l,i,n),this.placeholder(t,e,l),!0}if(o.includes("image")||o.includes("math")){const l={role:o};if(i&&R(l,i,n),o.includes("math")){if(t.namespaceURI===wt)l.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:it(t)};else{const{text:a,language:f}=J(t);a&&(l.text={plain:a,ssml:"",language:f})}l.textref=y(D(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,o.includes("math")?"math":"image",l),!0}if(!j(e,o))return!1;this.flushText(),this.descend(t,o);const u=this.current.object;if(o.length>0&&(u.role=o),i)R(u,i,n),o.includes("figure")&&(this.current.noText=!0);else if(o.includes("figure")){const l=this.implicitCaptionOf(t);if(l){const{text:a,language:f}=H(l);a&&(R(u,a,f),this.current.noText=!0)}}else if(o.includes("table")){const l=this.implicitCaptionOf(t);if(l){const{text:a,language:f}=H(l);a&&(R(u,a,f),this.foldedCaptions.add(l))}}const x=t.getAttribute("id");return x&&(u.id=x),!1}implicitCaptionOf(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling)if(F(e).includes("caption")&&!e.getAttribute("aria-labelledby"))return e;return null}tail(t,e,i){if(e)return;const r=t.tagName.toLowerCase(),n=F(t);if(!n.includes("pagebreak")&&j(r,n)){this.flushText(),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const o=this.leafTextEnabled&&n.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(n)||o)&&this.applyTextref(t),this.current=i}}applyTextref(t){const e=this.current.object,i=D(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=y(i,t),this.domRangeEnabled&&this.lastFlowRange){const r=i?{el:t,selector:i}:void 0,n=lt(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,r);n&&(e.textref=st({...n,container:i}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const r=this.docRoot.createRange();r.setStart(...this.lastFlowRange.first),r.setEnd(...this.lastFlowRange.last);const n=at(r);n&&(e.textref=`${e.textref??"#"}${nt(n)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(/^\s*$/.test(e)){(this.textAcc.length>0||this.segments.length>0)&&(this.textAcc+=$(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const i=this.textContext(t);if(Q(i,this.currentCtx)||(this.closeSegment(),this.currentCtx=i),this.textAcc+=$(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const r=t;this.flowFirstNode===null&&(this.flowFirstNode=r,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=r,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){let e;for(let r=t.parentElement,n=!1;r;r=r.parentElement){const o=Tt(r);if(o){if(!n&&k.containsObject(r))break;e={lang:O(r),tag:"sub",attrs:{alias:o},abbr:r}}if(r===this.current.el&&(n=!0),n&&!k.isSoleContent(r))break}if(e)return e;const i={lang:O(t.parentElement),tag:""};for(let r=t.parentElement;r&&r!==this.current.el;r=r.parentElement){const[n,o]=K(r.tagName.toLowerCase());if(n&&n!=="break"){i.tag=n,i.attrs=o;break}}return i}static containsObject(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling){const i=e.tagName.toLowerCase(),r=F(e);if(!(z.has(i)||k.isPlaceholder(e,i,r))&&(j(i,r)||k.containsObject(e)))return!0}return!1}static isPlaceholder(t,e,i){return i.includes("pagebreak")||i.includes("image")||i.includes("math")?!0:["img","svg","audio","video"].includes(e)||e==="a"&&!!t.getAttribute("href")}static isSoleContent(t){for(let e=t.parentNode?.firstChild;e;e=e.nextSibling)if(e!==t&&(e.nodeType===X||e.nodeType===q&&!/^[\s\p{P}]*$/u.test(e.nodeValue??"")))return!1;return!0}updateFlowSpace(){this.textAcc.length>0&&(this.flowEndsWithSpace=this.textAcc.endsWith(" "))}closeSegment(){this.textAcc.length!==0&&(this.segments.push({kind:"text",text:this.textAcc,ctx:this.currentCtx}),this.textAcc="")}resetFlow(){this.segments=[],this.textAcc="",this.currentCtx={lang:void 0,tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0}placeholder(t,e,i,r){if(I(i))return;const n=new S;if(n.el=t,n.object=i,this.current.noText){this.appendChild(n);return}this.closeSegment(),this.pendingChildren.push(n),this.segments.push({kind:"placeholder",tag:e,child:n,candidateID:r??t.getAttribute("id")??void 0}),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,i=this.flowFirstNode,r=this.flowFirstOffset,n=this.flowLastNode,o=this.flowLastOffset;if(this.resetFlow(),this.lastFlowRange=null,this.lastFlowText=null,t.length===0)return;for(;t.length>0;){const s=t[0];if(s.kind==="break"){t=t.slice(1);continue}if(s.kind==="text"){const c=s.text.replace(/^\s+/,"");if(c===""){t=t.slice(1);continue}t=[{...s,text:c},...t.slice(1)]}break}for(;t.length>0;){const s=t[t.length-1];if(s.kind==="break"){t=t.slice(0,-1);continue}if(s.kind==="text"){const c=s.text.replace(/\s+$/,"");if(c===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...s,text:c}]}break}const u=[];for(let s=0;s<t.length;s++){const c=t[s],d=c.kind==="text"?c.ctx.abbr:void 0;if(!d){u.push(c);continue}let m=c.text;const E=[];let b=[];for(let p=s+1;p<t.length;p++){const T=t[p];if(T.kind==="placeholder"&&tt(d,T.child.el)){b.push(T);continue}if(T.kind!=="text"||T.ctx.abbr!==d)break;m+=T.text,E.push(...b),b=[],s=p}u.push({...c,text:m},...E)}if(t=u,!t.some(s=>s.kind==="text"&&s.text.trim()!=="")){for(const s of e)this.appendChild(s);return}const l=[];for(const s of t)if(s.kind==="text"&&s.text.trim()!==""){const c=s.ctx.lang;l.some(d=>L(d,c))||l.push(c)}let a=O(this.current.el??null);l.length===1&&(a=l[0]);let f=!1;for(const s of t)if(s.kind!=="text"||s.ctx.tag!==""||!L(s.ctx.lang,a)){f=!0;break}f&&a===void 0&&(a="en");const g=s=>s!==void 0&&!L(s,a);if(f)for(const s of t){if(s.kind!=="placeholder")continue;let c=this.copy?void 0:s.candidateID;(!c||!this.idAlloc.claim(c))&&(c=this.idAlloc.allocate(s.tag,d=>this.ids.has(d))),s.child.object.id=c}let w="",W=!1,A=!1,C=!1,N=!1;for(const s of t)if(s.kind==="text"){const c=s.text.startsWith(" "),d=s.text.replace(/^ +| +$/g,"");if(d===""){N=!0;continue}let m=!1;if(w.length>0){const E=W||N||c;A?m=!0:C?m=E&&!xt(d,a):m=E}m&&(w+=" "),w+=d,W=s.text.endsWith(" "),A=!1,C=!1,N=!1}else s.kind==="break"?A=!0:s.kind==="placeholder"&&(w+=bt,C=!0);w=pt(w,a);const V=t.some(s=>s.kind==="placeholder");this.lastFlowText=w.trim();const B={plain:f&&!V?"":w.trim(),ssml:"",language:a??""};if(f){let s="";for(const c of t)if(c.kind==="text"){const{tag:d,attrs:m,lang:E}=c.ctx,b=d==="sub"?/^( *)([^]*?)( *)$/.exec(c.text):null,p=b?b[2]:c.text;if(b&&p===""){s+=c.text;continue}if(s+=b?.[1]??"",g(E)){const T=d==="sub"?G(d,m,p):P(p);s+=`<lang xml:lang="${M(E)}">${T}</lang>`}else s+=d?G(d,m,p):P(p);s+=b?.[3]??""}else c.kind==="break"?s+="<break/>":c.kind==="placeholder"&&(s+=`<readium:${c.tag} id="${M(c.child.object.id)}" />`);B.ssml=s}const v=new S;v.object={text:B};for(const s of e)v.children.push(s);this.appendChild(v),i&&n&&(this.lastFlowRange={first:[i,r],last:[n,o]})}}function Tt(h){return F(h).includes("abbreviation")?$(h.getAttribute("title")??"",!0).trim():""}function G(h,t,e){const i=Object.entries(t??{}).map(([r,n])=>` ${r}="${M(n)}"`).join("");return`<${h}${i}>${P(e)}</${h}>`}const kt=/<body[\s>]/i;function zt(h,t,e){const{predicate:i,leafText:r,domRange:n,textFragment:o}=ct(e?.textrefs);if(typeof h!="string"){const f=t??(h.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),g=new k(f==="application/xhtml+xml");return g.selectorPredicate=i,g.leafTextEnabled=r,g.domRangeEnabled=n,g.textFragmentEnabled=o,g.docRoot=h.ownerDocument,g.baseHref=e?.href,g.selectorRoot=h,g.selectorRootAnchor=ot(h),g.convert(h),g.result()}let u=t??_(h),x=new DOMParser().parseFromString(h,u);if(u==="application/xhtml+xml"){const f=x.getElementsByTagNameNS("*","parsererror")[0];if(f){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${f.textContent?.trim()??""}`);u="text/html",x=new DOMParser().parseFromString(h,u)}}const l=new k(u==="application/xhtml+xml");l.selectorPredicate=i,l.leafTextEnabled=r,l.textFragmentEnabled=o,l.docRoot=x,l.baseHref=e?.href;const a=x.querySelector("body");return a&&!kt.test(h)?l.convertChildren(a):l.convert(a??x.documentElement),l.result()}export{k as Converter,zt as parseMarkup};
@@ -1 +1 @@
1
- import{normalizedNodeText as u}from"./a11y.js";import{textIsEmpty as p}from"./text.js";import{ariaSubstitutedBuilders as m,substitutedOwnSelectorBuilders as x}from"./object.js";import{hasElementChild as b,isAncestorOf as A}from"./dom.js";import{nodeLanguage as k}from"./language.js";import{selectorForElement as h,textrefForSelector as R}from"./selectorGenerator.js";function D(s,t,r,n,f){const e={role:f},i=(t.getAttribute("title")??"").trim();i?e.text={plain:i,ssml:"",language:k(t)}:r&&(e.text={plain:r,ssml:"",language:n},m.add(e));const o=!!(e.text&&!p(e.text)),l=!s.xmlParsed&&(b(t)||o&&t.firstChild!==null);if(!o&&!l){const{text:c,language:g}=u(t);c&&(e.text={plain:c,ssml:"",language:g})}const a=h(t,s.selectorRoot,s.selectorRootAnchor),d=R(a,t);return d&&(e.textref=d),s.placeholder(t,"pagebreak",e),l}function F(s,t,r){const n={role:r},{text:f,language:e}=u(t);f&&(n.text={plain:f,ssml:"",language:e});const i=t.getAttribute("href")??"";let o=t.getAttribute("id")??"";if(!o&&i.startsWith("#")){const l=s.ids.get(i.slice(1));(!l||s.suppressed.has(l))&&(o=i.slice(1))}if(i.startsWith("#")){const l=i.slice(1),a=s.ids.get(l);if(a&&!A(a,t)&&s.noterefDepth<3){const d=s.spawnChild(a);d.convert(a);const c=d.resultBuilders();if(c.length>0){for(const g of c)delete g.id;n.children=c}}}!n.children&&i&&(n.children=[{textref:i}]),s.placeholder(t,"noteref",n,o||void 0)}function I(s,t,r,n,f){const e={};if(r.length>0&&(e.role=r),n){e.text={plain:n,ssml:"",language:f},m.add(e);const o=h(t,s.selectorRoot,s.selectorRootAnchor);o&&x.set(e,o)}else{const{text:o,language:l}=u(t);o&&(e.text={plain:o,ssml:"",language:l})}const i=t.getAttribute("href");i&&(e.textref=i),s.placeholder(t,r[0]??"link",e)}export{I as link,F as noteref,D as pagebreak};
1
+ import{ssmlAttrEscape as w}from"@readium/helpers";import{normalizedNodeText as m}from"./a11y.js";import{normalizeWhitespace as E,textIsEmpty as S}from"./text.js";import{ariaSubstitutedBuilders as h,substitutedOwnSelectorBuilders as k}from"./object.js";import{hasElementChild as I,isAncestorOf as g}from"./dom.js";import{nodeLanguage as j}from"./language.js";import{selectorForElement as p,textrefForSelector as B}from"./selectorGenerator.js";import{decodeIdFragment as x,detachSelfTextref as L}from"./textrefFragment.js";function M(t,e,i,n,d){const o={role:d},r=E(e.getAttribute("title")??"",!0).trim();r?o.text={plain:r,ssml:"",language:j(e)}:i&&(o.text={plain:i,ssml:"",language:n},h.add(o));const s=!!(o.text&&!S(o.text)),l=!t.xmlParsed&&(I(e)||s&&e.firstChild!==null);if(!s&&!l){const{text:a,language:u}=m(e);a&&(o.text={plain:a,ssml:"",language:u})}const f=p(e,t.selectorRoot,t.selectorRootAnchor),c=B(f,e);return c&&(o.textref=c),t.placeholder(e,"pagebreak",o),l}function P(t,e,i){const n={role:i},{text:d,language:o}=m(e);d&&(n.text={plain:d,ssml:"",language:o});const r=e.getAttribute("href")??"",s=r.startsWith("#")?x(r)??r.slice(1):void 0;let l=e.getAttribute("id")??"";if(!l&&s!==void 0){const f=t.ids.get(s);(!f||t.suppressed.has(f))&&(l=s)}if(s!==void 0){const f=t.ids.get(s);if(f&&!g(f,e)&&t.noterefDepth<3){const c=t.spawnChild(f);c.convert(f);const a=c.resultBuilders();if(a.length>0){for(const u of a)A(u);n.children=a}}}!n.children&&r&&(n.children=[{textref:r}]),t.placeholder(e,"noteref",n,l||void 0)}function $(t,e,i,n,d){t.placeholder(e,i[0]??"link",b(t,e,i,n,d))}function q(t,e,i,n,d){const o=b(t,e,i,n,d),r=e.getAttribute("href")??"";if(r.startsWith("#")){const s=t.ids.get(x(r)??r.slice(1));if(s&&!g(s,e)&&t.noterefDepth<3){const l=N(s).flatMap(f=>{const c=t.spawnChild(f);return c.copy=!0,c.convert(f),c.resultBuilders()});C(l),l.length>0&&(o.children=l)}}t.placeholder(e,i[0],o)}function b(t,e,i,n,d){const o={};if(i.length>0&&(o.role=i),n){o.text={plain:n,ssml:"",language:d},h.add(o);const s=p(e,t.selectorRoot,t.selectorRootAnchor);s&&k.set(o,s)}else{const{text:s,language:l}=m(e);s&&(o.text={plain:s,ssml:"",language:l})}const r=e.getAttribute("href");return r&&(o.textref=r),o}function A(t){const e=t.id;e!==void 0&&(delete t.id,L(t,e))}function C(t,e){for(const i of t)(i.id===void 0||!e?.text?.ssml.includes(`id="${w(i.id)}"`))&&A(i),i.children&&C(i.children,i)}function N(t){const e=t.tagName.toLowerCase()==="dt"?t:t.closest("dt");if(!e)return[t];let i=e.nextElementSibling;for(;i&&i.tagName.toLowerCase()==="dt";)i=i.nextElementSibling;const n=[];for(;i&&i.tagName.toLowerCase()==="dd";i=i.nextElementSibling)n.push(i);return n.length>0?[e,...n]:[t]}export{$ as link,P as noteref,M as pagebreak,q as reference};
@@ -0,0 +1 @@
1
+ import{startsWithBindingPunct as P}from"@readium/helpers";const h="\0",p="()[]{}()[]{}「」『』【】〔〕〈〉《》",w=`""''`,f={ar:"”“’‘",bg:"„“",cs:"„“‚‘",da:"“”‘’»«›‹",de:"„“‚‘»«›‹«»‹›",el:"«»“”",en:"“”‘’",es:"“”‘’",et:"„“‚‘",fi:"””’’»»››",fr:"«»",he:"””’’",hr:"„“‚‘",hu:"„”»«",hy:"«»",is:"„“‚‘",it:"«»“”",ja:"「」『』",ka:"„“«»",ko:"“”‘’",lt:"„“",lv:"“”‘’",nb:"«»‘’",nl:"‘’",pl:"„”«»",pt:"“”‘’",ro:"„”«»",ru:"«»„“",sk:"„“‚‘",sl:"„“‚‘",sr:"„”’’",sv:"””’’»»››",tr:"“”‘’",uk:"«»„“",zh:"“”‘’","zh-hant":"「」『』"},g=/[\s​-‍⁠,;、,\u0000]/,l=new Map;function a(e){const t=e?.toLowerCase()??"";let n=l.get(t);if(n)return n;const c=p+w+(f[t]??f[t.split("-")[0]]??f.en);n={pairs:new Set,opening:new Set,closing:new Set};for(let i=0;i<c.length;i+=2)n.pairs.add(c[i]+c[i+1]),n.opening.add(c[i]),n.closing.add(c[i+1]);return l.set(t,n),n}function k(e,t){return!P(e)||t?.toLowerCase().split("-")[0]==="fr"&&"»;:!?".includes(e[0])?!1:!(a(t).opening.has(e[0])&&e.length>1&&!/[\s\p{P}]/u.test(e[1]))}function S(e,t){const{pairs:n,opening:c,closing:i}=a(t);for(let r=e.indexOf(h);r!==-1;r=e.indexOf(h,r+1)){let s=r,o=r+1;for(;s>0&&g.test(e[s-1]);)s--;for(;o<e.length&&g.test(e[o]);)o++;const u=e[s-1],d=e[o];u===void 0||d===void 0||!n.has(u+d)||i.has(u)&&s>1&&!/[\s\p{Ps}\p{Pi}\p{Pd}]/u.test(e[s-2])||c.has(d)&&o<e.length-1&&!/[\s\p{P}]/u.test(e[o+1])||(e=e.slice(0,s-1)+h+e.slice(o+1),r=s-2)}return e.replace(/ *\u0000[\u0000 ]*/g,(r,s)=>{const o=e.slice(s+r.length);return s>0&&o!==""&&r.includes(" ")&&!k(o,t)?" ":""})}export{h as DROPPED,k as bindsToPrevious,S as removeDropped};
package/dist/object.js CHANGED
@@ -1 +1 @@
1
- import{GuidedNavigationObject as a,GuidedNavigationDescription as u,GuidedNavigationText as h}from"@readium/shared";import{textIsEmpty as l,finalizeText as o}from"./text.js";function N(e,n,t){e.description=n,e.descriptionLanguage=t}const g=["math","separator"],x=new WeakSet,s=new WeakSet,p=new WeakMap,f=new WeakMap;function j(e){return s.has(e)}function k(e){return f.get(e)}function c(e){return e.role?.some(n=>g.includes(n))?!1:!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||l(e.text))&&!(e.children&&e.children.length>0)&&!e.description}function v(e){return!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||l(e.text))&&!!(e.children&&e.children.length>0)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description}function m(e){return!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class y{constructor(){this.object={},this.children=[],this.noText=!1,this.hasChildBlock=!1}finalize(n){const t=this.object,d=[];for(const i of this.children){const r=i.finalize(n);if(!c(r)){if(v(r)){d.push(...r.children??[]);continue}d.push(r)}}if(d.length>0&&(t.children=d),t.role?.length&&t.children?.length===1&&!t.role.includes("presentation")){const i=t.children[0];i.role?.length&&t.role.every(r=>i.role.includes(r))&&delete t.role}if((!t.text||l(t.text))&&t.children?.length===1){const i=t.children[0];m(i)&&(i.text&&(t.text=i.text),t.children=i.children)}if(this.el&&n&&!c(t)&&!b(t)){const i=n(this.el);i&&(t.textref=i)}return t}}function b(e){return!!e.audioref||!!e.imgref||!!e.textref||!!e.videoref||!!(e.text&&(e.text.plain!==""||e.text.ssml!==""))||!!(e.children&&e.children.length>0)}function w(e){const n=new a({id:e.id||void 0,textref:e.textref||void 0,imgref:e.imgref||void 0,audioref:e.audioref||void 0,videoref:e.videoref||void 0,text:o(e.text),role:e.role&&e.role.length>0?new Set(e.role):void 0,children:e.children&&e.children.length>0?e.children.map(w):void 0,description:e.description?new u({text:new h({plain:e.description,language:e.descriptionLanguage||void 0})}):void 0});x.has(e)&&s.add(n);const t=p.get(e);return t&&f.set(n,t),n}export{y as NavObject,x as ariaSubstitutedBuilders,w as finalizeToGuidedNavigationObject,j as isAriaSubstituted,c as isEmptyObj,N as setDescription,k as substitutedOwnSelector,p as substitutedOwnSelectorBuilders};
1
+ import{GuidedNavigationObject as a,GuidedNavigationDescription as h,GuidedNavigationText as u}from"@readium/shared";import{textIsEmpty as c,finalizeText as g}from"./text.js";import{detachSelfTextref as x}from"./textrefFragment.js";function y(e,n,t){e.description=n,e.descriptionLanguage=t}const p=["math","separator"],v=new WeakSet,f=new WeakSet,m=new WeakMap,o=new WeakMap;function z(e){return f.has(e)}function C(e){return o.get(e)}function s(e){return e.role?.some(n=>p.includes(n))?!1:!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||c(e.text))&&!(e.children&&e.children.length>0)&&!e.description}function b(e){return!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||c(e.text))&&!!(e.children&&e.children.length>0)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description}function w(e){return!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class G{constructor(){this.object={},this.children=[],this.noText=!1,this.hasChildBlock=!1}finalize(n){const t=this.object,d=[];for(const i of this.children){const r=i.finalize(n);if(!s(r)){if(b(r)){d.push(...r.children??[]);continue}d.push(r)}}if(d.length>0&&(t.children=d),t.role?.length&&t.children?.length===1&&!t.role.includes("presentation")){const i=t.children[0];i.role?.length&&t.role.every(r=>i.role.includes(r))&&delete t.role}if((!t.text||c(t.text))&&t.children?.length===1){const i=t.children[0];w(i)&&(i.text&&(t.text=i.text),t.children=i.children)}if(this.el&&n&&!s(t)&&!S(t)){const i=n(this.el);i&&(t.textref=i)}const l=this.el?.getAttribute("id");return l&&t.id!==l&&x(t,l),t}}function S(e){return!!e.audioref||!!e.imgref||!!e.textref||!!e.videoref||!!(e.text&&(e.text.plain!==""||e.text.ssml!==""))||!!(e.children&&e.children.length>0)}function O(e){const n=new a({id:e.id||void 0,textref:e.textref||void 0,imgref:e.imgref||void 0,audioref:e.audioref||void 0,videoref:e.videoref||void 0,text:g(e.text),role:e.role&&e.role.length>0?new Set(e.role):void 0,children:e.children&&e.children.length>0?e.children.map(O):void 0,description:e.description?new h({text:new u({plain:e.description,language:e.descriptionLanguage||void 0})}):void 0});v.has(e)&&f.add(n);const t=m.get(e);return t&&o.set(n,t),n}export{G as NavObject,v as ariaSubstitutedBuilders,O as finalizeToGuidedNavigationObject,z as isAriaSubstituted,s as isEmptyObj,y as setDescription,C as substitutedOwnSelector,m as substitutedOwnSelectorBuilders};
package/dist/prescan.js CHANGED
@@ -1 +1 @@
1
- import{extractNodeRoles as c}from"./roles.js";import{isAncestorOf as u}from"./dom.js";function m(i){for(let r=i.parentElement;r;r=r.parentElement)if(c(r).includes("endnotes"))return!0;return!1}function p(i,r,l){const s=[],f=(t,e)=>{const n=t.getAttribute("id");if(n&&!r.has(n)&&r.set(n,t),e=e||t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"),!e&&t.tagName.toLowerCase()==="a"&&c(t).includes("noteref")){const a=t.getAttribute("href")??"";a.startsWith("#")&&s.push({id:a.slice(1),ref:t})}for(let o=t.firstElementChild;o;o=o.nextElementSibling)f(o,e)};f(i,!1);for(const t of s){const e=r.get(t.id);e&&(u(e,t.ref)||m(e)||l.add(e))}}export{p as prescan};
1
+ import{extractNodeRoles as c}from"./roles.js";import{isAncestorOf as u}from"./dom.js";import{decodeIdFragment as m}from"./textrefFragment.js";function d(i){for(let r=i.parentElement;r;r=r.parentElement)if(c(r).includes("endnotes"))return!0;return!1}function A(i,r,l){const f=[],a=(t,e)=>{const n=t.getAttribute("id");if(n&&!r.has(n)&&r.set(n,t),e=e||t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"),!e&&t.tagName.toLowerCase()==="a"&&c(t).includes("noteref")){const s=t.getAttribute("href")??"";s.startsWith("#")&&f.push({id:m(s)??s.slice(1),ref:t})}for(let o=t.firstElementChild;o;o=o.nextElementSibling)a(o,e)};a(i,!1);for(const t of f){const e=r.get(t.id);e&&(u(e,t.ref)||d(e)||l.add(e))}}export{A as prescan};
package/dist/roles.js CHANGED
@@ -1 +1 @@
1
- const u=["heading1","heading2","heading3","heading4","heading5","heading6"],c={"doc-abstract":"abstract","doc-acknowledgments":"acknowledgments","doc-afterword":"afterword","doc-appendix":"appendix",article:"article","doc-backlink":"backlink","doc-biblioentry":"listItem","doc-bibliography":"bibliography","doc-biblioref":"biblioref",blockquote:"blockquote",caption:"caption",cell:"cell","doc-chapter":"chapter","doc-colophon":"colophon",columnheader:"columnheader",complementary:"complementary","doc-conclusion":"conclusion","doc-cover":"cover","doc-credit":"credit","doc-credits":"credits","doc-dedication":"dedication",definition:"definition","doc-endnote":"footnote","doc-endnotes":"endnotes","doc-epigraph":"epigraph","doc-epilogue":"epilogue","doc-errata":"errata","doc-example":"example",figure:"figure","doc-footnote":"footnote","doc-foreword":"foreword","doc-glossary":"glossary","doc-glossref":"glossref",img:"image",image:"image","doc-index":"index","doc-introduction":"introduction",list:"list",listitem:"listItem",main:"main",math:"math",navigation:"navigation","doc-noteref":"noteref","doc-notice":"notice","doc-pagebreak":"pagebreak","doc-pagelist":"pagelist",paragraph:"paragraph","doc-part":"part","doc-preface":"preface","doc-prologue":"prologue","doc-pullquote":"pullquote",grid:"table",gridcell:"cell",presentation:"presentation",none:"presentation","doc-qna":"qna",qna:"qna",region:"region",row:"row",rowheader:"rowheader",separator:"separator","doc-subtitle":"subtitle",table:"table",term:"term","doc-tip":"tip","doc-toc":"toc"},f={abstract:"abstract",acknowledgments:"acknowledgments",afterword:"afterword",appendix:"appendix",aside:"aside",backlink:"backlink",biblioentry:"listItem",bibliography:"bibliography",biblioref:"biblioref","table-cell":"cell",chapter:"chapter",colophon:"colophon",conclusion:"conclusion",cover:"cover",credit:"credit",credits:"credits",dedication:"dedication",glossdef:"definition",endnote:"footnote",endnotes:"endnotes",rearnote:"footnote",rearnotes:"endnotes",epigraph:"epigraph",epilogue:"epilogue",errata:"errata",example:"example",figure:"figure",footnote:"footnote",foreword:"foreword",glossary:"glossary",glossref:"glossref",index:"index",introduction:"introduction",landmarks:"landmarks",list:"list","list-item":"listItem",loa:"loa",loi:"loi",lot:"lot",lov:"lov",noteref:"noteref",notice:"notice",pagebreak:"pagebreak","page-list":"pagelist",pagelist:"pagelist",part:"part",preface:"preface",prologue:"prologue",pullquote:"pullquote",qna:"qna","table-row":"row",subtitle:"subtitle",table:"table",glossterm:"term",tip:"tip",toc:"toc"},g={article:"article",aside:"aside",audio:"audio",blockquote:"blockquote",caption:"caption",figcaption:"caption",td:"cell",dd:"definition",details:"details",figure:"figure",header:"header",h1:"heading1",h2:"heading2",h3:"heading3",h4:"heading4",h5:"heading5",h6:"heading6",img:"image",ul:"list",ol:"list",li:"listItem",main:"main",math:"math",nav:"navigation",p:"paragraph",pre:"preformatted",tr:"row",section:"section",hr:"separator",summary:"summary",table:"table",dfn:"term",dt:"term",video:"video",svg:"image"},b=new Set(["tr","td","th"]),m=new Set(["tr","thead","tbody","tfoot"]);function h(e){const o=e.getAttribute("role");if(!o)return!1;const t=o.split(/\s+/).filter(Boolean);return t.includes("presentation")||t.includes("none")}function d(e){return(e.getAttribute("role")??"").trim()!==""}function w(e,o){if(!b.has(o)||d(e))return!1;for(let t=e.parentElement;t;t=t.parentElement){const a=t.tagName.toLowerCase();if(a!=="table"&&!m.has(a))return!1;if(h(t))return!0;if(a==="table"||d(t))return!1}return!1}function l(e,o){const t=e.getAttribute("role");return t?t.split(/\s+/).filter(Boolean).includes(o):!1}function k(e){return e.tagName.toLowerCase()==="table"||l(e,"table")||l(e,"grid")||l(e,"treegrid")}function y(e){return e.tagName.toLowerCase()==="tr"||l(e,"row")}function v(e){let o=null;for(let a=e.parentElement;a;a=a.parentElement)if(k(a)){o=a;break}return o?o.ownerDocument.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>y(a)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}).nextNode()===e:!1}function p(e){const o=[];let t=!1;const a=e.getAttribute("role");if(a)for(const i of a.split(/\s+/).filter(Boolean))if((i==="presentation"||i==="none")&&(t=!0),i==="heading"){let r=2;const s=parseInt(e.getAttribute("aria-level")??"",10);Number.isFinite(s)&&s>=1&&(r=Math.min(s,6)),o.push(u[r-1])}else c[i]&&o.push(c[i]);const n=e.getAttribute("epub:type");if(n)for(const i of n.split(/\s+/).filter(Boolean)){const r=f[i];r&&o.push(r)}return{attrRoles:o,presentational:t}}function x(e){const{attrRoles:o,presentational:t}=p(e);return o.length>0||t}function E(e){const o=[],t=r=>{o.includes(r)||o.push(r)},{attrRoles:a,presentational:n}=p(e),i=e.tagName.toLowerCase();if(n)return["presentation"];if(w(e,i))return["presentation"];if(i==="body")t("body");else if(i==="th")switch(e.getAttribute("scope")){case"col":t("columnheader");break;case"row":t("rowheader");break;default:{const r=e.parentElement;r&&v(r)?t("columnheader"):e.previousElementSibling===null?t("rowheader"):t("cell")}}else{const r=g[i];r&&t(r)}for(const r of a)t(r);return o}export{E as extractNodeRoles,x as hasExplicitRole};
1
+ const u=["heading1","heading2","heading3","heading4","heading5","heading6"],s={"doc-abstract":"abstract","doc-acknowledgments":"acknowledgments","doc-afterword":"afterword","doc-appendix":"appendix",article:"article","doc-backlink":"backlink","doc-biblioentry":"listItem","doc-bibliography":"bibliography","doc-biblioref":"biblioref",blockquote:"blockquote",caption:"caption",cell:"cell","doc-chapter":"chapter","doc-colophon":"colophon",columnheader:"columnheader",complementary:"complementary","doc-conclusion":"conclusion","doc-cover":"cover","doc-credit":"credit","doc-credits":"credits","doc-dedication":"dedication",definition:"definition","doc-endnote":"footnote","doc-endnotes":"endnotes","doc-epigraph":"epigraph","doc-epilogue":"epilogue","doc-errata":"errata","doc-example":"example",figure:"figure","doc-footnote":"footnote","doc-foreword":"foreword","doc-glossary":"glossary","doc-glossref":"glossref",img:"image",image:"image","doc-index":"index","doc-introduction":"introduction",list:"list",listitem:"listItem",main:"main",math:"math",navigation:"navigation","doc-noteref":"noteref","doc-notice":"notice","doc-pagebreak":"pagebreak","doc-pagelist":"pagelist",paragraph:"paragraph","doc-part":"part","doc-preface":"preface","doc-prologue":"prologue","doc-pullquote":"pullquote",grid:"table",gridcell:"cell",presentation:"presentation",none:"presentation","doc-qna":"qna",qna:"qna",region:"region",row:"row",rowheader:"rowheader",separator:"separator","doc-subtitle":"subtitle",table:"table",term:"term","doc-tip":"tip","doc-toc":"toc"},f={abstract:"abstract",acknowledgments:"acknowledgments",afterword:"afterword",appendix:"appendix",aside:"aside",backlink:"backlink",biblioentry:"listItem",bibliography:"bibliography",biblioref:"biblioref","table-cell":"cell",chapter:"chapter",colophon:"colophon",conclusion:"conclusion",cover:"cover",credit:"credit",credits:"credits",dedication:"dedication",glossdef:"definition",endnote:"footnote",endnotes:"endnotes",rearnote:"footnote",rearnotes:"endnotes",epigraph:"epigraph",epilogue:"epilogue",errata:"errata",example:"example",figure:"figure",footnote:"footnote",foreword:"foreword",glossary:"glossary",glossref:"glossref",index:"index",introduction:"introduction",landmarks:"landmarks",list:"list","list-item":"listItem",loa:"loa",loi:"loi",lot:"lot",lov:"lov",noteref:"noteref",notice:"notice",pagebreak:"pagebreak","page-list":"pagelist",pagelist:"pagelist",part:"part",preface:"preface",prologue:"prologue",pullquote:"pullquote",qna:"qna","table-row":"row",subtitle:"subtitle",table:"table",glossterm:"term",tip:"tip",toc:"toc"},g={abbr:"abbreviation",acronym:"abbreviation",article:"article",aside:"aside",audio:"audio",blockquote:"blockquote",caption:"caption",figcaption:"caption",td:"cell",dd:"definition",details:"details",figure:"figure",header:"header",h1:"heading1",h2:"heading2",h3:"heading3",h4:"heading4",h5:"heading5",h6:"heading6",img:"image",ul:"list",ol:"list",li:"listItem",main:"main",math:"math",nav:"navigation",p:"paragraph",pre:"preformatted",tr:"row",section:"section",hr:"separator",summary:"summary",table:"table",dfn:"term",dt:"term",video:"video",svg:"image"},b=new Set(["tr","td","th"]),m=new Set(["tr","thead","tbody","tfoot"]);function h(e){const o=e.getAttribute("role");if(!o)return!1;const t=o.split(/\s+/).filter(Boolean);return t.includes("presentation")||t.includes("none")}function d(e){return(e.getAttribute("role")??"").trim()!==""}function w(e,o){if(!b.has(o)||d(e))return!1;for(let t=e.parentElement;t;t=t.parentElement){const a=t.tagName.toLowerCase();if(a!=="table"&&!m.has(a))return!1;if(h(t))return!0;if(a==="table"||d(t))return!1}return!1}function l(e,o){const t=e.getAttribute("role");return t?t.split(/\s+/).filter(Boolean).includes(o):!1}function k(e){return e.tagName.toLowerCase()==="table"||l(e,"table")||l(e,"grid")||l(e,"treegrid")}function v(e){return e.tagName.toLowerCase()==="tr"||l(e,"row")}function y(e){let o=null;for(let a=e.parentElement;a;a=a.parentElement)if(k(a)){o=a;break}return o?o.ownerDocument.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>v(a)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}).nextNode()===e:!1}function p(e){const o=[];let t=!1;const a=e.getAttribute("role");if(a)for(const i of a.split(/\s+/).filter(Boolean))if((i==="presentation"||i==="none")&&(t=!0),i==="heading"){let r=2;const c=parseInt(e.getAttribute("aria-level")??"",10);Number.isFinite(c)&&c>=1&&(r=Math.min(c,6)),o.push(u[r-1])}else s[i]&&o.push(s[i]);const n=e.getAttribute("epub:type");if(n)for(const i of n.split(/\s+/).filter(Boolean)){const r=f[i];r&&o.push(r)}return{attrRoles:o,presentational:t}}function x(e){const{attrRoles:o,presentational:t}=p(e);return o.length>0||t}function E(e){const o=[],t=r=>{o.includes(r)||o.push(r)},{attrRoles:a,presentational:n}=p(e),i=e.tagName.toLowerCase();if(n)return["presentation"];if(w(e,i))return["presentation"];if(i==="body")t("body");else if(i==="th")switch(e.getAttribute("scope")){case"col":t("columnheader");break;case"row":t("rowheader");break;default:{const r=e.parentElement;r&&y(r)?t("columnheader"):e.previousElementSibling===null?t("rowheader"):t("cell")}}else{const r=g[i];r&&t(r)}for(const r of a)t(r);return o}export{E as extractNodeRoles,x as hasExplicitRole};
package/dist/text.js CHANGED
@@ -1 +1 @@
1
- import{GuidedNavigationText as l}from"@readium/shared";function f(e){return e.plain===""&&e.ssml===""&&e.language===""}function c(e){if(!(!e||e.plain===""&&e.ssml===""))return new l({plain:e.plain!==""?e.plain:void 0,ssml:e.ssml!==""?e.ssml:void 0,language:e.language!==""?e.language:void 0})}function g(e,a){if(e.lang!==a.lang||e.tag!==a.tag)return!1;const n=Object.entries(e.attrs??{}),i=Object.entries(a.attrs??{});return n.length!==i.length?!1:n.every(([s,t])=>a.attrs?.[s]===t)}const r=/[\u00A0\u2007\u202F]/;function u(e){return r.test(e)}function p(e,a){let n="",i=!1,s=!1;for(const t of e)if(u(t))n+=t,i=!1,s=!0;else if(/\s/.test(t)){if(a&&!s||i)continue;n+=" ",i=!0}else t!=="​"&&t!=="­"&&(n+=t,i=!1,s=!0);return n}export{g as ctxEqual,c as finalizeText,u as isNoBreakSpace,p as normalizeWhitespace,f as textIsEmpty};
1
+ import{GuidedNavigationText as r}from"@readium/shared";function f(e){return e.plain===""&&e.ssml===""&&e.language===""}function c(e){if(!(!e||e.plain===""&&e.ssml===""))return new r({plain:e.plain!==""?e.plain:void 0,ssml:e.ssml!==""?e.ssml:void 0,language:e.language!==""?e.language:void 0})}function g(e,n){if(e.lang!==n.lang||e.tag!==n.tag||e.abbr!==n.abbr)return!1;const a=Object.entries(e.attrs??{}),i=Object.entries(n.attrs??{});return a.length!==i.length?!1:a.every(([s,t])=>n.attrs?.[s]===t)}const l=/[\u00A0\u2007\u202F]/;function u(e){return l.test(e)}function p(e,n){let a="",i=!1,s=!1;for(const t of e)if(u(t))a+=t,i=!1,s=!0;else if(/\s/.test(t)){if(n&&!s||i)continue;a+=" ",i=!0}else t!=="​"&&t!=="­"&&(a+=t,i=!1,s=!0);return a}export{g as ctxEqual,c as finalizeText,u as isNoBreakSpace,p as normalizeWhitespace,f as textIsEmpty};
@@ -1 +1 @@
1
- const l="#css(";function C(e){return`${l}${encodeURIComponent(e)})`}function v(e){if(!(!e||!e.startsWith(l)||!e.endsWith(")")))return decodeURIComponent(e.slice(l.length,-1))}const m="#domrange(",g=")";function U(e){return`${m}${encodeURIComponent(JSON.stringify(e))}${g}`}function x(e){if(!(!e||!e.startsWith(m)||!e.endsWith(g)))try{const n=JSON.parse(decodeURIComponent(e.slice(m.length,-g.length)));return!n?.start?.cssSelector||typeof n.start.textNodeIndex!="number"?void 0:n}catch{return}}const h=":~:text=";function a(e){return encodeURIComponent(e).replace(/-/g,"%2D")}function I(e){let n="";return e.prefix&&(n+=`${a(e.prefix)}-,`),n+=a(e.textStart),e.textEnd&&(n+=`,${a(e.textEnd)}`),e.suffix&&(n+=`,-${a(e.suffix)}`),`${h}${n}`}function p(e){if(!e)return;const n=e.indexOf(h);if(n===-1)return;const o=e.slice(n+h.length).split("&")[0];if(o)try{let t=o.split(",");const i={textStart:""};return t[0].endsWith("-")&&(i.prefix=decodeURIComponent(t[0].slice(0,-1)),t=t.slice(1)),t.length>0&&t[t.length-1].startsWith("-")&&(i.suffix=decodeURIComponent(t[t.length-1].slice(1)),t=t.slice(0,-1)),t.length===0||t[0]===""?void 0:(i.textStart=decodeURIComponent(t[0]),t.length>1&&(i.textEnd=decodeURIComponent(t[1])),i)}catch{return}}function $(e,n){if(!e.domRange||!n.domRange||e.href!==n.href)return;const o={start:e.domRange.start,end:n.domRange.end??n.domRange.start};e.domRange.container!==void 0&&(o.container=e.domRange.container);const t={domRange:o,cssSelector:o.container??o.start.cssSelector};return e.href!==void 0&&(t.href=e.href),t}function F(e){if(e.startsWith("#"))try{return decodeURIComponent(e.slice(1))}catch{return}}function E(e){const n=e?.textref;if(!n)return;const o=n.indexOf(":~:"),t=o===-1?n:n.slice(0,o),i=t.indexOf("#"),S=i===-1?t:t.slice(0,i),u=i===-1?"":t.slice(i);let d,s;const f=x(u);if(f)s=f,d=f.container??f.start.cssSelector;else{const R=v(u);R!==void 0?d=R:e.id&&F(u)===e.id&&(d=`#${CSS.escape(e.id)}`)}const r=p(n);if(d===void 0&&s===void 0&&r===void 0)return;const c={};return S!==""&&(c.href=S),d!==void 0&&(c.cssSelector=d),s!==void 0&&(c.domRange=s),r?.textEnd!==void 0?c.fragment=I(r):r&&(c.text={highlight:r.textStart},r.prefix!==void 0&&(c.text.before=r.prefix),r.suffix!==void 0&&(c.text.after=r.suffix)),c}export{$ as combineDomRangeTextrefs,v as decodeCssSelectorFragment,x as decodeDomRangeFragment,p as decodeTextFragmentDirective,E as decodeTextref,C as encodeCssSelectorFragment,U as encodeDomRangeFragment,I as encodeTextFragmentDirective};
1
+ const l="#css(";function R(e){return`${l}${encodeURIComponent(e)})`}function U(e,t){const o=`#${encodeURIComponent(t)}`;(e.textref===o||e.textref?.startsWith(`${o}:~:`))&&(e.textref=R(`#${CSS.escape(t)}`)+e.textref.slice(o.length))}function v(e){if(!(!e||!e.startsWith(l)||!e.endsWith(")")))return decodeURIComponent(e.slice(l.length,-1))}const m="#domrange(",g=")";function $(e){return`${m}${encodeURIComponent(JSON.stringify(e))}${g}`}function p(e){if(!(!e||!e.startsWith(m)||!e.endsWith(g)))try{const t=JSON.parse(decodeURIComponent(e.slice(m.length,-g.length)));return!t?.start?.cssSelector||typeof t.start.textNodeIndex!="number"?void 0:t}catch{return}}const h=":~:text=";function a(e){return encodeURIComponent(e).replace(/-/g,"%2D")}function I(e){let t="";return e.prefix&&(t+=`${a(e.prefix)}-,`),t+=a(e.textStart),e.textEnd&&(t+=`,${a(e.textEnd)}`),e.suffix&&(t+=`,-${a(e.suffix)}`),`${h}${t}`}function C(e){if(!e)return;const t=e.indexOf(h);if(t===-1)return;const o=e.slice(t+h.length).split("&")[0];if(o)try{let n=o.split(",");const i={textStart:""};return n[0].endsWith("-")&&(i.prefix=decodeURIComponent(n[0].slice(0,-1)),n=n.slice(1)),n.length>0&&n[n.length-1].startsWith("-")&&(i.suffix=decodeURIComponent(n[n.length-1].slice(1)),n=n.slice(0,-1)),n.length===0||n[0]===""?void 0:(i.textStart=decodeURIComponent(n[0]),n.length>1&&(i.textEnd=decodeURIComponent(n[1])),i)}catch{return}}function E(e,t){if(!e.domRange||!t.domRange||e.href!==t.href)return;const o={start:e.domRange.start,end:t.domRange.end??t.domRange.start};e.domRange.container!==void 0&&(o.container=e.domRange.container);const n={domRange:o,cssSelector:o.container??o.start.cssSelector};return e.href!==void 0&&(n.href=e.href),n}function F(e){if(e.startsWith("#"))try{return decodeURIComponent(e.slice(1))}catch{return}}function D(e){const t=e?.textref;if(!t)return;const o=t.indexOf(":~:"),n=o===-1?t:t.slice(0,o),i=n.indexOf("#"),x=i===-1?n:n.slice(0,i),u=i===-1?"":n.slice(i);let d,s;const f=p(u);if(f)s=f,d=f.container??f.start.cssSelector;else{const S=v(u);S!==void 0?d=S:e.id&&F(u)===e.id&&(d=`#${CSS.escape(e.id)}`)}const r=C(t);if(d===void 0&&s===void 0&&r===void 0)return;const c={};return x!==""&&(c.href=x),d!==void 0&&(c.cssSelector=d),s!==void 0&&(c.domRange=s),r?.textEnd!==void 0?c.fragment=I(r):r&&(c.text={highlight:r.textStart},r.prefix!==void 0&&(c.text.before=r.prefix),r.suffix!==void 0&&(c.text.after=r.suffix)),c}export{E as combineDomRangeTextrefs,v as decodeCssSelectorFragment,p as decodeDomRangeFragment,F as decodeIdFragment,C as decodeTextFragmentDirective,D as decodeTextref,U as detachSelfTextref,R as encodeCssSelectorFragment,$ as encodeDomRangeFragment,I as encodeTextFragmentDirective};
@@ -7,6 +7,7 @@ renaming, or removing a fixture.
7
7
 
8
8
  | Role | Fixtures |
9
9
  | --- | --- |
10
+ | `abbreviation` | `abbreviation-acronym-html-native`, `abbreviation-before-formatting`, `abbreviation-before-image`, `abbreviation-html-native`, `abbreviation-language`, `abbreviation-line-break`, `abbreviation-nested`, `abbreviation-nested-emphasis`, `abbreviation-nested-term`, `abbreviation-nested-term-punctuation`, `abbreviation-no-title`, `abbreviation-spanning-terms`, `abbreviation-with-image`, `abbreviation-with-svg-and-math` |
10
11
  | `abstract` | `abstract-epub-type`, `abstract-role-aria` |
11
12
  | `accessible-name` | `accessible-name-labelledby-aria-hidden`, `accessible-name-labelledby-hidden-attribute` |
12
13
  | `acknowledgments` | `acknowledgments-epub-type`, `acknowledgments-role-aria` |
@@ -17,7 +18,7 @@ renaming, or removing a fixture.
17
18
  | `audio` | `audio-html-native`, `audio-no-description` |
18
19
  | `backlink` | `backlink-epub-type`, `backlink-role-aria` |
19
20
  | `bibliography` | `bibliography-epub-type`, `bibliography-role-aria` |
20
- | `biblioref` | `biblioref-epub-type`, `biblioref-role-aria` |
21
+ | `biblioref` | `biblioref-epub-type`, `biblioref-role-aria`, `biblioref-target-descendant-ids`, `biblioref-target-in-bibliography-role-aria`, `biblioref-target-mixed-content` |
21
22
  | `blockquote` | `blockquote-html-native`, `blockquote-role-aria` |
22
23
  | `body` | `body-html-native` |
23
24
  | `chapter` | `chapter-epub-type`, `chapter-role-aria` |
@@ -39,7 +40,7 @@ renaming, or removing a fixture.
39
40
  | `footnote` | `footnote-epub-type`, `footnote-role-aria`, `noteref-target-in-endnotes-epub-type`, `noteref-target-in-endnotes-role-aria` |
40
41
  | `foreword` | `foreword-epub-type`, `foreword-role-aria` |
41
42
  | `glossary` | `glossary-epub-type`, `glossary-role-aria` |
42
- | `glossref` | `glossref-epub-type`, `glossref-role-aria`, `glossref-role-aria-mid-sentence` |
43
+ | `glossref` | `glossref-epub-type`, `glossref-role-aria`, `glossref-role-aria-mid-sentence`, `glossref-sole-content`, `glossref-target-in-glossary-role-aria`, `glossref-target-percent-encoded` |
43
44
  | `header` | `header-html-native` |
44
45
  | `heading` | `heading-html-native`, `heading-role-aria` |
45
46
  | `image` | `image-alt-html-native`, `image-no-description`, `image-role-aria` |
@@ -55,7 +56,7 @@ renaming, or removing a fixture.
55
56
  | `main` | `main-html-native`, `main-role-aria` |
56
57
  | `math` | `math-html-native`, `math-no-description`, `math-role-aria` |
57
58
  | `navigation` | `navigation-html-native`, `navigation-role-aria` |
58
- | `noteref` | `noteref-role-aria` |
59
+ | `noteref` | `noteref-after-closing-straight-quote`, `noteref-after-closing-straight-quote-split`, `noteref-enclosed-across-formatting`, `noteref-enclosed-adjacent-pairs`, `noteref-enclosed-adjacent-text`, `noteref-enclosed-before-formatting`, `noteref-enclosed-guillemets-french`, `noteref-enclosed-quotes-chinese`, `noteref-enclosed-quotes-german`, `noteref-enclosed-quotes-swedish`, `noteref-enclosed-straight-quotes`, `noteref-in-lone-block`, `noteref-role-aria`, `noteref-target-malformed-escape`, `noteref-target-percent-encoded` |
59
60
  | `notice` | `notice-epub-type`, `notice-role-aria` |
60
61
  | `pagebreak` | `pagebreak-epub-type`, `pagebreak-role-aria` |
61
62
  | `pagelist` | `pagelist-epub-type`, `pagelist-role-aria` |
@@ -72,10 +73,10 @@ renaming, or removing a fixture.
72
73
  | `separator` | `separator-html-native`, `separator-role-aria`, `separator-with-glyphs` |
73
74
  | `subtitle` | `subtitle-epub-type`, `subtitle-role-aria` |
74
75
  | `summary` | `summary-html-native` |
75
- | `table` | `table-caption`, `table-caption-element-html-native`, `table-caption-role-aria`, `table-colspan-html-native`, `table-colspan-role-aria`, `table-epub-type`, `table-html-native`, `table-in-role-none-wrapper`, `table-nested-html-native`, `table-nested-role-aria`, `table-no-headers`, `table-role-aria`, `table-rowgroup-role-aria`, `table-rowspan-html-native`, `table-rowspan-role-aria`, `table-sectioning`, `table-th-no-scope` |
76
+ | `table` | `table-caption`, `table-caption-element-html-native`, `table-caption-role-aria`, `table-cell-abbreviation`, `table-cell-noteref`, `table-colspan-html-native`, `table-colspan-role-aria`, `table-epub-type`, `table-html-native`, `table-in-role-none-wrapper`, `table-nested-html-native`, `table-nested-role-aria`, `table-no-headers`, `table-role-aria`, `table-rowgroup-role-aria`, `table-rowspan-html-native`, `table-rowspan-role-aria`, `table-sectioning`, `table-th-no-scope` |
76
77
  | `term` | `term-epub-type`, `term-html-native`, `term-role-aria` |
77
78
  | `tip` | `tip-epub-type`, `tip-role-aria` |
78
79
  | `toc` | `toc-epub-type`, `toc-role-aria` |
79
80
  | `video` | `video-html-native`, `video-no-description` |
80
81
 
81
- 180 fixtures across 70 roles.
82
+ 216 fixtures across 71 roles.
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p>The <acronym title="World Health Organization">WHO</acronym> said.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-acronym-html-native",
3
+ "description": "An obsolete acronym with a title becomes an SSML sub, same as abbr",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> <emphasis>said</emphasis> so.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="World Health Organization">WHO</abbr> <em>said</em> so.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-before-formatting",
3
+ "description": "The space between an abbr and following formatted text stays outside the sub",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "children": [
3
+ {
4
+ "id": "image1",
5
+ "imgref": "logo.png",
6
+ "role": [
7
+ "image"
8
+ ],
9
+ "description": {
10
+ "text": {
11
+ "plain": "logo"
12
+ }
13
+ }
14
+ }
15
+ ],
16
+ "role": [
17
+ "paragraph"
18
+ ],
19
+ "text": {
20
+ "plain": "The WHO said so.",
21
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> <emphasis>said</emphasis> so.",
22
+ "language": "en"
23
+ }
24
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="World Health Organization">WHO</abbr><img src="logo.png" alt="logo"/> <em>said</em> so.</p>
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "abbreviation-before-image",
3
+ "description": "Whitespace after an abbr and an image stays plain, rather than in a sub that would speak the expansion again",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "image",
8
+ "paragraph"
9
+ ],
10
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
11
+ "inputKind": "fragment"
12
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="World Health Organization">WHO</abbr> said.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-html-native",
3
+ "description": "An abbr with a title becomes an SSML sub whose alias is the title",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <lang xml:lang=\"fr\"><sub alias=\"Organisation mondiale de la santé\">OMS</sub></lang> said.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p lang="en">The <abbr lang="fr" title="Organisation mondiale de la santé">OMS</abbr> said.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-language",
3
+ "description": "An abbr in another language keeps its sub, wrapped in a lang since sub can't carry xml:lang",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="World Health Organization">W<br/>HO</abbr> said.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-line-break",
3
+ "description": "A line break inside an abbr is only visual: its expansion is still one sub, spoken once",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <sub alias=\"United States of America\">USA</sub> today.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="United States of America"><abbr title="United States">US</abbr>A</abbr> today.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-nested",
3
+ "description": "An abbr nested in another is covered by the outer one's expansion: one sub, spoken once",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
+ "language": "en"
8
+ }
9
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="World Health Organization"><em>W</em>HO</abbr> said.</p>
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "abbreviation-nested-emphasis",
3
+ "description": "Formatting inside an abbr is dropped: its whole text becomes one sub",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "paragraph"
8
+ ],
9
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
10
+ "inputKind": "fragment"
11
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "children": [
6
+ {
7
+ "role": [
8
+ "term"
9
+ ],
10
+ "text": {
11
+ "ssml": "<sub alias=\"World Health Organization\">WHO</sub>",
12
+ "language": "en"
13
+ }
14
+ },
15
+ {
16
+ "text": {
17
+ "plain": "said."
18
+ }
19
+ }
20
+ ]
21
+ }
@@ -0,0 +1 @@
1
+ <p><abbr title="World Health Organization"><dfn>WHO</dfn></abbr> said.</p>
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "abbreviation-nested-term",
3
+ "description": "An abbr wrapping a whole term still expands that term's text",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "term",
8
+ "paragraph"
9
+ ],
10
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
11
+ "inputKind": "fragment"
12
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "children": [
6
+ {
7
+ "text": {
8
+ "plain": "The"
9
+ }
10
+ },
11
+ {
12
+ "role": [
13
+ "term"
14
+ ],
15
+ "text": {
16
+ "ssml": "<sub alias=\"World Health Organization\">W.H.O</sub>",
17
+ "language": "en"
18
+ }
19
+ },
20
+ {
21
+ "text": {
22
+ "plain": ". said."
23
+ }
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr title="World Health Organization"><dfn>W.H.O</dfn>.</abbr> said.</p>
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "abbreviation-nested-term-punctuation",
3
+ "description": "An abbr wrapping a term and punctuation outside it still expands that term's text",
4
+ "role": "abbreviation",
5
+ "rolesCovered": [
6
+ "abbreviation",
7
+ "term",
8
+ "paragraph"
9
+ ],
10
+ "sourceRef": "https://www.w3.org/TR/speech-synthesis11/#S3.1.10",
11
+ "inputKind": "fragment"
12
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "role": [
3
+ "paragraph"
4
+ ],
5
+ "text": {
6
+ "plain": "The WHO said."
7
+ }
8
+ }
@@ -0,0 +1 @@
1
+ <p>The <abbr>WHO</abbr> said.</p>