@readium/guided-navigation 1.3.0 → 1.4.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 (306) hide show
  1. package/README.md +6 -6
  2. package/dist/a11y.js +1 -1
  3. package/dist/converter.js +1 -1
  4. package/dist/elementHandlers.js +1 -1
  5. package/dist/emptyPairs.js +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/object.js +1 -1
  8. package/dist/textrefFragment.js +1 -1
  9. package/fixtures/README.md +4 -4
  10. package/fixtures/ROLES_COVERAGE.md +3 -3
  11. package/fixtures/abbreviation-acronym-html-native/gnd.json +3 -5
  12. package/fixtures/abbreviation-before-formatting/gnd.json +3 -5
  13. package/fixtures/abbreviation-before-image/gnd.json +10 -14
  14. package/fixtures/abbreviation-html-native/gnd.json +3 -5
  15. package/fixtures/abbreviation-language/gnd.json +3 -5
  16. package/fixtures/abbreviation-line-break/gnd.json +3 -5
  17. package/fixtures/abbreviation-nested/gnd.json +3 -5
  18. package/fixtures/abbreviation-nested-emphasis/gnd.json +3 -5
  19. package/fixtures/abbreviation-nested-term/gnd.json +4 -8
  20. package/fixtures/abbreviation-nested-term-punctuation/gnd.json +4 -8
  21. package/fixtures/abbreviation-no-title/gnd.json +1 -3
  22. package/fixtures/abbreviation-period-mid-sentence/gnd.json +3 -5
  23. package/fixtures/abbreviation-period-sentence-end/gnd.json +3 -5
  24. package/fixtures/abbreviation-spanning-terms/gnd.json +3 -9
  25. package/fixtures/abbreviation-with-image/gnd.json +10 -14
  26. package/fixtures/abbreviation-with-svg-and-math/gnd.json +15 -21
  27. package/fixtures/abstract-epub-type/gnd.json +3 -7
  28. package/fixtures/abstract-role-aria/gnd.json +1 -3
  29. package/fixtures/accessible-name-labelledby-aria-hidden/gnd.json +2 -7
  30. package/fixtures/accessible-name-labelledby-hidden-attribute/gnd.json +2 -7
  31. package/fixtures/acknowledgments-epub-type/gnd.json +3 -7
  32. package/fixtures/acknowledgments-role-aria/gnd.json +1 -3
  33. package/fixtures/afterword-epub-type/gnd.json +3 -7
  34. package/fixtures/afterword-role-aria/gnd.json +1 -3
  35. package/fixtures/appendix-epub-type/gnd.json +3 -8
  36. package/fixtures/appendix-role-aria/gnd.json +1 -3
  37. package/fixtures/article-html-native/gnd.json +1 -3
  38. package/fixtures/article-role-aria/gnd.json +2 -4
  39. package/fixtures/aside-epub-type/gnd.json +3 -7
  40. package/fixtures/aside-html-native/gnd.json +1 -3
  41. package/fixtures/audio-html-native/gnd.json +3 -5
  42. package/fixtures/audio-no-description/gnd.json +2 -4
  43. package/fixtures/backlink-epub-type/gnd.json +3 -8
  44. package/fixtures/backlink-role-aria/gnd.json +2 -5
  45. package/fixtures/bibliography-epub-type/gnd.json +7 -18
  46. package/fixtures/bibliography-role-aria/gnd.json +4 -12
  47. package/fixtures/biblioref-epub-type/gnd.json +3 -8
  48. package/fixtures/biblioref-role-aria/gnd.json +2 -5
  49. package/fixtures/biblioref-target-descendant-ids/gnd.json +31 -49
  50. package/fixtures/biblioref-target-in-bibliography-role-aria/gnd.json +16 -29
  51. package/fixtures/biblioref-target-mixed-content/gnd.json +27 -36
  52. package/fixtures/blockquote-html-native/gnd.json +1 -3
  53. package/fixtures/blockquote-role-aria/gnd.json +2 -4
  54. package/fixtures/body-html-native/gnd.json +1 -3
  55. package/fixtures/chapter-epub-type/gnd.json +4 -11
  56. package/fixtures/chapter-role-aria/gnd.json +2 -7
  57. package/fixtures/colophon-epub-type/gnd.json +3 -7
  58. package/fixtures/colophon-role-aria/gnd.json +1 -3
  59. package/fixtures/complementary-role-aria/gnd.json +1 -3
  60. package/fixtures/conclusion-epub-type/gnd.json +3 -7
  61. package/fixtures/conclusion-role-aria/gnd.json +1 -3
  62. package/fixtures/cover-epub-type/gnd.json +5 -12
  63. package/fixtures/cover-role-aria/gnd.json +3 -6
  64. package/fixtures/credit-epub-type/gnd.json +4 -10
  65. package/fixtures/credit-role-aria/gnd.json +1 -3
  66. package/fixtures/credits-epub-type/gnd.json +9 -23
  67. package/fixtures/credits-role-aria/gnd.json +4 -14
  68. package/fixtures/dedication-epub-type/gnd.json +3 -7
  69. package/fixtures/dedication-role-aria/gnd.json +1 -3
  70. package/fixtures/definition-epub-type/gnd.json +4 -10
  71. package/fixtures/definition-html-native/gnd.json +1 -3
  72. package/fixtures/definition-role-aria/gnd.json +1 -3
  73. package/fixtures/description-roleless-lone-child/gnd.json +5 -9
  74. package/fixtures/description-roleless-wrapper/gnd.json +8 -12
  75. package/fixtures/details-html-native/gnd.json +1 -3
  76. package/fixtures/details-summary-html-native/gnd.json +2 -6
  77. package/fixtures/endnotes-epub-type/gnd.json +9 -26
  78. package/fixtures/endnotes-role-aria/gnd.json +4 -14
  79. package/fixtures/epigraph-epub-type/gnd.json +3 -7
  80. package/fixtures/epigraph-role-aria/gnd.json +1 -3
  81. package/fixtures/epilogue-epub-type/gnd.json +3 -7
  82. package/fixtures/epilogue-role-aria/gnd.json +1 -3
  83. package/fixtures/errata-epub-type/gnd.json +3 -7
  84. package/fixtures/errata-role-aria/gnd.json +1 -3
  85. package/fixtures/example-epub-type/gnd.json +5 -14
  86. package/fixtures/example-role-aria/gnd.json +1 -3
  87. package/fixtures/figure-aria-label-caption/gnd.json +19 -0
  88. package/fixtures/figure-aria-label-caption/input.html +1 -0
  89. package/fixtures/figure-aria-label-caption/meta.json +12 -0
  90. package/fixtures/figure-basic-html-native/gnd.json +4 -8
  91. package/fixtures/figure-basic-role-aria/gnd.json +4 -8
  92. package/fixtures/figure-caption-block-content/gnd.json +33 -0
  93. package/fixtures/figure-caption-block-content/input.html +7 -0
  94. package/fixtures/figure-caption-block-content/meta.json +14 -0
  95. package/fixtures/figure-caption-element-html-native/gnd.json +14 -8
  96. package/fixtures/figure-caption-element-html-native/meta.json +1 -1
  97. package/fixtures/figure-caption-element-role-aria/gnd.json +14 -8
  98. package/fixtures/figure-caption-element-role-aria/meta.json +1 -1
  99. package/fixtures/figure-caption-html-native/gnd.json +3 -5
  100. package/fixtures/figure-caption-role-aria/gnd.json +3 -5
  101. package/fixtures/figure-credit-nested-in-aria-labelledby-caption/gnd.json +13 -21
  102. package/fixtures/figure-credit-nested-in-caption/gnd.json +13 -21
  103. package/fixtures/figure-credit-nested-in-caption/meta.json +1 -1
  104. package/fixtures/figure-credit-role-aria/gnd.json +12 -18
  105. package/fixtures/figure-credit-role-aria/meta.json +1 -1
  106. package/fixtures/figure-describedby/gnd.json +4 -8
  107. package/fixtures/figure-epub-type/gnd.json +5 -11
  108. package/fixtures/figure-no-description/gnd.json +3 -7
  109. package/fixtures/footnote-epub-type/gnd.json +5 -14
  110. package/fixtures/footnote-role-aria/gnd.json +17 -31
  111. package/fixtures/foreword-epub-type/gnd.json +3 -7
  112. package/fixtures/foreword-role-aria/gnd.json +1 -3
  113. package/fixtures/glossary-epub-type/gnd.json +10 -22
  114. package/fixtures/glossary-role-aria/gnd.json +5 -15
  115. package/fixtures/glossref-epub-type/gnd.json +3 -8
  116. package/fixtures/glossref-role-aria/gnd.json +2 -5
  117. package/fixtures/glossref-role-aria-mid-sentence/gnd.json +5 -13
  118. package/fixtures/glossref-sole-content/gnd.json +11 -26
  119. package/fixtures/glossref-target-in-glossary-role-aria/gnd.json +17 -32
  120. package/fixtures/glossref-target-percent-encoded/gnd.json +17 -32
  121. package/fixtures/glossref-target-percent-encoded/meta.json +1 -1
  122. package/fixtures/header-html-native/gnd.json +1 -3
  123. package/fixtures/heading-html-native/gnd.json +6 -18
  124. package/fixtures/heading-role-aria/gnd.json +6 -18
  125. package/fixtures/heading-role-presentation/gnd.json +6 -12
  126. package/fixtures/hidden-aria-hidden-html-native/gnd.json +2 -6
  127. package/fixtures/hidden-attribute-html-native/gnd.json +2 -6
  128. package/fixtures/image-alt-html-native/gnd.json +3 -5
  129. package/fixtures/image-decorative-empty-alt/gnd.json +2 -6
  130. package/fixtures/image-decorative-role-presentation/gnd.json +2 -6
  131. package/fixtures/image-decorative-whitespace-alt/gnd.json +4 -8
  132. package/fixtures/image-no-description/gnd.json +2 -4
  133. package/fixtures/image-role-aria/gnd.json +3 -5
  134. package/fixtures/index-epub-type/gnd.json +11 -32
  135. package/fixtures/index-role-aria/gnd.json +10 -28
  136. package/fixtures/introduction-epub-type/gnd.json +3 -7
  137. package/fixtures/introduction-role-aria/gnd.json +1 -3
  138. package/fixtures/landmarks-epub-type/gnd.json +15 -43
  139. package/fixtures/language-alt-inherited/gnd.json +8 -12
  140. package/fixtures/language-alt-own-lang/gnd.json +8 -12
  141. package/fixtures/language-block/gnd.json +5 -11
  142. package/fixtures/language-block-empty-lang/gnd.json +1 -3
  143. package/fixtures/language-describedby-shared/gnd.json +19 -27
  144. package/fixtures/language-document/gnd.json +3 -7
  145. package/fixtures/language-empty-lang-stops-inheritance/gnd.json +6 -10
  146. package/fixtures/language-figcaption/gnd.json +13 -16
  147. package/fixtures/language-figcaption/meta.json +1 -1
  148. package/fixtures/language-figcaption-credit/gnd.json +17 -25
  149. package/fixtures/language-figcaption-credit/meta.json +1 -1
  150. package/fixtures/language-figcaption-switches/gnd.json +13 -15
  151. package/fixtures/language-figcaption-switches/meta.json +1 -1
  152. package/fixtures/language-figcaption-switches-throughout/gnd.json +13 -16
  153. package/fixtures/language-figcaption-switches-throughout/meta.json +1 -1
  154. package/fixtures/language-inline-case-insensitive/gnd.json +3 -5
  155. package/fixtures/language-inline-case-insensitive-ssml/gnd.json +3 -5
  156. package/fixtures/language-inline-empty-lang/gnd.json +3 -5
  157. package/fixtures/language-inline-empty-lang-formatted/gnd.json +1 -3
  158. package/fixtures/language-inline-empty-lang-only/gnd.json +1 -3
  159. package/fixtures/language-inline-empty-lang-undeclared/gnd.json +3 -5
  160. package/fixtures/language-inline-lang-attribute/gnd.json +3 -5
  161. package/fixtures/language-inline-nested/gnd.json +3 -5
  162. package/fixtures/language-inline-repeated/gnd.json +3 -5
  163. package/fixtures/language-inline-two-languages/gnd.json +3 -5
  164. package/fixtures/language-labelledby-target/gnd.json +8 -12
  165. package/fixtures/language-labelledby-target-aria-label/gnd.json +12 -16
  166. package/fixtures/language-labelledby-target-switches/gnd.json +6 -10
  167. package/fixtures/language-labelledby-targets-case/gnd.json +11 -17
  168. package/fixtures/language-labelledby-targets-differ/gnd.json +9 -15
  169. package/fixtures/language-link-switches/gnd.json +10 -13
  170. package/fixtures/language-pagebreak-label/gnd.json +10 -14
  171. package/fixtures/language-undeclared-description/gnd.json +4 -8
  172. package/fixtures/language-xml-lang-empty-html-inherits/gnd.json +8 -12
  173. package/fixtures/language-xml-lang-empty-html-lang-applies/gnd.json +8 -12
  174. package/fixtures/language-xml-lang-empty-xhtml/gnd.json +6 -10
  175. package/fixtures/language-xml-lang-over-lang/gnd.json +8 -12
  176. package/fixtures/link-containing-image/gnd.json +12 -17
  177. package/fixtures/link-containing-pagebreak/gnd.json +12 -17
  178. package/fixtures/link-content-conversion/gnd.json +14 -20
  179. package/fixtures/link-content-identity/gnd.json +7 -8
  180. package/fixtures/link-content-words/gnd.json +9 -14
  181. package/fixtures/list-aria-posinset-setsize/gnd.json +3 -7
  182. package/fixtures/list-epub-type/gnd.json +6 -14
  183. package/fixtures/list-html-native/gnd.json +4 -12
  184. package/fixtures/list-item-posinset-override/gnd.json +7 -15
  185. package/fixtures/list-item-value-override/gnd.json +7 -15
  186. package/fixtures/list-ordered-html-native/gnd.json +7 -15
  187. package/fixtures/list-ordered-reversed/gnd.json +7 -15
  188. package/fixtures/list-ordered-start/gnd.json +7 -15
  189. package/fixtures/list-role-aria/gnd.json +4 -12
  190. package/fixtures/listitem-role-presentation/gnd.json +5 -11
  191. package/fixtures/loa-epub-type/gnd.json +11 -32
  192. package/fixtures/loi-epub-type/gnd.json +11 -32
  193. package/fixtures/lot-epub-type/gnd.json +11 -32
  194. package/fixtures/lov-epub-type/gnd.json +11 -32
  195. package/fixtures/main-html-native/gnd.json +1 -3
  196. package/fixtures/main-role-aria/gnd.json +1 -3
  197. package/fixtures/manifest.json +51 -11
  198. package/fixtures/math-html-native/gnd.json +5 -7
  199. package/fixtures/math-inline/gnd.json +10 -14
  200. package/fixtures/math-no-description/gnd.json +3 -5
  201. package/fixtures/math-role-aria/gnd.json +5 -7
  202. package/fixtures/navigation-html-native/gnd.json +1 -3
  203. package/fixtures/navigation-role-aria/gnd.json +1 -3
  204. package/fixtures/nested-blockquote/gnd.json +3 -9
  205. package/fixtures/nested-section/gnd.json +3 -9
  206. package/fixtures/noteref-after-closing-straight-quote/gnd.json +13 -20
  207. package/fixtures/noteref-after-closing-straight-quote-split/gnd.json +12 -17
  208. package/fixtures/noteref-enclosed-across-formatting/gnd.json +13 -20
  209. package/fixtures/noteref-enclosed-adjacent-pairs/gnd.json +38 -62
  210. package/fixtures/noteref-enclosed-adjacent-text/gnd.json +16 -23
  211. package/fixtures/noteref-enclosed-before-formatting/gnd.json +16 -23
  212. package/fixtures/noteref-enclosed-guillemets-french/gnd.json +42 -63
  213. package/fixtures/noteref-enclosed-quotes-chinese/gnd.json +15 -25
  214. package/fixtures/noteref-enclosed-quotes-german/gnd.json +49 -75
  215. package/fixtures/noteref-enclosed-quotes-swedish/gnd.json +28 -42
  216. package/fixtures/noteref-enclosed-straight-quotes/gnd.json +13 -20
  217. package/fixtures/noteref-in-lone-block/gnd.json +12 -17
  218. package/fixtures/noteref-role-aria/gnd.json +1 -3
  219. package/fixtures/noteref-target-in-endnotes-epub-type/gnd.json +10 -29
  220. package/fixtures/noteref-target-in-endnotes-role-aria/gnd.json +9 -26
  221. package/fixtures/noteref-target-malformed-escape/gnd.json +13 -20
  222. package/fixtures/noteref-target-percent-encoded/gnd.json +13 -20
  223. package/fixtures/notice-epub-type/gnd.json +3 -7
  224. package/fixtures/notice-role-aria/gnd.json +1 -3
  225. package/fixtures/pagebreak-epub-type/gnd.json +6 -14
  226. package/fixtures/pagebreak-role-aria/gnd.json +5 -11
  227. package/fixtures/pagelist-epub-type/gnd.json +15 -43
  228. package/fixtures/pagelist-role-aria/gnd.json +14 -40
  229. package/fixtures/paragraph-basic/gnd.json +1 -3
  230. package/fixtures/part-epub-type/gnd.json +4 -11
  231. package/fixtures/part-role-aria/gnd.json +2 -7
  232. package/fixtures/preface-epub-type/gnd.json +3 -7
  233. package/fixtures/preface-role-aria/gnd.json +1 -3
  234. package/fixtures/preformatted-html-native/gnd.json +1 -3
  235. package/fixtures/presentation-role-aria/gnd.json +1 -3
  236. package/fixtures/prologue-epub-type/gnd.json +3 -7
  237. package/fixtures/prologue-role-aria/gnd.json +1 -3
  238. package/fixtures/pullquote-epub-type/gnd.json +3 -8
  239. package/fixtures/pullquote-role-aria/gnd.json +1 -3
  240. package/fixtures/qna-epub-type/gnd.json +3 -8
  241. package/fixtures/qna-role-aria/gnd.json +1 -3
  242. package/fixtures/redundant-role-body-chapter/gnd.json +3 -10
  243. package/fixtures/redundant-role-nested-chapter/gnd.json +4 -13
  244. package/fixtures/region-role-aria/gnd.json +1 -3
  245. package/fixtures/section-html-native/gnd.json +1 -3
  246. package/fixtures/separator-html-native/gnd.json +3 -9
  247. package/fixtures/separator-role-aria/gnd.json +3 -9
  248. package/fixtures/separator-with-glyphs/gnd.json +3 -9
  249. package/fixtures/subtitle-epub-type/gnd.json +3 -7
  250. package/fixtures/subtitle-role-aria/gnd.json +1 -3
  251. package/fixtures/summary-html-native/gnd.json +1 -3
  252. package/fixtures/table-aria-label-caption/gnd.json +27 -0
  253. package/fixtures/table-aria-label-caption/input.html +1 -0
  254. package/fixtures/table-aria-label-caption/meta.json +13 -0
  255. package/fixtures/table-caption/gnd.json +22 -42
  256. package/fixtures/table-caption/meta.json +1 -1
  257. package/fixtures/table-caption-aria-labelledby/gnd.json +28 -0
  258. package/fixtures/table-caption-aria-labelledby/input.html +1 -0
  259. package/fixtures/table-caption-aria-labelledby/meta.json +13 -0
  260. package/fixtures/table-caption-element-html-native/gnd.json +13 -22
  261. package/fixtures/table-caption-element-html-native/meta.json +1 -1
  262. package/fixtures/table-caption-role-aria/gnd.json +10 -15
  263. package/fixtures/table-cell-abbreviation/gnd.json +8 -16
  264. package/fixtures/table-cell-link/gnd.json +8 -19
  265. package/fixtures/table-cell-noteref/gnd.json +15 -25
  266. package/fixtures/table-colspan-html-native/gnd.json +9 -21
  267. package/fixtures/table-colspan-role-aria/gnd.json +9 -21
  268. package/fixtures/table-epub-type/gnd.json +7 -17
  269. package/fixtures/table-html-native/gnd.json +10 -30
  270. package/fixtures/table-in-role-none-wrapper/gnd.json +6 -18
  271. package/fixtures/table-nested-html-native/gnd.json +7 -19
  272. package/fixtures/table-nested-in-presentation-table/gnd.json +8 -24
  273. package/fixtures/table-nested-role-aria/gnd.json +7 -19
  274. package/fixtures/table-no-headers/gnd.json +11 -25
  275. package/fixtures/table-role-aria/gnd.json +10 -30
  276. package/fixtures/table-role-presentation-explicit-cell/gnd.json +4 -12
  277. package/fixtures/table-role-presentation-html-native/gnd.json +7 -17
  278. package/fixtures/table-role-presentation-role-aria/gnd.json +7 -17
  279. package/fixtures/table-rowgroup-role-aria/gnd.json +4 -10
  280. package/fixtures/table-rowspan-html-native/gnd.json +9 -21
  281. package/fixtures/table-rowspan-role-aria/gnd.json +9 -21
  282. package/fixtures/table-sectioning/gnd.json +10 -24
  283. package/fixtures/table-th-no-scope/gnd.json +11 -25
  284. package/fixtures/term-epub-type/gnd.json +4 -10
  285. package/fixtures/term-html-native/gnd.json +1 -3
  286. package/fixtures/term-role-aria/gnd.json +1 -3
  287. package/fixtures/term-span-in-dt/gnd.json +3 -9
  288. package/fixtures/tip-epub-type/gnd.json +3 -8
  289. package/fixtures/tip-role-aria/gnd.json +1 -3
  290. package/fixtures/toc-epub-type/gnd.json +15 -43
  291. package/fixtures/toc-role-aria/gnd.json +14 -40
  292. package/fixtures/video-html-native/gnd.json +3 -5
  293. package/fixtures/video-no-description/gnd.json +2 -4
  294. package/package.json +6 -2
  295. package/src/a11y.ts +3 -12
  296. package/src/converter.ts +10 -45
  297. package/src/elementHandlers.ts +3 -12
  298. package/src/emptyPairs.ts +35 -15
  299. package/src/index.ts +2 -1
  300. package/src/object.ts +4 -10
  301. package/src/textrefFragment.ts +7 -16
  302. package/types/src/a11y.d.ts +0 -2
  303. package/types/src/converter.d.ts +0 -2
  304. package/types/src/emptyPairs.d.ts +3 -0
  305. package/types/src/index.d.ts +2 -1
  306. package/types/src/textrefFragment.d.ts +0 -4
