@readium/shared 1.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 (150) hide show
  1. package/LICENSE +28 -0
  2. package/README.MD +27 -0
  3. package/dist/index.js +2536 -0
  4. package/dist/index.umd.cjs +2 -0
  5. package/package.json +73 -0
  6. package/src/fetcher/Fetcher.ts +37 -0
  7. package/src/fetcher/HttpFetcher.ts +122 -0
  8. package/src/fetcher/Resource.ts +37 -0
  9. package/src/fetcher/index.ts +2 -0
  10. package/src/index.ts +4 -0
  11. package/src/opds/Acquisition.ts +54 -0
  12. package/src/opds/Availability.ts +61 -0
  13. package/src/opds/Copies.ts +43 -0
  14. package/src/opds/Holds.ts +43 -0
  15. package/src/opds/Price.ts +51 -0
  16. package/src/opds/index.ts +5 -0
  17. package/src/publication/BelongsTo.ts +51 -0
  18. package/src/publication/Contributor.ts +129 -0
  19. package/src/publication/GuidedNavigation.ts +176 -0
  20. package/src/publication/Link.ts +332 -0
  21. package/src/publication/LocalizedString.ts +74 -0
  22. package/src/publication/Locator.ts +225 -0
  23. package/src/publication/LocatorCollection.ts +133 -0
  24. package/src/publication/Manifest.ts +256 -0
  25. package/src/publication/Metadata.ts +329 -0
  26. package/src/publication/Properties.ts +44 -0
  27. package/src/publication/Publication.ts +148 -0
  28. package/src/publication/PublicationCollection.ts +144 -0
  29. package/src/publication/ReadingProgression.ts +28 -0
  30. package/src/publication/Subject.ts +115 -0
  31. package/src/publication/encryption/Encryption.ts +68 -0
  32. package/src/publication/encryption/Properties.ts +20 -0
  33. package/src/publication/encryption/index.ts +2 -0
  34. package/src/publication/epub/EPUBLayout.ts +10 -0
  35. package/src/publication/epub/Presentation.ts +16 -0
  36. package/src/publication/epub/Properties.ts +28 -0
  37. package/src/publication/epub/Publication.ts +51 -0
  38. package/src/publication/epub/index.ts +4 -0
  39. package/src/publication/html/DomRange.ts +63 -0
  40. package/src/publication/html/DomRangePoint.ts +64 -0
  41. package/src/publication/html/Locations.ts +129 -0
  42. package/src/publication/html/index.ts +3 -0
  43. package/src/publication/index.ts +19 -0
  44. package/src/publication/opds/Properties.ts +84 -0
  45. package/src/publication/opds/Publication.ts +14 -0
  46. package/src/publication/opds/index.ts +2 -0
  47. package/src/publication/presentation/Metadata.ts +19 -0
  48. package/src/publication/presentation/Presentation.ts +155 -0
  49. package/src/publication/presentation/Properties.ts +70 -0
  50. package/src/publication/presentation/index.ts +3 -0
  51. package/src/publication/services/content/Content.ts +36 -0
  52. package/src/publication/services/content/ContentTokenizer.ts +62 -0
  53. package/src/publication/services/content/Iterator.ts +46 -0
  54. package/src/publication/services/content/element/attributes.ts +44 -0
  55. package/src/publication/services/content/element/element.ts +118 -0
  56. package/src/publication/services/content/element/index.ts +3 -0
  57. package/src/publication/services/content/element/text_role.ts +60 -0
  58. package/src/publication/services/content/index.ts +5 -0
  59. package/src/publication/services/content/iterators/HTMLResourceContentIterator.ts +571 -0
  60. package/src/publication/services/content/iterators/PDFTextContentIterator.ts +184 -0
  61. package/src/publication/services/content/iterators/PublicationContentIterator.ts +144 -0
  62. package/src/publication/services/content/iterators/helpers.ts +146 -0
  63. package/src/publication/services/content/iterators/index.ts +3 -0
  64. package/src/publication/services/index.ts +1 -0
  65. package/src/util/JSONParse.ts +31 -0
  66. package/src/util/Language.ts +5 -0
  67. package/src/util/URITemplate.ts +83 -0
  68. package/src/util/index.ts +5 -0
  69. package/src/util/mediatype/MediaType.ts +563 -0
  70. package/src/util/mediatype/index.ts +1 -0
  71. package/src/util/tokenizer/TextTokenizer.ts +126 -0
  72. package/src/util/tokenizer/Tokenizer.ts +8 -0
  73. package/src/util/tokenizer/index.ts +2 -0
  74. package/src/util/tokenizer/tokenize-english/README.md +7 -0
  75. package/src/util/tokenizer/tokenize-english/abbreviations.js +52 -0
  76. package/src/util/tokenizer/tokenize-english/index.d.ts +3 -0
  77. package/src/util/tokenizer/tokenize-english/index.js +243 -0
  78. package/src/util/tokenizer/tokenize-english/utils.js +16 -0
  79. package/src/util/tokenizer/tokenize-text/README.MD +6 -0
  80. package/src/util/tokenizer/tokenize-text/index.d.ts +52 -0
  81. package/src/util/tokenizer/tokenize-text/index.js +256 -0
  82. package/src/util/tokenizer/tokenize-text/tokens.js +100 -0
  83. package/types/src/fetcher/Fetcher.d.ts +27 -0
  84. package/types/src/fetcher/HttpFetcher.d.ts +28 -0
  85. package/types/src/fetcher/Resource.d.ts +15 -0
  86. package/types/src/fetcher/index.d.ts +2 -0
  87. package/types/src/index.d.ts +4 -0
  88. package/types/src/opds/Acquisition.d.ts +26 -0
  89. package/types/src/opds/Availability.d.ts +32 -0
  90. package/types/src/opds/Copies.d.ts +22 -0
  91. package/types/src/opds/Holds.d.ts +22 -0
  92. package/types/src/opds/Price.d.ts +29 -0
  93. package/types/src/opds/index.d.ts +5 -0
  94. package/types/src/publication/BelongsTo.d.ts +23 -0
  95. package/types/src/publication/Contributor.d.ts +60 -0
  96. package/types/src/publication/GuidedNavigation.d.ts +70 -0
  97. package/types/src/publication/Link.d.ts +128 -0
  98. package/types/src/publication/LocalizedString.d.ts +48 -0
  99. package/types/src/publication/Locator.d.ts +101 -0
  100. package/types/src/publication/LocatorCollection.d.ts +54 -0
  101. package/types/src/publication/Manifest.d.ts +59 -0
  102. package/types/src/publication/Metadata.d.ts +101 -0
  103. package/types/src/publication/Properties.d.ts +28 -0
  104. package/types/src/publication/Publication.d.ts +53 -0
  105. package/types/src/publication/PublicationCollection.d.ts +34 -0
  106. package/types/src/publication/ReadingProgression.d.ts +9 -0
  107. package/types/src/publication/Subject.d.ts +56 -0
  108. package/types/src/publication/encryption/Encryption.d.ts +33 -0
  109. package/types/src/publication/encryption/Properties.d.ts +10 -0
  110. package/types/src/publication/encryption/index.d.ts +2 -0
  111. package/types/src/publication/epub/EPUBLayout.d.ts +5 -0
  112. package/types/src/publication/epub/Presentation.d.ts +7 -0
  113. package/types/src/publication/epub/Properties.d.ts +14 -0
  114. package/types/src/publication/epub/Publication.d.ts +19 -0
  115. package/types/src/publication/epub/index.d.ts +4 -0
  116. package/types/src/publication/html/DomRange.d.ts +40 -0
  117. package/types/src/publication/html/DomRangePoint.d.ts +36 -0
  118. package/types/src/publication/html/Locations.d.ts +45 -0
  119. package/types/src/publication/html/index.d.ts +3 -0
  120. package/types/src/publication/index.d.ts +19 -0
  121. package/types/src/publication/opds/Properties.d.ts +38 -0
  122. package/types/src/publication/opds/Publication.d.ts +6 -0
  123. package/types/src/publication/opds/index.d.ts +2 -0
  124. package/types/src/publication/presentation/Metadata.d.ts +6 -0
  125. package/types/src/publication/presentation/Presentation.d.ts +95 -0
  126. package/types/src/publication/presentation/Properties.d.ts +32 -0
  127. package/types/src/publication/presentation/index.d.ts +3 -0
  128. package/types/src/publication/services/content/Content.d.ts +20 -0
  129. package/types/src/publication/services/content/ContentTokenizer.d.ts +19 -0
  130. package/types/src/publication/services/content/Iterator.d.ts +38 -0
  131. package/types/src/publication/services/content/element/attributes.d.ts +31 -0
  132. package/types/src/publication/services/content/element/element.d.ts +107 -0
  133. package/types/src/publication/services/content/element/index.d.ts +3 -0
  134. package/types/src/publication/services/content/element/text_role.d.ts +53 -0
  135. package/types/src/publication/services/content/index.d.ts +5 -0
  136. package/types/src/publication/services/content/iterators/HTMLResourceContentIterator.d.ts +30 -0
  137. package/types/src/publication/services/content/iterators/PDFTextContentIterator.d.ts +60 -0
  138. package/types/src/publication/services/content/iterators/PublicationContentIterator.d.ts +59 -0
  139. package/types/src/publication/services/content/iterators/helpers.d.ts +10 -0
  140. package/types/src/publication/services/content/iterators/index.d.ts +3 -0
  141. package/types/src/publication/services/index.d.ts +1 -0
  142. package/types/src/util/JSONParse.d.ts +11 -0
  143. package/types/src/util/Language.d.ts +1 -0
  144. package/types/src/util/URITemplate.d.ts +24 -0
  145. package/types/src/util/index.d.ts +5 -0
  146. package/types/src/util/mediatype/MediaType.d.ts +148 -0
  147. package/types/src/util/mediatype/index.d.ts +1 -0
  148. package/types/src/util/tokenizer/TextTokenizer.d.ts +39 -0
  149. package/types/src/util/tokenizer/Tokenizer.d.ts +6 -0
  150. package/types/src/util/tokenizer/index.d.ts +2 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * A serializable representation of a boundary point in a DOM Range.
