@readium/shared 1.2.1 → 2.0.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 (56) hide show
  1. package/dist/index.js +1256 -1152
  2. package/dist/index.umd.cjs +3 -3
  3. package/package.json +11 -10
  4. package/src/publication/AltIdentifier.ts +58 -0
  5. package/src/publication/Contributor.ts +15 -0
  6. package/src/publication/GuidedNavigation.ts +126 -15
  7. package/src/publication/Layout.ts +13 -0
  8. package/src/publication/Link.ts +9 -1
  9. package/src/publication/Manifest.ts +5 -5
  10. package/src/publication/Metadata.ts +77 -8
  11. package/src/publication/Profiles.ts +15 -0
  12. package/src/publication/Properties.ts +10 -0
  13. package/src/publication/Publication.ts +2 -2
  14. package/src/publication/ReadingProgression.ts +2 -15
  15. package/src/publication/TDM.ts +56 -0
  16. package/src/publication/epub/MediaOverlay.ts +43 -0
  17. package/src/publication/epub/Metadata.ts +16 -0
  18. package/src/publication/epub/Properties.ts +0 -10
  19. package/src/publication/epub/index.ts +2 -2
  20. package/src/publication/index.ts +4 -1
  21. package/src/util/JSONParse.ts +3 -3
  22. package/types/src/publication/AltIdentifier.d.ts +23 -0
  23. package/types/src/publication/Contributor.d.ts +4 -0
  24. package/types/src/publication/GuidedNavigation.d.ts +62 -9
  25. package/types/src/publication/Layout.d.ts +8 -0
  26. package/types/src/publication/Link.d.ts +3 -0
  27. package/types/src/publication/Manifest.d.ts +2 -2
  28. package/types/src/publication/Metadata.d.ts +25 -2
  29. package/types/src/publication/Profiles.d.ts +10 -0
  30. package/types/src/publication/Properties.d.ts +6 -0
  31. package/types/src/publication/Publication.d.ts +1 -1
  32. package/types/src/publication/ReadingProgression.d.ts +2 -5
  33. package/types/src/publication/TDM.d.ts +30 -0
  34. package/types/src/publication/accessibility/Accessibility.d.ts +196 -0
  35. package/types/src/publication/accessibility/AccessibilityMetadataDisplayGuide.d.ts +211 -0
  36. package/types/src/publication/accessibility/Localization.d.ts +37 -0
  37. package/types/src/publication/accessibility/index.d.ts +3 -0
  38. package/types/src/publication/epub/MediaOverlay.d.ts +19 -0
  39. package/types/src/publication/epub/Metadata.d.ts +6 -0
  40. package/types/src/publication/epub/Properties.d.ts +1 -5
  41. package/types/src/publication/epub/index.d.ts +2 -2
  42. package/types/src/publication/index.d.ts +4 -1
  43. package/types/src/util/JSONParse.d.ts +2 -2
  44. package/LICENSE +0 -28
  45. package/src/publication/epub/EPUBLayout.ts +0 -10
  46. package/src/publication/epub/Presentation.ts +0 -16
  47. package/src/publication/presentation/Metadata.ts +0 -19
  48. package/src/publication/presentation/Presentation.ts +0 -155
  49. package/src/publication/presentation/Properties.ts +0 -70
  50. package/src/publication/presentation/index.ts +0 -3
  51. package/types/src/publication/epub/EPUBLayout.d.ts +0 -5
  52. package/types/src/publication/epub/Presentation.d.ts +0 -7
  53. package/types/src/publication/presentation/Metadata.d.ts +0 -6
  54. package/types/src/publication/presentation/Presentation.d.ts +0 -95
  55. package/types/src/publication/presentation/Properties.d.ts +0 -32
  56. package/types/src/publication/presentation/index.d.ts +0 -3