package/README.md CHANGED
@@ -92,7 +92,7 @@ The directive is generated by Google's [text-fragments-polyfill](https://github.
92
92
 
93
93
  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.
94
94
 
95
- Use `decodeTextref({ id, textref })` to read a `textref` back. It returns:
95
+ Use `decodeTextref({ textref })` to read a `textref` back. It returns:
96
96
 
97
97
  ```typescript
98
98
  { href?, cssSelector?, domRange?, text?, fragment? }
@@ -103,7 +103,7 @@ Use `decodeTextref({ id, textref })` to read a `textref` back. It returns:
103
103
  - Exact match (one quote) → `text: { highlight, before?, after? }`
104
104
  - Range (the `textStart`/`textEnd` case above) → `fragment` (the raw `:~:text=...` string)
105
105
 
106
- It returns `undefined` if the `textref` is navigational rather than a reference to the node's own content, e.g. a link's `href`. `#css(...)` and `#domrange(...)` are always the node's own. A `#id` is the node's own only when it matches the node's `id`. `combineDomRangeTextrefs(first, last)` joins two decoded `domRange` references into one spanning both, as long as they're in the same resource.
106
+ A `textref` always references the node's own content, so `#id`, `#css(...)` and `#domrange(...)` all locate it. It returns `undefined` when there's nothing to locate, e.g. a `textref` naming a whole resource. `combineDomRangeTextrefs(first, last)` joins two decoded `domRange` references into one spanning both, as long as they're in the same resource.
107
107
 
108
108
  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`).
109
109
 
@@ -112,12 +112,12 @@ The lower-level pieces are exported too: `encodeCssSelectorFragment(selector)`/`
112
112
  - **`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"]`.
