@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.
- package/LICENSE +28 -0
- package/README.MD +27 -0
- package/dist/index.js +2536 -0
- package/dist/index.umd.cjs +2 -0
- package/package.json +73 -0
- package/src/fetcher/Fetcher.ts +37 -0
- package/src/fetcher/HttpFetcher.ts +122 -0
- package/src/fetcher/Resource.ts +37 -0
- package/src/fetcher/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/opds/Acquisition.ts +54 -0
- package/src/opds/Availability.ts +61 -0
- package/src/opds/Copies.ts +43 -0
- package/src/opds/Holds.ts +43 -0
- package/src/opds/Price.ts +51 -0
- package/src/opds/index.ts +5 -0
- package/src/publication/BelongsTo.ts +51 -0
- package/src/publication/Contributor.ts +129 -0
- package/src/publication/GuidedNavigation.ts +176 -0
- package/src/publication/Link.ts +332 -0
- package/src/publication/LocalizedString.ts +74 -0
- package/src/publication/Locator.ts +225 -0
- package/src/publication/LocatorCollection.ts +133 -0
- package/src/publication/Manifest.ts +256 -0
- package/src/publication/Metadata.ts +329 -0
- package/src/publication/Properties.ts +44 -0
- package/src/publication/Publication.ts +148 -0
- package/src/publication/PublicationCollection.ts +144 -0
- package/src/publication/ReadingProgression.ts +28 -0
- package/src/publication/Subject.ts +115 -0
- package/src/publication/encryption/Encryption.ts +68 -0
- package/src/publication/encryption/Properties.ts +20 -0
- package/src/publication/encryption/index.ts +2 -0
- package/src/publication/epub/EPUBLayout.ts +10 -0
- package/src/publication/epub/Presentation.ts +16 -0
- package/src/publication/epub/Properties.ts +28 -0
- package/src/publication/epub/Publication.ts +51 -0
- package/src/publication/epub/index.ts +4 -0
- package/src/publication/html/DomRange.ts +63 -0
- package/src/publication/html/DomRangePoint.ts +64 -0
- package/src/publication/html/Locations.ts +129 -0
- package/src/publication/html/index.ts +3 -0
- package/src/publication/index.ts +19 -0
- package/src/publication/opds/Properties.ts +84 -0
- package/src/publication/opds/Publication.ts +14 -0
- package/src/publication/opds/index.ts +2 -0
- package/src/publication/presentation/Metadata.ts +19 -0
- package/src/publication/presentation/Presentation.ts +155 -0
- package/src/publication/presentation/Properties.ts +70 -0
- package/src/publication/presentation/index.ts +3 -0
- package/src/publication/services/content/Content.ts +36 -0
- package/src/publication/services/content/ContentTokenizer.ts +62 -0
- package/src/publication/services/content/Iterator.ts +46 -0
- package/src/publication/services/content/element/attributes.ts +44 -0
- package/src/publication/services/content/element/element.ts +118 -0
- package/src/publication/services/content/element/index.ts +3 -0
- package/src/publication/services/content/element/text_role.ts +60 -0
- package/src/publication/services/content/index.ts +5 -0
- package/src/publication/services/content/iterators/HTMLResourceContentIterator.ts +571 -0
- package/src/publication/services/content/iterators/PDFTextContentIterator.ts +184 -0
- package/src/publication/services/content/iterators/PublicationContentIterator.ts +144 -0
- package/src/publication/services/content/iterators/helpers.ts +146 -0
- package/src/publication/services/content/iterators/index.ts +3 -0
- package/src/publication/services/index.ts +1 -0
- package/src/util/JSONParse.ts +31 -0
- package/src/util/Language.ts +5 -0
- package/src/util/URITemplate.ts +83 -0
- package/src/util/index.ts +5 -0
- package/src/util/mediatype/MediaType.ts +563 -0
- package/src/util/mediatype/index.ts +1 -0
- package/src/util/tokenizer/TextTokenizer.ts +126 -0
- package/src/util/tokenizer/Tokenizer.ts +8 -0
- package/src/util/tokenizer/index.ts +2 -0
- package/src/util/tokenizer/tokenize-english/README.md +7 -0
- package/src/util/tokenizer/tokenize-english/abbreviations.js +52 -0
- package/src/util/tokenizer/tokenize-english/index.d.ts +3 -0
- package/src/util/tokenizer/tokenize-english/index.js +243 -0
- package/src/util/tokenizer/tokenize-english/utils.js +16 -0
- package/src/util/tokenizer/tokenize-text/README.MD +6 -0
- package/src/util/tokenizer/tokenize-text/index.d.ts +52 -0
- package/src/util/tokenizer/tokenize-text/index.js +256 -0
- package/src/util/tokenizer/tokenize-text/tokens.js +100 -0
- package/types/src/fetcher/Fetcher.d.ts +27 -0
- package/types/src/fetcher/HttpFetcher.d.ts +28 -0
- package/types/src/fetcher/Resource.d.ts +15 -0
- package/types/src/fetcher/index.d.ts +2 -0
- package/types/src/index.d.ts +4 -0
- package/types/src/opds/Acquisition.d.ts +26 -0
- package/types/src/opds/Availability.d.ts +32 -0
- package/types/src/opds/Copies.d.ts +22 -0
- package/types/src/opds/Holds.d.ts +22 -0
- package/types/src/opds/Price.d.ts +29 -0
- package/types/src/opds/index.d.ts +5 -0
- package/types/src/publication/BelongsTo.d.ts +23 -0
- package/types/src/publication/Contributor.d.ts +60 -0
- package/types/src/publication/GuidedNavigation.d.ts +70 -0
- package/types/src/publication/Link.d.ts +128 -0
- package/types/src/publication/LocalizedString.d.ts +48 -0
- package/types/src/publication/Locator.d.ts +101 -0
- package/types/src/publication/LocatorCollection.d.ts +54 -0
- package/types/src/publication/Manifest.d.ts +59 -0
- package/types/src/publication/Metadata.d.ts +101 -0
- package/types/src/publication/Properties.d.ts +28 -0
- package/types/src/publication/Publication.d.ts +53 -0
- package/types/src/publication/PublicationCollection.d.ts +34 -0
- package/types/src/publication/ReadingProgression.d.ts +9 -0
- package/types/src/publication/Subject.d.ts +56 -0
- package/types/src/publication/encryption/Encryption.d.ts +33 -0
- package/types/src/publication/encryption/Properties.d.ts +10 -0
- package/types/src/publication/encryption/index.d.ts +2 -0
- package/types/src/publication/epub/EPUBLayout.d.ts +5 -0
- package/types/src/publication/epub/Presentation.d.ts +7 -0
- package/types/src/publication/epub/Properties.d.ts +14 -0
- package/types/src/publication/epub/Publication.d.ts +19 -0
- package/types/src/publication/epub/index.d.ts +4 -0
- package/types/src/publication/html/DomRange.d.ts +40 -0
- package/types/src/publication/html/DomRangePoint.d.ts +36 -0
- package/types/src/publication/html/Locations.d.ts +45 -0
- package/types/src/publication/html/index.d.ts +3 -0
- package/types/src/publication/index.d.ts +19 -0
- package/types/src/publication/opds/Properties.d.ts +38 -0
- package/types/src/publication/opds/Publication.d.ts +6 -0
- package/types/src/publication/opds/index.d.ts +2 -0
- package/types/src/publication/presentation/Metadata.d.ts +6 -0
- package/types/src/publication/presentation/Presentation.d.ts +95 -0
- package/types/src/publication/presentation/Properties.d.ts +32 -0
- package/types/src/publication/presentation/index.d.ts +3 -0
- package/types/src/publication/services/content/Content.d.ts +20 -0
- package/types/src/publication/services/content/ContentTokenizer.d.ts +19 -0
- package/types/src/publication/services/content/Iterator.d.ts +38 -0
- package/types/src/publication/services/content/element/attributes.d.ts +31 -0
- package/types/src/publication/services/content/element/element.d.ts +107 -0
- package/types/src/publication/services/content/element/index.d.ts +3 -0
- package/types/src/publication/services/content/element/text_role.d.ts +53 -0
- package/types/src/publication/services/content/index.d.ts +5 -0
- package/types/src/publication/services/content/iterators/HTMLResourceContentIterator.d.ts +30 -0
- package/types/src/publication/services/content/iterators/PDFTextContentIterator.d.ts +60 -0
- package/types/src/publication/services/content/iterators/PublicationContentIterator.d.ts +59 -0
- package/types/src/publication/services/content/iterators/helpers.d.ts +10 -0
- package/types/src/publication/services/content/iterators/index.d.ts +3 -0
- package/types/src/publication/services/index.d.ts +1 -0
- package/types/src/util/JSONParse.d.ts +11 -0
- package/types/src/util/Language.d.ts +1 -0
- package/types/src/util/URITemplate.d.ts +24 -0
- package/types/src/util/index.d.ts +5 -0
- package/types/src/util/mediatype/MediaType.d.ts +148 -0
- package/types/src/util/mediatype/index.d.ts +1 -0
- package/types/src/util/tokenizer/TextTokenizer.d.ts +39 -0
- package/types/src/util/tokenizer/Tokenizer.d.ts +6 -0
- package/types/src/util/tokenizer/index.d.ts +2 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Token is an object like:
|
|
3
|
+
|
|
4
|
+
{
|
|
5
|
+
"value": "text content",
|
|
6
|
+
|
|
7
|
+
// Position of the index
|
|
8
|
+
"index": 0,
|
|
9
|
+
|
|
10
|
+
// Length of the token
|
|
11
|
+
"offset": "text content".length
|
|
12
|
+
}
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// Return a string ID to represent a list of tokens
|
|
16
|
+
function tokensId(tokens, prepend) {
|
|
17
|
+
if (!prepend) return null;
|
|
18
|
+
|
|
19
|
+
return tokens.reduce(function(prev, token) {
|
|
20
|
+
var tokId = [
|
|
21
|
+
token.index,
|
|
22
|
+
token.offset,
|
|
23
|
+
token.value
|
|
24
|
+
].join('-');
|
|
25
|
+
|
|
26
|
+
return [prev, tokId].join(':');
|
|
27
|
+
}, prepend);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Return properties for a token
|
|
31
|
+
function tokenProperties(tok) {
|
|
32
|
+
const { index, offset, value, ...rest } = tok;
|
|
33
|
+
return rest;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Normalize and resolve a list of tokens relative to a token
|
|
37
|
+
function normalizeTokens(relative, tokens) {
|
|
38
|
+
var _index = 0;
|
|
39
|
+
|
|
40
|
+
// Force as an array
|
|
41
|
+
if (!Array.isArray(tokens)) tokens = [tokens];
|
|
42
|
+
|
|
43
|
+
return tokens.map(function(subtoken) {
|
|
44
|
+
if (subtoken === null) return null;
|
|
45
|
+
if (typeof subtoken === 'string') {
|
|
46
|
+
subtoken = {
|
|
47
|
+
value: subtoken,
|
|
48
|
+
index: _index,
|
|
49
|
+
offset: subtoken.length
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (typeof subtoken === 'object') {
|
|
54
|
+
subtoken.index = subtoken.index || 0;
|
|
55
|
+
_index = _index + subtoken.index + subtoken.offset;
|
|
56
|
+
|
|
57
|
+
// Transform as an absolute token
|
|
58
|
+
subtoken.index = relative.index + subtoken.index;
|
|
59
|
+
subtoken.offset = subtoken.offset || subtoken.value.length;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return subtoken;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Merge tokens
|
|
67
|
+
function mergeTokens(tokens, mergeWith) {
|
|
68
|
+
if (tokens.length == 0) return null;
|
|
69
|
+
|
|
70
|
+
var value = '';
|
|
71
|
+
var offset = 0;
|
|
72
|
+
|
|
73
|
+
var firstIndex = tokens[0]?.index;
|
|
74
|
+
|
|
75
|
+
tokens.forEach(function(token, i) {
|
|
76
|
+
var prev = tokens[i - 1];
|
|
77
|
+
var next = tokens[i + 1];
|
|
78
|
+
|
|
79
|
+
var toFill = prev ? (token.index + 1 - (prev.index + prev.offset)): 0;
|
|
80
|
+
value = value + new Array(toFill).join(mergeWith) + token.value;
|
|
81
|
+
|
|
82
|
+
var absoluteOffset = (token.index - firstIndex) + token.offset;
|
|
83
|
+
if (absoluteOffset > offset) offset = absoluteOffset;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
// Index equal is the one from the first token
|
|
88
|
+
index: firstIndex,
|
|
89
|
+
|
|
90
|
+
value: value,
|
|
91
|
+
offset: Math.max(offset, value.length)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export default {
|
|
96
|
+
tokensId: tokensId,
|
|
97
|
+
normalize: normalizeTokens,
|
|
98
|
+
properties: tokenProperties,
|
|
99
|
+
merge: mergeTokens
|
|
100
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Link } from '../publication/Link';
|
|
2
|
+
import { Resource } from './Resource';
|
|
3
|
+
/** Provides access to a [Resource] from a [Link]. */
|
|
4
|
+
export interface Fetcher {
|
|
5
|
+
/**
|
|
6
|
+
* Known resources available in the medium, such as file paths on the file system
|
|
7
|
+
* or entries in a ZIP archive. This list is not exhaustive, and additional
|
|
8
|
+
* unknown resources might be reachable.
|
|
9
|
+
*
|
|
10
|
+
* If the medium has an inherent resource order, it should be followed.
|
|
11
|
+
* Otherwise, HREFs are sorted alphabetically.
|
|
12
|
+
*/
|
|
13
|
+
links(): Link[];
|
|
14
|
+
/**
|
|
15
|
+
* Returns the [Resource] at the given [link]'s HREF.
|
|
16
|
+
*
|
|
17
|
+
* A [Resource] is always returned, since for some cases we can't know if it exists before
|
|
18
|
+
* actually fetching it, such as HTTP. Therefore, errors are handled at the Resource level.
|
|
19
|
+
*/
|
|
20
|
+
get(link: Link): Resource;
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare class EmptyFetcher implements Fetcher {
|
|
24
|
+
close(): void;
|
|
25
|
+
links(): Link[];
|
|
26
|
+
get(_link: Link): Resource;
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Link } from '../publication/Link';
|
|
2
|
+
import { Fetcher } from './Fetcher';
|
|
3
|
+
import { NumberRange, Resource } from './Resource';
|
|
4
|
+
export type FetchImplementation = (input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>;
|
|
5
|
+
export declare class HttpFetcher implements Fetcher {
|
|
6
|
+
private readonly baseUrl?;
|
|
7
|
+
private readonly client;
|
|
8
|
+
constructor(client?: FetchImplementation, baseUrl?: string);
|
|
9
|
+
links(): Link[];
|
|
10
|
+
get(link: Link): Resource;
|
|
11
|
+
close(): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class HttpResource implements Resource {
|
|
14
|
+
private readonly _link;
|
|
15
|
+
private readonly url;
|
|
16
|
+
private readonly client;
|
|
17
|
+
private _headResponse?;
|
|
18
|
+
constructor(client: FetchImplementation, link: Link, url: string);
|
|
19
|
+
/** Cached HEAD response to get the expected content length and other metadata. */
|
|
20
|
+
private headResponse;
|
|
21
|
+
close(): void;
|
|
22
|
+
link(): Promise<Link>;
|
|
23
|
+
read(range?: NumberRange): Promise<Uint8Array | undefined>;
|
|
24
|
+
length(): Promise<number>;
|
|
25
|
+
readAsJSON(): Promise<unknown>;
|
|
26
|
+
readAsString(): Promise<string>;
|
|
27
|
+
readAsXML(): Promise<XMLDocument>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Link } from '../publication/Link';
|
|
2
|
+
export declare class NumberRange {
|
|
3
|
+
readonly start: number;
|
|
4
|
+
readonly endInclusive: number;
|
|
5
|
+
constructor(start: number, endInclusive: number);
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class Resource {
|
|
8
|
+
abstract link(): Promise<Link>;
|
|
9
|
+
abstract length(): Promise<number | undefined>;
|
|
10
|
+
abstract read(range?: NumberRange): Promise<Uint8Array | undefined>;
|
|
11
|
+
readAsString(): Promise<string | undefined>;
|
|
12
|
+
readAsJSON(): Promise<unknown | undefined>;
|
|
13
|
+
readAsXML(): Promise<XMLDocument | undefined>;
|
|
14
|
+
abstract close(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPDS Acquisition Object.
|
|
3
|
+
*
|
|
4
|
+
* https://drafts.opds.io/schema/acquisition-object.schema.json
|
|
5
|
+
*/
|
|
6
|
+
export declare class Acquisition {
|
|
7
|
+
/** Currency for the price, eg. EUR. */
|
|
8
|
+
type: string;
|
|
9
|
+
/** Price value, should only be used for display purposes, because of precision issues
|
|
10
|
+
* inherent with Double and the JSON parsing. */
|
|
11
|
+
children?: Array<Acquisition>;
|
|
12
|
+
/** Creates a [Acquisition]. */
|
|
13
|
+
constructor(values: {
|
|
14
|
+
type: string;
|
|
15
|
+
children?: Array<Acquisition>;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Parses a [Acquisition] from its RWPM JSON representation.
|
|
19
|
+
*/
|
|
20
|
+
static deserialize(json: any): Acquisition | undefined;
|
|
21
|
+
static deserializeArray(json: any): Array<Acquisition> | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Serializes a [Acquisition] to its RWPM JSON representation.
|
|
24
|
+
*/
|
|
25
|
+
serialize(): any;
|
|
26
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare enum AvailabilityStatus {
|
|
2
|
+
available = "available",
|
|
3
|
+
reserved = "reserved",
|
|
4
|
+
ready = "ready"
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Indicated the availability of a given resource.
|
|
8
|
+
*
|
|
9
|
+
* https://drafts.opds.io/schema/properties.schema.json
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export declare class Availability {
|
|
13
|
+
/**Timestamp for the previous state change. */
|
|
14
|
+
since?: Date;
|
|
15
|
+
/**Timestamp for the next state change. */
|
|
16
|
+
until?: Date;
|
|
17
|
+
state: AvailabilityStatus;
|
|
18
|
+
/** Creates a [Availability]. */
|
|
19
|
+
constructor(values: {
|
|
20
|
+
state: AvailabilityStatus;
|
|
21
|
+
since?: Date;
|
|
22
|
+
until?: Date;
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Parses a [Availability] from its RWPM JSON representation.
|
|
26
|
+
*/
|
|
27
|
+
static deserialize(json: any): Availability | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Serializes a [Availability] to its RWPM JSON representation.
|
|
30
|
+
*/
|
|
31
|
+
serialize(): any;
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library-specific feature that contains information about the copies that a library has acquired.
|
|
3
|
+
*
|
|
4
|
+
* https://drafts.opds.io/schema/properties.schema.json
|
|
5
|
+
*/
|
|
6
|
+
export declare class Copies {
|
|
7
|
+
total?: number;
|
|
8
|
+
available?: number;
|
|
9
|
+
/** Creates a [Copies]. */
|
|
10
|
+
constructor(values: {
|
|
11
|
+
total?: number;
|
|
12
|
+
available?: number;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Parses a [Copies] from its RWPM JSON representation.
|
|
16
|
+
*/
|
|
17
|
+
static deserialize(json: any): Copies | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Serializes a [Copies] to its RWPM JSON representation.
|
|
20
|
+
*/
|
|
21
|
+
serialize(): any;
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library-specific features when a specific book is unavailable but provides a hold list.
|
|
3
|
+
*
|
|
4
|
+
* https://drafts.opds.io/schema/properties.schema.json
|
|
5
|
+
*/
|
|
6
|
+
export declare class Holds {
|
|
7
|
+
total?: number;
|
|
8
|
+
position?: number;
|
|
9
|
+
/** Creates a [Price]. */
|
|
10
|
+
constructor(values: {
|
|
11
|
+
total?: number;
|
|
12
|
+
position?: number;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Parses a [Holds] from its RWPM JSON representation.
|
|
16
|
+
*/
|
|
17
|
+
static deserialize(json: any): Holds | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Serializes a [Holds] to its RWPM JSON representation.
|
|
20
|
+
*/
|
|
21
|
+
serialize(): any;
|
|
22
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The price of a publication in an OPDS link.
|
|
3
|
+
*
|
|
4
|
+
* https://drafts.opds.io/schema/properties.schema.json
|
|
5
|
+
*
|
|
6
|
+
* currency Currency for the price, eg. EUR.
|
|
7
|
+
* value Price value, should only be used for display purposes, because of precision issues
|
|
8
|
+
* inherent with Double and the JSON parsing.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Price {
|
|
11
|
+
/** Currency for the price, eg. EUR. */
|
|
12
|
+
currency: string;
|
|
13
|
+
/** Price value, should only be used for display purposes, because of precision issues
|
|
14
|
+
* inherent with Double and the JSON parsing. */
|
|
15
|
+
value: number;
|
|
16
|
+
/** Creates a [Price]. */
|
|
17
|
+
constructor(values: {
|
|
18
|
+
currency: string;
|
|
19
|
+
value: number;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Parses a [Price] from its RWPM JSON representation.
|
|
23
|
+
*/
|
|
24
|
+
static deserialize(json: any): Price | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Serializes a [Price] to its RWPM JSON representation.
|
|
27
|
+
*/
|
|
28
|
+
serialize(): any;
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Contributors as Collection } from './Contributor';
|
|
2
|
+
/**
|
|
3
|
+
* BelongsTo Object for the Readium Web Publication Manifest.
|
|
4
|
+
* https://readium.org/webpub-manifest/schema/contributor-object.schema.json
|
|
5
|
+
*/
|
|
6
|
+
export declare class BelongsTo {
|
|
7
|
+
/**
|
|
8
|
+
* Map of [BelongsTo] items.
|
|
9
|
+
*/
|
|
10
|
+
readonly items: Map<string, Collection>;
|
|
11
|
+
/** Creates an Array of [Subject]. */
|
|
12
|
+
constructor(values?: {
|
|
13
|
+
items?: Map<string, Collection>;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Parses a [BelongsTo] from its RWPM JSON representation.
|
|
17
|
+
*/
|
|
18
|
+
static deserialize(json: any): BelongsTo | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Serializes a [BelongsTo] to its RWPM JSON representation.
|
|
21
|
+
*/
|
|
22
|
+
serialize(): any;
|
|
23
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Links } from './Link';
|
|
2
|
+
import { LocalizedString } from './LocalizedString';
|
|
3
|
+
/**
|
|
4
|
+
* Contributor Object for the Readium Web Publication Manifest.
|
|
5
|
+
* https://readium.org/webpub-manifest/schema/contributor-object.schema.json
|
|
6
|
+
*/
|
|
7
|
+
export declare class Contributor {
|
|
8
|
+
/** The name of the contributor. */
|
|
9
|
+
readonly name: LocalizedString;
|
|
10
|
+
/** The string used to sort the name of the contributor. */
|
|
11
|
+
readonly sortAs?: string;
|
|
12
|
+
/** An unambiguous reference to this contributor. */
|
|
13
|
+
readonly identifier?: string;
|
|
14
|
+
/** The role of the contributor in the publication making. */
|
|
15
|
+
readonly roles?: Set<string>;
|
|
16
|
+
/** Used to retrieve similar publications for the given contributor. */
|
|
17
|
+
readonly links?: Links;
|
|
18
|
+
/** The position of the publication in this collection/series, when the contributor represents a collection. */
|
|
19
|
+
readonly position?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a [Contributor] object.
|
|
22
|
+
*/
|
|
23
|
+
constructor(values: {
|
|
24
|
+
name: LocalizedString;
|
|
25
|
+
sortAs?: string;
|
|
26
|
+
identifier?: string;
|
|
27
|
+
roles?: Set<string>;
|
|
28
|
+
links?: Links;
|
|
29
|
+
position?: number;
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Parses a [Contributor] from its RWPM JSON representation.
|
|
33
|
+
*
|
|
34
|
+
* A contributor can be parsed from a single string, or a full-fledged object.
|
|
35
|
+
*/
|
|
36
|
+
static deserialize(json: any): Contributor | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Serializes a [Contributor] to its RWPM JSON representation.
|
|
39
|
+
*/
|
|
40
|
+
serialize(): any;
|
|
41
|
+
}
|
|
42
|
+
export declare class Contributors {
|
|
43
|
+
/**
|
|
44
|
+
* Array of [Contributor] .
|
|
45
|
+
*/
|
|
46
|
+
readonly items: Array<Contributor>;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a [Contributors] object.
|
|
49
|
+
*/
|
|
50
|
+
constructor(items: Array<Contributor>);
|
|
51
|
+
/**
|
|
52
|
+
* Parses a [Contributors] from its RWPM JSON representation.
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
static deserialize(json: any): Contributors | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Serializes a [Contributors] to its RWPM JSON representation.
|
|
58
|
+
*/
|
|
59
|
+
serialize(): any;
|
|
60
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Links } from "./Link";
|
|
2
|
+
export interface Clip {
|
|
3
|
+
audioResource: string;
|
|
4
|
+
fragmentId?: string;
|
|
5
|
+
start?: number;
|
|
6
|
+
end?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Guided Navigation Document
|
|
10
|
+
* https://readium.org/guided-navigation/schema/document.schema.json
|
|
11
|
+
*/
|
|
12
|
+
export declare class GuidedNavigationDocument {
|
|
13
|
+
readonly links?: Links;
|
|
14
|
+
readonly guided?: GuidedNavigationObject[];
|
|
15
|
+
constructor(values: {
|
|
16
|
+
links?: Links;
|
|
17
|
+
guided?: GuidedNavigationObject[];
|
|
18
|
+
});
|
|
19
|
+
static deserialize(json: any): GuidedNavigationDocument | undefined;
|
|
20
|
+
serialize(): any;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Guided Navigation Object
|
|
24
|
+
* https://github.com/readium/guided-navigation/blob/main/schema/object.schema.json
|
|
25
|
+
*/
|
|
26
|
+
export declare class GuidedNavigationObject {
|
|
27
|
+
/** References an audio resource or a fragment of it. */
|
|
28
|
+
readonly audioref?: string;
|
|
29
|
+
/** Items that are children of the containing Guided Navigation Object. */
|
|
30
|
+
readonly children?: GuidedNavigationObject[];
|
|
31
|
+
/** References an image or a fragment of it. */
|
|
32
|
+
readonly imgref?: string;
|
|
33
|
+
/** Convey the structural semantics of a publication. */
|
|
34
|
+
readonly role?: Set<string>;
|
|
35
|
+
/** Textual equivalent of the resources or fragment of the resources referenced by the current Guided Navigation Object. */
|
|
36
|
+
readonly text?: string;
|
|
37
|
+
/** References a textual resource or a fragment of it. */
|
|
38
|
+
readonly textref?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a [GuidedNavigation] object.
|
|
41
|
+
*/
|
|
42
|
+
constructor(values: {
|
|
43
|
+
audioref?: string;
|
|
44
|
+
children?: GuidedNavigationObject[];
|
|
45
|
+
imgref?: string;
|
|
46
|
+
role?: Set<string>;
|
|
47
|
+
text?: string;
|
|
48
|
+
textref?: string;
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Parses a [GuidedNavigationObject] from its RWPM JSON representation.
|
|
52
|
+
*
|
|
53
|
+
* A GuidedNavigationObject can be parsed from a single string, or a full-fledged object.
|
|
54
|
+
*/
|
|
55
|
+
static deserialize(json: any): GuidedNavigationObject | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Parses a [GuidedNavigationObject] array from its RWPM JSON representation.
|
|
58
|
+
*/
|
|
59
|
+
static deserializeArray(json: any): GuidedNavigationObject[] | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Serializes a [GuidedNavigationObject] to its RWPM JSON representation.
|
|
62
|
+
*/
|
|
63
|
+
serialize(): any;
|
|
64
|
+
get audioFile(): string | undefined;
|
|
65
|
+
get audioTime(): string | undefined;
|
|
66
|
+
get textFile(): string | undefined;
|
|
67
|
+
get fragmentId(): string | undefined;
|
|
68
|
+
get clip(): Clip | undefined;
|
|
69
|
+
private parseTimer;
|
|
70
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { MediaType } from '../util/mediatype/MediaType';
|
|
2
|
+
import { Properties } from './Properties';
|
|
3
|
+
import { Locator } from './Locator';
|
|
4
|
+
/**
|
|
5
|
+
* Link Object for the Readium Web Publication Manifest.
|
|
6
|
+
* https://readium.org/webpub-manifest/schema/link.schema.json
|
|
7
|
+
*/
|
|
8
|
+
export declare class Link {
|
|
9
|
+
/** URI or URI template of the linked resource. */
|
|
10
|
+
readonly href: string;
|
|
11
|
+
/** Indicates that a URI template is used in href. */
|
|
12
|
+
readonly templated?: boolean;
|
|
13
|
+
/** MIME type of the linked resource. */
|
|
14
|
+
readonly type?: string;
|
|
15
|
+
/** Title of the linked resource. */
|
|
16
|
+
readonly title?: string;
|
|
17
|
+
/** Relation between the linked resource and its containing collection. */
|
|
18
|
+
readonly rels?: Set<string>;
|
|
19
|
+
/** Properties associated to the linked resource. */
|
|
20
|
+
properties?: Properties;
|
|
21
|
+
/** Height of the linked resource in pixels. */
|
|
22
|
+
readonly height?: number;
|
|
23
|
+
/** Width of the linked resource in pixels. */
|
|
24
|
+
readonly width?: number;
|
|
25
|
+
/** Length of the linked resource in seconds. */
|
|
26
|
+
readonly duration?: number;
|
|
27
|
+
/** Bitrate of the linked resource in kbps. */
|
|
28
|
+
readonly bitrate?: number;
|
|
29
|
+
/** Expected language of the linked resource. */
|
|
30
|
+
readonly languages?: Array<string>;
|
|
31
|
+
/** Alternate resources for the linked resource. */
|
|
32
|
+
readonly alternates?: Links;
|
|
33
|
+
/** Resources that are children of the linked resource, in the context of a given collection role. */
|
|
34
|
+
readonly children?: Links;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a [Link].
|
|
37
|
+
*/
|
|
38
|
+
constructor(values: {
|
|
39
|
+
href: string;
|
|
40
|
+
templated?: boolean;
|
|
41
|
+
type?: string;
|
|
42
|
+
title?: string;
|
|
43
|
+
rels?: Set<string>;
|
|
44
|
+
properties?: Properties;
|
|
45
|
+
height?: number;
|
|
46
|
+
width?: number;
|
|
47
|
+
duration?: number;
|
|
48
|
+
bitrate?: number;
|
|
49
|
+
languages?: Array<string>;
|
|
50
|
+
alternates?: Links;
|
|
51
|
+
children?: Links;
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Parses a [Link] from its RWPM JSON representation.
|
|
55
|
+
*/
|
|
56
|
+
static deserialize(json: any): Link | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Serializes a [Link] to its RWPM JSON representation.
|
|
59
|
+
*/
|
|
60
|
+
serialize(): any;
|
|
61
|
+
/** MediaType of the linked resource. */
|
|
62
|
+
get mediaType(): MediaType;
|
|
63
|
+
/** Computes an absolute URL to the link, relative to the given `baseURL`.
|
|
64
|
+
* If the link's `href` is already absolute, the `baseURL` is ignored.
|
|
65
|
+
*/
|
|
66
|
+
toURL(baseUrl?: string): string | undefined;
|
|
67
|
+
/** List of URI template parameter keys, if the `Link` is templated. */
|
|
68
|
+
get templateParameters(): Set<string>;
|
|
69
|
+
/** Expands the `Link`'s HREF by replacing URI template variables by the given parameters.
|
|
70
|
+
* See RFC 6570 on URI template: https://tools.ietf.org/html/rfc6570
|
|
71
|
+
*/
|
|
72
|
+
expandTemplate(parameters: {
|
|
73
|
+
[param: string]: string;
|
|
74
|
+
}): Link;
|
|
75
|
+
/**
|
|
76
|
+
* Makes a copy of this [Link] after merging in the given additional other [properties].
|
|
77
|
+
*/
|
|
78
|
+
addProperties(properties: {
|
|
79
|
+
[key: string]: any;
|
|
80
|
+
}): Link;
|
|
81
|
+
/**
|
|
82
|
+
* Creates a [Locator] from a reading order [Link].
|
|
83
|
+
*/
|
|
84
|
+
get locator(): Locator;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parses multiple JSON links into an array of Link.
|
|
88
|
+
*/
|
|
89
|
+
export declare class Links {
|
|
90
|
+
items: Array<Link>;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a [Links].
|
|
93
|
+
*/
|
|
94
|
+
constructor(items: Array<Link>);
|
|
95
|
+
/**
|
|
96
|
+
* Creates a list of [Link] from its RWPM JSON representation.
|
|
97
|
+
*/
|
|
98
|
+
static deserialize(json: any): Links | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Serializes an array of [Link] to its RWPM JSON representation.
|
|
101
|
+
*/
|
|
102
|
+
serialize(): any;
|
|
103
|
+
/** Finds the first link with the given relation. */
|
|
104
|
+
findWithRel(rel: string): Link | undefined;
|
|
105
|
+
/** Finds all the links with the given relation. */
|
|
106
|
+
filterByRel(rel: string): Array<Link>;
|
|
107
|
+
/** Finds the first link matching the given HREF. */
|
|
108
|
+
findWithHref(href: string): Link | undefined;
|
|
109
|
+
/** Finds the index of the first link matching the given HREF. */
|
|
110
|
+
findIndexWithHref(href: string): number;
|
|
111
|
+
/** Finds the first link matching the given media type. */
|
|
112
|
+
findWithMediaType(mediaType: string): Link | undefined;
|
|
113
|
+
/** Finds all the links matching the given media type. */
|
|
114
|
+
filterByMediaType(mediaType: string): Array<Link>;
|
|
115
|
+
/** Finds all the links matching any of the given media types. */
|
|
116
|
+
filterByMediaTypes(mediaTypes: Array<string>): Array<Link>;
|
|
117
|
+
/** Returns whether all the resources in the collection are audio clips. */
|
|
118
|
+
everyIsAudio(): boolean;
|
|
119
|
+
/** Returns whether all the resources in the collection are bitmaps. */
|
|
120
|
+
everyIsBitmap(): boolean;
|
|
121
|
+
/** Returns whether all the resources in the collection are HTML documents. */
|
|
122
|
+
everyIsHTML(): boolean;
|
|
123
|
+
/** Returns whether all the resources in the collection are video clips. */
|
|
124
|
+
everyIsVideo(): boolean;
|
|
125
|
+
/** Returns whether all the resources in the collection are matching any of the given media types. */
|
|
126
|
+
everyMatchesMediaType(mediaTypes: string | Array<string>): boolean;
|
|
127
|
+
filterLinksHasType(): Array<Link>;
|
|
128
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a string with multiple translations indexed by a BCP 47 language tag.
|
|
3
|
+
*/
|
|
4
|
+
export declare class LocalizedString {
|
|
5
|
+
readonly translations: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
8
|
+
static readonly UNDEFINED_LANGUAGE = "undefined";
|
|
9
|
+
static readonly LANGUAGE_EN = "en";
|
|
10
|
+
/**
|
|
11
|
+
* translations can be a string or a collection of language/translation pairs,
|
|
12
|
+
* for a single string the language is assumed to be undefined
|
|
13
|
+
*/
|
|
14
|
+
constructor(translations: string | {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Parses a [LocalizedString] from its RWPM JSON representation.
|
|
19
|
+
*
|
|
20
|
+
* "anyOf": [
|
|
21
|
+
* {
|
|
22
|
+
* "type": "string"
|
|
23
|
+
* },
|
|
24
|
+
* {
|
|
25
|
+
* "description": "The language in a language map must be a valid BCP 47 tag.",
|
|
26
|
+
* "type": "object",
|
|
27
|
+
* "patternProperties": {
|
|
28
|
+
* "^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?<privateUse>x(-[A-Za-z0-9]{1,8})+))?)|(?<privateUse2>x(-[A-Za-z0-9]{1,8})+))$": {
|
|
29
|
+
* "type": "string"
|
|
30
|
+
* }
|
|
31
|
+
* },
|
|
32
|
+
* "additionalProperties": false,
|
|
33
|
+
* "minProperties": 1
|
|
34
|
+
* }
|
|
35
|
+
* ]
|
|
36
|
+
*/
|
|
37
|
+
static deserialize(json: any): undefined | LocalizedString;
|
|
38
|
+
serialize(): any;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the first translation for the given [language] BCP–47 tag.
|
|
41
|
+
* If not found, then fallback:
|
|
42
|
+
* 1. on the undefined language
|
|
43
|
+
* 2. on the English language
|
|
44
|
+
* 3. the first translation found
|
|
45
|
+
* 4. returns empty string
|
|
46
|
+
*/
|
|
47
|
+
getTranslation(language?: string): string;
|
|
48
|
+
}
|