@readium/navigator 2.4.0-alpha.13 → 2.4.0-alpha.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/navigator",
3
- "version": "2.4.0-alpha.13",
3
+ "version": "2.4.0-alpha.14",
4
4
  "type": "module",
5
5
  "description": "Next generation SDK for publications in Web Apps",
6
6
  "author": "readium",
@@ -55,8 +55,8 @@
55
55
  "typescript-plugin-css-modules": "^5.2.0",
56
56
  "user-agent-data-types": "^0.4.2",
57
57
  "vite": "^7.3.1",
58
- "@readium/shared": "2.2.0-alpha.2",
59
- "@readium/navigator-html-injectables": "2.3.1-alpha.2"
58
+ "@readium/navigator-html-injectables": "2.3.1-alpha.2",
59
+ "@readium/shared": "2.2.0-alpha.2"
60
60
  },
61
61
  "scripts": {
62
62
  "clean": "rimraf types dist",
@@ -837,7 +837,7 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
837
837
  return;
838
838
  }
839
839
 
840
- const progression = locator?.locations?.progression;
840
+ const progression = locator.locations?.progression;
841
841
  const hasProgression = progression && progression > 0;
842
842
  if(hasProgression)
843
843
  done = await new Promise<boolean>((res, _) => {
@@ -849,6 +849,36 @@ export class EpubNavigator extends VisualNavigator implements Configurable<Confi
849
849
  }
850
850
 
851
851
  public go(locator: Locator, _: boolean, cb: (ok: boolean) => void): void {
852
+ if(!locator.href) {
853
+ let fellback = false;
854
+ if(typeof locator.locations.position === "number") {
855
+ const match = this.positions.find(p => p.locations.position === locator.locations.position);
856
+ if (match) {
857
+ locator = match.copyWithLocations(locator.locations);
858
+ fellback = true;
859
+ }
860
+ }
861
+ if(!fellback && typeof locator.locations?.totalProgression === "number") {
862
+ // If locator has no href, but it does have a totalProgression,
863
+ // we can attempt to find the right resource from the positions list.
864
+ // This is here to help with conversion from OPDS locators which only
865
+ // require the total progression in the publication.
866
+ const targetProgression = locator.locations.totalProgression;
867
+ let closestIdx = 0;
868
+ let closestDist = Infinity;
869
+ for (let i = 0; i < this.positions.length; i++) {
870
+ const pos = this.positions[i];
871
+ // Use totalProgression if available, otherwise estimate from index
872
+ const posProg = pos.locations.totalProgression ?? (i / this.positions.length);
873
+ const dist = Math.abs(posProg - targetProgression);
874
+ if (dist < closestDist) {
875
+ closestDist = dist;
876
+ closestIdx = i;
877
+ }
878
+ }
879
+ locator = this.positions[closestIdx].copyWithLocations(locator.locations);
880
+ }
881
+ }
852
882
  const href = locator.href.split("#")[0];
853
883
  let link = this.pub.readingOrder.findWithHref(href);
854
884
  if(!link) {