113
113
  - **`text`** carries `ssml` when the text needs it (inline formatting, a language shift, an abbreviation, 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`. `plain` alongside it is the text as written, link words included, with footnotes, pagebreaks and images left out. It doesn't say where embedded objects sit: use `ssml` for that.
114
114
  - **`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`.
115
- - **`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.
116
- - **`description`** holds a node's accessible name (`aria-label`, `alt`, `<figcaption>`...) as `description.text` when it differs from its visible text.
115
+ - **`imgref`/`audioref`/`videoref`** are a media element's `src`. **`textref`** locates the node's own content (see [Text references](#text-references-textrefs)). A link's destination isn't kept: links, `backlink`, `biblioref` and `glossref` carry their text, and `biblioref`/`glossref` embed their target as `children`.
116
+ - **`description`** holds a node's accessible name (`aria-label`, `aria-labelledby`, `alt`...) as `description.text` when it differs from its visible text. A `<figcaption>` or table `<caption>` isn't folded into it: it stays a `caption` object, its blocks keeping their own text.
117
117
  - Empty/presentational/`aria-hidden`/`hidden` content and role-less wrapper `<div>`s are dropped from the tree, not kept as empty nodes.
118
- - 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: "..." }] }`.
118
+ - 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, or text substituted from `aria-label`, is never hoisted: `<p><a href="..." aria-label="Go">Cover</a></p>` → `{ role: ["paragraph"], children: [{ text: { plain: "Go" } }] }`.
119
119
 
120
- 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.
120
+ 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, its box when no `textref` locates it. Both only know about objects returned by `parseMarkup`/`makeGnd`, not deserialized ones.
121
121
 
122
122
  ## Footnotes and pagebreaks
123
123
 
package/dist/a11y.js CHANGED
@@ -1 +1 @@
1
- import{normalizeWhitespace as o}from"./text.js";import{hasExplicitRole as w}from"./roles.js";import{nodeLanguage as d,sharedLanguage as g}from"./language.js";function y(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function p(t,s,a){let u="";const l=(r,n)=>{if(r.nodeType===3){const e=r.nodeValue??"";u+=e,e.trim()&&a.add(d(r.parentElement));return}if(!(s&&r.nodeType===1&&!n&&w(r)))for(let e=r.firstChild;e;e=e.nextSibling)l(e,!1)};return l(t,!0),u}function x(t,s){const a=new Set;return{text:o(p(t,s,a),!0).trim(),language:g(a)}}function A(t){return x(t,!1)}function z(t){return x(t,!0)}function B(t){if(y(t))return[null,!1,""];const s=(t.getAttribute("aria-labelledby")??"").trim();if(s){const r=[...new Set(s.split(/\s+/).filter(Boolean))],n=t.ownerDocument,e=r.map(i=>n.getElementById(i)).filter(i=>i!==null);if(e.length>0){let i="";const c=new Set;e.forEach((m,h)=>{const b=m.getAttribute("aria-label");b?(i+=b,c.add(d(m))):i+=p(m,!0,c),h<e.length-1&&(i+=" ")});const f=o(i,!0).trim();if(f!=="")return[f,!0,g(c)]}}const a=o(t.getAttribute("aria-label")??"",!0).trim();if(a)return[a,!0,d(t)];const u=(t.getAttribute("aria-describedby")??"").trim();if(u){const n=[...new Set(u.split(/\s+/).filter(Boolean))].map(e=>t.ownerDocument.getElementById(e)).filter(e=>e!==null);if(n.length>0){const e=new Set,i=n.map(f=>p(f,!0,e)).join(" "),c=o(i,!0).trim();if(c!=="")return[c,!0,g(e)]}}const l=t.tagName.toLowerCase();if(l==="img"){const r=o(t.getAttribute("alt")??"",!0).trim();if(r)return[r,!0,d(t)];const n=o(t.getAttribute("title")??"",!0).trim();if(n)return[n,!0,d(t)]}else if(l==="svg"){const r=t.querySelector(":scope > title");if(r){const{text:n,language:e}=A(r);if(n)return[n,!0,e]}}else if(l==="math"){const r=o(t.getAttribute("alttext")??"",!0).trim();if(r)return[r,!0,d(t)]}return[null,!0,""]}const S={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function N(t){return S[t]??["",void 0]}const L=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{N as convertElementToSSMLTag,B as extractNodeAria,A as normalizedNodeText,z as normalizedNodeTextExcludingExplicitRoles,L as skippedElements};
1
+ import{normalizeWhitespace as s}from"./text.js";import{hasExplicitRole as x}from"./roles.js";import{nodeLanguage as u,sharedLanguage as g}from"./language.js";function w(t){return!!(t.getAttribute("aria-hidden")==="true"||t.hasAttribute("hidden"))}function p(t,a,c){let f="";const o=(r,n)=>{if(r.nodeType===3){const e=r.nodeValue??"";f+=e,e.trim()&&c.add(u(r.parentElement));return}if(!(a&&r.nodeType===1&&!n&&x(r)))for(let e=r.firstChild;e;e=e.nextSibling)o(e,!1)};return o(t,!0),f}function y(t){const a=new Set;return{text:s(p(t,!1,a),!0).trim(),language:g(a)}}function v(t){if(w(t))return[null,!1,""];const a=(t.getAttribute("aria-labelledby")??"").trim();if(a){const r=[...new Set(a.split(/\s+/).filter(Boolean))],n=t.ownerDocument,e=r.map(i=>n.getElementById(i)).filter(i=>i!==null);if(e.length>0){let i="";const l=new Set;e.forEach((m,h)=>{const b=m.getAttribute("aria-label");b?(i+=b,l.add(u(m))):i+=p(m,!0,l),h<e.length-1&&(i+=" ")});const d=s(i,!0).trim();if(d!=="")return[d,!0,g(l)]}}const c=s(t.getAttribute("aria-label")??"",!0).trim();if(c)return[c,!0,u(t)];const f=(t.getAttribute("aria-describedby")??"").trim();if(f){const n=[...new Set(f.split(/\s+/).filter(Boolean))].map(e=>t.ownerDocument.getElementById(e)).filter(e=>e!==null);if(n.length>0){const e=new Set,i=n.map(d=>p(d,!0,e)).join(" "),l=s(i,!0).trim();if(l!=="")return[l,!0,g(e)]}}const o=t.tagName.toLowerCase();if(o==="img"){const r=s(t.getAttribute("alt")??"",!0).trim();if(r)return[r,!0,u(t)];const n=s(t.getAttribute("title")??"",!0).trim();if(n)return[n,!0,u(t)]}else if(o==="svg"){const r=t.querySelector(":scope > title");if(r){const{text:n,language:e}=y(r);if(n)return[n,!0,e]}}else if(o==="math"){const r=s(t.getAttribute("alttext")??"",!0).trim();if(r)return[r,!0,u(t)]}return[null,!0,""]}const A={em:["emphasis"],b:["emphasis"],i:["emphasis",{level:"reduced"}],strong:["emphasis",{level:"strong"}],br:["break"]};function B(t){return A[t]??["",void 0]}const N=new Set(["script","style","template","noscript","textarea","select","datalist","iframe","rt","rp","rtc"]);export{B as convertElementToSSMLTag,v as extractNodeAria,y as normalizedNodeText,N as skippedElements};
package/dist/converter.js CHANGED
@@ -1 +1 @@
1
- import{hasExplicitRole as K,extractNodeRoles as F}from"./roles.js";import{skippedElements as y,extractNodeAria as G,normalizedNodeText as Q,normalizedNodeTextExcludingExplicitRoles as V,convertElementToSSMLTag as Z}from"./a11y.js";import{normalizeWhitespace as N,ctxEqual as _}from"./text.js";import{ssmlTextEscape as B,ssmlAttrEscape as I}from"@readium/helpers";import{NavObject as S,isEmptyObj as X,finalizeToGuidedNavigationObject as tt,setDescription as R}from"./object.js";import{sniffMediaType as et,isInlineTag as z,isAncestorOf as it}from"./dom.js";import{nodeLanguage as st,declaredLanguage as D,sameLanguage as j}from"./language.js";import{encodeDomRangeFragment as nt,encodeTextFragmentDirective as rt}from"./textrefFragment.js";import{resolveRefs as ot}from"./href.js";import{rootAnchorSelector as lt,textrefForSelector as $,selectorForElement as M}from"./selectorGenerator.js";import{generateDomRange as at}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as ct}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as ht}from"./options.js";import{IdAllocator as ft}from"./idAllocator.js";import{prescan as dt}from"./prescan.js";import{pagebreak as ut,noteref as pt,reference as gt,link as mt}from"./elementHandlers.js";import{removeDropped as xt,bindsToPrevious as bt,DROPPED as wt}from"./emptyPairs.js";const Et="http://www.w3.org/1998/Math/MathML",O=3,U=1,kt=4,Tt=new Set(["summary","dfn","span"]);function A(f,t){return Tt.has(f)&&t.length>0?!0:!z(f)}class u{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new ft,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.copy=!1,this.root=new S,this.current=this.root,this.foldedCaptions=new Set,this.segments=[],this.textAcc="",this.currentCtx={lang:void 0,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.words=null,this.xmlParsed=t}spawnChild(t,e=1){const i=new u(this.xmlParsed);return i.ids=this.ids,i.suppressed=this.suppressed,i.idAlloc=this.idAlloc,i.noterefDepth=this.noterefDepth+e,i.allowNode=t,i.docRoot=this.docRoot,i.selectorRoot=this.selectorRoot,i.selectorRootAnchor=this.selectorRootAnchor,i.selectorPredicate=this.selectorPredicate,i.domRangeEnabled=this.domRangeEnabled,i.textFragmentEnabled=this.textFragmentEnabled,i.leafTextEnabled=this.leafTextEnabled,i.copy=this.copy,i}prescan(t){dt(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=>$(M(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0||t.text?X(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>ot(e,this.baseHref)),t.map(tt)}descend(t,e){const i=new S;i.el=t,i.noText=this.foldedCaptions.has(t)||(!K(t)||e.includes("caption"))&&this.current.noText,this.current.children.push(i),this.current.hasChildBlock=!0,this.current=i}appendChild(t){t.noText=this.current.noText,this.current.children.push(t)}walk(t){if(t.nodeType===O){u.punctuationOwner(t)||this.text(t);return}if(t.nodeType!==U)return;const e=t,i=this.current,o=this.head(e);if(!o){const s=this.current!==i&&this.current.el===e?u.ownPunctuation(e):[],r=h=>(h.compareDocumentPosition(e)&kt)!==0;for(const h of s)r(h)&&this.text(h);for(let h=e.firstChild;h;h=h.nextSibling)this.walk(h);for(const h of s)r(h)||this.text(h)}this.tail(e,o,i)}head(t){const e=t.tagName.toLowerCase();if(y.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[i,o,s]=G(t);if(!o&&t!==this.allowNode)return!0;const r=F(t);if((e==="img"||e==="svg")&&(r.includes("presentation")||i===null&&t.hasAttribute("alt")&&t.getAttribute("alt").trim()===""))return!0;if(e==="br")return!this.current.noText&&!this.textContext(t).abbr&&(this.closeSegment(),this.segments.push({kind:"break"}),this.words?.push({kind:"break"}),this.flowEndsWithSpace=!0),!0;if(r.includes("pagebreak"))return!ut(this,t,i,s,r);if(e==="a"&&r.includes("noteref")&&t.getAttribute("href"))return pt(this,t,r),!0;if(e==="a"&&(r.includes("glossref")||r.includes("biblioref"))&&t.getAttribute("href"))return gt(this,t,r,i,s),!0;if(e==="a"&&t.getAttribute("href"))return mt(this,t,r,i,s),!0;if(e==="img"){const l={role:r},c=t.getAttribute("src");return c&&(l.imgref=c),i&&R(l,i,s),this.placeholder(t,"image",l),!0}if(e==="audio"||e==="video"){const l={role:r};let c=t.getAttribute("src");if(!c){const d=t.querySelector(":scope > source[src]");d&&(c=d.getAttribute("src"))}return e==="audio"?c&&(l.audioref=c):c&&(l.videoref=c),i&&R(l,i,s),this.placeholder(t,e,l),!0}if(r.includes("image")||r.includes("math")){const l={role:r};if(i&&R(l,i,s),r.includes("math")){if(t.namespaceURI===Et)l.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:st(t)};else{const{text:c,language:d}=Q(t);c&&(l.text={plain:c,ssml:"",language:d})}l.textref=$(M(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,r.includes("math")?"math":"image",l),!0}if(!A(e,r))return!1;this.flushText(),z(e)||this.words?.push({kind:"break"}),this.descend(t,r);const h=this.current.object;if(r.length>0&&(h.role=r),i)R(h,i,s),r.includes("figure")&&(this.current.noText=!0);else if(r.includes("figure")){const l=this.implicitCaptionOf(t);if(l){const{text:c,language:d}=V(l);c&&(R(h,c,d),this.current.noText=!0)}}else if(r.includes("table")){const l=this.implicitCaptionOf(t);if(l){const{text:c,language:d}=V(l);c&&(R(h,c,d),this.foldedCaptions.add(l))}}const b=t.getAttribute("id");return b&&(h.id=b),!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,i){if(e)return;const o=t.tagName.toLowerCase(),s=F(t);if(!s.includes("pagebreak")&&A(o,s)){this.flushText(),z(o)||this.words?.push({kind:"break"}),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const r=this.leafTextEnabled&&s.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(s)||r)&&this.applyTextref(t),this.current=i}}applyTextref(t){const e=this.current.object,i=M(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=$(i,t),this.domRangeEnabled&&this.lastFlowRange){const o=i?{el:t,selector:i}:void 0,s=at(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,o);s&&(e.textref=nt({...s,container:i}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const o=this.docRoot.createRange();o.setStart(...this.lastFlowRange.first),o.setEnd(...this.lastFlowRange.last);const s=ct(o);s&&(e.textref=`${e.textref??"#"}${rt(s)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(this.words?.push({kind:"text",text:N(e,!1)}),/^\s*$/.test(e)){(this.textAcc.length>0||this.segments.length>0)&&(this.textAcc+=N(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const i=this.textContext(t);if(_(i,this.currentCtx)||(this.closeSegment(),this.currentCtx=i),this.textAcc+=N(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const o=t;this.flowFirstNode===null&&(this.flowFirstNode=o,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=o,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){const e=u.punctuationOwner(t);let i=e?u.abbreviationOver(e):null;if(!e){let s=t.parentElement;for(;s&&s!==this.current.el;s=s.parentElement)if(W(s)){if(u.containsObject(s))break;i=s}s&&s===this.current.el&&(i=u.abbreviationOver(s)??i)}if(i)return{lang:D(i),tag:"sub",attrs:{alias:W(i)},abbr:i};const o={lang:D(t.parentElement),tag:""};for(let s=t.parentElement;s&&s!==this.current.el;s=s.parentElement){const[r,h]=Z(s.tagName.toLowerCase());if(r&&r!=="break"){o.tag=r,o.attrs=h;break}}return o}static containsObject(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling){const i=e.tagName.toLowerCase(),o=F(e);if(!(y.has(i)||u.isPlaceholder(e,i,o))&&(A(i,o)||u.containsObject(e)))return!0}return!1}static isPlaceholder(t,e,i){return i.includes("pagebreak")||i.includes("image")||i.includes("math")?!0:["img","svg","audio","video"].includes(e)||e==="a"&&!!t.getAttribute("href")}static abbreviationOver(t){let e=null;for(let i=t;i&&(W(i)&&(e=i),!!u.isSoleContent(i));i=i.parentElement);return e}static punctuationOwner(t){const e=t.nodeValue??"";if(t.nodeType!==O||!/\S/.test(e)||!/^[\s\p{P}]*$/u.test(e))return null;let i=null;for(let o=t.parentElement?.firstElementChild??null;o&&u.isSoleContent(o);o=o.firstElementChild){const s=o.tagName.toLowerCase(),r=F(o);if(y.has(s)||u.isPlaceholder(o,s,r)||!G(o)[1])break;A(s,r)&&(i=o)}return i&&u.abbreviationOver(i)?.contains(t)?i:null}static ownPunctuation(t){const e=u.abbreviationOver(t),i=[],o=s=>{if(s!==t){s.nodeType===O&&u.punctuationOwner(s)===t&&i.push(s);for(let r=s.firstChild;r;r=r.nextSibling)o(r)}};return e&&o(e),i}static isSoleContent(t){for(let e=t.parentNode?.firstChild;e;e=e.nextSibling)if(e!==t&&(e.nodeType===U||e.nodeType===O&&!/^[\s\p{P}]*$/u.test(e.nodeValue??"")))return!1;return!0}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:void 0,tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0}placeholder(t,e,i,{candidateID:o,words:s}={}){if(X(i))return;const r=new S;if(r.el=t,r.object=i,this.current.noText){this.appendChild(r);return}this.closeSegment(),this.pendingChildren.push(r),this.segments.push({kind:"placeholder",tag:e,child:r,candidateID:o??t.getAttribute("id")??void 0,words:s?.length?s:void 0}),this.words?.push(...s?.length?s:[{kind:"placeholder"}]),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,i=this.flowFirstNode,o=this.flowFirstOffset,s=this.flowLastNode,r=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 a=n.text.replace(/^\s+/,"");if(a===""){t=t.slice(1);continue}t=[{...n,text:a},...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 a=n.text.replace(/\s+$/,"");if(a===""){t=t.slice(0,-1);continue}t=[...t.slice(0,-1),{...n,text:a}]}break}const h=[];for(let n=0;n<t.length;n++){const a=t[n],p=a.kind==="text"?a.ctx.abbr:void 0;if(!p){h.push(a);continue}let m=a.text;const k=[];let w=[];for(let x=n+1;x<t.length;x++){const T=t[x];if(T.kind==="placeholder"&&it(p,T.child.el)){w.push(T);continue}if(T.kind!=="text"||T.ctx.abbr!==p)break;m+=T.text,k.push(...w),w=[],n=x}h.push({...a,text:m},...k)}if(t=h,!t.some(n=>n.kind==="text"&&n.text.trim()!=="")){for(const n of e)this.appendChild(n);return}const l=[];for(const n of t)if(n.kind==="text"&&n.text.trim()!==""){const a=n.ctx.lang;l.some(p=>j(p,a))||l.push(a)}let c=D(this.current.el??this.allowNode);l.length===1&&(c=l[0]);let d=!1;for(const n of t)if(n.kind!=="text"||n.ctx.tag!==""||!j(n.ctx.lang,c)){d=!0;break}d&&c===void 0&&(c="en");const g=n=>n!==void 0&&!j(n,c);if(d)for(const n of t){if(n.kind!=="placeholder")continue;let a=this.copy?void 0:n.candidateID;(!a||!this.idAlloc.claim(a))&&(a=this.idAlloc.allocate(n.tag,p=>this.ids.has(p))),n.child.object.id=a}let E="",H=!1,L=!1,v=!1,C=!1;for(const n of t.flatMap(a=>a.words??[a]))if(n.kind==="text"){const a=n.text.startsWith(" "),p=n.text.replace(/^ +| +$/g,"");if(p===""){C=!0;continue}let m=!1;if(E.length>0){const k=H||C||a;L?m=!0:v?m=k&&!bt(p,c):m=k}m&&(E+=" "),E+=p,H=n.text.endsWith(" "),L=!1,v=!1,C=!1}else n.kind==="break"?L=!0:n.kind==="placeholder"&&(E+=wt,v=!0);E=xt(E,c);const J=t.some(n=>n.kind==="placeholder");this.lastFlowText=E.trim();const q={plain:d&&!J?"":E.trim(),ssml:"",language:c??""};if(d){let n="";for(const a of t)if(a.kind==="text"){const{tag:p,attrs:m,lang:k}=a.ctx,w=p==="sub"?/^( *)([^]*?)( *)$/.exec(a.text):null,x=w?w[2]:a.text;if(w&&x===""){n+=a.text;continue}if(n+=w?.[1]??"",g(k)){const T=p==="sub"?Y(p,m,x):B(x);n+=`<lang xml:lang="${I(k)}">${T}</lang>`}else n+=p?Y(p,m,x):B(x);n+=w?.[3]??""}else a.kind==="break"?n+="<break/>":a.kind==="placeholder"&&(n+=`<readium:${a.tag} id="${I(a.child.object.id)}" />`);q.ssml=n}const P=new S;P.object={text:q};for(const n of e)P.children.push(n);this.appendChild(P),i&&s&&(this.lastFlowRange={first:[i,o],last:[s,r]})}}function W(f){return F(f).includes("abbreviation")?N(f.getAttribute("title")??"",!0).trim():""}function Y(f,t,e){const i=Object.entries(t??{}).map(([o,s])=>` ${o}="${I(s)}"`).join("");return`<${f}${i}>${B(e)}</${f}>`}const Rt=/<body[\s>]/i;function zt(f,t,e){const{predicate:i,leafText:o,domRange:s,textFragment:r}=ht(e?.textrefs);if(typeof f!="string"){const d=t??(f.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),g=new u(d==="application/xhtml+xml");return g.selectorPredicate=i,g.leafTextEnabled=o,g.domRangeEnabled=s,g.textFragmentEnabled=r,g.docRoot=f.ownerDocument,g.baseHref=e?.href,g.selectorRoot=f,g.selectorRootAnchor=lt(f),g.convert(f),g.result()}let h=t??et(f),b=new DOMParser().parseFromString(f,h);if(h==="application/xhtml+xml"){const d=b.getElementsByTagNameNS("*","parsererror")[0];if(d){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${d.textContent?.trim()??""}`);h="text/html",b=new DOMParser().parseFromString(f,h)}}const l=new u(h==="application/xhtml+xml");l.selectorPredicate=i,l.leafTextEnabled=o,l.textFragmentEnabled=r,l.docRoot=b,l.baseHref=e?.href;const c=b.querySelector("body");return c&&!Rt.test(f)?l.convertChildren(c):l.convert(c??b.documentElement),l.result()}export{u as Converter,zt as parseMarkup};
1
+ import{hasExplicitRole as J,extractNodeRoles as R}from"./roles.js";import{skippedElements as $,extractNodeAria as G,normalizedNodeText as K,convertElementToSSMLTag as Q}from"./a11y.js";import{normalizeWhitespace as v,ctxEqual as Z}from"./text.js";import{ssmlTextEscape as B,ssmlAttrEscape as I}from"@readium/helpers";import{NavObject as F,isEmptyObj as V,finalizeToGuidedNavigationObject as _,setDescription as S}from"./object.js";import{sniffMediaType as tt,isInlineTag as z,isAncestorOf as et}from"./dom.js";import{nodeLanguage as st,declaredLanguage as j,sameLanguage as M}from"./language.js";import{encodeDomRangeFragment as it,encodeTextFragmentDirective as nt}from"./textrefFragment.js";import{resolveRefs as rt}from"./href.js";import{rootAnchorSelector as ot,textrefForSelector as A,selectorForElement as O}from"./selectorGenerator.js";import{generateDomRange as lt}from"./domRangeGenerator.js";import{textFragmentDirectiveFor as at}from"./textFragmentGenerator.js";import{normalizeTextrefOptions as ct}from"./options.js";import{IdAllocator as ht}from"./idAllocator.js";import{prescan as ft}from"./prescan.js";import{pagebreak as dt,noteref as ut,reference as gt,link as pt}from"./elementHandlers.js";import{removeDropped as mt,bindsToPrevious as xt,DROPPED as bt}from"./emptyPairs.js";const wt="http://www.w3.org/1998/Math/MathML",N=3,X=1,kt=4,Et=new Set(["summary","dfn","span"]);function L(f,t){return Et.has(f)&&t.length>0?!0:!z(f)}class d{constructor(t){this.ids=new Map,this.suppressed=new Set,this.idAlloc=new ht,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.copy=!1,this.root=new F,this.current=this.root,this.segments=[],this.textAcc="",this.currentCtx={lang:void 0,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.words=null,this.xmlParsed=t}spawnChild(t,e=1){const s=new d(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.copy=this.copy,s}prescan(t){ft(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=>A(O(e,this.selectorRoot,this.selectorRootAnchor),e));return!t.children||t.children.length===0||t.text?V(t)?[]:[t]:t.children}result(){const t=this.resultBuilders();return this.baseHref&&t.forEach(e=>rt(e,this.baseHref)),t.map(_)}descend(t,e){const s=new F;s.el=t,s.noText=(!J(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===N){d.punctuationOwner(t)||this.text(t);return}if(t.nodeType!==X)return;const e=t,s=this.current,o=this.head(e);if(!o){const i=this.current!==s&&this.current.el===e?d.ownPunctuation(e):[],r=a=>(a.compareDocumentPosition(e)&kt)!==0;for(const a of i)r(a)&&this.text(a);for(let a=e.firstChild;a;a=a.nextSibling)this.walk(a);for(const a of i)r(a)||this.text(a)}this.tail(e,o,s)}head(t){const e=t.tagName.toLowerCase();if($.has(e)||this.suppressed.has(t)&&t!==this.allowNode)return!0;const[s,o,i]=G(t);if(!o&&t!==this.allowNode)return!0;const r=R(t);if((e==="img"||e==="svg")&&(r.includes("presentation")||s===null&&t.hasAttribute("alt")&&t.getAttribute("alt").trim()===""))return!0;if(e==="br")return!this.current.noText&&!this.textContext(t).abbr&&(this.closeSegment(),this.segments.push({kind:"break"}),this.words?.push({kind:"break"}),this.flowEndsWithSpace=!0),!0;if(r.includes("pagebreak"))return!dt(this,t,s,i,r);if(e==="a"&&r.includes("noteref")&&t.getAttribute("href"))return ut(this,t,r),!0;if(e==="a"&&(r.includes("glossref")||r.includes("biblioref"))&&t.getAttribute("href"))return gt(this,t,r,s,i),!0;if(e==="a"&&t.getAttribute("href"))return pt(this,t,r,s,i),!0;if(e==="img"){const c={role:r},h=t.getAttribute("src");return h&&(c.imgref=h),s&&S(c,s,i),this.placeholder(t,"image",c),!0}if(e==="audio"||e==="video"){const c={role:r};let h=t.getAttribute("src");if(!h){const g=t.querySelector(":scope > source[src]");g&&(h=g.getAttribute("src"))}return e==="audio"?h&&(c.audioref=h):h&&(c.videoref=h),s&&S(c,s,i),this.placeholder(t,e,c),!0}if(r.includes("image")||r.includes("math")){const c={role:r};if(s&&S(c,s,i),r.includes("math")){if(t.namespaceURI===wt)c.text={plain:"",ssml:new XMLSerializer().serializeToString(t),language:st(t)};else{const{text:h,language:g}=K(t);h&&(c.text={plain:h,ssml:"",language:g})}c.textref=A(O(t,this.selectorRoot,this.selectorRootAnchor),t)}return this.placeholder(t,r.includes("math")?"math":"image",c),!0}if(!L(e,r))return!1;this.flushText(),z(e)||this.words?.push({kind:"break"}),this.descend(t,r);const a=this.current.object;r.length>0&&(a.role=r),s&&(S(a,s,i),r.includes("figure")&&(this.current.noText=!0));const b=t.getAttribute("id");return b&&(a.id=b),!1}tail(t,e,s){if(e)return;const o=t.tagName.toLowerCase(),i=R(t);if(!i.includes("pagebreak")&&L(o,i)){this.flushText(),z(o)||this.words?.push({kind:"break"}),this.current.hasChildBlock&&(this.lastFlowRange=null,this.lastFlowText=null);const r=this.leafTextEnabled&&i.length===0&&!!this.lastFlowText;(this.selectorPredicate?.(i)||r)&&this.applyTextref(t),this.current=s}}applyTextref(t){const e=this.current.object,s=O(t,this.selectorRoot,this.selectorRootAnchor);if(e.textref=A(s,t),this.domRangeEnabled&&this.lastFlowRange){const o=s?{el:t,selector:s}:void 0,i=lt(this.lastFlowRange,this.selectorRoot,this.selectorRootAnchor,o);i&&(e.textref=it({...i,container:s}))}if(this.textFragmentEnabled&&this.lastFlowRange&&this.docRoot){const o=this.docRoot.createRange();o.setStart(...this.lastFlowRange.first),o.setEnd(...this.lastFlowRange.last);const i=at(o);i&&(e.textref=`${e.textref??"#"}${nt(i)}`)}}text(t){if(this.current.noText)return;const e=t.nodeValue??"";if(this.words?.push({kind:"text",text:v(e,!1)}),/^\s*$/.test(e)){(this.textAcc.length>0||this.segments.length>0)&&(this.textAcc+=v(e,this.flowEndsWithSpace),this.updateFlowSpace());return}const s=this.textContext(t);if(Z(s,this.currentCtx)||(this.closeSegment(),this.currentCtx=s),this.textAcc+=v(e,this.flowEndsWithSpace),this.updateFlowSpace(),this.domRangeEnabled||this.textFragmentEnabled){const o=t;this.flowFirstNode===null&&(this.flowFirstNode=o,this.flowFirstOffset=e.search(/\S/)),this.flowLastNode=o,this.flowLastOffset=e.length-(e.match(/\s+$/)?.[0].length??0)}}textContext(t){const e=d.punctuationOwner(t);let s=e?d.abbreviationOver(e):null;if(!e){let i=t.parentElement;for(;i&&i!==this.current.el;i=i.parentElement)if(W(i)){if(d.containsObject(i))break;s=i}i&&i===this.current.el&&(s=d.abbreviationOver(i)??s)}if(s)return{lang:j(s),tag:"sub",attrs:{alias:W(s)},abbr:s};const o={lang:j(t.parentElement),tag:""};for(let i=t.parentElement;i&&i!==this.current.el;i=i.parentElement){const[r,a]=Q(i.tagName.toLowerCase());if(r&&r!=="break"){o.tag=r,o.attrs=a;break}}return o}static containsObject(t){for(let e=t.firstElementChild;e;e=e.nextElementSibling){const s=e.tagName.toLowerCase(),o=R(e);if(!($.has(s)||d.isPlaceholder(e,s,o))&&(L(s,o)||d.containsObject(e)))return!0}return!1}static isPlaceholder(t,e,s){return s.includes("pagebreak")||s.includes("image")||s.includes("math")?!0:["img","svg","audio","video"].includes(e)||e==="a"&&!!t.getAttribute("href")}static abbreviationOver(t){let e=null;for(let s=t;s&&(W(s)&&(e=s),!!d.isSoleContent(s));s=s.parentElement);return e}static punctuationOwner(t){const e=t.nodeValue??"";if(t.nodeType!==N||!/\S/.test(e)||!/^[\s\p{P}]*$/u.test(e))return null;let s=null;for(let o=t.parentElement?.firstElementChild??null;o&&d.isSoleContent(o);o=o.firstElementChild){const i=o.tagName.toLowerCase(),r=R(o);if($.has(i)||d.isPlaceholder(o,i,r)||!G(o)[1])break;L(i,r)&&(s=o)}return s&&d.abbreviationOver(s)?.contains(t)?s:null}static ownPunctuation(t){const e=d.abbreviationOver(t),s=[],o=i=>{if(i!==t){i.nodeType===N&&d.punctuationOwner(i)===t&&s.push(i);for(let r=i.firstChild;r;r=r.nextSibling)o(r)}};return e&&o(e),s}static isSoleContent(t){for(let e=t.parentNode?.firstChild;e;e=e.nextSibling)if(e!==t&&(e.nodeType===X||e.nodeType===N&&!/^[\s\p{P}]*$/u.test(e.nodeValue??"")))return!1;return!0}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:void 0,tag:""},this.flowEndsWithSpace=!0,this.pendingChildren=[],this.flowFirstNode=null,this.flowFirstOffset=0,this.flowLastNode=null,this.flowLastOffset=0}placeholder(t,e,s,{candidateID:o,words:i}={}){if(V(s))return;!s.textref&&this.selectorPredicate?.(s.role??[])&&(s.textref=A(O(t,this.selectorRoot,this.selectorRootAnchor),t));const r=new F;if(r.el=t,r.object=s,this.current.noText){this.appendChild(r);return}this.closeSegment(),this.pendingChildren.push(r),this.segments.push({kind:"placeholder",tag:e,child:r,candidateID:o??t.getAttribute("id")??void 0,words:i?.length?i:void 0}),this.words?.push(...i?.length?i:[{kind:"placeholder"}]),this.flowEndsWithSpace=!1}flushText(){this.closeSegment();let t=this.segments;const e=this.pendingChildren,s=this.flowFirstNode,o=this.flowFirstOffset,i=this.flowLastNode,r=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}const a=[];for(let n=0;n<t.length;n++){const l=t[n],u=l.kind==="text"?l.ctx.abbr:void 0;if(!u){a.push(l);continue}let m=l.text;const E=[];let w=[];for(let x=n+1;x<t.length;x++){const T=t[x];if(T.kind==="placeholder"&&et(u,T.child.el)){w.push(T);continue}if(T.kind!=="text"||T.ctx.abbr!==u)break;m+=T.text,E.push(...w),w=[],n=x}a.push({...l,text:m},...E)}if(t=a,!t.some(n=>n.kind==="text"&&n.text.trim()!=="")){for(const n of e)this.appendChild(n);return}const c=[];for(const n of t)if(n.kind==="text"&&n.text.trim()!==""){const l=n.ctx.lang;c.some(u=>M(u,l))||c.push(l)}let h=j(this.current.el??this.allowNode);c.length===1&&(h=c[0]);let g=!1;for(const n of t)if(n.kind!=="text"||n.ctx.tag!==""||!M(n.ctx.lang,h)){g=!0;break}g&&h===void 0&&(h="en");const p=n=>n!==void 0&&!M(n,h);if(g)for(const n of t){if(n.kind!=="placeholder")continue;let l=this.copy?void 0:n.candidateID;(!l||!this.idAlloc.claim(l))&&(l=this.idAlloc.allocate(n.tag,u=>this.ids.has(u))),n.child.object.id=l}let k="",H=!1,P=!1,C=!1,y=!1;for(const n of t.flatMap(l=>l.words??[l]))if(n.kind==="text"){const l=n.text.startsWith(" "),u=n.text.replace(/^ +| +$/g,"");if(u===""){y=!0;continue}let m=!1;if(k.length>0){const E=H||y||l;P?m=!0:C?m=E&&!xt(u,h):m=E}m&&(k+=" "),k+=u,H=n.text.endsWith(" "),P=!1,C=!1,y=!1}else n.kind==="break"?P=!0:n.kind==="placeholder"&&(k+=bt,C=!0);k=mt(k,h);const Y=t.some(n=>n.kind==="placeholder");this.lastFlowText=k.trim();const q={plain:g&&!Y?"":k.trim(),ssml:"",language:h??""};if(g){let n="";for(const l of t)if(l.kind==="text"){const{tag:u,attrs:m,lang:E}=l.ctx,w=u==="sub"?/^( *)([^]*?)( *)$/.exec(l.text):null,x=w?w[2]:l.text;if(w&&x===""){n+=l.text;continue}if(n+=w?.[1]??"",p(E)){const T=u==="sub"?U(u,m,x):B(x);n+=`<lang xml:lang="${I(E)}">${T}</lang>`}else n+=u?U(u,m,x):B(x);n+=w?.[3]??""}else l.kind==="break"?n+="<break/>":l.kind==="placeholder"&&(n+=`<readium:${l.tag} id="${I(l.child.object.id)}" />`);q.ssml=n}const D=new F;D.object={text:q};for(const n of e)D.children.push(n);this.appendChild(D),s&&i&&(this.lastFlowRange={first:[s,o],last:[i,r]})}}function W(f){return R(f).includes("abbreviation")?v(f.getAttribute("title")??"",!0).trim():""}function U(f,t,e){const s=Object.entries(t??{}).map(([o,i])=>` ${o}="${I(i)}"`).join("");return`<${f}${s}>${B(e)}</${f}>`}const Tt=/<body[\s>]/i;function It(f,t,e){const{predicate:s,leafText:o,domRange:i,textFragment:r}=ct(e?.textrefs);if(typeof f!="string"){const g=t??(f.ownerDocument.contentType==="text/html"?"text/html":"application/xhtml+xml"),p=new d(g==="application/xhtml+xml");return p.selectorPredicate=s,p.leafTextEnabled=o,p.domRangeEnabled=i,p.textFragmentEnabled=r,p.docRoot=f.ownerDocument,p.baseHref=e?.href,p.selectorRoot=f,p.selectorRootAnchor=ot(f),p.convert(f),p.result()}let a=t??tt(f),b=new DOMParser().parseFromString(f,a);if(a==="application/xhtml+xml"){const g=b.getElementsByTagNameNS("*","parsererror")[0];if(g){if(!e?.htmlFallback)throw new Error(`XHTML parsing failed: ${g.textContent?.trim()??""}`);a="text/html",b=new DOMParser().parseFromString(f,a)}}const c=new d(a==="application/xhtml+xml");c.selectorPredicate=s,c.leafTextEnabled=o,c.textFragmentEnabled=r,c.docRoot=b,c.baseHref=e?.href;const h=b.querySelector("body");return h&&!Tt.test(f)?c.convertChildren(h):c.convert(h??b.documentElement),c.result()}export{d as Converter,It as parseMarkup};
@@ -1 +1 @@
1
- import{ssmlAttrEscape as A}from"@readium/helpers";import{normalizedNodeText as u}from"./a11y.js";import{normalizeWhitespace as k,textIsEmpty as E}from"./text.js";import{ariaSubstitutedBuilders as m,substitutedOwnSelectorBuilders as S,isHoistable as I}from"./object.js";import{hasElementChild as j,isAncestorOf as g}from"./dom.js";import{nodeLanguage as B}from"./language.js";import{selectorForElement as p,textrefForSelector as D}from"./selectorGenerator.js";import{decodeIdFragment as x,detachSelfTextref as L}from"./textrefFragment.js";function M(t,e,i,s,c){const n={role:c},d=k(e.getAttribute("title")??"",!0).trim();d?n.text={plain:d,ssml:"",language:B(e)}:i&&(n.text={plain:i,ssml:"",language:s},m.add(n));const l=!!(n.text&&!E(n.text)),r=!t.xmlParsed&&(j(e)||l&&e.firstChild!==null);if(!l&&!r){const{text:f,language:h}=u(e);f&&(n.text={plain:f,ssml:"",language:h})}const o=p(e,t.selectorRoot,t.selectorRootAnchor),a=D(o,e);return a&&(n.textref=a),t.placeholder(e,"pagebreak",n),r}function P(t,e,i){const s={role:i},{text:c,language:n}=u(e);c&&(s.text={plain:c,ssml:"",language:n});const d=e.getAttribute("href")??"",l=d.startsWith("#")?x(d)??d.slice(1):void 0;let r=e.getAttribute("id")??"";if(!r&&l!==void 0){const o=t.ids.get(l);(!o||t.suppressed.has(o))&&(r=l)}if(l!==void 0){const o=t.ids.get(l);if(o&&!g(o,e)&&t.noterefDepth<3){const a=t.spawnChild(o);a.convert(o);const f=a.resultBuilders();if(f.length>0){for(const h of f)w(h);s.children=f}}}!s.children&&d&&(s.children=[{textref:d}]),t.placeholder(e,"noteref",s,{candidateID:r||void 0})}function $(t,e,i,s,c){const{obj:n,words:d}=b(t,e,i,s,c);t.placeholder(e,i[0]??"link",n,{words:i.includes("backlink")?void 0:d})}function q(t,e,i,s,c){const{obj:n,words:d}=b(t,e,i,s,c),l=e.getAttribute("href")??"";if(l.startsWith("#")){const r=t.ids.get(x(l)??l.slice(1));if(r&&!g(r,e)&&t.noterefDepth<3){const o=N(r).flatMap(a=>{const f=t.spawnChild(a);return f.copy=!0,f.convert(a),f.resultBuilders()});C(o),o.length>0&&(n.children=[...n.children??[],...o])}}t.placeholder(e,i[0],n,{words:d})}function b(t,e,i,s,c){const n={};i.length>0&&(n.role=i);const d=s?[{kind:"text",text:s}]:[];if(s){n.text={plain:s,ssml:"",language:c},m.add(n);const r=p(e,t.selectorRoot,t.selectorRootAnchor);r&&S.set(n,r)}else{const r=t.spawnChild(e,0);r.words=d,r.convertChildren(e);const o=r.resultBuilders();o.length===1&&o[0].text&&I(o[0])?(n.text=o[0].text,o[0].children&&(n.children=o[0].children)):o.length>0&&(n.children=o)}const l=e.getAttribute("href");return l&&(n.textref=l),{obj:n,words:d}}function w(t){const e=t.id;e!==void 0&&(delete t.id,L(t,e))}function C(t,e){for(const i of t)(i.id===void 0||!e?.text?.ssml.includes(`id="${A(i.id)}"`))&&w(i),i.children&&C(i.children,i)}function N(t){const e=t.tagName.toLowerCase()==="dt"?t:t.closest("dt");if(!e)return[t];let i=e.nextElementSibling;for(;i&&i.tagName.toLowerCase()==="dt";)i=i.nextElementSibling;const s=[];for(;i&&i.tagName.toLowerCase()==="dd";i=i.nextElementSibling)s.push(i);return s.length>0?[e,...s]:[t]}export{$ as link,P as noteref,M as pagebreak,q as reference};
1
+ import{ssmlAttrEscape as C}from"@readium/helpers";import{normalizedNodeText as u}from"./a11y.js";import{normalizeWhitespace as k,textIsEmpty as A}from"./text.js";import{ariaSubstitutedBuilders as m,substitutedOwnSelectorBuilders as j,isHoistable as E}from"./object.js";import{hasElementChild as S,isAncestorOf as g}from"./dom.js";import{nodeLanguage as B}from"./language.js";import{selectorForElement as p,textrefForSelector as I}from"./selectorGenerator.js";import{decodeIdFragment as x}from"./textrefFragment.js";function H(t,e,i,o,c){const n={role:c},d=k(e.getAttribute("title")??"",!0).trim();d?n.text={plain:d,ssml:"",language:B(e)}:i&&(n.text={plain:i,ssml:"",language:o},m.add(n));const s=!!(n.text&&!A(n.text)),l=!t.xmlParsed&&(S(e)||s&&e.firstChild!==null);if(!s&&!l){const{text:f,language:h}=u(e);f&&(n.text={plain:f,ssml:"",language:h})}const r=p(e,t.selectorRoot,t.selectorRootAnchor),a=I(r,e);return a&&(n.textref=a),t.placeholder(e,"pagebreak",n),l}function M(t,e,i){const o={role:i},{text:c,language:n}=u(e);c&&(o.text={plain:c,ssml:"",language:n});const d=e.getAttribute("href")??"",s=d.startsWith("#")?x(d)??d.slice(1):void 0;let l=e.getAttribute("id")??"";if(!l&&s!==void 0){const r=t.ids.get(s);(!r||t.suppressed.has(r))&&(l=s)}if(s!==void 0){const r=t.ids.get(s);if(r&&!g(r,e)&&t.noterefDepth<3){const a=t.spawnChild(r);a.convert(r);const f=a.resultBuilders();if(f.length>0){for(const h of f)delete h.id;o.children=f}}}!o.children&&d&&(o.children=[{textref:d}]),t.placeholder(e,"noteref",o,{candidateID:l||void 0})}function P(t,e,i,o,c){const{obj:n,words:d}=b(t,e,i,o,c);t.placeholder(e,i[0]??"link",n,{words:i.includes("backlink")?void 0:d})}function T(t,e,i,o,c){const{obj:n,words:d}=b(t,e,i,o,c),s=e.getAttribute("href")??"";if(s.startsWith("#")){const l=t.ids.get(x(s)??s.slice(1));if(l&&!g(l,e)&&t.noterefDepth<3){const r=D(l).flatMap(a=>{const f=t.spawnChild(a);return f.copy=!0,f.convert(a),f.resultBuilders()});w(r),r.length>0&&(n.children=[...n.children??[],...r])}}t.placeholder(e,i[0],n,{words:d})}function b(t,e,i,o,c){const n={};i.length>0&&(n.role=i);const d=o?[{kind:"text",text:o}]:[];if(o){n.text={plain:o,ssml:"",language:c},m.add(n);const s=p(e,t.selectorRoot,t.selectorRootAnchor);s&&j.set(n,s)}else{const s=t.spawnChild(e,0);s.words=d,s.convertChildren(e);const l=s.resultBuilders();l.length===1&&l[0].text&&E(l[0])?(n.text=l[0].text,l[0].children&&(n.children=l[0].children)):l.length>0&&(n.children=l)}return{obj:n,words:d}}function w(t,e){for(const i of t)(i.id===void 0||!e?.text?.ssml.includes(`id="${C(i.id)}"`))&&delete i.id,i.children&&w(i.children,i)}function D(t){const e=t.tagName.toLowerCase()==="dt"?t:t.closest("dt");if(!e)return[t];let i=e.nextElementSibling;for(;i&&i.tagName.toLowerCase()==="dt";)i=i.nextElementSibling;const o=[];for(;i&&i.tagName.toLowerCase()==="dd";i=i.nextElementSibling)o.push(i);return o.length>0?[e,...o]:[t]}export{P as link,M as noteref,H as pagebreak,T as reference};
@@ -1 +1 @@
1
- import{startsWithBindingPunct as P}from"@readium/helpers";const h="\0",p="()[]{}()[]{}「」『』【】〔〕〈〉《》",w=`""''`,f={ar:"”“’‘",bg:"„“",cs:"„“‚‘",da:"“”‘’»«›‹",de:"„“‚‘»«›‹«»‹›",el:"«»“”",en:"“”‘’",es:"“”‘’",et:"„“‚‘",fi:"””’’»»››",fr:"«»",he:"””’’",hr:"„“‚‘",hu:"„”»«",hy:"«»",is:"„“‚‘",it:"«»“”",ja:"「」『』",ka:"„“«»",ko:"“”‘’",lt:"„“",lv:"“”‘’",nb:"«»‘’",nl:"‘’",pl:"„”«»",pt:"“”‘’",ro:"„”«»",ru:"«»„“",sk:"„“‚‘",sl:"„“‚‘",sr:"„”’’",sv:"””’’»»››",tr:"“”‘’",uk:"«»„“",zh:"“”‘’","zh-hant":"「」『』"},g=/[\s​-‍⁠,;、,\u0000]/,l=new Map;function a(e){const t=e?.toLowerCase()??"";let n=l.get(t);if(n)return n;const c=p+w+(f[t]??f[t.split("-")[0]]??f.en);n={pairs:new Set,opening:new Set,closing:new Set};for(let i=0;i<c.length;i+=2)n.pairs.add(c[i]+c[i+1]),n.opening.add(c[i]),n.closing.add(c[i+1]);return l.set(t,n),n}function k(e,t){return!P(e)||t?.toLowerCase().split("-")[0]==="fr"&&"»;:!?".includes(e[0])?!1:!(a(t).opening.has(e[0])&&e.length>1&&!/[\s\p{P}]/u.test(e[1]))}function S(e,t){const{pairs:n,opening:c,closing:i}=a(t);for(let r=e.indexOf(h);r!==-1;r=e.indexOf(h,r+1)){let s=r,o=r+1;for(;s>0&&g.test(e[s-1]);)s--;for(;o<e.length&&g.test(e[o]);)o++;const u=e[s-1],d=e[o];u===void 0||d===void 0||!n.has(u+d)||i.has(u)&&s>1&&!/[\s\p{Ps}\p{Pi}\p{Pd}]/u.test(e[s-2])||c.has(d)&&o<e.length-1&&!/[\s\p{P}]/u.test(e[o+1])||(e=e.slice(0,s-1)+h+e.slice(o+1),r=s-2)}return e.replace(/ *\u0000[\u0000 ]*/g,(r,s)=>{const o=e.slice(s+r.length);return s>0&&o!==""&&r.includes(" ")&&!k(o,t)?" ":""})}export{h as DROPPED,k as bindsToPrevious,S as removeDropped};
1
+ import{startsWithBindingPunct as A}from"@readium/helpers";const d="\0",R="()[]{}()[]{}「」『』【】〔〕〈〉《》",S=`""''`,p={ar:"”“’‘",bg:"„“",cs:"„“‚‘",da:"“”‘’»«›‹",de:"„“‚‘»«›‹«»‹›",el:"«»“”",en:"“”‘’",es:"“”‘’",et:"„“‚‘",fi:"””’’»»››",fr:"«»",he:"””’’",hr:"„“‚‘",hu:"„”»«",hy:"«»",is:"„“‚‘",it:"«»“”",ja:"「」『』",ka:"„“«»",ko:"“”‘’",lt:"„“",lv:"“”‘’",nb:"«»‘’",nl:"‘’",pl:"„”«»",pt:"“”‘’",ro:"„”«»",ru:"«»„“",sk:"„“‚‘",sl:"„“‚‘",sr:"„”’’",sv:"””’’»»››",tr:"“”‘’",uk:"«»„“",zh:"“”‘’","zh-hant":"「」『』"},P=/[\s​-‍⁠,;、,\u0000]/,k=new Map;function m(s){const o=s?.toLowerCase()??"";let r=k.get(o);if(r)return r;const l=R+S+(p[o]??p[o.split("-")[0]]??p.en);r={pairs:new Set,opening:new Set,closing:new Set};for(let n=0;n<l.length;n+=2)r.pairs.add(l[n]+l[n+1]),r.opening.add(l[n]),r.closing.add(l[n+1]);return k.set(o,r),r}function v(s,o){return!A(s)||o?.toLowerCase().split("-")[0]==="fr"&&"»;:!?".includes(s[0])?!1:!(m(o).opening.has(s[0])&&s.length>1&&!/[\s\p{P}]/u.test(s[1]))}function O(s,o){const{pairs:r,opening:l,closing:n}=m(o);let t=s;const h=Array.from({length:s.length},(c,e)=>[e]);for(let c=t.indexOf(d);c!==-1;c=t.indexOf(d,c+1)){let e=c,i=c+1;for(;e>0&&P.test(t[e-1]);)e--;for(;i<t.length&&P.test(t[i]);)i++;const f=t[e-1],a=t[i];f===void 0||a===void 0||!r.has(f+a)||n.has(f)&&e>1&&!/[\s\p{Ps}\p{Pi}\p{Pd}]/u.test(t[e-2])||l.has(a)&&i<t.length-1&&!/[\s\p{P}]/u.test(t[i+1])||(t=t.slice(0,e-1)+d+t.slice(i+1),h.splice(e-1,i-e+2,h.slice(e-1,i+1).flat()),c=e-2)}const g=new Array(s.length).fill(!1);for(const c of t.matchAll(/ *\u0000[\u0000 ]*/g)){const e=c.index,i=e+c[0].length,f=t.slice(i),a=e>0&&f!==""&&c[0].includes(" ")&&!v(f,o)?t.indexOf(" ",e):-1;for(let u=e;u<i;u++)if(u!==a)for(const w of h[u])g[w]=!0}return g}function E(s,o){const r=O(s,o);let l="";for(let n=0;n<s.length;n++)r[n]||(l+=s[n]);return l}export{d as DROPPED,v as bindsToPrevious,O as droppedMask,E as removeDropped};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{makeGnd as r}from"./makeGnd.js";import{parseMarkup as m}from"./converter.js";import{combineDomRangeTextrefs as n,decodeCssSelectorFragment as a,decodeDomRangeFragment as s,decodeTextref as c,encodeCssSelectorFragment as p,encodeDomRangeFragment as f}from"./textrefFragment.js";import{isAriaSubstituted as x,substitutedOwnSelector as D}from"./object.js";import{DROPPED as u,removeDropped as F}from"./emptyPairs.js";export{u as DROPPED,n as combineDomRangeTextrefs,a as decodeCssSelectorFragment,s as decodeDomRangeFragment,c as decodeTextref,p as encodeCssSelectorFragment,f as encodeDomRangeFragment,x as isAriaSubstituted,r as makeGnd,m as parseMarkup,F as removeDropped,D as substitutedOwnSelector};
1
+ import{makeGnd as r}from"./makeGnd.js";import{parseMarkup as m}from"./converter.js";import{combineDomRangeTextrefs as a,decodeCssSelectorFragment as n,decodeDomRangeFragment as p,decodeTextref as s,encodeCssSelectorFragment as c,encodeDomRangeFragment as x}from"./textrefFragment.js";import{isAriaSubstituted as g,substitutedOwnSelector as D}from"./object.js";import{extractNodeRoles as u}from"./roles.js";import{DROPPED as l,droppedMask as F,removeDropped as S}from"./emptyPairs.js";export{l as DROPPED,a as combineDomRangeTextrefs,n as decodeCssSelectorFragment,p as decodeDomRangeFragment,s as decodeTextref,F as droppedMask,c as encodeCssSelectorFragment,x as encodeDomRangeFragment,u as extractNodeRoles,g as isAriaSubstituted,r as makeGnd,m as parseMarkup,S as removeDropped,D as substitutedOwnSelector};
package/dist/object.js CHANGED
@@ -1 +1 @@
1
- import{GuidedNavigationObject as h,GuidedNavigationDescription as u,GuidedNavigationText as g}from"@readium/shared";import{nonSelfNestingRoles as p}from"./roles.js";import{textIsEmpty as s,finalizeText as x}from"./text.js";import{detachSelfTextref as m}from"./textrefFragment.js";function R(e,n,t){e.description=n,e.descriptionLanguage=t}const v=["math","separator"],b=new WeakSet,o=new WeakSet,w=new WeakMap,a=new WeakMap;function W(e){return o.has(e)}function y(e){return a.get(e)}function f(e){return e.role?.some(n=>v.includes(n))?!1:!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||s(e.text))&&!(e.children&&e.children.length>0)&&!e.description}function S(e){return!e.audioref&&!e.imgref&&!e.textref&&!e.videoref&&(!e.text||s(e.text))&&!!(e.children&&e.children.length>0)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description}function N(e){return!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class B{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(!f(r)){if(S(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],r=t.role;i.role=i.role?.filter(c=>!(p.has(c)&&r.includes(c))),i.role?.length||delete i.role}if((!t.text||s(t.text))&&t.children?.length===1){const i=t.children[0];N(i)&&(i.text&&(t.text=i.text),t.children=i.children)}if(this.el&&n&&!f(t)&&!O(t)){const i=n(this.el);i&&(t.textref=i)}const l=this.el?.getAttribute("id");return l&&t.id!==l&&m(t,l),t}}function O(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 j(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:x(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(j):void 0,description:e.description?new u({text:new g({plain:e.description,language:e.descriptionLanguage||void 0})}):void 0});b.has(e)&&o.add(n);const t=w.get(e);return t&&a.set(n,t),n}export{B as NavObject,b as ariaSubstitutedBuilders,j as finalizeToGuidedNavigationObject,W as isAriaSubstituted,f as isEmptyObj,N as isHoistable,R as setDescription,y as substitutedOwnSelector,w as substitutedOwnSelectorBuilders};
1
+ import{GuidedNavigationObject as h,GuidedNavigationDescription as u,GuidedNavigationText as g}from"@readium/shared";import{nonSelfNestingRoles as p}from"./roles.js";import{textIsEmpty as l,finalizeText as x}from"./text.js";function z(e,n,t){e.description=n,e.descriptionLanguage=t}const v=["math","separator"],f=new WeakSet,a=new WeakSet,m=new WeakMap,o=new WeakMap;function C(e){return a.has(e)}function G(e){return o.get(e)}function c(e){return e.role?.some(n=>v.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 b(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 w(e){return!f.has(e)&&!(e.role&&e.role.length>0)&&!e.id&&!e.description&&!e.textref&&!e.imgref&&!e.audioref&&!e.videoref}class R{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(b(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],r=t.role;i.role=i.role?.filter(s=>!(p.has(s)&&r.includes(s))),i.role?.length||delete i.role}if((!t.text||l(t.text))&&t.children?.length===1){const i=t.children[0];w(i)&&(i.text&&(t.text=i.text),t.children=i.children)}if(this.el&&n&&!c(t)&&!S(t)){const i=n(this.el);i&&(t.textref=i)}return t}}function S(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 N(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:x(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(N):void 0,description:e.description?new u({text:new g({plain:e.description,language:e.descriptionLanguage||void 0})}):void 0});f.has(e)&&a.add(n);const t=m.get(e);return t&&o.set(n,t),n}export{R as NavObject,f as ariaSubstitutedBuilders,N as finalizeToGuidedNavigationObject,C as isAriaSubstituted,c as isEmptyObj,w as isHoistable,z as setDescription,G as substitutedOwnSelector,m as substitutedOwnSelectorBuilders};
@@ -1 +1 @@
1
- const l="#css(";function R(e){return`${l}${encodeURIComponent(e)})`}function U(e,t){const o=`#${encodeURIComponent(t)}`;(e.textref===o||e.textref?.startsWith(`${o}:~:`))&&(e.textref=R(`#${CSS.escape(t)}`)+e.textref.slice(o.length))}function v(e){if(!(!e||!e.startsWith(l)||!e.endsWith(")")))return decodeURIComponent(e.slice(l.length,-1))}const m="#domrange(",g=")";function $(e){return`${m}${encodeURIComponent(JSON.stringify(e))}${g}`}function p(e){if(!(!e||!e.startsWith(m)||!e.endsWith(g)))try{const t=JSON.parse(decodeURIComponent(e.slice(m.length,-g.length)));return!t?.start?.cssSelector||typeof t.start.textNodeIndex!="number"?void 0:t}catch{return}}const h=":~:text=";function a(e){return encodeURIComponent(e).replace(/-/g,"%2D")}function I(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)}`),`${h}${t}`}function C(e){if(!e)return;const t=e.indexOf(h);if(t===-1)return;const o=e.slice(t+h.length).split("&")[0];if(o)try{let n=o.split(",");const i={textStart:""};return n[0].endsWith("-")&&(i.prefix=decodeURIComponent(n[0].slice(0,-1)),n=n.slice(1)),n.length>0&&n[n.length-1].startsWith("-")&&(i.suffix=decodeURIComponent(n[n.length-1].slice(1)),n=n.slice(0,-1)),n.length===0||n[0]===""?void 0:(i.textStart=decodeURIComponent(n[0]),n.length>1&&(i.textEnd=decodeURIComponent(n[1])),i)}catch{return}}function E(e,t){if(!e.domRange||!t.domRange||e.href!==t.href)return;const o={start:e.domRange.start,end:t.domRange.end??t.domRange.start};e.domRange.container!==void 0&&(o.container=e.domRange.container);const n={domRange:o,cssSelector:o.container??o.start.cssSelector};return e.href!==void 0&&(n.href=e.href),n}function F(e){if(e.startsWith("#"))try{return decodeURIComponent(e.slice(1))}catch{return}}function D(e){const t=e?.textref;if(!t)return;const o=t.indexOf(":~:"),n=o===-1?t:t.slice(0,o),i=n.indexOf("#"),x=i===-1?n:n.slice(0,i),u=i===-1?"":n.slice(i);let d,s;const f=p(u);if(f)s=f,d=f.container??f.start.cssSelector;else{const S=v(u);S!==void 0?d=S:e.id&&F(u)===e.id&&(d=`#${CSS.escape(e.id)}`)}const r=C(t);if(d===void 0&&s===void 0&&r===void 0)return;const c={};return x!==""&&(c.href=x),d!==void 0&&(c.cssSelector=d),s!==void 0&&(c.domRange=s),r?.textEnd!==void 0?c.fragment=I(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{E as combineDomRangeTextrefs,v as decodeCssSelectorFragment,p as decodeDomRangeFragment,F as decodeIdFragment,C as decodeTextFragmentDirective,D as decodeTextref,U as detachSelfTextref,R as encodeCssSelectorFragment,$ as encodeDomRangeFragment,I as encodeTextFragmentDirective};
1
+ const l="#css(";function U(e){return`${l}${encodeURIComponent(e)})`}function x(e){if(!(!e||!e.startsWith(l)||!e.endsWith(")")))return decodeURIComponent(e.slice(l.length,-1))}const m="#domrange(",g=")";function $(e){return`${m}${encodeURIComponent(JSON.stringify(e))}${g}`}function I(e){if(!(!e||!e.startsWith(m)||!e.endsWith(g)))try{const n=JSON.parse(decodeURIComponent(e.slice(m.length,-g.length)));return!n?.start?.cssSelector||typeof n.start.textNodeIndex!="number"?void 0:n}catch{return}}const h=":~:text=";function a(e){return encodeURIComponent(e).replace(/-/g,"%2D")}function p(e){let n="";return e.prefix&&(n+=`${a(e.prefix)}-,`),n+=a(e.textStart),e.textEnd&&(n+=`,${a(e.textEnd)}`),e.suffix&&(n+=`,-${a(e.suffix)}`),`${h}${n}`}function F(e){if(!e)return;const n=e.indexOf(h);if(n===-1)return;const o=e.slice(n+h.length).split("&")[0];if(o)try{let t=o.split(",");const i={textStart:""};return t[0].endsWith("-")&&(i.prefix=decodeURIComponent(t[0].slice(0,-1)),t=t.slice(1)),t.length>0&&t[t.length-1].startsWith("-")&&(i.suffix=decodeURIComponent(t[t.length-1].slice(1)),t=t.slice(0,-1)),t.length===0||t[0]===""?void 0:(i.textStart=decodeURIComponent(t[0]),t.length>1&&(i.textEnd=decodeURIComponent(t[1])),i)}catch{return}}function E(e,n){if(!e.domRange||!n.domRange||e.href!==n.href)return;const o={start:e.domRange.start,end:n.domRange.end??n.domRange.start};e.domRange.container!==void 0&&(o.container=e.domRange.container);const t={domRange:o,cssSelector:o.container??o.start.cssSelector};return e.href!==void 0&&(t.href=e.href),t}function C(e){if(e.startsWith("#"))try{return decodeURIComponent(e.slice(1))}catch{return}}function D(e){const n=e?.textref;if(!n)return;const o=n.indexOf(":~:"),t=o===-1?n:n.slice(0,o),i=t.indexOf("#"),S=i===-1?t:t.slice(0,i),u=i===-1?"":t.slice(i);let d,s;const f=I(u);if(f)s=f,d=f.container??f.start.cssSelector;else{const R=x(u);if(R!==void 0)d=R;else{const v=C(u);v&&(d=`#${CSS.escape(v)}`)}}const r=F(n);if(d===void 0&&s===void 0&&r===void 0)return;const c={};return S!==""&&(c.href=S),d!==void 0&&(c.cssSelector=d),s!==void 0&&(c.domRange=s),r?.textEnd!==void 0?c.fragment=p(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{E as combineDomRangeTextrefs,x as decodeCssSelectorFragment,I as decodeDomRangeFragment,C as decodeIdFragment,F as decodeTextFragmentDirective,D as decodeTextref,U as encodeCssSelectorFragment,$ as encodeDomRangeFragment,p as encodeTextFragmentDirective};
@@ -130,12 +130,12 @@ Roles whose roles.md definition is "a list of links to X" or "a collection
130
130
  of X" (`landmarks`, `loa`, `loi`, `lot`, `lov`, `pagelist`, `toc`, `index`,
131
131
  `bibliography`, `glossary`, `endnotes`, `credits`) are modeled as an actual
132
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:
133
+ are. A `listItem` holding a link carries the link's visible `text`; the
134
+ link's destination isn't kept, since a `textref` always references the
135
+ object's own content:
136
136
 
137
137
  ```jsonc
138
- { "role": ["listItem"], "text": { "plain": "Cover" }, "textref": "cover.xhtml" }
138
+ { "role": ["listItem"], "text": { "plain": "Cover" } }
139
139
  ```
140
140
 
141
141
  ## `manifest.json`
@@ -37,7 +37,7 @@ renaming, or removing a fixture.
37
37
  | `epilogue` | `epilogue-epub-type`, `epilogue-role-aria` |
38
38
  | `errata` | `errata-epub-type`, `errata-role-aria` |
39
39
  | `example` | `example-epub-type`, `example-role-aria` |
40
- | `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`, `language-describedby-shared`, `language-figcaption`, `language-figcaption-credit`, `language-figcaption-switches`, `language-figcaption-switches-throughout` |
40
+ | `figure` | `figure-aria-label-caption`, `figure-basic-html-native`, `figure-basic-role-aria`, `figure-caption-block-content`, `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`, `language-describedby-shared`, `language-figcaption`, `language-figcaption-credit`, `language-figcaption-switches`, `language-figcaption-switches-throughout` |
41
41
  | `footnote` | `footnote-epub-type`, `footnote-role-aria`, `noteref-target-in-endnotes-epub-type`, `noteref-target-in-endnotes-role-aria` |
42
42
  | `foreword` | `foreword-epub-type`, `foreword-role-aria` |
43
43
  | `glossary` | `glossary-epub-type`, `glossary-role-aria` |
@@ -75,10 +75,10 @@ renaming, or removing a fixture.
75
75
  | `separator` | `separator-html-native`, `separator-role-aria`, `separator-with-glyphs` |
76
76
  | `subtitle` | `subtitle-epub-type`, `subtitle-role-aria` |
77
77
  | `summary` | `summary-html-native` |
78
- | `table` | `table-caption`, `table-caption-element-html-native`, `table-caption-role-aria`, `table-cell-abbreviation`, `table-cell-noteref`, `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` |
78
+ | `table` | `table-aria-label-caption`, `table-caption`, `table-caption-aria-labelledby`, `table-caption-element-html-native`, `table-caption-role-aria`, `table-cell-abbreviation`, `table-cell-noteref`, `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` |
79
79
  | `term` | `term-epub-type`, `term-html-native`, `term-role-aria`, `term-span-in-dt` |
80
80
  | `tip` | `tip-epub-type`, `tip-role-aria` |
81
81
  | `toc` | `toc-epub-type`, `toc-role-aria` |
82
82
  | `video` | `video-html-native`, `video-no-description` |
83
83
 
84
- 259 fixtures across 73 roles.
84
+ 263 fixtures across 73 roles.
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
8
6
  }
9
7
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> <emphasis>said</emphasis> so.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> <emphasis>said</emphasis> so."
8
6
  }
9
7
  }
@@ -1,24 +1,20 @@
1
1
  {
2
+ "role": ["paragraph"],
3
+ "text": {
4
+ "language": "en",
5
+ "plain": "The WHO said so.",
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> <emphasis>said</emphasis> so."
7
+ },
2
8
  "children": [
3
9
  {
10
+ "role": ["image"],
4
11
  "id": "image1",
5
- "imgref": "logo.png",
6
- "role": [
7
- "image"
8
- ],
9
12
  "description": {
10
13
  "text": {
11
14
  "plain": "logo"
12
15
  }
13
- }
16
+ },
17
+ "imgref": "logo.png"
14
18
  }
15
- ],
16
- "role": [
17
- "paragraph"
18
- ],
19
- "text": {
20
- "plain": "The WHO said so.",
21
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> <emphasis>said</emphasis> so.",
22
- "language": "en"
23
- }
19
+ ]
24
20
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
8
6
  }
