@readium/guided-navigation 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/a11y.js +1 -1
- package/dist/converter.js +1 -1
- package/dist/dom.js +1 -1
- package/dist/elementHandlers.js +1 -1
- package/dist/emptyPairs.js +1 -0
- package/dist/language.js +1 -0
- package/dist/object.js +1 -1
- package/dist/prescan.js +1 -1
- package/dist/roles.js +1 -1
- package/dist/text.js +1 -1
- package/dist/textrefFragment.js +1 -1
- package/fixtures/ROLES_COVERAGE.md +5 -4
- package/fixtures/abbreviation-acronym-html-native/gnd.json +9 -0
- package/fixtures/abbreviation-acronym-html-native/input.html +1 -0
- package/fixtures/abbreviation-acronym-html-native/meta.json +11 -0
- package/fixtures/abbreviation-before-formatting/gnd.json +9 -0
- package/fixtures/abbreviation-before-formatting/input.html +1 -0
- package/fixtures/abbreviation-before-formatting/meta.json +11 -0
- package/fixtures/abbreviation-before-image/gnd.json +24 -0
- package/fixtures/abbreviation-before-image/input.html +1 -0
- package/fixtures/abbreviation-before-image/meta.json +12 -0
- package/fixtures/abbreviation-html-native/gnd.json +9 -0
- package/fixtures/abbreviation-html-native/input.html +1 -0
- package/fixtures/abbreviation-html-native/meta.json +11 -0
- package/fixtures/abbreviation-language/gnd.json +9 -0
- package/fixtures/abbreviation-language/input.html +1 -0
- package/fixtures/abbreviation-language/meta.json +11 -0
- package/fixtures/abbreviation-line-break/gnd.json +9 -0
- package/fixtures/abbreviation-line-break/input.html +1 -0
- package/fixtures/abbreviation-line-break/meta.json +11 -0
- package/fixtures/abbreviation-nested/gnd.json +9 -0
- package/fixtures/abbreviation-nested/input.html +1 -0
- package/fixtures/abbreviation-nested/meta.json +11 -0
- package/fixtures/abbreviation-nested-emphasis/gnd.json +9 -0
- package/fixtures/abbreviation-nested-emphasis/input.html +1 -0
- package/fixtures/abbreviation-nested-emphasis/meta.json +11 -0
- package/fixtures/abbreviation-nested-term/gnd.json +21 -0
- package/fixtures/abbreviation-nested-term/input.html +1 -0
- package/fixtures/abbreviation-nested-term/meta.json +12 -0
- package/fixtures/abbreviation-nested-term-punctuation/gnd.json +26 -0
- package/fixtures/abbreviation-nested-term-punctuation/input.html +1 -0
- package/fixtures/abbreviation-nested-term-punctuation/meta.json +12 -0
- package/fixtures/abbreviation-no-title/gnd.json +8 -0
- package/fixtures/abbreviation-no-title/input.html +1 -0
- package/fixtures/abbreviation-no-title/meta.json +11 -0
- package/fixtures/abbreviation-spanning-terms/gnd.json +33 -0
- package/fixtures/abbreviation-spanning-terms/input.html +1 -0
- package/fixtures/abbreviation-spanning-terms/meta.json +12 -0
- package/fixtures/abbreviation-with-image/gnd.json +24 -0
- package/fixtures/abbreviation-with-image/input.html +1 -0
- package/fixtures/abbreviation-with-image/meta.json +12 -0
- package/fixtures/abbreviation-with-svg-and-math/gnd.json +39 -0
- package/fixtures/abbreviation-with-svg-and-math/input.html +1 -0
- package/fixtures/abbreviation-with-svg-and-math/meta.json +13 -0
- package/fixtures/biblioref-target-descendant-ids/gnd.json +90 -0
- package/fixtures/biblioref-target-descendant-ids/input.html +1 -0
- package/fixtures/biblioref-target-descendant-ids/meta.json +14 -0
- package/fixtures/biblioref-target-in-bibliography-role-aria/gnd.json +59 -0
- package/fixtures/biblioref-target-in-bibliography-role-aria/input.html +6 -0
- package/fixtures/biblioref-target-in-bibliography-role-aria/meta.json +14 -0
- package/fixtures/biblioref-target-mixed-content/gnd.json +63 -0
- package/fixtures/biblioref-target-mixed-content/input.html +1 -0
- package/fixtures/biblioref-target-mixed-content/meta.json +11 -0
- package/fixtures/glossref-target-in-glossary-role-aria/gnd.json +76 -0
- package/fixtures/glossref-target-in-glossary-role-aria/input.html +5 -0
- package/fixtures/glossref-target-in-glossary-role-aria/meta.json +14 -0
- package/fixtures/glossref-target-percent-encoded/gnd.json +68 -0
- package/fixtures/glossref-target-percent-encoded/input.html +1 -0
- package/fixtures/glossref-target-percent-encoded/meta.json +14 -0
- package/fixtures/manifest.json +330 -0
- package/fixtures/noteref-after-closing-straight-quote/gnd.json +32 -0
- package/fixtures/noteref-after-closing-straight-quote/input.html +1 -0
- package/fixtures/noteref-after-closing-straight-quote/meta.json +13 -0
- package/fixtures/noteref-after-closing-straight-quote-split/gnd.json +38 -0
- package/fixtures/noteref-after-closing-straight-quote-split/input.html +1 -0
- package/fixtures/noteref-after-closing-straight-quote-split/meta.json +12 -0
- package/fixtures/noteref-enclosed-across-formatting/gnd.json +32 -0
- package/fixtures/noteref-enclosed-across-formatting/input.html +1 -0
- package/fixtures/noteref-enclosed-across-formatting/meta.json +13 -0
- package/fixtures/noteref-enclosed-adjacent-pairs/gnd.json +108 -0
- package/fixtures/noteref-enclosed-adjacent-pairs/input.html +1 -0
- package/fixtures/noteref-enclosed-adjacent-pairs/meta.json +13 -0
- package/fixtures/noteref-enclosed-adjacent-text/gnd.json +34 -0
- package/fixtures/noteref-enclosed-adjacent-text/input.html +1 -0
- package/fixtures/noteref-enclosed-adjacent-text/meta.json +13 -0
- package/fixtures/noteref-enclosed-before-formatting/gnd.json +34 -0
- package/fixtures/noteref-enclosed-before-formatting/input.html +1 -0
- package/fixtures/noteref-enclosed-before-formatting/meta.json +13 -0
- package/fixtures/noteref-enclosed-guillemets-french/gnd.json +103 -0
- package/fixtures/noteref-enclosed-guillemets-french/input.html +1 -0
- package/fixtures/noteref-enclosed-guillemets-french/meta.json +13 -0
- package/fixtures/noteref-enclosed-quotes-chinese/gnd.json +47 -0
- package/fixtures/noteref-enclosed-quotes-chinese/input.html +1 -0
- package/fixtures/noteref-enclosed-quotes-chinese/meta.json +13 -0
- package/fixtures/noteref-enclosed-quotes-german/gnd.json +124 -0
- package/fixtures/noteref-enclosed-quotes-german/input.html +1 -0
- package/fixtures/noteref-enclosed-quotes-german/meta.json +13 -0
- package/fixtures/noteref-enclosed-quotes-swedish/gnd.json +70 -0
- package/fixtures/noteref-enclosed-quotes-swedish/input.html +1 -0
- package/fixtures/noteref-enclosed-quotes-swedish/meta.json +13 -0
- package/fixtures/noteref-enclosed-straight-quotes/gnd.json +32 -0
- package/fixtures/noteref-enclosed-straight-quotes/input.html +1 -0
- package/fixtures/noteref-enclosed-straight-quotes/meta.json +13 -0
- package/fixtures/noteref-in-lone-block/gnd.json +29 -0
- package/fixtures/noteref-in-lone-block/input.html +1 -0
- package/fixtures/noteref-in-lone-block/meta.json +12 -0
- package/fixtures/noteref-target-malformed-escape/gnd.json +32 -0
- package/fixtures/noteref-target-malformed-escape/input.html +1 -0
- package/fixtures/noteref-target-malformed-escape/meta.json +13 -0
- package/fixtures/noteref-target-percent-encoded/gnd.json +32 -0
- package/fixtures/noteref-target-percent-encoded/input.html +1 -0
- package/fixtures/noteref-target-percent-encoded/meta.json +13 -0
- package/package.json +1 -1
- package/src/a11y.ts +50 -39
- package/src/converter.ts +140 -50
- package/src/dom.ts +0 -10
- package/src/elementHandlers.ts +76 -22
- package/src/emptyPairs.ts +74 -0
- package/src/language.ts +37 -0
- package/src/object.ts +11 -1
- package/src/prescan.ts +2 -1
- package/src/roles.ts +2 -0
- package/src/text.ts +5 -2
- package/src/textrefFragment.ts +9 -1
- package/types/src/a11y.d.ts +9 -4
- package/types/src/converter.d.ts +4 -0
- package/types/src/dom.d.ts +0 -1
- package/types/src/elementHandlers.d.ts +3 -2
- package/types/src/emptyPairs.d.ts +3 -0
- package/types/src/language.d.ts +4 -0
- package/types/src/object.d.ts +2 -0
- package/types/src/text.d.ts +2 -1
- 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
|
|
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 P,extractNodeRoles as F}from"./roles.js";import{skippedElements as W,extractNodeAria as B,normalizedNodeText as z,normalizedNodeTextExcludingExplicitRoles as O,convertElementToSSMLTag as H}from"./a11y.js";import{normalizeWhitespace as v,ctxEqual as I}from"./text.js";import{ssmlAttrEscape as A,ssmlTextEscape as L,startsWithBindingPunct as _}from"@readium/helpers";import{NavObject as w,isEmptyObj as D,finalizeToGuidedNavigationObject as q}from"./object.js";import{sniffMediaType as X,nodeLanguage as y,isInlineTag as G}from"./dom.js";import{encodeDomRangeFragment as U,encodeTextFragmentDirective as V}from"./textrefFragment.js";import{resolveRefs as Y}from"./href.js";import{rootAnchorSelector as J,textrefForSelector as S,selectorForElement as C}from"./selectorGenerator.js";import{generateDomRange as K}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as Q}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as Z}from"./options.js";import{IdAllocator as tt}from"./idAllocator.js";import{prescan as et}from"./prescan.js";import{pagebreak as st,noteref as it,link as rt}from"./elementHandlers.js";const nt="http://www.w3.org/1998/Math/MathML",ot=3,lt=1,at=new Set(["summary","dfn","span"]);function M(c,t){return at.has(c)&&t.length>0?!0:!G(c)}class b{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new tt,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 w,this.current=this.root,this.foldedCaptions=new Set,this.segments=[],this.textAcc="",this.currentCtx={lang:"",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 b(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){et(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=>S(C(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0?D(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>Y(e,this.baseHref)),t.map(q)}descend(t,e){const s=new w;s.el=t,s.noText=this.foldedCaptions.has(t)||(!P(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===ot){this.text(t);return}if(t.nodeType!==lt)return;const e=t,s=this.current,a=this.head(e);if(!a)for(let i=e.firstChild;i;i=i.nextSibling)this.walk(i);this.tail(e,a,s)}head(t){const e=t.tagName.toLowerCase();if(W.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[s,a]=B(t);if(!a&&t!==this.allowNode)return!0;const i=F(t);if((e==="img"||e==="svg")&&(i.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(i.includes("pagebreak"))return!st(this,t,s,i);if(e==="a"&&i.includes("noteref")&&t.getAttribute("href"))return it(this,t,i),!0;if(e==="a"&&t.getAttribute("href"))return rt(this,t,i,s),!0;if(e==="img"){const o={role:i},n=t.getAttribute("src");return n&&(o.imgref=n),s&&(o.description=s),this.placeholder(t,"image",o),!0}if(e==="audio"||e==="video"){const o={role:i};let n=t.getAttribute("src");if(!n){const d=t.querySelector(":scope > source[src]");d&&(n=d.getAttribute("src"))}return e==="audio"?n&&(o.audioref=n):n&&(o.videoref=n),s&&(o.description=s),this.placeholder(t,e,o),!0}if(i.includes("image")||i.includes("math")){const o={role:i};if(s&&(o.description=s),i.includes("math")){if(t.namespaceURI===nt)o.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:""};else{const n=z(t);n&&(o.text={plain:n,ssml:"",language:""})}o.textref=S(C(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,i.includes("math")?"math":"image",o),!0}if(!M(e,i))return!1;this.flushText(),this.descend(t,i);const f=this.current.object;if(i.length>0&&(f.role=i),s)f.description=s,i.includes("figure")&&(this.current.noText=!0);else if(i.includes("figure")){const o=this.implicitCaptionOf(t);if(o){const n=O(o);n&&(f.description=n,this.current.noText=!0)}}else if(i.includes("table")){const o=this.implicitCaptionOf(t);if(o){const n=O(o);n&&(f.description=n,this.foldedCaptions.add(o))}}const m=t.getAttribute("id");return m&&(f.id=m),!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,s){if(e)return;const a=t.tagName.toLowerCase(),i=F(t);if(!i.includes("pagebreak")&&M(a,i)){this.flushText(),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const f=this.leafTextEnabled&&i.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(i)||f)&&this.applyTextref(t),this.current=s}}applyTextref(t){const e=this.current.object,s=C(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=S(s,t),this.domRangeEnabled&&this.lastFlowRange){const a=s?{el:t,selector:s}:void 0,i=K(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,a);i&&(e.textref=U({...i,container:s}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const a=this.docRoot.createRange();a.setStart(...this.lastFlowRange.first),a.setEnd(...this.lastFlowRange.last);const i=Q(a);i&&(e.textref=`${e.textref??"#"}${V(i)}`)}}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+=v(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const s=this.textContext(t);if(I(s,this.currentCtx)||(this.closeSegment(),this.currentCtx=s),this.textAcc+=v(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const a=t;this.flowFirstNode===null&&(this.flowFirstNode=a,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=a,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){const e={lang:y(t.parentElement),tag:""};for(let s=t.parentElement;s&&s!==this.current.el;s=s.parentElement){const[a,i]=H(s.tagName.toLowerCase());if(a&&a!=="break"){e.tag=a,e.attrs=i;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:"",tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0}placeholder(t,e,s,a){if(D(s))return;const i=new w;if(i.el=t,i.object=s,this.current.noText){this.appendChild(i);return}this.closeSegment(),this.pendingChildren.push(i),this.segments.push({kind:"placeholder",tag:e,child:i,candidateID:a??t.getAttribute("id")??void 0}),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,s=this.flowFirstNode,a=this.flowFirstOffset,i=this.flowLastNode,f=this.flowLastOffset;if(this.resetFlow(),this.lastFlowRange=null,this.lastFlowText=null,t.length===0)return;for(;t.length>0;){const r=t[0];if(r.kind==="break"){t=t.slice(1);continue}if(r.kind==="text"){const l=r.text.replace(/^\s+/,"");if(l===""){t=t.slice(1);continue}t=[{...r,text:l},...t.slice(1)]}break}for(;t.length>0;){const r=t[t.length-1];if(r.kind==="break"){t=t.slice(0,-1);continue}if(r.kind==="text"){const l=r.text.replace(/\s+$/,"");if(l===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...r,text:l}]}break}if(!t.some(r=>r.kind==="text"&&r.text.trim()!=="")){for(const r of e)this.appendChild(r);return}const o=[];for(const r of t)if(r.kind==="text"&&r.text.trim()!==""){const l=r.ctx.lang;o.includes(l)||o.push(l)}let n=y(this.current.el??null);o.length===1&&o[0]!==""&&(n=o[0]);let d=!1;for(const r of t)if(r.kind!=="text"||r.ctx.tag!==""||r.ctx.lang!==n){d=!0;break}if(d&&n===""&&(n="en"),d)for(const r of t){if(r.kind!=="placeholder")continue;let l=r.candidateID;(!l||!this.idAlloc.claim(l))&&(l=this.idAlloc.allocate(r.tag,g=>this.ids.has(g))),r.child.object.id=l}let u="",h=!1,E=!1,T=!1,R=!1;for(const r of t)if(r.kind==="text"){const l=r.text.startsWith(" "),g=r.text.replace(/^ +| +$/g,"");if(g===""){R=!0;continue}let p=!1;if(u.length>0){const x=h||R||l;E?p=!0:T?p=x&&!_(g):p=x}p&&(u+=" "),u+=g,h=r.text.endsWith(" "),E=!1,T=!1,R=!1}else r.kind==="break"?E=!0:r.kind==="placeholder"&&(T=!0);const $=t.some(r=>r.kind==="placeholder");this.lastFlowText=u.trim();const N={plain:d&&!$?"":u.trim(),ssml:"",language:n};if(d){let r="";for(const l of t)if(l.kind==="text"){let g=l.ctx.tag,p=l.ctx.attrs;if(l.ctx.lang!==n&&l.ctx.lang!==""&&(g="lang",p=void 0),g){r+=`<${g}`;for(const[x,j]of Object.entries(p??{}))r+=` ${x}="${A(j)}"`;l.ctx.lang!==n&&l.ctx.lang!==""&&(r+=` xml:lang="${A(l.ctx.lang)}"`),r+=`>${L(l.text)}</${g}>`}else r+=L(l.text)}else l.kind==="break"?r+="<break/>":l.kind==="placeholder"&&(r+=`<readium:${l.tag} id="${A(l.child.object.id)}" />`);N.ssml=r}const k=new w;k.object={text:N};for(const r of e)k.children.push(r);this.appendChild(k),s&&i&&(this.lastFlowRange={first:[s,a],last:[i,f]})}}const ct=/<body[\s>]/i;function At(c,t,e){const{predicate:s,leafText:a,domRange:i,textFragment:f}=Z(e?.textrefs);if(typeof c!="string"){const u=t??(c.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),h=new b(u==="application/xhtml+xml");return h.selectorPredicate=s,h.leafTextEnabled=a,h.domRangeEnabled=i,h.textFragmentEnabled=f,h.docRoot=c.ownerDocument,h.baseHref=e?.href,h.selectorRoot=c,h.selectorRootAnchor=J(c),h.convert(c),h.result()}let m=t??X(c),o=new DOMParser().parseFromString(c,m);if(m==="application/xhtml+xml"){const u=o.getElementsByTagNameNS("*","parsererror")[0];if(u){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${u.textContent?.trim()??""}`);m="text/html",o=new DOMParser().parseFromString(c,m)}}const n=new b(m==="application/xhtml+xml");n.selectorPredicate=s,n.leafTextEnabled=a,n.textFragmentEnabled=f,n.docRoot=o,n.baseHref=e?.href;const d=o.querySelector("body");return d&&!ct.test(c)?n.convertChildren(d):n.convert(d??o.documentElement),n.result()}export{b as Converter,At 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};
|
package/dist/dom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function s(e){for(let t=e.firstChild;t;t=t.nextSibling)if(t.nodeType===1)return!0;return!1}function a(e,t){for(let n=t;n;n=n.parentElement)if(n===e)return!0;return!1}const r=new Set(["object","base","font","tt","i","b","u","big","small","em","strong","dfn","code","samp","kbd","var","cite","abbr","time","acronym","mark","ruby","rt","rp","rtc","a","img","br","wbr","map","q","sub","sup","bdo","iframe","embed","span","input","select","textarea","label","button","optgroup","option","legend","datalist","keygen","output","progress","meter","area","param","source","track","summary","command","basefont","bgsound","menuitem","data","bdi","s","strike","nobr","rb"]);function i(e){return r.has(e)}function o(e){const t=e.slice(0,500);return/<\?xml\b/.test(t)||/xmlns:epub=/.test(t)||/DOCTYPE\s+html\s+PUBLIC\s+"-\/\/W3C\/\/DTD XHTML/i.test(t)?"application/xhtml+xml":"text/html"}export{s as hasElementChild,a as isAncestorOf,i as isInlineTag,o as sniffMediaType};
|
package/dist/elementHandlers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizedNodeText as
|
|
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/language.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r="http://www.w3.org/XML/1998/namespace";function a(t){return t.getAttributeNS(r,"lang")??(t.getAttribute("xml:lang")?.trim()||null)??t.getAttribute("lang")}function o(t){for(let n=t;n;n=n.parentElement){const e=a(n);if(e!==null)return e.trim()}}function g(t){return o(t)??""}function u(t,n){return t===n||t!==void 0&&n!==void 0&&t.toLowerCase()===n.toLowerCase()}function i(t){let n;for(const e of t)if(n===void 0)n=e;else if(!u(n,e))return"";return n??""}export{o as declaredLanguage,g as nodeLanguage,u as sameLanguage,i as sharedLanguage};
|
package/dist/object.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GuidedNavigationObject as
|
|
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
|
|
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"],
|
|
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
|
|
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};
|
package/dist/textrefFragment.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const l="#css(";function
|
|
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-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` |
|
|
@@ -78,4 +79,4 @@ renaming, or removing a fixture.
|
|
|
78
79
|
| `toc` | `toc-epub-type`, `toc-role-aria` |
|
|
79
80
|
| `video` | `video-html-native`, `video-no-description` |
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
213 fixtures across 71 roles.
|
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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 @@
|
|
|
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
|
+
}
|