@readium/shared 2.2.0-beta.2 → 2.2.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 (141) hide show
  1. package/dist/index.js +249 -252
  2. package/dist/index.umd.cjs +3 -3
  3. package/package.json +1 -1
  4. package/src/fetcher/Fetcher.ts +2 -2
  5. package/src/fetcher/HttpFetcher.ts +3 -3
  6. package/src/fetcher/Resource.ts +1 -1
  7. package/src/fetcher/index.ts +3 -3
  8. package/src/index.ts +4 -4
  9. package/src/opds/Availability.ts +1 -1
  10. package/src/opds/Copies.ts +1 -1
  11. package/src/opds/Holds.ts +1 -1
  12. package/src/opds/Price.ts +1 -1
  13. package/src/opds/index.ts +5 -5
  14. package/src/publication/BelongsTo.ts +1 -1
  15. package/src/publication/Contributor.ts +4 -4
  16. package/src/publication/GuidedNavigation.ts +19 -19
  17. package/src/publication/Link.ts +6 -6
  18. package/src/publication/Locator.ts +1 -1
  19. package/src/publication/LocatorCollection.ts +4 -4
  20. package/src/publication/Manifest.ts +6 -6
  21. package/src/publication/Metadata.ts +13 -13
  22. package/src/publication/Publication.ts +12 -14
  23. package/src/publication/PublicationCollection.ts +1 -1
  24. package/src/publication/ReadingProgression.ts +1 -1
  25. package/src/publication/Subject.ts +2 -2
  26. package/src/publication/accessibility/AccessibilityMetadataDisplayGuide.ts +20 -20
  27. package/src/publication/accessibility/Localization.ts +15 -15
  28. package/src/publication/accessibility/index.ts +3 -3
  29. package/src/publication/encryption/Properties.ts +2 -2
  30. package/src/publication/encryption/index.ts +2 -2
  31. package/src/publication/epub/Metadata.ts +3 -3
  32. package/src/publication/epub/Properties.ts +1 -1
  33. package/src/publication/epub/Publication.ts +2 -2
  34. package/src/publication/epub/index.ts +4 -4
  35. package/src/publication/html/DomRange.ts +1 -1
  36. package/src/publication/html/DomRangePoint.ts +1 -1
  37. package/src/publication/html/Locations.ts +3 -3
  38. package/src/publication/html/index.ts +3 -3
  39. package/src/publication/index.ts +24 -24
  40. package/src/publication/opds/Properties.ts +4 -4
  41. package/src/publication/opds/Publication.ts +2 -2
  42. package/src/publication/opds/index.ts +2 -2
  43. package/src/publication/services/content/Content.ts +3 -3
  44. package/src/publication/services/content/ContentTokenizer.ts +6 -6
  45. package/src/publication/services/content/Iterator.ts +2 -2
  46. package/src/publication/services/content/element/attributes.ts +2 -2
  47. package/src/publication/services/content/element/element.ts +5 -5
  48. package/src/publication/services/content/element/index.ts +3 -3
  49. package/src/publication/services/content/index.ts +5 -5
  50. package/src/publication/services/content/iterators/HTMLResourceContentIterator.ts +8 -8
  51. package/src/publication/services/content/iterators/PDFTextContentIterator.ts +21 -21
  52. package/src/publication/services/content/iterators/PublicationContentIterator.ts +6 -6
  53. package/src/publication/services/content/iterators/helpers.ts +1 -1
  54. package/src/publication/services/content/iterators/index.ts +3 -3
  55. package/src/publication/services/index.ts +2 -2
  56. package/src/publication/services/timeline/Timeline.ts +53 -44
  57. package/src/publication/services/timeline/index.ts +2 -2
  58. package/src/util/index.ts +5 -5
  59. package/src/util/mediatype/index.ts +1 -1
  60. package/src/util/tokenizer/TextTokenizer.ts +5 -5
  61. package/src/util/tokenizer/index.ts +2 -2
  62. package/types/src/fetcher/Fetcher.d.ts +2 -2
  63. package/types/src/fetcher/HttpFetcher.d.ts +3 -3
  64. package/types/src/fetcher/Resource.d.ts +1 -1
  65. package/types/src/fetcher/index.d.ts +3 -3
  66. package/types/src/index.d.ts +4 -4
  67. package/types/src/opds/index.d.ts +5 -5
  68. package/types/src/publication/BelongsTo.d.ts +1 -1
  69. package/types/src/publication/Contributor.d.ts +3 -3
  70. package/types/src/publication/GuidedNavigation.d.ts +1 -1
  71. package/types/src/publication/Link.d.ts +3 -3
  72. package/types/src/publication/LocatorCollection.d.ts +3 -3
  73. package/types/src/publication/Manifest.d.ts +4 -4
  74. package/types/src/publication/Metadata.d.ts +10 -10
  75. package/types/src/publication/Publication.d.ts +11 -12
  76. package/types/src/publication/PublicationCollection.d.ts +1 -1
  77. package/types/src/publication/ReadingProgression.d.ts +1 -1
  78. package/types/src/publication/Subject.d.ts +2 -2
  79. package/types/src/publication/accessibility/AccessibilityMetadataDisplayGuide.d.ts +2 -2
  80. package/types/src/publication/accessibility/index.d.ts +3 -3
  81. package/types/src/publication/encryption/Properties.d.ts +1 -1
  82. package/types/src/publication/encryption/index.d.ts +2 -2
  83. package/types/src/publication/epub/Metadata.d.ts +1 -1
  84. package/types/src/publication/epub/Publication.d.ts +1 -1
  85. package/types/src/publication/epub/index.d.ts +4 -4
  86. package/types/src/publication/html/DomRange.d.ts +1 -1
  87. package/types/src/publication/html/Locations.d.ts +1 -1
  88. package/types/src/publication/html/index.d.ts +3 -3
  89. package/types/src/publication/index.d.ts +24 -24
  90. package/types/src/publication/opds/Properties.d.ts +2 -2
  91. package/types/src/publication/opds/Publication.d.ts +1 -1
  92. package/types/src/publication/opds/index.d.ts +2 -2
  93. package/types/src/publication/services/content/Content.d.ts +2 -2
  94. package/types/src/publication/services/content/ContentTokenizer.d.ts +2 -2
  95. package/types/src/publication/services/content/Iterator.d.ts +1 -1
  96. package/types/src/publication/services/content/element/attributes.d.ts +1 -1
  97. package/types/src/publication/services/content/element/element.d.ts +4 -4
  98. package/types/src/publication/services/content/element/index.d.ts +3 -3
  99. package/types/src/publication/services/content/index.d.ts +5 -5
  100. package/types/src/publication/services/content/iterators/HTMLResourceContentIterator.d.ts +4 -4
  101. package/types/src/publication/services/content/iterators/PDFTextContentIterator.d.ts +3 -3
  102. package/types/src/publication/services/content/iterators/PublicationContentIterator.d.ts +5 -5
  103. package/types/src/publication/services/content/iterators/helpers.d.ts +1 -1
  104. package/types/src/publication/services/content/iterators/index.d.ts +3 -3
  105. package/types/src/publication/services/index.d.ts +2 -2
  106. package/types/src/publication/services/timeline/Timeline.d.ts +9 -11
  107. package/types/src/publication/services/timeline/index.d.ts +2 -2
  108. package/types/src/util/index.d.ts +5 -5
  109. package/types/src/util/mediatype/index.d.ts +1 -1
  110. package/types/src/util/tokenizer/TextTokenizer.d.ts +2 -2
  111. package/types/src/util/tokenizer/index.d.ts +2 -2
  112. package/types/test/AltIdentifier.test.d.ts +0 -1
  113. package/types/test/Contributor.test.d.ts +0 -1
  114. package/types/test/GuidedNavigation.test.d.ts +0 -1
  115. package/types/test/Link.test.d.ts +0 -1
  116. package/types/test/LocalizedString.test.d.ts +0 -1
  117. package/types/test/Locator.test.d.ts +0 -1
  118. package/types/test/LocatorCollection.test.d.ts +0 -1
  119. package/types/test/Manifest.test.d.ts +0 -1
  120. package/types/test/Metadata.test.d.ts +0 -1
  121. package/types/test/Properties.test.d.ts +0 -1
  122. package/types/test/Publication.test.d.ts +0 -1
  123. package/types/test/PublicationCollection.test.d.ts +0 -1
  124. package/types/test/Subject.test.d.ts +0 -1
  125. package/types/test/TDM.test.d.ts +0 -1
  126. package/types/test/Timeline.test.d.ts +0 -1
  127. package/types/test/accessibility/Accessibility.test.d.ts +0 -1
  128. package/types/test/accessibility/AccessibilityMetadataDisplayGuide.test.d.ts +0 -1
  129. package/types/test/accessibility/Localization.test.d.ts +0 -1
  130. package/types/test/encryption/Encryption.test.d.ts +0 -1
  131. package/types/test/encryption/Properties.test.d.ts +0 -1
  132. package/types/test/epub/MediaOverlay.test.d.ts +0 -1
  133. package/types/test/epub/Metadata.test.d.ts +0 -1
  134. package/types/test/epub/PropertiesTest.test.d.ts +0 -1
  135. package/types/test/epub/PublicationTest.test.d.ts +0 -1
  136. package/types/test/html/DomRange.test.d.ts +0 -1
  137. package/types/test/html/Locator.test.d.ts +0 -1
  138. package/types/test/opds/PropertiesTest.test.d.ts +0 -1
  139. package/types/test/opds/PublicationTest.test.d.ts +0 -1
  140. package/types/test/util/URITemplate.test.d.ts +0 -1
  141. package/types/test/util/mediatype/MediaType.test.d.ts +0 -1