9
7
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <lang xml:lang=\"fr\"><sub alias=\"Organisation mondiale de la santé\">OMS</sub></lang> said.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <lang xml:lang=\"fr\"><sub alias=\"Organisation mondiale de la santé\">OMS</sub></lang> said."
8
6
  }
9
7
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
8
6
  }
9
7
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"United States of America\">USA</sub> today.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"United States of America\">USA</sub> today."
8
6
  }
9
7
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub> said."
8
6
  }
9
7
  }
@@ -1,15 +1,11 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "children": [
6
4
  {
7
- "role": [
8
- "term"
9
- ],
5
+ "role": ["term"],
10
6
  "text": {
11
- "ssml": "<sub alias=\"World Health Organization\">WHO</sub>",
12
- "language": "en"
7
+ "language": "en",
8
+ "ssml": "<sub alias=\"World Health Organization\">WHO</sub>"
13
9
  }
14
10
  },
15
11
  {
@@ -1,4 +1,5 @@
1
1
  {
2
+ "role": ["paragraph"],
2
3
  "children": [
3
4
  {
4
5
  "text": {
@@ -6,12 +7,10 @@
6
7
  }
7
8
  },
8
9
  {
9
- "role": [
10
- "term"
11
- ],
10
+ "role": ["term"],
12
11
  "text": {
13
- "ssml": "<sub alias=\"Doctor\">Dr.</sub>",
14
- "language": "en"
12
+ "language": "en",
13
+ "ssml": "<sub alias=\"Doctor\">Dr.</sub>"
15
14
  }
16
15
  },
17
16
  {
@@ -19,8 +18,5 @@
19
18
  "plain": "Watson."
20
19
  }
21
20
  }
22
- ],
23
- "role": [
24
- "paragraph"
25
21
  ]
26
22
  }
@@ -1,7 +1,5 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
4
  "plain": "The WHO said."
7
5
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "The <sub alias=\"World Health Organization\">W.H.O.</sub> said.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "The <sub alias=\"World Health Organization\">W.H.O.</sub> said."
8
6
  }
