@readium/shared 2.2.0-alpha.2 → 2.2.0-beta.2

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 (54) hide show
  1. package/dist/index.js +1032 -794
  2. package/dist/index.umd.cjs +3 -3
  3. package/package.json +11 -11
  4. package/src/fetcher/HttpFetcher.ts +2 -2
  5. package/src/fetcher/Resource.ts +4 -4
  6. package/src/publication/Manifest.ts +11 -13
  7. package/src/publication/Publication.ts +43 -0
  8. package/src/publication/html/Locations.ts +0 -14
  9. package/src/publication/services/index.ts +2 -1
  10. package/src/publication/services/timeline/Timeline.ts +349 -0
  11. package/src/publication/services/timeline/TimelineItem.ts +24 -0
  12. package/src/publication/services/timeline/index.ts +2 -0
  13. package/src/util/mediatype/MediaType.ts +4 -0
  14. package/types/src/fetcher/HttpFetcher.d.ts +1 -1
  15. package/types/src/fetcher/Resource.d.ts +1 -1
  16. package/types/src/publication/Manifest.d.ts +1 -1
  17. package/types/src/publication/Publication.d.ts +14 -0
  18. package/types/src/publication/html/Locations.d.ts +0 -6
  19. package/types/src/publication/services/index.d.ts +1 -0
  20. package/types/src/publication/services/timeline/Timeline.d.ts +94 -0
  21. package/types/src/publication/services/timeline/TimelineItem.d.ts +24 -0
  22. package/types/src/publication/services/timeline/index.d.ts +2 -0
  23. package/types/src/util/mediatype/MediaType.d.ts +1 -0
  24. package/types/test/AltIdentifier.test.d.ts +1 -0
  25. package/types/test/Contributor.test.d.ts +1 -0
  26. package/types/test/GuidedNavigation.test.d.ts +1 -0
  27. package/types/test/Link.test.d.ts +1 -0
  28. package/types/test/LocalizedString.test.d.ts +1 -0
  29. package/types/test/Locator.test.d.ts +1 -0
  30. package/types/test/LocatorCollection.test.d.ts +1 -0
  31. package/types/test/Manifest.test.d.ts +1 -0
  32. package/types/test/Metadata.test.d.ts +1 -0
  33. package/types/test/Properties.test.d.ts +1 -0
  34. package/types/test/Publication.test.d.ts +1 -0
  35. package/types/test/PublicationCollection.test.d.ts +1 -0
  36. package/types/test/Subject.test.d.ts +1 -0
  37. package/types/test/TDM.test.d.ts +1 -0
  38. package/types/test/Timeline.test.d.ts +1 -0
  39. package/types/test/accessibility/Accessibility.test.d.ts +1 -0
  40. package/types/test/accessibility/AccessibilityMetadataDisplayGuide.test.d.ts +1 -0
  41. package/types/test/accessibility/Localization.test.d.ts +1 -0
  42. package/types/test/encryption/Encryption.test.d.ts +1 -0
  43. package/types/test/encryption/Properties.test.d.ts +1 -0
  44. package/types/test/epub/MediaOverlay.test.d.ts +1 -0
  45. package/types/test/epub/Metadata.test.d.ts +1 -0
  46. package/types/test/epub/PropertiesTest.test.d.ts +1 -0
  47. package/types/test/epub/PublicationTest.test.d.ts +1 -0
  48. package/types/test/html/DomRange.test.d.ts +1 -0
  49. package/types/test/html/Locator.test.d.ts +1 -0
  50. package/types/test/opds/PropertiesTest.test.d.ts +1 -0
  51. package/types/test/opds/PublicationTest.test.d.ts +1 -0
  52. package/types/test/util/URITemplate.test.d.ts +1 -0
  53. package/types/test/util/mediatype/MediaType.test.d.ts +1 -0
  54. package/LICENSE +0 -28
@@ -6,12 +6,14 @@ import { Fetcher } from '../fetcher/Fetcher';
6
6
  import { PublicationCollection } from './PublicationCollection';
7
7
  import { Resource } from '../fetcher/Resource';
8
8
  import { GuidedNavigationDocument } from "./GuidedNavigation";
