@readium/guided-navigation 1.3.0 → 1.5.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 +6 -6
- package/dist/a11y.js +1 -1
- package/dist/converter.js +1 -1
- package/dist/elementHandlers.js +1 -1
- package/dist/emptyPairs.js +1 -1
- package/dist/index.js +1 -1
- package/dist/object.js +1 -1
- package/dist/roles.js +1 -1
- package/dist/textrefFragment.js +1 -1
- package/fixtures/README.md +4 -4
- package/fixtures/ROLES_COVERAGE.md +7 -3
- package/fixtures/abbreviation-acronym-html-native/gnd.json +3 -5
- package/fixtures/abbreviation-before-formatting/gnd.json +3 -5
- package/fixtures/abbreviation-before-image/gnd.json +10 -14
- package/fixtures/abbreviation-html-native/gnd.json +3 -5
- package/fixtures/abbreviation-language/gnd.json +3 -5
- package/fixtures/abbreviation-line-break/gnd.json +3 -5
- package/fixtures/abbreviation-nested/gnd.json +3 -5
- package/fixtures/abbreviation-nested-emphasis/gnd.json +3 -5
- package/fixtures/abbreviation-nested-term/gnd.json +4 -8
- package/fixtures/abbreviation-nested-term-punctuation/gnd.json +4 -8
- package/fixtures/abbreviation-no-title/gnd.json +1 -3
- package/fixtures/abbreviation-period-mid-sentence/gnd.json +3 -5
- package/fixtures/abbreviation-period-sentence-end/gnd.json +3 -5
- package/fixtures/abbreviation-spanning-terms/gnd.json +3 -9
- package/fixtures/abbreviation-with-image/gnd.json +10 -14
- package/fixtures/abbreviation-with-svg-and-math/gnd.json +15 -21
- package/fixtures/abstract-epub-type/gnd.json +3 -7
- package/fixtures/abstract-role-aria/gnd.json +1 -3
- package/fixtures/accessible-name-labelledby-aria-hidden/gnd.json +2 -7
- package/fixtures/accessible-name-labelledby-hidden-attribute/gnd.json +2 -7
- package/fixtures/acknowledgments-epub-type/gnd.json +3 -7
- package/fixtures/acknowledgments-role-aria/gnd.json +1 -3
- package/fixtures/afterword-epub-type/gnd.json +3 -7
- package/fixtures/afterword-role-aria/gnd.json +1 -3
- package/fixtures/appendix-epub-type/gnd.json +3 -8
- package/fixtures/appendix-role-aria/gnd.json +1 -3
- package/fixtures/article-html-native/gnd.json +1 -3
- package/fixtures/article-role-aria/gnd.json +2 -4
- package/fixtures/aside-epub-type/gnd.json +3 -7
- package/fixtures/aside-html-native/gnd.json +1 -3
- package/fixtures/audio-html-native/gnd.json +3 -5
- package/fixtures/audio-no-description/gnd.json +2 -4
- package/fixtures/backlink-epub-type/gnd.json +3 -8
- package/fixtures/backlink-role-aria/gnd.json +2 -5
- package/fixtures/bibliography-epub-type/gnd.json +7 -18
- package/fixtures/bibliography-role-aria/gnd.json +4 -12
- package/fixtures/biblioref-epub-type/gnd.json +3 -8
- package/fixtures/biblioref-role-aria/gnd.json +2 -5
- package/fixtures/biblioref-target-descendant-ids/gnd.json +31 -49
- package/fixtures/biblioref-target-in-bibliography-role-aria/gnd.json +16 -29
- package/fixtures/biblioref-target-mixed-content/gnd.json +27 -36
- package/fixtures/blockquote-html-native/gnd.json +1 -3
- package/fixtures/blockquote-role-aria/gnd.json +2 -4
- package/fixtures/body-html-native/gnd.json +1 -3
- package/fixtures/bubble-epub-type/gnd.json +11 -0
- package/fixtures/bubble-epub-type/input.xhtml +11 -0
- package/fixtures/bubble-epub-type/meta.json +10 -0
- package/fixtures/chapter-epub-type/gnd.json +4 -11
- package/fixtures/chapter-role-aria/gnd.json +2 -7
- package/fixtures/colophon-epub-type/gnd.json +3 -7
- package/fixtures/colophon-role-aria/gnd.json +1 -3
- package/fixtures/complementary-role-aria/gnd.json +1 -3
- package/fixtures/conclusion-epub-type/gnd.json +3 -7
- package/fixtures/conclusion-role-aria/gnd.json +1 -3
- package/fixtures/cover-epub-type/gnd.json +5 -12
- package/fixtures/cover-role-aria/gnd.json +3 -6
- package/fixtures/credit-epub-type/gnd.json +4 -10
- package/fixtures/credit-role-aria/gnd.json +1 -3
- package/fixtures/credits-epub-type/gnd.json +9 -23
- package/fixtures/credits-role-aria/gnd.json +4 -14
- package/fixtures/dedication-epub-type/gnd.json +3 -7
- package/fixtures/dedication-role-aria/gnd.json +1 -3
- package/fixtures/definition-epub-type/gnd.json +4 -10
- package/fixtures/definition-html-native/gnd.json +1 -3
- package/fixtures/definition-role-aria/gnd.json +1 -3
- package/fixtures/description-roleless-lone-child/gnd.json +5 -9
- package/fixtures/description-roleless-wrapper/gnd.json +8 -12
- package/fixtures/details-html-native/gnd.json +1 -3
- package/fixtures/details-summary-html-native/gnd.json +2 -6
- package/fixtures/endnotes-epub-type/gnd.json +9 -26
- package/fixtures/endnotes-role-aria/gnd.json +4 -14
- package/fixtures/epigraph-epub-type/gnd.json +3 -7
- package/fixtures/epigraph-role-aria/gnd.json +1 -3
- package/fixtures/epilogue-epub-type/gnd.json +3 -7
- package/fixtures/epilogue-role-aria/gnd.json +1 -3
- package/fixtures/errata-epub-type/gnd.json +3 -7
- package/fixtures/errata-role-aria/gnd.json +1 -3
- package/fixtures/example-epub-type/gnd.json +5 -14
- package/fixtures/example-role-aria/gnd.json +1 -3
- package/fixtures/figure-aria-label-caption/gnd.json +19 -0
- package/fixtures/figure-aria-label-caption/input.html +1 -0
- package/fixtures/figure-aria-label-caption/meta.json +12 -0
- package/fixtures/figure-basic-html-native/gnd.json +4 -8
- package/fixtures/figure-basic-role-aria/gnd.json +4 -8
- package/fixtures/figure-caption-block-content/gnd.json +33 -0
- package/fixtures/figure-caption-block-content/input.html +7 -0
- package/fixtures/figure-caption-block-content/meta.json +14 -0
- package/fixtures/figure-caption-element-html-native/gnd.json +14 -8
- package/fixtures/figure-caption-element-html-native/meta.json +1 -1
- package/fixtures/figure-caption-element-role-aria/gnd.json +14 -8
- package/fixtures/figure-caption-element-role-aria/meta.json +1 -1
- package/fixtures/figure-caption-html-native/gnd.json +3 -5
- package/fixtures/figure-caption-role-aria/gnd.json +3 -5
- package/fixtures/figure-credit-nested-in-aria-labelledby-caption/gnd.json +13 -21
- package/fixtures/figure-credit-nested-in-caption/gnd.json +13 -21
- package/fixtures/figure-credit-nested-in-caption/meta.json +1 -1
- package/fixtures/figure-credit-role-aria/gnd.json +12 -18
- package/fixtures/figure-credit-role-aria/meta.json +1 -1
- package/fixtures/figure-describedby/gnd.json +4 -8
- package/fixtures/figure-epub-type/gnd.json +5 -11
- package/fixtures/figure-no-description/gnd.json +3 -7
- package/fixtures/footnote-epub-type/gnd.json +5 -14
- package/fixtures/footnote-role-aria/gnd.json +17 -31
- package/fixtures/foreword-epub-type/gnd.json +3 -7
- package/fixtures/foreword-role-aria/gnd.json +1 -3
- package/fixtures/glossary-epub-type/gnd.json +10 -22
- package/fixtures/glossary-role-aria/gnd.json +5 -15
- package/fixtures/glossref-epub-type/gnd.json +3 -8
- package/fixtures/glossref-role-aria/gnd.json +2 -5
- package/fixtures/glossref-role-aria-mid-sentence/gnd.json +5 -13
- package/fixtures/glossref-sole-content/gnd.json +11 -26
- package/fixtures/glossref-target-in-glossary-role-aria/gnd.json +17 -32
- package/fixtures/glossref-target-percent-encoded/gnd.json +17 -32
- package/fixtures/glossref-target-percent-encoded/meta.json +1 -1
- package/fixtures/header-html-native/gnd.json +1 -3
- package/fixtures/heading-html-native/gnd.json +6 -18
- package/fixtures/heading-role-aria/gnd.json +6 -18
- package/fixtures/heading-role-presentation/gnd.json +6 -12
- package/fixtures/hidden-aria-hidden-html-native/gnd.json +2 -6
- package/fixtures/hidden-attribute-html-native/gnd.json +2 -6
- package/fixtures/image-alt-html-native/gnd.json +3 -5
- package/fixtures/image-decorative-empty-alt/gnd.json +2 -6
- package/fixtures/image-decorative-role-presentation/gnd.json +2 -6
- package/fixtures/image-decorative-whitespace-alt/gnd.json +4 -8
- package/fixtures/image-no-description/gnd.json +2 -4
- package/fixtures/image-role-aria/gnd.json +3 -5
- package/fixtures/index-epub-type/gnd.json +11 -32
- package/fixtures/index-role-aria/gnd.json +10 -28
- package/fixtures/introduction-epub-type/gnd.json +3 -7
- package/fixtures/introduction-role-aria/gnd.json +1 -3
- package/fixtures/landmarks-epub-type/gnd.json +15 -43
- package/fixtures/language-alt-inherited/gnd.json +8 -12
- package/fixtures/language-alt-own-lang/gnd.json +8 -12
- package/fixtures/language-block/gnd.json +5 -11
- package/fixtures/language-block-empty-lang/gnd.json +1 -3
- package/fixtures/language-describedby-shared/gnd.json +19 -27
- package/fixtures/language-document/gnd.json +3 -7
- package/fixtures/language-empty-lang-stops-inheritance/gnd.json +6 -10
- package/fixtures/language-figcaption/gnd.json +13 -16
- package/fixtures/language-figcaption/meta.json +1 -1
- package/fixtures/language-figcaption-credit/gnd.json +17 -25
- package/fixtures/language-figcaption-credit/meta.json +1 -1
- package/fixtures/language-figcaption-switches/gnd.json +13 -15
- package/fixtures/language-figcaption-switches/meta.json +1 -1
- package/fixtures/language-figcaption-switches-throughout/gnd.json +13 -16
- package/fixtures/language-figcaption-switches-throughout/meta.json +1 -1
- package/fixtures/language-inline-case-insensitive/gnd.json +3 -5
- package/fixtures/language-inline-case-insensitive-ssml/gnd.json +3 -5
- package/fixtures/language-inline-empty-lang/gnd.json +3 -5
- package/fixtures/language-inline-empty-lang-formatted/gnd.json +1 -3
- package/fixtures/language-inline-empty-lang-only/gnd.json +1 -3
- package/fixtures/language-inline-empty-lang-undeclared/gnd.json +3 -5
- package/fixtures/language-inline-lang-attribute/gnd.json +3 -5
- package/fixtures/language-inline-nested/gnd.json +3 -5
- package/fixtures/language-inline-repeated/gnd.json +3 -5
- package/fixtures/language-inline-two-languages/gnd.json +3 -5
- package/fixtures/language-labelledby-target/gnd.json +8 -12
- package/fixtures/language-labelledby-target-aria-label/gnd.json +12 -16
- package/fixtures/language-labelledby-target-switches/gnd.json +6 -10
- package/fixtures/language-labelledby-targets-case/gnd.json +11 -17
- package/fixtures/language-labelledby-targets-differ/gnd.json +9 -15
- package/fixtures/language-link-switches/gnd.json +10 -13
- package/fixtures/language-pagebreak-label/gnd.json +10 -14
- package/fixtures/language-undeclared-description/gnd.json +4 -8
- package/fixtures/language-xml-lang-empty-html-inherits/gnd.json +8 -12
- package/fixtures/language-xml-lang-empty-html-lang-applies/gnd.json +8 -12
- package/fixtures/language-xml-lang-empty-xhtml/gnd.json +6 -10
- package/fixtures/language-xml-lang-over-lang/gnd.json +8 -12
- package/fixtures/link-containing-image/gnd.json +12 -17
- package/fixtures/link-containing-pagebreak/gnd.json +12 -17
- package/fixtures/link-content-conversion/gnd.json +14 -20
- package/fixtures/link-content-identity/gnd.json +7 -8
- package/fixtures/link-content-words/gnd.json +9 -14
- package/fixtures/list-aria-posinset-setsize/gnd.json +3 -7
- package/fixtures/list-epub-type/gnd.json +6 -14
- package/fixtures/list-html-native/gnd.json +4 -12
- package/fixtures/list-item-posinset-override/gnd.json +7 -15
- package/fixtures/list-item-value-override/gnd.json +7 -15
- package/fixtures/list-ordered-html-native/gnd.json +7 -15
- package/fixtures/list-ordered-reversed/gnd.json +7 -15
- package/fixtures/list-ordered-start/gnd.json +7 -15
- package/fixtures/list-role-aria/gnd.json +4 -12
- package/fixtures/listitem-role-presentation/gnd.json +5 -11
- package/fixtures/loa-epub-type/gnd.json +11 -32
- package/fixtures/loi-epub-type/gnd.json +11 -32
- package/fixtures/lot-epub-type/gnd.json +11 -32
- package/fixtures/lov-epub-type/gnd.json +11 -32
- package/fixtures/main-html-native/gnd.json +1 -3
- package/fixtures/main-role-aria/gnd.json +1 -3
- package/fixtures/manifest.json +121 -11
- package/fixtures/math-html-native/gnd.json +5 -7
- package/fixtures/math-inline/gnd.json +10 -14
- package/fixtures/math-no-description/gnd.json +3 -5
- package/fixtures/math-role-aria/gnd.json +5 -7
- package/fixtures/navigation-html-native/gnd.json +1 -3
- package/fixtures/navigation-role-aria/gnd.json +1 -3
- package/fixtures/nested-blockquote/gnd.json +3 -9
- package/fixtures/nested-section/gnd.json +3 -9
- package/fixtures/noteref-after-closing-straight-quote/gnd.json +13 -20
- package/fixtures/noteref-after-closing-straight-quote-split/gnd.json +12 -17
- package/fixtures/noteref-enclosed-across-formatting/gnd.json +13 -20
- package/fixtures/noteref-enclosed-adjacent-pairs/gnd.json +38 -62
- package/fixtures/noteref-enclosed-adjacent-text/gnd.json +16 -23
- package/fixtures/noteref-enclosed-before-formatting/gnd.json +16 -23
- package/fixtures/noteref-enclosed-guillemets-french/gnd.json +42 -63
- package/fixtures/noteref-enclosed-quotes-chinese/gnd.json +15 -25
- package/fixtures/noteref-enclosed-quotes-german/gnd.json +49 -75
- package/fixtures/noteref-enclosed-quotes-swedish/gnd.json +28 -42
- package/fixtures/noteref-enclosed-straight-quotes/gnd.json +13 -20
- package/fixtures/noteref-in-lone-block/gnd.json +12 -17
- package/fixtures/noteref-role-aria/gnd.json +1 -3
- package/fixtures/noteref-target-in-endnotes-epub-type/gnd.json +10 -29
- package/fixtures/noteref-target-in-endnotes-role-aria/gnd.json +9 -26
- package/fixtures/noteref-target-malformed-escape/gnd.json +13 -20
- package/fixtures/noteref-target-percent-encoded/gnd.json +13 -20
- package/fixtures/notice-epub-type/gnd.json +3 -7
- package/fixtures/notice-role-aria/gnd.json +1 -3
- package/fixtures/pagebreak-epub-type/gnd.json +6 -14
- package/fixtures/pagebreak-role-aria/gnd.json +5 -11
- package/fixtures/pagelist-epub-type/gnd.json +15 -43
- package/fixtures/pagelist-role-aria/gnd.json +14 -40
- package/fixtures/panel-epub-type/gnd.json +27 -0
- package/fixtures/panel-epub-type/input.xhtml +14 -0
- package/fixtures/panel-epub-type/meta.json +13 -0
- package/fixtures/panel-group-epub-type/gnd.json +32 -0
- package/fixtures/panel-group-epub-type/input.xhtml +14 -0
- package/fixtures/panel-group-epub-type/meta.json +11 -0
- package/fixtures/panel-object-role-img/gnd.json +14 -0
- package/fixtures/panel-object-role-img/input.xhtml +11 -0
- package/fixtures/panel-object-role-img/meta.json +11 -0
- package/fixtures/panel-role-img-labelled/gnd.json +21 -0
- package/fixtures/panel-role-img-labelled/input.xhtml +13 -0
- package/fixtures/panel-role-img-labelled/meta.json +12 -0
- package/fixtures/panel-svg-epub-type/gnd.json +14 -0
- package/fixtures/panel-svg-epub-type/input.xhtml +11 -0
- package/fixtures/panel-svg-epub-type/meta.json +11 -0
- package/fixtures/paragraph-basic/gnd.json +1 -3
- package/fixtures/part-epub-type/gnd.json +4 -11
- package/fixtures/part-role-aria/gnd.json +2 -7
- package/fixtures/preface-epub-type/gnd.json +3 -7
- package/fixtures/preface-role-aria/gnd.json +1 -3
- package/fixtures/preformatted-html-native/gnd.json +1 -3
- package/fixtures/presentation-role-aria/gnd.json +1 -3
- package/fixtures/prologue-epub-type/gnd.json +3 -7
- package/fixtures/prologue-role-aria/gnd.json +1 -3
- package/fixtures/pullquote-epub-type/gnd.json +3 -8
- package/fixtures/pullquote-role-aria/gnd.json +1 -3
- package/fixtures/qna-epub-type/gnd.json +3 -8
- package/fixtures/qna-role-aria/gnd.json +1 -3
- package/fixtures/redundant-role-body-chapter/gnd.json +3 -10
- package/fixtures/redundant-role-nested-chapter/gnd.json +4 -13
- package/fixtures/region-role-aria/gnd.json +1 -3
- package/fixtures/section-html-native/gnd.json +1 -3
- package/fixtures/separator-html-native/gnd.json +3 -9
- package/fixtures/separator-role-aria/gnd.json +3 -9
- package/fixtures/separator-with-glyphs/gnd.json +3 -9
- package/fixtures/sound-epub-type/gnd.json +11 -0
- package/fixtures/sound-epub-type/input.xhtml +11 -0
- package/fixtures/sound-epub-type/meta.json +10 -0
- package/fixtures/subtitle-epub-type/gnd.json +3 -7
- package/fixtures/subtitle-role-aria/gnd.json +1 -3
- package/fixtures/summary-html-native/gnd.json +1 -3
- package/fixtures/table-aria-label-caption/gnd.json +27 -0
- package/fixtures/table-aria-label-caption/input.html +1 -0
- package/fixtures/table-aria-label-caption/meta.json +13 -0
- package/fixtures/table-caption/gnd.json +22 -42
- package/fixtures/table-caption/meta.json +1 -1
- package/fixtures/table-caption-aria-labelledby/gnd.json +28 -0
- package/fixtures/table-caption-aria-labelledby/input.html +1 -0
- package/fixtures/table-caption-aria-labelledby/meta.json +13 -0
- package/fixtures/table-caption-element-html-native/gnd.json +13 -22
- package/fixtures/table-caption-element-html-native/meta.json +1 -1
- package/fixtures/table-caption-role-aria/gnd.json +10 -15
- package/fixtures/table-cell-abbreviation/gnd.json +8 -16
- package/fixtures/table-cell-link/gnd.json +8 -19
- package/fixtures/table-cell-noteref/gnd.json +15 -25
- package/fixtures/table-colspan-html-native/gnd.json +9 -21
- package/fixtures/table-colspan-role-aria/gnd.json +9 -21
- package/fixtures/table-epub-type/gnd.json +7 -17
- package/fixtures/table-html-native/gnd.json +10 -30
- package/fixtures/table-in-role-none-wrapper/gnd.json +6 -18
- package/fixtures/table-nested-html-native/gnd.json +7 -19
- package/fixtures/table-nested-in-presentation-table/gnd.json +8 -24
- package/fixtures/table-nested-role-aria/gnd.json +7 -19
- package/fixtures/table-no-headers/gnd.json +11 -25
- package/fixtures/table-role-aria/gnd.json +10 -30
- package/fixtures/table-role-presentation-explicit-cell/gnd.json +4 -12
- package/fixtures/table-role-presentation-html-native/gnd.json +7 -17
- package/fixtures/table-role-presentation-role-aria/gnd.json +7 -17
- package/fixtures/table-rowgroup-role-aria/gnd.json +4 -10
- package/fixtures/table-rowspan-html-native/gnd.json +9 -21
- package/fixtures/table-rowspan-role-aria/gnd.json +9 -21
- package/fixtures/table-sectioning/gnd.json +10 -24
- package/fixtures/table-th-no-scope/gnd.json +11 -25
- package/fixtures/term-epub-type/gnd.json +4 -10
- package/fixtures/term-html-native/gnd.json +1 -3
- package/fixtures/term-role-aria/gnd.json +1 -3
- package/fixtures/term-span-in-dt/gnd.json +3 -9
- package/fixtures/tip-epub-type/gnd.json +3 -8
- package/fixtures/tip-role-aria/gnd.json +1 -3
- package/fixtures/toc-epub-type/gnd.json +15 -43
- package/fixtures/toc-role-aria/gnd.json +14 -40
- package/fixtures/video-html-native/gnd.json +3 -5
- package/fixtures/video-no-description/gnd.json +2 -4
- package/package.json +6 -2
- package/src/a11y.ts +3 -12
- package/src/converter.ts +18 -47
- package/src/elementHandlers.ts +3 -12
- package/src/emptyPairs.ts +35 -15
- package/src/index.ts +2 -1
- package/src/object.ts +4 -10
- package/src/roles.ts +7 -0
- package/src/textrefFragment.ts +7 -16
- package/types/src/a11y.d.ts +0 -2
- package/types/src/converter.d.ts +1 -2
- package/types/src/emptyPairs.d.ts +3 -0
- package/types/src/index.d.ts +2 -1
- package/types/src/textrefFragment.d.ts +0 -4
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ The directive is generated by Google's [text-fragments-polyfill](https://github.
|
|
|
92
92
|
|
|
93
93
|
If the node's text is too long, the polyfill only keeps the first few words and the last few words (`textStart` and `textEnd`), instead of the whole thing.
|
|
94
94
|
|
|
95
|
-
Use `decodeTextref({
|
|
95
|
+
Use `decodeTextref({ textref })` to read a `textref` back. It returns:
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
98
|
{ href?, cssSelector?, domRange?, text?, fragment? }
|
|
@@ -103,7 +103,7 @@ Use `decodeTextref({ id, textref })` to read a `textref` back. It returns:
|
|
|
103
103
|
- Exact match (one quote) → `text: { highlight, before?, after? }`
|
|
104
104
|
- Range (the `textStart`/`textEnd` case above) → `fragment` (the raw `:~:text=...` string)
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
A `textref` always references the node's own content, so `#id`, `#css(...)` and `#domrange(...)` all locate it. It returns `undefined` when there's nothing to locate, e.g. a `textref` naming a whole resource. `combineDomRangeTextrefs(first, last)` joins two decoded `domRange` references into one spanning both, as long as they're in the same resource.
|
|
107
107
|
|
|
108
108
|
The lower-level pieces are exported too: `encodeCssSelectorFragment(selector)`/`decodeCssSelectorFragment(textref)` for `#css(...)`, and `encodeDomRangeFragment(domRange)`/`decodeDomRangeFragment(textref)` for `#domrange(...)` (a `DomRangeJSON`: `{ start: { cssSelector, textNodeIndex, charOffset? }, end?: {...} }`, the RWPM shape behind `@readium/shared`'s `DomRange`).
|
|
109
109
|
|
|
@@ -112,12 +112,12 @@ The lower-level pieces are exported too: `encodeCssSelectorFragment(selector)`/`
|
|
|
112
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"]`.
|
|
113
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.
|
|
114
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`.
|
|
115
|
-
- **`imgref`/`audioref`/`videoref`** are a media element's `src`. **`textref`**
|
|
116
|
-
- **`description`** holds a node's accessible name (`aria-label`, `
|
|
115
|
+
- **`imgref`/`audioref`/`videoref`** are a media element's `src`. **`textref`** locates the node's own content (see [Text references](#text-references-textrefs)). A link's destination isn't kept: links, `backlink`, `biblioref` and `glossref` carry their text, and `biblioref`/`glossref` embed their target as `children`.
|
|
116
|
+
- **`description`** holds a node's accessible name (`aria-label`, `aria-labelledby`, `alt`...) as `description.text` when it differs from its visible text. A `<figcaption>` or table `<caption>` isn't folded into it: it stays a `caption` object, its blocks keeping their own text.
|
|
117
117
|
- Empty/presentational/`aria-hidden`/`hidden` content and role-less wrapper `<div>`s are dropped from the tree, not kept as empty nodes.
|
|
118
|
-
- A block whose only child has no role/id/ref of its own gets that child's text hoisted into it: `<p><em>Cover</em></p>` → `{ role: ["paragraph"], text: { plain: "Cover" } }`, not a nested anonymous child. A child carrying its own ref is never hoisted: `<p><a href="...">Cover</a></p>` → `{ role: ["paragraph"], children: [{ text: { plain: "
|
|
118
|
+
- A block whose only child has no role/id/ref of its own gets that child's text hoisted into it: `<p><em>Cover</em></p>` → `{ role: ["paragraph"], text: { plain: "Cover" } }`, not a nested anonymous child. A child carrying its own ref, or text substituted from `aria-label`, is never hoisted: `<p><a href="..." aria-label="Go">Cover</a></p>` → `{ role: ["paragraph"], children: [{ text: { plain: "Go" } }] }`.
|
|
119
119
|
|
|
120
|
-
When `text` comes from `aria-label`/`aria-labelledby` instead of the element's content, it isn't on the page. `isAriaSubstituted(object)` tells such objects apart, and `substitutedOwnSelector(object)` returns a substituted link's own CSS selector,
|
|
120
|
+
When `text` comes from `aria-label`/`aria-labelledby` instead of the element's content, it isn't on the page. `isAriaSubstituted(object)` tells such objects apart, and `substitutedOwnSelector(object)` returns a substituted link's own CSS selector, its box when no `textref` locates it. Both only know about objects returned by `parseMarkup`/`makeGnd`, not deserialized ones.
|
|
121
121
|
|
|
122
122
|
## Footnotes and pagebreaks
|
|
123
123
|
|
package/dist/a11y.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeWhitespace as
|
|
1
|
+
import{normalizeWhitespace as s}from"./text.js";import{hasExplicitRole as x}from"./roles.js";import{nodeLanguage as u,sharedLanguage as g}from"./language.js";function w(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function p(t,a,c){let f="";const o=(r,n)=>{if(r.nodeType===3){const e=r.nodeValue??"";f+=e,e.trim()&&c.add(u(r.parentElement));return}if(!(a&&r.nodeType===1&&!n&&x(r)))for(let e=r.firstChild;e;e=e.nextSibling)o(e,!1)};return o(t,!0),f}function y(t){const a=new Set;return{text:s(p(t,!1,a),!0).trim(),language:g(a)}}function v(t){if(w(t))return[null,!1,""];const a=(t.getAttribute("aria-labelledby")??"").trim();if(a){const r=[...new Set(a.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 l=new Set;e.forEach((m,h)=>{const b=m.getAttribute("aria-label");b?(i+=b,l.add(u(m))):i+=p(m,!0,l),h<e.length-1&&(i+=" ")});const d=s(i,!0).trim();if(d!=="")return[d,!0,g(l)]}}const c=s(t.getAttribute("aria-label")??"",!0).trim();if(c)return[c,!0,u(t)];const f=(t.getAttribute("aria-describedby")??"").trim();if(f){const n=[...new Set(f.split(/\s+/).filter(Boolean))].map(e=>t.ownerDocument.getElementById(e)).filter(e=>e!==null);if(n.length>0){const e=new Set,i=n.map(d=>p(d,!0,e)).join(" "),l=s(i,!0).trim();if(l!=="")return[l,!0,g(e)]}}const o=t.tagName.toLowerCase();if(o==="img"){const r=s(t.getAttribute("alt")??"",!0).trim();if(r)return[r,!0,u(t)];const n=s(t.getAttribute("title")??"",!0).trim();if(n)return[n,!0,u(t)]}else if(o==="svg"){const r=t.querySelector(":scope > title");if(r){const{text:n,language:e}=y(r);if(n)return[n,!0,e]}}else if(o==="math"){const r=s(t.getAttribute("alttext")??"",!0).trim();if(r)return[r,!0,u(t)]}return[null,!0,""]}const A={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function B(t){return A[t]??["",void 0]}const N=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{B as convertElementToSSMLTag,v as extractNodeAria,y as normalizedNodeText,N as skippedElements};
|
package/dist/converter.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
import{hasExplicitRole as J,extractNodeRoles as F}from"./roles.js";import{skippedElements as $,extractNodeAria as q,normalizedNodeText as K,convertElementToSSMLTag as Q}from"./a11y.js";import{normalizeWhitespace as v,ctxEqual as Z}from"./text.js";import{ssmlTextEscape as W,ssmlAttrEscape as B}from"@readium/helpers";import{NavObject as A,isEmptyObj as V,finalizeToGuidedNavigationObject as _,setDescription as S}from"./object.js";import{sniffMediaType as tt,isInlineTag as z,isAncestorOf as et}from"./dom.js";import{nodeLanguage as st,declaredLanguage as j,sameLanguage as M}from"./language.js";import{encodeDomRangeFragment as it,encodeTextFragmentDirective as nt}from"./textrefFragment.js";import{resolveRefs as rt}from"./href.js";import{rootAnchorSelector as ot,textrefForSelector as O,selectorForElement as N}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 pt}from"./elementHandlers.js";import{removeDropped as mt,bindsToPrevious as xt,DROPPED as bt}from"./emptyPairs.js";const wt="http://www.w3.org/1998/Math/MathML",L=3,X=1,kt=4,Et=new Set(["summary","dfn","span"]);function R(d,t){return Et.has(d)&&t.length>0?!0:!z(d)}class f{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 A,this.current=this.root,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 s=new f(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.copy=this.copy,s}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=>O(N(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0||t.text?V(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>rt(e,this.baseHref)),t.map(_)}descend(t,e){const s=new A;s.el=t,s.noText=(!J(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===L){f.punctuationOwner(t)||this.text(t);return}if(t.nodeType!==X)return;const e=t,s=this.current,o=this.head(e);if(!o){const i=this.current!==s&&this.current.el===e?f.ownPunctuation(e):[],r=a=>(a.compareDocumentPosition(e)&kt)!==0;for(const a of i)r(a)&&this.text(a);for(let a=e.firstChild;a;a=a.nextSibling)this.walk(a);for(const a of i)r(a)||this.text(a)}this.tail(e,o,s)}head(t){const e=t.tagName.toLowerCase();if($.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[s,o,i]=q(t);if(!o&&t!==this.allowNode)return!0;const r=F(t);if((e==="img"||e==="svg")&&(r.includes("presentation")||s===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!dt(this,t,s,i,r);if(e==="a"&&r.includes("noteref")&&t.getAttribute("href"))return ut(this,t,r),!0;if(e==="a"&&(r.includes("glossref")||r.includes("biblioref"))&&t.getAttribute("href"))return gt(this,t,r,s,i),!0;if(e==="a"&&t.getAttribute("href"))return pt(this,t,r,s,i),!0;if(e==="img"){const c={role:r},h=t.getAttribute("src");return h&&(c.imgref=h),s&&S(c,s,i),this.placeholder(t,"image",c),!0}if(e==="audio"||e==="video"){const c={role:r};let h=t.getAttribute("src");if(!h){const g=t.querySelector(":scope > source[src]");g&&(h=g.getAttribute("src"))}return e==="audio"?h&&(c.audioref=h):h&&(c.videoref=h),s&&S(c,s,i),this.placeholder(t,e,c),!0}if(f.actsAsImage(e,r)||r.includes("math")){const c={role:r};if(s&&S(c,s,i),r.includes("math")){if(t.namespaceURI===wt)c.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:st(t)};else{const{text:h,language:g}=K(t);h&&(c.text={plain:h,ssml:"",language:g})}c.textref=O(N(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,r.includes("math")?"math":"image",c),!0}if(!R(e,r))return!1;this.flushText(),z(e)||this.words?.push({kind:"break"}),this.descend(t,r);const a=this.current.object;r.length>0&&(a.role=r),s&&(S(a,s,i),r.includes("figure")&&(this.current.noText=!0));const b=t.getAttribute("id");return b&&(a.id=b),!1}tail(t,e,s){if(e)return;const o=t.tagName.toLowerCase(),i=F(t);if(!i.includes("pagebreak")&&R(o,i)){this.flushText(),z(o)||this.words?.push({kind:"break"}),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const r=this.leafTextEnabled&&i.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(i)||r)&&this.applyTextref(t),this.current=s}}applyTextref(t){const e=this.current.object,s=N(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=O(s,t),this.domRangeEnabled&&this.lastFlowRange){const o=s?{el:t,selector:s}:void 0,i=lt(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,o);i&&(e.textref=it({...i,container:s}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const o=this.docRoot.createRange();o.setStart(...this.lastFlowRange.first),o.setEnd(...this.lastFlowRange.last);const i=at(o);i&&(e.textref=`${e.textref??"#"}${nt(i)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(this.words?.push({kind:"text",text:v(e,!1)}),/^\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(Z(s,this.currentCtx)||(this.closeSegment(),this.currentCtx=s),this.textAcc+=v(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=f.punctuationOwner(t);let s=e?f.abbreviationOver(e):null;if(!e){let i=t.parentElement;for(;i&&i!==this.current.el;i=i.parentElement)if(I(i)){if(f.containsObject(i))break;s=i}i&&i===this.current.el&&(s=f.abbreviationOver(i)??s)}if(s)return{lang:j(s),tag:"sub",attrs:{alias:I(s)},abbr:s};const o={lang:j(t.parentElement),tag:""};for(let i=t.parentElement;i&&i!==this.current.el;i=i.parentElement){const[r,a]=Q(i.tagName.toLowerCase());if(r&&r!=="break"){o.tag=r,o.attrs=a;break}}return o}static containsObject(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling){const s=e.tagName.toLowerCase(),o=F(e);if(!($.has(s)||f.isPlaceholder(e,s,o))&&(R(s,o)||f.containsObject(e)))return!0}return!1}static isPlaceholder(t,e,s){return s.includes("pagebreak")||f.actsAsImage(e,s)||s.includes("math")?!0:["img","svg","audio","video"].includes(e)||e==="a"&&!!t.getAttribute("href")}static actsAsImage(t,e){const s=e.includes("panel")||e.includes("panelGroup");return e.includes("image")&&(t==="svg"||!s||!R(t,e))}static abbreviationOver(t){let e=null;for(let s=t;s&&(I(s)&&(e=s),!!f.isSoleContent(s));s=s.parentElement);return e}static punctuationOwner(t){const e=t.nodeValue??"";if(t.nodeType!==L||!/\S/.test(e)||!/^[\s\p{P}]*$/u.test(e))return null;let s=null;for(let o=t.parentElement?.firstElementChild??null;o&&f.isSoleContent(o);o=o.firstElementChild){const i=o.tagName.toLowerCase(),r=F(o);if($.has(i)||f.isPlaceholder(o,i,r)||!q(o)[1])break;R(i,r)&&(s=o)}return s&&f.abbreviationOver(s)?.contains(t)?s:null}static ownPunctuation(t){const e=f.abbreviationOver(t),s=[],o=i=>{if(i!==t){i.nodeType===L&&f.punctuationOwner(i)===t&&s.push(i);for(let r=i.firstChild;r;r=r.nextSibling)o(r)}};return e&&o(e),s}static isSoleContent(t){for(let e=t.parentNode?.firstChild;e;e=e.nextSibling)if(e!==t&&(e.nodeType===X||e.nodeType===L&&!/^[\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,s,{candidateID:o,words:i}={}){if(V(s))return;!s.textref&&this.selectorPredicate?.(s.role??[])&&(s.textref=O(N(t,this.selectorRoot,this.selectorRootAnchor),t));const r=new A;if(r.el=t,r.object=s,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:i?.length?i:void 0}),this.words?.push(...i?.length?i:[{kind:"placeholder"}]),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,s=this.flowFirstNode,o=this.flowFirstOffset,i=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 l=n.text.replace(/^\s+/,"");if(l===""){t=t.slice(1);continue}t=[{...n,text:l},...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 l=n.text.replace(/\s+$/,"");if(l===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...n,text:l}]}break}const a=[];for(let n=0;n<t.length;n++){const l=t[n],u=l.kind==="text"?l.ctx.abbr:void 0;if(!u){a.push(l);continue}let m=l.text;const E=[];let w=[];for(let x=n+1;x<t.length;x++){const T=t[x];if(T.kind==="placeholder"&&et(u,T.child.el)){w.push(T);continue}if(T.kind!=="text"||T.ctx.abbr!==u)break;m+=T.text,E.push(...w),w=[],n=x}a.push({...l,text:m},...E)}if(t=a,!t.some(n=>n.kind==="text"&&n.text.trim()!=="")){for(const n of e)this.appendChild(n);return}const c=[];for(const n of t)if(n.kind==="text"&&n.text.trim()!==""){const l=n.ctx.lang;c.some(u=>M(u,l))||c.push(l)}let h=j(this.current.el??this.allowNode);c.length===1&&(h=c[0]);let g=!1;for(const n of t)if(n.kind!=="text"||n.ctx.tag!==""||!M(n.ctx.lang,h)){g=!0;break}g&&h===void 0&&(h="en");const p=n=>n!==void 0&&!M(n,h);if(g)for(const n of t){if(n.kind!=="placeholder")continue;let l=this.copy?void 0:n.candidateID;(!l||!this.idAlloc.claim(l))&&(l=this.idAlloc.allocate(n.tag,u=>this.ids.has(u))),n.child.object.id=l}let k="",H=!1,P=!1,y=!1,C=!1;for(const n of t.flatMap(l=>l.words??[l]))if(n.kind==="text"){const l=n.text.startsWith(" "),u=n.text.replace(/^ +| +$/g,"");if(u===""){C=!0;continue}let m=!1;if(k.length>0){const E=H||C||l;P?m=!0:y?m=E&&!xt(u,h):m=E}m&&(k+=" "),k+=u,H=n.text.endsWith(" "),P=!1,y=!1,C=!1}else n.kind==="break"?P=!0:n.kind==="placeholder"&&(k+=bt,y=!0);k=mt(k,h);const Y=t.some(n=>n.kind==="placeholder");this.lastFlowText=k.trim();const G={plain:g&&!Y?"":k.trim(),ssml:"",language:h??""};if(g){let n="";for(const l of t)if(l.kind==="text"){const{tag:u,attrs:m,lang:E}=l.ctx,w=u==="sub"?/^( *)([^]*?)( *)$/.exec(l.text):null,x=w?w[2]:l.text;if(w&&x===""){n+=l.text;continue}if(n+=w?.[1]??"",p(E)){const T=u==="sub"?U(u,m,x):W(x);n+=`<lang xml:lang="${B(E)}">${T}</lang>`}else n+=u?U(u,m,x):W(x);n+=w?.[3]??""}else l.kind==="break"?n+="<break/>":l.kind==="placeholder"&&(n+=`<readium:${l.tag} id="${B(l.child.object.id)}" />`);G.ssml=n}const D=new A;D.object={text:G};for(const n of e)D.children.push(n);this.appendChild(D),s&&i&&(this.lastFlowRange={first:[s,o],last:[i,r]})}}function I(d){return F(d).includes("abbreviation")?v(d.getAttribute("title")??"",!0).trim():""}function U(d,t,e){const s=Object.entries(t??{}).map(([o,i])=>` ${o}="${B(i)}"`).join("");return`<${d}${s}>${W(e)}</${d}>`}const Tt=/<body[\s>]/i;function Bt(d,t,e){const{predicate:s,leafText:o,domRange:i,textFragment:r}=ct(e?.textrefs);if(typeof d!="string"){const g=t??(d.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),p=new f(g==="application/xhtml+xml");return p.selectorPredicate=s,p.leafTextEnabled=o,p.domRangeEnabled=i,p.textFragmentEnabled=r,p.docRoot=d.ownerDocument,p.baseHref=e?.href,p.selectorRoot=d,p.selectorRootAnchor=ot(d),p.convert(d),p.result()}let a=t??tt(d),b=new DOMParser().parseFromString(d,a);if(a==="application/xhtml+xml"){const g=b.getElementsByTagNameNS("*","parsererror")[0];if(g){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${g.textContent?.trim()??""}`);a="text/html",b=new DOMParser().parseFromString(d,a)}}const c=new f(a==="application/xhtml+xml");c.selectorPredicate=s,c.leafTextEnabled=o,c.textFragmentEnabled=r,c.docRoot=b,c.baseHref=e?.href;const h=b.querySelector("body");return h&&!Tt.test(d)?c.convertChildren(h):c.convert(h??b.documentElement),c.result()}export{f as Converter,Bt as parseMarkup};
|
package/dist/elementHandlers.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ssmlAttrEscape as
|
|
1
|
+
import{ssmlAttrEscape as C}from"@readium/helpers";import{normalizedNodeText as u}from"./a11y.js";import{normalizeWhitespace as k,textIsEmpty as A}from"./text.js";import{ariaSubstitutedBuilders as m,substitutedOwnSelectorBuilders as j,isHoistable as E}from"./object.js";import{hasElementChild as S,isAncestorOf as g}from"./dom.js";import{nodeLanguage as B}from"./language.js";import{selectorForElement as p,textrefForSelector as I}from"./selectorGenerator.js";import{decodeIdFragment as x}from"./textrefFragment.js";function H(t,e,i,o,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:o},m.add(n));const s=!!(n.text&&!A(n.text)),l=!t.xmlParsed&&(S(e)||s&&e.firstChild!==null);if(!s&&!l){const{text:f,language:h}=u(e);f&&(n.text={plain:f,ssml:"",language:h})}const r=p(e,t.selectorRoot,t.selectorRootAnchor),a=I(r,e);return a&&(n.textref=a),t.placeholder(e,"pagebreak",n),l}function M(t,e,i){const o={role:i},{text:c,language:n}=u(e);c&&(o.text={plain:c,ssml:"",language:n});const d=e.getAttribute("href")??"",s=d.startsWith("#")?x(d)??d.slice(1):void 0;let l=e.getAttribute("id")??"";if(!l&&s!==void 0){const r=t.ids.get(s);(!r||t.suppressed.has(r))&&(l=s)}if(s!==void 0){const r=t.ids.get(s);if(r&&!g(r,e)&&t.noterefDepth<3){const a=t.spawnChild(r);a.convert(r);const f=a.resultBuilders();if(f.length>0){for(const h of f)delete h.id;o.children=f}}}!o.children&&d&&(o.children=[{textref:d}]),t.placeholder(e,"noteref",o,{candidateID:l||void 0})}function P(t,e,i,o,c){const{obj:n,words:d}=b(t,e,i,o,c);t.placeholder(e,i[0]??"link",n,{words:i.includes("backlink")?void 0:d})}function T(t,e,i,o,c){const{obj:n,words:d}=b(t,e,i,o,c),s=e.getAttribute("href")??"";if(s.startsWith("#")){const l=t.ids.get(x(s)??s.slice(1));if(l&&!g(l,e)&&t.noterefDepth<3){const r=D(l).flatMap(a=>{const f=t.spawnChild(a);return f.copy=!0,f.convert(a),f.resultBuilders()});w(r),r.length>0&&(n.children=[...n.children??[],...r])}}t.placeholder(e,i[0],n,{words:d})}function b(t,e,i,o,c){const n={};i.length>0&&(n.role=i);const d=o?[{kind:"text",text:o}]:[];if(o){n.text={plain:o,ssml:"",language:c},m.add(n);const s=p(e,t.selectorRoot,t.selectorRootAnchor);s&&j.set(n,s)}else{const s=t.spawnChild(e,0);s.words=d,s.convertChildren(e);const l=s.resultBuilders();l.length===1&&l[0].text&&E(l[0])?(n.text=l[0].text,l[0].children&&(n.children=l[0].children)):l.length>0&&(n.children=l)}return{obj:n,words:d}}function w(t,e){for(const i of t)(i.id===void 0||!e?.text?.ssml.includes(`id="${C(i.id)}"`))&&delete i.id,i.children&&w(i.children,i)}function D(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 o=[];for(;i&&i.tagName.toLowerCase()==="dd";i=i.nextElementSibling)o.push(i);return o.length>0?[e,...o]:[t]}export{P as link,M as noteref,H as pagebreak,T as reference};
|
package/dist/emptyPairs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{startsWithBindingPunct as
|
|
1
|
+
import{startsWithBindingPunct as A}from"@readium/helpers";const d="\0",R="()[]{}()[]{}「」『』【】〔〕〈〉《》",S=`""''`,p={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":"「」『』"},P=/[\s-,;、,\u0000]/,k=new Map;function m(s){const o=s?.toLowerCase()??"";let r=k.get(o);if(r)return r;const l=R+S+(p[o]??p[o.split("-")[0]]??p.en);r={pairs:new Set,opening:new Set,closing:new Set};for(let n=0;n<l.length;n+=2)r.pairs.add(l[n]+l[n+1]),r.opening.add(l[n]),r.closing.add(l[n+1]);return k.set(o,r),r}function v(s,o){return!A(s)||o?.toLowerCase().split("-")[0]==="fr"&&"»;:!?".includes(s[0])?!1:!(m(o).opening.has(s[0])&&s.length>1&&!/[\s\p{P}]/u.test(s[1]))}function O(s,o){const{pairs:r,opening:l,closing:n}=m(o);let t=s;const h=Array.from({length:s.length},(c,e)=>[e]);for(let c=t.indexOf(d);c!==-1;c=t.indexOf(d,c+1)){let e=c,i=c+1;for(;e>0&&P.test(t[e-1]);)e--;for(;i<t.length&&P.test(t[i]);)i++;const f=t[e-1],a=t[i];f===void 0||a===void 0||!r.has(f+a)||n.has(f)&&e>1&&!/[\s\p{Ps}\p{Pi}\p{Pd}]/u.test(t[e-2])||l.has(a)&&i<t.length-1&&!/[\s\p{P}]/u.test(t[i+1])||(t=t.slice(0,e-1)+d+t.slice(i+1),h.splice(e-1,i-e+2,h.slice(e-1,i+1).flat()),c=e-2)}const g=new Array(s.length).fill(!1);for(const c of t.matchAll(/ *\u0000[\u0000 ]*/g)){const e=c.index,i=e+c[0].length,f=t.slice(i),a=e>0&&f!==""&&c[0].includes(" ")&&!v(f,o)?t.indexOf(" ",e):-1;for(let u=e;u<i;u++)if(u!==a)for(const w of h[u])g[w]=!0}return g}function E(s,o){const r=O(s,o);let l="";for(let n=0;n<s.length;n++)r[n]||(l+=s[n]);return l}export{d as DROPPED,v as bindsToPrevious,O as droppedMask,E as removeDropped};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{makeGnd as r}from"./makeGnd.js";import{parseMarkup as m}from"./converter.js";import{combineDomRangeTextrefs as
|
|
1
|
+
import{makeGnd as r}from"./makeGnd.js";import{parseMarkup as m}from"./converter.js";import{combineDomRangeTextrefs as a,decodeCssSelectorFragment as n,decodeDomRangeFragment as p,decodeTextref as s,encodeCssSelectorFragment as c,encodeDomRangeFragment as x}from"./textrefFragment.js";import{isAriaSubstituted as g,substitutedOwnSelector as D}from"./object.js";import{extractNodeRoles as u}from"./roles.js";import{DROPPED as l,droppedMask as F,removeDropped as S}from"./emptyPairs.js";export{l as DROPPED,a as combineDomRangeTextrefs,n as decodeCssSelectorFragment,p as decodeDomRangeFragment,s as decodeTextref,F as droppedMask,c as encodeCssSelectorFragment,x as encodeDomRangeFragment,u as extractNodeRoles,g as isAriaSubstituted,r as makeGnd,m as parseMarkup,S as removeDropped,D as substitutedOwnSelector};
|
package/dist/object.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GuidedNavigationObject as h,GuidedNavigationDescription as u,GuidedNavigationText as g}from"@readium/shared";import{nonSelfNestingRoles as p}from"./roles.js";import{textIsEmpty 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 l,finalizeText as x}from"./text.js";function z(e,n,t){e.description=n,e.descriptionLanguage=t}const v=["math","separator"],f=new WeakSet,a=new WeakSet,m=new WeakMap,o=new WeakMap;function C(e){return a.has(e)}function G(e){return o.get(e)}function c(e){return e.role?.some(n=>v.includes(n))?!1:!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||l(e.text))&&!(e.children&&e.children.length>0)&&!e.description}function b(e){return!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||l(e.text))&&!!(e.children&&e.children.length>0)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description}function w(e){return!f.has(e)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class R{constructor(){this.object={},this.children=[],this.noText=!1,this.hasChildBlock=!1}finalize(n){const t=this.object,d=[];for(const i of this.children){const r=i.finalize(n);if(!c(r)){if(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],r=t.role;i.role=i.role?.filter(s=>!(p.has(s)&&r.includes(s))),i.role?.length||delete i.role}if((!t.text||l(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&&!c(t)&&!S(t)){const i=n(this.el);i&&(t.textref=i)}return 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 N(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(N):void 0,description:e.description?new u({text:new g({plain:e.description,language:e.descriptionLanguage||void 0})}):void 0});f.has(e)&&a.add(n);const t=m.get(e);return t&&o.set(n,t),n}export{R as NavObject,f as ariaSubstitutedBuilders,N as finalizeToGuidedNavigationObject,C as isAriaSubstituted,c as isEmptyObj,w as isHoistable,z as setDescription,G as substitutedOwnSelector,m as substitutedOwnSelectorBuilders};
|
package/dist/roles.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const p=["heading1","heading2","heading3","heading4","heading5","heading6"],
|
|
1
|
+
const p=["heading1","heading2","heading3","heading4","heading5","heading6"],c={"doc-abstract":"abstract","doc-acknowledgments":"acknowledgments","doc-afterword":"afterword","doc-appendix":"appendix",article:"article","doc-backlink":"backlink","doc-biblioentry":"listItem","doc-bibliography":"bibliography","doc-biblioref":"biblioref",blockquote:"blockquote",caption:"caption",cell:"cell","doc-chapter":"chapter","doc-colophon":"colophon",columnheader:"columnheader",complementary:"complementary","doc-conclusion":"conclusion","doc-cover":"cover","doc-credit":"credit","doc-credits":"credits","doc-dedication":"dedication",definition:"definition","doc-endnote":"footnote","doc-endnotes":"endnotes","doc-epigraph":"epigraph","doc-epilogue":"epilogue","doc-errata":"errata","doc-example":"example",figure:"figure","doc-footnote":"footnote","doc-foreword":"foreword","doc-glossary":"glossary","doc-glossref":"glossref",img:"image",image:"image","doc-index":"index","doc-introduction":"introduction",list:"list",listitem:"listItem",main:"main",math:"math",navigation:"navigation","doc-noteref":"noteref","doc-notice":"notice","doc-pagebreak":"pagebreak","doc-pagelist":"pagelist",paragraph:"paragraph","doc-part":"part","doc-preface":"preface","doc-prologue":"prologue","doc-pullquote":"pullquote",grid:"table",gridcell:"cell",presentation:"presentation",none:"presentation","doc-qna":"qna",qna:"qna",region:"region",row:"row",rowheader:"rowheader",separator:"separator","doc-subtitle":"subtitle",table:"table",term:"term","doc-tip":"tip","doc-toc":"toc"},g={abstract:"abstract",acknowledgments:"acknowledgments",afterword:"afterword",appendix:"appendix",aside:"aside",backlink:"backlink",balloon:"bubble",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",panel:"panel","panel-group":"panelGroup",pagelist:"pagelist",part:"part",preface:"preface",prologue:"prologue",pullquote:"pullquote",qna:"qna","sound-area":"sound","table-row":"row",subtitle:"subtitle",table:"table",glossterm:"term",tip:"tip",toc:"toc"},f={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","bubble","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","panel","paragraph","preface","prologue","pullquote","row","rowheader","sound","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 n of a.split(/\s+/).filter(Boolean))if((n==="presentation"||n==="none")&&(t=!0),n==="heading"){let r=2;const s=parseInt(e.getAttribute("aria-level")??"",10);Number.isFinite(s)&&s>=1&&(r=Math.min(s,6)),o.push(p[r-1])}else c[n]&&o.push(c[n]);const i=e.getAttribute("epub:type");if(i)for(const n of i.split(/\s+/).filter(Boolean)){const r=g[n];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:i}=u(e),n=e.tagName.toLowerCase();if(i)return["presentation"];if(w(e,n))return["presentation"];if(n==="body")t("body");else if(n==="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=f[n];r&&t(r)}for(const r of a)t(r);return o}export{R as extractNodeRoles,E as hasExplicitRole,x as nonSelfNestingRoles};
|
package/dist/textrefFragment.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const l="#css(";function
|
|
1
|
+
const l="#css(";function U(e){return`${l}${encodeURIComponent(e)})`}function x(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 I(e){if(!(!e||!e.startsWith(m)||!e.endsWith(g)))try{const n=JSON.parse(decodeURIComponent(e.slice(m.length,-g.length)));return!n?.start?.cssSelector||typeof n.start.textNodeIndex!="number"?void 0:n}catch{return}}const h=":~:text=";function a(e){return encodeURIComponent(e).replace(/-/g,"%2D")}function p(e){let n="";return e.prefix&&(n+=`${a(e.prefix)}-,`),n+=a(e.textStart),e.textEnd&&(n+=`,${a(e.textEnd)}`),e.suffix&&(n+=`,-${a(e.suffix)}`),`${h}${n}`}function F(e){if(!e)return;const n=e.indexOf(h);if(n===-1)return;const o=e.slice(n+h.length).split("&")[0];if(o)try{let t=o.split(",");const i={textStart:""};return t[0].endsWith("-")&&(i.prefix=decodeURIComponent(t[0].slice(0,-1)),t=t.slice(1)),t.length>0&&t[t.length-1].startsWith("-")&&(i.suffix=decodeURIComponent(t[t.length-1].slice(1)),t=t.slice(0,-1)),t.length===0||t[0]===""?void 0:(i.textStart=decodeURIComponent(t[0]),t.length>1&&(i.textEnd=decodeURIComponent(t[1])),i)}catch{return}}function E(e,n){if(!e.domRange||!n.domRange||e.href!==n.href)return;const o={start:e.domRange.start,end:n.domRange.end??n.domRange.start};e.domRange.container!==void 0&&(o.container=e.domRange.container);const t={domRange:o,cssSelector:o.container??o.start.cssSelector};return e.href!==void 0&&(t.href=e.href),t}function C(e){if(e.startsWith("#"))try{return decodeURIComponent(e.slice(1))}catch{return}}function D(e){const n=e?.textref;if(!n)return;const o=n.indexOf(":~:"),t=o===-1?n:n.slice(0,o),i=t.indexOf("#"),S=i===-1?t:t.slice(0,i),u=i===-1?"":t.slice(i);let d,s;const f=I(u);if(f)s=f,d=f.container??f.start.cssSelector;else{const R=x(u);if(R!==void 0)d=R;else{const v=C(u);v&&(d=`#${CSS.escape(v)}`)}}const r=F(n);if(d===void 0&&s===void 0&&r===void 0)return;const c={};return S!==""&&(c.href=S),d!==void 0&&(c.cssSelector=d),s!==void 0&&(c.domRange=s),r?.textEnd!==void 0?c.fragment=p(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,x as decodeCssSelectorFragment,I as decodeDomRangeFragment,C as decodeIdFragment,F as decodeTextFragmentDirective,D as decodeTextref,U as encodeCssSelectorFragment,$ as encodeDomRangeFragment,p as encodeTextFragmentDirective};
|
package/fixtures/README.md
CHANGED
|
@@ -130,12 +130,12 @@ Roles whose roles.md definition is "a list of links to X" or "a collection
|
|
|
130
130
|
of X" (`landmarks`, `loa`, `loi`, `lot`, `lov`, `pagelist`, `toc`, `index`,
|
|
131
131
|
`bibliography`, `glossary`, `endnotes`, `credits`) are modeled as an actual
|
|
132
132
|
`list`/`listItem` structure, not a flat text blob — because that's what they
|
|
133
|
-
are. A `listItem`
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
are. A `listItem` holding a link carries the link's visible `text`; the
|
|
134
|
+
link's destination isn't kept, since a `textref` always references the
|
|
135
|
+
object's own content:
|
|
136
136
|
|
|
137
137
|
```jsonc
|
|
138
|
-
{ "role": ["listItem"], "text": { "plain": "Cover" }
|
|
138
|
+
{ "role": ["listItem"], "text": { "plain": "Cover" } }
|
|
139
139
|
```
|
|
140
140
|
|
|
141
141
|
## `manifest.json`
|
|
@@ -21,6 +21,7 @@ renaming, or removing a fixture.
|
|
|
21
21
|
| `biblioref` | `biblioref-epub-type`, `biblioref-role-aria`, `biblioref-target-descendant-ids`, `biblioref-target-in-bibliography-role-aria`, `biblioref-target-mixed-content` |
|
|
22
22
|
| `blockquote` | `blockquote-html-native`, `blockquote-role-aria`, `nested-blockquote` |
|
|
23
23
|
| `body` | `body-html-native` |
|
|
24
|
+
| `bubble` | `bubble-epub-type` |
|
|
24
25
|
| `chapter` | `chapter-epub-type`, `chapter-role-aria`, `redundant-role-body-chapter`, `redundant-role-nested-chapter` |
|
|
25
26
|
| `colophon` | `colophon-epub-type`, `colophon-role-aria` |
|
|
26
27
|
| `complementary` | `complementary-role-aria` |
|
|
@@ -37,7 +38,7 @@ renaming, or removing a fixture.
|
|
|
37
38
|
| `epilogue` | `epilogue-epub-type`, `epilogue-role-aria` |
|
|
38
39
|
| `errata` | `errata-epub-type`, `errata-role-aria` |
|
|
39
40
|
| `example` | `example-epub-type`, `example-role-aria` |
|
|
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` |
|
|
41
|
+
| `figure` | `figure-aria-label-caption`, `figure-basic-html-native`, `figure-basic-role-aria`, `figure-caption-block-content`, `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` |
|
|
41
42
|
| `footnote` | `footnote-epub-type`, `footnote-role-aria`, `noteref-target-in-endnotes-epub-type`, `noteref-target-in-endnotes-role-aria` |
|
|
42
43
|
| `foreword` | `foreword-epub-type`, `foreword-role-aria` |
|
|
43
44
|
| `glossary` | `glossary-epub-type`, `glossary-role-aria` |
|
|
@@ -62,6 +63,8 @@ renaming, or removing a fixture.
|
|
|
62
63
|
| `notice` | `notice-epub-type`, `notice-role-aria` |
|
|
63
64
|
| `pagebreak` | `language-pagebreak-label`, `pagebreak-epub-type`, `pagebreak-role-aria` |
|
|
64
65
|
| `pagelist` | `pagelist-epub-type`, `pagelist-role-aria` |
|
|
66
|
+
| `panel` | `panel-epub-type`, `panel-object-role-img`, `panel-role-img-labelled`, `panel-svg-epub-type` |
|
|
67
|
+
| `panelGroup` | `panel-group-epub-type` |
|
|
65
68
|
| `paragraph` | `paragraph-basic` |
|
|
66
69
|
| `part` | `part-epub-type`, `part-role-aria` |
|
|
67
70
|
| `preface` | `preface-epub-type`, `preface-role-aria` |
|
|
@@ -73,12 +76,13 @@ renaming, or removing a fixture.
|
|
|
73
76
|
| `region` | `region-role-aria` |
|
|
74
77
|
| `section` | `nested-section`, `section-html-native` |
|
|
75
78
|
| `separator` | `separator-html-native`, `separator-role-aria`, `separator-with-glyphs` |
|
|
79
|
+
| `sound` | `sound-epub-type` |
|
|
76
80
|
| `subtitle` | `subtitle-epub-type`, `subtitle-role-aria` |
|
|
77
81
|
| `summary` | `summary-html-native` |
|
|
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` |
|
|
82
|
+
| `table` | `table-aria-label-caption`, `table-caption`, `table-caption-aria-labelledby`, `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` |
|
|
79
83
|
| `term` | `term-epub-type`, `term-html-native`, `term-role-aria`, `term-span-in-dt` |
|
|
80
84
|
| `tip` | `tip-epub-type`, `tip-role-aria` |
|
|
81
85
|
| `toc` | `toc-epub-type`, `toc-role-aria` |
|
|
82
86
|
| `video` | `video-html-native`, `video-no-description` |
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
270 fixtures across 77 roles.
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"World Health Organization\">WHO</sub> <emphasis>said</emphasis> so."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
+
"role": ["paragraph"],
|
|
3
|
+
"text": {
|
|
4
|
+
"language": "en",
|
|
5
|
+
"plain": "The WHO said so.",
|
|
6
|
+
"ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> <emphasis>said</emphasis> so."
|
|
7
|
+
},
|
|
2
8
|
"children": [
|
|
3
9
|
{
|
|
10
|
+
"role": ["image"],
|
|
4
11
|
"id": "image1",
|
|
5
|
-
"imgref": "logo.png",
|
|
6
|
-
"role": [
|
|
7
|
-
"image"
|
|
8
|
-
],
|
|
9
12
|
"description": {
|
|
10
13
|
"text": {
|
|
11
14
|
"plain": "logo"
|
|
12
15
|
}
|
|
13
|
-
}
|
|
16
|
+
},
|
|
17
|
+
"imgref": "logo.png"
|
|
14
18
|
}
|
|
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
|
-
}
|
|
19
|
+
]
|
|
24
20
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <lang xml:lang=\"fr\"><sub alias=\"Organisation mondiale de la santé\">OMS</sub></lang> said."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"United States of America\">USA</sub> today."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"children": [
|
|
6
4
|
{
|
|
7
|
-
"role": [
|
|
8
|
-
"term"
|
|
9
|
-
],
|
|
5
|
+
"role": ["term"],
|
|
10
6
|
"text": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
7
|
+
"language": "en",
|
|
8
|
+
"ssml": "<sub alias=\"World Health Organization\">WHO</sub>"
|
|
13
9
|
}
|
|
14
10
|
},
|
|
15
11
|
{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"role": ["paragraph"],
|
|
2
3
|
"children": [
|
|
3
4
|
{
|
|
4
5
|
"text": {
|
|
@@ -6,12 +7,10 @@
|
|
|
6
7
|
}
|
|
7
8
|
},
|
|
8
9
|
{
|
|
9
|
-
"role": [
|
|
10
|
-
"term"
|
|
11
|
-
],
|
|
10
|
+
"role": ["term"],
|
|
12
11
|
"text": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
12
|
+
"language": "en",
|
|
13
|
+
"ssml": "<sub alias=\"Doctor\">Dr.</sub>"
|
|
15
14
|
}
|
|
16
15
|
},
|
|
17
16
|
{
|
|
@@ -19,8 +18,5 @@
|
|
|
19
18
|
"plain": "Watson."
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
|
-
],
|
|
23
|
-
"role": [
|
|
24
|
-
"paragraph"
|
|
25
21
|
]
|
|
26
22
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "The <sub alias=\"World Health Organization\">W.H.O.</sub> said."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"text": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"language": "en",
|
|
5
|
+
"ssml": "She joined the <sub alias=\"World Health Organization\">W.H.O.</sub> Then she left."
|
|
8
6
|
}
|
|
9
7
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"role": [
|
|
3
|
-
"paragraph"
|
|
4
|
-
],
|
|
2
|
+
"role": ["paragraph"],
|
|
5
3
|
"children": [
|
|
6
4
|
{
|
|
7
|
-
"role": [
|
|
8
|
-
"term"
|
|
9
|
-
],
|
|
5
|
+
"role": ["term"],
|
|
10
6
|
"text": {
|
|
11
7
|
"plain": "A"
|
|
12
8
|
}
|
|
@@ -17,9 +13,7 @@
|
|
|
17
13
|
}
|
|
18
14
|
},
|
|
19
15
|
{
|
|
20
|
-
"role": [
|
|
21
|
-
"term"
|
|
22
|
-
],
|
|
16
|
+
"role": ["term"],
|
|
23
17
|
"text": {
|
|
24
18
|
"plain": "B"
|
|
25
19
|
}
|