@@ -0,0 +1,43 @@
1
+ /* Copyright 2025 Readium Foundation. All rights reserved.
2
+ * Use of this source code is governed by a BSD-style license,
3
+ * available in the LICENSE file present in the Github repository of the project.
4
+ */
5
+
6
+ export class MediaOverlay {
7
+ /** Author-defined CSS class name to apply to the currently-playing EPUB Content Document element. */
8
+ public activeClass?: string;
9
+
10
+ /** Author-defined CSS class name to apply to the EPUB Content Document's document element when playback is active. */
11
+ public playbackActiveClass?: string;
12
+
13
+ /** Creates a MediaOverlay object */
14
+ constructor(values: {
15
+ activeClass?: string;
16
+ playbackActiveClass?: string;
17
+ }) {
18
+ this.activeClass = values.activeClass;
19
+ this.playbackActiveClass = values.playbackActiveClass;
20
+ }
21
+
22
+ /**
23
+ * Parses a MediaOverlay from its RWPM JSON representation.
24
+ */
25
+ public static deserialize(json: any): MediaOverlay | undefined {
26
+ if (!json) return;
27
+
28
+ return new MediaOverlay({
29
+ activeClass: json.activeClass,
30
+ playbackActiveClass: json.playbackActiveClass,
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Serializes a MediaOverlay to its RWPM JSON representation.
36
+ */
37
+ public serialize(): any {
38
+ const json: any = {};
39
+ if (this.activeClass) json.activeClass = this.activeClass;
40
+ if (this.playbackActiveClass) json.playbackActiveClass = this.playbackActiveClass;
41
+ return json;
42
+ }
43
+ }
@@ -0,0 +1,16 @@
1
+ import { Metadata } from "../Metadata";
2
+ import { MediaOverlay } from "./MediaOverlay";
3
+
4
+ declare module '../Metadata' {
5
+ export interface Metadata {
6
+ getMediaOverlay(): MediaOverlay | undefined;
7
+ }
8
+ }
9
+
10
+ Metadata.prototype.getMediaOverlay = function(): MediaOverlay | undefined {
11
+ const mediaOverlay = this.otherMetadata?.['mediaOverlay'];
12
+
13
+ if (!mediaOverlay) return;
14
+
15
+ return MediaOverlay.deserialize(mediaOverlay);
16
+ };
@@ -1,5 +1,4 @@
1
1
  import { Properties } from '../Properties';
2
- import { EPUBLayout } from './EPUBLayout';
3
2
 
4
3
  // EPUB extensions for link [Properties].
5
4
  // https://readium.org/webpub-manifest/schema/extensions/epub/properties.schema.json
@@ -11,18 +10,9 @@ declare module '../Properties' {
11
10
  * media type.
12
11
  */
13
12
  getContains(): Set<string> | undefined;
14
-
15
- /**
16
- * Hints how the layout of the resource should be presented.
17
- */
18
- getLayout(): EPUBLayout | undefined;
19
13
  }
20
14
  }
21
15
 
22
16
  Properties.prototype.getContains = function(): Set<string> | undefined {
23
17
  return new Set<string>(this.otherProperties['contains'] || []);
24
18
  };
25
-
26
- Properties.prototype.getLayout = function(): EPUBLayout | undefined {
27
- return this.otherProperties['layout'];
28
- };
@@ -1,4 +1,4 @@
1
- export * from './EPUBLayout';
2
- export * from './Presentation';
1
+ export * from './MediaOverlay';
2
+ export * from './Metadata';
3
3
  export * from './Properties';
4
4
  export * from './Publication';
@@ -2,8 +2,8 @@ export * from './encryption';
2
2
  export * from './epub';
3
3
  export * from './html';
4
4
  export * from './opds';
5
- export * from './presentation';
6
5
  export * from './services';
6
+ export * from './AltIdentifier';
7
7
  export * from './BelongsTo';
8
8
  export * from './Contributor';
9
9
  export * from './Link';
@@ -12,9 +12,12 @@ export * from './Locator';
12
12
  export * from './LocatorCollection';
13
13
  export * from './Manifest';
14
14
  export * from './Metadata';
15
+ export * from './Profiles';
15
16
  export * from './Properties';
16
17
  export * from './Publication';
17
18
  export * from './PublicationCollection';
19
+ export * from './Layout';
18
20
  export * from './ReadingProgression';
19
21
  export * from './Subject';
22
+ export * from './TDM';
20
23
  export * from './GuidedNavigation';
@@ -23,9 +23,9 @@ export function positiveNumberfromJSON(json: any): number | undefined {
23
23
  return num !== undefined && Math.sign(json) >= 0 ? json : undefined;
24
24
  }
25
25
 
26
- /** Converts a Set of a string to a string Array object */
27
- export function setToArray(obj: Set<string>): Array<string> {
28
- const list = new Array<string>();
26
+ /** Converts a Set to an Array object */
27
+ export function setToArray(obj: Set<any>): Array<any> {
28
+ const list = new Array<any>();
29
29
  obj.forEach(x => list.push(x));
30
30
  return list;
31
31
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Represents an alternate identifier for a publication.
3
+ * https://readium.org/webpub-manifest/schema/altIdentifier.schema.json
4
+ */
5
+ export declare class AltIdentifier {
6
+ /** The value of the alternate identifier. */
7
+ readonly value: string;
8
+ /** The scheme of the alternate identifier (URI format). */
9
+ readonly scheme?: string;
10
+ /** Creates an AltIdentifier object */
11
+ constructor(values: {
12
+ value: string;
13
+ scheme?: string;
14
+ });
15
+ /**
16
+ * Parses an AltIdentifier from its RWPM JSON representation.
17
+ */
18
+ static deserialize(json: string | any): AltIdentifier | undefined;
19
+ /**
20
+ * Serializes an AltIdentifier to its RWPM JSON representation.
21
+ */
22
+ serialize(): string | any;
23
+ }
@@ -1,5 +1,6 @@
1
1
  import { Links } from './Link';
2
2
  import { LocalizedString } from './LocalizedString';
3
+ import { AltIdentifier } from './AltIdentifier';
3
4
  /**
4
5
  * Contributor Object for the Readium Web Publication Manifest.
5
6
  * https://readium.org/webpub-manifest/schema/contributor-object.schema.json
@@ -11,6 +12,8 @@ export declare class Contributor {
11
12
  readonly sortAs?: string;
12
13
  /** An unambiguous reference to this contributor. */
13
14
  readonly identifier?: string;
15
+ /** Alternate identifiers for this contributor. */
16
+ readonly altIdentifiers?: Set<AltIdentifier>;
14
17
  /** The role of the contributor in the publication making. */
15
18
  readonly roles?: Set<string>;
16
19
  /** Used to retrieve similar publications for the given contributor. */
@@ -24,6 +27,7 @@ export declare class Contributor {
24
27
  name: LocalizedString;
25
28
  sortAs?: string;
26
29
  identifier?: string;
30
+ altIdentifiers?: Set<AltIdentifier>;
27
31
  roles?: Set<string>;
28
32
  links?: Links;
29
33
  position?: number;
@@ -19,6 +19,33 @@ export declare class GuidedNavigationDocument {
19
19
  static deserialize(json: any): GuidedNavigationDocument | undefined;
20
20
  serialize(): any;
21
21
  }
22
+ /**
23
+ * Represents a text value containing plain text, SSML, and language information.
24
+ */
25
+ export declare class GuidedNavigationText {
26
+ /** Plain text content */
27
+ readonly plain?: string;
28
+ /** SSML (Speech Synthesis Markup Language) content */
29
+ readonly ssml?: string;
30
+ /**
31
+ * BCP 47 language tag
32
+ * @pattern ^((?<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})+))$
33
+ */
34
+ readonly language?: string;
35
+ constructor(values: {
36
+ plain?: string;
37
+ ssml?: string;
38
+ language?: string;
39
+ });
40
+ /**
41
+ * Deserializes a GuidedNavigationText from JSON
42
+ */
43
+ static deserialize(json: any): GuidedNavigationText | undefined;
44
+ /**
45
+ * Serializes the text to a plain object
46
+ */
47
+ serialize(): any;
48
+ }
22
49
  /**
23
50
  * Guided Navigation Object
24
51
  * https://github.com/readium/guided-navigation/blob/main/schema/object.schema.json
@@ -32,10 +59,23 @@ export declare class GuidedNavigationObject {
32
59
  readonly imgref?: string;
33
60
  /** Convey the structural semantics of a publication. */
34
61
  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;
62
+ /**
63
+ * Indicates the heading level (1-6) for the navigation object.
64
+ * @minimum 1
65
+ * @maximum 6
66
+ */
67
+ readonly level?: number;
68
+ /**
69
+ * Textual equivalent of the resources or fragment of the resources referenced by the current Guided Navigation Object.
70
+ */
71
+ readonly text?: GuidedNavigationText;
37
72
  /** References a textual resource or a fragment of it. */
38
73
  readonly textref?: string;
74
+ /**
75
+ * Describes the image referenced by the current Guided Navigation Object.
76
+ * This is a GuidedNavigationObject that should not contain 'level' or 'children' properties.
77
+ */
78
+ readonly description?: Omit<GuidedNavigationObject, 'level' | 'children'>;
39
79
  /**
40
80
  * Creates a [GuidedNavigation] object.
41
81
  */
@@ -44,22 +84,35 @@ export declare class GuidedNavigationObject {
44
84
  children?: GuidedNavigationObject[];
45
85
  imgref?: string;
46
86
  role?: Set<string>;
47
- text?: string;
87
+ level?: number;
88
+ text?: GuidedNavigationText;
48
89
  textref?: string;
90
+ description?: Omit<GuidedNavigationObject, 'level' | 'children'>;
49
91
  });
50
92
  /**
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
- */
93
+ * Gets the plain text content.
94
+ * Returns undefined if no text is available.
95
+ */
96
+ get plainText(): string | undefined;
97
+ /**
98
+ * Gets the SSML content if available.
99
+ */
100
+ get ssmlText(): string | undefined;
101
+ /**
102
+ * Gets the language of the text if available.
103
+ */
104
+ get textLanguage(): string | undefined;
105
+ /**
106
+ * Deserializes a GuidedNavigationObject from JSON
107
+ */
55
108
  static deserialize(json: any): GuidedNavigationObject | undefined;
56
109
  /**
57
110
  * Parses a [GuidedNavigationObject] array from its RWPM JSON representation.
58
- */
111
+ */
59
112
  static deserializeArray(json: any): GuidedNavigationObject[] | undefined;
60
113
  /**
61
114
  * Serializes a [GuidedNavigationObject] to its RWPM JSON representation.
62
- */
115
+ */
63
116
  serialize(): any;
64
117
  get audioFile(): string | undefined;
65
118
  get audioTime(): string | undefined;
@@ -0,0 +1,8 @@
1
+ /** Hint about the nature of the layout for the publication.
2
+ * https://readium.org/webpub-manifest/contexts/default/#layout-and-reading-progression
3
+ */
4
+ export declare enum Layout {
5
+ reflowable = "reflowable",
6
+ fixed = "fixed",
7
+ scrolled = "scrolled"
8
+ }
@@ -22,6 +22,8 @@ export declare class Link {
22
22
  readonly height?: number;
23
23
  /** Width of the linked resource in pixels. */
24
24
  readonly width?: number;
25
+ /** Size of the linked resource in bytes. */
26
+ readonly size?: number;
25
27
  /** Length of the linked resource in seconds. */
26
28
  readonly duration?: number;
27
29
  /** Bitrate of the linked resource in kbps. */
@@ -44,6 +46,7 @@ export declare class Link {
44
46
  properties?: Properties;
45
47
  height?: number;
46
48
  width?: number;
49
+ size?: number;
47
50
  duration?: number;
48
51
  bitrate?: number;
49
52
  languages?: Array<string>;
@@ -15,7 +15,7 @@ export declare class Manifest {
15
15
  /** Identifies resources that are necessary for rendering the publication. */
16
16
  readonly resources?: Links;
17
17
  /** Identifies the collection that contains a table of contents. */
18
- readonly tableOfContents?: Links;
18
+ readonly toc?: Links;
19
19
  readonly subcollections?: Map<string, Array<PublicationCollection>>;
20
20
  constructor(values: {
21
21
  context?: Array<string>;
@@ -23,7 +23,7 @@ export declare class Manifest {
23
23
  links: Links;
24
24
  readingOrder: Links;
25
25
  resources?: Links;
26
- tableOfContents?: Links;
26
+ toc?: Links;
27
27
  subcollections?: Map<string, Array<PublicationCollection>>;
28
28
  });
29
29
  /**
@@ -1,8 +1,12 @@
1
+ import { AltIdentifier } from './AltIdentifier';
1
2
  import { BelongsTo } from './BelongsTo';
2
3
  import { Contributors } from './Contributor';
4
+ import { Layout } from './Layout';
3
5
  import { LocalizedString } from './LocalizedString';
6
+ import { Profile } from './Profiles';
4
7
  import { ReadingProgression } from './ReadingProgression';
5
8
  import { Subjects } from './Subject';
9
+ import { TDM } from './TDM';
6
10
  /**
7
11
  * https://readium.org/webpub-manifest/schema/metadata.schema.json
8
12
  *
@@ -14,7 +18,9 @@ import { Subjects } from './Subject';
14
18
  export declare class Metadata {
15
19
  title: LocalizedString;
16
20
  typeUri?: string;
21
+ conformsTo?: Array<Profile>;
17
22
  identifier?: string;
23
+ altIdentifier?: AltIdentifier;
18
24
  subtitle?: LocalizedString;
19
25
  sortAs?: LocalizedString;
20
26
  artists?: Contributors;
@@ -38,9 +44,11 @@ export declare class Metadata {
38
44
  belongsTo?: BelongsTo;
39
45
  belongsToCollections?: Contributors;
40
46
  belongsToSeries?: Contributors;
47
+ layout?: Layout;
41
48
  readingProgression?: ReadingProgression;
42
49
  duration?: number;
43
50
  numberOfPages?: number;
51
+ tdm?: TDM;
44
52
  otherMetadata?: {
45
53
  [key: string]: any;
46
54
  };
@@ -50,7 +58,9 @@ export declare class Metadata {
50
58
  constructor(values: {
51
59
  title: LocalizedString;
52
60
  typeUri?: string;
61
+ conformsTo?: Array<Profile>;
53
62
  identifier?: string;
63
+ altIdentifier?: AltIdentifier;
54
64
  subtitle?: LocalizedString;
55
65
  sortAs?: LocalizedString;
56
66
  artists?: Contributors;
@@ -74,9 +84,11 @@ export declare class Metadata {
74
84
  belongsTo?: BelongsTo;
75
85
  belongsToCollections?: Contributors;
76
86
  belongsToSeries?: Contributors;
87
+ layout?: Layout;
77
88
  readingProgression?: ReadingProgression;
78
89
  duration?: number;
79
90
  numberOfPages?: number;
91
+ tdm?: TDM;
80
92
  otherMetadata?: {
81
93
  [key: string]: any;
82
94
  };
@@ -92,8 +104,19 @@ export declare class Metadata {
92
104
  */
93
105
  serialize(): any;
94
106
  /**
95
- * Computes a [ReadingProgression] when the value of [readingProgression] is set to
96
- * auto, using the publication language.
107
+ * Computes a [Layout] using the [conformsTo] profile and layout property.
108
+ *
109
+ * Special cases:
110
+ * - EPUB profile defaults to reflowable if layout is not present
111
+ * - Divina profile defaults to fixed if layout is not present
112
+ * - Layout is ignored for audiobook and PDF profiles
113
+ * - Layout is ignored if set to reflowable on a Divina profile
114
+ *
115
+ * Note: Stops at the first matching profile.
116
+ */
117
+ get effectiveLayout(): Layout | null;
118
+ /**
119
+ * Computes a [ReadingProgression] when the value of [readingProgression] is undefined, using the publication language.
97
120
  *
98
121
  * See this issue for more details: https://github.com/readium/architecture/issues/113
99
122
  */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Registered profiles.
3
+ * https://readium.org/webpub-manifest/profiles/
4
+ */
5
+ export declare enum Profile {
6
+ EPUB = "https://readium.org/webpub-manifest/profiles/epub",
7
+ AUDIOBOOK = "https://readium.org/webpub-manifest/profiles/audiobook",
8
+ DIVINA = "https://readium.org/webpub-manifest/profiles/divina",
9
+ PDF = "https://readium.org/webpub-manifest/profiles/pdf"
10
+ }
@@ -1,3 +1,8 @@
1
+ export declare enum Page {
2
+ left = "left",
3
+ right = "right",
4
+ center = "center"
5
+ }
1
6
  /**
2
7
  * Properties associated to the linked resource.
3
8
  *
@@ -11,6 +16,7 @@ export declare class Properties {
11
16
  constructor(values: {
12
17
  [key: string]: any;
13
18
  });
19
+ get page(): Page | undefined;
14
20
  /**
15
21
  * Creates a [Properties] from its RWPM JSON representation.
16
22
  */
@@ -20,7 +20,7 @@ export declare class Publication {
20
20
  /** Identifies resources that are necessary for rendering the publication. */
21
21
  readonly resources?: Links;
22
22
  /** Identifies the collection that contains a table of contents. */
23
- readonly tableOfContents?: Links;
23
+ readonly toc?: Links;
24
24
  /** Identifies the collection that contains sub collections. */
25
25
  readonly subcollections?: Map<string, Array<PublicationCollection>>;
26
26
  constructor(values: {
@@ -1,9 +1,6 @@
1
- import { Page } from './presentation/Presentation';
1
+ import { Page } from "./Properties";
2
2
  export declare enum ReadingProgression {
3
- auto = "auto",
4
- btt = "btt",
5
3
  ltr = "ltr",
6
- rtl = "rtl",
7
- ttb = "ttb"
4
+ rtl = "rtl"
8
5
  }
9
6
  export declare function leadingPage(readingProgression: ReadingProgression): Page;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * https://readium.org/webpub-manifest/contexts/default/#text-and-data-mining
3
+ */
4
+ export declare enum TDMReservation {
5
+ all = "all",
6
+ none = "none"
7
+ }
8
+ export declare class TDM {
9
+ /**
10
+ * Indicates whether the publication allows text and data mining.
11
+ */
12
+ readonly reservation?: TDMReservation;
13
+ /**
14
+ * Additional policy information about text and data mining usage.
15
+ */
16
+ readonly policy?: string;
17
+ /** Creates a [TDM] object */
18
+ constructor(values: {
19
+ reservation?: TDMReservation;
20
+ policy?: string;
21
+ });
22
+ /**
23
+ * Parses a [TDM] from its RWPM JSON representation.
24
+ */
25
+ static deserialize(json: any): TDM | undefined;
26
+ /**
27
+ * Serializes a [TDM] to its RWPM JSON representation.
28
+ */
29
+ serialize(): any;
30
+ }