@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/dom.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const ELEMENT_NODE = 1;
|
|
2
|
+
|
|
3
|
+
export function nodeLanguage(el: Element | null): string {
|
|
4
|
+
for (let n: Element | null = el; n; n = n.parentElement) {
|
|
5
|
+
const xmlLang = n.getAttribute("xml:lang");
|
|
6
|
+
if (xmlLang) return xmlLang;
|
|
7
|
+
const lang = n.getAttribute("lang");
|
|
8
|
+
if (lang) return lang;
|
|
9
|
+
}
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function hasElementChild(el: Element): boolean {
|
|
14
|
+
for (let c = el.firstChild; c; c = c.nextSibling) {
|
|
15
|
+
if (c.nodeType === ELEMENT_NODE) return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isAncestorOf(anc: Element, n: Element): boolean {
|
|
21
|
+
for (let p: Element | null = n; p; p = p.parentElement) {
|
|
22
|
+
if (p === anc) return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// From jsoup, everything except "device":
|
|
28
|
+
// https://github.com/jhy/jsoup/blob/0b10d516ed8f907f8fb4acb9a0806137a8988d45/src/main/java/org/jsoup/parser/Tag.java#L243
|
|
29
|
+
const inlineTags = new Set([
|
|
30
|
+
"object", "base", "font", "tt", "i", "b", "u", "big", "small", "em", "strong",
|
|
31
|
+
"dfn", "code", "samp", "kbd", "var", "cite", "abbr", "time", "acronym",
|
|
32
|
+
"mark", "ruby", "rt", "rp", "rtc", "a", "img", "br", "wbr", "map", "q",
|
|
33
|
+
"sub", "sup", "bdo", "iframe", "embed", "span", "input", "select",
|
|
34
|
+
"textarea", "label", "button", "optgroup", "option", "legend", "datalist",
|
|
35
|
+
"keygen", "output", "progress", "meter", "area", "param", "source",
|
|
36
|
+
"track", "summary", "command", "basefont", "bgsound", "menuitem", "data",
|
|
37
|
+
"bdi", "s", "strike", "nobr", "rb",
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export function isInlineTag(tagName: string): boolean {
|
|
41
|
+
return inlineTags.has(tagName);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type GndMediaType = "text/html" | "application/xhtml+xml";
|
|
45
|
+
|
|
46
|
+
export function sniffMediaType(input: string): GndMediaType {
|
|
47
|
+
const head = input.slice(0, 500);
|
|
48
|
+
if (
|
|
49
|
+
/<\?xml\b/.test(head) ||
|
|
50
|
+
/xmlns:epub=/.test(head) ||
|
|
51
|
+
/DOCTYPE\s+html\s+PUBLIC\s+"-\/\/W3C\/\/DTD XHTML/i.test(head)
|
|
52
|
+
) {
|
|
53
|
+
return "application/xhtml+xml";
|
|
54
|
+
}
|
|
55
|
+
return "text/html";
|
|
56
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Builds a Locator DomRange for TextrefOptions.domRange — see
|
|
2
|
+
// Converter.applyTextref in converter.ts.
|
|
3
|
+
import type { DomRangeJSON } from "./textrefFragment.ts";
|
|
4
|
+
import { selectorForElement } from "./selectorGenerator.ts";
|
|
5
|
+
|
|
6
|
+
const TEXT_NODE = 3;
|
|
7
|
+
|
|
8
|
+
// A DomRangePoint's textNodeIndex counts only among container's Text-node
|
|
9
|
+
// children, per the Locator HTML extension spec.
|
|
10
|
+
function textNodeIndexAmongChildren(container: Element, target: Text): number {
|
|
11
|
+
let idx = 0;
|
|
12
|
+
for (const child of Array.from(container.childNodes)) {
|
|
13
|
+
if (child === target) return idx;
|
|
14
|
+
if (child.nodeType === TEXT_NODE) idx++;
|
|
15
|
+
}
|
|
16
|
+
return idx;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// A selector already computed for `el` elsewhere (applyTextref's own base
|
|
20
|
+
// textref) — reused instead of recomputed when a range point's container
|
|
21
|
+
// turns out to be that same element.
|
|
22
|
+
export interface KnownSelector {
|
|
23
|
+
el: Element;
|
|
24
|
+
selector: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function domRangePoint(
|
|
28
|
+
node: Text,
|
|
29
|
+
offset: number,
|
|
30
|
+
selectorRoot: Element | null,
|
|
31
|
+
rootAnchor: string | null,
|
|
32
|
+
known: KnownSelector | undefined,
|
|
33
|
+
): DomRangeJSON["start"] | undefined {
|
|
34
|
+
const container = node.parentElement;
|
|
35
|
+
if (!container) return undefined;
|
|
36
|
+
const cssSelector =
|
|
37
|
+
known && container === known.el ? known.selector : selectorForElement(container, selectorRoot, rootAnchor);
|
|
38
|
+
if (!cssSelector) return undefined;
|
|
39
|
+
return { cssSelector, textNodeIndex: textNodeIndexAmongChildren(container, node), charOffset: offset };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Builds a Locator DomRange pinpointing range's exact start/end text nodes
|
|
43
|
+
// and character offsets, not just the containing element — only meaningful
|
|
44
|
+
// against a live, already-rendered document (see TextrefOptions.domRange).
|
|
45
|
+
export function generateDomRange(
|
|
46
|
+
range: { first: [Text, number]; last: [Text, number] },
|
|
47
|
+
selectorRoot: Element | null,
|
|
48
|
+
rootAnchor: string | null,
|
|
49
|
+
known?: KnownSelector,
|
|
50
|
+
): DomRangeJSON | undefined {
|
|
51
|
+
const start = domRangePoint(...range.first, selectorRoot, rootAnchor, known);
|
|
52
|
+
if (!start) return undefined;
|
|
53
|
+
const end = domRangePoint(...range.last, selectorRoot, rootAnchor, known);
|
|
54
|
+
return end ? { start, end } : { start };
|
|
55
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Handlers for element kinds that build one placeholder ObjBuilder each
|
|
2
|
+
// (pagebreak/noteref/link), calling back into the converter for
|
|
3
|
+
// placeholder() and, for noteref's footnote embedding, convert()/resultBuilders()
|
|
4
|
+
// on a sub-Converter of its own.
|
|
5
|
+
import type { GndRole } from "./types.ts";
|
|
6
|
+
import { normalizedNodeText } from "./a11y.ts";
|
|
7
|
+
import { textIsEmpty } from "./text.ts";
|
|
8
|
+
import { type ObjBuilder, ariaSubstitutedBuilders, substitutedOwnSelectorBuilders } from "./object.ts";
|
|
9
|
+
import { hasElementChild, isAncestorOf } from "./dom.ts";
|
|
10
|
+
import { Converter } from "./converter.ts";
|
|
11
|
+
import { selectorForElement, textrefForSelector } from "./selectorGenerator.ts";
|
|
12
|
+
|
|
13
|
+
// Returns true if el's children should still be descended into (a
|
|
14
|
+
// pagebreak with element children of its own, in HTML parsing).
|
|
15
|
+
export function pagebreak(converter: Converter, el: Element, aria: string | null, roles: GndRole[]): boolean {
|
|
16
|
+
const obj: ObjBuilder = { role: roles };
|
|
17
|
+
const title = (el.getAttribute("title") ?? "").trim();
|
|
18
|
+
if (title) {
|
|
19
|
+
obj.text = { plain: title, ssml: "", language: "" };
|
|
20
|
+
} else if (aria) {
|
|
21
|
+
obj.text = { plain: aria, ssml: "", language: "" };
|
|
22
|
+
ariaSubstitutedBuilders.add(obj);
|
|
23
|
+
}
|
|
24
|
+
const labelled = !!(obj.text && !textIsEmpty(obj.text));
|
|
25
|
+
const descend = !converter.xmlParsed && (hasElementChild(el) || (labelled && el.firstChild !== null));
|
|
26
|
+
if (!labelled && !descend) {
|
|
27
|
+
const text = normalizedNodeText(el);
|
|
28
|
+
if (text) obj.text = { plain: text, ssml: "", language: "" };
|
|
29
|
+
}
|
|
30
|
+
const selector = selectorForElement(el, converter.selectorRoot, converter.selectorRootAnchor);
|
|
31
|
+
const textref = textrefForSelector(selector, el);
|
|
32
|
+
if (textref) obj.textref = textref;
|
|
33
|
+
converter.placeholder(el, "pagebreak", obj);
|
|
34
|
+
return descend;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function noteref(converter: Converter, el: Element, roles: GndRole[]): void {
|
|
38
|
+
const obj: ObjBuilder = { role: roles };
|
|
39
|
+
const text = normalizedNodeText(el);
|
|
40
|
+
if (text) obj.text = { plain: text, ssml: "", language: "" };
|
|
41
|
+
|
|
42
|
+
const href = el.getAttribute("href") ?? "";
|
|
43
|
+
let candidateID = el.getAttribute("id") ?? "";
|
|
44
|
+
if (!candidateID && href.startsWith("#")) {
|
|
45
|
+
// A target still output at its own location keeps its id there.
|
|
46
|
+
const target = converter.ids.get(href.slice(1));
|
|
47
|
+
if (!target || converter.suppressed.has(target)) candidateID = href.slice(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (href.startsWith("#")) {
|
|
51
|
+
const fragment = href.slice(1);
|
|
52
|
+
const target = converter.ids.get(fragment);
|
|
53
|
+
if (target && !isAncestorOf(target, el) && converter.noterefDepth < 3) {
|
|
54
|
+
const sub = converter.spawnChild(target);
|
|
55
|
+
sub.convert(target);
|
|
56
|
+
const children = sub.resultBuilders();
|
|
57
|
+
if (children.length > 0) {
|
|
58
|
+
// The target's own id already carries its meaning via this
|
|
59
|
+
// noteref's own id — repeating it on the embedded content would
|
|
60
|
+
// be redundant.
|
|
61
|
+
for (const c of children) delete c.id;
|
|
62
|
+
obj.children = children;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (!obj.children && href) {
|
|
67
|
+
obj.children = [{ textref: href }];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
converter.placeholder(el, "noteref", obj, candidateID || undefined);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function link(converter: Converter, el: Element, roles: GndRole[], aria: string | null): void {
|
|
74
|
+
const obj: ObjBuilder = {};
|
|
75
|
+
if (roles.length > 0) obj.role = roles;
|
|
76
|
+
if (aria) {
|
|
77
|
+
obj.text = { plain: aria, ssml: "", language: "" };
|
|
78
|
+
ariaSubstitutedBuilders.add(obj);
|
|
79
|
+
const selector = selectorForElement(el, converter.selectorRoot, converter.selectorRootAnchor);
|
|
80
|
+
if (selector) substitutedOwnSelectorBuilders.set(obj, selector);
|
|
81
|
+
} else {
|
|
82
|
+
const text = normalizedNodeText(el);
|
|
83
|
+
if (text) obj.text = { plain: text, ssml: "", language: "" };
|
|
84
|
+
}
|
|
85
|
+
const href = el.getAttribute("href");
|
|
86
|
+
if (href) obj.textref = href;
|
|
87
|
+
converter.placeholder(el, roles[0] ?? "link", obj);
|
|
88
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Allocates/claims ids for SSML placeholders (<readium:noteref id="..." />
|
|
2
|
+
// and friends), shared across sub-Converters — see Converter.idAlloc.
|
|
3
|
+
export class IdAllocator {
|
|
4
|
+
private claimed = new Set<string>();
|
|
5
|
+
private counters = new Map<string, number>();
|
|
6
|
+
|
|
7
|
+
// `isTaken` additionally excludes ids already in use elsewhere (e.g. a
|
|
8
|
+
// real author-written id in the document) that this allocator has no way
|
|
9
|
+
// of knowing about on its own.
|
|
10
|
+
allocate(prefix: string, isTaken: (id: string) => boolean): string {
|
|
11
|
+
for (;;) {
|
|
12
|
+
const n = (this.counters.get(prefix) ?? 0) + 1;
|
|
13
|
+
this.counters.set(prefix, n);
|
|
14
|
+
const id = `${prefix}${n}`;
|
|
15
|
+
if (isTaken(id) || this.claimed.has(id)) continue;
|
|
16
|
+
this.claimed.add(id);
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
claim(id: string): boolean {
|
|
22
|
+
if (this.claimed.has(id)) return false;
|
|
23
|
+
this.claimed.add(id);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type { GndRole } from "./types.ts";
|
|
2
|
+
export { makeGnd } from "./makeGnd.ts";
|
|
3
|
+
export { parseMarkup } from "./converter.ts";
|
|
4
|
+
export type { GndMediaType } from "./dom.ts";
|
|
5
|
+
export type { GndGenerationOptions, TextrefOptions } from "./options.ts";
|
|
6
|
+
export {
|
|
7
|
+
encodeCssSelectorFragment,
|
|
8
|
+
decodeCssSelectorFragment,
|
|
9
|
+
encodeDomRangeFragment,
|
|
10
|
+
decodeDomRangeFragment,
|
|
11
|
+
decodeTextref,
|
|
12
|
+
combineDomRangeTextrefs,
|
|
13
|
+
} from "./textrefFragment.ts";
|
|
14
|
+
export type { DomRangeJSON, DecodedTextref } from "./textrefFragment.ts";
|
|
15
|
+
export { isAriaSubstituted, substitutedOwnSelector } from "./object.ts";
|
package/src/makeGnd.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GuidedNavigationDocument } from "@readium/shared";
|
|
2
|
+
import { parseMarkup } from "./converter.ts";
|
|
3
|
+
import type { GndMediaType } from "./dom.ts";
|
|
4
|
+
import type { GndGenerationOptions } from "./options.ts";
|
|
5
|
+
|
|
6
|
+
export type { GndMediaType };
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Builds a Guided Navigation document from an HTML or XHTML fragment or
|
|
10
|
+
* document, following https://github.com/readium/guided-navigation.
|
|
11
|
+
* Returns undefined when the input has no navigable content, as `guided` can't be empty.
|
|
12
|
+
*/
|
|
13
|
+
export function makeGnd(
|
|
14
|
+
input: string | Element,
|
|
15
|
+
mediaType?: GndMediaType,
|
|
16
|
+
options?: GndGenerationOptions,
|
|
17
|
+
): GuidedNavigationDocument | undefined {
|
|
18
|
+
const guided = parseMarkup(input, mediaType, options);
|
|
19
|
+
return guided.length > 0 ? new GuidedNavigationDocument({ guided }) : undefined;
|
|
20
|
+
}
|
package/src/object.ts
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { GuidedNavigationDescription, GuidedNavigationObject, GuidedNavigationText } from "@readium/shared";
|
|
2
|
+
import type { GndRole } from "./types.ts";
|
|
3
|
+
import { type TextBuilder, textIsEmpty, finalizeText } from "./text.ts";
|
|
4
|
+
|
|
5
|
+
export interface ObjBuilder {
|
|
6
|
+
id?: string;
|
|
7
|
+
audioref?: string;
|
|
8
|
+
imgref?: string;
|
|
9
|
+
textref?: string;
|
|
10
|
+
videoref?: string;
|
|
11
|
+
text?: TextBuilder;
|
|
12
|
+
role?: GndRole[];
|
|
13
|
+
children?: ObjBuilder[];
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Roles whose entire information is the role itself, with no ref/text/
|
|
18
|
+
// children to otherwise survive on: `math` has no ref field of its own
|
|
19
|
+
// (unlike audio/image/video, it names no external resource), and
|
|
20
|
+
// `separator` (e.g. `<hr>`) is content-free by design.
|
|
21
|
+
const contentFreeRoles: readonly GndRole[] = ["math", "separator"];
|
|
22
|
+
|
|
23
|
+
// Marks text substituted from aria-label/aria-labelledby rather than the
|
|
24
|
+
// element's own content — the Node set mirrors the Builder one across finalizeToGuidedNavigationObject().
|
|
25
|
+
export const ariaSubstitutedBuilders = new WeakSet<ObjBuilder>();
|
|
26
|
+
const ariaSubstitutedNodes = new WeakSet<GuidedNavigationObject>();
|
|
27
|
+
|
|
28
|
+
// A substituted link's own CSS selector — its `textref` is its href, which
|
|
29
|
+
// never resolves to an on-page location, so this is its fallback box (set only by link()).
|
|
30
|
+
export const substitutedOwnSelectorBuilders = new WeakMap<ObjBuilder, string>();
|
|
31
|
+
const substitutedOwnSelectorNodes = new WeakMap<GuidedNavigationObject, string>();
|
|
32
|
+
|
|
33
|
+
// Only objects produced by this module's parseMarkup()/makeGnd() carry this; an object deserialized from JSON never does.
|
|
34
|
+
export function isAriaSubstituted(node: GuidedNavigationObject): boolean {
|
|
35
|
+
return ariaSubstitutedNodes.has(node);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function substitutedOwnSelector(node: GuidedNavigationObject): string | undefined {
|
|
39
|
+
return substitutedOwnSelectorNodes.get(node);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function isEmptyObj(o: ObjBuilder): boolean {
|
|
43
|
+
if (o.role?.some((role) => contentFreeRoles.includes(role))) return false;
|
|
44
|
+
return (
|
|
45
|
+
!o.audioref &&
|
|
46
|
+
!o.imgref &&
|
|
47
|
+
!o.textref &&
|
|
48
|
+
!o.videoref &&
|
|
49
|
+
(!o.text || textIsEmpty(o.text)) &&
|
|
50
|
+
!(o.children && o.children.length > 0) &&
|
|
51
|
+
!o.description
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// A transparent wrapper (e.g. a plain <div>) carrying no information of its
|
|
56
|
+
// own besides its children — spliced into the parent's children.
|
|
57
|
+
function isChildrenOnly(o: ObjBuilder): boolean {
|
|
58
|
+
return (
|
|
59
|
+
!o.audioref &&
|
|
60
|
+
!o.imgref &&
|
|
61
|
+
!o.textref &&
|
|
62
|
+
!o.videoref &&
|
|
63
|
+
(!o.text || textIsEmpty(o.text)) &&
|
|
64
|
+
!!(o.children && o.children.length > 0) &&
|
|
65
|
+
!(o.role && o.role.length > 0) &&
|
|
66
|
+
!o.id &&
|
|
67
|
+
!o.description
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A lone child with no role/id/ref of its own: its text is hoisted into the
|
|
72
|
+
// parent object directly, e.g. a paragraph wrapping plain emphasis becomes
|
|
73
|
+
// {role, text} rather than nesting an anonymous child. A child carrying its
|
|
74
|
+
// own ref (e.g. an <a href>'s textref) is never hoisted — refs identify a
|
|
75
|
+
// distinct target and merging them into the parent would silently discard
|
|
76
|
+
// whichever of the two textrefs isn't kept.
|
|
77
|
+
function isHoistable(o: ObjBuilder): boolean {
|
|
78
|
+
return (
|
|
79
|
+
!(o.role && o.role.length > 0) &&
|
|
80
|
+
!o.id &&
|
|
81
|
+
!o.description &&
|
|
82
|
+
!o.textref &&
|
|
83
|
+
!o.imgref &&
|
|
84
|
+
!o.audioref &&
|
|
85
|
+
!o.videoref
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A node being built up during the tree walk, before its final shape is known. */
|
|
90
|
+
export class NavObject {
|
|
91
|
+
el?: Element;
|
|
92
|
+
object: ObjBuilder = {};
|
|
93
|
+
children: NavObject[] = [];
|
|
94
|
+
noText = false;
|
|
95
|
+
hasChildBlock = false;
|
|
96
|
+
|
|
97
|
+
// `selfTextref` references this object's own element, for objects that would otherwise lack the schema's required content.
|
|
98
|
+
finalize(selfTextref?: (el: Element) => string | undefined): ObjBuilder {
|
|
99
|
+
const result = this.object;
|
|
100
|
+
const finalChildren: ObjBuilder[] = [];
|
|
101
|
+
for (const child of this.children) {
|
|
102
|
+
const res = child.finalize(selfTextref);
|
|
103
|
+
if (isEmptyObj(res)) continue;
|
|
104
|
+
if (isChildrenOnly(res)) {
|
|
105
|
+
finalChildren.push(...(res.children ?? []));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
finalChildren.push(res);
|
|
109
|
+
}
|
|
110
|
+
if (finalChildren.length > 0) result.children = finalChildren;
|
|
111
|
+
|
|
112
|
+
// A wrapper whose own role is entirely redundant with its sole child's
|
|
113
|
+
// role (e.g. <dt><dfn>term</dfn></dt> naming one term twice) sheds that
|
|
114
|
+
// role — the child already carries it. Excludes "presentation": unlike
|
|
115
|
+
// every other role, it cascades from an ancestor onto real structural
|
|
116
|
+
// descendants (HTML-AAM's presentational-table rule) rather than
|
|
117
|
+
// marking the same entity twice, so identical nesting there is genuine.
|
|
118
|
+
if (result.role?.length && result.children?.length === 1 && !result.role.includes("presentation")) {
|
|
119
|
+
const child = result.children[0];
|
|
120
|
+
if (child.role?.length && result.role.every((role) => child.role!.includes(role))) {
|
|
121
|
+
delete result.role;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Hoist a lone child with no role/id/ref into the object itself: its text
|
|
126
|
+
// merges directly into the parent, e.g. a paragraph wrapping plain
|
|
127
|
+
// emphasis becomes {role, text} instead of nesting an anonymous child.
|
|
128
|
+
if ((!result.text || textIsEmpty(result.text)) && result.children?.length === 1) {
|
|
129
|
+
const child = result.children[0];
|
|
130
|
+
if (isHoistable(child)) {
|
|
131
|
+
if (child.text) result.text = child.text;
|
|
132
|
+
result.children = child.children;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (this.el && selfTextref && !isEmptyObj(result) && !hasRequiredContent(result)) {
|
|
137
|
+
const textref = selfTextref(this.el);
|
|
138
|
+
if (textref) result.textref = textref;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// The Guided Navigation schema requires at least one ref, a non-empty text, or children.
|
|
146
|
+
function hasRequiredContent(o: ObjBuilder): boolean {
|
|
147
|
+
return (
|
|
148
|
+
!!o.audioref ||
|
|
149
|
+
!!o.imgref ||
|
|
150
|
+
!!o.textref ||
|
|
151
|
+
!!o.videoref ||
|
|
152
|
+
!!(o.text && (o.text.plain !== "" || o.text.ssml !== "")) ||
|
|
153
|
+
!!(o.children && o.children.length > 0)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function finalizeToGuidedNavigationObject(o: ObjBuilder): GuidedNavigationObject {
|
|
158
|
+
const node = new GuidedNavigationObject({
|
|
159
|
+
id: o.id || undefined,
|
|
160
|
+
textref: o.textref || undefined,
|
|
161
|
+
imgref: o.imgref || undefined,
|
|
162
|
+
audioref: o.audioref || undefined,
|
|
163
|
+
videoref: o.videoref || undefined,
|
|
164
|
+
text: finalizeText(o.text),
|
|
165
|
+
role: o.role && o.role.length > 0 ? new Set(o.role) : undefined,
|
|
166
|
+
children: o.children && o.children.length > 0 ? o.children.map(finalizeToGuidedNavigationObject) : undefined,
|
|
167
|
+
description: o.description
|
|
168
|
+
? new GuidedNavigationDescription({ text: new GuidedNavigationText({ plain: o.description }) })
|
|
169
|
+
: undefined,
|
|
170
|
+
});
|
|
171
|
+
if (ariaSubstitutedBuilders.has(o)) ariaSubstitutedNodes.add(node);
|
|
172
|
+
const ownSelector = substitutedOwnSelectorBuilders.get(o);
|
|
173
|
+
if (ownSelector) substitutedOwnSelectorNodes.set(node, ownSelector);
|
|
174
|
+
return node;
|
|
175
|
+
}
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { GndRole } from "./types.ts";
|
|
2
|
+
|
|
3
|
+
// Not a GND role, never written to a node's `role` — an opt-in keyword for
|
|
4
|
+
// the `roles` array, matching a roleless block that owns its own leaf text
|
|
5
|
+
// (e.g. a <div> used where a <p> would normally go).
|
|
6
|
+
export const leafTextRoleKeyword = "leaf-text";
|
|
7
|
+
|
|
8
|
+
export interface TextrefOptions {
|
|
9
|
+
// Which roles get a generated textref reference. `true` covers every node
|
|
10
|
+
// that gets a role; an array restricts generation to just those roles.
|
|
11
|
+
// Either form may also include/be leafTextRoleKeyword to cover roleless
|
|
12
|
+
// leaf-text blocks too.
|
|
13
|
+
roles?: boolean | GndRole[];
|
|
14
|
+
// Also compute a DomRange (textNodeIndex/charOffset) alongside the CSS
|
|
15
|
+
// selector, for exact (not css-selector-only) DOM addressing. Requires
|
|
16
|
+
// converting a live, already-rendered element (see Converter.convert) —
|
|
17
|
+
// a domRange computed against parseMarkup()'s detached document can't be
|
|
18
|
+
// resolved back against whatever later renders the resource, so it's a
|
|
19
|
+
// no-op there.
|
|
20
|
+
domRange?: boolean;
|
|
21
|
+
// Also append a WICG Text Fragment (":~:text=...") directive when the
|
|
22
|
+
// node's own text can be found uniquely (or made unique with bounded
|
|
23
|
+
// surrounding context) across the whole document. Unlike domRange, this
|
|
24
|
+
// only needs the document's text content, so it works against
|
|
25
|
+
// parseMarkup()'s detached document too, not just a live element.
|
|
26
|
+
textFragment?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface GndGenerationOptions {
|
|
30
|
+
// Generates a reference (see textrefFragment.ts) into textref for
|
|
31
|
+
// nodes as they're converted. Off by default — selector generation has a
|
|
32
|
+
// real compute cost.
|
|
33
|
+
textrefs?: boolean | GndRole[] | TextrefOptions;
|
|
34
|
+
// Re-parse string input as text/html when XHTML parsing fails, instead of
|
|
35
|
+
// throwing.
|
|
36
|
+
htmlFallback?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizeRoles(opt: boolean | GndRole[] | undefined): ((roles: GndRole[]) => boolean) | null {
|
|
40
|
+
if (opt === true) return (roles) => roles.length > 0;
|
|
41
|
+
if (Array.isArray(opt) && opt.length > 0) {
|
|
42
|
+
const set = new Set(opt.filter((r) => r !== leafTextRoleKeyword));
|
|
43
|
+
return (roles) => roles.some((r) => set.has(r));
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function wantsLeafText(opt: boolean | GndRole[] | undefined): boolean {
|
|
49
|
+
return opt === true || (Array.isArray(opt) && opt.includes(leafTextRoleKeyword));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface NormalizedTextrefOptions {
|
|
53
|
+
predicate: ((roles: GndRole[]) => boolean) | null;
|
|
54
|
+
leafText: boolean;
|
|
55
|
+
domRange: boolean;
|
|
56
|
+
textFragment: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isTextrefOptions(
|
|
60
|
+
opt: GndGenerationOptions["textrefs"],
|
|
61
|
+
): opt is TextrefOptions {
|
|
62
|
+
return !!opt && typeof opt === "object" && !Array.isArray(opt);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function normalizeTextrefOptions(
|
|
66
|
+
opt: GndGenerationOptions["textrefs"],
|
|
67
|
+
): NormalizedTextrefOptions {
|
|
68
|
+
if (isTextrefOptions(opt)) {
|
|
69
|
+
return {
|
|
70
|
+
predicate: normalizeRoles(opt.roles),
|
|
71
|
+
leafText: wantsLeafText(opt.roles),
|
|
72
|
+
domRange: !!opt.domRange,
|
|
73
|
+
textFragment: !!opt.textFragment,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return { predicate: normalizeRoles(opt), leafText: wantsLeafText(opt), domRange: false, textFragment: false };
|
|
77
|
+
}
|
package/src/prescan.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { extractNodeRoles } from "./roles.ts";
|
|
2
|
+
import { isAncestorOf } from "./dom.ts";
|
|
3
|
+
|
|
4
|
+
function hasEndnotesAncestor(el: Element): boolean {
|
|
5
|
+
for (let p: Element | null = el.parentElement; p; p = p.parentElement) {
|
|
6
|
+
if (extractNodeRoles(p).includes("endnotes")) return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// One pass over root before the real walk: records every element's own id
|
|
12
|
+
// (for noteref/pagebreak href resolution), and suppresses a noteref's
|
|
13
|
+
// target from also appearing at its original location.
|
|
14
|
+
export function prescan(root: Element, ids: Map<string, Element>, suppressed: Set<Element>): void {
|
|
15
|
+
const noterefTargets: { id: string; ref: Element }[] = [];
|
|
16
|
+
const walk = (n: Element, hidden: boolean) => {
|
|
17
|
+
const id = n.getAttribute("id");
|
|
18
|
+
if (id && !ids.has(id)) ids.set(id, n);
|
|
19
|
+
hidden = hidden || n.getAttribute("aria-hidden") === "true" || n.hasAttribute("hidden");
|
|
20
|
+
if (!hidden && n.tagName.toLowerCase() === "a") {
|
|
21
|
+
const roles = extractNodeRoles(n);
|
|
22
|
+
if (roles.includes("noteref")) {
|
|
23
|
+
const href = n.getAttribute("href") ?? "";
|
|
24
|
+
if (href.startsWith("#")) {
|
|
25
|
+
noterefTargets.push({ id: href.slice(1), ref: n });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
for (let c = n.firstElementChild; c; c = c.nextElementSibling) walk(c, hidden);
|
|
30
|
+
};
|
|
31
|
+
walk(root, false);
|
|
32
|
+
|
|
33
|
+
for (const target of noterefTargets) {
|
|
34
|
+
const n = ids.get(target.id);
|
|
35
|
+
if (!n) continue;
|
|
36
|
+
if (isAncestorOf(n, target.ref)) continue;
|
|
37
|
+
if (hasEndnotesAncestor(n)) continue;
|
|
38
|
+
suppressed.add(n);
|
|
39
|
+
}
|
|
40
|
+
}
|