@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
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// textref fragments: a "#css()" fragment carrying a CSS selector, a
|
|
2
|
+
// "#domrange()" fragment (for callers converting a live, already-rendered
|
|
3
|
+
// DOM) carrying a serialized Locator DomRange — see the Locator HTML
|
|
4
|
+
// extension spec: https://readium.org/architecture/models/locators/extensions/html.html#the-domrange-object
|
|
5
|
+
// — and a ":~:text=..." suffix per the WICG Text Fragments spec
|
|
6
|
+
// (https://wicg.github.io/scroll-to-text-fragment/), which appends onto
|
|
7
|
+
// whatever fragment already precedes it rather than replacing it. None of
|
|
8
|
+
// these is a Locator itself — textref is a plain URI reference, per the
|
|
9
|
+
// guided-navigation spec.
|
|
10
|
+
|
|
11
|
+
const CSS_PREFIX = "#css(";
|
|
12
|
+
const CSS_SUFFIX = ")";
|
|
13
|
+
|
|
14
|
+
export function encodeCssSelectorFragment(selector: string): string {
|
|
15
|
+
return `${CSS_PREFIX}${encodeURIComponent(selector)}${CSS_SUFFIX}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function decodeCssSelectorFragment(textref: string | undefined): string | undefined {
|
|
19
|
+
if (!textref || !textref.startsWith(CSS_PREFIX) || !textref.endsWith(CSS_SUFFIX)) return undefined;
|
|
20
|
+
return decodeURIComponent(textref.slice(CSS_PREFIX.length, -CSS_SUFFIX.length));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DOMRANGE_PREFIX = "#domrange(";
|
|
24
|
+
const DOMRANGE_SUFFIX = ")";
|
|
25
|
+
|
|
26
|
+
// The RWPM JSON shape produced/consumed by @readium/shared's DomRange —
|
|
27
|
+
// {start: {cssSelector, textNodeIndex, charOffset?}, end?: {...}}.
|
|
28
|
+
export interface DomRangeJSON {
|
|
29
|
+
start: { cssSelector: string; textNodeIndex: number; charOffset?: number };
|
|
30
|
+
end?: { cssSelector: string; textNodeIndex: number; charOffset?: number };
|
|
31
|
+
// The block element's own selector — distinct from start's selector, which
|
|
32
|
+
// is whatever child actually contains the first flow text node (e.g. a
|
|
33
|
+
// word-token <span>), not the block itself.
|
|
34
|
+
container?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function encodeDomRangeFragment(domRange: DomRangeJSON): string {
|
|
38
|
+
return `${DOMRANGE_PREFIX}${encodeURIComponent(JSON.stringify(domRange))}${DOMRANGE_SUFFIX}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function decodeDomRangeFragment(textref: string | undefined): DomRangeJSON | undefined {
|
|
42
|
+
if (!textref || !textref.startsWith(DOMRANGE_PREFIX) || !textref.endsWith(DOMRANGE_SUFFIX)) return undefined;
|
|
43
|
+
try {
|
|
44
|
+
const json = JSON.parse(decodeURIComponent(textref.slice(DOMRANGE_PREFIX.length, -DOMRANGE_SUFFIX.length)));
|
|
45
|
+
if (!json?.start?.cssSelector || typeof json.start.textNodeIndex !== "number") return undefined;
|
|
46
|
+
return json as DomRangeJSON;
|
|
47
|
+
} catch {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const TEXT_DIRECTIVE_MARK = ":~:text=";
|
|
53
|
+
|
|
54
|
+
// WICG Text Fragments directive grammar: text=[prefix-,]textStart[,textEnd][,-suffix].
|
|
55
|
+
export interface TextFragmentDirective {
|
|
56
|
+
textStart: string;
|
|
57
|
+
textEnd?: string;
|
|
58
|
+
prefix?: string;
|
|
59
|
+
suffix?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// A literal "-" isn't touched by encodeURIComponent, but the grammar uses
|
|
63
|
+
// "-," and ",-" as prefix/suffix markers, so it must always be escaped in
|
|
64
|
+
// content to stay unambiguous.
|
|
65
|
+
function encodeFragmentPart(s: string): string {
|
|
66
|
+
return encodeURIComponent(s).replace(/-/g, "%2D");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function encodeTextFragmentDirective(fragment: TextFragmentDirective): string {
|
|
70
|
+
let s = "";
|
|
71
|
+
if (fragment.prefix) s += `${encodeFragmentPart(fragment.prefix)}-,`;
|
|
72
|
+
s += encodeFragmentPart(fragment.textStart);
|
|
73
|
+
if (fragment.textEnd) s += `,${encodeFragmentPart(fragment.textEnd)}`;
|
|
74
|
+
if (fragment.suffix) s += `,-${encodeFragmentPart(fragment.suffix)}`;
|
|
75
|
+
return `${TEXT_DIRECTIVE_MARK}${s}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Locates ":~:text=" anywhere in textref — it's a suffix appended onto
|
|
79
|
+
// whatever fragment (bare id / #css(...) / #domrange(...)) already precedes
|
|
80
|
+
// it, never the whole string.
|
|
81
|
+
export function decodeTextFragmentDirective(textref: string | undefined): TextFragmentDirective | undefined {
|
|
82
|
+
if (!textref) return undefined;
|
|
83
|
+
const markIndex = textref.indexOf(TEXT_DIRECTIVE_MARK);
|
|
84
|
+
if (markIndex === -1) return undefined;
|
|
85
|
+
const raw = textref.slice(markIndex + TEXT_DIRECTIVE_MARK.length).split("&")[0];
|
|
86
|
+
if (!raw) return undefined;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
let parts = raw.split(",");
|
|
90
|
+
const result: TextFragmentDirective = { textStart: "" };
|
|
91
|
+
|
|
92
|
+
if (parts[0].endsWith("-")) {
|
|
93
|
+
result.prefix = decodeURIComponent(parts[0].slice(0, -1));
|
|
94
|
+
parts = parts.slice(1);
|
|
95
|
+
}
|
|
96
|
+
if (parts.length > 0 && parts[parts.length - 1].startsWith("-")) {
|
|
97
|
+
result.suffix = decodeURIComponent(parts[parts.length - 1].slice(1));
|
|
98
|
+
parts = parts.slice(0, -1);
|
|
99
|
+
}
|
|
100
|
+
if (parts.length === 0 || parts[0] === "") return undefined;
|
|
101
|
+
|
|
102
|
+
result.textStart = decodeURIComponent(parts[0]);
|
|
103
|
+
if (parts.length > 1) result.textEnd = decodeURIComponent(parts[1]);
|
|
104
|
+
return result;
|
|
105
|
+
} catch {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface DecodedTextref {
|
|
111
|
+
cssSelector?: string;
|
|
112
|
+
domRange?: DomRangeJSON;
|
|
113
|
+
text?: { highlight?: string; before?: string; after?: string };
|
|
114
|
+
fragment?: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Combines two nodes' own decoded textrefs into one spanning locator (each
|
|
118
|
+
// `DomRangeJSON` point carries its own `cssSelector`, so start/end in two
|
|
119
|
+
// different elements is already legal). `undefined` when either side has no
|
|
120
|
+
// `domRange` to combine — a bare selector has no `textNodeIndex` to build one from.
|
|
121
|
+
export function combineDomRangeTextrefs(first: DecodedTextref, last: DecodedTextref): DecodedTextref | undefined {
|
|
122
|
+
if (!first.domRange || !last.domRange) return undefined;
|
|
123
|
+
const domRange: DomRangeJSON = { start: first.domRange.start, end: last.domRange.end ?? last.domRange.start };
|
|
124
|
+
if (first.domRange.container !== undefined) domRange.container = first.domRange.container;
|
|
125
|
+
return { domRange, cssSelector: domRange.container ?? domRange.start.cssSelector };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function decodeIdFragment(base: string): string | undefined {
|
|
129
|
+
if (!base.startsWith("#")) return undefined;
|
|
130
|
+
try {
|
|
131
|
+
return decodeURIComponent(base.slice(1));
|
|
132
|
+
} catch {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Decodes a node's own generated textref, distinguishing it from an
|
|
138
|
+
// unrelated navigational textref (link href, pagebreak/noteref reference)
|
|
139
|
+
// that happens to also start with "#" — those are never wrapped in
|
|
140
|
+
// "#css(...)"/"#domrange(...)", and a bare "#id" is only trusted as a
|
|
141
|
+
// self-reference when it matches this same node's own id (the shape
|
|
142
|
+
// Converter.applyTextref produces), not an id belonging elsewhere. A
|
|
143
|
+
// ":~:text=..." suffix is independent of all that — it can accompany any of
|
|
144
|
+
// the above, or stand alone — so it's decoded separately from the rest of
|
|
145
|
+
// the string and merged into the result.
|
|
146
|
+
export function decodeTextref(node: { id?: string; textref?: string } | undefined): DecodedTextref | undefined {
|
|
147
|
+
const textref = node?.textref;
|
|
148
|
+
if (!textref) return undefined;
|
|
149
|
+
|
|
150
|
+
const markIndex = textref.indexOf(":~:");
|
|
151
|
+
const base = markIndex === -1 ? textref : textref.slice(0, markIndex);
|
|
152
|
+
|
|
153
|
+
let cssSelector: string | undefined;
|
|
154
|
+
let domRange: DomRangeJSON | undefined;
|
|
155
|
+
const baseDomRange = decodeDomRangeFragment(base);
|
|
156
|
+
if (baseDomRange) {
|
|
157
|
+
domRange = baseDomRange;
|
|
158
|
+
cssSelector = baseDomRange.container ?? baseDomRange.start.cssSelector;
|
|
159
|
+
} else {
|
|
160
|
+
const decoded = decodeCssSelectorFragment(base);
|
|
161
|
+
if (decoded !== undefined) {
|
|
162
|
+
cssSelector = decoded;
|
|
163
|
+
} else if (node?.id && decodeIdFragment(base) === node.id) {
|
|
164
|
+
cssSelector = `#${CSS.escape(node.id)}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// A textStart/textEnd range can't be collapsed back into one exact
|
|
169
|
+
// "highlight" string without the full text in between, so it's carried
|
|
170
|
+
// as-is via locations.fragments (which the WICG grammar natively
|
|
171
|
+
// supports) instead. Only the exact-match case (no textEnd) becomes a
|
|
172
|
+
// text.highlight/before/after quote.
|
|
173
|
+
const directive = decodeTextFragmentDirective(textref);
|
|
174
|
+
|
|
175
|
+
if (cssSelector === undefined && domRange === undefined && directive === undefined) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const result: DecodedTextref = {};
|
|
180
|
+
if (cssSelector !== undefined) result.cssSelector = cssSelector;
|
|
181
|
+
if (domRange !== undefined) result.domRange = domRange;
|
|
182
|
+
if (directive?.textEnd !== undefined) {
|
|
183
|
+
result.fragment = encodeTextFragmentDirective(directive);
|
|
184
|
+
} else if (directive) {
|
|
185
|
+
result.text = { highlight: directive.textStart };
|
|
186
|
+
if (directive.prefix !== undefined) result.text.before = directive.prefix;
|
|
187
|
+
if (directive.suffix !== undefined) result.text.after = directive.suffix;
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Normalized (whitespace-coalesced and trimmed) text content of a node's subtree. */
|
|
2
|
+
export declare function normalizedNodeText(el: Node): string;
|
|
3
|
+
/** Same as `normalizedNodeText`, excluding explicitly-role-bearing descendants. */
|
|
4
|
+
export declare function normalizedNodeTextExcludingExplicitRoles(el: Node): string;
|
|
5
|
+
/**
|
|
6
|
+
* Computes the text that becomes a node's `GuidedNavigationObject.description`, and
|
|
7
|
+
* whether the node is visible in the first place. Follows the AccName
|
|
8
|
+
* precedence order (https://www.w3.org/TR/accname/#terminology, 2.A-2.D)
|
|
9
|
+
* for its accessible-name sources, with a non-AccName `aria-describedby`
|
|
10
|
+
* fallback spliced in between 2.C and 2.D — see that branch below.
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractNodeAria(el: Element): [string | null, boolean];
|
|
13
|
+
/**
|
|
14
|
+
* Maps an HTML element to the SSML tag its text should be wrapped in.
|
|
15
|
+
* https://www.w3.org/TR/speech-synthesis11/#S3.2.2
|
|
16
|
+
*/
|
|
17
|
+
export declare function convertElementToSSMLTag(tagName: string): [string, Record<string, string>?];
|
|
18
|
+
/** Elements whose entire subtree carries no user-facing content. */
|
|
19
|
+
export declare const skippedElements: Set<string>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { GuidedNavigationObject } from "@readium/shared";
|
|
2
|
+
import type { GndRole } from "./types.ts";
|
|
3
|
+
import { type ObjBuilder } from "./object.ts";
|
|
4
|
+
import { type GndMediaType } from "./dom.ts";
|
|
5
|
+
import { type GndGenerationOptions } from "./options.ts";
|
|
6
|
+
import { IdAllocator } from "./idAllocator.ts";
|
|
7
|
+
/** Walks a DOM subtree, building the Guided Navigation object tree. */
|
|
8
|
+
export declare class Converter {
|
|
9
|
+
xmlParsed: boolean;
|
|
10
|
+
ids: Map<string, Element>;
|
|
11
|
+
suppressed: Set<Element>;
|
|
12
|
+
idAlloc: IdAllocator;
|
|
13
|
+
noterefDepth: number;
|
|
14
|
+
allowNode: Element | null;
|
|
15
|
+
selectorPredicate: ((roles: GndRole[]) => boolean) | null;
|
|
16
|
+
domRangeEnabled: boolean;
|
|
17
|
+
textFragmentEnabled: boolean;
|
|
18
|
+
leafTextEnabled: boolean;
|
|
19
|
+
docRoot: Document | null;
|
|
20
|
+
selectorRoot: Element | null;
|
|
21
|
+
selectorRootAnchor: string | null;
|
|
22
|
+
private root;
|
|
23
|
+
private current;
|
|
24
|
+
private foldedCaptions;
|
|
25
|
+
private segments;
|
|
26
|
+
private textAcc;
|
|
27
|
+
private currentCtx;
|
|
28
|
+
private flowEndsWithSpace;
|
|
29
|
+
private pendingChildren;
|
|
30
|
+
private flowFirstNode;
|
|
31
|
+
private flowFirstOffset;
|
|
32
|
+
private flowLastNode;
|
|
33
|
+
private flowLastOffset;
|
|
34
|
+
private lastFlowRange;
|
|
35
|
+
private lastFlowText;
|
|
36
|
+
constructor(xmlParsed: boolean);
|
|
37
|
+
spawnChild(allowNode: Element, depthDelta?: number): Converter;
|
|
38
|
+
prescan(root: Element): void;
|
|
39
|
+
convert(root: Element): void;
|
|
40
|
+
convertChildren(root: Element): void;
|
|
41
|
+
resultBuilders(): ObjBuilder[];
|
|
42
|
+
result(): GuidedNavigationObject[];
|
|
43
|
+
private descend;
|
|
44
|
+
private appendChild;
|
|
45
|
+
private walk;
|
|
46
|
+
private head;
|
|
47
|
+
private implicitCaptionOf;
|
|
48
|
+
private tail;
|
|
49
|
+
private applyTextref;
|
|
50
|
+
private text;
|
|
51
|
+
private textContext;
|
|
52
|
+
private updateFlowSpace;
|
|
53
|
+
private closeSegment;
|
|
54
|
+
private resetFlow;
|
|
55
|
+
placeholder(el: Element, tag: string, object: ObjBuilder, candidateID?: string): void;
|
|
56
|
+
private flushText;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Converts an HTML or XHTML fragment or document into Guided Navigation
|
|
60
|
+
* objects.
|
|
61
|
+
*
|
|
62
|
+
* Given a string, `input` is parsed into a detached document that's never
|
|
63
|
+
* seen again — `options.textrefs.domRange` has nothing to resolve back
|
|
64
|
+
* against there, so it's ignored. Reflects exactly the input it's given: a
|
|
65
|
+
* real, author-written <body> becomes its own role: ["body"] node like any
|
|
66
|
+
* other element; a <body> synthesized only by text/html parsing around a
|
|
67
|
+
* bodyless fragment is not content and is skipped through; a bodyless XHTML
|
|
68
|
+
* fragment's root element is itself the content. Malformed XHTML throws,
|
|
69
|
+
* unless `options.htmlFallback` re-parses it as text/html.
|
|
70
|
+
*
|
|
71
|
+
* Given a live, already-rendered element instead, it's converted in place —
|
|
72
|
+
* no parsing, no detached copy — so `domRange` can pinpoint exact text
|
|
73
|
+
* nodes a DOM-highlighting consumer can resolve straight back against that
|
|
74
|
+
* same document.
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseMarkup(input: string | Element, mediaType?: GndMediaType, options?: GndGenerationOptions): GuidedNavigationObject[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function nodeLanguage(el: Element | null): string;
|
|
2
|
+
export declare function hasElementChild(el: Element): boolean;
|
|
3
|
+
export declare function isAncestorOf(anc: Element, n: Element): boolean;
|
|
4
|
+
export declare function isInlineTag(tagName: string): boolean;
|
|
5
|
+
export type GndMediaType = "text/html" | "application/xhtml+xml";
|
|
6
|
+
export declare function sniffMediaType(input: string): GndMediaType;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DomRangeJSON } from "./textrefFragment.ts";
|
|
2
|
+
export interface KnownSelector {
|
|
3
|
+
el: Element;
|
|
4
|
+
selector: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function generateDomRange(range: {
|
|
7
|
+
first: [Text, number];
|
|
8
|
+
last: [Text, number];
|
|
9
|
+
}, selectorRoot: Element | null, rootAnchor: string | null, known?: KnownSelector): DomRangeJSON | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { GndRole } from "./types.ts";
|
|
2
|
+
import { Converter } from "./converter.ts";
|
|
3
|
+
export declare function pagebreak(converter: Converter, el: Element, aria: string | null, roles: GndRole[]): boolean;
|
|
4
|
+
export declare function noteref(converter: Converter, el: Element, roles: GndRole[]): void;
|
|
5
|
+
export declare function link(converter: Converter, el: Element, roles: GndRole[], aria: string | null): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
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 { encodeCssSelectorFragment, decodeCssSelectorFragment, encodeDomRangeFragment, decodeDomRangeFragment, decodeTextref, combineDomRangeTextrefs, } from "./textrefFragment.ts";
|
|
7
|
+
export type { DomRangeJSON, DecodedTextref } from "./textrefFragment.ts";
|
|
8
|
+
export { isAriaSubstituted, substitutedOwnSelector } from "./object.ts";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GuidedNavigationDocument } from "@readium/shared";
|
|
2
|
+
import type { GndMediaType } from "./dom.ts";
|
|
3
|
+
import type { GndGenerationOptions } from "./options.ts";
|
|
4
|
+
export type { GndMediaType };
|
|
5
|
+
/**
|
|
6
|
+
* Builds a Guided Navigation document from an HTML or XHTML fragment or
|
|
7
|
+
* document, following https://github.com/readium/guided-navigation.
|
|
8
|
+
* Returns undefined when the input has no navigable content, as `guided` can't be empty.
|
|
9
|
+
*/
|
|
10
|
+
export declare function makeGnd(input: string | Element, mediaType?: GndMediaType, options?: GndGenerationOptions): GuidedNavigationDocument | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { GuidedNavigationObject } from "@readium/shared";
|
|
2
|
+
import type { GndRole } from "./types.ts";
|
|
3
|
+
import { type TextBuilder } from "./text.ts";
|
|
4
|
+
export interface ObjBuilder {
|
|
5
|
+
id?: string;
|
|
6
|
+
audioref?: string;
|
|
7
|
+
imgref?: string;
|
|
8
|
+
textref?: string;
|
|
9
|
+
videoref?: string;
|
|
10
|
+
text?: TextBuilder;
|
|
11
|
+
role?: GndRole[];
|
|
12
|
+
children?: ObjBuilder[];
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const ariaSubstitutedBuilders: WeakSet<ObjBuilder>;
|
|
16
|
+
export declare const substitutedOwnSelectorBuilders: WeakMap<ObjBuilder, string>;
|
|
17
|
+
export declare function isAriaSubstituted(node: GuidedNavigationObject): boolean;
|
|
18
|
+
export declare function substitutedOwnSelector(node: GuidedNavigationObject): string | undefined;
|
|
19
|
+
export declare function isEmptyObj(o: ObjBuilder): boolean;
|
|
20
|
+
/** A node being built up during the tree walk, before its final shape is known. */
|
|
21
|
+
export declare class NavObject {
|
|
22
|
+
el?: Element;
|
|
23
|
+
object: ObjBuilder;
|
|
24
|
+
children: NavObject[];
|
|
25
|
+
noText: boolean;
|
|
26
|
+
hasChildBlock: boolean;
|
|
27
|
+
finalize(selfTextref?: (el: Element) => string | undefined): ObjBuilder;
|
|
28
|
+
}
|
|
29
|
+
export declare function finalizeToGuidedNavigationObject(o: ObjBuilder): GuidedNavigationObject;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GndRole } from "./types.ts";
|
|
2
|
+
export declare const leafTextRoleKeyword = "leaf-text";
|
|
3
|
+
export interface TextrefOptions {
|
|
4
|
+
roles?: boolean | GndRole[];
|
|
5
|
+
domRange?: boolean;
|
|
6
|
+
textFragment?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface GndGenerationOptions {
|
|
9
|
+
textrefs?: boolean | GndRole[] | TextrefOptions;
|
|
10
|
+
htmlFallback?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface NormalizedTextrefOptions {
|
|
13
|
+
predicate: ((roles: GndRole[]) => boolean) | null;
|
|
14
|
+
leafText: boolean;
|
|
15
|
+
domRange: boolean;
|
|
16
|
+
textFragment: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function normalizeTextrefOptions(opt: GndGenerationOptions["textrefs"]): NormalizedTextrefOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prescan(root: Element, ids: Map<string, Element>, suppressed: Set<Element>): void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function rootAnchorSelector(selectorRoot: Element | null): string | null;
|
|
2
|
+
export declare function selectorForElement(el: Element, selectorRoot: Element | null, rootAnchor: string | null): string | undefined;
|
|
3
|
+
export declare function textrefForSelector(selector: string | undefined, el: Element): string | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GuidedNavigationText } from "@readium/shared";
|
|
2
|
+
export interface TextBuilder {
|
|
3
|
+
plain: string;
|
|
4
|
+
ssml: string;
|
|
5
|
+
language: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function textIsEmpty(t: TextBuilder): boolean;
|
|
8
|
+
export declare function finalizeText(t?: TextBuilder): GuidedNavigationText | undefined;
|
|
9
|
+
export interface SSMLContext {
|
|
10
|
+
lang: string;
|
|
11
|
+
tag: string;
|
|
12
|
+
attrs?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare function ctxEqual(a: SSMLContext, b: SSMLContext): boolean;
|
|
15
|
+
export declare function isNoBreakSpace(ch: string): boolean;
|
|
16
|
+
export declare function normalizeWhitespace(text: string, stripLeading: boolean): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare function encodeCssSelectorFragment(selector: string): string;
|
|
2
|
+
export declare function decodeCssSelectorFragment(textref: string | undefined): string | undefined;
|
|
3
|
+
export interface DomRangeJSON {
|
|
4
|
+
start: {
|
|
5
|
+
cssSelector: string;
|
|
6
|
+
textNodeIndex: number;
|
|
7
|
+
charOffset?: number;
|
|
8
|
+
};
|
|
9
|
+
end?: {
|
|
10
|
+
cssSelector: string;
|
|
11
|
+
textNodeIndex: number;
|
|
12
|
+
charOffset?: number;
|
|
13
|
+
};
|
|
14
|
+
container?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function encodeDomRangeFragment(domRange: DomRangeJSON): string;
|
|
17
|
+
export declare function decodeDomRangeFragment(textref: string | undefined): DomRangeJSON | undefined;
|
|
18
|
+
export interface TextFragmentDirective {
|
|
19
|
+
textStart: string;
|
|
20
|
+
textEnd?: string;
|
|
21
|
+
prefix?: string;
|
|
22
|
+
suffix?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function encodeTextFragmentDirective(fragment: TextFragmentDirective): string;
|
|
25
|
+
export declare function decodeTextFragmentDirective(textref: string | undefined): TextFragmentDirective | undefined;
|
|
26
|
+
export interface DecodedTextref {
|
|
27
|
+
cssSelector?: string;
|
|
28
|
+
domRange?: DomRangeJSON;
|
|
29
|
+
text?: {
|
|
30
|
+
highlight?: string;
|
|
31
|
+
before?: string;
|
|
32
|
+
after?: string;
|
|
33
|
+
};
|
|
34
|
+
fragment?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function combineDomRangeTextrefs(first: DecodedTextref, last: DecodedTextref): DecodedTextref | undefined;
|
|
37
|
+
export declare function decodeTextref(node: {
|
|
38
|
+
id?: string;
|
|
39
|
+
textref?: string;
|
|
40
|
+
} | undefined): DecodedTextref | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GndRole = string;
|