@readium/shared 2.3.0 → 2.4.0-alpha.1

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 (167) hide show
  1. package/LICENSE +28 -0
  2. package/README.MD +7 -8
  3. package/dist/ar-DyHX_uy2.js +7 -0
  4. package/dist/da-Dct0PS3E.js +7 -0
  5. package/dist/fr-C5HEel98.js +7 -0
  6. package/dist/index.js +4993 -1
  7. package/dist/index.umd.cjs +3 -0
  8. package/dist/it-DFOBoXGy.js +7 -0
  9. package/dist/pt_PT-Di3sVjze.js +7 -0
  10. package/dist/sv-BfzAFsVN.js +7 -0
  11. package/package.json +26 -33
  12. package/src/fetcher/HttpFetcher.ts +5 -5
  13. package/src/fetcher/Resource.ts +10 -5
  14. package/src/publication/Link.ts +6 -2
  15. package/src/publication/Locator.ts +3 -21
  16. package/src/publication/Manifest.ts +10 -10
  17. package/src/publication/Publication.ts +1 -2
  18. package/src/publication/accessibility/Localization.ts +14 -12
  19. package/src/publication/accessibility/SupportedLanguages.ts +1 -1
  20. package/src/publication/encryption/Properties.ts +15 -3
  21. package/src/publication/epub/Metadata.ts +12 -6
  22. package/src/publication/epub/Properties.ts +13 -3
  23. package/src/publication/epub/Publication.ts +39 -18
  24. package/src/publication/html/Locations.ts +101 -54
  25. package/src/publication/opds/Properties.ts +66 -21
  26. package/src/publication/opds/Publication.ts +9 -3
  27. package/src/publication/services/content/iterators/HTMLResourceContentIterator.ts +1 -3
  28. package/src/publication/services/timeline/Timeline.ts +59 -268
  29. package/src/publication/services/timeline/TimelineItem.ts +3 -3
  30. package/src/publication/services/timeline/index.ts +0 -12
  31. package/src/util/npt.ts +0 -19
  32. package/types/src/fetcher/HttpFetcher.d.ts +3 -3
  33. package/types/src/fetcher/Resource.d.ts +6 -2
  34. package/types/src/publication/encryption/Properties.d.ts +9 -2
  35. package/types/src/publication/epub/Metadata.d.ts +6 -3
  36. package/types/src/publication/epub/Properties.d.ts +10 -2
  37. package/types/src/publication/epub/Publication.d.ts +18 -7
  38. package/types/src/publication/html/Locations.d.ts +44 -15
  39. package/types/src/publication/opds/Properties.d.ts +36 -8
  40. package/types/src/publication/opds/Publication.d.ts +5 -2
  41. package/types/src/publication/services/timeline/Timeline.d.ts +12 -78
  42. package/types/src/publication/services/timeline/TimelineItem.d.ts +3 -3
  43. package/types/src/publication/services/timeline/index.d.ts +0 -6
  44. package/types/src/util/npt.d.ts +0 -10
  45. package/dist/_virtual/preload-helper.js +0 -1
  46. package/dist/fetcher/Fetcher.js +0 -1
  47. package/dist/fetcher/HttpFetcher.js +0 -1
  48. package/dist/fetcher/Resource.js +0 -1
  49. package/dist/locales/publication-metadata/ar.json.js +0 -1
  50. package/dist/locales/publication-metadata/da.json.js +0 -1
  51. package/dist/locales/publication-metadata/el.json.js +0 -1
  52. package/dist/locales/publication-metadata/en.json.js +0 -1
  53. package/dist/locales/publication-metadata/es.json.js +0 -1
  54. package/dist/locales/publication-metadata/et.json.js +0 -1
  55. package/dist/locales/publication-metadata/fi.json.js +0 -1
  56. package/dist/locales/publication-metadata/fr.json.js +0 -1
  57. package/dist/locales/publication-metadata/it.json.js +0 -1
  58. package/dist/locales/publication-metadata/pl.json.js +0 -1
  59. package/dist/locales/publication-metadata/pt_PT.json.js +0 -1
  60. package/dist/locales/publication-metadata/sv.json.js +0 -1
  61. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/constants.js +0 -1
  62. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/index.js +0 -1
  63. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-attribute.js +0 -1
  64. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-class.js +0 -1
  65. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-fallback.js +0 -1
  66. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-id.js +0 -1
  67. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-nth-child.js +0 -1
  68. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-nth-of-type.js +0 -1
  69. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/selector-tag.js +0 -1
  70. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/types.js +0 -1
  71. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-cartesian.js +0 -1
  72. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-data.js +0 -1
  73. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-dom.js +0 -1
  74. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-element-data.js +0 -1
  75. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-iselement.js +0 -1
  76. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-messages.js +0 -1
  77. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-options.js +0 -1
  78. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-powerset.js +0 -1
  79. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-selectors.js +0 -1
  80. package/dist/node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/utilities-typescript.js +0 -1
  81. package/dist/opds/Acquisition.js +0 -1
  82. package/dist/opds/Availability.js +0 -1
  83. package/dist/opds/Copies.js +0 -1
  84. package/dist/opds/Holds.js +0 -1
  85. package/dist/opds/Price.js +0 -1
  86. package/dist/publication/AltIdentifier.js +0 -1
  87. package/dist/publication/BelongsTo.js +0 -1
  88. package/dist/publication/Contributor.js +0 -1
  89. package/dist/publication/GuidedNavigation.js +0 -1
  90. package/dist/publication/Layout.js +0 -1
  91. package/dist/publication/Link.js +0 -1
  92. package/dist/publication/LocalizedString.js +0 -1
  93. package/dist/publication/Locator.js +0 -1
  94. package/dist/publication/LocatorCollection.js +0 -1
  95. package/dist/publication/Manifest.js +0 -1
  96. package/dist/publication/Metadata.js +0 -1
  97. package/dist/publication/Profiles.js +0 -1
  98. package/dist/publication/Properties.js +0 -1
  99. package/dist/publication/Publication.js +0 -1
  100. package/dist/publication/PublicationCollection.js +0 -1
  101. package/dist/publication/ReadingProgression.js +0 -1
  102. package/dist/publication/Subject.js +0 -1
  103. package/dist/publication/TDM.js +0 -1
  104. package/dist/publication/accessibility/Accessibility.js +0 -1
  105. package/dist/publication/accessibility/AccessibilityMetadataDisplayGuide.js +0 -1
  106. package/dist/publication/accessibility/Localization.js +0 -1
  107. package/dist/publication/accessibility/SupportedLanguages.js +0 -1
  108. package/dist/publication/encryption/Encryption.js +0 -1
  109. package/dist/publication/encryption/Properties.js +0 -1
  110. package/dist/publication/encryption/index.js +0 -1
  111. package/dist/publication/epub/MediaOverlay.js +0 -1
  112. package/dist/publication/epub/Metadata.js +0 -1
  113. package/dist/publication/epub/Properties.js +0 -1
  114. package/dist/publication/epub/Publication.js +0 -1
  115. package/dist/publication/epub/index.js +0 -1
  116. package/dist/publication/html/DomRange.js +0 -1
  117. package/dist/publication/html/DomRangePoint.js +0 -1
  118. package/dist/publication/html/Locations.js +0 -1
  119. package/dist/publication/html/index.js +0 -1
  120. package/dist/publication/opds/Properties.js +0 -1
  121. package/dist/publication/opds/Publication.js +0 -1
  122. package/dist/publication/opds/index.js +0 -1
  123. package/dist/publication/services/content/Content.js +0 -2
  124. package/dist/publication/services/content/ContentTokenizer.js +0 -1
  125. package/dist/publication/services/content/Iterator.js +0 -1
  126. package/dist/publication/services/content/element/attributes.js +0 -1
  127. package/dist/publication/services/content/element/element.js +0 -1
  128. package/dist/publication/services/content/element/text_role.js +0 -1
  129. package/dist/publication/services/content/iterators/HTMLResourceContentIterator.js +0 -1
  130. package/dist/publication/services/content/iterators/PDFTextContentIterator.js +0 -1
  131. package/dist/publication/services/content/iterators/PublicationContentIterator.js +0 -1
  132. package/dist/publication/services/content/iterators/helpers.js +0 -1
  133. package/dist/publication/services/timeline/Timeline.js +0 -1
  134. package/dist/publication/services/timeline/audio.js +0 -1
  135. package/dist/publication/services/timeline/html.js +0 -1
  136. package/dist/publication/services/timeline/index.js +0 -1
  137. package/dist/util/JSONParse.js +0 -1
  138. package/dist/util/URITemplate.js +0 -1
  139. package/dist/util/mediatype/MediaType.js +0 -1
  140. package/dist/util/npt.js +0 -1
  141. package/dist/util/tokenizer/TextTokenizer.js +0 -1
  142. package/dist/util/tokenizer/tokenize-english/abbreviations.js +0 -1
  143. package/dist/util/tokenizer/tokenize-english/index.js +0 -2
  144. package/dist/util/tokenizer/tokenize-english/utils.js +0 -1
  145. package/dist/util/tokenizer/tokenize-text/index.js +0 -1
  146. package/dist/util/tokenizer/tokenize-text/tokens.js +0 -1
  147. package/src/locales/publication-metadata/ar.json +0 -402
  148. package/src/locales/publication-metadata/brh.json +0 -1
  149. package/src/locales/publication-metadata/da.json +0 -310
  150. package/src/locales/publication-metadata/el.json +0 -310
  151. package/src/locales/publication-metadata/en.json +0 -310
  152. package/src/locales/publication-metadata/es.json +0 -333
  153. package/src/locales/publication-metadata/et.json +0 -310
  154. package/src/locales/publication-metadata/fi.json +0 -310
  155. package/src/locales/publication-metadata/fr.json +0 -333
  156. package/src/locales/publication-metadata/he.json +0 -9
  157. package/src/locales/publication-metadata/it.json +0 -333
  158. package/src/locales/publication-metadata/lt.json +0 -8
  159. package/src/locales/publication-metadata/pl.json +0 -333
  160. package/src/locales/publication-metadata/pt_PT.json +0 -329
  161. package/src/locales/publication-metadata/sv.json +0 -310
  162. package/src/locales/publication-metadata/tr.json +0 -51
  163. package/src/locales/publication-metadata/uk.json +0 -1
  164. package/src/publication/services/timeline/audio.ts +0 -31
  165. package/src/publication/services/timeline/html.ts +0 -5
  166. package/types/src/publication/services/timeline/audio.d.ts +0 -4
  167. package/types/src/publication/services/timeline/html.d.ts +0 -4