@@ -1,6 +1,6 @@
1
1
  // Localization.ts
2
2
 
3
- import { SUPPORTED_LANGUAGES } from './SupportedLanguages';
3
+ import { SUPPORTED_LANGUAGES } from './SupportedLanguages.ts';
4
4
  // Static import for English (default locale)
5
5
  import enLocale from '@edrlab/thorium-locales/publication-metadata/en.json';
6
6
 
@@ -65,20 +65,20 @@ class LocalizationImpl {
65
65
  if (localeCode in this.loadedLocales) {
66
66
  return true;
67
67
  }
68
-
68
+
69
69
  try {
70
70
  // Check if we have a loader for this locale
71
71
  if (!(localeCode in jsonLoaders)) {
72
72
  console.warn(`Locale file not found for: ${localeCode}`);
73
73
  return false;
74
74
  }
75
-
75
+
76
76
  const localeModule = await jsonLoaders[localeCode]();
77
77
  const data = localeModule.default;
78
-
78
+
79
79
  // Extract the accessibility.display-guide part
80
80
  const accessibilityData = data?.publication?.metadata?.accessibility?.['display-guide'];
81
-
81
+
82
82
  if (accessibilityData) {
83
83
  this.loadedLocales[localeCode] = accessibilityData;
84
84
  return true;
@@ -113,12 +113,12 @@ class LocalizationImpl {
113
113
  if (!(localeCode in this.loadedLocales)) {
114
114
  await this.loadLocale(localeCode);
115
115
  }
116
-
116
+
117
117
  if (!(localeCode in this.loadedLocales)) {
118
118
  console.warn(`Locale '${localeCode}' is not available`);
119
119
  return false;
120
120
  }
121
-
121
+
122
122
  this.locale = this.loadedLocales[localeCode];
123
123
  this.currentLocaleCode = localeCode;
124
124
  return true;
@@ -141,14 +141,14 @@ class LocalizationImpl {
141
141
  private getNestedValue(obj: any, path: string): string | L10nString | undefined {
142
142
  const parts = path.split('.');
143
143
  let current = obj;
144
-
144
+
145
145
  for (const part of parts) {
146
146
  if (current === null || current === undefined) {
147
147
  return undefined;
148
148
  }
149
149
  current = current[part];
150
150
  }
151
-
151
+
152
152
  return current;
153
153
  }
154
154
 
@@ -160,19 +160,19 @@ class LocalizationImpl {
160
160
  public getString(key: string): L10nString {
161
161
  // First try the current locale
162
162
  let value = this.getNestedValue(this.locale, key);
163
-
163
+
164
164
  // If not found and current locale is not English, try falling back to English
165
165
  if (value === undefined && this.currentLocaleCode !== 'en') {
166
166
  value = this.getNestedValue(this.loadedLocales['en'], key);
167
167
  }
168
-
168
+
169
169
  // If we have a value, return it with proper formatting
170
170
  if (value !== undefined) {
171
- return typeof value === 'string'
172
- ? { compact: value, descriptive: value }
171
+ return typeof value === 'string'
172
+ ? { compact: value, descriptive: value }
173
173
  : value;
174
174
  }
175
-
175
+
176
176
  // If we get here, the key wasn't found in either locale
177
177
  console.warn(`Missing localization for key: ${key}`);
178
178
  return { compact: '', descriptive: '' };
@@ -182,4 +182,4 @@ class LocalizationImpl {
182
182
  /**
183
183
  * The singleton instance of the [Localization] class.
184
184
  */
185
- export const Localization = LocalizationImpl.getInstance();
185
+ export const Localization = LocalizationImpl.getInstance();
@@ -1,3 +1,3 @@
1
- export * from './Accessibility';
2
- export * from './AccessibilityMetadataDisplayGuide';
3
- export * from './Localization';
1
+ export * from './Accessibility.ts';
2
+ export * from './AccessibilityMetadataDisplayGuide.ts';
3
+ export * from './Localization.ts';
@@ -1,5 +1,5 @@
1
- import { Properties } from '../Properties';
2
- import { Encryption } from './Encryption';
1
+ import { Properties } from '../Properties.ts';
2
+ import { Encryption } from './Encryption.ts';
3
3
 
4
4
  // Encryption extensions for link [Properties].
5
5
 
@@ -1,2 +1,2 @@
1
- export * from './Encryption';
2
- export * from './Properties';
1
+ export * from './Encryption.ts';
2
+ export * from './Properties.ts';
@@ -1,5 +1,5 @@
1
- import { Metadata } from "../Metadata";
2
- import { MediaOverlay } from "./MediaOverlay";
1
+ import { Metadata } from "../Metadata.ts";
2
+ import { MediaOverlay } from "./MediaOverlay.ts";
3
3
 
4
4
  declare module '../Metadata' {
5
5
  export interface Metadata {
@@ -13,4 +13,4 @@ Metadata.prototype.getMediaOverlay = function(): MediaOverlay | undefined {
13
13
  if (!mediaOverlay) return;
14
14
 
15
15
  return MediaOverlay.deserialize(mediaOverlay);
16
- };
16
+ };
@@ -1,4 +1,4 @@
1
- import { Properties } from '../Properties';
1
+ import { Properties } from '../Properties.ts';
2
2
 
3
3
  // EPUB extensions for link [Properties].
4
4
  // https://readium.org/webpub-manifest/schema/extensions/epub/properties.schema.json
@@ -1,5 +1,5 @@
1
- import { Links } from '../Link';
2
- import { Publication } from '../Publication';
1
+ import { Links } from '../Link.ts';
2
+ import { Publication } from '../Publication.ts';
3
3
 
4
4
  // EPUB extensions for [Publication].
5
5
  // https://readium.org/webpub-manifest/schema/extensions/epub/subcollections.schema.json
@@ -1,4 +1,4 @@
1
- export * from './MediaOverlay';
2
- export * from './Metadata';
3
- export * from './Properties';
4
- export * from './Publication';
1
+ export * from './MediaOverlay.ts';
2
+ export * from './Metadata.ts';
3
+ export * from './Properties.ts';
4
+ export * from './Publication.ts';
@@ -3,7 +3,7 @@
3
3
  * available in the LICENSE file present in the Github repository of the project.
4
4
  */
5
5
 
6
- import { DomRangePoint } from './DomRangePoint';
6
+ import { DomRangePoint } from './DomRangePoint.ts';
7
7
 
8
8
  /**
9
9
  * This construct enables a serializable representation of a DOM Range.
@@ -1,4 +1,4 @@
1
- import { positiveNumberfromJSON } from '../../util/JSONParse';
1
+ import { positiveNumberfromJSON } from '../../util/JSONParse.ts';
2
2
 
3
3
  /**
4
4
  * A serializable representation of a boundary point in a DOM Range.
@@ -1,5 +1,5 @@
1
- import { LocatorLocations } from '../Locator';
2
- import { DomRange } from './DomRange';
1
+ import { LocatorLocations } from '../Locator.ts';
2
+ import { DomRange } from './DomRange.ts';
3
3
 
4
4
  // HTML extensions for [Locations].
5
5
  // https://github.com/readium/architecture/blob/master/models/locators/extensions/html.md
@@ -126,4 +126,4 @@ LocatorLocations.prototype.space = function(): [number, number, number, number]
126
126
  if(xywh.length !== 4) return; // Must have four parts
127
127
  if(xywh.some(isNaN)) return; // All parts must be numbers
128
128
  return xywh as [number, number, number, number];
129
- }
129
+ }
@@ -1,3 +1,3 @@
1
- export * from './DomRange';
2
- export * from './DomRangePoint';
3
- export * from './Locations';
1
+ export * from './DomRange.ts';
2
+ export * from './DomRangePoint.ts';
3
+ export * from './Locations.ts';
@@ -1,24 +1,24 @@
1
- export * from './accessibility';
2
- export * from './encryption';
3
- export * from './epub';
4
- export * from './html';
5
- export * from './opds';
6
- export * from './services';
7
- export * from './AltIdentifier';
8
- export * from './BelongsTo';
9
- export * from './Contributor';
10
- export * from './Link';
11
- export * from './LocalizedString';
12
- export * from './Locator';
13
- export * from './LocatorCollection';
14
- export * from './Manifest';
15
- export * from './Metadata';
16
- export * from './Profiles';
17
- export * from './Properties';
18
- export * from './Publication';
19
- export * from './PublicationCollection';
20
- export * from './Layout';
21
- export * from './ReadingProgression';
22
- export * from './Subject';
23
- export * from './TDM';
24
- export * from './GuidedNavigation';
1
+ export * from './accessibility/index.ts';
2
+ export * from './encryption/index.ts';
3
+ export * from './epub/index.ts';
4
+ export * from './html/index.ts';
5
+ export * from './opds/index.ts';
6
+ export * from './services/index.ts';
7
+ export * from './AltIdentifier.ts';
8
+ export * from './BelongsTo.ts';
9
+ export * from './Contributor.ts';
10
+ export * from './Link.ts';
11
+ export * from './LocalizedString.ts';
12
+ export * from './Locator.ts';
13
+ export * from './LocatorCollection.ts';
14
+ export * from './Manifest.ts';
15
+ export * from './Metadata.ts';
16
+ export * from './Profiles.ts';
17
+ export * from './Properties.ts';
18
+ export * from './Publication.ts';
19
+ export * from './PublicationCollection.ts';
20
+ export * from './Layout.ts';
21
+ export * from './ReadingProgression.ts';
22
+ export * from './Subject.ts';
23
+ export * from './TDM.ts';
24
+ export * from './GuidedNavigation.ts';
@@ -1,7 +1,7 @@
1
- import { Copies, Acquisition, Holds, Price, Availability } from '../../opds';
2
- import { positiveNumberfromJSON } from '../../util/JSONParse';
3
- import { Link } from '../Link';
4
- import { Properties } from '../Properties';
1
+ import { Copies, Acquisition, Holds, Price, Availability } from '../../opds/index.ts';
2
+ import { positiveNumberfromJSON } from '../../util/JSONParse.ts';
3
+ import { Link } from '../Link.ts';
4
+ import { Properties } from '../Properties.ts';
5
5
 
6
6
  // OPDS extensions for link [Properties].
7
7
  // https://drafts.opds.io/schema/properties.schema.json
@@ -1,5 +1,5 @@
1
- import { Links } from '../Link';
2
- import { Publication } from '../Publication';
1
+ import { Links } from '../Link.ts';
2
+ import { Publication } from '../Publication.ts';
3
3
 
4
4
  // OPDS extensions for [Publication]
5
5
 
@@ -1,2 +1,2 @@
1
- export * from './Properties';
2
- export * from './Publication';
1
+ export * from './Properties.ts';
2
+ export * from './Publication.ts';
@@ -1,5 +1,5 @@
1
- import { Iterator } from "./Iterator";
2
- import { ContentElement, TextualElement } from "./element";
1
+ import { Iterator } from "./Iterator.ts";
2
+ import { ContentElement, TextualElement } from "./element/index.ts";
3
3
 
4
4
  /**
5
5
  * Provides an iterable list of content [Element]s.
@@ -33,4 +33,4 @@ export abstract class Content {
33
33
  }
34
34
  return list;
35
35
  }
36
- }
36
+ }
@@ -1,13 +1,13 @@
1
- import { DefaultTextContentTokenizer, Range, TextTokenizer, TextUnit, Tokenizer } from "../../../util";
2
- import { Locator, LocatorText } from "../../Locator";
3
- import { ContentElement, TextElement, TextSegment } from "./element";
1
+ import { DefaultTextContentTokenizer, Range, TextTokenizer, TextUnit, Tokenizer } from "../../../util/index.ts";
2
+ import { Locator, LocatorText } from "../../Locator.ts";
3
+ import { ContentElement, TextElement, TextSegment } from "./element/index.ts";
4
4
 
5
5
  // A tokenizer splitting a [Content.Element] into smaller pieces.
6
6
  export type ContentTokenizer = Tokenizer<ContentElement, ContentElement>;
7
7
 
8
8
  export class TextContentTokenizer implements ContentTokenizer {
9
9
  /**
10
- *
10
+ *
11
11
  * @param defaultLanguage The default assumed language
12
12
  * @param unit The unit of the produced [Locator]s.
13
13
  * @param contextSnippetLength Length of `before` and `after` snippets in the produced [Locator]s.
@@ -27,7 +27,7 @@ export class TextContentTokenizer implements ContentTokenizer {
27
27
  new TextElement(
28
28
  data.locator,
29
29
  data.role,
30
- data.segments.map(s => this.tokenizeSegment(s)).flat(),
30
+ data.segments.map(s => this.tokenizeSegment(s)).flat(),
31
31
  )
32
32
  ];
33
33
  }
@@ -59,4 +59,4 @@ export class TextContentTokenizer implements ContentTokenizer {
59
59
  highlight: str.substring(range[0], range[1]),
60
60
  })
61
61
  }
62
- }
62
+ }
@@ -1,4 +1,4 @@
1
- import { ContentElement } from "./element";
1
+ import { ContentElement } from "./element/index.ts";
2
2
 
3
3
  export class IllegalStateError extends Error {
4
4
  constructor(message: string) {
@@ -43,4 +43,4 @@ export abstract class Iterator {
43
43
  async previousOrNull(): Promise<ContentElement | null> {
44
44
  return (await this.hasPrevious()) ? this.previous() : null;
45
45
  }
46
- }
46
+ }
@@ -1,4 +1,4 @@
1
- import { Language } from "../../../../util/Language";
1
+ import { Language } from "../../../../util/Language.ts";
2
2
 
3
3
  export class Attribute<V> {
4
4
  constructor(
@@ -41,4 +41,4 @@ export abstract class AttributesHolder {
41
41
  attributes<V>(key: AttributeKeys | string): V[] {
42
42
  return this._attributes.filter(attribute => attribute.key === key).map(attribute => attribute.value);
43
43
  }
44
- }
44
+ }
@@ -1,7 +1,7 @@
1
- import { Link } from "../../../Link";
2
- import { Locator } from "../../../Locator";
3
- import { AttributesHolder, Attribute } from "./attributes";
4
- import { TextRole } from "./text_role";
1
+ import { Link } from "../../../Link.ts";
2
+ import { Locator } from "../../../Locator.ts";
3
+ import { AttributesHolder, Attribute } from "./attributes.ts";
4
+ import { TextRole } from "./text_role.ts";
5
5
 
6
6
  /**
7
7
  * Represents a single semantic content element part of a publication.
@@ -115,4 +115,4 @@ export class TextElement extends TextualElement {
115
115
  get text(): string | undefined {
116
116
  return this.segments.map(segment => segment.text).join("");
117
117
  }
118
- }
118
+ }
@@ -1,3 +1,3 @@
1
- export * from './element';
2
- export * from './attributes';
3
- export * from './text_role';
1
+ export * from './element.ts';
2
+ export * from './attributes.ts';
3
+ export * from './text_role.ts';
@@ -1,5 +1,5 @@
1
- export * from './Content';
2
- export * from './ContentTokenizer';
3
- export * from './Iterator';
4
- export * from './element';
5
- export * from './iterators';
1
+ export * from './Content.ts';
2
+ export * from './ContentTokenizer.ts';
3
+ export * from './Iterator.ts';
4
+ export * from './element/index.ts';
5
+ export * from './iterators/index.ts';
@@ -1,9 +1,9 @@
1
- import { Resource } from "../../../../fetcher/Resource";
2
- import { Link, Links } from "../../../Link";
3
- import { Locator, LocatorLocations } from "../../../Locator";
4
- import { IllegalStateError, Iterator } from "../Iterator";
5
- import { Attribute, AttributeKeys, AudioElement, Body, ContentElement, Footnote, Heading, ImageElement, TextElement, TextQuote, TextRole, TextSegment, VideoElement } from "../element";
6
- import { appendNormalizedWhitespace, elementLanguage, isBlank, isInlineTag, srcRelativeToHref, trimUnicodeSpace, trimUnicodeSpaceEnd, trimUnicodeSpaceStart, trimmingTextLocator } from "./helpers";
1
+ import { Resource } from "../../../../fetcher/Resource.ts";
2
+ import { Link, Links } from "../../../Link.ts";
3
+ import { Locator, LocatorLocations } from "../../../Locator.ts";
4
+ import { IllegalStateError, Iterator } from "../Iterator.ts";
5
+ import { Attribute, AttributeKeys, AudioElement, Body, ContentElement, Footnote, Heading, ImageElement, TextElement, TextQuote, TextRole, TextSegment, VideoElement } from "../element/index.ts";
6
+ import { appendNormalizedWhitespace, elementLanguage, isBlank, isInlineTag, srcRelativeToHref, trimUnicodeSpace, trimUnicodeSpaceEnd, trimUnicodeSpaceStart, trimmingTextLocator } from "./helpers.ts";
7
7
  import { getCssSelector } from "css-selector-generator";
8
8
 
9
9
  interface ElementWithDelta {
@@ -297,7 +297,7 @@ class ContentParser implements NodeVisitor {
297
297
  sr.attributes
298
298
  );
299
299
  });
300
-
300
+
301
301
  return new TextElement(
302
302
  new Locator({
303
303
  href: this.baseLocator.href,
@@ -568,4 +568,4 @@ class ContentParser implements NodeVisitor {
568
568
  this.rawTextAcc = "";
569
569
  this.textAcc = "";
570
570
  }
571
- }
571
+ }
@@ -1,6 +1,6 @@
1
- import { Locator } from "../../../Locator";
2
- import { Attribute, ContentElement } from "../element";
3
- import { IllegalStateError, Iterator } from "../Iterator";
1
+ import { Locator } from "../../../Locator.ts";
2
+ import { Attribute, ContentElement } from "../element/index.ts";
3
+ import { IllegalStateError, Iterator } from "../Iterator.ts";
4
4
 
5
5
  // Type TextItem represents a text item in a PDF page (extracted from pdf.js TextItem type).
6
6
  type TextItem = {
@@ -47,7 +47,7 @@ class ElementInDirection {
47
47
  ) {}
48
48
  }
49
49
 
50
- /* An iterator which iterates through a whole PDF page provided,
50
+ /* An iterator which iterates through a whole PDF page provided,
51
51
  and returns the elements based on a [PDFReadableElement] array. */
52
52
 
53
53
  // TODO extend Iterator class!
@@ -65,7 +65,7 @@ export class PageContentIteratorPDF extends Iterator{
65
65
  */
66
66
  private pageContent: Array<TextItem>,
67
67
  private startLocator?: Locator | null | undefined
68
- ) {
68
+ ) {
69
69
  super();
70
70
  const contentFiltered = this.pageContent.filter(
71
71
  (item: TextItem) => item?.str !== " " && item?.str !== ""
@@ -95,7 +95,7 @@ export class PageContentIteratorPDF extends Iterator{
95
95
 
96
96
 
97
97
  // Returns the current element to be read.
98
- current(): ContentElement | null {
98
+ current(): ContentElement | null {
99
99
  return this.currentElement ? this.currentElement.element : null;
100
100
  }
101
101
 
@@ -105,9 +105,9 @@ export class PageContentIteratorPDF extends Iterator{
105
105
  }
106
106
 
107
107
  previous(): ContentElement {
108
-
108
+
109
109
  if (!this.currentElement) throw new IllegalStateError("Called next() without a successful call to hasNext() first");
110
-
110
+
111
111
  this.currentElement = this.nextIn(Direction.Backward);
112
112
 
113
113
  if (this.currentElementIndex && this.currentElementIndex > 0) {
@@ -115,11 +115,11 @@ export class PageContentIteratorPDF extends Iterator{
115
115
  this.currentProgression = newIndex / this.pageContentFiltered.length * 100;
116
116
  this.currentElementIndex = newIndex;
117
117
  }
118
-
119
- return this.currentElement ?
120
- this.currentElement.element :
118
+
119
+ return this.currentElement ?
120
+ this.currentElement.element :
121
121
  new PDFContentElement(new Locator( { href : "", type: "" }), { index: -1, text: "" });
122
-
122
+
123
123
  }
124
124
 
125
125
  async hasNext(): Promise<boolean> {
@@ -128,21 +128,21 @@ export class PageContentIteratorPDF extends Iterator{
128
128
  }
129
129
 
130
130
  next(): ContentElement {
131
-
131
+
132
132
  this.currentElement = this.nextIn(Direction.Forward);
133
133
  const currentIndex = this.currentElementIndex;
134
134
  if (currentIndex !== null &&
135
- currentIndex >= 0 &&
135
+ currentIndex >= 0 &&
136
136
  currentIndex < this.pageContentFiltered.length - 1) {
137
137
  const newIndex = currentIndex + 1;
138
138
  this.currentProgression = newIndex / (this.pageContentFiltered.length) * 100;
139
139
  this.currentElementIndex = newIndex;
140
140
  }
141
-
142
- return this.currentElement ?
143
- this.currentElement.element :
141
+
142
+ return this.currentElement ?
143
+ this.currentElement.element :
144
144
  new PDFContentElement(new Locator( { href : "", type: "" }), { index: -1, text: "" });
145
-
145
+
146
146
  }
147
147
 
148
148
  private nextIn(direction: Direction): ElementInDirection | null {
@@ -173,12 +173,12 @@ export class PageContentIteratorPDF extends Iterator{
173
173
  */
174
174
  private updateElementIndex(): number | null {
175
175
  if (this.currentProgression === 0) return 0;
176
-
176
+
177
177
  // return null if the current progression is out of bounds
178
178
  if (this.currentProgression < 0 || this.currentProgression >= 100) return null;
179
-
179
+
180
180
  // Convert the progression percentage to an index in the pageContentFiltered array
181
181
  return Math.floor(this.currentProgression * this.pageContentFiltered.length / 100);
182
182
  }
183
183
 
184
- }
184
+ }
@@ -1,8 +1,8 @@
1
- import { Resource } from "../../../../fetcher/Resource";
2
- import { Locator } from "../../../Locator";
3
- import { Publication } from "../../../Publication";
4
- import { IllegalStateError, Iterator } from "../Iterator";
5
- import { ContentElement } from "../element";
1
+ import { Resource } from "../../../../fetcher/Resource.ts";
2
+ import { Locator } from "../../../Locator.ts";
3
+ import { Publication } from "../../../Publication.ts";
4
+ import { IllegalStateError, Iterator } from "../Iterator.ts";
5
+ import { ContentElement } from "../element/index.ts";
6
6
 
7
7
  // Creates a [Content.Iterator] instance for the [Resource], starting from the given [Locator].
8
8
  // Returns null if the resource media type is not supported.
@@ -141,4 +141,4 @@ export class PublicationContentIterator extends Iterator {
141
141
 
142
142
  return null;
143
143
  }
144
- }
144
+ }
@@ -1,4 +1,4 @@
1
- import { LocatorText } from "../../../Locator";
1
+ import { LocatorText } from "../../../Locator.ts";
2
2
 
3
3
 
4
4
  // https://github.com/jhy/jsoup/blob/0b10d516ed8f907f8fb4acb9a0806137a8988d45/src/main/java/org/jsoup/parser/Tag.java#L243
@@ -1,3 +1,3 @@
1
- export * from './PublicationContentIterator';
2
- export * from './PDFTextContentIterator';
3
- export * from './HTMLResourceContentIterator';
1
+ export * from './PublicationContentIterator.ts';
2
+ export * from './PDFTextContentIterator.ts';
3
+ export * from './HTMLResourceContentIterator.ts';
@@ -1,2 +1,2 @@
1
- export * from './content';
2
- export * from './timeline';
1
+ export * from './timeline/index.ts';
2
+ export * from './content/index.ts';