@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.
Files changed (590) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +157 -0
  3. package/dist/a11y.js +1 -0
  4. package/dist/converter.js +1 -0
  5. package/dist/dom.js +1 -0
  6. package/dist/domRangeGenerator.js +1 -0
  7. package/dist/elementHandlers.js +1 -0
  8. package/dist/idAllocator.js +1 -0
  9. package/dist/index.js +1 -0
  10. package/dist/makeGnd.js +1 -0
  11. package/dist/object.js +1 -0
  12. package/dist/options.js +1 -0
  13. package/dist/prescan.js +1 -0
  14. package/dist/roles.js +1 -0
  15. package/dist/selectorGenerator.js +1 -0
  16. package/dist/text.js +1 -0
  17. package/dist/textFragmentGenerator.js +1 -0
  18. package/dist/textrefFragment.js +1 -0
  19. package/fixtures/README.md +185 -0
  20. package/fixtures/ROLES_COVERAGE.md +80 -0
  21. package/fixtures/abstract-epub-type/gnd.json +15 -0
  22. package/fixtures/abstract-epub-type/input.xhtml +11 -0
  23. package/fixtures/abstract-epub-type/meta.json +10 -0
  24. package/fixtures/abstract-role-aria/gnd.json +8 -0
  25. package/fixtures/abstract-role-aria/input.html +1 -0
  26. package/fixtures/abstract-role-aria/meta.json +10 -0
  27. package/fixtures/acknowledgments-epub-type/gnd.json +15 -0
  28. package/fixtures/acknowledgments-epub-type/input.xhtml +11 -0
  29. package/fixtures/acknowledgments-epub-type/meta.json +10 -0
  30. package/fixtures/acknowledgments-role-aria/gnd.json +8 -0
  31. package/fixtures/acknowledgments-role-aria/input.html +1 -0
  32. package/fixtures/acknowledgments-role-aria/meta.json +10 -0
  33. package/fixtures/afterword-epub-type/gnd.json +15 -0
  34. package/fixtures/afterword-epub-type/input.xhtml +11 -0
  35. package/fixtures/afterword-epub-type/meta.json +10 -0
  36. package/fixtures/afterword-role-aria/gnd.json +8 -0
  37. package/fixtures/afterword-role-aria/input.html +1 -0
  38. package/fixtures/afterword-role-aria/meta.json +10 -0
  39. package/fixtures/appendix-epub-type/gnd.json +16 -0
  40. package/fixtures/appendix-epub-type/input.xhtml +11 -0
  41. package/fixtures/appendix-epub-type/meta.json +10 -0
  42. package/fixtures/appendix-role-aria/gnd.json +8 -0
  43. package/fixtures/appendix-role-aria/input.html +1 -0
  44. package/fixtures/appendix-role-aria/meta.json +10 -0
  45. package/fixtures/article-html-native/gnd.json +8 -0
  46. package/fixtures/article-html-native/input.html +1 -0
  47. package/fixtures/article-html-native/meta.json +10 -0
  48. package/fixtures/article-role-aria/gnd.json +8 -0
  49. package/fixtures/article-role-aria/input.html +1 -0
  50. package/fixtures/article-role-aria/meta.json +10 -0
  51. package/fixtures/aside-epub-type/gnd.json +15 -0
  52. package/fixtures/aside-epub-type/input.xhtml +11 -0
  53. package/fixtures/aside-epub-type/meta.json +10 -0
  54. package/fixtures/aside-html-native/gnd.json +8 -0
  55. package/fixtures/aside-html-native/input.html +1 -0
  56. package/fixtures/aside-html-native/meta.json +10 -0
  57. package/fixtures/audio-html-native/gnd.json +11 -0
  58. package/fixtures/audio-html-native/input.html +1 -0
  59. package/fixtures/audio-html-native/meta.json +10 -0
  60. package/fixtures/audio-no-description/gnd.json +6 -0
  61. package/fixtures/audio-no-description/input.html +1 -0
  62. package/fixtures/audio-no-description/meta.json +10 -0
  63. package/fixtures/backlink-epub-type/gnd.json +16 -0
  64. package/fixtures/backlink-epub-type/input.xhtml +11 -0
  65. package/fixtures/backlink-epub-type/meta.json +10 -0
  66. package/fixtures/backlink-role-aria/gnd.json +9 -0
  67. package/fixtures/backlink-role-aria/input.html +1 -0
  68. package/fixtures/backlink-role-aria/meta.json +10 -0
  69. package/fixtures/bibliography-epub-type/gnd.json +38 -0
  70. package/fixtures/bibliography-epub-type/input.xhtml +16 -0
  71. package/fixtures/bibliography-epub-type/meta.json +12 -0
  72. package/fixtures/bibliography-role-aria/gnd.json +30 -0
  73. package/fixtures/bibliography-role-aria/input.html +6 -0
  74. package/fixtures/bibliography-role-aria/meta.json +12 -0
  75. package/fixtures/biblioref-epub-type/gnd.json +16 -0
  76. package/fixtures/biblioref-epub-type/input.xhtml +11 -0
  77. package/fixtures/biblioref-epub-type/meta.json +10 -0
  78. package/fixtures/biblioref-role-aria/gnd.json +9 -0
  79. package/fixtures/biblioref-role-aria/input.html +1 -0
  80. package/fixtures/biblioref-role-aria/meta.json +10 -0
  81. package/fixtures/blockquote-html-native/gnd.json +8 -0
  82. package/fixtures/blockquote-html-native/input.html +1 -0
  83. package/fixtures/blockquote-html-native/meta.json +10 -0
  84. package/fixtures/blockquote-role-aria/gnd.json +8 -0
  85. package/fixtures/blockquote-role-aria/input.html +1 -0
  86. package/fixtures/blockquote-role-aria/meta.json +10 -0
  87. package/fixtures/body-html-native/gnd.json +8 -0
  88. package/fixtures/body-html-native/input.html +1 -0
  89. package/fixtures/body-html-native/meta.json +10 -0
  90. package/fixtures/chapter-epub-type/gnd.json +23 -0
  91. package/fixtures/chapter-epub-type/input.xhtml +13 -0
  92. package/fixtures/chapter-epub-type/meta.json +11 -0
  93. package/fixtures/chapter-role-aria/gnd.json +16 -0
  94. package/fixtures/chapter-role-aria/input.html +3 -0
  95. package/fixtures/chapter-role-aria/meta.json +11 -0
  96. package/fixtures/colophon-epub-type/gnd.json +15 -0
  97. package/fixtures/colophon-epub-type/input.xhtml +11 -0
  98. package/fixtures/colophon-epub-type/meta.json +10 -0
  99. package/fixtures/colophon-role-aria/gnd.json +8 -0
  100. package/fixtures/colophon-role-aria/input.html +1 -0
  101. package/fixtures/colophon-role-aria/meta.json +10 -0
  102. package/fixtures/complementary-role-aria/gnd.json +8 -0
  103. package/fixtures/complementary-role-aria/input.html +1 -0
  104. package/fixtures/complementary-role-aria/meta.json +10 -0
  105. package/fixtures/conclusion-epub-type/gnd.json +15 -0
  106. package/fixtures/conclusion-epub-type/input.xhtml +11 -0
  107. package/fixtures/conclusion-epub-type/meta.json +10 -0
  108. package/fixtures/conclusion-role-aria/gnd.json +8 -0
  109. package/fixtures/conclusion-role-aria/input.html +1 -0
  110. package/fixtures/conclusion-role-aria/meta.json +10 -0
  111. package/fixtures/cover-epub-type/gnd.json +26 -0
  112. package/fixtures/cover-epub-type/input.xhtml +13 -0
  113. package/fixtures/cover-epub-type/meta.json +10 -0
  114. package/fixtures/cover-role-aria/gnd.json +12 -0
  115. package/fixtures/cover-role-aria/input.html +1 -0
  116. package/fixtures/cover-role-aria/meta.json +10 -0
  117. package/fixtures/credit-epub-type/gnd.json +22 -0
  118. package/fixtures/credit-epub-type/input.xhtml +11 -0
  119. package/fixtures/credit-epub-type/meta.json +10 -0
  120. package/fixtures/credit-role-aria/gnd.json +8 -0
  121. package/fixtures/credit-role-aria/input.html +1 -0
  122. package/fixtures/credit-role-aria/meta.json +10 -0
  123. package/fixtures/credits-epub-type/gnd.json +51 -0
  124. package/fixtures/credits-epub-type/input.xhtml +16 -0
  125. package/fixtures/credits-epub-type/meta.json +13 -0
  126. package/fixtures/credits-role-aria/gnd.json +32 -0
  127. package/fixtures/credits-role-aria/input.html +6 -0
  128. package/fixtures/credits-role-aria/meta.json +13 -0
  129. package/fixtures/dedication-epub-type/gnd.json +15 -0
  130. package/fixtures/dedication-epub-type/input.xhtml +11 -0
  131. package/fixtures/dedication-epub-type/meta.json +10 -0
  132. package/fixtures/dedication-role-aria/gnd.json +8 -0
  133. package/fixtures/dedication-role-aria/input.html +1 -0
  134. package/fixtures/dedication-role-aria/meta.json +10 -0
  135. package/fixtures/definition-epub-type/gnd.json +22 -0
  136. package/fixtures/definition-epub-type/input.xhtml +13 -0
  137. package/fixtures/definition-epub-type/meta.json +11 -0
  138. package/fixtures/definition-html-native/gnd.json +8 -0
  139. package/fixtures/definition-html-native/input.html +3 -0
  140. package/fixtures/definition-html-native/meta.json +10 -0
  141. package/fixtures/definition-role-aria/gnd.json +8 -0
  142. package/fixtures/definition-role-aria/input.html +1 -0
  143. package/fixtures/definition-role-aria/meta.json +10 -0
  144. package/fixtures/details-html-native/gnd.json +8 -0
  145. package/fixtures/details-html-native/input.html +1 -0
  146. package/fixtures/details-html-native/meta.json +10 -0
  147. package/fixtures/details-summary-html-native/gnd.json +20 -0
  148. package/fixtures/details-summary-html-native/input.html +4 -0
  149. package/fixtures/details-summary-html-native/meta.json +11 -0
  150. package/fixtures/endnotes-epub-type/gnd.json +56 -0
  151. package/fixtures/endnotes-epub-type/input.xhtml +16 -0
  152. package/fixtures/endnotes-epub-type/meta.json +13 -0
  153. package/fixtures/endnotes-role-aria/gnd.json +34 -0
  154. package/fixtures/endnotes-role-aria/input.html +6 -0
  155. package/fixtures/endnotes-role-aria/meta.json +13 -0
  156. package/fixtures/epigraph-epub-type/gnd.json +15 -0
  157. package/fixtures/epigraph-epub-type/input.xhtml +11 -0
  158. package/fixtures/epigraph-epub-type/meta.json +10 -0
  159. package/fixtures/epigraph-role-aria/gnd.json +8 -0
  160. package/fixtures/epigraph-role-aria/input.html +1 -0
  161. package/fixtures/epigraph-role-aria/meta.json +10 -0
  162. package/fixtures/epilogue-epub-type/gnd.json +15 -0
  163. package/fixtures/epilogue-epub-type/input.xhtml +11 -0
  164. package/fixtures/epilogue-epub-type/meta.json +10 -0
  165. package/fixtures/epilogue-role-aria/gnd.json +8 -0
  166. package/fixtures/epilogue-role-aria/input.html +1 -0
  167. package/fixtures/epilogue-role-aria/meta.json +10 -0
  168. package/fixtures/errata-epub-type/gnd.json +15 -0
  169. package/fixtures/errata-epub-type/input.xhtml +11 -0
  170. package/fixtures/errata-epub-type/meta.json +10 -0
  171. package/fixtures/errata-role-aria/gnd.json +8 -0
  172. package/fixtures/errata-role-aria/input.html +1 -0
  173. package/fixtures/errata-role-aria/meta.json +10 -0
  174. package/fixtures/example-epub-type/gnd.json +30 -0
  175. package/fixtures/example-epub-type/input.xhtml +15 -0
  176. package/fixtures/example-epub-type/meta.json +10 -0
  177. package/fixtures/example-role-aria/gnd.json +8 -0
  178. package/fixtures/example-role-aria/input.html +1 -0
  179. package/fixtures/example-role-aria/meta.json +10 -0
  180. package/fixtures/figure-basic-html-native/gnd.json +18 -0
  181. package/fixtures/figure-basic-html-native/input.html +3 -0
  182. package/fixtures/figure-basic-html-native/meta.json +10 -0
  183. package/fixtures/figure-basic-role-aria/gnd.json +18 -0
  184. package/fixtures/figure-basic-role-aria/input.html +3 -0
  185. package/fixtures/figure-basic-role-aria/meta.json +10 -0
  186. package/fixtures/figure-caption-element-html-native/gnd.json +11 -0
  187. package/fixtures/figure-caption-element-html-native/input.html +11 -0
  188. package/fixtures/figure-caption-element-html-native/meta.json +11 -0
  189. package/fixtures/figure-caption-element-role-aria/gnd.json +11 -0
  190. package/fixtures/figure-caption-element-role-aria/input.html +11 -0
  191. package/fixtures/figure-caption-element-role-aria/meta.json +11 -0
  192. package/fixtures/figure-caption-html-native/gnd.json +11 -0
  193. package/fixtures/figure-caption-html-native/input.html +11 -0
  194. package/fixtures/figure-caption-html-native/meta.json +11 -0
  195. package/fixtures/figure-caption-role-aria/gnd.json +11 -0
  196. package/fixtures/figure-caption-role-aria/input.html +11 -0
  197. package/fixtures/figure-caption-role-aria/meta.json +11 -0
  198. package/fixtures/figure-credit-nested-in-aria-labelledby-caption/gnd.json +39 -0
  199. package/fixtures/figure-credit-nested-in-aria-labelledby-caption/input.html +4 -0
  200. package/fixtures/figure-credit-nested-in-aria-labelledby-caption/meta.json +13 -0
  201. package/fixtures/figure-credit-nested-in-caption/gnd.json +38 -0
  202. package/fixtures/figure-credit-nested-in-caption/input.html +4 -0
  203. package/fixtures/figure-credit-nested-in-caption/meta.json +12 -0
  204. package/fixtures/figure-credit-role-aria/gnd.json +32 -0
  205. package/fixtures/figure-credit-role-aria/input.html +5 -0
  206. package/fixtures/figure-credit-role-aria/meta.json +12 -0
  207. package/fixtures/figure-describedby/gnd.json +23 -0
  208. package/fixtures/figure-describedby/input.html +4 -0
  209. package/fixtures/figure-describedby/meta.json +11 -0
  210. package/fixtures/figure-epub-type/gnd.json +25 -0
  211. package/fixtures/figure-epub-type/input.xhtml +13 -0
  212. package/fixtures/figure-epub-type/meta.json +11 -0
  213. package/fixtures/figure-no-description/gnd.json +13 -0
  214. package/fixtures/figure-no-description/input.html +3 -0
  215. package/fixtures/figure-no-description/meta.json +11 -0
  216. package/fixtures/footnote-epub-type/gnd.json +39 -0
  217. package/fixtures/footnote-epub-type/input.xhtml +12 -0
  218. package/fixtures/footnote-epub-type/meta.json +11 -0
  219. package/fixtures/footnote-role-aria/gnd.json +50 -0
  220. package/fixtures/footnote-role-aria/input.html +5 -0
  221. package/fixtures/footnote-role-aria/meta.json +12 -0
  222. package/fixtures/foreword-epub-type/gnd.json +15 -0
  223. package/fixtures/foreword-epub-type/input.xhtml +11 -0
  224. package/fixtures/foreword-epub-type/meta.json +10 -0
  225. package/fixtures/foreword-role-aria/gnd.json +8 -0
  226. package/fixtures/foreword-role-aria/input.html +1 -0
  227. package/fixtures/foreword-role-aria/meta.json +10 -0
  228. package/fixtures/glossary-epub-type/gnd.json +46 -0
  229. package/fixtures/glossary-epub-type/input.xhtml +16 -0
  230. package/fixtures/glossary-epub-type/meta.json +12 -0
  231. package/fixtures/glossary-role-aria/gnd.json +49 -0
  232. package/fixtures/glossary-role-aria/input.html +6 -0
  233. package/fixtures/glossary-role-aria/meta.json +12 -0
  234. package/fixtures/glossref-epub-type/gnd.json +16 -0
  235. package/fixtures/glossref-epub-type/input.xhtml +11 -0
  236. package/fixtures/glossref-epub-type/meta.json +10 -0
  237. package/fixtures/glossref-role-aria/gnd.json +9 -0
  238. package/fixtures/glossref-role-aria/input.html +1 -0
  239. package/fixtures/glossref-role-aria/meta.json +10 -0
  240. package/fixtures/glossref-role-aria-mid-sentence/gnd.json +32 -0
  241. package/fixtures/glossref-role-aria-mid-sentence/input.html +4 -0
  242. package/fixtures/glossref-role-aria-mid-sentence/meta.json +11 -0
  243. package/fixtures/header-html-native/gnd.json +8 -0
  244. package/fixtures/header-html-native/input.html +1 -0
  245. package/fixtures/header-html-native/meta.json +10 -0
  246. package/fixtures/heading-html-native/gnd.json +52 -0
  247. package/fixtures/heading-html-native/input.html +6 -0
  248. package/fixtures/heading-html-native/meta.json +15 -0
  249. package/fixtures/heading-role-aria/gnd.json +52 -0
  250. package/fixtures/heading-role-aria/input.html +6 -0
  251. package/fixtures/heading-role-aria/meta.json +15 -0
  252. package/fixtures/heading-role-presentation/gnd.json +28 -0
  253. package/fixtures/heading-role-presentation/input.html +3 -0
  254. package/fixtures/heading-role-presentation/meta.json +10 -0
  255. package/fixtures/hidden-aria-hidden-html-native/gnd.json +20 -0
  256. package/fixtures/hidden-aria-hidden-html-native/input.html +3 -0
  257. package/fixtures/hidden-aria-hidden-html-native/meta.json +10 -0
  258. package/fixtures/hidden-attribute-html-native/gnd.json +20 -0
  259. package/fixtures/hidden-attribute-html-native/input.html +3 -0
  260. package/fixtures/hidden-attribute-html-native/meta.json +10 -0
  261. package/fixtures/image-alt-html-native/gnd.json +11 -0
  262. package/fixtures/image-alt-html-native/input.html +1 -0
  263. package/fixtures/image-alt-html-native/meta.json +10 -0
  264. package/fixtures/image-decorative-empty-alt/gnd.json +20 -0
  265. package/fixtures/image-decorative-empty-alt/input.html +3 -0
  266. package/fixtures/image-decorative-empty-alt/meta.json +10 -0
  267. package/fixtures/image-decorative-role-presentation/gnd.json +20 -0
  268. package/fixtures/image-decorative-role-presentation/input.html +3 -0
  269. package/fixtures/image-decorative-role-presentation/meta.json +10 -0
  270. package/fixtures/image-decorative-whitespace-alt/gnd.json +20 -0
  271. package/fixtures/image-decorative-whitespace-alt/input.html +3 -0
  272. package/fixtures/image-decorative-whitespace-alt/meta.json +10 -0
  273. package/fixtures/image-no-description/gnd.json +6 -0
  274. package/fixtures/image-no-description/input.html +1 -0
  275. package/fixtures/image-no-description/meta.json +10 -0
  276. package/fixtures/image-role-aria/gnd.json +11 -0
  277. package/fixtures/image-role-aria/input.html +7 -0
  278. package/fixtures/image-role-aria/meta.json +10 -0
  279. package/fixtures/index-epub-type/gnd.json +48 -0
  280. package/fixtures/index-epub-type/input.xhtml +16 -0
  281. package/fixtures/index-epub-type/meta.json +12 -0
  282. package/fixtures/index-role-aria/gnd.json +40 -0
  283. package/fixtures/index-role-aria/input.html +6 -0
  284. package/fixtures/index-role-aria/meta.json +12 -0
  285. package/fixtures/introduction-epub-type/gnd.json +15 -0
  286. package/fixtures/introduction-epub-type/input.xhtml +11 -0
  287. package/fixtures/introduction-epub-type/meta.json +10 -0
  288. package/fixtures/introduction-role-aria/gnd.json +8 -0
  289. package/fixtures/introduction-role-aria/input.html +1 -0
  290. package/fixtures/introduction-role-aria/meta.json +10 -0
  291. package/fixtures/landmarks-epub-type/gnd.json +61 -0
  292. package/fixtures/landmarks-epub-type/input.xhtml +17 -0
  293. package/fixtures/landmarks-epub-type/meta.json +12 -0
  294. package/fixtures/language-block/gnd.json +25 -0
  295. package/fixtures/language-block/input.html +11 -0
  296. package/fixtures/language-block/meta.json +10 -0
  297. package/fixtures/language-document/gnd.json +16 -0
  298. package/fixtures/language-document/input.html +10 -0
  299. package/fixtures/language-document/meta.json +10 -0
  300. package/fixtures/language-inline-lang-attribute/gnd.json +9 -0
  301. package/fixtures/language-inline-lang-attribute/input.html +1 -0
  302. package/fixtures/language-inline-lang-attribute/meta.json +10 -0
  303. package/fixtures/language-inline-nested/gnd.json +9 -0
  304. package/fixtures/language-inline-nested/input.html +1 -0
  305. package/fixtures/language-inline-nested/meta.json +10 -0
  306. package/fixtures/language-inline-repeated/gnd.json +9 -0
  307. package/fixtures/language-inline-repeated/input.html +1 -0
  308. package/fixtures/language-inline-repeated/meta.json +10 -0
  309. package/fixtures/language-inline-two-languages/gnd.json +9 -0
  310. package/fixtures/language-inline-two-languages/input.html +1 -0
  311. package/fixtures/language-inline-two-languages/meta.json +10 -0
  312. package/fixtures/list-aria-posinset-setsize/gnd.json +15 -0
  313. package/fixtures/list-aria-posinset-setsize/input.html +3 -0
  314. package/fixtures/list-aria-posinset-setsize/meta.json +11 -0
  315. package/fixtures/list-epub-type/gnd.json +30 -0
  316. package/fixtures/list-epub-type/input.xhtml +14 -0
  317. package/fixtures/list-epub-type/meta.json +11 -0
  318. package/fixtures/list-html-native/gnd.json +31 -0
  319. package/fixtures/list-html-native/input.html +5 -0
  320. package/fixtures/list-html-native/meta.json +11 -0
  321. package/fixtures/list-item-posinset-override/gnd.json +31 -0
  322. package/fixtures/list-item-posinset-override/input.html +5 -0
  323. package/fixtures/list-item-posinset-override/meta.json +11 -0
  324. package/fixtures/list-item-value-override/gnd.json +31 -0
  325. package/fixtures/list-item-value-override/input.html +5 -0
  326. package/fixtures/list-item-value-override/meta.json +11 -0
  327. package/fixtures/list-ordered-html-native/gnd.json +31 -0
  328. package/fixtures/list-ordered-html-native/input.html +5 -0
  329. package/fixtures/list-ordered-html-native/meta.json +11 -0
  330. package/fixtures/list-ordered-reversed/gnd.json +31 -0
  331. package/fixtures/list-ordered-reversed/input.html +5 -0
  332. package/fixtures/list-ordered-reversed/meta.json +11 -0
  333. package/fixtures/list-ordered-start/gnd.json +31 -0
  334. package/fixtures/list-ordered-start/input.html +5 -0
  335. package/fixtures/list-ordered-start/meta.json +11 -0
  336. package/fixtures/list-role-aria/gnd.json +31 -0
  337. package/fixtures/list-role-aria/input.html +5 -0
  338. package/fixtures/list-role-aria/meta.json +11 -0
  339. package/fixtures/listitem-role-presentation/gnd.json +23 -0
  340. package/fixtures/listitem-role-presentation/input.html +4 -0
  341. package/fixtures/listitem-role-presentation/meta.json +10 -0
  342. package/fixtures/loa-epub-type/gnd.json +48 -0
  343. package/fixtures/loa-epub-type/input.xhtml +16 -0
  344. package/fixtures/loa-epub-type/meta.json +12 -0
  345. package/fixtures/loi-epub-type/gnd.json +48 -0
  346. package/fixtures/loi-epub-type/input.xhtml +16 -0
  347. package/fixtures/loi-epub-type/meta.json +12 -0
  348. package/fixtures/lot-epub-type/gnd.json +48 -0
  349. package/fixtures/lot-epub-type/input.xhtml +16 -0
  350. package/fixtures/lot-epub-type/meta.json +12 -0
  351. package/fixtures/lov-epub-type/gnd.json +48 -0
  352. package/fixtures/lov-epub-type/input.xhtml +16 -0
  353. package/fixtures/lov-epub-type/meta.json +12 -0
  354. package/fixtures/main-html-native/gnd.json +8 -0
  355. package/fixtures/main-html-native/input.html +1 -0
  356. package/fixtures/main-html-native/meta.json +10 -0
  357. package/fixtures/main-role-aria/gnd.json +8 -0
  358. package/fixtures/main-role-aria/input.html +1 -0
  359. package/fixtures/main-role-aria/meta.json +10 -0
  360. package/fixtures/manifest.json +1782 -0
  361. package/fixtures/math-html-native/gnd.json +14 -0
  362. package/fixtures/math-html-native/input.html +7 -0
  363. package/fixtures/math-html-native/meta.json +10 -0
  364. package/fixtures/math-no-description/gnd.json +9 -0
  365. package/fixtures/math-no-description/input.html +7 -0
  366. package/fixtures/math-no-description/meta.json +10 -0
  367. package/fixtures/math-role-aria/gnd.json +14 -0
  368. package/fixtures/math-role-aria/input.html +1 -0
  369. package/fixtures/math-role-aria/meta.json +10 -0
  370. package/fixtures/navigation-html-native/gnd.json +8 -0
  371. package/fixtures/navigation-html-native/input.html +1 -0
  372. package/fixtures/navigation-html-native/meta.json +10 -0
  373. package/fixtures/navigation-role-aria/gnd.json +8 -0
  374. package/fixtures/navigation-role-aria/input.html +1 -0
  375. package/fixtures/navigation-role-aria/meta.json +10 -0
  376. package/fixtures/noteref-role-aria/gnd.json +13 -0
  377. package/fixtures/noteref-role-aria/input.html +1 -0
  378. package/fixtures/noteref-role-aria/meta.json +10 -0
  379. package/fixtures/noteref-target-in-endnotes-epub-type/gnd.json +72 -0
  380. package/fixtures/noteref-target-in-endnotes-epub-type/input.xhtml +17 -0
  381. package/fixtures/noteref-target-in-endnotes-epub-type/meta.json +15 -0
  382. package/fixtures/noteref-target-in-endnotes-role-aria/gnd.json +69 -0
  383. package/fixtures/noteref-target-in-endnotes-role-aria/input.html +7 -0
  384. package/fixtures/noteref-target-in-endnotes-role-aria/meta.json +15 -0
  385. package/fixtures/notice-epub-type/gnd.json +15 -0
  386. package/fixtures/notice-epub-type/input.xhtml +11 -0
  387. package/fixtures/notice-epub-type/meta.json +10 -0
  388. package/fixtures/notice-role-aria/gnd.json +8 -0
  389. package/fixtures/notice-role-aria/input.html +1 -0
  390. package/fixtures/notice-role-aria/meta.json +10 -0
  391. package/fixtures/pagebreak-epub-type/gnd.json +36 -0
  392. package/fixtures/pagebreak-epub-type/input.xhtml +12 -0
  393. package/fixtures/pagebreak-epub-type/meta.json +10 -0
  394. package/fixtures/pagebreak-role-aria/gnd.json +33 -0
  395. package/fixtures/pagebreak-role-aria/input.html +2 -0
  396. package/fixtures/pagebreak-role-aria/meta.json +10 -0
  397. package/fixtures/pagelist-epub-type/gnd.json +61 -0
  398. package/fixtures/pagelist-epub-type/input.xhtml +17 -0
  399. package/fixtures/pagelist-epub-type/meta.json +12 -0
  400. package/fixtures/pagelist-role-aria/gnd.json +54 -0
  401. package/fixtures/pagelist-role-aria/input.html +7 -0
  402. package/fixtures/pagelist-role-aria/meta.json +12 -0
  403. package/fixtures/paragraph-basic/gnd.json +8 -0
  404. package/fixtures/paragraph-basic/input.html +1 -0
  405. package/fixtures/paragraph-basic/meta.json +10 -0
  406. package/fixtures/part-epub-type/gnd.json +23 -0
  407. package/fixtures/part-epub-type/input.xhtml +13 -0
  408. package/fixtures/part-epub-type/meta.json +11 -0
  409. package/fixtures/part-role-aria/gnd.json +16 -0
  410. package/fixtures/part-role-aria/input.html +3 -0
  411. package/fixtures/part-role-aria/meta.json +11 -0
  412. package/fixtures/preface-epub-type/gnd.json +15 -0
  413. package/fixtures/preface-epub-type/input.xhtml +11 -0
  414. package/fixtures/preface-epub-type/meta.json +10 -0
  415. package/fixtures/preface-role-aria/gnd.json +8 -0
  416. package/fixtures/preface-role-aria/input.html +1 -0
  417. package/fixtures/preface-role-aria/meta.json +10 -0
  418. package/fixtures/preformatted-html-native/gnd.json +8 -0
  419. package/fixtures/preformatted-html-native/input.html +2 -0
  420. package/fixtures/preformatted-html-native/meta.json +10 -0
  421. package/fixtures/presentation-role-aria/gnd.json +8 -0
  422. package/fixtures/presentation-role-aria/input.html +1 -0
  423. package/fixtures/presentation-role-aria/meta.json +10 -0
  424. package/fixtures/prologue-epub-type/gnd.json +15 -0
  425. package/fixtures/prologue-epub-type/input.xhtml +11 -0
  426. package/fixtures/prologue-epub-type/meta.json +10 -0
  427. package/fixtures/prologue-role-aria/gnd.json +8 -0
  428. package/fixtures/prologue-role-aria/input.html +1 -0
  429. package/fixtures/prologue-role-aria/meta.json +10 -0
  430. package/fixtures/pullquote-epub-type/gnd.json +16 -0
  431. package/fixtures/pullquote-epub-type/input.xhtml +11 -0
  432. package/fixtures/pullquote-epub-type/meta.json +10 -0
  433. package/fixtures/pullquote-role-aria/gnd.json +8 -0
  434. package/fixtures/pullquote-role-aria/input.html +1 -0
  435. package/fixtures/pullquote-role-aria/meta.json +10 -0
  436. package/fixtures/qna-epub-type/gnd.json +16 -0
  437. package/fixtures/qna-epub-type/input.xhtml +11 -0
  438. package/fixtures/qna-epub-type/meta.json +10 -0
  439. package/fixtures/qna-role-aria/gnd.json +8 -0
  440. package/fixtures/qna-role-aria/input.html +1 -0
  441. package/fixtures/qna-role-aria/meta.json +10 -0
  442. package/fixtures/region-role-aria/gnd.json +8 -0
  443. package/fixtures/region-role-aria/input.html +1 -0
  444. package/fixtures/region-role-aria/meta.json +10 -0
  445. package/fixtures/section-html-native/gnd.json +8 -0
  446. package/fixtures/section-html-native/input.html +1 -0
  447. package/fixtures/section-html-native/meta.json +10 -0
  448. package/fixtures/separator-html-native/gnd.json +26 -0
  449. package/fixtures/separator-html-native/input.html +3 -0
  450. package/fixtures/separator-html-native/meta.json +10 -0
  451. package/fixtures/separator-role-aria/gnd.json +26 -0
  452. package/fixtures/separator-role-aria/input.html +3 -0
  453. package/fixtures/separator-role-aria/meta.json +10 -0
  454. package/fixtures/separator-with-glyphs/gnd.json +28 -0
  455. package/fixtures/separator-with-glyphs/input.html +3 -0
  456. package/fixtures/separator-with-glyphs/meta.json +10 -0
  457. package/fixtures/subtitle-epub-type/gnd.json +15 -0
  458. package/fixtures/subtitle-epub-type/input.xhtml +11 -0
  459. package/fixtures/subtitle-epub-type/meta.json +10 -0
  460. package/fixtures/subtitle-role-aria/gnd.json +8 -0
  461. package/fixtures/subtitle-role-aria/input.html +1 -0
  462. package/fixtures/subtitle-role-aria/meta.json +10 -0
  463. package/fixtures/summary-html-native/gnd.json +8 -0
  464. package/fixtures/summary-html-native/input.html +1 -0
  465. package/fixtures/summary-html-native/meta.json +10 -0
  466. package/fixtures/table-caption/gnd.json +81 -0
  467. package/fixtures/table-caption/input.html +5 -0
  468. package/fixtures/table-caption/meta.json +14 -0
  469. package/fixtures/table-caption-element-html-native/gnd.json +42 -0
  470. package/fixtures/table-caption-element-html-native/input.html +5 -0
  471. package/fixtures/table-caption-element-html-native/meta.json +14 -0
  472. package/fixtures/table-caption-role-aria/gnd.json +27 -0
  473. package/fixtures/table-caption-role-aria/input.html +4 -0
  474. package/fixtures/table-caption-role-aria/meta.json +13 -0
  475. package/fixtures/table-colspan-html-native/gnd.json +45 -0
  476. package/fixtures/table-colspan-html-native/input.html +4 -0
  477. package/fixtures/table-colspan-html-native/meta.json +13 -0
  478. package/fixtures/table-colspan-role-aria/gnd.json +45 -0
  479. package/fixtures/table-colspan-role-aria/input.html +4 -0
  480. package/fixtures/table-colspan-role-aria/meta.json +13 -0
  481. package/fixtures/table-epub-type/gnd.json +37 -0
  482. package/fixtures/table-epub-type/input.xhtml +16 -0
  483. package/fixtures/table-epub-type/meta.json +12 -0
  484. package/fixtures/table-html-native/gnd.json +76 -0
  485. package/fixtures/table-html-native/input.html +5 -0
  486. package/fixtures/table-html-native/meta.json +14 -0
  487. package/fixtures/table-in-role-none-wrapper/gnd.json +44 -0
  488. package/fixtures/table-in-role-none-wrapper/input.html +6 -0
  489. package/fixtures/table-in-role-none-wrapper/meta.json +14 -0
  490. package/fixtures/table-nested-html-native/gnd.json +48 -0
  491. package/fixtures/table-nested-html-native/input.html +3 -0
  492. package/fixtures/table-nested-html-native/meta.json +12 -0
  493. package/fixtures/table-nested-in-presentation-table/gnd.json +63 -0
  494. package/fixtures/table-nested-in-presentation-table/input.html +3 -0
  495. package/fixtures/table-nested-in-presentation-table/meta.json +14 -0
  496. package/fixtures/table-nested-role-aria/gnd.json +48 -0
  497. package/fixtures/table-nested-role-aria/input.html +9 -0
  498. package/fixtures/table-nested-role-aria/meta.json +12 -0
  499. package/fixtures/table-no-headers/gnd.json +53 -0
  500. package/fixtures/table-no-headers/input.html +10 -0
  501. package/fixtures/table-no-headers/meta.json +12 -0
  502. package/fixtures/table-role-aria/gnd.json +76 -0
  503. package/fixtures/table-role-aria/input.html +5 -0
  504. package/fixtures/table-role-aria/meta.json +14 -0
  505. package/fixtures/table-role-presentation-explicit-cell/gnd.json +30 -0
  506. package/fixtures/table-role-presentation-explicit-cell/input.html +3 -0
  507. package/fixtures/table-role-presentation-explicit-cell/meta.json +11 -0
  508. package/fixtures/table-role-presentation-html-native/gnd.json +37 -0
  509. package/fixtures/table-role-presentation-html-native/input.html +4 -0
  510. package/fixtures/table-role-presentation-html-native/meta.json +13 -0
  511. package/fixtures/table-role-presentation-role-aria/gnd.json +37 -0
  512. package/fixtures/table-role-presentation-role-aria/input.html +4 -0
  513. package/fixtures/table-role-presentation-role-aria/meta.json +13 -0
  514. package/fixtures/table-rowgroup-role-aria/gnd.json +22 -0
  515. package/fixtures/table-rowgroup-role-aria/input.html +5 -0
  516. package/fixtures/table-rowgroup-role-aria/meta.json +12 -0
  517. package/fixtures/table-rowspan-html-native/gnd.json +45 -0
  518. package/fixtures/table-rowspan-html-native/input.html +4 -0
  519. package/fixtures/table-rowspan-html-native/meta.json +13 -0
  520. package/fixtures/table-rowspan-role-aria/gnd.json +45 -0
  521. package/fixtures/table-rowspan-role-aria/input.html +4 -0
  522. package/fixtures/table-rowspan-role-aria/meta.json +13 -0
  523. package/fixtures/table-sectioning/gnd.json +52 -0
  524. package/fixtures/table-sectioning/input.html +11 -0
  525. package/fixtures/table-sectioning/meta.json +13 -0
  526. package/fixtures/table-th-no-scope/gnd.json +53 -0
  527. package/fixtures/table-th-no-scope/input.html +4 -0
  528. package/fixtures/table-th-no-scope/meta.json +12 -0
  529. package/fixtures/term-epub-type/gnd.json +22 -0
  530. package/fixtures/term-epub-type/input.xhtml +13 -0
  531. package/fixtures/term-epub-type/meta.json +11 -0
  532. package/fixtures/term-html-native/gnd.json +8 -0
  533. package/fixtures/term-html-native/input.html +1 -0
  534. package/fixtures/term-html-native/meta.json +10 -0
  535. package/fixtures/term-role-aria/gnd.json +8 -0
  536. package/fixtures/term-role-aria/input.html +1 -0
  537. package/fixtures/term-role-aria/meta.json +10 -0
  538. package/fixtures/tip-epub-type/gnd.json +16 -0
  539. package/fixtures/tip-epub-type/input.xhtml +11 -0
  540. package/fixtures/tip-epub-type/meta.json +10 -0
  541. package/fixtures/tip-role-aria/gnd.json +8 -0
  542. package/fixtures/tip-role-aria/input.html +1 -0
  543. package/fixtures/tip-role-aria/meta.json +10 -0
  544. package/fixtures/toc-epub-type/gnd.json +61 -0
  545. package/fixtures/toc-epub-type/input.xhtml +17 -0
  546. package/fixtures/toc-epub-type/meta.json +12 -0
  547. package/fixtures/toc-role-aria/gnd.json +54 -0
  548. package/fixtures/toc-role-aria/input.html +7 -0
  549. package/fixtures/toc-role-aria/meta.json +12 -0
  550. package/fixtures/video-html-native/gnd.json +11 -0
  551. package/fixtures/video-html-native/input.html +1 -0
  552. package/fixtures/video-html-native/meta.json +10 -0
  553. package/fixtures/video-no-description/gnd.json +6 -0
  554. package/fixtures/video-no-description/input.html +1 -0
  555. package/fixtures/video-no-description/meta.json +10 -0
  556. package/package.json +65 -0
  557. package/src/a11y.ts +166 -0
  558. package/src/converter.ts +730 -0
  559. package/src/dom.ts +56 -0
  560. package/src/domRangeGenerator.ts +55 -0
  561. package/src/elementHandlers.ts +88 -0
  562. package/src/idAllocator.ts +26 -0
  563. package/src/index.ts +15 -0
  564. package/src/makeGnd.ts +20 -0
  565. package/src/object.ts +175 -0
  566. package/src/options.ts +77 -0
  567. package/src/prescan.ts +40 -0
  568. package/src/roles.ts +350 -0
  569. package/src/selectorGenerator.ts +86 -0
  570. package/src/text.ts +65 -0
  571. package/src/textFragmentGenerator.ts +11 -0
  572. package/src/textrefFragment.ts +190 -0
  573. package/src/types.ts +2 -0
  574. package/types/src/a11y.d.ts +19 -0
  575. package/types/src/converter.d.ts +76 -0
  576. package/types/src/dom.d.ts +6 -0
  577. package/types/src/domRangeGenerator.d.ts +9 -0
  578. package/types/src/elementHandlers.d.ts +5 -0
  579. package/types/src/idAllocator.d.ts +6 -0
  580. package/types/src/index.d.ts +8 -0
  581. package/types/src/makeGnd.d.ts +10 -0
  582. package/types/src/object.d.ts +29 -0
  583. package/types/src/options.d.ts +18 -0
  584. package/types/src/prescan.d.ts +1 -0
  585. package/types/src/roles.d.ts +3 -0
  586. package/types/src/selectorGenerator.d.ts +3 -0
  587. package/types/src/text.d.ts +16 -0
  588. package/types/src/textFragmentGenerator.d.ts +2 -0
  589. package/types/src/textrefFragment.d.ts +40 -0
  590. 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,2 @@
1
+ // A plain string rather than a union so new roles don't require a type change; see roles.ts for the roles generated.
2
+ export type GndRole = string;
@@ -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,6 @@
1
+ export declare class IdAllocator {
2
+ private claimed;
3
+ private counters;
4
+ allocate(prefix: string, isTaken: (id: string) => boolean): string;
5
+ claim(id: string): boolean;
6
+ }
@@ -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
+ import type { GndRole } from "./types.ts";
2
+ export declare function hasExplicitRole(el: Element): boolean;
3
+ export declare function extractNodeRoles(el: Element): GndRole[];
@@ -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,2 @@
1
+ import type { TextFragmentDirective } from "./textrefFragment.ts";
2
+ export declare function textFragmentDirectiveFor(range: Range): TextFragmentDirective | undefined;
@@ -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;