@@ -1 +0,0 @@
1
- class e{constructor(i){this.algorithm=i.algorithm,this.compression=i.compression,this.originalLength=i.originalLength,this.profile=i.profile,this.scheme=i.scheme}static deserialize(i){if(i&&i.algorithm)return new e({algorithm:i.algorithm,compression:i.compression,originalLength:i.originalLength,profile:i.profile,scheme:i.scheme})}serialize(){const i={algorithm:this.algorithm};return this.compression!==void 0&&(i.compression=this.compression),this.originalLength!==void 0&&(i.originalLength=this.originalLength),this.profile!==void 0&&(i.profile=this.profile),this.scheme!==void 0&&(i.scheme=this.scheme),i}}export{e as Encryption};
@@ -1 +0,0 @@
1
- import{Encryption as e}from"./Encryption.js";function n(r){return e.deserialize(r.otherProperties.encrypted)}export{n as getEncryption};
@@ -1 +0,0 @@
1
- import{Encryption as t}from"./Encryption.js";import{getEncryption as p}from"./Properties.js";export{t as Encryption,p as getEncryption};
@@ -1 +0,0 @@
1
- class a{constructor(s){this.activeClass=s.activeClass,this.playbackActiveClass=s.playbackActiveClass}static deserialize(s){if(s)return new a({activeClass:s.activeClass,playbackActiveClass:s.playbackActiveClass})}serialize(){const s={};return this.activeClass&&(s.activeClass=this.activeClass),this.playbackActiveClass&&(s.playbackActiveClass=this.playbackActiveClass),s}}export{a as MediaOverlay};
@@ -1 +0,0 @@
1
- import{MediaOverlay as a}from"./MediaOverlay.js";function i(r){const e=r.otherMetadata?.mediaOverlay;if(e)return a.deserialize(e)}export{i as getMediaOverlay};
@@ -1 +0,0 @@
1
- function e(t){return new Set(t.otherProperties.contains||[])}export{e as getContains};
@@ -1 +0,0 @@
1
- function i(t){return t.linksWithRole("pageList")}function n(t){return t.linksWithRole("landmarks")}function e(t){return t.linksWithRole("loa")}function l(t){return t.linksWithRole("loi")}function o(t){return t.linksWithRole("lot")}function s(t){return t.linksWithRole("lov")}export{n as getLandmarks,e as getListOfAudioClips,l as getListOfIllustrations,o as getListOfTables,s as getListOfVideoClips,i as getPageList};
@@ -1 +0,0 @@
1
- import{MediaOverlay as i}from"./MediaOverlay.js";import{getMediaOverlay as r}from"./Metadata.js";import{getContains as a}from"./Properties.js";import{getLandmarks as f,getListOfAudioClips as l,getListOfIllustrations as p,getListOfTables as L,getListOfVideoClips as O,getPageList as d}from"./Publication.js";export{i as MediaOverlay,a as getContains,f as getLandmarks,l as getListOfAudioClips,p as getListOfIllustrations,L as getListOfTables,O as getListOfVideoClips,r as getMediaOverlay,d as getPageList};
@@ -1 +0,0 @@
1
- import{DomRangePoint as r}from"./DomRangePoint.js";class i{constructor(t){this.start=t.start,this.end=t.end}static deserialize(t){if(!t)return;let e=r.deserialize(t.start);if(e)return new i({start:e,end:r.deserialize(t.end)})}serialize(){const t={start:this.start.serialize()};return this.end&&(t.end=this.end.serialize()),t}}export{i as DomRange};
@@ -1 +0,0 @@
1
- import{positiveNumberfromJSON as r}from"../../util/JSONParse.js";class c{constructor(e){this.cssSelector=e.cssSelector,this.textNodeIndex=e.textNodeIndex,this.charOffset=e.charOffset}static deserialize(e){if(!(e&&e.cssSelector))return;let s=r(e.textNodeIndex);if(s===void 0)return;let t=r(e.charOffset);return t===void 0&&(t=r(e.offset)),new c({cssSelector:e.cssSelector,textNodeIndex:s,charOffset:t})}serialize(){const e={cssSelector:this.cssSelector,textNodeIndex:this.textNodeIndex};return this.charOffset!==void 0&&(e.charOffset=this.charOffset),e}}export{c as DomRangePoint};
@@ -1 +0,0 @@
1
- import{DomRange as u}from"./DomRange.js";import{parseNptTime as h}from"../../util/npt.js";function x(e){return e.otherLocations?.get("cssSelector")}function C(e){return e.otherLocations?.get("partialCfi")}function L(e){return u.deserialize(e.otherLocations?.get("domRange"))}function n(e){return new Map(e.fragments.map(t=>t.startsWith("#")?t.slice(1):t).join("&").split("&").filter(t=>!t.startsWith("#")).map(t=>t.split("=")).filter(t=>t.length===2).map(t=>[t[0].trim().toLowerCase(),t[1].trim()]))}function N(e){if(!e.fragments.length)return;let t=e.fragments.find(r=>r.length&&!r.includes("="));if(!t){const r=n(e);r.has("id")?t=r.get("id"):r.has("name")&&(t=r.get("name"))}return t?.startsWith("#")?t.slice(1):t}function W(e){const t=parseInt(n(e).get("page"));if(!isNaN(t)&&t>=0)return t}function R(e){const t=n(e).get("t");if(t)return h(t)}function y(e){const t=n(e);if(!t.has("xywh"))return;const r=t.get("xywh");let i="pixel",s=r;const o=r.toLowerCase();o.startsWith("pixel:")?s=r.slice(6):o.startsWith("percent:")&&(i="percent",s=r.slice(8));const c=i==="percent"?parseFloat:m=>parseInt(m,10),a=s.split(",").map(c);if(a.length!==4||a.some(isNaN))return;const[g,p,f,l]=a;return{unit:i,x:g,y:p,width:f,height:l}}export{x as getCssSelector,L as getDomRange,n as getFragmentParameters,N as getHtmlId,W as getPage,C as getPartialCfi,y as getSpace,R as getTime};
@@ -1 +0,0 @@
1
- import{DomRange as g}from"./DomRange.js";import{DomRangePoint as r}from"./DomRangePoint.js";import{getCssSelector as m,getDomRange as n,getFragmentParameters as f,getHtmlId as i,getPage as p,getPartialCfi as P,getSpace as l,getTime as s}from"./Locations.js";export{g as DomRange,r as DomRangePoint,m as getCssSelector,n as getDomRange,f as getFragmentParameters,i as getHtmlId,p as getPage,P as getPartialCfi,l as getSpace,s as getTime};
@@ -1 +0,0 @@
1
- import{positiveNumberfromJSON as t}from"../../util/JSONParse.js";import{Link as o}from"../Link.js";import{Price as n}from"../../opds/Price.js";import{Acquisition as s}from"../../opds/Acquisition.js";import{Holds as u}from"../../opds/Holds.js";import{Copies as m}from"../../opds/Copies.js";import{Availability as p}from"../../opds/Availability.js";function A(e){return t(e.otherProperties.numberOfItems)}function g(e){return n.deserialize(e.otherProperties.price)}function b(e){const r=e.otherProperties.indirectAcquisition;if(r&&Array.isArray(r))return r.map(i=>s.deserialize(i)).filter(i=>i!==void 0)}function z(e){return u.deserialize(e.otherProperties.holds)}function v(e){return m.deserialize(e.otherProperties.copies)}function y(e){return p.deserialize(e.otherProperties.availability)}function q(e){return o.deserialize(e.otherProperties.authenticate)}export{q as getAuthenticate,y as getAvailability,v as getCopies,z as getHolds,b as getIndirectAcquisitions,A as getNumberOfItems,g as getPrice};
@@ -1 +0,0 @@
1
- function t(e){return e.linksWithRole("images")}export{t as getImages};
@@ -1 +0,0 @@
1
- import{getAuthenticate as i,getAvailability as g,getCopies as o,getHolds as r,getIndirectAcquisitions as s,getNumberOfItems as m,getPrice as a}from"./Properties.js";import{getImages as f}from"./Publication.js";export{i as getAuthenticate,g as getAvailability,o as getCopies,r as getHolds,f as getImages,s as getIndirectAcquisitions,m as getNumberOfItems,a as getPrice};
@@ -1,2 +0,0 @@
1
- class r{text(e=`
2
- `){return this.elements().map(t=>t?.text).filter(t=>t!==void 0&&t.length>0).join(e)}elements(){const e=[],t=this.iterator();for(;t.hasNext();)e.push(t.next());return e}}export{r as Content};
@@ -1 +0,0 @@
1
- import{Locator as c,LocatorText as x}from"../../Locator.js";import{DefaultTextContentTokenizer as l}from"../../../util/tokenizer/TextTokenizer.js";import{TextElement as i,TextSegment as h}from"./element/element.js";class p{constructor(t,e,o=50,n=r=>l(r,e)){this.defaultLanguage=t,this.contextSnippetLength=o,this.textTokenizerFactory=n}tokenize(t){return t instanceof i?[new i(t.locator,t.role,t.segments.map(e=>this.tokenizeSegment(e)).flat())]:[t]}tokenizeSegment(t){return this.textTokenizerFactory(t.language??this.defaultLanguage).tokenize(t.text).map(e=>new h(new c({href:t.locator.href,type:t.locator.type,title:t.locator.title,locations:t.locator.locations,text:this.extractTextContextIn(t.text,e)}),t.text.substring(e[0],e[1]),t._attributes))}extractTextContextIn(t,e){const o=t.substring(e[1],e[1]+this.contextSnippetLength),n=t.substring(e[0]-this.contextSnippetLength,e[0]);return new x({after:o.length>0?o:void 0,before:n.length>0?n:void 0,highlight:t.substring(e[0],e[1])})}}export{p as TextContentTokenizer};
@@ -1 +0,0 @@
1
- class s extends Error{constructor(t){super(t)}}class e{async nextOrNull(){return await this.hasNext()?this.next():null}async previousOrNull(){return await this.hasPrevious()?this.previous():null}}export{s as IllegalStateError,e as Iterator};
@@ -1 +0,0 @@
1
- class r{constructor(t,e){this.key=t,this.value=e}}var i=(a=>(a.ACCESSIBILITY_LABEL="accessibilityLabel",a.LANGUAGE="language",a))(i||{});class s{constructor(t=[]){this._attributes=t}get language(){return this.attribute("language")}get accessibilityLabel(){return this.attribute("accessibilityLabel")}attribute(t){return this._attributes.find(e=>e.key===t)?.value}attributes(t){return this._attributes.filter(e=>e.key===t).map(e=>e.value)}}export{r as Attribute,i as AttributeKeys,s as AttributesHolder};
@@ -1 +0,0 @@
1
- import{AttributesHolder as i}from"./attributes.js";class c extends i{constructor(t,e=[]){super(e),this.locator=t}}class r extends c{get text(){return this.accessibilityLabel}}class d extends r{constructor(t,e,s=[]){super(t,s),this.embeddedLink=e}}class u extends r{constructor(t,e,s=[]){super(t,s),this.embeddedLink=e}}class a extends r{constructor(t,e,s,o=[]){super(t,o),this.embeddedLink=e,this.caption=s}get text(){return(this.caption?.length||0)>0?this.caption:super.text}}class x extends i{constructor(t,e,s=[]){super(s),this.locator=t,this.text=e}}class m extends r{constructor(t,e,s,o=[]){super(t,o),this.role=e,this.segments=s}get text(){return this.segments.map(t=>t.text).join("")}}export{d as AudioElement,c as ContentElement,a as ImageElement,m as TextElement,x as TextSegment,r as TextualElement,u as VideoElement};
@@ -1 +0,0 @@
1
- class r{constructor(e){this.level=e}get role(){return`heading-${this.level}`}}const s={role:"body"},l={role:"footnote"};class n{constructor(e,o){this.referenceUrl=e,this.referenceTitle=o,this.role="quote"}}export{s as Body,l as Footnote,r as Heading,n as TextQuote};
@@ -1 +0,0 @@
1
- import{Link as h,Links as A}from"../../../Link.js";import{Locator as u,LocatorLocations as p}from"../../../Locator.js";import{Iterator as L,IllegalStateError as d}from"../Iterator.js";import{trimmingTextLocator as w,isInlineTag as b,srcRelativeToHref as m,isBlank as f,elementLanguage as R,appendNormalizedWhitespace as S,trimUnicodeSpaceEnd as T,trimUnicodeSpace as y,trimUnicodeSpaceStart as N}from"./helpers.js";import{getCssSelector as I}from"../../../../node_modules/.pnpm/css-selector-generator@3.8.0/node_modules/css-selector-generator/esm/index.js";import{getCssSelector as C}from"../../../html/Locations.js";import{ImageElement as M,VideoElement as k,AudioElement as v,TextSegment as U,TextElement as H}from"../element/element.js";import{Attribute as x,AttributeKeys as E}from"../element/attributes.js";import{TextQuote as O,Heading as B,Body as D,Footnote as _}from"../element/text_role.js";class $ extends L{constructor(e,t,s=50){super(),this.resource=e,this.locator=t,this.beforeMaxLength=s,this.currentElement=null,this.currentIndex=null,this.parsedElementRecipes=null,this.parser=null}async hasPrevious(){if(this.currentElement?.delta===-1)return!0;const e=await this.elements(),t=(this.currentIndex??e.startIndex)-1,s=e.elements.at(t);return s?(this.currentIndex=t,this.currentElement={delta:-1,element:this.parser.executeRecipe(s)},!0):!1}previous(){if(!this.currentElement||this.currentElement.delta!==-1)throw new d("Called previous() without a successful call to hasPrevious() first");const e=this.currentElement.element;return this.currentElement=null,e}async hasNext(){if(this.currentElement?.delta===1)return!0;const e=await this.elements(),t=(this.currentIndex??e.startIndex-1)+1,s=e.elements.at(t);return s?(this.currentIndex=t,this.currentElement={delta:1,element:this.parser.executeRecipe(s)},!0):!1}next(){if(!this.currentElement||this.currentElement.delta!==1)throw new d("Called next() without a successful call to hasNext() first");const e=this.currentElement.element;return this.currentElement=null,e}async elements(){return this.parsedElementRecipes??=await this.parseElements(),this.parsedElementRecipes}async parseElements(){const e=await this.resource.readAsString(),t=new DOMParser().parseFromString(e,this.locator.type),s=C(this.locator.locations);return this.parser=new P(t,this.locator,s?t.querySelector(s):null,this.beforeMaxLength),G(this.parser,t.body),this.parser.result()}}function G(a,e){let t=e,s=0;for(;t!=null;)if(a.head(t,s),t.firstChild!=null)t=t.firstChild,s++;else{for(;t?.nextSibling==null&&s>0;)t&&a.tail(t,s),t=t?.parentNode||null,s--;if(t&&a.tail(t,s),t===e)break;t=t?.nextSibling||null}}class P{constructor(e,t,s,i){this.doc=e,this.baseLocator=t,this.startElement=s,this.beforeMaxLength=i,this.elementRecipes=[],this.startIndex=0,this.segmentRecipesAcc=[],this.textAcc="",this.wholeRawTextAcc=null,this.elementRawTextAcc="",this.rawTextAcc="",this.currentLanguage=null,this.breadcrumbs=[],this.recipeCssSelectorCache=new WeakMap}result(){return{elements:this.elementRecipes,startIndex:this.baseLocator.locations.progression===1?this.elementRecipes.length:this.startIndex}}executeRecipe(e){const t=e.recipe.cssSelectorNode?this.cssSelector(e.recipe.cssSelectorNode):null;if(e.type===1){const s=e.recipe;return new M(new u({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,locations:new p(t?{otherLocations:new Map([["cssSelector",t]])}:{})}),new h({href:s.href}),s.caption,s.attributes)}else if(e.type===2||e.type===3){const s=new u({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,locations:new p(t?{otherLocations:new Map([["cssSelector",t]])}:{})}),i=e.recipe;return e.type===3?new k(s,i.link):new v(s,i.link)}else if(e.type===0){const s=e.recipe,i=s.segments.map(r=>{const o=r.cssSelectorNode?this.cssSelector(r.cssSelectorNode):null;return new U(new u({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,text:w(r.text,this.wholeRawTextAcc?.substring(r.beforeRange[0],r.beforeRange[1])),locations:new p(o?{otherLocations:new Map([["cssSelector",o]])}:{})}),r.text,r.attributes)});return new H(new u({href:this.baseLocator.href,type:this.baseLocator.type,title:this.baseLocator.title,text:w(s.text,i.length&&i[0].locator.text?.before||""),locations:new p(t?{otherLocations:new Map([["cssSelector",t]])}:{})}),s.role,i)}else throw new Error("Unknown recipe type")}cssSelector(e){const t=e,s=this.recipeCssSelectorCache.get(t);if(s)return s;const i=new Map;let r=t;for(;r&&r!==this.doc.body;){for(let n=0;n<r.attributes.length;n++){const c=r.attributes[n];c.prefix&&(i.has(r)?i.set(r,i.get(r).concat([c])):i.set(r,[c]),r.attributes.removeNamedItem(c.name))}r=r.parentElement}const o=I(t,{root:this.doc});return i.forEach((n,c)=>n.forEach(l=>c.attributes.setNamedItem(l))),this.recipeCssSelectorCache.set(t,o),o}head(e,t){if(e.nodeType==Node.ELEMENT_NODE){const s=!b(e);s&&(this.flushText(),this.breadcrumbs.push(e));const i=e.nodeName.toUpperCase();if(i==="BR")this.flushText();else if(i==="IMG"||i==="AUDIO"||i==="VIDEO")if(this.flushText(),i==="IMG"){const r=e,o=m(r,this.baseLocator.href);let n=r.getAttribute("alt");n?.length||(n=r.getAttribute("title")),o!=null&&this.elementRecipes.push({type:1,recipe:{href:o,caption:void 0,cssSelectorNode:e,attributes:n?.length?[new x(E.ACCESSIBILITY_LABEL,n)]:[]}})}else{const r=e,o=m(r,this.baseLocator.href);let n;if(o!=null)n=new h({href:o});else{const c=[...r.getElementsByTagName("source")].map(l=>{const g=m(l,this.baseLocator.href);return g?new h({href:g,type:l.getAttribute("type")||void 0}):null}).filter(l=>!!l);c.length>0&&(n=new h({href:c[0].href,type:c[0].type,alternates:c.length>1?new A(c.slice(1)):void 0}))}n&&(i==="AUDIO"?this.elementRecipes.push({type:2,recipe:{cssSelectorNode:e,link:n}}):i==="VIDEO"&&this.elementRecipes.push({type:3,recipe:{cssSelectorNode:e,link:n}}))}s&&this.flushText()}}tail(e,t){if(e.nodeType===Node.TEXT_NODE&&!f(e.textContent)){const s=R(e.parentElement);this.currentLanguage!==s&&(this.flushSegment(),this.currentLanguage=s),this.rawTextAcc+=e.textContent,this.textAcc=S(this.textAcc,e.textContent)}else if(e.nodeType===Node.ELEMENT_NODE&&!b(e)){if(!this.breadcrumbs.length||this.breadcrumbs.at(-1)!==e)throw new Error("HTMLContentIterator: breadcrumbs mismatch");this.flushText(),this.breadcrumbs.pop()}}flushText(){if(this.flushSegment(),this.startIndex===0&&this.startElement&&this.breadcrumbs.length&&this.breadcrumbs.at(-1)===this.startElement&&(this.startIndex=this.elementRecipes.length),!this.segmentRecipesAcc.length)return;this.segmentRecipesAcc[this.segmentRecipesAcc.length-1].text=T(this.segmentRecipesAcc[this.segmentRecipesAcc.length-1].text);let e=D;if(this.breadcrumbs.length>0){const t=this.breadcrumbs.at(-1);if(t.getAttributeNS("http://www.idpf.org/2007/ops","type")==="footnote")e=_;else switch(t.nodeName.toUpperCase()){case"H1":case"H2":case"H3":case"H4":case"H5":case"H6":e=new B(parseInt(t.nodeName[1]));break;case"BLOCKQUOTE":case"Q":e=new O(t.getAttribute("cite")?.length?new URL(t.getAttribute("cite")):void 0,t.getAttribute("title")||void 0);break}}this.elementRecipes.push({type:0,recipe:{text:this.elementRawTextAcc,role:e,segments:[...this.segmentRecipesAcc],cssSelectorNode:this.breadcrumbs.at(-1)}}),this.elementRawTextAcc="",this.segmentRecipesAcc=[]}flushSegment(){let e=this.textAcc;const t=y(e);if(!f(t)){if(!this.segmentRecipesAcc.length){e=N(e);const s=e.length&&f(e[e.length-1])?e[e.length-1]:"";e=t+s}this.segmentRecipesAcc.push({text:e,attributes:this.currentLanguage?[new x(E.LANGUAGE,this.currentLanguage)]:[],beforeRange:this.wholeRawTextAcc?[this.wholeRawTextAcc.length-this.beforeMaxLength,this.wholeRawTextAcc.length]:[0,0],cssSelectorNode:this.breadcrumbs.at(-1)})}this.rawTextAcc.length&&(this.wholeRawTextAcc=(this.wholeRawTextAcc||"")+this.rawTextAcc,this.elementRawTextAcc+=this.rawTextAcc),this.rawTextAcc="",this.textAcc=""}}export{$ as HTMLResourceContentIterator};
@@ -1 +0,0 @@
1
- import{Locator as l}from"../../../Locator.js";import{Iterator as u,IllegalStateError as h}from"../Iterator.js";import{ContentElement as c}from"../element/element.js";class s extends c{constructor(e,t,r=[]){super(e,r),this.element=t}get text(){return this.element.text}}class o{constructor(e,t){this.element=e,this.direction=t}}class m extends u{constructor(e,t){super(),this.pageContent=e,this.startLocator=t,this.pageContentFiltered=[],this.currentElement=null,this.currentProgression=0,this.currentElementIndex=0;const r=this.pageContent.filter(n=>n?.str!==" "&&n?.str!=="");if(this.pageContentFiltered=r.map(n=>new s(n.locator,{index:r.indexOf(n),text:n.str,readingDirection:n.dir})),this.startLocator&&(this.currentProgression=this.startLocator?.locations?.progression||0,this.updateElementIndex()),this.pageContentFiltered.length>0){const n=this.currentElementIndex;(n||n===0)&&(this.currentElement=new o(this.pageContentFiltered[n],1))}}current(){return this.currentElement?this.currentElement.element:null}async hasPrevious(){return this.currentElement?.direction,this.nextIn(-1)!==null}previous(){if(!this.currentElement)throw new h("Called next() without a successful call to hasNext() first");if(this.currentElement=this.nextIn(-1),this.currentElementIndex&&this.currentElementIndex>0){const e=this.currentElementIndex-1;this.currentProgression=e/this.pageContentFiltered.length*100,this.currentElementIndex=e}return this.currentElement?this.currentElement.element:new s(new l({href:"",type:""}),{index:-1,text:""})}async hasNext(){return this.currentElement?.direction,this.nextIn(1)!==null}next(){this.currentElement=this.nextIn(1);const e=this.currentElementIndex;if(e!==null&&e>=0&&e<this.pageContentFiltered.length-1){const t=e+1;this.currentProgression=t/this.pageContentFiltered.length*100,this.currentElementIndex=t}return this.currentElement?this.currentElement.element:new s(new l({href:"",type:""}),{index:-1,text:""})}nextIn(e){const t=this.currentElementIndex;if(t===null||t===this.pageContentFiltered.length-1&&e===1||t===0&&e===-1)return null;const r=this.pageContentFiltered[t+e];return r?new o(r,e):null}updateElementIndex(){return this.currentProgression===0?0:this.currentProgression<0||this.currentProgression>=100?null:Math.floor(this.currentProgression*this.pageContentFiltered.length/100)}}export{s as PDFContentElement,m as PageContentIteratorPDF};
@@ -1 +0,0 @@
1
- import{Iterator as c,IllegalStateError as o}from"../Iterator.js";class l{constructor(t,r){this.index=t,this.iterator=r}async nextContentIn(t){return t===1?this.iterator.nextOrNull():this.iterator.previousOrNull()}}class h{constructor(t,r){this.element=t,this.direction=r}}class f extends c{constructor(t,r,e){super(),this.publication=t,this.startLocator=r,this.resourceContentIteratorFactories=e,this._currentIterator=null,this.currentElement=null}async hasPrevious(){return this.currentElement=await this.nextIn(-1),this.currentElement!==null}previous(){if(this.currentElement?.direction!==-1)throw new o("Called previous() without a successful call to hasPrevious() first");return this.currentElement.element}async hasNext(){return this.currentElement=await this.nextIn(1),this.currentElement!==null}next(){if(this.currentElement?.direction!==1)throw new o("Called next() without a successful call to hasNext() first");return this.currentElement.element}async nextIn(t){const r=this.currentIterator;if(!r)return null;const e=await r.nextContentIn(t);if(!e){const n=this.nextIteratorIn(t,r.index);return n?(this._currentIterator=n,this.nextIn(t)):null}return new h(e,t)}get currentIterator(){return this._currentIterator||(this._currentIterator=this.initialIterator()),this._currentIterator}initialIterator(){const t=this.startLocator?this.publication.readingOrder.findIndexWithHref(this.startLocator.href):0,r=this.startLocator||0;return this.loadIteratorAt(t,r)??this.nextIteratorIn(1,t)}nextIteratorIn(t,r){const e=r+t;if(e<0||e>=this.publication.manifest.readingOrder.items.length)return null;const n=t===1?0:1;return this.loadIteratorAt(e,n)??this.nextIteratorIn(t,e)}loadIteratorAt(t,r){const e=this.publication.readingOrder.items[t],n=typeof r=="number"?this.publication.manifest.locatorFromLink(e)?.copyWithLocations({progression:r}):r;if(!n)return null;const a=this.publication.get(e);for(const u of this.resourceContentIteratorFactories){const s=u(a,n);if(s)return new l(t,s)}return null}}export{f as PublicationContentIterator};
@@ -1 +0,0 @@
1
- import{LocatorText as g}from"../../../Locator.js";const A=["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","DEVICE","BASEFONT","BGSOUND","MENUITEM","DATA","BDI","S","STRIKE","NOBR","RB"];function p(e){return A.includes(e.nodeName.toUpperCase())}function B(e,t){const n=e.getAttribute("src");if(!n?.length)return null;try{return new URL(n,t).toString()}catch{return n}}const i="[\\s\\u0085\\u00A0\\u2000-\\u200A\\u2028\\u2029\\u202F\\u205F\\u3000]",T=new RegExp(`^${i}+$`,"g"),s=new RegExp(`^${i}+|${i}+$/g`,"g"),l=new RegExp(`^${i}+`,"g"),E=new RegExp(`${i}+$`,"g"),R=e=>e?.length?T.test(e):!0,u=e=>e.replace(s,""),N=e=>e.replace(l,""),M=e=>e.replace(E,""),U=(e,t="")=>new g({before:t+(l.exec(e)?.[0]??""),highlight:u(e),after:E.exec(e)?.[0]??""});function h(e){for(;e;){let t=e.getAttribute("lang")||e.getAttributeNS("http://www.w3.org/1999/xhtml","lang")||e.getAttributeNS("http://www.w3.org/XML/1998/namespace","lang");if(t)return t;e=e.parentElement}return null}function O(e,t){const n=e.length>0&&e[e.length-1]===" ";let o=!1,c=!1;for(let r=0;r<t.length;r++)if(R(t[r])){if(n&&!c||o)continue;e+=" ",o=!0}else{const a=t.charCodeAt(r);a!==8203&&a!==173&&(e+=t[r],o=!1,c=!0)}return e}export{O as appendNormalizedWhitespace,h as elementLanguage,R as isBlank,p as isInlineTag,B as srcRelativeToHref,u as trimUnicodeSpace,M as trimUnicodeSpaceEnd,N as trimUnicodeSpaceStart,U as trimmingTextLocator};
@@ -1 +0,0 @@
1
- import{getTime as g,getHtmlId as k}from"../../html/Locations.js";import{Profile as u}from"../../Profiles.js";import{isNptStartOfResource as v,formatNptTime as I,parseNptTime as T}from"../../../util/npt.js";class l{constructor(e,t,i=[],s=[],n=void 0){this._trimmedLinkMap=new Map,this._allItems=e,this.linkMap=t,this._conformsTo=i,this.tocLinks=s,this._tocDepth=n}static build(e,t={}){const i=e.toc?.items??[],s=e.readingOrder.items,{depth:n}=t,o=e.metadata?.conformsTo??[],r=new Map,c=[];for(let h=0;h<s.length;h++){const f=s[h],a=l.bareHref(f.href),p=f.title??l.findTitleInToc(i,a,n),d=l.collectChildrenFromToc(i,a,n,1,r),m={title:p,references:[f.href],children:d.length>0?d:void 0};r.set(m,f),c.push(m)}return new l(c,r,o,i,n)}augment(e){for(const t of this.flatAll){const i=this.linkFor(t);if(!i)continue;const s=e(t,i);s.position!==void 0&&(t.position=s.position),s.scroll!==void 0&&(t.scroll=s.scroll),s.role!==void 0&&(t.role=s.role)}}get depth(){return this._depth}set depth(e){this._depth!==e&&(this._depth=e,this._tocDepth=e,this._items=void 0,this._flat=void 0,this._toc=void 0)}get items(){return this._items||(this._depth!==void 0?(this._trimmedLinkMap=new Map,this._items=l.trimToDepth(this._allItems,this._depth,this.linkMap,this._trimmedLinkMap)):this._items=this._allItems),this._items}locate(e){const t=e.href.split("#")[0],i=g(e.locations),s=k(e.locations),n=e.locations.progression;if(i!==void 0){let o=-1/0,r;for(const c of this.flat){if(!this.itemMatchesHref(c,t))continue;const h=this.itemStartTime(c,t);h!==void 0&&h<=i&&h>o&&(o=h,r=c)}if(r)return r}if(s){const o=this.flat.find(r=>this.itemMatchesHref(r,t)?r.references.some(c=>c.split("#")[1]===s):!1);if(o)return o}if(n!==void 0){let o=-1/0,r;for(const h of this.flat){if(!this.itemMatchesHref(h,t))continue;const f=this.itemScrollPosition(h);f!==void 0&&f<=n&&f>o&&(o=f,r=h)}if(r)return r;const c=this.items.find(h=>this.itemMatchesHref(h,t));if(c?.children?.length&&!c.children.some(h=>h.scroll!==void 0)){const h=Math.min(Math.floor(n*c.children.length),c.children.length-1);return c.children[h]}}return this.flat.find(o=>this.itemMatchesHref(o,t))}adjacentTo(e){const t=this.flat.indexOf(e);return{previous:t>0?this.flat[t-1]:void 0,next:t>=0&&t<this.flat.length-1?this.flat[t+1]:void 0}}segmentsForHref(e){const t=e.split("#")[0],i=this.items.find(s=>this.itemMatchesHref(s,t));return i?i.children?.length?i.children:[i]:[]}ancestors(e){return this.ancestorPath(this.items,e)??[]}linkFor(e){return this.linkMap.get(e)??this._trimmedLinkMap.get(e)}get contextualizedToc(){return this._toc||(this._toc=this.tocLinks.length>0?this.buildTocEntries(this.tocLinks,this._tocDepth,1):this._allItems.map(e=>this.entryFor(this.linkFor(e),e))),this._toc}tocEntryFor(e){const t=this.linkFor(e);if(!t)return;const i=this.findTocEntryByLink(this.contextualizedToc,t);return i||this.nearestTocEntryForResource(t.href,e)}get flat(){return this._flat||(this._flat=this.flattenItems(this.items)),this._flat}get flatAll(){return this.flattenItems(this._allItems)}static findTitleInToc(e,t,i){const{atStart:s,fragments:n}=l.collectTocCandidates(e,t,i,1);if(s.length>0)return s[0].title;if(n.length===1)return n[0].title}static collectChildrenFromToc(e,t,i,s,n){if(i!==void 0&&s>i)return[];const o=[];for(const r of e){const c=l.bareHref(r.href);if((c===t||c==="")&&r.title&&!l.isStartOfResource(r.href)){const f=c===""?t+r.href:r.href,a={title:r.title,references:[f]};n.set(a,r),o.push(a)}r.children?.items?.length&&o.push(...l.collectChildrenFromToc(r.children.items,t,i,s+1,n))}return o}static collectTocCandidates(e,t,i,s){if(i!==void 0&&s>i)return{atStart:[],fragments:[]};const n=[],o=[];for(const r of e){const c=l.bareHref(r.href);if((c===t||c==="")&&r.title&&(l.isStartOfResource(r.href)?n.push(r):o.push(r)),r.children?.items?.length){const h=l.collectTocCandidates(r.children.items,t,i,s+1);n.push(...h.atStart),o.push(...h.fragments)}}return{atStart:n,fragments:o}}static isStartOfResource(e){const t=e.split("#")[1];if(!t)return!0;const i=t.match(/(?:^|&)t=([^&]+)/);return i!==null&&v(i[1])}get linkToItem(){if(!this._linkToItem){this._linkToItem=new Map;for(const[e,t]of this.linkMap)this._linkToItem.set(t,e)}return this._linkToItem}buildTocEntries(e,t,i){return t!==void 0&&i>t?[]:e.map(s=>{const n=this.linkToItem.get(s)??this.resourceStartItem(s.href),o=s.children?.items?.length?this.buildTocEntries(s.children.items,t,i+1):[];return{...this.entryFor(s,n),children:o.length>0?o:void 0}})}tocLinksFlat(e,t,i){if(t!==void 0&&i>t)return[];const s=[];for(const n of e)s.push(n),n.children?.items?.length&&s.push(...this.tocLinksFlat(n.children.items,t,i+1));return s}entryFor(e,t){const i=this._conformsTo.includes(u.AUDIOBOOK);return{link:e,position:!i&&t?.position!==void 0?String(t.position):void 0,timestamp:i&&t?.position!==void 0?I(t.position):void 0}}resourceStartItem(e){const t=l.bareHref(e);return this._allItems.find(i=>this.itemMatchesHref(i,t))}findTocEntryByLink(e,t){for(const i of e){if(i.link===t)return i;if(i.children){const s=this.findTocEntryByLink(i.children,t);if(s)return s}}}nearestTocEntryForResource(e,t){const i=l.bareHref(e),s=this.tocLinksFlat(this.tocLinks,this._tocDepth,1).filter(f=>l.bareHref(f.href)===i).map(f=>({link:f,item:this.linkToItem.get(f)??this.resourceStartItem(f.href)}));if(s.length===0)return;const n=this._conformsTo.includes(u.AUDIOBOOK),o=n?t.position??0:t.scroll??0;let r,c=-1/0;for(const f of s){const a=n?f.item?.position??0:f.item?.scroll??0;a<=o&&a>c&&(c=a,r=f)}const h=r??s[0];return this.findTocEntryByLink(this.contextualizedToc,h.link)}static trimToDepth(e,t,i,s){return e.map(n=>{const o={...n,children:t>1&&n.children?.length?l.trimToDepth(n.children,t-1,i,s):void 0},r=i.get(n);return r&&s.set(o,r),o})}flattenItems(e){const t=[];for(const i of e)t.push(i),i.children&&t.push(...this.flattenItems(i.children));return t}itemStartTime(e,t){for(const i of e.references){const s=i.indexOf("#"),n=s>=0?i.slice(0,s):i,o=s>=0?i.slice(s+1):void 0;if((n||t)!==t)continue;if(!o)return;const c=o.match(/(?:^|&)t=([^&]+)/);return c?T(c[1]):void 0}}itemMatchesHref(e,t){return e.references.some(i=>{const s=i.split("#")[0];return s===t||s===""})}ancestorPath(e,t){for(const i of e){if(i===t)return[];if(i.children){const s=this.ancestorPath(i.children,t);if(s!==null)return[i,...s]}}return null}itemScrollPosition(e){return e.scroll}static bareHref(e){return e.split("#")[0]}}export{l as Timeline};
@@ -1 +0,0 @@
1
- import{parseNptTime as p}from"../../../util/npt.js";import{Timeline as g}from"./Timeline.js";function O(s,f){const o=g.build(s,f),r=s.readingOrder.items;if(!(r.length<=1||r.every(t=>t.duration!==void 0)))return o;let c=0;const d=new Map(r.map(t=>{const i=c;return c+=t.duration??0,[t.href,i]}));return o.augment((t,i)=>{const e=i.href,n=e.indexOf("#"),m=n>=0?e.slice(0,n):e,u=n>=0?e.slice(n+1):void 0,l=d.get(m)??0,a=u?.match(/(?:^|&)t=([^&]+)/),h=a?p(a[1]):void 0;return{position:l+(h??0)}}),o}export{O as buildAudioTimeline};
@@ -1 +0,0 @@
1
- import{Timeline as l}from"./Timeline.js";function n(i,e){return l.build(i,e)}export{n as buildHtmlTimeline};
@@ -1 +0,0 @@
1
- import{Profile as e}from"../../Profiles.js";import{buildAudioTimeline as m}from"./audio.js";import{buildHtmlTimeline as r}from"./html.js";function f(i,o){return i.metadata?.conformsTo?.includes(e.AUDIOBOOK)??!1?m(i,o):r(i,o)}export{m as buildAudioTimeline,r as buildHtmlTimeline,f as buildTimeline};
@@ -1 +0,0 @@
1
- function n(r){return r&&Array.isArray(r)?r:void 0}function u(r){return r&&typeof r=="string"?[r]:n(r)}function o(r){return typeof r=="string"?new Date(r):void 0}function e(r){return isNaN(r)?void 0:r}function f(r){return e(r)!==void 0&&Math.sign(r)>=0?r:void 0}function a(r){const t=new Array;return r.forEach(i=>t.push(i)),t}export{n as arrayfromJSON,u as arrayfromJSONorString,o as datefromJSON,e as numberfromJSON,f as positiveNumberfromJSON,a as setToArray};
@@ -1 +0,0 @@
1
- class i{constructor(t){this.uri=t,this.parameters=this.getParameters(t)}getParameters(t){const n=/\{\??([^}]+)\}/g,a=t.match(n);return a?new Set(a.join(",").replace(n,"$1").split(",").map(e=>e.trim())):new Set}expand(t){const n=e=>e.split(",").map(s=>{const r=t[s];return r?encodeURIComponent(r):""}).join(","),a=e=>"?"+e.split(",").map(s=>{const r=s.split("=")[0],o=t[r];return o?`${r}=${encodeURIComponent(o)}`:""}).join("&");return this.uri.replace(/\{(\??)([^}]+)\}/g,(...e)=>e[1]?a(e[2]):n(e[2]))}}export{i as URITemplate};
@@ -1 +0,0 @@
1
- class t{constructor(e){let i,o,p=e.mediaType.replace(/\s/g,"").split(";");const s=p[0].split("/");if(s.length===2){if(i=s[0].toLowerCase().trim(),o=s[1].toLowerCase().trim(),i.length===0||o.length===0)throw new Error("Invalid media type")}else throw new Error("Invalid media type");const r={};for(let n=1;n<p.length;n++){const a=p[n].split("=");if(a.length===2){const u=a[0].toLocaleLowerCase(),f=u==="charset"?a[1].toUpperCase():a[1];r[u]=f}}const c={},m=Object.keys(r);m.sort((n,a)=>n.localeCompare(a)),m.forEach(n=>c[n]=r[n]);let l="";for(const n in c){const a=c[n];l+=`;${n}=${a}`}const g=`${i}/${o}${l}`,E=c.encoding;this.string=g,this.type=i,this.subtype=o,this.parameters=c,this.encoding=E,this.name=e.name,this.fileExtension=e.fileExtension}static parse(e){return new t(e)}get structuredSyntaxSuffix(){const e=this.subtype.split("+");return e.length>1?`+${e[e.length-1]}`:void 0}get charset(){return this.parameters.charset}contains(e){const i=typeof e=="string"?t.parse({mediaType:e}):e;if(!((this.type==="*"||this.type===i.type)&&(this.subtype==="*"||this.subtype===i.subtype)))return!1;const o=new Set(Object.entries(this.parameters).map(([s,r])=>`${s}=${r}`)),p=new Set(Object.entries(i.parameters).map(([s,r])=>`${s}=${r}`));for(const s of Array.from(o.values()))if(!p.has(s))return!1;return!0}matches(e){const i=typeof e=="string"?t.parse({mediaType:e}):e;return this.contains(i)||i.contains(this)}matchesAny(...e){for(const i of e)if(this.matches(i))return!0;return!1}equals(e){return this.string===e.string}get isZIP(){return this.matchesAny(t.ZIP,t.LCP_PROTECTED_AUDIOBOOK,t.LCP_PROTECTED_PDF)||this.structuredSyntaxSuffix==="+zip"}get isJSON(){return this.matchesAny(t.JSON)||this.structuredSyntaxSuffix==="+json"}get isOPDS(){return this.matchesAny(t.OPDS1,t.OPDS1_ENTRY,t.OPDS2,t.OPDS2_PUBLICATION,t.OPDS_AUTHENTICATION)||this.structuredSyntaxSuffix==="+json"}get isHTML(){return this.matchesAny(t.HTML,t.XHTML)}get isBitmap(){return this.matchesAny(t.AVIF,t.BMP,t.GIF,t.JPEG,t.PNG,t.TIFF,t.WEBP)}get isAudio(){return this.type==="audio"}get isVideo(){return this.type==="video"}get isRWPM(){return this.matchesAny(t.READIUM_AUDIOBOOK_MANIFEST,t.DIVINA_MANIFEST,t.READIUM_WEBPUB_MANIFEST)}get isPublication(){return this.matchesAny(t.READIUM_AUDIOBOOK,t.READIUM_AUDIOBOOK_MANIFEST,t.CBZ,t.DIVINA,t.DIVINA_MANIFEST,t.EPUB,t.LCP_PROTECTED_AUDIOBOOK,t.LCP_PROTECTED_PDF,t.LPF,t.PDF,t.W3C_WPUB_MANIFEST,t.READIUM_WEBPUB,t.READIUM_WEBPUB_MANIFEST,t.ZAB)}static get AAC(){return t.parse({mediaType:"audio/aac",fileExtension:"aac"})}static get ACSM(){return t.parse({mediaType:"application/vnd.adobe.adept+xml",name:"Adobe Content Server Message",fileExtension:"acsm"})}static get AIFF(){return t.parse({mediaType:"audio/aiff",fileExtension:"aiff"})}static get AVI(){return t.parse({mediaType:"video/x-msvideo",fileExtension:"avi"})}static get AVIF(){return t.parse({mediaType:"image/avif",fileExtension:"avif"})}static get BINARY(){return t.parse({mediaType:"application/octet-stream"})}static get BMP(){return t.parse({mediaType:"image/bmp",fileExtension:"bmp"})}static get CBZ(){return t.parse({mediaType:"application/vnd.comicbook+zip",name:"Comic Book Archive",fileExtension:"cbz"})}static get CSS(){return t.parse({mediaType:"text/css",fileExtension:"css"})}static get DIVINA(){return t.parse({mediaType:"application/divina+zip",name:"Digital Visual Narratives",fileExtension:"divina"})}static get DIVINA_MANIFEST(){return t.parse({mediaType:"application/divina+json",name:"Digital Visual Narratives",fileExtension:"json"})}static get EPUB(){return t.parse({mediaType:"application/epub+zip",name:"EPUB",fileExtension:"epub"})}static get GIF(){return t.parse({mediaType:"image/gif",fileExtension:"gif"})}static get GZ(){return t.parse({mediaType:"application/gzip",fileExtension:"gz"})}static get HTML(){return t.parse({mediaType:"text/html",fileExtension:"html"})}static get JAVASCRIPT(){return t.parse({mediaType:"text/javascript",fileExtension:"js"})}static get JPEG(){return t.parse({mediaType:"image/jpeg",fileExtension:"jpeg"})}static get JSON(){return t.parse({mediaType:"application/json"})}static get LCP_LICENSE_DOCUMENT(){return t.parse({mediaType:"application/vnd.readium.lcp.license.v1.0+json",name:"LCP License",fileExtension:"lcpl"})}static get LCP_PROTECTED_AUDIOBOOK(){return t.parse({mediaType:"application/audiobook+lcp",name:"LCP Protected Audiobook",fileExtension:"lcpa"})}static get LCP_PROTECTED_PDF(){return t.parse({mediaType:"application/pdf+lcp",name:"LCP Protected PDF",fileExtension:"lcpdf"})}static get LCP_STATUS_DOCUMENT(){return t.parse({mediaType:"application/vnd.readium.license.status.v1.0+json"})}static get LPF(){return t.parse({mediaType:"application/lpf+zip",fileExtension:"lpf"})}static get MP3(){return t.parse({mediaType:"audio/mpeg",fileExtension:"mp3"})}static get MPEG(){return t.parse({mediaType:"video/mpeg",fileExtension:"mpeg"})}static get NCX(){return t.parse({mediaType:"application/x-dtbncx+xml",fileExtension:"ncx"})}static get OGG(){return t.parse({mediaType:"audio/ogg",fileExtension:"oga"})}static get OGV(){return t.parse({mediaType:"video/ogg",fileExtension:"ogv"})}static get OPDS1(){return t.parse({mediaType:"application/atom+xml;profile=opds-catalog"})}static get OPDS1_ENTRY(){return t.parse({mediaType:"application/atom+xml;type=entry;profile=opds-catalog"})}static get OPDS2(){return t.parse({mediaType:"application/opds+json"})}static get OPDS2_PUBLICATION(){return t.parse({mediaType:"application/opds-publication+json"})}static get OPDS_AUTHENTICATION(){return t.parse({mediaType:"application/opds-authentication+json"})}static get OPUS(){return t.parse({mediaType:"audio/opus",fileExtension:"opus"})}static get OTF(){return t.parse({mediaType:"font/otf",fileExtension:"otf"})}static get PDF(){return t.parse({mediaType:"application/pdf",name:"PDF",fileExtension:"pdf"})}static get PNG(){return t.parse({mediaType:"image/png",fileExtension:"png"})}static get READIUM_AUDIOBOOK(){return t.parse({mediaType:"application/audiobook+zip",name:"Readium Audiobook",fileExtension:"audiobook"})}static get READIUM_AUDIOBOOK_MANIFEST(){return t.parse({mediaType:"application/audiobook+json",name:"Readium Audiobook",fileExtension:"json"})}static get READIUM_CONTENT_DOCUMENT(){return t.parse({mediaType:"application/vnd.readium.content+json",name:"Readium Content Document",fileExtension:"json"})}static get READIUM_GUIDED_NAVIGATION_DOCUMENT(){return t.parse({mediaType:"application/guided-navigation+json",name:"Readium Guided Navigation Document",fileExtension:"json"})}static get READIUM_POSITION_LIST(){return t.parse({mediaType:"application/vnd.readium.position-list+json",name:"Readium Position List",fileExtension:"json"})}static get READIUM_WEBPUB(){return t.parse({mediaType:"application/webpub+zip",name:"Readium Web Publication",fileExtension:"webpub"})}static get READIUM_WEBPUB_MANIFEST(){return t.parse({mediaType:"application/webpub+json",name:"Readium Web Publication",fileExtension:"json"})}static get SMIL(){return t.parse({mediaType:"application/smil+xml",fileExtension:"smil"})}static get SVG(){return t.parse({mediaType:"image/svg+xml",fileExtension:"svg"})}static get TEXT(){return t.parse({mediaType:"text/plain",fileExtension:"txt"})}static get TIFF(){return t.parse({mediaType:"image/tiff",fileExtension:"tiff"})}static get TTF(){return t.parse({mediaType:"font/ttf",fileExtension:"ttf"})}static get W3C_WPUB_MANIFEST(){return t.parse({mediaType:"application/x.readium.w3c.wpub+json",name:"Web Publication",fileExtension:"json"})}static get WAV(){return t.parse({mediaType:"audio/wav",fileExtension:"wav"})}static get WEBM_AUDIO(){return t.parse({mediaType:"audio/webm",fileExtension:"webm"})}static get WEBM_VIDEO(){return t.parse({mediaType:"video/webm",fileExtension:"webm"})}static get WEBP(){return t.parse({mediaType:"image/webp",fileExtension:"webp"})}static get WOFF(){return t.parse({mediaType:"font/woff",fileExtension:"woff"})}static get WOFF2(){return t.parse({mediaType:"font/woff2",fileExtension:"woff2"})}static get XHTML(){return t.parse({mediaType:"application/xhtml+xml",fileExtension:"xhtml"})}static get XML(){return t.parse({mediaType:"application/xml",fileExtension:"xml"})}static get ZAB(){return t.parse({mediaType:"application/x.readium.zab+zip",name:"Zipped Audio Book",fileExtension:"zab"})}static get ZIP(){return t.parse({mediaType:"application/zip",fileExtension:"zip"})}}export{t as MediaType};
package/dist/util/npt.js DELETED
@@ -1 +0,0 @@
1
- function c(o){const s=o.split(",")[0].trim(),t=(s.toLowerCase().startsWith("npt:")?s.slice(4):s).split(":");if(t.length===1){const n=parseFloat(t[0]);return isNaN(n)?void 0:n}if(t.length===2){const n=parseInt(t[0],10),r=parseFloat(t[1]);return isNaN(n)||isNaN(r)?void 0:n*60+r}if(t.length===3){const n=parseInt(t[0],10),r=parseInt(t[1],10),e=parseFloat(t[2]);return isNaN(n)||isNaN(r)||isNaN(e)?void 0:n*3600+r*60+e}}function p(o){const s=c(o);return s!==void 0&&s===0}function l(o){const s=Math.floor(o),a=Math.floor(s/3600),i=Math.floor(s%3600/60),t=s%60,n=String(i).padStart(2,"0"),r=String(t).padStart(2,"0");return a>0?`${a}:${n}:${r}`:`${i}:${r}`}export{l as formatNptTime,p as isNptStartOfResource,c as parseNptTime};
@@ -1 +0,0 @@
1
- import a from"./tokenize-english/index.js";import h from"./tokenize-text/index.js";var l=(t=>(t.Word="word",t.Sentence="sentence",t.Paragraph="paragraph",t))(l||{});const p=(t,e)=>"Segmenter"in Intl?new c(t,e):new u(t,e);class c{constructor(e,n){if(this.unit=n,e=e??navigator?.language,!("Segmenter"in Intl))throw new Error("Intl.Segmenter is not supported in this environment");if(n==="paragraph")throw new Error("IntlTextTokenizer does not handle TextUnit.Paragraph");this.segmenter=new Intl.Segmenter(e,{granularity:n})}tokenize(e){const n=this.segmenter.segment(e),i=[];for(let r of n){if(this.unit==="word"&&r.isWordLike===!1)continue;const s=o(r.segment);s!==null&&i.push([r.index,r.index+s.length])}return i}}class u{constructor(e,n){if(this.unit=n,e=e??navigator?.language,this.isEnglish=e.toLowerCase().split("-")[0]==="en",n==="paragraph")throw new Error("NaiveTextTokenizer does not handle TextUnit.Paragraph");this.tokenizer=new h}tokenize(e){let n=[];switch(this.unit){case"word":n=this.tokenizer.words()(e);break;case"sentence":this.isEnglish?n=a(this.tokenizer).sentences()(e):n=this.tokenizer.sections()(e);break;default:n=[]}if(!n)return[];const i=[];return n.forEach(r=>{if(r.value.length===0)return;const s=o(r.value);s!==null&&i.push([r.index,r.index+s.length])}),i}}const g=new RegExp("[\\p{L}\\p{N}]+","u"),o=t=>{const e=t.trimEnd();return e.length===0||e.match(g)===null?null:e};export{p as DefaultTextContentTokenizer,c as IntlTextTokenizer,u as NaiveTextTokenizer,l as TextUnit,o as speakableToken};
@@ -1 +0,0 @@
1
- const e=["ie","eg","ext","Fig","fig","Figs","figs","et al","Co","Corp","Ave","Inc","Ex","Viz","vs","Vs","repr","Rep","Dem","trans","Vol","pp","rev","est","Ref","Refs","Eq","Eqs","Ch","Sec","Secs","mi","Dept","Univ","Nos","No","Mol","Cell","Miss","Mrs","Mr","Ms","Prof","Dr","Sgt","Col","Gen","Rep","Sen","Gov","Lt","Maj","Capt","St","Sr","Jr","jr","Rev","PhD","MD","BA","MA","MM","BSc","MSc","Jan","Feb","Mar","Apr","Jun","Jul","Aug","Sep","Sept","Oct","Nov","Dec","Sun","Mon","Tu","Tue","Tues","Wed","Th","Thu","Thur","Thurs","Fri","Sat"];export{e as default};
@@ -1,2 +0,0 @@
1
- import s from"./utils.js";import g from"./abbreviations.js";function v(e){return/^[A-Z][a-z].*/.test(e)||c(e)}function p(e){return v(e)||/``|"|'/.test(e.substring(0,2))}function C(e){return~g.indexOf(e.replace(/\W+/g,""))}function N(e,n){if(e==="a.m."||e==="p.m."){var r=n.replace(/\W+/g,"").slice(-3).toLowerCase();if(r==="day")return!0}return!1}function h(e){var n=e.replace(/[\(\)\[\]\{\}]/g,"").match(/(.\.)*/);return n&&n[0].length>0}function m(e){return e.length<=3?!0:v(e)}function c(e,n){return n&&(e=e.slice(n-1,n+2)),!isNaN(Number(e))}function O(e){return e.match(/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$/)}function z(e){return e.match(/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/)}function W(e){var n=0;if((n=e.indexOf("."))>-1||(n=e.indexOf("!"))>-1||(n=e.indexOf("?"))>-1){var r=e.charAt(n+1);if(r.match(/[a-zA-Z].*/))return[e.slice(0,n),e.charAt(n),e.slice(n+1)]}return!1}function o(e){return e==="."||e==="!"||e==="?"}function y(e,n){n=Object.assign(n||{},{newlineBoundary:n&&n.newlineBoundary||!0});var r=/\s/;return e.serie(e.re(r,{split:!0}),e.splitAndMerge(function(t,Z,S,L,b,A){var u,f=[t,null],i=t,a=A.slice(b+1).find(function(x){return!r.test(x.value)});if(t===`
2
- `&&n.newlineBoundary||o(t)||s.endsWithChar(t,"?!"))return f;if(s.endsWithChar(t,".")){if(a){if(t.length===2&&isNaN(t.charAt(0))&&t.match(/[a-zA-Z]/)||C(t))return i;if(p(a.value)){if(N(t,a.value)||c(a.value)&&m(t))return i}else if(s.endsWith(t,"..")||h(t)||m(t))return i}return f}let l;return(l=t.indexOf("."))>-1&&(c(t,l)||h(t)||z(t)||O(t))?i:(u=W(t))?[u[0]+u[1],null,u[2]]:i}),e.filter(function(t){return t.trim()!=""}))}const B=(e,...n)=>(...r)=>e(...n,...r);function _(e){return{sentences:B(y,e)}}export{_ as default};
@@ -1 +0,0 @@
1
- function n(e,t){return t.length>1?t.indexOf(e.slice(-1))>-1:e.slice(-1)===t}function i(e,t){return e.slice(e.length-t.length)===t}const s={endsWith:i,endsWithChar:n};export{s as default};
@@ -1 +0,0 @@
1
- import g from"./tokens.js";var m=' \r\n  !"#$%&()*+,-.\\/:;<=>?@[\\]^_`{|}~',k=new RegExp("([^"+m+"]+)");function i(u){if(!(this instanceof i))return new i(u);this.opts=Object.assign({cacheGet:function(t){return null},cacheSet:function(t,n){}},u)}i.prototype.split=function(t,n={}){var e=this;return n=Object.assign({preserveProperties:!0,cache:()=>null},n),function(r,c){if(arguments.length===6)return t.apply(null,arguments);var o,a,l;if(r===void 0)return[];if(typeof r=="string"?r=[{value:r,index:0,offset:r.length}]:Array.isArray(r)||(r=[r]),a=g.tokensId(r,n.cache()),a&&(l=e.opts.cacheGet(a),l))return l;var h=r.map(function(s,f){var v=r[f+1],p=t(s.value,Object.assign({},s),o?Object.assign({},o):null,v?Object.assign({},v):null,f,r)||[];if(p=g.normalize(s,p),n.preserveProperties){var y=g.properties(s);p=p.map(function(d){return Object.assign({},d,y)})}return o=s,p}).filter(Boolean).flat();return a&&e.opts.cacheSet(a,h),h}};i.prototype.re=function(t,n={}){return n=Object.assign({split:!1},n),this.split(function(e,r){for(var c=e,o=[],a,l=0;a=t.exec(e);){var h=a.index,s=l+h,f=a[0]||"",v=f.length;if(n.split&&l<s){var p=c.slice(l,s);o.push({value:p,index:l,offset:p.length})}o.push({value:f,index:s,offset:v,match:a}),e=e.slice(h+v),l=s+v}return n.split&&e&&o.push({value:e,index:l,offset:e.length}),o},{cache:function(){return t.toString()}})};i.prototype.splitAndMerge=function(t,n={}){var e=this;return n=Object.assign({mergeWith:""},n),function(r){var c=[],o=[];function a(){if(o.length!=0){var l=g.merge(o,n.mergeWith);c.push(l),o=[]}}return e.split(function(l,h){var s=t.apply(null,arguments);s=g.normalize(h,s),s.forEach(function(f){f===null?a():o.push(f)})})(r),a(),c}};i.prototype.filter=function(t){return this.split(function(n,e){if(t.apply(null,arguments))return{value:e.value,index:0,offset:e.offset}})};i.prototype.extend=function(t){return this.split(function(n,e){var r=typeof t=="function"?t.apply(null,arguments):t;return Object.assign({value:e.value,index:0,offset:e.offset},r)})};i.prototype.ifthen=function(u,t){return this.split(function(n,e){if(u.apply(null,arguments))return t.apply(null,arguments);const{index:r,...c}=e;return c})};i.prototype.test=function(t){return this.filter(function(n,e){return t.test(n)},{cache:t.toString()})};i.prototype.flow=function(...t){const n=t.reduce((e,r)=>(...c)=>r(e(...c)));return this.split(n)};i.prototype.serie=function(...t){return t.reduce((n,e)=>(...r)=>e(n(...r)))};i.prototype.merge=function(){return this.splitAndMerge(u=>[u])};i.prototype.sections=function(){return this.re(/([^\n\.,;!?]+)/i,{split:!1})};i.prototype.words=function(){return this.re(k)};i.prototype.characters=function(){return this.re(/[^\s]/)};export{i as default};
@@ -1 +0,0 @@
1
- function v(e,i){return i?e.reduce(function(f,r){var n=[r.index,r.offset,r.value].join("-");return[f,n].join(":")},i):null}function u(e){const{index:i,offset:f,value:r,...n}=e;return n}function o(e,i){var f=0;return Array.isArray(i)||(i=[i]),i.map(function(r){return r===null?null:(typeof r=="string"&&(r={value:r,index:f,offset:r.length}),typeof r=="object"&&(r.index=r.index||0,f=f+r.index+r.offset,r.index=e.index+r.index,r.offset=r.offset||r.value.length),r)})}function c(e,i){if(e.length==0)return null;var f="",r=0,n=e[0]?.index;return e.forEach(function(a,t){var l=e[t-1];e[t+1];var x=l?a.index+1-(l.index+l.offset):0;f=f+new Array(x).join(i)+a.value;var d=a.index-n+a.offset;d>r&&(r=d)}),{index:n,value:f,offset:Math.max(r,f.length)}}const g={tokensId:v,normalize:o,properties:u,merge:c};export{g as default};