9
7
  }
@@ -1,9 +1,7 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "text": {
6
- "ssml": "She joined the <sub alias=\"World Health Organization\">W.H.O.</sub> Then she left.",
7
- "language": "en"
4
+ "language": "en",
5
+ "ssml": "She joined the <sub alias=\"World Health Organization\">W.H.O.</sub> Then she left."
8
6
  }
9
7
  }
@@ -1,12 +1,8 @@
1
1
  {
2
- "role": [
3
- "paragraph"
4
- ],
2
+ "role": ["paragraph"],
5
3
  "children": [
6
4
  {
7
- "role": [
8
- "term"
9
- ],
5
+ "role": ["term"],
10
6
  "text": {
11
7
  "plain": "A"
12
8
  }
@@ -17,9 +13,7 @@
17
13
  }
18
14
  },
19
15
  {
20
- "role": [
21
- "term"
22
- ],
16
+ "role": ["term"],
23
17
  "text": {
24
18
  "plain": "B"
25
19
  }
@@ -1,24 +1,20 @@
1
1
  {
2
+ "role": ["paragraph"],
3
+ "text": {
4
+ "language": "en",
5
+ "plain": "The WHO said.",
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> said."
7
+ },
2
8
  "children": [
3
9
  {
10
+ "role": ["image"],
4
11
  "id": "image1",
5
- "imgref": "dot.png",
6
- "role": [
7
- "image"
8
- ],
9
12
  "description": {
10
13
  "text": {
11
14
  "plain": "dot"
12
15
  }
13
- }
16
+ },
17
+ "imgref": "dot.png"
14
18
  }
15
- ],
16
- "role": [
17
- "paragraph"
18
- ],
19
- "text": {
20
- "plain": "The WHO said.",
21
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> said.",
22
- "language": "en"
23
- }
19
+ ]
24
20
  }
