@readium/guided-navigation 1.2.3 → 1.2.4
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/README.md +4 -1
- package/dist/converter.js +1 -1
- package/dist/elementHandlers.js +1 -1
- package/dist/object.js +1 -1
- package/dist/roles.js +1 -1
- package/fixtures/ROLES_COVERAGE.md +12 -10
- package/fixtures/abbreviation-nested-term-punctuation/gnd.json +6 -6
- package/fixtures/abbreviation-nested-term-punctuation/input.html +1 -1
- package/fixtures/abbreviation-nested-term-punctuation/meta.json +1 -1
- package/fixtures/accessible-name-labelledby-aria-hidden/gnd.json +1 -1
- package/fixtures/accessible-name-labelledby-hidden-attribute/gnd.json +1 -1
- package/fixtures/biblioref-target-descendant-ids/gnd.json +3 -3
- package/fixtures/biblioref-target-in-bibliography-role-aria/gnd.json +1 -1
- package/fixtures/biblioref-target-mixed-content/gnd.json +3 -3
- package/fixtures/description-roleless-lone-child/gnd.json +24 -0
- package/fixtures/description-roleless-lone-child/input.html +1 -0
- package/fixtures/description-roleless-lone-child/meta.json +11 -0
- package/fixtures/description-roleless-wrapper/gnd.json +25 -0
- package/fixtures/description-roleless-wrapper/input.html +1 -0
- package/fixtures/description-roleless-wrapper/meta.json +10 -0
- package/fixtures/glossary-role-aria/gnd.json +23 -31
- package/fixtures/glossref-role-aria-mid-sentence/gnd.json +1 -1
- package/fixtures/glossref-sole-content/gnd.json +12 -20
- package/fixtures/glossref-target-in-glossary-role-aria/gnd.json +13 -21
- package/fixtures/glossref-target-percent-encoded/gnd.json +1 -1
- package/fixtures/language-alt-inherited/gnd.json +25 -0
- package/fixtures/language-alt-inherited/input.html +1 -0
- package/fixtures/language-alt-inherited/meta.json +11 -0
- package/fixtures/language-alt-own-lang/gnd.json +25 -0
- package/fixtures/language-alt-own-lang/input.html +1 -0
- package/fixtures/language-alt-own-lang/meta.json +11 -0
- package/fixtures/language-block-empty-lang/gnd.json +8 -0
- package/fixtures/language-block-empty-lang/input.html +1 -0
- package/fixtures/language-block-empty-lang/meta.json +10 -0
- package/fixtures/language-describedby-shared/gnd.json +49 -0
- package/fixtures/language-describedby-shared/input.html +1 -0
- package/fixtures/language-describedby-shared/meta.json +12 -0
- package/fixtures/language-empty-lang-stops-inheritance/gnd.json +24 -0
- package/fixtures/language-empty-lang-stops-inheritance/input.html +1 -0
- package/fixtures/language-empty-lang-stops-inheritance/meta.json +11 -0
- package/fixtures/language-figcaption/gnd.json +25 -0
- package/fixtures/language-figcaption/input.html +1 -0
- package/fixtures/language-figcaption/meta.json +11 -0
- package/fixtures/language-figcaption-credit/gnd.json +41 -0
- package/fixtures/language-figcaption-credit/input.html +1 -0
- package/fixtures/language-figcaption-credit/meta.json +12 -0
- package/fixtures/language-figcaption-switches/gnd.json +24 -0
- package/fixtures/language-figcaption-switches/input.html +1 -0
- package/fixtures/language-figcaption-switches/meta.json +11 -0
- package/fixtures/language-figcaption-switches-throughout/gnd.json +25 -0
- package/fixtures/language-figcaption-switches-throughout/input.html +1 -0
- package/fixtures/language-figcaption-switches-throughout/meta.json +11 -0
- package/fixtures/language-inline-case-insensitive/gnd.json +9 -0
- package/fixtures/language-inline-case-insensitive/input.html +1 -0
- package/fixtures/language-inline-case-insensitive/meta.json +10 -0
- package/fixtures/language-inline-case-insensitive-ssml/gnd.json +9 -0
- package/fixtures/language-inline-case-insensitive-ssml/input.html +1 -0
- package/fixtures/language-inline-case-insensitive-ssml/meta.json +10 -0
- package/fixtures/language-inline-empty-lang/gnd.json +9 -0
- package/fixtures/language-inline-empty-lang/input.html +1 -0
- package/fixtures/language-inline-empty-lang/meta.json +10 -0
- package/fixtures/language-inline-empty-lang-formatted/gnd.json +8 -0
- package/fixtures/language-inline-empty-lang-formatted/input.html +1 -0
- package/fixtures/language-inline-empty-lang-formatted/meta.json +10 -0
- package/fixtures/language-inline-empty-lang-only/gnd.json +8 -0
- package/fixtures/language-inline-empty-lang-only/input.html +1 -0
- package/fixtures/language-inline-empty-lang-only/meta.json +10 -0
- package/fixtures/language-inline-empty-lang-undeclared/gnd.json +9 -0
- package/fixtures/language-inline-empty-lang-undeclared/input.html +1 -0
- package/fixtures/language-inline-empty-lang-undeclared/meta.json +10 -0
- package/fixtures/language-labelledby-target/gnd.json +26 -0
- package/fixtures/language-labelledby-target/input.html +1 -0
- package/fixtures/language-labelledby-target/meta.json +11 -0
- package/fixtures/language-labelledby-target-aria-label/gnd.json +32 -0
- package/fixtures/language-labelledby-target-aria-label/input.html +1 -0
- package/fixtures/language-labelledby-target-aria-label/meta.json +11 -0
- package/fixtures/language-labelledby-target-switches/gnd.json +25 -0
- package/fixtures/language-labelledby-target-switches/input.html +1 -0
- package/fixtures/language-labelledby-target-switches/meta.json +11 -0
- package/fixtures/language-labelledby-targets-case/gnd.json +36 -0
- package/fixtures/language-labelledby-targets-case/input.html +1 -0
- package/fixtures/language-labelledby-targets-case/meta.json +11 -0
- package/fixtures/language-labelledby-targets-differ/gnd.json +35 -0
- package/fixtures/language-labelledby-targets-differ/input.html +1 -0
- package/fixtures/language-labelledby-targets-differ/meta.json +11 -0
- package/fixtures/language-link-switches/gnd.json +20 -0
- package/fixtures/language-link-switches/input.html +1 -0
- package/fixtures/language-link-switches/meta.json +11 -0
- package/fixtures/language-pagebreak-label/gnd.json +22 -0
- package/fixtures/language-pagebreak-label/input.html +1 -0
- package/fixtures/language-pagebreak-label/meta.json +11 -0
- package/fixtures/language-undeclared-description/gnd.json +23 -0
- package/fixtures/language-undeclared-description/input.html +1 -0
- package/fixtures/language-undeclared-description/meta.json +11 -0
- package/fixtures/language-xml-lang-empty-html-inherits/gnd.json +25 -0
- package/fixtures/language-xml-lang-empty-html-inherits/input.html +1 -0
- package/fixtures/language-xml-lang-empty-html-inherits/meta.json +11 -0
- package/fixtures/language-xml-lang-empty-html-lang-applies/gnd.json +25 -0
- package/fixtures/language-xml-lang-empty-html-lang-applies/input.html +1 -0
- package/fixtures/language-xml-lang-empty-html-lang-applies/meta.json +11 -0
- package/fixtures/language-xml-lang-empty-xhtml/gnd.json +24 -0
- package/fixtures/language-xml-lang-empty-xhtml/input.xhtml +2 -0
- package/fixtures/language-xml-lang-empty-xhtml/meta.json +11 -0
- package/fixtures/language-xml-lang-over-lang/gnd.json +25 -0
- package/fixtures/language-xml-lang-over-lang/input.html +1 -0
- package/fixtures/language-xml-lang-over-lang/meta.json +11 -0
- package/fixtures/link-containing-image/gnd.json +35 -0
- package/fixtures/link-containing-image/input.html +1 -0
- package/fixtures/link-containing-image/meta.json +12 -0
- package/fixtures/link-containing-pagebreak/gnd.json +33 -0
- package/fixtures/link-containing-pagebreak/input.html +1 -0
- package/fixtures/link-containing-pagebreak/meta.json +12 -0
- package/fixtures/link-content-conversion/gnd.json +31 -0
- package/fixtures/link-content-conversion/input.html +1 -0
- package/fixtures/link-content-conversion/meta.json +12 -0
- package/fixtures/link-content-identity/gnd.json +21 -0
- package/fixtures/link-content-identity/input.html +1 -0
- package/fixtures/link-content-identity/meta.json +10 -0
- package/fixtures/link-content-words/gnd.json +46 -0
- package/fixtures/link-content-words/input.html +1 -0
- package/fixtures/link-content-words/meta.json +10 -0
- package/fixtures/manifest.json +401 -1
- package/fixtures/math-inline/gnd.json +22 -0
- package/fixtures/math-inline/input.html +1 -0
- package/fixtures/math-inline/meta.json +11 -0
- package/fixtures/nested-blockquote/gnd.json +22 -0
- package/fixtures/nested-blockquote/input.html +5 -0
- package/fixtures/nested-blockquote/meta.json +11 -0
- package/fixtures/nested-section/gnd.json +22 -0
- package/fixtures/nested-section/input.html +5 -0
- package/fixtures/nested-section/meta.json +11 -0
- package/fixtures/redundant-role-body-chapter/gnd.json +23 -0
- package/fixtures/redundant-role-body-chapter/input.xhtml +10 -0
- package/fixtures/redundant-role-body-chapter/meta.json +13 -0
- package/fixtures/redundant-role-nested-chapter/gnd.json +30 -0
- package/fixtures/redundant-role-nested-chapter/input.xhtml +12 -0
- package/fixtures/redundant-role-nested-chapter/meta.json +13 -0
- package/fixtures/term-span-in-dt/gnd.json +24 -0
- package/fixtures/term-span-in-dt/input.html +4 -0
- package/fixtures/term-span-in-dt/meta.json +12 -0
- package/package.json +1 -1
- package/src/converter.ts +72 -15
- package/src/elementHandlers.ts +31 -11
- package/src/object.ts +7 -10
- package/src/roles.ts +49 -0
- package/types/src/converter.d.ts +21 -2
- package/types/src/object.d.ts +1 -0
- package/types/src/roles.d.ts +1 -0
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Generates [Guided Navigation](https://github.com/readium/guided-navigation) (GND) documents from HTML and XHTML, as [`@readium/shared`](https://www.npmjs.com/package/@readium/shared) `GuidedNavigationDocument`/`GuidedNavigationObject` instances.
|
|
4
4
|
|
|
5
|
+
> [!WARNING]
|
|
6
|
+
> Breaking changes can ship in minor versions. Patch versions never contain breaking changes. Use a tilde range (`~x.y.z`) rather than a caret range, and check the changelog before upgrading to a new minor version.
|
|
7
|
+
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
7
10
|
```sh
|
|
@@ -107,7 +110,7 @@ The lower-level pieces are exported too: `encodeCssSelectorFragment(selector)`/`
|
|
|
107
110
|
## Objects
|
|
108
111
|
|
|
109
112
|
- **`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, 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`.
|
|
113
|
+
- **`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`. `plain` alongside it is the text as written, link words included, with footnotes, pagebreaks and images left out. It doesn't say where embedded objects sit: use `ssml` for that.
|
|
111
114
|
- **`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
115
|
- **`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
116
|
- **`description`** holds a node's accessible name (`aria-label`, `alt`, `<figcaption>`...) as `description.text` when it differs from its visible text.
|
package/dist/converter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
+
import{hasExplicitRole as K,extractNodeRoles as F}from"./roles.js";import{skippedElements as y,extractNodeAria as G,normalizedNodeText as Q,normalizedNodeTextExcludingExplicitRoles as V,convertElementToSSMLTag as Z}from"./a11y.js";import{normalizeWhitespace as N,ctxEqual as _}from"./text.js";import{ssmlTextEscape as B,ssmlAttrEscape as I}from"@readium/helpers";import{NavObject as S,isEmptyObj as X,finalizeToGuidedNavigationObject as tt,setDescription as R}from"./object.js";import{sniffMediaType as et,isInlineTag as z,isAncestorOf as it}from"./dom.js";import{nodeLanguage as st,declaredLanguage as D,sameLanguage as j}from"./language.js";import{encodeDomRangeFragment as nt,encodeTextFragmentDirective as rt}from"./textrefFragment.js";import{resolveRefs as ot}from"./href.js";import{rootAnchorSelector as lt,textrefForSelector as $,selectorForElement as M}from"./selectorGenerator.js";import{generateDomRange as at}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as ct}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as ht}from"./options.js";import{IdAllocator as ft}from"./idAllocator.js";import{prescan as dt}from"./prescan.js";import{pagebreak as ut,noteref as pt,reference as gt,link as mt}from"./elementHandlers.js";import{removeDropped as xt,bindsToPrevious as bt,DROPPED as wt}from"./emptyPairs.js";const Et="http://www.w3.org/1998/Math/MathML",O=3,U=1,kt=4,Tt=new Set(["summary","dfn","span"]);function A(f,t){return Tt.has(f)&&t.length>0?!0:!z(f)}class u{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new ft,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.words=null,this.xmlParsed=t}spawnChild(t,e=1){const i=new u(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){dt(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=>$(M(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0||t.text?X(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>ot(e,this.baseHref)),t.map(tt)}descend(t,e){const i=new S;i.el=t,i.noText=this.foldedCaptions.has(t)||(!K(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===O){u.punctuationOwner(t)||this.text(t);return}if(t.nodeType!==U)return;const e=t,i=this.current,o=this.head(e);if(!o){const s=this.current!==i&&this.current.el===e?u.ownPunctuation(e):[],r=h=>(h.compareDocumentPosition(e)&kt)!==0;for(const h of s)r(h)&&this.text(h);for(let h=e.firstChild;h;h=h.nextSibling)this.walk(h);for(const h of s)r(h)||this.text(h)}this.tail(e,o,i)}head(t){const e=t.tagName.toLowerCase();if(y.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[i,o,s]=G(t);if(!o&&t!==this.allowNode)return!0;const r=F(t);if((e==="img"||e==="svg")&&(r.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.words?.push({kind:"break"}),this.flowEndsWithSpace=!0),!0;if(r.includes("pagebreak"))return!ut(this,t,i,s,r);if(e==="a"&&r.includes("noteref")&&t.getAttribute("href"))return pt(this,t,r),!0;if(e==="a"&&(r.includes("glossref")||r.includes("biblioref"))&&t.getAttribute("href"))return gt(this,t,r,i,s),!0;if(e==="a"&&t.getAttribute("href"))return mt(this,t,r,i,s),!0;if(e==="img"){const l={role:r},c=t.getAttribute("src");return c&&(l.imgref=c),i&&R(l,i,s),this.placeholder(t,"image",l),!0}if(e==="audio"||e==="video"){const l={role:r};let c=t.getAttribute("src");if(!c){const d=t.querySelector(":scope > source[src]");d&&(c=d.getAttribute("src"))}return e==="audio"?c&&(l.audioref=c):c&&(l.videoref=c),i&&R(l,i,s),this.placeholder(t,e,l),!0}if(r.includes("image")||r.includes("math")){const l={role:r};if(i&&R(l,i,s),r.includes("math")){if(t.namespaceURI===Et)l.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:st(t)};else{const{text:c,language:d}=Q(t);c&&(l.text={plain:c,ssml:"",language:d})}l.textref=$(M(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,r.includes("math")?"math":"image",l),!0}if(!A(e,r))return!1;this.flushText(),z(e)||this.words?.push({kind:"break"}),this.descend(t,r);const h=this.current.object;if(r.length>0&&(h.role=r),i)R(h,i,s),r.includes("figure")&&(this.current.noText=!0);else if(r.includes("figure")){const l=this.implicitCaptionOf(t);if(l){const{text:c,language:d}=V(l);c&&(R(h,c,d),this.current.noText=!0)}}else if(r.includes("table")){const l=this.implicitCaptionOf(t);if(l){const{text:c,language:d}=V(l);c&&(R(h,c,d),this.foldedCaptions.add(l))}}const b=t.getAttribute("id");return b&&(h.id=b),!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 o=t.tagName.toLowerCase(),s=F(t);if(!s.includes("pagebreak")&&A(o,s)){this.flushText(),z(o)||this.words?.push({kind:"break"}),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const r=this.leafTextEnabled&&s.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(s)||r)&&this.applyTextref(t),this.current=i}}applyTextref(t){const e=this.current.object,i=M(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=$(i,t),this.domRangeEnabled&&this.lastFlowRange){const o=i?{el:t,selector:i}:void 0,s=at(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,o);s&&(e.textref=nt({...s,container:i}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const o=this.docRoot.createRange();o.setStart(...this.lastFlowRange.first),o.setEnd(...this.lastFlowRange.last);const s=ct(o);s&&(e.textref=`${e.textref??"#"}${rt(s)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(this.words?.push({kind:"text",text:N(e,!1)}),/^\s*$/.test(e)){(this.textAcc.length>0||this.segments.length>0)&&(this.textAcc+=N(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const i=this.textContext(t);if(_(i,this.currentCtx)||(this.closeSegment(),this.currentCtx=i),this.textAcc+=N(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const o=t;this.flowFirstNode===null&&(this.flowFirstNode=o,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=o,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){const e=u.punctuationOwner(t);let i=e?u.abbreviationOver(e):null;if(!e){let s=t.parentElement;for(;s&&s!==this.current.el;s=s.parentElement)if(W(s)){if(u.containsObject(s))break;i=s}s&&s===this.current.el&&(i=u.abbreviationOver(s)??i)}if(i)return{lang:D(i),tag:"sub",attrs:{alias:W(i)},abbr:i};const o={lang:D(t.parentElement),tag:""};for(let s=t.parentElement;s&&s!==this.current.el;s=s.parentElement){const[r,h]=Z(s.tagName.toLowerCase());if(r&&r!=="break"){o.tag=r,o.attrs=h;break}}return o}static containsObject(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling){const i=e.tagName.toLowerCase(),o=F(e);if(!(y.has(i)||u.isPlaceholder(e,i,o))&&(A(i,o)||u.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 abbreviationOver(t){let e=null;for(let i=t;i&&(W(i)&&(e=i),!!u.isSoleContent(i));i=i.parentElement);return e}static punctuationOwner(t){const e=t.nodeValue??"";if(t.nodeType!==O||!/\S/.test(e)||!/^[\s\p{P}]*$/u.test(e))return null;let i=null;for(let o=t.parentElement?.firstElementChild??null;o&&u.isSoleContent(o);o=o.firstElementChild){const s=o.tagName.toLowerCase(),r=F(o);if(y.has(s)||u.isPlaceholder(o,s,r)||!G(o)[1])break;A(s,r)&&(i=o)}return i&&u.abbreviationOver(i)?.contains(t)?i:null}static ownPunctuation(t){const e=u.abbreviationOver(t),i=[],o=s=>{if(s!==t){s.nodeType===O&&u.punctuationOwner(s)===t&&i.push(s);for(let r=s.firstChild;r;r=r.nextSibling)o(r)}};return e&&o(e),i}static isSoleContent(t){for(let e=t.parentNode?.firstChild;e;e=e.nextSibling)if(e!==t&&(e.nodeType===U||e.nodeType===O&&!/^[\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,{candidateID:o,words:s}={}){if(X(i))return;const r=new S;if(r.el=t,r.object=i,this.current.noText){this.appendChild(r);return}this.closeSegment(),this.pendingChildren.push(r),this.segments.push({kind:"placeholder",tag:e,child:r,candidateID:o??t.getAttribute("id")??void 0,words:s?.length?s:void 0}),this.words?.push(...s?.length?s:[{kind:"placeholder"}]),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,i=this.flowFirstNode,o=this.flowFirstOffset,s=this.flowLastNode,r=this.flowLastOffset;if(this.resetFlow(),this.lastFlowRange=null,this.lastFlowText=null,t.length===0)return;for(;t.length>0;){const n=t[0];if(n.kind==="break"){t=t.slice(1);continue}if(n.kind==="text"){const a=n.text.replace(/^\s+/,"");if(a===""){t=t.slice(1);continue}t=[{...n,text:a},...t.slice(1)]}break}for(;t.length>0;){const n=t[t.length-1];if(n.kind==="break"){t=t.slice(0,-1);continue}if(n.kind==="text"){const a=n.text.replace(/\s+$/,"");if(a===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...n,text:a}]}break}const h=[];for(let n=0;n<t.length;n++){const a=t[n],p=a.kind==="text"?a.ctx.abbr:void 0;if(!p){h.push(a);continue}let m=a.text;const k=[];let w=[];for(let x=n+1;x<t.length;x++){const T=t[x];if(T.kind==="placeholder"&&it(p,T.child.el)){w.push(T);continue}if(T.kind!=="text"||T.ctx.abbr!==p)break;m+=T.text,k.push(...w),w=[],n=x}h.push({...a,text:m},...k)}if(t=h,!t.some(n=>n.kind==="text"&&n.text.trim()!=="")){for(const n of e)this.appendChild(n);return}const l=[];for(const n of t)if(n.kind==="text"&&n.text.trim()!==""){const a=n.ctx.lang;l.some(p=>j(p,a))||l.push(a)}let c=D(this.current.el??this.allowNode);l.length===1&&(c=l[0]);let d=!1;for(const n of t)if(n.kind!=="text"||n.ctx.tag!==""||!j(n.ctx.lang,c)){d=!0;break}d&&c===void 0&&(c="en");const g=n=>n!==void 0&&!j(n,c);if(d)for(const n of t){if(n.kind!=="placeholder")continue;let a=this.copy?void 0:n.candidateID;(!a||!this.idAlloc.claim(a))&&(a=this.idAlloc.allocate(n.tag,p=>this.ids.has(p))),n.child.object.id=a}let E="",H=!1,L=!1,v=!1,C=!1;for(const n of t.flatMap(a=>a.words??[a]))if(n.kind==="text"){const a=n.text.startsWith(" "),p=n.text.replace(/^ +| +$/g,"");if(p===""){C=!0;continue}let m=!1;if(E.length>0){const k=H||C||a;L?m=!0:v?m=k&&!bt(p,c):m=k}m&&(E+=" "),E+=p,H=n.text.endsWith(" "),L=!1,v=!1,C=!1}else n.kind==="break"?L=!0:n.kind==="placeholder"&&(E+=wt,v=!0);E=xt(E,c);const J=t.some(n=>n.kind==="placeholder");this.lastFlowText=E.trim();const q={plain:d&&!J?"":E.trim(),ssml:"",language:c??""};if(d){let n="";for(const a of t)if(a.kind==="text"){const{tag:p,attrs:m,lang:k}=a.ctx,w=p==="sub"?/^( *)([^]*?)( *)$/.exec(a.text):null,x=w?w[2]:a.text;if(w&&x===""){n+=a.text;continue}if(n+=w?.[1]??"",g(k)){const T=p==="sub"?Y(p,m,x):B(x);n+=`<lang xml:lang="${I(k)}">${T}</lang>`}else n+=p?Y(p,m,x):B(x);n+=w?.[3]??""}else a.kind==="break"?n+="<break/>":a.kind==="placeholder"&&(n+=`<readium:${a.tag} id="${I(a.child.object.id)}" />`);q.ssml=n}const P=new S;P.object={text:q};for(const n of e)P.children.push(n);this.appendChild(P),i&&s&&(this.lastFlowRange={first:[i,o],last:[s,r]})}}function W(f){return F(f).includes("abbreviation")?N(f.getAttribute("title")??"",!0).trim():""}function Y(f,t,e){const i=Object.entries(t??{}).map(([o,s])=>` ${o}="${I(s)}"`).join("");return`<${f}${i}>${B(e)}</${f}>`}const Rt=/<body[\s>]/i;function zt(f,t,e){const{predicate:i,leafText:o,domRange:s,textFragment:r}=ht(e?.textrefs);if(typeof f!="string"){const d=t??(f.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),g=new u(d==="application/xhtml+xml");return g.selectorPredicate=i,g.leafTextEnabled=o,g.domRangeEnabled=s,g.textFragmentEnabled=r,g.docRoot=f.ownerDocument,g.baseHref=e?.href,g.selectorRoot=f,g.selectorRootAnchor=lt(f),g.convert(f),g.result()}let h=t??et(f),b=new DOMParser().parseFromString(f,h);if(h==="application/xhtml+xml"){const d=b.getElementsByTagNameNS("*","parsererror")[0];if(d){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${d.textContent?.trim()??""}`);h="text/html",b=new DOMParser().parseFromString(f,h)}}const l=new u(h==="application/xhtml+xml");l.selectorPredicate=i,l.leafTextEnabled=o,l.textFragmentEnabled=r,l.docRoot=b,l.baseHref=e?.href;const c=b.querySelector("body");return c&&!Rt.test(f)?l.convertChildren(c):l.convert(c??b.documentElement),l.result()}export{u as Converter,zt as parseMarkup};
|
package/dist/elementHandlers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ssmlAttrEscape as
|
|
1
|
+
import{ssmlAttrEscape as A}from"@readium/helpers";import{normalizedNodeText as u}from"./a11y.js";import{normalizeWhitespace as k,textIsEmpty as E}from"./text.js";import{ariaSubstitutedBuilders as m,substitutedOwnSelectorBuilders as S,isHoistable as I}from"./object.js";import{hasElementChild as j,isAncestorOf as g}from"./dom.js";import{nodeLanguage as B}from"./language.js";import{selectorForElement as p,textrefForSelector as D}from"./selectorGenerator.js";import{decodeIdFragment as x,detachSelfTextref as L}from"./textrefFragment.js";function M(t,e,i,s,c){const n={role:c},d=k(e.getAttribute("title")??"",!0).trim();d?n.text={plain:d,ssml:"",language:B(e)}:i&&(n.text={plain:i,ssml:"",language:s},m.add(n));const l=!!(n.text&&!E(n.text)),r=!t.xmlParsed&&(j(e)||l&&e.firstChild!==null);if(!l&&!r){const{text:f,language:h}=u(e);f&&(n.text={plain:f,ssml:"",language:h})}const o=p(e,t.selectorRoot,t.selectorRootAnchor),a=D(o,e);return a&&(n.textref=a),t.placeholder(e,"pagebreak",n),r}function P(t,e,i){const s={role:i},{text:c,language:n}=u(e);c&&(s.text={plain:c,ssml:"",language:n});const d=e.getAttribute("href")??"",l=d.startsWith("#")?x(d)??d.slice(1):void 0;let r=e.getAttribute("id")??"";if(!r&&l!==void 0){const o=t.ids.get(l);(!o||t.suppressed.has(o))&&(r=l)}if(l!==void 0){const o=t.ids.get(l);if(o&&!g(o,e)&&t.noterefDepth<3){const a=t.spawnChild(o);a.convert(o);const f=a.resultBuilders();if(f.length>0){for(const h of f)w(h);s.children=f}}}!s.children&&d&&(s.children=[{textref:d}]),t.placeholder(e,"noteref",s,{candidateID:r||void 0})}function $(t,e,i,s,c){const{obj:n,words:d}=b(t,e,i,s,c);t.placeholder(e,i[0]??"link",n,{words:i.includes("backlink")?void 0:d})}function q(t,e,i,s,c){const{obj:n,words:d}=b(t,e,i,s,c),l=e.getAttribute("href")??"";if(l.startsWith("#")){const r=t.ids.get(x(l)??l.slice(1));if(r&&!g(r,e)&&t.noterefDepth<3){const o=N(r).flatMap(a=>{const f=t.spawnChild(a);return f.copy=!0,f.convert(a),f.resultBuilders()});C(o),o.length>0&&(n.children=[...n.children??[],...o])}}t.placeholder(e,i[0],n,{words:d})}function b(t,e,i,s,c){const n={};i.length>0&&(n.role=i);const d=s?[{kind:"text",text:s}]:[];if(s){n.text={plain:s,ssml:"",language:c},m.add(n);const r=p(e,t.selectorRoot,t.selectorRootAnchor);r&&S.set(n,r)}else{const r=t.spawnChild(e,0);r.words=d,r.convertChildren(e);const o=r.resultBuilders();o.length===1&&o[0].text&&I(o[0])?(n.text=o[0].text,o[0].children&&(n.children=o[0].children)):o.length>0&&(n.children=o)}const l=e.getAttribute("href");return l&&(n.textref=l),{obj:n,words:d}}function w(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="${A(i.id)}"`))&&w(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 s=[];for(;i&&i.tagName.toLowerCase()==="dd";i=i.nextElementSibling)s.push(i);return s.length>0?[e,...s]:[t]}export{$ as link,P as noteref,M as pagebreak,q as reference};
|
package/dist/object.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GuidedNavigationObject as
|
|
1
|
+
import{GuidedNavigationObject as h,GuidedNavigationDescription as u,GuidedNavigationText as g}from"@readium/shared";import{nonSelfNestingRoles as p}from"./roles.js";import{textIsEmpty as s,finalizeText as x}from"./text.js";import{detachSelfTextref as m}from"./textrefFragment.js";function R(e,n,t){e.description=n,e.descriptionLanguage=t}const v=["math","separator"],b=new WeakSet,o=new WeakSet,w=new WeakMap,a=new WeakMap;function W(e){return o.has(e)}function y(e){return a.get(e)}function f(e){return e.role?.some(n=>v.includes(n))?!1:!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||s(e.text))&&!(e.children&&e.children.length>0)&&!e.description}function S(e){return!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||s(e.text))&&!!(e.children&&e.children.length>0)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description}function N(e){return!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class B{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(!f(r)){if(S(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],r=t.role;i.role=i.role?.filter(c=>!(p.has(c)&&r.includes(c))),i.role?.length||delete i.role}if((!t.text||s(t.text))&&t.children?.length===1){const i=t.children[0];N(i)&&(i.text&&(t.text=i.text),t.children=i.children)}if(this.el&&n&&!f(t)&&!O(t)){const i=n(this.el);i&&(t.textref=i)}const l=this.el?.getAttribute("id");return l&&t.id!==l&&m(t,l),t}}function O(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 j(e){const n=new h({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:x(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(j):void 0,description:e.description?new u({text:new g({plain:e.description,language:e.descriptionLanguage||void 0})}):void 0});b.has(e)&&o.add(n);const t=w.get(e);return t&&a.set(n,t),n}export{B as NavObject,b as ariaSubstitutedBuilders,j as finalizeToGuidedNavigationObject,W as isAriaSubstituted,f as isEmptyObj,N as isHoistable,R as setDescription,y as substitutedOwnSelector,w as substitutedOwnSelectorBuilders};
|
package/dist/roles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const p=["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"},x=new Set(["abbreviation","abstract","acknowledgments","afterword","bibliography","body","caption","cell","chapter","colophon","columnheader","conclusion","cover","credit","credits","dedication","definition","endnotes","epigraph","epilogue","errata","footnote","foreword","glossary",...p,"index","introduction","landmarks","listItem","loa","loi","lot","lov","main","pagelist","paragraph","preface","prologue","pullquote","row","rowheader","subtitle","summary","term","toc"]),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 u(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(p[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 E(e){const{attrRoles:o,presentational:t}=u(e);return o.length>0||t}function R(e){const o=[],t=r=>{o.includes(r)||o.push(r)},{attrRoles:a,presentational:n}=u(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{R as extractNodeRoles,E as hasExplicitRole,x as nonSelfNestingRoles};
|
|
@@ -19,9 +19,9 @@ renaming, or removing a fixture.
|
|
|
19
19
|
| `backlink` | `backlink-epub-type`, `backlink-role-aria` |
|
|
20
20
|
| `bibliography` | `bibliography-epub-type`, `bibliography-role-aria` |
|
|
21
21
|
| `biblioref` | `biblioref-epub-type`, `biblioref-role-aria`, `biblioref-target-descendant-ids`, `biblioref-target-in-bibliography-role-aria`, `biblioref-target-mixed-content` |
|
|
22
|
-
| `blockquote` | `blockquote-html-native`, `blockquote-role-aria` |
|
|
22
|
+
| `blockquote` | `blockquote-html-native`, `blockquote-role-aria`, `nested-blockquote` |
|
|
23
23
|
| `body` | `body-html-native` |
|
|
24
|
-
| `chapter` | `chapter-epub-type`, `chapter-role-aria` |
|
|
24
|
+
| `chapter` | `chapter-epub-type`, `chapter-role-aria`, `redundant-role-body-chapter`, `redundant-role-nested-chapter` |
|
|
25
25
|
| `colophon` | `colophon-epub-type`, `colophon-role-aria` |
|
|
26
26
|
| `complementary` | `complementary-role-aria` |
|
|
27
27
|
| `conclusion` | `conclusion-epub-type`, `conclusion-role-aria` |
|
|
@@ -30,35 +30,37 @@ renaming, or removing a fixture.
|
|
|
30
30
|
| `credits` | `credits-epub-type`, `credits-role-aria` |
|
|
31
31
|
| `dedication` | `dedication-epub-type`, `dedication-role-aria` |
|
|
32
32
|
| `definition` | `definition-epub-type`, `definition-html-native`, `definition-role-aria` |
|
|
33
|
+
| `description` | `description-roleless-lone-child`, `description-roleless-wrapper` |
|
|
33
34
|
| `details` | `details-html-native`, `details-summary-html-native` |
|
|
34
35
|
| `endnotes` | `endnotes-epub-type`, `endnotes-role-aria` |
|
|
35
36
|
| `epigraph` | `epigraph-epub-type`, `epigraph-role-aria` |
|
|
36
37
|
| `epilogue` | `epilogue-epub-type`, `epilogue-role-aria` |
|
|
37
38
|
| `errata` | `errata-epub-type`, `errata-role-aria` |
|
|
38
39
|
| `example` | `example-epub-type`, `example-role-aria` |
|
|
39
|
-
| `figure` | `figure-basic-html-native`, `figure-basic-role-aria`, `figure-caption-element-html-native`, `figure-caption-element-role-aria`, `figure-caption-html-native`, `figure-caption-role-aria`, `figure-credit-nested-in-aria-labelledby-caption`, `figure-credit-nested-in-caption`, `figure-credit-role-aria`, `figure-describedby`, `figure-epub-type`, `figure-no-description` |
|
|
40
|
+
| `figure` | `figure-basic-html-native`, `figure-basic-role-aria`, `figure-caption-element-html-native`, `figure-caption-element-role-aria`, `figure-caption-html-native`, `figure-caption-role-aria`, `figure-credit-nested-in-aria-labelledby-caption`, `figure-credit-nested-in-caption`, `figure-credit-role-aria`, `figure-describedby`, `figure-epub-type`, `figure-no-description`, `language-describedby-shared`, `language-figcaption`, `language-figcaption-credit`, `language-figcaption-switches`, `language-figcaption-switches-throughout` |
|
|
40
41
|
| `footnote` | `footnote-epub-type`, `footnote-role-aria`, `noteref-target-in-endnotes-epub-type`, `noteref-target-in-endnotes-role-aria` |
|
|
41
42
|
| `foreword` | `foreword-epub-type`, `foreword-role-aria` |
|
|
42
43
|
| `glossary` | `glossary-epub-type`, `glossary-role-aria` |
|
|
43
44
|
| `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` |
|
|
44
45
|
| `header` | `header-html-native` |
|
|
45
46
|
| `heading` | `heading-html-native`, `heading-role-aria` |
|
|
46
|
-
| `image` | `image-alt-html-native`, `image-no-description`, `image-role-aria` |
|
|
47
|
+
| `image` | `image-alt-html-native`, `image-no-description`, `image-role-aria`, `language-alt-inherited`, `language-alt-own-lang`, `language-labelledby-target`, `language-labelledby-target-aria-label`, `language-labelledby-target-switches`, `language-labelledby-targets-case`, `language-labelledby-targets-differ`, `language-undeclared-description` |
|
|
47
48
|
| `index` | `index-epub-type`, `index-role-aria` |
|
|
48
49
|
| `introduction` | `introduction-epub-type`, `introduction-role-aria` |
|
|
49
50
|
| `landmarks` | `landmarks-epub-type` |
|
|
50
|
-
| `language` | `language-block`, `language-document`, `language-inline-lang-attribute`, `language-inline-nested`, `language-inline-repeated`, `language-inline-two-languages` |
|
|
51
|
+
| `language` | `language-block`, `language-block-empty-lang`, `language-document`, `language-empty-lang-stops-inheritance`, `language-inline-case-insensitive`, `language-inline-case-insensitive-ssml`, `language-inline-empty-lang`, `language-inline-empty-lang-formatted`, `language-inline-empty-lang-only`, `language-inline-empty-lang-undeclared`, `language-inline-lang-attribute`, `language-inline-nested`, `language-inline-repeated`, `language-inline-two-languages`, `language-xml-lang-empty-html-inherits`, `language-xml-lang-empty-html-lang-applies`, `language-xml-lang-empty-xhtml`, `language-xml-lang-over-lang` |
|
|
52
|
+
| `link` | `language-link-switches`, `link-containing-image`, `link-containing-pagebreak`, `link-content-conversion`, `link-content-identity`, `link-content-words` |
|
|
51
53
|
| `list` | `list-aria-posinset-setsize`, `list-epub-type`, `list-html-native`, `list-item-posinset-override`, `list-item-value-override`, `list-ordered-html-native`, `list-ordered-reversed`, `list-ordered-start`, `list-role-aria` |
|
|
52
54
|
| `loa` | `loa-epub-type` |
|
|
53
55
|
| `loi` | `loi-epub-type` |
|
|
54
56
|
| `lot` | `lot-epub-type` |
|
|
55
57
|
| `lov` | `lov-epub-type` |
|
|
56
58
|
| `main` | `main-html-native`, `main-role-aria` |
|
|
57
|
-
| `math` | `math-html-native`, `math-no-description`, `math-role-aria` |
|
|
59
|
+
| `math` | `math-html-native`, `math-inline`, `math-no-description`, `math-role-aria` |
|
|
58
60
|
| `navigation` | `navigation-html-native`, `navigation-role-aria` |
|
|
59
61
|
| `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` |
|
|
60
62
|
| `notice` | `notice-epub-type`, `notice-role-aria` |
|
|
61
|
-
| `pagebreak` | `pagebreak-epub-type`, `pagebreak-role-aria` |
|
|
63
|
+
| `pagebreak` | `language-pagebreak-label`, `pagebreak-epub-type`, `pagebreak-role-aria` |
|
|
62
64
|
| `pagelist` | `pagelist-epub-type`, `pagelist-role-aria` |
|
|
63
65
|
| `paragraph` | `paragraph-basic` |
|
|
64
66
|
| `part` | `part-epub-type`, `part-role-aria` |
|
|
@@ -69,14 +71,14 @@ renaming, or removing a fixture.
|
|
|
69
71
|
| `pullquote` | `pullquote-epub-type`, `pullquote-role-aria` |
|
|
70
72
|
| `qna` | `qna-epub-type`, `qna-role-aria` |
|
|
71
73
|
| `region` | `region-role-aria` |
|
|
72
|
-
| `section` | `section-html-native` |
|
|
74
|
+
| `section` | `nested-section`, `section-html-native` |
|
|
73
75
|
| `separator` | `separator-html-native`, `separator-role-aria`, `separator-with-glyphs` |
|
|
74
76
|
| `subtitle` | `subtitle-epub-type`, `subtitle-role-aria` |
|
|
75
77
|
| `summary` | `summary-html-native` |
|
|
76
78
|
| `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` |
|
|
77
|
-
| `term` | `term-epub-type`, `term-html-native`, `term-role-aria` |
|
|
79
|
+
| `term` | `term-epub-type`, `term-html-native`, `term-role-aria`, `term-span-in-dt` |
|
|
78
80
|
| `tip` | `tip-epub-type`, `tip-role-aria` |
|
|
79
81
|
| `toc` | `toc-epub-type`, `toc-role-aria` |
|
|
80
82
|
| `video` | `video-html-native`, `video-no-description` |
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
256 fixtures across 73 roles.
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
5
2
|
"children": [
|
|
6
3
|
{
|
|
7
4
|
"text": {
|
|
8
|
-
"plain": "
|
|
5
|
+
"plain": "Ask"
|
|
9
6
|
}
|
|
10
7
|
},
|
|
11
8
|
{
|
|
@@ -13,14 +10,17 @@
|
|
|
13
10
|
"term"
|
|
14
11
|
],
|
|
15
12
|
"text": {
|
|
16
|
-
"ssml": "<sub alias=\"
|
|
13
|
+
"ssml": "<sub alias=\"Doctor\">Dr.</sub>",
|
|
17
14
|
"language": "en"
|
|
18
15
|
}
|
|
19
16
|
},
|
|
20
17
|
{
|
|
21
18
|
"text": {
|
|
22
|
-
"plain": ".
|
|
19
|
+
"plain": "Watson."
|
|
23
20
|
}
|
|
24
21
|
}
|
|
22
|
+
],
|
|
23
|
+
"role": [
|
|
24
|
+
"paragraph"
|
|
25
25
|
]
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<p>
|
|
1
|
+
<p>Ask <abbr title="Doctor"><dfn>Dr</dfn>.</abbr> Watson.</p>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "abbreviation-nested-term-punctuation",
|
|
3
|
-
"description": "An abbr wrapping a term and
|
|
3
|
+
"description": "An abbr wrapping a term and its period expands them together: the period is part of the term's expansion",
|
|
4
4
|
"role": "abbreviation",
|
|
5
5
|
"rolesCovered": [
|
|
6
6
|
"abbreviation",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"paragraph"
|
|
22
22
|
],
|
|
23
23
|
"text": {
|
|
24
|
-
"plain": "Entry.",
|
|
24
|
+
"plain": "Entry book.",
|
|
25
25
|
"ssml": "Entry <readium:link id=\"link1\" />.",
|
|
26
26
|
"language": "en"
|
|
27
27
|
}
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"paragraph"
|
|
46
46
|
],
|
|
47
47
|
"text": {
|
|
48
|
-
"plain": "See.",
|
|
48
|
+
"plain": "See 1.",
|
|
49
49
|
"ssml": "See <readium:biblioref id=\"biblioref1\" />.",
|
|
50
50
|
"language": "en"
|
|
51
51
|
}
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"paragraph"
|
|
71
71
|
],
|
|
72
72
|
"text": {
|
|
73
|
-
"plain": "Entry.",
|
|
73
|
+
"plain": "Entry book.",
|
|
74
74
|
"ssml": "Entry <readium:link id=\"lnk\" />.",
|
|
75
75
|
"language": "en"
|
|
76
76
|
}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"paragraph"
|
|
28
28
|
],
|
|
29
29
|
"text": {
|
|
30
|
-
"plain": "Lighthouses were first electrified in the 1870s along the coast.",
|
|
30
|
+
"plain": "Lighthouses were first electrified in the 1870s (Smith, 1988) along the coast.",
|
|
31
31
|
"ssml": "Lighthouses were first electrified in the 1870s (<readium:biblioref id=\"biblioref1\" />) along the coast.",
|
|
32
32
|
"language": "en"
|
|
33
33
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"text": {
|
|
19
|
-
"plain": "Author. Year",
|
|
19
|
+
"plain": "Author Title. Year",
|
|
20
20
|
"ssml": "Author <readium:link id=\"link1\" />. Year",
|
|
21
21
|
"language": "en"
|
|
22
22
|
}
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"paragraph"
|
|
36
36
|
],
|
|
37
37
|
"text": {
|
|
38
|
-
"plain": "See.",
|
|
38
|
+
"plain": "See 1.",
|
|
39
39
|
"ssml": "See <readium:biblioref id=\"biblioref1\" />.",
|
|
40
40
|
"language": "en"
|
|
41
41
|
}
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"paragraph"
|
|
55
55
|
],
|
|
56
56
|
"text": {
|
|
57
|
-
"plain": "Author. Year",
|
|
57
|
+
"plain": "Author Title. Year",
|
|
58
58
|
"ssml": "Author <readium:link id=\"link2\" />. Year",
|
|
59
59
|
"language": "en"
|
|
60
60
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<ul><li><div aria-label="Sidebar">One.</div></li></ul>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "description-roleless-lone-child",
|
|
3
|
+
"description": "A lone roleless child with a description is not hoisted into its parent",
|
|
4
|
+
"role": "description",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"list",
|
|
7
|
+
"listItem"
|
|
8
|
+
],
|
|
9
|
+
"sourceRef": "https://github.com/readium/guided-navigation/tree/main/examples/read-aloud",
|
|
10
|
+
"inputKind": "fragment"
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"children": [
|
|
3
|
+
{
|
|
4
|
+
"role": [
|
|
5
|
+
"paragraph"
|
|
6
|
+
],
|
|
7
|
+
"text": {
|
|
8
|
+
"plain": "One."
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"role": [
|
|
13
|
+
"paragraph"
|
|
14
|
+
],
|
|
15
|
+
"text": {
|
|
16
|
+
"plain": "Two."
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"description": {
|
|
21
|
+
"text": {
|
|
22
|
+
"plain": "Sidebar"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div aria-label="Sidebar"><p>One.</p><p>Two.</p></div>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "description-roleless-wrapper",
|
|
3
|
+
"description": "A roleless wrapper with a description is kept as an object, not spliced into its parent",
|
|
4
|
+
"role": "description",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"paragraph"
|
|
7
|
+
],
|
|
8
|
+
"sourceRef": "https://github.com/readium/guided-navigation/tree/main/examples/read-aloud",
|
|
9
|
+
"inputKind": "fragment"
|
|
10
|
+
}
|
|
@@ -1,49 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"glossary"
|
|
4
|
-
],
|
|
5
2
|
"children": [
|
|
6
3
|
{
|
|
7
4
|
"id": "fresnel-lens",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"term"
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
]
|
|
5
|
+
"role": [
|
|
6
|
+
"term"
|
|
7
|
+
],
|
|
8
|
+
"text": {
|
|
9
|
+
"plain": "Fresnel lens"
|
|
10
|
+
}
|
|
18
11
|
},
|
|
19
12
|
{
|
|
20
|
-
"text": {
|
|
21
|
-
"plain": "A compact lens for focusing light."
|
|
22
|
-
},
|
|
23
13
|
"role": [
|
|
24
14
|
"definition"
|
|
25
|
-
]
|
|
15
|
+
],
|
|
16
|
+
"text": {
|
|
17
|
+
"plain": "A compact lens for focusing light."
|
|
18
|
+
}
|
|
26
19
|
},
|
|
27
20
|
{
|
|
28
21
|
"id": "keeper",
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"term"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
22
|
+
"role": [
|
|
23
|
+
"term"
|
|
24
|
+
],
|
|
25
|
+
"text": {
|
|
26
|
+
"plain": "Keeper"
|
|
27
|
+
}
|
|
39
28
|
},
|
|
40
29
|
{
|
|
41
|
-
"text": {
|
|
42
|
-
"plain": "A person responsible for maintaining a lighthouse."
|
|
43
|
-
},
|
|
44
30
|
"role": [
|
|
45
31
|
"definition"
|
|
46
|
-
]
|
|
32
|
+
],
|
|
33
|
+
"text": {
|
|
34
|
+
"plain": "A person responsible for maintaining a lighthouse."
|
|
35
|
+
}
|
|
47
36
|
}
|
|
37
|
+
],
|
|
38
|
+
"role": [
|
|
39
|
+
"glossary"
|
|
48
40
|
]
|
|
49
41
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"text": {
|
|
3
3
|
"language": "en",
|
|
4
|
-
"plain": "A text-to-speech system is composed of two parts: a and a.",
|
|
4
|
+
"plain": "A text-to-speech system is composed of two parts: a front-end and a back-end.",
|
|
5
5
|
"ssml": "A text-to-speech system is composed of two parts: a <readium:glossref id=\"glossref1\" /> and a <readium:glossref id=\"glossref2\" />."
|
|
6
6
|
},
|
|
7
7
|
"role": [
|
|
@@ -5,16 +5,12 @@
|
|
|
5
5
|
{
|
|
6
6
|
"children": [
|
|
7
7
|
{
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"plain": "Fresnel lens"
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
]
|
|
8
|
+
"role": [
|
|
9
|
+
"term"
|
|
10
|
+
],
|
|
11
|
+
"text": {
|
|
12
|
+
"plain": "Fresnel lens"
|
|
13
|
+
}
|
|
18
14
|
},
|
|
19
15
|
{
|
|
20
16
|
"role": [
|
|
@@ -42,16 +38,12 @@
|
|
|
42
38
|
"children": [
|
|
43
39
|
{
|
|
44
40
|
"id": "fresnel-lens",
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"plain": "Fresnel lens"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
]
|
|
41
|
+
"role": [
|
|
42
|
+
"term"
|
|
43
|
+
],
|
|
44
|
+
"text": {
|
|
45
|
+
"plain": "Fresnel lens"
|
|
46
|
+
}
|
|
55
47
|
},
|
|
56
48
|
{
|
|
57
49
|
"role": [
|