@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/roles.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import type { GndRole } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
// https://github.com/readium/guided-navigation/blob/main/schema/roles.schema.json
|
|
4
|
+
// `sequence` is intentionally omitted: it has no documented HTML/ARIA/epub:type
|
|
5
|
+
// mapping anywhere in the spec or its examples.
|
|
6
|
+
|
|
7
|
+
const headingRoles: GndRole[] = [
|
|
8
|
+
"heading1",
|
|
9
|
+
"heading2",
|
|
10
|
+
"heading3",
|
|
11
|
+
"heading4",
|
|
12
|
+
"heading5",
|
|
13
|
+
"heading6",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
const ariaRoles: Record<string, GndRole> = {
|
|
17
|
+
"doc-abstract": "abstract",
|
|
18
|
+
"doc-acknowledgments": "acknowledgments",
|
|
19
|
+
"doc-afterword": "afterword",
|
|
20
|
+
"doc-appendix": "appendix",
|
|
21
|
+
article: "article",
|
|
22
|
+
"doc-backlink": "backlink",
|
|
23
|
+
"doc-biblioentry": "listItem", // Deprecated in DPUB-ARIA 1.1
|
|
24
|
+
"doc-bibliography": "bibliography",
|
|
25
|
+
"doc-biblioref": "biblioref",
|
|
26
|
+
blockquote: "blockquote",
|
|
27
|
+
caption: "caption",
|
|
28
|
+
cell: "cell",
|
|
29
|
+
"doc-chapter": "chapter",
|
|
30
|
+
"doc-colophon": "colophon",
|
|
31
|
+
columnheader: "columnheader",
|
|
32
|
+
complementary: "complementary",
|
|
33
|
+
"doc-conclusion": "conclusion",
|
|
34
|
+
"doc-cover": "cover",
|
|
35
|
+
"doc-credit": "credit",
|
|
36
|
+
"doc-credits": "credits",
|
|
37
|
+
"doc-dedication": "dedication",
|
|
38
|
+
definition: "definition",
|
|
39
|
+
"doc-endnote": "footnote", // Deprecated in DPUB-ARIA 1.1
|
|
40
|
+
"doc-endnotes": "endnotes",
|
|
41
|
+
"doc-epigraph": "epigraph",
|
|
42
|
+
"doc-epilogue": "epilogue",
|
|
43
|
+
"doc-errata": "errata",
|
|
44
|
+
"doc-example": "example",
|
|
45
|
+
figure: "figure",
|
|
46
|
+
"doc-footnote": "footnote",
|
|
47
|
+
"doc-foreword": "foreword",
|
|
48
|
+
"doc-glossary": "glossary",
|
|
49
|
+
"doc-glossref": "glossref",
|
|
50
|
+
img: "image",
|
|
51
|
+
image: "image", // ARIA 1.3 synonym of img
|
|
52
|
+
"doc-index": "index",
|
|
53
|
+
"doc-introduction": "introduction",
|
|
54
|
+
list: "list",
|
|
55
|
+
listitem: "listItem",
|
|
56
|
+
main: "main",
|
|
57
|
+
math: "math",
|
|
58
|
+
navigation: "navigation",
|
|
59
|
+
"doc-noteref": "noteref",
|
|
60
|
+
"doc-notice": "notice",
|
|
61
|
+
"doc-pagebreak": "pagebreak",
|
|
62
|
+
"doc-pagelist": "pagelist",
|
|
63
|
+
paragraph: "paragraph",
|
|
64
|
+
"doc-part": "part",
|
|
65
|
+
"doc-preface": "preface",
|
|
66
|
+
"doc-prologue": "prologue",
|
|
67
|
+
"doc-pullquote": "pullquote",
|
|
68
|
+
grid: "table",
|
|
69
|
+
gridcell: "cell",
|
|
70
|
+
presentation: "presentation",
|
|
71
|
+
none: "presentation",
|
|
72
|
+
"doc-qna": "qna",
|
|
73
|
+
qna: "qna",
|
|
74
|
+
region: "region",
|
|
75
|
+
row: "row",
|
|
76
|
+
rowheader: "rowheader",
|
|
77
|
+
separator: "separator",
|
|
78
|
+
"doc-subtitle": "subtitle",
|
|
79
|
+
table: "table",
|
|
80
|
+
term: "term",
|
|
81
|
+
"doc-tip": "tip",
|
|
82
|
+
"doc-toc": "toc",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const epubTypeRoles: Record<string, GndRole> = {
|
|
86
|
+
abstract: "abstract",
|
|
87
|
+
acknowledgments: "acknowledgments",
|
|
88
|
+
afterword: "afterword",
|
|
89
|
+
appendix: "appendix",
|
|
90
|
+
aside: "aside",
|
|
91
|
+
backlink: "backlink",
|
|
92
|
+
biblioentry: "listItem", // Deprecated in DPUB-ARIA 1.1
|
|
93
|
+
bibliography: "bibliography",
|
|
94
|
+
biblioref: "biblioref",
|
|
95
|
+
"table-cell": "cell",
|
|
96
|
+
chapter: "chapter",
|
|
97
|
+
colophon: "colophon",
|
|
98
|
+
conclusion: "conclusion",
|
|
99
|
+
cover: "cover",
|
|
100
|
+
credit: "credit",
|
|
101
|
+
credits: "credits",
|
|
102
|
+
dedication: "dedication",
|
|
103
|
+
glossdef: "definition",
|
|
104
|
+
endnote: "footnote",
|
|
105
|
+
endnotes: "endnotes",
|
|
106
|
+
rearnote: "footnote", // Deprecated alias of endnote
|
|
107
|
+
rearnotes: "endnotes", // Deprecated alias of endnotes
|
|
108
|
+
epigraph: "epigraph",
|
|
109
|
+
epilogue: "epilogue",
|
|
110
|
+
errata: "errata",
|
|
111
|
+
example: "example",
|
|
112
|
+
figure: "figure",
|
|
113
|
+
footnote: "footnote",
|
|
114
|
+
foreword: "foreword",
|
|
115
|
+
glossary: "glossary",
|
|
116
|
+
glossref: "glossref",
|
|
117
|
+
index: "index",
|
|
118
|
+
introduction: "introduction",
|
|
119
|
+
landmarks: "landmarks",
|
|
120
|
+
list: "list",
|
|
121
|
+
"list-item": "listItem",
|
|
122
|
+
loa: "loa",
|
|
123
|
+
loi: "loi",
|
|
124
|
+
lot: "lot",
|
|
125
|
+
lov: "lov",
|
|
126
|
+
noteref: "noteref",
|
|
127
|
+
notice: "notice",
|
|
128
|
+
pagebreak: "pagebreak",
|
|
129
|
+
"page-list": "pagelist",
|
|
130
|
+
pagelist: "pagelist",
|
|
131
|
+
part: "part",
|
|
132
|
+
preface: "preface",
|
|
133
|
+
prologue: "prologue",
|
|
134
|
+
pullquote: "pullquote",
|
|
135
|
+
qna: "qna",
|
|
136
|
+
"table-row": "row",
|
|
137
|
+
subtitle: "subtitle",
|
|
138
|
+
table: "table",
|
|
139
|
+
glossterm: "term",
|
|
140
|
+
tip: "tip",
|
|
141
|
+
toc: "toc",
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Elements whose role depends only on their tag name.
|
|
145
|
+
const simpleElementTypeRoles: Record<string, GndRole> = {
|
|
146
|
+
article: "article",
|
|
147
|
+
aside: "aside",
|
|
148
|
+
audio: "audio",
|
|
149
|
+
blockquote: "blockquote",
|
|
150
|
+
caption: "caption",
|
|
151
|
+
figcaption: "caption",
|
|
152
|
+
td: "cell",
|
|
153
|
+
dd: "definition",
|
|
154
|
+
details: "details",
|
|
155
|
+
figure: "figure",
|
|
156
|
+
header: "header",
|
|
157
|
+
h1: "heading1",
|
|
158
|
+
h2: "heading2",
|
|
159
|
+
h3: "heading3",
|
|
160
|
+
h4: "heading4",
|
|
161
|
+
h5: "heading5",
|
|
162
|
+
h6: "heading6",
|
|
163
|
+
img: "image",
|
|
164
|
+
ul: "list",
|
|
165
|
+
ol: "list",
|
|
166
|
+
li: "listItem",
|
|
167
|
+
main: "main",
|
|
168
|
+
math: "math",
|
|
169
|
+
nav: "navigation",
|
|
170
|
+
p: "paragraph",
|
|
171
|
+
pre: "preformatted",
|
|
172
|
+
tr: "row",
|
|
173
|
+
section: "section",
|
|
174
|
+
hr: "separator",
|
|
175
|
+
summary: "summary",
|
|
176
|
+
table: "table",
|
|
177
|
+
dfn: "term",
|
|
178
|
+
dt: "term",
|
|
179
|
+
video: "video",
|
|
180
|
+
svg: "image",
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// ARIA presentational inheritance: only a presentational <table>'s own
|
|
184
|
+
// required owned elements without an explicit role inherit it.
|
|
185
|
+
const tableOwnedTags = new Set(["tr", "td", "th"]);
|
|
186
|
+
const tableOwnedIntermediateTags = new Set(["tr", "thead", "tbody", "tfoot"]);
|
|
187
|
+
|
|
188
|
+
function isElementPresentational(el: Element): boolean {
|
|
189
|
+
const role = el.getAttribute("role");
|
|
190
|
+
if (!role) return false;
|
|
191
|
+
const vals = role.split(/\s+/).filter(Boolean);
|
|
192
|
+
return vals.includes("presentation") || vals.includes("none");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function hasExplicitAriaRole(el: Element): boolean {
|
|
196
|
+
return (el.getAttribute("role") ?? "").trim() !== "";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function inheritsTablePresentation(el: Element, tagName: string): boolean {
|
|
200
|
+
if (!tableOwnedTags.has(tagName) || hasExplicitAriaRole(el)) return false;
|
|
201
|
+
for (let p = el.parentElement; p; p = p.parentElement) {
|
|
202
|
+
const tag = p.tagName.toLowerCase();
|
|
203
|
+
if (tag !== "table" && !tableOwnedIntermediateTags.has(tag)) return false;
|
|
204
|
+
if (isElementPresentational(p)) return true;
|
|
205
|
+
if (tag === "table" || hasExplicitAriaRole(p)) return false;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function hasRole(el: Element, role: string): boolean {
|
|
211
|
+
const attr = el.getAttribute("role");
|
|
212
|
+
if (!attr) return false;
|
|
213
|
+
return attr.split(/\s+/).filter(Boolean).includes(role);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function isTableContainer(el: Element): boolean {
|
|
217
|
+
return el.tagName.toLowerCase() === "table" || hasRole(el, "table") || hasRole(el, "grid") || hasRole(el, "treegrid");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function isRowElement(el: Element): boolean {
|
|
221
|
+
return el.tagName.toLowerCase() === "tr" || hasRole(el, "row");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Unscoped <th> fallback: first row -> columnheader, else -> rowheader.
|
|
225
|
+
// Walks ancestors by tag/role instead of `closest("table")` — an ARIA-only
|
|
226
|
+
// table (role="grid"/"table", no literal <table> tag) has no HTML tag to
|
|
227
|
+
// find, only its structural descendants.
|
|
228
|
+
function isFirstRowOfTable(tr: Element): boolean {
|
|
229
|
+
let container: Element | null = null;
|
|
230
|
+
for (let p = tr.parentElement; p; p = p.parentElement) {
|
|
231
|
+
if (isTableContainer(p)) {
|
|
232
|
+
container = p;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (!container) return false;
|
|
237
|
+
|
|
238
|
+
const walker = container.ownerDocument.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
239
|
+
acceptNode: (n) => (isRowElement(n as Element) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP),
|
|
240
|
+
});
|
|
241
|
+
return walker.nextNode() === tr;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Determines the Guided Navigation roles of an element, combining the roles
|
|
246
|
+
* derived from the element type itself with the ones from its ARIA `role` and
|
|
247
|
+
* `epub:type` attributes, e.g. `<section epub:type="chapter">` -> `[section, chapter]`.
|
|
248
|
+
* An ARIA role of "presentation"/"none" strips the element of its native semantics.
|
|
249
|
+
*/
|
|
250
|
+
// Roles from an explicit `role=`/`epub:type` attribute, as opposed to the
|
|
251
|
+
// tag-name mapping below that every element gets for free.
|
|
252
|
+
function computeAttrRoles(el: Element): { attrRoles: GndRole[]; presentational: boolean } {
|
|
253
|
+
const attrRoles: GndRole[] = [];
|
|
254
|
+
let presentational = false;
|
|
255
|
+
|
|
256
|
+
const role = el.getAttribute("role");
|
|
257
|
+
if (role) {
|
|
258
|
+
for (const val of role.split(/\s+/).filter(Boolean)) {
|
|
259
|
+
if (val === "presentation" || val === "none") {
|
|
260
|
+
presentational = true;
|
|
261
|
+
}
|
|
262
|
+
if (val === "heading") {
|
|
263
|
+
// The heading level comes from aria-level. It defaults to 2:
|
|
264
|
+
// https://www.w3.org/TR/wai-aria/#heading
|
|
265
|
+
let level = 2;
|
|
266
|
+
const ariaLevel = parseInt(el.getAttribute("aria-level") ?? "", 10);
|
|
267
|
+
if (Number.isFinite(ariaLevel) && ariaLevel >= 1) {
|
|
268
|
+
level = Math.min(ariaLevel, 6);
|
|
269
|
+
}
|
|
270
|
+
attrRoles.push(headingRoles[level - 1]);
|
|
271
|
+
} else if (ariaRoles[val]) {
|
|
272
|
+
attrRoles.push(ariaRoles[val]);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// epub:type is only meaningful (and only ever set) in XHTML documents with
|
|
278
|
+
// the epub namespace declared; read the literal attribute name rather than
|
|
279
|
+
// resolving the namespace, since XHTML documents always use the "epub"
|
|
280
|
+
// prefix in practice.
|
|
281
|
+
const epubType = el.getAttribute("epub:type");
|
|
282
|
+
if (epubType) {
|
|
283
|
+
for (const val of epubType.split(/\s+/).filter(Boolean)) {
|
|
284
|
+
const mapped = epubTypeRoles[val];
|
|
285
|
+
if (mapped) attrRoles.push(mapped);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return { attrRoles, presentational };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Whether el's role was explicitly authored (`role=`/`epub:type`), not just
|
|
293
|
+
// inferred from its tag — e.g. a credit line vs. a plain `<p>`/`<pre>`.
|
|
294
|
+
export function hasExplicitRole(el: Element): boolean {
|
|
295
|
+
const { attrRoles, presentational } = computeAttrRoles(el);
|
|
296
|
+
return attrRoles.length > 0 || presentational;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function extractNodeRoles(el: Element): GndRole[] {
|
|
300
|
+
const roles: GndRole[] = [];
|
|
301
|
+
const add = (role: GndRole) => {
|
|
302
|
+
if (!roles.includes(role)) roles.push(role);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
const { attrRoles, presentational } = computeAttrRoles(el);
|
|
306
|
+
|
|
307
|
+
const tagName = el.tagName.toLowerCase();
|
|
308
|
+
|
|
309
|
+
if (presentational) {
|
|
310
|
+
// The element only retains the presentation role
|
|
311
|
+
return ["presentation"];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (inheritsTablePresentation(el, tagName)) {
|
|
315
|
+
return ["presentation"];
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Based on element type. The element's own role comes first, followed by the
|
|
319
|
+
// more specific attribute-based roles, matching the ordering of the examples
|
|
320
|
+
// in the Guided Navigation specification.
|
|
321
|
+
if (tagName === "body") {
|
|
322
|
+
add("body");
|
|
323
|
+
} else if (tagName === "th") {
|
|
324
|
+
switch (el.getAttribute("scope")) {
|
|
325
|
+
case "col":
|
|
326
|
+
add("columnheader");
|
|
327
|
+
break;
|
|
328
|
+
case "row":
|
|
329
|
+
add("rowheader");
|
|
330
|
+
break;
|
|
331
|
+
default: {
|
|
332
|
+
const tr = el.parentElement;
|
|
333
|
+
if (tr && isFirstRowOfTable(tr)) {
|
|
334
|
+
add("columnheader");
|
|
335
|
+
} else if (el.previousElementSibling === null) {
|
|
336
|
+
add("rowheader");
|
|
337
|
+
} else {
|
|
338
|
+
add("cell");
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
const mapped = simpleElementTypeRoles[tagName];
|
|
344
|
+
if (mapped) add(mapped);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
for (const r of attrRoles) add(r);
|
|
348
|
+
|
|
349
|
+
return roles;
|
|
350
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The id-or-generated-CSS-selector heuristic every other textref option
|
|
2
|
+
// (domRange, textFragment) builds its own reference on top of.
|
|
3
|
+
import { getCssSelector } from "css-selector-generator";
|
|
4
|
+
import { encodeCssSelectorFragment } from "./textrefFragment.ts";
|
|
5
|
+
|
|
6
|
+
function isUniqueId(doc: Document, id: string): boolean {
|
|
7
|
+
return doc.querySelectorAll(`#${CSS.escape(id)}`).length === 1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// One level of a >-joined climb, reasoning only about node's own siblings.
|
|
11
|
+
// Never an attribute selector: those latch onto JS-mutated attributes (e.g. layout-script `style`) and can stop matching later.
|
|
12
|
+
function siblingSelector(node: Element): string {
|
|
13
|
+
const id = node.getAttribute("id");
|
|
14
|
+
if (id && isUniqueId(node.ownerDocument, id)) return `#${CSS.escape(id)}`;
|
|
15
|
+
const parent = node.parentElement;
|
|
16
|
+
const tag = node.tagName.toLowerCase();
|
|
17
|
+
if (!parent) return tag;
|
|
18
|
+
const siblings = Array.from(parent.children);
|
|
19
|
+
for (const cls of node.classList) {
|
|
20
|
+
const escaped = `.${CSS.escape(cls)}`;
|
|
21
|
+
if (siblings.filter((s) => s.matches(escaped)).length === 1) return escaped;
|
|
22
|
+
}
|
|
23
|
+
if (siblings.filter((s) => s.tagName === node.tagName).length === 1) return tag;
|
|
24
|
+
return `${tag}:nth-child(${siblings.indexOf(node) + 1})`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Climbs from node up to (not including) stopAt, one siblingSelector() per level, short-circuiting once an ancestor id resolves (siblingSelector already confirmed it's document-unique).
|
|
28
|
+
// Returns undefined if node turns out not to be inside stopAt at all.
|
|
29
|
+
function climb(node: Element, stopAt: Element): string[] | undefined {
|
|
30
|
+
const parts: string[] = [];
|
|
31
|
+
let cur: Element | null = node;
|
|
32
|
+
while (cur && cur !== stopAt) {
|
|
33
|
+
const part = siblingSelector(cur);
|
|
34
|
+
parts.unshift(part);
|
|
35
|
+
if (part.startsWith("#")) return parts;
|
|
36
|
+
cur = cur.parentElement;
|
|
37
|
+
}
|
|
38
|
+
return cur === stopAt ? parts : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Stable, page-global anchor for selectorRoot, built via the same climbing logic as selectorForElement.
|
|
42
|
+
// Avoids css-selector-generator's own root/fallback modes, which can silently emit a `:scope`-relative selector — only valid via `root.querySelector()`, never as a global one.
|
|
43
|
+
export function rootAnchorSelector(selectorRoot: Element | null): string | null {
|
|
44
|
+
if (!selectorRoot) return null;
|
|
45
|
+
const id = selectorRoot.getAttribute("id");
|
|
46
|
+
if (id && isUniqueId(selectorRoot.ownerDocument, id)) return `#${CSS.escape(id)}`;
|
|
47
|
+
const docEl = selectorRoot.ownerDocument.documentElement;
|
|
48
|
+
const parts = climb(selectorRoot, docEl) ?? [];
|
|
49
|
+
if (parts.length > 0 && parts[0].startsWith("#")) return parts.join(" > ");
|
|
50
|
+
return [docEl.tagName.toLowerCase(), ...parts].join(" > ");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// An element's own "#id" when unique, else a selector relative to selectorRoot (the live element the conversion is scoped to) — for embedding elsewhere (e.g. domRangeGenerator.ts's DomRangeJSON), not as a textref by itself.
|
|
54
|
+
// Without a live selectorRoot (a detached, throwaway document), there's no unrelated host content to guard against, so any id is trusted as-is.
|
|
55
|
+
export function selectorForElement(
|
|
56
|
+
el: Element,
|
|
57
|
+
selectorRoot: Element | null,
|
|
58
|
+
rootAnchor: string | null,
|
|
59
|
+
): string | undefined {
|
|
60
|
+
const id = el.getAttribute("id");
|
|
61
|
+
if (id && (!selectorRoot || isUniqueId(el.ownerDocument, id))) return `#${CSS.escape(id)}`;
|
|
62
|
+
|
|
63
|
+
if (!selectorRoot) {
|
|
64
|
+
return getCssSelector(el, { selectors: ["id", "class", "tag", "nthchild"] }) ?? undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (el === selectorRoot) return rootAnchor ?? undefined;
|
|
68
|
+
|
|
69
|
+
const parts = climb(el, selectorRoot);
|
|
70
|
+
if (!parts || parts.length === 0) return undefined;
|
|
71
|
+
if (parts[0].startsWith("#")) return parts.join(" > ");
|
|
72
|
+
return rootAnchor ? `${rootAnchor} > ${parts.join(" > ")}` : parts.join(" > ");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The base textref every generated node gets: a bare "#id" URL fragment when
|
|
76
|
+
// the element has one, a "#css(<selector>)" fragment otherwise. Wraps
|
|
77
|
+
// selectorForElement's raw value so callers that already hold that value
|
|
78
|
+
// (e.g. domRangeGenerator.ts, reusing it for the same element) can skip
|
|
79
|
+
// recomputing it.
|
|
80
|
+
// Bare-id iff selector equals this element's own escaped id, unfooled by CSS.escape's literal spaces (id="foo bar").
|
|
81
|
+
export function textrefForSelector(selector: string | undefined, el: Element): string | undefined {
|
|
82
|
+
if (!selector) return undefined;
|
|
83
|
+
const id = el.getAttribute("id");
|
|
84
|
+
const isBareId = !!id && selector === `#${CSS.escape(id)}`;
|
|
85
|
+
return isBareId ? `#${encodeURIComponent(id)}` : encodeCssSelectorFragment(selector);
|
|
86
|
+
}
|
package/src/text.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { GuidedNavigationText } from "@readium/shared";
|
|
2
|
+
|
|
3
|
+
export interface TextBuilder {
|
|
4
|
+
plain: string;
|
|
5
|
+
ssml: string;
|
|
6
|
+
language: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function textIsEmpty(t: TextBuilder): boolean {
|
|
10
|
+
return t.plain === "" && t.ssml === "" && t.language === "";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function finalizeText(t?: TextBuilder): GuidedNavigationText | undefined {
|
|
14
|
+
if (!t || (t.plain === "" && t.ssml === "")) return undefined;
|
|
15
|
+
return new GuidedNavigationText({
|
|
16
|
+
plain: t.plain !== "" ? t.plain : undefined,
|
|
17
|
+
ssml: t.ssml !== "" ? t.ssml : undefined,
|
|
18
|
+
language: t.language !== "" ? t.language : undefined,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SSMLContext {
|
|
23
|
+
lang: string;
|
|
24
|
+
tag: string;
|
|
25
|
+
attrs?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function ctxEqual(a: SSMLContext, b: SSMLContext): boolean {
|
|
29
|
+
if (a.lang !== b.lang || a.tag !== b.tag) return false;
|
|
30
|
+
const ae = Object.entries(a.attrs ?? {});
|
|
31
|
+
const be = Object.entries(b.attrs ?? {});
|
|
32
|
+
if (ae.length !== be.length) return false;
|
|
33
|
+
return ae.every(([k, v]) => b.attrs?.[k] === v);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Unicode's Line_Break=GL ("glue") space codepoints; no `\p{...}` covers this directly.
|
|
37
|
+
const NO_BREAK_SPACE_RE = /[\u00A0\u2007\u202F]/;
|
|
38
|
+
|
|
39
|
+
export function isNoBreakSpace(ch: string): boolean {
|
|
40
|
+
return NO_BREAK_SPACE_RE.test(ch);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function normalizeWhitespace(text: string, stripLeading: boolean): string {
|
|
44
|
+
let out = "";
|
|
45
|
+
let lastWasWhite = false;
|
|
46
|
+
let reachedNonWhite = false;
|
|
47
|
+
for (const ch of text) {
|
|
48
|
+
if (isNoBreakSpace(ch)) {
|
|
49
|
+
// Never collapsed or stripped as leading, unlike an ordinary space.
|
|
50
|
+
out += ch;
|
|
51
|
+
lastWasWhite = false;
|
|
52
|
+
reachedNonWhite = true;
|
|
53
|
+
} else if (/\s/.test(ch)) {
|
|
54
|
+
if ((stripLeading && !reachedNonWhite) || lastWasWhite) continue;
|
|
55
|
+
out += " ";
|
|
56
|
+
lastWasWhite = true;
|
|
57
|
+
} else if (ch !== "\u200B" && ch !== "\u00AD") {
|
|
58
|
+
// zero width space, soft hyphen
|
|
59
|
+
out += ch;
|
|
60
|
+
lastWasWhite = false;
|
|
61
|
+
reachedNonWhite = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Generates a WICG Text Fragment directive for TextrefOptions.textFragment —
|
|
2
|
+
// see Converter.applyTextref in converter.ts. Delegates to @readium/helpers'
|
|
3
|
+
// text-fragments-polyfill port rather than reimplementing WICG's
|
|
4
|
+
// word-boundary/disambiguation logic.
|
|
5
|
+
import { generateFragmentFromRange, GenerateFragmentStatus } from "@readium/helpers";
|
|
6
|
+
import type { TextFragmentDirective } from "./textrefFragment.ts";
|
|
7
|
+
|
|
8
|
+
export function textFragmentDirectiveFor(range: Range): TextFragmentDirective | undefined {
|
|
9
|
+
const result = generateFragmentFromRange(range);
|
|
10
|
+
return result.status === GenerateFragmentStatus.SUCCESS ? result.fragment : undefined;
|
|
11
|
+
}
|