@readium/guided-navigation 1.0.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/LICENSE +28 -0
- package/README.md +157 -0
- package/dist/a11y.js +1 -0
- package/dist/converter.js +1 -0
- package/dist/dom.js +1 -0
- package/dist/domRangeGenerator.js +1 -0
- package/dist/elementHandlers.js +1 -0
- package/dist/idAllocator.js +1 -0
- package/dist/index.js +1 -0
- package/dist/makeGnd.js +1 -0
- package/dist/object.js +1 -0
- package/dist/options.js +1 -0
- package/dist/prescan.js +1 -0
- package/dist/roles.js +1 -0
- package/dist/selectorGenerator.js +1 -0
- package/dist/text.js +1 -0
- package/dist/textFragmentGenerator.js +1 -0
- package/dist/textrefFragment.js +1 -0
- package/fixtures/README.md +185 -0
- package/fixtures/ROLES_COVERAGE.md +80 -0
- package/fixtures/abstract-epub-type/gnd.json +15 -0
- package/fixtures/abstract-epub-type/input.xhtml +11 -0
- package/fixtures/abstract-epub-type/meta.json +10 -0
- package/fixtures/abstract-role-aria/gnd.json +8 -0
- package/fixtures/abstract-role-aria/input.html +1 -0
- package/fixtures/abstract-role-aria/meta.json +10 -0
- package/fixtures/acknowledgments-epub-type/gnd.json +15 -0
- package/fixtures/acknowledgments-epub-type/input.xhtml +11 -0
- package/fixtures/acknowledgments-epub-type/meta.json +10 -0
- package/fixtures/acknowledgments-role-aria/gnd.json +8 -0
- package/fixtures/acknowledgments-role-aria/input.html +1 -0
- package/fixtures/acknowledgments-role-aria/meta.json +10 -0
- package/fixtures/afterword-epub-type/gnd.json +15 -0
- package/fixtures/afterword-epub-type/input.xhtml +11 -0
- package/fixtures/afterword-epub-type/meta.json +10 -0
- package/fixtures/afterword-role-aria/gnd.json +8 -0
- package/fixtures/afterword-role-aria/input.html +1 -0
- package/fixtures/afterword-role-aria/meta.json +10 -0
- package/fixtures/appendix-epub-type/gnd.json +16 -0
- package/fixtures/appendix-epub-type/input.xhtml +11 -0
- package/fixtures/appendix-epub-type/meta.json +10 -0
- package/fixtures/appendix-role-aria/gnd.json +8 -0
- package/fixtures/appendix-role-aria/input.html +1 -0
- package/fixtures/appendix-role-aria/meta.json +10 -0
- package/fixtures/article-html-native/gnd.json +8 -0
- package/fixtures/article-html-native/input.html +1 -0
- package/fixtures/article-html-native/meta.json +10 -0
- package/fixtures/article-role-aria/gnd.json +8 -0
- package/fixtures/article-role-aria/input.html +1 -0
- package/fixtures/article-role-aria/meta.json +10 -0
- package/fixtures/aside-epub-type/gnd.json +15 -0
- package/fixtures/aside-epub-type/input.xhtml +11 -0
- package/fixtures/aside-epub-type/meta.json +10 -0
- package/fixtures/aside-html-native/gnd.json +8 -0
- package/fixtures/aside-html-native/input.html +1 -0
- package/fixtures/aside-html-native/meta.json +10 -0
- package/fixtures/audio-html-native/gnd.json +11 -0
- package/fixtures/audio-html-native/input.html +1 -0
- package/fixtures/audio-html-native/meta.json +10 -0
- package/fixtures/audio-no-description/gnd.json +6 -0
- package/fixtures/audio-no-description/input.html +1 -0
- package/fixtures/audio-no-description/meta.json +10 -0
- package/fixtures/backlink-epub-type/gnd.json +16 -0
- package/fixtures/backlink-epub-type/input.xhtml +11 -0
- package/fixtures/backlink-epub-type/meta.json +10 -0
- package/fixtures/backlink-role-aria/gnd.json +9 -0
- package/fixtures/backlink-role-aria/input.html +1 -0
- package/fixtures/backlink-role-aria/meta.json +10 -0
- package/fixtures/bibliography-epub-type/gnd.json +38 -0
- package/fixtures/bibliography-epub-type/input.xhtml +16 -0
- package/fixtures/bibliography-epub-type/meta.json +12 -0
- package/fixtures/bibliography-role-aria/gnd.json +30 -0
- package/fixtures/bibliography-role-aria/input.html +6 -0
- package/fixtures/bibliography-role-aria/meta.json +12 -0
- package/fixtures/biblioref-epub-type/gnd.json +16 -0
- package/fixtures/biblioref-epub-type/input.xhtml +11 -0
- package/fixtures/biblioref-epub-type/meta.json +10 -0
- package/fixtures/biblioref-role-aria/gnd.json +9 -0
- package/fixtures/biblioref-role-aria/input.html +1 -0
- package/fixtures/biblioref-role-aria/meta.json +10 -0
- package/fixtures/blockquote-html-native/gnd.json +8 -0
- package/fixtures/blockquote-html-native/input.html +1 -0
- package/fixtures/blockquote-html-native/meta.json +10 -0
- package/fixtures/blockquote-role-aria/gnd.json +8 -0
- package/fixtures/blockquote-role-aria/input.html +1 -0
- package/fixtures/blockquote-role-aria/meta.json +10 -0
- package/fixtures/body-html-native/gnd.json +8 -0
- package/fixtures/body-html-native/input.html +1 -0
- package/fixtures/body-html-native/meta.json +10 -0
- package/fixtures/chapter-epub-type/gnd.json +23 -0
- package/fixtures/chapter-epub-type/input.xhtml +13 -0
- package/fixtures/chapter-epub-type/meta.json +11 -0
- package/fixtures/chapter-role-aria/gnd.json +16 -0
- package/fixtures/chapter-role-aria/input.html +3 -0
- package/fixtures/chapter-role-aria/meta.json +11 -0
- package/fixtures/colophon-epub-type/gnd.json +15 -0
- package/fixtures/colophon-epub-type/input.xhtml +11 -0
- package/fixtures/colophon-epub-type/meta.json +10 -0
- package/fixtures/colophon-role-aria/gnd.json +8 -0
- package/fixtures/colophon-role-aria/input.html +1 -0
- package/fixtures/colophon-role-aria/meta.json +10 -0
- package/fixtures/complementary-role-aria/gnd.json +8 -0
- package/fixtures/complementary-role-aria/input.html +1 -0
- package/fixtures/complementary-role-aria/meta.json +10 -0
- package/fixtures/conclusion-epub-type/gnd.json +15 -0
- package/fixtures/conclusion-epub-type/input.xhtml +11 -0
- package/fixtures/conclusion-epub-type/meta.json +10 -0
- package/fixtures/conclusion-role-aria/gnd.json +8 -0
- package/fixtures/conclusion-role-aria/input.html +1 -0
- package/fixtures/conclusion-role-aria/meta.json +10 -0
- package/fixtures/cover-epub-type/gnd.json +26 -0
- package/fixtures/cover-epub-type/input.xhtml +13 -0
- package/fixtures/cover-epub-type/meta.json +10 -0
- package/fixtures/cover-role-aria/gnd.json +12 -0
- package/fixtures/cover-role-aria/input.html +1 -0
- package/fixtures/cover-role-aria/meta.json +10 -0
- package/fixtures/credit-epub-type/gnd.json +22 -0
- package/fixtures/credit-epub-type/input.xhtml +11 -0
- package/fixtures/credit-epub-type/meta.json +10 -0
- package/fixtures/credit-role-aria/gnd.json +8 -0
- package/fixtures/credit-role-aria/input.html +1 -0
- package/fixtures/credit-role-aria/meta.json +10 -0
- package/fixtures/credits-epub-type/gnd.json +51 -0
- package/fixtures/credits-epub-type/input.xhtml +16 -0
- package/fixtures/credits-epub-type/meta.json +13 -0
- package/fixtures/credits-role-aria/gnd.json +32 -0
- package/fixtures/credits-role-aria/input.html +6 -0
- package/fixtures/credits-role-aria/meta.json +13 -0
- package/fixtures/dedication-epub-type/gnd.json +15 -0
- package/fixtures/dedication-epub-type/input.xhtml +11 -0
- package/fixtures/dedication-epub-type/meta.json +10 -0
- package/fixtures/dedication-role-aria/gnd.json +8 -0
- package/fixtures/dedication-role-aria/input.html +1 -0
- package/fixtures/dedication-role-aria/meta.json +10 -0
- package/fixtures/definition-epub-type/gnd.json +22 -0
- package/fixtures/definition-epub-type/input.xhtml +13 -0
- package/fixtures/definition-epub-type/meta.json +11 -0
- package/fixtures/definition-html-native/gnd.json +8 -0
- package/fixtures/definition-html-native/input.html +3 -0
- package/fixtures/definition-html-native/meta.json +10 -0
- package/fixtures/definition-role-aria/gnd.json +8 -0
- package/fixtures/definition-role-aria/input.html +1 -0
- package/fixtures/definition-role-aria/meta.json +10 -0
- package/fixtures/details-html-native/gnd.json +8 -0
- package/fixtures/details-html-native/input.html +1 -0
- package/fixtures/details-html-native/meta.json +10 -0
- package/fixtures/details-summary-html-native/gnd.json +20 -0
- package/fixtures/details-summary-html-native/input.html +4 -0
- package/fixtures/details-summary-html-native/meta.json +11 -0
- package/fixtures/endnotes-epub-type/gnd.json +56 -0
- package/fixtures/endnotes-epub-type/input.xhtml +16 -0
- package/fixtures/endnotes-epub-type/meta.json +13 -0
- package/fixtures/endnotes-role-aria/gnd.json +34 -0
- package/fixtures/endnotes-role-aria/input.html +6 -0
- package/fixtures/endnotes-role-aria/meta.json +13 -0
- package/fixtures/epigraph-epub-type/gnd.json +15 -0
- package/fixtures/epigraph-epub-type/input.xhtml +11 -0
- package/fixtures/epigraph-epub-type/meta.json +10 -0
- package/fixtures/epigraph-role-aria/gnd.json +8 -0
- package/fixtures/epigraph-role-aria/input.html +1 -0
- package/fixtures/epigraph-role-aria/meta.json +10 -0
- package/fixtures/epilogue-epub-type/gnd.json +15 -0
- package/fixtures/epilogue-epub-type/input.xhtml +11 -0
- package/fixtures/epilogue-epub-type/meta.json +10 -0
- package/fixtures/epilogue-role-aria/gnd.json +8 -0
- package/fixtures/epilogue-role-aria/input.html +1 -0
- package/fixtures/epilogue-role-aria/meta.json +10 -0
- package/fixtures/errata-epub-type/gnd.json +15 -0
- package/fixtures/errata-epub-type/input.xhtml +11 -0
- package/fixtures/errata-epub-type/meta.json +10 -0
- package/fixtures/errata-role-aria/gnd.json +8 -0
- package/fixtures/errata-role-aria/input.html +1 -0
- package/fixtures/errata-role-aria/meta.json +10 -0
- package/fixtures/example-epub-type/gnd.json +30 -0
- package/fixtures/example-epub-type/input.xhtml +15 -0
- package/fixtures/example-epub-type/meta.json +10 -0
- package/fixtures/example-role-aria/gnd.json +8 -0
- package/fixtures/example-role-aria/input.html +1 -0
- package/fixtures/example-role-aria/meta.json +10 -0
- package/fixtures/figure-basic-html-native/gnd.json +18 -0
- package/fixtures/figure-basic-html-native/input.html +3 -0
- package/fixtures/figure-basic-html-native/meta.json +10 -0
- package/fixtures/figure-basic-role-aria/gnd.json +18 -0
- package/fixtures/figure-basic-role-aria/input.html +3 -0
- package/fixtures/figure-basic-role-aria/meta.json +10 -0
- package/fixtures/figure-caption-element-html-native/gnd.json +11 -0
- package/fixtures/figure-caption-element-html-native/input.html +11 -0
- package/fixtures/figure-caption-element-html-native/meta.json +11 -0
- package/fixtures/figure-caption-element-role-aria/gnd.json +11 -0
- package/fixtures/figure-caption-element-role-aria/input.html +11 -0
- package/fixtures/figure-caption-element-role-aria/meta.json +11 -0
- package/fixtures/figure-caption-html-native/gnd.json +11 -0
- package/fixtures/figure-caption-html-native/input.html +11 -0
- package/fixtures/figure-caption-html-native/meta.json +11 -0
- package/fixtures/figure-caption-role-aria/gnd.json +11 -0
- package/fixtures/figure-caption-role-aria/input.html +11 -0
- package/fixtures/figure-caption-role-aria/meta.json +11 -0
- package/fixtures/figure-credit-nested-in-aria-labelledby-caption/gnd.json +39 -0
- package/fixtures/figure-credit-nested-in-aria-labelledby-caption/input.html +4 -0
- package/fixtures/figure-credit-nested-in-aria-labelledby-caption/meta.json +13 -0
- package/fixtures/figure-credit-nested-in-caption/gnd.json +38 -0
- package/fixtures/figure-credit-nested-in-caption/input.html +4 -0
- package/fixtures/figure-credit-nested-in-caption/meta.json +12 -0
- package/fixtures/figure-credit-role-aria/gnd.json +32 -0
- package/fixtures/figure-credit-role-aria/input.html +5 -0
- package/fixtures/figure-credit-role-aria/meta.json +12 -0
- package/fixtures/figure-describedby/gnd.json +23 -0
- package/fixtures/figure-describedby/input.html +4 -0
- package/fixtures/figure-describedby/meta.json +11 -0
- package/fixtures/figure-epub-type/gnd.json +25 -0
- package/fixtures/figure-epub-type/input.xhtml +13 -0
- package/fixtures/figure-epub-type/meta.json +11 -0
- package/fixtures/figure-no-description/gnd.json +13 -0
- package/fixtures/figure-no-description/input.html +3 -0
- package/fixtures/figure-no-description/meta.json +11 -0
- package/fixtures/footnote-epub-type/gnd.json +39 -0
- package/fixtures/footnote-epub-type/input.xhtml +12 -0
- package/fixtures/footnote-epub-type/meta.json +11 -0
- package/fixtures/footnote-role-aria/gnd.json +50 -0
- package/fixtures/footnote-role-aria/input.html +5 -0
- package/fixtures/footnote-role-aria/meta.json +12 -0
- package/fixtures/foreword-epub-type/gnd.json +15 -0
- package/fixtures/foreword-epub-type/input.xhtml +11 -0
- package/fixtures/foreword-epub-type/meta.json +10 -0
- package/fixtures/foreword-role-aria/gnd.json +8 -0
- package/fixtures/foreword-role-aria/input.html +1 -0
- package/fixtures/foreword-role-aria/meta.json +10 -0
- package/fixtures/glossary-epub-type/gnd.json +46 -0
- package/fixtures/glossary-epub-type/input.xhtml +16 -0
- package/fixtures/glossary-epub-type/meta.json +12 -0
- package/fixtures/glossary-role-aria/gnd.json +49 -0
- package/fixtures/glossary-role-aria/input.html +6 -0
- package/fixtures/glossary-role-aria/meta.json +12 -0
- package/fixtures/glossref-epub-type/gnd.json +16 -0
- package/fixtures/glossref-epub-type/input.xhtml +11 -0
- package/fixtures/glossref-epub-type/meta.json +10 -0
- package/fixtures/glossref-role-aria/gnd.json +9 -0
- package/fixtures/glossref-role-aria/input.html +1 -0
- package/fixtures/glossref-role-aria/meta.json +10 -0
- package/fixtures/glossref-role-aria-mid-sentence/gnd.json +32 -0
- package/fixtures/glossref-role-aria-mid-sentence/input.html +4 -0
- package/fixtures/glossref-role-aria-mid-sentence/meta.json +11 -0
- package/fixtures/header-html-native/gnd.json +8 -0
- package/fixtures/header-html-native/input.html +1 -0
- package/fixtures/header-html-native/meta.json +10 -0
- package/fixtures/heading-html-native/gnd.json +52 -0
- package/fixtures/heading-html-native/input.html +6 -0
- package/fixtures/heading-html-native/meta.json +15 -0
- package/fixtures/heading-role-aria/gnd.json +52 -0
- package/fixtures/heading-role-aria/input.html +6 -0
- package/fixtures/heading-role-aria/meta.json +15 -0
- package/fixtures/heading-role-presentation/gnd.json +28 -0
- package/fixtures/heading-role-presentation/input.html +3 -0
- package/fixtures/heading-role-presentation/meta.json +10 -0
- package/fixtures/hidden-aria-hidden-html-native/gnd.json +20 -0
- package/fixtures/hidden-aria-hidden-html-native/input.html +3 -0
- package/fixtures/hidden-aria-hidden-html-native/meta.json +10 -0
- package/fixtures/hidden-attribute-html-native/gnd.json +20 -0
- package/fixtures/hidden-attribute-html-native/input.html +3 -0
- package/fixtures/hidden-attribute-html-native/meta.json +10 -0
- package/fixtures/image-alt-html-native/gnd.json +11 -0
- package/fixtures/image-alt-html-native/input.html +1 -0
- package/fixtures/image-alt-html-native/meta.json +10 -0
- package/fixtures/image-decorative-empty-alt/gnd.json +20 -0
- package/fixtures/image-decorative-empty-alt/input.html +3 -0
- package/fixtures/image-decorative-empty-alt/meta.json +10 -0
- package/fixtures/image-decorative-role-presentation/gnd.json +20 -0
- package/fixtures/image-decorative-role-presentation/input.html +3 -0
- package/fixtures/image-decorative-role-presentation/meta.json +10 -0
- package/fixtures/image-decorative-whitespace-alt/gnd.json +20 -0
- package/fixtures/image-decorative-whitespace-alt/input.html +3 -0
- package/fixtures/image-decorative-whitespace-alt/meta.json +10 -0
- package/fixtures/image-no-description/gnd.json +6 -0
- package/fixtures/image-no-description/input.html +1 -0
- package/fixtures/image-no-description/meta.json +10 -0
- package/fixtures/image-role-aria/gnd.json +11 -0
- package/fixtures/image-role-aria/input.html +7 -0
- package/fixtures/image-role-aria/meta.json +10 -0
- package/fixtures/index-epub-type/gnd.json +48 -0
- package/fixtures/index-epub-type/input.xhtml +16 -0
- package/fixtures/index-epub-type/meta.json +12 -0
- package/fixtures/index-role-aria/gnd.json +40 -0
- package/fixtures/index-role-aria/input.html +6 -0
- package/fixtures/index-role-aria/meta.json +12 -0
- package/fixtures/introduction-epub-type/gnd.json +15 -0
- package/fixtures/introduction-epub-type/input.xhtml +11 -0
- package/fixtures/introduction-epub-type/meta.json +10 -0
- package/fixtures/introduction-role-aria/gnd.json +8 -0
- package/fixtures/introduction-role-aria/input.html +1 -0
- package/fixtures/introduction-role-aria/meta.json +10 -0
- package/fixtures/landmarks-epub-type/gnd.json +61 -0
- package/fixtures/landmarks-epub-type/input.xhtml +17 -0
- package/fixtures/landmarks-epub-type/meta.json +12 -0
- package/fixtures/language-block/gnd.json +25 -0
- package/fixtures/language-block/input.html +11 -0
- package/fixtures/language-block/meta.json +10 -0
- package/fixtures/language-document/gnd.json +16 -0
- package/fixtures/language-document/input.html +10 -0
- package/fixtures/language-document/meta.json +10 -0
- package/fixtures/language-inline-lang-attribute/gnd.json +9 -0
- package/fixtures/language-inline-lang-attribute/input.html +1 -0
- package/fixtures/language-inline-lang-attribute/meta.json +10 -0
- package/fixtures/language-inline-nested/gnd.json +9 -0
- package/fixtures/language-inline-nested/input.html +1 -0
- package/fixtures/language-inline-nested/meta.json +10 -0
- package/fixtures/language-inline-repeated/gnd.json +9 -0
- package/fixtures/language-inline-repeated/input.html +1 -0
- package/fixtures/language-inline-repeated/meta.json +10 -0
- package/fixtures/language-inline-two-languages/gnd.json +9 -0
- package/fixtures/language-inline-two-languages/input.html +1 -0
- package/fixtures/language-inline-two-languages/meta.json +10 -0
- package/fixtures/list-aria-posinset-setsize/gnd.json +15 -0
- package/fixtures/list-aria-posinset-setsize/input.html +3 -0
- package/fixtures/list-aria-posinset-setsize/meta.json +11 -0
- package/fixtures/list-epub-type/gnd.json +30 -0
- package/fixtures/list-epub-type/input.xhtml +14 -0
- package/fixtures/list-epub-type/meta.json +11 -0
- package/fixtures/list-html-native/gnd.json +31 -0
- package/fixtures/list-html-native/input.html +5 -0
- package/fixtures/list-html-native/meta.json +11 -0
- package/fixtures/list-item-posinset-override/gnd.json +31 -0
- package/fixtures/list-item-posinset-override/input.html +5 -0
- package/fixtures/list-item-posinset-override/meta.json +11 -0
- package/fixtures/list-item-value-override/gnd.json +31 -0
- package/fixtures/list-item-value-override/input.html +5 -0
- package/fixtures/list-item-value-override/meta.json +11 -0
- package/fixtures/list-ordered-html-native/gnd.json +31 -0
- package/fixtures/list-ordered-html-native/input.html +5 -0
- package/fixtures/list-ordered-html-native/meta.json +11 -0
- package/fixtures/list-ordered-reversed/gnd.json +31 -0
- package/fixtures/list-ordered-reversed/input.html +5 -0
- package/fixtures/list-ordered-reversed/meta.json +11 -0
- package/fixtures/list-ordered-start/gnd.json +31 -0
- package/fixtures/list-ordered-start/input.html +5 -0
- package/fixtures/list-ordered-start/meta.json +11 -0
- package/fixtures/list-role-aria/gnd.json +31 -0
- package/fixtures/list-role-aria/input.html +5 -0
- package/fixtures/list-role-aria/meta.json +11 -0
- package/fixtures/listitem-role-presentation/gnd.json +23 -0
- package/fixtures/listitem-role-presentation/input.html +4 -0
- package/fixtures/listitem-role-presentation/meta.json +10 -0
- package/fixtures/loa-epub-type/gnd.json +48 -0
- package/fixtures/loa-epub-type/input.xhtml +16 -0
- package/fixtures/loa-epub-type/meta.json +12 -0
- package/fixtures/loi-epub-type/gnd.json +48 -0
- package/fixtures/loi-epub-type/input.xhtml +16 -0
- package/fixtures/loi-epub-type/meta.json +12 -0
- package/fixtures/lot-epub-type/gnd.json +48 -0
- package/fixtures/lot-epub-type/input.xhtml +16 -0
- package/fixtures/lot-epub-type/meta.json +12 -0
- package/fixtures/lov-epub-type/gnd.json +48 -0
- package/fixtures/lov-epub-type/input.xhtml +16 -0
- package/fixtures/lov-epub-type/meta.json +12 -0
- package/fixtures/main-html-native/gnd.json +8 -0
- package/fixtures/main-html-native/input.html +1 -0
- package/fixtures/main-html-native/meta.json +10 -0
- package/fixtures/main-role-aria/gnd.json +8 -0
- package/fixtures/main-role-aria/input.html +1 -0
- package/fixtures/main-role-aria/meta.json +10 -0
- package/fixtures/manifest.json +1782 -0
- package/fixtures/math-html-native/gnd.json +14 -0
- package/fixtures/math-html-native/input.html +7 -0
- package/fixtures/math-html-native/meta.json +10 -0
- package/fixtures/math-no-description/gnd.json +9 -0
- package/fixtures/math-no-description/input.html +7 -0
- package/fixtures/math-no-description/meta.json +10 -0
- package/fixtures/math-role-aria/gnd.json +14 -0
- package/fixtures/math-role-aria/input.html +1 -0
- package/fixtures/math-role-aria/meta.json +10 -0
- package/fixtures/navigation-html-native/gnd.json +8 -0
- package/fixtures/navigation-html-native/input.html +1 -0
- package/fixtures/navigation-html-native/meta.json +10 -0
- package/fixtures/navigation-role-aria/gnd.json +8 -0
- package/fixtures/navigation-role-aria/input.html +1 -0
- package/fixtures/navigation-role-aria/meta.json +10 -0
- package/fixtures/noteref-role-aria/gnd.json +13 -0
- package/fixtures/noteref-role-aria/input.html +1 -0
- package/fixtures/noteref-role-aria/meta.json +10 -0
- package/fixtures/noteref-target-in-endnotes-epub-type/gnd.json +72 -0
- package/fixtures/noteref-target-in-endnotes-epub-type/input.xhtml +17 -0
- package/fixtures/noteref-target-in-endnotes-epub-type/meta.json +15 -0
- package/fixtures/noteref-target-in-endnotes-role-aria/gnd.json +69 -0
- package/fixtures/noteref-target-in-endnotes-role-aria/input.html +7 -0
- package/fixtures/noteref-target-in-endnotes-role-aria/meta.json +15 -0
- package/fixtures/notice-epub-type/gnd.json +15 -0
- package/fixtures/notice-epub-type/input.xhtml +11 -0
- package/fixtures/notice-epub-type/meta.json +10 -0
- package/fixtures/notice-role-aria/gnd.json +8 -0
- package/fixtures/notice-role-aria/input.html +1 -0
- package/fixtures/notice-role-aria/meta.json +10 -0
- package/fixtures/pagebreak-epub-type/gnd.json +36 -0
- package/fixtures/pagebreak-epub-type/input.xhtml +12 -0
- package/fixtures/pagebreak-epub-type/meta.json +10 -0
- package/fixtures/pagebreak-role-aria/gnd.json +33 -0
- package/fixtures/pagebreak-role-aria/input.html +2 -0
- package/fixtures/pagebreak-role-aria/meta.json +10 -0
- package/fixtures/pagelist-epub-type/gnd.json +61 -0
- package/fixtures/pagelist-epub-type/input.xhtml +17 -0
- package/fixtures/pagelist-epub-type/meta.json +12 -0
- package/fixtures/pagelist-role-aria/gnd.json +54 -0
- package/fixtures/pagelist-role-aria/input.html +7 -0
- package/fixtures/pagelist-role-aria/meta.json +12 -0
- package/fixtures/paragraph-basic/gnd.json +8 -0
- package/fixtures/paragraph-basic/input.html +1 -0
- package/fixtures/paragraph-basic/meta.json +10 -0
- package/fixtures/part-epub-type/gnd.json +23 -0
- package/fixtures/part-epub-type/input.xhtml +13 -0
- package/fixtures/part-epub-type/meta.json +11 -0
- package/fixtures/part-role-aria/gnd.json +16 -0
- package/fixtures/part-role-aria/input.html +3 -0
- package/fixtures/part-role-aria/meta.json +11 -0
- package/fixtures/preface-epub-type/gnd.json +15 -0
- package/fixtures/preface-epub-type/input.xhtml +11 -0
- package/fixtures/preface-epub-type/meta.json +10 -0
- package/fixtures/preface-role-aria/gnd.json +8 -0
- package/fixtures/preface-role-aria/input.html +1 -0
- package/fixtures/preface-role-aria/meta.json +10 -0
- package/fixtures/preformatted-html-native/gnd.json +8 -0
- package/fixtures/preformatted-html-native/input.html +2 -0
- package/fixtures/preformatted-html-native/meta.json +10 -0
- package/fixtures/presentation-role-aria/gnd.json +8 -0
- package/fixtures/presentation-role-aria/input.html +1 -0
- package/fixtures/presentation-role-aria/meta.json +10 -0
- package/fixtures/prologue-epub-type/gnd.json +15 -0
- package/fixtures/prologue-epub-type/input.xhtml +11 -0
- package/fixtures/prologue-epub-type/meta.json +10 -0
- package/fixtures/prologue-role-aria/gnd.json +8 -0
- package/fixtures/prologue-role-aria/input.html +1 -0
- package/fixtures/prologue-role-aria/meta.json +10 -0
- package/fixtures/pullquote-epub-type/gnd.json +16 -0
- package/fixtures/pullquote-epub-type/input.xhtml +11 -0
- package/fixtures/pullquote-epub-type/meta.json +10 -0
- package/fixtures/pullquote-role-aria/gnd.json +8 -0
- package/fixtures/pullquote-role-aria/input.html +1 -0
- package/fixtures/pullquote-role-aria/meta.json +10 -0
- package/fixtures/qna-epub-type/gnd.json +16 -0
- package/fixtures/qna-epub-type/input.xhtml +11 -0
- package/fixtures/qna-epub-type/meta.json +10 -0
- package/fixtures/qna-role-aria/gnd.json +8 -0
- package/fixtures/qna-role-aria/input.html +1 -0
- package/fixtures/qna-role-aria/meta.json +10 -0
- package/fixtures/region-role-aria/gnd.json +8 -0
- package/fixtures/region-role-aria/input.html +1 -0
- package/fixtures/region-role-aria/meta.json +10 -0
- package/fixtures/section-html-native/gnd.json +8 -0
- package/fixtures/section-html-native/input.html +1 -0
- package/fixtures/section-html-native/meta.json +10 -0
- package/fixtures/separator-html-native/gnd.json +26 -0
- package/fixtures/separator-html-native/input.html +3 -0
- package/fixtures/separator-html-native/meta.json +10 -0
- package/fixtures/separator-role-aria/gnd.json +26 -0
- package/fixtures/separator-role-aria/input.html +3 -0
- package/fixtures/separator-role-aria/meta.json +10 -0
- package/fixtures/separator-with-glyphs/gnd.json +28 -0
- package/fixtures/separator-with-glyphs/input.html +3 -0
- package/fixtures/separator-with-glyphs/meta.json +10 -0
- package/fixtures/subtitle-epub-type/gnd.json +15 -0
- package/fixtures/subtitle-epub-type/input.xhtml +11 -0
- package/fixtures/subtitle-epub-type/meta.json +10 -0
- package/fixtures/subtitle-role-aria/gnd.json +8 -0
- package/fixtures/subtitle-role-aria/input.html +1 -0
- package/fixtures/subtitle-role-aria/meta.json +10 -0
- package/fixtures/summary-html-native/gnd.json +8 -0
- package/fixtures/summary-html-native/input.html +1 -0
- package/fixtures/summary-html-native/meta.json +10 -0
- package/fixtures/table-caption/gnd.json +81 -0
- package/fixtures/table-caption/input.html +5 -0
- package/fixtures/table-caption/meta.json +14 -0
- package/fixtures/table-caption-element-html-native/gnd.json +42 -0
- package/fixtures/table-caption-element-html-native/input.html +5 -0
- package/fixtures/table-caption-element-html-native/meta.json +14 -0
- package/fixtures/table-caption-role-aria/gnd.json +27 -0
- package/fixtures/table-caption-role-aria/input.html +4 -0
- package/fixtures/table-caption-role-aria/meta.json +13 -0
- package/fixtures/table-colspan-html-native/gnd.json +45 -0
- package/fixtures/table-colspan-html-native/input.html +4 -0
- package/fixtures/table-colspan-html-native/meta.json +13 -0
- package/fixtures/table-colspan-role-aria/gnd.json +45 -0
- package/fixtures/table-colspan-role-aria/input.html +4 -0
- package/fixtures/table-colspan-role-aria/meta.json +13 -0
- package/fixtures/table-epub-type/gnd.json +37 -0
- package/fixtures/table-epub-type/input.xhtml +16 -0
- package/fixtures/table-epub-type/meta.json +12 -0
- package/fixtures/table-html-native/gnd.json +76 -0
- package/fixtures/table-html-native/input.html +5 -0
- package/fixtures/table-html-native/meta.json +14 -0
- package/fixtures/table-in-role-none-wrapper/gnd.json +44 -0
- package/fixtures/table-in-role-none-wrapper/input.html +6 -0
- package/fixtures/table-in-role-none-wrapper/meta.json +14 -0
- package/fixtures/table-nested-html-native/gnd.json +48 -0
- package/fixtures/table-nested-html-native/input.html +3 -0
- package/fixtures/table-nested-html-native/meta.json +12 -0
- package/fixtures/table-nested-in-presentation-table/gnd.json +63 -0
- package/fixtures/table-nested-in-presentation-table/input.html +3 -0
- package/fixtures/table-nested-in-presentation-table/meta.json +14 -0
- package/fixtures/table-nested-role-aria/gnd.json +48 -0
- package/fixtures/table-nested-role-aria/input.html +9 -0
- package/fixtures/table-nested-role-aria/meta.json +12 -0
- package/fixtures/table-no-headers/gnd.json +53 -0
- package/fixtures/table-no-headers/input.html +10 -0
- package/fixtures/table-no-headers/meta.json +12 -0
- package/fixtures/table-role-aria/gnd.json +76 -0
- package/fixtures/table-role-aria/input.html +5 -0
- package/fixtures/table-role-aria/meta.json +14 -0
- package/fixtures/table-role-presentation-explicit-cell/gnd.json +30 -0
- package/fixtures/table-role-presentation-explicit-cell/input.html +3 -0
- package/fixtures/table-role-presentation-explicit-cell/meta.json +11 -0
- package/fixtures/table-role-presentation-html-native/gnd.json +37 -0
- package/fixtures/table-role-presentation-html-native/input.html +4 -0
- package/fixtures/table-role-presentation-html-native/meta.json +13 -0
- package/fixtures/table-role-presentation-role-aria/gnd.json +37 -0
- package/fixtures/table-role-presentation-role-aria/input.html +4 -0
- package/fixtures/table-role-presentation-role-aria/meta.json +13 -0
- package/fixtures/table-rowgroup-role-aria/gnd.json +22 -0
- package/fixtures/table-rowgroup-role-aria/input.html +5 -0
- package/fixtures/table-rowgroup-role-aria/meta.json +12 -0
- package/fixtures/table-rowspan-html-native/gnd.json +45 -0
- package/fixtures/table-rowspan-html-native/input.html +4 -0
- package/fixtures/table-rowspan-html-native/meta.json +13 -0
- package/fixtures/table-rowspan-role-aria/gnd.json +45 -0
- package/fixtures/table-rowspan-role-aria/input.html +4 -0
- package/fixtures/table-rowspan-role-aria/meta.json +13 -0
- package/fixtures/table-sectioning/gnd.json +52 -0
- package/fixtures/table-sectioning/input.html +11 -0
- package/fixtures/table-sectioning/meta.json +13 -0
- package/fixtures/table-th-no-scope/gnd.json +53 -0
- package/fixtures/table-th-no-scope/input.html +4 -0
- package/fixtures/table-th-no-scope/meta.json +12 -0
- package/fixtures/term-epub-type/gnd.json +22 -0
- package/fixtures/term-epub-type/input.xhtml +13 -0
- package/fixtures/term-epub-type/meta.json +11 -0
- package/fixtures/term-html-native/gnd.json +8 -0
- package/fixtures/term-html-native/input.html +1 -0
- package/fixtures/term-html-native/meta.json +10 -0
- package/fixtures/term-role-aria/gnd.json +8 -0
- package/fixtures/term-role-aria/input.html +1 -0
- package/fixtures/term-role-aria/meta.json +10 -0
- package/fixtures/tip-epub-type/gnd.json +16 -0
- package/fixtures/tip-epub-type/input.xhtml +11 -0
- package/fixtures/tip-epub-type/meta.json +10 -0
- package/fixtures/tip-role-aria/gnd.json +8 -0
- package/fixtures/tip-role-aria/input.html +1 -0
- package/fixtures/tip-role-aria/meta.json +10 -0
- package/fixtures/toc-epub-type/gnd.json +61 -0
- package/fixtures/toc-epub-type/input.xhtml +17 -0
- package/fixtures/toc-epub-type/meta.json +12 -0
- package/fixtures/toc-role-aria/gnd.json +54 -0
- package/fixtures/toc-role-aria/input.html +7 -0
- package/fixtures/toc-role-aria/meta.json +12 -0
- package/fixtures/video-html-native/gnd.json +11 -0
- package/fixtures/video-html-native/input.html +1 -0
- package/fixtures/video-html-native/meta.json +10 -0
- package/fixtures/video-no-description/gnd.json +6 -0
- package/fixtures/video-no-description/input.html +1 -0
- package/fixtures/video-no-description/meta.json +10 -0
- package/package.json +65 -0
- package/src/a11y.ts +166 -0
- package/src/converter.ts +730 -0
- package/src/dom.ts +56 -0
- package/src/domRangeGenerator.ts +55 -0
- package/src/elementHandlers.ts +88 -0
- package/src/idAllocator.ts +26 -0
- package/src/index.ts +15 -0
- package/src/makeGnd.ts +20 -0
- package/src/object.ts +175 -0
- package/src/options.ts +77 -0
- package/src/prescan.ts +40 -0
- package/src/roles.ts +350 -0
- package/src/selectorGenerator.ts +86 -0
- package/src/text.ts +65 -0
- package/src/textFragmentGenerator.ts +11 -0
- package/src/textrefFragment.ts +190 -0
- package/src/types.ts +2 -0
- package/types/src/a11y.d.ts +19 -0
- package/types/src/converter.d.ts +76 -0
- package/types/src/dom.d.ts +6 -0
- package/types/src/domRangeGenerator.d.ts +9 -0
- package/types/src/elementHandlers.d.ts +5 -0
- package/types/src/idAllocator.d.ts +6 -0
- package/types/src/index.d.ts +8 -0
- package/types/src/makeGnd.d.ts +10 -0
- package/types/src/object.d.ts +29 -0
- package/types/src/options.d.ts +18 -0
- package/types/src/prescan.d.ts +1 -0
- package/types/src/roles.d.ts +3 -0
- package/types/src/selectorGenerator.d.ts +3 -0
- package/types/src/text.d.ts +16 -0
- package/types/src/textFragmentGenerator.d.ts +2 -0
- package/types/src/textrefFragment.d.ts +40 -0
- package/types/src/types.d.ts +1 -0
package/src/converter.ts
ADDED
|
@@ -0,0 +1,730 @@
|
|
|
1
|
+
import type { GuidedNavigationObject } from "@readium/shared";
|
|
2
|
+
import type { GndRole } from "./types.ts";
|
|
3
|
+
import { extractNodeRoles, hasExplicitRole } from "./roles.ts";
|
|
4
|
+
import {
|
|
5
|
+
extractNodeAria,
|
|
6
|
+
normalizedNodeText,
|
|
7
|
+
normalizedNodeTextExcludingExplicitRoles,
|
|
8
|
+
convertElementToSSMLTag,
|
|
9
|
+
skippedElements,
|
|
10
|
+
} from "./a11y.ts";
|
|
11
|
+
import {
|
|
12
|
+
type TextBuilder,
|
|
13
|
+
type SSMLContext,
|
|
14
|
+
ctxEqual,
|
|
15
|
+
normalizeWhitespace,
|
|
16
|
+
} from "./text.ts";
|
|
17
|
+
import { ssmlAttrEscape, ssmlTextEscape, startsWithBindingPunct } from "@readium/helpers";
|
|
18
|
+
import { type ObjBuilder, NavObject, isEmptyObj, finalizeToGuidedNavigationObject } from "./object.ts";
|
|
19
|
+
import { type GndMediaType, nodeLanguage, isInlineTag, sniffMediaType } from "./dom.ts";
|
|
20
|
+
import { encodeDomRangeFragment, encodeTextFragmentDirective } from "./textrefFragment.ts";
|
|
21
|
+
import { rootAnchorSelector, selectorForElement, textrefForSelector } from "./selectorGenerator.ts";
|
|
22
|
+
import { generateDomRange } from "./domRangeGenerator.ts";
|
|
23
|
+
import { textFragmentDirectiveFor } from "./textFragmentGenerator.ts";
|
|
24
|
+
import { type GndGenerationOptions, normalizeTextrefOptions } from "./options.ts";
|
|
25
|
+
import { IdAllocator } from "./idAllocator.ts";
|
|
26
|
+
import { prescan as prescanImpl } from "./prescan.ts";
|
|
27
|
+
import { pagebreak, noteref, link } from "./elementHandlers.ts";
|
|
28
|
+
|
|
29
|
+
const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
|
|
30
|
+
|
|
31
|
+
const TEXT_NODE = 3;
|
|
32
|
+
const ELEMENT_NODE = 1;
|
|
33
|
+
|
|
34
|
+
// These elements are normally treated as inline (text flows through them
|
|
35
|
+
// without opening their own object), but when they carry a role of their own
|
|
36
|
+
// that role shouldn't be silently discarded — they become block elements instead.
|
|
37
|
+
const roleOverridesInline = new Set(["summary", "dfn", "span"]);
|
|
38
|
+
|
|
39
|
+
function isBlockNode(tagName: string, roles: GndRole[]): boolean {
|
|
40
|
+
if (roleOverridesInline.has(tagName) && roles.length > 0) return true;
|
|
41
|
+
return !isInlineTag(tagName);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type SegmentKind = "text" | "break" | "placeholder";
|
|
45
|
+
|
|
46
|
+
interface Segment {
|
|
47
|
+
kind: SegmentKind;
|
|
48
|
+
text?: string;
|
|
49
|
+
ctx?: SSMLContext;
|
|
50
|
+
tag?: string;
|
|
51
|
+
child?: NavObject;
|
|
52
|
+
candidateID?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Walks a DOM subtree, building the Guided Navigation object tree. */
|
|
56
|
+
export class Converter {
|
|
57
|
+
xmlParsed: boolean;
|
|
58
|
+
ids = new Map<string, Element>();
|
|
59
|
+
suppressed = new Set<Element>();
|
|
60
|
+
idAlloc = new IdAllocator();
|
|
61
|
+
noterefDepth = 0;
|
|
62
|
+
allowNode: Element | null = null;
|
|
63
|
+
selectorPredicate: ((roles: GndRole[]) => boolean) | null = null;
|
|
64
|
+
// Only meaningful (and safe) when converting a live, already-rendered
|
|
65
|
+
// element — see TextrefOptions.domRange in options.ts.
|
|
66
|
+
domRangeEnabled = false;
|
|
67
|
+
// Unlike domRangeEnabled, safe against a detached parsed document too —
|
|
68
|
+
// see TextrefOptions.textFragment in options.ts.
|
|
69
|
+
textFragmentEnabled = false;
|
|
70
|
+
// See TextrefOptions.roles' leafTextRoleKeyword in options.ts.
|
|
71
|
+
leafTextEnabled = false;
|
|
72
|
+
docRoot: Document | null = null;
|
|
73
|
+
// The live element selectors are climbed relative to — see
|
|
74
|
+
// selectorGenerator.ts's selectorForElement(). Only set when converting a
|
|
75
|
+
// live, already-rendered element (same caveat as domRangeEnabled).
|
|
76
|
+
selectorRoot: Element | null = null;
|
|
77
|
+
// Prefixed onto every generated selector — see selectorGenerator.ts's rootAnchorSelector().
|
|
78
|
+
selectorRootAnchor: string | null = null;
|
|
79
|
+
|
|
80
|
+
private root = new NavObject();
|
|
81
|
+
private current = this.root;
|
|
82
|
+
|
|
83
|
+
// Captions whose text was already folded into a table's `description` —
|
|
84
|
+
// only these specific elements go silent, not the whole table (rows/cells
|
|
85
|
+
// still need their own text).
|
|
86
|
+
private foldedCaptions = new Set<Element>();
|
|
87
|
+
|
|
88
|
+
private segments: Segment[] = [];
|
|
89
|
+
private textAcc = "";
|
|
90
|
+
private currentCtx: SSMLContext = { lang: "", tag: "" };
|
|
91
|
+
private flowEndsWithSpace = true;
|
|
92
|
+
private pendingChildren: NavObject[] = [];
|
|
93
|
+
|
|
94
|
+
// Boundary text nodes of the flow currently being accumulated, for
|
|
95
|
+
// domRange generation — see text()/resetFlow()/flushText().
|
|
96
|
+
private flowFirstNode: Text | null = null;
|
|
97
|
+
private flowFirstOffset = 0;
|
|
98
|
+
private flowLastNode: Text | null = null;
|
|
99
|
+
private flowLastOffset = 0;
|
|
100
|
+
// The boundary nodes of the flow flushText() just flushed, read by tail()
|
|
101
|
+
// right after calling it to build a domRange for the block it closes.
|
|
102
|
+
private lastFlowRange: { first: [Text, number]; last: [Text, number] } | null = null;
|
|
103
|
+
// The plain-text string of the flow flushText() just flushed, read by
|
|
104
|
+
// tail() right after calling it as the text-fragment candidate text.
|
|
105
|
+
private lastFlowText: string | null = null;
|
|
106
|
+
|
|
107
|
+
constructor(xmlParsed: boolean) {
|
|
108
|
+
this.xmlParsed = xmlParsed;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// A sub-conversion sharing this converter's document-wide state (ids,
|
|
112
|
+
// suppressed, idAlloc) — for content reached from within the same
|
|
113
|
+
// document, e.g. a noteref's footnote target. New fields shared this way
|
|
114
|
+
// belong here, not re-copied at each call site.
|
|
115
|
+
spawnChild(allowNode: Element, depthDelta = 1): Converter {
|
|
116
|
+
const child = new Converter(this.xmlParsed);
|
|
117
|
+
child.ids = this.ids;
|
|
118
|
+
child.suppressed = this.suppressed;
|
|
119
|
+
child.idAlloc = this.idAlloc;
|
|
120
|
+
child.noterefDepth = this.noterefDepth + depthDelta;
|
|
121
|
+
child.allowNode = allowNode;
|
|
122
|
+
child.docRoot = this.docRoot;
|
|
123
|
+
child.selectorRoot = this.selectorRoot;
|
|
124
|
+
child.selectorRootAnchor = this.selectorRootAnchor;
|
|
125
|
+
child.selectorPredicate = this.selectorPredicate;
|
|
126
|
+
child.domRangeEnabled = this.domRangeEnabled;
|
|
127
|
+
child.textFragmentEnabled = this.textFragmentEnabled;
|
|
128
|
+
child.leafTextEnabled = this.leafTextEnabled;
|
|
129
|
+
return child;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
prescan(root: Element) {
|
|
133
|
+
prescanImpl(root, this.ids, this.suppressed);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Converts root itself — used when root is meaningful content in its own
|
|
137
|
+
// right (e.g. a footnote element referenced by a noteref), not just a
|
|
138
|
+
// structural container.
|
|
139
|
+
convert(root: Element) {
|
|
140
|
+
this.prescan(root);
|
|
141
|
+
this.walk(root);
|
|
142
|
+
this.flushText();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Converts root's children — used at the top level, where root is always
|
|
146
|
+
// just the document's <body> (or a fragment's implicit wrapper), never
|
|
147
|
+
// content of its own.
|
|
148
|
+
convertChildren(root: Element) {
|
|
149
|
+
this.prescan(root);
|
|
150
|
+
for (let c = root.firstChild; c; c = c.nextSibling) this.walk(c);
|
|
151
|
+
this.flushText();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
resultBuilders(): ObjBuilder[] {
|
|
155
|
+
const res = this.root.finalize((el) => textrefForSelector(selectorForElement(el, this.selectorRoot, this.selectorRootAnchor), el));
|
|
156
|
+
if (!res.children || res.children.length === 0) {
|
|
157
|
+
if (isEmptyObj(res)) return [];
|
|
158
|
+
return [res];
|
|
159
|
+
}
|
|
160
|
+
return res.children;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
result(): GuidedNavigationObject[] {
|
|
164
|
+
return this.resultBuilders().map(finalizeToGuidedNavigationObject);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// An explicit-role descendant is content in its own right and skips
|
|
168
|
+
// inherited `noText` — except `caption`, always the already-folded source.
|
|
169
|
+
private descend(el: Element, roles: GndRole[]) {
|
|
170
|
+
const node = new NavObject();
|
|
171
|
+
node.el = el;
|
|
172
|
+
node.noText =
|
|
173
|
+
this.foldedCaptions.has(el) || ((!hasExplicitRole(el) || roles.includes("caption")) && this.current.noText);
|
|
174
|
+
this.current.children.push(node);
|
|
175
|
+
this.current.hasChildBlock = true;
|
|
176
|
+
this.current = node;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private appendChild(child: NavObject) {
|
|
180
|
+
child.noText = this.current.noText;
|
|
181
|
+
this.current.children.push(child);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private walk(node: Node) {
|
|
185
|
+
if (node.nodeType === TEXT_NODE) {
|
|
186
|
+
this.text(node);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (node.nodeType !== ELEMENT_NODE) return;
|
|
190
|
+
const el = node as Element;
|
|
191
|
+
|
|
192
|
+
const parent = this.current;
|
|
193
|
+
const wasSkip = this.head(el);
|
|
194
|
+
if (!wasSkip) {
|
|
195
|
+
for (let c = el.firstChild; c; c = c.nextSibling) this.walk(c);
|
|
196
|
+
}
|
|
197
|
+
this.tail(el, wasSkip, parent);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Returns true if children should not be traversed (already handled
|
|
201
|
+
// wholesale, invisible, or explicitly skipped).
|
|
202
|
+
private head(el: Element): boolean {
|
|
203
|
+
const tagName = el.tagName.toLowerCase();
|
|
204
|
+
|
|
205
|
+
if (skippedElements.has(tagName)) return true;
|
|
206
|
+
if (this.suppressed.has(el) && el !== this.allowNode) return true;
|
|
207
|
+
|
|
208
|
+
const [aria, visible] = extractNodeAria(el);
|
|
209
|
+
if (!visible && el !== this.allowNode) return true;
|
|
210
|
+
|
|
211
|
+
const roles = extractNodeRoles(el);
|
|
212
|
+
|
|
213
|
+
if (
|
|
214
|
+
(tagName === "img" || tagName === "svg") &&
|
|
215
|
+
(roles.includes("presentation") ||
|
|
216
|
+
(aria === null && el.hasAttribute("alt") && el.getAttribute("alt")!.trim() === ""))
|
|
217
|
+
) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (tagName === "br") {
|
|
222
|
+
if (!this.current.noText) {
|
|
223
|
+
this.closeSegment();
|
|
224
|
+
this.segments.push({ kind: "break" });
|
|
225
|
+
this.flowEndsWithSpace = true;
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (roles.includes("pagebreak")) {
|
|
231
|
+
return !pagebreak(this, el, aria, roles);
|
|
232
|
+
}
|
|
233
|
+
if (tagName === "a" && roles.includes("noteref") && el.getAttribute("href")) {
|
|
234
|
+
noteref(this, el, roles);
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
if (tagName === "a" && el.getAttribute("href")) {
|
|
238
|
+
// Any other link — backlink/biblioref/glossref, or a plain navigational
|
|
239
|
+
// link with no specific role (e.g. a TOC entry) — carries its href as
|
|
240
|
+
// textref. When it's the sole content of its enclosing block (the usual
|
|
241
|
+
// case for list items), the hoist rule promotes it onto that block;
|
|
242
|
+
// otherwise it becomes an inline SSML placeholder like any other
|
|
243
|
+
// embedded object.
|
|
244
|
+
link(this, el, roles, aria);
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
if (tagName === "img") {
|
|
248
|
+
const obj: ObjBuilder = { role: roles };
|
|
249
|
+
const src = el.getAttribute("src");
|
|
250
|
+
if (src) obj.imgref = src;
|
|
251
|
+
if (aria) obj.description = aria;
|
|
252
|
+
this.placeholder(el, "image", obj);
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
if (tagName === "audio" || tagName === "video") {
|
|
256
|
+
const obj: ObjBuilder = { role: roles };
|
|
257
|
+
let src = el.getAttribute("src");
|
|
258
|
+
if (!src) {
|
|
259
|
+
const source = el.querySelector(":scope > source[src]");
|
|
260
|
+
if (source) src = source.getAttribute("src");
|
|
261
|
+
}
|
|
262
|
+
if (tagName === "audio") {
|
|
263
|
+
if (src) obj.audioref = src;
|
|
264
|
+
} else if (src) {
|
|
265
|
+
obj.videoref = src;
|
|
266
|
+
}
|
|
267
|
+
if (aria) obj.description = aria;
|
|
268
|
+
this.placeholder(el, tagName, obj);
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
if (roles.includes("image") || roles.includes("math")) {
|
|
272
|
+
// Elements acting as images without being one, e.g. <span role="img">:
|
|
273
|
+
// their content is replaced by their accessible name.
|
|
274
|
+
const obj: ObjBuilder = { role: roles };
|
|
275
|
+
if (aria) obj.description = aria;
|
|
276
|
+
if (roles.includes("math")) {
|
|
277
|
+
// MathML is carried as-is in SSML, other math markup as plain text.
|
|
278
|
+
if (el.namespaceURI === MATHML_NS) {
|
|
279
|
+
obj.text = { plain: "", ssml: new XMLSerializer().serializeToString(el), language: "" };
|
|
280
|
+
} else {
|
|
281
|
+
const text = normalizedNodeText(el);
|
|
282
|
+
if (text) obj.text = { plain: text, ssml: "", language: "" };
|
|
283
|
+
}
|
|
284
|
+
obj.textref = textrefForSelector(selectorForElement(el, this.selectorRoot, this.selectorRootAnchor), el);
|
|
285
|
+
}
|
|
286
|
+
this.placeholder(el, roles.includes("math") ? "math" : "image", obj);
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!isBlockNode(tagName, roles)) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
this.flushText();
|
|
295
|
+
this.descend(el, roles);
|
|
296
|
+
|
|
297
|
+
const cur = this.current.object;
|
|
298
|
+
if (roles.length > 0) cur.role = roles;
|
|
299
|
+
if (aria) {
|
|
300
|
+
cur.description = aria;
|
|
301
|
+
if (roles.includes("figure")) {
|
|
302
|
+
this.current.noText = true;
|
|
303
|
+
}
|
|
304
|
+
} else if (roles.includes("figure")) {
|
|
305
|
+
const caption = this.implicitCaptionOf(el);
|
|
306
|
+
if (caption) {
|
|
307
|
+
// Not suppressed — walked normally so a nested explicit-role
|
|
308
|
+
// descendant (e.g. a credit) still speaks.
|
|
309
|
+
const text = normalizedNodeTextExcludingExplicitRoles(caption);
|
|
310
|
+
if (text) {
|
|
311
|
+
cur.description = text;
|
|
312
|
+
this.current.noText = true;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
} else if (roles.includes("table")) {
|
|
316
|
+
const caption = this.implicitCaptionOf(el);
|
|
317
|
+
if (caption) {
|
|
318
|
+
const text = normalizedNodeTextExcludingExplicitRoles(caption);
|
|
319
|
+
if (text) {
|
|
320
|
+
cur.description = text;
|
|
321
|
+
this.foldedCaptions.add(caption);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const id = el.getAttribute("id");
|
|
326
|
+
if (id) cur.id = id;
|
|
327
|
+
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// HTML-AAM implicit name: a table/figure with no explicit ARIA name folds
|
|
332
|
+
// its native/ARIA caption child's text in as its own description instead
|
|
333
|
+
// of speaking that child separately.
|
|
334
|
+
private implicitCaptionOf(el: Element): Element | null {
|
|
335
|
+
for (let c = el.firstElementChild; c; c = c.nextElementSibling) {
|
|
336
|
+
if (extractNodeRoles(c).includes("caption") && !c.getAttribute("aria-labelledby")) return c;
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
private tail(el: Element, wasSkip: boolean, parent: NavObject) {
|
|
342
|
+
if (wasSkip) return;
|
|
343
|
+
const tagName = el.tagName.toLowerCase();
|
|
344
|
+
const roles = extractNodeRoles(el);
|
|
345
|
+
// A descended pagebreak is a placeholder in its parent's flow; head() never opened a block for it.
|
|
346
|
+
if (roles.includes("pagebreak")) return;
|
|
347
|
+
if (isBlockNode(tagName, roles)) {
|
|
348
|
+
this.flushText();
|
|
349
|
+
// A child block splits el's text into several flows; the last one alone doesn't represent el.
|
|
350
|
+
if (this.current.hasChildBlock) {
|
|
351
|
+
this.lastFlowRange = null;
|
|
352
|
+
this.lastFlowText = null;
|
|
353
|
+
}
|
|
354
|
+
const isLeafText = this.leafTextEnabled && roles.length === 0 && !!this.lastFlowText;
|
|
355
|
+
if (this.selectorPredicate?.(roles) || isLeafText) {
|
|
356
|
+
this.applyTextref(el);
|
|
357
|
+
}
|
|
358
|
+
this.current = parent;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Sets cur.textref to a reference for el: the base id-or-selector
|
|
363
|
+
// reference (selectorGenerator.ts), upgraded to a domRange
|
|
364
|
+
// (domRangeGenerator.ts) when domRangeEnabled and el's own flow just
|
|
365
|
+
// flushed some text, with a text-fragment directive
|
|
366
|
+
// (textFragmentGenerator.ts) appended on top when textFragmentEnabled and
|
|
367
|
+
// el's own flow flushed text with real source-node boundaries (a flow with
|
|
368
|
+
// no such boundary — e.g. purely synthesized text — has no Range to
|
|
369
|
+
// generate a fragment from) — each an independent option, applied in this
|
|
370
|
+
// fixed order regardless of which others are also enabled.
|
|
371
|
+
private applyTextref(el: Element) {
|
|
372
|
+
const cur = this.current.object;
|
|
373
|
+
const selector = selectorForElement(el, this.selectorRoot, this.selectorRootAnchor);
|
|
374
|
+
cur.textref = textrefForSelector(selector, el);
|
|
375
|
+
|
|
376
|
+
if (this.domRangeEnabled && this.lastFlowRange) {
|
|
377
|
+
const known = selector ? { el, selector } : undefined;
|
|
378
|
+
const domRange = generateDomRange(this.lastFlowRange, this.selectorRoot, this.selectorRootAnchor, known);
|
|
379
|
+
if (domRange) cur.textref = encodeDomRangeFragment({ ...domRange, container: selector });
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (this.textFragmentEnabled && this.lastFlowRange && this.docRoot) {
|
|
383
|
+
const range = this.docRoot.createRange();
|
|
384
|
+
range.setStart(...this.lastFlowRange.first);
|
|
385
|
+
range.setEnd(...this.lastFlowRange.last);
|
|
386
|
+
const directive = textFragmentDirectiveFor(range);
|
|
387
|
+
if (directive) cur.textref = `${cur.textref ?? "#"}${encodeTextFragmentDirective(directive)}`;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
private text(node: Node) {
|
|
392
|
+
if (this.current.noText) return;
|
|
393
|
+
const data = node.nodeValue ?? "";
|
|
394
|
+
if (/^\s*$/.test(data)) {
|
|
395
|
+
if (this.textAcc.length > 0 || this.segments.length > 0) {
|
|
396
|
+
this.textAcc += normalizeWhitespace(data, this.flowEndsWithSpace);
|
|
397
|
+
this.updateFlowSpace();
|
|
398
|
+
}
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const ctx = this.textContext(node);
|
|
402
|
+
if (!ctxEqual(ctx, this.currentCtx)) {
|
|
403
|
+
this.closeSegment();
|
|
404
|
+
this.currentCtx = ctx;
|
|
405
|
+
}
|
|
406
|
+
this.textAcc += normalizeWhitespace(data, this.flowEndsWithSpace);
|
|
407
|
+
this.updateFlowSpace();
|
|
408
|
+
|
|
409
|
+
if (this.domRangeEnabled || this.textFragmentEnabled) {
|
|
410
|
+
const text = node as Text;
|
|
411
|
+
if (this.flowFirstNode === null) {
|
|
412
|
+
this.flowFirstNode = text;
|
|
413
|
+
this.flowFirstOffset = data.search(/\S/);
|
|
414
|
+
}
|
|
415
|
+
this.flowLastNode = text;
|
|
416
|
+
this.flowLastOffset = data.length - (data.match(/\s+$/)?.[0].length ?? 0);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private textContext(node: Node): SSMLContext {
|
|
421
|
+
const ctx: SSMLContext = { lang: nodeLanguage(node.parentElement), tag: "" };
|
|
422
|
+
for (let p = node.parentElement; p && p !== this.current.el; p = p.parentElement) {
|
|
423
|
+
const [tag, attrs] = convertElementToSSMLTag(p.tagName.toLowerCase());
|
|
424
|
+
if (tag && tag !== "break") {
|
|
425
|
+
ctx.tag = tag;
|
|
426
|
+
ctx.attrs = attrs;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return ctx;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private updateFlowSpace() {
|
|
434
|
+
if (this.textAcc.length > 0) {
|
|
435
|
+
this.flowEndsWithSpace = this.textAcc.endsWith(" ");
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
private closeSegment() {
|
|
440
|
+
if (this.textAcc.length === 0) return;
|
|
441
|
+
this.segments.push({ kind: "text", text: this.textAcc, ctx: this.currentCtx });
|
|
442
|
+
this.textAcc = "";
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
private resetFlow() {
|
|
446
|
+
this.segments = [];
|
|
447
|
+
this.textAcc = "";
|
|
448
|
+
this.currentCtx = { lang: "", tag: "" };
|
|
449
|
+
this.flowEndsWithSpace = true;
|
|
450
|
+
this.pendingChildren = [];
|
|
451
|
+
this.flowFirstNode = null;
|
|
452
|
+
this.flowFirstOffset = 0;
|
|
453
|
+
this.flowLastNode = null;
|
|
454
|
+
this.flowLastOffset = 0;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
placeholder(el: Element, tag: string, object: ObjBuilder, candidateID?: string) {
|
|
458
|
+
if (isEmptyObj(object)) return;
|
|
459
|
+
const child = new NavObject();
|
|
460
|
+
child.el = el;
|
|
461
|
+
child.object = object;
|
|
462
|
+
if (this.current.noText) {
|
|
463
|
+
this.appendChild(child);
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
this.closeSegment();
|
|
467
|
+
this.pendingChildren.push(child);
|
|
468
|
+
this.segments.push({
|
|
469
|
+
kind: "placeholder",
|
|
470
|
+
tag,
|
|
471
|
+
child,
|
|
472
|
+
candidateID: candidateID ?? el.getAttribute("id") ?? undefined,
|
|
473
|
+
});
|
|
474
|
+
this.flowEndsWithSpace = false;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
private flushText() {
|
|
478
|
+
this.closeSegment();
|
|
479
|
+
let segments = this.segments;
|
|
480
|
+
const pending = this.pendingChildren;
|
|
481
|
+
const flowFirstNode = this.flowFirstNode;
|
|
482
|
+
const flowFirstOffset = this.flowFirstOffset;
|
|
483
|
+
const flowLastNode = this.flowLastNode;
|
|
484
|
+
const flowLastOffset = this.flowLastOffset;
|
|
485
|
+
this.resetFlow();
|
|
486
|
+
this.lastFlowRange = null;
|
|
487
|
+
this.lastFlowText = null;
|
|
488
|
+
|
|
489
|
+
if (segments.length === 0) return;
|
|
490
|
+
|
|
491
|
+
// Trim the edges of the flow.
|
|
492
|
+
while (segments.length > 0) {
|
|
493
|
+
const seg = segments[0];
|
|
494
|
+
if (seg.kind === "break") {
|
|
495
|
+
segments = segments.slice(1);
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
if (seg.kind === "text") {
|
|
499
|
+
const trimmed = seg.text!.replace(/^\s+/, "");
|
|
500
|
+
if (trimmed === "") {
|
|
501
|
+
segments = segments.slice(1);
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
segments = [{ ...seg, text: trimmed }, ...segments.slice(1)];
|
|
505
|
+
}
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
while (segments.length > 0) {
|
|
509
|
+
const seg = segments[segments.length - 1];
|
|
510
|
+
if (seg.kind === "break") {
|
|
511
|
+
segments = segments.slice(0, -1);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
if (seg.kind === "text") {
|
|
515
|
+
const trimmed = seg.text!.replace(/\s+$/, "");
|
|
516
|
+
if (trimmed === "") {
|
|
517
|
+
segments = segments.slice(0, -1);
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
segments = [...segments.slice(0, -1), { ...seg, text: trimmed }];
|
|
521
|
+
}
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
const hasText = segments.some((s) => s.kind === "text" && s.text!.trim() !== "");
|
|
526
|
+
if (!hasText) {
|
|
527
|
+
for (const child of pending) this.appendChild(child);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
const textLangs: string[] = [];
|
|
532
|
+
for (const seg of segments) {
|
|
533
|
+
if (seg.kind === "text" && seg.text!.trim() !== "") {
|
|
534
|
+
const lang = seg.ctx!.lang;
|
|
535
|
+
if (!textLangs.includes(lang)) textLangs.push(lang);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
let baseLang = nodeLanguage(this.current.el ?? null);
|
|
539
|
+
if (textLangs.length === 1 && textLangs[0] !== "") {
|
|
540
|
+
baseLang = textLangs[0];
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
let needSSML = false;
|
|
544
|
+
for (const seg of segments) {
|
|
545
|
+
if (seg.kind !== "text" || seg.ctx!.tag !== "" || seg.ctx!.lang !== baseLang) {
|
|
546
|
+
needSSML = true;
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Default to English when an SSML representation is required (mixed
|
|
552
|
+
// formatting, embedded objects, or a language shift) but no explicit
|
|
553
|
+
// language was declared anywhere in the document.
|
|
554
|
+
if (needSSML && baseLang === "") {
|
|
555
|
+
baseLang = "en";
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
if (needSSML) {
|
|
559
|
+
for (const seg of segments) {
|
|
560
|
+
if (seg.kind !== "placeholder") continue;
|
|
561
|
+
let id = seg.candidateID;
|
|
562
|
+
if (!id || !this.idAlloc.claim(id)) {
|
|
563
|
+
id = this.idAlloc.allocate(seg.tag!, (candidate) => this.ids.has(candidate));
|
|
564
|
+
}
|
|
565
|
+
seg.child!.object.id = id;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
let plainB = "";
|
|
570
|
+
let prevTrail = false;
|
|
571
|
+
let sawBreak = false;
|
|
572
|
+
let sawPlaceholder = false;
|
|
573
|
+
let midSpace = false;
|
|
574
|
+
for (const seg of segments) {
|
|
575
|
+
if (seg.kind === "text") {
|
|
576
|
+
const lead = seg.text!.startsWith(" ");
|
|
577
|
+
const t = seg.text!.replace(/^ +| +$/g, "");
|
|
578
|
+
if (t === "") {
|
|
579
|
+
midSpace = true;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
let join = false;
|
|
583
|
+
if (plainB.length > 0) {
|
|
584
|
+
const spaced = prevTrail || midSpace || lead;
|
|
585
|
+
if (sawBreak) join = true;
|
|
586
|
+
else if (sawPlaceholder) join = spaced && !startsWithBindingPunct(t);
|
|
587
|
+
else join = spaced;
|
|
588
|
+
}
|
|
589
|
+
if (join) plainB += " ";
|
|
590
|
+
plainB += t;
|
|
591
|
+
prevTrail = seg.text!.endsWith(" ");
|
|
592
|
+
sawBreak = false;
|
|
593
|
+
sawPlaceholder = false;
|
|
594
|
+
midSpace = false;
|
|
595
|
+
} else if (seg.kind === "break") {
|
|
596
|
+
sawBreak = true;
|
|
597
|
+
} else if (seg.kind === "placeholder") {
|
|
598
|
+
sawPlaceholder = true;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Plain text is only worth keeping alongside SSML when it diverges from
|
|
603
|
+
// what stripping tags from the SSML would produce — i.e. when a
|
|
604
|
+
// placeholder (an embedded reference) was dropped from it. A pure
|
|
605
|
+
// formatting/language shift with no embedded objects makes plain text a
|
|
606
|
+
// redundant, mechanical derivative of the SSML, so it's left out.
|
|
607
|
+
const hasPlaceholder = segments.some((s) => s.kind === "placeholder");
|
|
608
|
+
this.lastFlowText = plainB.trim();
|
|
609
|
+
const text: TextBuilder = {
|
|
610
|
+
plain: needSSML && !hasPlaceholder ? "" : plainB.trim(),
|
|
611
|
+
ssml: "",
|
|
612
|
+
language: baseLang,
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
if (needSSML) {
|
|
616
|
+
let sb = "";
|
|
617
|
+
for (const seg of segments) {
|
|
618
|
+
if (seg.kind === "text") {
|
|
619
|
+
let tag = seg.ctx!.tag;
|
|
620
|
+
let attrs = seg.ctx!.attrs;
|
|
621
|
+
if (seg.ctx!.lang !== baseLang && seg.ctx!.lang !== "") {
|
|
622
|
+
// A language shift takes priority over whatever SSML tag the
|
|
623
|
+
// shifting element would otherwise map to.
|
|
624
|
+
tag = "lang";
|
|
625
|
+
attrs = undefined;
|
|
626
|
+
}
|
|
627
|
+
if (tag) {
|
|
628
|
+
sb += `<${tag}`;
|
|
629
|
+
for (const [k, v] of Object.entries(attrs ?? {})) {
|
|
630
|
+
sb += ` ${k}="${ssmlAttrEscape(v)}"`;
|
|
631
|
+
}
|
|
632
|
+
if (seg.ctx!.lang !== baseLang && seg.ctx!.lang !== "") {
|
|
633
|
+
sb += ` xml:lang="${ssmlAttrEscape(seg.ctx!.lang)}"`;
|
|
634
|
+
}
|
|
635
|
+
sb += `>${ssmlTextEscape(seg.text!)}</${tag}>`;
|
|
636
|
+
} else {
|
|
637
|
+
sb += ssmlTextEscape(seg.text!);
|
|
638
|
+
}
|
|
639
|
+
} else if (seg.kind === "break") {
|
|
640
|
+
sb += "<break/>";
|
|
641
|
+
} else if (seg.kind === "placeholder") {
|
|
642
|
+
sb += `<readium:${seg.tag} id="${ssmlAttrEscape(seg.child!.object.id!)}" />`;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
text.ssml = sb;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const textObj = new NavObject();
|
|
649
|
+
textObj.object = { text };
|
|
650
|
+
for (const child of pending) {
|
|
651
|
+
textObj.children.push(child);
|
|
652
|
+
}
|
|
653
|
+
this.appendChild(textObj);
|
|
654
|
+
|
|
655
|
+
if (flowFirstNode && flowLastNode) {
|
|
656
|
+
this.lastFlowRange = { first: [flowFirstNode, flowFirstOffset], last: [flowLastNode, flowLastOffset] };
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// A DOM <body> only counts as real content when the input actually wrote
|
|
662
|
+
// one — text/html parsing synthesizes a <body> around any fragment
|
|
663
|
+
// regardless of what was passed in, and that synthesized wrapper was
|
|
664
|
+
// never "in the input" just because the parser added it.
|
|
665
|
+
const BODY_TAG_RE = /<body[\s>]/i;
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Converts an HTML or XHTML fragment or document into Guided Navigation
|
|
669
|
+
* objects.
|
|
670
|
+
*
|
|
671
|
+
* Given a string, `input` is parsed into a detached document that's never
|
|
672
|
+
* seen again — `options.textrefs.domRange` has nothing to resolve back
|
|
673
|
+
* against there, so it's ignored. Reflects exactly the input it's given: a
|
|
674
|
+
* real, author-written <body> becomes its own role: ["body"] node like any
|
|
675
|
+
* other element; a <body> synthesized only by text/html parsing around a
|
|
676
|
+
* bodyless fragment is not content and is skipped through; a bodyless XHTML
|
|
677
|
+
* fragment's root element is itself the content. Malformed XHTML throws,
|
|
678
|
+
* unless `options.htmlFallback` re-parses it as text/html.
|
|
679
|
+
*
|
|
680
|
+
* Given a live, already-rendered element instead, it's converted in place —
|
|
681
|
+
* no parsing, no detached copy — so `domRange` can pinpoint exact text
|
|
682
|
+
* nodes a DOM-highlighting consumer can resolve straight back against that
|
|
683
|
+
* same document.
|
|
684
|
+
*/
|
|
685
|
+
export function parseMarkup(
|
|
686
|
+
input: string | Element,
|
|
687
|
+
mediaType?: GndMediaType,
|
|
688
|
+
options?: GndGenerationOptions,
|
|
689
|
+
): GuidedNavigationObject[] {
|
|
690
|
+
const { predicate, leafText, domRange, textFragment } = normalizeTextrefOptions(options?.textrefs);
|
|
691
|
+
|
|
692
|
+
if (typeof input !== "string") {
|
|
693
|
+
const mt = mediaType ?? (input.ownerDocument.contentType === "text/html" ? "text/html" : "application/xhtml+xml");
|
|
694
|
+
const converter = new Converter(mt === "application/xhtml+xml");
|
|
695
|
+
converter.selectorPredicate = predicate;
|
|
696
|
+
converter.leafTextEnabled = leafText;
|
|
697
|
+
converter.domRangeEnabled = domRange;
|
|
698
|
+
converter.textFragmentEnabled = textFragment;
|
|
699
|
+
converter.docRoot = input.ownerDocument;
|
|
700
|
+
converter.selectorRoot = input;
|
|
701
|
+
converter.selectorRootAnchor = rootAnchorSelector(input);
|
|
702
|
+
converter.convert(input);
|
|
703
|
+
return converter.result();
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
let mt = mediaType ?? sniffMediaType(input);
|
|
707
|
+
let doc = new DOMParser().parseFromString(input, mt);
|
|
708
|
+
if (mt === "application/xhtml+xml") {
|
|
709
|
+
const error = doc.getElementsByTagNameNS("*", "parsererror")[0];
|
|
710
|
+
if (error) {
|
|
711
|
+
if (!options?.htmlFallback) {
|
|
712
|
+
throw new Error(`XHTML parsing failed: ${error.textContent?.trim() ?? ""}`);
|
|
713
|
+
}
|
|
714
|
+
mt = "text/html";
|
|
715
|
+
doc = new DOMParser().parseFromString(input, mt);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
const converter = new Converter(mt === "application/xhtml+xml");
|
|
719
|
+
converter.selectorPredicate = predicate;
|
|
720
|
+
converter.leafTextEnabled = leafText;
|
|
721
|
+
converter.textFragmentEnabled = textFragment;
|
|
722
|
+
converter.docRoot = doc;
|
|
723
|
+
const body = doc.querySelector("body");
|
|
724
|
+
if (body && !BODY_TAG_RE.test(input)) {
|
|
725
|
+
converter.convertChildren(body);
|
|
726
|
+
} else {
|
|
727
|
+
converter.convert(body ?? doc.documentElement);
|
|
728
|
+
}
|
|
729
|
+
return converter.result();
|
|
730
|
+
}
|