9
+ import { Timeline } from './services/timeline/Timeline';
9
10
  export type ServiceFactory = () => null;
10
11
  /** Shared model for a Readium Publication. */
11
12
  export declare class Publication {
12
13
  /** The manifest holding the publication metadata extracted from the publication file */
13
14
  manifest: Manifest;
14
15
  private readonly fetcher;
16
+ private _timeline;
15
17
  readonly context?: Array<string>;
16
18
  readonly metadata: Metadata;
17
19
  readonly links: Links;
@@ -27,6 +29,12 @@ export declare class Publication {
27
29
  manifest: Manifest;
28
30
  fetcher?: Fetcher;
29
31
  });
32
+ /**
33
+ * Returns the publication's timeline, built from its reading order and table of contents.
34
+ * Called with no arguments, the result is cached. Pass options to build a fresh timeline
35
+ * with a specific configuration (e.g. a depth limit).
36
+ */
37
+ get timeline(): Timeline;
30
38
  /** The URL where this publication is served, computed from the `Link` with `self` relation.
31
39
  * e.g. https://provider.com/pub1293/manifest.json gives https://provider.com/pub1293/
32
40
  */
@@ -44,6 +52,12 @@ export declare class Publication {
44
52
  * Finds the first [Link] having the given [rel] in the publications's links.
45
53
  */
46
54
  linkWithRel(rel: string): Link | undefined;
55
+ /**
56
+ * Gets the cover image for the publication.
57
+ * First looks for rel='cover' in links/resources/readingOrder,
58
+ * then falls back to any image (JPEG, PNG, GIF, AVIF, SVG) as bitmap fallback.
59
+ */
60
+ getCover(): Link | undefined;
47
61
  positionsFromManifest(): Promise<Locator[]>;
48
62
  guideForLink(link: Link): Promise<GuidedNavigationDocument | undefined>;
49
63
  /**
@@ -41,11 +41,5 @@ declare module '../Locator' {
41
41
  * https://www.w3.org/TR/media-frags/
42
42
  */
43
43
  space(): [number, number, number, number] | undefined;
44
- /**
45
- * Text fragments, used by browsers to jump to/highlight text.
46
- *
47
- * https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments
48
- */
49
- text(): string | undefined;
50
44
  }
51
45
  }
@@ -1 +1,2 @@
1
1
  export * from './content';