@@ -1,39 +1,33 @@
1
1
  {
2
+ "role": ["paragraph"],
3
+ "text": {
4
+ "language": "en",
5
+ "plain": "The WHO and OED said.",
6
+ "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> and <sub alias=\"Organisation for Economic Co-operation and Development\">OED</sub><readium:math id=\"math1\" /> said."
7
+ },
2
8
  "children": [
3
9
  {
10
+ "role": ["image"],
4
11
  "id": "image1",
5
- "role": [
6
- "image"
7
- ],
8
- "textref": "#css(svg)",
9
12
  "description": {
10
13
  "text": {
11
14
  "plain": "dot"
12
15
  }
13
- }
16
+ },
17
+ "textref": "#css(svg)"
14
18
  },
15
19
  {
20
+ "role": ["math"],
16
21
  "id": "math1",
17
- "role": [
18
- "math"
19
- ],
20
- "text": {
21
- "ssml": "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" alttext=\"c\"><mi>c</mi></math>"
22
- },
23
- "textref": "#css(math)",
24
22
  "description": {
25
23
  "text": {
26
24
  "plain": "c"
27
25
  }
26
+ },
27
+ "textref": "#css(math)",
28
+ "text": {
29
+ "ssml": "<math xmlns=\"http://www.w3.org/1998/Math/MathML\" alttext=\"c\"><mi>c</mi></math>"
28
30
  }
29
31
  }
30
- ],
31
- "role": [
32
- "paragraph"
33
- ],
34
- "text": {
35
- "plain": "The WHO and OED said.",
36
- "ssml": "The <sub alias=\"World Health Organization\">WHO</sub><readium:image id=\"image1\" /> and <sub alias=\"Organisation for Economic Co-operation and Development\">OED</sub><readium:math id=\"math1\" /> said.",
37
- "language": "en"
38
- }
32
+ ]
39
33
  }