@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
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2022, Readium Foundation
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # @readium/guided-navigation
2
+
3
+ Generates [Guided Navigation](https://github.com/readium/guided-navigation) (GND) documents from HTML and XHTML, as [`@readium/shared`](https://www.npmjs.com/package/@readium/shared) `GuidedNavigationDocument`/`GuidedNavigationObject` instances.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @readium/guided-navigation
9
+ ```
10
+
11
+ Needs DOM globals (`DOMParser`, `XMLSerializer`, `Range`, `CSS.escape`…): a browser, or a DOM implementation such as jsdom installed on `globalThis`. No HTML/XML parser is bundled.
12
+
13
+ ## Building a GND document
14
+
15
+ ```typescript
16
+ import { makeGnd } from "@readium/guided-navigation";
17
+
18
+ const gnd = makeGnd(`
19
+ <section epub:type="chapter">
20
+ <h1>Chapter One</h1>
21
+ <p>It was a dark and stormy night.</p>
22
+ </section>
23
+ `);
24
+ // gnd?.guided: GuidedNavigationObject[]
25
+ ```
26
+
27
+ ```typescript
28
+ function makeGnd(input: string | Element, mediaType?: GndMediaType, options?: GndGenerationOptions): GuidedNavigationDocument | undefined;
29
+ function parseMarkup(input: string | Element, mediaType?: GndMediaType, options?: GndGenerationOptions): GuidedNavigationObject[];
30
+ ```
31
+
32
+ `input` is either raw markup, or a live, already-rendered element to convert in place — see `domRange` below for why that distinction matters. `mediaType` is `"text/html" | "application/xhtml+xml"`. Omit it to sniff from `input` (a string: XML declaration, `xmlns:epub`, XHTML doctype → XHTML, else HTML; an element: its own document's content type).
33
+
34
+ Malformed XHTML (an undeclared `epub:` prefix, an HTML entity like `&nbsp;`…) throws. Pass `{ htmlFallback: true }` in `options` to re-parse it as HTML instead.
35
+
36
+ `makeGnd` returns `undefined` when the input has no navigable content, since a document's `guided` can't be empty. `parseMarkup` returns the objects without the document wrapper, and an empty array in that case.
37
+
38
+ Use `serialize()` on the result to get the JSON.
39
+
40
+ ## Text references (`textrefs`)
41
+
42
+ Off by default — it costs extra compute to generate. When on, every node with a role gets a `textref`: a link back to the element it came from, either `#id` (if it has one) or `#css(<selector>)`. It's a URI reference, not a Readium `Locator`.
43
+
44
+ ```typescript
45
+ interface GndGenerationOptions {
46
+ textrefs?: boolean | GndRole[] | TextrefOptions;
47
+ }
48
+
49
+ interface TextrefOptions {
50
+ roles?: boolean | GndRole[]; // which roles get a reference; true = every role
51
+ domRange?: boolean; // also compute exact textNodeIndex/charOffset
52
+ textFragment?: boolean; // also append a WICG Text Fragment directive
53
+ }
54
+ ```
55
+
56
+ ```typescript
57
+ makeGnd(html, undefined, { textrefs: true }); // every role
58
+ makeGnd(html, undefined, { textrefs: ["heading1", "paragraph"] }); // just these roles
59
+ ```
60
+
61
+ Whatever the option, a node with no text, children or other ref of its own (e.g. `<hr>`, or `<span role="img" aria-label="…">`) always gets a `textref` to its element, since the schema requires one of them. So does every `math` node, to locate it.
62
+
63
+ `roles` also accepts `"leaf-text"`, not a real GND role — it matches a roleless block that owns its own text directly (e.g. a `<div>` standing in for `<p>`, no role, no semantic tag). `true` already includes it; in an array, add it explicitly:
64
+
65
+ ```typescript
66
+ makeGnd(html, undefined, { textrefs: ["leaf-text"] }); // only roleless leaf-text blocks
67
+ makeGnd(html, undefined, { textrefs: ["leaf-text", "heading1"] }); // that, plus real headings
68
+ ```
69
+
70
+ `domRange` makes the reference more precise: `#domrange(...)`, pointing at the exact text node and character offset, not just the element. This only works if you pass a live DOM element as `input` (not an HTML string) — pass a string and `domRange` is silently skipped, because a string gets parsed into a detached copy you can't point back to:
71
+
72
+ ```typescript
73
+ makeGnd(document.querySelector("article")!, undefined, {
74
+ textrefs: { roles: true, domRange: true },
75
+ });
76
+ ```
77
+
78
+ `cssSelector` and `domRange` prefer an id, then a unique class or tag, falling back to `tag:nth-child(n)` only when none of those disambiguate a node from its siblings. That fallback (and `domRange`'s text-node index/offset, which is positional regardless) is only accurate against the DOM as it existed at generation time.
79
+
80
+ `textFragment` adds a [WICG Text Fragment](https://wicg.github.io/scroll-to-text-fragment/) directive on top of whatever reference you already have, e.g. `#css(p.foo):~:text=It%20was...`. It only needs the text, so — unlike `domRange` — it works fine with a plain HTML string:
81
+
82
+ ```typescript
83
+ makeGnd(html, undefined, { textrefs: { roles: true, textFragment: true } });
84
+ ```
85
+
86
+ The directive is generated by Google's [text-fragments-polyfill](https://github.com/GoogleChromeLabs/text-fragments-polyfill) (via `@readium/helpers`). If the node's text is unique in the document, that text is the whole directive. If it's repeated (e.g. the same heading twice), the polyfill adds a bit of surrounding text so it matches only one spot. If it still can't make it unique, no directive is generated.
87
+
88
+ If the node's text is too long, the polyfill only keeps the first few words and the last few words (`textStart` and `textEnd`), instead of the whole thing.
89
+
90
+ Use `decodeTextref({ id, textref })` to read a `textref` back. It returns:
91
+
92
+ ```typescript
93
+ { cssSelector?, domRange?, text?, fragment? }
94
+ ```
95
+
96
+ - Exact match (one quote) → `text: { highlight, before?, after? }`
97
+ - Range (the `textStart`/`textEnd` case above) → `fragment` (the raw `:~:text=...` string)
98
+
99
+ It returns `undefined` if the `textref` isn't one of ours (e.g. it's a plain link's `href`). `combineDomRangeTextrefs(first, last)` joins two decoded `domRange` references into one spanning both.
100
+
101
+ The lower-level pieces are exported too: `encodeCssSelectorFragment(selector)`/`decodeCssSelectorFragment(textref)` for `#css(...)`, and `encodeDomRangeFragment(domRange)`/`decodeDomRangeFragment(textref)` for `#domrange(...)` (a `DomRangeJSON`: `{ start: { cssSelector, textNodeIndex, charOffset? }, end?: {...} }`, the RWPM shape behind `@readium/shared`'s `DomRange`).
102
+
103
+ ## Objects
104
+
105
+ - **`role`** can have multiple entries: tag name, ARIA `role`, `epub:type` all contribute, in that order (e.g. `<section epub:type="chapter">` → `["section", "chapter"]`). `role="presentation"`/`"none"` overrides everything to `["presentation"]`.
106
+ - **`text`** carries `ssml` when the text needs it (inline formatting, a language shift, or an embedded footnote/pagebreak/image mid-sentence). `ssml` marks embedded objects with a `<readium:noteref id="..." />`-style placeholder whose `id` matches a sibling in `children`.
107
+ - **`math`** nodes carry MathML as-is in `text.ssml` (`<math xmlns="http://www.w3.org/1998/Math/MathML">…</math>`), or other `role="math"` markup's content in `text.plain`, with `alttext`/`aria-label` as `description`.
108
+ - **`imgref`/`audioref`/`videoref`** are a media element's `src`. **`textref`** is an `href` — reused for navigational-list items (`toc`, `index`...), `noteref`/`backlink`/`biblioref`/`glossref`, and plain links.
109
+ - **`description`** holds a node's accessible name (`aria-label`, `alt`, `<figcaption>`...) as `description.text` when it differs from its visible text.
110
+ - Empty/presentational/`aria-hidden`/`hidden` content and role-less wrapper `<div>`s are dropped from the tree, not kept as empty nodes.
111
+ - A block whose only child has no role/id/ref of its own gets that child's text hoisted into it: `<p><em>Cover</em></p>` → `{ role: ["paragraph"], text: { plain: "Cover" } }`, not a nested anonymous child. A child carrying its own ref is never hoisted: `<p><a href="...">Cover</a></p>` → `{ role: ["paragraph"], children: [{ text: { plain: "Cover" }, textref: "..." }] }`.
112
+
113
+ When `text` comes from `aria-label`/`aria-labelledby` instead of the element's content, it isn't on the page. `isAriaSubstituted(object)` tells such objects apart, and `substitutedOwnSelector(object)` returns a substituted link's own CSS selector, since its `textref` is its `href`. Both only know about objects returned by `parseMarkup`/`makeGnd`, not deserialized ones.
114
+
115
+ ## Footnotes and pagebreaks
116
+
117
+ Both are read out of narrative order, so the converter handles them specially:
118
+
119
+ - **`noteref`** (`<a role="doc-noteref" href="#note1">`) resolves its `href` and embeds the target's whole subtree as `children` — no second lookup needed. Unresolvable hrefs get a plain `textref` child instead. The footnote is suppressed from also appearing at its original location — except when that location is inside an `endnotes` section, where it's kept so the section's own list isn't left silent. The kept footnote keeps its id, and the noteref gets a generated one (`noteref1`…) instead.
120
+ - **`pagebreak`** (`<span epub:type="pagebreak" title="42">`) carries its label as `text`. Mid-sentence, it's a `<readium:pagebreak id="..." />` placeholder in that sentence's `ssml`, with the pagebreak node as a sibling `children` entry.
121
+
122
+ ## Roles
123
+
124
+ Three independent sources, mapped in [`src/roles.ts`](src/roles.ts):
125
+
126
+ 1. **Element type** — `<h1>` → `heading1`, `<nav>` → `navigation`, `<blockquote>` → `blockquote`, etc.
127
+ 2. **ARIA role** — `role="doc-chapter"` → `chapter`, `role="figure"` → `figure`, etc. `role="heading"` reads its level from `aria-level` (default `2`).
128
+ 3. **`epub:type`** — `epub:type="chapter"` → `chapter`, `epub:type="pagebreak"` → `pagebreak`, etc. (XHTML only, see below).
129
+
130
+ ## `epub:type` requires XHTML
131
+
132
+ `epub:type` only means anything in namespace-aware XHTML. Pass a complete XHTML document (`xmlns:epub` on the root):
133
+
134
+ ```xml
135
+ <?xml version="1.0" encoding="UTF-8"?>
136
+ <!DOCTYPE html>
137
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
138
+ <head><meta charset="utf-8"/><title>...</title></head>
139
+ <body>
140
+ <section epub:type="chapter">...</section>
141
+ </body>
142
+ </html>
143
+ ```
144
+
145
+ ARIA roles and native elements work as plain HTML fragments.
146
+
147
+ ## Fixtures
148
+
149
+ [`fixtures/`](fixtures/README.md) is a language-agnostic conformance suite for HTML → GND, shipped with the package.
150
+
151
+ ## Development
152
+
153
+ ```sh
154
+ pnpm run test # Jest
155
+ pnpm run build # outputs dist/ and types/
156
+ pnpm run generate-fixtures-manifest
157
+ ```
package/dist/a11y.js ADDED
@@ -0,0 +1 @@
1
+ import{normalizeWhitespace as c}from"./text.js";import{hasExplicitRole as g}from"./roles.js";function p(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function x(t){let s="";const u=r=>{r.nodeType===3&&(s+=r.nodeValue??"");for(let i=r.firstChild;i;i=i.nextSibling)u(i)};return u(t),s}function h(t){return c(x(t),!0).trim()}function d(t){let s="";const u=(r,i)=>{if(r.nodeType===3){s+=r.nodeValue??"";return}if(!(r.nodeType===1&&!i&&g(r)))for(let e=r.firstChild;e;e=e.nextSibling)u(e,!1)};return u(t,!0),s}function T(t){return c(d(t),!0).trim()}function w(t){if(p(t))return[null,!1];const s=(t.getAttribute("aria-labelledby")??"").trim();if(s){const e=[...new Set(s.split(/\s+/).filter(Boolean))],n=t.ownerDocument,l=e.map(o=>n.getElementById(o)).filter(o=>o!==null);if(l.length>0){let o="";l.forEach((f,b)=>{if(p(f))return;const m=f.getAttribute("aria-label");o+=m||d(f),b<l.length-1&&(o+=" ")});const a=c(o,!0).trim();if(a!=="")return[a,!0]}}const u=(t.getAttribute("aria-label")??"").trim();if(u)return[u,!0];const r=(t.getAttribute("aria-describedby")??"").trim();if(r){const n=[...new Set(r.split(/\s+/).filter(Boolean))].map(l=>t.ownerDocument.getElementById(l)).filter(l=>l!==null);if(n.length>0){const l=n.map(a=>d(a)).join(" "),o=c(l,!0).trim();if(o!=="")return[o,!0]}}const i=t.tagName.toLowerCase();if(i==="img"){const e=(t.getAttribute("alt")??"").trim();if(e)return[e,!0];const n=(t.getAttribute("title")??"").trim();if(n)return[n,!0]}else if(i==="svg"){const e=t.querySelector(":scope > title");if(e){const n=h(e);if(n)return[n,!0]}}else if(i==="math"){const e=(t.getAttribute("alttext")??"").trim();if(e)return[e,!0]}return[null,!0]}const y={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function S(t){return y[t]??["",void 0]}const B=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{S as convertElementToSSMLTag,w as extractNodeAria,h as normalizedNodeText,T as normalizedNodeTextExcludingExplicitRoles,B as skippedElements};
@@ -0,0 +1 @@
1
+ import{hasExplicitRole as P,extractNodeRoles as F}from"./roles.js";import{skippedElements as W,extractNodeAria as B,normalizedNodeText as z,normalizedNodeTextExcludingExplicitRoles as O,convertElementToSSMLTag as I}from"./a11y.js";import{normalizeWhitespace as L,ctxEqual as _}from"./text.js";import{ssmlAttrEscape as A,ssmlTextEscape as v,startsWithBindingPunct as q}from"@readium/helpers";import{NavObject as w,isEmptyObj as D,finalizeToGuidedNavigationObject as X}from"./object.js";import{sniffMediaType as G,nodeLanguage as y,isInlineTag as H}from"./dom.js";import{encodeDomRangeFragment as U,encodeTextFragmentDirective as V}from"./textrefFragment.js";import{rootAnchorSelector as Y,textrefForSelector as S,selectorForElement as C}from"./selectorGenerator.js";import{generateDomRange as J}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as K}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as Q}from"./options.js";import{IdAllocator as Z}from"./idAllocator.js";import{prescan as tt}from"./prescan.js";import{pagebreak as et,noteref as st,link as it}from"./elementHandlers.js";const nt="http://www.w3.org/1998/Math/MathML",rt=3,ot=1,lt=new Set(["summary","dfn","span"]);function M(c,t){return lt.has(c)&&t.length>0?!0:!H(c)}class b{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new Z,this.noterefDepth=0,this.allowNode=null,this.selectorPredicate=null,this.domRangeEnabled=!1,this.textFragmentEnabled=!1,this.leafTextEnabled=!1,this.docRoot=null,this.selectorRoot=null,this.selectorRootAnchor=null,this.root=new w,this.current=this.root,this.foldedCaptions=new Set,this.segments=[],this.textAcc="",this.currentCtx={lang:"",tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0,this.lastFlowRange=null,this.lastFlowText=null,this.xmlParsed=t}spawnChild(t,e=1){const s=new b(this.xmlParsed);return s.ids=this.ids,s.suppressed=this.suppressed,s.idAlloc=this.idAlloc,s.noterefDepth=this.noterefDepth+e,s.allowNode=t,s.docRoot=this.docRoot,s.selectorRoot=this.selectorRoot,s.selectorRootAnchor=this.selectorRootAnchor,s.selectorPredicate=this.selectorPredicate,s.domRangeEnabled=this.domRangeEnabled,s.textFragmentEnabled=this.textFragmentEnabled,s.leafTextEnabled=this.leafTextEnabled,s}prescan(t){tt(t,this.ids,this.suppressed)}convert(t){this.prescan(t),this.walk(t),this.flushText()}convertChildren(t){this.prescan(t);for(let e=t.firstChild;e;e=e.nextSibling)this.walk(e);this.flushText()}resultBuilders(){const t=this.root.finalize(e=>S(C(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0?D(t)?[]:[t]:t.children}result(){return this.resultBuilders().map(X)}descend(t,e){const s=new w;s.el=t,s.noText=this.foldedCaptions.has(t)||(!P(t)||e.includes("caption"))&&this.current.noText,this.current.children.push(s),this.current.hasChildBlock=!0,this.current=s}appendChild(t){t.noText=this.current.noText,this.current.children.push(t)}walk(t){if(t.nodeType===rt){this.text(t);return}if(t.nodeType!==ot)return;const e=t,s=this.current,a=this.head(e);if(!a)for(let i=e.firstChild;i;i=i.nextSibling)this.walk(i);this.tail(e,a,s)}head(t){const e=t.tagName.toLowerCase();if(W.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[s,a]=B(t);if(!a&&t!==this.allowNode)return!0;const i=F(t);if((e==="img"||e==="svg")&&(i.includes("presentation")||s===null&&t.hasAttribute("alt")&&t.getAttribute("alt").trim()===""))return!0;if(e==="br")return this.current.noText||(this.closeSegment(),this.segments.push({kind:"break"}),this.flowEndsWithSpace=!0),!0;if(i.includes("pagebreak"))return!et(this,t,s,i);if(e==="a"&&i.includes("noteref")&&t.getAttribute("href"))return st(this,t,i),!0;if(e==="a"&&t.getAttribute("href"))return it(this,t,i,s),!0;if(e==="img"){const o={role:i},r=t.getAttribute("src");return r&&(o.imgref=r),s&&(o.description=s),this.placeholder(t,"image",o),!0}if(e==="audio"||e==="video"){const o={role:i};let r=t.getAttribute("src");if(!r){const f=t.querySelector(":scope > source[src]");f&&(r=f.getAttribute("src"))}return e==="audio"?r&&(o.audioref=r):r&&(o.videoref=r),s&&(o.description=s),this.placeholder(t,e,o),!0}if(i.includes("image")||i.includes("math")){const o={role:i};if(s&&(o.description=s),i.includes("math")){if(t.namespaceURI===nt)o.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:""};else{const r=z(t);r&&(o.text={plain:r,ssml:"",language:""})}o.textref=S(C(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,i.includes("math")?"math":"image",o),!0}if(!M(e,i))return!1;this.flushText(),this.descend(t,i);const h=this.current.object;if(i.length>0&&(h.role=i),s)h.description=s,i.includes("figure")&&(this.current.noText=!0);else if(i.includes("figure")){const o=this.implicitCaptionOf(t);if(o){const r=O(o);r&&(h.description=r,this.current.noText=!0)}}else if(i.includes("table")){const o=this.implicitCaptionOf(t);if(o){const r=O(o);r&&(h.description=r,this.foldedCaptions.add(o))}}const p=t.getAttribute("id");return p&&(h.id=p),!1}implicitCaptionOf(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling)if(F(e).includes("caption")&&!e.getAttribute("aria-labelledby"))return e;return null}tail(t,e,s){if(e)return;const a=t.tagName.toLowerCase(),i=F(t);if(!i.includes("pagebreak")&&M(a,i)){this.flushText(),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const h=this.leafTextEnabled&&i.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(i)||h)&&this.applyTextref(t),this.current=s}}applyTextref(t){const e=this.current.object,s=C(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=S(s,t),this.domRangeEnabled&&this.lastFlowRange){const a=s?{el:t,selector:s}:void 0,i=J(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,a);i&&(e.textref=U({...i,container:s}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const a=this.docRoot.createRange();a.setStart(...this.lastFlowRange.first),a.setEnd(...this.lastFlowRange.last);const i=K(a);i&&(e.textref=`${e.textref??"#"}${V(i)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(/^\s*$/.test(e)){(this.textAcc.length>0||this.segments.length>0)&&(this.textAcc+=L(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const s=this.textContext(t);if(_(s,this.currentCtx)||(this.closeSegment(),this.currentCtx=s),this.textAcc+=L(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const a=t;this.flowFirstNode===null&&(this.flowFirstNode=a,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=a,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){const e={lang:y(t.parentElement),tag:""};for(let s=t.parentElement;s&&s!==this.current.el;s=s.parentElement){const[a,i]=I(s.tagName.toLowerCase());if(a&&a!=="break"){e.tag=a,e.attrs=i;break}}return e}updateFlowSpace(){this.textAcc.length>0&&(this.flowEndsWithSpace=this.textAcc.endsWith(" "))}closeSegment(){this.textAcc.length!==0&&(this.segments.push({kind:"text",text:this.textAcc,ctx:this.currentCtx}),this.textAcc="")}resetFlow(){this.segments=[],this.textAcc="",this.currentCtx={lang:"",tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0}placeholder(t,e,s,a){if(D(s))return;const i=new w;if(i.el=t,i.object=s,this.current.noText){this.appendChild(i);return}this.closeSegment(),this.pendingChildren.push(i),this.segments.push({kind:"placeholder",tag:e,child:i,candidateID:a??t.getAttribute("id")??void 0}),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,s=this.flowFirstNode,a=this.flowFirstOffset,i=this.flowLastNode,h=this.flowLastOffset;if(this.resetFlow(),this.lastFlowRange=null,this.lastFlowText=null,t.length===0)return;for(;t.length>0;){const n=t[0];if(n.kind==="break"){t=t.slice(1);continue}if(n.kind==="text"){const l=n.text.replace(/^\s+/,"");if(l===""){t=t.slice(1);continue}t=[{...n,text:l},...t.slice(1)]}break}for(;t.length>0;){const n=t[t.length-1];if(n.kind==="break"){t=t.slice(0,-1);continue}if(n.kind==="text"){const l=n.text.replace(/\s+$/,"");if(l===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...n,text:l}]}break}if(!t.some(n=>n.kind==="text"&&n.text.trim()!=="")){for(const n of e)this.appendChild(n);return}const o=[];for(const n of t)if(n.kind==="text"&&n.text.trim()!==""){const l=n.ctx.lang;o.includes(l)||o.push(l)}let r=y(this.current.el??null);o.length===1&&o[0]!==""&&(r=o[0]);let f=!1;for(const n of t)if(n.kind!=="text"||n.ctx.tag!==""||n.ctx.lang!==r){f=!0;break}if(f&&r===""&&(r="en"),f)for(const n of t){if(n.kind!=="placeholder")continue;let l=n.candidateID;(!l||!this.idAlloc.claim(l))&&(l=this.idAlloc.allocate(n.tag,g=>this.ids.has(g))),n.child.object.id=l}let u="",d=!1,E=!1,T=!1,R=!1;for(const n of t)if(n.kind==="text"){const l=n.text.startsWith(" "),g=n.text.replace(/^ +| +$/g,"");if(g===""){R=!0;continue}let m=!1;if(u.length>0){const x=d||R||l;E?m=!0:T?m=x&&!q(g):m=x}m&&(u+=" "),u+=g,d=n.text.endsWith(" "),E=!1,T=!1,R=!1}else n.kind==="break"?E=!0:n.kind==="placeholder"&&(T=!0);const $=t.some(n=>n.kind==="placeholder");this.lastFlowText=u.trim();const N={plain:f&&!$?"":u.trim(),ssml:"",language:r};if(f){let n="";for(const l of t)if(l.kind==="text"){let g=l.ctx.tag,m=l.ctx.attrs;if(l.ctx.lang!==r&&l.ctx.lang!==""&&(g="lang",m=void 0),g){n+=`<${g}`;for(const[x,j]of Object.entries(m??{}))n+=` ${x}="${A(j)}"`;l.ctx.lang!==r&&l.ctx.lang!==""&&(n+=` xml:lang="${A(l.ctx.lang)}"`),n+=`>${v(l.text)}</${g}>`}else n+=v(l.text)}else l.kind==="break"?n+="<break/>":l.kind==="placeholder"&&(n+=`<readium:${l.tag} id="${A(l.child.object.id)}" />`);N.ssml=n}const k=new w;k.object={text:N};for(const n of e)k.children.push(n);this.appendChild(k),s&&i&&(this.lastFlowRange={first:[s,a],last:[i,h]})}}const at=/<body[\s>]/i;function kt(c,t,e){const{predicate:s,leafText:a,domRange:i,textFragment:h}=Q(e?.textrefs);if(typeof c!="string"){const u=t??(c.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),d=new b(u==="application/xhtml+xml");return d.selectorPredicate=s,d.leafTextEnabled=a,d.domRangeEnabled=i,d.textFragmentEnabled=h,d.docRoot=c.ownerDocument,d.selectorRoot=c,d.selectorRootAnchor=Y(c),d.convert(c),d.result()}let p=t??G(c),o=new DOMParser().parseFromString(c,p);if(p==="application/xhtml+xml"){const u=o.getElementsByTagNameNS("*","parsererror")[0];if(u){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${u.textContent?.trim()??""}`);p="text/html",o=new DOMParser().parseFromString(c,p)}}const r=new b(p==="application/xhtml+xml");r.selectorPredicate=s,r.leafTextEnabled=a,r.textFragmentEnabled=h,r.docRoot=o;const f=o.querySelector("body");return f&&!at.test(c)?r.convertChildren(f):r.convert(f??o.documentElement),r.result()}export{b as Converter,kt as parseMarkup};
package/dist/dom.js ADDED
@@ -0,0 +1 @@
1
+ function i(e){for(let t=e;t;t=t.parentElement){const n=t.getAttribute("xml:lang");if(n)return n;const r=t.getAttribute("lang");if(r)return r}return""}function s(e){for(let t=e.firstChild;t;t=t.nextSibling)if(t.nodeType===1)return!0;return!1}function o(e,t){for(let n=t;n;n=n.parentElement)if(n===e)return!0;return!1}const a=new Set(["object","base","font","tt","i","b","u","big","small","em","strong","dfn","code","samp","kbd","var","cite","abbr","time","acronym","mark","ruby","rt","rp","rtc","a","img","br","wbr","map","q","sub","sup","bdo","iframe","embed","span","input","select","textarea","label","button","optgroup","option","legend","datalist","keygen","output","progress","meter","area","param","source","track","summary","command","basefont","bgsound","menuitem","data","bdi","s","strike","nobr","rb"]);function u(e){return a.has(e)}function l(e){const t=e.slice(0,500);return/<\?xml\b/.test(t)||/xmlns:epub=/.test(t)||/DOCTYPE\s+html\s+PUBLIC\s+"-\/\/W3C\/\/DTD XHTML/i.test(t)?"application/xhtml+xml":"text/html"}export{s as hasElementChild,o as isAncestorOf,u as isInlineTag,i as nodeLanguage,l as sniffMediaType};
@@ -0,0 +1 @@
1
+ import{selectorForElement as d}from"./selectorGenerator.js";const s=3;function l(t,i){let e=0;for(const r of Array.from(t.childNodes)){if(r===i)return e;r.nodeType===s&&e++}return e}function f(t,i,e,r,n){const o=t.parentElement;if(!o)return;const c=n&&o===n.el?n.selector:d(o,e,r);if(c)return{cssSelector:c,textNodeIndex:l(o,t),charOffset:i}}function a(t,i,e,r){const n=f(...t.first,i,e,r);if(!n)return;const o=f(...t.last,i,e,r);return o?{start:n,end:o}:{start:n}}export{a as generateDomRange};
@@ -0,0 +1 @@
1
+ import{normalizedNodeText as d}from"./a11y.js";import{textIsEmpty as m}from"./text.js";import{ariaSubstitutedBuilders as g,substitutedOwnSelectorBuilders as p}from"./object.js";import{hasElementChild as x,isAncestorOf as b}from"./dom.js";import{selectorForElement as u,textrefForSelector as A}from"./selectorGenerator.js";function E(s,e,n,l){const t={role:l},i=(e.getAttribute("title")??"").trim();i?t.text={plain:i,ssml:"",language:""}:n&&(t.text={plain:n,ssml:"",language:""},g.add(t));const o=!!(t.text&&!m(t.text)),r=!s.xmlParsed&&(x(e)||o&&e.firstChild!==null);if(!o&&!r){const c=d(e);c&&(t.text={plain:c,ssml:"",language:""})}const f=u(e,s.selectorRoot,s.selectorRootAnchor),a=A(f,e);return a&&(t.textref=a),s.placeholder(e,"pagebreak",t),r}function S(s,e,n){const l={role:n},t=d(e);t&&(l.text={plain:t,ssml:"",language:""});const i=e.getAttribute("href")??"";let o=e.getAttribute("id")??"";if(!o&&i.startsWith("#")){const r=s.ids.get(i.slice(1));(!r||s.suppressed.has(r))&&(o=i.slice(1))}if(i.startsWith("#")){const r=i.slice(1),f=s.ids.get(r);if(f&&!b(f,e)&&s.noterefDepth<3){const a=s.spawnChild(f);a.convert(f);const c=a.resultBuilders();if(c.length>0){for(const h of c)delete h.id;l.children=c}}}!l.children&&i&&(l.children=[{textref:i}]),s.placeholder(e,"noteref",l,o||void 0)}function w(s,e,n,l){const t={};if(n.length>0&&(t.role=n),l){t.text={plain:l,ssml:"",language:""},g.add(t);const o=u(e,s.selectorRoot,s.selectorRootAnchor);o&&p.set(t,o)}else{const o=d(e);o&&(t.text={plain:o,ssml:"",language:""})}const i=e.getAttribute("href");i&&(t.textref=i),s.placeholder(e,n[0]??"link",t)}export{w as link,S as noteref,E as pagebreak};
@@ -0,0 +1 @@
1
+ class i{constructor(){this.claimed=new Set,this.counters=new Map}allocate(t,c){for(;;){const e=(this.counters.get(t)??0)+1;this.counters.set(t,e);const s=`${t}${e}`;if(!(c(s)||this.claimed.has(s)))return this.claimed.add(s),s}}claim(t){return this.claimed.has(t)?!1:(this.claimed.add(t),!0)}}export{i as IdAllocator};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{makeGnd as r}from"./makeGnd.js";import{parseMarkup as m}from"./converter.js";import{combineDomRangeTextrefs as a,decodeCssSelectorFragment as d,decodeDomRangeFragment as s,decodeTextref as c,encodeCssSelectorFragment as g,encodeDomRangeFragment as f}from"./textrefFragment.js";import{isAriaSubstituted as x,substitutedOwnSelector as i}from"./object.js";export{a as combineDomRangeTextrefs,d as decodeCssSelectorFragment,s as decodeDomRangeFragment,c as decodeTextref,g as encodeCssSelectorFragment,f as encodeDomRangeFragment,x as isAriaSubstituted,r as makeGnd,m as parseMarkup,i as substitutedOwnSelector};
@@ -0,0 +1 @@
1
+ import{GuidedNavigationDocument as t}from"@readium/shared";import{parseMarkup as i}from"./converter.js";function u(e,n,r){const o=i(e,n,r);return o.length>0?new t({guided:o}):void 0}export{u as makeGnd};
package/dist/object.js ADDED
@@ -0,0 +1 @@
1
+ import{GuidedNavigationObject as h,GuidedNavigationDescription as u,GuidedNavigationText as a}from"@readium/shared";import{textIsEmpty as l,finalizeText as o}from"./text.js";const x=["math","separator"],g=new WeakSet,s=new WeakSet,p=new WeakMap,f=new WeakMap;function N(e){return s.has(e)}function j(e){return f.get(e)}function c(e){return e.role?.some(n=>x.includes(n))?!1:!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||l(e.text))&&!(e.children&&e.children.length>0)&&!e.description}function v(e){return!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||l(e.text))&&!!(e.children&&e.children.length>0)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description}function m(e){return!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class k{constructor(){this.object={},this.children=[],this.noText=!1,this.hasChildBlock=!1}finalize(n){const t=this.object,d=[];for(const i of this.children){const r=i.finalize(n);if(!c(r)){if(v(r)){d.push(...r.children??[]);continue}d.push(r)}}if(d.length>0&&(t.children=d),t.role?.length&&t.children?.length===1&&!t.role.includes("presentation")){const i=t.children[0];i.role?.length&&t.role.every(r=>i.role.includes(r))&&delete t.role}if((!t.text||l(t.text))&&t.children?.length===1){const i=t.children[0];m(i)&&(i.text&&(t.text=i.text),t.children=i.children)}if(this.el&&n&&!c(t)&&!b(t)){const i=n(this.el);i&&(t.textref=i)}return t}}function b(e){return!!e.audioref||!!e.imgref||!!e.textref||!!e.videoref||!!(e.text&&(e.text.plain!==""||e.text.ssml!==""))||!!(e.children&&e.children.length>0)}function w(e){const n=new h({id:e.id||void 0,textref:e.textref||void 0,imgref:e.imgref||void 0,audioref:e.audioref||void 0,videoref:e.videoref||void 0,text:o(e.text),role:e.role&&e.role.length>0?new Set(e.role):void 0,children:e.children&&e.children.length>0?e.children.map(w):void 0,description:e.description?new u({text:new a({plain:e.description})}):void 0});g.has(e)&&s.add(n);const t=p.get(e);return t&&f.set(n,t),n}export{k as NavObject,g as ariaSubstitutedBuilders,w as finalizeToGuidedNavigationObject,N as isAriaSubstituted,c as isEmptyObj,j as substitutedOwnSelector,p as substitutedOwnSelectorBuilders};
@@ -0,0 +1 @@
1
+ const i="leaf-text";function t(e){if(e===!0)return r=>r.length>0;if(Array.isArray(e)&&e.length>0){const r=new Set(e.filter(n=>n!==i));return n=>n.some(f=>r.has(f))}return null}function a(e){return e===!0||Array.isArray(e)&&e.includes(i)}function l(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function s(e){return l(e)?{predicate:t(e.roles),leafText:a(e.roles),domRange:!!e.domRange,textFragment:!!e.textFragment}:{predicate:t(e),leafText:a(e),domRange:!1,textFragment:!1}}export{i as leafTextRoleKeyword,s as normalizeTextrefOptions};
@@ -0,0 +1 @@
1
+ import{extractNodeRoles as c}from"./roles.js";import{isAncestorOf as u}from"./dom.js";function m(i){for(let r=i.parentElement;r;r=r.parentElement)if(c(r).includes("endnotes"))return!0;return!1}function p(i,r,l){const s=[],f=(t,e)=>{const n=t.getAttribute("id");if(n&&!r.has(n)&&r.set(n,t),e=e||t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"),!e&&t.tagName.toLowerCase()==="a"&&c(t).includes("noteref")){const a=t.getAttribute("href")??"";a.startsWith("#")&&s.push({id:a.slice(1),ref:t})}for(let o=t.firstElementChild;o;o=o.nextElementSibling)f(o,e)};f(i,!1);for(const t of s){const e=r.get(t.id);e&&(u(e,t.ref)||m(e)||l.add(e))}}export{p as prescan};
package/dist/roles.js ADDED
@@ -0,0 +1 @@
1
+ const u=["heading1","heading2","heading3","heading4","heading5","heading6"],c={"doc-abstract":"abstract","doc-acknowledgments":"acknowledgments","doc-afterword":"afterword","doc-appendix":"appendix",article:"article","doc-backlink":"backlink","doc-biblioentry":"listItem","doc-bibliography":"bibliography","doc-biblioref":"biblioref",blockquote:"blockquote",caption:"caption",cell:"cell","doc-chapter":"chapter","doc-colophon":"colophon",columnheader:"columnheader",complementary:"complementary","doc-conclusion":"conclusion","doc-cover":"cover","doc-credit":"credit","doc-credits":"credits","doc-dedication":"dedication",definition:"definition","doc-endnote":"footnote","doc-endnotes":"endnotes","doc-epigraph":"epigraph","doc-epilogue":"epilogue","doc-errata":"errata","doc-example":"example",figure:"figure","doc-footnote":"footnote","doc-foreword":"foreword","doc-glossary":"glossary","doc-glossref":"glossref",img:"image",image:"image","doc-index":"index","doc-introduction":"introduction",list:"list",listitem:"listItem",main:"main",math:"math",navigation:"navigation","doc-noteref":"noteref","doc-notice":"notice","doc-pagebreak":"pagebreak","doc-pagelist":"pagelist",paragraph:"paragraph","doc-part":"part","doc-preface":"preface","doc-prologue":"prologue","doc-pullquote":"pullquote",grid:"table",gridcell:"cell",presentation:"presentation",none:"presentation","doc-qna":"qna",qna:"qna",region:"region",row:"row",rowheader:"rowheader",separator:"separator","doc-subtitle":"subtitle",table:"table",term:"term","doc-tip":"tip","doc-toc":"toc"},f={abstract:"abstract",acknowledgments:"acknowledgments",afterword:"afterword",appendix:"appendix",aside:"aside",backlink:"backlink",biblioentry:"listItem",bibliography:"bibliography",biblioref:"biblioref","table-cell":"cell",chapter:"chapter",colophon:"colophon",conclusion:"conclusion",cover:"cover",credit:"credit",credits:"credits",dedication:"dedication",glossdef:"definition",endnote:"footnote",endnotes:"endnotes",rearnote:"footnote",rearnotes:"endnotes",epigraph:"epigraph",epilogue:"epilogue",errata:"errata",example:"example",figure:"figure",footnote:"footnote",foreword:"foreword",glossary:"glossary",glossref:"glossref",index:"index",introduction:"introduction",landmarks:"landmarks",list:"list","list-item":"listItem",loa:"loa",loi:"loi",lot:"lot",lov:"lov",noteref:"noteref",notice:"notice",pagebreak:"pagebreak","page-list":"pagelist",pagelist:"pagelist",part:"part",preface:"preface",prologue:"prologue",pullquote:"pullquote",qna:"qna","table-row":"row",subtitle:"subtitle",table:"table",glossterm:"term",tip:"tip",toc:"toc"},g={article:"article",aside:"aside",audio:"audio",blockquote:"blockquote",caption:"caption",figcaption:"caption",td:"cell",dd:"definition",details:"details",figure:"figure",header:"header",h1:"heading1",h2:"heading2",h3:"heading3",h4:"heading4",h5:"heading5",h6:"heading6",img:"image",ul:"list",ol:"list",li:"listItem",main:"main",math:"math",nav:"navigation",p:"paragraph",pre:"preformatted",tr:"row",section:"section",hr:"separator",summary:"summary",table:"table",dfn:"term",dt:"term",video:"video",svg:"image"},b=new Set(["tr","td","th"]),m=new Set(["tr","thead","tbody","tfoot"]);function h(e){const o=e.getAttribute("role");if(!o)return!1;const t=o.split(/\s+/).filter(Boolean);return t.includes("presentation")||t.includes("none")}function d(e){return(e.getAttribute("role")??"").trim()!==""}function w(e,o){if(!b.has(o)||d(e))return!1;for(let t=e.parentElement;t;t=t.parentElement){const a=t.tagName.toLowerCase();if(a!=="table"&&!m.has(a))return!1;if(h(t))return!0;if(a==="table"||d(t))return!1}return!1}function l(e,o){const t=e.getAttribute("role");return t?t.split(/\s+/).filter(Boolean).includes(o):!1}function k(e){return e.tagName.toLowerCase()==="table"||l(e,"table")||l(e,"grid")||l(e,"treegrid")}function y(e){return e.tagName.toLowerCase()==="tr"||l(e,"row")}function v(e){let o=null;for(let a=e.parentElement;a;a=a.parentElement)if(k(a)){o=a;break}return o?o.ownerDocument.createTreeWalker(o,NodeFilter.SHOW_ELEMENT,{acceptNode:a=>y(a)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}).nextNode()===e:!1}function p(e){const o=[];let t=!1;const a=e.getAttribute("role");if(a)for(const i of a.split(/\s+/).filter(Boolean))if((i==="presentation"||i==="none")&&(t=!0),i==="heading"){let r=2;const s=parseInt(e.getAttribute("aria-level")??"",10);Number.isFinite(s)&&s>=1&&(r=Math.min(s,6)),o.push(u[r-1])}else c[i]&&o.push(c[i]);const n=e.getAttribute("epub:type");if(n)for(const i of n.split(/\s+/).filter(Boolean)){const r=f[i];r&&o.push(r)}return{attrRoles:o,presentational:t}}function x(e){const{attrRoles:o,presentational:t}=p(e);return o.length>0||t}function E(e){const o=[],t=r=>{o.includes(r)||o.push(r)},{attrRoles:a,presentational:n}=p(e),i=e.tagName.toLowerCase();if(n)return["presentation"];if(w(e,i))return["presentation"];if(i==="body")t("body");else if(i==="th")switch(e.getAttribute("scope")){case"col":t("columnheader");break;case"row":t("rowheader");break;default:{const r=e.parentElement;r&&v(r)?t("columnheader"):e.previousElementSibling===null?t("rowheader"):t("cell")}}else{const r=g[i];r&&t(r)}for(const r of a)t(r);return o}export{E as extractNodeRoles,x as hasExplicitRole};
@@ -0,0 +1 @@
1
+ import{getCssSelector as f}from"css-selector-generator";import{encodeCssSelectorFragment as l}from"./textrefFragment.js";function c(t,n){return t.querySelectorAll(`#${CSS.escape(n)}`).length===1}function m(t){const n=t.getAttribute("id");if(n&&c(t.ownerDocument,n))return`#${CSS.escape(n)}`;const r=t.parentElement,e=t.tagName.toLowerCase();if(!r)return e;const i=Array.from(r.children);for(const s of t.classList){const u=`.${CSS.escape(s)}`;if(i.filter(o=>o.matches(u)).length===1)return u}return i.filter(s=>s.tagName===t.tagName).length===1?e:`${e}:nth-child(${i.indexOf(t)+1})`}function a(t,n){const r=[];let e=t;for(;e&&e!==n;){const i=m(e);if(r.unshift(i),i.startsWith("#"))return r;e=e.parentElement}return e===n?r:void 0}function S(t){if(!t)return null;const n=t.getAttribute("id");if(n&&c(t.ownerDocument,n))return`#${CSS.escape(n)}`;const r=t.ownerDocument.documentElement,e=a(t,r)??[];return e.length>0&&e[0].startsWith("#")?e.join(" > "):[r.tagName.toLowerCase(),...e].join(" > ")}function p(t,n,r){const e=t.getAttribute("id");if(e&&(!n||c(t.ownerDocument,e)))return`#${CSS.escape(e)}`;if(!n)return f(t,{selectors:["id","class","tag","nthchild"]})??void 0;if(t===n)return r??void 0;const i=a(t,n);if(!(!i||i.length===0))return i[0].startsWith("#")?i.join(" > "):r?`${r} > ${i.join(" > ")}`:i.join(" > ")}function h(t,n){if(!t)return;const r=n.getAttribute("id");return!!r&&t===`#${CSS.escape(r)}`?`#${encodeURIComponent(r)}`:l(t)}export{S as rootAnchorSelector,p as selectorForElement,h as textrefForSelector};
package/dist/text.js ADDED
@@ -0,0 +1 @@
1
+ import{GuidedNavigationText as l}from"@readium/shared";function f(e){return e.plain===""&&e.ssml===""&&e.language===""}function c(e){if(!(!e||e.plain===""&&e.ssml===""))return new l({plain:e.plain!==""?e.plain:void 0,ssml:e.ssml!==""?e.ssml:void 0,language:e.language!==""?e.language:void 0})}function g(e,a){if(e.lang!==a.lang||e.tag!==a.tag)return!1;const n=Object.entries(e.attrs??{}),i=Object.entries(a.attrs??{});return n.length!==i.length?!1:n.every(([s,t])=>a.attrs?.[s]===t)}const r=/[\u00A0\u2007\u202F]/;function u(e){return r.test(e)}function p(e,a){let n="",i=!1,s=!1;for(const t of e)if(u(t))n+=t,i=!1,s=!0;else if(/\s/.test(t)){if(a&&!s||i)continue;n+=" ",i=!0}else t!=="​"&&t!=="­"&&(n+=t,i=!1,s=!0);return n}export{g as ctxEqual,c as finalizeText,u as isNoBreakSpace,p as normalizeWhitespace,f as textIsEmpty};
@@ -0,0 +1 @@
1
+ import{generateFragmentFromRange as r,GenerateFragmentStatus as n}from"@readium/helpers";function o(e){const t=r(e);return t.status===n.SUCCESS?t.fragment:void 0}export{o as textFragmentDirectiveFor};
@@ -0,0 +1 @@
1
+ const f="#css(";function p(e){return`${f}${encodeURIComponent(e)})`}function S(e){if(!(!e||!e.startsWith(f)||!e.endsWith(")")))return decodeURIComponent(e.slice(f.length,-1))}const u="#domrange(",l=")";function I(e){return`${u}${encodeURIComponent(JSON.stringify(e))}${l}`}function R(e){if(!(!e||!e.startsWith(u)||!e.endsWith(l)))try{const t=JSON.parse(decodeURIComponent(e.slice(u.length,-l.length)));return!t?.start?.cssSelector||typeof t.start.textNodeIndex!="number"?void 0:t}catch{return}}const g=":~:text=";function a(e){return encodeURIComponent(e).replace(/-/g,"%2D")}function v(e){let t="";return e.prefix&&(t+=`${a(e.prefix)}-,`),t+=a(e.textStart),e.textEnd&&(t+=`,${a(e.textEnd)}`),e.suffix&&(t+=`,-${a(e.suffix)}`),`${g}${t}`}function x(e){if(!e)return;const t=e.indexOf(g);if(t===-1)return;const i=e.slice(t+g.length).split("&")[0];if(i)try{let n=i.split(",");const o={textStart:""};return n[0].endsWith("-")&&(o.prefix=decodeURIComponent(n[0].slice(0,-1)),n=n.slice(1)),n.length>0&&n[n.length-1].startsWith("-")&&(o.suffix=decodeURIComponent(n[n.length-1].slice(1)),n=n.slice(0,-1)),n.length===0||n[0]===""?void 0:(o.textStart=decodeURIComponent(n[0]),n.length>1&&(o.textEnd=decodeURIComponent(n[1])),o)}catch{return}}function F(e,t){if(!e.domRange||!t.domRange)return;const i={start:e.domRange.start,end:t.domRange.end??t.domRange.start};return e.domRange.container!==void 0&&(i.container=e.domRange.container),{domRange:i,cssSelector:i.container??i.start.cssSelector}}function h(e){if(e.startsWith("#"))try{return decodeURIComponent(e.slice(1))}catch{return}}function C(e){const t=e?.textref;if(!t)return;const i=t.indexOf(":~:"),n=i===-1?t:t.slice(0,i);let o,d;const s=R(n);if(s)d=s,o=s.container??s.start.cssSelector;else{const m=S(n);m!==void 0?o=m:e?.id&&h(n)===e.id&&(o=`#${CSS.escape(e.id)}`)}const r=x(t);if(o===void 0&&d===void 0&&r===void 0)return;const c={};return o!==void 0&&(c.cssSelector=o),d!==void 0&&(c.domRange=d),r?.textEnd!==void 0?c.fragment=v(r):r&&(c.text={highlight:r.textStart},r.prefix!==void 0&&(c.text.before=r.prefix),r.suffix!==void 0&&(c.text.after=r.suffix)),c}export{F as combineDomRangeTextrefs,S as decodeCssSelectorFragment,R as decodeDomRangeFragment,x as decodeTextFragmentDirective,C as decodeTextref,p as encodeCssSelectorFragment,I as encodeDomRangeFragment,v as encodeTextFragmentDirective};
@@ -0,0 +1,185 @@
1
+ # Guided Navigation Test Fixtures
2
+
3
+ This directory is a language-agnostic conformance test suite for two pipeline
4
+ stages:
5
+
6
+ 1. **HTML parsing** — reading a document or fragment of HTML/XHTML.
7
+ 2. **Guided Navigation (GND) generation** — mapping the parsed HTML
8
+ onto the [Guided Navigation](https://github.com/readium/guided-navigation)
9
+ role vocabulary defined in
10
+ [`roles.md`](https://github.com/readium/guided-navigation/blob/main/roles.md).
11
+
12
+ [`@readium/speech`](https://github.com/readium/speech) extends it with
13
+ expected utterances for each fixture.
14
+
15
+ Fixtures here are **plain files on disk** (HTML + JSON) — not code. Any
16
+ platform (TypeScript, Kotlin, Swift, ...) can consume them with nothing more
17
+ than a JSON parser and a file reader. There is no query language, template
18
+ system, or fixture-specific code to learn.
19
+
20
+ ## Directory layout
21
+
22
+ ```
23
+ fixtures/
24
+ README.md this file
25
+ manifest.json flat index of every fixture, for discovery without a filesystem walk (generated — do not hand-edit)
26
+ ROLES_COVERAGE.md flat list of every role covered and its fixtures (generated — do not hand-edit)
27
+ <fixture-id>/
28
+ meta.json fixture metadata
29
+ input.html the input markup as HTML (a fragment or a full document, see meta.json.inputKind);
30
+ or input.xhtml when the fixture's content is XHTML (all *-epub-type fixtures)
31
+ gnd.json the expected Guided Navigation object(s) produced from the input file:
32
+ one object, or `{ "children": [...] }` for several top-level siblings
33
+ ```
34
+
35
+ `manifest.json` and `ROLES_COVERAGE.md` are both generated from the
36
+ `meta.json` files on disk by `scripts/build-fixtures-manifest.js`
37
+ (`pnpm run generate-fixtures-manifest`) — the filesystem is the source of
38
+ truth, not either of these files. Never hand-edit them; run the script
39
+ instead.
40
+
41
+ [roles.md](https://github.com/readium/guided-navigation/blob/main/roles.md)
42
+ was the seed used to originally populate this suite — it is not something
43
+ this suite continues to track itself against. Its tier/table categorization
44
+ does not appear anywhere in `meta.json`, `manifest.json`, or
45
+ `ROLES_COVERAGE.md` — only `role` does, since that's the actual content type
46
+ being tested (a "footnote", a "list", ...), not a classification scheme.
47
+
48
+ Each fixture directory is fully self-contained and independently loadable.
49
+
50
+ ## Fixture granularity
51
+
52
+ **One fixture = one distinct, scoped behavior.** Concretely:
53
+
54
+ - **One fixture per role, per distinct HTML encoding.** roles.md documents
55
+ up to three ways of expressing a role: a native HTML element, an explicit
56
+ ARIA role (`role="doc-..."` or a plain ARIA role), and an EPUB `epub:type`
57
+ attribute. Every one of these is a separate code path through stage 1
58
+ (HTML parsing), even when two encodings produce an identical GND result —
59
+ so each gets its own fixture, distinguished by its id/description and
60
+ visible directly in its `input.html` (e.g. `list-html-native` vs.
61
+ `list-role-aria` vs. `list-epub-type`). This isn't tracked as a field in
62
+ `meta.json` — it's not information a consumer needs to look up, just a
63
+ reason more than one fixture exists for the same role.
64
+ - **Trivial repetition is bundled into one fixture.** `heading1`...`heading6`
65
+ are the same pathway repeated at six depths, not six distinct behaviors —
66
+ they live together in one `heading-*` fixture. Multiple `<li>` inside one
67
+ `<ul>` is one `list-*` fixture, not one per item.
68
+
69
+ ## `meta.json` schema
70
+
71
+ ```jsonc
72
+ {
73
+ "id": "footnote-epub-type", // must match the directory name
74
+ "description": "Footnote encoded via epub:type, referenced by a noteref",
75
+ "role": "footnote", // the roles.md role name this fixture targets
76
+ "rolesCovered": ["footnote", "noteref"],// every role name this fixture's markup exercises
77
+ "sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
78
+ "inputKind": "document" // "fragment" | "document"
79
+ }
80
+ ```
81
+
82
+ `role` is a roles.md role name for the vast majority of fixtures — one
83
+ covering a concern that cuts across roles rather than targeting one, such
84
+ as language resolution, instead uses a short pseudo-role naming that
85
+ concern (e.g. `"language"`) not found in roles.md. `rolesCovered` still lists the real roles.md role(s) the
86
+ fixture's markup exercises, so that coverage tracking in
87
+ `ROLES_COVERAGE.md` stays accurate either way.
88
+
89
+ ## `gnd.json` and the Guided Navigation schema
90
+
91
+ Every object in `gnd.json` is valid against the
92
+ [Guided Navigation schema](https://readium.org/guided-navigation/schema/document.schema.json):
93
+ `text` is always a text object (`{ "plain": ... }`), `description` a
94
+ description object (`{ "text": { "plain": ... } }`), and every object has
95
+ at least one of `audioref`, `imgref`, `textref`, `videoref`, `text` or
96
+ `children`.
97
+
98
+ `textref` values generated from the markup (`#id`, `#css(...)`) depend on
99
+ each implementation's selector generator, so they aren't compared. They
100
+ only appear in `gnd.json` on `math` objects and where the schema requires
101
+ them, e.g. a `separator`.
102
+
103
+ ## `epub:type` fixtures are full XHTML documents
104
+
105
+ `epub:type` is only meaningful in XHTML with the `epub` namespace declared on
106
+ the document root — it is **not** a plain-HTML attribute, and there is no
107
+ "parse it as a literal attribute name in an HTML5 document" fallback: real
108
+ EPUB reading systems parse content documents as namespace-aware XHTML. Every
109
+ `*-epub-type` fixture therefore has `inputKind: "document"` and its
110
+ `input.xhtml` is a complete document:
111
+
112
+ ```xml
113
+ <?xml version="1.0" encoding="UTF-8"?>
114
+ <!DOCTYPE html>
115
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
116
+ <head><meta charset="utf-8"/><title>Fixture</title></head>
117
+ <body>
118
+ <div epub:type="chapter">...</div>
119
+ </body>
120
+ </html>
121
+ ```
122
+
123
+ By contrast, `role-aria` and `html-native` fixtures stay as bare fragments
124
+ (`inputKind: "fragment"`) since ARIA roles and native HTML elements don't
125
+ require any namespace declaration.
126
+
127
+ ## Navigational-list roles
128
+
129
+ Roles whose roles.md definition is "a list of links to X" or "a collection
130
+ of X" (`landmarks`, `loa`, `loi`, `lot`, `lov`, `pagelist`, `toc`, `index`,
131
+ `bibliography`, `glossary`, `endnotes`, `credits`) are modeled as an actual
132
+ `list`/`listItem` structure, not a flat text blob — because that's what they
133
+ are. A `listItem` that links to a target elsewhere in the work carries a
134
+ `textref` alongside its visible `text`, reusing the same field the
135
+ footnote/endnote fixtures already use for cross-references:
136
+
137
+ ```jsonc
138
+ { "role": ["listItem"], "text": { "plain": "Cover" }, "textref": "cover.xhtml" }
139
+ ```
140
+
141
+ ## `manifest.json`
142
+
143
+ A flat JSON array, one entry per fixture:
144
+
145
+ ```jsonc
146
+ [
147
+ {
148
+ "id": "footnote-epub-type",
149
+ "dir": "footnote-epub-type",
150
+ "role": "footnote",
151
+ "description": "Footnote encoded via epub:type, referenced by a noteref",
152
+ "files": {
153
+ "input": "input.xhtml",
154
+ "gnd": "gnd.json"
155
+ }
156
+ }
157
+ ]
158
+ ```
159
+
160
+ Any test runner, in any language, reads this one file to discover every
161
+ fixture and resolve its file paths — no directory listing required.
162
+
163
+ ## Consuming a fixture (any platform)
164
+
165
+ 1. Read `manifest.json`, iterate its entries.
166
+ 2. For each entry, read `files.input` (`input.html` or `input.xhtml`) and run
167
+ it through your implementation of HTML → GND.
168
+ 3. Compare the result to `gnd.json`, ignoring `textref` values generated
169
+ from the markup (see above).
170
+
171
+ ## Adding a new fixture
172
+
173
+ 1. `mkdir fixtures/<id>` and hand-write `input.html` (or `input.xhtml` for an
174
+ `epub:type` fixture, since `epub:type` requires XHTML — see above) for the
175
+ specific markup being tested.
176
+ 2. Hand-author `gnd.json` — the ground truth implementations must match.
177
+ 3. Write `meta.json`.
178
+ 4. Run `pnpm run generate-fixtures-manifest` to regenerate `manifest.json`
179
+ and `ROLES_COVERAGE.md` from what's now on disk.
180
+
181
+ ## This suite is not finished
182
+
183
+ New roles, new encodings, and new real-world edge cases get added to
184
+ `fixtures/` as they're encountered — this is a living suite, not a fixed
185
+ checklist against any external document.
@@ -0,0 +1,80 @@
1
+ # Fixture Coverage
2
+
3
+ Every role currently covered by a fixture in this directory, generated from
4
+ `fixtures/*/meta.json` by `scripts/build-fixtures-manifest.js` — do not
5
+ hand-edit this file. Run `npm run generate-fixtures-manifest` after adding,
6
+ renaming, or removing a fixture.
7
+
8
+ | Role | Fixtures |
9
+ | --- | --- |
10
+ | `abstract` | `abstract-epub-type`, `abstract-role-aria` |
11
+ | `acknowledgments` | `acknowledgments-epub-type`, `acknowledgments-role-aria` |
12
+ | `afterword` | `afterword-epub-type`, `afterword-role-aria` |
13
+ | `appendix` | `appendix-epub-type`, `appendix-role-aria` |
14
+ | `article` | `article-html-native`, `article-role-aria` |
15
+ | `aside` | `aside-epub-type`, `aside-html-native` |
16
+ | `audio` | `audio-html-native`, `audio-no-description` |
17
+ | `backlink` | `backlink-epub-type`, `backlink-role-aria` |
18
+ | `bibliography` | `bibliography-epub-type`, `bibliography-role-aria` |
19
+ | `biblioref` | `biblioref-epub-type`, `biblioref-role-aria` |
20
+ | `blockquote` | `blockquote-html-native`, `blockquote-role-aria` |
21
+ | `body` | `body-html-native` |
22
+ | `chapter` | `chapter-epub-type`, `chapter-role-aria` |
23
+ | `colophon` | `colophon-epub-type`, `colophon-role-aria` |
24
+ | `complementary` | `complementary-role-aria` |
25
+ | `conclusion` | `conclusion-epub-type`, `conclusion-role-aria` |
26
+ | `cover` | `cover-epub-type`, `cover-role-aria` |
27
+ | `credit` | `credit-epub-type`, `credit-role-aria` |
28
+ | `credits` | `credits-epub-type`, `credits-role-aria` |
29
+ | `dedication` | `dedication-epub-type`, `dedication-role-aria` |
30
+ | `definition` | `definition-epub-type`, `definition-html-native`, `definition-role-aria` |
31
+ | `details` | `details-html-native`, `details-summary-html-native` |
32
+ | `endnotes` | `endnotes-epub-type`, `endnotes-role-aria` |
33
+ | `epigraph` | `epigraph-epub-type`, `epigraph-role-aria` |
34
+ | `epilogue` | `epilogue-epub-type`, `epilogue-role-aria` |
35
+ | `errata` | `errata-epub-type`, `errata-role-aria` |
36
+ | `example` | `example-epub-type`, `example-role-aria` |
37
+ | `figure` | `figure-basic-html-native`, `figure-basic-role-aria`, `figure-caption-element-html-native`, `figure-caption-element-role-aria`, `figure-caption-html-native`, `figure-caption-role-aria`, `figure-credit-nested-in-aria-labelledby-caption`, `figure-credit-nested-in-caption`, `figure-credit-role-aria`, `figure-describedby`, `figure-epub-type`, `figure-no-description` |
38
+ | `footnote` | `footnote-epub-type`, `footnote-role-aria`, `noteref-target-in-endnotes-epub-type`, `noteref-target-in-endnotes-role-aria` |
39
+ | `foreword` | `foreword-epub-type`, `foreword-role-aria` |
40
+ | `glossary` | `glossary-epub-type`, `glossary-role-aria` |
41
+ | `glossref` | `glossref-epub-type`, `glossref-role-aria`, `glossref-role-aria-mid-sentence` |
42
+ | `header` | `header-html-native` |
43
+ | `heading` | `heading-html-native`, `heading-role-aria` |
44
+ | `image` | `image-alt-html-native`, `image-no-description`, `image-role-aria` |
45
+ | `index` | `index-epub-type`, `index-role-aria` |
46
+ | `introduction` | `introduction-epub-type`, `introduction-role-aria` |
47
+ | `landmarks` | `landmarks-epub-type` |
48
+ | `language` | `language-block`, `language-document`, `language-inline-lang-attribute`, `language-inline-nested`, `language-inline-repeated`, `language-inline-two-languages` |
49
+ | `list` | `list-aria-posinset-setsize`, `list-epub-type`, `list-html-native`, `list-item-posinset-override`, `list-item-value-override`, `list-ordered-html-native`, `list-ordered-reversed`, `list-ordered-start`, `list-role-aria` |
50
+ | `loa` | `loa-epub-type` |
51
+ | `loi` | `loi-epub-type` |
52
+ | `lot` | `lot-epub-type` |
53
+ | `lov` | `lov-epub-type` |
54
+ | `main` | `main-html-native`, `main-role-aria` |
55
+ | `math` | `math-html-native`, `math-no-description`, `math-role-aria` |
56
+ | `navigation` | `navigation-html-native`, `navigation-role-aria` |
57
+ | `noteref` | `noteref-role-aria` |
58
+ | `notice` | `notice-epub-type`, `notice-role-aria` |
59
+ | `pagebreak` | `pagebreak-epub-type`, `pagebreak-role-aria` |
60
+ | `pagelist` | `pagelist-epub-type`, `pagelist-role-aria` |
61
+ | `paragraph` | `paragraph-basic` |
62
+ | `part` | `part-epub-type`, `part-role-aria` |
63
+ | `preface` | `preface-epub-type`, `preface-role-aria` |
64
+ | `preformatted` | `preformatted-html-native` |
65
+ | `presentation` | `heading-role-presentation`, `hidden-aria-hidden-html-native`, `hidden-attribute-html-native`, `image-decorative-empty-alt`, `image-decorative-role-presentation`, `image-decorative-whitespace-alt`, `listitem-role-presentation`, `presentation-role-aria`, `table-nested-in-presentation-table`, `table-role-presentation-explicit-cell`, `table-role-presentation-html-native`, `table-role-presentation-role-aria` |
66
+ | `prologue` | `prologue-epub-type`, `prologue-role-aria` |
67
+ | `pullquote` | `pullquote-epub-type`, `pullquote-role-aria` |
68
+ | `qna` | `qna-epub-type`, `qna-role-aria` |
69
+ | `region` | `region-role-aria` |
70
+ | `section` | `section-html-native` |
71
+ | `separator` | `separator-html-native`, `separator-role-aria`, `separator-with-glyphs` |
72
+ | `subtitle` | `subtitle-epub-type`, `subtitle-role-aria` |
73
+ | `summary` | `summary-html-native` |
74
+ | `table` | `table-caption`, `table-caption-element-html-native`, `table-caption-role-aria`, `table-colspan-html-native`, `table-colspan-role-aria`, `table-epub-type`, `table-html-native`, `table-in-role-none-wrapper`, `table-nested-html-native`, `table-nested-role-aria`, `table-no-headers`, `table-role-aria`, `table-rowgroup-role-aria`, `table-rowspan-html-native`, `table-rowspan-role-aria`, `table-sectioning`, `table-th-no-scope` |
75
+ | `term` | `term-epub-type`, `term-html-native`, `term-role-aria` |
76
+ | `tip` | `tip-epub-type`, `tip-role-aria` |
77
+ | `toc` | `toc-epub-type`, `toc-role-aria` |
78
+ | `video` | `video-html-native`, `video-no-description` |
79
+
80
+ 178 fixtures across 69 roles.
@@ -0,0 +1,15 @@
1
+ {
2
+ "role": [
3
+ "body"
4
+ ],
5
+ "children": [
6
+ {
7
+ "text": {
8
+ "plain": "This work examines the maintenance of coastal lighthouses in the 19th century."
9
+ },
10
+ "role": [
11
+ "abstract"
12
+ ]
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE html>
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
4
+ <head>
5
+ <meta charset="utf-8"/>
6
+ <title>Fixture</title>
7
+ </head>
8
+ <body>
9
+ <div epub:type="abstract">This work examines the maintenance of coastal lighthouses in the 19th century.</div>
10
+ </body>
11
+ </html>
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "abstract-epub-type",
3
+ "description": "abstract role via epub:type=\"abstract\"",
4
+ "role": "abstract",
5
+ "rolesCovered": [
6
+ "abstract"
7
+ ],
8
+ "sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
9
+ "inputKind": "document"
10
+ }