2
+ export * from './timeline';
@@ -0,0 +1,94 @@
1
+ import { Link, Links } from "../../Link";
2
+ import { Locator } from "../../Locator";
3
+ import { TimelineItem } from "./TimelineItem";
4
+ interface PublicationLike {
5
+ toc?: Links;
6
+ readingOrder: Links;
7
+ }
8
+ /**
9
+ * A publication's timeline, built once from its reading order and table of contents.
10
+ *
11
+ * **Source of truth**: the reading order. Every reading order item becomes
12
+ * exactly one top-level `TimelineItem`. The TOC is consulted to:
13
+ * 1. Derive a display title when the reading order item has none.
14
+ * 2. Populate flat children — all TOC fragment entries that reference the
15
+ * resource, collected depth-first in TOC declaration order.
16
+ *
17
+ * No TOC hierarchy is reconstructed; that requires role context and is not yet
18
+ * implemented. TOC entries whose href does not match any reading order item
19
+ * are ignored.
20
+ *
21
+ * The `depth` build option limits how many levels deep into the TOC tree both
22
+ * title resolution and child collection may look. Level 1 = top-level TOC
23
+ * entries; level 2 = their children; etc. `undefined` means no limit.
24
+ */
25
+ export declare class Timeline {
26
+ private readonly _allItems;
27
+ private readonly linkMap;
28
+ private _depth;
29
+ private _items;
30
+ private _flat;
31
+ constructor(items: TimelineItem[], linkMap: Map<TimelineItem, Link>);
32
+ static build(publication: PublicationLike, options?: {
33
+ depth?: number;
34
+ }): Timeline;
35
+ /**
36
+ * The active depth limit for TOC traversal (title resolution and child
37
+ * collection). `undefined` means unlimited. Setting the same value again
38
+ * is a no-op; a new value invalidates the cached items and flat list.
39
+ */
40
+ get depth(): number | undefined;
41
+ set depth(value: number | undefined);
42
+ /** Top-level timeline items. Cached; invalidated when `depth` changes. */
43
+ get items(): TimelineItem[];
44
+ locate(locator: Locator): TimelineItem | undefined;
45
+ adjacentTo(item: TimelineItem): {
46
+ previous: TimelineItem | undefined;
47
+ next: TimelineItem | undefined;
48
+ };
49
+ segmentsForHref(href: string): TimelineItem[];
50
+ itemAtProgression(href: string, progression: number, duration?: number): TimelineItem | undefined;
51
+ ancestors(item: TimelineItem): TimelineItem[];
52
+ linkFor(item: TimelineItem): Link | undefined;
53
+ private get flat();
54
+ /**
55
+ * Resolve a display title for `bare` from the TOC, looking no deeper than
56
+ * `maxDepth` levels (1 = top-level entries only). Priority:
57
+ * 1. A start-of-resource entry: bare href or `#t=0` (audio).
58
+ * 2. Exactly one fragment entry referencing this resource — unambiguous.
59
+ * 3. Multiple fragment entries — ambiguous, returns `undefined`.
60
+ */
61
+ private static findTitleInToc;
62
+ /**
63
+ * Return the most relevant TOC Link for `bare` (used for `linkFor`).
64
+ * Prefers a start-of-resource entry; falls back to the first fragment entry.
65
+ */
66
+ private static findTocLink;
67
+ /**
68
+ * Collect all TOC entries that reference `bare` as flat children, walking
69
+ * up to `maxDepth` levels deep. Start-of-resource entries (#t=0 or no
70
+ * fragment) are excluded — they contribute to title resolution, not children.
71
+ * Order follows TOC declaration (depth-first).
72
+ */
73
+ private static collectChildrenFromToc;
74
+ /**
75
+ * Walk the TOC tree up to `maxDepth` levels and collect all entries whose
76
+ * bare href matches `bare`, split into start-of-resource entries and
77
+ * fragment entries.
78
+ */
79
+ private static collectTocCandidates;
80
+ /**
81
+ * A TOC href points to the start of its resource when it has no fragment,
82
+ * or when the fragment is `t=0` (audio: explicit beginning of the file).
83
+ */
84
+ private static isStartOfResource;
85
+ private static trimToDepth;
86
+ private flattenItems;
87
+ private itemMatchesTime;
88
+ private static parseTimeFragment;
89
+ private bareHrefFromItem;
90
+ private timeFromItem;
91
+ private ancestorPath;
92
+ private static bareHref;
93
+ }
94
+ export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Represents a single entry in a publication's timeline.
3
+ *
4
+ * The timeline contextualizes the reading order and table of contents so that
5
+ * consuming apps can display the current chapter title, build a progress bar,
6
+ * show previous/next as chapter titles, group search results by chapter, etc.
7
+ */
8
+ export interface TimelineItem {
9
+ /** Display title of this entry. */
10
+ title: string;
11
+ /**
12
+ * References as hrefs with optional fragments.
13
+ * e.g. ["track1.mp3#t=60"] for audio, ["chapter1.html"] for EPUB, ["#page=6"] for PDF.
14
+ */
15
+ references: string[];
16
+ /** Structural roles of this entry, e.g. ["chapter"], ["part"]. */
17
+ role?: string[];
18
+ /** Position number in the reading order context. */
19
+ position?: number;
20
+ /** Scroll progression within the resource (0 to 1), for entries that start mid-way in a resource. */
21
+ scroll?: number;
22
+ /** Nested entries. */
23
+ children?: TimelineItem[];
24
+ }
@@ -0,0 +1,2 @@
1
+ export * from './Timeline';
2
+ export * from './TimelineItem';
@@ -89,6 +89,7 @@ export declare class MediaType {
89
89
  static get ACSM(): MediaType;
90
90
  static get AIFF(): MediaType;
91
91
  static get AVI(): MediaType;
92
+ static get AVIF(): MediaType;
92
93
  static get BINARY(): MediaType;
93
94
  static get BMP(): MediaType;
94
95
  static get CBZ(): MediaType;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/LICENSE DELETED
@@ -1,28 +0,0 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2022, Readium Foundation
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.