3
+ *
4
+ * The [cssSelector] field always references a DOM element. If the original DOM Range
5
+ * start/endContainer property references a DOM text node, the [textNodeIndex] field is used to
6
+ * complement the CSS Selector; thereby providing a pointer to a child DOM text node; and
7
+ * [charOffset] is used to tell a position within the character data of that DOM text node
8
+ * (just as the DOM Range start/endOffset does). If the original DOM Range start/endContainer
9
+ * property references a DOM Element, then the [textNodeIndex] field is used to designate the
10
+ * child Text node (just as the DOM Range start/endOffset does), and the optional [charOffset]
11
+ * field is not used (as there is no explicit position within the character data of the text
12
+ * node).
13
+ *
14
+ * https://github.com/readium/architecture/blob/master/models/locators/extensions/html.md#the-start-and-end-object
15
+ */
16
+ export declare class DomRangePoint {
17
+ cssSelector: string;
18
+ textNodeIndex: number;
19
+ charOffset?: number;
20
+ /**
21
+ * Creates a [DomRange].
22
+ */
23
+ constructor(values: {
24
+ cssSelector: string;
25
+ textNodeIndex: number;
26
+ charOffset?: number;
27
+ });
28
+ /**
29
+ * Parses a [DomRangePoint] from its RWPM JSON representation.
30
+ */
31
+ static deserialize(json: any): DomRangePoint | undefined;
32
+ /**
33
+ * Serializes a [DomRangePoint] to its RWPM JSON representation.
34
+ */
35
+ serialize(): any;
36
+ }
@@ -0,0 +1,45 @@
1
+ import { DomRange } from './DomRange';
2
+ declare module '../Locator' {
3
+ interface LocatorLocations {
4
+ /**
5
+ * A CSS Selector.
6
+ */
7
+ getCssSelector(): string | undefined;
8
+ /**
9
+ * [partialCfi] is an expression conforming to the "right-hand" side of the EPUB CFI syntax, that is
10
+ * to say: without the EPUB-specific OPF spine item reference that precedes the first ! exclamation
11
+ * mark (which denotes the "step indirection" into a publication document). Note that the wrapping
12
+ * epubcfi(***) syntax is not used for the [partialCfi] string, i.e. the "fragment" part of the CFI
13
+ * grammar is ignored.
14
+ */
15
+ getPartialCfi(): string | undefined;
16
+ /**
17
+ * An HTML DOM range.
18
+ */
19
+ getDomRange(): DomRange | undefined;
20
+ /**
21
+ * All named parameters found in the fragments, such as `p=5`.
22
+ */
23
+ fragmentParameters(): Map<string, string>;
24
+ /**
25
+ * HTML ID fragment identifier.
26
+ */
27
+ htmlId(): string | undefined;
28
+ /**
29
+ * Page fragment identifier, used for example in PDF.
30
+ */
31
+ page(): number | undefined;
32
+ /**
33
+ * Temporal Dimension media fragment, used for example in audiobooks.
34
+ *
35
+ * https://www.w3.org/TR/media-frags/
36
+ */
37
+ time(): number | undefined;
38
+ /**
39
+ * Spatial Dimension media fragment, used for example in audiobooks.
40
+ *
41
+ * https://www.w3.org/TR/media-frags/
42
+ */
43
+ space(): [number, number, number, number] | undefined;
44
+ }
45
+ }
@@ -0,0 +1,3 @@
1
+ export * from './DomRange';
2
+ export * from './DomRangePoint';
3
+ export * from './Locations';
@@ -0,0 +1,19 @@
1
+ export * from './encryption';
2
+ export * from './epub';
3
+ export * from './html';
4
+ export * from './opds';
5
+ export * from './presentation';
6
+ export * from './BelongsTo';
7
+ export * from './Contributor';
8
+ export * from './Link';
9
+ export * from './LocalizedString';
10
+ export * from './Locator';
11
+ export * from './LocatorCollection';
12
+ export * from './Manifest';
13
+ export * from './Metadata';
14
+ export * from './Properties';
15
+ export * from './Publication';
16
+ export * from './PublicationCollection';
17
+ export * from './ReadingProgression';
18
+ export * from './Subject';
19
+ export * from './GuidedNavigation';
@@ -0,0 +1,38 @@
1
+ import { Copies, Acquisition, Holds, Price, Availability } from '../../opds';
2
+ import { Link } from '../Link';
3
+ declare module '../Properties' {
4
+ interface Properties {
5
+ /**
6
+ * Provides a hint about the expected number of items returned.
7
+ */
8
+ getNumberOfItems(): number | undefined;
9
+ /**
10
+ * The price of a publication is tied to its acquisition link.
11
+ */
12
+ getPrice(): Price | undefined;
13
+ /**
14
+ * Indirect acquisition provides a hint for the expected media type that will be acquired after
15
+ * additional steps.
16
+ */
17
+ getIndirectAcquisitions(): Array<Acquisition> | undefined;
18
+ /**
19
+ * Library-specific features when a specific book is unavailable but provides a hold list.
20
+ */
21
+ getHolds(): Holds | undefined;
22
+ /**
23
+ * Library-specific feature that contains information about the copies that a library has acquired.
24
+ */
25
+ getCopies(): Copies | undefined;
26
+ /**
27
+ * Indicated the availability of a given resource.
28
+ */
29
+ getAvailability(): Availability | undefined;
30
+ /**
31
+ * Indicates that the linked resource supports authentication with the associated Authentication
32
+ * Document.
33
+ *
34
+ * See https://drafts.opds.io/authentication-for-opds-1.0.html
35
+ */
36
+ getAuthenticate(): Link | undefined;
37
+ }
38
+ }
@@ -0,0 +1,6 @@
1
+ import { Links } from '../Link';
2
+ declare module '../Publication' {
3
+ interface Publication {
4
+ getImages(): Links | undefined;
5
+ }
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Properties';
2
+ export * from './Publication';
@@ -0,0 +1,6 @@
1
+ import { Presentation } from './Presentation';
2
+ declare module '../Metadata' {
3
+ interface Metadata {
4
+ getPresentation(): Presentation | undefined;
5
+ }
6
+ }
@@ -0,0 +1,95 @@
1
+ import { EPUBLayout } from '../epub/EPUBLayout';
2
+ /**
3
+ * Suggested orientation for the device when displaying the linked resource.
4
+ */
5
+ export declare enum Orientation {
6
+ auto = "auto",
7
+ landscape = "landscape",
8
+ portrait = "portrait"
9
+ }
10
+ /**
11
+ * Suggested method for handling overflow while displaying the linked resource.
12
+ */
13
+ export declare enum Overflow {
14
+ auto = "auto",
15
+ clipped = "clipped",
16
+ paginated = "paginated",
17
+ scrolled = "scrolled"
18
+ }
19
+ /**
20
+ * Indicates how the linked resource should be displayed in a reading environment that displays
21
+ * synthetic spreads.
22
+ */
23
+ export declare enum Page {
24
+ left = "left",
25
+ right = "right",
26
+ center = "center"
27
+ }
28
+ /**
29
+ * Indicates the condition to be met for the linked resource to be rendered within a synthetic
30
+ * spread.
31
+ */
32
+ export declare enum Spread {
33
+ auto = "auto",
34
+ both = "both",
35
+ none = "none",
36
+ landscape = "landscape"
37
+ }
38
+ /**
39
+ * Suggested method for constraining a resource inside the viewport.
40
+ */
41
+ export declare enum Fit {
42
+ contain = "contain",
43
+ cover = "cover",
44
+ width = "width",
45
+ height = "height"
46
+ }
47
+ /** The Presentation Hints extension defines a number of hints for User Agents about the way content
48
+ * should be presented to the user.
49
+ *
50
+ * https://readium.org/webpub-manifest/extensions/presentation.html
51
+ * https://readium.org/webpub-manifest/schema/extensions/presentation/metadata.schema.json
52
+ *
53
+ * These properties can be undefined to avoid having default values when it doesn't make sense for a
54
+ * given `Publication`. If a navigator needs a default value when not specified,
55
+ * `Presentation.defaultX` and `Presentation.X.default` can be used.
56
+ */
57
+ export declare class Presentation {
58
+ /** Specifies whether or not the parts of a linked resource that flow out of the viewport are clipped */
59
+ clipped?: boolean;
60
+ /** Suggested method for constraining a resource inside the viewport. */
61
+ fit?: Fit;
62
+ /** Suggested orientation for the device when displaying the linked resource. */
63
+ orientation?: Orientation;
64
+ /** Indicates the condition to be met for the linked resource to be rendered
65
+ * within a synthetic spread
66
+ */
67
+ spread?: Spread;
68
+ /** Hint about the nature of the layout for the linked resources (EPUB extension). */
69
+ layout?: EPUBLayout;
70
+ /** Indicates how the progression between resources from the [readingOrder] should be handled */
71
+ continuous?: boolean;
72
+ /** Indicates if the overflow of linked resources from the `readingOrder` or `resources` should
73
+ * be handled using dynamic pagination or scrolling.
74
+ */
75
+ overflow?: Overflow;
76
+ /** Creates a [Presentation]. */
77
+ constructor(values: {
78
+ clipped?: boolean;
79
+ continuous?: boolean;
80
+ fit?: Fit;
81
+ orientation?: Orientation;
82
+ overflow?: Overflow;
83
+ spread?: Spread;
84
+ layout?: EPUBLayout;
85
+ });
86
+ /**
87
+ * Parses a [Presentation] from its RWPM JSON representation.
88
+ *
89
+ */
90
+ static deserialize(json: any): Presentation | undefined;
91
+ /**
92
+ * Serializes a [Presentation] to its RWPM JSON representation.
93
+ */
94
+ serialize(): any;
95
+ }
@@ -0,0 +1,32 @@
1
+ import { Fit, Orientation, Overflow, Page, Spread } from './Presentation';
2
+ declare module '../Properties' {
3
+ interface Properties {
4
+ /**
5
+ * Specifies whether or not the parts of a linked resource that flow out of the viewport are
6
+ * clipped.
7
+ */
8
+ getClipped(): boolean | undefined;
9
+ /**
10
+ * Suggested method for constraining a resource inside the viewport.
11
+ */
12
+ getFit(): Fit | undefined;
13
+ /**
14
+ * Suggested orientation for the device when displaying the linked resource.
15
+ */
16
+ getOrientation(): Orientation | undefined;
17
+ /**
18
+ * Suggested method for handling overflow while displaying the linked resource.
19
+ */
20
+ getOverflow(): Overflow | undefined;
21
+ /**
22
+ * Indicates how the linked resource should be displayed in a reading environment that displays
23
+ * synthetic spreads.
24
+ */
25
+ getPage(): Page | undefined;
26
+ /**
27
+ * Indicates the condition to be met for the linked resource to be rendered within a synthetic
28
+ * spread.
29
+ */
30
+ getSpread(): Spread | undefined;
31
+ }
32
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Presentation';
2
+ export * from './Metadata';
3
+ export * from './Properties';
@@ -0,0 +1,20 @@
1
+ import { Iterator } from "./Iterator";
2
+ import { ContentElement } from "./element";
3
+ /**
4
+ * Provides an iterable list of content [Element]s.
5
+ */
6
+ export declare abstract class Content {
7
+ /**
8
+ * Extracts the full raw text, or returns null if no text content can be found.
9
+ * @param separator Separator to use between individual elements. Defaults to newline.
10
+ */
11
+ text(separator?: string): string | null;
12
+ /**
13
+ * Creates a new iterator for this content.
14
+ */
15
+ abstract iterator(): Iterator;
16
+ /**
17
+ * Returns all the elements as a list.
18
+ */
19
+ elements(): ContentElement[];
20
+ }
@@ -0,0 +1,19 @@
1
+ import { TextTokenizer, TextUnit, Tokenizer } from "../../../util";
2
+ import { ContentElement } from "./element";
3
+ export type ContentTokenizer = Tokenizer<ContentElement, ContentElement>;
4
+ export declare class TextContentTokenizer implements ContentTokenizer {
5
+ private readonly defaultLanguage;
6
+ private readonly contextSnippetLength;
7
+ private readonly textTokenizerFactory;
8
+ /**
9
+ *
10
+ * @param defaultLanguage The default assumed language
11
+ * @param unit The unit of the produced [Locator]s.
12
+ * @param contextSnippetLength Length of `before` and `after` snippets in the produced [Locator]s.
13
+ * @param textTokenizerFactory Factory to create a [TextTokenizer] from, using the specified language and unit.
14
+ */
15
+ constructor(defaultLanguage: string | null, unit: TextUnit, contextSnippetLength?: number, textTokenizerFactory?: (language: string | null) => TextTokenizer);
16
+ tokenize(data: ContentElement): ContentElement[];
17
+ private tokenizeSegment;
18
+ private extractTextContextIn;
19
+ }
@@ -0,0 +1,38 @@
1
+ import { ContentElement } from "./element";
2
+ export declare class IllegalStateError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ /**
6
+ * Iterates through a list of [Element] items asynchronously.
7
+ * [hasNext] and [hasPrevious] refer to the last element computed by a previous call to any of both methods.
8
+ */
9
+ export declare abstract class Iterator {
10
+ /**
11
+ * Returns true if the iterator has a next element, suspending the caller while processing it.
12
+ */
13
+ abstract hasNext(): Promise<boolean>;
14
+ /**
15
+ * Retrieves the element computed by a preceding call to [hasNext], or throws an
16
+ * [IllegalStateError] if [hasNext] was not invoked. This method should only be used in
17
+ * pair with [hasNext].
18
+ */
19
+ abstract next(): ContentElement;
20
+ /**
21
+ * Advances to the next item and returns it, or null if we reached the end.
22
+ */
23
+ nextOrNull(): Promise<ContentElement | null>;
24
+ /**
25
+ * Returns true if the iterator has a previous element, suspending the caller while processing it.
26
+ */
27
+ abstract hasPrevious(): Promise<boolean>;
28
+ /**
29
+ * Retrieves the element computed by a preceding call to [hasPrevious], or throws an
30
+ * [IllegalStateError] if [hasPrevious] was not invoked. This method should only be used in
31
+ * pair with [hasPrevious].
32
+ */
33
+ abstract previous(): ContentElement;
34
+ /**
35
+ * Advances to the previous item and returns it, or null if we reached the beginning.
36
+ */
37
+ previousOrNull(): Promise<ContentElement | null>;
38
+ }
@@ -0,0 +1,31 @@
1
+ import { Language } from "../../../../util/Language";
2
+ export declare class Attribute<V> {
3
+ key: AttributeKeys | string;
4
+ value: V;
5
+ constructor(key: AttributeKeys | string, value: V);
6
+ }
7
+ export declare enum AttributeKeys {
8
+ ACCESSIBILITY_LABEL = "accessibilityLabel",
9
+ LANGUAGE = "language"
10
+ }
11
+ export declare abstract class AttributesHolder {
12
+ /**
13
+ * Associated list of attributes.
14
+ */
15
+ readonly _attributes: Attribute<any>[];
16
+ constructor(
17
+ /**
18
+ * Associated list of attributes.
19
+ */
20
+ _attributes?: Attribute<any>[]);
21
+ get language(): Language | undefined;
22
+ get accessibilityLabel(): string | undefined;
23
+ /**
24
+ * Gets the first attribute with the given [key].
25
+ */
26
+ attribute<V>(key: AttributeKeys | string): V | undefined;
27
+ /**
28
+ * Gets all the attributes with the given [key].
29
+ */
30
+ attributes<V>(key: AttributeKeys | string): V[];
31
+ }
@@ -0,0 +1,107 @@
1
+ import { Link } from "../../../Link";
2
+ import { Locator } from "../../../Locator";
3
+ import { AttributesHolder, Attribute } from "./attributes";
4
+ import { TextRole } from "./text_role";
5
+ /**
6
+ * Represents a single semantic content element part of a publication.
7
+ * NOTE: This is named "Element" in other toolkits. This conflicts with the JavaScript `Element` type so it's been renamed.
8
+ */
9
+ export declare abstract class ContentElement extends AttributesHolder {
10
+ readonly locator: Locator;
11
+ constructor(locator: Locator, attributes?: Attribute<any>[]);
12
+ }
13
+ /**
14
+ * An element which can be represented as human-readable text.
15
+ * The default implementation returns the first accessibility label associated to the element.
16
+ */
17
+ export declare class TextualElement extends ContentElement {
18
+ /**
19
+ * Human-readable text representation for this element.
20
+ */
21
+ get text(): string | undefined;
22
+ }
23
+ /**
24
+ * An element referencing an embedded external resource.
25
+ */
26
+ export interface EmbeddedElement extends ContentElement {
27
+ /**
28
+ * Referenced resource in the publication.
29
+ */
30
+ readonly embeddedLink: Link;
31
+ }
32
+ /**
33
+ * An audio clip.
34
+ */
35
+ export declare class AudioElement extends TextualElement implements EmbeddedElement {
36
+ readonly embeddedLink: Link;
37
+ constructor(locator: Locator, embeddedLink: Link, attributes?: Attribute<any>[]);
38
+ }
39
+ /**
40
+ * A video clip.
41
+ */
42
+ export declare class VideoElement extends TextualElement implements EmbeddedElement {
43
+ readonly embeddedLink: Link;
44
+ constructor(locator: Locator, embeddedLink: Link, attributes?: Attribute<any>[]);
45
+ }
46
+ /**
47
+ * A bitmap image.
48
+ */
49
+ export declare class ImageElement extends TextualElement implements EmbeddedElement {
50
+ readonly embeddedLink: Link;
51
+ /**
52
+ * Short piece of text associated with the image.
53
+ */
54
+ readonly caption?: string | undefined;
55
+ constructor(locator: Locator, embeddedLink: Link,
56
+ /**
57
+ * Short piece of text associated with the image.
58
+ */
59
+ caption?: string | undefined, attributes?: Attribute<any>[]);
60
+ get text(): string | undefined;
61
+ }
62
+ export declare class TextSegment extends AttributesHolder {
63
+ /**
64
+ * Locator to the segment of text.
65
+ */
66
+ readonly locator: Locator;
67
+ /**
68
+ * Text in the segment.
69
+ */
70
+ readonly text: string;
71
+ constructor(
72
+ /**
73
+ * Locator to the segment of text.
74
+ */
75
+ locator: Locator,
76
+ /**
77
+ * Text in the segment.
78
+ */
79
+ text: string,
80
+ /**
81
+ * Attributes associated with this segment, e.g. language.
82
+ */
83
+ attributes?: Attribute<any>[]);
84
+ }
85
+ /**
86
+ * A text element.
87
+ */
88
+ export declare class TextElement extends TextualElement {
89
+ /**
90
+ * Purpose of this element in the broader context of the document.
91
+ */
92
+ readonly role: TextRole;
93
+ /**
94
+ * Ranged portions of text with associated attributes.
95
+ */
96
+ readonly segments: TextSegment[];
97
+ constructor(locator: Locator,
98
+ /**
99
+ * Purpose of this element in the broader context of the document.
100
+ */
101
+ role: TextRole,
102
+ /**
103
+ * Ranged portions of text with associated attributes.
104
+ */
105
+ segments: TextSegment[], attributes?: Attribute<any>[]);
106
+ get text(): string | undefined;
107
+ }
@@ -0,0 +1,3 @@
1
+ export * from './element';
2
+ export * from './attributes';
3
+ export * from './text_role';
@@ -0,0 +1,53 @@
1
+ export type Role = "heading-1" | "heading-2" | "heading-3" | "heading-4" | "heading-5" | "heading-6" | "body" | "footnote" | "quote";
2
+ /**
3
+ * Represents a purpose of an element in the broader context of the document.
4
+ */
5
+ export interface TextRole {
6
+ get role(): Role;
7
+ }
8
+ /**
9
+ * Title of a section.
10
+ */
11
+ export declare class Heading implements TextRole {
12
+ /**
13
+ * Heading importance, 1 being the highest.
14
+ */
15
+ readonly level: number;
16
+ constructor(
17
+ /**
18
+ * Heading importance, 1 being the highest.
19
+ */
20
+ level: number);
21
+ get role(): Role;
22
+ }
23
+ /**
24
+ * Normal body of content.
25
+ */
26
+ export declare const Body: TextRole;
27
+ /**
28
+ * A footnote at the bottom of a document.
29
+ */
30
+ export declare const Footnote: TextRole;
31
+ /**
32
+ * A quotation.
33
+ */
34
+ export declare class TextQuote implements TextRole {
35
+ /**
36
+ * URL to the source for this quote.
37
+ */
38
+ readonly referenceUrl: URL | undefined;
39
+ /**
40
+ * Name of the source for this quote.
41
+ */
42
+ readonly referenceTitle: string | undefined;
43
+ readonly role: Role;
44
+ constructor(
45
+ /**
46
+ * URL to the source for this quote.
47
+ */
48
+ referenceUrl: URL | undefined,
49
+ /**
50
+ * Name of the source for this quote.
51
+ */
52
+ referenceTitle: string | undefined);
53
+ }
@@ -0,0 +1,5 @@
1
+ export * from './Content';
2
+ export * from './ContentTokenizer';
3
+ export * from './Iterator';
4
+ export * from './element';
5
+ export * from './iterators';
@@ -0,0 +1,30 @@
1
+ import { Resource } from "../../../../fetcher/Resource";
2
+ import { Locator } from "../../../Locator";
3
+ import { Iterator } from "../Iterator";
4
+ import { ContentElement } from "../element";
5
+ /**
6
+ * Iterates an HTML [resource], starting from the given [locator].
7
+ *
8
+ * If you want to start mid-resource, the [locator] must contain a `cssSelector` key in its
9
+ * [Locator.Locations] object.
10
+ *
11
+ * If you want to start from the end of the resource, the [locator] must have a `progression` of 1.0.
12
+ *
13
+ * Locators will contain a `before` context of up to `beforeMaxLength` characters.
14
+ */
15
+ export declare class HTMLResourceContentIterator extends Iterator {
16
+ private resource;
17
+ private locator;
18
+ private beforeMaxLength;
19
+ private currentElement;
20
+ constructor(resource: Resource, locator: Locator, beforeMaxLength?: number);
21
+ hasPrevious(): Promise<boolean>;
22
+ previous(): ContentElement;
23
+ hasNext(): Promise<boolean>;
24
+ next(): ContentElement;
25
+ private currentIndex;
26
+ private parsedElementRecipes;
27
+ private elements;
28
+ private parser;
29
+ private parseElements;
30
+ }
@@ -0,0 +1,60 @@
1
+ import { Locator } from "../../../Locator";
2
+ import { Attribute, ContentElement } from "../element";
3
+ import { Iterator } from "../Iterator";
4
+ type TextItem = {
5
+ str: string;
6
+ dir: string;
7
+ locator: Locator;
8
+ };
9
+ /**
10
+ * A pdf element.
11
+ */
12
+ export declare class PDFContentElement extends ContentElement {
13
+ /**
14
+ * Readable text.
15
+ */
16
+ readonly element: PDFReadableElement;
17
+ constructor(locator: Locator,
18
+ /**
19
+ * Readable text.
20
+ */
21
+ element: PDFReadableElement, attributes?: Attribute<any>[]);
22
+ get text(): string | undefined;
23
+ }
24
+ export type PDFReadableElement = {
25
+ index: number;
26
+ text: string;
27
+ readingDirection?: string;
28
+ };
29
+ export declare class PageContentIteratorPDF extends Iterator {
30
+ /**
31
+ * The pdf page, represented as array of [TextItem] which will be iterated through.
32
+ * @param {Array<TextItem>} pageContent - an array that represents the page content of a PDF page.
33
+ * @param {Locator} startLocator - (optional) the locator of the first element to be read.
34
+ */
35
+ private pageContent;
36
+ private startLocator?;
37
+ private pageContentFiltered;
38
+ private currentElement;
39
+ private currentProgression;
40
+ private currentElementIndex;
41
+ constructor(
42
+ /**
43
+ * The pdf page, represented as array of [TextItem] which will be iterated through.
44
+ * @param {Array<TextItem>} pageContent - an array that represents the page content of a PDF page.
45
+ * @param {Locator} startLocator - (optional) the locator of the first element to be read.
46
+ */
47
+ pageContent: Array<TextItem>, startLocator?: Locator | null | undefined);
48
+ current(): ContentElement | null;
49
+ hasPrevious(): Promise<boolean>;
50
+ previous(): ContentElement;
51
+ hasNext(): Promise<boolean>;
52
+ next(): ContentElement;
53
+ private nextIn;
54
+ /**
55
+ * Updates the current [PDFReadableElement] position in the pageContentFiltered array
56
+ * based on the current progression value.
57
+ */
58
+ private updateElementIndex;
59
+ }
60
+ export {};